create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / file / rocksim / importt / RocksimHandler.java
index 7d2d527a86940695277c8f5f971cf06f15e58700..bf41c1687ec690bc9585b4fa3abf001ff89f8233 100644 (file)
@@ -7,6 +7,8 @@ package net.sf.openrocket.file.rocksim.importt;
 import net.sf.openrocket.aerodynamics.Warning;
 import net.sf.openrocket.aerodynamics.WarningSet;
 import net.sf.openrocket.document.OpenRocketDocument;
+import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
+import net.sf.openrocket.file.simplesax.AbstractElementHandler;
 import net.sf.openrocket.file.simplesax.ElementHandler;
 import net.sf.openrocket.file.simplesax.PlainTextHandler;
 import net.sf.openrocket.rocketcomponent.Rocket;
@@ -23,37 +25,7 @@ import java.util.HashMap;
  * <p/>
  * Limitations: Rocksim flight simulations are not imported; tube fins are not supported; Rocksim 'pods' are not supported.
  */
-public class RocksimHandler extends ElementHandler {
-
-    /**
-     * Length conversion.  Rocksim is in millimeters, OpenRocket in meters.
-     */
-    public static final int ROCKSIM_TO_OPENROCKET_LENGTH = 1000;
-
-    /**
-     * Mass conversion.  Rocksim is in grams, OpenRocket in kilograms.
-     */
-    public static final int ROCKSIM_TO_OPENROCKET_MASS = 1000;
-
-    /**
-     * Bulk Density conversion.  Rocksim is in kilograms/cubic meter, OpenRocket in kilograms/cubic meter.
-     */
-    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.
-     */
-    public static final int ROCKSIM_TO_OPENROCKET_RADIUS = 2 * ROCKSIM_TO_OPENROCKET_LENGTH;
+public class RocksimHandler extends AbstractElementHandler {
 
     /**
      * The main content handler.
@@ -96,7 +68,7 @@ public class RocksimHandler extends ElementHandler {
 /**
  * Handles the content of the <DesignInformation> tag.
  */
-class RocksimContentHandler extends ElementHandler {
+class RocksimContentHandler extends AbstractElementHandler {
     /**
      * The OpenRocketDocument that is the container for the rocket.
      */
@@ -132,15 +104,15 @@ class RocksimContentHandler extends ElementHandler {
     @Override
     public ElementHandler openElement(String element, HashMap<String, String> attributes,
                                       WarningSet warnings) {
-        if ("DesignInformation".equals(element)) {
+        if (RocksimCommonConstants.DESIGN_INFORMATION.equals(element)) {
             //The next sub-element is "RocketDesign", which is really the only thing that matters.  Rather than
             //create another handler just for that element, handle it here.
             return this;
         }
-        if ("FileVersion".equals(element)) {
+        if (RocksimCommonConstants.FILE_VERSION.equals(element)) {
             return PlainTextHandler.INSTANCE;
         }
-        if ("RocketDesign".equals(element)) {
+        if (RocksimCommonConstants.ROCKET_DESIGN.equals(element)) {
             return new RocketDesignHandler(rocket);
         }
         return null;
@@ -153,7 +125,7 @@ class RocksimContentHandler extends ElementHandler {
          * SAX handler for Rocksim file version number.  The value is not used currently, but could be used in the future
          * for backward/forward compatibility reasons (different lower level handlers could be called via a strategy pattern).
          */
-        if ("FileVersion".equals(element)) {
+        if (RocksimCommonConstants.FILE_VERSION.equals(element)) {
             version = content;
         }
     }
@@ -174,7 +146,7 @@ class RocksimContentHandler extends ElementHandler {
  * Correct functioning of this handler is predicated on the stage count element appearing before the actual stage parts
  * structures.  If that invariant is not true, then behavior will be unpredictable.
  */
-class RocketDesignHandler extends ElementHandler {
+class RocketDesignHandler extends AbstractElementHandler {
     /**
      * The parent component.
      */
@@ -272,7 +244,7 @@ class RocketDesignHandler extends ElementHandler {
                 return new StageHandler(stage);
             }
         }
-        if ("Name".equals(element)) {
+        if (RocksimCommonConstants.NAME.equals(element)) {
             return PlainTextHandler.INSTANCE;
         }
         if ("StageCount".equals(element)) {
@@ -303,29 +275,29 @@ class RocketDesignHandler extends ElementHandler {
     public void closeElement(String element, HashMap<String, String> attributes,
                              String content, WarningSet warnings) throws SAXException {
         try {
-            if ("Name".equals(element)) {
+            if (RocksimCommonConstants.NAME.equals(element)) {
                 component.setName(content);
             }
             if ("StageCount".equals(element)) {
                 stageCount = Integer.parseInt(content);
             }
             if ("Stage3Mass".equals(element)) {
-                stage3Mass = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS;
+                stage3Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
             }
             if ("Stage2Mass".equals(element)) {
-                stage2Mass = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS;
+                stage2Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
             }
             if ("Stage1Mass".equals(element)) {
-                stage1Mass = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS;
+                stage1Mass = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS;
             }
             if ("Stage3CG".equals(element)) {
-                stage3CG = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+                stage3CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
             if ("Stage2CGAlone".equals(element)) {
-                stage2CG = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+                stage2CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
             if ("Stage1CGAlone".equals(element)) {
-                stage1CG = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH;
+                stage1CG = Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH;
             }
         }
         catch (NumberFormatException nfe) {
@@ -338,7 +310,7 @@ class RocketDesignHandler extends ElementHandler {
 /**
  * A SAX handler for a Rocksim stage.
  */
-class StageHandler extends ElementHandler {
+class StageHandler extends AbstractElementHandler {
     /**
      * The parent OpenRocket component.
      */
@@ -359,13 +331,13 @@ class StageHandler extends ElementHandler {
 
     @Override
     public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
-        if ("NoseCone".equals(element)) {
+        if (RocksimCommonConstants.NOSE_CONE.equals(element)) {
             return new NoseConeHandler(component, warnings);
         }
-        if ("BodyTube".equals(element)) {
+        if (RocksimCommonConstants.BODY_TUBE.equals(element)) {
             return new BodyTubeHandler(component, warnings);
         }
-        if ("Transition".equals(element)) {
+        if (RocksimCommonConstants.TRANSITION.equals(element)) {
             return new TransitionHandler(component, warnings);
         }
         return null;