Support for configurable stage separation

This commit is contained in:
Sampo Niskanen 2012-02-10 18:00:43 +00:00
parent 737ede90a7
commit e56dabfd78
8 changed files with 299 additions and 76 deletions

View File

@ -1,3 +1,11 @@
2012-02-10 Sampo Niskanen
* Configurable stage separation events
2012-00-00 Doug Pedrick
* RKT saving support
2011-11-24 Sampo Niskanen
* Released version 1.1.9

View File

@ -674,6 +674,13 @@ ComponentCfgDlg.configuration = configuration
ComponentCfgDlg.configuration1 =
ComponentCfgDlg.Modify = Modify
!StageConfig
StageConfig.tab.Separation = Separation
StageConfig.tab.Separation.ttip = Stage separation options
StageConfig.separation.lbl.title = Select when this stage separates:
StageConfig.separation.lbl.plus = plus
StageConfig.separation.lbl.seconds = seconds
!EllipticalFinSetConfig
EllipticalFinSetCfg.Nbroffins = Number of fins:
EllipticalFinSetCfg.Rotation = Rotation:
@ -1120,6 +1127,14 @@ NoseCone.NoseCone = Nose cone
Transition.Transition = Transition
!Stage
Stage.Stage = Stage
Stage.SeparationEvent.UPPER_IGNITION = Upper stage motor ignition
Stage.SeparationEvent.IGNITION = Current stage motor ignition
Stage.SeparationEvent.BURNOUT = Current stage motor burnout
Stage.SeparationEvent.EJECTION = Current stage ejection charge
Stage.SeparationEvent.LAUNCH = Launch
Stage.SeparationEvent.NEVER = Never
! BodyTube
BodyTube.BodyTube = Body tube
! TubeCoupler

View File

@ -478,6 +478,14 @@ class DocumentConfig {
Reflection.findMethod(Rocket.class, "setDesigner", String.class)));
setters.put("Rocket:revision", new StringSetter(
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:separationdelay", new DoubleSetter(
Reflection.findMethod(Stage.class, "setSeparationDelay", double.class)));
}

View File

@ -1,6 +1,10 @@
package net.sf.openrocket.file.openrocket.savers;
import java.util.ArrayList;
import java.util.List;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Stage;
public class StageSaver extends ComponentAssemblySaver {
@ -10,11 +14,22 @@ public class StageSaver extends ComponentAssemblySaver {
ArrayList<String> list = new ArrayList<String>();
list.add("<stage>");
instance.addParams(c,list);
instance.addParams(c, list);
list.add("</stage>");
return list;
}
@Override
protected void addParams(RocketComponent c, List<String> elements) {
super.addParams(c, elements);
Stage stage = (Stage) c;
if (stage.getStageNumber() > 0) {
elements.add("<separationevent>"
+ stage.getSeparationEvent().name().toLowerCase().replace("_", "")
+ "</separationevent>");
elements.add("<separationdelay>" + stage.getSeparationDelay() + "</separationdelay>");
}
}
}

View File

@ -0,0 +1,60 @@
package net.sf.openrocket.gui.configdialog;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.DoubleModel;
import net.sf.openrocket.gui.adaptors.EnumModel;
import net.sf.openrocket.gui.components.StyledLabel;
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.startup.Application;
public class StageConfig extends RocketComponentConfig {
private static final Translator trans = Application.getTranslator();
public StageConfig(OpenRocketDocument document, RocketComponent component) {
super(document, component);
// Stage separation config (for non-first stage)
if (component.getStageNumber() > 0) {
JPanel tab = separationTab((Stage) component);
tabbedPane.insertTab(trans.get("tab.Separation"), null, tab,
trans.get("tab.Separation.ttip"), 1);
}
}
private JPanel separationTab(Stage stage) {
JPanel panel = new JPanel(new MigLayout("fill"));
// 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"));
panel.add(combo, "");
// ... and delay
panel.add(new JLabel(trans.get("separation.lbl.plus")), "");
DoubleModel dm = new DoubleModel(stage, "SeparationDelay", 0);
JSpinner spin = new JSpinner(dm.getSpinnerModel());
spin.setEditor(new SpinnerEditor(spin));
panel.add(spin, "");
//// seconds
panel.add(new JLabel(trans.get("separation.lbl.seconds")), "wrap unrel");
return panel;
}
}

View File

