1 package net.sf.openrocket.file.rocksim.export;
3 import net.sf.openrocket.file.rocksim.importt.RocksimHandler;
4 import net.sf.openrocket.file.rocksim.importt.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;
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;
28 * A common ancestor class for nose cones and transitions. This class is responsible for adapting an OpenRocket
29 * Transition to a Rocksim Transition.
31 @XmlAccessorType(XmlAccessType.FIELD)
32 public class AbstractTransitionDTO extends BasePartDTO {
34 @XmlElement(name = "ShapeCode")
35 private int shapeCode = 1;
36 @XmlElement(name = "ConstructionType")
37 private int constructionType = 1;
38 @XmlElement(name = "WallThickness")
39 private double wallThickness = 0d;
40 @XmlElement(name = "ShapeParameter")
41 private double shapeParameter = 0d;
43 @XmlElementWrapper(name = "AttachedParts")
45 @XmlElementRef(name = "BodyTube", type = BodyTubeDTO.class),
46 @XmlElementRef(name = "BodyTube", type = InnerBodyTubeDTO.class),
47 @XmlElementRef(name = "FinSet", type = FinSetDTO.class),
48 @XmlElementRef(name = "CustomFinSet", type = CustomFinSetDTO.class),
49 @XmlElementRef(name = "Ring", type = CenteringRingDTO.class),
50 @XmlElementRef(name = "Streamer", type = StreamerDTO.class),
51 @XmlElementRef(name = "Parachute", type = ParachuteDTO.class),
52 @XmlElementRef(name = "MassObject", type = MassObjectDTO.class)})
53 List<BasePartDTO> attachedParts = new ArrayList<BasePartDTO>();
56 * Default constructor.
58 protected AbstractTransitionDTO() {
62 * Conversion constructor.
64 * @param nc the OpenRocket component to convert
66 protected AbstractTransitionDTO(Transition nc) {
68 setConstructionType(nc.isFilled() ? 0 : 1);
69 setShapeCode(RocksimNoseConeCode.toCode(nc.getType()));
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());
77 setWallThickness(nc.getThickness() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
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));
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));
108 public int getShapeCode() {
112 public void setShapeCode(int theShapeCode) {
113 shapeCode = theShapeCode;
116 public int getConstructionType() {
117 return constructionType;
120 public void setConstructionType(int theConstructionType) {
121 constructionType = theConstructionType;
124 public double getWallThickness() {
125 return wallThickness;
128 public void setWallThickness(double theWallThickness) {
129 wallThickness = theWallThickness;
132 public double getShapeParameter() {
133 return shapeParameter;
136 public void setShapeParameter(double theShapeParameter) {
137 shapeParameter = theShapeParameter;