Permalink
Browse files

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

  • Loading branch information...
iXce committed May 23, 2013
1 parent 2a6eec7 commit 5e1a0be43c7637d819821bbf7dd9d573bc436bf4
Showing with 17 additions and 8 deletions.
  1. +2 −2 printcore.py
  2. +15 −6 printrun/gcoder.py
View
@@ -380,8 +380,8 @@ def _sendnext(self):
if self.priqueue:
self._send(self.priqueue.pop(0))
return
if self.printing and self.queueindex < len(self.mainqueue.idxs):
(layer, line) = self.mainqueue.idxs[self.queueindex]
if self.printing and self.queueindex < len(self.mainqueue):
(layer, line) = self.mainqueue.idxs(self.queueindex)
gline = self.mainqueue.all_layers[layer].lines[line]
tline = gline.raw
#check for host command
View
@@ -18,6 +18,7 @@
import re
import math
import datetime
from array import array
gcode_parsed_args = ["x", "y", "e", "f", "z", "p", "i", "j", "s"]
gcode_exp = re.compile("\([^\(\)]*\)|;.*|[/\*].*\n|[a-z][-+]?[0-9]*\.?[0-9]*")
@@ -119,7 +120,8 @@ class GCode(object):
lines = None
layers = None
all_layers = None
idxs = None
layer_idxs = None
line_idxs = None
append_layer = None
append_layer_id = None
@@ -148,7 +150,7 @@ def __init__(self,data):
self._preprocess_layers()
def __len__(self):
return len(self.idxs)
return len(self.line_idxs)
def append(self, command):
command = command.strip()
@@ -158,7 +160,8 @@ def append(self, command):
self.lines.append(gline)
self._preprocess([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):
"""Checks for G20, G21, G90 and G91, sets imperial and relative flags"""
@@ -217,7 +220,8 @@ def _preprocess_extrusion(self):
def _create_layers(self):
layers = {}
all_layers = []
idxs = []
layer_idxs = []
line_idxs = []
layer_id = 0
layer_line = 0
@@ -245,7 +249,8 @@ def _create_layers(self):
layer_line = 0
cur_lines.append(line)
idxs.append((layer_id, layer_line))
layer_idxs.append(layer_id)
line_idxs.append(layer_line)
layer_line += 1
prev_z = cur_z
@@ -272,7 +277,11 @@ def _create_layers(self):
all_layers.append(self.append_layer)
self.all_layers = all_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):
return len(self.layers)

0 comments on commit 5e1a0be

Please sign in to comment.