I18 changes
[debian/openrocket] / src / net / sf / openrocket / simulation / FlightDataType.java
1 package net.sf.openrocket.simulation;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import net.sf.openrocket.unit.UnitGroup;
7
8 /**
9  * A class defining a storable simulation variable type.  This class defined numerous ready
10  * types, and allows also creating new types with any name.  When retrieving types based on
11  * a name, you should use {@link #getType(String, UnitGroup)} to return the default unit type,
12  * or a new type if the name does not currently exist.
13  * <p>
14  * Each type has a type name (description), a unit group and a priority.  The type is identified
15  * purely by its name case-insensitively.  The unit group provides the units for the type.
16  * The priority is used to order the types.  The pre-existing types are defined specific priority
17  * numbers, and other types have a default priority number that is after all other types.
18  * 
19  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
20  */
21 public class FlightDataType implements Comparable<FlightDataType> {
22         
23         /** Priority of custom-created variables */
24         private static final int DEFAULT_PRIORITY = 999;
25         
26         /** List of existing types.  MUST BE DEFINED BEFORE ANY TYPES!! */
27         private static final Map<String, FlightDataType> EXISTING_TYPES = new HashMap<String, FlightDataType>();
28         
29
30
31         //// Time
32         public static final FlightDataType TYPE_TIME = newType("Time", UnitGroup.UNITS_FLIGHT_TIME, 1);
33         
34
35         //// Vertical position and motion
36         public static final FlightDataType TYPE_ALTITUDE = newType("Altitude", UnitGroup.UNITS_DISTANCE, 10);
37         public static final FlightDataType TYPE_VELOCITY_Z = newType("Vertical velocity", UnitGroup.UNITS_VELOCITY, 11);
38         public static final FlightDataType TYPE_ACCELERATION_Z = newType("Vertical acceleration", UnitGroup.UNITS_ACCELERATION, 12);
39         
40
41         //// Total motion
42         public static final FlightDataType TYPE_VELOCITY_TOTAL = newType("Total velocity", UnitGroup.UNITS_VELOCITY, 20);
43         public static final FlightDataType TYPE_ACCELERATION_TOTAL = newType("Total acceleration", UnitGroup.UNITS_ACCELERATION, 21);
44         
45
46         //// Lateral position and motion
47         
48         public static final FlightDataType TYPE_POSITION_X = newType("Position upwind", UnitGroup.UNITS_DISTANCE, 30);
49         public static final FlightDataType TYPE_POSITION_Y = newType("Position parallel to wind", UnitGroup.UNITS_DISTANCE, 31);
50         public static final FlightDataType TYPE_POSITION_XY = newType("Lateral distance", UnitGroup.UNITS_DISTANCE, 32);
51         public static final FlightDataType TYPE_POSITION_DIRECTION = newType("Lateral direction", UnitGroup.UNITS_ANGLE, 33);
52         
53         public static final FlightDataType TYPE_VELOCITY_XY = newType("Lateral velocity", UnitGroup.UNITS_VELOCITY, 34);
54         public static final FlightDataType TYPE_ACCELERATION_XY = newType("Lateral acceleration", UnitGroup.UNITS_ACCELERATION, 35);
55         
56
57         //// Angular motion
58         public static final FlightDataType TYPE_AOA = newType("Angle of attack", UnitGroup.UNITS_ANGLE, 40);
59         public static final FlightDataType TYPE_ROLL_RATE = newType("Roll rate", UnitGroup.UNITS_ROLL, 41);
60         public static final FlightDataType TYPE_PITCH_RATE = newType("Pitch rate", UnitGroup.UNITS_ROLL, 42);
61         public static final FlightDataType TYPE_YAW_RATE = newType("Yaw rate", UnitGroup.UNITS_ROLL, 43);
62         
63
64         //// Stability information
65         public static final FlightDataType TYPE_MASS = newType("Mass", UnitGroup.UNITS_MASS, 50);
66         public static final FlightDataType TYPE_LONGITUDINAL_INERTIA = newType("Longitudinal moment of inertia", UnitGroup.UNITS_INERTIA, 51);
67         public static final FlightDataType TYPE_ROTATIONAL_INERTIA = newType("Rotational moment of inertia", UnitGroup.UNITS_INERTIA, 52);
68         public static final FlightDataType TYPE_CP_LOCATION = newType("CP location", UnitGroup.UNITS_LENGTH, 53);
69         public static final FlightDataType TYPE_CG_LOCATION = newType("CG location", UnitGroup.UNITS_LENGTH, 54);
70         public static final FlightDataType TYPE_STABILITY = newType("Stability margin calibers", UnitGroup.UNITS_COEFFICIENT, 55);
71         
72
73         //// Characteristic numbers
74         public static final FlightDataType TYPE_MACH_NUMBER = newType("Mach number", UnitGroup.UNITS_COEFFICIENT, 60);
75         public static final FlightDataType TYPE_REYNOLDS_NUMBER = newType("Reynolds number", UnitGroup.UNITS_COEFFICIENT, 61);
76         
77
78         //// Thrust and drag
79         public static final FlightDataType TYPE_THRUST_FORCE = newType("Thrust", UnitGroup.UNITS_FORCE, 70);
80         public static final FlightDataType TYPE_DRAG_FORCE = newType("Drag force", UnitGroup.UNITS_FORCE, 71);
81         public static final FlightDataType TYPE_DRAG_COEFF = newType("Drag coefficient", UnitGroup.UNITS_COEFFICIENT, 72);
82         public static final FlightDataType TYPE_AXIAL_DRAG_COEFF = newType("Axial drag coefficient", UnitGroup.UNITS_COEFFICIENT, 73);
83         
84
85         ////  Component drag coefficients
86         public static final FlightDataType TYPE_FRICTION_DRAG_COEFF = newType("Friction drag coefficient", UnitGroup.UNITS_COEFFICIENT, 80);
87         public static final FlightDataType TYPE_PRESSURE_DRAG_COEFF = newType("Pressure drag coefficient", UnitGroup.UNITS_COEFFICIENT, 81);
88         public static final FlightDataType TYPE_BASE_DRAG_COEFF = newType("Base drag coefficient", UnitGroup.UNITS_COEFFICIENT, 82);
89         
90
91         ////  Other coefficients
92         public static final FlightDataType TYPE_NORMAL_FORCE_COEFF = newType("Normal force coefficient", UnitGroup.UNITS_COEFFICIENT, 90);
93         public static final FlightDataType TYPE_PITCH_MOMENT_COEFF = newType("Pitch moment coefficient", UnitGroup.UNITS_COEFFICIENT, 91);
94         public static final FlightDataType TYPE_YAW_MOMENT_COEFF = newType("Yaw moment coefficient", UnitGroup.UNITS_COEFFICIENT, 92);
95         public static final FlightDataType TYPE_SIDE_FORCE_COEFF = newType("Side force coefficient", UnitGroup.UNITS_COEFFICIENT, 93);
96         public static final FlightDataType TYPE_ROLL_MOMENT_COEFF = newType("Roll moment coefficient", UnitGroup.UNITS_COEFFICIENT, 94);
97         public static final FlightDataType TYPE_ROLL_FORCING_COEFF = newType("Roll forcing coefficient", UnitGroup.UNITS_COEFFICIENT, 95);
98         public static final FlightDataType TYPE_ROLL_DAMPING_COEFF = newType("Roll damping coefficient", UnitGroup.UNITS_COEFFICIENT, 96);
99         
100         public static final FlightDataType TYPE_PITCH_DAMPING_MOMENT_COEFF = newType("Pitch damping coefficient", UnitGroup.UNITS_COEFFICIENT, 97);
101         public static final FlightDataType TYPE_YAW_DAMPING_MOMENT_COEFF = newType("Yaw damping coefficient", UnitGroup.UNITS_COEFFICIENT, 98);
102         
103
104         ////  Reference length + area
105         public static final FlightDataType TYPE_REFERENCE_LENGTH = newType("Reference length", UnitGroup.UNITS_LENGTH, 100);
106         public static final FlightDataType TYPE_REFERENCE_AREA = newType("Reference area", UnitGroup.UNITS_AREA, 101);
107         
108
109         ////  Orientation
110         public static final FlightDataType TYPE_ORIENTATION_THETA = newType("Vertical orientation (zenith)", UnitGroup.UNITS_ANGLE, 106);
111         public static final FlightDataType TYPE_ORIENTATION_PHI = newType("Lateral orientation (azimuth)", UnitGroup.UNITS_ANGLE, 107);
112         
113
114         ////  Atmospheric conditions
115         public static final FlightDataType TYPE_WIND_VELOCITY = newType("Wind velocity", UnitGroup.UNITS_VELOCITY, 110);
116         public static final FlightDataType TYPE_AIR_TEMPERATURE = newType("Air temperature", UnitGroup.UNITS_TEMPERATURE, 111);
117         public static final FlightDataType TYPE_AIR_PRESSURE = newType("Air pressure", UnitGroup.UNITS_PRESSURE, 112);
118         public static final FlightDataType TYPE_SPEED_OF_SOUND = newType("Speed of sound", UnitGroup.UNITS_VELOCITY, 113);
119         
120
121         ////  Simulation information
122         public static final FlightDataType TYPE_TIME_STEP = newType("Simulation time step", UnitGroup.UNITS_TIME_STEP, 200);
123         public static final FlightDataType TYPE_COMPUTATION_TIME = newType("Computation time", UnitGroup.UNITS_SHORT_TIME, 201);
124         
125         
126
127         /**
128          * Return a {@link FlightDataType} based on a string description.  This returns known data types
129          * if possible, or a new type otherwise.
130          * 
131          * @param s             the string description of the type.
132          * @param u             the unit group the new type should belong to if a new group is created.
133          * @return              a data type.
134          */
135         public static synchronized FlightDataType getType(String s, UnitGroup u) {
136                 FlightDataType type = EXISTING_TYPES.get(s.toLowerCase());
137                 if (type != null) {
138                         return type;
139                 }
140                 type = newType(s, u, DEFAULT_PRIORITY);
141                 return type;
142         }
143         
144         /**
145          * Used while initializing the class.
146          */
147         private static synchronized FlightDataType newType(String s, UnitGroup u, int priority) {
148                 FlightDataType type = new FlightDataType(s, u, priority);
149                 EXISTING_TYPES.put(s.toLowerCase(), type);
150                 return type;
151         }
152         
153         
154         private final String name;
155         private final UnitGroup units;
156         private final int priority;
157         private final int hashCode;
158         
159         
160         private FlightDataType(String typeName, UnitGroup units, int priority) {
161                 if (typeName == null)
162                         throw new IllegalArgumentException("typeName is null");
163                 if (units == null)
164                         throw new IllegalArgumentException("units is null");
165                 this.name = typeName;
166                 this.units = units;
167                 this.priority = priority;
168                 this.hashCode = this.name.toLowerCase().hashCode();
169         }
170         
171         
172
173
174         public String getName() {
175                 return name;
176         }
177         
178         public UnitGroup getUnitGroup() {
179                 return units;
180         }
181         
182         @Override
183         public String toString() {
184                 return name;
185         }
186         
187         @Override
188         public boolean equals(Object other) {
189                 if (!(other instanceof FlightDataType))
190                         return false;
191                 return this.name.equalsIgnoreCase(((FlightDataType) other).name);
192         }
193         
194         @Override
195         public int hashCode() {
196                 return hashCode;
197         }
198         
199         @Override
200         public int compareTo(FlightDataType o) {
201                 if (this.priority != o.priority)
202                         return this.priority - o.priority;
203                 return this.name.compareToIgnoreCase(o.name);
204         }
205 }