Esempio n. 1
0
def stitchMultiExtruder(outputList, resultFile):
	print "Stitching %i files for multi-extrusion" % (len(outputList))
	currentExtruder = 0
	resultFile.write('T%d\n' % (currentExtruder))
	layerNr = -1
	hasLine = True
	outputList = map(lambda o: o.split('\n'), outputList)
	outputOrder = range(0, len(outputList))
	while hasLine:
		hasLine = False
		outputOrder.reverse()
		for outputIdx in outputOrder:
			layerHasLine = False
			while len(outputList[outputIdx]) > 0:
				line = outputList[outputIdx].pop(0)
				hasLine = True
				if line.startswith(';LAYER:'):
					break
				if 'Z' in line:
					lastZ = float(re.search('Z([^\s]+)', line).group(1))
				if not layerHasLine:
					nextExtruder = outputIdx
					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') + '\n')
						profile.resetTempOverride()
						currentExtruder = nextExtruder
					layerHasLine = True
				resultFile.write(line)
				resultFile.write('\n')
		layerNr += 1
Esempio n. 2
0
	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
		filesOrder = files[:]
		while hasLine:
			hasLine = False
			filesOrder.reverse()
			for f in filesOrder:
				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') + '\n')
							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()
Esempio n. 3
0
	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('object_center_x', profile.getPreferenceFloat('machine_width') / 2 - profile.getPreferenceFloat('extruder_offset_x%d' % (idx)))
				profile.setTempOverride('object_center_y', profile.getPreferenceFloat('machine_depth') / 2 - 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)
Esempio n. 4
0
def main():
	parser = OptionParser(usage="usage: %prog [options] <X,Y> <filename>[, <X,Y> <filename>][, ...]")
	parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
					  help="Encoded profile to use for the print")
	parser.add_option("-o", "--output", action="store", type="string", dest="output",
					  help="Output filename")
	(options, args) = parser.parse_args()
	if options.output is None:
		print 'Missing output filename'
		sys.exit(1)
	if options.profile is not None:
		profile.loadGlobalProfileFromString(options.profile)
	options.output = fixUTF8(options.output)

	clearZ = 0
	resultFile = open(options.output, "w")
	for idx in xrange(0, len(args), 2):
		position = map(float, args[idx].split(','))
		if len(position) < 9 + 2:
			position = position[0:2]
			position += [1,0,0]
			position += [0,1,0]
			position += [0,0,1]
		filenames = fixUTF8(args[idx + 1]).split('|')

		profile.setTempOverride('object_center_x', position[0])
		profile.setTempOverride('object_center_y', position[1])
		if idx == 0:
			resultFile.write(';TYPE:CUSTOM\n')
			resultFile.write(profile.getAlterationFileContents('start.gcode').replace('?filename?', ' '.join(filenames).encode('ascii', 'replace')))
		else:
			resultFile.write(';TYPE:CUSTOM\n')
			n = output[-1].rfind('Z')+1
			zString = output[-1][n:n+20]
			zString = zString[0:zString.find(' ')]
			clearZ = max(clearZ, float(zString) + 10)
			profile.setTempOverride('clear_z', clearZ)
			resultFile.write(profile.getAlterationFileContents('nextobject.gcode').replace('?filename?', ' '.join(filenames).encode('ascii', 'replace')))

		output = []
		for filename in filenames:
			extruderNr = filenames.index(filename)
			profile.resetTempOverride()
			if extruderNr > 0:
				profile.setTempOverride('object_center_x', position[0] - profile.getPreferenceFloat('extruder_offset_x%d' % (extruderNr)))
				profile.setTempOverride('object_center_y', position[1] - profile.getPreferenceFloat('extruder_offset_y%d' % (extruderNr)))
				profile.setTempOverride('fan_enabled', 'False')
				profile.setTempOverride('skirt_line_count', '0')
				profile.setTempOverride('alternative_center', filenames[0])
			else:
				profile.setTempOverride('object_center_x', position[0])
				profile.setTempOverride('object_center_y', position[1])
			profile.setTempOverride('object_matrix', ','.join(map(str, position[2:11])))
			output.append(export.getOutput(filename))
			profile.resetTempOverride()
		if len(output) == 1:
			resultFile.write(output[0])
		else:
			stitchMultiExtruder(output, resultFile)
	resultFile.write(';TYPE:CUSTOM\n')
	resultFile.write(profile.getAlterationFileContents('end.gcode'))
	resultFile.close()

	print "Running plugins"
	ret = profile.runPostProcessingPlugins(options.output)
	if ret is not None:
		print ret
	print "Finalizing %s" % (os.path.basename(options.output))
	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)
	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('object_center_x', item.centerX - self.extruderOffset[item.extruder][0])
				put('object_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)
				print action.sliceCmd
				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.getPreferenceFloat('machine_width') / 2
			action.centerY = profile.getPreferenceFloat('machine_depth') / 2
			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)
Esempio n. 7
0
def main():
    parser = OptionParser(
        usage=
        "usage: %prog [options] <X,Y> <filename>[, <X,Y> <filename>][, ...]")
    parser.add_option("-p",
                      "--profile",
                      action="store",
                      type="string",
                      dest="profile",
                      help="Encoded profile to use for the print")
    parser.add_option("-o",
                      "--output",
                      action="store",
                      type="string",
                      dest="output",
                      help="Output filename")
    (options, args) = parser.parse_args()
    if options.output is None:
        print 'Missing output filename'
        sys.exit(1)
    if options.profile is not None:
        profile.loadGlobalProfileFromString(options.profile)
    options.output = fixUTF8(options.output)

    clearZ = 0
    resultFile = open(options.output, "w")
    for idx in xrange(0, len(args), 2):
        position = map(float, args[idx].split(','))
        if len(position) < 9 + 2:
            position = position[0:2]
            position += [1, 0, 0]
            position += [0, 1, 0]
            position += [0, 0, 1]
        filenames = fixUTF8(args[idx + 1]).split('|')

        profile.setTempOverride('object_center_x', position[0])
        profile.setTempOverride('object_center_y', position[1])
        if idx == 0:
            resultFile.write(';TYPE:CUSTOM\n')
            resultFile.write(
                profile.getAlterationFileContents(
                    'start.gcode', len(filenames)).replace(
                        '?filename?',
                        ' '.join(filenames).encode('ascii', 'replace')))
        else:
            resultFile.write(';TYPE:CUSTOM\n')
            n = output[-1].rfind('Z') + 1
            zString = output[-1][n:n + 20]
            zString = zString[0:zString.find(' ')]
            clearZ = max(clearZ, float(zString) + 10)
            profile.setTempOverride('clear_z', clearZ)
            print position
            print profile.getAlterationFileContents('nextobject.gcode')
            resultFile.write(
                profile.getAlterationFileContents('nextobject.gcode').replace(
                    '?filename?',
                    ' '.join(filenames).encode('ascii', 'replace')))

        output = []
        for filename in filenames:
            extruderNr = filenames.index(filename)
            profile.resetTempOverride()
            if extruderNr > 0:
                profile.setTempOverride(
                    'object_center_x', position[0] -
                    profile.getPreferenceFloat('extruder_offset_x%d' %
                                               (extruderNr)))
                profile.setTempOverride(
                    'object_center_y', position[1] -
                    profile.getPreferenceFloat('extruder_offset_y%d' %
                                               (extruderNr)))
                profile.setTempOverride('fan_enabled', 'False')
                profile.setTempOverride('skirt_line_count', '0')
                profile.setTempOverride('alternative_center', filenames[0])
            else:
                profile.setTempOverride('object_center_x', position[0])
                profile.setTempOverride('object_center_y', position[1])
            profile.setTempOverride('object_matrix',
                                    ','.join(map(str, position[2:11])))
            if extruderNr > 0:
                if profile.getProfileSettingFloat('filament_diameter%d' %
                                                  (extruderNr + 1)) > 0:
                    profile.setTempOverride(
                        'filament_diameter',
                        profile.getProfileSetting('filament_diameter%d' %
                                                  (extruderNr + 1)))
            print extruderNr, profile.getPreferenceFloat(
                'extruder_offset_x%d' %
                (extruderNr)), profile.getPreferenceFloat(
                    'extruder_offset_y%d' % (extruderNr))
            output.append(export.getOutput(filename))
            profile.resetTempOverride()
        if len(output) == 1:
            resultFile.write(output[0])
        else:
            stitchMultiExtruder(output, resultFile)
    resultFile.write(';TYPE:CUSTOM\n')
    resultFile.write(profile.getAlterationFileContents('end.gcode'))
    resultFile.close()

    print "Running plugins"
    ret = profile.runPostProcessingPlugins(options.output)
    if ret is not None:
        print ret
    print "Finalizing %s" % (os.path.basename(options.output))
    if profile.getPreference('submit_slice_information') == 'True':
        filenames = fixUTF8(args[idx + 1]).split('|')
        for filename in filenames:
            m = hashlib.sha512()
            f = open(filename, "rb")
            while True:
                chunk = f.read(1024)
                if not chunk:
                    break
                m.update(chunk)
            f.close()
            data = {
                'processor': platform.processor(),
                'machine': platform.machine(),
                'platform': platform.platform(),
                'profile': profile.getGlobalProfileString(),
                'preferences': profile.getGlobalPreferencesString(),
                'modelhash': m.hexdigest(),
                'version': version.getVersion(),
            }
            try:
                f = urllib2.urlopen("http://platform.ultimaker.com/curastats/",
                                    data=urllib.urlencode(data),
                                    timeout=5)
                f.read()
                f.close()
            except:
                pass
Esempio n. 8
0
def stitchMultiExtruder(outputList, resultFile):
    print "Stitching %i files for multi-extrusion" % (len(outputList))
    currentExtruder = 0
    resultFile.write('T%d\n' % (currentExtruder))
    layerNr = 0
    hasLine = True
    outputList = map(lambda o: o.split('\n'), outputList)
    outputOrder = range(0, len(outputList))
    outputSlice = []
    for n in xrange(0, len(outputList)):
        outputSlice.append([0, 0])
    currentX = 0
    currentY = 0
    currentZ = 0
    currentF = 60
    while hasLine:
        hasLine = layerNr < 1000
        for n in xrange(0, len(outputList)):
            outputSlice[n][0] = outputSlice[n][1] + 1
            outputSlice[n][1] = outputSlice[n][0]
            while outputSlice[n][1] < len(outputList[n]) and not outputList[n][
                    outputSlice[n][1]].startswith(';LAYER:'):
                outputSlice[n][1] += 1
        outputOrder = range(currentExtruder, len(outputList)) + range(
            0, currentExtruder)
        for n in outputOrder:
            if outputSlice[n][1] > outputSlice[n][0] + 1:
                nextExtruder = n
                resultFile.write(';LAYER:%d\n' % (layerNr))
                resultFile.write(';EXTRUDER:%d\n' % (nextExtruder))

                startSlice = outputSlice[n][0]
                endSlice = outputSlice[n][1]

                currentE = 0
                while startSlice < len(outputList[n]) and not isPrintingLine(
                        outputList[n][startSlice]):
                    currentE = getCodeFloat(outputList[n][startSlice], 'E',
                                            currentE)
                    currentX = getCodeFloat(outputList[n][startSlice], 'X',
                                            currentX)
                    currentY = getCodeFloat(outputList[n][startSlice], 'Y',
                                            currentY)
                    currentZ = getCodeFloat(outputList[n][startSlice], 'Z',
                                            currentZ)
                    currentF = getCodeFloat(outputList[n][startSlice], 'F',
                                            currentF)
                    startSlice += 1
                while not isPrintingLine(outputList[n][endSlice - 1]):
                    endSlice -= 1

                if nextExtruder != currentExtruder:
                    profile.setTempOverride('extruder', nextExtruder)
                    profile.setTempOverride('new_x', currentX)
                    profile.setTempOverride('new_y', currentY)
                    profile.setTempOverride('new_z', currentZ)
                    resultFile.write(
                        profile.getAlterationFileContents(
                            'switchExtruder.gcode') + '\n')
                    profile.resetTempOverride()
                    currentExtruder = nextExtruder

                for idx in xrange(outputSlice[n][0], startSlice):
                    if not 'G1' in outputList[n][idx]:
                        resultFile.write(outputList[n][idx])
                        resultFile.write('\n')

                resultFile.write(
                    'G1 X%f Y%f Z%f F%f\n' %
                    (currentX, currentY, currentZ,
                     profile.getProfileSettingFloat('travel_speed') * 60))
                resultFile.write('G1 F%f\n' % (currentF))
                resultFile.write('G92 E%f\n' % (currentE))
                for idx in xrange(startSlice, endSlice):
                    resultFile.write(outputList[n][idx])
                    resultFile.write('\n')
                    currentX = getCodeFloat(outputList[n][idx], 'X', currentX)
                    currentY = getCodeFloat(outputList[n][idx], 'Y', currentY)
                    currentZ = getCodeFloat(outputList[n][idx], 'Z', currentZ)
                    hasLine = True
                resultFile.write('G92 E0\n')
        layerNr += 1
Esempio n. 9
0
def main():
	parser = OptionParser(usage="usage: %prog [options] <X,Y> <filename>[, <X,Y> <filename>][, ...]")
	parser.add_option("-p", "--profile", action="store", type="string", dest="profile",
					  help="Encoded profile to use for the print")
	parser.add_option("-o", "--output", action="store", type="string", dest="output",
					  help="Output filename")
	(options, args) = parser.parse_args()
	if options.output is None:
		print 'Missing output filename'
		sys.exit(1)
	if options.profile is not None:
		profile.loadGlobalProfileFromString(options.profile)
	options.output = fixUTF8(options.output)

	clearZ = 0
	resultFile = open(options.output, "w")
	for idx in xrange(0, len(args), 2):
		position = map(float, args[idx].split(','))
		if len(position) < 9 + 2:
			position = position[0:2]
			position += [1,0,0]
			position += [0,1,0]
			position += [0,0,1]
		filenames = fixUTF8(args[idx + 1]).split('|')

		profile.setTempOverride('object_center_x', position[0])
		profile.setTempOverride('object_center_y', position[1])
		if idx == 0:
			resultFile.write(';TYPE:CUSTOM\n')
			resultFile.write(profile.getAlterationFileContents('start.gcode', len(filenames)).replace('?filename?', ' '.join(filenames).encode('ascii', 'replace')))
		else:
			resultFile.write(';TYPE:CUSTOM\n')
			n = output[-1].rfind('Z')+1
			zString = output[-1][n:n+20]
			zString = zString[0:zString.find(' ')]
			clearZ = max(clearZ, float(zString) + 10)
			profile.setTempOverride('clear_z', clearZ)
			print position
			print profile.getAlterationFileContents('nextobject.gcode')
			resultFile.write(profile.getAlterationFileContents('nextobject.gcode').replace('?filename?', ' '.join(filenames).encode('ascii', 'replace')))

		output = []
		for filename in filenames:
			extruderNr = filenames.index(filename)
			profile.resetTempOverride()
			if extruderNr > 0:
				profile.setTempOverride('object_center_x', position[0] - profile.getPreferenceFloat('extruder_offset_x%d' % (extruderNr)))
				profile.setTempOverride('object_center_y', position[1] - profile.getPreferenceFloat('extruder_offset_y%d' % (extruderNr)))
				profile.setTempOverride('fan_enabled', 'False')
				profile.setTempOverride('skirt_line_count', '0')
				profile.setTempOverride('alternative_center', filenames[0])
			else:
				profile.setTempOverride('object_center_x', position[0])
				profile.setTempOverride('object_center_y', position[1])
			profile.setTempOverride('object_matrix', ','.join(map(str, position[2:11])))
			if extruderNr > 0:
				if profile.getProfileSettingFloat('filament_diameter%d' % (extruderNr + 1)) > 0:
					profile.setTempOverride('filament_diameter', profile.getProfileSetting('filament_diameter%d' % (extruderNr + 1)))
			print extruderNr, profile.getPreferenceFloat('extruder_offset_x%d' % (extruderNr)), profile.getPreferenceFloat('extruder_offset_y%d' % (extruderNr))
			output.append(export.getOutput(filename))
			profile.resetTempOverride()
		if len(output) == 1:
			resultFile.write(output[0])
		else:
			stitchMultiExtruder(output, resultFile)
	resultFile.write(';TYPE:CUSTOM\n')
	resultFile.write(profile.getAlterationFileContents('end.gcode'))
	resultFile.close()

	print "Running plugins"
	ret = profile.runPostProcessingPlugins(options.output)
	if ret is not None:
		print ret
	print "Finalizing %s" % (os.path.basename(options.output))
	if profile.getPreference('submit_slice_information') == 'True':
		filenames = fixUTF8(args[idx + 1]).split('|')
		for filename in filenames:
			m = hashlib.sha512()
			f = open(filename, "rb")
			while True:
				chunk = f.read(1024)
				if not chunk:
					break
				m.update(chunk)
			f.close()
			data = {
				'processor': platform.processor(),
				'machine': platform.machine(),
				'platform': platform.platform(),
				'profile': profile.getGlobalProfileString(),
				'preferences': profile.getGlobalPreferencesString(),
				'modelhash': m.hexdigest(),
				'version': version.getVersion(),
			}
			try:
				f = urllib2.urlopen("http://platform.ultimaker.com/curastats/", data = urllib.urlencode(data), timeout = 5);
				f.read()
				f.close()
			except:
				pass
Esempio n. 10
0
def stitchMultiExtruder(outputList, resultFile):
	print "Stitching %i files for multi-extrusion" % (len(outputList))
	currentExtruder = 0
	resultFile.write('T%d\n' % (currentExtruder))
	layerNr = 0
	hasLine = True
	outputList = map(lambda o: o.split('\n'), outputList)
	outputOrder = range(0, len(outputList))
	outputSlice = []
	for n in xrange(0, len(outputList)):
		outputSlice.append([0, 0])
	currentX = 0
	currentY = 0
	currentZ = 0
	currentF = 60
	while hasLine:
		hasLine = layerNr < 1000
		for n in xrange(0, len(outputList)):
			outputSlice[n][0] = outputSlice[n][1] + 1
			outputSlice[n][1] = outputSlice[n][0]
			while outputSlice[n][1] < len(outputList[n]) and not outputList[n][outputSlice[n][1]].startswith(';LAYER:'):
				outputSlice[n][1] += 1
		outputOrder = range(currentExtruder, len(outputList)) + range(0, currentExtruder)
		for n in outputOrder:
			if outputSlice[n][1] > outputSlice[n][0] + 1:
				nextExtruder = n
				resultFile.write(';LAYER:%d\n' % (layerNr))
				resultFile.write(';EXTRUDER:%d\n' % (nextExtruder))

				startSlice = outputSlice[n][0]
				endSlice = outputSlice[n][1]
				currentE = 0
				while not isPrintingLine(outputList[n][startSlice]):
					currentE = getCodeFloat(outputList[n][startSlice], 'E', currentE)
					currentX = getCodeFloat(outputList[n][startSlice], 'X', currentX)
					currentY = getCodeFloat(outputList[n][startSlice], 'Y', currentY)
					currentZ = getCodeFloat(outputList[n][startSlice], 'Z', currentZ)
					currentF = getCodeFloat(outputList[n][startSlice], 'F', currentF)
					startSlice += 1
				while not isPrintingLine(outputList[n][endSlice-1]):
					endSlice -= 1

				if nextExtruder != currentExtruder:
					profile.setTempOverride('extruder', nextExtruder)
					profile.setTempOverride('new_x', currentX)
					profile.setTempOverride('new_y', currentY)
					profile.setTempOverride('new_z', currentZ)
					resultFile.write(profile.getAlterationFileContents('switchExtruder.gcode') + '\n')
					profile.resetTempOverride()
					currentExtruder = nextExtruder

				for idx in xrange(outputSlice[n][0], startSlice):
					if not 'G1' in outputList[n][idx]:
						resultFile.write(outputList[n][idx])
						resultFile.write('\n')

				resultFile.write('G1 X%f Y%f Z%f F%f\n' % (currentX, currentY, currentZ, profile.getProfileSettingFloat('travel_speed') * 60))
				resultFile.write('G1 F%f\n' % (currentF))
				resultFile.write('G92 E%f\n' % (currentE))
				for idx in xrange(startSlice, endSlice):
					resultFile.write(outputList[n][idx])
					resultFile.write('\n')
					currentX = getCodeFloat(outputList[n][idx], 'X', currentX)
					currentY = getCodeFloat(outputList[n][idx], 'Y', currentY)
					currentZ = getCodeFloat(outputList[n][idx], 'Z', currentZ)
					hasLine = True
				resultFile.write('G92 E0\n')
		layerNr += 1
Esempio n. 11
0
	def _onRunSlicer(self, e):
		if self._isSimpleMode:
			self.GetTopLevelParent().simpleSettingsPanel.setupSlice()
		self._slicer.runSlicer(self._scene)
		if self._isSimpleMode:
			profile.resetTempOverride()
	def runSlicer(self, list, name, sceneView):
		#dlg=wx.FileDialog(self, "Save project gcode file", os.path.split(profile2.getPreference('lastFile'))[0], style=wx.FD_SAVE)
		#dlg.SetWildcard("GCode file (*.gcode)|*.gcode")
		#if dlg.ShowModal() != wx.ID_OK:
		#	dlg.Destroy()
		#	return
		#print sceneView
		resultFilename = name
		#dlg.Destroy()

		put = profile.setTempOverride
		oldProfile = profile.getGlobalProfileString()
		
		put('add_start_end_gcode', 'False')
		put('gcode_extension', 'project_tmp')
		#if self.printMode == 0:
		if 0:
			clearZ = 0
			actionList = []
			for item in list:
				if item.profile != None and os.path.isfile(item.profile):
					profile.loadGlobalProfile(item.profile)
				put('object_center_x', item.centerX - self.extruderOffset[item.extruder][0])
				put('object_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 list.index(item) > 0 and item.isSameExceptForPosition(list[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", list)
			meshLoader.saveMeshes(resultFilename + "_temp_.stl", list)

			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)
			put('object_center_x', sceneView._scene.getMinMaxPosition()[0] + (profile.getPreferenceFloat('machine_width') / 2))
			put('object_center_y', sceneView._scene.getMinMaxPosition()[1] + (profile.getPreferenceFloat('machine_depth') / 2))  
			actionList = []
			#print sceneView._scene.getMinMaxPosition()
			action = Action()
			action.sliceCmd = sliceRun.getSliceCommand(resultFilename + "_temp_.stl")
			action.centerX = profile.getPreferenceFloat('machine_width') / 2 #these dont do squat! but they have to be here. 
			action.centerY = profile.getPreferenceFloat('machine_depth') / 2
			#action.centerX = 0
			#action.centerY = 300
			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()
		
		self._pspw = ProjectSliceProgressWindow(self, actionList, resultFilename, sceneView)
		self._pspw.extruderOffset = self.extruderOffset
		self._pspw.Centre()

		if version.isDevVersion():
			self._pspw.Show(True) #DEBUG
