From bfa92b6b400ef257421d311d9739e964f1f69692 Mon Sep 17 00:00:00 2001 From: Simon Edwards Date: Tue, 27 Sep 2016 17:08:09 +0200 Subject: [PATCH 1/9] Correctly update the selected quality and quality changes after changing material. Contributes to CURA-2451 Changing material does not update quality profile to correct profile --- cura/Settings/MachineManager.py | 41 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 9c15d33e52..4569e51098 100644 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -539,8 +539,10 @@ class MachineManager(QObject): containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = material_id) if not containers or not self._active_container_stack: return + material_container = containers[0] + Logger.log("d", "Attempting to change the active material to %s", material_id) - old_variant = self._active_container_stack.findContainer({"type": "variant"}) + old_material = self._active_container_stack.findContainer({"type": "material"}) old_quality = self._active_container_stack.findContainer({"type": "quality"}) old_quality_changes = self._active_container_stack.findContainer({"type": "quality_changes"}) @@ -555,26 +557,37 @@ class MachineManager(QObject): old_material.nameChanged.disconnect(self._onMaterialNameChanged) material_index = self._active_container_stack.getContainerIndex(old_material) - self._active_container_stack.replaceContainer(material_index, containers[0]) + self._active_container_stack.replaceContainer(material_index, material_container) - containers[0].nameChanged.connect(self._onMaterialNameChanged) + material_container.nameChanged.connect(self._onMaterialNameChanged) - if containers[0].getMetaDataEntry("compatible") == False: + if material_container.getMetaDataEntry("compatible") == False: message = Message(catalog.i18nc("@info:status", "The selected material is imcompatible with the selected machine or configuration.")) message.show() - if old_quality: - if old_quality_changes: - new_quality = self._updateQualityChangesContainer( - old_quality.getMetaDataEntry("quality_type"), - preferred_quality_changes_name = old_quality_changes.getMetaDataEntry("name")) - else: - new_quality = self._updateQualityContainer(self._global_container_stack.getBottom(), old_variant, containers[0], old_quality.getName()) - else: - new_quality = self._updateQualityContainer(self._global_container_stack.getBottom(), old_variant, containers[0]) + new_quality_id = old_quality.getId() + quality_type = old_quality.getMetaDataEntry("quality_type") + if old_quality_changes: + quality_type = old_quality_changes.getMetaDataEntry("quality_type") + new_quality_id = old_quality_changes.getId() - self.setActiveQuality(new_quality.getId()) + # See if the requested quality type is available in the new situation. + machine_definition = self._active_container_stack.getBottom() + quality_manager = QualityManager.getInstance() + candidate_qualities = quality_manager.findQualityByQualityType(quality_type, + quality_manager.getWholeMachineDefinition(machine_definition), + [material_container]) + if not candidate_qualities: + # Fall back to normal quality + new_quality_id = quality_manager.findQualityByQualityType("normal", + quality_manager.getWholeMachineDefinition(machine_definition), + [material_container])[0].getId() + else: + if not old_quality_changes: + new_quality_id = candidate_qualities[0].getId() + + self.setActiveQuality(new_quality_id) @pyqtSlot(str) def setActiveVariant(self, variant_id): From 61477078a47ff03e16c0f358e969ff6371c98fa3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 27 Sep 2016 16:56:07 +0200 Subject: [PATCH 2/9] Raise exception when encountering unknown build adhesion type This is to warn future programmers when they add new build adhesion types. Contributes to issue CURA-2407. --- cura/ConvexHullDecorator.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index 4397251b6e..c87f972e9e 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -1,3 +1,6 @@ +# Copyright (c) 2016 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + from UM.Scene.SceneNodeDecorator import SceneNodeDecorator from UM.Application import Application from cura.Settings.ExtruderManager import ExtruderManager @@ -238,6 +241,8 @@ class ConvexHullDecorator(SceneNodeDecorator): extra_margin = max( 0, self._getSettingProperty("skirt_gap", "value") + self._getSettingPropertyy("skirt_line_count", "value") * self._getSettingProperty("skirt_brim_line_width", "value")) + else: + raise Exception("Unknown bed adhesion type. Did you forget to update the convex hull calculations for your new bed adhesion type?") # adjust head_and_fans with extra margin if extra_margin > 0: From 6783b4b3ef444654ab8aa5aada0c31cac3d44ccb Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 27 Sep 2016 16:56:50 +0200 Subject: [PATCH 3/9] Fix function call to _getSettingProperty Don't know who ever tested this... Contributes to issue CURA-2407. --- cura/ConvexHullDecorator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index c87f972e9e..492acc4eaf 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -240,7 +240,7 @@ class ConvexHullDecorator(SceneNodeDecorator): elif adhesion_type == "skirt": extra_margin = max( 0, self._getSettingProperty("skirt_gap", "value") + - self._getSettingPropertyy("skirt_line_count", "value") * self._getSettingProperty("skirt_brim_line_width", "value")) + self._getSettingProperty("skirt_line_count", "value") * self._getSettingProperty("skirt_brim_line_width", "value")) else: raise Exception("Unknown bed adhesion type. Did you forget to update the convex hull calculations for your new bed adhesion type?") From dc80d50eb5bbd73ebd7258159a717adc5f657f7a Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 27 Sep 2016 16:58:14 +0200 Subject: [PATCH 4/9] Remove unused value for extra_margin Since the else clause below now raises an exception and all its if clauses define extra_margin, this initial value is now unused. Contributes to issue CURA-2407. --- cura/ConvexHullDecorator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index 492acc4eaf..dde6deb650 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -231,7 +231,6 @@ class ConvexHullDecorator(SceneNodeDecorator): # Compensate for raft/skirt/brim # Add extra margin depending on adhesion type adhesion_type = self._global_stack.getProperty("adhesion_type", "value") - extra_margin = 0 if adhesion_type == "raft": extra_margin = max(0, self._getSettingProperty("raft_margin", "value")) From 6affb801898dc6359a0325dcccd420cc339351f8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 27 Sep 2016 17:09:19 +0200 Subject: [PATCH 5/9] Expand convex hull by horizontal expansion The getSetting call doesn't seem to work at the moment, but the rest of the routine works if I replace the getSetting call with an actual value. Contributes to issue CURA-2407. --- cura/ConvexHullDecorator.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index dde6deb650..e0325103e0 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -199,9 +199,16 @@ class ConvexHullDecorator(SceneNodeDecorator): # First, calculate the normal convex hull around the points convex_hull = hull.getConvexHull() - # Then, do a Minkowski hull with a simple 1x1 quad to outset and round the normal convex hull. - # This is done because of rounding errors. - rounded_hull = convex_hull.getMinkowskiHull(Polygon(numpy.array([[-0.5, -0.5], [-0.5, 0.5], [0.5, 0.5], [0.5, -0.5]], numpy.float32))) + #Then, offset the convex hull with the horizontal expansion value, since that is always added to the mesh. + #Use a minimum of 0.5mm to outset and round the normal convex hull if there is no horizontal expansion, because of edge cases. + horizontal_expansion = max(0.5, self._getSettingProperty("xy_offset", "value")) + expansion_polygon = Polygon(numpy.array([ + [-horizontal_expansion, -horizontal_expansion], + [-horizontal_expansion, horizontal_expansion], + [horizontal_expansion, horizontal_expansion], + [horizontal_expansion, -horizontal_expansion] + ], numpy.float32)) + rounded_hull = convex_hull.getMinkowskiHull(expansion_polygon) # Store the result in the cache self._2d_convex_hull_mesh = mesh From edc6955162f85c555a0a8ea936c803e33cf3bc16 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 27 Sep 2016 17:14:41 +0200 Subject: [PATCH 6/9] Use per-mesh settings if it has them For platform adhesion offset and that sort of thing, we now also listen to per mesh settings. It isn't yet re-computed when changing per-mesh settings though. I'm going to look how to do that next. Contributes to issue CURA-2407. --- cura/ConvexHullDecorator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index e0325103e0..97cd24d04d 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -296,6 +296,10 @@ class ConvexHullDecorator(SceneNodeDecorator): ## Private convenience function to get a setting from the correct extruder (as defined by limit_to_extruder property). def _getSettingProperty(self, setting_key, property="value"): + per_mesh_stack = self._node.callDecoration("getStack") + if per_mesh_stack: + return per_mesh_stack.getProperty(setting_key, property) + multi_extrusion = self._global_stack.getProperty("machine_extruder_count", "value") > 1 if not multi_extrusion: From 2721cde6f0e90329b0ac65ed3db836a30c8cfad8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 27 Sep 2016 17:30:26 +0200 Subject: [PATCH 7/9] Fix _getSettingProperty up Seems to work again now. Contributes to issue CURA-2407. --- cura/ConvexHullDecorator.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index 97cd24d04d..3995c35941 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -301,17 +301,20 @@ class ConvexHullDecorator(SceneNodeDecorator): return per_mesh_stack.getProperty(setting_key, property) multi_extrusion = self._global_stack.getProperty("machine_extruder_count", "value") > 1 - if not multi_extrusion: return self._global_stack.getProperty(setting_key, property) extruder_index = self._global_stack.getProperty(setting_key, "limit_to_extruder") - if extruder_index == "-1": # If extruder index is -1 use global instead - return self._global_stack.getProperty(setting_key, property) - - extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)] - stack = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id=extruder_stack_id)[0] - return stack.getProperty(setting_key, property) + if extruder_index == "-1": # If extruder index is -1 use the object's extruder instead. + extruder_stack_id = self._node.callDecoration("getActiveExtruder") + if not extruder_stack_id: #Decoration doesn't exist. + extruder_stack_id = ExtruderManager.getInstance().extruderIds["0"] + extruder_stack = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0] + return extruder_stack.getProperty(setting_key, property) + else: #Limit_to_extruder is set. Use that one. + extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)] + stack = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0] + return stack.getProperty(setting_key, property) ## Returns true if node is a descendent or the same as the root node. def __isDescendant(self, root, node): From 2bdb388ad57877b2fca412185758cfd20a18bda6 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 27 Sep 2016 17:31:43 +0200 Subject: [PATCH 8/9] Improve documentation This makes it more clear when that variable is -1. Contributes to issue CURA-2407. --- cura/ConvexHullDecorator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/ConvexHullDecorator.py b/cura/ConvexHullDecorator.py index 3995c35941..d1f3f07c4b 100644 --- a/cura/ConvexHullDecorator.py +++ b/cura/ConvexHullDecorator.py @@ -305,7 +305,7 @@ class ConvexHullDecorator(SceneNodeDecorator): return self._global_stack.getProperty(setting_key, property) extruder_index = self._global_stack.getProperty(setting_key, "limit_to_extruder") - if extruder_index == "-1": # If extruder index is -1 use the object's extruder instead. + if extruder_index == "-1": #No limit_to_extruder. extruder_stack_id = self._node.callDecoration("getActiveExtruder") if not extruder_stack_id: #Decoration doesn't exist. extruder_stack_id = ExtruderManager.getInstance().extruderIds["0"] From 99f53cb8322e07f1ff94195e44ecbcde0b82e841 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 28 Sep 2016 09:36:06 +0200 Subject: [PATCH 9/9] Early cop-out if there is no printer connected This indeterminate state is never visible, since showProgress is false then, but it might prevent some error message behind the scenes. Contributes to issue CURA-2060. --- resources/qml/MonitorButton.qml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/qml/MonitorButton.qml b/resources/qml/MonitorButton.qml index 607d0a24ca..83d8b4bfc9 100644 --- a/resources/qml/MonitorButton.qml +++ b/resources/qml/MonitorButton.qml @@ -161,6 +161,10 @@ Rectangle visible: showProgress; indeterminate: { + if (!printerConnected) + { + return true; + } switch(Cura.MachineManager.printerOutputDevices[0].jobState) { case "pausing":