mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 13:17:51 -06:00
Reduce indentation and complexity by using a pre-check
Contributes to issue CURA-7351.
This commit is contained in:
parent
cfc2cc3692
commit
d9649dc3dd
1 changed files with 29 additions and 28 deletions
|
@ -38,36 +38,37 @@ class RetractContinue(Script):
|
||||||
current_x = self.getValue(line, "X", current_x)
|
current_x = self.getValue(line, "X", current_x)
|
||||||
current_y = self.getValue(line, "Y", current_y)
|
current_y = self.getValue(line, "Y", current_y)
|
||||||
if self.getValue(line, "G") == 1:
|
if self.getValue(line, "G") == 1:
|
||||||
if self.getValue(line, "E"):
|
if not self.getValue(line, "E"): # Either None or 0: Not a retraction then.
|
||||||
new_e = self.getValue(line, "E")
|
continue
|
||||||
if new_e >= current_e: # Not a retraction.
|
new_e = self.getValue(line, "E")
|
||||||
continue
|
if new_e >= current_e: # Not a retraction.
|
||||||
# A retracted travel move may consist of multiple commands, due to combing.
|
continue
|
||||||
# This continues retracting over all of these moves and only unretracts at the end.
|
# A retracted travel move may consist of multiple commands, due to combing.
|
||||||
delta_line = 1
|
# This continues retracting over all of these moves and only unretracts at the end.
|
||||||
dx = current_x # Track the difference in X for this move only to compute the length of the travel.
|
delta_line = 1
|
||||||
dy = current_y
|
dx = current_x # Track the difference in X for this move only to compute the length of the travel.
|
||||||
while line_number + delta_line < len(lines) and self.getValue(lines[line_number + delta_line], "G") != 1:
|
dy = current_y
|
||||||
travel_move = lines[line_number + delta_line]
|
while line_number + delta_line < len(lines) and self.getValue(lines[line_number + delta_line], "G") != 1:
|
||||||
if self.getValue(travel_move, "G") != 0:
|
travel_move = lines[line_number + delta_line]
|
||||||
delta_line += 1
|
if self.getValue(travel_move, "G") != 0:
|
||||||
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
|
|
||||||
|
|
||||||
delta_line += 1
|
delta_line += 1
|
||||||
dx = travel_x
|
continue
|
||||||
dy = travel_y
|
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)
|
new_layer = "\n".join(lines)
|
||||||
data[layer_number] = new_layer
|
data[layer_number] = new_layer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue