Ejemplo n.º 1
0
def getFileOrGcodeDirectory( fileName, wasCancelled, words = [] ):
	"Get the gcode files in the directory the file is in if directory setting is true.  Otherwise, return the file in a list."
	if isEmptyOrCancelled( fileName, wasCancelled ):
		return []
	if isDirectorySetting():
		return gcodec.getFilesWithFileTypeWithoutWords( 'gcode', words, fileName )
	return [ fileName ]
Ejemplo n.º 2
0
def getCarving(fileName=''):
    "Get the triangle mesh for the stl file."
    if fileName == '':
        unmodified = gcodec.getFilesWithFileTypeWithoutWords('stl')
        if len(unmodified) == 0:
            print("There is no stl file in this folder.")
            return None
        fileName = unmodified[0]
    stlData = gcodec.getFileText(fileName, 'rb')
    if stlData == '':
        return None
    triangleMesh = triangle_mesh.TriangleMesh()
    vertexIndexTable = {}
    binarySolidworksHeaderErrorString = 'solid binary STL from Solid Edge, Unigraphics Solutions Inc.'
    binarySolidworksHeaderError = stlData[:len(
        binarySolidworksHeaderErrorString
    )] == binarySolidworksHeaderErrorString
    if binarySolidworksHeaderError:
        print('The solidworks file has the incorrect header:')
        print(binarySolidworksHeaderErrorString)
        print(
            'A binary stl should never start with the word "solid".  Because this error is common the file is been parsed as binary regardless.'
        )
    if (stlData[:5] == 'solid' and not binarySolidworksHeaderError):
        addFacesGivenText(stlData, triangleMesh, vertexIndexTable)
    else:
        addFacesGivenBinary(stlData, triangleMesh, vertexIndexTable)
    triangleMesh.setEdgesForAllFaces()
    return triangleMesh
Ejemplo n.º 3
0
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 = gcodec.getFilesWithFileTypeWithoutWords( 'html' )
	if len( hypertextFiles ) <= 0:
		print( 'Failed to find any help files in writeHypertext in docwrap.' )
		return
	documentDirectoryPath = gcodec.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 ) )
Ejemplo n.º 4
0
def getFileOrGcodeDirectory( fileName, wasCancelled, words = [] ):
	"Get the gcode files in the directory the file is in if directory preference is true.  Otherwise, return the file in a list."
	if isEmptyOrCancelled( fileName, wasCancelled ):
		return []
	if isDirectoryPreference():
		return gcodec.getFilesWithFileTypeWithoutWords( 'gcode', words, fileName )
	return [ fileName ]
