From cfc2cc36929daba962cac42a2bf8ff803b4990ba Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 8 Apr 2020 17:14:58 +0200 Subject: [PATCH 1/4] Fix crash when printer definition could not be found --- cura/Settings/MachineManager.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index aa7c15e28b..36e6c2631f 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -1254,7 +1254,11 @@ class MachineManager(QObject): return Logger.log("i", "Attempting to switch the printer type to [%s]", machine_name) # Get the definition id corresponding to this machine name - machine_definition_id = CuraContainerRegistry.getInstance().findDefinitionContainers(name = machine_name)[0].getId() + definitions = CuraContainerRegistry.getInstance().findDefinitionContainers(name=machine_name) + if not definitions: + Logger.log("e", "Unable to switch printer type since it could not be found!") + return + machine_definition_id = definitions[0].getId() # Try to find a machine with the same network key metadata_filter = {"group_id": self._global_container_stack.getMetaDataEntry("group_id")} new_machine = self.getMachine(machine_definition_id, metadata_filter = metadata_filter) From d9649dc3ddd7e055bc936030ae5f9ddc4b20bc7b Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 9 Apr 2020 11:03:10 +0200 Subject: [PATCH 2/4] Reduce indentation and complexity by using a pre-check Contributes to issue CURA-7351. --- .../scripts/RetractContinue.py | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/plugins/PostProcessingPlugin/scripts/RetractContinue.py b/plugins/PostProcessingPlugin/scripts/RetractContinue.py index b0af9cd95e..315d8edf1a 100644 --- a/plugins/PostProcessingPlugin/scripts/RetractContinue.py +++ b/plugins/PostProcessingPlugin/scripts/RetractContinue.py @@ -38,36 +38,37 @@ class RetractContinue(Script): current_x = self.getValue(line, "X", current_x) current_y = self.getValue(line, "Y", current_y) if self.getValue(line, "G") == 1: - if self.getValue(line, "E"): - new_e = self.getValue(line, "E") - if new_e >= current_e: # Not a retraction. - continue - # A retracted travel move may consist of multiple commands, due to combing. - # This continues retracting over all of these moves and only unretracts at the end. - delta_line = 1 - dx = current_x # Track the difference in X for this move only to compute the length of the travel. - dy = current_y - while line_number + delta_line < len(lines) and self.getValue(lines[line_number + delta_line], "G") != 1: - travel_move = lines[line_number + delta_line] - if self.getValue(travel_move, "G") != 0: - delta_line += 1 - continue - travel_x = self.getValue(travel_move, "X", dx) - travel_y = self.getValue(travel_move, "Y", dy) - f = self.getValue(travel_move, "F", "no f") - length = math.sqrt((travel_x - dx) * (travel_x - dx) + (travel_y - dy) * (travel_y - dy)) # Length of the travel move. - new_e -= length * extra_retraction_speed # New retraction is by ratio of this travel move. - if f == "no f": - new_travel_move = "G1 X{travel_x} Y{travel_y} E{new_e}".format(travel_x = travel_x, travel_y = travel_y, new_e = new_e) - else: - new_travel_move = "G1 F{f} X{travel_x} Y{travel_y} E{new_e}".format(f = f, travel_x = travel_x, travel_y = travel_y, new_e = new_e) - lines[line_number + delta_line] = new_travel_move - + if not self.getValue(line, "E"): # Either None or 0: Not a retraction then. + continue + new_e = self.getValue(line, "E") + if new_e >= current_e: # Not a retraction. + continue + # A retracted travel move may consist of multiple commands, due to combing. + # This continues retracting over all of these moves and only unretracts at the end. + delta_line = 1 + dx = current_x # Track the difference in X for this move only to compute the length of the travel. + dy = current_y + while line_number + delta_line < len(lines) and self.getValue(lines[line_number + delta_line], "G") != 1: + travel_move = lines[line_number + delta_line] + if self.getValue(travel_move, "G") != 0: delta_line += 1 - dx = travel_x - dy = travel_y + continue + travel_x = self.getValue(travel_move, "X", dx) + travel_y = self.getValue(travel_move, "Y", dy) + f = self.getValue(travel_move, "F", "no f") + length = math.sqrt((travel_x - dx) * (travel_x - dx) + (travel_y - dy) * (travel_y - dy)) # Length of the travel move. + new_e -= length * extra_retraction_speed # New retraction is by ratio of this travel move. + if f == "no f": + new_travel_move = "G1 X{travel_x} Y{travel_y} E{new_e}".format(travel_x = travel_x, travel_y = travel_y, new_e = new_e) + else: + new_travel_move = "G1 F{f} X{travel_x} Y{travel_y} E{new_e}".format(f = f, travel_x = travel_x, travel_y = travel_y, new_e = new_e) + lines[line_number + delta_line] = new_travel_move - current_e = new_e + delta_line += 1 + dx = travel_x + dy = travel_y + + current_e = new_e new_layer = "\n".join(lines) data[layer_number] = new_layer From 9b997d421b25c1bfc56be7c68ba75fd8f6902653 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 9 Apr 2020 11:22:05 +0200 Subject: [PATCH 3/4] Keep current_e updated even if not finding retractions Otherwise the new E is never going to be lower than the current E. I don't know how this ever worked then. Contributes to issue CURA-7351. --- plugins/PostProcessingPlugin/scripts/RetractContinue.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/PostProcessingPlugin/scripts/RetractContinue.py b/plugins/PostProcessingPlugin/scripts/RetractContinue.py index 315d8edf1a..aba55596b0 100644 --- a/plugins/PostProcessingPlugin/scripts/RetractContinue.py +++ b/plugins/PostProcessingPlugin/scripts/RetractContinue.py @@ -42,6 +42,7 @@ class RetractContinue(Script): continue new_e = self.getValue(line, "E") if new_e >= current_e: # Not a retraction. + current_e = new_e continue # A retracted travel move may consist of multiple commands, due to combing. # This continues retracting over all of these moves and only unretracts at the end. From d5166030d76838e4aa52c25338081468c2535195 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 9 Apr 2020 11:27:40 +0200 Subject: [PATCH 4/4] Don't detect retractions if E is almost equal, but rounding errors Contributes to issue CURA-7351. --- plugins/PostProcessingPlugin/scripts/RetractContinue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/PostProcessingPlugin/scripts/RetractContinue.py b/plugins/PostProcessingPlugin/scripts/RetractContinue.py index aba55596b0..076d55df3b 100644 --- a/plugins/PostProcessingPlugin/scripts/RetractContinue.py +++ b/plugins/PostProcessingPlugin/scripts/RetractContinue.py @@ -41,7 +41,7 @@ class RetractContinue(Script): if not self.getValue(line, "E"): # Either None or 0: Not a retraction then. continue new_e = self.getValue(line, "E") - if new_e >= current_e: # Not a retraction. + if new_e - current_e >= -0.0001: # Not a retraction. Account for floating point rounding errors. current_e = new_e continue # A retracted travel move may consist of multiple commands, due to combing.