create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / file / rocksim / export / BodyTubeDTO.java
1 package net.sf.openrocket.file.rocksim.export;
2
3 import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
4 import net.sf.openrocket.rocketcomponent.BodyTube;
5 import net.sf.openrocket.rocketcomponent.Bulkhead;
6 import net.sf.openrocket.rocketcomponent.CenteringRing;
7 import net.sf.openrocket.rocketcomponent.EngineBlock;
8 import net.sf.openrocket.rocketcomponent.FinSet;
9 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
10 import net.sf.openrocket.rocketcomponent.InnerTube;
11 import net.sf.openrocket.rocketcomponent.LaunchLug;
12 import net.sf.openrocket.rocketcomponent.MassObject;
13 import net.sf.openrocket.rocketcomponent.Parachute;
14 import net.sf.openrocket.rocketcomponent.RocketComponent;
15 import net.sf.openrocket.rocketcomponent.Streamer;
16 import net.sf.openrocket.rocketcomponent.Transition;
17 import net.sf.openrocket.rocketcomponent.TubeCoupler;
18
19 import javax.xml.bind.annotation.XmlAccessType;
20 import javax.xml.bind.annotation.XmlAccessorType;
21 import javax.xml.bind.annotation.XmlElement;
22 import javax.xml.bind.annotation.XmlElementRef;
23 import javax.xml.bind.annotation.XmlElementRefs;
24 import javax.xml.bind.annotation.XmlElementWrapper;
25 import javax.xml.bind.annotation.XmlRootElement;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 /**
30  * Models the XML element for a Rocksim body tube.
31  */
32 @XmlRootElement(name = RocksimCommonConstants.BODY_TUBE)
33 @XmlAccessorType(XmlAccessType.FIELD)
34 public class BodyTubeDTO extends BasePartDTO implements AttachableParts {
35
36     @XmlElement(name = RocksimCommonConstants.OD)
37     private double od = 0d;
38     @XmlElement(name = RocksimCommonConstants.ID)
39     private double id = 0d;
40     @XmlElement(name = RocksimCommonConstants.IS_MOTOR_MOUNT)
41     private int isMotorMount = 0;
42     @XmlElement(name = RocksimCommonConstants.MOTOR_DIA)
43     private double motorDia = 0d;
44     @XmlElement(name = RocksimCommonConstants.ENGINE_OVERHANG)
45     private double engineOverhang = 0d;
46     @XmlElement(name = RocksimCommonConstants.IS_INSIDE_TUBE)
47     private int isInsideTube = 0;
48     @XmlElementWrapper(name = RocksimCommonConstants.ATTACHED_PARTS)
49     @XmlElementRefs({
50             @XmlElementRef(name = RocksimCommonConstants.BODY_TUBE, type = BodyTubeDTO.class),
51             @XmlElementRef(name = RocksimCommonConstants.BODY_TUBE, type = InnerBodyTubeDTO.class),
52             @XmlElementRef(name = RocksimCommonConstants.RING, type = CenteringRingDTO.class),
53             @XmlElementRef(name = RocksimCommonConstants.LAUNCH_LUG, type = LaunchLugDTO.class),
54             @XmlElementRef(name = RocksimCommonConstants.FIN_SET, type = FinSetDTO.class),
55             @XmlElementRef(name = RocksimCommonConstants.CUSTOM_FIN_SET, type = CustomFinSetDTO.class),
56             @XmlElementRef(name = RocksimCommonConstants.STREAMER, type = StreamerDTO.class),
57             @XmlElementRef(name = RocksimCommonConstants.PARACHUTE, type = ParachuteDTO.class),
58             @XmlElementRef(name = RocksimCommonConstants.MASS_OBJECT, type = MassObjectDTO.class)})
59     List<BasePartDTO> attachedParts = new ArrayList<BasePartDTO>();
60
61     /**
62      * Constructor.
63      */
64     public BodyTubeDTO() {
65     }
66
67     /**
68      * Copy constructor.
69      *
70      * @param theORInnerTube  an OR inner tube; used by subclasses
71      */
72     protected BodyTubeDTO(InnerTube theORInnerTube) {
73         super(theORInnerTube);
74     }
75
76     /**
77      * Copy constructor.
78      *
79      * @param theORBodyTube an OR body tube
80      */
81     protected BodyTubeDTO(BodyTube theORBodyTube) {
82         super(theORBodyTube);
83
84         setEngineOverhang(theORBodyTube.getMotorOverhang() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
85         setID(theORBodyTube.getInnerRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS);
86         setOD(theORBodyTube.getOuterRadius() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS);
87         setMotorDia((theORBodyTube.getMotorMountDiameter() / 2) * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS);
88         setMotorMount(theORBodyTube.isMotorMount());
89
90         List<RocketComponent> children = theORBodyTube.getChildren();
91         for (int i = 0; i < children.size(); i++) {
92             RocketComponent rocketComponents = children.get(i);
93             if (rocketComponents instanceof InnerTube) {
94                 final InnerTube innerTube = (InnerTube) rocketComponents;
95                 final InnerBodyTubeDTO innerBodyTubeDTO = new InnerBodyTubeDTO(innerTube, this);
96                 //Only add the inner tube if it is NOT a cluster.
97                 if (innerTube.getClusterCount() == 1) {
98                     attachedParts.add(innerBodyTubeDTO);
99                 }
100             } else if (rocketComponents instanceof BodyTube) {
101                 attachedParts.add(new BodyTubeDTO((BodyTube) rocketComponents));
102             } else if (rocketComponents instanceof Transition) {
103                 attachedParts.add(new TransitionDTO((Transition) rocketComponents));
104             } else if (rocketComponents instanceof EngineBlock) {
105                 attachedParts.add(new EngineBlockDTO((EngineBlock) rocketComponents));
106             } else if (rocketComponents instanceof TubeCoupler) {
107                 attachedParts.add(new TubeCouplerDTO((TubeCoupler) rocketComponents));
108             } else if (rocketComponents instanceof CenteringRing) {
109                 attachedParts.add(new CenteringRingDTO((CenteringRing) rocketComponents));
110             } else if (rocketComponents instanceof Bulkhead) {
111                 attachedParts.add(new BulkheadDTO((Bulkhead) rocketComponents));
112             } else if (rocketComponents instanceof LaunchLug) {
113                 attachedParts.add(new LaunchLugDTO((LaunchLug) rocketComponents));
114             } else if (rocketComponents instanceof Streamer) {
115                 attachedParts.add(new StreamerDTO((Streamer) rocketComponents));
116             } else if (rocketComponents instanceof Parachute) {
117                 attachedParts.add(new ParachuteDTO((Parachute) rocketComponents));
118             } else if (rocketComponents instanceof MassObject) {
119                 attachedParts.add(new MassObjectDTO((MassObject) rocketComponents));
120             } else if (rocketComponents instanceof FreeformFinSet) {
121                 attachedParts.add(new CustomFinSetDTO((FreeformFinSet) rocketComponents));
122             } else if (rocketComponents instanceof FinSet) {
123                 attachedParts.add(new FinSetDTO((FinSet) rocketComponents));
124             }
125         }
126     }
127
128     public double getOD() {
129         return od;
130     }
131
132     public void setOD(double theOd) {
133         od = theOd;
134     }
135
136     public double getID() {
137         return id;
138     }
139
140     public void setID(double theId) {
141         id = theId;
142     }
143
144     public int getMotorMount() {
145         return isMotorMount;
146     }
147
148     public void setMotorMount(boolean motorMount) {
149         if (motorMount) {
150             isMotorMount = 1;
151         } else {
152             isMotorMount = 0;
153         }
154
155     }
156
157     public void setMotorMount(int theMotorMount) {
158         isMotorMount = theMotorMount;
159     }
160
161     public double getMotorDia() {
162         return motorDia;
163     }
164
165     public void setMotorDia(double theMotorDia) {
166         motorDia = theMotorDia;
167     }
168
169     public double getEngineOverhang() {
170         return engineOverhang;
171     }
172
173     public void setEngineOverhang(double theEngineOverhang) {
174         engineOverhang = theEngineOverhang;
175     }
176
177     public int getInsideTube() {
178         return isInsideTube;
179     }
180
181     public void setInsideTube(boolean inside) {
182         if (inside) {
183             isInsideTube = 1;
184         } else {
185             isInsideTube = 0;
186         }
187     }
188
189     public void setInsideTube(int theInsideTube) {
190         isInsideTube = theInsideTube;
191     }
192
193     public List<BasePartDTO> getAttachedParts() {
194         return attachedParts;
195     }
196
197     @Override
198     public void addAttachedPart(BasePartDTO thePart) {
199         attachedParts.add(thePart);
200     }
201
202     @Override
203     public void removeAttachedPart(BasePartDTO part) {
204         attachedParts.remove(part);
205     }
206 }