Browse Source

Don't use material manager to find or remove materials

That remove function in the material manager was very weird...

Contributes to issue CURA-6776.
Ghostkeeper 5 years ago
parent
commit
12043df367
2 changed files with 5 additions and 20 deletions
  1. 1 1
      cura/Machines/MaterialManager.py
  2. 4 19
      plugins/3MFReader/ThreeMFWorkspaceReader.py

+ 1 - 1
cura/Machines/MaterialManager.py

@@ -255,7 +255,7 @@ class MaterialManager(QObject):
         for result in results:
             container_registry.removeContainer(result.getMetaDataEntry("id", ""))
 
-    @pyqtSlot("QVariant", result=bool)
+    @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

+ 4 - 19
plugins/3MFReader/ThreeMFWorkspaceReader.py

@@ -575,7 +575,6 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
     @call_on_qt_thread
     def read(self, file_name):
         application = CuraApplication.getInstance()
-        material_manager = application.getMaterialManager()
 
         archive = zipfile.ZipFile(file_name, "r")
 
@@ -673,7 +672,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                         if self._resolve_strategies["material"] == "override":
                             # Remove the old materials and then deserialize the one from the project
                             root_material_id = material_container.getMetaDataEntry("base_file")
-                            material_manager.removeMaterialByRootId(root_material_id)
+                            application.getContainerRegistry().removeContainer(root_material_id)
                         elif self._resolve_strategies["material"] == "new":
                             # Note that we *must* deserialize it with a new ID, as multiple containers will be
                             # auto created & added.
@@ -727,8 +726,6 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
         if self._machine_info.quality_changes_info is None:
             return
 
-        application = CuraApplication.getInstance()
-
         # If we have custom profiles, load them
         quality_changes_name = self._machine_info.quality_changes_info.name
         if self._machine_info.quality_changes_info is not None:
@@ -957,9 +954,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                 extruder_stack.variant = node.container
 
     def _applyMaterials(self, global_stack, extruder_stack_dict):
-        application = CuraApplication.getInstance()
-        material_manager = application.getMaterialManager()
-
+        machine_node = ContainerTree.getInstance().machines[global_stack]
         for position, extruder_stack in extruder_stack_dict.items():
             if position not in self._machine_info.extruder_info_dict:
                 continue
@@ -970,18 +965,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
             root_material_id = extruder_info.root_material_id
             root_material_id = self._old_new_materials.get(root_material_id, root_material_id)
 
-            build_plate_id = global_stack.variant.getId()
-
-            # get material diameter of this extruder
-            machine_material_diameter = extruder_stack.getCompatibleMaterialDiameter()
-            material_node = material_manager.getMaterialNode(global_stack.definition.getId(),
-                                                             extruder_stack.variant.getName(),
-                                                             build_plate_id,
-                                                             machine_material_diameter,
-                                                             root_material_id)
-
-            if material_node is not None and material_node.container is not None:
-                extruder_stack.material = material_node.container  # type: InstanceContainer
+            material_node = machine_node.variants[extruder_stack.variant.getName()].materials[root_material_id]
+            extruder_stack.material = material_node.container  # type: InstanceContainer
 
     def _applyChangesToMachine(self, global_stack, extruder_stack_dict):
         # Clear all first