Example #1
0
	def doFileLoadThread(self):
		for obj in self.objectList:
			if obj.filename is not None and os.path.isfile(obj.filename) and obj.fileTime != os.stat(obj.filename).st_mtime:
				obj.fileTime = os.stat(obj.filename).st_mtime
				mesh = meshLoader.loadMesh(obj.filename)
				obj.mesh = mesh
				obj.dirty = True
				obj.steepDirty = True
				self.updateModelTransform()
				self.glCanvas.zoom = self.objectsBoundaryCircleSize * 6.0
				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
			self.gcodeDirty = True
			self.gcode = gcodeInterpreter.gcode()
			self.gcode.progressCallback = self.loadProgress
			self.gcode.load(self.gcodeFilename)

			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 is not 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
		wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Example #2
0
	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 OnDropFiles(self, files):
		#if len(files) > 0:
			#profile.setPluginConfig([])
			#self.updateProfileToControls()
		profile.putPreference('lastFile', files[0])
		gcodeFilename = None
		for filename in files:
			self.addToModelMRU(filename)
			ext = filename[filename.rfind('.')+1:].upper()
			if ext == 'G' or ext == 'GCODE':
				gcodeFilename = filename
		if gcodeFilename is not None:
			if self.scene._gcode is not None:
				self.scene._gcode = None
				for layerVBOlist in self.scene._gcodeVBOs:
					for vbo in layerVBOlist:
						self.scene.glReleaseList.append(vbo)
				self.scene._gcodeVBOs = []
			self.scene._gcode = gcodeInterpreter.gcode()
			self.scene._gcodeFilename = gcodeFilename
			self.scene.printButton.setBottomText('')
			self.scene.setModelView(4)
			self.scene.printButton.setDisabled(False)
			self.scene.OnSliceDone(gcodeFilename)
			self.scene.OnViewChange()
		else:
			if self.scene.getModelView() == 4:
				self.scene.setModelView(0)
				self.scene.OnViewChange()
			self.scene.loadScene(files)
Example #4
0
	def _updateSliceProgress(self, progressValue, ready):
		if not ready:
			if self.printButton.getProgressBar() is not None and progressValue >= 0.0 and abs(self.printButton.getProgressBar() - progressValue) < 0.01:
				return
		self.printButton.setDisabled(not ready)
		if progressValue >= 0.0:
			self.printButton.setProgressBar(progressValue)
		else:
			self.printButton.setProgressBar(None)
		if self._gcode is not None:
			self._gcode = None
			for layerVBOlist in self._gcodeVBOs:
				for vbo in layerVBOlist:
					self.glReleaseList.append(vbo)
			self._gcodeVBOs = []
		if ready:
			self.printButton.setProgressBar(None)
			cost = self._slicer.getFilamentCost()
			if cost is not None:
				self.printButton.setBottomText('%s\n%s\n%s' % (self._slicer.getPrintTime(), self._slicer.getFilamentAmount(), cost))
			else:
				self.printButton.setBottomText('%s\n%s' % (self._slicer.getPrintTime(), self._slicer.getFilamentAmount()))
			self._gcode = gcodeInterpreter.gcode()
			self._gcodeFilename = self._slicer.getGCodeFilename()
		else:
			self.printButton.setBottomText('')
		self.QueueRefresh()
Example #5
0
    def LoadGCodeFile(self, filename):
        if self.machineCom is not 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))
