Commit 87019841 authored by Guillaume Seguin's avatar Guillaume Seguin

Start updating stlview to use gcoder parsed GCode

parent 5af6da86
...@@ -233,7 +233,7 @@ def vdiff(v, o): ...@@ -233,7 +233,7 @@ def vdiff(v, o):
class gcview(object): class gcview(object):
def __init__(self, lines, batch, w = 0.5, h = 0.5): def __init__(self, gcode, batch, w = 0.5, h = 0.5):
# Create the vertex and normal arrays. # Create the vertex and normal arrays.
vertices = [] vertices = []
normals = [] normals = []
...@@ -242,8 +242,12 @@ class gcview(object): ...@@ -242,8 +242,12 @@ class gcview(object):
self.vlists = [] self.vlists = []
self.layers = {} self.layers = {}
t0 = time.time() t0 = time.time()
lines = [self.transform(i) for i in lines] if gcode:
lines = [i for i in lines if i is not None] lines = [self.transform(gline) for gline in gcode.lines]
lines = [line for line in lines if line]
print len(lines)
else:
lines = []
print "transformed lines in %fs" % (time.time() - t0) print "transformed lines in %fs" % (time.time() - t0)
t0 = time.time() t0 = time.time()
layertemp = {} layertemp = {}
...@@ -355,22 +359,21 @@ class gcview(object): ...@@ -355,22 +359,21 @@ class gcview(object):
epoints = map(lambda x: vadd(E, x), points) epoints = map(lambda x: vadd(E, x), points)
return spoints, epoints, S, E return spoints, epoints, S, E
def transform(self, line): def transform(self, gline):
line = line.split(";")[0]
cur = self.prev[:] cur = self.prev[:]
if len(line) > 0: isg92 = (gline.command == "G92")
if "G1" in line or "G0" in line or "G92" in line: if gline.is_move or isg92:
if("X" in line): if gline.x is not None:
cur[0] = float(line.split("X")[1].split(" ")[0]) cur[0] = gline.x
if("Y" in line): if gline.y is not None:
cur[1] = float(line.split("Y")[1].split(" ")[0]) cur[1] = gline.y
if("Z" in line): if gline.z is not None:
cur[2] = float(line.split("Z")[1].split(" ")[0]) cur[2] = gline.z
if("E" in line): if gline.e is not None:
cur[3] = float(line.split("E")[1].split(" ")[0]) cur[3] = gline.e
if self.prev == cur: if self.prev == cur:
return None return None
if self.fline or "G92" in line: elif self.fline or isg92:
self.prev = cur self.prev = cur
self.fline = 0 self.fline = 0
return None return None
...@@ -378,6 +381,8 @@ class gcview(object): ...@@ -378,6 +381,8 @@ class gcview(object):
r = [self.prev, cur] r = [self.prev, cur]
self.prev = cur self.prev = cur
return r return r
else:
return None
def delete(self): def delete(self):
for i in self.vlists: for i in self.vlists:
...@@ -833,7 +838,7 @@ class GCFrame(wx.Frame): ...@@ -833,7 +838,7 @@ class GCFrame(wx.Frame):
m.curlayer = 0.0 m.curlayer = 0.0
m.scale = [1.0, 1.0, 1.0] m.scale = [1.0, 1.0, 1.0]
m.batch = pyglet.graphics.Batch() m.batch = pyglet.graphics.Batch()
m.gc = gcview([], batch = m.batch) m.gc = gcview(None, batch = m.batch)
self.models = {"": m} self.models = {"": m}
self.l = d() self.l = d()
self.modelindex = 0 self.modelindex = 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