def LoadGCodeFile(self, filename): if self.machineCom != None and self.machineCom.isPrinting(): return #Send an initial M110 to reset the line counter to zero. prevLineType = lineType = 'CUSTOM' gcodeList = ["M110"] for line in open(filename, 'r'): if line.startswith(';TYPE:'): lineType = line[6:].strip() if ';' in line: line = line[0:line.find(';')] line = line.strip() if len(line) > 0: if prevLineType != lineType: gcodeList.append((line, lineType, )) else: gcodeList.append(line) prevLineType = lineType gcode = gcodeInterpreter.gcode() gcode.loadList(gcodeList) #print "Loaded: %s (%d)" % (filename, len(gcodeList)) self.filename = filename self.gcode = gcode self.gcodeList = gcodeList wx.CallAfter(self.progress.SetRange, len(gcodeList)) wx.CallAfter(self.UpdateButtonStates) wx.CallAfter(self.UpdateProgress) wx.CallAfter(self.SetTitle, 'Printing: %s' % (filename))
def doFileLoadThread(self): for obj in self.objectList: if obj.filename != None and os.path.isfile(obj.filename) and obj.fileTime != os.stat(obj.filename).st_mtime: obj.ileTime = os.stat(obj.filename).st_mtime mesh = stl.stlModel() mesh.load(obj.filename) obj.dirty = False obj.mesh = mesh self.updateModelTransform() self.errorList = [] wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) if os.path.isfile(self.gcodeFilename) and self.gcodeFileTime != os.stat(self.gcodeFilename).st_mtime: self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime gcode = gcodeInterpreter.gcode() gcode.progressCallback = self.loadProgress gcode.load(self.gcodeFilename) self.gcodeDirty = False self.gcode = gcode self.gcodeDirty = True errorList = [] for line in open(self.gcodeFilename, "rt"): res = re.search(';Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)', line) if res != None: v1 = util3d.Vector3(float(res.group(2)), float(res.group(3)), float(res.group(4))) v2 = util3d.Vector3(float(res.group(5)), float(res.group(6)), float(res.group(7))) errorList.append([v1, v2]) self.errorList = errorList wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) elif not os.path.isfile(self.gcodeFilename): self.gcode = None
def LoadGCodeFile(self, filename): if self.printIdx != None: return #Send an initial M110 to reset the line counter to zero. lineType = 'CUSTOM' gcodeList = ["M110"] typeList = [lineType] for line in open(filename, 'r'): if line.startswith(';TYPE:'): lineType = line[6:].strip() if ';' in line: line = line[0:line.find(';')] line = line.strip() if len(line) > 0: gcodeList.append(line) typeList.append(lineType) gcode = gcodeInterpreter.gcode() gcode.loadList(gcodeList) print "Loaded: %s (%d)" % (filename, len(gcodeList)) self.gcode = gcode self.gcodeList = gcodeList self.typeList = typeList wx.CallAfter(self.progress.SetRange, len(gcodeList)) wx.CallAfter(self.UpdateButtonStates) wx.CallAfter(self.UpdateProgress)
def run(self): p = sliceRun.startSliceCommandProcess(self.cmdList[0]) line = p.stdout.readline() self.progressLog = [] maxValue = 1 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]) wx.CallAfter(self.notifyWindow.SetProgress, progress[0], int(progress[1]), maxValue) else: self.progressLog.append(line) line = p.stdout.readline() self.returnCode = p.wait() gcodeFilename = sliceRun.getExportFilename(self.filename) gcodefile = open(gcodeFilename, "a") for logLine in self.progressLog: if logLine.startswith('Model error('): gcodefile.write(';%s\n' % (logLine)) gcodefile.close() self.gcode = gcodeInterpreter.gcode() self.gcode.load(gcodeFilename) profile.replaceGCodeTags(gcodeFilename, self.gcode) wx.CallAfter(self.notifyWindow.OnSliceDone, self)
def doFileLoadThread(self): for obj in self.objectList: if obj.filename != None and os.path.isfile( obj.filename) and obj.fileTime != os.stat( obj.filename).st_mtime: obj.ileTime = os.stat(obj.filename).st_mtime mesh = meshLoader.loadMesh(obj.filename) obj.dirty = False obj.mesh = mesh self.updateModelTransform() scale = profile.getProfileSettingFloat('model_scale') size = (self.objectsMaxV - self.objectsMinV) * scale if size[0] > self.machineSize.x or size[ 1] > self.machineSize.y or size[2] > self.machineSize.z: self.OnScaleMax(None) self.glCanvas.zoom = numpy.max(size) * 2.5 self.errorList = [] wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) if os.path.isfile( self.gcodeFilename) and self.gcodeFileTime != os.stat( self.gcodeFilename).st_mtime: self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime gcode = gcodeInterpreter.gcode() gcode.progressCallback = self.loadProgress gcode.load(self.gcodeFilename) self.gcodeDirty = False self.gcode = gcode self.gcodeDirty = True errorList = [] for line in open(self.gcodeFilename, "rt"): res = re.search( ';Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)', line) if res != None: v1 = util3d.Vector3(float(res.group(2)), float(res.group(3)), float(res.group(4))) v2 = util3d.Vector3(float(res.group(5)), float(res.group(6)), float(res.group(7))) errorList.append([v1, v2]) self.errorList = errorList wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) elif not os.path.isfile(self.gcodeFilename): self.gcode = None
def doFileLoadThread(self): for obj in self.objectList: if obj.filename != None and os.path.isfile( obj.filename) and obj.fileTime != os.stat( obj.filename).st_mtime: obj.ileTime = os.stat(obj.filename).st_mtime mesh = stl.stlModel() mesh.load(obj.filename) obj.dirty = False obj.mesh = mesh self.updateModelTransform() wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) if os.path.isfile( self.gcodeFilename) and self.gcodeFileTime != os.stat( self.gcodeFilename).st_mtime: self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime gcode = gcodeInterpreter.gcode() gcode.progressCallback = self.loadProgress gcode.load(self.gcodeFilename) self.gcodeDirty = False self.errorList = [] self.gcode = gcode self.gcodeDirty = True wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) elif not os.path.isfile(self.gcodeFilename): self.gcode = None if os.path.isfile(self.logFilename): errorList = [] for line in open(self.logFilename, "rt"): res = re.search( 'Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)', line) if res != None: v1 = util3d.Vector3(float(res.group(2)), float(res.group(3)), float(res.group(4))) v2 = util3d.Vector3(float(res.group(5)), float(res.group(6)), float(res.group(7))) errorList.append([v1, v2]) self.errorList = errorList wx.CallAfter(self.glCanvas.Refresh)
def run(self): p = sliceRun.startSliceCommandProcess(self.cmdList[self.fileIdx]) line = p.stdout.readline() self.progressLog = [] maxValue = 1 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]) wx.CallAfter(self.notifyWindow.SetProgress, progress[0], int(progress[1]), maxValue) else: self.progressLog.append(line) 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() self.returnCode = p.wait() self.fileIdx += 1 if self.fileIdx == len(self.cmdList): if len(self.filelist) > 1: self._stitchMultiExtruder() gcodeFilename = sliceRun.getExportFilename(self.filelist[0]) gcodefile = open(gcodeFilename, "a") for logLine in self.progressLog: if logLine.startswith('Model error('): gcodefile.write(';%s\n' % (logLine)) gcodefile.close() wx.CallAfter(self.notifyWindow.statusText.SetLabel, "Running plugins") ret = profile.runPostProcessingPlugins(gcodeFilename) if ret != None: self.progressLog.append(ret) self.gcode = gcodeInterpreter.gcode() self.gcode.load(gcodeFilename) profile.replaceGCodeTags(gcodeFilename, self.gcode) wx.CallAfter(self.notifyWindow.OnSliceDone, self) else: self.run()
def LoadGCodeFile(self, filename): if self.printIdx != None: return #Send an initial M110 to reset the line counter to zero. gcodeList = ["M110"] for line in open(filename, 'r'): if ';' in line: line = line[0:line.find(';')] line = line.strip() if len(line) > 0: gcodeList.append(line) gcode = gcodeInterpreter.gcode() gcode.loadList(gcodeList) print "Loaded: %s (%d)" % (filename, len(gcodeList)) self.progress.SetRange(len(gcodeList)) self.gcode = gcode self.gcodeList = gcodeList self.UpdateButtonStates() self.UpdateProgress()
def run(self): p = subprocess.Popen(self.cmdList[self.fileIdx], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) line = p.stdout.readline() self.progressLog = [] maxValue = 1 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]) wx.CallAfter(self.notifyWindow.SetProgress, progress[0], int(progress[1]), maxValue) else: #print line self.progressLog.append(line) 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() self.returnCode = p.wait() logfile = open( sliceRun.getExportFilename(self.filelist[self.fileIdx], "log"), "w") for logLine in self.progressLog: logfile.write(logLine) logfile.write('\n') logfile.close() self.fileIdx += 1 if self.fileIdx == len(self.cmdList): if len(self.filelist) > 1: self._stitchMultiExtruder() self.gcode = gcodeInterpreter.gcode() self.gcode.load(sliceRun.getExportFilename(self.filelist[0])) wx.CallAfter(self.notifyWindow.OnSliceDone, self) else: self.run()
def run(self): p = sliceRun.startSliceCommandProcess(self.cmdList[self.fileIdx]) line = p.stdout.readline() self.progressLog = [] maxValue = 1 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]) wx.CallAfter(self.notifyWindow.SetProgress, progress[0], int(progress[1]), maxValue) else: self.progressLog.append(line) 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() self.returnCode = p.wait() self.fileIdx += 1 if self.fileIdx == len(self.cmdList): if len(self.filelist) > 1: self._stitchMultiExtruder() gcodeFilename = sliceRun.getExportFilename(self.filelist[0]) gcodefile = open(gcodeFilename, "a") for logLine in self.progressLog: if logLine.startswith('Model error('): gcodefile.write(';%s\n' % (logLine)) gcodefile.close() wx.CallAfter(self.notifyWindow.statusText.SetLabel, "Running plugins") ret = profile.runPostProcessingPlugins(gcodeFilename) if ret != None: self.progressLog.append(ret) self.gcode = gcodeInterpreter.gcode() self.gcode.load(gcodeFilename) profile.replaceGCodeTags(gcodeFilename, self.gcode) wx.CallAfter(self.notifyWindow.OnSliceDone, self) else: self.run()
def doFileLoadThread(self): for obj in self.objectList: if obj.filename != None and os.path.isfile(obj.filename) and obj.fileTime != os.stat(obj.filename).st_mtime: obj.ileTime = os.stat(obj.filename).st_mtime mesh = meshLoader.loadMesh(obj.filename) obj.dirty = False obj.mesh = mesh self.updateModelTransform() scale = profile.getProfileSettingFloat('model_scale') size = (self.objectsMaxV - self.objectsMinV) * scale if size[0] > self.machineSize.x or size[1] > self.machineSize.y or size[2] > self.machineSize.z: self.OnScaleMax(None) self.glCanvas.zoom = numpy.max(size) * 2.5 self.errorList = [] wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) if os.path.isfile(self.gcodeFilename) and self.gcodeFileTime != os.stat(self.gcodeFilename).st_mtime: self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime gcode = gcodeInterpreter.gcode() gcode.progressCallback = self.loadProgress gcode.load(self.gcodeFilename) self.gcodeDirty = False self.gcode = gcode self.gcodeDirty = True errorList = [] for line in open(self.gcodeFilename, "rt"): res = re.search(';Model error\(([a-z ]*)\): \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\) \(([0-9\.\-e]*), ([0-9\.\-e]*), ([0-9\.\-e]*)\)', line) if res != None: v1 = util3d.Vector3(float(res.group(2)), float(res.group(3)), float(res.group(4))) v2 = util3d.Vector3(float(res.group(5)), float(res.group(6)), float(res.group(7))) errorList.append([v1, v2]) self.errorList = errorList wx.CallAfter(self.updateToolbar) wx.CallAfter(self.glCanvas.Refresh) elif not os.path.isfile(self.gcodeFilename): self.gcode = None
def run(self): p = subprocess.Popen(self.cmdList[self.fileIdx], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) line = p.stdout.readline() self.progressLog = [] maxValue = 1 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]) wx.CallAfter(self.notifyWindow.SetProgress, progress[0], int(progress[1]), maxValue) else: #print line self.progressLog.append(line) 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() self.returnCode = p.wait() logfile = open(sliceRun.getExportFilename(self.filelist[self.fileIdx], "log"), "w") for logLine in self.progressLog: logfile.write(logLine) logfile.write('\n') logfile.close() self.fileIdx += 1 if self.fileIdx == len(self.cmdList): if len(self.filelist) > 1: self._stitchMultiExtruder() self.gcode = gcodeInterpreter.gcode() self.gcode.load(sliceRun.getExportFilename(self.filelist[0])) wx.CallAfter(self.notifyWindow.OnSliceDone, self) else: self.run()
def OnRun(self): resultFile = open(self.resultFilename, "w") put = profile.setTempOverride self.progressLog = [] for action in self.actionList: wx.CallAfter(self.SetTitle, "Building: [%d/%d]" % (self.actionList.index(action) + 1, len(self.actionList))) if not action.usePreviousSlice: p = subprocess.Popen(action.sliceCmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) line = p.stdout.readline() maxValue = 1 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]) wx.CallAfter(self.SetProgress, progress[0], int(progress[1]), maxValue) else: print line self.progressLog.append(line) wx.CallAfter(self.statusText.SetLabel, line) if self.abort: p.terminate() wx.CallAfter(self.statusText.SetLabel, "Aborted by user.") resultFile.close() return line = p.stdout.readline() self.returnCode = p.wait() put('machine_center_x', action.centerX - self.extruderOffset[action.extruder][0]) put('machine_center_y', action.centerY - self.extruderOffset[action.extruder][1]) put('clear_z', action.clearZ) put('extruder', action.extruder) put('print_temperature', action.temperature) if action == self.actionList[0]: resultFile.write(';TYPE:CUSTOM\n') resultFile.write('T%d\n' % (action.extruder)) currentExtruder = action.extruder prevTemp = action.temperature resultFile.write(profile.getAlterationFileContents('start.gcode')) else: #reset the extrusion length, and move to the next object center. resultFile.write(';TYPE:CUSTOM\n') if prevTemp != action.temperature: resultFile.write('M104 S%d\n' % (int(action.temperature))) prevTemp = action.temperature resultFile.write(profile.getAlterationFileContents('nextobject.gcode')) resultFile.write(';PRINTNR:%d\n' % self.actionList.index(action)) profile.resetTempOverride() if not action.usePreviousSlice: f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") data = f.read(4096) while data != '': resultFile.write(data) data = f.read(4096) f.close() savedCenterX = action.centerX savedCenterY = action.centerY else: f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") for line in f: if line[0] != ';': if 'X' in line: line = self._adjustNumberInLine(line, 'X', action.centerX - savedCenterX) if 'Y' in line: line = self._adjustNumberInLine(line, 'Y', action.centerY - savedCenterY) resultFile.write(line) f.close() if not action.leaveResultForNextSlice: os.remove(sliceRun.getExportFilename(action.filename, "project_tmp")) wx.CallAfter(self.progressGauge.SetValue, 10000) self.totalDoneFactor = 0.0 wx.CallAfter(self.progressGauge2.SetValue, self.actionList.index(action) + 1) resultFile.write(';TYPE:CUSTOM\n') resultFile.write('G1 Z%f F%f\n' % (self.actionList[-1].clearZ, profile.getProfileSettingFloat('max_z_speed') * 60)) resultFile.write(profile.getAlterationFileContents('end.gcode')) resultFile.close() gcode = gcodeInterpreter.gcode() gcode.load(self.resultFilename) self.abort = True sliceTime = time.time() - self.sliceStartTime status = "Build: %s" % (self.resultFilename) status += "\nSlicing took: %02d:%02d" % (sliceTime / 60, sliceTime % 60) status += "\nFilament: %.2fm %.2fg" % (gcode.extrusionAmount / 1000, gcode.calculateWeight() * 1000) status += "\nPrint time: %02d:%02d" % (int(gcode.totalMoveTimeMinute / 60), int(gcode.totalMoveTimeMinute % 60)) cost = gcode.calculateCost() if cost != False: status += "\nCost: %s" % (cost) profile.replaceGCodeTags(self.resultFilename, gcode) wx.CallAfter(self.statusText.SetLabel, status) wx.CallAfter(self.OnSliceDone)
def OnRun(self): resultFile = open(self.resultFilename, "w") put = profile.setTempOverride self.progressLog = [] for action in self.actionList: wx.CallAfter(self.SetTitle, "Building: [%d/%d]" % (self.actionList.index(action) + 1, len(self.actionList))) if not action.usePreviousSlice: p = sliceRun.startSliceCommandProcess(action.sliceCmd) line = p.stdout.readline() maxValue = 1 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]) wx.CallAfter(self.SetProgress, progress[0], int(progress[1]), maxValue) else: self.progressLog.append(line) wx.CallAfter(self.statusText.SetLabel, line) if self.abort: p.terminate() wx.CallAfter(self.statusText.SetLabel, "Aborted by user.") resultFile.close() return line = p.stdout.readline() self.returnCode = p.wait() put('machine_center_x', action.centerX - self.extruderOffset[action.extruder][0]) put('machine_center_y', action.centerY - self.extruderOffset[action.extruder][1]) put('clear_z', action.clearZ) put('extruder', action.extruder) put('print_temperature', action.temperature) if action == self.actionList[0]: resultFile.write(';TYPE:CUSTOM\n') resultFile.write('T%d\n' % (action.extruder)) currentExtruder = action.extruder prevTemp = action.temperature startGCode = profile.getAlterationFileContents('start.gcode') startGCode = startGCode.replace('?filename?', 'Multiple files') resultFile.write(startGCode) else: #reset the extrusion length, and move to the next object center. resultFile.write(';TYPE:CUSTOM\n') if prevTemp != action.temperature and action.temperature > 0: resultFile.write('M104 S%d\n' % (int(action.temperature))) prevTemp = action.temperature resultFile.write(profile.getAlterationFileContents('nextobject.gcode')) resultFile.write(';PRINTNR:%d\n' % self.actionList.index(action)) profile.resetTempOverride() if not action.usePreviousSlice: f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") data = f.read(4096) while data != '': resultFile.write(data) data = f.read(4096) f.close() savedCenterX = action.centerX savedCenterY = action.centerY else: f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") for line in f: if line[0] != ';': if 'X' in line: line = self._adjustNumberInLine(line, 'X', action.centerX - savedCenterX) if 'Y' in line: line = self._adjustNumberInLine(line, 'Y', action.centerY - savedCenterY) resultFile.write(line) f.close() if not action.leaveResultForNextSlice: os.remove(sliceRun.getExportFilename(action.filename, "project_tmp")) wx.CallAfter(self.progressGauge.SetValue, 10000) self.totalDoneFactor = 0.0 wx.CallAfter(self.progressGauge2.SetValue, self.actionList.index(action) + 1) resultFile.write(';TYPE:CUSTOM\n') if len(self.actionList) > 1 and self.actionList[-1].clearZ > 1: #only move to higher Z if we have sliced more then 1 object. This solves the "move into print after printing" problem with the print-all-at-once option. resultFile.write('G1 Z%f F%f\n' % (self.actionList[-1].clearZ, profile.getProfileSettingFloat('max_z_speed') * 60)) resultFile.write(profile.getAlterationFileContents('end.gcode')) resultFile.close() gcode = gcodeInterpreter.gcode() gcode.load(self.resultFilename) self.abort = True sliceTime = time.time() - self.sliceStartTime status = "Build: %s" % (self.resultFilename) status += "\nSlicing took: %02d:%02d" % (sliceTime / 60, sliceTime % 60) status += "\nFilament: %.2fm %.2fg" % (gcode.extrusionAmount / 1000, gcode.calculateWeight() * 1000) status += "\nPrint time: %02d:%02d" % (int(gcode.totalMoveTimeMinute / 60), int(gcode.totalMoveTimeMinute % 60)) cost = gcode.calculateCost() if cost != False: status += "\nCost: %s" % (cost) profile.replaceGCodeTags(self.resultFilename, gcode) wx.CallAfter(self.statusText.SetLabel, status) wx.CallAfter(self.OnSliceDone)