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:
kruland2607 2012-10-18 14:29:11 -05:00
parent 8c56b7b793
commit 5b32242b45
11 changed files with 62 additions and 53 deletions

View File

@ -1041,7 +1041,7 @@ class MotorMountHandler extends AbstractElementHandler {
warnings.add(Warning.fromString("Unknown ignition event type '" + content + "', ignoring."));
return;
}
mount.setIgnitionEvent(event);
mount.setDefaultIgnitionEvent(event);
return;
}
@ -1053,7 +1053,7 @@ class MotorMountHandler extends AbstractElementHandler {
warnings.add(Warning.fromString("Illegal ignition delay specified, ignoring."));
return;
}
mount.setIgnitionDelay(d);
mount.setDefaultIgnitionDelay(d);
return;
}

View File

@ -158,10 +158,10 @@ public class RocketComponentSaver {
}
elements.add(" <ignitionevent>"
+ mount.getIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
+ mount.getDefaultIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
+ "</ignitionevent>");
elements.add(" <ignitiondelay>" + mount.getIgnitionDelay() + "</ignitiondelay>");
elements.add(" <ignitiondelay>" + mount.getDefaultIgnitionDelay() + "</ignitiondelay>");
elements.add(" <overhang>" + mount.getMotorOverhang() + "</overhang>");
elements.add("</motormount>");

View File

@ -240,7 +240,7 @@ public class MotorConfigurationPanel extends JPanel {
if (motor == null)
//// None
return null;
MotorConfiguration.IgnitionEvent ignition = mount.getIgnitionEvent();
MotorConfiguration.IgnitionEvent ignition = mount.getDefaultIgnitionEvent();
return ignition.toString();
}

View File

