diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java index fb875379f..9e485a2cf 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java @@ -1,6 +1,7 @@ package net.sf.openrocket.file.openrocket.savers; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Locale; @@ -28,6 +29,10 @@ public class StageSaver extends ComponentAssemblySaver { super.addParams(c, elements); Stage stage = (Stage) c; + if (stage.getOutside()) { + elements.addAll(this.addStageReplicationParams(stage)); + } + if (stage.getStageNumber() > 0) { // NOTE: Default config must be BEFORE overridden config for proper backward compatibility later on elements.addAll(separationConfig(stage.getStageSeparationConfiguration().getDefault(), false)); @@ -49,11 +54,43 @@ public class StageSaver extends ComponentAssemblySaver { elements.add(""); elements.addAll(separationConfig(config, true)); elements.add(""); + } } } } + private Collection addStageReplicationParams(final Stage currentStage) { + List elementsToReturn = new ArrayList(); + + if (null != currentStage) { + + boolean outsideFlag = currentStage.getOutside(); + elementsToReturn.add(""); + int instanceCount = currentStage.getInstanceCount(); + elementsToReturn.add(""); + double radialOffset = currentStage.getRadialPosition(); + elementsToReturn.add(""); + double angularOffset = currentStage.getAngularPosition(); + elementsToReturn.add(""); + + // 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("" + axialOffset + ""); + int relativeTo = currentStage.getRelativeToStage(); + elementsToReturn.add(""); + } + + // do not save + double angularSeparation = Double.NaN; // doesn't need to be saved b/c it's derived from instanceCount + } + + return elementsToReturn; + } + private List separationConfig(StageSeparationConfiguration config, boolean indent) { List elements = new ArrayList(2); elements.add((indent ? " " : "") + "" @@ -63,4 +100,4 @@ public class StageSaver extends ComponentAssemblySaver { return elements; } -} +} \ No newline at end of file diff --git a/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java b/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java index f17562c69..40265c1fa 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/OutsideComponent.java @@ -61,19 +61,4 @@ public interface OutsideComponent { */ 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); - - } diff --git a/core/src/net/sf/openrocket/rocketcomponent/Stage.java b/core/src/net/sf/openrocket/rocketcomponent/Stage.java index 855096e25..332e526f7 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Stage.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Stage.java @@ -17,7 +17,7 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon private boolean outside = false; private double angularPosition_rad = 0; private double radialPosition_m = 0; - private double rotation_rad = 0; + private int stageRelativeTo = 0; private int count = 1; private double angularSeparation = Math.PI; @@ -146,37 +146,33 @@ public class Stage extends ComponentAssembly implements FlightConfigurableCompon if (this.outside) { fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); } - } - @Override - public double getRotation() { - if (this.outside) { - return this.rotation_rad; - } else { - return 0.; - } - + /** + * Stages may be positioned relative to other stages. In that case, this will set the stage number + * against which this stage is positioned. + * + * @return the stage number which this stage is positioned relative to + */ + public int getRelativeToStage() { + return this.stageRelativeTo; } - @Override - public void setRotation(final double rotation) { - this.rotation_rad = rotation; - if (this.outside) { - fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); - } + /* + * + * @param _relTo the stage number which this stage is positioned relative to + */ + public void setRelativeToStage(final int _relTo) { + mutex.verify(); + this.stageRelativeTo = _relTo; } public RocketComponent.Position getRelativePositionMethod() { return this.relativePosition; } - @Override - public void setRelativePosition(final Position position) { + public void setRelativePositionMethod(final Position position) { super.setRelativePosition(position); - if (this.outside) { - fireComponentChangeEvent(ComponentChangeEvent.BOTH_CHANGE); - } } public double getAxialPosition() { diff --git a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java index 53b39c921..883a6dc42 100644 --- a/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java +++ b/swing/src/net/sf/openrocket/gui/configdialog/StageConfig.java @@ -95,21 +95,6 @@ public class StageConfig extends RocketComponentConfig { motherPanel.add( angleUnitSelector, "growx 1, wrap"); 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 JLabel countLabel = new JLabel(trans.get("RocketCompCfg.outside.count")); motherPanel.add( countLabel, "align left"); @@ -127,7 +112,7 @@ public class StageConfig extends RocketComponentConfig { parallelEnabledModel.addEnableComponent( positionLabel, true); // EnumModel(ChangeSource source, String valueName, Enum[] values) { - ComboBoxModel posRelModel = new EnumModel(component, "RelativePosition", + ComboBoxModel posRelModel = new EnumModel(component, "RelativePositionMethod", new RocketComponent.Position[] { RocketComponent.Position.TOP, RocketComponent.Position.MIDDLE, @@ -143,6 +128,7 @@ public class StageConfig extends RocketComponentConfig { motherPanel.add( relativeStageLabel); parallelEnabledModel.addEnableComponent( relativeStageLabel, true); // may need to implement a new ComponentComboModel or something + IntegerModel relToStageModel = new IntegerModel( stage, "RelativeToStage",0); List stageList = stage.getParent().getChildren(); RocketComponent[] forCombo = new RocketComponent[stageList.size()]; forCombo = stageList.toArray(forCombo); @@ -152,7 +138,6 @@ public class StageConfig extends RocketComponentConfig { motherPanel.add( relToCombo , "growx, wrap"); parallelEnabledModel.addEnableComponent( relToCombo, true ); - // plus JLabel positionPlusLabel = new JLabel(trans.get("LaunchLugCfg.lbl.plus")); motherPanel.add( positionPlusLabel );