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:
parent
d45b68a78e
commit
4490a6c1cb
@ -63,6 +63,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
|
|||||||
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
|
import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
|
||||||
import net.sf.openrocket.rocketcomponent.ShockCord;
|
import net.sf.openrocket.rocketcomponent.ShockCord;
|
||||||
import net.sf.openrocket.rocketcomponent.Stage;
|
import net.sf.openrocket.rocketcomponent.Stage;
|
||||||
|
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.Streamer;
|
import net.sf.openrocket.rocketcomponent.Streamer;
|
||||||
import net.sf.openrocket.rocketcomponent.StructuralComponent;
|
import net.sf.openrocket.rocketcomponent.StructuralComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
import net.sf.openrocket.rocketcomponent.SymmetricComponent;
|
||||||
@ -489,11 +490,11 @@ class DocumentConfig {
|
|||||||
Reflection.findMethod(Rocket.class, "setRevision", String.class)));
|
Reflection.findMethod(Rocket.class, "setRevision", String.class)));
|
||||||
|
|
||||||
// Stage
|
// Stage
|
||||||
setters.put("Stage:separationevent", new EnumSetter<Stage.SeparationEvent>(
|
setters.put("Stage:separationevent", new EnumSetter<StageSeparationConfiguration.SeparationEvent>(
|
||||||
Reflection.findMethod(Stage.class, "setSeparationEvent", Stage.SeparationEvent.class),
|
Reflection.findMethod(Stage.class, "setDefaultSeparationEvent", StageSeparationConfiguration.SeparationEvent.class),
|
||||||
Stage.SeparationEvent.class));
|
StageSeparationConfiguration.SeparationEvent.class));
|
||||||
setters.put("Stage:separationdelay", new DoubleSetter(
|
setters.put("Stage:separationdelay", new DoubleSetter(
|
||||||
Reflection.findMethod(Stage.class, "setSeparationDelay", double.class)));
|
Reflection.findMethod(Stage.class, "setDefaultSeparationDelay", double.class)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ public class StageSaver extends ComponentAssemblySaver {
|
|||||||
|
|
||||||
if (stage.getStageNumber() > 0) {
|
if (stage.getStageNumber() > 0) {
|
||||||
elements.add("<separationevent>"
|
elements.add("<separationevent>"
|
||||||
+ stage.getSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
|
+ stage.getDefaultSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
|
||||||
+ "</separationevent>");
|
+ "</separationevent>");
|
||||||
elements.add("<separationdelay>" + stage.getSeparationDelay() + "</separationdelay>");
|
elements.add("<separationdelay>" + stage.getDefaultSeparationDelay() + "</separationdelay>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import net.sf.openrocket.gui.components.StyledLabel.Style;
|
|||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
import net.sf.openrocket.rocketcomponent.RocketComponent;
|
||||||
import net.sf.openrocket.rocketcomponent.Stage;
|
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;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
public class StageConfig extends RocketComponentConfig {
|
public class StageConfig extends RocketComponentConfig {
|
||||||
@ -40,16 +40,16 @@ public class StageConfig extends RocketComponentConfig {
|
|||||||
// Select separation event
|
// Select separation event
|
||||||
panel.add(new StyledLabel(trans.get("separation.lbl.title"), Style.BOLD), "spanx, wrap rel");
|
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, "");
|
panel.add(combo, "");
|
||||||
|
|
||||||
// ... and delay
|
// ... and delay
|
||||||
panel.add(new JLabel(trans.get("separation.lbl.plus")), "");
|
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());
|
JSpinner spin = new JSpinner(dm.getSpinnerModel());
|
||||||
spin.setEditor(new SpinnerEditor(spin));
|
spin.setEditor(new SpinnerEditor(spin));
|
||||||
panel.add(spin, "");
|
panel.add(spin, "width 45");
|
||||||
|
|
||||||
//// seconds
|
//// seconds
|
||||||
panel.add(new JLabel(trans.get("separation.lbl.seconds")), "wrap unrel");
|
panel.add(new JLabel(trans.get("separation.lbl.seconds")), "wrap unrel");
|
||||||
|
@ -1,102 +1,14 @@
|
|||||||
package net.sf.openrocket.rocketcomponent;
|
package net.sf.openrocket.rocketcomponent;
|
||||||
|
|
||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.simulation.FlightEvent;
|
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.util.MathUtil;
|
import net.sf.openrocket.util.MathUtil;
|
||||||
|
|
||||||
public class Stage extends ComponentAssembly {
|
public class Stage extends ComponentAssembly {
|
||||||
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
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;
|
|
||||||
|
|
||||||
|
private final StageSeparationConfiguration defaultConfiguration = new StageSeparationConfiguration();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getComponentName() {
|
public String getComponentName() {
|
||||||
@ -105,28 +17,28 @@ public class Stage extends ComponentAssembly {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SeparationEvent getSeparationEvent() {
|
public StageSeparationConfiguration.SeparationEvent getDefaultSeparationEvent() {
|
||||||
return separationEvent;
|
return defaultConfiguration.getSeparationEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setSeparationEvent(SeparationEvent separationEvent) {
|
public void setDefaultSeparationEvent(StageSeparationConfiguration.SeparationEvent separationEvent) {
|
||||||
if (separationEvent == this.separationEvent)
|
if (separationEvent == defaultConfiguration.getSeparationEvent())
|
||||||
return;
|
return;
|
||||||
this.separationEvent = separationEvent;
|
defaultConfiguration.setSeparationEvent(separationEvent);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public double getSeparationDelay() {
|
public double getDefaultSeparationDelay() {
|
||||||
return separationDelay;
|
return defaultConfiguration.getSeparationDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setSeparationDelay(double separationDelay) {
|
public void setDefaultSeparationDelay(double separationDelay) {
|
||||||
if (MathUtil.equals(separationDelay, this.separationDelay))
|
if (MathUtil.equals(separationDelay, defaultConfiguration.getSeparationDelay()))
|
||||||
return;
|
return;
|
||||||
this.separationDelay = separationDelay;
|
defaultConfiguration.setSeparationDelay(separationDelay);
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -367,9 +367,9 @@ public class BasicEventSimulationEngine implements SimulationEngine {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
Stage stage = (Stage) status.getConfiguration().getRocket().getChild(stageNo);
|
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,
|
addEvent(new FlightEvent(FlightEvent.Type.STAGE_SEPARATION,
|
||||||
event.getTime() + stage.getSeparationDelay(), stage));
|
event.getTime() + stage.getDefaultSeparationDelay(), stage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user