2 * LaunchLugHandler.java
4 package net.sf.openrocket.file.rocksim.importt;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
8 import net.sf.openrocket.file.rocksim.RocksimFinishCode;
9 import net.sf.openrocket.file.simplesax.ElementHandler;
10 import net.sf.openrocket.file.simplesax.PlainTextHandler;
11 import net.sf.openrocket.material.Material;
12 import net.sf.openrocket.rocketcomponent.LaunchLug;
13 import net.sf.openrocket.rocketcomponent.RocketComponent;
14 import org.xml.sax.SAXException;
16 import java.util.HashMap;
19 * The SAX handler for Rocksim Launch Lugs.
21 class LaunchLugHandler extends PositionDependentHandler<LaunchLug> {
24 * The OpenRocket LaunchLug instance.
26 private final LaunchLug lug;
32 * @param warnings the warning set
34 * @throws IllegalArgumentException thrown if <code>c</code> is null
36 public LaunchLugHandler(RocketComponent c, WarningSet warnings) throws IllegalArgumentException {
38 throw new IllegalArgumentException("The parent component of a launch lug may not be null.");
40 lug = new LaunchLug();
41 if (isCompatible(c, LaunchLug.class, warnings)) {
47 public ElementHandler openElement(String element, HashMap<String, String> attributes, WarningSet warnings) {
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 (RocksimCommonConstants.OD.equals(element)) {
58 lug.setOuterRadius(Math.max(0, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS));
60 if (RocksimCommonConstants.ID.equals(element)) {
61 lug.setInnerRadius(Math.max(0, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_RADIUS));
63 if (RocksimCommonConstants.LEN.equals(element)) {
64 lug.setLength(Math.max(0, Double.parseDouble(content) / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LENGTH));
66 if (RocksimCommonConstants.MATERIAL.equals(element)) {
67 setMaterialName(content);
69 if (RocksimCommonConstants.RADIAL_ANGLE.equals(element)) {
70 lug.setRadialDirection(Double.parseDouble(content));
72 if (RocksimCommonConstants.FINISH_CODE.equals(element)) {
73 lug.setFinish(RocksimFinishCode.fromCode(Integer.parseInt(content)).asOpenRocket());
76 catch (NumberFormatException nfe) {
77 warnings.add("Could not convert " + element + " value of " + content + ". It is expected to be a number.");
82 * Get the LaunchLug component this handler is working upon.
84 * @return a LaunchLug component
87 public LaunchLug getComponent() {
92 * Set the relative position onto the component. This cannot be done directly because setRelativePosition is not
93 * public in all components.
95 * @param position the OpenRocket position
98 public void setRelativePosition(RocketComponent.Position position) {
99 lug.setRelativePosition(position);
103 * Get the required type of material for this component.
108 public Material.Type getMaterialType() {
109 return Material.Type.BULK;