12 file = open(fileName,
"r")
17 line = line.strip(
"\n")
18 if len(line.split(
"\""))==3:
19 contentName = line.split(
"\"")[1]
20 content = line.split(
"\"")[2].
split()
23 result[name] = dens,fractions
27 elif len(content) == 1:
29 fractions[
getMaterial(contentName,materialMap)] = float(content[0][1:])*0.01
32 result[name] = dens,fractions
34 for material
in result:
36 for fraction
in result[material][1]:
37 sum+= result[material][1][fraction]
38 if math.fabs(sum - 1.0) > maxDist:
39 raise Exception(
"Material Fractions do not add up to 100%: "+ material+
" "+str(sum))
45 file = open(fileName,
"r")
47 line = line.strip(
"\n")
48 content = line.split()
50 materialMap[content[0]] = content[1]
51 if material
in materialMap:
52 result = materialMap[material]+
":"+material
54 result =
"materials:"+material
59 file = open(fileName,
'r')
60 dom = xml.dom.minidom.parse(file)
67 for node
in rootNode.childNodes:
68 if node.nodeName == name:
71 raise Exception(
"Could not find: \""+name+
"\" in childnodes of the rootNode!")
77 for node
in rootNode.childNodes:
78 if node.nodeName == name
and node.nodeType == node.ELEMENT_NODE:
79 for i
in range(0,node.attributes.length):
80 if node.attributes.item(i).name ==
"name":
81 result[node.attributes.item(i).nodeValue] = node
86 output = dom.toprettyxml()
87 for line
in output.splitlines():
88 if not line.strip(
" \t") ==
"":
96 for i
in range(0,node.attributes.length):
98 result[node.attributes.item(i).name] = node.attributes.item(i).nodeValue
104 for node
in domina.childNodes:
105 print "NodeName:", node.nodeName,
106 if node.nodeType == node.ELEMENT_NODE:
107 print "Typ ELEMENT_NODE"
109 elif node.nodeType == node.TEXT_NODE:
110 print "Typ TEXT_NODE, Content: ", node.nodeValue.strip()
111 elif node.nodeType == node.COMMENT_NODE:
112 print "Typ COMMENT_NODE, "
118 matNodes =
getNodes(rootNode,
"CompositeMaterial")
119 for name
in matNodes:
120 print " "+name+
" (dens = "+
getAttributes(matNodes[name])[
"density"]+
")"
121 for fractionNode
in matNodes[name].childNodes:
122 if fractionNode.nodeName ==
"MaterialFraction":
124 for materialNode
in fractionNode.childNodes:
125 if materialNode.nodeName ==
"rMaterial":
128 print " |-- "+fractionString
140 newMaterial = doc.createElement(
"CompositeMaterial")
141 newMaterial.setAttribute(
"name",name)
142 newMaterial.setAttribute(
"density",density)
143 newMaterial.setAttribute(
"method",method)
144 newMaterial.setAttribute(
"symbol",symbol)
146 for fracMaterialName
in fractions:
147 fraction = doc.createElement(
"MaterialFraction")
148 fraction.setAttribute(
"fraction",str(fractions[fracMaterialName]))
149 newMaterial.appendChild(fraction)
150 fracMaterial = doc.createElement(
"rMaterial")
151 fracMaterial.setAttribute(
"name",fracMaterialName)
152 fraction.appendChild(fracMaterial)
154 exMaterials =
getNodes(rootNode,
"CompositeMaterial")
155 if name
in exMaterials:
156 rootNode.replaceChild(newMaterial,exMaterials[name])
158 rootNode.appendChild(newMaterial)
162 optParser = optparse.OptionParser()
163 optParser.add_option(
"-t",
"--titles", dest=
"titlesFile",
164 help=
"the .titles file to parse (as generated by mixture)", metavar=
"TITLES")
165 optParser.add_option(
"-x",
"--xml", dest=
"xmlFile",
166 help=
"the .xml file to parse (must be DDD complient)", metavar=
"XML")
167 optParser.add_option(
"-o",
"--output", dest=
"output",
168 help=
"the file to write the new materials into default: materialOutput.xml", metavar=
"XMLOUT")
169 optParser.add_option(
"-m",
"--materialMap", dest=
"materialMap",
170 help=
"file containing map of materials not defined in materials.xml. default: material.map", metavar=
"MMAP")
172 (options, args) = optParser.parse_args()
174 if options.titlesFile ==
None:
175 raise Exception(
"no .titles File given!")
176 if options.xmlFile ==
None:
178 if options.output ==
None:
179 options.output =
"materialOutput.xml"
180 if options.materialMap ==
None:
181 options.materialMap =
"material.map"
184 materials =
readFractions(options.titlesFile, options.materialMap)
192 for material
in materials:
197 outFile = open(options.output,
"w")
def createCompositeMaterial