Example #1
0
	def getReplacedSVGTemplate(self, fileName, procedureName, rotatedLoopLayers, xmlElement=None):
		'Get the lines of text from the layer_template.svg file.'
		self.extent = self.cornerMaximum - self.cornerMinimum
		svgTemplateText = archive.getFileText(archive.getTemplatesPath('layer_template.svg'))
		self.xmlParser = XMLSimpleReader( fileName, None, svgTemplateText )
		self.svgElement = self.xmlParser.getRoot()
		svgElementDictionary = self.svgElement.attributeDictionary
		self.sliceDictionary = getSliceDictionary(self.svgElement)
		self.controlBoxHeight = float(self.sliceDictionary['controlBoxHeight'])
		self.controlBoxWidth = float(self.sliceDictionary['controlBoxWidth'])
		self.margin = float(self.sliceDictionary['margin'])
		self.marginTop = float(self.sliceDictionary['marginTop'])
		self.textHeight = float(self.sliceDictionary['textHeight'])
		self.unitScale = float(self.sliceDictionary['unitScale'])
		svgMinWidth = float(self.sliceDictionary['svgMinWidth'])
		self.controlBoxHeightMargin = self.controlBoxHeight + self.marginTop
		if not self.addLayerTemplateToSVG:
			self.svgElement.getXMLElementByID('layerTextTemplate').removeFromIDNameParent()
			del self.svgElement.getXMLElementByID('sliceElementTemplate').attributeDictionary['transform']
		self.graphicsXMLElement = self.svgElement.getXMLElementByID('sliceElementTemplate')
		self.graphicsXMLElement.attributeDictionary['id'] = 'z:'
		self.addRotatedLoopLayersToOutput(rotatedLoopLayers)
		self.setMetadataNoscriptElement('layerThickness', 'Layer Thickness: ', self.layerThickness)
		self.setMetadataNoscriptElement('maxX', 'X: ', self.cornerMaximum.x)
		self.setMetadataNoscriptElement('minX', 'X: ', self.cornerMinimum.x)
		self.setMetadataNoscriptElement('maxY', 'Y: ', self.cornerMaximum.y)
		self.setMetadataNoscriptElement('minY', 'Y: ', self.cornerMinimum.y)
		self.setMetadataNoscriptElement('maxZ', 'Z: ', self.cornerMaximum.z)
		self.setMetadataNoscriptElement('minZ', 'Z: ', self.cornerMinimum.z)
		self.textHeight = float( self.sliceDictionary['textHeight'] )
		controlTop = len(rotatedLoopLayers) * (self.margin + self.extent.y * self.unitScale + self.textHeight) + self.marginTop + self.textHeight
		self.svgElement.getFirstChildWithClassName('title').text = os.path.basename(fileName) + ' - Slice Layers'
		svgElementDictionary['height'] = '%spx' % self.getRounded(max(controlTop, self.controlBoxHeightMargin))
		width = max(self.extent.x * self.unitScale, svgMinWidth)
		svgElementDictionary['width'] = '%spx' % self.getRounded( width )
		self.sliceDictionary['decimalPlacesCarried'] = str( self.decimalPlacesCarried )
		if self.perimeterWidth != None:
			self.sliceDictionary['perimeterWidth'] = self.getRounded( self.perimeterWidth )
		self.sliceDictionary['yAxisPointingUpward'] = 'true'
		self.sliceDictionary['procedureName'] = procedureName
		self.setDimensionTexts('dimX', 'X: ' + self.getRounded(self.extent.x))
		self.setDimensionTexts('dimY', 'Y: ' + self.getRounded(self.extent.y))
		self.setDimensionTexts('dimZ', 'Z: ' + self.getRounded(self.extent.z))
		self.setTexts('numberOfLayers', 'Number of Layers: %s' % len(rotatedLoopLayers))
		volume = 0.0
		for rotatedLoopLayer in rotatedLoopLayers:
			volume += euclidean.getAreaLoops(rotatedLoopLayer.loops)
		volume *= 0.001
		self.setTexts('volume', 'Volume: %s cm3' % self.getRounded(volume))
		if not self.addLayerTemplateToSVG:
			self.svgElement.getFirstChildWithClassName('script').removeFromIDNameParent()
			self.svgElement.getXMLElementByID('isoControlBox').removeFromIDNameParent()
			self.svgElement.getXMLElementByID('layerControlBox').removeFromIDNameParent()
			self.svgElement.getXMLElementByID('scrollControlBox').removeFromIDNameParent()
		self.graphicsXMLElement.removeFromIDNameParent()
		self.addOriginalAsComment(xmlElement)
		output = cStringIO.StringIO()
		output.write(self.xmlParser.beforeRoot)
		self.svgElement.addXML(0, output)
		return xml_simple_writer.getBeforeRootOutput(self.xmlParser)
