Support for opening recovery device on stage separation
authorplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 19 Apr 2012 17:24:03 +0000 (17:24 +0000)
committerplaa <plaa@180e2498-e6e9-4542-8430-84ac67f01cd8>
Thu, 19 Apr 2012 17:24:03 +0000 (17:24 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@574 180e2498-e6e9-4542-8430-84ac67f01cd8

core/ChangeLog
core/fileformat.txt
core/resources/l10n/messages.properties
core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java
core/src/net/sf/openrocket/file/openrocket/savers/RecoveryDeviceSaver.java
core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java

index 109e5694ddb3b4a64e417a9153bc6e82ce7b2e44..f519be9fb3a24db8b7cfa6907db46c9346e46151 100644 (file)
@@ -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
index 4ea6985c238689a82216b72a99c8c3613e71760c..3e58beee3a0679bc56887bc0ffa47fffd2b148af 100644 (file)
@@ -39,4 +39,5 @@ The following file format versions exist:
       digesting algorithm was changed.  Adds <separationevent> and
       <separationdelay> 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
index b15792f89e0d8157c24ab4ff18f15100ecea0825..e1072d0b0cc4b40b309e7c17e47f948aaf1380fa 100644 (file)
@@ -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
index 7ad6c6af7714e1799406c3d3e962a7d234ffcedf..0525a4ed58be061f68cbbe89071db7d130cb7a01 100644 (file)
@@ -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<RocketComponent> 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<RocketComponent> 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;
index b4c4cc74ff844a2bae888b5a7f7f939e9dca62e6..a73d8fd6988729e0fbbc8c8db015d2b575d62749 100644 (file)
@@ -19,7 +19,7 @@ public class RecoveryDeviceSaver extends MassObjectSaver {
                else
                        elements.add("<cd>" + dev.getCD() + "</cd>");
                
-               elements.add("<deployevent>" + dev.getDeployEvent().name().toLowerCase(Locale.ENGLISH) + "</deployevent>");
+               elements.add("<deployevent>" + dev.getDeployEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "") + "</deployevent>");
                elements.add("<deployaltitude>" + dev.getDeployAltitude() + "</deployaltitude>");
                elements.add("<deploydelay>" + dev.getDeployDelay() + "</deploydelay>");
                elements.add(materialParam(dev.getMaterial()));
index 4156bfbe3167157ac6be8eab1d2a738f445ae1e9..e9c493db7086e76980b9a328f56d05b638c0f814 100644 (file)
@@ -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<Double,Double> altitude = (Pair<Double,Double>)e.getData();
+                               
+                               double alt = ((RecoveryDevice) source).getDeployAltitude();
+                               Pair<Double, Double> altitude = (Pair<Double, Double>) 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();
        }
-
+       
 }