Commit 5e1a0be4 authored by Guillaume Seguin's avatar Guillaume Seguin

Use arrays for storing layer/line ids instead of an heavy list of tuples

parent 2a6eec73
...@@ -380,8 +380,8 @@ class printcore(): ...@@ -380,8 +380,8 @@ class printcore():
if self.priqueue: if self.priqueue:
self._send(self.priqueue.pop(0)) self._send(self.priqueue.pop(0))
return return
if self.printing and self.queueindex < len(self.mainqueue.idxs): if self.printing and self.queueindex < len(self.mainqueue):
(layer, line) = self.mainqueue.idxs[self.queueindex] (layer, line) = self.mainqueue.idxs(self.queueindex)
gline = self.mainqueue.all_layers[layer].lines[line] gline = self.mainqueue.all_layers[layer].lines[line]
tline = gline.raw tline = gline.raw
#check for host command #check for host command
......
...@@ -18,6 +18,7 @@ import sys ...@@ -18,6 +18,7 @@ import sys
import re import re
import math import math
import datetime import datetime
from array import array
gcode_parsed_args = ["x", "y", "e", "f", "z", "p", "i", "j", "s"] gcode_parsed_args = ["x", "y", "e", "f", "z", "p", "i", "j", "s"]
gcode_exp = re.compile("\([^\(\)]*\)|;.*|[/\*].*\n|[a-z][-+]?[0-9]*\.?[0-9]*") gcode_exp = re.compile("\([^\(\)]*\)|;.*|[/\*].*\n|[a-z][-+]?[0-9]*\.?[0-9]*")
...@@ -119,7 +120,8 @@ class GCode(object): ...@@ -119,7 +120,8 @@ class GCode(object):
lines = None lines = None
layers = None layers = None
all_layers = None all_layers = None
idxs = None layer_idxs = None
line_idxs = None
append_layer = None append_layer = None
append_layer_id = None append_layer_id = None
...@@ -148,7 +150,7 @@ class GCode(object): ...@@ -148,7 +150,7 @@ class GCode(object):
self._preprocess_layers() self._preprocess_layers()
def __len__(self): def __len__(self):
return len(self.idxs) return len(self.line_idxs)
def append(self, command): def append(self, command):
command = command.strip() command = command.strip()
...@@ -158,7 +160,8 @@ class GCode(object): ...@@ -158,7 +160,8 @@ class GCode(object):
self.lines.append(gline) self.lines.append(gline)
self._preprocess([gline]) self._preprocess([gline])
self.append_layer.lines.append(gline) self.append_layer.lines.append(gline)
self.idxs.append((self.append_layer_id, len(self.append_layer.lines))) self.layer_idxs.append(self.append_layer_id)
self.line_idxs.append(len(self.append_layer.lines))
def _preprocess_lines(self, lines = None): def _preprocess_lines(self, lines = None):
"""Checks for G20, G21, G90 and G91, sets imperial and relative flags""" """Checks for G20, G21, G90 and G91, sets imperial and relative flags"""
...@@ -217,7 +220,8 @@ class GCode(object): ...@@ -217,7 +220,8 @@ class GCode(object):
def _create_layers(self): def _create_layers(self):
layers = {} layers = {}
all_layers = [] all_layers = []
idxs = [] layer_idxs = []
line_idxs = []
layer_id = 0 layer_id = 0
layer_line = 0 layer_line = 0
...@@ -245,7 +249,8 @@ class GCode(object): ...@@ -245,7 +249,8 @@ class GCode(object):
layer_line = 0 layer_line = 0
cur_lines.append(line) cur_lines.append(line)
idxs.append((layer_id, layer_line)) layer_idxs.append(layer_id)
line_idxs.append(layer_line)
layer_line += 1 layer_line += 1
prev_z = cur_z prev_z = cur_z
...@@ -272,7 +277,11 @@ class GCode(object): ...@@ -272,7 +277,11 @@ class GCode(object):
all_layers.append(self.append_layer) all_layers.append(self.append_layer)
self.all_layers = all_layers self.all_layers = all_layers
self.layers = layers self.layers = layers
self.idxs = idxs self.layer_idxs = array('I', layer_idxs)
self.line_idxs = array('I', line_idxs)
def idxs(self, i):
return self.layer_idxs[i], self.line_idxs[i]
def num_layers(self): def num_layers(self):
return len(self.layers) return len(self.layers)
......
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