1 package org.lcsim.geometry.compact.converter.lcdd.util;
2
3 import org.jdom.DataConversionException;
4 import org.jdom.Element;
5
6
7
8
9
10
11
12
13 public class Rotation extends RefElement
14 {
15
16
17
18
19 public Rotation(String name)
20 {
21 super("rotation",name);
22 setAttribute("x","0.0");
23 setAttribute("y","0.0");
24 setAttribute("z","0.0");
25 setAttribute("unit","radian");
26 }
27
28
29
30
31
32
33 public Rotation(String name, double rx, double ry, double rz)
34 {
35 super("rotation",name);
36 setAttribute("x",Double.toString(rx));
37 setAttribute("y",Double.toString(ry));
38 setAttribute("z",Double.toString(rz));
39 setAttribute("unit","radian");
40 }
41
42
43
44
45
46
47
48
49 public Rotation(String name, Element element)
50 {
51 super("rotation", name);
52
53 if (!element.getName().equals("rotation"))
54 throw new IllegalArgumentException("expect rotation element but got " + element.getAttributeValue("name"));
55
56 double x,y,z;
57 x = y = z = 0.;
58
59 try {
60
61 if (element.getAttribute("x") != null)
62 {
63 x = element.getAttribute("x").getDoubleValue();
64 }
65
66 if (element.getAttribute("y") != null)
67 {
68 y = element.getAttribute("y").getDoubleValue();
69 }
70
71 if (element.getAttribute("z") != null)
72 {
73 z = element.getAttribute("z").getDoubleValue();
74 }
75 }
76 catch (DataConversionException except)
77 {
78 throw new RuntimeException(except);
79 }
80
81 setX(x);
82 setY(y);
83 setZ(z);
84 }
85
86 public void setX(double d)
87 {
88 setAttribute("x",String.valueOf(d));
89 }
90 public void setY(double d)
91 {
92 setAttribute("y",String.valueOf(d));
93 }
94 public void setZ(double d)
95 {
96 setAttribute("z",String.valueOf(d));
97 }
98 }