Browse Source

Fix getting correct initial extruder number

As found in the discussion in #6847.

This was done as a 5 minute fix.
Ghostkeeper 5 years ago
parent
commit
d18c0703b4
2 changed files with 22 additions and 6 deletions
  1. 20 1
      cura/Settings/ExtruderManager.py
  2. 2 5
      plugins/CuraEngineBackend/StartSliceJob.py

+ 20 - 1
cura/Settings/ExtruderManager.py

@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Ultimaker B.V.
+# Copyright (c) 2020 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
 from PyQt5.QtCore import pyqtSignal, pyqtProperty, QObject, QVariant  # For communicating data and events to Qt.
@@ -275,6 +275,25 @@ class ExtruderManager(QObject):
             Logger.log("e", "Unable to find one or more of the extruders in %s", used_extruder_stack_ids)
             return []
 
+    ##  Get the extruder that the print will start with.
+    #
+    #   This should mirror the implementation in CuraEngine of
+    #   ``FffGcodeWriter::getStartExtruder()``.
+    def getInitialExtruderNr(self) -> int:
+        application = cura.CuraApplication.CuraApplication.getInstance()
+        global_stack = application.getGlobalContainerStack()
+
+        # Starts with the adhesion extruder.
+        if global_stack.getProperty("adhesion_type", "value") != "none":
+            return global_stack.getProperty("adhesion_extruder_nr", "value")
+
+        # No adhesion? Well maybe there is still support brim.
+        if (global_stack.getProperty("support_enable", "value") or global_stack.getProperty("support_tree_enable", "value")) and global_stack.getProperty("support_brim_enable", "value"):
+            return global_stack.getProperty("support_infill_extruder_nr", "value")
+
+        # REALLY no adhesion? Use the first used extruder.
+        return self.getUsedExtruderStacks()[0].getProperty("extruder_nr", "value")
+
     ##  Removes the container stack and user profile for the extruders for a specific machine.
     #
     #   \param machine_id The machine to remove the extruders for.

+ 2 - 5
plugins/CuraEngineBackend/StartSliceJob.py

@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Ultimaker B.V.
+# Copyright (c) 2020 Ultimaker B.V.
 # Cura is released under the terms of the LGPLv3 or higher.
 
 import numpy
@@ -343,10 +343,7 @@ class StartSliceJob(Job):
         result["time"] = time.strftime("%H:%M:%S") #Some extra settings.
         result["date"] = time.strftime("%d-%m-%Y")
         result["day"] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][int(time.strftime("%w"))]
-
-        initial_extruder_stack = CuraApplication.getInstance().getExtruderManager().getUsedExtruderStacks()[0]
-        initial_extruder_nr = initial_extruder_stack.getProperty("extruder_nr", "value")
-        result["initial_extruder_nr"] = initial_extruder_nr
+        result["initial_extruder_nr"] = CuraApplication.getInstance().getExtruderManager().getInitialExtruderNr()
 
         return result