1 package org.lcsim.geometry.compact.converter.lcdd.util;
2
3 import org.jdom.Element;
4
5
6
7
8
9 public class PhysVol extends Element
10 {
11 private static int n = 0;
12
13 public PhysVol(Volume volume, Volume mother, Position p, Rotation r)
14 {
15 super("physvol");
16 Element volumeref = new Element("volumeref");
17 if (volume != null) volumeref.setAttribute("ref",volume.getRefName());
18 addContent(volumeref);
19
20 Element positionref = new Element("positionref");
21 positionref.setAttribute("ref","identity_pos");
22 addContent(positionref);
23
24 Element rotationref = new Element("rotationref");
25 rotationref.setAttribute("ref","identity_rot");
26 addContent(rotationref);
27
28 setPosition(p);
29
30 setRotation(r);
31
32 mother.addPhysVol(this);
33 }
34
35 public PhysVol()
36 {
37 this(null);
38 }
39 public PhysVol(Volume volume)
40 {
41 super("physvol");
42 Element volumeref = new Element("volumeref");
43 if (volume != null) volumeref.setAttribute("ref",volume.getRefName());
44 addContent(volumeref);
45
46 Element positionref = new Element("positionref");
47 positionref.setAttribute("ref","identity_pos");
48 addContent(positionref);
49
50 Element rotationref = new Element("rotationref");
51 rotationref.setAttribute("ref","identity_rot");
52 addContent(rotationref);
53 }
54 public void setVolume(Volume volume)
55 {
56 getChild("volumeref").setAttribute("ref",volume.getRefName());
57 }
58
59 public void setZ(double z)
60 {
61 Element positionref = getChild("positionref");
62 if (positionref != null) this.removeContent(positionref);
63 Position position = (Position) getChild("position");
64 if (position == null)
65 {
66 position = new Position("volpos_"+(n++));
67 addContent(1,position);
68 }
69 position.setZ(z);
70 }
71
72 public void setPosition(Position pos)
73 {
74 Element positionRef = getChild("positionref");
75 positionRef.setAttribute("ref", pos.getRefName());
76 }
77
78 public void setRotation(Rotation rot)
79 {
80 Element rotationRef = getChild("rotationref");
81 rotationRef.setAttribute("ref",rot.getRefName());
82 }
83 public void addPhysVolID(String name, int value)
84 {
85 Element element = new Element("physvolid");
86 element.setAttribute("field_name",name);
87 element.setAttribute("value",String.valueOf(value));
88 addContent(element);
89 }
90
91 public void addPhysVolID(PhysVolID id)
92 {
93 addContent(id);
94 }
95 }