Skip to content

Commit

Permalink
Merge pull request #1158 from volconst/layer-counts
Browse files Browse the repository at this point in the history
Refine layer counting
  • Loading branch information
kliment committed Feb 2, 2021
2 parents 669375d + 1618ae5 commit bde80f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions printrun/gcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,12 @@ def append_lines(lines, isEnd):
return
nonlocal layerbeginduration, last_layer_z
if cur_layer_has_extrusion and prev_z != last_layer_z \
or not all_layers or isEnd:
or not all_layers:
layer = Layer([], prev_z)
last_layer_z = prev_z
finished_layer = len(all_layers)-1 if all_layers else None
all_layers.append(layer)
all_zs.add(prev_z)
else:
layer = all_layers[-1]
finished_layer = None
Expand Down Expand Up @@ -543,7 +544,7 @@ def append_lines(lines, isEnd):

max_e = max(max_e, total_e)
max_e_multi=max(max_e_multi, total_e_multi)
cur_layer_has_extrusion |= line.extruding
cur_layer_has_extrusion |= line.extruding and (line.x is not None or line.y is not None)
elif line.command == "G92":
offset_e = current_e - line.e
offset_e_multi = current_e_multi - line.e
Expand Down Expand Up @@ -654,7 +655,6 @@ def append_lines(lines, isEnd):

if cur_z != prev_z and cur_layer_has_extrusion:
append_lines(cur_lines, False)
all_zs.add(prev_z)
cur_lines = []
cur_layer_has_extrusion = False

Expand Down Expand Up @@ -689,7 +689,6 @@ def append_lines(lines, isEnd):
if build_layers:
if cur_lines:
append_lines(cur_lines, True)
all_zs.add(prev_z)

self.append_layer_id = len(all_layers)
self.append_layer = Layer([])
Expand Down
17 changes: 17 additions & 0 deletions testfiles/layer-detect2.gcode
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; Print this file to see the parsed layers
; This file tests problem reported in
; https://github.com/kliment/Printrun/pull/1069#issuecomment-770091308

G28
G0 Z15
G1 E6 ; should not count as x,y not moved

G0 X10 Y10 Z0.2
G1 X20 E7

G0 Z10
M83 ;relative extrusion mode
G1 E-3 ; retract should not create layer

;@!print([l.z for l in self.fgcode.all_layers])
;@!print('test ', 'passed' if len(self.fgcode.all_layers) == 1 else 'failed')

0 comments on commit bde80f0

Please sign in to comment.