Пример #1
0
	def getReplacedSVGTemplate(self, fileName, procedureName, rotatedLoopLayers, 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.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.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(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.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__()
Пример #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__()
Пример #3
0
	def parseSVG(self, fileName, svgText):
		"Parse SVG text and store the layers."
		self.fileName = fileName
		xmlParser = DocumentNode(fileName, svgText)
		self.documentElement = xmlParser.getDocumentElement()
		if self.documentElement == None:
			print('Warning, documentElement was None in parseSVG in SVGReader, so nothing will be done for:')
			print(fileName)
			return
		self.parseSVGByElementNode(self.documentElement)
Пример #4
0
	def parseSVG(self, fileName, svgText):
		"Parse SVG text and store the layers."
		self.fileName = fileName
		xmlParser = DocumentNode(fileName, svgText)
		self.documentElement = xmlParser.getDocumentElement()
		if self.documentElement == None:
			print('Warning, documentElement was None in parseSVG in SVGReader, so nothing will be done for:')
			print(fileName)
			return
		self.parseSVGByElementNode(self.documentElement)
Пример #5
0
def getCarving(fileName=''):
	"Get the carving for the xml file."
	xmlText = archive.getFileText(fileName)
	if xmlText == '':
		return None
	xmlParser = DocumentNode(fileName, xmlText)
	lowerLocalName = xmlParser.getDocumentElement().getNodeName().lower()
	pluginModule = archive.getModuleWithDirectoryPath( getPluginsDirectoryPath(), lowerLocalName )
	if pluginModule == None:
		return None
	return pluginModule.getCarvingFromParser( xmlParser )
Пример #6
0
def getCarving(fileName=''):
	"Get the carving for the xml file."
	xmlText = archive.getFileText(fileName)
	if xmlText == '':
		return None
	xmlParser = DocumentNode(fileName, xmlText)
	lowerLocalName = xmlParser.getDocumentElement().getNodeName().lower()
	pluginModule = archive.getModuleWithDirectoryPath( getPluginsDirectoryPath(), lowerLocalName )
	if pluginModule == None:
		return None
	return pluginModule.getCarvingFromParser( xmlParser )
Пример #7
0
	def __init__(self, fontFamily):
		"Initialize."
		self.fontFamily = fontFamily
		self.glyphDictionary = {}
		self.glyphElementNodeDictionary = {}
		self.missingGlyph = None
		fileName = os.path.join(getFontsDirectoryPath(), fontFamily + '.svg')
		documentElement = DocumentNode(fileName, archive.getFileText(fileName)).getDocumentElement()
		self.fontElementNode = documentElement.getFirstChildByLocalName('defs').getFirstChildByLocalName('font')
		self.fontFaceElementNode = self.fontElementNode.getFirstChildByLocalName('font-face')
		self.unitsPerEM = float(self.fontFaceElementNode.attributes['units-per-em'])
		glyphElementNodes = self.fontElementNode.getChildElementsByLocalName('glyph')
		for glyphElementNode in glyphElementNodes:
			self.glyphElementNodeDictionary[glyphElementNode.attributes['unicode']] = glyphElementNode
Пример #8
0
	def __init__(self, fontFamily):
		"Initialize."
		self.fontFamily = fontFamily
		self.glyphDictionary = {}
		self.glyphElementNodeDictionary = {}
		self.missingGlyph = None
		fileName = os.path.join(getFontsDirectoryPath(), fontFamily + '.svg')
		documentElement = DocumentNode(fileName, archive.getFileText(fileName)).getDocumentElement()
		self.fontElementNode = documentElement.getFirstChildByLocalName('defs').getFirstChildByLocalName('font')
		self.fontFaceElementNode = self.fontElementNode.getFirstChildByLocalName('font-face')
		self.unitsPerEM = float(self.fontFaceElementNode.attributes['units-per-em'])
		glyphElementNodes = self.fontElementNode.getChildElementsByLocalName('glyph')
		for glyphElementNode in glyphElementNodes:
			self.glyphElementNodeDictionary[glyphElementNode.attributes['unicode']] = glyphElementNode