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 * @throws IllegalArgumentException thrown if <code>c</code> is null
32 public InnerBodyTubeHandler(RocketComponent c) throws IllegalArgumentException {
34 throw new IllegalArgumentException("The parent component of an inner tube may not be null.");
36 bodyTube = new InnerTube();
41 public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
42 if ("AttachedParts".equals(element)) {
43 return new AttachedPartsHandler(bodyTube);
45 return PlainTextHandler.INSTANCE;
49 public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
51 super.closeElement(element, attributes, content, warnings);
54 if ("OD".equals(element)) {
55 bodyTube.setOuterRadius(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS);
57 if ("ID".equals(element)) {
58 final double r = Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS;
59 bodyTube.setInnerRadius(r);
61 if ("Len".equals(element)) {
62 bodyTube.setLength(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
64 if ("IsMotorMount".equals(element)) {
65 bodyTube.setMotorMount("1".equals(content));
67 if ("EngineOverhang".equals(element)) {
68 bodyTube.setMotorOverhang(Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH);
70 if ("Material".equals(element)) {
71 setMaterialName(content);
74 catch (NumberFormatException nfe) {
75 warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
80 * Get the InnerTube component this handler is working upon.
82 * @return an InnerTube component
85 public InnerTube getComponent() {
90 * Set the relative position onto the component. This cannot be done directly because setRelativePosition is not
91 * public in all components.
93 * @param position the OpenRocket position
96 public void setRelativePosition(RocketComponent.Position position) {
97 bodyTube.setRelativePosition(position);
101 * Get the required type of material for this component.
106 public Material.Type getMaterialType() {
107 return Material.Type.BULK;