[Fix][Issue #294] Multiple fixes to ensure undo & redo function correctly
- The Rocket#trackStages function needs to handle being updated with the same stage id#, but different instance - Rocket#update now updates the stageMap - FlightConfigurations refactored to use stage numbers instead of references.
This commit is contained in:
parent
31938d69d7
commit
6d70cc61f1
@ -3,7 +3,6 @@ package net.sf.openrocket.rocketcomponent;
|
|||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@ -42,18 +41,17 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
|
|
||||||
private class StageFlags implements Cloneable {
|
private class StageFlags implements Cloneable {
|
||||||
public boolean active = true;
|
public boolean active = true;
|
||||||
public int prev = -1;
|
//public int prev = -1;
|
||||||
public AxialStage stage = null;
|
public int stageNumber = -1;
|
||||||
|
|
||||||
public StageFlags(AxialStage _stage, int _prev, boolean _active) {
|
public StageFlags( int _num, boolean _active) {
|
||||||
this.stage = _stage;
|
this.stageNumber = _num;
|
||||||
this.prev = _prev;
|
|
||||||
this.active = _active;
|
this.active = _active;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StageFlags clone(){
|
public StageFlags clone(){
|
||||||
return new StageFlags( this.stage, this.prev, true);
|
return new StageFlags( this.stageNumber, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +189,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
|
|
||||||
for (StageFlags flags : this.stages.values()) {
|
for (StageFlags flags : this.stages.values()) {
|
||||||
if (flags.active) {
|
if (flags.active) {
|
||||||
activeStages.add(flags.stage);
|
activeStages.add( rocket.getStage( flags.stageNumber) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +213,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
AxialStage bottomStage = null;
|
AxialStage bottomStage = null;
|
||||||
for (StageFlags curFlags : this.stages.values()) {
|
for (StageFlags curFlags : this.stages.values()) {
|
||||||
if (curFlags.active) {
|
if (curFlags.active) {
|
||||||
bottomStage = curFlags.stage;
|
bottomStage = rocket.getStage( curFlags.stageNumber);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bottomStage;
|
return bottomStage;
|
||||||
@ -264,18 +262,14 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateStages() {
|
private void updateStages() {
|
||||||
if (this.rocket.getStageCount() == this.stages.size()) {
|
if (this.rocket.getStageCount() == this.stages.size()) {
|
||||||
// no changes needed
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.stages.clear();
|
this.stages.clear();
|
||||||
for (AxialStage curStage : this.rocket.getStageList()) {
|
for (AxialStage curStage : this.rocket.getStageList()) {
|
||||||
int prevStageNum = curStage.getStageNumber() - 1;
|
|
||||||
if (curStage.getParent() instanceof AxialStage) {
|
StageFlags flagsToAdd = new StageFlags( curStage.getStageNumber(), true);
|
||||||
prevStageNum = curStage.getParent().getStageNumber();
|
|
||||||
}
|
|
||||||
StageFlags flagsToAdd = new StageFlags(curStage, prevStageNum, true);
|
|
||||||
this.stages.put(curStage.getStageNumber(), flagsToAdd);
|
this.stages.put(curStage.getStageNumber(), flagsToAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,9 +355,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
private void updateMotors() {
|
private void updateMotors() {
|
||||||
this.motors.clear();
|
this.motors.clear();
|
||||||
|
|
||||||
Iterator<RocketComponent> iter = rocket.iterator(false);
|
for ( RocketComponent comp : getActiveComponents() ){
|
||||||
while( iter.hasNext() ){
|
|
||||||
RocketComponent comp = iter.next();
|
|
||||||
if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){
|
if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){
|
||||||
MotorMount mount = (MotorMount)comp;
|
MotorMount mount = (MotorMount)comp;
|
||||||
MotorConfiguration motorConfig = mount.getMotorConfig( fcid);
|
MotorConfiguration motorConfig = mount.getMotorConfig( fcid);
|
||||||
@ -532,8 +524,8 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
final String fmt = " [%-2s][%4s]: %6s \n";
|
final String fmt = " [%-2s][%4s]: %6s \n";
|
||||||
buf.append(String.format(fmt, "#", "?actv", "Name"));
|
buf.append(String.format(fmt, "#", "?actv", "Name"));
|
||||||
for (StageFlags flags : stages.values()) {
|
for (StageFlags flags : stages.values()) {
|
||||||
AxialStage curStage = flags.stage;
|
final int stageNumber = flags.stageNumber;
|
||||||
buf.append(String.format(fmt, curStage.getStageNumber(), (flags.active?" on": "off"), curStage.getName()));
|
buf.append(String.format(fmt, stageNumber, (flags.active?" on": "off"), rocket.getStage( stageNumber).getName()));
|
||||||
}
|
}
|
||||||
buf.append("\n");
|
buf.append("\n");
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
@ -226,7 +226,12 @@ public class Rocket extends RocketComponent {
|
|||||||
AxialStage value = stageMap.get(stageNumber);
|
AxialStage value = stageMap.get(stageNumber);
|
||||||
|
|
||||||
if (newStage.equals(value)) {
|
if (newStage.equals(value)) {
|
||||||
// stage is already added. skip.
|
// stage is already added
|
||||||
|
if( newStage != value ){
|
||||||
|
// but the value is the wrong instance
|
||||||
|
stageMap.put(stageNumber, newStage);
|
||||||
|
}
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
stageNumber = getNewStageNumber();
|
stageNumber = getNewStageNumber();
|
||||||
newStage.setStageNumber(stageNumber);
|
newStage.setStageNumber(stageNumber);
|
||||||
@ -454,9 +459,19 @@ public class Rocket extends RocketComponent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
|
updateStageMap();
|
||||||
updateConfigurations();
|
updateConfigurations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateStageMap(){
|
||||||
|
for( RocketComponent component : getChildren() ){
|
||||||
|
if (component instanceof AxialStage) {
|
||||||
|
AxialStage stage = (AxialStage) component;
|
||||||
|
trackStage(stage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateConfigurations(){
|
private void updateConfigurations(){
|
||||||
this.selectedConfiguration.update();
|
this.selectedConfiguration.update();
|
||||||
for( FlightConfiguration config : configSet ){
|
for( FlightConfiguration config : configSet ){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user