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;
20 * The base class for all OpenRocket to Rocksim conversions.
23 @XmlAccessorType(XmlAccessType.FIELD)
24 public abstract class BasePartDTO {
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;
58 * Default constructor.
60 protected BasePartDTO() {
64 * Copy constructor of sorts, that performs all common conversions for components.
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);
76 setUseKnownCG(ec.isCGOverridden() || ec.isMassOverridden() ? 1 : 0);
77 setName(ec.getName());
79 setXb(ec.getPositionValue() * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
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);
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);
92 if (ec instanceof ExternalComponent) {
93 ExternalComponent comp = (ExternalComponent) ec;
94 setLocationMode(RocksimLocationMode.toCode(comp.getRelativePosition()));
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());
102 setMaterial(material);
104 setFinishCode(RocksimFinishCode.toCode(comp.getFinish()));
106 else if (ec instanceof StructuralComponent) {
107 StructuralComponent comp = (StructuralComponent) ec;
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());
116 setMaterial(material);
118 else if (ec instanceof RecoveryDevice) {
119 RecoveryDevice comp = (RecoveryDevice) ec;
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());
128 setMaterial(material);
132 public Double getKnownMass() {
136 public void setKnownMass(Double theKnownMass) {
137 knownMass = theKnownMass;
140 public double getDensity() {
144 public void setDensity(double theDensity) {
145 density = theDensity;
148 public String getMaterial() {
152 public void setMaterial(String theMaterial) {
153 material = theMaterial;
156 public String getName() {
160 public void setName(String theName) {
164 public Double getKnownCG() {
168 public void setKnownCG(Double theKnownCG) {
169 knownCG = theKnownCG;
172 public int getUseKnownCG() {
176 public void setUseKnownCG(int theUseKnownCG) {
177 useKnownCG = theUseKnownCG;
180 public double getXb() {
184 public void setXb(double theXb) {
188 public double getCalcMass() {
192 public void setCalcMass(double theCalcMass) {
193 calcMass = theCalcMass;
196 public double getCalcCG() {
200 public void setCalcCG(double theCalcCG) {
204 public int getDensityType() {
208 public void setDensityType(int theDensityType) {
209 densityType = theDensityType;
212 public String getRadialLoc() {
216 public void setRadialLoc(String theRadialLoc) {
217 radialLoc = theRadialLoc;
220 public double getRadialAngle() {
224 public void setRadialAngle(double theRadialAngle) {
225 radialAngle = theRadialAngle;
228 public int getLocationMode() {
232 public void setLocationMode(int theLocationMode) {
233 locationMode = theLocationMode;
236 public double getLen() {
240 public void setLen(double theLen) {
244 public int getFinishCode() {
248 public void setFinishCode(int theFinishCode) {
249 finishCode = theFinishCode;