create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / Stage.java
1 package net.sf.openrocket.rocketcomponent;
2
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;
7
8 public class Stage extends ComponentAssembly {
9         
10         private static final Translator trans = Application.getTranslator();
11         
12         
13         public static enum SeparationEvent {
14                 //// Upper stage motor ignition
15                 UPPER_IGNITION("Stage.SeparationEvent.UPPER_IGNITION") {
16                         @Override
17                         public boolean isSeparationEvent(FlightEvent e, Stage stage) {
18                                 if (e.getType() != FlightEvent.Type.IGNITION)
19                                         return false;
20                                 
21                                 int ignition = e.getSource().getStageNumber();
22                                 int mount = stage.getStageNumber();
23                                 return (mount == ignition + 1);
24                         }
25                 },
26                 //// Current stage motor ignition
27                 IGNITION("Stage.SeparationEvent.IGNITION") {
28                         @Override
29                         public boolean isSeparationEvent(FlightEvent e, Stage stage) {
30                                 if (e.getType() != FlightEvent.Type.IGNITION)
31                                         return false;
32                                 
33                                 int ignition = e.getSource().getStageNumber();
34                                 int mount = stage.getStageNumber();
35                                 return (mount == ignition);
36                         }
37                 },
38                 //// Current stage motor burnout
39                 BURNOUT("Stage.SeparationEvent.BURNOUT") {
40                         @Override
41                         public boolean isSeparationEvent(FlightEvent e, Stage stage) {
42                                 if (e.getType() != FlightEvent.Type.BURNOUT)
43                                         return false;
44                                 
45                                 int ignition = e.getSource().getStageNumber();
46                                 int mount = stage.getStageNumber();
47                                 return (mount == ignition);
48                         }
49                 },
50                 //// Current stage ejection charge
51                 EJECTION("Stage.SeparationEvent.EJECTION") {
52                         @Override
53                         public boolean isSeparationEvent(FlightEvent e, Stage stage) {
54                                 if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
55                                         return false;
56                                 
57                                 int ignition = e.getSource().getStageNumber();
58                                 int mount = stage.getStageNumber();
59                                 return (mount == ignition);
60                         }
61                 },
62                 //// Launch
63                 LAUNCH("Stage.SeparationEvent.LAUNCH") {
64                         @Override
65                         public boolean isSeparationEvent(FlightEvent e, Stage stage) {
66                                 return e.getType() == FlightEvent.Type.LAUNCH;
67                         }
68                 },
69                 //// Never
70                 NEVER("Stage.SeparationEvent.NEVER") {
71                         @Override
72                         public boolean isSeparationEvent(FlightEvent e, Stage stage) {
73                                 return false;
74                         }
75                 },
76                 ;
77                 
78                 
79                 private final String description;
80                 
81                 SeparationEvent(String description) {
82                         this.description = description;
83                 }
84                 
85                 /**
86                  * Test whether a specific event is a stage separation event.
87                  */
88                 public abstract boolean isSeparationEvent(FlightEvent e, Stage stage);
89                 
90                 @Override
91                 public String toString() {
92                         return trans.get(description);
93                 }
94         };
95         
96         
97         private SeparationEvent separationEvent = SeparationEvent.UPPER_IGNITION;
98         private double separationDelay = 0;
99         
100         
101         @Override
102         public String getComponentName() {
103                 //// Stage
104                 return trans.get("Stage.Stage");
105         }
106         
107         
108         public SeparationEvent getSeparationEvent() {
109                 return separationEvent;
110         }
111         
112         
113         public void setSeparationEvent(SeparationEvent separationEvent) {
114                 if (separationEvent == this.separationEvent)
115                         return;
116                 this.separationEvent = separationEvent;
117                 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
118         }
119         
120         
121         public double getSeparationDelay() {
122                 return separationDelay;
123         }
124         
125         
126         public void setSeparationDelay(double separationDelay) {
127                 if (MathUtil.equals(separationDelay, this.separationDelay))
128                         return;
129                 this.separationDelay = separationDelay;
130                 fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
131         }
132         
133         
134         
135         @Override
136         public boolean allowsChildren() {
137                 return true;
138         }
139         
140         /**
141          * Check whether the given type can be added to this component.  A Stage allows
142          * only BodyComponents to be added.
143          *
144          * @param type The RocketComponent class type to add.
145          *
146          * @return Whether such a component can be added.
147          */
148         @Override
149         public boolean isCompatible(Class<? extends RocketComponent> type) {
150                 return BodyComponent.class.isAssignableFrom(type);
151         }
152 }