2012-02-21 14:27:03 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import __init__
|
|
|
|
|
2012-04-24 16:46:29 +00:00
|
|
|
import wx, sys, os, math, threading, subprocess, time
|
2012-02-23 14:56:03 +00:00
|
|
|
|
2012-04-12 11:58:19 +00:00
|
|
|
from util import profile
|
2012-03-28 12:26:40 +00:00
|
|
|
from util import sliceRun
|
2012-04-18 12:07:41 +00:00
|
|
|
from util import exporer
|
2012-02-21 14:27:03 +00:00
|
|
|
|
|
|
|
class sliceProgessPanel(wx.Panel):
|
2012-04-24 16:46:29 +00:00
|
|
|
def __init__(self, mainWindow, parent, filelist):
|
2012-02-21 14:27:03 +00:00
|
|
|
wx.Panel.__init__(self, parent, -1)
|
2012-02-21 15:37:31 +00:00
|
|
|
self.mainWindow = mainWindow
|
2012-04-24 16:46:29 +00:00
|
|
|
self.filelist = filelist
|
2012-02-21 14:27:03 +00:00
|
|
|
self.abort = False
|
2012-02-23 14:56:03 +00:00
|
|
|
|
|
|
|
#How long does each step take compared to the others. This is used to make a better scaled progress bar, and guess time left.
|
|
|
|
self.sliceStepTimeFactor = {
|
|
|
|
'start': 3.3713991642,
|
|
|
|
'slice': 15.4984838963,
|
|
|
|
'preface': 5.17178297043,
|
|
|
|
'inset': 116.362634182,
|
|
|
|
'fill': 215.702672005,
|
|
|
|
'multiply': 21.9536788464,
|
|
|
|
'speed': 12.759510994,
|
|
|
|
'raft': 31.4580039978,
|
|
|
|
'skirt': 19.3436040878,
|
2012-04-07 14:27:22 +00:00
|
|
|
'skin': 1.0,
|
2012-02-27 16:21:50 +00:00
|
|
|
'joris': 1.0,
|
2012-02-23 14:56:03 +00:00
|
|
|
'comb': 23.7805759907,
|
|
|
|
'cool': 27.148763895,
|
|
|
|
'dimension': 90.4914340973
|
|
|
|
}
|
|
|
|
self.totalRunTimeFactor = 0
|
|
|
|
for v in self.sliceStepTimeFactor.itervalues():
|
|
|
|
self.totalRunTimeFactor += v
|
2012-02-21 14:27:03 +00:00
|
|
|
|
2012-04-24 16:46:29 +00:00
|
|
|
box = wx.StaticBox(self, -1, filelist[0])
|
2012-02-21 22:05:30 +00:00
|
|
|
self.sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)
|
|
|
|
|
2012-02-21 14:27:03 +00:00
|
|
|
mainSizer = wx.BoxSizer(wx.VERTICAL)
|
2012-02-21 22:05:30 +00:00
|
|
|
mainSizer.Add(self.sizer, 0, flag=wx.EXPAND)
|
2012-02-21 14:27:03 +00:00
|
|
|
|
|
|
|
self.statusText = wx.StaticText(self, -1, "Starting...")
|
|
|
|
self.progressGauge = wx.Gauge(self, -1)
|
2012-02-23 14:56:03 +00:00
|
|
|
self.progressGauge.SetRange(10000)
|
2012-02-21 14:27:03 +00:00
|
|
|
self.abortButton = wx.Button(self, -1, "X", style=wx.BU_EXACTFIT)
|
2012-02-21 22:05:30 +00:00
|
|
|
self.sizer.Add(self.statusText, 2, flag=wx.ALIGN_CENTER )
|
|
|
|
self.sizer.Add(self.progressGauge, 2)
|
|
|
|
self.sizer.Add(self.abortButton, 0)
|
|
|
|
|
2012-02-21 14:27:03 +00:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnAbort, self.abortButton)
|
|
|
|
|
|
|
|
self.SetSizer(mainSizer)
|
2012-02-23 14:56:03 +00:00
|
|
|
self.prevStep = 'start'
|
|
|
|
self.totalDoneFactor = 0.0
|
|
|
|
self.startTime = time.time()
|
2012-04-12 11:58:19 +00:00
|
|
|
if profile.getPreference('save_profile') == 'True':
|
2012-04-24 16:46:29 +00:00
|
|
|
profile.saveGlobalProfile(self.filelist[0][: self.filelist[0].rfind('.')] + "_profile.ini")
|
|
|
|
cmdList = []
|
|
|
|
oldProfile = profile.getGlobalProfileString()
|
|
|
|
for filename in self.filelist:
|
|
|
|
if self.filelist.index(filename) > 0:
|
|
|
|
profile.putProfileSetting('fan_enabled', 'False')
|
|
|
|
if len(self.filelist) > 1:
|
|
|
|
profile.putProfileSetting('add_start_end_gcode', 'False')
|
|
|
|
profile.putProfileSetting('gcode_extension', 'multi_extrude_tmp')
|
|
|
|
cmdList.append(sliceRun.getSliceCommand(filename))
|
|
|
|
profile.loadGlobalProfileFromString(oldProfile)
|
|
|
|
self.thread = WorkerThread(self, filelist, cmdList)
|
2012-02-21 14:27:03 +00:00
|
|
|
|
|
|
|
def OnAbort(self, e):
|
|
|
|
if self.abort:
|
2012-02-21 15:37:31 +00:00
|
|
|
self.mainWindow.removeSliceProgress(self)
|
2012-02-21 14:27:03 +00:00
|
|
|
else:
|
|
|
|
self.abort = True
|
2012-02-21 22:05:30 +00:00
|
|
|
|
|
|
|
def OnShowGCode(self, e):
|
2012-04-24 16:46:29 +00:00
|
|
|
self.mainWindow.preview3d.loadModelFiles(self.filelist)
|
2012-03-23 13:04:50 +00:00
|
|
|
self.mainWindow.preview3d.setViewMode("GCode")
|
2012-02-21 22:05:30 +00:00
|
|
|
|
2012-03-05 17:53:19 +00:00
|
|
|
def OnShowLog(self, e):
|
|
|
|
LogWindow('\n'.join(self.progressLog))
|
|
|
|
|
2012-04-18 12:07:41 +00:00
|
|
|
def OnOpenFileLocation(self, e):
|
2012-04-24 16:46:29 +00:00
|
|
|
exporer.openExporer(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode")
|
2012-04-18 12:07:41 +00:00
|
|
|
|
2012-03-05 17:53:19 +00:00
|
|
|
def OnSliceDone(self, result):
|
2012-02-21 22:05:30 +00:00
|
|
|
self.progressGauge.Destroy()
|
2012-03-20 13:50:22 +00:00
|
|
|
self.abortButton.Destroy()
|
2012-03-05 17:53:19 +00:00
|
|
|
self.progressLog = result.progressLog
|
2012-03-11 10:56:50 +00:00
|
|
|
self.logButton = wx.Button(self, -1, "Show Log")
|
2012-03-20 13:50:22 +00:00
|
|
|
self.abortButton = wx.Button(self, -1, "X", style=wx.BU_EXACTFIT)
|
2012-03-11 10:56:50 +00:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnShowLog, self.logButton)
|
2012-03-20 13:50:22 +00:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnAbort, self.abortButton)
|
2012-03-11 10:56:50 +00:00
|
|
|
self.sizer.Add(self.logButton, 0)
|
2012-03-05 17:53:19 +00:00
|
|
|
if result.returnCode == 0:
|
2012-02-24 22:01:22 +00:00
|
|
|
self.statusText.SetLabel("Ready.")
|
2012-04-18 12:07:41 +00:00
|
|
|
if exporer.hasExporer():
|
|
|
|
self.openFileLocationButton = wx.Button(self, -1, "Open file location")
|
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnOpenFileLocation, self.openFileLocationButton)
|
|
|
|
self.sizer.Add(self.openFileLocationButton, 0)
|
2012-03-19 15:15:16 +00:00
|
|
|
self.showButton = wx.Button(self, -1, "Show result")
|
2012-02-24 22:01:22 +00:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnShowGCode, self.showButton)
|
|
|
|
self.sizer.Add(self.showButton, 0)
|
|
|
|
else:
|
2012-03-05 17:53:19 +00:00
|
|
|
self.statusText.SetLabel("Something went wrong during slicing!")
|
2012-03-11 10:56:50 +00:00
|
|
|
self.sizer.Add(self.abortButton, 0)
|
2012-02-21 22:05:30 +00:00
|
|
|
self.sizer.Layout()
|
2012-03-09 16:33:40 +00:00
|
|
|
self.Layout()
|
2012-02-21 22:05:30 +00:00
|
|
|
self.abort = True
|
2012-04-24 16:46:29 +00:00
|
|
|
if self.mainWindow.preview3d.loadReModelFiles(self.filelist):
|
2012-03-23 13:04:50 +00:00
|
|
|
self.mainWindow.preview3d.setViewMode("GCode")
|
2012-02-23 14:56:03 +00:00
|
|
|
|
|
|
|
def SetProgress(self, stepName, layer, maxLayer):
|
|
|
|
if self.prevStep != stepName:
|
|
|
|
self.totalDoneFactor += self.sliceStepTimeFactor[self.prevStep]
|
|
|
|
newTime = time.time()
|
|
|
|
#print "#####" + str(newTime-self.startTime) + " " + self.prevStep + " -> " + stepName
|
|
|
|
self.startTime = newTime
|
|
|
|
self.prevStep = stepName
|
|
|
|
|
|
|
|
progresValue = ((self.totalDoneFactor + self.sliceStepTimeFactor[stepName] * layer / maxLayer) / self.totalRunTimeFactor) * 10000
|
|
|
|
self.progressGauge.SetValue(int(progresValue))
|
|
|
|
self.statusText.SetLabel(stepName + " [" + str(layer) + "/" + str(maxLayer) + "]")
|
2012-02-21 14:27:03 +00:00
|
|
|
|
|
|
|
class WorkerThread(threading.Thread):
|
2012-04-24 16:46:29 +00:00
|
|
|
def __init__(self, notifyWindow, filelist, cmdList):
|
2012-02-21 14:27:03 +00:00
|
|
|
threading.Thread.__init__(self)
|
2012-04-24 16:46:29 +00:00
|
|
|
self.filelist = filelist
|
2012-02-21 14:27:03 +00:00
|
|
|
self.notifyWindow = notifyWindow
|
2012-04-24 16:46:29 +00:00
|
|
|
self.cmdList = cmdList
|
|
|
|
self.fileIdx = 0
|
2012-02-21 14:27:03 +00:00
|
|
|
self.start()
|
|
|
|
|
|
|
|
def run(self):
|
2012-04-24 16:46:29 +00:00
|
|
|
p = subprocess.Popen(self.cmdList[self.fileIdx], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
2012-02-21 14:27:03 +00:00
|
|
|
line = p.stdout.readline()
|
2012-03-05 17:53:19 +00:00
|
|
|
self.progressLog = []
|
2012-04-24 16:46:29 +00:00
|
|
|
maxValue = 1
|
2012-02-21 14:27:03 +00:00
|
|
|
while(len(line) > 0):
|
|
|
|
line = line.rstrip()
|
|
|
|
if line[0:9] == "Progress[" and line[-1:] == "]":
|
|
|
|
progress = line[9:-1].split(":")
|
|
|
|
if len(progress) > 2:
|
|
|
|
maxValue = int(progress[2])
|
2012-02-23 14:56:03 +00:00
|
|
|
wx.CallAfter(self.notifyWindow.SetProgress, progress[0], int(progress[1]), maxValue)
|
2012-02-21 14:27:03 +00:00
|
|
|
else:
|
2012-02-23 14:56:03 +00:00
|
|
|
print line
|
2012-03-05 17:53:19 +00:00
|
|
|
self.progressLog.append(line)
|
2012-02-21 14:27:03 +00:00
|
|
|
wx.CallAfter(self.notifyWindow.statusText.SetLabel, line)
|
|
|
|
if self.notifyWindow.abort:
|
|
|
|
p.terminate()
|
|
|
|
wx.CallAfter(self.notifyWindow.statusText.SetLabel, "Aborted by user.")
|
|
|
|
return
|
|
|
|
line = p.stdout.readline()
|
2012-03-05 17:53:19 +00:00
|
|
|
self.returnCode = p.wait()
|
2012-04-24 16:46:29 +00:00
|
|
|
logfile = open(self.filelist[self.fileIdx][: self.filelist[self.fileIdx].rfind('.')] + "_export.log", "w")
|
2012-03-15 14:25:16 +00:00
|
|
|
for logLine in self.progressLog:
|
|
|
|
logfile.write(logLine)
|
|
|
|
logfile.write('\n')
|
|
|
|
logfile.close()
|
2012-04-24 16:46:29 +00:00
|
|
|
self.fileIdx += 1
|
|
|
|
if self.fileIdx == len(self.cmdList):
|
|
|
|
if len(self.filelist) > 1:
|
|
|
|
self._stitchMultiExtruder()
|
|
|
|
wx.CallAfter(self.notifyWindow.OnSliceDone, self)
|
|
|
|
else:
|
|
|
|
self.run()
|
|
|
|
|
|
|
|
def _stitchMultiExtruder(self):
|
|
|
|
files = []
|
|
|
|
resultFile = open(self.filelist[0][:self.filelist[0].rfind('.')]+'_export.gcode', "w")
|
|
|
|
resultFile.write(';TYPE:CUSTOM\n')
|
|
|
|
resultFile.write(unicode(profile.getAlterationFileContents('start.gcode')).encode('utf-8'))
|
|
|
|
for filename in self.filelist:
|
|
|
|
files.append(open(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp', "r"))
|
|
|
|
|
|
|
|
hasLine = True
|
|
|
|
while hasLine:
|
|
|
|
hasLine = False
|
|
|
|
for f in files:
|
|
|
|
for line in f:
|
|
|
|
resultFile.write(line)
|
|
|
|
hasLine = True
|
|
|
|
if line.startswith(';LAYER:'):
|
|
|
|
break
|
|
|
|
for f in files:
|
|
|
|
f.close()
|
|
|
|
for filename in self.filelist:
|
|
|
|
os.remove(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp')
|
|
|
|
resultFile.write(';TYPE:CUSTOM\n')
|
|
|
|
resultFile.write(unicode(profile.getAlterationFileContents('end.gcode')).encode('utf-8'))
|
|
|
|
resultFile.close()
|
2012-03-05 17:53:19 +00:00
|
|
|
|
|
|
|
class LogWindow(wx.Frame):
|
|
|
|
def __init__(self, logText):
|
|
|
|
super(LogWindow, self).__init__(None, title="Slice log")
|
|
|
|
self.textBox = wx.TextCtrl(self, -1, logText, style=wx.TE_MULTILINE|wx.TE_DONTWRAP|wx.TE_READONLY)
|
|
|
|
self.SetSize((400,300))
|
|
|
|
self.Centre()
|
|
|
|
self.Show(True)
|
2012-02-23 14:56:03 +00:00
|
|
|
|