2012-02-21 14:27:03 +00:00
|
|
|
from __future__ import absolute_import
|
|
|
|
import __init__
|
|
|
|
|
2012-02-23 14:56:03 +00:00
|
|
|
import wx
|
|
|
|
import sys
|
|
|
|
import math
|
|
|
|
import threading
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
|
2012-03-28 12:26:40 +00:00
|
|
|
from util import sliceRun
|
2012-02-21 14:27:03 +00:00
|
|
|
|
|
|
|
class sliceProgessPanel(wx.Panel):
|
2012-02-21 15:37:31 +00:00
|
|
|
def __init__(self, mainWindow, parent, filename):
|
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-02-21 14:27:03 +00:00
|
|
|
self.filename = filename
|
|
|
|
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
|
|
|
|
|
|
|
box = wx.StaticBox(self, -1, filename)
|
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-03-30 11:54:49 +00:00
|
|
|
p = subprocess.Popen(sliceRun.getSliceCommand(self.filename), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
self.thread = WorkerThread(self, filename, p)
|
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-03-18 12:00:31 +00:00
|
|
|
self.mainWindow.preview3d.loadModelFile(self.filename)
|
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))
|
|
|
|
|
|
|
|
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-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-03-23 13:04:50 +00:00
|
|
|
if self.mainWindow.preview3d.loadReModelFile(self.filename):
|
|
|
|
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-03-30 11:54:49 +00:00
|
|
|
def __init__(self, notifyWindow, filename, process):
|
2012-02-21 14:27:03 +00:00
|
|
|
threading.Thread.__init__(self)
|
|
|
|
self.filename = filename
|
|
|
|
self.notifyWindow = notifyWindow
|
2012-03-30 11:54:49 +00:00
|
|
|
self.process = process
|
2012-02-21 14:27:03 +00:00
|
|
|
self.start()
|
|
|
|
|
|
|
|
def run(self):
|
2012-03-30 11:54:49 +00:00
|
|
|
p = self.process
|
2012-02-21 14:27:03 +00:00
|
|
|
line = p.stdout.readline()
|
|
|
|
maxValue = 1
|
2012-03-05 17:53:19 +00:00
|
|
|
self.progressLog = []
|
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-03-15 14:25:16 +00:00
|
|
|
logfile = open(self.filename[: self.filename.rfind('.')] + "_export.log", "w")
|
|
|
|
for logLine in self.progressLog:
|
|
|
|
logfile.write(logLine)
|
|
|
|
logfile.write('\n')
|
|
|
|
logfile.close()
|
2012-03-05 17:53:19 +00:00
|
|
|
wx.CallAfter(self.notifyWindow.OnSliceDone, self)
|
|
|
|
|
|
|
|
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
|
|
|
|