def processXMLElementByDerivation(derivation, xmlElement): 'Process the xml element by derivation.' if derivation == None: derivation = ArrayDerivation(xmlElement) if derivation.target == None: print('Warning, array could not get target for:') print(xmlElement) return if len(derivation.paths) < 1: print('Warning, array could not get paths for:') print(xmlElement) return groupDictionaryCopy = xmlElement.attributeDictionary.copy() euclidean.removeElementsFromDictionary( groupDictionaryCopy, ['closed', 'paths', 'target', 'track', 'vertexes']) evaluate.removeIdentifiersFromDictionary(groupDictionaryCopy) targetMatrix = matrix.getBranchMatrixSetXMLElement(derivation.target) xmlElement.className = 'group' totalIndex = 0 for path in derivation.paths: addPathToGroup(derivation, groupDictionaryCopy, path, targetMatrix, totalIndex) xmlElement.getXMLProcessor().processXMLElement(xmlElement) return
def getCumulativeVector3Remove(defaultVector3, prefix, xmlElement): """Get cumulative vector3 and delete the prefixed attributes.""" if prefix == '': defaultVector3.x = evaluate.getEvaluatedFloat(defaultVector3.x, 'x', xmlElement) defaultVector3.y = evaluate.getEvaluatedFloat(defaultVector3.y, 'y', xmlElement) defaultVector3.z = evaluate.getEvaluatedFloat(defaultVector3.z, 'z', xmlElement) euclidean.removeElementsFromDictionary(xmlElement.attributeDictionary, ['x', 'y', 'z']) prefix = 'cartesian' defaultVector3 = evaluate.getVector3ByPrefix(defaultVector3, prefix, xmlElement) euclidean.removePrefixFromDictionary(xmlElement.attributeDictionary, prefix) return defaultVector3
def addXML(self, depth, output): 'Add xml for this object.' attributeCopy = {} if self.xmlElement != None: attributeCopy = evaluate.getEvaluatedDictionaryByCopyKeys(['paths', 'target', 'vertexes'], self.xmlElement) euclidean.removeElementsFromDictionary(attributeCopy, matrix.getKeysM()) euclidean.removeTrueFromDictionary(attributeCopy, 'visible') innerOutput = StringIO.StringIO() self.addXMLInnerSection(depth + 1, innerOutput) self.addXMLArchivableObjects(depth + 1, innerOutput) xml_simple_writer.addBeginEndInnerXMLTag(attributeCopy, depth, innerOutput.getvalue(), self.getXMLLocalName(), output)
def getCumulativeVector3Remove(defaultVector3, elementNode, prefix): 'Get cumulative vector3 and delete the prefixed attributes.' if prefix == '': defaultVector3.x = evaluate.getEvaluatedFloat(defaultVector3.x, elementNode, 'x') defaultVector3.y = evaluate.getEvaluatedFloat(defaultVector3.y, elementNode, 'y') defaultVector3.z = evaluate.getEvaluatedFloat(defaultVector3.z, elementNode, 'z') euclidean.removeElementsFromDictionary(elementNode.attributes, ['x', 'y', 'z']) prefix = 'cartesian' defaultVector3 = evaluate.getVector3ByPrefix(defaultVector3, elementNode, prefix) euclidean.removePrefixFromDictionary(elementNode.attributes, prefix) return defaultVector3
def addXML(self, depth, output): 'Add xml for this object.' attributeCopy = {} if self.xmlElement != None: attributeCopy = evaluate.getEvaluatedDictionaryByCopyKeys(['paths', 'target', 'vertexes'], self.xmlElement) euclidean.removeElementsFromDictionary(attributeCopy, matrix.getKeysM()) euclidean.removeTrueFromDictionary(attributeCopy, 'visible') innerOutput = cStringIO.StringIO() self.addXMLInnerSection(depth + 1, innerOutput) self.addXMLArchivableObjects(depth + 1, innerOutput) xml_simple_writer.addBeginEndInnerXMLTag(attributeCopy, self.getXMLClassName(), depth, innerOutput.getvalue(), output)
def getCarvingFromParser( xmlParser ): "Get the carving for the parser." booleanGeometry = boolean_geometry.BooleanGeometry() artOfIllusionElement = xmlParser.getRoot() artOfIllusionElement.xmlObject = booleanGeometry euclidean.removeElementsFromDictionary( artOfIllusionElement.attributeDictionary, ['fileversion', 'xmlns:bf'] ) sceneElement = artOfIllusionElement.getFirstChildByLocalName('Scene') xmlElements = sceneElement.getFirstChildByLocalName('objects').getChildNodesByLocalName('bf:Elem') for xmlElement in xmlElements: processXMLElement( booleanGeometry.archivableObjects, artOfIllusionElement, xmlElement ) return booleanGeometry
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)
def getCarvingFromParser( xmlParser ): "Get the carving for the parser." booleanGeometry = boolean_geometry.BooleanGeometry() artOfIllusionElement = xmlParser.getDocumentElement() artOfIllusionElement.xmlObject = booleanGeometry euclidean.removeElementsFromDictionary( artOfIllusionElement.attributes, ['fileversion', 'xmlns:bf'] ) sceneElement = artOfIllusionElement.getFirstChildByLocalName('Scene') elementNodes = sceneElement.getFirstChildByLocalName('objects').getChildElementsByLocalName('bf:Elem') for elementNode in elementNodes: processAppendElementNode(booleanGeometry.archivableObjects, elementNode, artOfIllusionElement) return booleanGeometry
def getTetragridMatrix(elementNode, prefix, tetragrid): 'Get the tetragrid from the elementNode matrix value.' matrixKey = prefix + 'matrix' evaluatedDictionary = evaluate.getEvaluatedDictionaryByEvaluationKeys(elementNode, [matrixKey]) if len(evaluatedDictionary.keys()) < 1: return tetragrid value = evaluatedDictionary[matrixKey] if value == None or value == 'None': print('Warning, value in getTetragridMatrix in matrix is None for matrixKey for dictionary:') print(matrixKey) print(evaluatedDictionary) else: tetragrid = getIdentityTetragrid(tetragrid) for rowIndex, row in enumerate(value): for elementIndex, element in enumerate(row): tetragrid[rowIndex][elementIndex] = element euclidean.removeElementsFromDictionary(elementNode.attributes, [matrixKey]) return tetragrid
def getTetragridR(elementNode, prefix, tetragrid): 'Get the tetragrid from the elementNode letter r values.' rowKeys = 'Pr1 Pr2 Pr3 Pr4'.replace('P', prefix).split() evaluatedDictionary = evaluate.getEvaluatedDictionaryByEvaluationKeys(elementNode, rowKeys) if len(evaluatedDictionary.keys()) < 1: return tetragrid for rowKeyIndex, rowKey in enumerate(rowKeys): if rowKey in evaluatedDictionary: value = evaluatedDictionary[rowKey] if value == None or value == 'None': print('Warning, value in getTetragridR in matrix is None for rowKey for dictionary:') print(rowKey) print(evaluatedDictionary) else: tetragrid = getIdentityTetragrid(tetragrid) for elementIndex, element in enumerate(value): tetragrid[rowKeyIndex][elementIndex] = element euclidean.removeElementsFromDictionary(elementNode.attributes, rowKeys) return tetragrid
def getTetragridC(elementNode, prefix, tetragrid): 'Get the matrix Tetragrid from the elementNode letter c values.' columnKeys = 'Pc1 Pc2 Pc3 Pc4'.replace('P', prefix).split() evaluatedDictionary = evaluate.getEvaluatedDictionaryByEvaluationKeys(elementNode, columnKeys) if len(evaluatedDictionary.keys()) < 1: return tetragrid for columnKeyIndex, columnKey in enumerate(columnKeys): if columnKey in evaluatedDictionary: value = evaluatedDictionary[columnKey] if value == None or value == 'None': print('Warning, value in getTetragridC in matrix is None for columnKey for dictionary:') print(columnKey) print(evaluatedDictionary) else: tetragrid = getIdentityTetragrid(tetragrid) for elementIndex, element in enumerate(value): tetragrid[elementIndex][columnKeyIndex] = element euclidean.removeElementsFromDictionary(elementNode.attributes, columnKeys) return tetragrid
def getTetragridM(elementNode, prefix, tetragrid): 'Get the tetragrid from the elementNode letter m values.' keysM = getKeysM(prefix) evaluatedDictionary = evaluate.getEvaluatedDictionaryByEvaluationKeys(elementNode, keysM) if len(evaluatedDictionary.keys()) < 1: return tetragrid for row in xrange(4): for column in xrange(4): key = getKeyM(row, column, prefix) if key in evaluatedDictionary: value = evaluatedDictionary[key] if value == None or value == 'None': print('Warning, value in getTetragridM in matrix is None for key for dictionary:') print(key) print(evaluatedDictionary) else: tetragrid = getIdentityTetragrid(tetragrid) tetragrid[row][column] = float(value) euclidean.removeElementsFromDictionary(elementNode.attributes, keysM) return tetragrid
def getTetragridA(prefix, tetragrid, xmlElement): 'Get the tetragrid from the xmlElement letter a values.' keysA = getKeysA(prefix) evaluatedDictionary = evaluate.getEvaluatedDictionaryByEvaluationKeys(keysA, xmlElement) if len(evaluatedDictionary.keys()) < 1: return tetragrid for row in xrange(4): for column in xrange(4): key = getKeyA(row, column, prefix) if key in evaluatedDictionary: value = evaluatedDictionary[key] if value == None or value == 'None': print('Warning, value in getTetragridA in matrix is None for key for dictionary:') print(key) print(evaluatedDictionary) else: tetragrid = getIdentityTetragrid(tetragrid) tetragrid[row][column] = float(value) euclidean.removeElementsFromDictionary(xmlElement.attributeDictionary, keysA) return tetragrid
def processXMLElement(xmlElement): 'Process the xml element.' target = evaluate.getXMLElementByKey('target', xmlElement) if target == None: print('Warning, copy could not get target.') return del xmlElement.attributeDictionary['target'] copyMatrix = matrix.getFromObjectOrXMLElement(xmlElement) targetMatrix = matrix.getFromObjectOrXMLElement(target) targetDictionaryCopy = target.attributeDictionary.copy() euclidean.removeElementsFromDictionary(targetDictionaryCopy, ['id', 'name']) targetDictionaryCopy.update(xmlElement.attributeDictionary) xmlElement.attributeDictionary = targetDictionaryCopy euclidean.removeTrueFromDictionary(xmlElement.attributeDictionary, 'visible') xmlElement.className = target.className target.copyXMLChildren(xmlElement.getIDSuffix(), xmlElement) xmlElement.getXMLProcessor().processXMLElement(xmlElement) if copyMatrix != None and targetMatrix != None: xmlElement.object.matrix4X4 = copyMatrix.getSelfTimesOther( targetMatrix.tetragrid)
def processElementNodeByDerivation(derivation, elementNode): 'Process the xml element by derivation.' if derivation is None: derivation = ArrayDerivation(elementNode) if derivation.target is None: print('Warning, array could not get target for:') print(elementNode) return if len(derivation.paths) < 1: print('Warning, array could not get paths for:') print(elementNode) return groupDictionaryCopy = elementNode.attributes.copy() euclidean.removeElementsFromDictionary( groupDictionaryCopy, ['closed', 'paths', 'target', 'track', 'vertexes']) evaluate.removeIdentifiersFromDictionary(groupDictionaryCopy) targetMatrix = matrix.getBranchMatrixSetElementNode(derivation.target) elementNode.localName = 'group' totalIndex = 0 for path in derivation.paths: addPathToGroup(derivation, groupDictionaryCopy, path, targetMatrix, totalIndex) elementNode.getXMLProcessor().processElementNode(elementNode)
def removeListArtOfIllusionFromDictionary(dictionary, scrubKeys): "Remove the list and art of illusion keys from the dictionary." euclidean.removeElementsFromDictionary(dictionary, ['bf:id', 'bf:type']) euclidean.removeElementsFromDictionary(dictionary, scrubKeys)