I18 changes
[debian/openrocket] / src / net / sf / openrocket / simulation / FlightEvent.java
1 package net.sf.openrocket.simulation;
2
3 import net.sf.openrocket.rocketcomponent.RocketComponent;
4
5
6 /**
7  * A class that defines an event during the flight of a rocket.
8  * 
9  * @author Sampo Niskanen <sampo.niskanen@iki.fi>
10  */
11 public class FlightEvent implements Comparable<FlightEvent> {
12         
13         /**
14          * The type of the flight event.
15          * 
16          * @author Sampo Niskanen <sampo.niskanen@iki.fi>
17          */
18         public enum Type {
19                 /** 
20                  * Rocket launch.
21                  */
22                 LAUNCH("Launch"),
23                 /** 
24                  * Ignition of a motor.  Source is the motor mount the motor of which has ignited,
25                  * and the data is the MotorId of the motor instance.
26                  */
27                 IGNITION("Motor ignition"),
28                 /**
29                  * When the motor has lifted off the ground.
30                  */
31                 LIFTOFF("Lift-off"),
32                 /**
33                  * Launch rod has been cleared.
34                  */
35                 LAUNCHROD("Launch rod clearance"),
36                 /** 
37                  * Burnout of a motor.  Source is the motor mount the motor of which has burnt out,
38                  * and the data is the MotorId of the motor instance.
39                  */
40                 BURNOUT("Motor burnout"),
41                 /** 
42                  * Ejection charge of a motor fired.  Source is the motor mount the motor of
43                  * which has exploded its ejection charge, and data is the MotorId of the motor instance.
44                  */
45                 EJECTION_CHARGE("Ejection charge"),
46                 /** 
47                  * Separation of a stage.  Source is the stage which has separated all lower stages. 
48                  */
49                 STAGE_SEPARATION("Stage separation"),
50                 /** 
51                  * Apogee has been reached.
52                  */
53                 APOGEE("Apogee"),
54                 /** 
55                  * Opening of a recovery device.  Source is the RecoveryComponent which has opened. 
56                  */
57                 RECOVERY_DEVICE_DEPLOYMENT("Recovery device deployment"),
58                 /** 
59                  * Ground has been hit after flight.
60                  */
61                 GROUND_HIT("Ground hit"),
62
63                 /**
64                  * End of simulation.  Placing this to the queue will end the simulation.
65                  */
66                 SIMULATION_END("Simulation end"),
67
68                 /**
69                  * A change in altitude has occurred.  Data is a <code>Pair<Double,Double></code>
70                  * which contains the old and new altitudes.
71                  */
72                 ALTITUDE("Altitude change");
73                 
74                 private final String name;
75                 
76                 private Type(String name) {
77                         this.name = name;
78                 }
79                 
80                 @Override
81                 public String toString() {
82                         return name;
83                 }
84         }
85         
86         private final Type type;
87         private final double time;
88         private final RocketComponent source;
89         private final Object data;
90         
91         
92         public FlightEvent(Type type, double time) {
93                 this(type, time, null);
94         }
95         
96         public FlightEvent(Type type, double time, RocketComponent source) {
97                 this(type, time, source, null);
98         }
99         
100         public FlightEvent(Type type, double time, RocketComponent source, Object data) {
101                 this.type = type;
102                 this.time = time;
103                 this.source = source;
104                 this.data = data;
105         }
106         
107         
108
109         public Type getType() {
110                 return type;
111         }
112         
113         public double getTime() {
114                 return time;
115         }
116         
117         public RocketComponent getSource() {
118                 return source;
119         }
120         
121         public Object getData() {
122                 return data;
123         }
124         
125         
126         /**
127          * Return a new FlightEvent with the same information as the current event
128          * but with <code>null</code> source.  This is used to avoid memory leakage by
129          * retaining references to obsolete components.
130          * 
131          * @return      a new FlightEvent with same type, time and data.
132          */
133         public FlightEvent resetSourceAndData() {
134                 return new FlightEvent(type, time, null, null);
135         }
136         
137         
138         /**
139          * Compares this event to another event depending on the event time.  Secondary
140          * sorting is performed based on the event type ordinal.
141          */
142         @Override
143         public int compareTo(FlightEvent o) {
144                 if (this.time < o.time)
145                         return -1;
146                 if (this.time > o.time)
147                         return 1;
148                 
149                 return this.type.ordinal() - o.type.ordinal();
150         }
151         
152         @Override
153         public String toString() {
154                 return "FlightEvent[type=" + type.name() + ",time=" + time + ",source=" + source + "]";
155         }
156 }