2 package net.sf.openrocket.preset.xml;
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;
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;
16 * Transition preset XML handler.
18 @XmlRootElement(name = "Transition")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class TransitionDTO extends BaseComponentDTO {
22 @XmlElement(name = "Shape")
23 private ShapeDTO shape;
25 @XmlElement(name = "ForeOutsideDiameter")
26 private AnnotatedLengthDTO foreOutsideDiameter;
27 @XmlElement(name = "ForeShoulderDiameter")
28 private AnnotatedLengthDTO foreShoulderDiameter;
29 @XmlElement(name = "ForeShoulderLength")
30 private AnnotatedLengthDTO foreShoulderLength;
32 @XmlElement(name = "AftOutsideDiameter")
33 private AnnotatedLengthDTO aftOutsideDiameter;
34 @XmlElement(name = "AftShoulderDiameter")
35 private AnnotatedLengthDTO aftShoulderDiameter;
36 @XmlElement(name = "AftShoulderLength")
37 private AnnotatedLengthDTO aftShoulderLength;
39 @XmlElement(name = "Length")
40 private AnnotatedLengthDTO length;
42 @XmlElement(name = "Thickness")
43 private AnnotatedLengthDTO thickness;
47 * Default constructor.
49 public TransitionDTO() {
53 * Most-useful constructor that maps a Transition preset to a TransitionDTO.
55 * @param thePreset the preset
57 * @throws net.sf.openrocket.util.BugException thrown if the expected transition keys are not in the preset
59 public TransitionDTO(final ComponentPreset 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));
74 public ShapeDTO getShape() {
78 public void setShape(final ShapeDTO theShape) {
82 public double getForeOutsideDiameter() {
83 return foreOutsideDiameter.getValue();
86 public void setForeOutsideDiameter(final AnnotatedLengthDTO theForeOutsideDiameter) {
87 foreOutsideDiameter = theForeOutsideDiameter;
90 public void setForeOutsideDiameter(final double theForeOutsideDiameter) {
91 foreOutsideDiameter = new AnnotatedLengthDTO(theForeOutsideDiameter);
94 public double getForeShoulderDiameter() {
95 return foreShoulderDiameter.getValue();
98 public void setForeShoulderDiameter(final AnnotatedLengthDTO theForeShoulderDiameter) {
99 foreShoulderDiameter = theForeShoulderDiameter;
102 public void setForeShoulderDiameter(final double theForeShoulderDiameter) {
103 foreShoulderDiameter = new AnnotatedLengthDTO(theForeShoulderDiameter);
106 public double getForeShoulderLength() {
107 return foreShoulderLength.getValue();
110 public void setForeShoulderLength(final AnnotatedLengthDTO theForeShoulderLength) {
111 foreShoulderLength = theForeShoulderLength;
114 public void setForeShoulderLength(final double theForeShoulderLength) {
115 foreShoulderLength = new AnnotatedLengthDTO(theForeShoulderLength);
118 public double getAftOutsideDiameter() {
119 return aftOutsideDiameter.getValue();
122 public void setAftOutsideDiameter(final AnnotatedLengthDTO theAftOutsideDiameter) {
123 aftOutsideDiameter = theAftOutsideDiameter;
126 public void setAftOutsideDiameter(final double theAftOutsideDiameter) {
127 aftOutsideDiameter = new AnnotatedLengthDTO(theAftOutsideDiameter);
130 public double getAftShoulderDiameter() {
131 return aftShoulderDiameter.getValue();
134 public void setAftShoulderDiameter(final AnnotatedLengthDTO theAftShoulderDiameter) {
135 aftShoulderDiameter = theAftShoulderDiameter;
138 public void setAftShoulderDiameter(final double theAftShoulderDiameter) {
139 aftShoulderDiameter = new AnnotatedLengthDTO(theAftShoulderDiameter);
142 public double getAftShoulderLength() {
143 return aftShoulderLength.getValue();
146 public void setAftShoulderLength(final AnnotatedLengthDTO theAftShoulderLength) {
147 aftShoulderLength = theAftShoulderLength;
150 public void setAftShoulderLength(final double theAftShoulderLength) {
151 aftShoulderLength = new AnnotatedLengthDTO(theAftShoulderLength);
154 public double getLength() {
155 return length.getValue();
158 public void setLength(final AnnotatedLengthDTO theLength) {
162 public void setLength(final double theLength) {
163 length = new AnnotatedLengthDTO(theLength);
166 public double getThickness() {
167 return thickness.getValue();
170 public void setThickness(AnnotatedLengthDTO thickness) {
171 this.thickness = thickness;
174 public void setThickness(double thickness) {
175 this.thickness = new AnnotatedLengthDTO(thickness);
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());
195 return ComponentPresetFactory.create(props);