From c2ce7b9c243b25b46f4bdf66fe1fc5b894c69149 Mon Sep 17 00:00:00 2001 From: daid Date: Tue, 3 Apr 2012 12:06:02 +0200 Subject: [PATCH] Updated print window with statistics about the print. Filament used, and estimated print time. --- Cura/gui/preferencesDialog.py | 4 ++++ Cura/gui/printWindow.py | 21 ++++++++++++++------- Cura/util/gcodeInterpreter.py | 7 +++++++ Cura/util/profile.py | 1 + 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Cura/gui/preferencesDialog.py b/Cura/gui/preferencesDialog.py index 564a583c..782ee338 100644 --- a/Cura/gui/preferencesDialog.py +++ b/Cura/gui/preferencesDialog.py @@ -25,6 +25,10 @@ class preferencesDialog(configBase.configWindowBase): c = configBase.SettingRow(left, 'Machine height (mm)', 'machine_height', '200', 'Size of the machine in mm', type = 'preference') validators.validFloat(c, 10.0) + configBase.TitleRow(left, 'Filament settings') + c = configBase.SettingRow(left, 'Filament density (kg/m3)', 'filament_density', '1300', 'Weight of the filament per m3. Around 1300 for PLA. And around 1040 for ABS. This value is used to estimate the weight if the filament used for the print.', type = 'preference') + validators.validFloat(c, 500.0, 3000.0) + configBase.TitleRow(left, 'Communication settings') c = configBase.SettingRow(left, 'Serial port', 'serial_port', ['AUTO'] + machineCom.serialList(), 'Serial port to use for communication with the printer', type = 'preference') c = configBase.SettingRow(left, 'Baudrate', 'serial_baud', '250000', 'Speed of the serial port communication\nNeeds to match your firmware settings\nCommon values are 250000, 115200, 57600', type = 'preference') diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index f4c22e03..ea86a6c9 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -24,6 +24,7 @@ class printWindow(wx.Frame): self.machineCom = None self.machineConnected = False self.thread = None + self.gcode = None self.gcodeList = None self.printIdx = None self.bufferLineCount = 4 @@ -78,8 +79,13 @@ class printWindow(wx.Frame): def UpdateProgress(self): status = "" + if self.gcode != None: + status += "Filament: %.2fm %.2fg\n" % (self.gcode.extrusionAmount / 1000, self.gcode.calculateWeight() * 1000) + status += "Print time: %02d:%02d\n" % (int(self.gcode.totalMoveTimeMinute / 60), int(self.gcode.totalMoveTimeMinute % 60)) if self.printIdx == None: self.progress.SetValue(0) + if self.gcodeList != None: + status += 'Line: -/%d\n' % (len(self.gcodeList)) else: self.progress.SetValue(self.printIdx) status += 'Line: %d/%d\n' % (self.printIdx, len(self.gcodeList)) @@ -131,19 +137,19 @@ class printWindow(wx.Frame): gcodeList.append(line) gcode = gcodeInterpreter.gcode() gcode.loadList(gcodeList) - print gcode.extrusionAmount - print gcode.totalMoveTimeMinute print "Loaded: %s (%d)" % (filename, len(gcodeList)) self.progress.SetRange(len(gcodeList)) + self.gcode = gcode self.gcodeList = gcodeList self.UpdateButtonStates() self.UpdateProgress() def sendLine(self, lineNr): if lineNr >= len(self.gcodeList): - return + return False checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (lineNr, self.gcodeList[lineNr]))) self.machineCom.sendCommand("N%d%s*%d" % (lineNr, self.gcodeList[lineNr], checksum)) + return True def PrinterMonitor(self): skipCount = 0 @@ -151,7 +157,7 @@ class printWindow(wx.Frame): line = self.machineCom.readline() if line == None: self.machineConnected = False - wx.CallAfter(self.UpdateButtonState) + wx.CallAfter(self.UpdateButtonStates) return if self.machineConnected: while self.sendCnt > 0: @@ -160,14 +166,14 @@ class printWindow(wx.Frame): self.sendCnt -= 1 elif line.startswith("start"): self.machineConnected = True - wx.CallAfter(self.UpdateButtonState) + wx.CallAfter(self.UpdateButtonStates) if self.printIdx != None: if line.startswith("ok"): if skipCount > 0: skipCount -= 1 else: - self.sendLine(self.printIdx) - self.printIdx += 1 + if self.sendLine(self.printIdx): + self.printIdx += 1 wx.CallAfter(self.UpdateProgress) elif "resend" in line.lower() or "rs" in line: try: @@ -177,3 +183,4 @@ class printWindow(wx.Frame): lineNr=int(line.split()[1]) self.printIdx = lineNr #we should actually resend the line here, but we also get an "ok" for each error from Marlin. And thus we'll resend on the OK. + diff --git a/Cura/util/gcodeInterpreter.py b/Cura/util/gcodeInterpreter.py index 06ebd5ac..3570d49e 100644 --- a/Cura/util/gcodeInterpreter.py +++ b/Cura/util/gcodeInterpreter.py @@ -7,6 +7,7 @@ import re import os from util import util3d +from util import profile class gcodePath(): def __init__(self, newType, pathType, startPoint): @@ -31,6 +32,12 @@ class gcode(): def loadList(self, l): self._load(l) + def calculateWeight(self): + #Calculates the weight of the filament in kg + radius = float(profile.getProfileSetting('filament_diameter')) / 2 + volumeM3 = (self.extrusionAmount * (math.pi * radius * radius)) / (1000*1000*1000) + return volumeM3 * float(profile.getPreference('filament_density')) + def _load(self, gcodeFile): filePos = 0 pos = util3d.Vector3() diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 2548ec81..5845e14c 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -69,6 +69,7 @@ preferencesDefaultSettings = { 'machine_width': '205', 'machine_depth': '205', 'machine_height': '200', + 'filament_density': '1300', 'steps_per_e': '0', 'serial_port': 'AUTO', 'serial_baud': '250000', -- 2.30.2