From 8c56b7b79318b39f585b9faa6346b23568a95d53 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Wed, 17 Oct 2012 20:36:32 -0500 Subject: [PATCH] Added MotorConfiguration object and made MotorMount interface extend SupportsFlightConfiguration. Created a class BaseMotorMount which implements SupportsFlightConfiguration and provides a place to unify the common code in InnerTube and BodyTube. --- .../openrocket/importt/OpenRocketLoader.java | 5 +- .../gui/configdialog/MotorConfig.java | 5 +- .../gui/main/SimulationRunDialog.java | 5 +- .../rocketcomponent/BaseMotorMount.java | 119 +++++++++++++++ .../openrocket/rocketcomponent/BodyTube.java | 126 ++++++++-------- .../DeploymentConfiguration.java | 2 +- .../openrocket/rocketcomponent/InnerTube.java | 140 ++++++++++-------- .../rocketcomponent/MotorConfiguration.java | 130 ++++++++++++++++ .../rocketcomponent/MotorMount.java | 85 +---------- .../net/sf/openrocket/util/TestRockets.java | 5 +- 10 files changed, 407 insertions(+), 215 deletions(-) create mode 100644 core/src/net/sf/openrocket/rocketcomponent/BaseMotorMount.java create mode 100644 core/src/net/sf/openrocket/rocketcomponent/MotorConfiguration.java diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java index 8ce874141..b98e0dbcb 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java @@ -50,6 +50,7 @@ import net.sf.openrocket.rocketcomponent.InternalComponent; import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.MassComponent; import net.sf.openrocket.rocketcomponent.MassObject; +import net.sf.openrocket.rocketcomponent.MotorConfiguration; import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.Parachute; @@ -1029,8 +1030,8 @@ class MotorMountHandler extends AbstractElementHandler { } if (element.equals("ignitionevent")) { - MotorMount.IgnitionEvent event = null; - for (MotorMount.IgnitionEvent e : MotorMount.IgnitionEvent.values()) { + MotorConfiguration.IgnitionEvent event = null; + for (MotorConfiguration.IgnitionEvent e : MotorConfiguration.IgnitionEvent.values()) { if (e.name().toLowerCase(Locale.ENGLISH).replaceAll("_", "").equals(content)) { event = e; break; diff --git a/core/src/net/sf/openrocket/gui/configdialog/MotorConfig.java b/core/src/net/sf/openrocket/gui/configdialog/MotorConfig.java index 1c2d3b89f..842735388 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/MotorConfig.java +++ b/core/src/net/sf/openrocket/gui/configdialog/MotorConfig.java @@ -31,8 +31,9 @@ import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.rocketcomponent.Configuration; +import net.sf.openrocket.rocketcomponent.MotorConfiguration; +import net.sf.openrocket.rocketcomponent.MotorConfiguration.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; @@ -122,7 +123,7 @@ public class MotorConfig extends JPanel { //// Ignition at: panel.add(new JLabel(trans.get("MotorCfg.lbl.Ignitionat")), ""); - combo = new JComboBox(new EnumModel(mount, "IgnitionEvent")); + combo = new JComboBox(new EnumModel(mount, "IgnitionEvent")); panel.add(combo, "growx, wrap"); // ... and delay diff --git a/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java b/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java index 65fabb8fa..5a8418edc 100644 --- a/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java +++ b/core/src/net/sf/openrocket/gui/main/SimulationRunDialog.java @@ -32,8 +32,9 @@ import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.logging.LogHelper; import net.sf.openrocket.rocketcomponent.Configuration; +import net.sf.openrocket.rocketcomponent.MotorConfiguration; +import net.sf.openrocket.rocketcomponent.MotorConfiguration.IgnitionEvent; import net.sf.openrocket.rocketcomponent.MotorMount; -import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent; import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.simulation.SimulationStatus; import net.sf.openrocket.simulation.customexpression.CustomExpression; @@ -308,7 +309,7 @@ public class SimulationRunDialog extends JDialog { Iterator iterator = config.motorIterator(); while (iterator.hasNext()) { MotorMount m = iterator.next(); - if (m.getIgnitionEvent() == IgnitionEvent.LAUNCH) + if (m.getIgnitionEvent() == MotorConfiguration.IgnitionEvent.LAUNCH) launchBurn = MathUtil.max(launchBurn, m.getMotor(id).getBurnTimeEstimate()); else otherBurn = otherBurn + m.getMotor(id).getBurnTimeEstimate(); diff --git a/core/src/net/sf/openrocket/rocketcomponent/BaseMotorMount.java b/core/src/net/sf/openrocket/rocketcomponent/BaseMotorMount.java new file mode 100644 index 000000000..209c9de5b --- /dev/null +++ b/core/src/net/sf/openrocket/rocketcomponent/BaseMotorMount.java @@ -0,0 +1,119 @@ +package net.sf.openrocket.rocketcomponent; + +import java.util.HashMap; + +import net.sf.openrocket.motor.Motor; + +public class BaseMotorMount implements SupportsFlightConfiguration, Cloneable { + + private HashMap motors = new HashMap(); + private MotorConfiguration defaultConfiguration = new MotorConfiguration(); + + @Override + public MotorConfiguration getFlightConfiguration(String configId) { + return motors.get(configId); + } + + @Override + public void setFlightConfiguration(String configId, MotorConfiguration config) { + if ( config == null ) { + motors.remove(configId); + } else { + motors.put(configId, config); + } + } + + @Override + public void cloneFlightConfiguration(String oldConfigId, String newConfigId) { + MotorConfiguration oldConfig = getFlightConfiguration(oldConfigId); + setFlightConfiguration(newConfigId, oldConfig.clone()); + } + + @Override + public MotorConfiguration getDefaultFlightConfiguration() { + return defaultConfiguration; + } + + @Override + public void setDefaultFlightConfiguration(MotorConfiguration config) { + defaultConfiguration = config; + } + + public Motor getMotor(String id) { + if (id == null) + return null; + + MotorConfiguration motorConfig =getFlightConfiguration(id); + if ( motorConfig == null ) { + return null; + } + return motorConfig.getMotor(); + } + + /** + * Change the motor used in this mount for the given flight configuration. + * + * @param id + * @param motor + * @return true if the new motor is different from the old motor. + */ + public boolean setMotor(String id, Motor motor) { + if (id == null) { + if (motor != null) { + throw new IllegalArgumentException("Cannot set non-null motor for id null"); + } + } + if ( motor == null ) { + setFlightConfiguration(id, null); + } + MotorConfiguration current = getFlightConfiguration(id); + if ( current == null ) { + current = new MotorConfiguration(); + setFlightConfiguration(id, current); + } + Motor currentMotor = current.getMotor(); + if (motor.equals(currentMotor)) { + return false; + } + current.setMotor(motor); + return true; + } + + public double getMotorDelay(String id) { + MotorConfiguration current = getFlightConfiguration(id); + Double delay = ( current == null ) ? null : current.getEjectionDelay(); + if (delay == null) + return Motor.PLUGGED; + return delay; + } + + /** + * Change the motor ejection delay for the given flight configuration + * + * @param id + * @param delay + * @return true if the new value for the delay is different from the old + */ + public boolean setMotorDelay(String id, double delay) { + MotorConfiguration current = getFlightConfiguration(id); + if ( current == null ) { + current = new MotorConfiguration(); + setFlightConfiguration(id, current); + } + if ( current.getEjectionDelay() != delay ) { + current.setEjectionDelay(delay); + return true; + } else { + return false; + } + } + + @Override + protected BaseMotorMount clone() { + BaseMotorMount clone = new BaseMotorMount(); + clone.defaultConfiguration = defaultConfiguration.clone(); + clone.motors = (HashMap) motors.clone(); + return clone; + } + +} diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index 792e78659..146f34eb6 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -27,13 +27,9 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial // When changing the inner radius, thickness is modified private boolean motorMount = false; - private HashMap ejectionDelays = new HashMap(); - private HashMap motors = new HashMap(); - private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC; - private double ignitionDelay = 0; private double overhang = 0; - + private BaseMotorMount baseMotorMount = new BaseMotorMount(); public BodyTube() { super(); @@ -338,6 +334,56 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial //////////////// Motor mount ///////////////// + @Override + public MotorConfiguration getFlightConfiguration(String configId) { + return baseMotorMount.getFlightConfiguration(configId); + } + + @Override + public void setFlightConfiguration(String configId, + MotorConfiguration config) { + baseMotorMount.setFlightConfiguration(configId, config); + } + + @Override + public void cloneFlightConfiguration(String oldConfigId, String newConfigId) { + baseMotorMount.cloneFlightConfiguration(oldConfigId, newConfigId); + } + + @Override + public MotorConfiguration getDefaultFlightConfiguration() { + return baseMotorMount.getDefaultFlightConfiguration(); + } + + @Override + public void setDefaultFlightConfiguration(MotorConfiguration config) { + baseMotorMount.setDefaultFlightConfiguration(config); + } + + @Override + public Motor getMotor(String id) { + return baseMotorMount.getMotor(id); + } + + @Override + public void setMotor(String id, Motor motor) { + if (baseMotorMount.setMotor(id, motor)) { + fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); + } + } + + @Override + public double getMotorDelay(String id) { + return baseMotorMount.getMotorDelay(id); + } + + @Override + public void setMotorDelay(String id, double delay) { + if (baseMotorMount.setMotorDelay(id, delay)) { + fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); + } + } + @Override public boolean isMotorMount() { return motorMount; @@ -351,50 +397,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); } - @Override - public Motor getMotor(String id) { - if (id == null) - return null; - - // Check whether the id is valid for the current rocket - RocketComponent root = this.getRoot(); - if (!(root instanceof Rocket)) - return null; - if (!((Rocket) root).isFlightConfigurationID(id)) - return null; - - return motors.get(id); - } - - @Override - public void setMotor(String id, Motor motor) { - if (id == null) { - if (motor != null) { - throw new IllegalArgumentException("Cannot set non-null motor for id null"); - } - } - Motor current = motors.get(id); - if ((motor == null && current == null) || - (motor != null && motor.equals(current))) - return; - motors.put(id, motor); - fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); - } - - @Override - public double getMotorDelay(String id) { - Double delay = ejectionDelays.get(id); - if (delay == null) - return Motor.PLUGGED; - return delay; - } - - @Override - public void setMotorDelay(String id, double delay) { - ejectionDelays.put(id, delay); - fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); - } - @Override public int getMotorCount() { return 1; @@ -404,35 +406,38 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial public double getMotorMountDiameter() { return getInnerRadius() * 2; } - + // FIXME - rename to getDefaultIgnitionEvent @Override - public IgnitionEvent getIgnitionEvent() { - return ignitionEvent; + public MotorConfiguration.IgnitionEvent getIgnitionEvent() { + return getDefaultFlightConfiguration().getIgnitionEvent(); } + // FIXME @Override - public void setIgnitionEvent(IgnitionEvent event) { + public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) { + MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent(); if (ignitionEvent == event) return; - ignitionEvent = event; + getDefaultFlightConfiguration().setIgnitionEvent(event); fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE); } - + // FIXME @Override public double getIgnitionDelay() { - return ignitionDelay; + return getDefaultFlightConfiguration().getIgnitionDelay(); } + // FIXME @Override public void setIgnitionDelay(double delay) { + double ignitionDelay = getIgnitionDelay(); if (MathUtil.equals(delay, ignitionDelay)) return; - ignitionDelay = delay; + getDefaultFlightConfiguration().setIgnitionDelay(delay); fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE); } - @Override public double getMotorOverhang() { return overhang; @@ -449,7 +454,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial @Override public Coordinate getMotorPosition(String id) { - Motor motor = motors.get(id); + Motor motor = getMotor(id); if (motor == null) { throw new IllegalArgumentException("No motor with id " + id + " defined."); } @@ -470,8 +475,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial @Override protected RocketComponent copyWithOriginalID() { RocketComponent c = super.copyWithOriginalID(); - ((BodyTube) c).motors = (HashMap) motors.clone(); - ((BodyTube) c).ejectionDelays = (HashMap) ejectionDelays.clone(); + ((BodyTube) c).baseMotorMount = baseMotorMount.clone(); return c; } } diff --git a/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java index 5fffc6a6e..3e11ebad4 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java @@ -49,7 +49,7 @@ public class DeploymentConfiguration implements Cloneable { description += " + " + deployDelay + "s"; } if ( deployEvent == DeployEvent.ALTITUDE && deployAltitude != 0 ) { - description += " " + UnitGroup.UNITS_DISTANCE.fromUnit(deployAltitude); + description += " " + UnitGroup.UNITS_DISTANCE.toString(deployAltitude); } return description; } diff --git a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java index d615dcccc..469c69097 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/InnerTube.java @@ -19,22 +19,17 @@ import net.sf.openrocket.util.MathUtil; * * @author Sampo Niskanen */ -public class InnerTube extends ThicknessRingComponent - implements Clusterable, RadialParent, MotorMount { +public class InnerTube extends ThicknessRingComponent implements Clusterable, RadialParent, MotorMount { private static final Translator trans = Application.getTranslator(); private ClusterConfiguration cluster = ClusterConfiguration.SINGLE; private double clusterScale = 1.0; private double clusterRotation = 0.0; - private boolean motorMount = false; - private HashMap ejectionDelays = new HashMap(); - private HashMap motors = new HashMap(); - private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC; - private double ignitionDelay = 0; private double overhang = 0; - + + private BaseMotorMount baseMotorMount = new BaseMotorMount(); /** * Main constructor. @@ -217,16 +212,47 @@ public class InnerTube extends ThicknessRingComponent return newArray; } - - - //////////////// Motor mount ///////////////// + + @Override + public MotorConfiguration getFlightConfiguration(String configId) { + return baseMotorMount.getFlightConfiguration(configId); + } + + + @Override + public void setFlightConfiguration(String configId, MotorConfiguration config) { + baseMotorMount.setFlightConfiguration(configId, config); + fireComponentChangeEvent(ComponentChangeEvent.ALL_CHANGE); + } + + + @Override + public void cloneFlightConfiguration(String oldConfigId, String newConfigId) { + baseMotorMount.cloneFlightConfiguration(oldConfigId, newConfigId); + } + + + @Override + public MotorConfiguration getDefaultFlightConfiguration() { + return baseMotorMount.getDefaultFlightConfiguration(); + } + + + @Override + public void setDefaultFlightConfiguration(MotorConfiguration config) { + baseMotorMount.setDefaultFlightConfiguration(config); + fireComponentChangeEvent(ComponentChangeEvent.ALL_CHANGE); + } + + @Override public boolean isMotorMount() { return motorMount; } + @Override public void setMotorMount(boolean mount) { if (motorMount == mount) @@ -235,49 +261,6 @@ public class InnerTube extends ThicknessRingComponent fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); } - @Override - public Motor getMotor(String id) { - if (id == null) - return null; - - // Check whether the id is valid for the current rocket - RocketComponent root = this.getRoot(); - if (!(root instanceof Rocket)) - return null; - if (!((Rocket) root).isFlightConfigurationID(id)) - return null; - - return motors.get(id); - } - - @Override - public void setMotor(String id, Motor motor) { - if (id == null) { - if (motor != null) { - throw new IllegalArgumentException("Cannot set non-null motor for id null"); - } - } - Motor current = motors.get(id); - if ((motor == null && current == null) || - (motor != null && motor.equals(current))) - return; - motors.put(id, motor); - fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); - } - - @Override - public double getMotorDelay(String id) { - Double delay = ejectionDelays.get(id); - if (delay == null) - return Motor.PLUGGED; - return delay; - } - - @Override - public void setMotorDelay(String id, double delay) { - ejectionDelays.put(id, delay); - fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); - } @Deprecated @Override @@ -290,34 +273,62 @@ public class InnerTube extends ThicknessRingComponent return getInnerRadius() * 2; } + // FIXME - rename to getDefaultIgnitionEvent @Override - public IgnitionEvent getIgnitionEvent() { - return ignitionEvent; + public MotorConfiguration.IgnitionEvent getIgnitionEvent() { + return getDefaultFlightConfiguration().getIgnitionEvent(); } + // FIXME @Override - public void setIgnitionEvent(IgnitionEvent event) { + public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) { + MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent(); if (ignitionEvent == event) return; - ignitionEvent = event; + getDefaultFlightConfiguration().setIgnitionEvent(event); fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE); } - + // FIXME @Override public double getIgnitionDelay() { - return ignitionDelay; + return getDefaultFlightConfiguration().getIgnitionDelay(); } + // FIXME @Override public void setIgnitionDelay(double delay) { + double ignitionDelay = getIgnitionDelay(); if (MathUtil.equals(delay, ignitionDelay)) return; - ignitionDelay = delay; + getDefaultFlightConfiguration().setIgnitionDelay(delay); fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE); } - + @Override + public Motor getMotor(String id) { + return baseMotorMount.getMotor(id); + } + + @Override + public void setMotor(String id, Motor motor) { + if (baseMotorMount.setMotor(id, motor) ) { + fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); + } + } + + + public double getMotorDelay(String id) { + return baseMotorMount.getMotorDelay(id); + } + + + public void setMotorDelay(String id, double delay) { + if (baseMotorMount.setMotorDelay(id, delay) ) { + fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE); + } + } + @Override public double getMotorOverhang() { return overhang; @@ -334,7 +345,7 @@ public class InnerTube extends ThicknessRingComponent @Override public Coordinate getMotorPosition(String id) { - Motor motor = motors.get(id); + Motor motor = getMotor(id); if (motor == null) { throw new IllegalArgumentException("No motor with id " + id + " defined."); } @@ -352,8 +363,7 @@ public class InnerTube extends ThicknessRingComponent @Override protected RocketComponent copyWithOriginalID() { RocketComponent c = super.copyWithOriginalID(); - ((InnerTube) c).motors = (HashMap) motors.clone(); - ((InnerTube) c).ejectionDelays = (HashMap) ejectionDelays.clone(); + ((InnerTube) c).baseMotorMount = baseMotorMount.clone(); return c; } diff --git a/core/src/net/sf/openrocket/rocketcomponent/MotorConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/MotorConfiguration.java new file mode 100644 index 000000000..0f60cb59f --- /dev/null +++ b/core/src/net/sf/openrocket/rocketcomponent/MotorConfiguration.java @@ -0,0 +1,130 @@ +package net.sf.openrocket.rocketcomponent; + +import net.sf.openrocket.l10n.Translator; +import net.sf.openrocket.motor.Motor; +import net.sf.openrocket.simulation.FlightEvent; +import net.sf.openrocket.startup.Application; + +public class MotorConfiguration implements Cloneable { + + private MotorConfiguration.IgnitionEvent ignitionEvent = MotorConfiguration.IgnitionEvent.AUTOMATIC; + private double ignitionDelay = 0; + private Motor motor = null; + private Double ejectionDelay = 0d; + + public MotorConfiguration.IgnitionEvent getIgnitionEvent() { + return ignitionEvent; + } + + public void setIgnitionEvent(MotorConfiguration.IgnitionEvent ignitionEvent) { + this.ignitionEvent = ignitionEvent; + } + + public double getIgnitionDelay() { + return ignitionDelay; + } + + public void setIgnitionDelay(double ignitionDelay) { + this.ignitionDelay = ignitionDelay; + } + + public Motor getMotor() { + return motor; + } + + public void setMotor(Motor motor) { + this.motor = motor; + } + + public Double getEjectionDelay() { + return ejectionDelay; + } + + public void setEjectionDelay(Double ejectionDelay) { + this.ejectionDelay = ejectionDelay; + } + + @Override + protected MotorConfiguration clone() { + MotorConfiguration clone = new MotorConfiguration(); + clone.motor = motor; + clone.ejectionDelay = ejectionDelay; + clone.ignitionDelay = ignitionDelay; + clone.ignitionEvent = ignitionEvent; + return clone; + } + + + + public static enum IgnitionEvent { + //// Automatic (launch or ejection charge) + AUTOMATIC("MotorMount.IgnitionEvent.AUTOMATIC") { + @Override + public boolean isActivationEvent(FlightEvent e, RocketComponent source) { + int count = source.getRocket().getStageCount(); + int stage = source.getStageNumber(); + + if (stage == count - 1) { + return LAUNCH.isActivationEvent(e, source); + } else { + return EJECTION_CHARGE.isActivationEvent(e, source); + } + } + }, + //// Launch + LAUNCH("MotorMount.IgnitionEvent.LAUNCH") { + @Override + public boolean isActivationEvent(FlightEvent e, RocketComponent source) { + return (e.getType() == FlightEvent.Type.LAUNCH); + } + }, + //// First ejection charge of previous stage + EJECTION_CHARGE("MotorMount.IgnitionEvent.EJECTION_CHARGE") { + @Override + public boolean isActivationEvent(FlightEvent e, RocketComponent source) { + if (e.getType() != FlightEvent.Type.EJECTION_CHARGE) + return false; + + int charge = e.getSource().getStageNumber(); + int mount = source.getStageNumber(); + return (mount + 1 == charge); + } + }, + //// First burnout of previous stage + BURNOUT("MotorMount.IgnitionEvent.BURNOUT") { + @Override + public boolean isActivationEvent(FlightEvent e, RocketComponent source) { + if (e.getType() != FlightEvent.Type.BURNOUT) + return false; + + int charge = e.getSource().getStageNumber(); + int mount = source.getStageNumber(); + return (mount + 1 == charge); + } + }, + //// Never + NEVER("MotorMount.IgnitionEvent.NEVER") { + @Override + public boolean isActivationEvent(FlightEvent e, RocketComponent source) { + return false; + } + }, + ; + + + private static final Translator trans = Application.getTranslator(); + private final String description; + + IgnitionEvent(String description) { + this.description = description; + } + + public abstract boolean isActivationEvent(FlightEvent e, RocketComponent source); + + @Override + public String toString() { + return trans.get(description); + } + } + +} diff --git a/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java b/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java index 1c849d4d2..58326db26 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java +++ b/core/src/net/sf/openrocket/rocketcomponent/MotorMount.java @@ -1,85 +1,10 @@ package net.sf.openrocket.rocketcomponent; -import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.motor.Motor; -import net.sf.openrocket.simulation.FlightEvent; -import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.ChangeSource; import net.sf.openrocket.util.Coordinate; -public interface MotorMount extends ChangeSource { - - public static enum IgnitionEvent { - //// Automatic (launch or ejection charge) - AUTOMATIC("MotorMount.IgnitionEvent.AUTOMATIC") { - @Override - public boolean isActivationEvent(FlightEvent e, RocketComponent source) { - int count = source.getRocket().getStageCount(); - int stage = source.getStageNumber(); - - if (stage == count - 1) { - return LAUNCH.isActivationEvent(e, source); - } else { - return EJECTION_CHARGE.isActivationEvent(e, source); - } - } - }, - //// Launch - LAUNCH("MotorMount.IgnitionEvent.LAUNCH") { - @Override - public boolean isActivationEvent(FlightEvent e, RocketComponent source) { - return (e.getType() == FlightEvent.Type.LAUNCH); - } - }, - //// First ejection charge of previous stage - EJECTION_CHARGE("MotorMount.IgnitionEvent.EJECTION_CHARGE") { - @Override - public boolean isActivationEvent(FlightEvent e, RocketComponent source) { - if (e.getType() != FlightEvent.Type.EJECTION_CHARGE) - return false; - - int charge = e.getSource().getStageNumber(); - int mount = source.getStageNumber(); - return (mount + 1 == charge); - } - }, - //// First burnout of previous stage - BURNOUT("MotorMount.IgnitionEvent.BURNOUT") { - @Override - public boolean isActivationEvent(FlightEvent e, RocketComponent source) { - if (e.getType() != FlightEvent.Type.BURNOUT) - return false; - - int charge = e.getSource().getStageNumber(); - int mount = source.getStageNumber(); - return (mount + 1 == charge); - } - }, - //// Never - NEVER("MotorMount.IgnitionEvent.NEVER") { - @Override - public boolean isActivationEvent(FlightEvent e, RocketComponent source) { - return false; - } - }, - ; - - - private static final Translator trans = Application.getTranslator(); - private final String description; - - IgnitionEvent(String description) { - this.description = description; - } - - public abstract boolean isActivationEvent(FlightEvent e, RocketComponent source); - - @Override - public String toString() { - return trans.get(description); - } - }; - +public interface MotorMount extends ChangeSource, SupportsFlightConfiguration { /** * Is the component currently a motor mount. @@ -150,16 +75,16 @@ public interface MotorMount extends ChangeSource { /** * Return the event that ignites this motor. * - * @return the {@link IgnitionEvent} that ignites this motor. + * @return the {@link MotorConfiguration.IgnitionEvent} that ignites this motor. */ - public IgnitionEvent getIgnitionEvent(); + public MotorConfiguration.IgnitionEvent getIgnitionEvent(); /** * Sets the event that ignites this motor. * - * @param event the {@link IgnitionEvent} that ignites this motor. + * @param event the {@link MotorConfiguration.IgnitionEvent} that ignites this motor. */ - public void setIgnitionEvent(IgnitionEvent event); + public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event); /** diff --git a/core/src/net/sf/openrocket/util/TestRockets.java b/core/src/net/sf/openrocket/util/TestRockets.java index 1c3e8d55a..e1a444b5a 100644 --- a/core/src/net/sf/openrocket/util/TestRockets.java +++ b/core/src/net/sf/openrocket/util/TestRockets.java @@ -18,7 +18,8 @@ import net.sf.openrocket.rocketcomponent.InnerTube; import net.sf.openrocket.rocketcomponent.InternalComponent; import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.MassComponent; -import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent; +import net.sf.openrocket.rocketcomponent.MotorConfiguration; +import net.sf.openrocket.rocketcomponent.MotorConfiguration.IgnitionEvent; import net.sf.openrocket.rocketcomponent.NoseCone; import net.sf.openrocket.rocketcomponent.ReferenceType; import net.sf.openrocket.rocketcomponent.Rocket; @@ -135,7 +136,7 @@ public class TestRockets { body.setThickness(rnd(0.002)); body.setFilled(rnd.nextBoolean()); body.setIgnitionDelay(rnd.nextDouble() * 3); - body.setIgnitionEvent((IgnitionEvent) randomEnum(IgnitionEvent.class)); + body.setIgnitionEvent((MotorConfiguration.IgnitionEvent) randomEnum(MotorConfiguration.IgnitionEvent.class)); body.setLength(rnd(0.3)); body.setMotorMount(rnd.nextBoolean()); body.setMotorOverhang(rnd.nextGaussian() * 0.03);