added save-to-ork code, removed stage rotation parameter.
This commit is contained in:
parent
8b4c1c386b
commit
d5de1cbac4
@ -1,6 +1,7 @@
|
|||||||
package net.sf.openrocket.file.openrocket.savers;
|
package net.sf.openrocket.file.openrocket.savers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@ -28,6 +29,10 @@ public class StageSaver extends ComponentAssemblySaver {
|
|||||||
super.addParams(c, elements);
|
super.addParams(c, elements);
|
||||||
Stage stage = (Stage) c;
|
Stage stage = (Stage) c;
|
||||||
|
|
||||||
|
if (stage.getOutside()) {
|
||||||
|
elements.addAll(this.addStageReplicationParams(stage));
|
||||||
|
}
|
||||||
|
|
||||||
if (stage.getStageNumber() > 0) {
|
if (stage.getStageNumber() > 0) {
|
||||||
// NOTE: Default config must be BEFORE overridden config for proper backward compatibility later on
|
// NOTE: Default config must be BEFORE overridden config for proper backward compatibility later on
|
||||||
elements.addAll(separationConfig(stage.getStageSeparationConfiguration().getDefault(), false));
|
elements.addAll(separationConfig(stage.getStageSeparationConfiguration().getDefault(), false));
|
||||||
@ -49,11 +54,43 @@ public class StageSaver extends ComponentAssemblySaver {
|
|||||||
elements.add("<separationconfiguration configid=\"" + id + "\">");
|
elements.add("<separationconfiguration configid=\"" + id + "\">");
|
||||||
elements.addAll(separationConfig(config, true));
|
elements.addAll(separationConfig(config, true));
|
||||||
elements.add("</separationconfiguration>");
|
elements.add("</separationconfiguration>");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Collection<? extends String> addStageReplicationParams(final Stage currentStage) {
|
||||||
|
List<String> elementsToReturn = new ArrayList<String>();
|
||||||
|
|
||||||
|
if (null != currentStage) {
|
||||||
|
|
||||||
|
boolean outsideFlag = currentStage.getOutside();
|
||||||
|
elementsToReturn.add("<outside=\"" + outsideFlag + "\">");
|
||||||
|
int instanceCount = currentStage.getInstanceCount();
|
||||||
|
elementsToReturn.add("<instanceCount=\"" + instanceCount + "\">");
|
||||||
|
double radialOffset = currentStage.getRadialPosition();
|
||||||
|
elementsToReturn.add("<radialOffset=\"" + radialOffset + "\">");
|
||||||
|
double angularOffset = currentStage.getAngularPosition();
|
||||||
|
elementsToReturn.add("<angleOffset=\"" + angularOffset + "\">");
|
||||||
|
|
||||||
|
// Save position unless "AFTER"
|
||||||
|
if (currentStage.getRelativePosition() != RocketComponent.Position.AFTER) {
|
||||||
|
// The type names are currently equivalent to the enum names except for case.
|
||||||
|
String type = currentStage.getRelativePositionMethod().name().toLowerCase(Locale.ENGLISH);
|
||||||
|
double axialOffset = currentStage.getAxialPosition();
|
||||||
|
elementsToReturn.add("<position type=\"" + type + "\">" + axialOffset + "</position>");
|
||||||
|
int relativeTo = currentStage.getRelativeToStage();
|
||||||
|
elementsToReturn.add("<relativeTo=\"" + relativeTo + "\">");
|
||||||
|
}
|
||||||
|
|
||||||
|
// do not save
|
||||||
|
double angularSeparation = Double.NaN; // doesn't need to be saved b/c it's derived from instanceCount
|
||||||
|
}
|
||||||
|
|
||||||
|
return elementsToReturn;
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> separationConfig(StageSeparationConfiguration config, boolean indent) {
|
private List<String> separationConfig(StageSeparationConfiguration config, boolean indent) {
|
||||||
List<String> elements = new ArrayList<String>(2);
|
List<String> elements = new ArrayList<String>(2);
|
||||||
elements.add((indent ? " " : "") + "<separationevent>"
|
elements.add((indent ? " " : "") + "<separationevent>"
|
||||||
@ -63,4 +100,4 @@ public class StageSaver extends ComponentAssemblySaver {
|
|||||||
return elements;
|
return elements;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -61,19 +61,4 @@ public interface OutsideComponent {
|
|||||||
*/
|
*/
|
||||||
public void setRadialPosition(final double radius);
|
public void setRadialPosition(final double radius);
|
||||||
|
|
||||||
/**
|
|
||||||
* If component is not symmetric, this is the axial rotation angle (around it's own center). Defaults to 0.
|
|
||||||
*
|
|
||||||
* @return Rotation angle in radians.
|
|
||||||
*/
|
|
||||||
public double getRotation();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If component is not symmetric, this is the axial rotation angle (around it's own center). Defaults to 0.
|
|
||||||
*
|
|
||||||
* @param rotation Rotation angle in radians.
|
|
||||||
*/
|
|
||||||
public void setRotation(final double rotation);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon
|
|||||||
private boolean outside = false;
|
private boolean outside = false;
|
||||||
private double angularPosition_rad = 0;
|
private double angularPosition_rad = 0;
|
||||||
private double radialPosition_m = 0;
|
private double radialPosition_m = 0;
|
||||||
private double rotation_rad = 0;
|
private int stageRelativeTo = 0;
|
||||||
|
|
||||||
private int count = 1;
|
private int count = 1;
|
||||||
private double angularSeparation = Math.PI;
|
private double angularSeparation = Math.PI;
|
||||||
@ -146,37 +146,33 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon
|
|||||||
if (this.outside) {
|
if (this.outside) {
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public double getRotation() {
|
* Stages may be positioned relative to other stages. In that case, this will set the stage number
|
||||||
if (this.outside) {
|
* against which this stage is positioned.
|
||||||
return this.rotation_rad;
|
*
|
||||||
} else {
|
* @return the stage number which this stage is positioned relative to
|
||||||
return 0.;
|
*/
|
||||||
}
|
public int getRelativeToStage() {
|
||||||
|
return this.stageRelativeTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/*
|
||||||
public void setRotation(final double rotation) {
|
*
|
||||||
this.rotation_rad = rotation;
|
* @param _relTo the stage number which this stage is positioned relative to
|
||||||
if (this.outside) {
|
*/
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
public void setRelativeToStage(final int _relTo) {
|
||||||
}
|
mutex.verify();
|
||||||
|
this.stageRelativeTo = _relTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RocketComponent.Position getRelativePositionMethod() {
|
public RocketComponent.Position getRelativePositionMethod() {
|
||||||
return this.relativePosition;
|
return this.relativePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void setRelativePositionMethod(final Position position) {
|
||||||
public void setRelativePosition(final Position position) {
|
|
||||||
super.setRelativePosition(position);
|
super.setRelativePosition(position);
|
||||||
if (this.outside) {
|
|
||||||
fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAxialPosition() {
|
public double getAxialPosition() {
|
||||||
|
@ -95,21 +95,6 @@ public class StageConfig extends RocketComponentConfig {
|
|||||||
motherPanel.add( angleUnitSelector, "growx 1, wrap");
|
motherPanel.add( angleUnitSelector, "growx 1, wrap");
|
||||||
parallelEnabledModel.addEnableComponent( angleUnitSelector , true);
|
parallelEnabledModel.addEnableComponent( angleUnitSelector , true);
|
||||||
|
|
||||||
// Not convinced this is a useful option, or that the user will need to modify this.
|
|
||||||
// // set rotation angle of the stage. Does not affect the location
|
|
||||||
// JLabel rotationLabel = new JLabel(trans.get("RocketCompCfg.outside.rotation"));
|
|
||||||
// motherPanel.add( rotationLabel, "align left");
|
|
||||||
// parallelEnabledModel.addEnableComponent( rotationLabel, true);
|
|
||||||
// DoubleModel rotationModel = new DoubleModel( stage, "Rotation", 1.0, UnitGroup.UNITS_ANGLE, 0.0, Math.PI*2);
|
|
||||||
// rotationModel.setCurrentUnit( UnitGroup.UNITS_ANGLE.getUnit("rad") );
|
|
||||||
// JSpinner rotationSpinner = new JSpinner(rotationModel.getSpinnerModel());
|
|
||||||
// rotationSpinner.setEditor(new SpinnerEditor(rotationSpinner));
|
|
||||||
// motherPanel.add(rotationSpinner, "growx 1");
|
|
||||||
// parallelEnabledModel.addEnableComponent( rotationSpinner, true);
|
|
||||||
// UnitSelector rotationUnitSelector = new UnitSelector( rotationModel);
|
|
||||||
// motherPanel.add( rotationUnitSelector, "growx 1, wrap");
|
|
||||||
// parallelEnabledModel.addEnableComponent( rotationUnitSelector , true);
|
|
||||||
|
|
||||||
// set multiplicity
|
// set multiplicity
|
||||||
JLabel countLabel = new JLabel(trans.get("RocketCompCfg.outside.count"));
|
JLabel countLabel = new JLabel(trans.get("RocketCompCfg.outside.count"));
|
||||||
motherPanel.add( countLabel, "align left");
|
motherPanel.add( countLabel, "align left");
|
||||||
@ -127,7 +112,7 @@ public class StageConfig extends RocketComponentConfig {
|
|||||||
parallelEnabledModel.addEnableComponent( positionLabel, true);
|
parallelEnabledModel.addEnableComponent( positionLabel, true);
|
||||||
|
|
||||||
// EnumModel(ChangeSource source, String valueName, Enum<T>[] values) {
|
// EnumModel(ChangeSource source, String valueName, Enum<T>[] values) {
|
||||||
ComboBoxModel<RocketComponent.Position> posRelModel = new EnumModel<RocketComponent.Position>(component, "RelativePosition",
|
ComboBoxModel<RocketComponent.Position> posRelModel = new EnumModel<RocketComponent.Position>(component, "RelativePositionMethod",
|
||||||
new RocketComponent.Position[] {
|
new RocketComponent.Position[] {
|
||||||
RocketComponent.Position.TOP,
|
RocketComponent.Position.TOP,
|
||||||
RocketComponent.Position.MIDDLE,
|
RocketComponent.Position.MIDDLE,
|
||||||
@ -143,6 +128,7 @@ public class StageConfig extends RocketComponentConfig {
|
|||||||
motherPanel.add( relativeStageLabel);
|
motherPanel.add( relativeStageLabel);
|
||||||
parallelEnabledModel.addEnableComponent( relativeStageLabel, true);
|
parallelEnabledModel.addEnableComponent( relativeStageLabel, true);
|
||||||
// may need to implement a new ComponentComboModel or something
|
// may need to implement a new ComponentComboModel or something
|
||||||
|
IntegerModel relToStageModel = new IntegerModel( stage, "RelativeToStage",0);
|
||||||
List<RocketComponent> stageList = stage.getParent().getChildren();
|
List<RocketComponent> stageList = stage.getParent().getChildren();
|
||||||
RocketComponent[] forCombo = new RocketComponent[stageList.size()];
|
RocketComponent[] forCombo = new RocketComponent[stageList.size()];
|
||||||
forCombo = stageList.toArray(forCombo);
|
forCombo = stageList.toArray(forCombo);
|
||||||
@ -152,7 +138,6 @@ public class StageConfig extends RocketComponentConfig {
|
|||||||
motherPanel.add( relToCombo , "growx, wrap");
|
motherPanel.add( relToCombo , "growx, wrap");
|
||||||
parallelEnabledModel.addEnableComponent( relToCombo, true );
|
parallelEnabledModel.addEnableComponent( relToCombo, true );
|
||||||
|
|
||||||
|
|
||||||
// plus
|
// plus
|
||||||
JLabel positionPlusLabel = new JLabel(trans.get("LaunchLugCfg.lbl.plus"));
|
JLabel positionPlusLabel = new JLabel(trans.get("LaunchLugCfg.lbl.plus"));
|
||||||
motherPanel.add( positionPlusLabel );
|
motherPanel.add( positionPlusLabel );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user