Browse Source

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

Nino van Hooff 4 years ago
parent
commit
fbedfc88d4

+ 0 - 45
plugins/PostProcessingPlugin/scripts/BQ_PauseAtHeight.py

@@ -1,45 +0,0 @@
-from ..Script import Script
-class BQ_PauseAtHeight(Script):
-    def __init__(self):
-        super().__init__()
-
-    def getSettingDataString(self):
-        return """{
-            "name":"Pause at height (BQ Printers)",
-            "key": "BQ_PauseAtHeight",
-            "metadata":{},
-            "version": 2,
-            "settings":
-            {
-                "pause_height":
-                {
-                    "label": "Pause height",
-                    "description": "At what height should the pause occur",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 5.0
-                }
-            }
-        }"""
-
-    def execute(self, data):
-        pause_z = self.getSettingValueByKey("pause_height")
-        for layer in data: 
-            lines = layer.split("\n")
-            for line in lines:
-                if self.getValue(line, 'G') == 1 or self.getValue(line, 'G') == 0:
-                    current_z = self.getValue(line, 'Z')
-                    if current_z is not None:
-                        if current_z >= pause_z:
-                            prepend_gcode = ";TYPE:CUSTOM\n"
-                            prepend_gcode += "; -- Pause at height (%.2f mm) --\n" % pause_z
-
-                            # Insert Pause gcode
-                            prepend_gcode += "M25        ; Pauses the print and waits for the user to resume it\n"
-                            
-                            index = data.index(layer) 
-                            layer = prepend_gcode + layer
-                            data[index] = layer # Override the data of this layer with the modified data
-                            return data
-                        break
-        return data

+ 132 - 15
plugins/PostProcessingPlugin/scripts/PauseAtHeight.py

@@ -25,7 +25,7 @@ class PauseAtHeight(Script):
                     "label": "Pause at",
                     "description": "Whether to pause at a certain height or at a certain layer.",
                     "type": "enum",
-                    "options": {"height": "Height", "layer_no": "Layer No."},
+                    "options": {"height": "Height", "layer_no": "Layer Number"},
                     "default_value": "height"
                 },
                 "pause_height":
@@ -49,6 +49,15 @@ class PauseAtHeight(Script):
                     "minimum_value_warning": "1",
                     "enabled": "pause_at == 'layer_no'"
                 },
