create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / preset / xml / TransitionDTO.java
1
2 package net.sf.openrocket.preset.xml;
3
4 import net.sf.openrocket.preset.ComponentPreset;
5 import net.sf.openrocket.preset.ComponentPresetFactory;
6 import net.sf.openrocket.preset.InvalidComponentPresetException;
7 import net.sf.openrocket.preset.TypedPropertyMap;
8
9 import javax.xml.bind.annotation.XmlAccessType;
10 import javax.xml.bind.annotation.XmlAccessorType;
11 import javax.xml.bind.annotation.XmlElement;
12 import javax.xml.bind.annotation.XmlRootElement;
13 import java.util.List;
14
15 /**
16  * Transition preset XML handler.
17  */
18 @XmlRootElement(name = "Transition")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class TransitionDTO extends BaseComponentDTO {
21
22     @XmlElement(name = "Shape")
23     private ShapeDTO shape;
24
25     @XmlElement(name = "ForeOutsideDiameter")
26     private AnnotatedLengthDTO foreOutsideDiameter;
27     @XmlElement(name = "ForeShoulderDiameter")
28     private AnnotatedLengthDTO foreShoulderDiameter;
29     @XmlElement(name = "ForeShoulderLength")
30     private AnnotatedLengthDTO foreShoulderLength;
31
32     @XmlElement(name = "AftOutsideDiameter")
33     private AnnotatedLengthDTO aftOutsideDiameter;
34     @XmlElement(name = "AftShoulderDiameter")
35     private AnnotatedLengthDTO aftShoulderDiameter;
36     @XmlElement(name = "AftShoulderLength")
37     private AnnotatedLengthDTO aftShoulderLength;
38
39     @XmlElement(name = "Length")
40     private AnnotatedLengthDTO length;
41     
42     @XmlElement(name = "Thickness")
43     private AnnotatedLengthDTO thickness;
44
45
46     /**
47      * Default constructor.
48      */
49     public TransitionDTO() {
50     }
51
52     /**
53      * Most-useful constructor that maps a Transition preset to a TransitionDTO.
54      *
55      * @param thePreset  the preset
56      *
57      * @throws net.sf.openrocket.util.BugException thrown if the expected transition keys are not in the preset
58      */
59     public TransitionDTO(final ComponentPreset thePreset) {
60         super(thePreset);
61         setShape(ShapeDTO.asDTO(thePreset.get(ComponentPreset.SHAPE)));
62         setForeOutsideDiameter(thePreset.get(ComponentPreset.FORE_OUTER_DIAMETER));
63         setForeShoulderDiameter(thePreset.get(ComponentPreset.FORE_SHOULDER_DIAMETER));
64         setForeShoulderLength(thePreset.get(ComponentPreset.FORE_SHOULDER_LENGTH));
65         setAftOutsideDiameter(thePreset.get(ComponentPreset.AFT_OUTER_DIAMETER));
66         setAftShoulderDiameter(thePreset.get(ComponentPreset.AFT_SHOULDER_DIAMETER));
67         setAftShoulderLength(thePreset.get(ComponentPreset.AFT_SHOULDER_LENGTH));
68         setLength(thePreset.get(ComponentPreset.LENGTH));
69         if ( thePreset.has(ComponentPreset.THICKNESS)) {
70                 setThickness(thePreset.get(ComponentPreset.THICKNESS));
71         }
72     }
73
74     public ShapeDTO getShape() {
75         return shape;
76     }
77
78     public void setShape(final ShapeDTO theShape) {
79         shape = theShape;
80     }
81
82     public double getForeOutsideDiameter() {
83         return foreOutsideDiameter.getValue();
84     }
85
86     public void setForeOutsideDiameter(final AnnotatedLengthDTO theForeOutsideDiameter) {
87         foreOutsideDiameter = theForeOutsideDiameter;
88     }
89
90     public void setForeOutsideDiameter(final double theForeOutsideDiameter) {
91         foreOutsideDiameter = new AnnotatedLengthDTO(theForeOutsideDiameter);
92     }
93
94     public double getForeShoulderDiameter() {
95         return foreShoulderDiameter.getValue();
96     }
97
98     public void setForeShoulderDiameter(final AnnotatedLengthDTO theForeShoulderDiameter) {
99         foreShoulderDiameter = theForeShoulderDiameter;
100     }
101
102     public void setForeShoulderDiameter(final double theForeShoulderDiameter) {
103         foreShoulderDiameter = new AnnotatedLengthDTO(theForeShoulderDiameter);
104     }
105
106     public double getForeShoulderLength() {
107         return foreShoulderLength.getValue();
108     }
109
110     public void setForeShoulderLength(final AnnotatedLengthDTO theForeShoulderLength) {
111         foreShoulderLength = theForeShoulderLength;
112     }
113
114     public void setForeShoulderLength(final double theForeShoulderLength) {
115         foreShoulderLength = new AnnotatedLengthDTO(theForeShoulderLength);
116     }
117
118     public double getAftOutsideDiameter() {
119         return aftOutsideDiameter.getValue();
120     }
121
122     public void setAftOutsideDiameter(final AnnotatedLengthDTO theAftOutsideDiameter) {
123         aftOutsideDiameter = theAftOutsideDiameter;
124     }
125
126     public void setAftOutsideDiameter(final double theAftOutsideDiameter) {
127         aftOutsideDiameter = new AnnotatedLengthDTO(theAftOutsideDiameter);
128     }
129
130     public double getAftShoulderDiameter() {
131         return aftShoulderDiameter.getValue();
132     }
133
134     public void setAftShoulderDiameter(final AnnotatedLengthDTO theAftShoulderDiameter) {
135         aftShoulderDiameter = theAftShoulderDiameter;
136     }
137
138     public void setAftShoulderDiameter(final double theAftShoulderDiameter) {
139         aftShoulderDiameter = new AnnotatedLengthDTO(theAftShoulderDiameter);
140     }
141
142     public double getAftShoulderLength() {
143         return aftShoulderLength.getValue();
144     }
145
146     public void setAftShoulderLength(final AnnotatedLengthDTO theAftShoulderLength) {
147         aftShoulderLength = theAftShoulderLength;
148     }
149
150     public void setAftShoulderLength(final double theAftShoulderLength) {
151         aftShoulderLength = new AnnotatedLengthDTO(theAftShoulderLength);
152     }
153
154     public double getLength() {
155         return length.getValue();
156     }
157
158     public void setLength(final AnnotatedLengthDTO theLength) {
159         length = theLength;
160     }
161
162     public void setLength(final double theLength) {
163         length = new AnnotatedLengthDTO(theLength);
164     }
165
166     public double getThickness() {
167                 return thickness.getValue();
168         }
169
170         public void setThickness(AnnotatedLengthDTO thickness) {
171                 this.thickness = thickness;
172         }
173
174         public void setThickness(double thickness) {
175                 this.thickness = new AnnotatedLengthDTO(thickness);
176         }
177
178         @Override
179         public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
180         TypedPropertyMap props = new TypedPropertyMap();
181         addProps(props, materials);
182         props.put(ComponentPreset.SHAPE, shape.getORShape());
183         props.put(ComponentPreset.FORE_OUTER_DIAMETER, this.getForeOutsideDiameter());
184         props.put(ComponentPreset.FORE_SHOULDER_DIAMETER, this.getForeShoulderDiameter());
185         props.put(ComponentPreset.FORE_SHOULDER_LENGTH, this.getForeShoulderLength());
186         props.put(ComponentPreset.AFT_OUTER_DIAMETER, this.getAftOutsideDiameter());
187         props.put(ComponentPreset.AFT_SHOULDER_DIAMETER, this.getAftShoulderDiameter());
188         props.put(ComponentPreset.AFT_SHOULDER_LENGTH, this.getAftShoulderLength());
189         props.put(ComponentPreset.LENGTH, this.getLength());
190         props.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
191         if ( thickness != null ) {
192                 props.put(ComponentPreset.THICKNESS, this.getThickness());
193         }
194
195         return ComponentPresetFactory.create(props);
196     }
197 }