Esempio n. 13
0
def main():
    parser = OptionParser(usage="usage: %prog [options] <X,Y> <filename>[, <X,Y> <filename>][, ...]")
    parser.add_option(
        "-p", "--profile", action="store", type="string", dest="profile", help="Encoded profile to use for the print"
    )
    parser.add_option("-o", "--output", action="store", type="string", dest="output", help="Output filename")
    (options, args) = parser.parse_args()
    if options.output is None:
        print "Missing output filename"
        sys.exit(1)
    if options.profile is not None:
        profile.loadGlobalProfileFromString(options.profile)
    options.output = fixUTF8(options.output)

    clearZ = 0
    resultFile = open(options.output, "w")
    for idx in xrange(0, len(args), 2):
        position = map(float, args[idx].split(","))
        if len(position) < 9 + 2:
            position = position[0:2]
            position += [1, 0, 0]
            position += [0, 1, 0]
            position += [0, 0, 1]
        filenames = fixUTF8(args[idx + 1]).split("|")

        profile.setTempOverride("object_center_x", position[0])
        profile.setTempOverride("object_center_y", position[1])
        if idx == 0:
            resultFile.write(";TYPE:CUSTOM\n")
            resultFile.write(
                profile.getAlterationFileContents("start.gcode").replace(
                    "?filename?", " ".join(filenames).encode("ascii", "replace")
                )
            )
        else:
            resultFile.write(";TYPE:CUSTOM\n")
            n = output[-1].rfind("Z") + 1
            zString = output[-1][n : n + 20]
            zString = zString[0 : zString.find(" ")]
            clearZ = max(clearZ, float(zString) + 10)
            profile.setTempOverride("clear_z", clearZ)
            print position
            print profile.getAlterationFileContents("nextobject.gcode")
            resultFile.write(
                profile.getAlterationFileContents("nextobject.gcode").replace(
                    "?filename?", " ".join(filenames).encode("ascii", "replace")
                )
            )

        output = []
        for filename in filenames:
            extruderNr = filenames.index(filename)
            profile.resetTempOverride()
            if extruderNr > 0:
                profile.setTempOverride(
                    "object_center_x", position[0] - profile.getPreferenceFloat("extruder_offset_x%d" % (extruderNr))
                )
                profile.setTempOverride(
                    "object_center_y", position[1] - profile.getPreferenceFloat("extruder_offset_y%d" % (extruderNr))
                )
                profile.setTempOverride("fan_enabled", "False")
                profile.setTempOverride("skirt_line_count", "0")
                profile.setTempOverride("alternative_center", filenames[0])
            else:
                profile.setTempOverride("object_center_x", position[0])
                profile.setTempOverride("object_center_y", position[1])
            profile.setTempOverride("object_matrix", ",".join(map(str, position[2:11])))
            output.append(export.getOutput(filename))
            profile.resetTempOverride()
        if len(output) == 1:
            resultFile.write(output[0])
        else:
            stitchMultiExtruder(output, resultFile)
    resultFile.write(";TYPE:CUSTOM\n")
    resultFile.write(profile.getAlterationFileContents("end.gcode"))
    resultFile.close()

    print "Running plugins"
    ret = profile.runPostProcessingPlugins(options.output)
    if ret is not None:
        print ret
    print "Finalizing %s" % (os.path.basename(options.output))
    if profile.getPreference("submit_slice_information") == "True":
        filenames = fixUTF8(args[idx + 1]).split("|")
        for filename in filenames:
            m = hashlib.sha512()
            f = open(filename, "rb")
            while True:
                chunk = f.read(1024)
                if not chunk:
                    break
                m.update(chunk)
            f.close()
            data = {
                "processor": platform.processor(),
                "machine": platform.machine(),
                "platform": platform.platform(),
                "profile": profile.getGlobalProfileString(),
                "preferences": profile.getGlobalPreferencesString(),
                "modelhash": m.hexdigest(),
                "version": version.getVersion(),
            }
            try:
                f = urllib2.urlopen("http://platform.ultimaker.com/curastats/", data=urllib.urlencode(data), timeout=5)
                f.read()
                f.close()
            except:
                pass