2 package net.sf.openrocket.preset.xml;
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;
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;
18 * Streamer preset XML handler.
20 @XmlRootElement(name = "Parachute")
21 @XmlAccessorType(XmlAccessType.FIELD)
22 public class ParachuteDTO extends BaseComponentDTO {
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;
33 @XmlElement(name = "LineMaterial")
34 private AnnotatedMaterialDTO lineMaterial;
38 * Default constructor.
40 public ParachuteDTO() {
43 public double getDiameter() {
44 return diameter.getValue();
47 public void setDiameter(AnnotatedLengthDTO diameter) {
48 this.diameter = diameter;
50 public void setDiameter(double diameter) {
51 this.diameter = new AnnotatedLengthDTO(diameter);
54 public Integer getSides() {
58 public void setSides(Integer sides) {
62 public Integer getLineCount() {
66 public void setLineCount(Integer lineCount) {
67 this.lineCount = lineCount;
70 public double getLineLength() {
71 return lineLength.getValue();
74 public void setLineLength(AnnotatedLengthDTO lineLength) {
75 this.lineLength = lineLength;
78 public void setLineLength(double lineLength) {
79 this.lineLength = new AnnotatedLengthDTO(lineLength);
82 public AnnotatedMaterialDTO getLineMaterial() {
86 public void setLineMaterial(AnnotatedMaterialDTO lineMaterial) {
87 this.lineMaterial = lineMaterial;
91 * Most-useful constructor that maps a BodyTube preset to a BodyTubeDTO.
93 * @param preset the preset
95 * @throws net.sf.openrocket.util.BugException thrown if the expected body tube keys are not in the preset
97 public ParachuteDTO(final ComponentPreset 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));
104 if ( preset.has(ComponentPreset.SIDES)) {
105 setSides(preset.get(ComponentPreset.SIDES));
107 if ( preset.has(ComponentPreset.LINE_MATERIAL)) {
108 setLineMaterial(new AnnotatedMaterialDTO(preset.get(ComponentPreset.LINE_MATERIAL)));
113 public ComponentPreset asComponentPreset(java.util.List<MaterialDTO> materials) throws InvalidComponentPresetException {
114 return asComponentPreset(ComponentPreset.Type.PARACHUTE, materials);
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());
128 if ( this.sides != null ) {
129 props.put(ComponentPreset.SIDES, this.getSides());
131 if ( this.lineMaterial != null ) {
132 Material m = find(materials, this.lineMaterial);
134 props.put(ComponentPreset.LINE_MATERIAL, m);
138 return ComponentPresetFactory.create(props);