From: daid Date: Mon, 26 Mar 2012 15:14:31 +0000 (+0200) Subject: Modified gcodeInterperter to use an object for the path parts, instead of a dict... X-Git-Tag: RC1~16^2~8 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=2cd4ddb67c24cfd1f52c691fd462fa38dbb4ecd3;p=cura.git Modified gcodeInterperter to use an object for the path parts, instead of a dict. Tiny bit faster, and cleaner code. --- diff --git a/Cura/newui/gcodeInterpreter.py b/Cura/newui/gcodeInterpreter.py index bc591cf9..5424cfea 100644 --- a/Cura/newui/gcodeInterpreter.py +++ b/Cura/newui/gcodeInterpreter.py @@ -9,6 +9,13 @@ import os from newui import util3d +class gcodePath(): + def __init__(self, newType, pathType, layerNr, startPoint): + self.type = newType + self.pathType = pathType + self.list = [startPoint] + self.layerNr = layerNr + class gcode(): def __init__(self): self.regMatch = {} @@ -35,8 +42,9 @@ class gcode(): pathType = 'CUSTOM'; layerNr = 0; #Note layer 0 will be the start code. startCodeDone = False - currentPath = {'type': 'move', 'pathType': pathType, 'list': [pos.copy()], 'layerNr': layerNr} - currentPath['list'][-1].e = totalExtrusion + currentPath = gcodePath('move', pathType, layerNr, pos.copy()) + currentPath.list[0].e = totalExtrusion + pathList.append(currentPath) for line in gcodeFile: if filePos != gcodeFile.tell(): filePos = gcodeFile.tell() @@ -105,11 +113,12 @@ class gcode(): currentE += e if totalExtrusion > maxExtrusion: maxExtrusion = totalExtrusion - if currentPath['type'] != moveType or currentPath['pathType'] != pathType: + if currentPath.type != moveType or currentPath.pathType != pathType: + currentPath = gcodePath(moveType, pathType, layerNr, currentPath.list[-1]) pathList.append(currentPath) - currentPath = {'type': moveType, 'pathType': pathType, 'list': [currentPath['list'][-1]], 'layerNr': layerNr} - currentPath['list'].append(pos.copy()) - currentPath['list'][-1].e = totalExtrusion + newPos = pos.copy() + newPos.e = totalExtrusion + currentPath.list.append(newPos) elif G == 20: #Units are inches scale = 25.4 elif G == 21: #Units are mm diff --git a/Cura/newui/preview3d.py b/Cura/newui/preview3d.py index 679f05b4..e9421df8 100644 --- a/Cura/newui/preview3d.py +++ b/Cura/newui/preview3d.py @@ -444,35 +444,35 @@ class PreviewGLCanvas(glcanvas.GLCanvas): curLayerNum = 0 for path in self.parent.gcode.pathList: - if path['layerNr'] != curLayerNum: + if path.layerNr != curLayerNum: prevLayerZ = curLayerZ - curLayerZ = path['list'][1].z - curLayerNum = path['layerNr'] + curLayerZ = path.list[1].z + curLayerNum = path.layerNr layerThickness = curLayerZ - prevLayerZ c = 1.0 - if path['layerNr'] != self.parent.layerSpin.GetValue(): - if path['layerNr'] < self.parent.layerSpin.GetValue(): - c = 0.9 - (self.parent.layerSpin.GetValue() - path['layerNr']) * 0.1 + if path.layerNr != self.parent.layerSpin.GetValue(): + if path.layerNr < self.parent.layerSpin.GetValue(): + c = 0.9 - (self.parent.layerSpin.GetValue() - path.layerNr) * 0.1 if c < 0.4: c = 0.4 else: break - if path['type'] == 'move': + if path.type == 'move': glColor3f(0,0,c) - if path['type'] == 'extrude': - if path['pathType'] == 'FILL': + if path.type == 'extrude': + if path.pathType == 'FILL': glColor3f(c/2,c/2,0) - elif path['pathType'] == 'WALL-INNER': + elif path.pathType == 'WALL-INNER': glColor3f(0,c,0) else: glColor3f(c,0,0) - if path['type'] == 'retract': + if path.type == 'retract': glColor3f(0,c,c) - if c > 0.4 and path['type'] == 'extrude': - for i in xrange(0, len(path['list'])-1): - v0 = path['list'][i] - v1 = path['list'][i+1] + if c > 0.4 and path.type == 'extrude': + for i in xrange(0, len(path.list)-1): + v0 = path.list[i] + v1 = path.list[i+1] # Calculate line width from ePerDistance (needs layer thickness and filament diameter) dist = (v0 - v1).vsize() @@ -488,7 +488,7 @@ class PreviewGLCanvas(glcanvas.GLCanvas): v1 = v1 - normal * lineWidth glBegin(GL_QUADS) - if path['pathType'] == 'FILL': #Remove depth buffer fighting on infill/wall overlap + if path.pathType == 'FILL': #Remove depth buffer fighting on infill/wall overlap glVertex3f(v0.x, v0.y, v0.z - 0.02) glVertex3f(v1.x, v1.y, v1.z - 0.02) glVertex3f(v3.x, v3.y, v3.z - 0.02) @@ -511,7 +511,7 @@ class PreviewGLCanvas(glcanvas.GLCanvas): # glEnd() else: glBegin(GL_LINE_STRIP) - for v in path['list']: + for v in path.list: glVertex3f(v.x, v.y, v.z) glEnd() glEndList()