Example #2
0
	def getReplacedSVGTemplate(self, fileName, loopLayers, procedureName, elementNode=None):
		'Get the lines of text from the layer_template.svg file.'
		self.extent = self.cornerMaximum - self.cornerMinimum
		svgTemplateText = archive.getFileText(archive.getTemplatesPath('layer_template.svg'))
		documentNode = DocumentNode(fileName, svgTemplateText)
		self.svgElement = documentNode.getDocumentElement()
		svgElementDictionary = self.svgElement.attributes
		self.sliceDictionary = getSliceDictionary(self.svgElement)
		self.controlBoxHeight = float(self.sliceDictionary['controlBoxHeight'])
		self.controlBoxWidth = float(self.sliceDictionary['controlBoxWidth'])
		self.margin = float(self.sliceDictionary['margin'])
		self.marginTop = float(self.sliceDictionary['marginTop'])
		self.textHeight = float(self.sliceDictionary['textHeight'])
		self.unitScale = float(self.sliceDictionary['unitScale'])
		svgMinWidth = float(self.sliceDictionary['svgMinWidth'])
		self.controlBoxHeightMargin = self.controlBoxHeight + self.marginTop
		if not self.addLayerTemplateToSVG:
			self.svgElement.getElementNodeByID('layerTextTemplate').removeFromIDNameParent()
			del self.svgElement.getElementNodeByID('sliceElementTemplate').attributes['transform']
		self.graphicsElementNode = self.svgElement.getElementNodeByID('sliceElementTemplate')
		self.graphicsElementNode.attributes['id'] = 'z:'
		self.addLoopLayersToOutput(loopLayers)
		self.setMetadataNoscriptElement('layerThickness', 'Layer Thickness: ', self.layerThickness)
		self.setMetadataNoscriptElement('maxX', 'X: ', self.cornerMaximum.x)
		self.setMetadataNoscriptElement('minX', 'X: ', self.cornerMinimum.x)
		self.setMetadataNoscriptElement('maxY', 'Y: ', self.cornerMaximum.y)
		self.setMetadataNoscriptElement('minY', 'Y: ', self.cornerMinimum.y)
		self.setMetadataNoscriptElement('maxZ', 'Z: ', self.cornerMaximum.z)
		self.setMetadataNoscriptElement('minZ', 'Z: ', self.cornerMinimum.z)
		self.textHeight = float( self.sliceDictionary['textHeight'] )
		controlTop = len(loopLayers) * (self.margin + self.extent.y * self.unitScale + self.textHeight) + self.marginTop + self.textHeight
		self.svgElement.getFirstChildByLocalName('title').setTextContent(os.path.basename(fileName) + ' - Slice Layers')
		svgElementDictionary['height'] = '%spx' % self.getRounded(max(controlTop, self.controlBoxHeightMargin))
		width = max(self.extent.x * self.unitScale, svgMinWidth)
		svgElementDictionary['width'] = '%spx' % self.getRounded( width )
		self.sliceDictionary['decimalPlacesCarried'] = str( self.decimalPlacesCarried )
		if self.perimeterWidth != None:
			self.sliceDictionary['perimeterWidth'] = self.getRounded( self.perimeterWidth )
		self.sliceDictionary['yAxisPointingUpward'] = 'true'
		self.sliceDictionary['procedureName'] = procedureName
		self.setDimensionTexts('dimX', 'X: ' + self.getRounded(self.extent.x))
		self.setDimensionTexts('dimY', 'Y: ' + self.getRounded(self.extent.y))
		self.setDimensionTexts('dimZ', 'Z: ' + self.getRounded(self.extent.z))
		self.setTexts('numberOfLayers', 'Number of Layers: %s' % len(loopLayers))
		volume = 0.0
		for loopLayer in loopLayers:
			volume += euclidean.getAreaLoops(loopLayer.loops)
		volume *= 0.001 * self.layerThickness
		self.setTexts('volume', 'Volume: %s cm3' % self.getRounded(volume))
		if not self.addLayerTemplateToSVG:
			self.svgElement.getFirstChildByLocalName('script').removeFromIDNameParent()
			self.svgElement.getElementNodeByID('isoControlBox').removeFromIDNameParent()
			self.svgElement.getElementNodeByID('layerControlBox').removeFromIDNameParent()
			self.svgElement.getElementNodeByID('scrollControlBox').removeFromIDNameParent()
		self.graphicsElementNode.removeFromIDNameParent()
		self.addOriginalAsComment(elementNode)
		return documentNode.__repr__()
