1 package net.sf.openrocket.preset.xml;
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;
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;
16 * A NoseCone preset XML handler.
18 @XmlRootElement(name = "NoseCone")
19 @XmlAccessorType(XmlAccessType.FIELD)
20 public class NoseConeDTO extends BaseComponentDTO {
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;
33 @XmlElement(name = "Thickness")
34 private AnnotatedLengthDTO thickness;
37 * Default constructor.
39 public NoseConeDTO() {
47 * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
49 public NoseConeDTO(final ComponentPreset 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));
56 if ( thePreset.has(ComponentPreset.AFT_SHOULDER_LENGTH)) {
57 setShoulderLength(thePreset.get(ComponentPreset.AFT_SHOULDER_LENGTH));
59 setLength(thePreset.get(ComponentPreset.LENGTH));
60 if ( thePreset.has(ComponentPreset.THICKNESS)) {
61 setThickness(thePreset.get(ComponentPreset.THICKNESS));
65 public ShapeDTO getShape() {
69 public void setShape(final ShapeDTO theShape) {
73 public double getOutsideDiameter() {
74 return outsideDiameter.getValue();
77 public void setOutsideDiameter(final AnnotatedLengthDTO theOutsideDiameter) {
78 outsideDiameter = theOutsideDiameter;
81 public void setOutsideDiameter(final double theOutsideDiameter) {
82 outsideDiameter = new AnnotatedLengthDTO(theOutsideDiameter);
85 public double getShoulderDiameter() {
86 return shoulderDiameter.getValue();
89 public void setShoulderDiameter(final AnnotatedLengthDTO theShoulderDiameter) {
90 shoulderDiameter = theShoulderDiameter;
93 public void setShoulderDiameter(final double theShoulderDiameter) {
94 shoulderDiameter = new AnnotatedLengthDTO(theShoulderDiameter);
97 public double getShoulderLength() {
98 return shoulderLength.getValue();
101 public void setShoulderLength(final AnnotatedLengthDTO theShoulderLength) {
102 shoulderLength = theShoulderLength;
105 public void setShoulderLength(final double theShoulderLength) {
106 shoulderLength = new AnnotatedLengthDTO(theShoulderLength);
109 public double getLength() {
110 return length.getValue();
113 public void setLength(final AnnotatedLengthDTO theLength) {
117 public void setLength(final double theLength) {
118 length = new AnnotatedLengthDTO(theLength);
121 public double getThickness() {
122 return thickness.getValue();
125 public void setThickness(AnnotatedLengthDTO thickness) {
126 this.thickness = thickness;
129 public void setThickness(double thickness) {
130 this.thickness = new AnnotatedLengthDTO(thickness);
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());
142 if ( shoulderDiameter != null ) {
143 props.put(ComponentPreset.AFT_SHOULDER_DIAMETER, this.getShoulderDiameter());
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());
151 return ComponentPresetFactory.create(props);