From 643fa71478d2778e2b5a63676aae3215c1f139d3 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 22 Nov 2015 16:25:36 -0500 Subject: [PATCH] [Feature] Implemented RailButton IO code. --- .../file/openrocket/OpenRocketSaver.java | 8 ++-- .../openrocket/importt/DocumentConfig.java | 12 +++++ .../openrocket/savers/RailButtonSaver.java | 42 +++++++++++++++++ .../rocketcomponent/ParallelStage.java | 3 +- .../rocketcomponent/RailButton.java | 47 +++++++++++++++---- 5 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 core/src/net/sf/openrocket/file/openrocket/savers/RailButtonSaver.java diff --git a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java index 508e3e274..8f7403a84 100644 --- a/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/OpenRocketSaver.java @@ -19,14 +19,15 @@ import net.sf.openrocket.document.Simulation; import net.sf.openrocket.document.StorageOptions; import net.sf.openrocket.file.RocketSaver; import net.sf.openrocket.rocketcomponent.AxialStage; -import net.sf.openrocket.rocketcomponent.ParallelStage; import net.sf.openrocket.rocketcomponent.DeploymentConfiguration.DeployEvent; import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent; import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfigurationID; import net.sf.openrocket.rocketcomponent.MotorMount; +import net.sf.openrocket.rocketcomponent.ParallelStage; import net.sf.openrocket.rocketcomponent.PodSet; +import net.sf.openrocket.rocketcomponent.RailButton; import net.sf.openrocket.rocketcomponent.RecoveryDevice; import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.RocketComponent; @@ -227,8 +228,9 @@ public class OpenRocketSaver extends RocketSaver { * NOTE: Remember to update the supported versions in DocumentConfig as well! * * File version 1.8 is required for: - * - external or parallel booster stages + * - external/parallel booster stages * - external pods + * - Rail Buttons * * File version 1.7 is required for: * - simulation extensions @@ -259,7 +261,7 @@ public class OpenRocketSaver extends RocketSaver { ///////////////// // Search the rocket for any Boosters or Pods (version 1.8) for (RocketComponent c : document.getRocket()) { - if ((c instanceof ParallelStage) || (c instanceof PodSet)) { + if ((c instanceof ParallelStage) || (c instanceof PodSet) || (c instanceof RailButton)) { return FILE_VERSION_DIVISOR + 8; } } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java b/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java index 1b70cd063..714659241 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java @@ -75,6 +75,7 @@ class DocumentConfig { constructors.put("freeformfinset", FreeformFinSet.class.getConstructor(new Class[0])); constructors.put("tubefinset", TubeFinSet.class.getConstructor(new Class[0])); constructors.put("launchlug", LaunchLug.class.getConstructor(new Class[0])); + constructors.put("railbutton", RailButton.class.getConstructor(new Class[0])); // Internal components constructors.put("engineblock", EngineBlock.class.getConstructor(new Class[0])); @@ -177,6 +178,17 @@ class DocumentConfig { setters.put("LaunchLug:instanceseparation", new DoubleSetter( Reflection.findMethod( LaunchLug.class, "setInstanceSeparation", double.class))); + // RailButton + setters.put("RailButton:instancecount", new IntSetter( + Reflection.findMethod(LaunchLug.class, "setInstanceCount",int.class))); + setters.put("RailButton:instanceseparation", new DoubleSetter( + Reflection.findMethod( LaunchLug.class, "setInstanceSeparation", double.class))); + setters.put("RailButton:height", new DoubleSetter( + Reflection.findMethod( LaunchLug.class, "setTotalHeight", double.class))); + setters.put("RailButton:outerdiameter", new DoubleSetter( + Reflection.findMethod( LaunchLug.class, "setOuterDiameter", double.class))); + + // Transition setters.put("Transition:shape", new EnumSetter( Reflection.findMethod(Transition.class, "setType", Transition.Shape.class), diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RailButtonSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RailButtonSaver.java new file mode 100644 index 000000000..1f7fb4dcf --- /dev/null +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RailButtonSaver.java @@ -0,0 +1,42 @@ +package net.sf.openrocket.file.openrocket.savers; + +import java.util.ArrayList; +import java.util.List; + +import net.sf.openrocket.rocketcomponent.RailButton; + + +public class RailButtonSaver extends ExternalComponentSaver { + + private static final RailButtonSaver instance = new RailButtonSaver(); + + public static List getElements(net.sf.openrocket.rocketcomponent.RocketComponent c) { + List list = new ArrayList(); + + list.add(""); + instance.addParams(c, list); + list.add(""); + + return list; + } + + @Override + protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List elements) { + super.addParams(c, elements); + RailButton rb = (RailButton) c; + + addElement( elements, "outerradius", rb.getOuterRadius()); + addElement( elements, "height", rb.getTotalHeight()); + addElement( elements, "radialDirection", rb.getRadialDirection()); + } + + protected static void addElement( final List elements, final String enclosingTag, final double value){ + addElement( elements, enclosingTag, Double.toString( value )); + } + + protected static void addElement( final List elements, final String enclosingTag, final String value){ + elements.add("<"+enclosingTag+">" + value + ""); + } + + +} diff --git a/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java b/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java index e46e4d753..0c1bdfbdc 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/ParallelStage.java @@ -7,6 +7,7 @@ import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.BugException; import net.sf.openrocket.util.Coordinate; +import net.sf.openrocket.util.MathUtil; public class ParallelStage extends AxialStage implements FlightConfigurableComponent, RingInstanceable { @@ -209,7 +210,7 @@ public class ParallelStage extends AxialStage implements FlightConfigurableCompo @Override public void setAngularOffset(final double angle_rad) { mutex.verify(); - this.angularPosition_rad = angle_rad; + this.angularPosition_rad = MathUtil.reduce180( angle_rad); fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RailButton.java b/core/src/net/sf/openrocket/rocketcomponent/RailButton.java index e4603ac82..a7e567bfc 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RailButton.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RailButton.java @@ -28,7 +28,6 @@ public class RailButton extends ExternalComponent implements LineInstanceable { /* * Rail Button Dimensions (side view) * - * * <= outer dia => * v * ^ [[[[[[]]]]]] lipThickness @@ -50,23 +49,34 @@ public class RailButton extends ExternalComponent implements LineInstanceable { protected final static double MINIMUM_STANDOFF= 0.001; - private double radialDirection = 0; private int instanceCount = 1; private double instanceSeparation = 0; // front-front along the positive rocket axis. i.e. [1,0,0]; - public RailButton( final double id, final double od, final double ht ) { - this( od, id, ht, ht/4, ht/4); + public RailButton(){ + super(Position.MIDDLE); + this.outerDiameter = 0; + this.height = 0; + this.innerDiameter = 0; + this.thickness = 0; + this.setStandoff( 0); + this.setInstanceSeparation( 1.0); + } + + public RailButton( final double od, final double ht ) { + this(); + this.setOuterDiameter( od); + this.setTotalHeight( ht); } public RailButton( final double od, final double id, final double h, final double _thickness, final double _standoff ) { super(Position.MIDDLE); - this.innerDiameter = id; this.outerDiameter = od; - this.height = h-_standoff; + this.height = h-_standoff; + this.innerDiameter = id; this.thickness = _thickness; this.setStandoff( _standoff); - this.instanceSeparation = od*2; + this.setInstanceSeparation( od*2); } private static final RailButton make1010Button(){ @@ -79,6 +89,8 @@ public class RailButton extends ExternalComponent implements LineInstanceable { rb1010.setMassOverridden(true); rb1010.setOverrideMass(0.0019); + rb1010.setInstanceCount(1); + rb1010.setInstanceSeparation( od*6 ); return rb1010; } @@ -121,20 +133,37 @@ public class RailButton extends ExternalComponent implements LineInstanceable { public void setInnerDiameter( final double newID ){ this.innerDiameter = newID; + fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } public void setOuterDiameter( final double newOD ){ this.outerDiameter = newOD; + if( 0 == this.innerDiameter){ + this.innerDiameter = this.outerDiameter*0.8; + } + if( 0 == this.instanceSeparation ){ + this.instanceSeparation = newOD*8; + } + fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } - public void setTotalHeight( final double newHeight ) { - this.height = newHeight-this.standoff; + if( 0 == this.thickness){ + this.thickness = newHeight*0.25; + } + if( 0 == this.standoff){ + this.height = newHeight*0.75; + this.offset = newHeight*0.25; + }else{ + this.height = newHeight-this.standoff; + } + fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } public void setThickness( final double newThickness ) { this.thickness = newThickness; + fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } // public void setThickness(double thickness) {