Update FlightConfiguration active instances whenever active components change, not every time get getActiveInstances() is called
This commit is contained in:
parent
74c2d75e63
commit
584353463b
@ -64,6 +64,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
final protected HashMap<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>();
|
final protected HashMap<Integer, StageFlags> stages = new HashMap<Integer, StageFlags>();
|
||||||
final protected HashMap<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
|
final protected HashMap<MotorConfigurationId, MotorConfiguration> motors = new HashMap<MotorConfigurationId, MotorConfiguration>();
|
||||||
final private Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
|
final private Collection<MotorConfiguration> activeMotors = new ArrayList<MotorConfiguration>();
|
||||||
|
final private InstanceMap activeInstances = new InstanceMap();
|
||||||
|
|
||||||
private int boundsModID = -1;
|
private int boundsModID = -1;
|
||||||
private BoundingBox cachedBounds = new BoundingBox();
|
private BoundingBox cachedBounds = new BoundingBox();
|
||||||
@ -101,6 +102,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
|
|
||||||
updateStages();
|
updateStages();
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rocket getRocket() {
|
public Rocket getRocket() {
|
||||||
@ -121,12 +123,14 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
cur.active = _active;
|
cur.active = _active;
|
||||||
}
|
}
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyStages(FlightConfiguration other) {
|
public void copyStages(FlightConfiguration other) {
|
||||||
for (StageFlags cur : other.stages.values())
|
for (StageFlags cur : other.stages.values())
|
||||||
stages.put(cur.stageNumber, new StageFlags(cur.stageNumber, cur.active));
|
stages.put(cur.stageNumber, new StageFlags(cur.stageNumber, cur.active));
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -137,6 +141,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
public void clearStage(final int stageNumber) {
|
public void clearStage(final int stageNumber) {
|
||||||
_setStageActive( stageNumber, false );
|
_setStageActive( stageNumber, false );
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,6 +168,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
_setStageActive(i, true);
|
_setStageActive(i, true);
|
||||||
}
|
}
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,6 +180,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
_setAllStages(false);
|
_setAllStages(false);
|
||||||
_setStageActive(stageNumber, true);
|
_setStageActive(stageNumber, true);
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,9 +203,11 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
if ((0 <= stageNumber) && (stages.containsKey(stageNumber))) {
|
if ((0 <= stageNumber) && (stages.containsKey(stageNumber))) {
|
||||||
StageFlags flags = stages.get(stageNumber);
|
StageFlags flags = stages.get(stageNumber);
|
||||||
flags.active = !flags.active;
|
flags.active = !flags.active;
|
||||||
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateMotors();
|
|
||||||
log.error("error: attempt to retrieve via a bad stage number: " + stageNumber);
|
log.error("error: attempt to retrieve via a bad stage number: " + stageNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,15 +295,18 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InstanceMap getActiveInstances() {
|
||||||
|
return activeInstances;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generates a read-only, instance-aware collection of the components for this rocket & configuration
|
* Generates a read-only, instance-aware collection of the components for this rocket & configuration
|
||||||
*
|
*
|
||||||
* TODO: swap in this function for the 'getActiveComponents() function, above; ONLY WHEN READY / MATURE!
|
* TODO: swap in this function for the 'getActiveComponents() function, above; ONLY WHEN READY / MATURE!
|
||||||
*/
|
*/
|
||||||
public InstanceMap getActiveInstances() {
|
private void updateActiveInstances() {
|
||||||
InstanceMap contexts = new InstanceMap();
|
activeInstances.clear();
|
||||||
getActiveContextListAt( this.rocket, contexts, Transformation.IDENTITY);
|
getActiveContextListAt( this.rocket, activeInstances, Transformation.IDENTITY);
|
||||||
return contexts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private InstanceMap getActiveContextListAt(final RocketComponent component, final InstanceMap results, final Transformation parentTransform ){
|
private InstanceMap getActiveContextListAt(final RocketComponent component, final InstanceMap results, final Transformation parentTransform ){
|
||||||
@ -401,6 +413,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
|
|
||||||
updateStages();
|
updateStages();
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStages() {
|
private void updateStages() {
|
||||||
@ -531,6 +544,7 @@ public class FlightConfiguration implements FlightConfigurableParameter<FlightCo
|
|||||||
public void update(){
|
public void update(){
|
||||||
updateStages();
|
updateStages();
|
||||||
updateMotors();
|
updateMotors();
|
||||||
|
updateActiveInstances();
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////// Helper methods ///////////////
|
/////////////// Helper methods ///////////////
|
||||||
|
@ -66,7 +66,6 @@ import net.sf.openrocket.simulation.listeners.SimulationListener;
|
|||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
public class TestRockets {
|
public class TestRockets {
|
||||||
|
|
||||||
public final static FlightConfigurationId TEST_FCID_0 = new FlightConfigurationId("d010716e-ce0e-469d-ae46-190f3653ebbf");
|
public final static FlightConfigurationId TEST_FCID_0 = new FlightConfigurationId("d010716e-ce0e-469d-ae46-190f3653ebbf");
|
||||||
public final static FlightConfigurationId TEST_FCID_1 = new FlightConfigurationId("f41bee5b-ebb8-4d92-bce7-53001577a313");
|
public final static FlightConfigurationId TEST_FCID_1 = new FlightConfigurationId("f41bee5b-ebb8-4d92-bce7-53001577a313");
|
||||||
public final static FlightConfigurationId TEST_FCID_2 = new FlightConfigurationId("3e8d1280-53c2-4234-89a7-de215ef5cd69");
|
public final static FlightConfigurationId TEST_FCID_2 = new FlightConfigurationId("3e8d1280-53c2-4234-89a7-de215ef5cd69");
|
||||||
@ -1705,30 +1704,32 @@ public class TestRockets {
|
|||||||
|
|
||||||
// find the body and fins
|
// find the body and fins
|
||||||
final InstanceMap imap = rocket.getSelectedConfiguration().getActiveInstances();
|
final InstanceMap imap = rocket.getSelectedConfiguration().getActiveInstances();
|
||||||
|
RocketComponent c = null;
|
||||||
for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) {
|
for(Map.Entry<RocketComponent, ArrayList<InstanceContext>> entry: imap.entrySet() ) {
|
||||||
RocketComponent c = entry.getKey();
|
c = entry.getKey();
|
||||||
if (c instanceof TrapezoidFinSet) {
|
if (c instanceof TrapezoidFinSet) {
|
||||||
final TrapezoidFinSet fins = (TrapezoidFinSet) c;
|
break;
|
||||||
final BodyTube body = (BodyTube) fins.getParent();
|
|
||||||
body.removeChild(fins);
|
|
||||||
|
|
||||||
// create a PodSet to hook the fins to
|
|
||||||
PodSet podset = new PodSet();
|
|
||||||
podset.setInstanceCount(fins.getFinCount());
|
|
||||||
|
|
||||||
body.addChild(podset);
|
|
||||||
|
|
||||||
// put a phantom body tube on the pods
|
|
||||||
BodyTube podBody = new BodyTube(fins.getRootChord(), 0);
|
|
||||||
podBody.setName("Pod Body");
|
|
||||||
podset.addChild(podBody);
|
|
||||||
|
|
||||||
// change the number of fins to 1 and put the revised
|
|
||||||
// finset on the podbody
|
|
||||||
fins.setFinCount(1);
|
|
||||||
podBody.addChild(fins);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
final TrapezoidFinSet fins = (TrapezoidFinSet) c;
|
||||||
|
final BodyTube body = (BodyTube) fins.getParent();
|
||||||
|
body.removeChild(fins);
|
||||||
|
|
||||||
|
// create a PodSet to hook the fins to
|
||||||
|
PodSet podset = new PodSet();
|
||||||
|
podset.setInstanceCount(fins.getFinCount());
|
||||||
|
|
||||||
|
body.addChild(podset);
|
||||||
|
|
||||||
|
// put a phantom body tube on the pods
|
||||||
|
BodyTube podBody = new BodyTube(fins.getRootChord(), 0);
|
||||||
|
podBody.setName("Pod Body");
|
||||||
|
podset.addChild(podBody);
|
||||||
|
|
||||||
|
// change the number of fins to 1 and put the revised
|
||||||
|
// finset on the podbody
|
||||||
|
fins.setFinCount(1);
|
||||||
|
podBody.addChild(fins);
|
||||||
|
|
||||||
return rocket;
|
return rocket;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user