コード例 #1
0
	def OnSlice(self, e):
		put = profile.setTempOverride
		oldProfile = profile.getGlobalProfileString()

		put('model_multiply_x', '1')
		put('model_multiply_y', '1')
		put('enable_raft', 'False')
		put('add_start_end_gcode', 'False')
		put('gcode_extension', 'project_tmp')
		
		clearZ = 0
		actionList = []
		for item in self.list:
			if item.profile != None and os.path.isfile(item.profile):
				profile.loadGlobalProfile(item.profile)
			put('machine_center_x', item.centerX - self.extruderOffset[item.extruder].x)
			put('machine_center_y', item.centerY - self.extruderOffset[item.extruder].y)
			put('model_scale', item.scale)
			put('flip_x', item.flipX)
			put('flip_y', item.flipY)
			put('flip_z', item.flipZ)
			put('model_rotate_base', item.rotate)
			put('swap_xz', item.swapXZ)
			put('swap_yz', item.swapYZ)
			
			action = Action()
			action.sliceCmd = sliceRun.getSliceCommand(item.filename)
			action.centerX = item.centerX
			action.centerY = item.centerY
			action.extruder = item.extruder
			action.filename = item.filename
			clearZ = max(clearZ, item.getMaximum().z * item.scale + 5.0)
			action.clearZ = clearZ
			action.leaveResultForNextSlice = False
			action.usePreviousSlice = False
			actionList.append(action)

			if self.list.index(item) > 0 and item.isSameExceptForPosition(self.list[self.list.index(item)-1]):
				actionList[-2].leaveResultForNextSlice = True
				actionList[-1].usePreviousSlice = True

			if item.profile != None:
				profile.loadGlobalProfileFromString(oldProfile)
		
		#Restore the old profile.
		profile.resetTempOverride()
		
		dlg=wx.FileDialog(self, "Save project gcode file", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
		dlg.SetWildcard("GCode file (*.gcode)|*.gcode")
		if dlg.ShowModal() != wx.ID_OK:
			dlg.Destroy()
			return
		resultFilename = dlg.GetPath()
		dlg.Destroy()
		
		pspw = ProjectSliceProgressWindow(actionList, resultFilename)
		pspw.extruderOffset = self.extruderOffset
		pspw.Centre()
		pspw.Show(True)
コード例 #2
0
ファイル: sliceProgessPanel.py プロジェクト: CNCBASHER/Cura
    def _stitchMultiExtruder(self):
        files = []
        resultFile = open(sliceRun.getExportFilename(self.filelist[0]), "w")
        resultFile.write(';TYPE:CUSTOM\n')
        resultFile.write(profile.getAlterationFileContents('start.gcode'))
        for filename in self.filelist:
            if os.path.isfile(
                    sliceRun.getExportFilename(filename, 'multi_extrude_tmp')):
                files.append(
                    open(
                        sliceRun.getExportFilename(filename,
                                                   'multi_extrude_tmp'), "r"))
            else:
                return

        currentExtruder = 0
        resultFile.write('T%d\n' % (currentExtruder))
        layerNr = -1
        hasLine = True
        while hasLine:
            hasLine = False
            for f in files:
                layerHasLine = False
                for line in f:
                    hasLine = True
                    if line.startswith(';LAYER:'):
                        break
                    if 'Z' in line:
                        lastZ = float(re.search('Z([^\s]+)', line).group(1))
                    if not layerHasLine:
                        nextExtruder = files.index(f)
                        resultFile.write(';LAYER:%d\n' % (layerNr))
                        resultFile.write(';EXTRUDER:%d\n' % (nextExtruder))
                        if nextExtruder != currentExtruder:
                            resultFile.write(';TYPE:CUSTOM\n')
                            profile.setTempOverride('extruder', nextExtruder)
                            resultFile.write(
                                profile.getAlterationFileContents(
                                    'switchExtruder.gcode'))
                            profile.resetTempOverride()
                            currentExtruder = nextExtruder
                        layerHasLine = True
                    resultFile.write(line)
            layerNr += 1
        for f in files:
            f.close()
        for filename in self.filelist:
            os.remove(sliceRun.getExportFilename(filename,
                                                 'multi_extrude_tmp'))
        resultFile.write(';TYPE:CUSTOM\n')
        resultFile.write(profile.getAlterationFileContents('end.gcode'))
        resultFile.close()
コード例 #3
0
ファイル: sliceProgessPanel.py プロジェクト: CNCBASHER/Cura
    def __init__(self, mainWindow, parent, filelist):
        wx.Panel.__init__(self, parent, -1)
        self.mainWindow = mainWindow
        self.filelist = filelist
        self.abort = False

        box = wx.StaticBox(self, -1, filelist[0])
        self.sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        mainSizer.Add(self.sizer, 0, flag=wx.EXPAND)

        self.statusText = wx.StaticText(self, -1, "Starting...")
        self.progressGauge = wx.Gauge(self, -1)
        self.progressGauge.SetRange(10000 * len(filelist))
        self.abortButton = wx.Button(self, -1, "X", style=wx.BU_EXACTFIT)
        self.sizer.Add(self.statusText, 2, flag=wx.ALIGN_CENTER)
        self.sizer.Add(self.progressGauge, 2)
        self.sizer.Add(self.abortButton, 0)

        self.Bind(wx.EVT_BUTTON, self.OnAbort, self.abortButton)

        self.SetSizer(mainSizer)
        self.prevStep = 'start'
        self.totalDoneFactor = 0.0
        self.startTime = time.time()
        if profile.getPreference('save_profile') == 'True':
            profile.saveGlobalProfile(
                self.filelist[0][:self.filelist[0].rfind('.')] +
                "_profile.ini")
        cmdList = []
        for filename in self.filelist:
            idx = self.filelist.index(filename)
            #print filename, idx
            if idx > 0:
                profile.setTempOverride('fan_enabled', 'False')
                profile.setTempOverride('skirt_line_count', '0')
                profile.setTempOverride(
                    'machine_center_x',
                    profile.getProfileSettingFloat('machine_center_x') -
                    profile.getPreferenceFloat('extruder_offset_x%d' % (idx)))
                profile.setTempOverride(
                    'machine_center_y',
                    profile.getProfileSettingFloat('machine_center_y') -
                    profile.getPreferenceFloat('extruder_offset_y%d' % (idx)))
                profile.setTempOverride('alternative_center', self.filelist[0])
            if len(self.filelist) > 1:
                profile.setTempOverride('add_start_end_gcode', 'False')
                profile.setTempOverride('gcode_extension', 'multi_extrude_tmp')
            cmdList.append(sliceRun.getSliceCommand(filename))
        profile.resetTempOverride()
        self.thread = WorkerThread(self, filelist, cmdList)
コード例 #4
0
ファイル: sliceProgessPanel.py プロジェクト: festlv/Cura
	def _stitchMultiExtruder(self):
		files = []
		resultFile = open(sliceRun.getExportFilename(self.filelist[0]), "w")
		resultFile.write(';TYPE:CUSTOM\n')
		resultFile.write(profile.getAlterationFileContents('start.gcode'))
		for filename in self.filelist:
			if os.path.isfile(sliceRun.getExportFilename(filename, 'multi_extrude_tmp')):
				files.append(open(sliceRun.getExportFilename(filename, 'multi_extrude_tmp'), "r"))
			else:
				return
		
		currentExtruder = 0
		resultFile.write('T%d\n' % (currentExtruder))
		layerNr = -1
		hasLine = True
		while hasLine:
			hasLine = False
			for f in files:
				layerHasLine = False
				for line in f:
					hasLine = True
					if line.startswith(';LAYER:'):
						break
					if 'Z' in line:
						lastZ = float(re.search('Z([^\s]+)', line).group(1))
					if not layerHasLine:
						nextExtruder = files.index(f)
						resultFile.write(';LAYER:%d\n' % (layerNr))
						resultFile.write(';EXTRUDER:%d\n' % (nextExtruder))
						if nextExtruder != currentExtruder:
							resultFile.write(';TYPE:CUSTOM\n')
							profile.setTempOverride('extruder', nextExtruder)
							resultFile.write(profile.getAlterationFileContents('switchExtruder.gcode'))
							profile.resetTempOverride()
							currentExtruder = nextExtruder
						layerHasLine = True
					resultFile.write(line)
			layerNr += 1
		for f in files:
			f.close()
		for filename in self.filelist:
			os.remove(sliceRun.getExportFilename(filename, 'multi_extrude_tmp'))
		resultFile.write(';TYPE:CUSTOM\n')
		resultFile.write(profile.getAlterationFileContents('end.gcode'))
		resultFile.close()
コード例 #5
0
ファイル: sliceProgessPanel.py プロジェクト: festlv/Cura
	def __init__(self, mainWindow, parent, filelist):
		wx.Panel.__init__(self, parent, -1)
		self.mainWindow = mainWindow
		self.filelist = filelist
		self.abort = False
		
		box = wx.StaticBox(self, -1, filelist[0])
		self.sizer = wx.StaticBoxSizer(box, wx.HORIZONTAL)

		mainSizer = wx.BoxSizer(wx.VERTICAL) 
		mainSizer.Add(self.sizer, 0, flag=wx.EXPAND)

		self.statusText = wx.StaticText(self, -1, "Starting...")
		self.progressGauge = wx.Gauge(self, -1)
		self.progressGauge.SetRange(10000 * len(filelist))
		self.abortButton = wx.Button(self, -1, "X", style=wx.BU_EXACTFIT)
		self.sizer.Add(self.statusText, 2, flag=wx.ALIGN_CENTER )
		self.sizer.Add(self.progressGauge, 2)
		self.sizer.Add(self.abortButton, 0)

		self.Bind(wx.EVT_BUTTON, self.OnAbort, self.abortButton)

		self.SetSizer(mainSizer)
		self.prevStep = 'start'
		self.totalDoneFactor = 0.0
		self.startTime = time.time()
		if profile.getPreference('save_profile') == 'True':
			profile.saveGlobalProfile(self.filelist[0][: self.filelist[0].rfind('.')] + "_profile.ini")
		cmdList = []
		for filename in self.filelist:
			idx = self.filelist.index(filename)
			#print filename, idx
			if idx > 0:
				profile.setTempOverride('fan_enabled', 'False')
				profile.setTempOverride('skirt_line_count', '0')
				profile.setTempOverride('machine_center_x', profile.getProfileSettingFloat('machine_center_x') - profile.getPreferenceFloat('extruder_offset_x%d' % (idx)))
				profile.setTempOverride('machine_center_y', profile.getProfileSettingFloat('machine_center_y') - profile.getPreferenceFloat('extruder_offset_y%d' % (idx)))
				profile.setTempOverride('alternative_center', self.filelist[0])
			if len(self.filelist) > 1:
				profile.setTempOverride('add_start_end_gcode', 'False')
				profile.setTempOverride('gcode_extension', 'multi_extrude_tmp')
			cmdList.append(sliceRun.getSliceCommand(filename))
		profile.resetTempOverride()
		self.thread = WorkerThread(self, filelist, cmdList)
コード例 #6
0
ファイル: projectPlanner.py プロジェクト: custodian/Cura
	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)
