diff --git a/cura/Machines/MaterialManager.py b/cura/Machines/MaterialManager.py index 24995e417b..5d5938d95d 100644 --- a/cura/Machines/MaterialManager.py +++ b/cura/Machines/MaterialManager.py @@ -246,7 +246,7 @@ class MaterialManager(QObject): def removeMaterialByRootId(self, root_material_id: str): container_registry = CuraContainerRegistry.getInstance() - results = container_registry.findContainers(id=root_material_id) + results = container_registry.findContainers(id = root_material_id) if not results: container_registry.addWrongContainerId(root_material_id) diff --git a/cura/Machines/Models/MaterialManagementModel.py b/cura/Machines/Models/MaterialManagementModel.py index 1b7774c4d3..2c8617073d 100644 --- a/cura/Machines/Models/MaterialManagementModel.py +++ b/cura/Machines/Models/MaterialManagementModel.py @@ -45,4 +45,21 @@ class MaterialManagementModel(QObject): if container_registry.isReadOnly(root_material_id): Logger.log("w", "Cannot set name of read-only container %s.", root_material_id) return - return container_registry.findContainers(id = root_material_id)[0].setName(name) \ No newline at end of file + return container_registry.findContainers(id = root_material_id)[0].setName(name) + + ## Deletes a material from Cura. + # + # This function does not do any safety checking any more. Please call this + # function only if: + # - The material is not read-only. + # - The material is not used in any stacks. + # If the material was not lazy-loaded yet, this will fully load the + # container. When removing this material node, all other materials with + # the same base fill will also be removed. + # \param material_node The material to remove. + @pyqtSlot("QVariant") + def removeMaterial(self, material_node: "MaterialNode") -> None: + container_registry = CuraContainerRegistry.getInstance() + materials_this_base_file = container_registry.findContainersMetadata(base_file = material_node.base_file) + for material_metadata in materials_this_base_file: + container_registry.removeContainer(material_metadata["id"]) \ No newline at end of file diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index 80d746351c..3453c866e3 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -302,7 +302,7 @@ Item { // Set the active material as the fallback. It will be selected when the current material is deleted base.newRootMaterialIdToSwitchTo = base.active_root_material_id - base.materialManager.removeMaterial(base.currentItem.container_node); + base.materialManagement.removeMaterial(base.currentItem.container_node); } } diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index 8302f5f65a..83c7de9aee 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -565,7 +565,7 @@ TabView } // update the values - base.materialManagement.setMaterialName(base.currentMaterialNode, new_name) + materialManagement.setMaterialName(base.currentMaterialNode, new_name) properties.name = new_name }