Example #1
0
def convertXMLElementRenameByPaths(geometryOutput, xmlElement):
    'Convert the xml element to a path xml element and add paths.'
    createLinkPath(xmlElement)
    for geometryOutputChild in geometryOutput:
        pathElement = xml_simple_reader.XMLElement()
        pathElement.setParentAddToChildNodes(xmlElement)
        convertXMLElementByPath(geometryOutputChild, pathElement)
Example #2
0
def convertXMLElementRenameByPaths(geometryOutput, xmlElement):
    "Convert the xml element to a path xml element and add paths."
    xmlElement.className = 'path'
    for geometryOutputChild in geometryOutput:
        pathElement = xml_simple_reader.XMLElement()
        pathElement.setParentAddToChildren(xmlElement)
        convertXMLElementRename(geometryOutputChild, pathElement)
Example #3
0
 def addOriginalAsComment(self, xmlElement):
     'Add original xmlElement as a comment.'
     if xmlElement == None:
         return
     if xmlElement.localName == 'comment':
         xmlElement.setParentAddToChildNodes(self.svgElement)
         return
     commentElement = xml_simple_reader.XMLElement()
     commentElement.localName = 'comment'
     xmlElementOutput = cStringIO.StringIO()
     xmlElement.addXML(0, xmlElementOutput)
     textLines = archive.getTextLines(xmlElementOutput.getvalue())
     commentElementOutput = cStringIO.StringIO()
     isComment = False
     for textLine in textLines:
         lineStripped = textLine.strip()
         if lineStripped[:len('<!--')] == '<!--':
             isComment = True
         if not isComment:
             if len(textLine) > 0:
                 commentElementOutput.write(textLine + '\n')
         if '-->' in lineStripped:
             isComment = False
     commentElement.text = '%s%s-->\n' % (globalOriginalTextString,
                                          commentElementOutput.getvalue())
     commentElement.setParentAddToChildNodes(self.svgElement)
Example #4
0
def addGeometryList(faces, xmlElement):
    "Add vertex elements to an xml element."
    for face in faces:
        faceElement = xml_simple_reader.XMLElement()
        face.addToAttributeDictionary(faceElement.attributeDictionary)
        faceElement.className = 'face'
        faceElement.parent = xmlElement
        xmlElement.children.append(faceElement)
Example #5
0
def processXMLElementByDerivation(derivation, xmlElement):
	'Process the xml element by derivation.'
	if derivation == None:
		derivation = DisjoinDerivation(xmlElement)
	targetXMLElement = derivation.targetXMLElement
	if targetXMLElement == None:
		print('Warning, disjoin could not get target for:')
		print(xmlElement)
		return
	xmlObject = targetXMLElement.xmlObject
	if xmlObject == None:
		print('Warning, processXMLElementByDerivation in disjoin could not get xmlObject for:')
		print(targetXMLElement)
		print(derivation.xmlElement)
		return
	transformedVertexes = xmlObject.getTransformedVertexes()
	if len(transformedVertexes) < 1:
		print('Warning, transformedVertexes is zero in processXMLElementByDerivation in disjoin for:')
		print(xmlObject)
		print(targetXMLElement)
		print(derivation.xmlElement)
		return
	xmlElement.localName = 'group'
	xmlElement.getXMLProcessor().processXMLElement(xmlElement)
	matrix.getBranchMatrixSetXMLElement(targetXMLElement)
	targetChainMatrix = matrix.Matrix(xmlObject.getMatrixChainTetragrid())
	minimumZ = boolean_geometry.getMinimumZ(xmlObject)
	z = minimumZ + 0.5 * derivation.sheetThickness
	zoneArrangement = triangle_mesh.ZoneArrangement(derivation.layerThickness, transformedVertexes)
	oldVisibleString = targetXMLElement.attributeDictionary['visible']
	targetXMLElement.attributeDictionary['visible'] = True
	loops = boolean_geometry.getEmptyZLoops([xmlObject], derivation.importRadius, False, z, zoneArrangement)
	targetXMLElement.attributeDictionary['visible'] = oldVisibleString
	vector3Loops = euclidean.getVector3Paths(loops, z)
	pathElement = getLinkedXMLElement('_sheet', xmlElement, targetXMLElement)
	path.convertXMLElement(vector3Loops, pathElement)
	targetOutput = xmlObject.getGeometryOutput()
	differenceElement = getLinkedXMLElement('_solid', xmlElement, targetXMLElement)
	targetElementCopy = targetXMLElement.getCopy('_positive', differenceElement)
	targetElementCopy.attributeDictionary['visible'] = True
	targetElementCopy.attributeDictionary.update(targetChainMatrix.getAttributeDictionary('matrix.'))
	complexMaximum = euclidean.getMaximumByVector3Path(transformedVertexes).dropAxis()
	complexMinimum = euclidean.getMinimumByVector3Path(transformedVertexes).dropAxis()
	centerComplex = 0.5 * (complexMaximum + complexMinimum)
	centerVector3 = Vector3(centerComplex.real, centerComplex.imag, minimumZ)
	slightlyMoreThanHalfExtent = 0.501 * (complexMaximum - complexMinimum)
	inradius = Vector3(slightlyMoreThanHalfExtent.real, slightlyMoreThanHalfExtent.imag, derivation.sheetThickness)
	cubeElement = xml_simple_reader.XMLElement()
	cubeElement.attributeDictionary['inradius'] = str(inradius)
	if not centerVector3.getIsDefault():
		cubeElement.attributeDictionary['translate.'] = str(centerVector3)
	cubeElement.localName = 'cube'
	cubeElement.importName = differenceElement.importName
	cubeElement.setParentAddToChildNodes(differenceElement)
	difference.processXMLElement(differenceElement)
