Commit 4b372f56 authored by Guillaume Seguin's avatar Guillaume Seguin

Speedup full file gcode loading in printrun/gviz.py

FWIW, on my test system with my test GCode loading time goes down from 5.7s to
2.3s between b3a673bc and this commit, that's almost 60% gone.
However, there is still a lot of room for functional improvements :
- I don't think the roundtrip through the target array is useful
- There's no handling of relative coordinates (neither for position nor for e)
- The arcs drawing code might be wrong
- The stlview bits are not enabled and probably have to be looked at and updated
parent 0833d378
...@@ -316,13 +316,19 @@ class gviz(wx.Panel): ...@@ -316,13 +316,19 @@ class gviz(wx.Panel):
self.clear() self.clear()
self.add_parsed_gcodes(gcode.lines) self.add_parsed_gcodes(gcode.lines)
def add_parsed_gcodes(self, lines, hilight = 0): def add_parsed_gcodes(self, lines):
def _readgcode(): def _y(y):
return self.build_dimensions[1] - (y - self.build_dimensions[4])
def _x(x):
return x - self.build_dimensions[3]
for gline in lines:
if gline.command not in ["G0", "G1", "G2", "G3"]:
continue
target = self.lastpos[:] target = self.lastpos[:]
target[5] = 0.0 target[5] = 0.0
target[6] = 0.0 target[6] = 0.0
if hilight:
target = self.hilightpos[:]
if gline.x != None: target[0] = gline.x if gline.x != None: target[0] = gline.x
if gline.y != None: target[1] = gline.y if gline.y != None: target[1] = gline.y
if gline.z != None: target[2] = gline.z if gline.z != None: target[2] = gline.z
...@@ -330,51 +336,34 @@ class gviz(wx.Panel): ...@@ -330,51 +336,34 @@ class gviz(wx.Panel):
if gline.f != None: target[4] = gline.f if gline.f != None: target[4] = gline.f
if gline.i != None: target[5] = gline.i if gline.i != None: target[5] = gline.i
if gline.j != None: target[6] = gline.j if gline.j != None: target[6] = gline.j
if not hilight: z = target[2]
if not target[2] in self.lines.keys(): if z not in self.layers:
self.lines[target[2]]=[] self.lines[z] = []
self.pens[target[2]]=[] self.pens[z] = []
self.arcs[target[2]]=[] self.arcs[z] = []
self.arcpens[target[2]]=[] self.arcpens[z] = []
self.layers+=[target[2]] self.layers.append(z)
return target
def _y(y): start_pos = self.lastpos[:]
return self.build_dimensions[1] - (y - self.build_dimensions[4])
def _x(x):
return x - self.build_dimensions[3]
for gline in lines: if gline.command in ["G0", "G1"]:
start_pos = self.hilightpos[:] if hilight else self.lastpos[:]
if gline.command in [ "G0", "G1" ]:
target = _readgcode()
line = [ _x(start_pos[0]), _y(start_pos[1]), _x(target[0]), _y(target[1]) ] line = [ _x(start_pos[0]), _y(start_pos[1]), _x(target[0]), _y(target[1]) ]
if not hilight: self.lines[z].append(line)
self.lines[ target[2] ] += [line] self.pens[z].append(self.mainpen if target[3] != self.lastpos[3] else self.travelpen)
self.pens[ target[2] ] += [self.mainpen if target[3] != self.lastpos[3] else self.travelpen]
self.lastpos = target self.lastpos = target
else:
self.hilight += [line]
self.hilightpos = target
self.dirty = 1 self.dirty = 1
if gline.command in [ "G2", "G3" ]: if gline.command in ["G2", "G3"]:
target = _readgcode() arc = [_x(start_pos[0]), _y(start_pos[1]),
arc = [] _x(target[0]), _y(target[1]),
arc += [ _x(start_pos[0]), _y(start_pos[1]) ] _x(start_pos[0] + target[5]), _y(start_pos[1] + target[6]) ] # center
arc += [ _x(target[0]), _y(target[1]) ] # FIXME : verify this works : why not reverse endpoints 4, 5
arc += [ _x(start_pos[0] + target[5]), _y(start_pos[1] + target[6]) ] # center
if gline.command == "G2": # clockwise, reverse endpoints if gline.command == "G2": # clockwise, reverse endpoints
arc[0], arc[1], arc[2], arc[3] = arc[2], arc[3], arc[0], arc[1] arc[0], arc[1], arc[2], arc[3] = arc[2], arc[3], arc[0], arc[1]
if not hilight: self.arcs[z].append(arc)
self.arcs[ target[2] ] += [arc] self.arcpens[z].append(self.arcpen)
self.arcpens[ target[2] ] += [self.arcpen]
self.lastpos = target self.lastpos = target
else:
self.hilightarcs += [arc]
self.hilightpos = target
self.dirty = 1 self.dirty = 1
def addgcode(self, gcode = "M105", hilight = 0): def addgcode(self, gcode = "M105", hilight = 0):
......
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