diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java index dfc0e4cbf..3f7ac4066 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/OpenRocketLoader.java @@ -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( - Reflection.findMethod(Stage.class, "setSeparationEvent", Stage.SeparationEvent.class), - Stage.SeparationEvent.class)); + setters.put("Stage:separationevent", new EnumSetter( + 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))); } diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java index 23f591f31..d4262b2da 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java @@ -28,9 +28,9 @@ public class StageSaver extends ComponentAssemblySaver { if (stage.getStageNumber() > 0) { elements.add("" - + stage.getSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + + stage.getDefaultSeparationEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + ""); - elements.add("" + stage.getSeparationDelay() + ""); + elements.add("" + stage.getDefaultSeparationDelay() + ""); } } } diff --git a/core/src/net/sf/openrocket/gui/configdialog/StageConfig.java b/core/src/net/sf/openrocket/gui/configdialog/StageConfig.java index 218172972..c7e76e875 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/StageConfig.java +++ b/core/src/net/sf/openrocket/gui/configdialog/StageConfig.java @@ -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(stage, "SeparationEvent")); + JComboBox combo = new JComboBox(new EnumModel(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"); diff --git a/core/src/net/sf/openrocket/rocketcomponent/Stage.java b/core/src/net/sf/openrocket/rocketcomponent/Stage.java index 6ea9c2979..3963117d2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Stage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Stage.java @@ -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); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/StageSeparationConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/StageSeparationConfiguration.java new file mode 100644 index 000000000..1b6c99322 --- /dev/null +++ b/core/src/net/sf/openrocket/rocketcomponent/StageSeparationConfiguration.java @@ -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; + } + +} diff --git a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java index dfd38ffee..1de6ccabb 100644 --- a/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java +++ b/core/src/net/sf/openrocket/simulation/BasicEventSimulationEngine.java @@ -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)); } }