@ -309,7 +309,7 @@ public class SimulationRunDialog extends JDialog {
Iterator<MotorMount> iterator = config.motorIterator();
while (iterator.hasNext()) {
MotorMount m = iterator.next();
if (m.getIgnitionEvent() == MotorConfiguration.IgnitionEvent.LAUNCH)
if (m.getDefaultIgnitionEvent() == MotorConfiguration.IgnitionEvent.LAUNCH)
launchBurn = MathUtil.max(launchBurn, m.getMotor(id).getBurnTimeEstimate());
else
otherBurn = otherBurn + m.getMotor(id).getBurnTimeEstimate();

View File

@ -4,10 +4,10 @@ import java.util.HashMap;
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 MotorConfiguration defaultConfiguration = new MotorConfiguration();
private MotorConfiguration defaultConfiguration = MotorConfiguration.makeDefaultMotorConfiguration();
@Override
public MotorConfiguration getFlightConfiguration(String configId) {
@ -39,7 +39,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
defaultConfiguration = config;
}
public Motor getMotor(String id) {
Motor getMotor(String id) {
if (id == null)
return null;
@ -57,7 +57,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
* @param 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 (motor != null) {
throw new IllegalArgumentException("Cannot set non-null motor for id null");
@ -79,7 +79,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
return true;
}
public double getMotorDelay(String id) {
double getMotorDelay(String id) {
MotorConfiguration current = getFlightConfiguration(id);
Double delay = ( current == null ) ? null : current.getEjectionDelay();
if (delay == null)
@ -94,7 +94,7 @@ public class BaseMotorMount implements SupportsFlightConfiguration<MotorConfigur
* @param delay
* @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);
if ( current == null ) {
current = new MotorConfiguration();

View File

@ -2,7 +2,6 @@ package net.sf.openrocket.rocketcomponent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.motor.Motor;
@ -406,32 +405,29 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
public double getMotorMountDiameter() {
return getInnerRadius() * 2;
}
// FIXME - rename to getDefaultIgnitionEvent
@Override
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
public MotorConfiguration.IgnitionEvent getDefaultIgnitionEvent() {
return getDefaultFlightConfiguration().getIgnitionEvent();
}
// FIXME
@Override
public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent();
public void setDefaultIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
MotorConfiguration.IgnitionEvent ignitionEvent = getDefaultIgnitionEvent();
if (ignitionEvent == event)
return;
getDefaultFlightConfiguration().setIgnitionEvent(event);
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
}
// FIXME
@Override
public double getIgnitionDelay() {
public double getDefaultIgnitionDelay() {
return getDefaultFlightConfiguration().getIgnitionDelay();
}
// FIXME
@Override
public void setIgnitionDelay(double delay) {
double ignitionDelay = getIgnitionDelay();
public void setDefaultIgnitionDelay(double delay) {
double ignitionDelay = getDefaultIgnitionDelay();
if (MathUtil.equals(delay, ignitionDelay))
return;
getDefaultFlightConfiguration().setIgnitionDelay(delay);
@ -462,8 +458,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
return new Coordinate(this.getLength() - motor.getLength() + this.getMotorOverhang());
}
/*
* (non-Javadoc)
@ -471,7 +465,6 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial
*
* @see rocketcomponent.RocketComponent#copy()
*/
@SuppressWarnings("unchecked")
@Override
protected RocketComponent copyWithOriginalID() {
RocketComponent c = super.copyWithOriginalID();

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.rocketcomponent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import net.sf.openrocket.l10n.Translator;
@ -273,32 +272,28 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
return getInnerRadius() * 2;
}
// FIXME - rename to getDefaultIgnitionEvent
@Override
public MotorConfiguration.IgnitionEvent getIgnitionEvent() {
public MotorConfiguration.IgnitionEvent getDefaultIgnitionEvent() {
return getDefaultFlightConfiguration().getIgnitionEvent();
}
// FIXME
@Override
public void setIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
MotorConfiguration.IgnitionEvent ignitionEvent = getIgnitionEvent();
public void setDefaultIgnitionEvent(MotorConfiguration.IgnitionEvent event) {
MotorConfiguration.IgnitionEvent ignitionEvent = getDefaultIgnitionEvent();
if (ignitionEvent == event)
return;
getDefaultFlightConfiguration().setIgnitionEvent(event);
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
}
// FIXME
@Override
public double getIgnitionDelay() {
public double getDefaultIgnitionDelay() {
return getDefaultFlightConfiguration().getIgnitionDelay();
}
// FIXME
@Override
public void setIgnitionDelay(double delay) {
double ignitionDelay = getIgnitionDelay();
public void setDefaultIgnitionDelay(double delay) {
double ignitionDelay = getDefaultIgnitionDelay();
if (MathUtil.equals(delay, ignitionDelay))
return;
getDefaultFlightConfiguration().setIgnitionDelay(delay);
@ -317,12 +312,12 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
}
}
@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);
@ -342,7 +337,6 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
}
@Override
public Coordinate getMotorPosition(String id) {
Motor motor = getMotor(id);
@ -359,7 +353,6 @@ public class InnerTube extends ThicknessRingComponent implements Clusterable, Ra
*
* @see rocketcomponent.RocketComponent#copy()
*/
@SuppressWarnings("unchecked")
@Override
protected RocketComponent copyWithOriginalID() {
RocketComponent c = super.copyWithOriginalID();

View File

@ -7,11 +7,34 @@ import net.sf.openrocket.startup.Application;
public class MotorConfiguration implements Cloneable {
private MotorConfiguration.IgnitionEvent ignitionEvent = MotorConfiguration.IgnitionEvent.AUTOMATIC;
private double ignitionDelay = 0;
private MotorConfiguration.IgnitionEvent ignitionEvent;
private Double ignitionDelay;
private Motor motor = null;
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() {
return ignitionEvent;
}
@ -20,11 +43,11 @@ public class MotorConfiguration implements Cloneable {
this.ignitionEvent = ignitionEvent;
}
public double getIgnitionDelay() {
public Double getIgnitionDelay() {
return ignitionDelay;
}
public void setIgnitionDelay(double ignitionDelay) {
public void setIgnitionDelay(Double ignitionDelay) {
this.ignitionDelay = ignitionDelay;
}

View File

@ -77,14 +77,14 @@ public interface MotorMount extends ChangeSource, SupportsFlightConfiguration<Mo
*
* @return the {@link MotorConfiguration.IgnitionEvent} that ignites this motor.
*/
public MotorConfiguration.IgnitionEvent getIgnitionEvent();
public MotorConfiguration.IgnitionEvent getDefaultIgnitionEvent();
/**
* Sets the event 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
*/
public double getIgnitionDelay();
public double getDefaultIgnitionDelay();
/**
* Sets the ignition delay of this motor.
*
* @param delay the ignition delay.
*/
public void setIgnitionDelay(double delay);
public void setDefaultIgnitionDelay(double delay);
/**

View File

@ -348,9 +348,9 @@ public class BasicEventSimulationEngine implements SimulationEngine {
MotorMount mount = status.getMotorConfiguration().getMotorMount(id);
RocketComponent component = (RocketComponent) mount;
if (mount.getIgnitionEvent().isActivationEvent(event, component)) {
if (mount.getDefaultIgnitionEvent().isActivationEvent(event, component)) {
addEvent(new FlightEvent(FlightEvent.Type.IGNITION,
status.getSimulationTime() + mount.getIgnitionDelay(),
status.getSimulationTime() + mount.getDefaultIgnitionDelay(),
component, id));
}
}

View File

@ -135,8 +135,8 @@ public class TestRockets {
setBasics(body);
body.setThickness(rnd(0.002));
body.setFilled(rnd.nextBoolean());
body.setIgnitionDelay(rnd.nextDouble() * 3);
body.setIgnitionEvent((MotorConfiguration.IgnitionEvent) randomEnum(MotorConfiguration.IgnitionEvent.class));
body.setDefaultIgnitionDelay(rnd.nextDouble() * 3);
body.setDefaultIgnitionEvent((MotorConfiguration.IgnitionEvent) randomEnum(MotorConfiguration.IgnitionEvent.class));
body.setLength(rnd(0.3));
body.setMotorMount(rnd.nextBoolean());
body.setMotorOverhang(rnd.nextGaussian() * 0.03);