mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
More V2 shenanigans
- Rename the start location to end purge location to match with what it represents - Added location and position enums - Rewrite the _get_adjustment_lines function as _move_to_location (generic) - Replace goto_str with a position tuple for consistency and error prevention (typo prevention)
This commit is contained in:
parent
79ec595785
commit
d80f291dc5
1 changed files with 106 additions and 93 deletions
|
@ -20,14 +20,19 @@ from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
class Location(str, Enum):
|
class Location(str, Enum):
|
||||||
LEFT_FRONT = "LF"
|
|
||||||
RIGHT_FRONT = "RF"
|
|
||||||
LEFT_REAR = "LR"
|
|
||||||
RIGHT_REAR = "RR"
|
|
||||||
LEFT = "left"
|
LEFT = "left"
|
||||||
RIGHT = "right"
|
RIGHT = "right"
|
||||||
TOP = "top"
|
TOP = "top"
|
||||||
BOTTOM = "bottom"
|
BOTTOM = "bottom"
|
||||||
|
REAR = "rear"
|
||||||
|
FRONT = "front"
|
||||||
|
|
||||||
|
|
||||||
|
class Position(tuple, Enum):
|
||||||
|
LEFT_FRONT = ("left", "front")
|
||||||
|
RIGHT_FRONT = ("right", "front")
|
||||||
|
LEFT_REAR = ("left", "rear")
|
||||||
|
RIGHT_REAR = ("right", "rear")
|
||||||
|
|
||||||
|
|
||||||
class PurgeLinesAndUnload(Script):
|
class PurgeLinesAndUnload(Script):
|
||||||
|
@ -36,7 +41,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.curaApp = Application.getInstance().getGlobalContainerStack()
|
self.curaApp = Application.getInstance().getGlobalContainerStack()
|
||||||
self.extruder = self.curaApp.extruderList
|
self.extruder = self.curaApp.extruderList
|
||||||
self.start_location = None
|
self.end_purge_location = None
|
||||||
self.speed_travel = None
|
self.speed_travel = None
|
||||||
# This will be True when there are more than 4 'machine_disallowed_areas'
|
# This will be True when there are more than 4 'machine_disallowed_areas'
|
||||||
self.show_warning = False
|
self.show_warning = False
|
||||||
|
@ -198,7 +203,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
self._get_build_plate_extents()
|
self._get_build_plate_extents()
|
||||||
self.speed_travel = self.extruder[0].getProperty("speed_travel", "value") * 60
|
self.speed_travel = self.extruder[0].getProperty("speed_travel", "value") * 60
|
||||||
# The start location changes according to which quadrant the nozzle is in at the beginning
|
# The start location changes according to which quadrant the nozzle is in at the beginning
|
||||||
self.start_location = self._get_real_start_point(data[1])
|
self.end_purge_location = self._get_real_start_point(data[1])
|
||||||
|
|
||||||
# Mapping settings to corresponding methods
|
# Mapping settings to corresponding methods
|
||||||
procedures = {
|
procedures = {
|
||||||
|
@ -224,9 +229,9 @@ class PurgeLinesAndUnload(Script):
|
||||||
Message(title="[Purge Lines and Unload]", text=msg_text).show()
|
Message(title="[Purge Lines and Unload]", text=msg_text).show()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _get_real_start_point(self, first_section: str) -> str:
|
def _get_real_start_point(self, first_section: str) -> tuple:
|
||||||
last_x, last_y = 0.0, 0.0
|
last_x, last_y = 0.0, 0.0
|
||||||
start_quadrant = Location.LEFT_FRONT
|
start_quadrant = Position.LEFT_FRONT
|
||||||
|
|
||||||
for line in first_section.split("\n"):
|
for line in first_section.split("\n"):
|
||||||
if line.startswith(";") and not line.startswith(";LAYER_COUNT") or not line:
|
if line.startswith(";") and not line.startswith(";LAYER_COUNT") or not line:
|
||||||
|
@ -244,13 +249,13 @@ class PurgeLinesAndUnload(Script):
|
||||||
self.machine_width / 2, self.machine_depth / 2)
|
self.machine_width / 2, self.machine_depth / 2)
|
||||||
|
|
||||||
if last_x <= midpoint_x and last_y <= midpoint_y:
|
if last_x <= midpoint_x and last_y <= midpoint_y:
|
||||||
start_quadrant = Location.LEFT_FRONT
|
start_quadrant = Position.LEFT_FRONT
|
||||||
elif last_x > midpoint_x and last_y <= midpoint_y:
|
elif last_x > midpoint_x and last_y <= midpoint_y:
|
||||||
start_quadrant = Location.RIGHT_FRONT
|
start_quadrant = Position.RIGHT_FRONT
|
||||||
elif last_x > midpoint_x and last_y > midpoint_y:
|
elif last_x > midpoint_x and last_y > midpoint_y:
|
||||||
start_quadrant = Location.RIGHT_REAR
|
start_quadrant = Position.RIGHT_REAR
|
||||||
elif last_x <= midpoint_x and last_y > midpoint_y:
|
elif last_x <= midpoint_x and last_y > midpoint_y:
|
||||||
start_quadrant = Location.LEFT_REAR
|
start_quadrant = Position.LEFT_REAR
|
||||||
|
|
||||||
return start_quadrant
|
return start_quadrant
|
||||||
|
|
||||||
|
@ -270,16 +275,16 @@ class PurgeLinesAndUnload(Script):
|
||||||
prime_tower_y = self.curaApp.getProperty("prime_tower_position_y", "value")
|
prime_tower_y = self.curaApp.getProperty("prime_tower_position_y", "value")
|
||||||
prime_tower_loc = self._prime_tower_quadrant(prime_tower_x, prime_tower_y)
|
prime_tower_loc = self._prime_tower_quadrant(prime_tower_x, prime_tower_y)
|
||||||
# Shortstop an error if Start Location comes through as None
|
# Shortstop an error if Start Location comes through as None
|
||||||
if self.start_location is None:
|
if self.end_purge_location is None:
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
if prime_tower_loc != self.start_location:
|
if prime_tower_loc != self.end_purge_location:
|
||||||
startup = first_section[1].split("\n")
|
startup = first_section[1].split("\n")
|
||||||
for index, line in enumerate(startup):
|
for index, line in enumerate(startup):
|
||||||
if ";LAYER_COUNT:" in line:
|
if ";LAYER_COUNT:" in line:
|
||||||
try:
|
try:
|
||||||
if startup[index + 1].startswith("G0"):
|
if startup[index + 1].startswith("G0"):
|
||||||
prime_move = startup[index + 1] + " ; Move to Prime Tower"
|
prime_move = startup[index + 1] + " ; Move to Prime Tower"
|
||||||
adjustment_lines = self._get_adjustment_lines(prime_tower_loc)
|
adjustment_lines = self._move_to_location("Prime Tower", prime_tower_loc)
|
||||||
startup[index + 1] = adjustment_lines + prime_move + "\n" + startup[index]
|
startup[index + 1] = adjustment_lines + prime_move + "\n" + startup[index]
|
||||||
startup.pop(index)
|
startup.pop(index)
|
||||||
first_section[1] = "\n".join(startup)
|
first_section[1] = "\n".join(startup)
|
||||||
|
@ -288,45 +293,70 @@ class PurgeLinesAndUnload(Script):
|
||||||
pass
|
pass
|
||||||
# The start_location changes to the prime tower location in case 'Move to Start' is enabled.
|
# The start_location changes to the prime tower location in case 'Move to Start' is enabled.
|
||||||
if move_to_prime_present:
|
if move_to_prime_present:
|
||||||
self.start_location = prime_tower_loc
|
self.end_purge_location = prime_tower_loc
|
||||||
return first_section
|
return first_section
|
||||||
|
|
||||||
# Determine the quadrant that the prime tower rests in so the orthogonal moves can be calculated
|
# Determine the quadrant that the prime tower rests in so the orthogonal moves can be calculated
|
||||||
def _prime_tower_quadrant(self, prime_tower_x: float, prime_tower_y: float) -> str:
|
def _prime_tower_quadrant(self, prime_tower_x: float, prime_tower_y: float) -> tuple:
|
||||||
midpoint_x, midpoint_y = (0.0, 0.0) if self.origin_at_center else (
|
midpoint_x, midpoint_y = (0.0, 0.0) if self.origin_at_center else (
|
||||||
self.machine_width / 2, self.machine_depth / 2)
|
self.machine_width / 2, self.machine_depth / 2)
|
||||||
|
|
||||||
if prime_tower_x < midpoint_x and prime_tower_y < midpoint_y:
|
if prime_tower_x < midpoint_x and prime_tower_y < midpoint_y:
|
||||||
return Location.LEFT_FRONT
|
return Position.LEFT_FRONT
|
||||||
elif prime_tower_x > midpoint_x and prime_tower_y < midpoint_y:
|
elif prime_tower_x > midpoint_x and prime_tower_y < midpoint_y:
|
||||||
return Location.RIGHT_FRONT
|
return Position.RIGHT_FRONT
|
||||||
elif prime_tower_x > midpoint_x and prime_tower_y > midpoint_y:
|
elif prime_tower_x > midpoint_x and prime_tower_y > midpoint_y:
|
||||||
return Location.RIGHT_REAR
|
return Position.RIGHT_REAR
|
||||||
elif prime_tower_x < midpoint_x and prime_tower_y > midpoint_y:
|
elif prime_tower_x < midpoint_x and prime_tower_y > midpoint_y:
|
||||||
return Location.LEFT_REAR
|
return Position.LEFT_REAR
|
||||||
else:
|
else:
|
||||||
return Location.LEFT_FRONT # return Default in case of no match
|
return Position.LEFT_FRONT # return Default in case of no match
|
||||||
|
|
||||||
# This puts the 'Move to Prime' tower lines together when they are required
|
def _move_to_location(self, location_name: str, location: tuple) -> str:
|
||||||
def _get_adjustment_lines(self, prime_tower_loc: str):
|
"""
|
||||||
adj_lines = ";MESH:NONMESH---------[Move to Prime Tower]"
|
Compare the input tuple (B) with the end purge location (A) and describe the move from A to B.
|
||||||
# Move commands linked to keys (Start location, Prime tower location)
|
|
||||||
move_commands = {
|
|
||||||
(Location.LEFT_FRONT, Location.RIGHT_FRONT): f"G0 F{self.speed_travel} X{self.machine_right}",
|
|
||||||
(Location.LEFT_FRONT, Location.RIGHT_REAR): f"G0 F{self.speed_travel} X{self.machine_right}",
|
|
||||||
(Location.LEFT_FRONT, Location.LEFT_REAR): f"G0 F{self.speed_travel} Y{self.machine_back}",
|
|
||||||
(Location.RIGHT_REAR, Location.LEFT_FRONT): f"G0 F{self.speed_travel} X{self.machine_left}",
|
|
||||||
(Location.RIGHT_REAR, Location.RIGHT_FRONT): f"G0 F{self.speed_travel} Y{self.machine_front}",
|
|
||||||
(Location.RIGHT_REAR, Location.LEFT_REAR): f"G0 F{self.speed_travel} X{self.machine_left}"
|
|
||||||
}
|
|
||||||
|
|
||||||
key = (self.start_location, prime_tower_loc)
|
Parameters:
|
||||||
if key in move_commands:
|
location_name (str): A descriptive name for the target location.
|
||||||
adj_lines += f"\n{move_commands[key]} ; Start move"
|
location (tuple): The target tuple (e.g., ("right", "front")).
|
||||||
adj_lines += "\nG0 F600 Z0 ; Nail down the string"
|
|
||||||
adj_lines += "\nG0 F600 Z2 ; Move up"
|
|
||||||
|
|
||||||
return adj_lines
|
Returns:
|
||||||
|
str: G-code for the move from A to B or an empty string if no move is required.
|
||||||
|
"""
|
||||||
|
# Validate input
|
||||||
|
if len(self.end_purge_location) != 2 or len(location) != 2:
|
||||||
|
raise ValueError("Both locations must be tuples of length 2.")
|
||||||
|
|
||||||
|
# Extract components
|
||||||
|
start_side, start_depth = self.end_purge_location
|
||||||
|
target_side, target_depth = location
|
||||||
|
|
||||||
|
moves = [f";MESH:NONMESH---------[Move to {location_name}]\n G0 F600 Z2 ; Move up\n"]
|
||||||
|
|
||||||
|
# Helper function to add G-code for moves
|
||||||
|
def add_move(axis: str, position: float) -> None:
|
||||||
|
moves.append(
|
||||||
|
f"G0 F{self.speed_travel} {axis}{position} ; Start move\n"
|
||||||
|
f"G0 F600 Z0 ; Nail down the string\n"
|
||||||
|
f"G0 F600 Z2 ; Move up\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Compare sides
|
||||||
|
if start_side != target_side:
|
||||||
|
if target_side == Location.RIGHT:
|
||||||
|
add_move("X", self.machine_right)
|
||||||
|
else:
|
||||||
|
add_move("X", self.machine_left)
|
||||||
|
|
||||||
|
# Compare positions
|
||||||
|
if start_depth != target_depth:
|
||||||
|
if target_depth == Location.REAR:
|
||||||
|
add_move("Y", self.machine_back)
|
||||||
|
else:
|
||||||
|
add_move("Y", self.machine_front)
|
||||||
|
|
||||||
|
# Combine moves into a single G-code string or return empty if no movement is needed
|
||||||
|
return "".join(moves) if len(moves) > 1 else f";----------[Already at {location_name}, No Moves necessary]\n"
|
||||||
|
|
||||||
def _get_build_plate_extents(self):
|
def _get_build_plate_extents(self):
|
||||||
# Machine disallowed areas can be ordered at the whim of the definition author and cannot be counted on when parsed
|
# Machine disallowed areas can be ordered at the whim of the definition author and cannot be counted on when parsed
|
||||||
|
@ -415,7 +445,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_left + 3} Y{self.machine_front + 20} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_left + 3} Y{self.machine_front + 20} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 X{self.machine_left + 3} Y{self.machine_front + 35} ; Wipe\n"
|
purge_str += f"G0 X{self.machine_left + 3} Y{self.machine_front + 35} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
elif where_at == Location.RIGHT:
|
elif where_at == Location.RIGHT:
|
||||||
purge_len = int(self.machine_depth - 20) if purge_extrusion_full else int(
|
purge_len = int(self.machine_depth - 20) if purge_extrusion_full else int(
|
||||||
(self.machine_back - self.machine_front) / 2)
|
(self.machine_back - self.machine_front) / 2)
|
||||||
|
@ -437,7 +467,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_right - 3} Y{self.machine_back - 20} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_right - 3} Y{self.machine_back - 20} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 X{self.machine_right - 3} Y{self.machine_back - 35} ; Wipe\n"
|
purge_str += f"G0 X{self.machine_right - 3} Y{self.machine_back - 35} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.RIGHT_REAR
|
self.end_purge_location = Position.RIGHT_REAR
|
||||||
elif where_at == Location.BOTTOM:
|
elif where_at == Location.BOTTOM:
|
||||||
purge_len = int(self.machine_width) - 20 if purge_extrusion_full else int(
|
purge_len = int(self.machine_width) - 20 if purge_extrusion_full else int(
|
||||||
(self.machine_right - self.machine_left) / 2)
|
(self.machine_right - self.machine_left) / 2)
|
||||||
|
@ -459,7 +489,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_left + 20} Y{self.machine_front + 3} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_left + 20} Y{self.machine_front + 3} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 X{self.machine_left + 35} Y{self.machine_front + 3} ; Wipe\n"
|
purge_str += f"G0 X{self.machine_left + 35} Y{self.machine_front + 3} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
elif where_at == Location.TOP:
|
elif where_at == Location.TOP:
|
||||||
purge_len = int(self.machine_width - 20) if purge_extrusion_full else int(
|
purge_len = int(self.machine_width - 20) if purge_extrusion_full else int(
|
||||||
(self.machine_right - self.machine_left) / 2)
|
(self.machine_right - self.machine_left) / 2)
|
||||||
|
@ -482,7 +512,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_right - 20} Y{self.machine_back - 3} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_right - 20} Y{self.machine_back - 3} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 X{self.machine_right - 35} Y{self.machine_back - 3} ; Wipe\n"
|
purge_str += f"G0 X{self.machine_right - 35} Y{self.machine_back - 3} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.RIGHT_REAR
|
self.end_purge_location = Position.RIGHT_REAR
|
||||||
# Some cartesian printers (BIBO, Weedo, MethodX, etc.) are Origin at Center
|
# Some cartesian printers (BIBO, Weedo, MethodX, etc.) are Origin at Center
|
||||||
elif self.bed_shape == "rectangular" and self.origin_at_center:
|
elif self.bed_shape == "rectangular" and self.origin_at_center:
|
||||||
if where_at == Location.LEFT:
|
if where_at == Location.LEFT:
|
||||||
|
@ -504,7 +534,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_left + 3} Y{self.machine_front + 20} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_left + 3} Y{self.machine_front + 20} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 X{self.machine_left + 3} Y{self.machine_front + 35} ; Wipe\n"
|
purge_str += f"G0 X{self.machine_left + 3} Y{self.machine_front + 35} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
elif where_at == Location.RIGHT:
|
elif where_at == Location.RIGHT:
|
||||||
purge_len = int(self.machine_back - 20) if purge_extrusion_full else int(
|
purge_len = int(self.machine_back - 20) if purge_extrusion_full else int(
|
||||||
(self.machine_back - self.machine_front) / 2)
|
(self.machine_back - self.machine_front) / 2)
|
||||||
|
@ -524,7 +554,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_right - 3} Y{self.machine_back - 20} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_right - 3} Y{self.machine_back - 20} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 F{self.speed_travel} X{self.machine_right - 3} Y{self.machine_back - 35} ; Wipe\n"
|
purge_str += f"G0 F{self.speed_travel} X{self.machine_right - 3} Y{self.machine_back - 35} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.RIGHT_REAR
|
self.end_purge_location = Position.RIGHT_REAR
|
||||||
elif where_at == Location.BOTTOM:
|
elif where_at == Location.BOTTOM:
|
||||||
purge_len = int(self.machine_right - self.machine_left - 20) if purge_extrusion_full else int(
|
purge_len = int(self.machine_right - self.machine_left - 20) if purge_extrusion_full else int(
|
||||||
(self.machine_right - self.machine_left) / 2)
|
(self.machine_right - self.machine_left) / 2)
|
||||||
|
@ -544,7 +574,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_left + 20} Y{self.machine_front + 3} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_left + 20} Y{self.machine_front + 3} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_left + 35} Y{self.machine_front + 3} ; Wipe\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_left + 35} Y{self.machine_front + 3} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
elif where_at == Location.TOP:
|
elif where_at == Location.TOP:
|
||||||
purge_len = int(self.machine_right - self.machine_left - 20) if purge_extrusion_full else abs(
|
purge_len = int(self.machine_right - self.machine_left - 20) if purge_extrusion_full else abs(
|
||||||
int(self.machine_right - 10))
|
int(self.machine_right - 10))
|
||||||
|
@ -565,7 +595,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_right - 20} Y{self.machine_back - 3} Z0.3 ; Slide over and down\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_right - 20} Y{self.machine_back - 3} Z0.3 ; Slide over and down\n"
|
||||||
purge_str += f"G0 F{print_speed} X{self.machine_right - 35} Y{self.machine_back - 3} ; Wipe\n"
|
purge_str += f"G0 F{print_speed} X{self.machine_right - 35} Y{self.machine_back - 3} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.RIGHT_REAR
|
self.end_purge_location = Position.RIGHT_REAR
|
||||||
# Elliptic printers with Origin at Center
|
# Elliptic printers with Origin at Center
|
||||||
elif self.bed_shape == "elliptic":
|
elif self.bed_shape == "elliptic":
|
||||||
if where_at in [Location.LEFT, Location.RIGHT]:
|
if where_at in [Location.LEFT, Location.RIGHT]:
|
||||||
|
@ -592,7 +622,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X-{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
purge_str += f"G0 F{print_speed} X-{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
||||||
purge_str += f"G0 F{print_speed} X-{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
purge_str += f"G0 F{print_speed} X-{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
elif where_at == Location.RIGHT:
|
elif where_at == Location.RIGHT:
|
||||||
# Travel to the purge start
|
# Travel to the purge start
|
||||||
purge_str += f"G0 F{self.speed_travel} X{round(radius_1 * .707, 2)} Y-{round(radius_1 * .707, 2)} ; Travel\n"
|
purge_str += f"G0 F{self.speed_travel} X{round(radius_1 * .707, 2)} Y-{round(radius_1 * .707, 2)} ; Travel\n"
|
||||||
|
@ -609,7 +639,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
purge_str += f"G0 F{print_speed} X{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
purge_str += f"G0 F{print_speed} X{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
||||||
purge_str += f"G0 F{print_speed} X{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
purge_str += f"G0 F{print_speed} X{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
||||||
|
|
||||||
self.start_location = Location.RIGHT_REAR
|
self.end_purge_location = Position.RIGHT_REAR
|
||||||
elif where_at == Location.BOTTOM:
|
elif where_at == Location.BOTTOM:
|
||||||
# Travel to the purge start
|
# Travel to the purge start
|
||||||
purge_str += f"G0 F{self.speed_travel} X-{round(radius_1 * .707, 2)} Y-{round(radius_1 * .707, 2)} ; Travel\n"
|
purge_str += f"G0 F{self.speed_travel} X-{round(radius_1 * .707, 2)} Y-{round(radius_1 * .707, 2)} ; Travel\n"
|
||||||
|
@ -625,7 +655,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
# Wipe
|
# Wipe
|
||||||
purge_str += f"G0 F{print_speed} Y-{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
purge_str += f"G0 F{print_speed} Y-{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
||||||
purge_str += f"G0 F{print_speed} Y-{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
purge_str += f"G0 F{print_speed} Y-{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
elif where_at == Location.TOP:
|
elif where_at == Location.TOP:
|
||||||
# Travel to the purge start
|
# Travel to the purge start
|
||||||
purge_str += f"G0 F{self.speed_travel} X{round(radius_1 * .707, 2)} Y{round(radius_1 * .707, 2)} ; Travel\n"
|
purge_str += f"G0 F{self.speed_travel} X{round(radius_1 * .707, 2)} Y{round(radius_1 * .707, 2)} ; Travel\n"
|
||||||
|
@ -641,7 +671,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
# Wipe
|
# Wipe
|
||||||
purge_str += f"G0 F{print_speed} Y{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
purge_str += f"G0 F{print_speed} Y{round((radius_1 - 3) * .707 - 15, 2)} Z0.3 ; Slide Over\n"
|
||||||
purge_str += f"G0 F{print_speed} Y{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
purge_str += f"G0 F{print_speed} Y{round((radius_1 - 3) * .707, 2)} ; Wipe\n"
|
||||||
self.start_location = Location.RIGHT_REAR
|
self.end_purge_location = Position.RIGHT_REAR
|
||||||
|
|
||||||
# Common ending for purge_str
|
# Common ending for purge_str
|
||||||
purge_str += "G0 F600 Z2 ; Move Z\n;---------------------[End of Purge]"
|
purge_str += "G0 F600 Z2 ; Move Z\n;---------------------[End of Purge]"
|
||||||
|
@ -680,6 +710,7 @@ class PurgeLinesAndUnload(Script):
|
||||||
def _move_to_start(self, data: str) -> str:
|
def _move_to_start(self, data: str) -> str:
|
||||||
start_x = None
|
start_x = None
|
||||||
start_y = None
|
start_y = None
|
||||||
|
move_str = None
|
||||||
layer = data[2].split("\n")
|
layer = data[2].split("\n")
|
||||||
for line in layer:
|
for line in layer:
|
||||||
if line.startswith("G0") and " X" in line and " Y" in line:
|
if line.startswith("G0") and " X" in line and " Y" in line:
|
||||||
|
@ -688,64 +719,46 @@ class PurgeLinesAndUnload(Script):
|
||||||
break
|
break
|
||||||
start_x = start_x or 0
|
start_x = start_x or 0
|
||||||
start_y = start_y or 0
|
start_y = start_y or 0
|
||||||
if self.start_location is None:
|
if self.end_purge_location is None:
|
||||||
self.start_location = Location.LEFT_FRONT
|
self.end_purge_location = Position.LEFT_FRONT
|
||||||
move_str = f";MESH:NONMESH---------[Travel to Layer Start]\nG0 F600 Z2 ; Move up\n"
|
|
||||||
midpoint_x = self.machine_width / 2
|
midpoint_x = self.machine_width / 2
|
||||||
midpoint_y = self.machine_depth / 2
|
midpoint_y = self.machine_depth / 2
|
||||||
if not self.origin_at_center:
|
if not self.origin_at_center:
|
||||||
if float(start_x) <= float(midpoint_x):
|
if float(start_x) <= float(midpoint_x):
|
||||||
goto_str = "Lt"
|
x_target = Location.LEFT
|
||||||
else:
|
else:
|
||||||
goto_str = "Rt"
|
x_target = Location.RIGHT
|
||||||
if float(start_y) <= float(midpoint_y):
|
if float(start_y) <= float(midpoint_y):
|
||||||
goto_str += "Frt"
|
y_target = Location.FRONT
|
||||||
else:
|
else:
|
||||||
goto_str += "Bk"
|
y_target = Location.REAR
|
||||||
else:
|
else:
|
||||||
if float(start_x) <= 0:
|
if float(start_x) <= 0:
|
||||||
goto_str = "Lt"
|
x_target = Location.LEFT
|
||||||
else:
|
else:
|
||||||
goto_str = "Rt"
|
x_target = Location.RIGHT
|
||||||
if float(start_y) <= 0:
|
if float(start_y) <= 0:
|
||||||
goto_str += "Frt"
|
y_target = Location.FRONT
|
||||||
else:
|
else:
|
||||||
goto_str += "Bk"
|
y_target = Location.REAR
|
||||||
|
target_location = (x_target, y_target)
|
||||||
if self.bed_shape == "rectangular":
|
if self.bed_shape == "rectangular":
|
||||||
if goto_str == "LtFrt":
|
move_str = self._move_to_location("Layer Start", target_location)
|
||||||
move_str += f"G0 F{self.speed_travel} X{self.machine_left + 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
move_str += f"G0 F{self.speed_travel} Y{self.machine_front + 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
elif goto_str == "RtFrt":
|
|
||||||
move_str += f"G0 F{self.speed_travel} X{self.machine_right - 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
move_str += f"G0 F{self.speed_travel} Y{self.machine_front + 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
elif goto_str == "LtBk":
|
|
||||||
move_str += f"G0 F{self.speed_travel} X{self.machine_left + 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
move_str += f"G0 F{self.speed_travel} Y{self.machine_back - 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
elif goto_str == "RtBk":
|
|
||||||
move_str += f"G0 F{self.speed_travel} X{self.machine_right - 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
move_str += f"G0 F{self.speed_travel} Y{self.machine_back - 5} Z2 ; Ortho move\n"
|
|
||||||
move_str += f"G0 F600 Z0 ; Nail down the string\nG0 Z2 ; Move up\n"
|
|
||||||
elif self.bed_shape == "elliptic" and self.origin_at_center:
|
elif self.bed_shape == "elliptic" and self.origin_at_center:
|
||||||
|
move_str = f";MESH:NONMESH---------[Travel to Layer Start]\nG0 F600 Z2 ; Move up\n"
|
||||||
|
|
||||||
radius = self.machine_width / 2
|
radius = self.machine_width / 2
|
||||||
offset_sin = round(2 ** .5 / 2 * radius, 2)
|
offset_sin = round(2 ** .5 / 2 * radius, 2)
|
||||||
if goto_str == "LtFrt":
|
if target_location == Position.LEFT_FRONT:
|
||||||
move_str += f"G0 F{self.speed_travel} X-{offset_sin} Z2 ; Move\nG0 Y-{offset_sin} Z2 ; Move to start\n"
|
move_str += f"G0 F{self.speed_travel} X-{offset_sin} Z2 ; Move\nG0 Y-{offset_sin} Z2 ; Move to start\n"
|
||||||
elif goto_str == "LtBk":
|
elif target_location == Position.LEFT_REAR:
|
||||||
if self.start_location == Location.LEFT_REAR:
|
if self.end_purge_location == Position.LEFT_REAR:
|
||||||
move_str += f"G2 X0 Y{offset_sin} I{offset_sin} J{offset_sin} ; Move around to start\n"
|
move_str += f"G2 X0 Y{offset_sin} I{offset_sin} J{offset_sin} ; Move around to start\n"
|
||||||
else:
|
else:
|
||||||
move_str += f"G0 F{self.speed_travel} X-{offset_sin} Z2 ; Ortho move\nG0 Y{offset_sin} Z2 ; Ortho move\n"
|
move_str += f"G0 F{self.speed_travel} X-{offset_sin} Z2 ; Ortho move\nG0 Y{offset_sin} Z2 ; Ortho move\n"
|
||||||
elif goto_str == "RtFrt":
|
elif target_location == Position.RIGHT_FRONT:
|
||||||
move_str += f"G0 F{self.speed_travel} X{offset_sin} Z2 ; Ortho move\nG0 Y-{offset_sin} Z2 ; Ortho move\n"
|
move_str += f"G0 F{self.speed_travel} X{offset_sin} Z2 ; Ortho move\nG0 Y-{offset_sin} Z2 ; Ortho move\n"
|
||||||
elif goto_str == "RtBk":
|
elif target_location == Position.RIGHT_REAR:
|
||||||
move_str += f"G0 F{self.speed_travel} X{offset_sin} Z2 ; Ortho move\nG0 Y{offset_sin} Z2 ; Ortho move\n"
|
move_str += f"G0 F{self.speed_travel} X{offset_sin} Z2 ; Ortho move\nG0 Y{offset_sin} Z2 ; Ortho move\n"
|
||||||
move_str += ";---------------------[End of layer start travels]"
|
move_str += ";---------------------[End of layer start travels]"
|
||||||
# Add the move_str to the end of the StartUp section and move 'LAYER_COUNT' to the end.
|
# Add the move_str to the end of the StartUp section and move 'LAYER_COUNT' to the end.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue