create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / rocketcomponent / MotorMount.java
1 package net.sf.openrocket.rocketcomponent;
2
3 import net.sf.openrocket.l10n.Translator;
4 import net.sf.openrocket.motor.Motor;
5 import net.sf.openrocket.simulation.FlightEvent;
6 import net.sf.openrocket.startup.Application;
7 import net.sf.openrocket.util.ChangeSource;
8 import net.sf.openrocket.util.Coordinate;
9
10 public interface MotorMount extends ChangeSource {
11         
12         public static enum IgnitionEvent {
13                 //// Automatic (launch or ejection charge)
14                 AUTOMATIC("MotorMount.IgnitionEvent.AUTOMATIC") {
15                         @Override
16                         public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
17                                 int count = source.getRocket().getStageCount();
18                                 int stage = source.getStageNumber();
19                                 
20                                 if (stage == count - 1) {
21                                         return LAUNCH.isActivationEvent(e, source);
22                                 } else {
23                                         return EJECTION_CHARGE.isActivationEvent(e, source);
24                                 }
25                         }
26                 },
27                 //// Launch
28                 LAUNCH("MotorMount.IgnitionEvent.LAUNCH") {
29                         @Override
30                         public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
31                                 return (e.getType() == FlightEvent.Type.LAUNCH);
32                         }
33                 },
34                 //// First ejection charge of previous stage
35                 EJECTION_CHARGE("MotorMount.IgnitionEvent.EJECTION_CHARGE") {
36                         @Override
37                         public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
38                                 if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
39                                         return false;
40                                 
41                                 int charge = e.getSource().getStageNumber();
42                                 int mount = source.getStageNumber();
43                                 return (mount + 1 == charge);
44                         }
45                 },
46                 //// First burnout of previous stage
47                 BURNOUT("MotorMount.IgnitionEvent.BURNOUT") {
48                         @Override
49                         public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
50                                 if (e.getType() != FlightEvent.Type.BURNOUT)
51                                         return false;
52                                 
53                                 int charge = e.getSource().getStageNumber();
54                                 int mount = source.getStageNumber();
55                                 return (mount + 1 == charge);
56                         }
57                 },
58                 //// Never
59                 NEVER("MotorMount.IgnitionEvent.NEVER") {
60                         @Override
61                         public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
62                                 return false;
63                         }
64                 },
65                 ;
66                 
67
68                 private static final Translator trans = Application.getTranslator();
69                 private final String description;
70                 
71                 IgnitionEvent(String description) {
72                         this.description = description;
73                 }
74                 
75                 public abstract boolean isActivationEvent(FlightEvent e, RocketComponent source);
76                 
77                 @Override
78                 public String toString() {
79                         return trans.get(description);
80                 }
81         };
82         
83         
84         /**
85          * Is the component currently a motor mount.
86          * 
87          * @return  whether the component holds a motor.
88          */
89         public boolean isMotorMount();
90         
91         /**
92          * Set whether the component is currently a motor mount.
93          */
94         public void setMotorMount(boolean mount);
95         
96         
97         /**
98          * Return the motor for the motor configuration.  May return <code>null</code>
99          * if no motor has been set.  This method must return <code>null</code> if ID
100          * is <code>null</code> or if the ID is not valid for the current rocket
101          * (or if the component is not part of any rocket).
102          * 
103          * @param id    the motor configuration ID
104          * @return      the motor, or <code>null</code> if not set.
105          */
106         public Motor getMotor(String id);
107         
108         /**
109          * Set the motor for the motor configuration.  May be set to <code>null</code>
110          * to remove the motor.
111          * 
112          * @param id     the motor configuration ID
113          * @param motor  the motor, or <code>null</code>.
114          */
115         public void setMotor(String id, Motor motor);
116         
117         /**
118          * Get the number of similar motors clustered.
119          * 
120          * TODO: HIGH: This should not be used, since the components themselves can be clustered
121          * 
122          * @return  the number of motors.
123          */
124         @Deprecated
125         public int getMotorCount();
126         
127         
128
129         /**
130          * Return the ejection charge delay of given motor configuration.
131          * A "plugged" motor without an ejection charge is given by
132          * {@link Motor#PLUGGED} (<code>Double.POSITIVE_INFINITY</code>).
133          * 
134          * @param id    the motor configuration ID
135          * @return      the ejection charge delay.
136          */
137         public double getMotorDelay(String id);
138         
139         /**
140          * Set the ejection change delay of the given motor configuration.  
141          * The ejection charge is disable (a "plugged" motor) is set by
142          * {@link Motor#PLUGGED} (<code>Double.POSITIVE_INFINITY</code>).
143          * 
144          * @param id     the motor configuration ID
145          * @param delay  the ejection charge delay.
146          */
147         public void setMotorDelay(String id, double delay);
148         
149         
150         /**
151          * Return the event that ignites this motor.
152          * 
153          * @return   the {@link IgnitionEvent} that ignites this motor.
154          */
155         public IgnitionEvent getIgnitionEvent();
156         
157         /**
158          * Sets the event that ignites this motor.
159          * 
160          * @param event   the {@link IgnitionEvent} that ignites this motor.
161          */
162         public void setIgnitionEvent(IgnitionEvent event);
163         
164         
165         /**
166          * Returns the ignition delay of this motor.
167          * 
168          * @return  the ignition delay
169          */
170         public double getIgnitionDelay();
171         
172         /**
173          * Sets the ignition delay of this motor.
174          * 
175          * @param delay   the ignition delay.
176          */
177         public void setIgnitionDelay(double delay);
178         
179         
180         /**
181          * Return the distance that the motors hang outside this motor mount.
182          * 
183          * @return  the overhang length.
184          */
185         public double getMotorOverhang();
186         
187         /**
188          * Sets the distance that the motors hang outside this motor mount.
189          * 
190          * @param overhang   the overhang length.
191          */
192         public void setMotorOverhang(double overhang);
193         
194         
195
196         /**
197          * Return the inner diameter of the motor mount.
198          * 
199          * @return  the inner diameter of the motor mount.
200          */
201         public double getMotorMountDiameter();
202         
203         
204         /**
205          * Return the position of the motor relative to this component.  The coordinate
206          * is that of the front cap of the motor.
207          * 
208          * @return      the position of the motor relative to this component.
209          * @throws  IllegalArgumentException if a motor with the specified ID does not exist.
210          */
211         public Coordinate getMotorPosition(String id);
212         
213 }