Example #3
0
	def execute(self):
		"""Export the canvas as an svg file."""
		svgFileName = archive.getFilePathWithUnderscoredBasename( self.fileName, self.suffix )
		boundingBox = self.canvas.bbox( settings.Tkinter.ALL ) # tuple (w, n, e, s)
		self.boxW = boundingBox[0]
		self.boxN = boundingBox[1]
		boxWidth = boundingBox[2] - self.boxW
		boxHeight = boundingBox[3] - self.boxN
		print('Exported svg file saved as ' + svgFileName )
		svgTemplateText = archive.getFileText(archive.getTemplatesPath('canvas_template.svg'))
		output = cStringIO.StringIO()
		lines = archive.getTextLines( svgTemplateText )
		firstWordTable = {}
		firstWordTable['height="999px"'] = '		height="%spx"' % int( round( boxHeight ) )
		firstWordTable['<!--replaceLineWith_coloredLines-->'] = self.getCanvasLinesOutput()
		firstWordTable['replaceLineWithTitle'] = archive.getSummarizedFileName( self.fileName )
		firstWordTable['width="999px"'] = '		width="%spx"' % int( round( boxWidth ) )
		for line in lines:
			parseLineReplace( firstWordTable, line, output )
		archive.writeFileText( svgFileName, output.getvalue() )
		fileExtension = self.fileExtension.value
		svgViewer = self.svgViewer.value
		if svgViewer == '':
			return
		if svgViewer == 'webbrowser':
			settings.openWebPage( svgFileName )
			return
		svgFilePath = '"' + os.path.normpath( svgFileName ) + '"' # " to send in file name with spaces
		shellCommand = svgViewer + ' ' + svgFilePath
		print('')
		if fileExtension == '':
			print('Sending the shell command:')
			print(shellCommand)
			commandResult = os.system(shellCommand)
			if commandResult != 0:
				print('It may be that the system could not find the %s program.' % svgViewer )
				print('If so, try installing the %s program or look for another svg viewer, like Netscape which can be found at:' % svgViewer )
				print('http://www.netscape.org/')
			return
		convertedFileName = archive.getFilePathWithUnderscoredBasename( svgFilePath, '.' + fileExtension + '"')
		shellCommand += ' ' + convertedFileName
		print('Sending the shell command:')
		print(shellCommand)
		commandResult = os.system(shellCommand)
		if commandResult != 0:
			print('The %s program could not convert the svg to the %s file format.' % ( svgViewer, fileExtension ) )
			print('Try installing the %s program or look for another one, like Image Magick which can be found at:' % svgViewer )
			print('http://www.imagemagick.org/script/index.php')
