Browse Source

Do not add and register Extruders if they are already there

CURA-3756
Lipu Fei 7 years ago
parent
commit
b2f0623ecf
2 changed files with 11 additions and 0 deletions
  1. 7 0
      cura/Settings/ExtruderManager.py
  2. 4 0
      cura/Settings/GlobalStack.py

+ 7 - 0
cura/Settings/ExtruderManager.py

@@ -237,6 +237,13 @@ class ExtruderManager(QObject):
         if machine_id not in self._extruder_trains:
             self._extruder_trains[machine_id] = {}
             changed = True
+
+        # do not register if an extruder has already been registered at the position on this machine
+        if any(item.getId() == extruder_train.getId() for item in self._extruder_trains[machine_id].values()):
+            Logger.log("w", "Extruder [%s] has already been registered on machine [%s], not doing anything",
+                       extruder_train.getId(), machine_id)
+            return
+
         if extruder_train:
             self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train
             changed = True

+ 4 - 0
cura/Settings/GlobalStack.py

@@ -52,12 +52,16 @@ class GlobalStack(CuraContainerStack):
         extruder_count = self.getProperty("machine_extruder_count", "value")
         if extruder_count and len(self._extruders) + 1 > extruder_count:
             Logger.log("w", "Adding extruder {meta} to {id} but its extruder count is {count}".format(id = self.id, count = extruder_count, meta = str(extruder.getMetaData())))
+            return
 
         position = extruder.getMetaDataEntry("position")
         if position is None:
             Logger.log("w", "No position defined for extruder {extruder}, cannot add it to stack {stack}", extruder = extruder.id, stack = self.id)
             return
 
+        if any(item.getId() == extruder.id for item in self._extruders.values()):
+            Logger.log("w", "Extruder [%s] has already been added to this stack [%s]", extruder.id, self._id)
+            return
         self._extruders[position] = extruder
 
     ##  Overridden from ContainerStack