From 632a4475751fdbe2cba42598ba03e312659f8a3f Mon Sep 17 00:00:00 2001 From: Daid Date: Sun, 29 Apr 2012 12:00:13 +0200 Subject: [PATCH] Show print time, filemant used and cost estimate after slicing. --- Cura/gui/printWindow.py | 11 +++-------- Cura/gui/sliceProgessPanel.py | 10 +++++++++- Cura/util/gcodeInterpreter.py | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index 195b594..5f68556 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -176,14 +176,9 @@ class printWindow(wx.Frame): status = "" if self.gcode != None: status += "Filament: %.2fm %.2fg\n" % (self.gcode.extrusionAmount / 1000, self.gcode.calculateWeight() * 1000) - cost_kg = float(profile.getPreference('filament_cost_kg')) - cost_meter = float(profile.getPreference('filament_cost_meter')) - if cost_kg > 0.0 and cost_meter > 0.0: - status += "Filament cost: %.2f / %.2f\n" % (self.gcode.calculateWeight() * cost_kg, self.gcode.extrusionAmount / 1000 * cost_meter) - elif cost_kg > 0.0: - status += "Filament cost: %.2f\n" % (self.gcode.calculateWeight() * cost_kg) - elif cost_meter > 0.0: - status += "Filament cost: %.2f\n" % (self.gcode.extrusionAmount / 1000 * cost_meter) + cost = self.gcode.calculateCost() + if cost != False: + status += "Filament cost: %s\n" % (cost) status += "Print time: %02d:%02d\n" % (int(self.gcode.totalMoveTimeMinute / 60), int(self.gcode.totalMoveTimeMinute % 60)) if self.printIdx == None: self.progress.SetValue(0) diff --git a/Cura/gui/sliceProgessPanel.py b/Cura/gui/sliceProgessPanel.py index b56fc5e..c28e2cb 100644 --- a/Cura/gui/sliceProgessPanel.py +++ b/Cura/gui/sliceProgessPanel.py @@ -6,6 +6,7 @@ import wx, sys, os, math, threading, subprocess, time from util import profile from util import sliceRun from util import exporer +from util import gcodeInterpreter class sliceProgessPanel(wx.Panel): def __init__(self, mainWindow, parent, filelist): @@ -100,7 +101,12 @@ class sliceProgessPanel(wx.Panel): self.Bind(wx.EVT_BUTTON, self.OnAbort, self.abortButton) self.sizer.Add(self.logButton, 0) if result.returnCode == 0: - self.statusText.SetLabel("Ready.") + status = "Ready: Filament: %.2fm %.2fg" % (result.gcode.extrusionAmount / 1000, result.gcode.calculateWeight() * 1000) + status += " Print time: %02d:%02d\n" % (int(result.gcode.totalMoveTimeMinute / 60), int(result.gcode.totalMoveTimeMinute % 60)) + cost = result.gcode.calculateCost() + if cost != False: + status += "Cost: %s\n" % (cost) + self.statusText.SetLabel(status) if exporer.hasExporer(): self.openFileLocationButton = wx.Button(self, -1, "Open file location") self.Bind(wx.EVT_BUTTON, self.OnOpenFileLocation, self.openFileLocationButton) @@ -169,6 +175,8 @@ class WorkerThread(threading.Thread): if self.fileIdx == len(self.cmdList): if len(self.filelist) > 1: self._stitchMultiExtruder() + self.gcode = gcodeInterpreter.gcode() + self.gcode.load(self.filelist[0][:self.filelist[0].rfind('.')]+'_export.gcode') wx.CallAfter(self.notifyWindow.OnSliceDone, self) else: self.run() diff --git a/Cura/util/gcodeInterpreter.py b/Cura/util/gcodeInterpreter.py index 0518be2..7e83d3f 100644 --- a/Cura/util/gcodeInterpreter.py +++ b/Cura/util/gcodeInterpreter.py @@ -38,6 +38,17 @@ class gcode(): volumeM3 = (self.extrusionAmount * (math.pi * radius * radius)) / (1000*1000*1000) return volumeM3 * float(profile.getPreference('filament_density')) + def calculateCost(self): + cost_kg = float(profile.getPreference('filament_cost_kg')) + cost_meter = float(profile.getPreference('filament_cost_meter')) + if cost_kg > 0.0 and cost_meter > 0.0: + return "%.2f / %.2f" % (self.calculateWeight() * cost_kg, self.extrusionAmount / 1000 * cost_meter) + elif cost_kg > 0.0: + return "%.2f" % (self.calculateWeight() * cost_kg) + elif cost_meter > 0.0: + return "%.2f" % (self.extrusionAmount / 1000 * cost_meter) + return False + def _load(self, gcodeFile): filePos = 0 pos = util3d.Vector3() @@ -200,8 +211,8 @@ class gcode(): self.layerList.append(currentLayer) self.extrusionAmount = maxExtrusion self.totalMoveTimeMinute = totalMoveTimeMinute - print "Extruded a total of: %d mm of filament" % (self.extrusionAmount) - print "Estimated print duration: %.2f minutes" % (self.totalMoveTimeMinute) + #print "Extruded a total of: %d mm of filament" % (self.extrusionAmount) + #print "Estimated print duration: %.2f minutes" % (self.totalMoveTimeMinute) def getCodeInt(self, line, code): if code not in self.regMatch: