DGP - Fix to non-bulk densities
authorrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 17 Mar 2010 03:22:45 +0000 (03:22 +0000)
committerrodinia814 <rodinia814@180e2498-e6e9-4542-8430-84ac67f01cd8>
Wed, 17 Mar 2010 03:22:45 +0000 (03:22 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@47 180e2498-e6e9-4542-8430-84ac67f01cd8

src/net/sf/openrocket/file/rocksim/BaseHandler.java
src/net/sf/openrocket/file/rocksim/FinSetHandler.java
src/net/sf/openrocket/file/rocksim/ParachuteHandler.java
src/net/sf/openrocket/file/rocksim/RocksimHandler.java

index aad4a330ebddbd5ed546103e47496954227dd159..e9a8469e10fb0d87c1b8a0a9c9512237903aedc2 100644 (file)
@@ -34,17 +34,17 @@ public abstract class BaseHandler<C extends RocketComponent> 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<String, String> attributes, String content, WarningSet warnings)
             throws SAXException {
@@ -57,7 +57,7 @@ public abstract class BaseHandler<C extends RocketComponent> 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<C extends RocketComponent> 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<C extends RocketComponent> 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<C extends RocketComponent> 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) {
index 180edae5e6e56893fe9fe1ead8a7af80378fe15a..fb8add582277643ce564bf69edaff7fb634c9e19 100644 (file)
@@ -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 <code>c</code> 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:
      *                  <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) {
@@ -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;
         }
     }
-    
+
 }
 
index 6f683a45c25b93b744ff07b076766e819dbe2425..f104a07e59f52678f027786ecf2fbe6de8947de9 100644 (file)
@@ -28,7 +28,7 @@ class ParachuteHandler extends PositionDependentHandler<Parachute> {
      * The shroud line density.
      */
     private double shroudLineDensity = 0.0d;
-    
+
     /**
      * Constructor.
      *
@@ -82,7 +82,7 @@ class ParachuteHandler extends PositionDependentHandler<Parachute> {
                 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));
index 4cd29afd0b670a06623d307136cfe072bbff2ee0..51c20514f8503c975d03fa0fb580e3fa225a4327 100644 (file)
@@ -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<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)) {