git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@47
180e2498-e6e9-4542-8430-
84ac67f01cd8
* The material name.
*/
private String materialName = "";
* The material name.
*/
private String materialName = "";
/**
* The SAX method called when the closing element tag is reached.
/**
* The SAX method called when the closing element tag is reached.
* @param element the element name.
* @param attributes attributes of the element.
* @param content the textual content of the element.
* @param warnings the warning set to store warnings in.
* @throws SAXException
*/
* @param element the element name.
* @param attributes attributes of the element.
* @param content the textual content of the element.
* @param warnings the warning set to store warnings in.
* @throws SAXException
*/
@Override
public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
throws SAXException {
@Override
public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
throws SAXException {
mass = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
}
if ("Density".equals(element)) {
mass = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
}
if ("Density".equals(element)) {
- density = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_DENSITY);
+ density = Math.max(0d, Double.parseDouble(content) / getDensityConversion());
}
if ("KnownCG".equals(element)) {
cg = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
}
if ("KnownCG".equals(element)) {
cg = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
/**
* Override the mass and Cg of the component.
/**
* Override the mass and Cg of the component.
* @param component the component
* @param override true if any override should happen
* @param mass the override mass
* @param component the component
* @param override true if any override should happen
* @param mass the override mass
/**
* Some CG positions in Rocksim do not correspond to the CG position reference in OpenRocket.
/**
* Some CG positions in Rocksim do not correspond to the CG position reference in OpenRocket.
* @param theCG the CG value to really use when overriding CG on the OpenRocket component
*/
protected void setCG(double theCG) {
cg = theCG;
}
* @param theCG the CG value to really use when overriding CG on the OpenRocket component
*/
protected void setCG(double theCG) {
cg = theCG;
}
/**
* Set the material name as specified in the Rocksim design file.
/**
* Set the material name as specified in the Rocksim design file.
* @param content the material name
*/
protected void setMaterialName(String content) {
materialName = content;
}
* @param content the material name
*/
protected void setMaterialName(String content) {
materialName = content;
}
/**
* Create a custom material based on the density.
*
* @param type the type of the material
* @param name the name of the component
* @param density the density in g/cm^3
/**
* Create a custom material based on the density.
*
* @param type the type of the material
* @param name the name of the component
* @param density the density in g/cm^3
* @return a Material instance
*/
public static Material createCustomMaterial(Material.Type type, String name, double density) {
return Material.newMaterial(type, "RS: " + name, density, true);
}
* @return a Material instance
*/
public static Material createCustomMaterial(Material.Type type, String name, double density) {
return Material.newMaterial(type, "RS: " + name, density, true);
}
+ /**
+ * Get the appropriate density conversion for different types of materials.
+ *
+ * @return a conversion value that is assumed to be in Rocksim Units / OpenRocket Units
+ */
+ private double getDensityConversion() {
+ switch (getMaterialType()) {
+ case LINE:
+ return RocksimHandler.ROCKSIM_TO_OPENROCKET_LINE_DENSITY;
+ case SURFACE:
+ return RocksimHandler.ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY;
+ case BULK:
+ default:
+ return RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY;
+ }
+ }
+
/**
* Set the material onto an instance of RocketComponent. This is done because only some subtypes of RocketComponent
* have the setMaterial method. Unfortunately the supertype cannot be used.
/**
* Set the material onto an instance of RocketComponent. This is done because only some subtypes of RocketComponent
* have the setMaterial method. Unfortunately the supertype cannot be used.
* @param component the component who's material is to be seta
* @param name the method name
* @param args the class types of the parameters
* @param component the component who's material is to be seta
* @param name the method name
* @param args the class types of the parameters
* @return the Method instance, or null
*/
private static Method getMethod(RocketComponent component, String name, Class[] args) {
* @return the Method instance, or null
*/
private static Method getMethod(RocketComponent component, String name, Class[] args) {
* The Rocksim calculated cg.
*/
private Double calcCg = 0d;
* The Rocksim calculated cg.
*/
private Double calcCg = 0d;
/**
* Constructor.
*
* @param c the parent
/**
* Constructor.
*
* @param c the parent
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public FinSetHandler(RocketComponent c) throws IllegalArgumentException {
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
public FinSetHandler(RocketComponent c) throws IllegalArgumentException {
mass = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
}
if ("Density".equals(element)) {
mass = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
}
if ("Density".equals(element)) {
- density = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_DENSITY);
+ density = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY);
}
if ("KnownCG".equals(element)) {
cg = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
}
if ("KnownCG".equals(element)) {
cg = Math.max(0d, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS);
* @param pointList a comma and pipe delimited string of X,Y coordinates from Rocksim. This is of the format:
* <pre>x0,y0|x1,y1|x2,y2|... </pre>
* @param warnings the warning set to convey incompatibilities to the user
* @param pointList a comma and pipe delimited string of X,Y coordinates from Rocksim. This is of the format:
* <pre>x0,y0|x1,y1|x2,y2|... </pre>
* @param warnings the warning set to convey incompatibilities to the user
* @return an array of OpenRocket Coordinates
*/
private Coordinate[] toCoordinates(String pointList, WarningSet warnings) {
* @return an array of OpenRocket Coordinates
*/
private Coordinate[] toCoordinates(String pointList, WarningSet warnings) {
}
}
if (!result.isEmpty()) {
}
}
if (!result.isEmpty()) {
- //OpenRocket requires fin plan points be ordered from leading root chord to trailing root chord in the
+ //OpenRocket requires fin plan points be ordered from leading root chord to trailing root chord in the
//Coordinate array.
Coordinate last = result.get(result.size() - 1);
if (last.x == 0 && last.y == 0) {
//Coordinate array.
Coordinate last = result.get(result.size() - 1);
if (last.x == 0 && last.y == 0) {
return FinSet.CrossSection.SQUARE;
}
}
return FinSet.CrossSection.SQUARE;
}
}
* The shroud line density.
*/
private double shroudLineDensity = 0.0d;
* The shroud line density.
*/
private double shroudLineDensity = 0.0d;
warnings.add("Parachute spill holes are not supported. Ignoring.");
}
if ("ShroudLineMassPerMM".equals(element)) {
warnings.add("Parachute spill holes are not supported. Ignoring.");
}
if ("ShroudLineMassPerMM".equals(element)) {
- shroudLineDensity = Double.parseDouble(content) * 10d/ RocksimHandler.ROCKSIM_TO_OPENROCKET_DENSITY;
+ shroudLineDensity = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LINE_DENSITY;
}
if ("ShroudLineMaterial".equals(element)) {
chute.setLineMaterial(BaseHandler.createCustomMaterial(Material.Type.LINE, content, shroudLineDensity));
}
if ("ShroudLineMaterial".equals(element)) {
chute.setLineMaterial(BaseHandler.createCustomMaterial(Material.Type.LINE, content, shroudLineDensity));
public static final int ROCKSIM_TO_OPENROCKET_MASS = 1000;
/**
public static final int ROCKSIM_TO_OPENROCKET_MASS = 1000;
/**
- * Density conversion. Rocksim is in milligrams/cubic centimeter, OpenRocket in grams/cubic centimeter.
+ * Bulk Density conversion. Rocksim is in kilograms/cubic meter, OpenRocket in kilograms/cubic meter.
- public static final int ROCKSIM_TO_OPENROCKET_DENSITY = 1;
+ public static final int ROCKSIM_TO_OPENROCKET_BULK_DENSITY = 1;
+
+ /**
+ * Surface Density conversion. Rocksim is in grams/sq centimeter, OpenRocket in kilograms/sq meter. 1000/(100*100) = 1/10
+ */
+ public static final double ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY = 1/10d;
+
+ /**
+ * Line Density conversion. Rocksim is in kilograms/meter, OpenRocket in kilograms/meter.
+ */
+ public static final int ROCKSIM_TO_OPENROCKET_LINE_DENSITY = 1;
/**
* Radius conversion. Rocksim is always in diameters, OpenRocket mostly in radius.
/**
* Radius conversion. Rocksim is always in diameters, OpenRocket mostly in radius.
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
/**
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
/**
- * In Rocksim stages are from the top down, so a single stage rocket is actually stage '3'. A 2-stage
+ * In Rocksim stages are from the top down, so a single stage rocket is actually stage '3'. A 2-stage
* rocket defines stage '2' as the initial booster with stage '3' sitting atop it. And so on.
*/
if ("Stage3Parts".equals(element)) {
* rocket defines stage '2' as the initial booster with stage '3' sitting atop it. And so on.
*/
if ("Stage3Parts".equals(element)) {