create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / preset / xml / ParachuteDTO.java
1
2 package net.sf.openrocket.preset.xml;
3
4 import net.sf.openrocket.material.Material;
5 import net.sf.openrocket.preset.ComponentPreset;
6 import net.sf.openrocket.preset.ComponentPresetFactory;
7 import net.sf.openrocket.preset.InvalidComponentPresetException;
8 import net.sf.openrocket.preset.TypedPropertyMap;
9 import net.sf.openrocket.preset.xml.BaseComponentDTO.AnnotatedMaterialDTO;
10
11 import javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlElement;
14 import javax.xml.bind.annotation.XmlRootElement;
15 import java.util.List;
16
17 /**
18  * Streamer preset XML handler.
19  */
20 @XmlRootElement(name = "Parachute")
21 @XmlAccessorType(XmlAccessType.FIELD)
22 public class ParachuteDTO extends BaseComponentDTO {
23
24     @XmlElement(name = "Diameter")
25     private AnnotatedLengthDTO diameter;
26     @XmlElement(name = "Sides")
27     private Integer sides;
28     @XmlElement(name = "LineCount")
29     private Integer lineCount;
30     @XmlElement(name = "LineLength")
31     private AnnotatedLengthDTO lineLength;
32     
33     @XmlElement(name = "LineMaterial")
34         private AnnotatedMaterialDTO lineMaterial;
35  
36
37     /**
38      * Default constructor.
39      */
40     public ParachuteDTO() {
41     }
42
43     public double getDiameter() {
44                 return diameter.getValue();
45         }
46
47         public void setDiameter(AnnotatedLengthDTO diameter) {
48                 this.diameter = diameter;
49         }
50         public void setDiameter(double diameter) {
51                 this.diameter = new AnnotatedLengthDTO(diameter);
52         }
53
54         public Integer getSides() {
55                 return sides;
56         }
57
58         public void setSides(Integer sides) {
59                 this.sides = sides;
60         }
61
62         public Integer getLineCount() {
63                 return lineCount;
64         }
65
66         public void setLineCount(Integer lineCount) {
67                 this.lineCount = lineCount;
68         }
69
70         public double getLineLength() {
71                 return lineLength.getValue();
72         }
73
74         public void setLineLength(AnnotatedLengthDTO lineLength) {
75                 this.lineLength = lineLength;
76         }
77
78         public void setLineLength(double lineLength) {
79                 this.lineLength = new AnnotatedLengthDTO(lineLength);
80         }
81
82         public AnnotatedMaterialDTO getLineMaterial() {
83                 return lineMaterial;
84         }
85
86         public void setLineMaterial(AnnotatedMaterialDTO lineMaterial) {
87                 this.lineMaterial = lineMaterial;
88         }
89
90         /**
91      * Most-useful constructor that maps a BodyTube preset to a BodyTubeDTO.
92      *
93      * @param preset  the preset
94      *
95      * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
96      */
97     public ParachuteDTO(final ComponentPreset preset) {
98         super(preset);
99         setDiameter(preset.get(ComponentPreset.DIAMETER));
100         setLineCount(preset.get(ComponentPreset.LINE_COUNT));
101         if ( preset.has(ComponentPreset.LINE_LENGTH)) {
102             setLineLength(preset.get(ComponentPreset.LINE_LENGTH));
103         }
104         if ( preset.has(ComponentPreset.SIDES)) {
105                 setSides(preset.get(ComponentPreset.SIDES));
106         }
107         if ( preset.has(ComponentPreset.LINE_MATERIAL)) {
108                 setLineMaterial(new AnnotatedMaterialDTO(preset.get(ComponentPreset.LINE_MATERIAL)));
109         }
110     }
111
112     @Override
113     public ComponentPreset asComponentPreset(java.util.List<MaterialDTO> materials) throws InvalidComponentPresetException {
114         return asComponentPreset(ComponentPreset.Type.PARACHUTE, materials);
115     }
116
117     public ComponentPreset asComponentPreset(ComponentPreset.Type type, List<MaterialDTO> materials) throws InvalidComponentPresetException {
118         TypedPropertyMap props = new TypedPropertyMap();
119         addProps(props, materials);
120         // TODO - seems some vendors use a bulk material for the sheet along with a Thickness.
121         // need to fix the MATERIAL packed into the componentpreset.
122         props.put(ComponentPreset.TYPE, type);
123         props.put(ComponentPreset.DIAMETER, this.getDiameter());
124         props.put(ComponentPreset.LINE_COUNT, this.getLineCount());
125         if ( this.lineLength != null ) {
126                 props.put(ComponentPreset.LINE_LENGTH, this.getLineLength());
127         }
128         if ( this.sides != null ) {
129                 props.put(ComponentPreset.SIDES, this.getSides());
130         }
131         if ( this.lineMaterial != null ) {
132                 Material m = find(materials, this.lineMaterial);
133                 if ( m != null ) {
134                         props.put(ComponentPreset.LINE_MATERIAL, m);
135                 }
136         }
137
138         return ComponentPresetFactory.create(props);
139     }
140 }