implemented loading of stage parameters (and fixed stage xml writing

This commit is contained in:
Daniel_M_Williams 2015-07-01 19:20:19 -04:00
parent 177b24a667
commit 8755777924
4 changed files with 33 additions and 29 deletions

View File

@ -406,6 +406,11 @@ class DocumentConfig {
setters.put("Stage:separationdelay", new DoubleSetter( setters.put("Stage:separationdelay", new DoubleSetter(
Reflection.findMethod(Stage.class, "getStageSeparationConfiguration"), Reflection.findMethod(Stage.class, "getStageSeparationConfiguration"),
Reflection.findMethod(StageSeparationConfiguration.class, "setSeparationDelay", double.class))); 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)));
} }

View File

@ -9,6 +9,7 @@ import net.sf.openrocket.rocketcomponent.InternalComponent;
import net.sf.openrocket.rocketcomponent.LaunchLug; import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.RocketComponent.Position; import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
import net.sf.openrocket.rocketcomponent.Stage;
import net.sf.openrocket.rocketcomponent.TubeFinSet; import net.sf.openrocket.rocketcomponent.TubeFinSet;
class PositionSetter implements Setter { class PositionSetter implements Setter {
@ -44,6 +45,9 @@ class PositionSetter implements Setter {
} else if (c instanceof TubeFinSet) { } else if (c instanceof TubeFinSet) {
((TubeFinSet) c).setRelativePosition(type); ((TubeFinSet) c).setRelativePosition(type);
c.setPositionValue(pos); c.setPositionValue(pos);
} else if (c instanceof Stage) {
((Stage) c).setRelativePositionMethod(type);
((Stage) c).setPositionValue(pos);
} else { } else {
warnings.add(Warning.FILE_INVALID_PARAMETER); warnings.add(Warning.FILE_INVALID_PARAMETER);
} }

View File

@ -62,30 +62,33 @@ public class StageSaver extends ComponentAssemblySaver {
private Collection<? extends String> addStageReplicationParams(final Stage currentStage) { private Collection<? extends String> addStageReplicationParams(final Stage currentStage) {
List<String> elementsToReturn = new ArrayList<String>(); List<String> elementsToReturn = new ArrayList<String>();
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) { 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" // Save position unless "AFTER"
if (currentStage.getRelativePosition() != RocketComponent.Position.AFTER) { if (currentStage.getRelativePosition() != RocketComponent.Position.AFTER) {
// The type names are currently equivalent to the enum names except for case. // position type and offset are saved in superclass
String type = currentStage.getRelativePositionMethod().name().toLowerCase(Locale.ENGLISH); // String type = currentStage.getRelativePositionMethod().name().toLowerCase(Locale.ENGLISH);
double axialOffset = currentStage.getAxialPosition(); // double axialOffset = currentStage.getAxialPosition();
elementsToReturn.add("<position type=\"" + type + "\">" + axialOffset + "</position>"); // elementsToReturn.add("<position type=\"" + type + "\">" + axialOffset + "</position>");
int relativeTo = currentStage.getRelativeToStage(); int relativeTo = currentStage.getRelativeToStage();
elementsToReturn.add("<relativeTo=\"" + relativeTo + "\">"); elementsToReturn.add("<" + relTo_tag + ">" + relativeTo + "</" + relTo_tag + ">");
} }
// do not save boolean outsideFlag = currentStage.getOutside();
double angularSeparation = Double.NaN; // doesn't need to be saved b/c it's derived from instanceCount elementsToReturn.add("<" + outside_tag + ">" + outsideFlag + "</" + outside_tag + ">");
int instanceCount = currentStage.getInstanceCount();
elementsToReturn.add("<" + instCt_tag + ">" + instanceCount + "</" + instCt_tag + ">");
double radialOffset = currentStage.getRadialPosition();
elementsToReturn.add("<" + radoffs_tag + ">" + radialOffset + "</" + radoffs_tag + ">");
double angularOffset = currentStage.getAngularPosition();
elementsToReturn.add("<" + startangle_tag + ">" + angularOffset + "</" + startangle_tag + ">");
} }
return elementsToReturn; return elementsToReturn;

View File

@ -28,7 +28,6 @@ public class StageSelectModel extends AbstractListModel<Stage> implements ComboB
protected Stage sourceStage = null; protected Stage sourceStage = null;
protected ArrayList<Stage> displayValues = new ArrayList<Stage>(); protected ArrayList<Stage> displayValues = new ArrayList<Stage>();
protected Stage selectedStage = null; protected Stage selectedStage = null;
protected int selectedStageIndex=-1; // index of stage in rocket, as returned by stage.getStageNumber();
//@SuppressWarnings("unchecked") //@SuppressWarnings("unchecked")
public StageSelectModel( final Stage _stage, String nullText) { public StageSelectModel( final Stage _stage, String nullText) {
@ -91,20 +90,13 @@ public class StageSelectModel extends AbstractListModel<Stage> implements ComboB
if( newItem instanceof Stage ){ if( newItem instanceof Stage ){
Stage nextStage = (Stage) newItem; Stage nextStage = (Stage) newItem;
int nextStageIndex = nextStage.getStageNumber();
if (nextStage.equals(this.selectedStage)){ if (nextStage.equals(this.selectedStage)){
return; // i.e. no change return; // i.e. no change
} }
this.selectedStage = nextStage; this.selectedStage = nextStage;
this.selectedStageIndex = nextStageIndex; this.sourceStage.setRelativeToStage(nextStage.getStageNumber());
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());
return; return;
} }
@ -134,7 +126,7 @@ public class StageSelectModel extends AbstractListModel<Stage> implements ComboB
@Override @Override
public String toString() { public String toString() {
return "StageSelectModel["+this.selectedStage.getName()+" @"+this.selectedStageIndex+"]"; return "StageSelectModel["+this.selectedStage.getName()+" ("+this.selectedStage.getStageNumber()+")]";
} }