Example #6
0
    def doFileLoadThread(self):
        for obj in self.objectList:
            if obj.filename is not None and os.path.isfile(
                    obj.filename) and obj.fileTime != os.stat(
                        obj.filename).st_mtime:
                obj.fileTime = os.stat(obj.filename).st_mtime
                try:
                    mesh = meshLoader.loadMesh(obj.filename)
                except:
                    wx.CallAfter(self.ShowWarningPopup,
                                 'Failed to load %s' % (obj.filename))
                    obj.mesh = None
                    obj.filename = None
                else:
                    obj.mesh = mesh
                obj.dirty = True
                obj.steepDirty = True
                self.updateModelTransform()
                if self.objectsBoundaryCircleSize is not None:
                    self.glCanvas.zoom = self.objectsBoundaryCircleSize * 6.0
                self.errorList = []
                wx.CallAfter(self.updateToolbar)
                wx.CallAfter(self.glCanvas.Refresh)
            elif obj.filename is None or not os.path.isfile(obj.filename):
                obj.mesh = None
                obj.filename = None

        if os.path.isfile(
                self.gcodeFilename) and self.gcodeFileTime != os.stat(
                    self.gcodeFilename).st_mtime:
            self.gcodeFileTime = os.stat(self.gcodeFilename).st_mtime
            self.gcodeDirty = True
            self.gcode = gcodeInterpreter.gcode()
            self.gcode.progressCallback = self.loadProgress
            self.gcode.load(self.gcodeFilename)

            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 is not 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
        wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Example #7
0
 def __init__(self):
     self._engineLog = []
     self._gcodeData = StringIO.StringIO()
     self._polygons = []
     self._replaceInfo = {}
     self._success = False
     self._printTimeSeconds = None
     self._filamentMM = [0.0] * 4
     self._modelHash = None
     self._profileString = profile.getProfileString()
     self._preferencesString = profile.getPreferencesString()
     self._gcodeInterpreter = gcodeInterpreter.gcode()
     self._gcodeLoadThread = None
     self._finished = False
Example #8
0
    def doFileLoadThread(self):
        for obj in self.objectList:
            if obj.filename is not None and os.path.isfile(
                    obj.filename) and obj.fileTime != os.stat(
                        obj.filename).st_mtime:
                obj.fileTime = os.stat(obj.filename).st_mtime
                mesh = meshLoader.loadMesh(obj.filename)
                obj.mesh = mesh
                obj.dirty = True
                obj.steepDirty = True
                self.updateModelTransform()
                self.OnScaleMax(True)
                self.glCanvas.zoom = numpy.max(self.objectsSize) * 3.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 is not 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
        wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Example #9
0
    def OnRun(self):
        self.progressLog = []
        p = sliceRun.startSliceCommandProcess(self.sliceCommand)
        line = p.stdout.readline()
        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.")
                return
            line = p.stdout.readline()
        line = p.stderr.readline()
        while len(line) > 0:
            line = line.rstrip()
            self.progressLog.append(line)
            line = p.stderr.readline()
        self.returnCode = p.wait()
        self.progressGauge2.SetValue(self.fileCount)

        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 is not None:
            status += "\nCost: %s" % (cost)
        profile.replaceGCodeTags(self.resultFilename, gcode)
        wx.CallAfter(self.statusText.SetLabel, status)
        wx.CallAfter(self.OnSliceDone)
Example #10
0
	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()
		line = p.stderr.readline()
		while(len(line) > 0):
			line = line.rstrip()
			self.progressLog.append(line)
			line = p.stderr.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()
Example #11
0
    def OnRun(self, index):
        while self.cmdIndex < len(self.sliceCmdList):
            cmdIndex = self.cmdIndex
            self.cmdIndex += 1
            action = self.sliceCmdList[cmdIndex]
            wx.CallAfter(
                self.SetTitle,
                _("Building: [%(index)d/%(size)d]") %
                (self.sliceCmdList.index(action) + 1, len(self.sliceCmdList)))

            p = sliceRun.startSliceCommandProcess(action)
            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, index, progress[0],
                                 int(progress[1]), maxValue)
                else:
                    wx.CallAfter(self.statusText[index].SetLabel, line)
                if self.abort:
                    p.terminate()
                    wx.CallAfter(self.statusText[index].SetLabel,
                                 _("Aborted by user."))
                    return
                line = p.stdout.readline()
            self.returnCode = p.wait()

            # Update output gocde file...
            # Warning: the user could have changed the profile between the slcer run and this code.  We might be using old information.
            gcodeFilename = self.outputFilenameList[index]
            gcode = gcodeInterpreter.gcode()
            gcode.load(gcodeFilename)
            profile.replaceGCodeTags(gcodeFilename, gcode)

            wx.CallAfter(self.progressGauge[index].SetValue, 10000)
            self.totalDoneFactor[index] = 0.0
            wx.CallAfter(
                self.progressTextTotal.SetLabel,
                _("Done %(index)d/%(size)d") %
                (self.cmdIndex, len(self.sliceCmdList)))
            wx.CallAfter(self.progressGaugeTotal.SetValue, self.cmdIndex)
