View Javadoc

1   package org.lcsim.geometry.compact.converter.lcdd.util;
2   
3   import org.jdom.DataConversionException;
4   import org.jdom.Element;
5   
6   /**
7    *
8    * The LCDD rotation element.
9    *
10   * @author tonyj
11   * @author jeremym
12   */
13  public class Rotation extends RefElement
14  {   
15     /** 
16      * Creates an identity rotation called <code>name</code>.
17      * @param name The unique name of this rotation. 
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      * Creates an identity rotation called <code>name</code> with given
30      * rotations about the X, Y, and Z axes.
31      * @param name The unique name of this rotation. 
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      * Create a named rotation called <code>name</code> with XML element <code>element</code>.
44      * @throws IllegalArgumentException If element is not called "rotation".
45      * @throws RuntimeException If a {@link org.jdom.DataConversionException} is caught when converting.
46      * @param name The unique name of this rotation.
47      * @param element The XML element to be converted.  It must be called "rotation".
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  }