Example #4
0
	def execute(self):
		"Export the canvas as an svg file."
		svgFileName = archive.getFilePathWithUnderscoredBasename( self.fileName, self.suffix )
		boundingBox = self.canvas.bbox( settings.Tkinter.ALL ) # tuple (w, n, e, s)
		self.boxW = boundingBox[0]
		self.boxN = boundingBox[1]
		boxWidth = boundingBox[2] - self.boxW
		boxHeight = boundingBox[3] - self.boxN
		print('Exported svg file saved as ' + svgFileName )
		svgTemplateText = archive.getFileText(archive.getTemplatesPath('canvas_template.svg'))
		output = cStringIO.StringIO()
		lines = archive.getTextLines( svgTemplateText )
		firstWordTable = {}
		firstWordTable['height="999px"'] = '		height="%spx"' % int( round( boxHeight ) )
		firstWordTable['<!--replaceLineWith_coloredLines-->'] = self.getCanvasLinesOutput()
		firstWordTable['replaceLineWithTitle'] = archive.getSummarizedFileName( self.fileName )
		firstWordTable['width="999px"'] = '		width="%spx"' % int( round( boxWidth ) )
		for line in lines:
			parseLineReplace( firstWordTable, line, output )
		archive.writeFileText( svgFileName, output.getvalue() )
		fileExtension = self.fileExtension.value
		svgViewer = self.svgViewer.value
		if svgViewer == '':
			return
		if svgViewer == 'webbrowser':
			settings.openWebPage( svgFileName )
			return
		svgFilePath = '"' + os.path.normpath( svgFileName ) + '"' # " to send in file name with spaces
		shellCommand = svgViewer + ' ' + svgFilePath
		print('')
		if fileExtension == '':
			print('Sending the shell command:')
			print(shellCommand)
			commandResult = os.system(shellCommand)
			if commandResult != 0:
				print('It may be that the system could not find the %s program.' % svgViewer )
				print('If so, try installing the %s program or look for another svg viewer, like Netscape which can be found at:' % svgViewer )
				print('http://www.netscape.org/')
			return
		convertedFileName = archive.getFilePathWithUnderscoredBasename( svgFilePath, '.' + fileExtension + '"')
		shellCommand += ' ' + convertedFileName
		print('Sending the shell command:')
		print(shellCommand)
		commandResult = os.system(shellCommand)
		if commandResult != 0:
			print('The %s program could not convert the svg to the %s file format.' % ( svgViewer, fileExtension ) )
			print('Try installing the %s program or look for another one, like Image Magick which can be found at:' % svgViewer )
			print('http://www.imagemagick.org/script/index.php')