Example #6
0
def processXMLElementByDerivation(derivation, xmlElement):
    'Process the xml element by derivation.'
    if derivation == None:
        derivation = ImportDerivation(xmlElement)
    if derivation.fileName == None:
        return
    parserFileName = xmlElement.getParser().fileName
    absoluteFileName = archive.getAbsoluteFolderPath(parserFileName,
                                                     derivation.fileName)
    if 'models/' not in absoluteFileName:
        print(
            'Warning, models/ was not in the absolute file path, so for security nothing will be done for:'
        )
        print(xmlElement)
        print('For which the absolute file path is:')
        print(absoluteFileName)
        print(
            'The import tool can only read a file which has models/ in the file path.'
        )
        print(
            'To import the file, move the file into a folder called model/ or a subfolder which is inside the model folder tree.'
        )
        return
    xmlText = ''
    if derivation.fileName.endswith('.xml'):
        xmlText = archive.getFileText(absoluteFileName)
    else:
        xmlText = getXMLFromCarvingFileName(absoluteFileName)
    print('The import tool is opening the file:')
    print(absoluteFileName)
    if xmlText == '':
        print(
            'The file %s could not be found by processXMLElement in import.' %
            derivation.fileName)
        return
    if derivation.importName == None:
        xmlElement.importName = archive.getUntilDot(derivation.fileName)
        if derivation.basename:
            xmlElement.importName = os.path.basename(xmlElement.importName)
        xmlElement.attributeDictionary['_importName'] = xmlElement.importName
    else:
        xmlElement.importName = derivation.importName
    importXMLElement = xml_simple_reader.XMLElement()
    xml_simple_reader.XMLSimpleReader(parserFileName, importXMLElement,
                                      xmlText)
    for child in importXMLElement.children:
        child.copyXMLChildren('', xmlElement)
        evaluate.removeIdentifiersFromDictionary(child.attributeDictionary)
        xmlElement.attributeDictionary.update(child.attributeDictionary)
        if derivation.overwriteRoot:
            xmlElement.getRoot().attributeDictionary.update(
                child.attributeDictionary)
    xmlElement.className = 'group'
    evaluate.processArchivable(group.Group, xmlElement)
