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