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.FinSet;
10 import net.sf.openrocket.rocketcomponent.RecoveryDevice;
11 import net.sf.openrocket.rocketcomponent.RocketComponent;
12 import net.sf.openrocket.rocketcomponent.StructuralComponent;
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;
22 @XmlAccessorType(XmlAccessType.FIELD)
23 public abstract class BasePartDTO {
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;
56 protected BasePartDTO() {
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);
67 setUseKnownCG(ec.isCGOverridden() || ec.isMassOverridden() ? 1 : 0);
68 setName(ec.getName());
70 setXb(ec.getPositionValue() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
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);
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);
83 if (ec instanceof ExternalComponent) {
84 ExternalComponent comp = (ExternalComponent) ec;
85 setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
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());
93 setMaterial(material);
95 setFinishCode(RocksimFinishCode.toCode(comp.getFinish()));
97 else if (ec instanceof StructuralComponent) {
98 StructuralComponent comp = (StructuralComponent) ec;
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());
107 setMaterial(material);
109 else if (ec instanceof RecoveryDevice) {
110 RecoveryDevice comp = (RecoveryDevice) ec;
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());
119 setMaterial(material);
124 public Double getKnownMass() {
128 public void setKnownMass(Double theKnownMass) {
129 knownMass = theKnownMass;
132 public double getDensity() {
136 public void setDensity(double theDensity) {
137 density = theDensity;
140 public String getMaterial() {
144 public void setMaterial(String theMaterial) {
145 material = theMaterial;
148 public String getName() {
152 public void setName(String theName) {
156 public Double getKnownCG() {
160 public void setKnownCG(Double theKnownCG) {
161 knownCG = theKnownCG;
164 public int getUseKnownCG() {
168 public void setUseKnownCG(int theUseKnownCG) {
169 useKnownCG = theUseKnownCG;
172 public double getXb() {
176 public void setXb(double theXb) {
180 public double getCalcMass() {
184 public void setCalcMass(double theCalcMass) {
185 calcMass = theCalcMass;
188 public double getCalcCG() {
192 public void setCalcCG(double theCalcCG) {
196 public int getDensityType() {
200 public void setDensityType(int theDensityType) {
201 densityType = theDensityType;
204 public String getRadialLoc() {
208 public void setRadialLoc(String theRadialLoc) {
209 radialLoc = theRadialLoc;
212 public double getRadialAngle() {
216 public void setRadialAngle(double theRadialAngle) {
217 radialAngle = theRadialAngle;
220 public int getLocationMode() {
224 public void setLocationMode(int theLocationMode) {
225 locationMode = theLocationMode;
228 public double getLen() {
232 public void setLen(double theLen) {
236 public int getFinishCode() {
240 public void setFinishCode(int theFinishCode) {
241 finishCode = theFinishCode;