1 package net.sf.openrocket.rocketcomponent;
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;
10 public interface MotorMount extends ChangeSource {
12 public static enum IgnitionEvent {
13 //// Automatic (launch or ejection charge)
14 AUTOMATIC("MotorMount.IgnitionEvent.AUTOMATIC") {
16 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
17 int count = source.getRocket().getStageCount();
18 int stage = source.getStageNumber();
20 if (stage == count - 1) {
21 return LAUNCH.isActivationEvent(e, source);
23 return EJECTION_CHARGE.isActivationEvent(e, source);
28 LAUNCH("MotorMount.IgnitionEvent.LAUNCH") {
30 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
31 return (e.getType() == FlightEvent.Type.LAUNCH);
34 //// First ejection charge of previous stage
35 EJECTION_CHARGE("MotorMount.IgnitionEvent.EJECTION_CHARGE") {
37 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
38 if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
41 int charge = e.getSource().getStageNumber();
42 int mount = source.getStageNumber();
43 return (mount + 1 == charge);
46 //// First burnout of previous stage
47 BURNOUT("MotorMount.IgnitionEvent.BURNOUT") {
49 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
50 if (e.getType() != FlightEvent.Type.BURNOUT)
53 int charge = e.getSource().getStageNumber();
54 int mount = source.getStageNumber();
55 return (mount + 1 == charge);
59 NEVER("MotorMount.IgnitionEvent.NEVER") {
61 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
68 private static final Translator trans = Application.getTranslator();
69 private final String description;
71 IgnitionEvent(String description) {
72 this.description = description;
75 public abstract boolean isActivationEvent(FlightEvent e, RocketComponent source);
78 public String toString() {
79 return trans.get(description);
85 * Is the component currently a motor mount.
87 * @return whether the component holds a motor.
89 public boolean isMotorMount();
92 * Set whether the component is currently a motor mount.
94 public void setMotorMount(boolean mount);
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).
103 * @param id the motor configuration ID
104 * @return the motor, or <code>null</code> if not set.
106 public Motor getMotor(String id);
109 * Set the motor for the motor configuration. May be set to <code>null</code>
110 * to remove the motor.
112 * @param id the motor configuration ID
113 * @param motor the motor, or <code>null</code>.
115 public void setMotor(String id, Motor motor);
118 * Get the number of similar motors clustered.
120 * TODO: HIGH: This should not be used, since the components themselves can be clustered
122 * @return the number of motors.
125 public int getMotorCount();
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>).
134 * @param id the motor configuration ID
135 * @return the ejection charge delay.
137 public double getMotorDelay(String id);
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>).
144 * @param id the motor configuration ID
145 * @param delay the ejection charge delay.
147 public void setMotorDelay(String id, double delay);
151 * Return the event that ignites this motor.
153 * @return the {@link IgnitionEvent} that ignites this motor.
155 public IgnitionEvent getIgnitionEvent();
158 * Sets the event that ignites this motor.
160 * @param event the {@link IgnitionEvent} that ignites this motor.
162 public void setIgnitionEvent(IgnitionEvent event);
166 * Returns the ignition delay of this motor.
168 * @return the ignition delay
170 public double getIgnitionDelay();
173 * Sets the ignition delay of this motor.
175 * @param delay the ignition delay.
177 public void setIgnitionDelay(double delay);
181 * Return the distance that the motors hang outside this motor mount.
183 * @return the overhang length.
185 public double getMotorOverhang();
188 * Sets the distance that the motors hang outside this motor mount.
190 * @param overhang the overhang length.
192 public void setMotorOverhang(double overhang);
197 * Return the inner diameter of the motor mount.
199 * @return the inner diameter of the motor mount.
201 public double getMotorMountDiameter();
205 * Return the position of the motor relative to this component. The coordinate
206 * is that of the front cap of the motor.
208 * @return the position of the motor relative to this component.
209 * @throws IllegalArgumentException if a motor with the specified ID does not exist.
211 public Coordinate getMotorPosition(String id);