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