/**
* A SAX handler for Rocksim's Parachute XML type.
- * <p/>
*/
-class ParachuteHandler extends PositionDependentHandler<Parachute> {
+class ParachuteHandler extends RecoveryDeviceHandler<Parachute> {
/**
* The OpenRocket Parachute instance
*/
* The shroud line density.
*/
private double shroudLineDensity = 0.0d;
-
+
/**
* Constructor.
*
* @param c the parent component
+ * @param warnings the warning set
+ *
* @throws IllegalArgumentException thrown if <code>c</code> is null
*/
- public ParachuteHandler(RocketComponent c) throws IllegalArgumentException {
+ public ParachuteHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
if (c == null) {
throw new IllegalArgumentException("The parent of a parachute may not be null.");
}
chute = new Parachute();
- c.addChild(chute);
+ if (isCompatible(c, Parachute.class, warnings)) {
+ c.addChild(chute);
+ }
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
return PlainTextHandler.INSTANCE;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
throws SAXException {
chute.setLineCount(Math.max(0, Integer.parseInt(content)));
}
if ("ShroudLineLen".equals(element)) {
- chute.setLineLength(Math.max(0, Double.parseDouble(
- content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH));
+ chute.setLineLength(Math.max(0, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH));
}
if ("SpillHoleDia".equals(element)) {
//Not supported in OpenRocket
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));
return chute;
}
- /**
- * Set the relative position onto the component. This cannot be done directly because setRelativePosition is not
- * public in all components.
- *
- * @param position the OpenRocket position
- */
- public void setRelativePosition(RocketComponent.Position position) {
- chute.setRelativePosition(position);
- }
-
- /**
- * Get the required type of material for this component.
- *
- * @return BULK
- */
- @Override
- public Material.Type getMaterialType() {
- return Material.Type.SURFACE;
- }
-
}