9 CONFIGFILE =
"configuration.xml"
16 LOGFILE = open(
"log.txt",
'w')
17 LOGFILE.write(
"Logfile\n")
19 cmd =
"rm -rf " + outdir
39 def generic_solid(table,element,ns,postfix="",prefix="",docpost="[postfix]",docpre="[prefix],"):
40 if GENSOLID_ONCE.has_key(table) == 0:
41 GENSOLID_ONCE[table]=1
42 f = open(outdir+soldir+table+
".cdl",
'w')
46 for att
in element.attributes.values():
47 s = s + att.name +
','
52 file = open(outdir+soldir+table,
'a')
54 for att
in element.attributes.values():
55 if att.name ==
"name":
56 s = s +
qname(att.value,ns) +
','
58 s = s +
unitc(att.value).__str__() +
','
60 file.write(s[:-1]+
"\n")
67 sections = r.getElementsByTagName(
"ZSection")
72 z.append(
unitc(s.getAttribute(
"z")))
73 rmin.append(
unitc(s.getAttribute(
"rMin")))
74 rmax.append(
unitc(s.getAttribute(
"rMax")))
80 LOGFILE.write(r.tagName +
" " +
qname(r.getAttribute(
"name"),ns) +
" z values not z1 <= z2\n")
82 for i
in range(0,len(rmin)):
83 if rmin[i] == rmax[i]:
84 LOGFILE.write(r.tagName +
" " +
qname(r.getAttribute(
"name"),ns) +
" rmin = rmax\n")
85 if (i != 0)
and (i != (len(rmin)-1)):
86 LOGFILE.write(
" the one above might be a problem!\n")
87 print r.tagName +
" " +
qname(r.getAttribute(
"name"),ns) +
" rmin = rmax\n", i, range(0,len(rmin))
89 for i
in range(0,len(rmin)):
91 LOGFILE.write(r.tagName +
" " +
qname(r.getAttribute(
"name"),ns) +
" rmin > rmax\n")
94 for i
in range(0,len(rmin)):
100 if rmax[i+1] < rmin[i]:
102 if rmin[i+1] > rmax[i]:
105 LOGFILE.write(r.tagName +
" " +
qname(r.getAttribute(
"name"),ns) +
" discontinuity at " + i.__str__() +
"\n")
109 LOGFILE.write(r.tagName +
" " +
qname(r.getAttribute(
"name"),ns) +
" simpler solid possible\n")
113 name =
qname(r.getAttribute(
"name"),ns) +
","
114 if r.tagName ==
"Polycone":
120 for i
in r.getElementsByTagName(
"ZSection"):
121 prefix = count.__str__() +
","
122 generic_solid(
"ZSECTIONS.dat",i,ns,name,prefix,
"polycone_solid_name,polyhedra_solid_name,",
"sequence_no,")
125 for i
in r.getElementsByTagName(
"RZPoint"):
126 prefix = count.__str__() +
","
127 generic_solid(
"RZPOINTS.dat",i,ns,name,prefix,
"polycone_solid_name,polyhedra_solid_name,",
"sequence_no,")
135 for c
in r.getElementsByTagName(
"rSolid"):
136 s = s +
qname(c.getAttribute(
"name"),ns) +
","
137 t = r.getElementsByTagName(
"Translation")
139 s = s +
unitc(t[0].getAttribute(
"x")).__str__() +
","
140 s = s +
unitc(t[0].getAttribute(
"y")).__str__() +
","
141 s = s +
unitc(t[0].getAttribute(
"z")).__str__() +
","
144 r = r.getElementsByTagName(
"rRotation")
146 s = s +
qname(r[0].getAttribute(
"name"),ns) +
","
148 s = s +
"rotations:UNIT,"
157 s = s + r.tagName +
','
162 s = s + r.tagName +
','
167 s = s + r.tagName +
','
172 s = s + r.tagName +
','
177 s = s + r.tagName +
','
182 s = s + r.tagName +
','
188 if len(r.getElementsByTagName(
"ZSection"))>0:
191 s = s + r.tagName +
','
197 if len(r.getElementsByTagName(
"ZSection"))>0:
201 s = s + r.tagName +
','
205 s = s + r.tagName +
','
210 s = s + r.tagName +
','
215 s = s + r.tagName +
','
220 s = s + r.tagName +
','
222 generic_solid(
"BOOLEANSOLIDS.dat",r,ns,
"I,"+comp,
"",
"operation,solidA,solidB,x,y,z,rot")
226 s = s + r.tagName +
','
228 generic_solid(
"BOOLDEANSOLIDS.dat",r,ns,
"U,"+comp,
"",
"operation,solidA,solidB,x,y,z,rot")
232 s = s + r.tagName +
','
234 generic_solid(
"BOOLEANSOLIDS.dat",r,ns,
"S,"+comp,
"",
"operation,solidA,solidB,x,y,z,rot")
240 'SubtractionSolid':subtractionsolid_action,
241 'UnionSolid':unionsolid_action,
242 'IntersectionSolid':intersectionsolid_action,
243 'Trapezoid':trapezoid_action,
244 'PseudoTrap':pseudotrap_action,
246 'Polycone':polycone_action,
247 'Polyhedra':polyhedra_action,
251 'ShapelessSolid':shapelesssolid_action,
252 'ReflectionSolid':reflectionsolid_action,
256 rad_to_deg = math.pi/180.
257 UNITS = {
u'deg':rad_to_deg,
277 x = string.split(s,
'*')
281 return string.atof(x[0])*UNITS[x[1]]
283 print "ERROR IN unitc: >" + s +
"<"
290 doc = xml.dom.minidom.parse(open(CONFIGFILE,
'r'))
291 file_elements = doc.getElementsByTagName("File")
292 print `file_elements`
293 for file_element
in file_elements:
294 file_name = file_element.getAttribute(
"name")
295 url_name = file_element.getAttribute(
"url")
296 print url_name + file_name
297 path = url_name+file_name
298 ns = string.split(path,
'/')[-1][:-4]
299 result.append([url_name+file_name,ns])
308 if r.tagName==
"ReflectionRotation":
316 if string.find(s,
':') == -1:
321 file = open(outdir+
"MATERIALFRACTIONS.dat",
'a')
322 fracs = e.getElementsByTagName(
"MaterialFraction")
324 fm = frac.getAttribute(
"fraction")
325 mat =
qname(frac.getElementsByTagName(
"rMaterial")[0].getAttribute(
"name"),ns)
326 result =
"" +
qname(e.getAttribute(
"name"),ns) +
',' + mat +
',' + fm +
"\n"
332 name_cat = string.split(s,
',')
333 CATEGORIES[name_cat[1]] =
''
335 nodelist = logp.childNodes
339 for i
in range(0,l-1):
340 if string.find(nodelist[i].nodeName,
"Ma") != -1:
341 mat =
qname(nodelist[i].getAttribute(
"name"),ns)
342 if string.find(nodelist[i].nodeName,
"So") != -1:
343 sol =
qname(nodelist[i].getAttribute(
"name"),ns)
344 result = name_cat[0] +
',' + sol +
',' + mat +
',' + name_cat[1] +
','
348 PPCOUNT[0] = PPCOUNT[0] + 1
349 nodelist = posp.childNodes
355 for i
in range(0,l-1):
356 nn = nodelist[i].nodeName
357 if string.find(nn,
'Pa') != -1:
358 parent =
qname(nodelist[i].getAttribute(
"name"),ns)
359 if string.find(nn,
'Child') != -1:
360 child =
qname(nodelist[i].getAttribute(
"name"),ns)
361 if string.find(nn,
'Tra') != -1:
362 tra.append(
unitc(nodelist[i].getAttribute(
"x")))
363 tra.append(
unitc(nodelist[i].getAttribute(
"y")))
364 tra.append(
unitc(nodelist[i].getAttribute(
"z")))
365 if string.find(nn,
'Rot') != -1:
366 rot =
qname(nodelist[i].getAttribute(
"name"),ns)
367 result = PPCOUNT[0].__str__() +
',' + s
369 result = result + tra[0].__str__() +
',' + tra[1].__str__() +
',' + tra[2].__str__() +
','
371 result = result +
",,,"
372 result = result + rot +
',' + parent +
',' + child +
','
378 document_path = doc[0]
380 print "Processing document: " + doc[0] +
" ns=" + doc[1]
381 doc = xml.dom.minidom.parse(open(doc[0],
'r'));
387 [
'MATERIALS.dat', [
'ElementaryMaterial',
'CompositeMaterial'] ,
388 [
':name',
'density'] ,0 ],
390 [
'ELEMENTARYMATERIALS.dat', [
'ElementaryMaterial'],
391 [
':name',
';atomicNumber',
'atomicWeight',
';symbol' ], 0 ],
393 [
'COMPOSITEMATERIALS.dat', [
'CompositeMaterial'],
394 [
':name',
';method' ], comp_action ],
396 [
'ROTATIONS.dat', [
'Rotation',
'ReflectionRotation'],
397 [
':name',
'thetaX',
'phiX',
'thetaY',
'phiY',
'thetaZ',
'phiZ'], rot_action ],
399 [
'LOGICALPARTS.dat', [
'LogicalPart'],
400 [
':name',
';category',
'itemid' ], log_action ],
402 [
'POSPARTS.dat', [
'PosPart'],
403 [
'copyNumber'], pos_action ],
405 [
'SOLIDS.dat', SOLIDTYPES.keys(),
406 [
':name'], SOLIDTYPES.values() ]
412 filename=outdir+tablename
413 file = open(outdir+tablename,
'a')
419 elCount = elCount + 1
420 els = doc.getElementsByTagName(el)
423 for at
in attributes:
432 attr = e.getAttribute(at)
434 attr =
qname(attr,namespace)
441 s = s + attr.__str__() +
","
449 s = action[elCount](e,s,namespace)
451 file.write(s[:len(s)-1]+
"\n")
454 file = open(outdir+
"CATEGORIES.dat",
'w')
455 for i
in CATEGORIES.keys():
def subtractionsolid_action
def rot_action
other actions
def generic_solid
Solid actions.
def reflectionsolid_action
def intersectionsolid_action
def shapelesssolid_action