2 * InnerBodyTubeHandler.java
4 package net.sf.openrocket.file.rocksim;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.simplesax.ElementHandler;
8 import net.sf.openrocket.file.simplesax.PlainTextHandler;
9 import net.sf.openrocket.material.Material;
10 import net.sf.openrocket.rocketcomponent.InnerTube;
11 import net.sf.openrocket.rocketcomponent.RocketComponent;
12 import org.xml.sax.SAXException;
14 import java.util.HashMap;
17 * A SAX handler for Rocksim inside tubes.
19 class InnerBodyTubeHandler extends PositionDependentHandler<InnerTube> {
22 * The OpenRocket InnerTube instance.
24 private final InnerTube bodyTube;
29 * @param c the parent component
30 * @param warnings the warning set
31 * @throws IllegalArgumentException thrown if <code>c</code> is null
33 public InnerBodyTubeHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
35 throw new IllegalArgumentException("The parent component of an inner tube may not be null.");
37 bodyTube = new InnerTube();
38 if (isCompatible(c, InnerTube.class, warnings)) {
44 public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
45 if ("AttachedParts".equals(element)) {
46 return new AttachedPartsHandler(bodyTube);
48 return PlainTextHandler.INSTANCE;
52 public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
54 super.closeElement(element, attributes, content, warnings);
57 if ("OD".equals(element)) {
58 bodyTube.setOuterRadius(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS);
60 if ("ID".equals(element)) {
61 final double r = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS;
62 bodyTube.setInnerRadius(r);
64 if ("Len".equals(element)) {
65 bodyTube.setLength(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
67 if ("IsMotorMount".equals(element)) {
68 bodyTube.setMotorMount("1".equals(content));
70 if ("EngineOverhang".equals(element)) {
71 bodyTube.setMotorOverhang(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
73 if ("Material".equals(element)) {
74 setMaterialName(content);
77 catch (NumberFormatException nfe) {
78 warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
83 * Get the InnerTube component this handler is working upon.
85 * @return an InnerTube component
88 public InnerTube getComponent() {
93 * Set the relative position onto the component. This cannot be done directly because setRelativePosition is not
94 * public in all components.
96 * @param position the OpenRocket position
99 public void setRelativePosition(RocketComponent.Position position) {
100 bodyTube.setRelativePosition(position);
104 * Get the required type of material for this component.
109 public Material.Type getMaterialType() {
110 return Material.Type.BULK;