From: plaa Date: Thu, 19 Apr 2012 17:24:03 +0000 (+0000) Subject: Support for opening recovery device on stage separation X-Git-Tag: upstream/12.09^2~346 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=5a526e3de9261f5485ad7b519dc981fd884a7953;p=debian%2Fopenrocket Support for opening recovery device on stage separation git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@574 180e2498-e6e9-4542-8430-84ac67f01cd8 --- diff --git a/core/ChangeLog b/core/ChangeLog index 109e5694..f519be9f 100644 --- a/core/ChangeLog +++ b/core/ChangeLog @@ -1,6 +1,10 @@ +2012-04-19 Sampo Niskanen + + * Allow opening recovery device on stage separation + 2012-04-11 Doug Pedrick - * [BUG] Printed simulation did not honor launch conditions + * [BUG] Printed simulation did not honor launch conditions 2012-04-09 Sampo Niskanen @@ -17,7 +21,7 @@ 2012-03-25 Doug Pedrick - * Printed rocket figure in design report now honors rotation angle of main figure; fixed bug in layout where the + * Printed rocket figure in design report now honors rotation angle of main figure; fixed bug in layout where the figure was clipped in the page margin. 2012-03-18 Jason Blood diff --git a/core/fileformat.txt b/core/fileformat.txt index 4ea6985c..3e58beee 100644 --- a/core/fileformat.txt +++ b/core/fileformat.txt @@ -39,4 +39,5 @@ The following file format versions exist: digesting algorithm was changed. Adds and elements to stage components (except sustainer). -1.5: Introduced with OpenRocket 12.xx. Added ComponentPresets. \ No newline at end of file +1.5: Introduced with OpenRocket 12.xx. Added ComponentPresets. + Added lowerstageseparation as recovery device deployment event. \ No newline at end of file diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index b15792f8..e1072d0b 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1197,6 +1197,8 @@ RecoveryDevice.DeployEvent.LAUNCH = Launch (plus NN seconds) RecoveryDevice.DeployEvent.EJECTION = First ejection charge of this stage RecoveryDevice.DeployEvent.APOGEE = Apogee RecoveryDevice.DeployEvent.ALTITUDE = Specific altitude during descent +RecoveryDevice.DeployEvent.CURRENT_STAGE_SEPARATION = Current stage separation +RecoveryDevice.DeployEvent.LOWER_STAGE_SEPARATION = Lower stage separation RecoveryDevice.DeployEvent.NEVER = Never ! FlightEvent diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java index 7ad6c6af..0525a4ed 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java @@ -19,6 +19,8 @@ import net.sf.openrocket.file.RocketSaver; import net.sf.openrocket.logging.LogHelper; import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.MotorMount; +import net.sf.openrocket.rocketcomponent.RecoveryDevice; +import net.sf.openrocket.rocketcomponent.RecoveryDevice.DeployEvent; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.TubeCoupler; @@ -186,6 +188,7 @@ public class OpenRocketSaver extends RocketSaver { /* * File version 1.5 is requires for: * - saving designs using ComponentPrests + * - recovery device deployment on lower stage separation * * File version 1.4 is required for: * - saving simulation data @@ -198,31 +201,29 @@ public class OpenRocketSaver extends RocketSaver { * Otherwise use version 1.0. */ - // Search the rocket for any ComponentPrests - { - Rocket r = document.getRocket(); - Iterator componentIterator = r.iterator(); - boolean usesComponentPreset = false; - while ( !usesComponentPreset && componentIterator.hasNext() ) { - RocketComponent c = componentIterator.next(); - if ( c.getPresetComponent() != null ) { - usesComponentPreset = true; - } - } - if ( usesComponentPreset ) { + // Search the rocket for any ComponentPresets (version 1.5) + for (RocketComponent c : document.getRocket()) { + if (c.getPresetComponent() != null) { return FILE_VERSION_DIVISOR + 5; } } + // Search for recovery device deployment type LOWER_STAGE_SEPARATION (version 1.5) + for (RocketComponent c : document.getRocket()) { + if (c instanceof RecoveryDevice) { + if (((RecoveryDevice) c).getDeployEvent() == DeployEvent.LOWER_STAGE_SEPARATION) { + return FILE_VERSION_DIVISOR + 5; + } + } + } + // Check if design has simulations defined (version 1.4) if (document.getSimulationCount() > 0) { return FILE_VERSION_DIVISOR + 4; } // Check for motor definitions (version 1.4) - Iterator iterator = document.getRocket().iterator(); - while (iterator.hasNext()) { - RocketComponent c = iterator.next(); + for (RocketComponent c : document.getRocket()) { if (!(c instanceof MotorMount)) continue; @@ -235,10 +236,7 @@ public class OpenRocketSaver extends RocketSaver { } // Check for fin tabs (version 1.1) - iterator = document.getRocket().iterator(); - while (iterator.hasNext()) { - RocketComponent c = iterator.next(); - + for (RocketComponent c : document.getRocket()) { // Check for fin tabs if (c instanceof FinSet) { FinSet fin = (FinSet) c; diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java index b4c4cc74..a73d8fd6 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java @@ -19,7 +19,7 @@ public class RecoveryDeviceSaver extends MassObjectSaver { else elements.add("" + dev.getCD() + ""); - elements.add("" + dev.getDeployEvent().name().toLowerCase(Locale.ENGLISH) + ""); + elements.add("" + dev.getDeployEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + ""); elements.add("" + dev.getDeployAltitude() + ""); elements.add("" + dev.getDeployDelay() + ""); elements.add(materialParam(dev.getMaterial())); diff --git a/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java b/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java index 4156bfbe..e9c493db 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java @@ -22,16 +22,14 @@ import net.sf.openrocket.util.Pair; */ public abstract class RecoveryDevice extends MassObject { private static final Translator trans = Application.getTranslator(); - + public static enum DeployEvent { - //// Launch (plus NN seconds) LAUNCH(trans.get("RecoveryDevice.DeployEvent.LAUNCH")) { @Override public boolean isActivationEvent(FlightEvent e, RocketComponent source) { return e.getType() == FlightEvent.Type.LAUNCH; } }, - //// First ejection charge of this stage EJECTION(trans.get("RecoveryDevice.DeployEvent.EJECTION")) { @Override public boolean isActivationEvent(FlightEvent e, RocketComponent source) { @@ -41,35 +39,42 @@ public abstract class RecoveryDevice extends MassObject { return charge.getStageNumber() == source.getStageNumber(); } }, - //// Apogee APOGEE(trans.get("RecoveryDevice.DeployEvent.APOGEE")) { @Override public boolean isActivationEvent(FlightEvent e, RocketComponent source) { return e.getType() == FlightEvent.Type.APOGEE; } }, - //// Specific altitude during descent ALTITUDE(trans.get("RecoveryDevice.DeployEvent.ALTITUDE")) { @SuppressWarnings("unchecked") @Override public boolean isActivationEvent(FlightEvent e, RocketComponent source) { if (e.getType() != FlightEvent.Type.ALTITUDE) return false; - - double alt = ((RecoveryDevice)source).getDeployAltitude(); - Pair altitude = (Pair)e.getData(); + + double alt = ((RecoveryDevice) source).getDeployAltitude(); + Pair altitude = (Pair) e.getData(); return (altitude.getU() >= alt) && (altitude.getV() <= alt); } }, - //// Never + LOWER_STAGE_SEPARATION(trans.get("RecoveryDevice.DeployEvent.LOWER_STAGE_SEPARATION")) { + @Override + public boolean isActivationEvent(FlightEvent e, RocketComponent source) { + if (e.getType() != FlightEvent.Type.STAGE_SEPARATION) + return false; + + int separation = e.getSource().getStageNumber(); + int current = source.getStageNumber(); + return (current + 1 == separation); + } + }, NEVER(trans.get("RecoveryDevice.DeployEvent.NEVER")) { @Override public boolean isActivationEvent(FlightEvent e, RocketComponent source) { return false; } - } - ; + }; private final String description; @@ -83,7 +88,7 @@ public abstract class RecoveryDevice extends MassObject { public String toString() { return description; } - + } @@ -96,7 +101,7 @@ public abstract class RecoveryDevice extends MassObject { private Material.Surface material; - + public RecoveryDevice() { this(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE)); @@ -106,19 +111,19 @@ public abstract class RecoveryDevice extends MassObject { super(); setMaterial(material); } - + public RecoveryDevice(double length, double radius, Material material) { super(length, radius); setMaterial(material); } - + public abstract double getArea(); public abstract double getComponentCD(double mach); - + public double getCD() { @@ -130,7 +135,7 @@ public abstract class RecoveryDevice extends MassObject { cd = getComponentCD(mach); return cd; } - + public void setCD(double cd) { if (MathUtil.equals(this.cd, cd) && !isCDAutomatic()) return; @@ -138,7 +143,7 @@ public abstract class RecoveryDevice extends MassObject { this.cdAutomatic = false; fireComponentChangeEvent(ComponentChangeEvent.AERODYNAMIC_CHANGE); } - + public boolean isCDAutomatic() { return cdAutomatic; @@ -159,11 +164,11 @@ public abstract class RecoveryDevice extends MassObject { public final void setMaterial(Material mat) { if (!(mat instanceof Material.Surface)) { - throw new IllegalArgumentException("Attempted to set non-surface material "+mat); + throw new IllegalArgumentException("Attempted to set non-surface material " + mat); } if (mat.equals(material)) return; - this.material = (Material.Surface)mat; + this.material = (Material.Surface) mat; fireComponentChangeEvent(ComponentChangeEvent.MASS_CHANGE); } @@ -173,7 +178,7 @@ public abstract class RecoveryDevice extends MassObject { public DeployEvent getDeployEvent() { return deployEvent; } - + public void setDeployEvent(DeployEvent deployEvent) { if (this.deployEvent == deployEvent) return; @@ -181,11 +186,11 @@ public abstract class RecoveryDevice extends MassObject { fireComponentChangeEvent(ComponentChangeEvent.EVENT_CHANGE); } - + public double getDeployAltitude() { return deployAltitude; } - + public void setDeployAltitude(double deployAltitude) { if (MathUtil.equals(this.deployAltitude, deployAltitude)) return; @@ -210,10 +215,10 @@ public abstract class RecoveryDevice extends MassObject { } - + @Override public double getComponentMass() { return getArea() * getMaterial().getDensity(); } - + }