Example #12
0
 def run(self):
     p = sliceRun.startSliceCommandProcess(self.cmdList[self.fileIdx])
     line = p.stdout.readline()
     self.progressLog = []
     maxValue = 1
     starttime = time.time()
     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("%0.2f: %s" %
                                     (time.time() - starttime, line))
             wx.CallAfter(self.notifyWindow.statusText.SetLabel, line)
         if self.notifyWindow.abort:
             p.terminate()
             wx.CallAfter(self.notifyWindow.mainWindow.removeSliceProgress,
                          self.notifyWindow)
             return
         line = p.stdout.readline()
     line = p.stderr.readline()
     while len(line) > 0:
         line = line.rstrip()
         self.progressLog.append(line)
         line = p.stderr.readline()
     self.returnCode = p.wait()
     self.fileIdx += 1
     if self.fileIdx == len(self.cmdList):
         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()
         self.gcode = gcodeInterpreter.gcode()
         self.gcode.load(gcodeFilename)
         profile.replaceGCodeTags(gcodeFilename, self.gcode)
         wx.CallAfter(self.notifyWindow.OnSliceDone, self)
     else:
         self.run()
Example #13
0
	def OnRun(self):
		self.progressLog = []
		p = sliceRun.startSliceCommandProcess(self.sliceCommand)
		line = p.stdout.readline()
		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.")
				return
			line = p.stdout.readline()
		line = p.stderr.readline()
		while len(line) > 0:
			line = line.rstrip()
			self.progressLog.append(line)
			line = p.stderr.readline()
		self.returnCode = p.wait()
		self.progressGauge2.SetValue(self.fileCount)

		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 is not None:
			status += "\nCost: %s" % (cost)
		profile.replaceGCodeTags(self.resultFilename, gcode)
		wx.CallAfter(self.statusText.SetLabel, status)
		wx.CallAfter(self.OnSliceDone)
Example #14
0
	def run(self):
		p = sliceRun.startSliceCommandProcess(self.cmdList[self.fileIdx])
		line = p.stdout.readline()
		self.progressLog = []
		maxValue = 1
		starttime = time.time()
		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("%0.2f: %s" % (time.time() - starttime, line))
				wx.CallAfter(self.notifyWindow.statusText.SetLabel, line)
			if self.notifyWindow.abort:
				p.terminate()
				wx.CallAfter(self.notifyWindow.mainWindow.removeSliceProgress, self.notifyWindow)
				return
			line = p.stdout.readline()
		line = p.stderr.readline()
		while len(line) > 0:
			line = line.rstrip()
			self.progressLog.append(line)
			line = p.stderr.readline()
		self.returnCode = p.wait()
		self.fileIdx += 1
		if self.fileIdx == len(self.cmdList):
			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()
			self.gcode = gcodeInterpreter.gcode()
			self.gcode.load(gcodeFilename)
			profile.replaceGCodeTags(gcodeFilename, self.gcode)
			wx.CallAfter(self.notifyWindow.OnSliceDone, self)
		else:
			self.run()
