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;
* <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.
/**
* Handles the content of the <DesignInformation> tag.
*/
-class RocksimContentHandler extends ElementHandler {
+class RocksimContentHandler extends AbstractElementHandler {
/**
* The OpenRocketDocument that is the container for the rocket.
*/
@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;
* 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;
}
}
* 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.
*/
return new StageHandler(stage);
}
}
- if ("Name".equals(element)) {
+ if (RocksimCommonConstants.NAME.equals(element)) {
return PlainTextHandler.INSTANCE;
}
if ("StageCount".equals(element)) {
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) {
/**
* A SAX handler for a Rocksim stage.
*/
-class StageHandler extends ElementHandler {
+class StageHandler extends AbstractElementHandler {
/**
* The parent OpenRocket component.
*/
@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;