Browse Source

CURA-4839 Avoid creating unique names for the extruder instance
containers if the strategy is upgrade existing

Diego Prado Gesto 7 years ago
parent
commit
e38cf957bb

+ 5 - 4
cura/Settings/CuraContainerRegistry.py

@@ -454,8 +454,9 @@ class CuraContainerRegistry(ContainerRegistry):
     #      - override the current machine
     #      - create new for custom quality profile
     # new_global_quality_changes is the new global quality changes container in this scenario.
+    # create_new_ids indicates if new unique ids must be created
     #
-    def addExtruderStackForSingleExtrusionMachine(self, machine, extruder_id, new_global_quality_changes = None):
+    def addExtruderStackForSingleExtrusionMachine(self, machine, extruder_id, new_global_quality_changes = None, create_new_ids = True):
         new_extruder_id = extruder_id
 
         extruder_definitions = self.findDefinitionContainers(id = new_extruder_id)
@@ -464,7 +465,7 @@ class CuraContainerRegistry(ContainerRegistry):
             return
 
         extruder_definition = extruder_definitions[0]
-        unique_name = self.uniqueName(machine.getName() + " " + new_extruder_id)
+        unique_name = self.uniqueName(machine.getName() + " " + new_extruder_id) if create_new_ids else machine.getName() + " " + new_extruder_id
 
         extruder_stack = ExtruderStack.ExtruderStack(unique_name)
         extruder_stack.setName(extruder_definition.getName())
@@ -474,7 +475,7 @@ class CuraContainerRegistry(ContainerRegistry):
         from cura.CuraApplication import CuraApplication
 
         # create a new definition_changes container for the extruder stack
-        definition_changes_id = self.uniqueName(extruder_stack.getId() + "_settings")
+        definition_changes_id = self.uniqueName(extruder_stack.getId() + "_settings") if create_new_ids else extruder_stack.getId() + "_settings"
         definition_changes_name = definition_changes_id
         definition_changes = InstanceContainer(definition_changes_id)
         definition_changes.setName(definition_changes_name)
@@ -501,7 +502,7 @@ class CuraContainerRegistry(ContainerRegistry):
         extruder_stack.setDefinitionChanges(definition_changes)
 
         # create empty user changes container otherwise
-        user_container_id = self.uniqueName(extruder_stack.getId() + "_user")
+        user_container_id = self.uniqueName(extruder_stack.getId() + "_user") if create_new_ids else extruder_stack.getId() + "_user"
         user_container_name = user_container_id
         user_container = InstanceContainer(user_container_id)
         user_container.setName(user_container_name)

+ 12 - 3
plugins/3MFReader/ThreeMFWorkspaceReader.py

@@ -721,7 +721,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                 stack.setName(global_stack_name_new)
 
                 container_stacks_added.append(stack)
-                self._container_registry.addContainer(stack)
+                # self._container_registry.addContainer(stack)
                 containers_added.append(stack)
             else:
                 Logger.log("e", "Resolve strategy of %s for machine is not supported", self._resolve_strategies["machine"])
@@ -793,13 +793,16 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                 # If we choose to override a machine but to create a new custom quality profile, the custom quality
                 # profile is not immediately applied to the global_stack, so this fix for single extrusion machines
                 # will use the current custom quality profile on the existing machine. The extra optional argument
-                # in that function is used in thia case to specify a new global stack quality_changes container so
+                # in that function is used in this case to specify a new global stack quality_changes container so
                 # the fix can correctly create and copy over the custom quality settings to the newly created extruder.
                 new_global_quality_changes = None
                 if self._resolve_strategies["quality_changes"] == "new" and len(quality_changes_instance_containers) > 0:
                     new_global_quality_changes = quality_changes_instance_containers[0]
+
+                # Depending if the strategy is to create a new or override, the ids must be or not be unique
                 stack = self._container_registry.addExtruderStackForSingleExtrusionMachine(global_stack, "fdmextruder",
-                                                                                           new_global_quality_changes)
+                                                                                           new_global_quality_changes,
+                                                                                           create_new_ids = self._resolve_strategies["machine"] == "new")
                 if new_global_quality_changes is not None:
                     quality_changes_instance_containers.append(stack.qualityChanges)
                     quality_and_definition_changes_instance_containers.append(stack.qualityChanges)
@@ -822,6 +825,12 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                 self._container_registry.removeContainer(container.getId())
             return
 
+        ## In case there is a new machine and once the extruders are created, the global stack is added to the registry,
+        # otherwise the accContainers function in CuraContainerRegistry will create an extruder stack and then creating
+        # useless files
+        if self._resolve_strategies["machine"] == "new":
+            self._container_registry.addContainer(global_stack)
+
         # Check quality profiles to make sure that if one stack has the "not supported" quality profile,
         # all others should have the same.
         #