[Feature] Implemented RailButton IO code.
This commit is contained in:
parent
52ee7ba750
commit
643fa71478
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<Transition.Shape>(
|
||||
Reflection.findMethod(Transition.class, "setType", Transition.Shape.class),
|
||||
|
@ -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<String> getElements(net.sf.openrocket.rocketcomponent.RocketComponent c) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
|
||||
list.add("<railbutton>");
|
||||
instance.addParams(c, list);
|
||||
list.add("</railbutton>");
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List<String> 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<String> elements, final String enclosingTag, final double value){
|
||||
addElement( elements, enclosingTag, Double.toString( value ));
|
||||
}
|
||||
|
||||
protected static void addElement( final List<String> elements, final String enclosingTag, final String value){
|
||||
elements.add("<"+enclosingTag+">" + value + "</"+enclosingTag+">");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user