1 package net.sf.openrocket.simulation;
3 import net.sf.openrocket.rocketcomponent.RocketComponent;
7 * A class that defines an event during the flight of a rocket.
9 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
11 public class FlightEvent implements Comparable<FlightEvent> {
14 * The type of the flight event.
16 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
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.
27 IGNITION("Motor ignition"),
29 * When the motor has lifted off the ground.
33 * Launch rod has been cleared.
35 LAUNCHROD("Launch rod clearance"),
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.
40 BURNOUT("Motor burnout"),
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.
45 EJECTION_CHARGE("Ejection charge"),
47 * Separation of a stage. Source is the stage which has separated all lower stages.
49 STAGE_SEPARATION("Stage separation"),
51 * Apogee has been reached.
55 * Opening of a recovery device. Source is the RecoveryComponent which has opened.
57 RECOVERY_DEVICE_DEPLOYMENT("Recovery device deployment"),
59 * Ground has been hit after flight.
61 GROUND_HIT("Ground hit"),
64 * End of simulation. Placing this to the queue will end the simulation.
66 SIMULATION_END("Simulation end"),
69 * A change in altitude has occurred. Data is a <code>Pair<Double,Double></code>
70 * which contains the old and new altitudes.
72 ALTITUDE("Altitude change");
74 private final String name;
76 private Type(String name) {
81 public String toString() {
86 private final Type type;
87 private final double time;
88 private final RocketComponent source;
89 private final Object data;
92 public FlightEvent(Type type, double time) {
93 this(type, time, null);
96 public FlightEvent(Type type, double time, RocketComponent source) {
97 this(type, time, source, null);
100 public FlightEvent(Type type, double time, RocketComponent source, Object data) {
103 this.source = source;
109 public Type getType() {
113 public double getTime() {
117 public RocketComponent getSource() {
121 public Object getData() {
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.
131 * @return a new FlightEvent with same type, time and data.
133 public FlightEvent resetSourceAndData() {
134 return new FlightEvent(type, time, null, null);
139 * Compares this event to another event depending on the event time. Secondary
140 * sorting is performed based on the event type ordinal.
143 public int compareTo(FlightEvent o) {
144 if (this.time < o.time)
146 if (this.time > o.time)
149 return this.type.ordinal() - o.type.ordinal();
153 public String toString() {
154 return "FlightEvent[type=" + type.name() + ",time=" + time + ",source=" + source + "]";