create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / file / rocksim / export / AbstractTransitionDTO.java
1 package net.sf.openrocket.file.rocksim.export;
2
3 import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
4 import net.sf.openrocket.file.rocksim.RocksimNoseConeCode;
5 import net.sf.openrocket.rocketcomponent.BodyTube;
6 import net.sf.openrocket.rocketcomponent.Bulkhead;
7 import net.sf.openrocket.rocketcomponent.CenteringRing;
8 import net.sf.openrocket.rocketcomponent.EngineBlock;
9 import net.sf.openrocket.rocketcomponent.FinSet;
10 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
11 import net.sf.openrocket.rocketcomponent.InnerTube;
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.Transition;
16 import net.sf.openrocket.rocketcomponent.TubeCoupler;
17
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlElement;
21 import javax.xml.bind.annotation.XmlElementRef;
22 import javax.xml.bind.annotation.XmlElementRefs;
23 import javax.xml.bind.annotation.XmlElementWrapper;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 /**
28  * A common ancestor class for nose cones and transitions.  This class is responsible for adapting an OpenRocket
29  * Transition to a Rocksim Transition.
30  */
31 @XmlAccessorType(XmlAccessType.FIELD)
32 public class AbstractTransitionDTO extends BasePartDTO implements AttachableParts {
33
34     @XmlElement(name = RocksimCommonConstants.SHAPE_CODE)
35     private int shapeCode = 1;
36     @XmlElement(name = RocksimCommonConstants.CONSTRUCTION_TYPE)
37     private int constructionType = 1;
38     @XmlElement(name = RocksimCommonConstants.WALL_THICKNESS)
39     private double wallThickness = 0d;
40     @XmlElement(name = RocksimCommonConstants.SHAPE_PARAMETER)
41     private double shapeParameter = 0d;
42
43     @XmlElementWrapper(name = RocksimCommonConstants.ATTACHED_PARTS)
44     @XmlElementRefs({
45             @XmlElementRef(name = RocksimCommonConstants.BODY_TUBE, type = BodyTubeDTO.class),
46             @XmlElementRef(name = RocksimCommonConstants.BODY_TUBE, type = InnerBodyTubeDTO.class),
47             @XmlElementRef(name = RocksimCommonConstants.FIN_SET, type = FinSetDTO.class),
48             @XmlElementRef(name = RocksimCommonConstants.CUSTOM_FIN_SET, type = CustomFinSetDTO.class),
49             @XmlElementRef(name = RocksimCommonConstants.RING, type = CenteringRingDTO.class),
50             @XmlElementRef(name = RocksimCommonConstants.STREAMER, type = StreamerDTO.class),
51             @XmlElementRef(name = RocksimCommonConstants.PARACHUTE, type = ParachuteDTO.class),
52             @XmlElementRef(name = RocksimCommonConstants.MASS_OBJECT, type = MassObjectDTO.class)})
53     List<BasePartDTO> attachedParts = new ArrayList<BasePartDTO>();
54
55     /**
56      * Default constructor.
57      */
58     protected AbstractTransitionDTO() {
59     }
60
61     /**
62      * Conversion constructor.
63      *
64      * @param nc  the OpenRocket component to convert
65      */
66     protected AbstractTransitionDTO(Transition nc) {
67         super(nc);
68         setConstructionType(nc.isFilled() ? 0 : 1);
69         setShapeCode(RocksimNoseConeCode.toCode(nc.getType()));
70
71         if (Transition.Shape.POWER.equals(nc.getType()) ||
72                 Transition.Shape.HAACK.equals(nc.getType()) ||
73                 Transition.Shape.PARABOLIC.equals(nc.getType())) {
74             setShapeParameter(nc.getShapeParameter());
75         }
76
77         setWallThickness(nc.getThickness() * RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH);
78
79         List<RocketComponent> children = nc.getChildren();
80         for (int i = 0; i < children.size(); i++) {
81             RocketComponent rocketComponents = children.get(i);
82             if (rocketComponents instanceof InnerTube) {
83                 attachedParts.add(new InnerBodyTubeDTO((InnerTube) rocketComponents, this));
84             } else if (rocketComponents instanceof BodyTube) {
85                 attachedParts.add(new BodyTubeDTO((BodyTube) rocketComponents));
86             } else if (rocketComponents instanceof Transition) {
87                 attachedParts.add(new TransitionDTO((Transition) rocketComponents));
88             } else if (rocketComponents instanceof EngineBlock) {
89                 attachedParts.add(new EngineBlockDTO((EngineBlock) rocketComponents));
90             } else if (rocketComponents instanceof TubeCoupler) {
91                 attachedParts.add(new TubeCouplerDTO((TubeCoupler) rocketComponents));
92             } else if (rocketComponents instanceof CenteringRing) {
93                 attachedParts.add(new CenteringRingDTO((CenteringRing) rocketComponents));
94             } else if (rocketComponents instanceof Bulkhead) {
95                 attachedParts.add(new BulkheadDTO((Bulkhead) rocketComponents));
96             } else if (rocketComponents instanceof Parachute) {
97                 attachedParts.add(new ParachuteDTO((Parachute) rocketComponents));
98             } else if (rocketComponents instanceof MassObject) {
99                 attachedParts.add(new MassObjectDTO((MassObject) rocketComponents));
100             } else if (rocketComponents instanceof FreeformFinSet) {
101                 attachedParts.add(new CustomFinSetDTO((FreeformFinSet) rocketComponents));
102             } else if (rocketComponents instanceof FinSet) {
103                 attachedParts.add(new FinSetDTO((FinSet) rocketComponents));
104             }
105         }
106     }
107
108     public int getShapeCode() {
109         return shapeCode;
110     }
111
112     public void setShapeCode(int theShapeCode) {
113         shapeCode = theShapeCode;
114     }
115
116     public int getConstructionType() {
117         return constructionType;
118     }
119
120     public void setConstructionType(int theConstructionType) {
121         constructionType = theConstructionType;
122     }
123
124     public double getWallThickness() {
125         return wallThickness;
126     }
127
128     public void setWallThickness(double theWallThickness) {
129         wallThickness = theWallThickness;
130     }
131
132     public double getShapeParameter() {
133         return shapeParameter;
134     }
135
136     public void setShapeParameter(double theShapeParameter) {
137         shapeParameter = theShapeParameter;
138     }
139
140     @Override
141     public void addAttachedPart(BasePartDTO part) {
142         attachedParts.add(part);
143     }
144
145     @Override
146     public void removeAttachedPart(BasePartDTO part) {
147         attachedParts.remove(part);
148     }
149 }