2 * RocksimLocationMode.java
4 package net.sf.openrocket.file.rocksim;
6 import net.sf.openrocket.rocketcomponent.RocketComponent;
9 * Models the relative position of parts on a rocket. Maps from Rocksim's notion to OpenRocket's.
11 enum RocksimLocationMode {
12 FRONT_OF_OWNING_PART (0, RocketComponent.Position.TOP),
13 FROM_TIP_OF_NOSE (1, RocketComponent.Position.ABSOLUTE),
14 BACK_OF_OWNING_PART (2, RocketComponent.Position.BOTTOM);
16 /** The value Rocksim uses internally (and in the XML file). */
17 private final int ordinal;
19 /** The OpenRocket position equivalent. */
20 private final RocketComponent.Position position;
25 * @param idx the rocksim enum value
26 * @param theOpenRocketPosition the corresponding OpenRocket position
28 RocksimLocationMode(int idx, RocketComponent.Position theOpenRocketPosition) {
30 position = theOpenRocketPosition;
34 * Get the OpenRocket position.
36 * @return the position instance
38 public RocketComponent.Position asOpenRocket() {
43 * Lookup an instance of this class from a rocksim enum value.
45 * @param rocksimCode the rocksim enum value
47 * @return an instance of this enum
49 public static RocksimLocationMode fromCode(int rocksimCode) {
50 RocksimLocationMode[] values = values();
51 for (RocksimLocationMode value : values) {
52 if (value.ordinal == rocksimCode) {
56 return FRONT_OF_OWNING_PART;