コード例 #7
0
ファイル: projectPlanner.py プロジェクト: jedahan/Cura
	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)
コード例 #8
0
ファイル: projectPlanner.py プロジェクト: jedahan/Cura
	def OnSlice(self, e):
		dlg=wx.FileDialog(self, "Save project gcode file", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_SAVE)
		dlg.SetWildcard("GCode file (*.gcode)|*.gcode")
		if dlg.ShowModal() != wx.ID_OK:
			dlg.Destroy()
			return
		resultFilename = dlg.GetPath()
		dlg.Destroy()

		put = profile.setTempOverride
		oldProfile = profile.getGlobalProfileString()
		
		put('add_start_end_gcode', 'False')
		put('gcode_extension', 'project_tmp')
		if self.printMode == 0:
			clearZ = 0
			actionList = []
			for item in self.list:
				if item.profile != None and os.path.isfile(item.profile):
					profile.loadGlobalProfile(item.profile)
				put('machine_center_x', item.centerX - self.extruderOffset[item.extruder][0])
				put('machine_center_y', item.centerY - self.extruderOffset[item.extruder][1])
				put('model_scale', item.scale)
				put('flip_x', item.flipX)
				put('flip_y', item.flipY)
				put('flip_z', item.flipZ)
				put('model_rotate_base', item.rotate)
				put('swap_xz', item.swapXZ)
				put('swap_yz', item.swapYZ)
				
				action = Action()
				action.sliceCmd = sliceRun.getSliceCommand(item.filename)
				action.centerX = item.centerX
				action.centerY = item.centerY
				action.temperature = profile.getProfileSettingFloat('print_temperature')
				action.extruder = item.extruder
				action.filename = item.filename
				clearZ = max(clearZ, item.getSize()[2] * item.scale + 5.0)
				action.clearZ = clearZ
				action.leaveResultForNextSlice = False
				action.usePreviousSlice = False
				actionList.append(action)

				if self.list.index(item) > 0 and item.isSameExceptForPosition(self.list[self.list.index(item)-1]):
					actionList[-2].leaveResultForNextSlice = True
					actionList[-1].usePreviousSlice = True

				if item.profile != None:
					profile.loadGlobalProfileFromString(oldProfile)
			
		else:
			self._saveCombinedSTL(resultFilename + "_temp_.stl")
			put('model_scale', 1.0)
			put('flip_x', False)
			put('flip_y', False)
			put('flip_z', False)
			put('model_rotate_base', 0)
			put('swap_xz', False)
			put('swap_yz', False)
			actionList = []
			
			action = Action()
			action.sliceCmd = sliceRun.getSliceCommand(resultFilename + "_temp_.stl")
			action.centerX = profile.getProfileSettingFloat('machine_center_x')
			action.centerY = profile.getProfileSettingFloat('machine_center_y')
			action.temperature = profile.getProfileSettingFloat('print_temperature')
			action.extruder = 0
			action.filename = resultFilename + "_temp_.stl"
			action.clearZ = 0
			action.leaveResultForNextSlice = False
			action.usePreviousSlice = False

			actionList.append(action)
		
		#Restore the old profile.
		profile.resetTempOverride()
		
		pspw = ProjectSliceProgressWindow(actionList, resultFilename)
		pspw.extruderOffset = self.extruderOffset
		pspw.Centre()
		pspw.Show(True)