updates for 0.9.4
[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> or if the ID is not valid for the current rocket
92          * (or if the component is not part of any rocket).
93          * 
94          * @param id    the motor configuration ID
95          * @return      the motor, or <code>null</code> if not set.
96          */
97         public Motor getMotor(String id);
98         
99         /**
100          * Set the motor for the motor configuration.  May be set to <code>null</code>
101          * to remove the motor.
102          * 
103          * @param id     the motor configuration ID
104          * @param motor  the motor, or <code>null</code>.
105          */
106         public void setMotor(String id, Motor motor);
107
108         /**
109          * Get the number of similar motors clustered.
110          * 
111          * TODO: HIGH: This should not be used, since the components themselves can be clustered
112          * 
113          * @return  the number of motors.
114          */
115         @Deprecated
116         public int getMotorCount();
117         
118         
119         
120         /**
121          * Return the ejection charge delay of given motor configuration.
122          * A "plugged" motor without an ejection charge is given by
123          * {@link Motor#PLUGGED} (<code>Double.POSITIVE_INFINITY</code>).
124          * 
125          * @param id    the motor configuration ID
126          * @return      the ejection charge delay.
127          */
128         public double getMotorDelay(String id);
129         
130         /**
131          * Set the ejection change delay of the given motor configuration.  
132          * The ejection charge is disable (a "plugged" motor) is set by
133          * {@link Motor#PLUGGED} (<code>Double.POSITIVE_INFINITY</code>).
134          * 
135          * @param id     the motor configuration ID
136          * @param delay  the ejection charge delay.
137          */
138         public void setMotorDelay(String id, double delay);
139         
140         
141         /**
142          * Return the event that ignites this motor.
143          * 
144          * @return   the {@link IgnitionEvent} that ignites this motor.
145          */
146         public IgnitionEvent getIgnitionEvent();
147         
148         /**
149          * Sets the event that ignites this motor.
150          * 
151          * @param event   the {@link IgnitionEvent} that ignites this motor.
152          */
153         public void setIgnitionEvent(IgnitionEvent event);
154         
155         
156         /**
157          * Returns the ignition delay of this motor.
158          * 
159          * @return  the ignition delay
160          */
161         public double getIgnitionDelay();
162         
163         /**
164          * Sets the ignition delay of this motor.
165          * 
166          * @param delay   the ignition delay.
167          */
168         public void setIgnitionDelay(double delay);
169         
170         
171         /**
172          * Return the distance that the motors hang outside this motor mount.
173          * 
174          * @return  the overhang length.
175          */
176         public double getMotorOverhang();
177         
178         /**
179          * Sets the distance that the motors hang outside this motor mount.
180          * 
181          * @param overhang   the overhang length.
182          */
183         public void setMotorOverhang(double overhang);
184         
185         
186         
187         /**
188          * Return the inner diameter of the motor mount.
189          * 
190          * @return  the inner diameter of the motor mount.
191          */
192         public double getMotorMountDiameter();
193         
194 }