Only have 1 load thread at a time, else we run into strange bugs

master
daid 2012-03-22 16:04:53 +01:00
parent ef26c9029e
commit a0fb01ba49
2 changed files with 38 additions and 16 deletions

View File

@ -10,9 +10,15 @@ import os
from newui import util3d from newui import util3d
class gcode(): class gcode():
def __init__(self, filename): def __init__(self):
self.regMatch = {} self.regMatch = {}
self.layerCount = 0
self.pathList = []
self.extrusionAmount = 0
self.totalMoveTimeMinute = 0
self.progressCallback = None
def load(self, filename):
fileSize = os.stat(filename).st_size fileSize = os.stat(filename).st_size
filePos = 0 filePos = 0
gcodeFile = open(filename, 'r') gcodeFile = open(filename, 'r')
@ -34,7 +40,8 @@ class gcode():
for line in gcodeFile: for line in gcodeFile:
if filePos != gcodeFile.tell(): if filePos != gcodeFile.tell():
filePos = gcodeFile.tell() filePos = gcodeFile.tell()
#print float(filePos) / float(fileSize) if self.progressCallback != None:
self.progressCallback(float(filePos) / float(fileSize))
if line.startswith(';TYPE:'): if line.startswith(';TYPE:'):
pathType = line[6:].strip() pathType = line[6:].strip()
if pathType != "CUSTOM": if pathType != "CUSTOM":
@ -185,5 +192,5 @@ class gcode():
if __name__ == '__main__': if __name__ == '__main__':
for filename in sys.argv[1:]: for filename in sys.argv[1:]:
gcode(filename) gcode().load(filename)

View File

@ -36,6 +36,8 @@ class previewPanel(wx.Panel):
self.triangleMesh = None self.triangleMesh = None
self.gcode = None self.gcode = None
self.modelFilename = None self.modelFilename = None
self.loadingProgressAmount = 0
self.loadThread = None
self.machineSize = Vector3(float(profile.getPreference('machine_width')), float(profile.getPreference('machine_depth')), float(profile.getPreference('machine_height'))) self.machineSize = Vector3(float(profile.getPreference('machine_width')), float(profile.getPreference('machine_depth')), float(profile.getPreference('machine_height')))
self.machineCenter = Vector3(0, 0, 0) self.machineCenter = Vector3(0, 0, 0)
@ -192,15 +194,19 @@ class previewPanel(wx.Panel):
self.gcodeFilename = filename[: filename.rfind('.')] + "_export.gcode" self.gcodeFilename = filename[: filename.rfind('.')] + "_export.gcode"
self.logFilename = filename[: filename.rfind('.')] + "_export.log" self.logFilename = filename[: filename.rfind('.')] + "_export.log"
#Do the STL file loading in a background thread so we don't block the UI. #Do the STL file loading in a background thread so we don't block the UI.
threading.Thread(target=self.doFileLoad).start() if self.loadThread != None and self.loadThread.isAlive():
self.loadThread.join()
self.loadThread = threading.Thread(target=self.doFileLoadThread)
self.loadThread.daemon = True
self.loadThread.start()
def loadReModelFile(self, filename): def loadReModelFile(self, filename):
#Only load this again if the filename matches the file we have already loaded (for auto loading GCode after slicing) #Only load this again if the filename matches the file we have already loaded (for auto loading GCode after slicing)
if self.modelFilename != filename: if self.modelFilename != filename:
return return
threading.Thread(target=self.doFileLoad).start() self.loadModelFile(filename)
def doFileLoad(self): def doFileLoadThread(self):
if os.path.isfile(self.modelFilename) and self.modelFileTime != os.stat(self.modelFilename).st_mtime: if os.path.isfile(self.modelFilename) and self.modelFileTime != os.stat(self.modelFilename).st_mtime:
self.modelFileTime = os.stat(self.modelFilename).st_mtime self.modelFileTime = os.stat(self.modelFilename).st_mtime
triangleMesh = fabmetheus_interpret.getCarving(self.modelFilename) triangleMesh = fabmetheus_interpret.getCarving(self.modelFilename)
@ -217,7 +223,10 @@ class previewPanel(wx.Panel):
if os.path.isfile(self.gcodeFilename) and self.gcodeFileTime != os.stat(self.gcodeFilename).st_mtime: if os.path.isfile(self.gcodeFilename) and self.gcodeFileTime != os.stat(self.gcodeFilename).st_mtime:
self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime
gcode = gcodeInterpreter.gcode(self.gcodeFilename) gcode = gcodeInterpreter.gcode()
gcode.progressCallback = self.loadProgress
gcode.load(self.gcodeFilename)
self.loadingProgressAmount = 0
self.gcodeDirty = False self.gcodeDirty = False
self.errorList = [] self.errorList = []
self.gcode = gcode self.gcode = gcode
@ -238,6 +247,10 @@ class previewPanel(wx.Panel):
self.errorList = errorList self.errorList = errorList
wx.CallAfter(self.glCanvas.Refresh) wx.CallAfter(self.glCanvas.Refresh)
def loadProgress(self, progress):
self.loadingProgressAmount = progress
wx.CallAfter(self.glCanvas.Refresh)
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:
@ -480,15 +493,16 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
glVertex3f(v3.x, v3.y, v3.z - 0.01) glVertex3f(v3.x, v3.y, v3.z - 0.01)
glVertex3f(v2.x, v2.y, v2.z - 0.01) glVertex3f(v2.x, v2.y, v2.z - 0.01)
glEnd() glEnd()
for v in path['list']:
glBegin(GL_TRIANGLE_FAN) #for v in path['list']:
glVertex3f(v.x, v.y, v.z - 0.001) # glBegin(GL_TRIANGLE_FAN)
for i in xrange(0, 16+1): # glVertex3f(v.x, v.y, v.z - 0.001)
if path['pathType'] == 'FILL': #Remove depth buffer fighting on infill/wall overlap # for i in xrange(0, 16+1):
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) # if path['pathType'] == 'FILL': #Remove depth buffer fighting on infill/wall overlap
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.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.01) # else:
glEnd() # 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()
else: else:
glBegin(GL_LINE_STRIP) glBegin(GL_LINE_STRIP)
for v in path['list']: for v in path['list']:
@ -601,6 +615,7 @@ class PreviewGLCanvas(glcanvas.GLCanvas):
glVertex3f(err[0].x, err[0].y, err[0].z) glVertex3f(err[0].x, err[0].y, err[0].z)
glVertex3f(err[1].x, err[1].y, err[1].z) glVertex3f(err[1].x, err[1].y, err[1].z)
glEnd() glEnd()
glFlush() glFlush()
def InitGL(self): def InitGL(self):