From: rodinia814 Date: Wed, 17 Mar 2010 03:22:45 +0000 (+0000) Subject: DGP - Fix to non-bulk densities X-Git-Tag: upstream/1.1.0~2^2~7 X-Git-Url: https://git.gag.com/?p=debian%2Fopenrocket;a=commitdiff_plain;h=6d71a8c4a93455ea8d3df1ed42d33b941847efcc DGP - Fix to non-bulk densities git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@47 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/src/net/sf/openrocket/file/rocksim/BaseHandler.java b/src/net/sf/openrocket/file/rocksim/BaseHandler.java index aad4a330..e9a8469e 100644 --- a/src/net/sf/openrocket/file/rocksim/BaseHandler.java +++ b/src/net/sf/openrocket/file/rocksim/BaseHandler.java @@ -34,17 +34,17 @@ public abstract class BaseHandler extends ElementHand * The material name. */ private String materialName = ""; - + /** * 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 */ - + @Override public void closeElement(String element, HashMap attributes, String content, WarningSet warnings) throws SAXException { @@ -57,7 +57,7 @@ public abstract class BaseHandler extends ElementHand 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); @@ -102,7 +102,7 @@ public abstract class BaseHandler extends ElementHand /** * 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 @@ -134,35 +134,52 @@ public abstract class BaseHandler extends ElementHand /** * 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; } - + /** * Set the material name as specified in the Rocksim design file. - * + * * @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 - * + * * @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. @@ -189,7 +206,7 @@ public abstract class BaseHandler extends ElementHand * @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) { diff --git a/src/net/sf/openrocket/file/rocksim/FinSetHandler.java b/src/net/sf/openrocket/file/rocksim/FinSetHandler.java index 180edae5..fb8add58 100644 --- a/src/net/sf/openrocket/file/rocksim/FinSetHandler.java +++ b/src/net/sf/openrocket/file/rocksim/FinSetHandler.java @@ -134,13 +134,13 @@ class FinSetHandler extends ElementHandler { * The Rocksim calculated cg. */ private Double calcCg = 0d; - + /** * Constructor. * * @param c the parent - * + * * @throws IllegalArgumentException thrown if c is null */ public FinSetHandler(RocketComponent c) throws IllegalArgumentException { @@ -220,7 +220,7 @@ class FinSetHandler extends ElementHandler { 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); @@ -314,7 +314,7 @@ class FinSetHandler extends ElementHandler { * @param pointList a comma and pipe delimited string of X,Y coordinates from Rocksim. This is of the format: *
x0,y0|x1,y1|x2,y2|... 
* @param warnings the warning set to convey incompatibilities to the user - * + * * @return an array of OpenRocket Coordinates */ private Coordinate[] toCoordinates(String pointList, WarningSet warnings) { @@ -339,7 +339,7 @@ class FinSetHandler extends ElementHandler { } } 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) { @@ -370,6 +370,6 @@ class FinSetHandler extends ElementHandler { return FinSet.CrossSection.SQUARE; } } - + } diff --git a/src/net/sf/openrocket/file/rocksim/ParachuteHandler.java b/src/net/sf/openrocket/file/rocksim/ParachuteHandler.java index 6f683a45..f104a07e 100644 --- a/src/net/sf/openrocket/file/rocksim/ParachuteHandler.java +++ b/src/net/sf/openrocket/file/rocksim/ParachuteHandler.java @@ -28,7 +28,7 @@ class ParachuteHandler extends PositionDependentHandler { * The shroud line density. */ private double shroudLineDensity = 0.0d; - + /** * Constructor. * @@ -82,7 +82,7 @@ class ParachuteHandler extends PositionDependentHandler { 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)); diff --git a/src/net/sf/openrocket/file/rocksim/RocksimHandler.java b/src/net/sf/openrocket/file/rocksim/RocksimHandler.java index 4cd29afd..51c20514 100644 --- a/src/net/sf/openrocket/file/rocksim/RocksimHandler.java +++ b/src/net/sf/openrocket/file/rocksim/RocksimHandler.java @@ -36,9 +36,19 @@ public class RocksimHandler extends ElementHandler { 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. @@ -210,7 +220,7 @@ class RocketDesignHandler extends ElementHandler { @Override public ElementHandler openElement(String element, HashMap 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)) {