@ -1,19 +1,137 @@
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 String getComponentName () {
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;
@Override
public String getComponentName() {
//// Stage
return trans.get("Stage.Stage");
}
public SeparationEvent getSeparationEvent() {
return separationEvent;
}
public void setSeparationEvent(SeparationEvent separationEvent) {
if (separationEvent == this.separationEvent)
return;
this.separationEvent = separationEvent;
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
}
public double getSeparationDelay() {
return separationDelay;
}
public void setSeparationDelay(double separationDelay) {
if (MathUtil.equals(separationDelay, this.separationDelay))
return;
this.separationDelay = separationDelay;
fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE);
}
@Override
public boolean allowsChildren() {
return true;
@ -28,7 +146,7 @@ public class Stage extends ComponentAssembly {
* @return Whether such a component can be added.
*/
@Override
public boolean isCompatible (Class<? extends RocketComponent> type) {
public boolean isCompatible(Class<? extends RocketComponent> type) {
return BodyComponent.class.isAssignableFrom(type);
}
}

View File

@ -16,6 +16,7 @@ import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.RecoveryDevice;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.Stage;
import net.sf.openrocket.simulation.exception.MotorIgnitionException;
import net.sf.openrocket.simulation.exception.SimulationException;
import net.sf.openrocket.simulation.exception.SimulationLaunchException;
@ -302,6 +303,12 @@ public class BasicEventSimulationEngine implements SimulationEngine {
for (event = nextEvent(); event != null; event = nextEvent()) {
// Ignore events for components that are no longer attached to the rocket
if (event.getSource() != null && event.getSource().getParent() != null &&
!status.getConfiguration().isStageActive(event.getSource().getStageNumber())) {
continue;
}
// Call simulation listeners, allow aborting event handling
if (!SimulationListenerHelper.fireHandleFlightEvent(status, event)) {
continue;
@ -342,6 +349,19 @@ public class BasicEventSimulationEngine implements SimulationEngine {
}
// Check for stage separation event
for (int stageNo : status.getConfiguration().getActiveStages()) {
if (stageNo == 0)
continue;
Stage stage = (Stage) status.getConfiguration().getRocket().getChild(stageNo);
if (stage.getSeparationEvent().isSeparationEvent(event, stage)) {
addEvent(new FlightEvent(FlightEvent.Type.STAGE_SEPARATION,
event.getTime() + stage.getSeparationDelay(), stage));
}
}
// Check for recovery device deployment, add events to queue
Iterator<RocketComponent> rci = status.getConfiguration().iterator();
while (rci.hasNext()) {
@ -374,14 +394,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
status.setMotorIgnited(true);
status.getFlightData().addEvent(event);
// Add stage separation event if appropriate
int n = component.getStageNumber();
if (n < component.getRocket().getStageCount() - 1) {
if (status.getConfiguration().isStageActive(n + 1)) {
addEvent(new FlightEvent(FlightEvent.Type.STAGE_SEPARATION, event.getTime(),
component.getStage()));
}
}
break;
}
@ -425,7 +437,7 @@ public class BasicEventSimulationEngine implements SimulationEngine {
// TODO: HIGH: Store lower stages to be simulated later
RocketComponent stage = event.getSource();
int n = stage.getStageNumber();
status.getConfiguration().setToStage(n);
status.getConfiguration().setToStage(n - 1);
status.getFlightData().addEvent(event);
break;
}
@ -503,7 +515,6 @@ public class BasicEventSimulationEngine implements SimulationEngine {
return ret;
}
/**
* Add a flight event to the event queue unless a listener aborts adding it.
*

View File

@ -22,68 +22,56 @@ public class FlightEvent implements Comparable<FlightEvent> {
/**
* Rocket launch.
*/
//// Launch
LAUNCH(trans.get("FlightEvent.Type.LAUNCH")),
/**
* Ignition of a motor. Source is the motor mount the motor of which has ignited,
* and the data is the MotorId of the motor instance.
*/
//// Motor ignition
IGNITION(trans.get("FlightEvent.Type.IGNITION")),
/**
* When the motor has lifted off the ground.
*/
//// Lift-off
LIFTOFF(trans.get("FlightEvent.Type.LIFTOFF")),
/**
* Launch rod has been cleared.
*/
//// Launch rod clearance
LAUNCHROD(trans.get("FlightEvent.Type.LAUNCHROD")),
/**
* Burnout of a motor. Source is the motor mount the motor of which has burnt out,
* and the data is the MotorId of the motor instance.
*/
//// Motor burnout
BURNOUT(trans.get("FlightEvent.Type.BURNOUT")),
/**
* Ejection charge of a motor fired. Source is the motor mount the motor of
* which has exploded its ejection charge, and data is the MotorId of the motor instance.
*/
//// Ejection charge
EJECTION_CHARGE(trans.get("FlightEvent.Type.EJECTION_CHARGE")),
/**
* Separation of a stage. Source is the stage which has separated all lower stages.
* Separation of a stage. Source is the stage which is being separated from the upper stages.
*/
//// Stage separation
STAGE_SEPARATION(trans.get("FlightEvent.Type.STAGE_SEPARATION")),
/**
* Apogee has been reached.
*/
//// Apogee
APOGEE(trans.get("FlightEvent.Type.APOGEE")),
/**
* Opening of a recovery device. Source is the RecoveryComponent which has opened.
*/
//// Recovery device deployment
RECOVERY_DEVICE_DEPLOYMENT(trans.get("FlightEvent.Type.RECOVERY_DEVICE_DEPLOYMENT")),
/**
* Ground has been hit after flight.
*/
//// Ground hit
GROUND_HIT(trans.get("FlightEvent.Type.GROUND_HIT")),
/**
* End of simulation. Placing this to the queue will end the simulation.
*/
//// Simulation end
SIMULATION_END(trans.get("FlightEvent.Type.SIMULATION_END")),
/**
* A change in altitude has occurred. Data is a <code>Pair<Double,Double></code>
* which contains the old and new altitudes.
*/
//// Altitude change
ALTITUDE(trans.get("FlightEvent.Type.ALTITUDE"));
private final String name;