1 package net.sf.openrocket.simulation;
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.rocketcomponent.RocketComponent;
5 import net.sf.openrocket.startup.Application;
9 * A class that defines an event during the flight of a rocket.
11 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
13 public class FlightEvent implements Comparable<FlightEvent> {
14 private static final Translator trans = Application.getTranslator();
17 * The type of the flight event.
19 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
26 LAUNCH(trans.get("FlightEvent.Type.LAUNCH")),
28 * Ignition of a motor. Source is the motor mount the motor of which has ignited,
29 * and the data is the MotorId of the motor instance.
32 IGNITION(trans.get("FlightEvent.Type.IGNITION")),
34 * When the motor has lifted off the ground.
37 LIFTOFF(trans.get("FlightEvent.Type.LIFTOFF")),
39 * Launch rod has been cleared.
41 //// Launch rod clearance
42 LAUNCHROD(trans.get("FlightEvent.Type.LAUNCHROD")),
44 * Burnout of a motor. Source is the motor mount the motor of which has burnt out,
45 * and the data is the MotorId of the motor instance.
48 BURNOUT(trans.get("FlightEvent.Type.BURNOUT")),
50 * Ejection charge of a motor fired. Source is the motor mount the motor of
51 * which has exploded its ejection charge, and data is the MotorId of the motor instance.
54 EJECTION_CHARGE(trans.get("FlightEvent.Type.EJECTION_CHARGE")),
56 * Separation of a stage. Source is the stage which has separated all lower stages.
59 STAGE_SEPARATION(trans.get("FlightEvent.Type.STAGE_SEPARATION")),
61 * Apogee has been reached.
64 APOGEE(trans.get("FlightEvent.Type.APOGEE")),
66 * Opening of a recovery device. Source is the RecoveryComponent which has opened.
68 //// Recovery device deployment
69 RECOVERY_DEVICE_DEPLOYMENT(trans.get("FlightEvent.Type.RECOVERY_DEVICE_DEPLOYMENT")),
71 * Ground has been hit after flight.
74 GROUND_HIT(trans.get("FlightEvent.Type.GROUND_HIT")),
77 * End of simulation. Placing this to the queue will end the simulation.
80 SIMULATION_END(trans.get("FlightEvent.Type.SIMULATION_END")),
83 * A change in altitude has occurred. Data is a <code>Pair<Double,Double></code>
84 * which contains the old and new altitudes.
87 ALTITUDE(trans.get("FlightEvent.Type.ALTITUDE"));
89 private final String name;
91 private Type(String name) {
96 public String toString() {
101 private final Type type;
102 private final double time;
103 private final RocketComponent source;
104 private final Object data;
107 public FlightEvent(Type type, double time) {
108 this(type, time, null);
111 public FlightEvent(Type type, double time, RocketComponent source) {
112 this(type, time, source, null);
115 public FlightEvent(Type type, double time, RocketComponent source, Object data) {
118 this.source = source;
124 public Type getType() {
128 public double getTime() {
132 public RocketComponent getSource() {
136 public Object getData() {
142 * Return a new FlightEvent with the same information as the current event
143 * but with <code>null</code> source. This is used to avoid memory leakage by
144 * retaining references to obsolete components.
146 * @return a new FlightEvent with same type, time and data.
148 public FlightEvent resetSourceAndData() {
149 return new FlightEvent(type, time, null, null);
154 * Compares this event to another event depending on the event time. Secondary
155 * sorting is performed based on the event type ordinal.
158 public int compareTo(FlightEvent o) {
159 if (this.time < o.time)
161 if (this.time > o.time)
164 return this.type.ordinal() - o.type.ordinal();
168 public String toString() {
169 return "FlightEvent[type=" + type.name() + ",time=" + time + ",source=" + source + "]";