Make GCode reader store paths per layer
parent
0834aec2d2
commit
ddfd386b73
|
@ -259,7 +259,7 @@ class previewPanel(wx.Panel):
|
||||||
def updateToolbar(self):
|
def updateToolbar(self):
|
||||||
self.layerSpin.Show(self.gcode != None)
|
self.layerSpin.Show(self.gcode != None)
|
||||||
if self.gcode != None:
|
if self.gcode != None:
|
||||||
self.layerSpin.SetRange(1, self.gcode.layerCount)
|
self.layerSpin.SetRange(1, len(self.gcode.layerList))
|
||||||
self.toolbar.Realize()
|
self.toolbar.Realize()
|
||||||
|
|
||||||
def OnViewChange(self, e):
|
def OnViewChange(self, e):
|
||||||
|
@ -442,77 +442,73 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
|
||||||
lineWidth = float(profile.getProfileSetting('nozzle_size')) / 2
|
lineWidth = float(profile.getProfileSetting('nozzle_size')) / 2
|
||||||
|
|
||||||
curLayerNum = 0
|
curLayerNum = 0
|
||||||
for path in self.parent.gcode.pathList:
|
for layer in self.parent.gcode.layerList:
|
||||||
if path.layerNr != curLayerNum:
|
for path in layer:
|
||||||
prevLayerZ = curLayerZ
|
c = 1.0
|
||||||
curLayerZ = path.list[1].z
|
if curLayerNum != self.parent.layerSpin.GetValue():
|
||||||
curLayerNum = path.layerNr
|
if curLayerNum < self.parent.layerSpin.GetValue():
|
||||||
layerThickness = curLayerZ - prevLayerZ
|
c = 0.9 - (self.parent.layerSpin.GetValue() - curLayerNum) * 0.1
|
||||||
|
if c < 0.4:
|
||||||
c = 1.0
|
c = 0.4
|
||||||
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':
|
|
||||||
glColor3f(0,0,c)
|
|
||||||
if path.type == 'extrude':
|
|
||||||
if path.pathType == 'FILL':
|
|
||||||
glColor3f(c/2,c/2,0)
|
|
||||||
elif path.pathType == 'WALL-INNER':
|
|
||||||
glColor3f(0,c,0)
|
|
||||||
else:
|
|
||||||
glColor3f(c,0,0)
|
|
||||||
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]
|
|
||||||
|
|
||||||
# Calculate line width from ePerDistance (needs layer thickness and filament diameter)
|
|
||||||
dist = (v0 - v1).vsize()
|
|
||||||
if dist > 0 and layerThickness > 0:
|
|
||||||
extrusionMMperDist = (v1.e - v0.e) / (v0 - v1).vsize()
|
|
||||||
lineWidth = extrusionMMperDist * filamentArea / layerThickness / 2
|
|
||||||
|
|
||||||
normal = (v0 - v1).cross(util3d.Vector3(0,0,1))
|
|
||||||
normal.normalize()
|
|
||||||
v2 = v0 + normal * lineWidth
|
|
||||||
v3 = v1 + normal * lineWidth
|
|
||||||
v0 = v0 - normal * lineWidth
|
|
||||||
v1 = v1 - normal * lineWidth
|
|
||||||
|
|
||||||
glBegin(GL_QUADS)
|
|
||||||
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)
|
|
||||||
glVertex3f(v2.x, v2.y, v2.z - 0.02)
|
|
||||||
else:
|
else:
|
||||||
glVertex3f(v0.x, v0.y, v0.z - 0.01)
|
break
|
||||||
glVertex3f(v1.x, v1.y, v1.z - 0.01)
|
if path.type == 'move':
|
||||||
glVertex3f(v3.x, v3.y, v3.z - 0.01)
|
glColor3f(0,0,c)
|
||||||
glVertex3f(v2.x, v2.y, v2.z - 0.01)
|
if path.type == 'extrude':
|
||||||
glEnd()
|
if path.pathType == 'FILL':
|
||||||
|
glColor3f(c/2,c/2,0)
|
||||||
|
elif path.pathType == 'WALL-INNER':
|
||||||
|
glColor3f(0,c,0)
|
||||||
|
else:
|
||||||
|
glColor3f(c,0,0)
|
||||||
|
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]
|
||||||
|
|
||||||
|
# Calculate line width from ePerDistance (needs layer thickness and filament diameter)
|
||||||
|
dist = (v0 - v1).vsize()
|
||||||
|
if dist > 0 and layerThickness > 0:
|
||||||
|
extrusionMMperDist = (v1.e - v0.e) / (v0 - v1).vsize()
|
||||||
|
lineWidth = extrusionMMperDist * filamentArea / layerThickness / 2
|
||||||
|
|
||||||
|
normal = (v0 - v1).cross(util3d.Vector3(0,0,1))
|
||||||
|
normal.normalize()
|
||||||
|
v2 = v0 + normal * lineWidth
|
||||||
|
v3 = v1 + normal * lineWidth
|
||||||
|
v0 = v0 - normal * lineWidth
|
||||||
|
v1 = v1 - normal * lineWidth
|
||||||
|
|
||||||
|
glBegin(GL_QUADS)
|
||||||
|
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)
|
||||||
|
glVertex3f(v2.x, v2.y, v2.z - 0.02)
|
||||||
|
else:
|
||||||
|
glVertex3f(v0.x, v0.y, v0.z - 0.01)
|
||||||
|
glVertex3f(v1.x, v1.y, v1.z - 0.01)
|
||||||
|
glVertex3f(v3.x, v3.y, v3.z - 0.01)
|
||||||
|
glVertex3f(v2.x, v2.y, v2.z - 0.01)
|
||||||
|
glEnd()
|
||||||
|
|
||||||
#for v in path['list']:
|
#for v in path['list']:
|
||||||
# glBegin(GL_TRIANGLE_FAN)
|
# glBegin(GL_TRIANGLE_FAN)
|
||||||
# glVertex3f(v.x, v.y, v.z - 0.001)
|
# glVertex3f(v.x, v.y, v.z - 0.001)
|
||||||
# for i in xrange(0, 16+1):
|
# for i in xrange(0, 16+1):
|
||||||
# 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(v.x + math.cos(math.pi*2/16*i) * lineWidth, v.y + math.sin(math.pi*2/16*i) * lineWidth, v.z - 0.02)
|
# 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)
|
||||||
# else:
|
# else:
|
||||||
# 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)
|
# 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)
|
||||||
# glEnd()
|
# glEnd()
|
||||||
else:
|
else:
|
||||||
glBegin(GL_LINE_STRIP)
|
glBegin(GL_LINE_STRIP)
|
||||||
for v in path.list:
|
for v in path.list:
|
||||||
glVertex3f(v.x, v.y, v.z)
|
glVertex3f(v.x, v.y, v.z)
|
||||||
glEnd()
|
glEnd()
|
||||||
|
curLayerNum += 1
|
||||||
glEndList()
|
glEndList()
|
||||||
if self.viewMode == "GCode" or self.viewMode == "Mixed":
|
if self.viewMode == "GCode" or self.viewMode == "Mixed":
|
||||||
glCallList(self.gcodeDisplayList)
|
glCallList(self.gcodeDisplayList)
|
||||||
|
|
|
@ -9,17 +9,15 @@ import os
|
||||||
from util import util3d
|
from util import util3d
|
||||||
|
|
||||||
class gcodePath():
|
class gcodePath():
|
||||||
def __init__(self, newType, pathType, layerNr, startPoint):
|
def __init__(self, newType, pathType, startPoint):
|
||||||
self.type = newType
|
self.type = newType
|
||||||
self.pathType = pathType
|
self.pathType = pathType
|
||||||
self.list = [startPoint]
|
self.list = [startPoint]
|
||||||
self.layerNr = layerNr
|
|
||||||
|
|
||||||
class gcode():
|
class gcode():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.regMatch = {}
|
self.regMatch = {}
|
||||||
self.layerCount = 0
|
self.layerList = []
|
||||||
self.pathList = []
|
|
||||||
self.extrusionAmount = 0
|
self.extrusionAmount = 0
|
||||||
self.totalMoveTimeMinute = 0
|
self.totalMoveTimeMinute = 0
|
||||||
self.progressCallback = None
|
self.progressCallback = None
|
||||||
|
@ -34,21 +32,22 @@ class gcode():
|
||||||
totalExtrusion = 0.0
|
totalExtrusion = 0.0
|
||||||
maxExtrusion = 0.0
|
maxExtrusion = 0.0
|
||||||
totalMoveTimeMinute = 0.0
|
totalMoveTimeMinute = 0.0
|
||||||
pathList = []
|
|
||||||
scale = 1.0
|
scale = 1.0
|
||||||
posAbs = True
|
posAbs = True
|
||||||
feedRate = 3600
|
feedRate = 3600
|
||||||
pathType = 'CUSTOM';
|
pathType = 'CUSTOM';
|
||||||
layerNr = 0; #Note layer 0 will be the start code.
|
|
||||||
startCodeDone = False
|
startCodeDone = False
|
||||||
currentPath = gcodePath('move', pathType, layerNr, pos.copy())
|
currentLayer = []
|
||||||
|
currentPath = gcodePath('move', pathType, pos.copy())
|
||||||
currentPath.list[0].e = totalExtrusion
|
currentPath.list[0].e = totalExtrusion
|
||||||
pathList.append(currentPath)
|
currentLayer.append(currentPath)
|
||||||
for line in gcodeFile:
|
for line in gcodeFile:
|
||||||
if filePos != gcodeFile.tell():
|
if filePos != gcodeFile.tell():
|
||||||
filePos = gcodeFile.tell()
|
filePos = gcodeFile.tell()
|
||||||
if self.progressCallback != None:
|
if self.progressCallback != None:
|
||||||
self.progressCallback(float(filePos) / float(fileSize))
|
self.progressCallback(float(filePos) / float(fileSize))
|
||||||
|
|
||||||
|
#Parse Cura_SF comments
|
||||||
if line.startswith(';TYPE:'):
|
if line.startswith(';TYPE:'):
|
||||||
pathType = line[6:].strip()
|
pathType = line[6:].strip()
|
||||||
if pathType != "CUSTOM":
|
if pathType != "CUSTOM":
|
||||||
|
@ -91,8 +90,10 @@ class gcode():
|
||||||
pos.z = z * scale
|
pos.z = z * scale
|
||||||
else:
|
else:
|
||||||
pos.z += z * scale
|
pos.z += z * scale
|
||||||
|
#Check if we have a new layer.
|
||||||
if oldPos.z != pos.z and startCodeDone:
|
if oldPos.z != pos.z and startCodeDone:
|
||||||
layerNr += 1
|
self.layerList.append(currentLayer)
|
||||||
|
currentLayer = []
|
||||||
if f is not None:
|
if f is not None:
|
||||||
feedRate = f
|
feedRate = f
|
||||||
if x is not None or y is not None or z is not None:
|
if x is not None or y is not None or z is not None:
|
||||||
|
@ -116,8 +117,8 @@ class gcode():
|
||||||
if totalExtrusion > maxExtrusion:
|
if totalExtrusion > maxExtrusion:
|
||||||
maxExtrusion = totalExtrusion
|
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])
|
currentPath = gcodePath(moveType, pathType, currentPath.list[-1])
|
||||||
pathList.append(currentPath)
|
currentLayer.append(currentPath)
|
||||||
newPos = pos.copy()
|
newPos = pos.copy()
|
||||||
newPos.e = totalExtrusion
|
newPos.e = totalExtrusion
|
||||||
currentPath.list.append(newPos)
|
currentPath.list.append(newPos)
|
||||||
|
@ -183,8 +184,7 @@ class gcode():
|
||||||
else:
|
else:
|
||||||
print "Unknown M code:" + str(M)
|
print "Unknown M code:" + str(M)
|
||||||
gcodeFile.close()
|
gcodeFile.close()
|
||||||
self.layerCount = layerNr
|
self.layerList.append(currentLayer)
|
||||||
self.pathList = pathList
|
|
||||||
self.extrusionAmount = maxExtrusion
|
self.extrusionAmount = maxExtrusion
|
||||||
self.totalMoveTimeMinute = totalMoveTimeMinute
|
self.totalMoveTimeMinute = totalMoveTimeMinute
|
||||||
print "Extruded a total of: %d mm of filament" % (self.extrusionAmount)
|
print "Extruded a total of: %d mm of filament" % (self.extrusionAmount)
|
||||||
|
|
Loading…
Reference in New Issue