1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.simulation.FlightEvent;
5 import net.sf.openrocket.startup.Application;
6 import net.sf.openrocket.util.MathUtil;
8 public class Stage extends ComponentAssembly {
10 private static final Translator trans = Application.getTranslator();
13 public static enum SeparationEvent {
14 //// Upper stage motor ignition
15 UPPER_IGNITION("Stage.SeparationEvent.UPPER_IGNITION") {
17 public boolean isSeparationEvent(FlightEvent e, Stage stage) {
18 if (e.getType() != FlightEvent.Type.IGNITION)
21 int ignition = e.getSource().getStageNumber();
22 int mount = stage.getStageNumber();
23 return (mount == ignition + 1);
26 //// Current stage motor ignition
27 IGNITION("Stage.SeparationEvent.IGNITION") {
29 public boolean isSeparationEvent(FlightEvent e, Stage stage) {
30 if (e.getType() != FlightEvent.Type.IGNITION)
33 int ignition = e.getSource().getStageNumber();
34 int mount = stage.getStageNumber();
35 return (mount == ignition);
38 //// Current stage motor burnout
39 BURNOUT("Stage.SeparationEvent.BURNOUT") {
41 public boolean isSeparationEvent(FlightEvent e, Stage stage) {
42 if (e.getType() != FlightEvent.Type.BURNOUT)
45 int ignition = e.getSource().getStageNumber();
46 int mount = stage.getStageNumber();
47 return (mount == ignition);
50 //// Current stage ejection charge
51 EJECTION("Stage.SeparationEvent.EJECTION") {
53 public boolean isSeparationEvent(FlightEvent e, Stage stage) {
54 if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
57 int ignition = e.getSource().getStageNumber();
58 int mount = stage.getStageNumber();
59 return (mount == ignition);
63 LAUNCH("Stage.SeparationEvent.LAUNCH") {
65 public boolean isSeparationEvent(FlightEvent e, Stage stage) {
66 return e.getType() == FlightEvent.Type.LAUNCH;
70 NEVER("Stage.SeparationEvent.NEVER") {
72 public boolean isSeparationEvent(FlightEvent e, Stage stage) {
79 private final String description;
81 SeparationEvent(String description) {
82 this.description = description;
86 * Test whether a specific event is a stage separation event.
88 public abstract boolean isSeparationEvent(FlightEvent e, Stage stage);
91 public String toString() {
92 return trans.get(description);
97 private SeparationEvent separationEvent = SeparationEvent.UPPER_IGNITION;
98 private double separationDelay = 0;
102 public String getComponentName() {
104 return trans.get("Stage.Stage");
108 public SeparationEvent getSeparationEvent() {
109 return separationEvent;
113 public void setSeparationEvent(SeparationEvent separationEvent) {
114 if (separationEvent == this.separationEvent)
116 this.separationEvent = separationEvent;
117 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
121 public double getSeparationDelay() {
122 return separationDelay;
126 public void setSeparationDelay(double separationDelay) {
127 if (MathUtil.equals(separationDelay, this.separationDelay))
129 this.separationDelay = separationDelay;
130 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
136 public boolean allowsChildren() {
141 * Check whether the given type can be added to this component. A Stage allows
142 * only BodyComponents to be added.
144 * @param type The RocketComponent class type to add.
146 * @return Whether such a component can be added.
149 public boolean isCompatible(Class<? extends RocketComponent> type) {
150 return BodyComponent.class.isAssignableFrom(type);