Browse Source

Merge branch 'master' of github.com:Ultimaker/Cura

Ghostkeeper 7 years ago
parent
commit
739fd2bbcb

+ 4 - 2
cura/Settings/ExtruderManager.py

@@ -77,8 +77,9 @@ class ExtruderManager(QObject):
     @pyqtProperty("QVariantMap", notify=extrudersChanged)
     def extruderIds(self):
         map = {}
-        for position in self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()]:
-            map[position] = self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][position].getId()
+        global_stack_id = Application.getInstance().getGlobalContainerStack().getId()
+        for position in self._extruder_trains[global_stack_id]:
+            map[position] = self._extruder_trains[global_stack_id][position].getId()
         return map
 
     @pyqtSlot(str, result = str)
@@ -462,6 +463,7 @@ class ExtruderManager(QObject):
         for extruder in self.getMachineExtruders(machine_id):
             ContainerRegistry.getInstance().removeContainer(extruder.userChanges.getId())
             ContainerRegistry.getInstance().removeContainer(extruder.getId())
+        del self._extruder_trains[machine_id]
 
     ##  Returns extruders for a specific machine.
     #

+ 7 - 7
cura/Settings/MachineManager.py

@@ -1061,19 +1061,19 @@ class MachineManager(QObject):
         # If the machine that is being removed is the currently active machine, set another machine as the active machine.
         activate_new_machine = (self._global_container_stack and self._global_container_stack.getId() == machine_id)
 
-        ExtruderManager.getInstance().removeMachineExtruders(machine_id)
+        # activate a new machine before removing a machine because this is safer
+        if activate_new_machine:
+            machine_stacks = ContainerRegistry.getInstance().findContainerStacks(type = "machine")
+            other_machine_stacks = [s for s in machine_stacks if s.getId() != machine_id]
+            if other_machine_stacks:
+                Application.getInstance().setGlobalContainerStack(other_machine_stacks[0])
 
+        ExtruderManager.getInstance().removeMachineExtruders(machine_id)
         containers = ContainerRegistry.getInstance().findInstanceContainers(type = "user", machine = machine_id)
         for container in containers:
             ContainerRegistry.getInstance().removeContainer(container.getId())
         ContainerRegistry.getInstance().removeContainer(machine_id)
 
-        if activate_new_machine:
-            stacks = ContainerRegistry.getInstance().findContainerStacks(type = "machine")
-            if stacks:
-                Application.getInstance().setGlobalContainerStack(stacks[0])
-
-
     @pyqtProperty(bool, notify = globalContainerChanged)
     def hasMaterials(self) -> bool:
         if self._global_container_stack:

+ 46 - 13
plugins/3MFReader/ThreeMFWorkspaceReader.py

@@ -393,12 +393,23 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
         global_stack_id_original = self._stripFileToId(global_stack_file)
         global_stack_id_new = global_stack_id_original
         global_stack_need_rename = False
+
+        extruder_stack_id_map = {}  # new and old ExtruderStack IDs map
         if self._resolve_strategies["machine"] == "new":
             # We need a new id if the id already exists
             if self._container_registry.findContainerStacks(id = global_stack_id_original):
                 global_stack_id_new = self.getNewId(global_stack_id_original)
                 global_stack_need_rename = True
 
+            for each_extruder_stack_file in extruder_stack_files:
+                old_container_id = self._stripFileToId(each_extruder_stack_file)
+                new_container_id = old_container_id
+                if self._container_registry.findContainerStacks(id = old_container_id):
+                    # get a new name for this extruder
+                    new_container_id = self.getNewId(old_container_id)
+
+                extruder_stack_id_map[old_container_id] = new_container_id
+
         # TODO: For the moment we use pretty naive existence checking. If the ID is the same, we assume in quite a few
         # TODO: cases that the container loaded is the same (most notable in materials & definitions).
         # TODO: It might be possible that we need to add smarter checking in the future.
@@ -492,9 +503,9 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                         instance_container.setDirty(True)
                     elif self._resolve_strategies["machine"] == "new":
                         # The machine is going to get a spiffy new name, so ensure that the id's of user settings match.
-                        extruder_id = instance_container.getMetaDataEntry("extruder", None)
-                        if extruder_id:
-                            new_extruder_id = self.getNewId(extruder_id)
+                        old_extruder_id = instance_container.getMetaDataEntry("extruder", None)
+                        if old_extruder_id:
+                            new_extruder_id = extruder_stack_id_map[old_extruder_id]
                             new_id = new_extruder_id + "_current_settings"
                             instance_container._id = new_id
                             instance_container.setName(new_id)
@@ -535,9 +546,9 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                         #       AND REFACTOR!!!
                         if self._resolve_strategies["machine"] == "new":
                             # The machine is going to get a spiffy new name, so ensure that the id's of user settings match.
