Prepare stages to be configurable by creating a

StageSeparationConfiguration object and renaming the current methods on
Stage to be for the default configuration.
This commit is contained in:
batwings 2012-10-24 14:06:34 -05:00
parent d45b68a78e
commit 4490a6c1cb
6 changed files with 135 additions and 112 deletions

View File

@ -63,6 +63,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
import net.sf.openrocket.rocketcomponent.ShockCord;
import net.sf.openrocket.rocketcomponent.Stage;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
import net.sf.openrocket.rocketcomponent.Streamer;
import net.sf.openrocket.rocketcomponent.StructuralComponent;
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
@ -489,11 +490,11 @@ class DocumentConfig {
Reflection.findMethod(Rocket.class, "setRevision", String.class)));
// Stage
setters.put("Stage:separationevent", new EnumSetter<Stage.SeparationEvent>(
Reflection.findMethod(Stage.class, "setSeparationEvent", Stage.SeparationEvent.class),
Stage.SeparationEvent.class));
setters.put("Stage:separationevent", new EnumSetter<StageSeparationConfiguration.SeparationEvent>(
Reflection.findMethod(Stage.class, "setDefaultSeparationEvent", StageSeparationConfiguration.SeparationEvent.class),
StageSeparationConfiguration.SeparationEvent.class));
setters.put("Stage:separationdelay", new DoubleSetter(
Reflection.findMethod(Stage.class, "setSeparationDelay", double.class)));
Reflection.findMethod(Stage.class, "setDefaultSeparationDelay", double.class)));
}

View File

@ -28,9 +28,9 @@ public class StageSaver extends ComponentAssemblySaver {
if (stage.getStageNumber() > 0) {
elements.add("<separationevent>"
+ stage.getSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
+ stage.getDefaultSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
+ "</separationevent>");
elements.add("<separationdelay>" + stage.getSeparationDelay() + "</separationdelay>");
elements.add("<separationdelay>" + stage.getDefaultSeparationDelay() + "</separationdelay>");
}
}
}

View File

