create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / preset / xml / NoseConeDTO.java
1 package net.sf.openrocket.preset.xml;
2
3 import java.util.List;
4
5 import javax.xml.bind.annotation.XmlAccessType;
6 import javax.xml.bind.annotation.XmlAccessorType;
7 import javax.xml.bind.annotation.XmlElement;
8 import javax.xml.bind.annotation.XmlRootElement;
9
10 import net.sf.openrocket.preset.ComponentPreset;
11 import net.sf.openrocket.preset.ComponentPresetFactory;
12 import net.sf.openrocket.preset.InvalidComponentPresetException;
13 import net.sf.openrocket.preset.TypedPropertyMap;
14
15 /**
16  * A NoseCone preset XML handler.
17  */
18 @XmlRootElement(name = "NoseCone")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class NoseConeDTO extends BaseComponentDTO {
21
22     @XmlElement(name = "Shape")
23     private ShapeDTO shape;
24     @XmlElement(name = "OutsideDiameter")
25     private AnnotatedLengthDTO outsideDiameter;
26     @XmlElement(name = "ShoulderDiameter")
27     private AnnotatedLengthDTO shoulderDiameter;
28     @XmlElement(name = "ShoulderLength")
29     private AnnotatedLengthDTO shoulderLength;
30     @XmlElement(name = "Length")
31     private AnnotatedLengthDTO length;
32
33     @XmlElement(name = "Thickness")
34     private AnnotatedLengthDTO thickness;
35     
36     /**
37      * Default constructor.
38      */
39     public NoseConeDTO() {
40     }
41
42     /**
43      * Constructor that
44      *
45      * @param thePreset
46      *
47      * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
48      */
49     public NoseConeDTO(final ComponentPreset thePreset) {
50         super(thePreset);
51         setShape(ShapeDTO.asDTO(thePreset.get(ComponentPreset.SHAPE)));
52         setOutsideDiameter(thePreset.get(ComponentPreset.AFT_OUTER_DIAMETER));
53         if ( thePreset.has(ComponentPreset.AFT_SHOULDER_DIAMETER)) {
54                 setShoulderDiameter(thePreset.get(ComponentPreset.AFT_SHOULDER_DIAMETER));
55         }
56         if ( thePreset.has(ComponentPreset.AFT_SHOULDER_LENGTH)) {
57                 setShoulderLength(thePreset.get(ComponentPreset.AFT_SHOULDER_LENGTH));
58         }
59         setLength(thePreset.get(ComponentPreset.LENGTH));
60         if ( thePreset.has(ComponentPreset.THICKNESS)) {
61                 setThickness(thePreset.get(ComponentPreset.THICKNESS));
62         }
63     }
64
65     public ShapeDTO getShape() {
66         return shape;
67     }
68
69     public void setShape(final ShapeDTO theShape) {
70         shape = theShape;
71     }
72
73     public double getOutsideDiameter() {
74         return outsideDiameter.getValue();
75     }
76
77     public void setOutsideDiameter(final AnnotatedLengthDTO theOutsideDiameter) {
78         outsideDiameter = theOutsideDiameter;
79     }
80
81     public void setOutsideDiameter(final double theOutsideDiameter) {
82         outsideDiameter = new AnnotatedLengthDTO(theOutsideDiameter);
83     }
84
85     public double getShoulderDiameter() {
86         return shoulderDiameter.getValue();
87     }
88
89     public void setShoulderDiameter(final AnnotatedLengthDTO theShoulderDiameter) {
90         shoulderDiameter = theShoulderDiameter;
91     }
92
93     public void setShoulderDiameter(final double theShoulderDiameter) {
94         shoulderDiameter = new AnnotatedLengthDTO(theShoulderDiameter);
95     }
96
97     public double getShoulderLength() {
98         return shoulderLength.getValue();
99     }
100
101     public void setShoulderLength(final AnnotatedLengthDTO theShoulderLength) {
102         shoulderLength = theShoulderLength;
103     }
104
105     public void setShoulderLength(final double theShoulderLength) {
106         shoulderLength = new AnnotatedLengthDTO(theShoulderLength);
107     }
108
109     public double getLength() {
110         return length.getValue();
111     }
112
113     public void setLength(final AnnotatedLengthDTO theLength) {
114         length = theLength;
115     }
116
117     public void setLength(final double theLength) {
118         length = new AnnotatedLengthDTO(theLength);
119     }
120
121     public double getThickness() {
122                 return thickness.getValue();
123         }
124
125         public void setThickness(AnnotatedLengthDTO thickness) {
126                 this.thickness = thickness;
127         }
128
129         public void setThickness(double thickness) {
130                 this.thickness = new AnnotatedLengthDTO(thickness);
131         }
132
133         @Override
134         public ComponentPreset asComponentPreset(List<MaterialDTO> materials) throws InvalidComponentPresetException {
135         TypedPropertyMap props = new TypedPropertyMap();
136         addProps(props, materials);
137         props.put(ComponentPreset.SHAPE, shape.getORShape());
138         props.put(ComponentPreset.AFT_OUTER_DIAMETER, this.getOutsideDiameter());
139         if ( shoulderLength != null ) {
140                 props.put(ComponentPreset.AFT_SHOULDER_LENGTH, this.getShoulderLength());
141         }
142         if ( shoulderDiameter != null ) {
143                 props.put(ComponentPreset.AFT_SHOULDER_DIAMETER, this.getShoulderDiameter());
144         }
145         props.put(ComponentPreset.LENGTH, this.getLength());
146         props.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
147         if ( thickness != null ) {
148                 props.put(ComponentPreset.THICKNESS, this.getThickness());
149         }
150
151         return ComponentPresetFactory.create(props);
152     }
153
154 }