Example #7
0
def processXMLElement(xmlElement):
    'Process the xml element.'
    fileName = evaluate.getEvaluatedValue('file', xmlElement)
    if fileName == None:
        return
    parserFileName = xmlElement.getRoot().parser.fileName
    absoluteFileName = archive.getAbsoluteFolderPath(parserFileName, fileName)
    absoluteFileName = os.path.abspath(absoluteFileName)
    if 'models/' not in absoluteFileName:
        print(
            'Warning, models/ was not in the absolute file path, so for security nothing will be done for:'
        )
        print(xmlElement)
        print('For which the absolute file path is:')
        print(absoluteFileName)
        print(
            'The import tool can only read a file which has models/ in the file path.'
        )
        print(
            'To import the file, move the file into a folder called model/ or a subfolder which is inside the model folder tree.'
        )
        return
    xmlText = ''
    if fileName.endswith('.xml'):
        xmlText = archive.getFileText(absoluteFileName)
    else:
        xmlText = getXMLFromCarvingFileName(absoluteFileName)
    print('The import tool is opening the file:')
    print(absoluteFileName)
    if xmlText == '':
        print(
            'The file %s could not be found by processXMLElement in import.' %
            fileName)
        return
    if '_importName' in xmlElement.attributeDictionary:
        xmlElement.importName = xmlElement.attributeDictionary['_importName']
    else:
        xmlElement.importName = archive.getUntilDot(fileName)
        if evaluate.getEvaluatedBooleanDefault(True, 'basename', xmlElement):
            xmlElement.importName = os.path.basename(xmlElement.importName)
        xmlElement.attributeDictionary['_importName'] = xmlElement.importName
    importXMLElement = xml_simple_reader.XMLElement()
    xml_simple_reader.XMLSimpleReader(parserFileName, importXMLElement,
                                      xmlText)
    for child in importXMLElement.children:
        child.copyXMLChildren('', xmlElement)
        euclidean.removeElementsFromDictionary(child.attributeDictionary,
                                               ['id', 'name'])
        xmlElement.attributeDictionary.update(child.attributeDictionary)
        if evaluate.getEvaluatedBooleanDefault(False, 'overwriteRoot',
                                               xmlElement):
            xmlElement.getRoot().attributeDictionary.update(
                child.attributeDictionary)
    group.processShape(group.Group, xmlElement)
Example #8
0
def getLinkedXMLElement(idSuffix, parentNode, target):
	'Get xmlElement with identifiers, importName and parentNode.'
	linkedXMLElement = xml_simple_reader.XMLElement()
	linkedXMLElement.importName = parentNode.importName
	euclidean.overwriteDictionary(target.attributeDictionary, ['id', 'name', 'quantity'], linkedXMLElement.attributeDictionary)
	linkedXMLElement.addSuffixToID(idSuffix)
	tagKeys = target.getTagKeys()
	tagKeys.append('disjoin')
	tagKeys.sort()
	tags = ', '.join(tagKeys)
	linkedXMLElement.attributeDictionary['tags'] = tags
	linkedXMLElement.setParentAddToChildNodes(parentNode)
	linkedXMLElement.addToIdentifierDictionaryIFIdentifierExists()
	return linkedXMLElement
Example #9
0
def getUnboundVertexElement(vertex):
    "Add vertex element to an xml element."
    vertexElement = xml_simple_reader.XMLElement()
    addVertexToAttributeDictionary(vertexElement.attributeDictionary, vertex)
    vertexElement.localName = 'vertex'
    return vertexElement
Example #10
0
 def createChildren(self, geometryOutput, parent):
     "Create children for the parent."
     for geometryOutputChild in geometryOutput:
         child = xml_simple_reader.XMLElement()
         child.setParentAddToChildren(parent)
         self.convertXMLElement(geometryOutputChild, child)
Example #11
0
	def createChildNodes( self, geometryOutput, parentNode ):
		"Create childNodes for the parentNode."
		for geometryOutputChild in geometryOutput:
			childNode = xml_simple_reader.XMLElement()
			childNode.setParentAddToChildNodes( parentNode )
			self.convertXMLElement(geometryOutputChild, childNode)