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