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>
25 LAUNCH(trans.get("FlightEvent.Type.LAUNCH")),
27 * Ignition of a motor. Source is the motor mount the motor of which has ignited,
28 * and the data is the MotorId of the motor instance.
30 IGNITION(trans.get("FlightEvent.Type.IGNITION")),
32 * When the motor has lifted off the ground.
34 LIFTOFF(trans.get("FlightEvent.Type.LIFTOFF")),
36 * Launch rod has been cleared.
38 LAUNCHROD(trans.get("FlightEvent.Type.LAUNCHROD")),
40 * Burnout of a motor. Source is the motor mount the motor of which has burnt out,
41 * and the data is the MotorId of the motor instance.
43 BURNOUT(trans.get("FlightEvent.Type.BURNOUT")),
45 * Ejection charge of a motor fired. Source is the motor mount the motor of
46 * which has exploded its ejection charge, and data is the MotorId of the motor instance.
48 EJECTION_CHARGE(trans.get("FlightEvent.Type.EJECTION_CHARGE")),
50 * Separation of a stage. Source is the stage which is being separated from the upper stages.
52 STAGE_SEPARATION(trans.get("FlightEvent.Type.STAGE_SEPARATION")),
54 * Apogee has been reached.
56 APOGEE(trans.get("FlightEvent.Type.APOGEE")),
58 * Opening of a recovery device. Source is the RecoveryComponent which has opened.
60 RECOVERY_DEVICE_DEPLOYMENT(trans.get("FlightEvent.Type.RECOVERY_DEVICE_DEPLOYMENT")),
62 * Ground has been hit after flight.
64 GROUND_HIT(trans.get("FlightEvent.Type.GROUND_HIT")),
67 * End of simulation. Placing this to the queue will end the simulation.
69 SIMULATION_END(trans.get("FlightEvent.Type.SIMULATION_END")),
72 * A change in altitude has occurred. Data is a <code>Pair<Double,Double></code>
73 * which contains the old and new altitudes.
75 ALTITUDE(trans.get("FlightEvent.Type.ALTITUDE"));
77 private final String name;
79 private Type(String name) {
84 public String toString() {
89 private final Type type;
90 private final double time;
91 private final RocketComponent source;
92 private final Object data;
95 public FlightEvent(Type type, double time) {
96 this(type, time, null);
99 public FlightEvent(Type type, double time, RocketComponent source) {
100 this(type, time, source, null);
103 public FlightEvent(Type type, double time, RocketComponent source, Object data) {
106 this.source = source;
112 public Type getType() {
116 public double getTime() {
120 public RocketComponent getSource() {
124 public Object getData() {
130 * Return a new FlightEvent with the same information as the current event
131 * but with <code>null</code> source. This is used to avoid memory leakage by
132 * retaining references to obsolete components.
134 * @return a new FlightEvent with same type, time and data.
136 public FlightEvent resetSourceAndData() {
137 return new FlightEvent(type, time, null, null);
142 * Compares this event to another event depending on the event time. Secondary
143 * sorting is performed based on the event type ordinal.
146 public int compareTo(FlightEvent o) {
147 if (this.time < o.time)
149 if (this.time > o.time)
152 return this.type.ordinal() - o.type.ordinal();
156 public String toString() {
157 return "FlightEvent[type=" + type.name() + ",time=" + time + ",source=" + source + "]";