Updates for 0.9.3
[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                  */
26                 IGNITION("Motor ignition"),
27                 /**
28                  * When the motor has lifted off the ground.
29                  */
30                 LIFTOFF("Lift-off"),
31                 /**
32                  * Launch rod has been cleared.
33                  */
34                 LAUNCHROD("Launch rod clearance"),
35                 /** 
36                  * Burnout of a motor.  Source is the motor mount the motor of which has burnt out. 
37                  */
38                 BURNOUT("Motor 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("Ejection charge"),
44                 /** 
45                  * Separation of a stage.  Source is the stage which has separated all lower stages. 
46                  */
47                 STAGE_SEPARATION("Stage separation"),
48                 /** 
49                  * Apogee has been reached.
50                  */
51                 APOGEE("Apogee"),
52                 /** 
53                  * Opening of a recovery device.  Source is the RecoveryComponent which has opened. 
54                  */
55                 RECOVERY_DEVICE_DEPLOYMENT("Recovery device deployment"),
56                 /** 
57                  * Ground has been hit after flight.
58                  */
59                 GROUND_HIT("Ground hit"),
60                 
61                 /**
62                  * End of simulation.  Placing this to the queue will end the simulation.
63                  */
64                 SIMULATION_END("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("Altitude change");
71
72                 private final String name;
73                 private Type(String name) {
74                         this.name = name;
75                 }
76                 @Override
77                 public String toString() {
78                         return name;
79                 }
80         }
81
82         private final Type type;
83         private final double time;
84         private final RocketComponent source;
85         private final Object data;
86
87         
88         public FlightEvent(Type type, double time) {
89                 this(type, time, null);
90         }
91         
92         public FlightEvent(Type type, double time, RocketComponent source) {
93                 this(type,time,source,null);
94         }
95
96         public FlightEvent(Type type, double time, RocketComponent source, Object data) {
97                 this.type = type;
98                 this.time = time;
99                 this.source = source;
100                 this.data = data;
101         }
102         
103
104         
105         public Type getType() {
106                 return type;
107         }
108         
109         public double getTime() {
110                 return time;
111         }
112         
113         public RocketComponent getSource() {
114                 return source;
115         }
116         
117         public Object getData() {
118                 return data;
119         }
120         
121         
122         public FlightEvent resetSource() {
123                 return new FlightEvent(type, time, null, data);
124         }
125
126         /**
127          * Compares this event to another event depending on the event time.  Secondary
128          * sorting is performed based on the event type ordinal.
129          */
130         @Override
131         public int compareTo(FlightEvent o) {
132                 if (this.time < o.time)
133                         return -1;
134                 if (this.time > o.time)
135                         return 1;
136                 
137                 return this.type.ordinal() - o.type.ordinal();
138         }
139         
140         @Override
141         public String toString() {
142                 return "FlightEvent[type="+type.name()+",time="+time+",source="+source+"]";
143         }
144 }