diff --git a/Cura/__init__.py b/Cura/__init__.py index 6e968ba..e69de29 100644 --- a/Cura/__init__.py +++ b/Cura/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 0 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/avr_isp/__init__.py b/Cura/avr_isp/__init__.py index 1638033..e69de29 100644 --- a/Cura/avr_isp/__init__.py +++ b/Cura/avr_isp/__init__.py @@ -1,13 +0,0 @@ -""" -This page is in the table of contents. -This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -""" -import os -import sys - -numberOfLevelsDeepInPackageHierarchy = 1 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura.py b/Cura/cura.py index 8e86f7b..195029f 100644 --- a/Cura/cura.py +++ b/Cura/cura.py @@ -8,7 +8,6 @@ Cura is a GPL tool chain to forge a gcode skein for a model. Based on Skeinforge The slicing code is the same as Skeinforge. But the UI has been revamped to be... sane. """ - from __future__ import absolute_import import __init__ @@ -47,6 +46,7 @@ def main(): parser = OptionParser(usage="usage: %prog [options] .stl") parser.add_option("-i", "--ini", action="store", type="string", dest="profileini", help="Load settings from a profile ini file") parser.add_option("-P", "--project", action="store_true", dest="openprojectplanner", help="Open the project planner") + parser.add_option("-F", "--flat", action="store_true", dest="openflatslicer", help="Open the 2D SVG slicer") parser.add_option("-r", "--print", action="store", type="string", dest="printfile", help="Open the printing interface, instead of the normal cura interface.") parser.add_option("-p", "--profile", action="store", type="string", dest="profile", help="Internal option, do not use!") (options, args) = parser.parse_args() @@ -58,6 +58,10 @@ def main(): from gui import projectPlanner projectPlanner.main() return + if options.openflatslicer != None: + from gui import flatSlicerWindow + flatSlicerWindow.main() + return if options.printfile != None: from gui import printWindow printWindow.startPrintInterface(options.printfile) diff --git a/Cura/cura_sf/__init__.py b/Cura/cura_sf/__init__.py index bdac25d..e69de29 100644 --- a/Cura/cura_sf/__init__.py +++ b/Cura/cura_sf/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 1 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/__init__.py b/Cura/cura_sf/fabmetheus_utilities/__init__.py index 1638033..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/__init__.py @@ -1,13 +0,0 @@ -""" -This page is in the table of contents. -This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -""" -import os -import sys - -numberOfLevelsDeepInPackageHierarchy = 1 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/archive.py b/Cura/cura_sf/fabmetheus_utilities/archive.py index 8b6d93f..c9e5655 100644 --- a/Cura/cura_sf/fabmetheus_utilities/archive.py +++ b/Cura/cura_sf/fabmetheus_utilities/archive.py @@ -10,6 +10,7 @@ import __init__ import os import sys import traceback +import zipfile __author__ = 'Enrique Perez (perez_enrique@yahoo.com)' @@ -101,10 +102,20 @@ def getFilePaths(fileInDirectory=''): def getFilePathsByDirectory(directoryName): 'Get the file paths in the directory of the file in directory.' absoluteDirectoryPath = os.path.abspath(directoryName) - directory = os.listdir(directoryName) filePaths = [] - for fileName in directory: - filePaths.append(os.path.join(absoluteDirectoryPath, fileName)) + if os.path.isdir(directoryName): + for fileName in os.listdir(directoryName): + filePaths.append(os.path.join(absoluteDirectoryPath, fileName)) + elif '.zip/' in directoryName: + zipfilename = directoryName[:directoryName.rfind('.zip/')+4] + subpath = directoryName[directoryName.rfind('.zip/')+5:] + + z = zipfile.ZipFile(zipfilename, 'r') + for name in z.namelist(): + if os.path.dirname(name) == subpath: + filePaths.append(os.path.join(zipfilename, name)) + z.close() + print directoryName, filePaths return filePaths def getFilePathsRecursively(fileInDirectory=''): @@ -156,14 +167,30 @@ def getFilesWithFileTypeWithoutWords(fileType, words = [], fileInDirectory=''): def getFileText(fileName, printWarning=True, readMode='r'): 'Get the entire text of a file.' + if '.zip/' in fileName: + zipfilename = fileName[:fileName.rfind('.zip/')+4] + subpath = fileName[fileName.rfind('.zip/')+5:] + + try: + z = zipfile.ZipFile(zipfilename, 'r') + f = z.open(subpath, 'r') + fileText = f.read() + f.close() + z.close() + return fileText + except KeyError: + if printWarning: + print('The file ' + fileName + ' does not exist.') + return '' try: - file = open(fileName, readMode) - fileText = file.read() - file.close() + f = open(fileName, readMode) + fileText = f.read() + f.close() return fileText except IOError: if printWarning: print('The file ' + fileName + ' does not exist.') + return '' def getFileTextInFileDirectory(fileInDirectory, fileName, readMode='r'): diff --git a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/__init__.py b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/__init__.py index 2dc8ddc..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 2 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/alphabetize.py b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/alphabetize.py deleted file mode 100644 index 379d2ef..0000000 --- a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/alphabetize.py +++ /dev/null @@ -1,232 +0,0 @@ -""" -Alphabetize is a script to alphabetize functions and signatures. - -""" - -from __future__ import absolute_import -#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module. -import __init__ - -from fabmetheus_utilities import archive -import cStringIO -import os - - -__author__ = 'Enrique Perez (perez_enrique@yahoo.com)' -__date__ = '$Date: 2008/21/04 $' -__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' - - -def addTogetherList(functionList, togetherLists): - 'Add the togetherList to the togetherLists is the sorted is different.' - sortedList = functionList[:] - sortedList.sort(compareFunctionName) - togetherList = None - for functionIndex in xrange(len(functionList)): - function = functionList[functionIndex] - sorted = sortedList[functionIndex] - if function != sorted: - together = (function, sorted) - if togetherList == None: - togetherList = [] - togetherLists.append(togetherList) - togetherList.append(together) - -def compareFunctionName(first, second): - 'Compare the function names.' - first = getConvertedName(first) - second = getConvertedName(second) - if first < second: - return -1 - return first < second - -def getConvertedName(name): - 'Get converted name with init at the beginning and main at the endCompare the function names.' - if name == 'def __init__': - return 'def !__init__' - if name == 'def main': - return 'def |main' - return name.lower() - -def getFunctionLists(fileName): - 'Get the function lists in the file.' - fileText = archive.getFileText(fileName) - functionList = [] - functionLists = [functionList] - lines = archive.getTextLines(fileText) - for line in lines: - lineStripped = line.strip() - if lineStripped.startswith('def '): - bracketIndex = lineStripped.find('(') - if bracketIndex > -1: - lineStripped = lineStripped[: bracketIndex] - functionList.append(lineStripped) - elif line.startswith('class'): - functionList = [] - functionLists.append(functionList) - return functionLists - -def getFunctionsWithStringByFileName(fileName, searchString): - 'Get the functions with the search string in the file.' - fileText = archive.getFileText(fileName) - functions = [] - lines = archive.getTextLines(fileText) - for line in lines: - lineStripped = line.strip() -# if lineStripped.startswith('def ') and searchString in lineStripped and '=' in lineStripped: - if lineStripped.startswith('def ') and searchString in lineStripped: - if '(self, ' not in lineStripped or lineStripped.count(',') > 1: - functions.append(lineStripped[len('def ') :].strip()) - functions.sort() - return functions - -def getFunctionsWithStringByFileNames(fileNames, searchString): - 'Get the functions with the search string in the files.' - functions = [] - for fileName in fileNames: - functions += getFunctionsWithStringByFileName(fileName, searchString) - functions.sort() - return functions - -def getParameterSequence(functionName): - 'Get the parameter sequence.' - parameterDictionary = {} - parameterSequence = [] - parameterText = functionName[functionName.find('(') + 1 :].replace('xmlElement', 'elementNode') - snippet = Snippet(0, parameterText) - strippedParameters = [] - for parameter in snippet.parameters: - strippedParameter = parameter.strip() - if strippedParameter != 'self': - strippedParameters.append(strippedParameter) - for parameterIndex, parameter in enumerate(strippedParameters): - parameterDictionary[parameter] = parameterIndex - sortedParameters = strippedParameters[:] - sortedParameters.sort() - for sortedParameter in sortedParameters: - parameterSequence.append(parameterDictionary[sortedParameter]) - return parameterSequence - -def getSnippetsByFileName(fileName, functionName): - 'Get the function signature snippets by the file name.' - fileText = archive.getFileText(fileName) - snippets = [] - functionStart = functionName[: functionName.find('(') + 1] - tokenEnd = getTokenEnd(0, fileText, functionStart) - while tokenEnd != -1: - snippet = Snippet(tokenEnd, fileText) - snippets.append(snippet) - tokenEnd = getTokenEnd(snippet.characterIndex, fileText, functionStart) - return snippets - -def getTogetherLists(fileName): - 'Get the lists of the unsorted and sorted functions in the file.' - functionLists = getFunctionLists(fileName) - togetherLists = [] - for functionList in functionLists: - addTogetherList(functionList, togetherLists) - return togetherLists - -def getTokenEnd(characterIndex, fileText, token): - 'Get the token end index for the file text and token.' - tokenIndex = fileText.find(token, characterIndex) - if tokenIndex == -1: - return -1 - return tokenIndex + len(token) - -def printTogetherListsByFileNames(fileNames): - 'Print the together lists of the file names, if the file name has a together list.' - for fileName in fileNames: - togetherLists = getTogetherLists(fileName) - if len(togetherLists) > 0: - for togetherList in togetherLists: - for together in togetherList: - function = together[0] - sorted = together[1] - return - - -class EndCharacterMonad: - 'A monad to return the parent monad when it encounters the end character.' - def __init__(self, endCharacter, parentMonad): - 'Initialize.' - self.endCharacter = endCharacter - self.parentMonad = parentMonad - - def getNextMonad(self, character): - 'Get the next monad.' - self.getSnippet().input.write(character) - if character == self.endCharacter: - return self.parentMonad - return self - - def getSnippet(self): - 'Get the snippet.' - return self.parentMonad.getSnippet() - - -class ParameterMonad: - 'A monad to handle parameters.' - def __init__(self, snippet): - 'Initialize.' - self.snippet = snippet - - def addParameter(self): - 'Add parameter to the snippet.' - parameterString = self.snippet.input.getvalue() - if len(parameterString) != 0: - self.snippet.input = cStringIO.StringIO() - self.snippet.parameters.append(parameterString) - - def getNextMonad(self, character): - 'Get the next monad.' - if character == '"': - self.snippet.input.write(character) - return EndCharacterMonad('"', self) - if character == '"': - self.snippet.input.write(character) - return EndCharacterMonad('"', self) - if character == '(': - self.snippet.input.write(character) - return EndCharacterMonad(')', self) - if character == ')': - self.addParameter() - return None - if character == ',': - self.addParameter() - return self - self.snippet.input.write(character) - return self - - def getSnippet(self): - 'Get the snippet.' - return self.snippet - - -class Snippet: - 'A class to get the variables for a function.' - def __init__(self, characterIndex, fileText): - 'Initialize.' - self.characterIndex = characterIndex - self.input = cStringIO.StringIO() - self.parameters = [] - monad = ParameterMonad(self) - for characterIndex in xrange(self.characterIndex, len(fileText)): - character = fileText[characterIndex] - monad = monad.getNextMonad(character) - if monad == None: - return - - def __repr__(self): - 'Get the string representation of this Snippet.' - return '%s %s' % (self.characterIndex, self.parameters) - - -def main(): - 'Run main function.' -# printTogetherListsByFileNames(archive.getPythonFileNamesExceptInitRecursively('/home/enrique/Desktop/fabmetheus')) - functions = getFunctionsWithStringByFileNames(archive.getPythonFileNamesExceptInitRecursively('/home/enrique/Desktop/fabmetheus'), ', xmlElement') - print(functions) - -if __name__ == "__main__": - main() diff --git a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/fabmetheus_interpret.py b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/fabmetheus_interpret.py index 65de7cf..d291420 100644 --- a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/fabmetheus_interpret.py +++ b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/fabmetheus_interpret.py @@ -35,7 +35,7 @@ def getGNUTranslatorFilesUnmodified(): def getGNUTranslatorGcodeFileTypeTuples(): "Get the file type tuples from the translators in the import plugins folder plus gcode." - fileTypeTuples = getTranslatorFileTypeTuples() + fileTypeTuples = [] #getTranslatorFileTypeTuples() fileTypeTuples.append( ('Gcode text files', '*.gcode') ) fileTypeTuples.sort() return fileTypeTuples diff --git a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/__init__.py b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/__init__.py index cefa3e7..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/__init__.py @@ -1,12 +0,0 @@ -""" -This page is in the table of contents. -This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -""" -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/prepare.py b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/prepare.py deleted file mode 100644 index bac2757..0000000 --- a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/prepare.py +++ /dev/null @@ -1,86 +0,0 @@ -""" -Prepare is a script to remove the generated files, run wikifier, and finally zip the package. - -""" - -from __future__ import absolute_import -#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module. -import __init__ - -from fabmetheus_utilities import archive -from fabmetheus_utilities.fabmetheus_tools import wikifier -import os - - -__author__ = 'Enrique Perez (perez_enrique@yahoo.com)' -__date__ = '$Date: 2008/21/04 $' -__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' - - -def prepareWikify(): - 'Remove generated files, then wikify the file comments.' - removeGeneratedFiles() - wikifier.main() - removeZip() - -def removeCSVFile(csvFilePath): - 'Remove csv file.' - if 'alterations' in csvFilePath and 'example_' not in csvFilePath: - os.remove(csvFilePath) - print('removeGeneratedFiles deleted ' + csvFilePath) - -def removeGcodeFile(gcodeFilePath): - 'Remove gcode file.' - if 'alterations' not in gcodeFilePath: - os.remove(gcodeFilePath) - print('removeGeneratedFiles deleted ' + gcodeFilePath) - return - if 'example_' not in gcodeFilePath: - os.remove(gcodeFilePath) - print('removeGeneratedFiles deleted ' + gcodeFilePath) - -def removeGeneratedFiles(): - 'Remove generated files.' - csvFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['csv']) - for csvFilePath in csvFilePaths: - removeCSVFile(csvFilePath) - gcodeFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['gcode']) - for gcodeFilePath in gcodeFilePaths: - removeGcodeFile(gcodeFilePath) - svgFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['svg']) - for svgFilePath in svgFilePaths: - removeSVGFile(svgFilePath) - xmlFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['xml']) - for xmlFilePath in xmlFilePaths: - removeXMLFile(xmlFilePath) - archive.removeBackupFilesByTypes(['gcode', 'svg', 'xml']) - -def removeSVGFile(svgFilePath): - 'Remove svg file.' - if archive.getEndsWithList(svgFilePath, ['_bottom.svg', '_carve.svg', '_chop.svg', '_cleave.svg', '_scale.svg', '_vectorwrite.svg']): - os.remove(svgFilePath) - print('removeGeneratedFiles deleted ' + svgFilePath) - -def removeXMLFile(xmlFilePath): - 'Remove xml file.' - if archive.getEndsWithList(xmlFilePath, ['_interpret.xml']): - os.remove(xmlFilePath) - print('removeGeneratedFiles deleted ' + xmlFilePath) - -def removeZip(): - 'Remove the zip file, then generate a new one.zip -r reprap_python_beanshell * -x \*.pyc \*~' - zipName = 'reprap_python_beanshell' - zipNameExtension = zipName + '.zip' - if zipNameExtension in os.listdir(os.getcwd()): - os.remove(zipNameExtension) - shellCommand = 'zip -r %s * -x \*.pyc \*~' % zipName - if os.system(shellCommand) != 0: - print('Failed to execute the following command in removeZip in prepare.') - print(shellCommand) - -def main(): - 'Run main function.' - prepareWikify() - -if __name__ == "__main__": - main() diff --git a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/wikifier.py b/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/wikifier.py deleted file mode 100644 index 50e0233..0000000 --- a/Cura/cura_sf/fabmetheus_utilities/fabmetheus_tools/wikifier.py +++ /dev/null @@ -1,215 +0,0 @@ -""" -Wikifier is a script to add spaces to the pydoc files and move them to the documentation folder. - -""" - -from __future__ import absolute_import -#Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module. -import __init__ - -from fabmetheus_utilities import archive -from fabmetheus_utilities import gcodec -from fabmetheus_utilities import settings -import cStringIO -import os - - -__author__ = 'Enrique Perez (perez_enrique@yahoo.com)' -__date__ = '$Date: 2008/21/04 $' -__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' - - -globalWikiLinkStart = '[', linkStartIndex, squareEndBracketIndex) - greaterThanIndexPlusOne = greaterThanIndex + 1 - closeATagIndex = line.find('', greaterThanIndexPlusOne, squareEndBracketIndex) - linkText = line[closeATagIndex + len('') + 1: squareEndBracketIndex] - linkLine = line[: linkStartIndex] + line[linkStartIndex + 1: greaterThanIndexPlusOne] + linkText + '' + line[squareEndBracketIndex + 1 :] - return linkLine - -def getNavigationHypertext(fileText, transferredFileNameIndex, transferredFileNames): - 'Get the hypertext help with navigation lines.' - helpTextEnd = fileText.find('

') - helpTextStart = fileText.find('

') - helpText = fileText[helpTextStart : helpTextEnd] - lines = archive.getTextLines(helpText) - headings = [] - headingLineTable = {} - for line in lines: - addToHeadings(headingLineTable, headings, line) - headingsToBeenAdded = True - output = cStringIO.StringIO() - for line in lines: - if line[: 2] == '==': - if headingsToBeenAdded: - output.write('
\n') - for heading in headings: - heading.addToOutput(output) - output.write('
\n') - headingsToBeenAdded = False - if line in headingLineTable: - line = headingLineTable[line] - if '<a href=' in line: - line = line.replace('<', '<').replace('>', '>') - while globalWikiLinkStart in line and ']' in line: - line = getLinkLine(line) - output.write(line + '\n') - helpText = output.getvalue() - previousFileName = 'contents.html' - previousIndex = transferredFileNameIndex - 1 - if previousIndex >= 0: - previousFileName = transferredFileNames[previousIndex] - previousLinkText = 'Previous' % previousFileName - nextLinkText = getNextLinkText(transferredFileNames, transferredFileNameIndex + 1) - navigationLine = getNavigationLine('Contents', previousLinkText, nextLinkText) - helpText = navigationLine + helpText + '
\n
\n' + navigationLine + '


\n' - return fileText[: helpTextStart] + helpText + fileText[helpTextEnd :] - -def getNavigationLine(contentsLinkText, previousLinkText, nextLinkText): - 'Get the wrapped pydoc hypertext help.' - return '

\n%s / %s / %s\n

\n' % (previousLinkText, nextLinkText, contentsLinkText) - -def getNextLinkText(hypertextFiles, nextIndex): - 'Get the next link text.' - nextFileName = 'contents.html' - if nextIndex < len(hypertextFiles): - nextFileName = hypertextFiles[nextIndex] - return 'Next' % nextFileName - -def getWrappedHypertext(fileText, hypertextFileIndex, hypertextFiles): - 'Get the wrapped pydoc hypertext help.' - helpTextEnd = fileText.find('

') - if helpTextEnd < 0: - print('Failed to find the helpTextEnd in getWrappedHypertext in docwrap.') - helpTextStart = fileText.find('

') - if helpTextStart < 0: - print('Failed to find the helpTextStart in getWrappedHypertext in docwrap.') - helpText = fileText[helpTextStart : helpTextEnd] - helpText = helpText.replace(' ', ' ') - return fileText[: helpTextStart] + helpText + fileText[helpTextEnd :] - -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 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 removeFilesInDirectory(directoryPath): - 'Remove all the files in a directory.' - fileNames = os.listdir(directoryPath) - for fileName in fileNames: - filePath = os.path.join(directoryPath, fileName) - os.remove(filePath) - -def writeContentsFile(documentDirectoryPath, hypertextFiles): - 'Write the contents file.' - output = cStringIO.StringIO() - output.write('\n \n Contents\n \n \n') - navigationLine = getNavigationLine('Contents', 'Previous', getNextLinkText(hypertextFiles, 0)) - output.write(navigationLine) - for hypertextFile in hypertextFiles: - writeContentsLine(hypertextFile, output) - output.write(navigationLine) - output.write(' \n\n') - filePath = os.path.join( documentDirectoryPath, 'contents.html') - archive.writeFileText(filePath, output.getvalue()) - -def writeContentsLine(hypertextFile, output): - 'Write a line of the contents file.' - summarizedFileName = hypertextFile[: hypertextFile.rfind('.')] - numberOfDots = summarizedFileName.count('.') - prefixSpaces = '  ' * numberOfDots - if numberOfDots > 0: - summarizedFileName = summarizedFileName[summarizedFileName.rfind('.') + 1 :] - capitalizedSummarizedFileName = settings.getEachWordCapitalized(summarizedFileName) - output.write('%s%s
\n' % (prefixSpaces, hypertextFile, capitalizedSummarizedFileName)) - -def writeHypertext(): - 'Run pydoc, then read, write and delete each of the files.' - shellCommand = 'pydoc -w ./' - commandResult = os.system(shellCommand) - if commandResult != 0: - print('Failed to execute the following command in writeHypertext in docwrap.') - print(shellCommand) - hypertextFiles = archive.getFilesWithFileTypeWithoutWords('html') - if len( hypertextFiles ) <= 0: - print('Failed to find any help files in writeHypertext in docwrap.') - return - documentDirectoryPath = archive.getAbsoluteFolderPath( hypertextFiles[0], 'documentation') - removeFilesInDirectory(documentDirectoryPath) - sortedReplaceFiles = [] - for hypertextFile in hypertextFiles: - sortedReplaceFiles.append(hypertextFile.replace('.html', '. html')) - sortedReplaceFiles.sort() - hypertextFiles = [] - for sortedReplaceFile in sortedReplaceFiles: - hypertextFiles.append(sortedReplaceFile.replace('. html', '.html')) - transferredFileNames = [] - for hypertextFileIndex in xrange(len(hypertextFiles)): - readWriteDeleteHypertextHelp(documentDirectoryPath, hypertextFileIndex, hypertextFiles, transferredFileNames) - for transferredFileNameIndex in xrange(len(transferredFileNames)): - readWriteNavigationHelp(documentDirectoryPath, transferredFileNameIndex, transferredFileNames) - writeContentsFile(documentDirectoryPath, transferredFileNames) - print('%s files were wrapped.' % len(transferredFileNames)) - - -class Heading: - 'A class to hold the heading and subheadings.' - def __init__(self, depth=0): - 'Initialize.' - self.depth = depth - - def addToOutput(self, output): - 'Add to the output.' - line = '  ' * self.depth + '%s
\n' % (self.name, self.name) - output.write(line) - - def getFromLine(self, headingLineTable, line): - 'Get the heading from a line.' - heading = 'h%s' % (self.depth + 2) - nextLine = '\n


\n' - if self.depth > 0: - nextLine = '\n' - self.name = line.replace('=', '').replace('
', '') - name = self.name - headingLine = '<%s>%s%s' % (name, name, heading, name, heading, nextLine) - headingLineTable[line] = headingLine - return self - - -def main(): - 'Display the craft dialog.' - writeHypertext() - -if __name__ == '__main__': - main() diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/__init__.py index 3345e96..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/__init__.py @@ -1,12 +0,0 @@ -""" -This page is in the table of contents. -This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -""" -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 2 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/creation/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/creation/__init__.py index cefa3e7..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/creation/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/creation/__init__.py @@ -1,12 +0,0 @@ -""" -This page is in the table of contents. -This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -""" -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/path_elements/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/path_elements/__init__.py index 58ec332..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/path_elements/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_tools/path_elements/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 4 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/__init__.py index cefa3e7..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/__init__.py @@ -1,12 +0,0 @@ -""" -This page is in the table of contents. -This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -""" -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_elements/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_elements/__init__.py index 58ec332..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_elements/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_elements/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 4 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_enumerables/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_enumerables/__init__.py index 58ec332..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_enumerables/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_enumerables/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 4 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_fundamentals/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_fundamentals/__init__.py index 58ec332..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_fundamentals/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/geometry_utilities/evaluate_fundamentals/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 4 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_matrix/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_matrix/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_matrix/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_matrix/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_meta/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_meta/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_meta/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_meta/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_paths/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_paths/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_paths/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_paths/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_shapes/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_shapes/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_shapes/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/manipulation_shapes/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/solids/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/solids/__init__.py index cefa3e7..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/solids/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/solids/__init__.py @@ -1,12 +0,0 @@ -""" -This page is in the table of contents. -This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -""" -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry/statements/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry/statements/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry/statements/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry/statements/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/__init__.py index 2dc8ddc..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 2 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/creation/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/creation/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/creation/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/creation/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_matrix/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_matrix/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_matrix/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_matrix/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_meta/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_meta/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_meta/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_meta/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_paths/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_paths/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_paths/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_paths/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_shapes/__init__.py b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_shapes/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_shapes/__init__.py +++ b/Cura/cura_sf/fabmetheus_utilities/geometry_plugins/manipulation_shapes/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/fabmetheus_utilities/settings.py b/Cura/cura_sf/fabmetheus_utilities/settings.py index c847293..92d3262 100644 --- a/Cura/cura_sf/fabmetheus_utilities/settings.py +++ b/Cura/cura_sf/fabmetheus_utilities/settings.py @@ -90,9 +90,6 @@ def calcLayerSkip(setting): return 0 return int(math.ceil((bottomThickness - layerThickness) / layerThickness + 0.0001) - 1) -def calculateBridgeFlow(setting): - return (profile.getProfileSettingFloat('bridge_speed') / 100) * (profile.getProfileSettingFloat('bridge_material_amount') / 100) - def getProfileInformation(): return { 'carve': { @@ -185,7 +182,7 @@ def getProfileInformation(): 'Activate_Speed': "True", 'Add_Flow_Rate': "True", 'Bridge_Feed_Rate_Multiplier_ratio': storedPercentSetting('bridge_speed'), - 'Bridge_Flow_Rate_Multiplier_ratio': calculateBridgeFlow, + 'Bridge_Flow_Rate_Multiplier_ratio': storedPercentSetting('bridge_speed'), 'Duty_Cyle_at_Beginning_portion': DEFSET, 'Duty_Cyle_at_Ending_portion': DEFSET, 'Feed_Rate_mm/s': storedSettingFloat("print_speed"), diff --git a/Cura/cura_sf/skeinforge_application/__init__.py b/Cura/cura_sf/skeinforge_application/__init__.py index bdac25d..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/__init__.py +++ b/Cura/cura_sf/skeinforge_application/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 1 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/__init__.py index 2dc8ddc..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 2 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/analyze_plugins/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/analyze_plugins/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/analyze_plugins/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/analyze_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/__init__.py index 58ec332..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 4 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/static_plugins/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/static_plugins/__init__.py index b83e941..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/static_plugins/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/static_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 5 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/meta_plugins/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/meta_plugins/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/meta_plugins/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/meta_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/profile_plugins/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/profile_plugins/__init__.py index 1121e8a..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_plugins/profile_plugins/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_plugins/profile_plugins/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 3 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/cura_sf/skeinforge_application/skeinforge_utilities/__init__.py b/Cura/cura_sf/skeinforge_application/skeinforge_utilities/__init__.py index 2dc8ddc..e69de29 100644 --- a/Cura/cura_sf/skeinforge_application/skeinforge_utilities/__init__.py +++ b/Cura/cura_sf/skeinforge_application/skeinforge_utilities/__init__.py @@ -1,9 +0,0 @@ -#This is required to workaround the python import bug where relative imports don't work if the module is imported as a main module. -import os -import sys -numberOfLevelsDeepInPackageHierarchy = 2 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/gui/__init__.py b/Cura/gui/__init__.py index 4870325..e69de29 100644 --- a/Cura/gui/__init__.py +++ b/Cura/gui/__init__.py @@ -1,9 +0,0 @@ -import os -import sys - -numberOfLevelsDeepInPackageHierarchy = 1 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/gui/expertConfig.py b/Cura/gui/expertConfig.py index 933bd8e..a0602e0 100644 --- a/Cura/gui/expertConfig.py +++ b/Cura/gui/expertConfig.py @@ -52,11 +52,9 @@ class expertConfigWindow(configBase.configWindowBase): validators.validFloat(c, 0.0) configBase.TitleRow(right, "Bridge") - c = configBase.SettingRow(right, "Bridge speed (%)", 'bridge_speed', '100', 'Speed at which bridges are printed, compared to normal printing speed.') + c = configBase.SettingRow(right, "Bridge speed (%)", 'bridge_speed', '100', 'Speed at which layers with bridges are printed, compared to normal printing speed.') validators.validFloat(c, 0.0) - c = configBase.SettingRow(right, "Bridge material (%)", 'bridge_material_amount', '100', 'Amount of material used for bridges, increase go extrude more material when printing a bridge.') - validators.validFloat(c, 0.0) - + configBase.TitleRow(right, "Sequence") c = configBase.SettingRow(right, "Print order sequence", 'sequence', ['Loops > Perimeter > Infill', 'Loops > Infill > Perimeter', 'Infill > Loops > Perimeter', 'Infill > Perimeter > Loops', 'Perimeter > Infill > Loops', 'Perimeter > Loops > Infill'], 'Sequence of printing. The perimeter is the outer print edge, the loops are the insides of the walls, and the infill is the insides.'); c = configBase.SettingRow(right, "Force first layer sequence", 'force_first_layer_sequence', True, 'This setting forces the order of the first layer to be \'Perimeter > Loops > Infill\'') diff --git a/Cura/gui/flatSlicerWindow.py b/Cura/gui/flatSlicerWindow.py new file mode 100644 index 0000000..5f28767 --- /dev/null +++ b/Cura/gui/flatSlicerWindow.py @@ -0,0 +1,195 @@ +import wx, os, platform, types, webbrowser + +from wx import glcanvas +import wx +try: + import OpenGL + OpenGL.ERROR_CHECKING = False + from OpenGL.GLU import * + from OpenGL.GL import * + hasOpenGLlibs = True +except: + print "Failed to find PyOpenGL: http://pyopengl.sourceforge.net/" + hasOpenGLlibs = False + +from gui import toolbarUtil +from gui import opengl +from util import util3d +from util import svg +from util import profile +from util import version + +class flatSlicerWindow(wx.Frame): + "Cura 2D SVG slicer" + def __init__(self): + super(flatSlicerWindow, self).__init__(None, title='Cura - ' + version.getVersion()) + + self.machineSize = util3d.Vector3(profile.getPreferenceFloat('machine_width'), profile.getPreferenceFloat('machine_depth'), profile.getPreferenceFloat('machine_height')) + self.filename = None + self.svg = None + + wx.EVT_CLOSE(self, self.OnClose) + self.panel = wx.Panel(self, -1) + self.SetSizer(wx.BoxSizer(wx.VERTICAL)) + self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND) + #self.SetIcon(icon.getMainIcon()) + + self.toolbar = toolbarUtil.Toolbar(self.panel) + + toolbarUtil.NormalButton(self.toolbar, self.OnOpenSVG, 'open.png', 'Open SVG') + self.toolbar.AddSeparator() + group = [] + toolbarUtil.RadioButton(self.toolbar, group, 'object-3d-on.png', 'object-3d-off.png', '3D view', callback=self.On3DClick) + toolbarUtil.RadioButton(self.toolbar, group, 'object-top-on.png', 'object-top-off.png', 'Topdown view', callback=self.OnTopClick).SetValue(True) + self.toolbar.AddSeparator() + toolbarUtil.NormalButton(self.toolbar, self.OnQuit, 'exit.png', 'Close project planner') + + self.toolbar.Realize() + + sizer = wx.GridBagSizer(2,2) + self.panel.SetSizer(sizer) + self.preview = PreviewGLCanvas(self.panel, self) + + sizer.Add(self.toolbar, (0,0), span=(1,1), flag=wx.EXPAND|wx.LEFT|wx.RIGHT) + sizer.Add(self.preview, (1,0), span=(5,1), flag=wx.EXPAND) + + sizer.AddGrowableCol(0) + sizer.AddGrowableRow(1) + + self.SetSize((600,400)) + + def OnClose(self, e): + self.Destroy() + + def OnQuit(self, e): + self.Close() + + def On3DClick(self): + self.preview.yaw = 30 + self.preview.pitch = 60 + self.preview.zoom = 300 + self.preview.view3D = True + self.preview.Refresh() + + def OnTopClick(self): + self.preview.view3D = False + self.preview.zoom = self.machineSize.x / 2 + 10 + self.preview.offsetX = 0 + self.preview.offsetY = 0 + self.preview.Refresh() + + def OnOpenSVG(self, e): + dlg=wx.FileDialog(self, "Open SVG file", os.path.split(profile.getPreference('lastFile'))[0], style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST) + dlg.SetWildcard("SVG files (*.svg)|*.svg;*.SVG") + if dlg.ShowModal() == wx.ID_OK: + self.filename = dlg.GetPath() + self.svg = svg.SVG(self.filename) + self.svg.center(complex(profile.getProfileSettingFloat('machine_center_x'), profile.getProfileSettingFloat('machine_center_y'))) + self.preview.Refresh() + dlg.Destroy() + +class PreviewGLCanvas(glcanvas.GLCanvas): + def __init__(self, parent, realParent): + attribList = (glcanvas.WX_GL_RGBA, glcanvas.WX_GL_DOUBLEBUFFER, glcanvas.WX_GL_DEPTH_SIZE, 24, glcanvas.WX_GL_STENCIL_SIZE, 8) + glcanvas.GLCanvas.__init__(self, parent, attribList = attribList) + self.parent = realParent + self.context = glcanvas.GLContext(self) + wx.EVT_PAINT(self, self.OnPaint) + wx.EVT_SIZE(self, self.OnSize) + wx.EVT_ERASE_BACKGROUND(self, self.OnEraseBackground) + wx.EVT_LEFT_DOWN(self, self.OnMouseLeftDown) + wx.EVT_MOTION(self, self.OnMouseMotion) + wx.EVT_MOUSEWHEEL(self, self.OnMouseWheel) + self.yaw = 30 + self.pitch = 60 + self.zoom = self.parent.machineSize.x / 2 + 10 + self.offsetX = 0 + self.offsetY = 0 + self.view3D = False + self.allowDrag = False + + def OnMouseLeftDown(self,e): + self.allowDrag = True + + def OnMouseMotion(self,e): + if self.allowDrag and e.Dragging() and e.LeftIsDown(): + if self.view3D: + self.yaw += e.GetX() - self.oldX + self.pitch -= e.GetY() - self.oldY + if self.pitch > 170: + self.pitch = 170 + if self.pitch < 10: + self.pitch = 10 + else: + self.offsetX += float(e.GetX() - self.oldX) * self.zoom / self.GetSize().GetHeight() * 2 + self.offsetY -= float(e.GetY() - self.oldY) * self.zoom / self.GetSize().GetHeight() * 2 + self.Refresh() + else: + self.allowDrag = False + if e.Dragging() and e.RightIsDown(): + if self.view3D: + self.zoom += e.GetY() - self.oldY + if self.zoom < 1: + self.zoom = 1 + self.Refresh() + self.oldX = e.GetX() + self.oldY = e.GetY() + + def OnMouseWheel(self,e): + if self.view3D: + self.zoom *= 1.0 - float(e.GetWheelRotation() / e.GetWheelDelta()) / 10.0 + if self.zoom < 1.0: + self.zoom = 1.0 + self.Refresh() + + def OnEraseBackground(self,event): + #Workaround for windows background redraw flicker. + pass + + def OnSize(self,event): + self.Refresh() + + def OnPaint(self,event): + dc = wx.PaintDC(self) + if not hasOpenGLlibs: + dc.Clear() + dc.DrawText("No PyOpenGL installation found.\nNo preview window available.", 10, 10) + return + self.SetCurrent(self.context) + opengl.InitGL(self, self.view3D, self.zoom) + if self.view3D: + glTranslate(0,0,-self.zoom) + glRotate(-self.pitch, 1,0,0) + glRotate(self.yaw, 0,0,1) + if False: #self.parent.triangleMesh != None: + glTranslate(0,0,-self.parent.triangleMesh.getMaximum().z / 2) + else: + glScale(1.0/self.zoom, 1.0/self.zoom, 1.0) + glTranslate(self.offsetX, self.offsetY, 0.0) + glTranslate(-self.parent.machineSize.x/2, -self.parent.machineSize.y/2, 0) + + self.OnDraw() + self.SwapBuffers() + + def OnDraw(self): + machineSize = self.parent.machineSize + opengl.DrawMachine(machineSize) + + if self.parent.svg != None: + for path in self.parent.svg.paths: + glColor3f(1.0,0.8,0.6) + glBegin(GL_LINE_STRIP) + for p in path: + glVertex3f(p.real, p.imag, 1) + glEnd() + + glFlush() + +def main(): + app = wx.App(False) + flatSlicerWindow().Show(True) + app.MainLoop() + +if __name__ == '__main__': + main() + diff --git a/Cura/gui/mainWindow.py b/Cura/gui/mainWindow.py index d4b8f55..affdfa3 100644 --- a/Cura/gui/mainWindow.py +++ b/Cura/gui/mainWindow.py @@ -15,9 +15,11 @@ from gui import machineCom from gui import printWindow from gui import simpleMode from gui import projectPlanner +from gui import flatSlicerWindow from gui import icon from util import profile from util import version +from util import sliceRun def main(): app = wx.App(False) @@ -66,6 +68,8 @@ class mainWindow(configBase.configWindowBase): expertMenu = wx.Menu() i = expertMenu.Append(-1, 'Open expert settings...') self.Bind(wx.EVT_MENU, self.OnExpertOpen, i) + i = expertMenu.Append(-1, 'Open SVG (2D) slicer...') + self.Bind(wx.EVT_MENU, self.OnSVGSlicerOpen, i) expertMenu.AppendSeparator() i = expertMenu.Append(-1, 'Install default Marlin firmware') self.Bind(wx.EVT_MENU, self.OnDefaultMarlinFirmware, i) @@ -333,10 +337,10 @@ class mainWindow(configBase.configWindowBase): if len(self.filelist) < 1: wx.MessageBox('You need to load a file and slice it before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - if not os.path.exists(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode"): + if not os.path.exists(sliceRun.getExportFilename(self.filelist[0])): wx.MessageBox('You need to slice the file to GCode before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - printWindow.printFile(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode") + printWindow.printFile(sliceRun.getExportFilename(self.filelist[0])) def OnExpertOpen(self, e): ecw = expertConfig.expertConfigWindow() @@ -348,6 +352,11 @@ class mainWindow(configBase.configWindowBase): pp.Centre() pp.Show(True) + def OnSVGSlicerOpen(self, e): + svgSlicer = flatSlicerWindow.flatSlicerWindow() + svgSlicer.Centre() + svgSlicer.Show(True) + def removeSliceProgress(self, spp): self.progressPanelList.remove(spp) newSize = self.GetSize(); diff --git a/Cura/gui/opengl.py b/Cura/gui/opengl.py index e5204cf..7f6fcb1 100644 --- a/Cura/gui/opengl.py +++ b/Cura/gui/opengl.py @@ -165,8 +165,8 @@ def ResetMatrixRotationAndScale(): matrix[2][2] = 1.0 if matrix[3][2] != 0.0: - matrix[3][0] /= -matrix[3][2] / 100 - matrix[3][1] /= -matrix[3][2] / 100 + matrix[3][0] = matrix[3][0] / (-matrix[3][2] / 100) + matrix[3][1] = matrix[3][1] / (-matrix[3][2] / 100) matrix[3][2] = -100 else: matrix[0][0] = scale2D @@ -227,25 +227,35 @@ def DrawGCodeLayer(layer): fillCycle = 0 fillColorCycle = [[0.5,0.5,0.0],[0.0,0.5,0.5],[0.5,0.0,0.5]] + moveColor = [0,0,1] + retractColor = [0,1,1] + supportColor = [0,1,1] + extrudeColor = [1,0,0] + innerWallColor = [0,1,0] + skirtColor = [0,0.5,0.5] + prevPathWasRetract = False glDisable(GL_CULL_FACE) for path in layer: if path.type == 'move': - glColor3f(0,0,1) + if prevPathWasRetract: + c = retractColor + else: + c = moveColor if path.type == 'extrude': if path.pathType == 'FILL': - glColor3fv(fillColorCycle[fillCycle]) + c = fillColorCycle[fillCycle] fillCycle = (fillCycle + 1) % len(fillColorCycle) elif path.pathType == 'WALL-INNER': - glColor3fv([0,1,0]) + c = innerWallColor elif path.pathType == 'SUPPORT': - glColor3fv([0,1,1]) + c = supportColor elif path.pathType == 'SKIRT': - glColor3fv([0,0.5,0.5]) + c = skirtColor else: - glColor3fv([1,0,0]) + c = extrudeColor if path.type == 'retract': - glColor3fv([0,1,1]) + c = [0,1,1] if path.type == 'extrude': drawLength = 0.0 prevNormal = None @@ -269,6 +279,7 @@ def DrawGCodeLayer(layer): vv1 = v1 - normal * lineWidth glBegin(GL_QUADS) + glColor3fv(c) glVertex3f(vv0.x, vv0.y, vv0.z - 0.01) glVertex3f(vv1.x, vv1.y, vv1.z - 0.01) glVertex3f(vv3.x, vv3.y, vv3.z - 0.01) @@ -280,6 +291,7 @@ def DrawGCodeLayer(layer): vv4 = v0 + n * lineWidth vv5 = v0 - n * lineWidth glBegin(GL_QUADS) + glColor3fv(c) glVertex3f(vv2.x, vv2.y, vv2.z) glVertex3f(vv4.x, vv4.y, vv4.z) glVertex3f(prevVv3.x, prevVv3.y, prevVv3.z) @@ -296,7 +308,11 @@ def DrawGCodeLayer(layer): prevVv3 = vv3 else: glBegin(GL_LINE_STRIP) + glColor3fv(c) for v in path.list: glVertex3f(v.x, v.y, v.z) glEnd() + prevPathWasRetract = False + if path.type == 'retract' and path.list[0].almostEqual(path.list[-1]): + prevPathWasRetract = True glEnable(GL_CULL_FACE) diff --git a/Cura/gui/preview3d.py b/Cura/gui/preview3d.py index 43cb8c9..49659d8 100644 --- a/Cura/gui/preview3d.py +++ b/Cura/gui/preview3d.py @@ -21,6 +21,7 @@ from util import profile from util import gcodeInterpreter from util import stl from util import util3d +from util import sliceRun class previewObject(): def __init__(self): @@ -207,8 +208,8 @@ class previewPanel(wx.Panel): self.logFileTime = None obj.filename = filelist[idx] - self.gcodeFilename = filelist[0][: filelist[0].rfind('.')] + "_export.gcode" - self.logFilename = filelist[0][: filelist[0].rfind('.')] + "_export.log" + self.gcodeFilename = sliceRun.getExportFilename(filelist[0]) + self.logFilename = sliceRun.getExportFilename(filelist[0], "log") #Do the STL file loading in a background thread so we don't block the UI. if self.loadThread != None and self.loadThread.isAlive(): self.loadThread.join() @@ -360,6 +361,8 @@ class PreviewGLCanvas(glcanvas.GLCanvas): else: self.offsetX += float(e.GetX() - self.oldX) * self.zoom / self.GetSize().GetHeight() * 2 self.offsetY -= float(e.GetY() - self.oldY) * self.zoom / self.GetSize().GetHeight() * 2 + + #Workaround for buggy ATI cards. size = self.GetSizeTuple() self.SetSize((size[0]+1, size[1])) self.SetSize((size[0], size[1])) diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index dd14425..39686ba 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -6,6 +6,7 @@ from wx.lib import buttons from gui import machineCom from gui import icon +from gui import toolbarUtil from util import profile from util import gcodeInterpreter @@ -53,7 +54,7 @@ class printProcessMonitor(): class PrintCommandButton(buttons.GenBitmapButton): def __init__(self, parent, command, bitmapFilename, size=(20,20)): - self.bitmap = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilename)) + self.bitmap = toolbarUtil.getBitmapImage(bitmapFilename) super(PrintCommandButton, self).__init__(parent.directControlPanel, -1, self.bitmap, size=size) self.command = command diff --git a/Cura/gui/projectPlanner.py b/Cura/gui/projectPlanner.py index 054fbe7..8096129 100644 --- a/Cura/gui/projectPlanner.py +++ b/Cura/gui/projectPlanner.py @@ -893,7 +893,7 @@ class ProjectSliceProgressWindow(wx.Frame): profile.resetTempOverride() if not action.usePreviousSlice: - f = open(action.filename[: action.filename.rfind('.')] + "_export.project_tmp", "r") + f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") data = f.read(4096) while data != '': resultFile.write(data) @@ -902,7 +902,7 @@ class ProjectSliceProgressWindow(wx.Frame): savedCenterX = action.centerX savedCenterY = action.centerY else: - f = open(action.filename[: action.filename.rfind('.')] + "_export.project_tmp", "r") + f = open(sliceRun.getExportFilename(action.filename, "project_tmp"), "r") for line in f: if line[0] != ';': if 'X' in line: @@ -913,7 +913,7 @@ class ProjectSliceProgressWindow(wx.Frame): f.close() if not action.leaveResultForNextSlice: - os.remove(action.filename[: action.filename.rfind('.')] + "_export.project_tmp") + os.remove(sliceRun.getExportFilename(action.filename, "project_tmp")) wx.CallAfter(self.progressGauge.SetValue, 10000) self.totalDoneFactor = 0.0 diff --git a/Cura/gui/simpleMode.py b/Cura/gui/simpleMode.py index ffd2ac7..0d9e95a 100644 --- a/Cura/gui/simpleMode.py +++ b/Cura/gui/simpleMode.py @@ -14,6 +14,7 @@ from gui import printWindow from gui import icon from util import profile from util import version +from util import sliceRun class simpleModeWindow(configBase.configWindowBase): "Main user interface window for Quickprint mode" @@ -211,7 +212,6 @@ class simpleModeWindow(configBase.configWindowBase): put('joris', 'False') put('cool_min_feedrate', '5') put('bridge_speed', '100') - put('bridge_material_amount', '100') put('raft_margin', '5') put('raft_base_material_amount', '100') put('raft_interface_material_amount', '100') @@ -276,10 +276,10 @@ class simpleModeWindow(configBase.configWindowBase): if len(self.filelist) < 1: wx.MessageBox('You need to load a file and slice it before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - if not os.path.exists(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode"): + if not os.path.exists(sliceRun.getExportFilename(self.filelist[0])): wx.MessageBox('You need to slice the file to GCode before you can print it.', 'Print error', wx.OK | wx.ICON_INFORMATION) return - printWindow.printFile(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode") + printWindow.printFile(sliceRun.getExportFilename(self.filelist[0])) def OnNormalSwitch(self, e): from gui import mainWindow diff --git a/Cura/gui/sliceProgessPanel.py b/Cura/gui/sliceProgessPanel.py index d2240a5..344ea64 100644 --- a/Cura/gui/sliceProgessPanel.py +++ b/Cura/gui/sliceProgessPanel.py @@ -68,7 +68,7 @@ class sliceProgessPanel(wx.Panel): LogWindow('\n'.join(self.progressLog)) def OnOpenFileLocation(self, e): - exporer.openExporer(self.filelist[0][: self.filelist[0].rfind('.')] + "_export.gcode") + exporer.openExporer(sliceRun.getExportFilename(self.filelist[0])) def OnSliceDone(self, result): self.progressGauge.Destroy() @@ -145,7 +145,7 @@ class WorkerThread(threading.Thread): return line = p.stdout.readline() self.returnCode = p.wait() - logfile = open(self.filelist[self.fileIdx][: self.filelist[self.fileIdx].rfind('.')] + "_export.log", "w") + logfile = open(sliceRun.getExportFilename(self.filelist[self.fileIdx], "log"), "w") for logLine in self.progressLog: logfile.write(logLine) logfile.write('\n') @@ -155,19 +155,19 @@ class WorkerThread(threading.Thread): if len(self.filelist) > 1: self._stitchMultiExtruder() self.gcode = gcodeInterpreter.gcode() - self.gcode.load(self.filelist[0][:self.filelist[0].rfind('.')]+'_export.gcode') + self.gcode.load(sliceRun.getExportFilename(self.filelist[0])) wx.CallAfter(self.notifyWindow.OnSliceDone, self) else: self.run() def _stitchMultiExtruder(self): files = [] - resultFile = open(self.filelist[0][:self.filelist[0].rfind('.')]+'_export.gcode', "w") + 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(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp'): - files.append(open(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp', "r")) + if os.path.isfile(sliceRun.getExportFilename(filename, 'multi_extrude_tmp')): + files.append(open(sliceRun.getExportFilename(filename, 'multi_extrude_tmp'), "r")) else: return @@ -201,7 +201,7 @@ class WorkerThread(threading.Thread): for f in files: f.close() for filename in self.filelist: - os.remove(filename[:filename.rfind('.')]+'_export.multi_extrude_tmp') + os.remove(sliceRun.getExportFilename(filename, 'multi_extrude_tmp')) resultFile.write(';TYPE:CUSTOM\n') resultFile.write(profile.getAlterationFileContents('end.gcode')) resultFile.close() diff --git a/Cura/gui/toolbarUtil.py b/Cura/gui/toolbarUtil.py index a609aa6..e49d77c 100644 --- a/Cura/gui/toolbarUtil.py +++ b/Cura/gui/toolbarUtil.py @@ -12,6 +12,13 @@ from util import profile # toolbar buttons. ####################################################### +def getBitmapImage(filename): + #The frozen executable has the script files in a zip, so we need to exit another level to get to our images. + if hasattr(sys, 'frozen'): + return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../../images", filename))) + else: + return wx.Bitmap(os.path.normpath(os.path.join(os.path.split(__file__)[0], "../images", filename))) + class Toolbar(wx.ToolBar): def __init__(self, parent): super(Toolbar, self).__init__(parent, -1, style=wx.TB_HORIZONTAL | wx.NO_BORDER) @@ -52,8 +59,8 @@ class Toolbar(wx.ToolBar): class ToggleButton(buttons.GenBitmapToggleButton): def __init__(self, parent, profileSetting, bitmapFilenameOn, bitmapFilenameOff, helpText='', id=-1, callback=None, size=(20,20)): - self.bitmapOn = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOn)) - self.bitmapOff = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOff)) + self.bitmapOn = getBitmapImage(bitmapFilenameOn) + self.bitmapOff = getBitmapImage(bitmapFilenameOff) super(ToggleButton, self).__init__(parent, id, self.bitmapOff, size=size) @@ -114,8 +121,8 @@ class ToggleButton(buttons.GenBitmapToggleButton): class RadioButton(buttons.GenBitmapButton): def __init__(self, parent, group, bitmapFilenameOn, bitmapFilenameOff, helpText='', id=-1, callback=None, size=(20,20)): - self.bitmapOn = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOn)) - self.bitmapOff = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilenameOff)) + self.bitmapOn = getBitmapImage(bitmapFilenameOn) + self.bitmapOff = getBitmapImage(bitmapFilenameOff) super(RadioButton, self).__init__(parent, id, self.bitmapOff, size=size) @@ -176,7 +183,7 @@ class RadioButton(buttons.GenBitmapButton): class NormalButton(buttons.GenBitmapButton): def __init__(self, parent, callback, bitmapFilename, helpText='', id=-1, size=(20,20)): - self.bitmap = wx.Bitmap(os.path.join(os.path.split(__file__)[0], "../images", bitmapFilename)) + self.bitmap = getBitmapImage(bitmapFilename) super(NormalButton, self).__init__(parent, id, self.bitmap, size=size) self.helpText = helpText diff --git a/Cura/images/cut-mesh.png b/Cura/images/cut-mesh.png new file mode 100644 index 0000000..f702874 Binary files /dev/null and b/Cura/images/cut-mesh.png differ diff --git a/Cura/setup.py b/Cura/setup.py new file mode 100644 index 0000000..e077f67 --- /dev/null +++ b/Cura/setup.py @@ -0,0 +1,61 @@ +import sys, os, zipfile +try: + import cx_Freeze +except: + print "ERROR: You need cx-Freeze installed to build this package" + sys.exit(1) + +freezeVersion = map(int, cx_Freeze.version.split('.')) +if freezeVersion[0] < 4 or freezeVersion[0] == 4 and freezeVersion[1] < 2: + print "ERROR: Your cx-Freeze version is too old to use with Cura." + sys.exit(1) + +sys.path.append(os.path.abspath('cura_sf')) + +# Dependencies are automatically detected, but it might need fine tuning. +build_exe_options = { +"silent": True, +"packages": [ + 'encodings.utf_8', + "OpenGL", "OpenGL.arrays", "OpenGL.platform", "OpenGL.GLU", +], "excludes": [ + 'Tkinter', 'tcl', 'cura_sf', 'fabmetheus_utilities', 'skeinforge_application', 'numpy', +], "include_files": [ + ('images', 'images'), +], "build_exe": 'freeze_build'} + +# GUI applications require a different base on Windows (the default is for a +# console application). +base = None +if sys.platform == "win32": + base = "Win32GUI" + +cx_Freeze.setup( name = "Cura", + version = "RC5", + description = "Cura", + options = {"build_exe": build_exe_options}, + executables = [cx_Freeze.Executable("cura.py", base=base)]) + +m = cx_Freeze.ModuleFinder(excludes=["gui"]) +m.IncludeFile(os.path.abspath("cura.py")) +m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/profile_plugins/extrusion.py")) +m.IncludeFile(os.path.abspath("cura_sf/fabmetheus_utilities/fabmetheus_tools/interpret_plugins/stl.py")) +m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/export_plugins/static_plugins/gcode_small.py")) +for name in os.listdir("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins"): + if name.endswith('.py'): + m.IncludeFile(os.path.abspath("cura_sf/skeinforge_application/skeinforge_plugins/craft_plugins/" + name)) +m.ReportMissingModules() +cwd = os.path.abspath(".") + +z = zipfile.ZipFile("freeze_build/cura_sf.zip", "w", zipfile.ZIP_DEFLATED) +for mod in m.modules: + if mod.file != None and mod.file.startswith(cwd): + if mod.file[len(cwd)+1:] == "cura.py": + z.write(mod.file[len(cwd)+1:], "__main__.py") + else: + z.write(mod.file[len(cwd)+1:]) +z.write('cura_sf/fabmetheus_utilities/templates/layer_template.svg') +z.write('cura_sf/fabmetheus_utilities/version.txt') +z.write('__init__.py') +z.close() + diff --git a/Cura/util/__init__.py b/Cura/util/__init__.py index 4870325..e69de29 100644 --- a/Cura/util/__init__.py +++ b/Cura/util/__init__.py @@ -1,9 +0,0 @@ -import os -import sys - -numberOfLevelsDeepInPackageHierarchy = 1 -packageFilePath = os.path.abspath(__file__) -for level in range( numberOfLevelsDeepInPackageHierarchy + 1 ): - packageFilePath = os.path.dirname( packageFilePath ) -if packageFilePath not in sys.path: - sys.path.insert( 0, packageFilePath ) diff --git a/Cura/util/exporer.py b/Cura/util/exporer.py index 5eca141..c729243 100644 --- a/Cura/util/exporer.py +++ b/Cura/util/exporer.py @@ -1,6 +1,3 @@ -from __future__ import absolute_import -import __init__ - import sys, os, subprocess def hasExporer(): diff --git a/Cura/util/gcodeInterpreter.py b/Cura/util/gcodeInterpreter.py index 78e71ac..b715050 100644 --- a/Cura/util/gcodeInterpreter.py +++ b/Cura/util/gcodeInterpreter.py @@ -1,13 +1,10 @@ -from __future__ import absolute_import -import __init__ - import sys import math import re import os -from util import util3d -from util import profile +import util3d +import profile class gcodePath(object): def __init__(self, newType, pathType, layerThickness, startPoint): @@ -25,10 +22,11 @@ class gcode(object): self.progressCallback = None def load(self, filename): - self._fileSize = os.stat(filename).st_size - gcodeFile = open(filename, 'r') - self._load(gcodeFile) - gcodeFile.close() + if os.path.isfile(filename): + self._fileSize = os.stat(filename).st_size + gcodeFile = open(filename, 'r') + self._load(gcodeFile) + gcodeFile.close() def loadList(self, l): self._load(l) @@ -217,6 +215,8 @@ class gcode(object): pass elif M == 109: #Set temperature, wait pass + elif M == 110: #Reset N counter + pass elif M == 113: #Extruder PWM (these should not be in the final GCode, but they are) pass else: diff --git a/Cura/util/mesh.py b/Cura/util/mesh.py index 1dbd8cd..c219848 100644 --- a/Cura/util/mesh.py +++ b/Cura/util/mesh.py @@ -1,9 +1,6 @@ -from __future__ import absolute_import -import __init__ - import sys, math, re, os, struct, time -from util import util3d +import util3d class meshFace(object): def __init__(self, v0, v1, v2): diff --git a/Cura/util/profile.py b/Cura/util/profile.py index 4742c5e..9304706 100644 --- a/Cura/util/profile.py +++ b/Cura/util/profile.py @@ -3,7 +3,7 @@ from __future__ import division #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module. import __init__ -import ConfigParser, os, traceback, math, re, zlib, base64, time +import ConfigParser, os, traceback, math, re, zlib, base64, time, sys ######################################################### ## Default settings when none are found. @@ -59,7 +59,6 @@ profileDefaultSettings = { 'enable_raft': 'False', 'cool_min_feedrate': '5', 'bridge_speed': '100', - 'bridge_material_amount': '100', 'raft_margin': '5', 'raft_base_material_amount': '100', 'raft_interface_material_amount': '100', @@ -171,7 +170,11 @@ preferencesDefaultSettings = { ## Profile functions def getDefaultProfilePath(): - return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../current_profile.ini")) + basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) + #If we have a frozen python install, we need to step out of the library.zip + if hasattr(sys, 'frozen'): + basePath = os.path.normpath(os.path.join(basePath, "..")) + return os.path.normpath(os.path.join(basePath, "current_profile.ini")) def loadGlobalProfile(filename): #Read a configuration file as global config @@ -273,7 +276,11 @@ global globalPreferenceParser globalPreferenceParser = None def getPreferencePath(): - return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../preferences.ini")) + basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) + #If we have a frozen python install, we need to step out of the library.zip + if hasattr(sys, 'frozen'): + basePath = os.path.normpath(os.path.join(basePath, "..")) + return os.path.normpath(os.path.join(basePath, "preferences.ini")) def getPreferenceFloat(name): try: diff --git a/Cura/util/sliceRun.py b/Cura/util/sliceRun.py index 7c2ca54..483dbc5 100644 --- a/Cura/util/sliceRun.py +++ b/Cura/util/sliceRun.py @@ -2,7 +2,12 @@ from __future__ import absolute_import import platform, os, subprocess, sys -from cura_sf.skeinforge_application.skeinforge_utilities import skeinforge_craft +if not hasattr(sys, 'frozen'): + cura_sf_path = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../cura_sf/")) + if cura_sf_path not in sys.path: + sys.path.append(cura_sf_path) + from skeinforge_application.skeinforge_utilities import skeinforge_craft + from util import profile #How long does each step take compared to the others. This is used to make a better scaled progress bar, and guess time left. @@ -32,10 +37,10 @@ def getPyPyExe(): "Return the path to the pypy executable if we can find it. Else return False" if platform.system() == "Windows": exeName = "pypy.exe" - pypyExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../pypy/pypy.exe")); + pypyExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../pypy/pypy.exe")) else: exeName = "pypy" - pypyExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../pypy/bin/pypy")); + pypyExe = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../pypy/bin/pypy")) if os.path.exists(pypyExe): return pypyExe @@ -73,15 +78,25 @@ def runSlice(fileNames): if platform.python_implementation() == "PyPy": skeinforge_craft.writeOutput(fileName) elif pypyExe == False: - print "************************************************" - print "* Failed to find pypy, so slicing with python! *" - print "************************************************" - skeinforge_craft.writeOutput(fileName) - print "************************************************" - print "* Failed to find pypy, so sliced with python! *" - print "************************************************" + if not hasattr(sys, 'frozen'): + print "************************************************" + print "* Failed to find pypy, so slicing with python! *" + print "************************************************" + skeinforge_craft.writeOutput(fileName) + print "************************************************" + print "* Failed to find pypy, so sliced with python! *" + print "************************************************" + else: + print "******************************************************************" + print "* Failed to find pypy, we need pypy to slice with a frozen build *" + print "* Place pypy in the same directory as Cura so Cura can find it. *" + print "******************************************************************" + sys.exit(1) else: - subprocess.call([pypyExe, os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1])), '-p', profile.getGlobalProfileString(), fileName]) + subprocess.call(getSliceCommand(fileName)) + +def getExportFilename(filename, ext = "gcode"): + return "%s_export.%s" % (filename[: filename.rfind('.')], ext) def getSliceCommand(filename): if profile.getPreference('slicer').startswith('Slic3r') and getSlic3rExe() != False: @@ -139,7 +154,13 @@ def getSliceCommand(filename): pypyExe = getPyPyExe() if pypyExe == False: pypyExe = sys.executable - cmd = [pypyExe, os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1])), '-p', profile.getGlobalProfileString()] + + #In case we have a frozen exe, then argv[0] points to the executable, but we want to give pypy a real script file. + if hasattr(sys, 'frozen'): + mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../..", "cura_sf.zip")) + else: + mainScriptFile = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", os.path.split(sys.argv[0])[1])) + cmd = [pypyExe, mainScriptFile, '-p', profile.getGlobalProfileString()] cmd.append(filename) return cmd diff --git a/Cura/util/stl.py b/Cura/util/stl.py index 7e3e642..8b87a41 100644 --- a/Cura/util/stl.py +++ b/Cura/util/stl.py @@ -1,10 +1,7 @@ -from __future__ import absolute_import -import __init__ - import sys, math, re, os, struct, time -from util import util3d -from util import mesh +import util3d +import mesh class stlModel(mesh.mesh): def __init__(self): diff --git a/Cura/util/svg.py b/Cura/util/svg.py new file mode 100644 index 0000000..8cd394c --- /dev/null +++ b/Cura/util/svg.py @@ -0,0 +1,190 @@ +import sys, math, re, os, struct, time +from xml.etree import ElementTree + +import profile + +def processRect(e): + x = float(e.get('x')) + y = float(e.get('y')) + width = float(e.get('width')) + height = float(e.get('height')) + return [[complex(x, -y), complex(x+width, -y), complex(x+width, -(y+height)), complex(x, -(y+height)), complex(x, -y)]] + +def processPath(e): + d = e.get('d').replace(',', ' ') + num = "" + cmd = None + paths = [] + curPath = None + + p = complex(0, 0) + for c in d + "#": + if c in "-+.0123456789e": + num += c + if c in " \t\n\r#": + if len(num) > 0: + param.append(float(num)) + num = "" + if c in "MmZzLlHhVvCcSsQqTtAa#": + if cmd == 'M': + p = complex(param[0], -param[1]) + curPath = None + i = 2 + while i < len(param): + if curPath == None: + curPath = [p] + paths.append(curPath) + p = complex(param[i], -param[i+1]) + curPath.append(p) + i += 2 + elif cmd == 'm': + p += complex(param[0], -param[1]) + curPath = None + i = 2 + while i < len(param): + if curPath == None: + curPath = [p] + paths.append(curPath) + p += complex(param[i], -param[i+1]) + curPath.append(p) + i += 2 + elif cmd == 'L': + if curPath == None: + curPath = [p] + paths.append(curPath) + i = 0 + while i < len(param): + p = complex(param[i], -param[i+1]) + curPath.append(p) + i += 2 + elif cmd == 'l': + if curPath == None: + curPath = [p] + paths.append(curPath) + i = 0 + while i < len(param): + p += complex(param[i], -param[i+1]) + curPath.append(p) + i += 2 + curPath.append(p) + elif cmd == 'C': + if curPath == None: + curPath = [p] + paths.append(curPath) + i = 0 + while i < len(param): + addCurve(curPath, p, complex(param[i], -param[i+1]), complex(param[i+2], -param[i+3]), complex(param[i+4], -param[i+5])) + p = complex(param[i+4], -param[i+5]) + curPath.append(p) + i += 6 + elif cmd == 'c': + if curPath == None: + curPath = [p] + paths.append(curPath) + i = 0 + while i < len(param): + addCurve(curPath, p, p + complex(param[i], -param[i+1]), p + complex(param[i+2], -param[i+3]), p + complex(param[i+4], -param[i+5])) + p += complex(param[i+4], -param[i+5]) + curPath.append(p) + i += 6 + elif cmd == 'a': + if curPath == None: + curPath = [p] + paths.append(curPath) + i = 0 + print param + while i < len(param): + endPoint = p + complex(param[i+5], -param[i+6]) + addArc(curPath, p, endPoint, param[i], param[i+1], param[i+2], param[i+3], param[i+4]) + p = endPoint + curPath.append(p) + i += 7 + elif cmd == 'Z' or cmd == 'z': + curPath.append(curPath[0]) + elif cmd != None: + print cmd + cmd = c + param = [] + return paths + +def interpolate(p0, p1, f): + return complex(p0.real + (p1.real - p0.real) * f, p0.imag + (p1.imag - p0.imag) * f) + +def addCurve(path, p0, q0, q1, p1): + oldPoint = p0 + for n in xrange(0, 100): + k = n / 100.0 + r0 = interpolate(p0, q0, k); + r1 = interpolate(q0, q1, k); + r2 = interpolate(q1, p1, k); + b0 = interpolate(r0, r1, k); + b1 = interpolate(r1, r2, k); + s = interpolate(b0, b1, k); + if abs(s - oldPoint) > 1.0: + path.append(s) + oldPoint = s + +def addArc(path, end, rx, ry, rot, largeArc, sweep): + pass + +def movePath(p, offset): + return map(lambda _p: _p - offset, p) + +class SVG(object): + def __init__(self, filename): + tagProcess = {} + tagProcess['rect'] = processRect + tagProcess['path'] = processPath + + self.paths = [] + for e in ElementTree.parse(open(filename, "r")).getiterator(): + tag = e.tag[e.tag.find('}')+1:] + if not tag in tagProcess: + #print 'unknown tag: %s' % (tag) + continue + self.paths.extend(tagProcess[tag](e)) + + def center(self, centerPoint): + offset = complex(0, 0) + n = 0 + for path in self.paths: + for point in path: + offset += point + n += 1 + offset /= n + offset -= centerPoint + + self.paths = [movePath(p, offset) for p in self.paths] + +if __name__ == '__main__': + svg = SVG("../logo.svg") + f = open("../../test_export.gcode", "w") + + f.write(';TYPE:CUSTOM\n') + f.write(profile.getAlterationFileContents('start.gcode')) + svg.center(complex(profile.getProfileSettingFloat('machine_center_x'), profile.getProfileSettingFloat('machine_center_y'))) + + layerThickness = 0.4 + filamentRadius = profile.getProfileSettingFloat('filament_diameter') / 2 + filamentArea = math.pi * filamentRadius * filamentRadius + lineWidth = profile.getProfileSettingFloat('nozzle_size') * 2 + + e = 0 + z = layerThickness + + for n in xrange(0, 20): + f.write("G1 Z%f F%f\n" % (z, profile.getProfileSettingFloat('max_z_speed')*60)) + for path in svg.paths: + oldPoint = path[0] + extrusionMMperDist = lineWidth * layerThickness / filamentArea + f.write("G1 X%f Y%f F%f\n" % (oldPoint.real, oldPoint.imag, profile.getProfileSettingFloat('travel_speed')*60)) + f.write("G1 F%f\n" % (profile.getProfileSettingFloat('print_speed')*60)) + for point in path[1:]: + dist = abs(oldPoint - point) + e += dist * extrusionMMperDist + f.write("G1 X%f Y%f E%f\n" % (point.real, point.imag, e)) + oldPoint = point + z += layerThickness + f.write(profile.getAlterationFileContents('end.gcode')) + f.close() + diff --git a/Cura/util/util3d.py b/Cura/util/util3d.py index b5140b2..43146a7 100644 --- a/Cura/util/util3d.py +++ b/Cura/util/util3d.py @@ -1,4 +1,3 @@ - import math class Vector3(object): diff --git a/Cura/util/version.py b/Cura/util/version.py index 98c9ea5..2c27a55 100644 --- a/Cura/util/version.py +++ b/Cura/util/version.py @@ -1,6 +1,3 @@ -from __future__ import absolute_import -import __init__ - import os def getVersion():