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 129f17bfe..5740faf50 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/DocumentConfig.java @@ -406,6 +406,11 @@ class DocumentConfig { setters.put("Stage:separationdelay", new DoubleSetter( Reflection.findMethod(Stage.class, "getStageSeparationConfiguration"), Reflection.findMethod(StageSeparationConfiguration.class, "setSeparationDelay", double.class))); + setters.put("Stage:outside", new BooleanSetter(Reflection.findMethod(Stage.class, "setOutside", boolean.class))); + setters.put("Stage:relativeto", new IntSetter(Reflection.findMethod(Stage.class, "setRelativeToStage", int.class))); + setters.put("Stage:instancecount", new IntSetter(Reflection.findMethod(Stage.class, "setCount", int.class))); + setters.put("Stage:radialoffset", new DoubleSetter(Reflection.findMethod(Stage.class, "setRadialPosition", double.class))); + setters.put("Stage:angleoffset", new DoubleSetter(Reflection.findMethod(Stage.class, "setAngularPosition", double.class))); } diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/PositionSetter.java b/core/src/net/sf/openrocket/file/openrocket/importt/PositionSetter.java index ad29d1e35..f976fe38e 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/PositionSetter.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/PositionSetter.java @@ -9,6 +9,7 @@ import net.sf.openrocket.rocketcomponent.InternalComponent; import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent.Position; +import net.sf.openrocket.rocketcomponent.Stage; import net.sf.openrocket.rocketcomponent.TubeFinSet; class PositionSetter implements Setter { @@ -44,6 +45,9 @@ class PositionSetter implements Setter { } else if (c instanceof TubeFinSet) { ((TubeFinSet) c).setRelativePosition(type); c.setPositionValue(pos); + } else if (c instanceof Stage) { + ((Stage) c).setRelativePositionMethod(type); + ((Stage) c).setPositionValue(pos); } else { warnings.add(Warning.FILE_INVALID_PARAMETER); } 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 9e485a2cf..c237a7d3c 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/StageSaver.java @@ -62,30 +62,33 @@ public class StageSaver extends ComponentAssemblySaver { private Collection addStageReplicationParams(final Stage currentStage) { List elementsToReturn = new ArrayList(); + final String relTo_tag = "relativeto"; + final String outside_tag = "outside"; + final String instCt_tag = "instancecount"; + final String radoffs_tag = "radialoffset"; + final String startangle_tag = "angleoffset"; + 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 + ""); + // position type and offset are saved in superclass + // String type = currentStage.getRelativePositionMethod().name().toLowerCase(Locale.ENGLISH); + // double axialOffset = currentStage.getAxialPosition(); + // elementsToReturn.add("" + axialOffset + ""); int relativeTo = currentStage.getRelativeToStage(); - elementsToReturn.add(""); + elementsToReturn.add("<" + relTo_tag + ">" + relativeTo + ""); } - // do not save - double angularSeparation = Double.NaN; // doesn't need to be saved b/c it's derived from instanceCount + boolean outsideFlag = currentStage.getOutside(); + elementsToReturn.add("<" + outside_tag + ">" + outsideFlag + ""); + int instanceCount = currentStage.getInstanceCount(); + elementsToReturn.add("<" + instCt_tag + ">" + instanceCount + ""); + double radialOffset = currentStage.getRadialPosition(); + elementsToReturn.add("<" + radoffs_tag + ">" + radialOffset + ""); + double angularOffset = currentStage.getAngularPosition(); + elementsToReturn.add("<" + startangle_tag + ">" + angularOffset + ""); + } return elementsToReturn; diff --git a/swing/src/net/sf/openrocket/gui/adaptors/StageSelectModel.java b/swing/src/net/sf/openrocket/gui/adaptors/StageSelectModel.java index 70d795f09..aa1694ebf 100644 --- a/swing/src/net/sf/openrocket/gui/adaptors/StageSelectModel.java +++ b/swing/src/net/sf/openrocket/gui/adaptors/StageSelectModel.java @@ -28,7 +28,6 @@ public class StageSelectModel extends AbstractListModel implements ComboB protected Stage sourceStage = null; protected ArrayList displayValues = new ArrayList(); protected Stage selectedStage = null; - protected int selectedStageIndex=-1; // index of stage in rocket, as returned by stage.getStageNumber(); //@SuppressWarnings("unchecked") public StageSelectModel( final Stage _stage, String nullText) { @@ -91,20 +90,13 @@ public class StageSelectModel extends AbstractListModel implements ComboB if( newItem instanceof Stage ){ Stage nextStage = (Stage) newItem; - int nextStageIndex = nextStage.getStageNumber(); - + if (nextStage.equals(this.selectedStage)){ return; // i.e. no change } - - this.selectedStage = nextStage; - this.selectedStageIndex = nextStageIndex; - this.sourceStage.setRelativeToStage(nextStageIndex); - // DEVEL - int nextDisplayIndex = this.displayValues.indexOf(newItem); - log.error("DEVEL success. set stage number to: "+nextDisplayIndex+" @"+nextStageIndex); - log.error("DEVEL success. set stage number to: "+nextStage.getName()+" ="+nextStage.toString()); + this.selectedStage = nextStage; + this.sourceStage.setRelativeToStage(nextStage.getStageNumber()); return; } @@ -134,7 +126,7 @@ public class StageSelectModel extends AbstractListModel implements ComboB @Override public String toString() { - return "StageSelectModel["+this.selectedStage.getName()+" @"+this.selectedStageIndex+"]"; + return "StageSelectModel["+this.selectedStage.getName()+" ("+this.selectedStage.getStageNumber()+")]"; }