From 9b06983f3e473c1d07c292116c7b5aeee8f1a5fa Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 16 Mar 2017 15:27:48 +0100 Subject: [PATCH 1/5] GCode reader: Better layerheight guess, refactoring, more robust, take extruder offset into account of multi extrusion. CURA-3390 --- plugins/GCodeReader/GCodeReader.py | 108 ++++++++++++++++------------- 1 file changed, 61 insertions(+), 47 deletions(-) diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 9413d06bf5..155fe231e2 100755 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -19,6 +19,7 @@ from cura import LayerDataBuilder from cura import LayerDataDecorator from cura.LayerPolygon import LayerPolygon from cura.GCodeListDecorator import GCodeListDecorator +from cura.Settings.ExtruderManager import ExtruderManager import numpy import math @@ -40,7 +41,9 @@ class GCodeReader(MeshReader): self._clearValues() self._scene_node = None self._position = namedtuple('Position', ['x', 'y', 'z', 'e']) - self._is_layers_in_file = False + self._is_layers_in_file = False # Does the Gcode have the layers comment? + self._extruder_offsets = {} # Offsets for multi extruders. key is index, value is [x-offset, y-offset] + self._current_layer_thickness = 0.2 # default Preferences.getInstance().addPreference("gcodereader/show_caution", True) @@ -90,19 +93,21 @@ class GCodeReader(MeshReader): def _getNullBoundingBox(): return AxisAlignedBox(minimum=Vector(0, 0, 0), maximum=Vector(10, 10, 10)) - def _createPolygon(self, current_z, path, nozzle_offset_x = 0, nozzle_offset_y = 0): + def _createPolygon(self, layer_thickness, path, extruder_offsets): countvalid = 0 for point in path: if point[3] > 0: countvalid += 1 + if countvalid >= 2: + # we know what to do now, no need to count further + continue if countvalid < 2: return False try: self._layer_data_builder.addLayer(self._layer_number) self._layer_data_builder.setLayerHeight(self._layer_number, path[0][2]) - self._layer_data_builder.setLayerThickness(self._layer_number, math.fabs(current_z - self._previous_z)) + self._layer_data_builder.setLayerThickness(self._layer_number, layer_thickness) this_layer = self._layer_data_builder.getLayer(self._layer_number) - layer_thickness = math.fabs(self._previous_z - current_z) # TODO: use this value except ValueError: return False count = len(path) @@ -110,19 +115,16 @@ class GCodeReader(MeshReader): line_widths = numpy.empty((count - 1, 1), numpy.float32) line_thicknesses = numpy.empty((count - 1, 1), numpy.float32) # TODO: need to calculate actual line width based on E values - line_widths[:, 0] = 0.4 - # TODO: need to calculate actual line heights - line_thicknesses[:, 0] = 0.2 + line_widths[:, 0] = 0.35 # Just a guess + line_thicknesses[:, 0] = layer_thickness points = numpy.empty((count, 3), numpy.float32) i = 0 for point in path: - points[i, 0] = point[0] - points[i, 1] = point[2] - points[i, 2] = -point[1] + points[i, :] = [point[0] + extruder_offsets[0], point[2], -point[1] - extruder_offsets[1]] if i > 0: line_types[i - 1] = point[3] if point[3] in [LayerPolygon.MoveCombingType, LayerPolygon.MoveRetractionType]: - line_widths[i - 1] = 0.2 + line_widths[i - 1] = 0.1 i += 1 this_poly = LayerPolygon(self._extruder_number, line_types, points, line_widths, line_thicknesses) @@ -135,13 +137,7 @@ class GCodeReader(MeshReader): x, y, z, e = position x = params.x if params.x is not None else x y = params.y if params.y is not None else y - z_changed = False - - if params.z is not None: - if z != params.z: - z_changed = True - self._previous_z = z - z = params.z + z = params.z if params.z is not None else position.z if params.e is not None: if params.e > e[self._extruder_number]: @@ -149,18 +145,16 @@ class GCodeReader(MeshReader): else: path.append([x, y, z, LayerPolygon.MoveRetractionType]) # retraction e[self._extruder_number] = params.e + + # Only when extruding we can determine the latest known "layer height" which is the difference in height between extrusions + # Also, 1.5 is a heuristic for any priming or whatsoever, we skip those. + if z > self._previous_z and (z - self._previous_z < 1.5): + self._current_layer_thickness = z - self._previous_z + 0.05 # allow a tiny overlap + self._previous_z = z + Logger.log("d", "Layer thickness recalculated: %s" % self._current_layer_thickness) else: path.append([x, y, z, LayerPolygon.MoveCombingType]) - if z_changed: - if not self._is_layers_in_file: - if len(path) > 1 and z > 0: - if self._createPolygon(z, path): - self._layer_number += 1 - path.clear() - else: - path.clear() - return self._position(x, y, z, e) # G0 and G1 should be handled exactly the same. @@ -192,7 +186,9 @@ class GCodeReader(MeshReader): s = line.upper().split(" ") x, y, z, e = None, None, None, None for item in s[1:]: - if not item: + if len(item) <= 1: + continue + if item.startswith(";"): continue if item[0] == "X": x = float(item[1:]) @@ -212,18 +208,20 @@ class GCodeReader(MeshReader): self._extruder_number = T if self._extruder_number + 1 > len(position.e): position.e.extend([0] * (self._extruder_number - len(position.e) + 1)) - if not self._is_layers_in_file: - if len(path) > 1 and position[2] > 0: - if self._createPolygon(position[2], path): - self._layer_number += 1 - path.clear() - else: - path.clear() return position _type_keyword = ";TYPE:" _layer_keyword = ";LAYER:" + ## For showing correct x, y offsets for each extruder + def _extruderOffsets(self): + result = {} + for extruder in ExtruderManager.getInstance().getExtruderStacks(): + result[int(extruder.getMetaData().get("position", "0"))] = [ + extruder.getProperty("machine_nozzle_offset_x", "value"), + extruder.getProperty("machine_nozzle_offset_y", "value")] + return result + def read(self, file_name): Logger.log("d", "Preparing to load %s" % file_name) self._cancelled = False @@ -238,6 +236,9 @@ class GCodeReader(MeshReader): Logger.log("d", "Opening file %s" % file_name) + self._extruder_offsets = self._extruderOffsets() # dict with index the extruder number. can be empty + + last_z = 0 with open(file_name, "r") as file: file_lines = 0 current_line = 0 @@ -256,7 +257,7 @@ class GCodeReader(MeshReader): self._message.setProgress(0) self._message.show() - Logger.log("d", "Parsing %s" % file_name) + Logger.log("d", "Parsing %s..." % file_name) current_position = self._position(0, 0, 0, [0]) current_path = [] @@ -266,6 +267,8 @@ class GCodeReader(MeshReader): Logger.log("d", "Parsing %s cancelled" % file_name) return None current_line += 1 + last_z = current_position.z + if current_line % file_step == 0: self._message.setProgress(math.floor(current_line / file_lines * 100)) Job.yieldThread() @@ -292,31 +295,42 @@ class GCodeReader(MeshReader): if self._is_layers_in_file and line[:len(self._layer_keyword)] == self._layer_keyword: try: layer_number = int(line[len(self._layer_keyword):]) - self._createPolygon(current_position[2], current_path) + self._createPolygon(self._current_layer_thickness, current_path, self._extruder_offsets.get(self._extruder_number, [0, 0])) current_path.clear() self._layer_number = layer_number except: pass - # This line is a comment. Ignore it. + # This line is a comment. Ignore it (except for the layer_keyword) if line.startswith(";"): continue G = self._getInt(line, "G") if G is not None: current_position = self._processGCode(G, line, current_position, current_path) + # < 2 is a heuristic for a movement only, that should not be counted as a layer + if current_position.z > last_z and abs(current_position.z - last_z) < 2: + if self._createPolygon(self._current_layer_thickness, current_path, self._extruder_offsets.get(self._extruder_number, [0, 0])): + current_path.clear() - T = self._getInt(line, "T") - if T is not None: - current_position = self._processTCode(T, line, current_position, current_path) - if self._createPolygon(current_position[2], current_path): - self._layer_number += 1 - current_path.clear() + if not self._is_layers_in_file: + self._layer_number += 1 - if not self._is_layers_in_file and len(current_path) > 1 and current_position[2] > 0: - if self._createPolygon(current_position[2], current_path): + continue + + if line.startswith("T"): + T = self._getInt(line, "T") + if T is not None: + self._createPolygon(self._current_layer_thickness, current_path, self._extruder_offsets.get(self._extruder_number, [0, 0])) + current_path.clear() + + current_position = self._processTCode(T, line, current_position, current_path) + + # "Flush" leftovers + if not self._is_layers_in_file and len(current_path) > 1: + if self._createPolygon(self._current_layer_thickness, current_path, self._extruder_offsets.get(self._extruder_number, [0, 0])): self._layer_number += 1 - current_path.clear() + current_path.clear() material_color_map = numpy.zeros((10, 4), dtype = numpy.float32) material_color_map[0, :] = [0.0, 0.7, 0.9, 1.0] From 6194ffa27ba2a39ccbb620fa3a422c50ab347677 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 16 Mar 2017 15:28:57 +0100 Subject: [PATCH 2/5] Removed comment. CURA-3390 --- plugins/GCodeReader/GCodeReader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/GCodeReader/GCodeReader.py b/plugins/GCodeReader/GCodeReader.py index 155fe231e2..15494f3712 100755 --- a/plugins/GCodeReader/GCodeReader.py +++ b/plugins/GCodeReader/GCodeReader.py @@ -151,7 +151,6 @@ class GCodeReader(MeshReader): if z > self._previous_z and (z - self._previous_z < 1.5): self._current_layer_thickness = z - self._previous_z + 0.05 # allow a tiny overlap self._previous_z = z - Logger.log("d", "Layer thickness recalculated: %s" % self._current_layer_thickness) else: path.append([x, y, z, LayerPolygon.MoveCombingType]) From aa691033e07dbc2b792dbe9c3b8e513e267835d3 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 16 Mar 2017 16:01:18 +0100 Subject: [PATCH 3/5] Added Not Supported profiles for incompatible materials. CURA-3510 --- .../um3_aa0.8_PVA_Not_Supported_Quality.inst.cfg | 13 +++++++++++++ .../um3_bb0.8_ABS_Not_Supported_Quality.inst.cfg | 13 +++++++++++++ .../um3_bb0.8_CPE_Not_Supported_Quality.inst.cfg | 13 +++++++++++++ .../um3_bb0.8_Nylon_Not_Supported_Quality.inst.cfg | 13 +++++++++++++ .../um3_bb0.8_PLA_Not_Supported_Quality.inst.cfg | 13 +++++++++++++ 5 files changed, 65 insertions(+) create mode 100755 resources/quality/ultimaker3/um3_aa0.8_PVA_Not_Supported_Quality.inst.cfg create mode 100755 resources/quality/ultimaker3/um3_bb0.8_ABS_Not_Supported_Quality.inst.cfg create mode 100755 resources/quality/ultimaker3/um3_bb0.8_CPE_Not_Supported_Quality.inst.cfg create mode 100755 resources/quality/ultimaker3/um3_bb0.8_Nylon_Not_Supported_Quality.inst.cfg create mode 100755 resources/quality/ultimaker3/um3_bb0.8_PLA_Not_Supported_Quality.inst.cfg diff --git a/resources/quality/ultimaker3/um3_aa0.8_PVA_Not_Supported_Quality.inst.cfg b/resources/quality/ultimaker3/um3_aa0.8_PVA_Not_Supported_Quality.inst.cfg new file mode 100755 index 0000000000..c0b5074799 --- /dev/null +++ b/resources/quality/ultimaker3/um3_aa0.8_PVA_Not_Supported_Quality.inst.cfg @@ -0,0 +1,13 @@ +[general] +version = 2 +name = Not Supported +definition = ultimaker3 + +[metadata] +weight = 0 +type = quality +quality_type = normal +material = generic_pva_ultimaker3_AA_0.8 +supported = false + +[values] diff --git a/resources/quality/ultimaker3/um3_bb0.8_ABS_Not_Supported_Quality.inst.cfg b/resources/quality/ultimaker3/um3_bb0.8_ABS_Not_Supported_Quality.inst.cfg new file mode 100755 index 0000000000..ab20d984b6 --- /dev/null +++ b/resources/quality/ultimaker3/um3_bb0.8_ABS_Not_Supported_Quality.inst.cfg @@ -0,0 +1,13 @@ +[general] +version = 2 +name = Not Supported +definition = ultimaker3 + +[metadata] +type = quality +quality_type = normal +material = generic_abs_ultimaker3_BB_0.8 +weight = 0 +supported = false + +[values] diff --git a/resources/quality/ultimaker3/um3_bb0.8_CPE_Not_Supported_Quality.inst.cfg b/resources/quality/ultimaker3/um3_bb0.8_CPE_Not_Supported_Quality.inst.cfg new file mode 100755 index 0000000000..02ea97395c --- /dev/null +++ b/resources/quality/ultimaker3/um3_bb0.8_CPE_Not_Supported_Quality.inst.cfg @@ -0,0 +1,13 @@ +[general] +version = 2 +name = Not Supported +definition = ultimaker3 + +[metadata] +type = quality +quality_type = normal +material = generic_cpe_ultimaker3_BB_0.8 +weight = 0 +supported = false + +[values] diff --git a/resources/quality/ultimaker3/um3_bb0.8_Nylon_Not_Supported_Quality.inst.cfg b/resources/quality/ultimaker3/um3_bb0.8_Nylon_Not_Supported_Quality.inst.cfg new file mode 100755 index 0000000000..4280213689 --- /dev/null +++ b/resources/quality/ultimaker3/um3_bb0.8_Nylon_Not_Supported_Quality.inst.cfg @@ -0,0 +1,13 @@ +[general] +version = 2 +name = Not Supported +definition = ultimaker3 + +[metadata] +type = quality +quality_type = normal +material = generic_nylon_ultimaker3_BB_0.8 +weight = 0 +supported = false + +[values] diff --git a/resources/quality/ultimaker3/um3_bb0.8_PLA_Not_Supported_Quality.inst.cfg b/resources/quality/ultimaker3/um3_bb0.8_PLA_Not_Supported_Quality.inst.cfg new file mode 100755 index 0000000000..d27d6a8174 --- /dev/null +++ b/resources/quality/ultimaker3/um3_bb0.8_PLA_Not_Supported_Quality.inst.cfg @@ -0,0 +1,13 @@ +[general] +version = 2 +name = Not Supported +definition = ultimaker3 + +[metadata] +type = quality +quality_type = normal +material = generic_pla_ultimaker3_BB_0.8 +weight = 0 +supported = false + +[values] From 7d62a699fbb32cb5dd947912b3cc7b915705ef08 Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Thu, 16 Mar 2017 16:04:47 +0100 Subject: [PATCH 4/5] Capitalize Not Supported. CURA-3390 --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 301dff3d20..6fcd0fbf4f 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -224,7 +224,7 @@ class CuraApplication(QtApplication): ContainerRegistry.getInstance().addContainer(empty_material_container) empty_quality_container = copy.deepcopy(empty_container) empty_quality_container._id = "empty_quality" - empty_quality_container.setName("Not supported") + empty_quality_container.setName("Not Supported") empty_quality_container.addMetaDataEntry("quality_type", "normal") empty_quality_container.addMetaDataEntry("type", "quality") ContainerRegistry.getInstance().addContainer(empty_quality_container) From d52515d57d32ded06b8faf345d433e00cca6ce29 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 16 Mar 2017 19:06:57 +0100 Subject: [PATCH 5/5] Added invert zoom preference option --- resources/qml/Preferences/GeneralPage.qml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/resources/qml/Preferences/GeneralPage.qml b/resources/qml/Preferences/GeneralPage.qml index 0220a605c8..00a3fdb893 100755 --- a/resources/qml/Preferences/GeneralPage.qml +++ b/resources/qml/Preferences/GeneralPage.qml @@ -45,6 +45,8 @@ UM.PreferencesPage showOverhangCheckbox.checked = boolCheck(UM.Preferences.getValue("view/show_overhang")) UM.Preferences.resetPreference("view/center_on_select"); centerOnSelectCheckbox.checked = boolCheck(UM.Preferences.getValue("view/center_on_select")) + UM.Preferences.resetPreference("view/invert_zoom"); + invertZoomCheckbox.checked = boolCheck(UM.Preferences.getValue("view/invert_zoom")) UM.Preferences.resetPreference("view/top_layer_count"); topLayerCountCheckbox.checked = boolCheck(UM.Preferences.getValue("view/top_layer_count")) UM.Preferences.resetPreference("cura/choice_on_profile_override") @@ -232,6 +234,20 @@ UM.PreferencesPage } } + UM.TooltipArea { + width: childrenRect.width; + height: childrenRect.height; + text: catalog.i18nc("@info:tooltip","Should the default zoom behavior of cura be inverted?") + + CheckBox + { + id: invertZoomCheckbox + text: catalog.i18nc("@action:button","Invert the direction of camera zoom."); + checked: boolCheck(UM.Preferences.getValue("view/invert_zoom")) + onClicked: UM.Preferences.setValue("view/invert_zoom", checked) + } + } + UM.TooltipArea { width: childrenRect.width height: childrenRect.height