Commit 8110107a authored by Guillaume Seguin's avatar Guillaume Seguin

Revert tuple changes and derive Layer from list

parent 8f2ea868
...@@ -78,13 +78,9 @@ def parse_coordinates(line, split_raw, imperial = False, force = False): ...@@ -78,13 +78,9 @@ def parse_coordinates(line, split_raw, imperial = False, force = False):
if code not in gcode_parsed_nonargs and bit[1]: if code not in gcode_parsed_nonargs and bit[1]:
setattr(line, code, unit_factor*float(bit[1])) setattr(line, code, unit_factor*float(bit[1]))
class Layer(object): class Layer(list):
lines = None __slots__ = ("duration")
duration = None
def __init__(self, lines):
self.lines = lines
def _preprocess(self, current_x, current_y, current_z): def _preprocess(self, current_x, current_y, current_z):
xmin = float("inf") xmin = float("inf")
...@@ -96,7 +92,7 @@ class Layer(object): ...@@ -96,7 +92,7 @@ class Layer(object):
relative = False relative = False
relative_e = False relative_e = False
for line in self.lines: for line in self:
if not line.is_move and line.command != "G92": if not line.is_move and line.command != "G92":
continue continue
if line.is_move: if line.is_move:
...@@ -183,9 +179,9 @@ class GCode(object): ...@@ -183,9 +179,9 @@ class GCode(object):
self.lines.append(gline) self.lines.append(gline)
self._preprocess_lines([gline]) self._preprocess_lines([gline])
self._preprocess_extrusion([gline]) self._preprocess_extrusion([gline])
self.append_layer.lines.append(gline) self.append_layer.append(gline)
self.layer_idxs.append(self.append_layer_id) self.layer_idxs.append(self.append_layer_id)
self.line_idxs.append(len(self.append_layer.lines)) self.line_idxs.append(len(self.append_layer))
return gline return gline
def _preprocess_lines(self, lines = None): def _preprocess_lines(self, lines = None):
...@@ -275,9 +271,8 @@ class GCode(object): ...@@ -275,9 +271,8 @@ class GCode(object):
cur_z = line.z cur_z = line.z
if cur_z != prev_z: if cur_z != prev_z:
cur_lines = tuple(cur_lines)
all_layers.append(Layer(cur_lines)) 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
cur_lines = [] cur_lines = []
...@@ -291,11 +286,10 @@ class GCode(object): ...@@ -291,11 +286,10 @@ class GCode(object):
prev_z = cur_z prev_z = cur_z
if cur_lines: if cur_lines:
cur_lines = tuple(cur_lines) all_layers.append(Layer(cur_lines))
all_layers.append(Layer(tuple(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] = tuple(old_lines) layers[prev_z] = old_lines
for idx in layers.keys(): for idx in layers.keys():
cur_lines = layers[idx] cur_lines = layers[idx]
...@@ -369,7 +363,7 @@ class GCode(object): ...@@ -369,7 +363,7 @@ class GCode(object):
# get device caps from firmware: max speed, acceleration/axis (including extruder) # get device caps from firmware: max speed, acceleration/axis (including extruder)
# calculate the maximum move duration accounting for above ;) # calculate the maximum move duration accounting for above ;)
for layer in self.all_layers: for layer in self.all_layers:
for line in layer.lines: for line in layer:
if line.command not in ["G1", "G0", "G4"]: if line.command not in ["G1", "G0", "G4"]:
continue continue
if line.command == "G4": if line.command == "G4":
......
...@@ -257,7 +257,7 @@ class GcodeModel(Model): ...@@ -257,7 +257,7 @@ class GcodeModel(Model):
prev_pos = (0, 0, 0) prev_pos = (0, 0, 0)
for layer_idx, layer in enumerate(model_data.all_layers): for layer_idx, layer in enumerate(model_data.all_layers):
for gline in layer.lines: for gline in layer:
if not gline.is_move: if not gline.is_move:
continue continue
vertex_list.append(prev_pos) vertex_list.append(prev_pos)
......
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