DGP - cleanup
[debian/openrocket] / core / src / net / sf / openrocket / file / rocksim / export / BasePartDTO.java
1 package net.sf.openrocket.file.rocksim.export;
2
3 import net.sf.openrocket.file.rocksim.importt.BaseHandler;
4 import net.sf.openrocket.file.rocksim.importt.RocksimDensityType;
5 import net.sf.openrocket.file.rocksim.importt.RocksimFinishCode;
6 import net.sf.openrocket.file.rocksim.importt.RocksimHandler;
7 import net.sf.openrocket.file.rocksim.importt.RocksimLocationMode;
8 import net.sf.openrocket.rocketcomponent.ExternalComponent;
9 import net.sf.openrocket.rocketcomponent.FinSet;
10 import net.sf.openrocket.rocketcomponent.RecoveryDevice;
11 import net.sf.openrocket.rocketcomponent.RocketComponent;
12 import net.sf.openrocket.rocketcomponent.StructuralComponent;
13
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 /**
20  * The base class for all OpenRocket to Rocksim conversions.
21  */
22 @XmlRootElement
23 @XmlAccessorType(XmlAccessType.FIELD)
24 public abstract class BasePartDTO {
25
26     @XmlElement(name = "KnownMass")
27     private Double knownMass = 0d;
28     @XmlElement(name = "Density")
29     private double density = 0d;
30     @XmlElement(name = "Material")
31     private String material = "";
32     @XmlElement(name = "Name")
33     private String name = "";
34     @XmlElement(name = "KnownCG")
35     private Double knownCG = null;
36     @XmlElement(name = "UseKnownCG")
37     private int useKnownCG = 1;
38     @XmlElement(name = "Xb")
39     private double xb = 0;
40     @XmlElement(name = "CalcMass")
41     private double calcMass = 0d;
42     @XmlElement(name = "CalcCG")
43     private double calcCG = 0d;
44     @XmlElement(name = "DensityType")
45     private int densityType = 0;
46     @XmlElement(name = "RadialLoc")
47     private String radialLoc = "0.";
48     @XmlElement(name = "RadialAngle")
49     private double radialAngle = 0;
50     @XmlElement(name = "LocationMode")
51     private int locationMode = 0;
52     @XmlElement(name = "Len", required = false, nillable = false)
53     private double len = 0d;
54     @XmlElement(name = "FinishCode")
55     private int finishCode = 0;
56
57     /**
58      * Default constructor.
59      */
60     protected BasePartDTO() {
61     }
62
63     /**
64      * Copy constructor of sorts, that performs all common conversions for components.
65      *
66      * @param ec
67      */
68     protected BasePartDTO(RocketComponent ec) {
69         setCalcCG(ec.getCG().x * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
70         setCalcMass(ec.getComponentMass() * RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
71         setKnownCG(ec.getOverrideCGX() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
72         setKnownMass(ec.getOverrideMass() * RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
73         if (! (ec instanceof FinSet)) {
74             setLen(ec.getLength() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
75         }
76         setUseKnownCG(ec.isCGOverridden() || ec.isMassOverridden() ? 1 : 0);
77         setName(ec.getName());
78
79         setXb(ec.getPositionValue() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
80
81         //When the relative position is BOTTOM, the position location of the bottom edge of the component is +
82         //to the right of the bottom of the parent, and - to the left.
83         //But in Rocksim, it's + to the left and - to the right
84         if (ec.getRelativePosition().equals(RocketComponent.Position.BOTTOM)) {
85             setXb((-1 * ec.getPositionValue()) * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
86         }
87         else if (ec.getRelativePosition().equals(RocketComponent.Position.MIDDLE)) {
88             //Mapped to TOP, so adjust accordingly
89             setXb((ec.getPositionValue() + (ec.getParent().getLength() - ec.getLength()) /2)* RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
90         }
91
92         if (ec instanceof ExternalComponent) {
93             ExternalComponent comp = (ExternalComponent) ec;
94             setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
95
96             setDensity(comp.getMaterial().getDensity() * RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
97             setDensityType(RocksimDensityType.toCode(comp.getMaterial().getType()));
98             String material = comp.getMaterial().getName();
99             if (material.startsWith(BaseHandler.ROCKSIM_MATERIAL_PREFIX)) {
100                 material = material.substring(BaseHandler.ROCKSIM_MATERIAL_PREFIX.length());
101             }
102             setMaterial(material);
103
104             setFinishCode(RocksimFinishCode.toCode(comp.getFinish()));
105         }
106         else if (ec instanceof StructuralComponent) {
107             StructuralComponent comp = (StructuralComponent) ec;
108
109             setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
110             setDensity(comp.getMaterial().getDensity() * RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
111             setDensityType(RocksimDensityType.toCode(comp.getMaterial().getType()));
112             String material = comp.getMaterial().getName();
113             if (material.startsWith(BaseHandler.ROCKSIM_MATERIAL_PREFIX)) {
114                 material = material.substring(BaseHandler.ROCKSIM_MATERIAL_PREFIX.length());
115             }
116             setMaterial(material);
117         }
118         else if (ec instanceof RecoveryDevice) {
119             RecoveryDevice comp = (RecoveryDevice) ec;
120
121             setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
122             setDensity(comp.getMaterial().getDensity() * RocksimHandler.ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY);
123             setDensityType(RocksimDensityType.toCode(comp.getMaterial().getType()));
124             String material = comp.getMaterial().getName();
125             if (material.startsWith(BaseHandler.ROCKSIM_MATERIAL_PREFIX)) {
126                 material = material.substring(BaseHandler.ROCKSIM_MATERIAL_PREFIX.length());
127             }
128             setMaterial(material);
129         }
130     }
131
132     public Double getKnownMass() {
133         return knownMass;
134     }
135
136     public void setKnownMass(Double theKnownMass) {
137         knownMass = theKnownMass;
138     }
139
140     public double getDensity() {
141         return density;
142     }
143
144     public void setDensity(double theDensity) {
145         density = theDensity;
146     }
147
148     public String getMaterial() {
149         return material;
150     }
151
152     public void setMaterial(String theMaterial) {
153         material = theMaterial;
154     }
155
156     public String getName() {
157         return name;
158     }
159
160     public void setName(String theName) {
161         name = theName;
162     }
163
164     public Double getKnownCG() {
165         return knownCG;
166     }
167
168     public void setKnownCG(Double theKnownCG) {
169         knownCG = theKnownCG;
170     }
171
172     public int getUseKnownCG() {
173         return useKnownCG;
174     }
175
176     public void setUseKnownCG(int theUseKnownCG) {
177         useKnownCG = theUseKnownCG;
178     }
179
180     public double getXb() {
181         return xb;
182     }
183
184     public void setXb(double theXb) {
185         xb = theXb;
186     }
187
188     public double getCalcMass() {
189         return calcMass;
190     }
191
192     public void setCalcMass(double theCalcMass) {
193         calcMass = theCalcMass;
194     }
195
196     public double getCalcCG() {
197         return calcCG;
198     }
199
200     public void setCalcCG(double theCalcCG) {
201         calcCG = theCalcCG;
202     }
203
204     public int getDensityType() {
205         return densityType;
206     }
207
208     public void setDensityType(int theDensityType) {
209         densityType = theDensityType;
210     }
211
212     public String getRadialLoc() {
213         return radialLoc;
214     }
215
216     public void setRadialLoc(String theRadialLoc) {
217         radialLoc = theRadialLoc;
218     }
219
220     public double getRadialAngle() {
221         return radialAngle;
222     }
223
224     public void setRadialAngle(double theRadialAngle) {
225         radialAngle = theRadialAngle;
226     }
227
228     public int getLocationMode() {
229         return locationMode;
230     }
231
232     public void setLocationMode(int theLocationMode) {
233         locationMode = theLocationMode;
234     }
235
236     public double getLen() {
237         return len;
238     }
239
240     public void setLen(double theLen) {
241         len = theLen;
242     }
243
244     public int getFinishCode() {
245         return finishCode;
246     }
247
248     public void setFinishCode(int theFinishCode) {
249         finishCode = theFinishCode;
250     }
251
252 }