@ -15,7 +15,7 @@ import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Stage;
import net.sf.openrocket.rocketcomponent.Stage.SeparationEvent;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
import net.sf.openrocket.startup.Application;
public class StageConfig extends RocketComponentConfig {
@ -40,16 +40,16 @@ public class StageConfig extends RocketComponentConfig {
// Select separation event
panel.add(new StyledLabel(trans.get("separation.lbl.title"), Style.BOLD), "spanx, wrap rel");
JComboBox combo = new JComboBox(new EnumModel<SeparationEvent>(stage, "SeparationEvent"));
JComboBox combo = new JComboBox(new EnumModel<StageSeparationConfiguration.SeparationEvent>(stage, "DefaultSeparationEvent"));
panel.add(combo, "");
// ... and delay
panel.add(new JLabel(trans.get("separation.lbl.plus")), "");
DoubleModel dm = new DoubleModel(stage, "SeparationDelay", 0);
DoubleModel dm = new DoubleModel(stage, "DefaultSeparationDelay", 0);
JSpinner spin = new JSpinner(dm.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "");
panel.add(spin, "width 45");
//// seconds
panel.add(new JLabel(trans.get("separation.lbl.seconds")), "wrap unrel");

View File

@ -1,102 +1,14 @@
package net.sf.openrocket.rocketcomponent;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.MathUtil;
public class Stage extends ComponentAssembly {
private static final Translator trans = Application.getTranslator();
public static enum SeparationEvent {
//// Upper stage motor ignition
UPPER_IGNITION("Stage.SeparationEvent.UPPER_IGNITION") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.IGNITION)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition + 1);
}
},
//// Current stage motor ignition
IGNITION("Stage.SeparationEvent.IGNITION") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.IGNITION)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition);
}
},
//// Current stage motor burnout
BURNOUT("Stage.SeparationEvent.BURNOUT") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.BURNOUT)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition);
}
},
//// Current stage ejection charge
EJECTION("Stage.SeparationEvent.EJECTION") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition);
}
},
//// Launch
LAUNCH("Stage.SeparationEvent.LAUNCH") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
return e.getType() == FlightEvent.Type.LAUNCH;
}
},
//// Never
NEVER("Stage.SeparationEvent.NEVER") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
return false;
}
},
;
private final String description;
SeparationEvent(String description) {
this.description = description;
}
/**
* Test whether a specific event is a stage separation event.
*/
public abstract boolean isSeparationEvent(FlightEvent e, Stage stage);
@Override
public String toString() {
return trans.get(description);
}
};
private SeparationEvent separationEvent = SeparationEvent.UPPER_IGNITION;
private double separationDelay = 0;
static final Translator trans = Application.getTranslator();
private final StageSeparationConfiguration defaultConfiguration = new StageSeparationConfiguration();
@Override
public String getComponentName() {
@ -105,28 +17,28 @@ public class Stage extends ComponentAssembly {
}
public SeparationEvent getSeparationEvent() {
return separationEvent;
public StageSeparationConfiguration.SeparationEvent getDefaultSeparationEvent() {
return defaultConfiguration.getSeparationEvent();
}
public void setSeparationEvent(SeparationEvent separationEvent) {
if (separationEvent == this.separationEvent)
public void setDefaultSeparationEvent(StageSeparationConfiguration.SeparationEvent separationEvent) {
if (separationEvent == defaultConfiguration.getSeparationEvent())
return;
this.separationEvent = separationEvent;
defaultConfiguration.setSeparationEvent(separationEvent);
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
}
public double getSeparationDelay() {
return separationDelay;
public double getDefaultSeparationDelay() {
return defaultConfiguration.getSeparationDelay();
}
public void setSeparationDelay(double separationDelay) {
if (MathUtil.equals(separationDelay, this.separationDelay))
public void setDefaultSeparationDelay(double separationDelay) {
if (MathUtil.equals(separationDelay, defaultConfiguration.getSeparationDelay()))
return;
this.separationDelay = separationDelay;
defaultConfiguration.setSeparationDelay(separationDelay);
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
}

View File

@ -0,0 +1,110 @@
package net.sf.openrocket.rocketcomponent;
import net.sf.openrocket.simulation.FlightEvent;
public class StageSeparationConfiguration {
private StageSeparationConfiguration.SeparationEvent separationEvent = StageSeparationConfiguration.SeparationEvent.UPPER_IGNITION;
private double separationDelay = 0;
public static enum SeparationEvent {
//// Upper stage motor ignition
UPPER_IGNITION("Stage.SeparationEvent.UPPER_IGNITION") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.IGNITION)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition + 1);
}
},
//// Current stage motor ignition
IGNITION("Stage.SeparationEvent.IGNITION") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.IGNITION)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition);
}
},
//// Current stage motor burnout
BURNOUT("Stage.SeparationEvent.BURNOUT") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.BURNOUT)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition);
}
},
//// Current stage ejection charge
EJECTION("Stage.SeparationEvent.EJECTION") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
if (e.getType() != FlightEvent.Type.EJECTION_CHARGE)
return false;
int ignition = e.getSource().getStageNumber();
int mount = stage.getStageNumber();
return (mount == ignition);
}
},
//// Launch
LAUNCH("Stage.SeparationEvent.LAUNCH") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
return e.getType() == FlightEvent.Type.LAUNCH;
}
},
//// Never
NEVER("Stage.SeparationEvent.NEVER") {
@Override
public boolean isSeparationEvent(FlightEvent e, Stage stage) {
return false;
}
},
;
private final String description;
SeparationEvent(String description) {
this.description = description;
}
/**
* Test whether a specific event is a stage separation event.
*/
public abstract boolean isSeparationEvent(FlightEvent e, Stage stage);
@Override
public String toString() {
return Stage.trans.get(description);
}
}
public StageSeparationConfiguration.SeparationEvent getSeparationEvent() {
return separationEvent;
}
public void setSeparationEvent(
StageSeparationConfiguration.SeparationEvent separationEvent) {
this.separationEvent = separationEvent;
}
public double getSeparationDelay() {
return separationDelay;
}
public void setSeparationDelay(double separationDelay) {
this.separationDelay = separationDelay;
}
}

View File

@ -367,9 +367,9 @@ public class BasicEventSimulationEngine implements SimulationEngine {
continue;
Stage stage = (Stage) status.getConfiguration().getRocket().getChild(stageNo);
if (stage.getSeparationEvent().isSeparationEvent(event, stage)) {
if (stage.getDefaultSeparationEvent().isSeparationEvent(event, stage)) {
addEvent(new FlightEvent(FlightEvent.Type.STAGE_SEPARATION,
event.getTime() + stage.getSeparationDelay(), stage));
event.getTime() + stage.getDefaultSeparationDelay(), stage));
}
}