+                "pause_method":
+                {
+                    "label": "Method",
+                    "description": "The method or gcode command to use for pausing.",
+                    "type": "enum",
+                    "options": {"marlin": "Marlin (M0)", "griffin": "Griffin (M0, firmware retract)", "bq": "BQ (M25)", "reprap": "RepRap (M226)", "repetier": "Repetier (@pause)"},
+                    "default_value": "marlin",
+                    "value": "\\\"griffin\\\" if machine_gcode_flavor==\\\"Griffin\\\" else \\\"reprap\\\" if machine_gcode_flavor==\\\"RepRap (RepRap)\\\" else \\\"repetier\\\" if machine_gcode_flavor==\\\"Repetier\\\" else \\\"bq\\\" if \\\"BQ\\\" in machine_name else \\\"marlin\\\""
+                },                    
                 "disarm_timeout":
                 {
                     "label": "Disarm timeout",
@@ -66,7 +75,8 @@ class PauseAtHeight(Script):
                     "description": "What X location does the head move to when pausing.",
                     "unit": "mm",
                     "type": "float",
-                    "default_value": 190
+                    "default_value": 190,
+                    "enabled": "pause_method != \\\"griffin\\\""
                 },
                 "head_park_y":
                 {
@@ -74,7 +84,17 @@ class PauseAtHeight(Script):
                     "description": "What Y location does the head move to when pausing.",
                     "unit": "mm",
                     "type": "float",
-                    "default_value": 190
+                    "default_value": 190,
+                    "enabled": "pause_method != \\\"griffin\\\""
+                },
+                "head_move_z":
+                {
+                    "label": "Head move Z",
+                    "description": "The Height of Z-axis retraction before parking.",
+                    "unit": "mm",
+                    "type": "float",
+                    "default_value": 15.0,
+                    "enabled": "pause_method == \\\"repetier\\\""
                 },
                 "retraction_amount":
                 {
@@ -82,7 +102,8 @@ class PauseAtHeight(Script):
                     "description": "How much filament must be retracted at pause.",
                     "unit": "mm",
                     "type": "float",
-                    "default_value": 0
+                    "default_value": 0,
+                    "enabled": "pause_method != \\\"griffin\\\""
                 },
                 "retraction_speed":
                 {
@@ -90,7 +111,8 @@ class PauseAtHeight(Script):
                     "description": "How fast to retract the filament.",
                     "unit": "mm/s",
                     "type": "float",
-                    "default_value": 25
+                    "default_value": 25,
+                    "enabled": "pause_method not in [\\\"griffin\\\", \\\"repetier\\\"]"
                 },
                 "extrude_amount":
                 {
@@ -98,7 +120,8 @@ class PauseAtHeight(Script):
                     "description": "How much filament should be extruded after pause. This is needed when doing a material change on Ultimaker2's to compensate for the retraction after the change. In that case 128+ is recommended.",
                     "unit": "mm",
                     "type": "float",
-                    "default_value": 0
+                    "default_value": 0,
+                    "enabled": "pause_method != \\\"griffin\\\""
                 },
                 "extrude_speed":
                 {
@@ -106,7 +129,8 @@ class PauseAtHeight(Script):
                     "description": "How fast to extrude the material after pause.",
                     "unit": "mm/s",
                     "type": "float",
-                    "default_value": 3.3333
+                    "default_value": 3.3333,
+                    "enabled": "pause_method not in [\\\"griffin\\\", \\\"repetier\\\"]"
                 },
                 "redo_layer":
                 {
@@ -121,18 +145,59 @@ class PauseAtHeight(Script):
                     "description": "Change the temperature during the pause.",
                     "unit": "°C",
                     "type": "int",
-                    "default_value": 0
+                    "default_value": 0,
+                    "enabled": "pause_method not in [\\\"griffin\\\", \\\"repetier\\\"]"
                 },
                 "display_text":
                 {
                     "label": "Display Text",
                     "description": "Text that should appear on the display while paused. If left empty, there will not be any message.",
                     "type": "str",
-                    "default_value": ""
+                    "default_value": "",
+                    "enabled": "pause_method != \\\"repetier\\\""
+                },
+                "machine_name":
+                {
+                    "label": "Machine Type",
+                    "description": "The name of your 3D printer model. This setting is controlled by the script and will not be visible.",
+                    "default_value": "Unknown",
+                    "type": "str",
+                    "enabled": false
+                },
+                "machine_gcode_flavor":
+                {
+                    "label": "G-code flavor",
+                    "description": "The type of g-code to be generated. This setting is controlled by the script and will not be visible.",
+                    "type": "enum",
+                    "options":
+                    {
+                        "RepRap (Marlin/Sprinter)": "Marlin",
+                        "RepRap (Volumetric)": "Marlin (Volumetric)",
+                        "RepRap (RepRap)": "RepRap",
+                        "UltiGCode": "Ultimaker 2",
+                        "Griffin": "Griffin",
+                        "Makerbot": "Makerbot",
+                        "BFB": "Bits from Bytes",
+                        "MACH3": "Mach3",
+                        "Repetier": "Repetier"
+                    },
+                    "default_value": "RepRap (Marlin/Sprinter)",
+                    "enabled": false
                 }
             }
         }"""
 
+    ##  Copy machine name and gcode flavor from global stack so we can use their value in the script stack
+    def initialize(self) -> None:
+        super().initialize()
+
+        global_container_stack = Application.getInstance().getGlobalContainerStack()
+        if global_container_stack is None or self._instance is None:
+            return
+
+        for key in ["machine_name", "machine_gcode_flavor"]:
+            self._instance.setProperty(key, "value", global_container_stack.getProperty(key, "value"))
+
     ##  Get the X and Y values for a layer (will be used to get X and Y of the
     #   layer after the pause).
     def getNextXY(self, layer: str) -> Tuple[float, float]:
@@ -158,6 +223,7 @@ class PauseAtHeight(Script):
         extrude_speed = self.getSettingValueByKey("extrude_speed")
         park_x = self.getSettingValueByKey("head_park_x")
         park_y = self.getSettingValueByKey("head_park_y")
+        move_z = self.getSettingValueByKey("head_move_z")
         layers_started = False
         redo_layer = self.getSettingValueByKey("redo_layer")
         standby_temperature = self.getSettingValueByKey("standby_temperature")
@@ -166,7 +232,14 @@ class PauseAtHeight(Script):
         initial_layer_height = Application.getInstance().getGlobalContainerStack().getProperty("layer_height_0", "value")
         display_text = self.getSettingValueByKey("display_text")
 
-        is_griffin = False
+        pause_method = self.getSettingValueByKey("pause_method")
+        pause_command = {
+            "marlin": self.putValue(M = 0),
+            "griffin": self.putValue(M = 0),
+            "bq": self.putValue(M = 25),
+            "reprap": self.putValue(M = 226),
+            "repetier": self.putValue("@pause now change filament and press continue printing")
+        }[pause_method]
 
         # T = ExtruderManager.getInstance().getActiveExtruderStack().getProperty("material_print_temperature", "value")
 
@@ -187,8 +260,6 @@ class PauseAtHeight(Script):
 
             # Scroll each line of instruction for each layer in the G-code
             for line in lines:
-                if ";FLAVOR:Griffin" in line:
-                    is_griffin = True
                 # Fist positive layer reached
                 if ";LAYER:0" in line:
                     layers_started = True
@@ -290,7 +361,22 @@ class PauseAtHeight(Script):
                 else:
                     prepend_gcode += ";current layer: {layer}\n".format(layer = current_layer)
 
-                if not is_griffin:
+                if pause_method == "repetier":
+                    #Retraction
+                    prepend_gcode += self.putValue(M = 83) + " ; switch to relative E values for any needed retraction\n"
+                    if retraction_amount != 0:
+                        prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = 6000) + "\n"
+
+                    #Move the head away
+                    prepend_gcode += self.putValue(G = 1, Z = current_z + 1, F = 300) + " ; move up a millimeter to get out of the way\n"
+                    prepend_gcode += self.putValue(G = 1, X = park_x, Y = park_y, F = 9000) + "\n"
+                    if current_z < move_z:
+                        prepend_gcode += self.putValue(G = 1, Z = current_z + move_z, F = 300) + "\n"
+
+                    #Disable the E steppers
+                    prepend_gcode += self.putValue(M = 84, E = 0) + "\n"
+
+                elif pause_method != "griffin":
                     # Retraction
                     prepend_gcode += self.putValue(M = 83) + " ; switch to relative E values for any needed retraction\n"
                     if retraction_amount != 0:
@@ -322,9 +408,40 @@ class PauseAtHeight(Script):
                     prepend_gcode += self.putValue(M = 18, S = disarm_timeout) + " ; Set the disarm timeout\n"
 
                 # Wait till the user continues printing
-                prepend_gcode += self.putValue(M = 0) + " ; Do the actual pause\n"
+                prepend_gcode += pause_command + " ; Do the actual pause\n"
+
+                if pause_method == "repetier":
+                    #Push the filament back,
+                    if retraction_amount != 0:
+                        prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = 6000) + "\n"
+
+                    # Optionally extrude material
+                    if extrude_amount != 0:
+                        prepend_gcode += self.putValue(G = 1, E = extrude_amount, F = 200) + "\n"
+                        prepend_gcode += self.putValue("@info wait for cleaning nozzle from previous filament") + "\n"
+                        prepend_gcode += self.putValue("@pause remove the waste filament from parking area and press continue printing") + "\n"
+
+                    # and retract again, the properly primes the nozzle when changing filament.
+                    if retraction_amount != 0:
+                        prepend_gcode += self.putValue(G = 1, E = -retraction_amount, F = 6000) + "\n"
+
+                    #Move the head back
+                    prepend_gcode += self.putValue(G = 1, Z = current_z + 1, F = 300) + "\n"
+                    prepend_gcode += self.putValue(G = 1, X = x, Y = y, F = 9000) + "\n"
+                    if retraction_amount != 0:
+                        prepend_gcode += self.putValue(G = 1, E = retraction_amount, F = 6000) + "\n"
+
+                    if current_extrusion_f != 0:
+                        prepend_gcode += self.putValue(G = 1, F = current_extrusion_f) + " ; restore extrusion feedrate\n"
+                    else:
+                        Logger.log("w", "No previous feedrate found in gcode, feedrate for next layer(s) might be incorrect")
+
+                    prepend_gcode += self.putValue(M = 82) + "\n"
+
+                    # reset extrude value to pre pause value
+                    prepend_gcode += self.putValue(G = 92, E = current_e) + "\n"
 
-                if not is_griffin:
+                elif pause_method != "griffin":
                     if control_temperatures:
                         # Set extruder resume temperature
                         prepend_gcode += self.putValue(M = 109, S = int(target_temperature.get(current_t, 0))) + " ; resume temperature\n"

+ 0 - 51
plugins/PostProcessingPlugin/scripts/PauseAtHeightRepRapFirmwareDuet.py

@@ -1,51 +0,0 @@
-from ..Script import Script
-
-class PauseAtHeightRepRapFirmwareDuet(Script):
-
-    def getSettingDataString(self):
-        return """{
-            "name": "Pause at height for RepRapFirmware DuetWifi / Duet Ethernet / Duet Maestro",
-            "key": "PauseAtHeightRepRapFirmwareDuet",
-            "metadata": {},
-            "version": 2,
-            "settings":
-            {
-                "pause_height":
-                {
-                    "label": "Pause height",
-                    "description": "At what height should the pause occur",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 5.0
-                }
-            }
-        }"""
-
-    def execute(self, data):
-        current_z = 0.
-        pause_z = self.getSettingValueByKey("pause_height")
-
-        layers_started = False
-        for layer_number, layer in enumerate(data):
-            lines = layer.split("\n")
-            for line in lines:
-                if ";LAYER:0" in line:
-                    layers_started = True
-                    continue
-
-                if not layers_started:
-                    continue
-
-                if self.getValue(line, 'G') == 1 or self.getValue(line, 'G') == 0:
-                    current_z = self.getValue(line, 'Z')
-                    if current_z != None:
-                        if current_z >= pause_z:
-                            prepend_gcode = ";TYPE:CUSTOM\n"
-                            prepend_gcode += "; -- Pause at height (%.2f mm) --\n" % pause_z
-                            prepend_gcode += self.putValue(M = 226) + "\n"
-                            layer = prepend_gcode + layer
-
-                            data[layer_number] = layer # Override the data of this layer with the modified data
-                            return data
-                        break
-        return data

+ 0 - 178
plugins/PostProcessingPlugin/scripts/PauseAtHeightforRepetier.py

@@ -1,178 +0,0 @@
-from UM.Logger import Logger
-from ..Script import Script
-class PauseAtHeightforRepetier(Script):
-    def __init__(self):
-        super().__init__()
-
-    def getSettingDataString(self):
-        return """{
-            "name":"Pause at height for repetier",
-            "key": "PauseAtHeightforRepetier",
-            "metadata": {},
-            "version": 2,
-            "settings":
-            {
-                "pause_height":
-                {
-                    "label": "Pause height",
-                    "description": "At what height should the pause occur",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 5.0
-                },
-                "head_park_x":
-                {
-                    "label": "Park print head X",
-                    "description": "What x location does the head move to when pausing.",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 5.0
-                },
-                "head_park_y":
-                {
-                    "label": "Park print head Y",
-                    "description": "What y location does the head move to when pausing.",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 5.0
-                },
-                "head_move_Z":
-                {
-                    "label": "Head move Z",
-                    "description": "The Hieght of Z-axis retraction before parking.",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 15.0
-                },
-                "retraction_amount":
-                {
-                    "label": "Retraction",
-                    "description": "How much fillament must be retracted at pause.",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 5.0
-                },
-                "extrude_amount":
-                {
-                    "label": "Extrude amount",
-                    "description": "How much filament should be extruded after pause. This is needed when doing a material change on Ultimaker2's to compensate for the retraction after the change. In that case 128+ is recommended.",
-                    "unit": "mm",
-                    "type": "float",
-                    "default_value": 90.0
-                },
-                "redo_layers":
-                {
-                    "label": "Redo layers",
-                    "description": "Redo a number of previous layers after a pause to increases adhesion.",
-                    "unit": "layers",
-                    "type": "int",
-                    "default_value": 0
-                }
-            }
-        }"""
-
-    def execute(self, data):
-        x = 0.
-        y = 0.
-        current_extrusion_f = 0
-        current_z = 0.
-        pause_z = self.getSettingValueByKey("pause_height")
-        retraction_amount = self.getSettingValueByKey("retraction_amount")
-        extrude_amount = self.getSettingValueByKey("extrude_amount")
-        park_x = self.getSettingValueByKey("head_park_x")
-        park_y = self.getSettingValueByKey("head_park_y")
-        move_Z = self.getSettingValueByKey("head_move_Z")
-        layers_started = False
-        redo_layers = self.getSettingValueByKey("redo_layers")
-        for layer in data:
-            lines = layer.split("\n")
-            for line in lines:
-                if ";LAYER:0" in line:
-                    layers_started = True
-                    continue
-
-                if not layers_started:
-                    continue
-
-                if self.getValue(line, 'G') == 1 or self.getValue(line, 'G') == 0:
-                    current_z = self.getValue(line, 'Z')
-                    if self.getValue(line, 'F') is not None and self.getValue(line, 'E') is not None:
-                        current_extrusion_f = self.getValue(line, 'F', current_extrusion_f)
-                    x = self.getValue(line, 'X', x)
-                    y = self.getValue(line, 'Y', y)
-                    if current_z is not None:
-                        if current_z >= pause_z:
-
-                            index = data.index(layer)
-                            prevLayer = data[index-1]
-                            prevLines = prevLayer.split("\n")
-                            current_e = 0.
-                            for prevLine in reversed(prevLines):
-                                current_e = self.getValue(prevLine, 'E', -1)
-                                if current_e >= 0:
-                                    break
-
-                            prepend_gcode = ";TYPE:CUSTOM\n"
-                            prepend_gcode += ";added code by post processing\n"
-                            prepend_gcode += ";script: PauseAtHeightforRepetier.py\n"
-                            prepend_gcode += ";current z: %f \n" % (current_z)
-                            prepend_gcode += ";current X: %f \n" % (x)
-                            prepend_gcode += ";current Y: %f \n" % (y)
-
-                            #Retraction
-                            prepend_gcode += "M83\n"
-                            if retraction_amount != 0:
-                                prepend_gcode += "G1 E-%f F6000\n" % (retraction_amount)
-
-                            #Move the head away
-                            prepend_gcode += "G1 Z%f F300\n" % (1 + current_z)
-                            prepend_gcode += "G1 X%f Y%f F9000\n" % (park_x, park_y)
-                            if current_z < move_Z:
-                                prepend_gcode += "G1 Z%f F300\n" % (current_z + move_Z)
-
-                            #Disable the E steppers
-                            prepend_gcode += "M84 E0\n"
-                            #Wait till the user continues printing
-                            prepend_gcode += "@pause now change filament and press continue printing ;Do the actual pause\n"
-
-                            #Push the filament back,
-                            if retraction_amount != 0:
-                                prepend_gcode += "G1 E%f F6000\n" % (retraction_amount)
-
-                            # Optionally extrude material
-                            if extrude_amount != 0:
-                                prepend_gcode += "G1 E%f F200\n" % (extrude_amount)
-                                prepend_gcode += "@info wait for cleaning nozzle from previous filament\n"
-                                prepend_gcode += "@pause  remove the waste filament from parking area and press continue printing\n"
-
-                            # and retract again, the properly primes the nozzle when changing filament.
-                            if retraction_amount != 0:
-                                prepend_gcode += "G1 E-%f F6000\n" % (retraction_amount)
-
-                            #Move the head back
-                            prepend_gcode += "G1 Z%f F300\n" % (1 + current_z)
-                            prepend_gcode +="G1 X%f Y%f F9000\n" % (x, y)
-                            if retraction_amount != 0:
-                                prepend_gcode +="G1 E%f F6000\n" % (retraction_amount)
-
-                            if current_extrusion_f != 0:
-                                prepend_gcode += self.putValue(G=1, F=current_extrusion_f) + " ; restore extrusion feedrate\n"
-                            else:
-                                Logger.log("w", "No previous feedrate found in gcode, feedrate for next layer(s) might be incorrect")
-
-                            prepend_gcode +="M82\n"
-
-                            # reset extrude value to pre pause value
-                            prepend_gcode +="G92 E%f\n" % (current_e)
-
-                            layer = prepend_gcode + layer
-
-                            # include a number of previous layers
-                            for i in range(1, redo_layers + 1):
-                                prevLayer = data[index-i]
-                                layer = prevLayer + layer
-
-                            data[index] = layer #Override the data of this layer with the modified data
-                            return data
-                        break
-        return data

+ 19 - 0
plugins/VersionUpgrade/VersionUpgrade462to47/VersionUpgrade462to47.py

@@ -97,6 +97,25 @@ class VersionUpgrade462to47(VersionUpgrade):
                 script_parser = configparser.ConfigParser(interpolation=None)
                 script_parser.optionxform = str  # type: ignore  # Don't transform the setting keys as they are case-sensitive.
                 script_parser.read_string(script_str)
+
+                # Unify all Pause at Height
+                script_id = script_parser.sections()[0]
+                if script_id in ["BQ_PauseAtHeight", "PauseAtHeightRepRapFirmwareDuet", "PauseAtHeightforRepetier"]:
+                    script_settings = script_parser.items(script_id)
+                    script_settings.append(("pause_method", {
+                        "BQ_PauseAtHeight": "bq",
+                        "PauseAtHeightforRepetier": "repetier",
+                        "PauseAtHeightRepRapFirmwareDuet": "reprap"
+                    }[script_id]))
+
+                    # Since we cannot rename a section, we remove the original section and create a new section with the new script id.
+                    script_parser.remove_section(script_id)
+                    script_id = "PauseAtHeight"
+                    script_parser.add_section(script_id)
+                    for setting_tuple in script_settings:
+                        script_parser.set(script_id, setting_tuple[0], setting_tuple[1])
+
+                # Update redo_layers to redo_layer
                 if "PauseAtHeight" in script_parser:
                     if "redo_layers" in script_parser["PauseAtHeight"]:
                         script_parser["PauseAtHeight"]["redo_layer"] = str(int(script_parser["PauseAtHeight"]["redo_layers"]) > 0)