2 * LaunchLugHandler.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.LaunchLug;
11 import net.sf.openrocket.rocketcomponent.RocketComponent;
12 import org.xml.sax.SAXException;
14 import java.util.HashMap;
17 * The SAX handler for Rocksim Launch Lugs.
19 class LaunchLugHandler extends PositionDependentHandler<LaunchLug> {
22 * The OpenRocket LaunchLug instance.
24 private final LaunchLug lug;
30 * @param warnings the warning set
32 * @throws IllegalArgumentException thrown if <code>c</code> is null
34 public LaunchLugHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
36 throw new IllegalArgumentException("The parent component of a launch lug may not be null.");
38 lug = new LaunchLug();
39 if (isCompatible(c, LaunchLug.class, warnings)) {
45 public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
46 return PlainTextHandler.INSTANCE;
50 public void closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
52 super.closeElement(element, attributes, content, warnings);
55 if ("OD".equals(element)) {
56 lug.setRadius(Math.max(0, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS));
58 if ("ID".equals(element)) {
59 lug.setInnerRadius(Math.max(0, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS));
61 if ("Len".equals(element)) {
62 lug.setLength(Math.max(0, Double.parseDouble(content) / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH));
64 if ("Material".equals(element)) {
65 setMaterialName(content);
67 if ("RadialAngle".equals(element)) {
68 lug.setRadialDirection(Double.parseDouble(content));
70 if ("FinishCode".equals(element)) {
71 lug.setFinish(RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket());
74 catch (NumberFormatException nfe) {
75 warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
80 * Get the LaunchLug component this handler is working upon.
82 * @return a LaunchLug component
85 public LaunchLug 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 lug.setRelativePosition(position);
101 * Get the required type of material for this component.
106 public Material.Type getMaterialType() {
107 return Material.Type.BULK;