Added MotorConfiguration object and made MotorMount interface extend
SupportsFlightConfiguration<MotorConfiguration>. Created a class BaseMotorMount which implements SupportsFlightConfiguration<MotorConfiguration> and provides a place to unify the common code in InnerTube and BodyTube.
This commit is contained in:
parent
a0b3ccae08
commit
8c56b7b793
@ -50,6 +50,7 @@ import net.sf.openrocket.rocketcomponent.InternalComponent;
|
|||||||
import net.sf.openrocket.rocketcomponent.LaunchLug;
|
import net.sf.openrocket.rocketcomponent.LaunchLug;
|
||||||
import net.sf.openrocket.rocketcomponent.MassComponent;
|
import net.sf.openrocket.rocketcomponent.MassComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.MassObject;
|
import net.sf.openrocket.rocketcomponent.MassObject;
|
||||||
|
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
import net.sf.openrocket.rocketcomponent.NoseCone;
|
import net.sf.openrocket.rocketcomponent.NoseCone;
|
||||||
import net.sf.openrocket.rocketcomponent.Parachute;
|
import net.sf.openrocket.rocketcomponent.Parachute;
|
||||||
@ -1029,8 +1030,8 @@ class MotorMountHandler extends AbstractElementHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (element.equals("ignitionevent")) {
|
if (element.equals("ignitionevent")) {
|
||||||
MotorMount.IgnitionEvent event = null;
|
MotorConfiguration.IgnitionEvent event = null;
|
||||||
for (MotorMount.IgnitionEvent e : MotorMount.IgnitionEvent.values()) {
|
for (MotorConfiguration.IgnitionEvent e : MotorConfiguration.IgnitionEvent.values()) {
|
||||||
if (e.name().toLowerCase(Locale.ENGLISH).replaceAll("_", "").equals(content)) {
|
if (e.name().toLowerCase(Locale.ENGLISH).replaceAll("_", "").equals(content)) {
|
||||||
event = e;
|
event = e;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -31,8 +31,9 @@ import net.sf.openrocket.l10n.Translator;
|
|||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
import net.sf.openrocket.motor.ThrustCurveMotor;
|
import net.sf.openrocket.motor.ThrustCurveMotor;
|
||||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
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;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
|
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
@ -122,7 +123,7 @@ public class MotorConfig extends JPanel {
|
|||||||
//// Ignition at:
|
//// Ignition at:
|
||||||
panel.add(new JLabel(trans.get("MotorCfg.lbl.Ignitionat")), "");
|
panel.add(new JLabel(trans.get("MotorCfg.lbl.Ignitionat")), "");
|
||||||
|
|
||||||
combo = new JComboBox(new EnumModel<IgnitionEvent>(mount, "IgnitionEvent"));
|
combo = new JComboBox(new EnumModel<MotorConfiguration.IgnitionEvent>(mount, "IgnitionEvent"));
|
||||||
panel.add(combo, "growx, wrap");
|
panel.add(combo, "growx, wrap");
|
||||||
|
|
||||||
// ... and delay
|
// ... and delay
|
||||||
|
|||||||
@ -32,8 +32,9 @@ import net.sf.openrocket.gui.util.SwingPreferences;
|
|||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
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;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount.IgnitionEvent;
|
|
||||||
import net.sf.openrocket.simulation.FlightEvent;
|
import net.sf.openrocket.simulation.FlightEvent;
|
||||||
import net.sf.openrocket.simulation.SimulationStatus;
|
import net.sf.openrocket.simulation.SimulationStatus;
|
||||||
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
import net.sf.openrocket.simulation.customexpression.CustomExpression;
|
||||||
@ -308,7 +309,7 @@ public class SimulationRunDialog extends JDialog {
|
|||||||
Iterator<MotorMount> iterator = config.motorIterator();
|
Iterator<MotorMount> iterator = config.motorIterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
MotorMount m = iterator.next();
|
MotorMount m = iterator.next();
|
||||||
if (m.getIgnitionEvent() == IgnitionEvent.LAUNCH)
|
if (m.getIgnitionEvent() == MotorConfiguration.IgnitionEvent.LAUNCH)
|
||||||
launchBurn = MathUtil.max(launchBurn, m.getMotor(id).getBurnTimeEstimate());
|
launchBurn = MathUtil.max(launchBurn, m.getMotor(id).getBurnTimeEstimate());
|
||||||
else
|
else
|
||||||
otherBurn = otherBurn + m.getMotor(id).getBurnTimeEstimate();
|
otherBurn = otherBurn + m.getMotor(id).getBurnTimeEstimate();
|
||||||
|
|||||||
119
core/src/net/sf/openrocket/rocketcomponent/BaseMotorMount.java
Normal file
119
core/src/net/sf/openrocket/rocketcomponent/BaseMotorMount.java
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import net.sf.openrocket.motor.Motor;
|
||||||
|
|
||||||
|
public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfiguration>, Cloneable {
|
||||||
|
|
||||||
|
private HashMap<String, MotorConfiguration > motors = new HashMap<String,MotorConfiguration>();
|
||||||
|
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<String,MotorConfiguration>) motors.clone();
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -27,13 +27,9 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
|||||||
// When changing the inner radius, thickness is modified
|
// When changing the inner radius, thickness is modified
|
||||||
|
|
||||||
private boolean motorMount = false;
|
private boolean motorMount = false;
|
||||||
private HashMap<String, Double> ejectionDelays = new HashMap<String, Double>();
|
|
||||||
private HashMap<String, Motor> motors = new HashMap<String, Motor>();
|
|
||||||
private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
|
|
||||||
private double ignitionDelay = 0;
|
|
||||||
private double overhang = 0;
|
private double overhang = 0;
|
||||||
|
|
||||||
|
private BaseMotorMount baseMotorMount = new BaseMotorMount();
|
||||||
|
|
||||||
public BodyTube() {
|
public BodyTube() {
|
||||||
super();
|
super();
|
||||||
@ -338,6 +334,56 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
|||||||
|
|
||||||
//////////////// Motor mount /////////////////
|
//////////////// 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
|
@Override
|
||||||
public boolean isMotorMount() {
|
public boolean isMotorMount() {
|
||||||
return motorMount;
|
return motorMount;
|
||||||
@ -351,50 +397,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
|||||||
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
|
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
|
@Override
|
||||||
public int getMotorCount() {
|
public int getMotorCount() {
|
||||||
return 1;
|
return 1;
|
||||||
@ -404,35 +406,38 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
|||||||
public double getMotorMountDiameter() {
|
public double getMotorMountDiameter() {
|
||||||
return getInnerRadius() * 2;
|
return getInnerRadius() * 2;
|
||||||
}
|
}
|
||||||
|
// FIXME - rename to getDefaultIgnitionEvent
|
||||||
@Override
|
@Override
|
||||||
public IgnitionEvent getIgnitionEvent() {
|
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
|
||||||
return ignitionEvent;
|
return getDefaultFlightConfiguration().getIgnitionEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionEvent(IgnitionEvent event) {
|
public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
|
||||||
|
MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent();
|
||||||
if (ignitionEvent == event)
|
if (ignitionEvent == event)
|
||||||
return;
|
return;
|
||||||
ignitionEvent = event;
|
getDefaultFlightConfiguration().setIgnitionEvent(event);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
@Override
|
@Override
|
||||||
public double getIgnitionDelay() {
|
public double getIgnitionDelay() {
|
||||||
return ignitionDelay;
|
return getDefaultFlightConfiguration().getIgnitionDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionDelay(double delay) {
|
public void setIgnitionDelay(double delay) {
|
||||||
|
double ignitionDelay = getIgnitionDelay();
|
||||||
if (MathUtil.equals(delay, ignitionDelay))
|
if (MathUtil.equals(delay, ignitionDelay))
|
||||||
return;
|
return;
|
||||||
ignitionDelay = delay;
|
getDefaultFlightConfiguration().setIgnitionDelay(delay);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getMotorOverhang() {
|
public double getMotorOverhang() {
|
||||||
return overhang;
|
return overhang;
|
||||||
@ -449,7 +454,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Coordinate getMotorPosition(String id) {
|
public Coordinate getMotorPosition(String id) {
|
||||||
Motor motor = motors.get(id);
|
Motor motor = getMotor(id);
|
||||||
if (motor == null) {
|
if (motor == null) {
|
||||||
throw new IllegalArgumentException("No motor with id " + id + " defined.");
|
throw new IllegalArgumentException("No motor with id " + id + " defined.");
|
||||||
}
|
}
|
||||||
@ -470,8 +475,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
|||||||
@Override
|
@Override
|
||||||
protected RocketComponent copyWithOriginalID() {
|
protected RocketComponent copyWithOriginalID() {
|
||||||
RocketComponent c = super.copyWithOriginalID();
|
RocketComponent c = super.copyWithOriginalID();
|
||||||
((BodyTube) c).motors = (HashMap<String, Motor>) motors.clone();
|
((BodyTube) c).baseMotorMount = baseMotorMount.clone();
|
||||||
((BodyTube) c).ejectionDelays = (HashMap<String, Double>) ejectionDelays.clone();
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,7 @@ public class DeploymentConfiguration implements Cloneable {
|
|||||||
description += " + " + deployDelay + "s";
|
description += " + " + deployDelay + "s";
|
||||||
}
|
}
|
||||||
if ( deployEvent == DeployEvent.ALTITUDE && deployAltitude != 0 ) {
|
if ( deployEvent == DeployEvent.ALTITUDE && deployAltitude != 0 ) {
|
||||||
description += " " + UnitGroup.UNITS_DISTANCE.fromUnit(deployAltitude);
|
description += " " + UnitGroup.UNITS_DISTANCE.toString(deployAltitude);
|
||||||
}
|
}
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,22 +19,17 @@ import net.sf.openrocket.util.MathUtil;
|
|||||||
*
|
*
|
||||||
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
* @author Sampo Niskanen <sampo.niskanen@iki.fi>
|
||||||
*/
|
*/
|
||||||
public class InnerTube extends ThicknessRingComponent
|
public class InnerTube extends ThicknessRingComponent implements Clusterable, RadialParent, MotorMount {
|
||||||
implements Clusterable, RadialParent, MotorMount {
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
private ClusterConfiguration cluster = ClusterConfiguration.SINGLE;
|
private ClusterConfiguration cluster = ClusterConfiguration.SINGLE;
|
||||||
private double clusterScale = 1.0;
|
private double clusterScale = 1.0;
|
||||||
private double clusterRotation = 0.0;
|
private double clusterRotation = 0.0;
|
||||||
|
|
||||||
|
|
||||||
private boolean motorMount = false;
|
private boolean motorMount = false;
|
||||||
private HashMap<String, Double> ejectionDelays = new HashMap<String, Double>();
|
|
||||||
private HashMap<String, Motor> motors = new HashMap<String, Motor>();
|
|
||||||
private IgnitionEvent ignitionEvent = IgnitionEvent.AUTOMATIC;
|
|
||||||
private double ignitionDelay = 0;
|
|
||||||
private double overhang = 0;
|
private double overhang = 0;
|
||||||
|
|
||||||
|
private BaseMotorMount baseMotorMount = new BaseMotorMount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main constructor.
|
* Main constructor.
|
||||||
@ -217,16 +212,47 @@ public class InnerTube extends ThicknessRingComponent
|
|||||||
return newArray;
|
return newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//////////////// Motor mount /////////////////
|
//////////////// 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
|
@Override
|
||||||
public boolean isMotorMount() {
|
public boolean isMotorMount() {
|
||||||
return motorMount;
|
return motorMount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMotorMount(boolean mount) {
|
public void setMotorMount(boolean mount) {
|
||||||
if (motorMount == mount)
|
if (motorMount == mount)
|
||||||
@ -235,49 +261,6 @@ public class InnerTube extends ThicknessRingComponent
|
|||||||
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
|
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
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
@ -290,34 +273,62 @@ public class InnerTube extends ThicknessRingComponent
|
|||||||
return getInnerRadius() * 2;
|
return getInnerRadius() * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME - rename to getDefaultIgnitionEvent
|
||||||
@Override
|
@Override
|
||||||
public IgnitionEvent getIgnitionEvent() {
|
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
|
||||||
return ignitionEvent;
|
return getDefaultFlightConfiguration().getIgnitionEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionEvent(IgnitionEvent event) {
|
public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
|
||||||
|
MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent();
|
||||||
if (ignitionEvent == event)
|
if (ignitionEvent == event)
|
||||||
return;
|
return;
|
||||||
ignitionEvent = event;
|
getDefaultFlightConfiguration().setIgnitionEvent(event);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
@Override
|
@Override
|
||||||
public double getIgnitionDelay() {
|
public double getIgnitionDelay() {
|
||||||
return ignitionDelay;
|
return getDefaultFlightConfiguration().getIgnitionDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionDelay(double delay) {
|
public void setIgnitionDelay(double delay) {
|
||||||
|
double ignitionDelay = getIgnitionDelay();
|
||||||
if (MathUtil.equals(delay, ignitionDelay))
|
if (MathUtil.equals(delay, ignitionDelay))
|
||||||
return;
|
return;
|
||||||
ignitionDelay = delay;
|
getDefaultFlightConfiguration().setIgnitionDelay(delay);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
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
|
@Override
|
||||||
public double getMotorOverhang() {
|
public double getMotorOverhang() {
|
||||||
return overhang;
|
return overhang;
|
||||||
@ -334,7 +345,7 @@ public class InnerTube extends ThicknessRingComponent
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Coordinate getMotorPosition(String id) {
|
public Coordinate getMotorPosition(String id) {
|
||||||
Motor motor = motors.get(id);
|
Motor motor = getMotor(id);
|
||||||
if (motor == null) {
|
if (motor == null) {
|
||||||
throw new IllegalArgumentException("No motor with id " + id + " defined.");
|
throw new IllegalArgumentException("No motor with id " + id + " defined.");
|
||||||
}
|
}
|
||||||
@ -352,8 +363,7 @@ public class InnerTube extends ThicknessRingComponent
|
|||||||
@Override
|
@Override
|
||||||
protected RocketComponent copyWithOriginalID() {
|
protected RocketComponent copyWithOriginalID() {
|
||||||
RocketComponent c = super.copyWithOriginalID();
|
RocketComponent c = super.copyWithOriginalID();
|
||||||
((InnerTube) c).motors = (HashMap<String, Motor>) motors.clone();
|
((InnerTube) c).baseMotorMount = baseMotorMount.clone();
|
||||||
((InnerTube) c).ejectionDelays = (HashMap<String, Double>) ejectionDelays.clone();
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,85 +1,10 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import net.sf.openrocket.l10n.Translator;
|
|
||||||
import net.sf.openrocket.motor.Motor;
|
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.ChangeSource;
|
||||||
import net.sf.openrocket.util.Coordinate;
|
import net.sf.openrocket.util.Coordinate;
|
||||||
|
|
||||||
public interface MotorMount extends ChangeSource {
|
public interface MotorMount extends ChangeSource, SupportsFlightConfiguration<MotorConfiguration> {
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the component currently a motor mount.
|
* 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 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.
|
* 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);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -18,7 +18,8 @@ import net.sf.openrocket.rocketcomponent.InnerTube;
|
|||||||
import net.sf.openrocket.rocketcomponent.InternalComponent;
|
import net.sf.openrocket.rocketcomponent.InternalComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.LaunchLug;
|
import net.sf.openrocket.rocketcomponent.LaunchLug;
|
||||||
import net.sf.openrocket.rocketcomponent.MassComponent;
|
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.NoseCone;
|
||||||
import net.sf.openrocket.rocketcomponent.ReferenceType;
|
import net.sf.openrocket.rocketcomponent.ReferenceType;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
@ -135,7 +136,7 @@ public class TestRockets {
|
|||||||
body.setThickness(rnd(0.002));
|
body.setThickness(rnd(0.002));
|
||||||
body.setFilled(rnd.nextBoolean());
|
body.setFilled(rnd.nextBoolean());
|
||||||
body.setIgnitionDelay(rnd.nextDouble() * 3);
|
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.setLength(rnd(0.3));
|
||||||
body.setMotorMount(rnd.nextBoolean());
|
body.setMotorMount(rnd.nextBoolean());
|
||||||
body.setMotorOverhang(rnd.nextGaussian() * 0.03);
|
body.setMotorOverhang(rnd.nextGaussian() * 0.03);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user