Changed MotorConfiguration construction to allow distinction between
that used for the "default" body tube and inner tube configuration, and those used for per flight configuration. Tightened up the access specification to methods in BaseMotorMount. Changed names of MotorMount methods to clearly indicate they operate on the default ignition event and delay.
This commit is contained in:
parent
8c56b7b793
commit
5b32242b45
@ -1041,7 +1041,7 @@ class MotorMountHandler extends AbstractElementHandler {
|
|||||||
warnings.add(Warning.fromString("Unknown ignition event type '" + content + "', ignoring."));
|
warnings.add(Warning.fromString("Unknown ignition event type '" + content + "', ignoring."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mount.setIgnitionEvent(event);
|
mount.setDefaultIgnitionEvent(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1053,7 +1053,7 @@ class MotorMountHandler extends AbstractElementHandler {
|
|||||||
warnings.add(Warning.fromString("Illegal ignition delay specified, ignoring."));
|
warnings.add(Warning.fromString("Illegal ignition delay specified, ignoring."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mount.setIgnitionDelay(d);
|
mount.setDefaultIgnitionDelay(d);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,10 +158,10 @@ public class RocketComponentSaver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
elements.add(" <ignitionevent>"
|
elements.add(" <ignitionevent>"
|
||||||
+ mount.getIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
|
+ mount.getDefaultIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
|
||||||
+ "</ignitionevent>");
|
+ "</ignitionevent>");
|
||||||
|
|
||||||
elements.add(" <ignitiondelay>" + mount.getIgnitionDelay() + "</ignitiondelay>");
|
elements.add(" <ignitiondelay>" + mount.getDefaultIgnitionDelay() + "</ignitiondelay>");
|
||||||
elements.add(" <overhang>" + mount.getMotorOverhang() + "</overhang>");
|
elements.add(" <overhang>" + mount.getMotorOverhang() + "</overhang>");
|
||||||
|
|
||||||
elements.add("</motormount>");
|
elements.add("</motormount>");
|
||||||
|
@ -240,7 +240,7 @@ public class MotorConfigurationPanel extends JPanel {
|
|||||||
if (motor == null)
|
if (motor == null)
|
||||||
//// None
|
//// None
|
||||||
return null;
|
return null;
|
||||||
MotorConfiguration.IgnitionEvent ignition = mount.getIgnitionEvent();
|
MotorConfiguration.IgnitionEvent ignition = mount.getDefaultIgnitionEvent();
|
||||||
return ignition.toString();
|
return ignition.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,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() == MotorConfiguration.IgnitionEvent.LAUNCH)
|
if (m.getDefaultIgnitionEvent() == 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();
|
||||||
|
@ -4,10 +4,10 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
|
|
||||||
public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfiguration>, Cloneable {
|
class BaseMotorMount implements SupportsFlightConfiguration<MotorConfiguration>, Cloneable {
|
||||||
|
|
||||||
private HashMap<String, MotorConfiguration > motors = new HashMap<String,MotorConfiguration>();
|
private HashMap<String, MotorConfiguration > motors = new HashMap<String,MotorConfiguration>();
|
||||||
private MotorConfiguration defaultConfiguration = new MotorConfiguration();
|
private MotorConfiguration defaultConfiguration = MotorConfiguration.makeDefaultMotorConfiguration();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MotorConfiguration getFlightConfiguration(String configId) {
|
public MotorConfiguration getFlightConfiguration(String configId) {
|
||||||
@ -39,7 +39,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
|
|||||||
defaultConfiguration = config;
|
defaultConfiguration = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Motor getMotor(String id) {
|
Motor getMotor(String id) {
|
||||||
if (id == null)
|
if (id == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
|
|||||||
* @param motor
|
* @param motor
|
||||||
* @return true if the new motor is different from the old motor.
|
* @return true if the new motor is different from the old motor.
|
||||||
*/
|
*/
|
||||||
public boolean setMotor(String id, Motor motor) {
|
boolean setMotor(String id, Motor motor) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
if (motor != null) {
|
if (motor != null) {
|
||||||
throw new IllegalArgumentException("Cannot set non-null motor for id null");
|
throw new IllegalArgumentException("Cannot set non-null motor for id null");
|
||||||
@ -79,7 +79,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getMotorDelay(String id) {
|
double getMotorDelay(String id) {
|
||||||
MotorConfiguration current = getFlightConfiguration(id);
|
MotorConfiguration current = getFlightConfiguration(id);
|
||||||
Double delay = ( current == null ) ? null : current.getEjectionDelay();
|
Double delay = ( current == null ) ? null : current.getEjectionDelay();
|
||||||
if (delay == null)
|
if (delay == null)
|
||||||
@ -94,7 +94,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
|
|||||||
* @param delay
|
* @param delay
|
||||||
* @return true if the new value for the delay is different from the old
|
* @return true if the new value for the delay is different from the old
|
||||||
*/
|
*/
|
||||||
public boolean setMotorDelay(String id, double delay) {
|
boolean setMotorDelay(String id, double delay) {
|
||||||
MotorConfiguration current = getFlightConfiguration(id);
|
MotorConfiguration current = getFlightConfiguration(id);
|
||||||
if ( current == null ) {
|
if ( current == null ) {
|
||||||
current = new MotorConfiguration();
|
current = new MotorConfiguration();
|
||||||
|
@ -2,7 +2,6 @@ package net.sf.openrocket.rocketcomponent;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.motor.Motor;
|
import net.sf.openrocket.motor.Motor;
|
||||||
@ -406,32 +405,29 @@ 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 MotorConfiguration.IgnitionEvent getIgnitionEvent() {
|
public MotorConfiguration.IgnitionEvent getDefaultIgnitionEvent() {
|
||||||
return getDefaultFlightConfiguration().getIgnitionEvent();
|
return getDefaultFlightConfiguration().getIgnitionEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
|
public void setDefaultIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
|
||||||
MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent();
|
MotorConfiguration.IgnitionEvent ignitionEvent = getDefaultIgnitionEvent();
|
||||||
if (ignitionEvent == event)
|
if (ignitionEvent == event)
|
||||||
return;
|
return;
|
||||||
getDefaultFlightConfiguration().setIgnitionEvent(event);
|
getDefaultFlightConfiguration().setIgnitionEvent(event);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
|
||||||
@Override
|
@Override
|
||||||
public double getIgnitionDelay() {
|
public double getDefaultIgnitionDelay() {
|
||||||
return getDefaultFlightConfiguration().getIgnitionDelay();
|
return getDefaultFlightConfiguration().getIgnitionDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionDelay(double delay) {
|
public void setDefaultIgnitionDelay(double delay) {
|
||||||
double ignitionDelay = getIgnitionDelay();
|
double ignitionDelay = getDefaultIgnitionDelay();
|
||||||
if (MathUtil.equals(delay, ignitionDelay))
|
if (MathUtil.equals(delay, ignitionDelay))
|
||||||
return;
|
return;
|
||||||
getDefaultFlightConfiguration().setIgnitionDelay(delay);
|
getDefaultFlightConfiguration().setIgnitionDelay(delay);
|
||||||
@ -463,15 +459,12 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
* Copy the motor and ejection delay HashMaps.
|
* Copy the motor and ejection delay HashMaps.
|
||||||
*
|
*
|
||||||
* @see rocketcomponent.RocketComponent#copy()
|
* @see rocketcomponent.RocketComponent#copy()
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected RocketComponent copyWithOriginalID() {
|
protected RocketComponent copyWithOriginalID() {
|
||||||
RocketComponent c = super.copyWithOriginalID();
|
RocketComponent c = super.copyWithOriginalID();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
@ -273,32 +272,28 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
|
|||||||
return getInnerRadius() * 2;
|
return getInnerRadius() * 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME - rename to getDefaultIgnitionEvent
|
|
||||||
@Override
|
@Override
|
||||||
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
|
public MotorConfiguration.IgnitionEvent getDefaultIgnitionEvent() {
|
||||||
return getDefaultFlightConfiguration().getIgnitionEvent();
|
return getDefaultFlightConfiguration().getIgnitionEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
|
public void setDefaultIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
|
||||||
MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent();
|
MotorConfiguration.IgnitionEvent ignitionEvent = getDefaultIgnitionEvent();
|
||||||
if (ignitionEvent == event)
|
if (ignitionEvent == event)
|
||||||
return;
|
return;
|
||||||
getDefaultFlightConfiguration().setIgnitionEvent(event);
|
getDefaultFlightConfiguration().setIgnitionEvent(event);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
|
||||||
@Override
|
@Override
|
||||||
public double getIgnitionDelay() {
|
public double getDefaultIgnitionDelay() {
|
||||||
return getDefaultFlightConfiguration().getIgnitionDelay();
|
return getDefaultFlightConfiguration().getIgnitionDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME
|
|
||||||
@Override
|
@Override
|
||||||
public void setIgnitionDelay(double delay) {
|
public void setDefaultIgnitionDelay(double delay) {
|
||||||
double ignitionDelay = getIgnitionDelay();
|
double ignitionDelay = getDefaultIgnitionDelay();
|
||||||
if (MathUtil.equals(delay, ignitionDelay))
|
if (MathUtil.equals(delay, ignitionDelay))
|
||||||
return;
|
return;
|
||||||
getDefaultFlightConfiguration().setIgnitionDelay(delay);
|
getDefaultFlightConfiguration().setIgnitionDelay(delay);
|
||||||
@ -317,12 +312,12 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public double getMotorDelay(String id) {
|
public double getMotorDelay(String id) {
|
||||||
return baseMotorMount.getMotorDelay(id);
|
return baseMotorMount.getMotorDelay(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setMotorDelay(String id, double delay) {
|
public void setMotorDelay(String id, double delay) {
|
||||||
if (baseMotorMount.setMotorDelay(id, delay) ) {
|
if (baseMotorMount.setMotorDelay(id, delay) ) {
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.MOTOR_CHANGE);
|
||||||
@ -342,7 +337,6 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
|
|||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Coordinate getMotorPosition(String id) {
|
public Coordinate getMotorPosition(String id) {
|
||||||
Motor motor = getMotor(id);
|
Motor motor = getMotor(id);
|
||||||
@ -359,7 +353,6 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
|
|||||||
*
|
*
|
||||||
* @see rocketcomponent.RocketComponent#copy()
|
* @see rocketcomponent.RocketComponent#copy()
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected RocketComponent copyWithOriginalID() {
|
protected RocketComponent copyWithOriginalID() {
|
||||||
RocketComponent c = super.copyWithOriginalID();
|
RocketComponent c = super.copyWithOriginalID();
|
||||||
|
@ -7,11 +7,34 @@ import net.sf.openrocket.startup.Application;
|
|||||||
|
|
||||||
public class MotorConfiguration implements Cloneable {
|
public class MotorConfiguration implements Cloneable {
|
||||||
|
|
||||||
private MotorConfiguration.IgnitionEvent ignitionEvent = MotorConfiguration.IgnitionEvent.AUTOMATIC;
|
private MotorConfiguration.IgnitionEvent ignitionEvent;
|
||||||
private double ignitionDelay = 0;
|
private Double ignitionDelay;
|
||||||
private Motor motor = null;
|
private Motor motor = null;
|
||||||
private Double ejectionDelay = 0d;
|
private Double ejectionDelay = 0d;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method which constructs a MotorConfiguration object which is suitable for
|
||||||
|
* use as the defaults for the MotorMount. In particular, it has Automatic ignitionEvent
|
||||||
|
* and 0 ignitionDelay.
|
||||||
|
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static MotorConfiguration makeDefaultMotorConfiguration() {
|
||||||
|
MotorConfiguration defaults = new MotorConfiguration();
|
||||||
|
defaults.ignitionDelay = 0d;
|
||||||
|
defaults.ignitionEvent = MotorConfiguration.IgnitionEvent.AUTOMATIC;
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a MotorConfiguration object which is suitable for use by per flight configuration
|
||||||
|
* scenarios. ignitionEvent and ignitionDelay are null to indicate that one should rely on the
|
||||||
|
* default value.
|
||||||
|
*/
|
||||||
|
MotorConfiguration() {
|
||||||
|
}
|
||||||
|
|
||||||
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
|
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
|
||||||
return ignitionEvent;
|
return ignitionEvent;
|
||||||
}
|
}
|
||||||
@ -20,11 +43,11 @@ public class MotorConfiguration implements Cloneable {
|
|||||||
this.ignitionEvent = ignitionEvent;
|
this.ignitionEvent = ignitionEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getIgnitionDelay() {
|
public Double getIgnitionDelay() {
|
||||||
return ignitionDelay;
|
return ignitionDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIgnitionDelay(double ignitionDelay) {
|
public void setIgnitionDelay(Double ignitionDelay) {
|
||||||
this.ignitionDelay = ignitionDelay;
|
this.ignitionDelay = ignitionDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +77,14 @@ public interface MotorMount extends ChangeSource, SupportsFlightConfiguration<Mo
|
|||||||
*
|
*
|
||||||
* @return the {@link MotorConfiguration.IgnitionEvent} that ignites this motor.
|
* @return the {@link MotorConfiguration.IgnitionEvent} that ignites this motor.
|
||||||
*/
|
*/
|
||||||
public MotorConfiguration.IgnitionEvent getIgnitionEvent();
|
public MotorConfiguration.IgnitionEvent getDefaultIgnitionEvent();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the event that ignites this motor.
|
* Sets the event that ignites this motor.
|
||||||
*
|
*
|
||||||
* @param event the {@link MotorConfiguration.IgnitionEvent} that ignites this motor.
|
* @param event the {@link MotorConfiguration.IgnitionEvent} that ignites this motor.
|
||||||
*/
|
*/
|
||||||
public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event);
|
public void setDefaultIgnitionEvent(MotorConfiguration.IgnitionEvent event);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,14 +92,14 @@ public interface MotorMount extends ChangeSource, SupportsFlightConfiguration<Mo
|
|||||||
*
|
*
|
||||||
* @return the ignition delay
|
* @return the ignition delay
|
||||||
*/
|
*/
|
||||||
public double getIgnitionDelay();
|
public double getDefaultIgnitionDelay();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the ignition delay of this motor.
|
* Sets the ignition delay of this motor.
|
||||||
*
|
*
|
||||||
* @param delay the ignition delay.
|
* @param delay the ignition delay.
|
||||||
*/
|
*/
|
||||||
public void setIgnitionDelay(double delay);
|
public void setDefaultIgnitionDelay(double delay);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -348,9 +348,9 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
MotorMount mount = status.getMotorConfiguration().getMotorMount(id);
|
MotorMount mount = status.getMotorConfiguration().getMotorMount(id);
|
||||||
RocketComponent component = (RocketComponent) mount;
|
RocketComponent component = (RocketComponent) mount;
|
||||||
|
|
||||||
if (mount.getIgnitionEvent().isActivationEvent(event, component)) {
|
if (mount.getDefaultIgnitionEvent().isActivationEvent(event, component)) {
|
||||||
addEvent(new FlightEvent(FlightEvent.Type.IGNITION,
|
addEvent(new FlightEvent(FlightEvent.Type.IGNITION,
|
||||||
status.getSimulationTime() + mount.getIgnitionDelay(),
|
status.getSimulationTime() + mount.getDefaultIgnitionDelay(),
|
||||||
component, id));
|
component, id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,8 @@ public class TestRockets {
|
|||||||
setBasics(body);
|
setBasics(body);
|
||||||
body.setThickness(rnd(0.002));
|
body.setThickness(rnd(0.002));
|
||||||
body.setFilled(rnd.nextBoolean());
|
body.setFilled(rnd.nextBoolean());
|
||||||
body.setIgnitionDelay(rnd.nextDouble() * 3);
|
body.setDefaultIgnitionDelay(rnd.nextDouble() * 3);
|
||||||
body.setIgnitionEvent((MotorConfiguration.IgnitionEvent) randomEnum(MotorConfiguration.IgnitionEvent.class));
|
body.setDefaultIgnitionEvent((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