Example #15
0
	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.fileTime = os.stat(obj.filename).st_mtime
				mesh = meshLoader.loadMesh(obj.filename)
				obj.dirty = False
				obj.mesh = mesh
				self.updateModelTransform()
				self.OnScaleMax(None, True)
				scale = profile.getProfileSettingFloat('model_scale')
				size = (self.objectsMaxV - self.objectsMinV) * scale
				self.toolbarInfo.SetValue('%0.1f %0.1f %0.1f' % (size[0], size[1], size[2]))
				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
		wx.CallAfter(self.checkReloadFileTimer.Start, 1000)
Example #16
0
	def OnRun(self, index):
		while self.cmdIndex < len(self.sliceCmdList):
			cmdIndex = self.cmdIndex;
			self.cmdIndex += 1			
			action = self.sliceCmdList[cmdIndex]
			wx.CallAfter(self.SetTitle, "Building: [%d/%d]"  % (self.sliceCmdList.index(action) + 1, len(self.sliceCmdList)))

			p = sliceRun.startSliceCommandProcess(action)
			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, index, progress[0], int(progress[1]), maxValue)
				else:
					wx.CallAfter(self.statusText[index].SetLabel, line)
				if self.abort:
					p.terminate()
					wx.CallAfter(self.statusText[index].SetLabel, "Aborted by user.")
					return
				line = p.stdout.readline()
			self.returnCode = p.wait()

			# Update output gocde file...
			# Warning: the user could have changed the profile between the slcer run and this code.  We might be using old information.
			gcodeFilename = self.outputFilenameList[index]
			gcode = gcodeInterpreter.gcode()
			gcode.load(gcodeFilename)
			profile.replaceGCodeTags(gcodeFilename, gcode)
			
			wx.CallAfter(self.progressGauge[index].SetValue, 10000)
			self.totalDoneFactor[index] = 0.0
			wx.CallAfter(self.progressTextTotal.SetLabel, "Done %d/%d" % (self.cmdIndex, len(self.sliceCmdList)))
			wx.CallAfter(self.progressGaugeTotal.SetValue, self.cmdIndex)
Example #17
0
	def showLoadModel(self, button = 1):
		if button == 1:
			dlg=wx.FileDialog(self, 'Open 3D model', os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST|wx.FD_MULTIPLE)
			dlg.SetWildcard(meshLoader.loadWildcardFilter() + "|GCode file (*.gcode)|*.g;*.gcode;*.G;*.GCODE")
			if dlg.ShowModal() != wx.ID_OK:
				dlg.Destroy()
				return
			filenames = dlg.GetPaths()
			dlg.Destroy()
			if len(filenames) < 1:
				return False
			profile.putPreference('lastFile', filenames[0])
			gcodeFilename = None
			for filename in filenames:
				self.GetParent().GetParent().GetParent().addToModelMRU(filename)
				ext = filename[filename.rfind('.')+1:].upper()
				if ext == 'G' or ext == 'GCODE':
					gcodeFilename = filename
			if gcodeFilename is not None:
				if self._gcode is not None:
					self._gcode = None
					for layerVBOlist in self._gcodeVBOs:
						for vbo in layerVBOlist:
							self.glReleaseList.append(vbo)
					self._gcodeVBOs = []
				self._gcode = gcodeInterpreter.gcode()
				self._gcodeFilename = gcodeFilename
				self.printButton.setBottomText('')
				self.viewSelection.setValue(4)
				self.printButton.setDisabled(False)
				self.OnViewChange()
			else:
				if self.viewSelection.getValue() == 4:
					self.viewSelection.setValue(0)
					self.OnViewChange()
				self.loadScene(filenames)
	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('object_center_x', action.centerX - self.extruderOffset[action.extruder][0])
			put('object_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()
		self.totalMoveTimeMinute = gcode.totalMoveTimeMinute
		if cost != False:
			status += "\nCost: %s" % (cost)
		profile.replaceGCodeTags(self.resultFilename, gcode)

		wx.CallAfter(self.statusText.SetLabel, status)
		wx.CallAfter(self.OnSliceDone)