Skip to content

Commit

Permalink
Rework first tool change handling
Browse files Browse the repository at this point in the history
  • Loading branch information
spegelius committed Jan 27, 2018
1 parent 5ffa0cb commit ca952c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
19 changes: 16 additions & 3 deletions src/gcode_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ def parse_print_settings(self):

is_tool_change = False
for cmd, comment, index in self.layers[0].read_lines():

if comment and comment.strip() == b"START SCRIPT END":
self.layers[0].start_gcode_end = index
self.pr_index = index
break

for layer in self.layers:
for cmd, comment, index in layer.read_lines():
if comment and comment.strip() == b"TOOL CHANGE":
Expand Down Expand Up @@ -105,7 +104,21 @@ def parse_print_settings(self):
else:
self.log.warning("No pre-prime run")
self.active_e = self.extruders[0]


# find first tool change and remove it if it's before any print moves. No need to
# do tool change here
for cmd, comment, index in self.layers[0].read_lines():
if not cmd or index <= self.layers[0].start_gcode_end:
continue
if gcode.is_tool_change(cmd) is not None:
if self.settings.get_hw_config_value("prerun.prime") == "True" or gcode.last_match == 0:
self.log.debug("Remove first tool change: {}".format(gcode.last_match))
self.layers[0].delete_line(index)
break
elif gcode.is_extrusion_move(cmd) or gcode.is_extrusion_speed_move(cmd):
# if print move before tool change, bail out. Tool change cannot be removed
break

def open_file(self, gcode_file):
""" Read given g-code file into list """
self.gcode_file = gcode_file
Expand Down
15 changes: 1 addition & 14 deletions src/slicer_prusa_slic3r.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,20 +239,7 @@ def parse_header(self):

def parse_print_settings(self):
""" Slic3r specific settings """

super().parse_print_settings()
if self.settings.get_hw_config_value("prerun.prime") == "True":
return
for cmd, comment, line_index in self.layers[0].read_lines():
# find first tool change and remove it if it's T0. No need to
# do tool change as e already have T0 active
if not cmd:
continue
if line_index > self.layers[0].start_gcode_end and gcode.is_tool_change(cmd) is not None:
if gcode.last_match == 0:
self.log.debug("Remove first T0")
self.layers[0].delete_line(line_index)
break

def parse_layers(self, lines):
"""
Expand Down Expand Up @@ -361,7 +348,7 @@ def filter_layers(self):
layer_data[z]['slots'] = slots

self.max_slots = slots
#print(self.max_slots)
self.log.debug("Max slots: {}".format(self.max_slots))

# tag layers for actions: tool change, infill, etc
zs.reverse()
Expand Down
17 changes: 2 additions & 15 deletions src/slicer_simplify3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,11 @@ def parse_layers(self, lines):

def parse_print_settings(self):
"""
Slic3r specific settings
Simplify3D specific settings
:return:
"""
super().parse_print_settings()

if self.settings.get_hw_config_value("prerun.prime") == "True":
return
for cmd, comment, line_index in self.layers[0].read_lines():
# find first tool change and remove it if it's T0. No need to
# do tool change as e already have T0 active
if not cmd:
continue
if line_index > self.layers[0].start_gcode_end and gcode.is_tool_change(cmd) is not None:
if gcode.last_match == 0:
self.log.debug("Remove first T0")
self.layers[0].delete_line(line_index)
break

def check_layer_change(self, line, current_layer):
"""
Check if line is layer change
Expand Down Expand Up @@ -372,7 +359,7 @@ def filter_layers(self):
layer_data[z]['slots'] = slots

self.max_slots = slots
#print(self.max_slots)
self.log.debug("Max slots: {}".format(self.max_slots))

# tag layers for actions: tool change, infill, etc
zs.reverse()
Expand Down

0 comments on commit ca952c3

Please sign in to comment.