Example #5
0
 def getReplacedSVGTemplate(self,
                            fileName,
                            procedureName,
                            rotatedLoopLayers,
                            xmlElement=None):
     'Get the lines of text from the layer_template.svg file.'
     self.extent = self.cornerMaximum - self.cornerMinimum
     svgTemplateText = archive.getFileText(
         archive.getTemplatesPath('layer_template.svg'))
     self.xmlParser = XMLSimpleReader(fileName, None, svgTemplateText)
     self.svgElement = self.xmlParser.getRoot()
     svgElementDictionary = self.svgElement.attributeDictionary
     self.sliceDictionary = getSliceDictionary(self.svgElement)
     self.controlBoxHeight = float(self.sliceDictionary['controlBoxHeight'])
     self.controlBoxWidth = float(self.sliceDictionary['controlBoxWidth'])
     self.margin = float(self.sliceDictionary['margin'])
     self.marginTop = float(self.sliceDictionary['marginTop'])
     self.textHeight = float(self.sliceDictionary['textHeight'])
     self.unitScale = float(self.sliceDictionary['unitScale'])
     svgMinWidth = float(self.sliceDictionary['svgMinWidth'])
     self.controlBoxHeightMargin = self.controlBoxHeight + self.marginTop
     if not self.addLayerTemplateToSVG:
         self.svgElement.getXMLElementByID(
             'layerTextTemplate').removeFromIDNameParent()
         del self.svgElement.getXMLElementByID(
             'sliceElementTemplate').attributeDictionary['transform']
     self.graphicsXMLElement = self.svgElement.getXMLElementByID(
         'sliceElementTemplate')
     self.graphicsXMLElement.attributeDictionary['id'] = 'z:'
     self.addRotatedLoopLayersToOutput(rotatedLoopLayers)
     self.setMetadataNoscriptElement('layerThickness', 'Layer Thickness: ',
                                     self.layerThickness)
     self.setMetadataNoscriptElement('maxX', 'X: ', self.cornerMaximum.x)
     self.setMetadataNoscriptElement('minX', 'X: ', self.cornerMinimum.x)
     self.setMetadataNoscriptElement('maxY', 'Y: ', self.cornerMaximum.y)
     self.setMetadataNoscriptElement('minY', 'Y: ', self.cornerMinimum.y)
     self.setMetadataNoscriptElement('maxZ', 'Z: ', self.cornerMaximum.z)
     self.setMetadataNoscriptElement('minZ', 'Z: ', self.cornerMinimum.z)
     self.textHeight = float(self.sliceDictionary['textHeight'])
     controlTop = len(rotatedLoopLayers) * (
         self.margin + self.extent.y * self.unitScale +
         self.textHeight) + self.marginTop + self.textHeight
     self.svgElement.getFirstChildWithClassName(
         'title').text = os.path.basename(fileName) + ' - Slice Layers'
     svgElementDictionary['height'] = '%spx' % self.getRounded(
         max(controlTop, self.controlBoxHeightMargin))
     width = max(self.extent.x * self.unitScale, svgMinWidth)
     svgElementDictionary['width'] = '%spx' % self.getRounded(width)
     self.sliceDictionary['decimalPlacesCarried'] = str(
         self.decimalPlacesCarried)
     if self.perimeterWidth != None:
         self.sliceDictionary['perimeterWidth'] = self.getRounded(
             self.perimeterWidth)
     self.sliceDictionary['yAxisPointingUpward'] = 'true'
     self.sliceDictionary['procedureName'] = procedureName
     self.setDimensionTexts('dimX', 'X: ' + self.getRounded(self.extent.x))
     self.setDimensionTexts('dimY', 'Y: ' + self.getRounded(self.extent.y))
     self.setDimensionTexts('dimZ', 'Z: ' + self.getRounded(self.extent.z))
     self.setTexts('numberOfLayers',
                   'Number of Layers: %s' % len(rotatedLoopLayers))
     volume = 0.0
     for rotatedLoopLayer in rotatedLoopLayers:
         volume += euclidean.getAreaLoops(rotatedLoopLayer.loops)
     volume *= 0.001
     self.setTexts('volume', 'Volume: %s cm3' % self.getRounded(volume))
     if not self.addLayerTemplateToSVG:
         self.svgElement.getFirstChildWithClassName(
             'script').removeFromIDNameParent()
         self.svgElement.getXMLElementByID(
             'isoControlBox').removeFromIDNameParent()
         self.svgElement.getXMLElementByID(
             'layerControlBox').removeFromIDNameParent()
         self.svgElement.getXMLElementByID(
             'scrollControlBox').removeFromIDNameParent()
     self.graphicsXMLElement.removeFromIDNameParent()
     self.addOriginalAsComment(xmlElement)
     output = cStringIO.StringIO()
     output.write(self.xmlParser.beforeRoot)
     self.svgElement.addXML(0, output)
     return xml_simple_writer.getBeforeRootOutput(self.xmlParser)