def updateToolbar(self):\r
self.layerSpin.Show(self.gcode != None)\r
if self.gcode != None:\r
- self.layerSpin.SetRange(1, self.gcode.layerCount)\r
+ self.layerSpin.SetRange(1, len(self.gcode.layerList))\r
self.toolbar.Realize()\r
\r
def OnViewChange(self, e):\r
lineWidth = float(profile.getProfileSetting('nozzle_size')) / 2\r
\r
curLayerNum = 0\r
- for path in self.parent.gcode.pathList:\r
- if path.layerNr != curLayerNum:\r
- prevLayerZ = curLayerZ\r
- curLayerZ = path.list[1].z\r
- curLayerNum = path.layerNr\r
- layerThickness = curLayerZ - prevLayerZ\r
- \r
- c = 1.0\r
- if path.layerNr != self.parent.layerSpin.GetValue():\r
- if path.layerNr < self.parent.layerSpin.GetValue():\r
- c = 0.9 - (self.parent.layerSpin.GetValue() - path.layerNr) * 0.1\r
- if c < 0.4:\r
- c = 0.4\r
- else:\r
- break\r
- if path.type == 'move':\r
- glColor3f(0,0,c)\r
- if path.type == 'extrude':\r
- if path.pathType == 'FILL':\r
- glColor3f(c/2,c/2,0)\r
- elif path.pathType == 'WALL-INNER':\r
- glColor3f(0,c,0)\r
- else:\r
- glColor3f(c,0,0)\r
- if path.type == 'retract':\r
- glColor3f(0,c,c)\r
- if c > 0.4 and path.type == 'extrude':\r
- for i in xrange(0, len(path.list)-1):\r
- v0 = path.list[i]\r
- v1 = path.list[i+1]\r
-\r
- # Calculate line width from ePerDistance (needs layer thickness and filament diameter)\r
- dist = (v0 - v1).vsize()\r
- if dist > 0 and layerThickness > 0:\r
- extrusionMMperDist = (v1.e - v0.e) / (v0 - v1).vsize()\r
- lineWidth = extrusionMMperDist * filamentArea / layerThickness / 2\r
-\r
- normal = (v0 - v1).cross(util3d.Vector3(0,0,1))\r
- normal.normalize()\r
- v2 = v0 + normal * lineWidth\r
- v3 = v1 + normal * lineWidth\r
- v0 = v0 - normal * lineWidth\r
- v1 = v1 - normal * lineWidth\r
-\r
- glBegin(GL_QUADS)\r
- if path.pathType == 'FILL': #Remove depth buffer fighting on infill/wall overlap\r
- glVertex3f(v0.x, v0.y, v0.z - 0.02)\r
- glVertex3f(v1.x, v1.y, v1.z - 0.02)\r
- glVertex3f(v3.x, v3.y, v3.z - 0.02)\r
- glVertex3f(v2.x, v2.y, v2.z - 0.02)\r
+ for layer in self.parent.gcode.layerList:\r
+ for path in layer:\r
+ c = 1.0\r
+ if curLayerNum != self.parent.layerSpin.GetValue():\r
+ if curLayerNum < self.parent.layerSpin.GetValue():\r
+ c = 0.9 - (self.parent.layerSpin.GetValue() - curLayerNum) * 0.1\r
+ if c < 0.4:\r
+ c = 0.4\r
else:\r
- glVertex3f(v0.x, v0.y, v0.z - 0.01)\r
- glVertex3f(v1.x, v1.y, v1.z - 0.01)\r
- glVertex3f(v3.x, v3.y, v3.z - 0.01)\r
- glVertex3f(v2.x, v2.y, v2.z - 0.01)\r
- glEnd()\r
+ break\r
+ if path.type == 'move':\r
+ glColor3f(0,0,c)\r
+ if path.type == 'extrude':\r
+ if path.pathType == 'FILL':\r
+ glColor3f(c/2,c/2,0)\r
+ elif path.pathType == 'WALL-INNER':\r
+ glColor3f(0,c,0)\r
+ else:\r
+ glColor3f(c,0,0)\r
+ if path.type == 'retract':\r
+ glColor3f(0,c,c)\r
+ if c > 0.4 and path.type == 'extrude':\r
+ for i in xrange(0, len(path.list)-1):\r
+ v0 = path.list[i]\r
+ v1 = path.list[i+1]\r
+\r
+ # Calculate line width from ePerDistance (needs layer thickness and filament diameter)\r
+ dist = (v0 - v1).vsize()\r
+ if dist > 0 and layerThickness > 0:\r
+ extrusionMMperDist = (v1.e - v0.e) / (v0 - v1).vsize()\r
+ lineWidth = extrusionMMperDist * filamentArea / layerThickness / 2\r
+\r
+ normal = (v0 - v1).cross(util3d.Vector3(0,0,1))\r
+ normal.normalize()\r
+ v2 = v0 + normal * lineWidth\r
+ v3 = v1 + normal * lineWidth\r
+ v0 = v0 - normal * lineWidth\r
+ v1 = v1 - normal * lineWidth\r
+\r
+ glBegin(GL_QUADS)\r
+ if path.pathType == 'FILL': #Remove depth buffer fighting on infill/wall overlap\r
+ glVertex3f(v0.x, v0.y, v0.z - 0.02)\r
+ glVertex3f(v1.x, v1.y, v1.z - 0.02)\r
+ glVertex3f(v3.x, v3.y, v3.z - 0.02)\r
+ glVertex3f(v2.x, v2.y, v2.z - 0.02)\r
+ else:\r
+ glVertex3f(v0.x, v0.y, v0.z - 0.01)\r
+ glVertex3f(v1.x, v1.y, v1.z - 0.01)\r
+ glVertex3f(v3.x, v3.y, v3.z - 0.01)\r
+ glVertex3f(v2.x, v2.y, v2.z - 0.01)\r
+ glEnd()\r
\r
- #for v in path['list']:\r
- # glBegin(GL_TRIANGLE_FAN)\r
- # glVertex3f(v.x, v.y, v.z - 0.001)\r
- # for i in xrange(0, 16+1):\r
- # if path['pathType'] == 'FILL': #Remove depth buffer fighting on infill/wall overlap\r
- # glVertex3f(v.x + math.cos(math.pi*2/16*i) * lineWidth, v.y + math.sin(math.pi*2/16*i) * lineWidth, v.z - 0.02)\r
- # else:\r
- # glVertex3f(v.x + math.cos(math.pi*2/16*i) * lineWidth, v.y + math.sin(math.pi*2/16*i) * lineWidth, v.z - 0.01)\r
- # glEnd()\r
- else:\r
- glBegin(GL_LINE_STRIP)\r
- for v in path.list:\r
- glVertex3f(v.x, v.y, v.z)\r
- glEnd()\r
+ #for v in path['list']:\r
+ # glBegin(GL_TRIANGLE_FAN)\r
+ # glVertex3f(v.x, v.y, v.z - 0.001)\r
+ # for i in xrange(0, 16+1):\r
+ # if path['pathType'] == 'FILL': #Remove depth buffer fighting on infill/wall overlap\r
+ # glVertex3f(v.x + math.cos(math.pi*2/16*i) * lineWidth, v.y + math.sin(math.pi*2/16*i) * lineWidth, v.z - 0.02)\r
+ # else:\r
+ # glVertex3f(v.x + math.cos(math.pi*2/16*i) * lineWidth, v.y + math.sin(math.pi*2/16*i) * lineWidth, v.z - 0.01)\r
+ # glEnd()\r
+ else:\r
+ glBegin(GL_LINE_STRIP)\r
+ for v in path.list:\r
+ glVertex3f(v.x, v.y, v.z)\r
+ glEnd()\r
+ curLayerNum += 1\r
glEndList()\r
if self.viewMode == "GCode" or self.viewMode == "Mixed":\r
glCallList(self.gcodeDisplayList)\r
from util import util3d
class gcodePath():
- def __init__(self, newType, pathType, layerNr, startPoint):
+ def __init__(self, newType, pathType, startPoint):
self.type = newType
self.pathType = pathType
self.list = [startPoint]
- self.layerNr = layerNr
class gcode():
def __init__(self):
self.regMatch = {}
- self.layerCount = 0
- self.pathList = []
+ self.layerList = []
self.extrusionAmount = 0
self.totalMoveTimeMinute = 0
self.progressCallback = None
totalExtrusion = 0.0
maxExtrusion = 0.0
totalMoveTimeMinute = 0.0
- pathList = []
scale = 1.0
posAbs = True
feedRate = 3600
pathType = 'CUSTOM';
- layerNr = 0; #Note layer 0 will be the start code.
startCodeDone = False
- currentPath = gcodePath('move', pathType, layerNr, pos.copy())
+ currentLayer = []
+ currentPath = gcodePath('move', pathType, pos.copy())
currentPath.list[0].e = totalExtrusion
- pathList.append(currentPath)
+ currentLayer.append(currentPath)
for line in gcodeFile:
if filePos != gcodeFile.tell():
filePos = gcodeFile.tell()
if self.progressCallback != None:
self.progressCallback(float(filePos) / float(fileSize))
+
+ #Parse Cura_SF comments
if line.startswith(';TYPE:'):
pathType = line[6:].strip()
if pathType != "CUSTOM":
pos.z = z * scale
else:
pos.z += z * scale
+ #Check if we have a new layer.
if oldPos.z != pos.z and startCodeDone:
- layerNr += 1
+ self.layerList.append(currentLayer)
+ currentLayer = []
if f is not None:
feedRate = f
if x is not None or y is not None or z is not None:
if totalExtrusion > maxExtrusion:
maxExtrusion = totalExtrusion
if currentPath.type != moveType or currentPath.pathType != pathType:
- currentPath = gcodePath(moveType, pathType, layerNr, currentPath.list[-1])
- pathList.append(currentPath)
+ currentPath = gcodePath(moveType, pathType, currentPath.list[-1])
+ currentLayer.append(currentPath)
newPos = pos.copy()
newPos.e = totalExtrusion
currentPath.list.append(newPos)
else:
print "Unknown M code:" + str(M)
gcodeFile.close()
- self.layerCount = layerNr
- self.pathList = pathList
+ self.layerList.append(currentLayer)
self.extrusionAmount = maxExtrusion
self.totalMoveTimeMinute = totalMoveTimeMinute
print "Extruded a total of: %d mm of filament" % (self.extrusionAmount)