]> git.gag.com Git - debian/openrocket/blob - core/src/net/sf/openrocket/preset/xml/TransitionDTO.java
Added optional Thickness element/property.
[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 double foreOutsideDiameter;
27     @XmlElement(name = "ForeShoulderDiameter")
28     private double foreShoulderDiameter;
29     @XmlElement(name = "ForeShoulderLength")
30     private double foreShoulderLength;
31
32     @XmlElement(name = "AftOutsideDiameter")
33     private double aftOutsideDiameter;
34     @XmlElement(name = "AftShoulderDiameter")
35     private double aftShoulderDiameter;
36     @XmlElement(name = "AftShoulderLength")
37     private double aftShoulderLength;
38
39     @XmlElement(name = "Length")
40     private double length;
41     
42     @XmlElement(name = "Thickness")
43     private Double 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;
84     }
85
86     public void setForeOutsideDiameter(final double theForeOutsideDiameter) {
87         foreOutsideDiameter = theForeOutsideDiameter;
88     }
89
90     public double getForeShoulderDiameter() {
91         return foreShoulderDiameter;
92     }
93
94     public void setForeShoulderDiameter(final double theForeShoulderDiameter) {
95         foreShoulderDiameter = theForeShoulderDiameter;
96     }
97
98     public double getForeShoulderLength() {
99         return foreShoulderLength;
100     }
101
102     public void setForeShoulderLength(final double theForeShoulderLength) {
103         foreShoulderLength = theForeShoulderLength;
104     }
105
106     public double getAftOutsideDiameter() {
107         return aftOutsideDiameter;
108     }
109
110     public void setAftOutsideDiameter(final double theAftOutsideDiameter) {
111         aftOutsideDiameter = theAftOutsideDiameter;
112     }
113
114     public double getAftShoulderDiameter() {
115         return aftShoulderDiameter;
116     }
117
118     public void setAftShoulderDiameter(final double theAftShoulderDiameter) {
119         aftShoulderDiameter = theAftShoulderDiameter;
120     }
121
122     public double getAftShoulderLength() {
123         return aftShoulderLength;
124     }
125
126     public void setAftShoulderLength(final double theAftShoulderLength) {
127         aftShoulderLength = theAftShoulderLength;
128     }
129
130     public double getLength() {
131         return length;
132     }
133
134     public void setLength(final double theLength) {
135         length = theLength;
136     }
137
138     public Double getThickness() {
139                 return thickness;
140         }
141
142         public void setThickness(Double thickness) {
143                 this.thickness = thickness;
144         }
145
146         public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
147         TypedPropertyMap props = new TypedPropertyMap();
148         addProps(props, materials);
149         props.put(ComponentPreset.SHAPE, shape.getORShape());
150         props.put(ComponentPreset.FORE_OUTER_DIAMETER, this.getForeOutsideDiameter());
151         props.put(ComponentPreset.FORE_SHOULDER_DIAMETER, this.getForeShoulderDiameter());
152         props.put(ComponentPreset.FORE_SHOULDER_LENGTH, this.getForeShoulderLength());
153         props.put(ComponentPreset.AFT_OUTER_DIAMETER, this.getAftOutsideDiameter());
154         props.put(ComponentPreset.AFT_SHOULDER_DIAMETER, this.getAftShoulderDiameter());
155         props.put(ComponentPreset.AFT_SHOULDER_LENGTH, this.getAftShoulderLength());
156         props.put(ComponentPreset.LENGTH, this.getLength());
157         props.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
158         if ( thickness != null ) {
159                 props.put(ComponentPreset.THICKNESS, thickness);
160         }
161
162         return ComponentPresetFactory.create(props);
163     }
164 }