Commit f1fc71ba authored by Guillaume Seguin's avatar Guillaume Seguin

Store all layers, including ones with no movement

This is a first step towards using gcoder.GCode as a storage for print-time
gcode. Now all we need is a "gcode line id => (layer id, in-layer line id)"
mapping to be able to do the indirection.
parent b7815661
...@@ -129,11 +129,12 @@ class GCode(object): ...@@ -129,11 +129,12 @@ class GCode(object):
lines = None lines = None
layers = None layers = None
all_layers = None
def __init__(self,data): def __init__(self,data):
self.lines = [Line(l2) for l2 in self.lines = [Line(l2) for l2 in
(l.strip() for l in data) (l.strip() for l in data)
if l2 and not l2.startswith(";")] if l2 and not l2[0] == ";"]
self._preprocess() self._preprocess()
self._create_layers() self._create_layers()
...@@ -166,6 +167,7 @@ class GCode(object): ...@@ -166,6 +167,7 @@ class GCode(object):
# FIXME : looks like this needs to be tested with list Z on move # FIXME : looks like this needs to be tested with list Z on move
def _create_layers(self): def _create_layers(self):
layers = {} layers = {}
all_layers = []
prev_z = None prev_z = None
cur_z = 0 cur_z = 0
...@@ -181,6 +183,7 @@ class GCode(object): ...@@ -181,6 +183,7 @@ class GCode(object):
cur_z = line.z cur_z = line.z
if cur_z != prev_z: if cur_z != prev_z:
all_layers.append(Layer(cur_lines))
old_lines = layers.get(prev_z, []) old_lines = layers.get(prev_z, [])
old_lines += cur_lines old_lines += cur_lines
layers[prev_z] = old_lines layers[prev_z] = old_lines
...@@ -189,9 +192,11 @@ class GCode(object): ...@@ -189,9 +192,11 @@ class GCode(object):
cur_lines.append(line) cur_lines.append(line)
prev_z = cur_z prev_z = cur_z
old_lines = layers.pop(prev_z, []) if cur_lines:
old_lines += cur_lines all_layers.append(Layer(cur_lines))
layers[prev_z] = old_lines old_lines = layers.pop(prev_z, [])
old_lines += cur_lines
layers[prev_z] = old_lines
for idx in layers.keys(): for idx in layers.keys():
cur_lines = layers[idx] cur_lines = layers[idx]
...@@ -201,10 +206,11 @@ class GCode(object): ...@@ -201,10 +206,11 @@ class GCode(object):
has_movement = True has_movement = True
break break
if has_movement: if has_movement:
layers[idx] = Layer(layers[idx]) layers[idx] = Layer(cur_lines)
else: else:
del layers[idx] del layers[idx]
self.all_layers = all_layers
self.layers = layers self.layers = layers
def num_layers(self): def num_layers(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment