1 package net.sf.openrocket.rocketcomponent;
3 import net.sf.openrocket.motor.Motor;
4 import net.sf.openrocket.simulation.FlightEvent;
5 import net.sf.openrocket.util.ChangeSource;
6 import net.sf.openrocket.util.Coordinate;
8 public interface MotorMount extends ChangeSource {
10 public static enum IgnitionEvent {
11 AUTOMATIC("Automatic (launch or ejection charge)") {
13 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
14 int count = source.getRocket().getStageCount();
15 int stage = source.getStageNumber();
17 if (stage == count-1) {
18 return LAUNCH.isActivationEvent(e, source);
20 return EJECTION_CHARGE.isActivationEvent(e, source);
26 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
27 return (e.getType() == FlightEvent.Type.LAUNCH);
30 EJECTION_CHARGE("First ejection charge of previous stage") {
32 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
33 if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
36 int charge = e.getSource().getStageNumber();
37 int mount = source.getStageNumber();
38 return (mount+1 == charge);
41 BURNOUT("First burnout of previous stage") {
43 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
44 if (e.getType() != FlightEvent.Type.BURNOUT)
47 int charge = e.getSource().getStageNumber();
48 int mount = source.getStageNumber();
49 return (mount+1 == charge);
54 public boolean isActivationEvent(FlightEvent e, RocketComponent source) {
61 private final String description;
63 IgnitionEvent(String description) {
64 this.description = description;
67 public abstract boolean isActivationEvent(FlightEvent e, RocketComponent source);
70 public String toString() {
77 * Is the component currently a motor mount.
79 * @return whether the component holds a motor.
81 public boolean isMotorMount();
84 * Set whether the component is currently a motor mount.
86 public void setMotorMount(boolean mount);
90 * Return the motor for the motor configuration. May return <code>null</code>
91 * if no motor has been set. This method must return <code>null</code> if ID
92 * is <code>null</code> or if the ID is not valid for the current rocket
93 * (or if the component is not part of any rocket).
95 * @param id the motor configuration ID
96 * @return the motor, or <code>null</code> if not set.
98 public Motor getMotor(String id);
101 * Set the motor for the motor configuration. May be set to <code>null</code>
102 * to remove the motor.
104 * @param id the motor configuration ID
105 * @param motor the motor, or <code>null</code>.
107 public void setMotor(String id, Motor motor);
110 * Get the number of similar motors clustered.
112 * TODO: HIGH: This should not be used, since the components themselves can be clustered
114 * @return the number of motors.
117 public int getMotorCount();
122 * Return the ejection charge delay of given motor configuration.
123 * A "plugged" motor without an ejection charge is given by
124 * {@link Motor#PLUGGED} (<code>Double.POSITIVE_INFINITY</code>).
126 * @param id the motor configuration ID
127 * @return the ejection charge delay.
129 public double getMotorDelay(String id);
132 * Set the ejection change delay of the given motor configuration.
133 * The ejection charge is disable (a "plugged" motor) is set by
134 * {@link Motor#PLUGGED} (<code>Double.POSITIVE_INFINITY</code>).
136 * @param id the motor configuration ID
137 * @param delay the ejection charge delay.
139 public void setMotorDelay(String id, double delay);
143 * Return the event that ignites this motor.
145 * @return the {@link IgnitionEvent} that ignites this motor.
147 public IgnitionEvent getIgnitionEvent();
150 * Sets the event that ignites this motor.
152 * @param event the {@link IgnitionEvent} that ignites this motor.
154 public void setIgnitionEvent(IgnitionEvent event);
158 * Returns the ignition delay of this motor.
160 * @return the ignition delay
162 public double getIgnitionDelay();
165 * Sets the ignition delay of this motor.
167 * @param delay the ignition delay.
169 public void setIgnitionDelay(double delay);
173 * Return the distance that the motors hang outside this motor mount.
175 * @return the overhang length.
177 public double getMotorOverhang();
180 * Sets the distance that the motors hang outside this motor mount.
182 * @param overhang the overhang length.
184 public void setMotorOverhang(double overhang);
189 * Return the inner diameter of the motor mount.
191 * @return the inner diameter of the motor mount.
193 public double getMotorMountDiameter();
197 * Return the position of the motor relative to this component. The coordinate
198 * is that of the front cap of the motor.
200 * @return the position of the motor relative to this component.
201 * @throws IllegalArgumentException if a motor with the specified ID does not exist.
203 public Coordinate getMotorPosition(String id);