2 * RocksimDensityType.java
4 package net.sf.openrocket.file.rocksim;
6 import net.sf.openrocket.material.Material;
9 * Models the nose cone shape of a rocket. Maps from Rocksim's notion to OpenRocket's.
11 public enum RocksimDensityType {
12 ROCKSIM_BULK (0, RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_BULK_DENSITY),
13 ROCKSIM_SURFACE(1, RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY),
14 ROCKSIM_LINE (2, RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_LINE_DENSITY);
16 /** The Rocksim enumeration value. Sent in XML. */
17 private final int ordinal;
19 /** The corresponding OpenRocket shape. */
20 private final double conversion;
25 * @param idx the Rocksim shape code
26 * @param theConversion the numerical conversion ratio to OpenRocket
28 private RocksimDensityType(int idx, double theConversion) {
30 conversion = theConversion;
34 * Get the OpenRocket shape that corresponds to the Rocksim value.
36 * @return a conversion
38 public double asOpenRocket() {
43 * Lookup an instance of this enum based upon the Rocksim code.
45 * @param rocksimDensityType the Rocksim code (from XML)
46 * @return an instance of this enum
48 public static RocksimDensityType fromCode(int rocksimDensityType) {
49 RocksimDensityType[] values = values();
50 for (RocksimDensityType value : values) {
51 if (value.ordinal == rocksimDensityType) {
55 return ROCKSIM_BULK; //Default
59 * Get the ordinal code.
61 * @param type the OR type
63 * @return the Rocksim XML value
65 public static int toCode(Material.Type type) {
66 if (type.equals(Material.Type.BULK)) {
67 return ROCKSIM_BULK.ordinal;
69 if (type.equals(Material.Type.LINE)) {
70 return ROCKSIM_LINE.ordinal;
72 if (type.equals(Material.Type.SURFACE)) {
73 return ROCKSIM_SURFACE.ordinal;
75 return ROCKSIM_BULK.ordinal;