Ejemplo n.º 5
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the stl file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'stl' )
		if len( unmodified ) == 0:
			print( "There is no stl file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	stlData = gcodec.getFileText( fileName, 'rb' )
	if stlData == '':
		return None
	triangleMesh = triangle_mesh.TriangleMesh()
	vertexIndexTable = {}
	binarySolidworksHeaderErrorString = 'solid binary STL from Solid Edge, Unigraphics Solutions Inc.'
	binarySolidworksHeaderError = stlData[ : len( binarySolidworksHeaderErrorString ) ] == binarySolidworksHeaderErrorString
	if binarySolidworksHeaderError:
		print( 'The solidworks file has the incorrect header:' )
		print( binarySolidworksHeaderErrorString )
		print( 'A binary stl should never start with the word "solid".  Because this error is common the file is been parsed as binary regardless.' )
	if ( stlData[ : 5 ] == 'solid' and not binarySolidworksHeaderError ):
		addFacesGivenText( stlData, triangleMesh, vertexIndexTable )
	else:
		addFacesGivenBinary( stlData, triangleMesh, vertexIndexTable )
	triangleMesh.setEdgesForAllFaces()
	return triangleMesh
Ejemplo n.º 6
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the gts file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'gts' )
		if len( unmodified ) == 0:
			print( "There is no gts file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	return getFromGNUTriangulatedSurfaceText( gcodec.getFileText( fileName ), triangle_mesh.TriangleMesh() )
Ejemplo n.º 7
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the gts file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'gts' )
		if len( unmodified ) == 0:
			print( "There is no gts file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	return getFromGNUTriangulatedSurfaceText( gcodec.getFileText( fileName ), triangle_mesh.TriangleMesh() )
Ejemplo n.º 8
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the slc file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'slc' )
		if len( unmodified ) == 0:
			print( "There is no slc file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	carving = SLCCarving()
	carving.readFile( fileName )
	return carving
Ejemplo n.º 9
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the slc file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'slc' )
		if len( unmodified ) == 0:
			print( "There is no slc file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	carving = SLCCarving()
	carving.readFile( fileName )
	return carving
Ejemplo n.º 10
0
def getCarving(fileName=''):
    "Get the triangle mesh for the gts file."
    if fileName == '':
        unmodified = gcodec.getFilesWithFileTypeWithoutWords('gts')
        if len(unmodified) == 0:
            print("There is no gts file in this folder.")
            return None
        fileName = unmodified[0]
    carving = SVGCarving()
    carving.parseSVG(gcodec.getFileText(fileName))
    return carving
Ejemplo n.º 11
0
def getCarving( fileName = '' ):
	"Get the carving for the xml file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'xml' )
		if len( unmodified ) == 0:
			print( "There is no xml file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	carving = XMLCarving()
	carving.parseXML( gcodec.getFileText( fileName ) )
	return carving
Ejemplo n.º 12
0
def getCarving(fileName=""):
    "Get the triangle mesh for the gts file."
    if fileName == "":
        unmodified = gcodec.getFilesWithFileTypeWithoutWords("gts")
        if len(unmodified) == 0:
            print("There is no gts file in this folder.")
            return None
        fileName = unmodified[0]
    carving = SVGCarving()
    carving.parseSVG(gcodec.getFileText(fileName))
    return carving
Ejemplo n.º 13
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the obj file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'obj' )
		if len( unmodified ) == 0:
			print( "There is no obj file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	objText = gcodec.getFileText( fileName, 'rb' )
	if objText == '':
		return None
	triangleMesh = triangle_mesh.TriangleMesh()
	addFacesGivenText( objText, triangleMesh )
	triangleMesh.setEdgesForAllFaces()
	return triangleMesh
Ejemplo n.º 14
0
def getCarving(fileName=''):
    "Get the triangle mesh for the obj file."
    if fileName == '':
        unmodified = gcodec.getFilesWithFileTypeWithoutWords('obj')
        if len(unmodified) == 0:
            print("There is no obj file in this folder.")
            return None
        fileName = unmodified[0]
    objText = gcodec.getFileText(fileName, 'rb')
    if objText == '':
        return None
    triangleMesh = triangle_mesh.TriangleMesh()
    addFacesGivenText(objText, triangleMesh)
    triangleMesh.setEdgesForAllFaces()
    return triangleMesh
Ejemplo n.º 15
0
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 = gcodec.getFilesWithFileTypeWithoutWords( 'html' )
	if len( hypertextFiles ) <= 0:
		print( 'Failed to find any help files in writeHypertext in docwrap.' )
		return
	documentDirectoryPath = gcodec.getAbsoluteFolderPath( hypertextFiles[ 0 ], 'documentation' )
	removeFilesInDirectory( documentDirectoryPath )
#	for hypertextFile in hypertextFiles[ : 1 ]:
	for hypertextFile in hypertextFiles:
		readWriteDeleteHypertextHelp( documentDirectoryPath, hypertextFile )
	print( '%s files were wrapped.' % len( hypertextFiles ) )
Ejemplo n.º 16
0
def getCarving( fileName = '' ):
	"Get the triangle mesh for the stl file."
	if fileName == '':
		unmodified = gcodec.getFilesWithFileTypeWithoutWords( 'stl' )
		if len( unmodified ) == 0:
			print( "There is no stl file in this folder." )
			return None
		fileName = unmodified[ 0 ]
	stlData = gcodec.getFileText( fileName, 'rb' )
	if stlData == '':
		return None
	triangleMesh = triangle_mesh.TriangleMesh()
	vertexIndexTable = {}
	numberOfVertexStrings = stlData.count( 'vertex' )
	requiredVertexStringsForText = max( 2, len( stlData ) / 8000 )
	if numberOfVertexStrings > requiredVertexStringsForText:
		addFacesGivenText( stlData, triangleMesh, vertexIndexTable )
	else:
#	A binary stl should never start with the word "solid".  Because this error is common the file is been parsed as binary regardless.
		addFacesGivenBinary( stlData, triangleMesh, vertexIndexTable )
	triangleMesh.setEdgesForAllFaces()
	return triangleMesh
Ejemplo n.º 17
0
def getGCodeFilesWhichAreNotLogFiles():
	"Get gcode files which are not log files."
	return gcodec.getFilesWithFileTypeWithoutWords('gcode', ['_log'] )
Ejemplo n.º 18
0
def getGCodeFilesWhichAreNotLogFiles():
	"Get gcode files which are not log files."
	return gcodec.getFilesWithFileTypeWithoutWords( 'gcode', [ '_log' ] )