1 package net.sf.openrocket.file.rocksim.export;
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.RecoveryDevice;
10 import net.sf.openrocket.rocketcomponent.RocketComponent;
11 import net.sf.openrocket.rocketcomponent.StructuralComponent;
13 import javax.xml.bind.annotation.XmlAccessType;
14 import javax.xml.bind.annotation.XmlAccessorType;
15 import javax.xml.bind.annotation.XmlElement;
16 import javax.xml.bind.annotation.XmlRootElement;
21 @XmlAccessorType(XmlAccessType.FIELD)
22 public abstract class BasePartDTO {
24 @XmlElement(name = "KnownMass")
25 private Double knownMass = 0d;
26 @XmlElement(name = "Density")
27 private double density = 0d;
28 @XmlElement(name = "Material")
29 private String material = "";
30 @XmlElement(name = "Name")
31 private String name = "";
32 @XmlElement(name = "KnownCG")
33 private Double knownCG = null;
34 @XmlElement(name = "UseKnownCG")
35 private int useKnownCG = 1;
36 @XmlElement(name = "Xb")
37 private double xb = 0;
38 @XmlElement(name = "CalcMass")
39 private double calcMass = 0d;
40 @XmlElement(name = "CalcCG")
41 private double calcCG = 0d;
42 @XmlElement(name = "DensityType")
43 private int densityType = 0;
44 @XmlElement(name = "RadialLoc")
45 private String radialLoc = "0.";
46 @XmlElement(name = "RadialAngle")
47 private double radialAngle = 0;
48 @XmlElement(name = "LocationMode")
49 private int locationMode = 0;
50 @XmlElement(name = "Len")
51 private double len = 0d;
52 @XmlElement(name = "FinishCode")
53 private int finishCode = 0;
55 protected BasePartDTO() {
58 protected BasePartDTO(RocketComponent ec) {
59 setCalcCG(ec.getCG().x * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
60 setCalcMass(ec.getComponentMass() * RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
61 setKnownCG(ec.getOverrideCGX() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
62 setKnownMass(ec.getOverrideMass() * RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
63 setLen(ec.getLength() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
64 setUseKnownCG(ec.isCGOverridden() || ec.isMassOverridden() ? 1 : 0);
65 setName(ec.getName());
67 setXb(ec.getPositionValue() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
68 if (ec instanceof ExternalComponent) {
69 ExternalComponent comp = (ExternalComponent) ec;
70 setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
72 if (comp.getRelativePosition().equals(RocketComponent.Position.BOTTOM)) {
75 setDensity(comp.getMaterial().getDensity() * RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
76 setDensityType(RocksimDensityType.toCode(comp.getMaterial().getType()));
77 String material = comp.getMaterial().getName();
78 if (material.startsWith(BaseHandler.ROCKSIM_MATERIAL_PREFIX)) {
79 material = material.substring(BaseHandler.ROCKSIM_MATERIAL_PREFIX.length());
81 setMaterial(material);
83 setFinishCode(RocksimFinishCode.toCode(comp.getFinish()));
85 else if (ec instanceof StructuralComponent) {
86 StructuralComponent comp = (StructuralComponent) ec;
88 setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
89 if (comp.getRelativePosition().equals(RocketComponent.Position.BOTTOM)) {
92 setDensity(comp.getMaterial().getDensity() * RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
93 setDensityType(RocksimDensityType.toCode(comp.getMaterial().getType()));
94 String material = comp.getMaterial().getName();
95 if (material.startsWith(BaseHandler.ROCKSIM_MATERIAL_PREFIX)) {
96 material = material.substring(BaseHandler.ROCKSIM_MATERIAL_PREFIX.length());
98 setMaterial(material);
100 else if (ec instanceof RecoveryDevice) {
101 RecoveryDevice comp = (RecoveryDevice) ec;
103 setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
104 if (comp.getRelativePosition().equals(RocketComponent.Position.BOTTOM)) {
107 setDensity(comp.getMaterial().getDensity() * RocksimHandler.ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY);
108 setDensityType(RocksimDensityType.toCode(comp.getMaterial().getType()));
109 String material = comp.getMaterial().getName();
110 if (material.startsWith(BaseHandler.ROCKSIM_MATERIAL_PREFIX)) {
111 material = material.substring(BaseHandler.ROCKSIM_MATERIAL_PREFIX.length());
113 setMaterial(material);
118 public Double getKnownMass() {
122 public void setKnownMass(Double theKnownMass) {
123 knownMass = theKnownMass;
126 public double getDensity() {
130 public void setDensity(double theDensity) {
131 density = theDensity;
134 public String getMaterial() {
138 public void setMaterial(String theMaterial) {
139 material = theMaterial;
142 public String getName() {
146 public void setName(String theName) {
150 public Double getKnownCG() {
154 public void setKnownCG(Double theKnownCG) {
155 knownCG = theKnownCG;
158 public int getUseKnownCG() {
162 public void setUseKnownCG(int theUseKnownCG) {
163 useKnownCG = theUseKnownCG;
166 public double getXb() {
170 public void setXb(double theXb) {
174 public double getCalcMass() {
178 public void setCalcMass(double theCalcMass) {
179 calcMass = theCalcMass;
182 public double getCalcCG() {
186 public void setCalcCG(double theCalcCG) {
190 public int getDensityType() {
194 public void setDensityType(int theDensityType) {
195 densityType = theDensityType;
198 public String getRadialLoc() {
202 public void setRadialLoc(String theRadialLoc) {
203 radialLoc = theRadialLoc;
206 public double getRadialAngle() {
210 public void setRadialAngle(double theRadialAngle) {
211 radialAngle = theRadialAngle;
214 public int getLocationMode() {
218 public void setLocationMode(int theLocationMode) {
219 locationMode = theLocationMode;
222 public double getLen() {
226 public void setLen(double theLen) {
230 public int getFinishCode() {
234 public void setFinishCode(int theFinishCode) {
235 finishCode = theFinishCode;