DGP - added DensityType parsing for recovery devices
[debian/openrocket] / src / net / sf / openrocket / file / rocksim / RocksimDensityType.java
1 /*
2  * RocksimDensityType.java
3  */
4 package net.sf.openrocket.file.rocksim;
5
6 /**
7  * Models the nose cone shape of a rocket.  Maps from Rocksim's notion to OpenRocket's.
8  */
9 enum RocksimDensityType {
10     ROCKSIM_BULK   (0, RocksimHandler.ROCKSIM_TO_OPENROCKET_BULK_DENSITY),
11     ROCKSIM_SURFACE(1, RocksimHandler.ROCKSIM_TO_OPENROCKET_SURFACE_DENSITY),
12     ROCKSIM_LINE   (2, RocksimHandler.ROCKSIM_TO_OPENROCKET_LINE_DENSITY);
13
14     /** The Rocksim enumeration value. Sent in XML. */
15     private final int ordinal;
16
17     /** The corresponding OpenRocket shape. */
18     private final double conversion;
19
20     /**
21      * Constructor.
22      *
23      * @param idx            the Rocksim shape code
24      * @param theConversion  the numerical conversion ratio to OpenRocket
25      */
26     private RocksimDensityType(int idx, double theConversion) {
27         ordinal = idx;
28         conversion = theConversion;
29     }
30
31     /**
32      * Get the OpenRocket shape that corresponds to the Rocksim value.
33      *
34      * @return a conversion
35      */
36     public double asOpenRocket() {
37         return conversion;
38     }
39
40     /**
41      * Lookup an instance of this enum based upon the Rocksim code.
42      *
43      * @param rocksimDensityType  the Rocksim code (from XML)
44      * @return an instance of this enum
45      */
46     public static RocksimDensityType fromCode(int rocksimDensityType) {
47         RocksimDensityType[] values = values();
48         for (RocksimDensityType value : values) {
49             if (value.ordinal == rocksimDensityType) {
50                 return value;
51             }
52         }
53         return ROCKSIM_BULK; //Default
54     }
55 }
56