def writeOutput(fileName, fileNamePenultimate, fileNameSuffix, filePenultimateWritten, gcodeText=''): 'Open penultimate file with outside program given text.' repository = settings.getReadRepository(ClairvoyanceRepository()) if repository.activateClairvoyance.value: if not filePenultimateWritten: archive.writeFileText(fileNamePenultimate, gcodeText) getWindowAnalyzeFile(fileNamePenultimate, repository)
def writeChainTextWithNounMessage(fileName, procedure, shouldAnalyze=True): 'Get and write a crafted shape file.' print('') print('The %s tool is parsing the file:' % procedure) print(os.path.basename(fileName)) print('') startTime = time.time() fileNameSuffix = fileName[:fileName.rfind('.' )] + '_' + procedure + '.gcode' craftText = getChainText(fileName, procedure) if craftText == '': print( 'Warning, there was no text output in writeChainTextWithNounMessage in skeinforge_craft for:' ) print(fileName) return archive.writeFileText(fileNameSuffix, craftText) window = None if shouldAnalyze: window = skeinforge_analyze.writeOutput(fileName, fileNameSuffix, fileNameSuffix, True, craftText) print('') print('The %s tool has created the file:' % procedure) print(fileNameSuffix) print('') print('It took %s to craft the file.' % euclidean.getDurationString(time.time() - startTime)) return window
def addInitializationToOutput(self): """Add initialization gcode to the output.""" self.addFromUpperLowerFile(self.repository.nameOfStartFile.value) # Add a start file if it exists. self.distanceFeedRate.addTagBracketedLine('creation', 'skeinforge') # GCode formatted comment absoluteFilePathUntilDot = os.path.abspath(__file__)[: os.path.abspath(__file__).rfind('.')] if absoluteFilePathUntilDot == '/home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/skeinforge_application/skeinforge_plugins/craft_plugins/preface': #is this script on Enrique's computer? archive.writeFileText(archive.getVersionFileName(), date.today().isoformat().replace('-', '.')[2 :]) versionText = archive.getFileText(archive.getVersionFileName()) self.distanceFeedRate.addTagBracketedLine('version', versionText) # GCode formatted comment self.distanceFeedRate.addLine('(<extruderInitialization>)') # GCode formatted comment if self.repository.setPositioningToAbsolute.value: self.distanceFeedRate.addLine('G90 ;set positioning to absolute') # Set positioning to absolute. if self.repository.setUnitsToMillimeters.value: self.distanceFeedRate.addLine('G21 ;set units to millimeters') # Set units to millimeters. if self.repository.startAtHome.value: self.distanceFeedRate.addLine('G28 ;start at home') # Start at home. if self.repository.resetExtruder.value: self.distanceFeedRate.addLine('G92 E0 ;reset extruder distance') # Start at home. craftTypeName = skeinforge_profile.getCraftTypeName() self.distanceFeedRate.addTagBracketedLine('craftTypeName', craftTypeName) self.distanceFeedRate.addTagBracketedLine('decimalPlacesCarried', self.distanceFeedRate.decimalPlacesCarried) extrusionHeight = float(self.svgReader.sliceDictionary['extrusionHeight']) self.distanceFeedRate.addTagRoundedLine('extrusionHeight', extrusionHeight) if self.repository.meta.value: self.distanceFeedRate.addTagBracketedLine('meta', self.repository.meta.value) extrusionWidth = float(self.svgReader.sliceDictionary['extrusionWidth']) self.distanceFeedRate.addTagRoundedLine('extrusionWidth', extrusionWidth) self.distanceFeedRate.addTagBracketedLine('profileName', skeinforge_profile.getProfileName(craftTypeName)) procedureNames = self.svgReader.sliceDictionary['procedureName'].replace(',', ' ').split() for procedureName in procedureNames: self.distanceFeedRate.addTagBracketedLine('procedureName', procedureName) self.distanceFeedRate.addTagBracketedLine('procedureName', 'preface') self.distanceFeedRate.addLine('(</extruderInitialization>)') # Initialization is finished, extrusion is starting. self.distanceFeedRate.addLine('(<crafting>)') # Initialization is finished, crafting is starting.
def getOutput(fileName): 'Export a gcode linear move file.' if fileName == '': return None repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName.encode('ascii', 'replace')) + ' is being chain exported.') gcodeText = gcodec.getGcodeFileText(fileName, '') procedures = skeinforge_craft.getProcedures('export', gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures(fileName, procedures[: -1], gcodeText) if gcodeText == '': return None fileNamePenultimate = fileName[: fileName.rfind('.')] + '_penultimate.gcode' if repository.savePenultimateGcode.value: archive.writeFileText(fileNamePenultimate, gcodeText) print('The penultimate file is saved as ' + archive.getSummarizedFileName(fileNamePenultimate)) exportGcode = getCraftedTextFromText(gcodeText, repository) replaceableExportGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule is None: replaceableExportGcode = exportGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportGcode = selectedPluginModule.getOutput(exportGcode) #else: # selectedPluginModule.writeOutput(outputFilename, exportGcode) if replaceableExportGcode is not None: replaceableExportGcode = getReplaceableExportGcode(repository.nameOfReplaceFile.value, replaceableExportGcode) if repository.alsoSendOutputTo.value != '': if replaceableExportGcode == None: replaceableExportGcode = selectedPluginModule.getOutput(exportGcode) sendOutputTo(repository.alsoSendOutputTo.value, replaceableExportGcode) print('It took %s to export the file.' % euclidean.getDurationString(time.time() - startTime)) return replaceableExportGcode
def writeXMLObject(absoluteFolderDirectory, derivation, fileNames, target, xmlObject): "Write one instance of the xmlObject." extension = evaluate.getEvaluatedString( xmlObject.getFabricationExtension(), derivation.elementNode, 'extension') fileNameRoot = derivation.fileName if fileNameRoot == '': fileNameRoot = evaluate.getEvaluatedString('', target, 'name') fileNameRoot = evaluate.getEvaluatedString(fileNameRoot, target, 'id') fileNameRoot += derivation.suffix fileName = '%s.%s' % (fileNameRoot, extension) suffixIndex = 2 while fileName in fileNames: fileName = '%s_%s.%s' % (fileNameRoot, suffixIndex, extension) suffixIndex += 1 absoluteFileName = os.path.join(absoluteFolderDirectory, fileName) fileNames.append(fileName) archive.makeDirectory(absoluteFolderDirectory) if not derivation.writeMatrix: xmlObject.matrix4X4 = matrix.Matrix() print('The write tool generated the file:') print(absoluteFileName) archive.writeFileText( absoluteFileName, xmlObject.getFabricationText(derivation.addLayerTemplate))
def exportProfileAsZipFile(abridgedSettings, suffixDirectoryPath, suffixFileNameWithoutExtension): 'Export the profile from the gcode text as a zip file.' if len(abridgedSettings) < 1: print('Warning, the synopsis zip file could not be generated because there are no setting comments in the file.') return suffixFileName = suffixFileNameWithoutExtension + 'zip' abridgedSettingsDictionary = {} for abridgedSetting in abridgedSettings: euclidean.addElementToListDictionary(abridgedSetting, abridgedSetting.procedure, abridgedSettingsDictionary) abridgedSettingFileNamePaths = [] for abridgedSettingsKey in abridgedSettingsDictionary: abridgedSettings = abridgedSettingsDictionary[abridgedSettingsKey] repositoryWriter = settings.getRepositoryWriter(abridgedSettingsKey) addAbridgedSettings(abridgedSettings, repositoryWriter) abridgedSettingFileNamePath = FileNamePath(suffixDirectoryPath, abridgedSettingsKey + '.csv') abridgedSettingFileNamePaths.append(abridgedSettingFileNamePath) archive.writeFileText(abridgedSettingFileNamePath.path, repositoryWriter.getvalue()) time.sleep(0.2) # the sleep is so that the file system is sure to be consistent zipArchive = zipfile.ZipFile(suffixFileName, 'w', compression=zipfile.ZIP_DEFLATED) for abridgedSettingFileNamePath in abridgedSettingFileNamePaths: zipArchive.write(abridgedSettingFileNamePath.path, abridgedSettingFileNamePath.fileName) zipArchive.close() time.sleep(0.2) # the sleep is so that the file system is sure to be consistent for abridgedSettingFileNamePath in abridgedSettingFileNamePaths: os.remove(abridgedSettingFileNamePath.path) print('The synopsis zip file is saved as ' + archive.getSummarizedFileName(suffixFileName))
def addInitializationToOutput(self): "Add initialization gcode to the output." self.addFromUpperLowerFile(self.repository.nameOfStartFile.value) # Add a start file if it exists. self.distanceFeedRate.addTagBracketedLine('creation', 'skeinforge') # GCode formatted comment absoluteFilePathUntilDot = os.path.abspath(__file__)[: os.path.abspath(__file__).rfind('.')] if absoluteFilePathUntilDot == '/home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/skeinforge_application/skeinforge_plugins/craft_plugins/preface': #is this script on Enrique's computer? archive.writeFileText(archive.getVersionFileName(), date.today().isoformat().replace('-', '.')[2 :]) versionText = archive.getFileText(archive.getVersionFileName()) self.distanceFeedRate.addTagBracketedLine('version', versionText) # GCode formatted comment self.distanceFeedRate.addLine('(<extruderInitialization>)') # GCode formatted comment if self.repository.setPositioningToAbsolute.value: self.distanceFeedRate.addLine('G90 ;set positioning to absolute') # Set positioning to absolute. if self.repository.setUnitsToMillimeters.value: self.distanceFeedRate.addLine('G21 ;set units to millimeters') # Set units to millimeters. if self.repository.startAtHome.value: self.distanceFeedRate.addLine('G28 ;start at home') # Start at home. if self.repository.turnExtruderOffAtStartUp.value: self.distanceFeedRate.addLine('M103') # Turn extruder off. craftTypeName = skeinforge_profile.getCraftTypeName() self.distanceFeedRate.addTagBracketedLine('craftTypeName', craftTypeName) self.distanceFeedRate.addTagBracketedLine('decimalPlacesCarried', self.distanceFeedRate.decimalPlacesCarried) layerThickness = float(self.svgReader.sliceDictionary['layerThickness']) self.distanceFeedRate.addTagRoundedLine('layerThickness', layerThickness) if self.repository.meta.value: self.distanceFeedRate.addTagBracketedLine('meta', self.repository.meta.value) perimeterWidth = float(self.svgReader.sliceDictionary['perimeterWidth']) self.distanceFeedRate.addTagRoundedLine('perimeterWidth', perimeterWidth) self.distanceFeedRate.addTagBracketedLine('profileName', skeinforge_profile.getProfileName(craftTypeName)) procedureNames = self.svgReader.sliceDictionary['procedureName'].replace(',', ' ').split() for procedureName in procedureNames: self.distanceFeedRate.addTagBracketedLine('procedureName', procedureName) self.distanceFeedRate.addTagBracketedLine('procedureName', 'preface') self.distanceFeedRate.addLine('(</extruderInitialization>)') # Initialization is finished, extrusion is starting. self.distanceFeedRate.addLine('(<crafting>)') # Initialization is finished, crafting is starting.
def addInitializationToOutput(self): "Add initialization gcode to the output." self.addFromUpperLowerFile( self.prefaceRepository.nameOfStartFile.value ) # Add a start file if it exists. self.distanceFeedRate.addTagBracketedLine('creation', 'skeinforge') # GCode formatted comment absoluteFilePathUntilDot = os.path.abspath( __file__ )[ : os.path.abspath( __file__ ).rfind('.') ] if absoluteFilePathUntilDot == '/home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/skeinforge_application/skeinforge_plugins/craft_plugins/preface': #is this script on Enrique's computer? archive.writeFileText( archive.getVersionFileName(), date.today().isoformat().replace('-', '.')[ 2 : ] ) versionText = archive.getFileText( archive.getVersionFileName() ) self.distanceFeedRate.addTagBracketedLine('version', versionText ) # GCode formatted comment self.distanceFeedRate.addLine('(<extruderInitialization>)') # GCode formatted comment if self.prefaceRepository.setPositioningToAbsolute.value: self.distanceFeedRate.addLine('G90') # Set positioning to absolute. if self.prefaceRepository.setUnitsToMillimeters.value: self.distanceFeedRate.addLine('G21') # Set units to millimeters. if self.prefaceRepository.startAtHome.value: self.distanceFeedRate.addLine('G28') # Start at home. if self.prefaceRepository.turnExtruderOffAtStartUp.value: self.distanceFeedRate.addLine('M103') # Turn extruder off. craftTypeName = skeinforge_profile.getCraftTypeName() self.distanceFeedRate.addTagBracketedLine('craftTypeName', craftTypeName ) self.distanceFeedRate.addTagBracketedLine('decimalPlacesCarried', self.distanceFeedRate.decimalPlacesCarried ) layerThickness = float( self.svgReader.sliceDictionary['layerThickness'] ) self.distanceFeedRate.addTagBracketedLine('layerThickness', self.distanceFeedRate.getRounded( layerThickness ) ) if self.prefaceRepository.meta.value: self.distanceFeedRate.addTagBracketedLine('meta', self.prefaceRepository.meta.value ) perimeterWidth = float( self.svgReader.sliceDictionary['perimeterWidth'] ) self.distanceFeedRate.addTagBracketedLine('perimeterWidth', self.distanceFeedRate.getRounded( perimeterWidth ) ) self.distanceFeedRate.addTagBracketedLine('profileName', skeinforge_profile.getProfileName( craftTypeName ) ) self.distanceFeedRate.addTagBracketedLine('procedureDone', self.svgReader.sliceDictionary['procedureDone'] ) self.distanceFeedRate.addTagBracketedLine('procedureDone', 'preface') self.distanceFeedRate.addLine('(</extruderInitialization>)') # Initialization is finished, extrusion is starting. self.distanceFeedRate.addLine('(<extrusion>)') # Initialization is finished, extrusion is starting.
def getWindowAnalyzeFile(fileName): "Get file interpretion." startTime = time.time() carving = getCarving(fileName) if carving == None: return None interpretGcode = str( carving ) if interpretGcode == '': return None repository = settings.getReadRepository( InterpretRepository() ) if repository.printInterpretion.value: print(interpretGcode) suffixFileName = fileName[ : fileName.rfind('.') ] + '_interpret.' + carving.getInterpretationSuffix() suffixDirectoryName = os.path.dirname(suffixFileName) suffixReplacedBaseName = os.path.basename(suffixFileName).replace(' ', '_') suffixFileName = os.path.join( suffixDirectoryName, suffixReplacedBaseName ) archive.writeFileText( suffixFileName, interpretGcode ) print('The interpret file is saved as ' + archive.getSummarizedFileName(suffixFileName) ) print('It took %s to interpret the file.' % euclidean.getDurationString( time.time() - startTime ) ) textProgram = repository.textProgram.value if textProgram == '': return None if textProgram == 'webbrowser': settings.openWebPage(suffixFileName) return None textFilePath = '"' + os.path.normpath(suffixFileName) + '"' # " to send in file name with spaces shellCommand = textProgram + ' ' + textFilePath print('Sending the shell command:') print(shellCommand) commandResult = os.system(shellCommand) if commandResult != 0: print('It may be that the system could not find the %s program.' % textProgram ) print('If so, try installing the %s program or look for another one, like Open Office which can be found at:' % textProgram ) print('http://www.openoffice.org/') print('Open office writer can then be started from the command line with the command "soffice -writer".')
def getWindowAnalyzeFile(fileName): "Get file interpretion." startTime = time.time() carving = getCarving(fileName) if carving is None: return None interpretGcode = str( carving ) if interpretGcode == '': return None repository = settings.getReadRepository( InterpretRepository() ) if repository.printInterpretion.value: print( interpretGcode ) suffixFileName = fileName[ : fileName.rfind('.') ] + '_interpret.' + carving.getInterpretationSuffix() suffixDirectoryName = os.path.dirname(suffixFileName) suffixReplacedBaseName = os.path.basename(suffixFileName).replace(' ', '_') suffixFileName = os.path.join( suffixDirectoryName, suffixReplacedBaseName ) archive.writeFileText( suffixFileName, interpretGcode ) print('The interpret file is saved as ' + archive.getSummarizedFileName(suffixFileName) ) print('It took %s to interpret the file.' % euclidean.getDurationString( time.time() - startTime ) ) textProgram = repository.textProgram.value if textProgram == '': return None if textProgram == 'webbrowser': settings.openWebPage(suffixFileName) return None textFilePath = '"' + os.path.normpath(suffixFileName) + '"' # " to send in file name with spaces shellCommand = textProgram + ' ' + textFilePath print('Sending the shell command:') print(shellCommand) commandResult = os.system(shellCommand) if commandResult != 0: print('It may be that the system could not find the %s program.' % textProgram ) print('If so, try installing the %s program or look for another one, like Open Office which can be found at:' % textProgram ) print('http://www.openoffice.org/') print('Open office writer can then be started from the command line with the command "soffice -writer".')
def writeXMLElement(fileNames, target, xmlElement): "Write target." object = target.object if object == None: print('Warning, writeTarget in write could not get object for:') print(xmlElement) return fileNameRoot = evaluate.getEvaluatedStringDefault('', 'name', target) fileNameRoot = evaluate.getEvaluatedStringDefault(fileNameRoot, 'id', target) fileNameRoot = evaluate.getEvaluatedStringDefault(fileNameRoot, 'file', xmlElement) fileNameRoot += evaluate.getEvaluatedStringDefault('', 'suffix', xmlElement) extension = evaluate.getEvaluatedStringDefault(object.getFabricationExtension(), 'extension', xmlElement) fileName = '%s.%s' % (fileNameRoot, extension) suffixIndex = 1 while fileName in fileNames: fileName = '%s_%s.%s' % (fileNameRoot, suffixIndex, extension) suffixIndex += 1 folderName = evaluate.getEvaluatedStringDefault('', 'folder', xmlElement) absoluteFolderDirectory = os.path.join(os.path.dirname(xmlElement.getRoot().parser.fileName), folderName) absoluteFileName = os.path.abspath(os.path.join(absoluteFolderDirectory, fileName)) if 'models/' not in absoluteFileName: print('Warning, models/ was not in the absolute file path, so for security nothing will be done for:') print(xmlElement) print('For which the absolute file path is:') print(absoluteFileName) print('The write tool can only write a file which has models/ in the file path.') print('To write the file, move the file into a folder called model/ or a subfolder which is inside the model folder tree.') return fileNames.append(fileName) archive.makeDirectory(absoluteFolderDirectory) if not evaluate.getEvaluatedBooleanDefault(True, 'writeMatrix', xmlElement): object.matrix4X4 = matrix.Matrix() print('The write tool generated the file:') print(absoluteFileName) archive.writeFileText(absoluteFileName, object.getFabricationText())
def readWriteNavigationHelp(documentDirectoryPath, transferredFileNameIndex, transferredFileNames): 'Read the hypertext help documents, and add the navigation lines to them.' fileName = os.path.basename(transferredFileNames[transferredFileNameIndex]) print('readWriteNavigationHelp ' + fileName) filePath = os.path.join(documentDirectoryPath, fileName) fileText = archive.getFileText(filePath) fileText = getNavigationHypertext(fileText, transferredFileNameIndex, transferredFileNames) archive.writeFileText(filePath, fileText)
def writeOutput( fileName, gcodeText = ''): "Write the exported version of a gcode file." binary16ByteRepository = Binary16ByteRepository() settings.getReadRepository( binary16ByteRepository ) gcodeText = gcodec.getGcodeFileText(fileName, gcodeText) skeinOutput = getOutput( gcodeText, binary16ByteRepository ) suffixFileName = fileName[ : fileName.rfind('.') ] + '.' + binary16ByteRepository.fileExtension.value archive.writeFileText( suffixFileName, skeinOutput ) print('The converted file is saved as ' + archive.getSummarizedFileName(suffixFileName) )
def writeOutput( fileName, gcodeText = ''): "Write the exported version of a gcode file." gcodeText = gcodec.getGcodeFileText(fileName, gcodeText) repository = GcodeTimeSegmentRepository() settings.getReadRepository(repository) output = getOutput(gcodeText, repository) suffixFileName = fileName[ : fileName.rfind('.') ] + '_gcode_time_segment.gcode' archive.writeFileText( suffixFileName, output ) print('The converted file is saved as ' + archive.getSummarizedFileName(suffixFileName) )
def writeOutput(fileName, shouldAnalyze=True): "Export a gcode linear move file." if fileName == "": return None repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print("File " + archive.getSummarizedFileName(fileName) + " is being chain exported.") fileNameSuffix = fileName[: fileName.rfind(".")] if repository.addExportSuffix.value: fileNameSuffix += "_export" gcodeText = gcodec.getGcodeFileText(fileName, "") if repository.addProfileExtension.value: profileName = skeinforge_profile.getProfileName(skeinforge_profile.getCraftTypeName()) if profileName: fileNameSuffix += "." + string.replace(profileName, " ", "_") if repository.addDescriptiveExtension.value: fileNameSuffix += getDescriptiveExtension(gcodeText) if repository.addTimestampExtension.value: fileNameSuffix += "." + getFirstValue(gcodeText, "(<timeStampPreface>") fileNameSuffix += "." + repository.fileExtension.value procedures = skeinforge_craft.getProcedures("export", gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures(fileName, procedures[:-1], gcodeText) if gcodeText == "": return None fileNamePenultimate = fileName[: fileName.rfind(".")] + "_penultimate.gcode" filePenultimateWritten = False if repository.savePenultimateGcode.value: archive.writeFileText(fileNamePenultimate, gcodeText) filePenultimateWritten = True print("The penultimate file is saved as " + archive.getSummarizedFileName(fileNamePenultimate)) exportGcode = getCraftedTextFromText(gcodeText, repository) window = None if shouldAnalyze: window = skeinforge_analyze.writeOutput( fileName, fileNamePenultimate, fileNameSuffix, filePenultimateWritten, gcodeText ) replaceableExportGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule == None: replaceableExportGcode = exportGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportGcode = selectedPluginModule.getOutput(exportGcode) else: selectedPluginModule.writeOutput(fileNameSuffix, exportGcode) if replaceableExportGcode != None: replaceableExportGcode = getReplaceableExportGcode(repository.nameOfReplaceFile.value, replaceableExportGcode) archive.writeFileText(fileNameSuffix, replaceableExportGcode) print("The exported file is saved as " + archive.getSummarizedFileName(fileNameSuffix)) if repository.alsoSendOutputTo.value != "": if replaceableExportGcode == None: replaceableExportGcode = selectedPluginModule.getOutput(exportGcode) sendOutputTo(repository.alsoSendOutputTo.value, replaceableExportGcode) print("It took %s to export the file." % euclidean.getDurationString(time.time() - startTime)) return window
def sendOutputTo(text, toValue): 'Send output to a file or a standard output.' if toValue == 'sys.stderr': print(text, ' ', '\n', sys.stderr) return if toValue == 'sys.stdout': print(text, ' ', '\n', sys.stdout) return archive.writeFileText(toValue, text)
def sendOutputTo(text, toValue): """Send output to a file or a standard output.""" if toValue == 'sys.stderr': print(text, ' ', '\n', sys.stderr) return if toValue == 'sys.stdout': print(text, ' ', '\n', sys.stdout) return archive.writeFileText(toValue, text)
def exportProfileAsCSVFile(abridgedSettings, suffixFileNameWithoutExtension): 'Export the profile from the gcode text as a csv file.' if len(abridgedSettings) < 1: print('Warning, the synopsis csv file could not be generated because there are no setting comments in the file.') return repositoryWriter = settings.getRepositoryWriter('profile') suffixFileName = suffixFileNameWithoutExtension + 'csv' addAbridgedSettings(abridgedSettings, repositoryWriter) archive.writeFileText(suffixFileName, repositoryWriter.getvalue()) print('The synopsis csv file is saved as ' + archive.getSummarizedFileName(suffixFileName))
def writeOutput(fileName, shouldAnalyze=True): 'Export a gcode linear move file.' if fileName == '': return None repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName) + ' is being chain exported.') fileNameSuffix = fileName[:fileName.rfind('.')] if repository.addExportSuffix.value: fileNameSuffix += '_export' fileNameSuffix += '.' + repository.fileExtension.value gcodeText = gcodec.getGcodeFileText(fileName, '') procedures = skeinforge_craft.getProcedures('export', gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures( fileName, procedures[:-1], gcodeText) if gcodeText == '': return None if repository.savePenultimateGcode.value: penultimateFileName = fileName[:fileName. rfind('.')] + '_penultimate.gcode' archive.writeFileText(penultimateFileName, gcodeText) print('The penultimate file is saved as ' + archive.getSummarizedFileName(penultimateFileName)) exportGcode = getCraftedTextFromText(gcodeText, repository) window = None if shouldAnalyze: window = skeinforge_analyze.writeOutput(fileName, fileNameSuffix, gcodeText) replaceableExportGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule == None: replaceableExportGcode = exportGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportGcode = selectedPluginModule.getOutput( exportGcode) else: selectedPluginModule.writeOutput(fileNameSuffix, exportGcode) if replaceableExportGcode != None: replaceableExportGcode = getReplaceableExportGcode( repository.nameOfReplaceFile.value, replaceableExportGcode) archive.writeFileText(fileNameSuffix, replaceableExportGcode) print('The exported file is saved as ' + archive.getSummarizedFileName(fileNameSuffix)) if repository.alsoSendOutputTo.value != '': if replaceableExportGcode == None: replaceableExportGcode = selectedPluginModule.getOutput( exportGcode) sendOutputTo(replaceableExportGcode, repository.alsoSendOutputTo.value) print('It took %s to export the file.' % euclidean.getDurationString(time.time() - startTime)) return window
def performAction(slicedModel): "Get carved text." filename = slicedModel.runtimeParameters.inputFilename carving = svg_writer.getCarving(filename) if carving == None: return if config.getboolean(name, 'debug'): carvingFilename = filename[:filename.rfind('.')] + '.carving.xml' archive.writeFileText(carvingFilename, str(carving)) logger.info("Carving XML written to %s", carvingFilename) CarveSkein(slicedModel).carve(carving)
def performAction(slicedModel): "Get carved text." filename = slicedModel.runtimeParameters.inputFilename carving = svg_writer.getCarving(filename) if carving == None: return if config.getboolean(name, 'debug'): carvingFilename = filename[: filename.rfind('.')] + '.carving.xml' archive.writeFileText(carvingFilename , str(carving)) logger.info("Carving XML written to %s", carvingFilename) CarveSkein(slicedModel).carve(carving)
def writeOutput(fileName=''): 'Export a gcode linear move file.' fileName = fabmetheus_interpret.getFirstTranslatorFileNameUnmodified( fileName) if fileName == '': return repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName) + ' is being chain exported.') suffixFileName = fileName[:fileName.rfind('.')] if repository.addExportSuffix.value: suffixFileName += '_export' suffixFileName += '.' + repository.fileExtension.value gcodeText = gcodec.getGcodeFileText(fileName, '') procedures = skeinforge_craft.getProcedures('export', gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures( fileName, procedures[:-1], gcodeText) if gcodeText == '': return window = skeinforge_analyze.writeOutput(fileName, suffixFileName, gcodeText) if repository.savePenultimateGcode.value: penultimateFileName = fileName[:fileName. rfind('.')] + '_penultimate.gcode' archive.writeFileText(penultimateFileName, gcodeText) print('The penultimate file is saved as ' + archive.getSummarizedFileName(penultimateFileName)) exportChainGcode = getCraftedTextFromText(gcodeText, repository) replaceableExportChainGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule == None: replaceableExportChainGcode = exportChainGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportChainGcode = selectedPluginModule.getOutput( exportChainGcode) else: selectedPluginModule.writeOutput(suffixFileName, exportChainGcode) if replaceableExportChainGcode != None: replaceableExportChainGcode = getReplaced(replaceableExportChainGcode) archive.writeFileText(suffixFileName, replaceableExportChainGcode) print('The exported file is saved as ' + archive.getSummarizedFileName(suffixFileName)) if repository.alsoSendOutputTo.value != '': if replaceableExportChainGcode == None: replaceableExportChainGcode = selectedPluginModule.getOutput( exportChainGcode) exec('print >> ' + repository.alsoSendOutputTo.value + ', replaceableExportChainGcode') print('It took %s to export the file.' % euclidean.getDurationString(time.time() - startTime)) return window
def writeOutput(fileName, shouldAnalyze=True): 'Export a gcode linear move file.' if fileName == '': return None repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName) + ' is being chain exported.') fileNameSuffix = fileName[: fileName.rfind('.')] if repository.addExportSuffix.value: fileNameSuffix += '_export' gcodeText = gcodec.getGcodeFileText(fileName, '') procedures = skeinforge_craft.getProcedures('export', gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures(fileName, procedures[: -1], gcodeText) if gcodeText == '': return None if repository.addProfileExtension.value: fileNameSuffix += '.' + getFirstValue(gcodeText, '(<profileName>') if repository.addDescriptiveExtension.value: print( 'getDescriptiveExtension(gcodeText)') print( getDescriptiveExtension(gcodeText)) fileNameSuffix += getDescriptiveExtension(gcodeText) if repository.addTimestampExtension.value: fileNameSuffix += '.' + getFirstValue(gcodeText, '(<timeStampPreface>') fileNameSuffix += '.' + repository.fileExtension.value fileNamePenultimate = fileName[: fileName.rfind('.')] + '_penultimate.gcode' filePenultimateWritten = False if repository.savePenultimateGcode.value: archive.writeFileText(fileNamePenultimate, gcodeText) filePenultimateWritten = True print('The penultimate file is saved as ' + archive.getSummarizedFileName(fileNamePenultimate)) exportGcode = getCraftedTextFromText(gcodeText, repository) window = None if shouldAnalyze and repository.analyzeGcode.value: window = skeinforge_analyze.writeOutput(fileName, fileNamePenultimate, fileNameSuffix, filePenultimateWritten, gcodeText) replaceableExportGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule == None: replaceableExportGcode = exportGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportGcode = selectedPluginModule.getOutput(exportGcode) else: selectedPluginModule.writeOutput(fileNameSuffix, exportGcode) if replaceableExportGcode != None: replaceableExportGcode = getReplaceableExportGcode(repository.nameOfReplaceFile.value, replaceableExportGcode) archive.writeFileText( fileNameSuffix, replaceableExportGcode ) print('The exported file is saved as ' + archive.getSummarizedFileName(fileNameSuffix)) if repository.alsoSendOutputTo.value != '': if replaceableExportGcode == None: replaceableExportGcode = selectedPluginModule.getOutput(exportGcode) sendOutputTo(repository.alsoSendOutputTo.value, replaceableExportGcode) print('It took %s to export the file.' % euclidean.getDurationString(time.time() - startTime)) return window
def writeContentsFile(documentDirectoryPath, hypertextFiles): 'Write the contents file.' output = cStringIO.StringIO() output.write('<html>\n <head>\n <title>Contents</title>\n </head>\n <body>\n') navigationLine = getNavigationLine('Contents', 'Previous', getNextLinkText(hypertextFiles, 0)) output.write(navigationLine) for hypertextFile in hypertextFiles: writeContentsLine(hypertextFile, output) output.write(navigationLine) output.write(' </body>\n</html>\n') filePath = os.path.join( documentDirectoryPath, 'contents.html') archive.writeFileText(filePath, output.getvalue())
def readWriteDeleteHypertextHelp(documentDirectoryPath, hypertextFileIndex, hypertextFiles, transferredFileNames): 'Read the pydoc hypertext help documents, write them in the documentation folder then delete the originals.' fileName = os.path.basename(hypertextFiles[hypertextFileIndex]) print('readWriteDeleteHypertextHelp ' + fileName) filePath = os.path.join(documentDirectoryPath, fileName) fileText = archive.getFileText(fileName) fileText = getWrappedHypertext(fileText, hypertextFileIndex, hypertextFiles) if fileText.find('This page is in the table of contents.') > - 1: fileText = fileText.replace('This page is in the table of contents.', '') transferredFileNames.append(fileName) archive.writeFileText(filePath, fileText) os.remove(fileName)
def sendOutputTo(outputTo, text): 'Send output to a file or a standard output.' if outputTo.endswith('stderr'): sys.stderr.write(text) sys.stderr.write('\n') sys.stderr.flush() return if outputTo.endswith('stdout'): sys.stdout.write(text) sys.stdout.write('\n') sys.stdout.flush() return archive.writeFileText(outputTo, text)
def sendOutputTo(outputTo, text): "Send output to a file or a standard output." if outputTo.endswith("stderr"): sys.stderr.write(text) sys.stderr.write("\n") sys.stderr.flush() return if outputTo.endswith("stdout"): sys.stdout.write(text) sys.stdout.write("\n") sys.stdout.flush() return archive.writeFileText(outputTo, text)
def addInitializationToOutput(self): "Add initialization gcode to the output." self.distanceFeedRate.addTagBracketedLine("format", "skeinforge gcode") absoluteFilePathUntilDot = archive.getUntilDot(archive.getCraftPluginsDirectoryPath("preface.py")) dateTodayString = date.today().isoformat().replace("-", ".")[2:] if ( absoluteFilePathUntilDot == "/home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/skeinforge_application/skeinforge_plugins/craft_plugins/preface" ): # is this script on Enrique's computer? archive.writeFileText(archive.getVersionFileName(), dateTodayString) versionText = archive.getFileText(archive.getVersionFileName()) self.distanceFeedRate.addTagBracketedLine("version", versionText) dateTimeTuple = datetime.now().timetuple() created = dateTodayString + "|%s:%s" % (dateTimeTuple[3], dateTimeTuple[4]) self.distanceFeedRate.addTagBracketedLine("created", created) self.distanceFeedRate.addLine("(<extruderInitialization>)") if self.repository.setPositioningToAbsolute.value: self.distanceFeedRate.addLine("G90 ;set positioning to absolute") # Set positioning to absolute. if self.repository.setUnitsToMillimeters.value: self.distanceFeedRate.addLine("G21 ;set units to millimeters") # Set units to millimeters. if self.repository.startAtHome.value: self.distanceFeedRate.addLine("G28 ;start at home") # Start at home. if self.repository.turnExtruderOffAtStartUp.value: self.distanceFeedRate.addLine("M103") # Turn extruder off. craftTypeName = skeinforge_profile.getCraftTypeName() self.distanceFeedRate.addTagBracketedLine("craftTypeName", craftTypeName) self.distanceFeedRate.addTagBracketedLine("decimalPlacesCarried", self.distanceFeedRate.decimalPlacesCarried) layerHeight = float(self.svgReader.sliceDictionary["layerHeight"]) self.distanceFeedRate.addTagRoundedLine("layerThickness", layerHeight) self.distanceFeedRate.addTagRoundedLine("layerHeight", layerHeight) if self.repository.meta.value: self.distanceFeedRate.addTagBracketedLine("meta", self.repository.meta.value) edgeWidth = float(self.svgReader.sliceDictionary["edgeWidth"]) self.distanceFeedRate.addTagRoundedLine("edgeWidth", edgeWidth) self.distanceFeedRate.addTagRoundedLine("perimeterWidth", edgeWidth) self.distanceFeedRate.addTagBracketedLine("profileName", skeinforge_profile.getProfileName(craftTypeName)) self.distanceFeedRate.addLine("(<settings>)") pluginFileNames = skeinforge_craft.getPluginFileNames() for pluginFileName in pluginFileNames: self.addToolSettingLines(pluginFileName) self.distanceFeedRate.addLine("(</settings>)") self.distanceFeedRate.addTagBracketedLine("timeStampPreface", strftime("%Y%m%d_%H%M%S")) procedureNames = self.svgReader.sliceDictionary["procedureName"].replace(",", " ").split() for procedureName in procedureNames: self.distanceFeedRate.addTagBracketedProcedure(procedureName) self.distanceFeedRate.addTagBracketedProcedure("preface") self.distanceFeedRate.addLine( "(</extruderInitialization>)" ) # Initialization is finished, extrusion is starting. self.distanceFeedRate.addLine("(<crafting>)") # Initialization is finished, crafting is starting.
def writeOutput(fileName=''): "Carve a GNU Triangulated Surface file." startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName) + ' is being carved.') repository = CarveRepository() settings.getReadRepository(repository) carveGcode = getCraftedText( fileName, '', repository ) if carveGcode == '': return suffixFileName = archive.getFilePathWithUnderscoredBasename( fileName, '_carve.svg') archive.writeFileText( suffixFileName, carveGcode ) print('The carved file is saved as ' + archive.getSummarizedFileName(suffixFileName) ) print('It took %s to carve the file.' % euclidean.getDurationString( time.time() - startTime ) ) settings.openSVGPage( suffixFileName, repository.svgViewer.value )
def carve(self, carving): "Parse 3D model file and store the carved slicedModel." carving.setCarveInfillInDirectionOfBridge(self.infillBridgeDirection) carving.setCarveLayerThickness(self.layerHeight) importRadius = 0.5 * self.importCoarsenessRatio * abs( self.extrusionWidth) carving.setCarveImportRadius( max(importRadius, 0.001 * self.layerHeight)) carving.setCarveIsCorrectMesh(self.correctMesh) rotatedLoopLayers = carving.getCarveRotatedBoundaryLayers() if len(rotatedLoopLayers) < 1: logger.warning( 'There are no slices for the model, this could be because the model is too small for the Layer Thickness.' ) return self.slicedModel.carvingCornerMaximum = carving.getCarveCornerMaximum() self.slicedModel.carvingCornerMinimum = carving.getCarveCornerMinimum() toBePrintedLayers = rotatedLoopLayers[self.layerPrintFrom:self. layerPrintTo] for toBePrintedLayer in toBePrintedLayers: sortedLoops = [] for toBePrintedLayerLoop in toBePrintedLayer.loops: lowerLeftPoint = self.getLowerLeftCorner(toBePrintedLayerLoop) lowerLeftIndex = toBePrintedLayerLoop.index(lowerLeftPoint) sortedLoops.append(toBePrintedLayerLoop[lowerLeftIndex:] + toBePrintedLayerLoop[:lowerLeftIndex]) toBePrintedLayer.loops = sortedLoops self.slicedModel.rotatedLoopLayers = toBePrintedLayers if config.getboolean(name, 'debug'): filename = self.slicedModel.runtimeParameters.inputFilename svgFilename = filename[:filename.rfind('.')] + '.svg' svgWriter = svg_writer.SVGWriter( True, self.slicedModel.carvingCornerMaximum, self.slicedModel.carvingCornerMinimum, self.slicedModel.runtimeParameters.decimalPlaces, self.slicedModel.runtimeParameters.layerHeight, self.slicedModel.runtimeParameters.layerThickness) archive.writeFileText( svgFilename, svgWriter.getReplacedSVGTemplate( self.slicedModel.runtimeParameters.inputFilename, '', self.slicedModel.rotatedLoopLayers)) logger.info("Carving SVG written to %s", svgFilename)
def writeOutput(fileName, shouldAnalyze=True): "Carve a GNU Triangulated Surface file." startTime = time.time() print("File " + archive.getSummarizedFileName(fileName) + " is being carved.") repository = CarveRepository() settings.getReadRepository(repository) carveGcode = getCraftedText(fileName, "", repository) if carveGcode == "": return suffixFileName = archive.getFilePathWithUnderscoredBasename(fileName, "_carve.svg") archive.writeFileText(suffixFileName, carveGcode) print("The carved file is saved as " + archive.getSummarizedFileName(suffixFileName)) print("It took %s to carve the file." % euclidean.getDurationString(time.time() - startTime)) if shouldAnalyze: settings.openSVGPage(suffixFileName, repository.svgViewer.value)
def execute(self): "Export the canvas as an svg file." svgFileName = archive.getFilePathWithUnderscoredBasename( self.fileName, self.suffix ) boundingBox = self.canvas.bbox( settings.Tkinter.ALL ) # tuple (w, n, e, s) self.boxW = boundingBox[0] self.boxN = boundingBox[1] boxWidth = boundingBox[2] - self.boxW boxHeight = boundingBox[3] - self.boxN print('Exported svg file saved as ' + svgFileName ) svgTemplateText = archive.getFileTextInFileDirectory( settings.__file__, os.path.join('templates', 'canvas_template.svg') ) output = cStringIO.StringIO() lines = archive.getTextLines( svgTemplateText ) firstWordTable = {} firstWordTable['height="999px"'] = ' height="%spx"' % int( round( boxHeight ) ) firstWordTable['<!--replaceLineWith_coloredLines-->'] = self.getCanvasLinesOutput() firstWordTable['replaceLineWithTitle'] = archive.getSummarizedFileName( self.fileName ) firstWordTable['width="999px"'] = ' width="%spx"' % int( round( boxWidth ) ) for line in lines: parseLineReplace( firstWordTable, line, output ) archive.writeFileText( svgFileName, output.getvalue() ) fileExtension = self.fileExtension.value svgViewer = self.svgViewer.value if svgViewer == '': return if svgViewer == 'webbrowser': settings.openWebPage( svgFileName ) return svgFilePath = '"' + os.path.normpath( svgFileName ) + '"' # " to send in file name with spaces shellCommand = svgViewer + ' ' + svgFilePath print('') if fileExtension == '': print('Sending the shell command:') print( shellCommand ) commandResult = os.system( shellCommand ) if commandResult != 0: print('It may be that the system could not find the %s program.' % svgViewer ) print('If so, try installing the %s program or look for another svg viewer, like Netscape which can be found at:' % svgViewer ) print('http://www.netscape.org/') return convertedFileName = archive.getFilePathWithUnderscoredBasename( svgFilePath, '.' + fileExtension + '"') shellCommand += ' ' + convertedFileName print('Sending the shell command:') print( shellCommand ) commandResult = os.system( shellCommand ) if commandResult != 0: print('The %s program could not convert the svg to the %s file format.' % ( svgViewer, fileExtension ) ) print('Try installing the %s program or look for another one, like Image Magick which can be found at:' % svgViewer ) print('http://www.imagemagick.org/script/index.php')
def writeXMLElement(fileNames, target, xmlElement): "Write target." object = target.object if object == None: print('Warning, writeTarget in write could not get object for:') print(xmlElement) return fileNameRoot = evaluate.getEvaluatedStringDefault('', 'name', target) fileNameRoot = evaluate.getEvaluatedStringDefault(fileNameRoot, 'id', target) fileNameRoot = evaluate.getEvaluatedStringDefault(fileNameRoot, 'file', xmlElement) fileNameRoot += evaluate.getEvaluatedStringDefault('', 'suffix', xmlElement) extension = evaluate.getEvaluatedStringDefault( object.getFabricationExtension(), 'extension', xmlElement) fileName = '%s.%s' % (fileNameRoot, extension) suffixIndex = 1 while fileName in fileNames: fileName = '%s_%s.%s' % (fileNameRoot, suffixIndex, extension) suffixIndex += 1 folderName = evaluate.getEvaluatedStringDefault('', 'folder', xmlElement) absoluteFolderDirectory = os.path.join( os.path.dirname(xmlElement.getRoot().parser.fileName), folderName) absoluteFileName = os.path.abspath( os.path.join(absoluteFolderDirectory, fileName)) if 'models/' not in absoluteFileName: print( 'Warning, models/ was not in the absolute file path, so for security nothing will be done for:' ) print(xmlElement) print('For which the absolute file path is:') print(absoluteFileName) print( 'The write tool can only write a file which has models/ in the file path.' ) print( 'To write the file, move the file into a folder called model/ or a subfolder which is inside the model folder tree.' ) return fileNames.append(fileName) archive.makeDirectory(absoluteFolderDirectory) if not evaluate.getEvaluatedBooleanDefault(True, 'writeMatrix', xmlElement): object.matrix4X4 = matrix.Matrix() print('The write tool generated the file:') print(absoluteFileName) archive.writeFileText(absoluteFileName, object.getFabricationText())
def addInitializationToOutput(self): "Add initialization gcode to the output." self.distanceFeedRate.addTagBracketedLine('format', 'skeinforge gcode') absoluteFilePathUntilDot = archive.getUntilDot(archive.getCraftPluginsDirectoryPath('preface.py')) dateTodayString = date.today().isoformat().replace('-', '.')[2 :] if absoluteFilePathUntilDot == '/home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/skeinforge_application/skeinforge_plugins/craft_plugins/preface': #is this script on Enrique's computer? archive.writeFileText(archive.getVersionFileName(), dateTodayString) versionText = archive.getFileText(archive.getVersionFileName()) self.distanceFeedRate.addTagBracketedLine('version', versionText) dateTimeTuple = datetime.now().timetuple() created = dateTodayString + '|%s:%s' % (dateTimeTuple[3], dateTimeTuple[4]) self.distanceFeedRate.addTagBracketedLine('created', created) self.distanceFeedRate.addLine('(<extruderInitialization>)') if self.repository.setPositioningToAbsolute.value: self.distanceFeedRate.addLine('G90 ;set positioning to absolute') # Set positioning to absolute. if self.repository.setUnitsToMillimeters.value: self.distanceFeedRate.addLine('G21 ;set units to millimeters') # Set units to millimeters. if self.repository.startAtHome.value: self.distanceFeedRate.addLine('G28 ;start at home') # Start at home. if self.repository.resetExtruder.value: self.distanceFeedRate.addLine('G92 E0 ;reset extruder distance') # Start at home. if self.repository.turnExtruderOffAtStartUp.value: self.distanceFeedRate.addLine('M103') # Turn extruder off. craftTypeName = skeinforge_profile.getCraftTypeName() self.distanceFeedRate.addTagBracketedLine('craftTypeName', craftTypeName) self.distanceFeedRate.addTagBracketedLine('decimalPlacesCarried', self.distanceFeedRate.decimalPlacesCarried) layerHeight = float(self.svgReader.sliceDictionary['layerHeight']) self.distanceFeedRate.addTagRoundedLine('layerThickness', layerHeight) self.distanceFeedRate.addTagRoundedLine('layerHeight', layerHeight) if self.repository.meta.value: self.distanceFeedRate.addTagBracketedLine('meta', self.repository.meta.value) edgeWidth = float(self.svgReader.sliceDictionary['edgeWidth']) self.distanceFeedRate.addTagRoundedLine('edgeWidth', edgeWidth) self.distanceFeedRate.addTagRoundedLine('perimeterWidth', edgeWidth) self.distanceFeedRate.addTagBracketedLine('profileName', skeinforge_profile.getProfileName(craftTypeName)) self.distanceFeedRate.addLine('(<settings>)') pluginFileNames = skeinforge_craft.getPluginFileNames() for pluginFileName in pluginFileNames: self.addToolSettingLines(pluginFileName) self.distanceFeedRate.addLine('(</settings>)') self.distanceFeedRate.addTagBracketedLine('timeStampPreface', strftime('%Y%m%d_%H%M%S')) procedureNames = self.svgReader.sliceDictionary['procedureName'].replace(',', ' ').split() for procedureName in procedureNames: self.distanceFeedRate.addTagBracketedProcedure(procedureName) self.distanceFeedRate.addTagBracketedProcedure('preface') self.distanceFeedRate.addLine('(</extruderInitialization>)') # Initialization is finished, extrusion is starting. self.distanceFeedRate.addLine('(<crafting>)') # Initialization is finished, crafting is starting.
def writeOutput(fileName=""): "Chop a GNU Triangulated Surface file. If no fileName is specified, chop the first GNU Triangulated Surface file in this folder." startTime = time.time() print("File " + archive.getSummarizedFileName(fileName) + " is being chopped.") repository = ChopRepository() settings.getReadRepository(repository) chopGcode = getCraftedText(fileName, "", repository) if chopGcode == "": return suffixFileName = fileName[: fileName.rfind(".")] + "_chop.svg" suffixDirectoryName = os.path.dirname(suffixFileName) suffixReplacedBaseName = os.path.basename(suffixFileName).replace(" ", "_") suffixFileName = os.path.join(suffixDirectoryName, suffixReplacedBaseName) archive.writeFileText(suffixFileName, chopGcode) print("The chopped file is saved as " + archive.getSummarizedFileName(suffixFileName)) print("It took %s to chop the file." % euclidean.getDurationString(time.time() - startTime)) settings.openSVGPage(suffixFileName, repository.svgViewer.value)
def writeOutput(fileName=''): "Cleave a GNU Triangulated Surface file. If no fileName is specified, cleave the first GNU Triangulated Surface file in this folder." startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName) + ' is being cleaved.') repository = CleaveRepository() settings.getReadRepository(repository) cleaveGcode = getCraftedText( fileName, '', repository ) if cleaveGcode == '': return suffixFileName = fileName[ : fileName.rfind('.') ] + '_cleave.svg' suffixDirectoryName = os.path.dirname(suffixFileName) suffixReplacedBaseName = os.path.basename(suffixFileName).replace(' ', '_') suffixFileName = os.path.join( suffixDirectoryName, suffixReplacedBaseName ) archive.writeFileText( suffixFileName, cleaveGcode ) print('The cleaved file is saved as ' + archive.getSummarizedFileName(suffixFileName) ) print('It took %s to cleave the file.' % euclidean.getDurationString( time.time() - startTime ) ) settings.openSVGPage( suffixFileName, repository.svgViewer.value )
def addInitializationToOutput(self): "Add initialization gcode to the output." self.distanceFeedRate.addTagBracketedLine('format', 'skeinforge gcode') absoluteFilePathUntilDot = archive.getUntilDot(archive.getCraftPluginsDirectoryPath('preface.py')) dateTodayString = date.today().isoformat().replace('-', '.')[2 :] if absoluteFilePathUntilDot == '/home/enrique/Desktop/backup/babbleold/script/reprap/fabmetheus/skeinforge_application/skeinforge_plugins/craft_plugins/preface': #is this script on Enrique's computer? archive.writeFileText(archive.getVersionFileName(), dateTodayString) versionText = archive.getFileText(archive.getVersionFileName()) self.distanceFeedRate.addTagBracketedLine('version', versionText) dateTimeTuple = datetime.now().timetuple() created = dateTodayString + '|%s:%s' % (dateTimeTuple[3], dateTimeTuple[4]) self.distanceFeedRate.addTagBracketedLine('created', created) self.distanceFeedRate.addLine('(<extruderInitialization>)') if self.repository.setPositioningToAbsolute.value: self.distanceFeedRate.addLine('G90 ;set positioning to absolute') # Set positioning to absolute. if self.repository.setUnitsToMillimeters.value: self.distanceFeedRate.addLine('G21 ;set units to millimeters') # Set units to millimeters. if self.repository.startAtHome.value: self.distanceFeedRate.addLine('G28 ;start at home') # Start at home. if self.repository.turnExtruderOffAtStartUp.value: self.distanceFeedRate.addLine('M103') # Turn extruder off. craftTypeName = skeinforge_profile.getCraftTypeName() self.distanceFeedRate.addTagBracketedLine('craftTypeName', craftTypeName) self.distanceFeedRate.addTagBracketedLine('decimalPlacesCarried', self.distanceFeedRate.decimalPlacesCarried) layerHeight = float(self.svgReader.sliceDictionary['layerHeight']) self.distanceFeedRate.addTagRoundedLine('layerThickness', layerHeight) self.distanceFeedRate.addTagRoundedLine('layerHeight', layerHeight) if self.repository.meta.value: self.distanceFeedRate.addTagBracketedLine('meta', self.repository.meta.value) edgeWidth = float(self.svgReader.sliceDictionary['edgeWidth']) self.distanceFeedRate.addTagRoundedLine('edgeWidth', edgeWidth) self.distanceFeedRate.addTagRoundedLine('perimeterWidth', edgeWidth) self.distanceFeedRate.addTagBracketedLine('profileName', skeinforge_profile.getProfileName(craftTypeName)) self.distanceFeedRate.addLine('(<settings>)') pluginFileNames = skeinforge_craft.getPluginFileNames() for pluginFileName in pluginFileNames: self.addToolSettingLines(pluginFileName) self.distanceFeedRate.addLine('(</settings>)') self.distanceFeedRate.addTagBracketedLine('timeStampPreface', strftime('%Y%m%d_%H%M%S')) procedureNames = self.svgReader.sliceDictionary['procedureName'].replace(',', ' ').split() for procedureName in procedureNames: self.distanceFeedRate.addTagBracketedProcedure(procedureName) self.distanceFeedRate.addTagBracketedProcedure('preface') self.distanceFeedRate.addLine('(</extruderInitialization>)') # Initialization is finished, extrusion is starting. self.distanceFeedRate.addLine('(<crafting>)') # Initialization is finished, crafting is starting.
def writeChainTextWithNounMessage( fileName, procedure ): "Get and write a crafted shape file." print('') print('The %s tool is parsing the file:' % procedure ) print( os.path.basename(fileName) ) print('') startTime = time.time() fileNameSuffix = fileName[ : fileName.rfind('.') ] + '_' + procedure + '.gcode' craftText = getChainText( fileName, procedure ) if craftText == '': return archive.writeFileText( fileNameSuffix, craftText ) print('') print('The %s tool has created the file:' % procedure ) print( fileNameSuffix ) print('') print('It took %s to craft the file.' % euclidean.getDurationString( time.time() - startTime ) ) skeinforge_analyze.writeOutput( fileName, fileNameSuffix, craftText )
def getWindowAnalyzeFileGivenText( fileName, gcodeText, repository=None): 'Write scalable vector graphics for a gcode file given the settings.' if gcodeText == '': return None if repository == None: repository = settings.getReadRepository( VectorwriteRepository() ) startTime = time.time() vectorwriteGcode = VectorwriteSkein().getCarvedSVG( fileName, gcodeText, repository ) if vectorwriteGcode == '': return None suffixFileName = fileName[ : fileName.rfind('.') ] + '_vectorwrite.svg' suffixDirectoryName = os.path.dirname(suffixFileName) suffixReplacedBaseName = os.path.basename(suffixFileName).replace(' ', '_') suffixFileName = os.path.join( suffixDirectoryName, suffixReplacedBaseName ) archive.writeFileText( suffixFileName, vectorwriteGcode ) print('The vectorwrite file is saved as ' + archive.getSummarizedFileName(suffixFileName) ) print('It took %s to vectorwrite the file.' % euclidean.getDurationString( time.time() - startTime ) ) settings.openSVGPage( suffixFileName, repository.svgViewer.value )
def writeSVGTextWithNounMessage(fileName, repository): 'Get and write an svg text and print messages.' print('') print('The %s tool is parsing the file:' % repository.lowerName) print(os.path.basename(fileName)) print('') startTime = time.time() fileNameSuffix = fileName[: fileName.rfind('.')] + '_' + repository.lowerName + '.svg' craftText = getChainText(fileName, repository.lowerName) if craftText == '': return archive.writeFileText(fileNameSuffix, craftText) print('') print('The %s tool has created the file:' % repository.lowerName) print(fileNameSuffix) print('') print('It took %s to craft the file.' % euclidean.getDurationString(time.time() - startTime)) settings.getReadRepository(repository) settings.openSVGPage(fileNameSuffix, repository.svgViewer.value)
def writeOutput(fileName=''): 'Export a gcode linear move file.' fileName = fabmetheus_interpret.getFirstTranslatorFileNameUnmodified(fileName) if fileName == '': return repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName) + ' is being chain exported.') suffixFileName = fileName[: fileName.rfind('.')] if repository.addExportSuffix.value: suffixFileName += '_export' suffixFileName += '.' + repository.fileExtension.value gcodeText = gcodec.getGcodeFileText(fileName, '') procedures = skeinforge_craft.getProcedures('export', gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures(fileName, procedures[ : - 1 ], gcodeText) if gcodeText == '': return window = skeinforge_analyze.writeOutput(fileName, suffixFileName, gcodeText) if repository.savePenultimateGcode.value: penultimateFileName = fileName[: fileName.rfind('.')] + '_penultimate.gcode' archive.writeFileText(penultimateFileName, gcodeText) print('The penultimate file is saved as ' + archive.getSummarizedFileName(penultimateFileName)) exportChainGcode = getCraftedTextFromText(gcodeText, repository) replaceableExportChainGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule == None: replaceableExportChainGcode = exportChainGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportChainGcode = selectedPluginModule.getOutput(exportChainGcode) else: selectedPluginModule.writeOutput(suffixFileName, exportChainGcode) if replaceableExportChainGcode != None: replaceableExportChainGcode = getReplaced(replaceableExportChainGcode) archive.writeFileText( suffixFileName, replaceableExportChainGcode ) print('The exported file is saved as ' + archive.getSummarizedFileName(suffixFileName)) if repository.alsoSendOutputTo.value != '': if replaceableExportChainGcode == None: replaceableExportChainGcode = selectedPluginModule.getOutput(exportChainGcode) exec('print >> ' + repository.alsoSendOutputTo.value + ', replaceableExportChainGcode') print('It took %s to export the file.' % euclidean.getDurationString(time.time() - startTime)) return window
def getOutput(fileName): 'Export a gcode linear move file.' if fileName == '': return None repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName.encode('ascii', 'replace')) + ' is being chain exported.') gcodeText = gcodec.getGcodeFileText(fileName, '') procedures = skeinforge_craft.getProcedures('export', gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures( fileName, procedures[:-1], gcodeText) if gcodeText == '': return None fileNamePenultimate = fileName[:fileName.rfind('.')] + '_penultimate.gcode' if repository.savePenultimateGcode.value: archive.writeFileText(fileNamePenultimate, gcodeText) print('The penultimate file is saved as ' + archive.getSummarizedFileName(fileNamePenultimate)) exportGcode = getCraftedTextFromText(gcodeText, repository) replaceableExportGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule is None: replaceableExportGcode = exportGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportGcode = selectedPluginModule.getOutput( exportGcode) #else: # selectedPluginModule.writeOutput(outputFilename, exportGcode) if replaceableExportGcode is not None: replaceableExportGcode = getReplaceableExportGcode( repository.nameOfReplaceFile.value, replaceableExportGcode) if repository.alsoSendOutputTo.value != '': if replaceableExportGcode == None: replaceableExportGcode = selectedPluginModule.getOutput( exportGcode) sendOutputTo(repository.alsoSendOutputTo.value, replaceableExportGcode) print('It took %s to export the file.' % euclidean.getDurationString(time.time() - startTime)) return replaceableExportGcode
def writeChainTextWithNounMessage(fileName, procedure): "Get and write a crafted shape file." print('') print('The %s tool is parsing the file:' % procedure) print(os.path.basename(fileName)) print('') startTime = time.time() fileNameSuffix = fileName[:fileName.rfind('.' )] + '_' + procedure + '.gcode' craftText = getChainText(fileName, procedure) if craftText == '': return archive.writeFileText(fileNameSuffix, craftText) print('') print('The %s tool has created the file:' % procedure) print(fileNameSuffix) print('') print('It took %s to craft the file.' % euclidean.getDurationString(time.time() - startTime)) skeinforge_analyze.writeOutput(fileName, fileNameSuffix, craftText)
def writeOutput(fileName=''): "Bottom the carving of a gcode file." print('') print('The bottom tool is parsing the file:') print(os.path.basename(fileName)) print('') startTime = time.time() fileNameSuffix = fileName[: fileName.rfind('.')] + '_bottom.svg' craftText = skeinforge_craft.getChainText(fileName, 'bottom') if craftText == '': return archive.writeFileText(fileNameSuffix, craftText) print('') print('The bottom tool has created the file:') print(fileNameSuffix) print('') print('It took %s to craft the file.' % euclidean.getDurationString(time.time() - startTime)) repository = BottomRepository() settings.getReadRepository(repository) settings.openSVGPage(fileNameSuffix, repository.svgViewer.value)
def export(self): 'Perform final modifications to slicedModel and performs export.' filename = self.slicedModel.runtimeParameters.inputFilename filenamePrefix = os.path.splitext(filename)[0] profileName = self.slicedModel.runtimeParameters.profileName if self.slicedModel.runtimeParameters.outputFilename != None: exportFileName = self.slicedModel.runtimeParameters.outputFilename else: exportFileName = filenamePrefix if self.addProfileExtension and profileName: exportFileName += '.' + string.replace(profileName, ' ', '_') exportFileName += '.' + self.fileExtension self.slicedModel.runtimeParameters.outputFilename = exportFileName replaceableExportGcode = self.getReplaceableExportGcode( self.nameOfReplaceFile, GcodeWriter(self.slicedModel).getSlicedModel()) archive.writeFileText(exportFileName, replaceableExportGcode) logger.info('Gcode exported to: %s', os.path.basename(exportFileName)) if self.debug: slicedModelTextFilename = filenamePrefix if self.addProfileExtension and profileName: slicedModelTextFilename += '.' + string.replace( profileName, ' ', '_') slicedModelTextFilename += '.slicedmodel.txt' archive.writeFileText(slicedModelTextFilename, str(self.slicedModel)) logger.info('Sliced Model Text exported to: %s', slicedModelTextFilename) if self.exportSlicedModel: slicedModelExportFilename = filenamePrefix if self.addProfileExtension and profileName: slicedModelExportFilename += '.' + string.replace( profileName, ' ', '_') slicedModelExportFilename += '.' + self.exportSlicedModelExtension if os.path.exists(slicedModelExportFilename ) and not self.overwriteExportedSlicedModel: backupFilename = '%s.%s.bak' % ( slicedModelExportFilename, datetime.datetime.now().strftime('%Y%m%d_%H%M%S_%f')) os.rename(slicedModelExportFilename, backupFilename) logger.info('Existing slicedmodel file backed up to: %s', backupFilename) logger.info('Sliced Model exported to: %s', slicedModelExportFilename) archive.writeFileText(slicedModelExportFilename, pickle.dumps(self.slicedModel))
def writeOutput(fileName, shouldAnalyze=True): 'Export a gcode linear move file.' if fileName == '': return None repository = ExportRepository() settings.getReadRepository(repository) startTime = time.time() print('File ' + archive.getSummarizedFileName(fileName) + ' is being chain exported.') fileNameSuffix = fileName[:fileName.rfind('.')] if repository.addExportSuffix.value: fileNameSuffix += '_export' if (repository.profileFileExtension.value == True): profileName = skeinforge_profile.getProfileName( skeinforge_profile.getCraftTypeName()) if profileName: fileNameSuffix += '.' + string.replace(profileName, ' ', '_') if (repository.descriptiveExtension.value == True): fileNameSuffix += descriptiveExtension() if (repository.timestampExtension.value == True): fileNameSuffix += '.' + strftime("%Y%m%d_%H%M%S") if (repository.archiveProfile.value == True): profileName = skeinforge_profile.getProfileName( skeinforge_profile.getCraftTypeName()) if profileName: profileZipFileName = fileNameSuffix + '.zip' zipper( archive.getProfilesPath( skeinforge_profile.getProfileDirectory()), profileName + '/', profileZipFileName) print('Profile archived to ' + profileZipFileName) if (repository.exportProfileAsCsv.value == True): csvExportFilename = fileNameSuffix + '.csv' archive.writeFileText(csvExportFilename, Condenser().readSettings()) fileNameSuffix += '.' + repository.fileExtension.value gcodeText = gcodec.getGcodeFileText(fileName, '') procedures = skeinforge_craft.getProcedures('export', gcodeText) gcodeText = skeinforge_craft.getChainTextFromProcedures( fileName, procedures[:-1], gcodeText) if gcodeText == '': return None if repository.savePenultimateGcode.value: penultimateFileName = fileName[:fileName. rfind('.')] + '_penultimate.gcode' archive.writeFileText(penultimateFileName, gcodeText) print('The penultimate file is saved as ' + archive.getSummarizedFileName(penultimateFileName)) exportGcode = getCraftedTextFromText(gcodeText, repository) window = None if shouldAnalyze: window = skeinforge_analyze.writeOutput(fileName, fileNameSuffix, gcodeText) replaceableExportGcode = None selectedPluginModule = getSelectedPluginModule(repository.exportPlugins) if selectedPluginModule == None: replaceableExportGcode = exportGcode else: if selectedPluginModule.globalIsReplaceable: replaceableExportGcode = selectedPluginModule.getOutput( exportGcode) else: selectedPluginModule.writeOutput(fileNameSuffix, exportGcode) if replaceableExportGcode != None: replaceableExportGcode = getReplaceableExportGcode( repository.nameOfReplaceFile.value, replaceableExportGcode) archive.writeFileText(fileNameSuffix, replaceableExportGcode) print('The exported file is saved as ' + archive.getSummarizedFileName(fileNameSuffix)) if repository.alsoSendOutputTo.value != '': if replaceableExportGcode == None: replaceableExportGcode = selectedPluginModule.getOutput( exportGcode) sendOutputTo(replaceableExportGcode, repository.alsoSendOutputTo.value) print('It took %s to export the file.' % euclidean.getDurationString(time.time() - startTime)) return window