-                            extruder_id = instance_container.getMetaDataEntry("extruder", None)
-                            if extruder_id:
-                                new_extruder_id = self.getNewId(extruder_id)
+                            old_extruder_id = instance_container.getMetaDataEntry("extruder", None)
+                            if old_extruder_id:
+                                new_extruder_id = extruder_stack_id_map[old_extruder_id]
                                 instance_container.setMetaDataEntry("extruder", new_extruder_id)
 
                             machine_id = instance_container.getMetaDataEntry("machine", None)
@@ -641,9 +652,22 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
 
                     elif self._resolve_strategies["machine"] == "new":
                         # create a new extruder stack from this one
-                        new_id = self.getNewId(container_id)
+                        new_id = extruder_stack_id_map[container_id]
                         stack = ExtruderStack(new_id)
-                        stack.deserialize(archive.open(extruder_stack_file).read().decode("utf-8"))
+
+                        # HACK: the global stack can have a new name, so we need to make sure that this extruder stack
+                        #       references to the new name instead of the old one. Normally, this can be done after
+                        #       deserialize() by setting the metadata, but in the case of ExtruderStack, deserialize()
+                        #       also does addExtruder() to its machine stack, so we have to make sure that it's pointing
+                        #       to the right machine BEFORE deserialization.
+                        extruder_config = configparser.ConfigParser()
+                        extruder_config.read_string(extruder_file_content)
+                        extruder_config.set("metadata", "machine", global_stack_id_new)
+                        tmp_string_io = io.StringIO()
+                        extruder_config.write(tmp_string_io)
+                        extruder_file_content = tmp_string_io.getvalue()
+
+                        stack.deserialize(extruder_file_content)
 
                         # Ensure a unique ID and name
                         stack._id = new_id
@@ -660,17 +684,26 @@ class ThreeMFWorkspaceReader(WorkspaceReader):
                     elif self._resolve_strategies["machine"] == "new":
                         # container not found, create a new one
                         stack = ExtruderStack(container_id)
-                        stack.deserialize(archive.open(extruder_stack_file).read().decode("utf-8"))
+
+                        # HACK: the global stack can have a new name, so we need to make sure that this extruder stack
+                        #       references to the new name instead of the old one. Normally, this can be done after
+                        #       deserialize() by setting the metadata, but in the case of ExtruderStack, deserialize()
+                        #       also does addExtruder() to its machine stack, so we have to make sure that it's pointing
+                        #       to the right machine BEFORE deserialization.
+                        extruder_config = configparser.ConfigParser()
+                        extruder_config.read_string(extruder_file_content)
+                        extruder_config.set("metadata", "machine", global_stack_id_new)
+                        tmp_string_io = io.StringIO()
+                        extruder_config.write(tmp_string_io)
+                        extruder_file_content = tmp_string_io.getvalue()
+
+                        stack.deserialize(extruder_file_content)
                         self._container_registry.addContainer(stack)
                         extruder_stacks_added.append(stack)
                         containers_added.append(stack)
                     else:
                         Logger.log("w", "Unknown resolve strategy: %s" % str(self._resolve_strategies["machine"]))
 
-                if global_stack_need_rename:
-                    if stack.getMetaDataEntry("machine"):
-                        stack.setMetaDataEntry("machine", global_stack_id_new)
-
                 extruder_stacks.append(stack)
         except:
             Logger.logException("w", "We failed to serialize the stack. Trying to clean up.")

+ 13 - 0
resources/variants/ultimaker2_extended_0.25.inst.cfg

@@ -0,0 +1,13 @@
+[general]
+name = 0.25 mm
+version = 2
+definition = ultimaker2_extended
+
+[metadata]
+author = Ultimaker
+type = variant
+setting_version = 1
+
+[values]
+machine_nozzle_size = 0.25
+machine_nozzle_tip_outer_diameter = 0.8

+ 13 - 0
resources/variants/ultimaker2_extended_0.4.inst.cfg

@@ -0,0 +1,13 @@
+[general]
+name = 0.4 mm
+version = 2
+definition = ultimaker2_extended
+
+[metadata]
+author = Ultimaker
+type = variant
+setting_version = 1
+
+[values]
+machine_nozzle_size = 0.4
+machine_nozzle_tip_outer_diameter = 1.05

+ 13 - 0
resources/variants/ultimaker2_extended_0.6.inst.cfg

@@ -0,0 +1,13 @@
+[general]
+name = 0.6 mm
+version = 2
+definition = ultimaker2_extended
+
+[metadata]
+author = Ultimaker
+type = variant
+setting_version = 1
+
+[values]
+machine_nozzle_size = 0.6
+machine_nozzle_tip_outer_diameter = 1.25

+ 13 - 0
resources/variants/ultimaker2_extended_0.8.inst.cfg

@@ -0,0 +1,13 @@
+[general]
+name = 0.8 mm
+version = 2
+definition = ultimaker2_extended
+
+[metadata]
+author = Ultimaker
+type = variant
+setting_version = 1
+
+[values]
+machine_nozzle_size = 0.8
+machine_nozzle_tip_outer_diameter = 1.35