Initial commit
[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,
23                 /**
24                  * When the motor has lifted off the ground.
25                  */
26                 LIFTOFF,
27                 /**
28                  * Launch rod has been cleared.
29                  */
30                 LAUNCHROD,
31                 /** 
32                  * Ignition of a motor.  Source is the motor mount the motor of which has ignited. 
33                  */
34                 IGNITION,
35                 /** 
36                  * Burnout of a motor.  Source is the motor mount the motor of which has burnt out. 
37                  */
38                 BURNOUT,
39                 /** 
40                  * Ejection charge of a motor fired.  Source is the motor mount the motor of
41                  * which has exploded its ejection charge. 
42                  */
43                 EJECTION_CHARGE,
44                 /** 
45                  * Opening of a recovery device.  Source is the RecoveryComponent which has opened. 
46                  */
47                 RECOVERY_DEVICE_DEPLOYMENT,
48                 /** 
49                  * Separation of a stage.  Source is the stage which has separated all lower stages. 
50                  */
51                 STAGE_SEPARATION,
52                 /** 
53                  * Apogee has been reached.
54                  */
55                 APOGEE,
56                 /** 
57                  * Ground has been hit after flight.
58                  */
59                 GROUND_HIT,
60                 
61                 /**
62                  * End of simulation.  Placing this to the queue will end the simulation.
63                  */
64                 SIMULATION_END,
65                 
66                 /**
67                  * A change in altitude has occurred.  Data is a <code>Pair<Double,Double></code>
68                  * which contains the old and new altitudes.
69                  */
70                 ALTITUDE
71         }
72
73         private final Type type;
74         private final double time;
75         private final RocketComponent source;
76         private final Object data;
77
78         
79         public FlightEvent(Type type, double time) {
80                 this(type, time, null);
81         }
82         
83         public FlightEvent(Type type, double time, RocketComponent source) {
84                 this(type,time,source,null);
85         }
86
87         public FlightEvent(Type type, double time, RocketComponent source, Object data) {
88                 this.type = type;
89                 this.time = time;
90                 this.source = source;
91                 this.data = data;
92         }
93         
94
95         
96         public Type getType() {
97                 return type;
98         }
99         
100         public double getTime() {
101                 return time;
102         }
103         
104         public RocketComponent getSource() {
105                 return source;
106         }
107         
108         public Object getData() {
109                 return data;
110         }
111         
112         
113         public FlightEvent resetSource() {
114                 return new FlightEvent(type, time, null, data);
115         }
116
117         /**
118          * Compares this event to another event depending on the event time.  Secondary
119          * sorting is performed based on the event type ordinal.
120          */
121         @Override
122         public int compareTo(FlightEvent o) {
123                 if (this.time < o.time)
124                         return -1;
125                 if (this.time > o.time)
126                         return 1;
127                 
128                 return this.type.ordinal() - o.type.ordinal();
129         }
130         
131         @Override
132         public String toString() {
133                 return "FlightEvent[type="+type.toString()+",time="+time+",source="+source+"]";
134         }
135 }