From 8b3290fb1e2aa0f704f7be3f036a53b6caf9a268 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 14 Mar 2019 10:50:53 +0100 Subject: [PATCH] Prevent the deletion of materials that are still active --- cura/Machines/MaterialManager.py | 20 ++++++++++++++++--- .../Preferences/Materials/MaterialsPage.qml | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/cura/Machines/MaterialManager.py b/cura/Machines/MaterialManager.py index ae6dbbd9bd..9a624d2221 100644 --- a/cura/Machines/MaterialManager.py +++ b/cura/Machines/MaterialManager.py @@ -553,10 +553,24 @@ class MaterialManager(QObject): # # Methods for GUI # + @pyqtSlot("QVariant", result=bool) + def canMaterialBeRemoved(self, material_node: "MaterialNode"): + # Check if the material is active in any extruder train. In that case, the material shouldn't be removed! + # In the future we might enable this again, but right now, it's causing a ton of issues if we do (since it + # corrupts the configuration) + root_material_id = material_node.getMetaDataEntry("base_file") + material_group = self.getMaterialGroup(root_material_id) + if not material_group: + return False + + nodes_to_remove = [material_group.root_material_node] + material_group.derived_material_node_list + ids_to_remove = [node.getMetaDataEntry("id", "") for node in nodes_to_remove] + + for extruder_stack in self._container_registry.findContainerStacks(type="extruder_train"): + if extruder_stack.material.getId() in ids_to_remove: + return False + return True - # - # Sets the new name for the given material. - # @pyqtSlot("QVariant", str) def setMaterialName(self, material_node: "MaterialNode", name: str) -> None: root_material_id = material_node.getMetaDataEntry("base_file") diff --git a/resources/qml/Preferences/Materials/MaterialsPage.qml b/resources/qml/Preferences/Materials/MaterialsPage.qml index a00a2340cd..097e1291bb 100644 --- a/resources/qml/Preferences/Materials/MaterialsPage.qml +++ b/resources/qml/Preferences/Materials/MaterialsPage.qml @@ -127,7 +127,7 @@ Item { text: catalog.i18nc("@action:button", "Remove") iconName: "list-remove" - enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated + enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated && base.materialManager.canMaterialBeRemoved(base.currentItem.container_node) onClicked: { forceActiveFocus();