[Bugfix] fixed Configuration getActive... routines
- getActiveStages() now correctly returns only active stages - getActiveComponents() now returns children of all active stages exactly once - Refactored the shape generate routines in rocketfigure - correctly omits inactive stages - always includes active stages
This commit is contained in:
parent
497fb658c7
commit
34091e338e
@ -98,7 +98,7 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
|||||||
* @param stageNumber stage number to inactivate
|
* @param stageNumber stage number to inactivate
|
||||||
*/
|
*/
|
||||||
public void clearOnlyStage(final int stageNumber) {
|
public void clearOnlyStage(final int stageNumber) {
|
||||||
setStage(stageNumber, false);
|
setStageActive(stageNumber, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +107,7 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
|||||||
* @param stageNumber stage number to activate
|
* @param stageNumber stage number to activate
|
||||||
*/
|
*/
|
||||||
public void setOnlyStage(final int stageNumber) {
|
public void setOnlyStage(final int stageNumber) {
|
||||||
setStage(stageNumber, true);
|
setStageActive(stageNumber, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,9 +116,10 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
|||||||
* @param stageNumber stage number to flag
|
* @param stageNumber stage number to flag
|
||||||
* @param _active inactive (<code>false</code>) or active (<code>true</code>)
|
* @param _active inactive (<code>false</code>) or active (<code>true</code>)
|
||||||
*/
|
*/
|
||||||
public void setStage(final int stageNumber, final boolean _active) {
|
public void setStageActive(final int stageNumber, final boolean _active) {
|
||||||
if ((0 <= stageNumber) && (stageMap.containsKey(stageNumber))) {
|
if ((0 <= stageNumber) && (stageMap.containsKey(stageNumber))) {
|
||||||
log.error("debug: setting stage " + stageNumber + " to " + _active);
|
String activeString = (_active ? "active" : "inactive");
|
||||||
|
log.error("debug: setting stage " + stageNumber + " to " + activeString + " " + this.toDebug());
|
||||||
stageMap.get(stageNumber).active = _active;
|
stageMap.get(stageNumber).active = _active;
|
||||||
fireChangeEvent();
|
fireChangeEvent();
|
||||||
return;
|
return;
|
||||||
@ -131,20 +132,21 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
|||||||
if ((0 <= stageNumber) && (stageMap.containsKey(stageNumber))) {
|
if ((0 <= stageNumber) && (stageMap.containsKey(stageNumber))) {
|
||||||
StageFlags flags = stageMap.get(stageNumber);
|
StageFlags flags = stageMap.get(stageNumber);
|
||||||
flags.active = !flags.active;
|
flags.active = !flags.active;
|
||||||
//log.error("debug: toggling stage " + stageNumber + " to " + !flags.active + " " + this.toDebug());
|
String activeString = (flags.active ? "active" : "inactive");
|
||||||
|
log.error("debug: toggling stage " + stageNumber + " to " + activeString + " " + this.toDebug());
|
||||||
fireChangeEvent();
|
fireChangeEvent();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.error("error: attempt to retrieve via a bad stage number: " + stageNumber);
|
log.error("error: attempt to retrieve via a bad stage number: " + stageNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Check whether the stage is active.
|
// * Check whether the stage is active.
|
||||||
*/
|
// */
|
||||||
public boolean isStageActive(final AxialStage stage) {
|
// public boolean isStageActive(final AxialStage stage) {
|
||||||
return this.isStageActive(stage.getStageNumber());
|
// return this.isStageActive(stage.getStageNumber());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
/**
|
||||||
* Check whether the stage specified by the index is active.
|
* Check whether the stage specified by the index is active.
|
||||||
*/
|
*/
|
||||||
@ -156,23 +158,21 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<RocketComponent> getActiveComponents() {
|
public Collection<RocketComponent> getActiveComponents() {
|
||||||
Queue<RocketComponent> toProcess = new ArrayDeque<RocketComponent>(this.rocket.getChildren());
|
Queue<RocketComponent> toProcess = new ArrayDeque<RocketComponent>(this.getActiveStages());
|
||||||
ArrayList<RocketComponent> toReturn = new ArrayList<RocketComponent>();
|
ArrayList<RocketComponent> toReturn = new ArrayList<RocketComponent>();
|
||||||
|
|
||||||
while (!toProcess.isEmpty()) {
|
while (!toProcess.isEmpty()) {
|
||||||
RocketComponent comp = toProcess.poll();
|
RocketComponent comp = toProcess.poll();
|
||||||
|
|
||||||
if (comp instanceof AxialStage) {
|
|
||||||
if (!isStageActive(comp.getStageNumber())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toReturn.add(comp);
|
toReturn.add(comp);
|
||||||
for (RocketComponent child : comp.getChildren()) {
|
for (RocketComponent child : comp.getChildren()) {
|
||||||
|
if (child instanceof AxialStage) {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
toProcess.offer(child);
|
toProcess.offer(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
@ -196,8 +196,10 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
|||||||
List<AxialStage> activeStages = new ArrayList<AxialStage>();
|
List<AxialStage> activeStages = new ArrayList<AxialStage>();
|
||||||
|
|
||||||
for (StageFlags flags : this.stageMap.values()) {
|
for (StageFlags flags : this.stageMap.values()) {
|
||||||
|
if (flags.active) {
|
||||||
activeStages.add(flags.stage);
|
activeStages.add(flags.stage);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return activeStages;
|
return activeStages;
|
||||||
}
|
}
|
||||||
@ -375,7 +377,6 @@ public class Configuration implements Cloneable, ChangeSource, ComponentChangeLi
|
|||||||
|
|
||||||
double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
|
double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
|
||||||
for (RocketComponent component : this.getActiveComponents()) {
|
for (RocketComponent component : this.getActiveComponents()) {
|
||||||
System.err.println("..bounds checking component: " + component.getName());
|
|
||||||
for (Coordinate coord : component.getComponentBounds()) {
|
for (Coordinate coord : component.getComponentBounds()) {
|
||||||
cachedBounds.add(coord);
|
cachedBounds.add(coord);
|
||||||
if (coord.x < minX)
|
if (coord.x < minX)
|
||||||
|
@ -17,6 +17,7 @@ import java.awt.geom.Rectangle2D;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import net.sf.openrocket.gui.figureelements.FigureElement;
|
import net.sf.openrocket.gui.figureelements.FigureElement;
|
||||||
import net.sf.openrocket.gui.util.ColorConversion;
|
import net.sf.openrocket.gui.util.ColorConversion;
|
||||||
@ -25,6 +26,7 @@ import net.sf.openrocket.motor.Motor;
|
|||||||
import net.sf.openrocket.motor.MotorInstance;
|
import net.sf.openrocket.motor.MotorInstance;
|
||||||
import net.sf.openrocket.motor.MotorInstanceConfiguration;
|
import net.sf.openrocket.motor.MotorInstanceConfiguration;
|
||||||
import net.sf.openrocket.rocketcomponent.AxialStage;
|
import net.sf.openrocket.rocketcomponent.AxialStage;
|
||||||
|
import net.sf.openrocket.rocketcomponent.BoosterSet;
|
||||||
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
|
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
|
||||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
import net.sf.openrocket.rocketcomponent.Configuration;
|
||||||
import net.sf.openrocket.rocketcomponent.MotorMount;
|
import net.sf.openrocket.rocketcomponent.MotorMount;
|
||||||
@ -186,9 +188,7 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
figureShapes.clear();
|
figureShapes.clear();
|
||||||
|
|
||||||
calculateSize();
|
calculateSize();
|
||||||
Rocket theRocket = configuration.getRocket();
|
getShapes( figureShapes, configuration);
|
||||||
Coordinate zero = new Coordinate(0,0,0);
|
|
||||||
getShapeTree( figureShapes, theRocket, zero);
|
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
fireChangeEvent();
|
fireChangeEvent();
|
||||||
@ -436,6 +436,18 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
return l.toArray(new RocketComponent[0]);
|
return l.toArray(new RocketComponent[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// facade for the recursive function below
|
||||||
|
private void getShapes(ArrayList<RocketComponentShape> allShapes, Configuration configuration){
|
||||||
|
System.err.println("getting shapes for stages: " + this.configuration.toDebug());
|
||||||
|
for( AxialStage stage : configuration.getActiveStages()){
|
||||||
|
int stageNumber = stage.getStageNumber();
|
||||||
|
String activeString = ( configuration.isStageActive(stageNumber) ? "active" : "inactive");
|
||||||
|
System.err.println(" "+stage.getName()+ "[" + stageNumber + "] is " + activeString );
|
||||||
|
|
||||||
|
getShapeTree( allShapes, stage, Coordinate.ZERO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: Recursive function
|
// NOTE: Recursive function
|
||||||
private void getShapeTree(
|
private void getShapeTree(
|
||||||
ArrayList<RocketComponentShape> allShapes, // this is the output parameter
|
ArrayList<RocketComponentShape> allShapes, // this is the output parameter
|
||||||
@ -444,45 +456,22 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
|
|
||||||
RocketPanel.VIEW_TYPE viewType = this.currentViewType;
|
RocketPanel.VIEW_TYPE viewType = this.currentViewType;
|
||||||
Transformation viewTransform = this.transformation;
|
Transformation viewTransform = this.transformation;
|
||||||
|
Coordinate[] locs = comp.getLocation();
|
||||||
|
|
||||||
Coordinate componentAbsoluteLocation = parentLocation.add(comp.getOffset());
|
// generate shapes
|
||||||
|
for( Coordinate curLocation : locs){
|
||||||
if( comp instanceof AxialStage){
|
allShapes = addThisShape( allShapes, viewType, comp, curLocation, viewTransform);
|
||||||
int num = ((AxialStage) comp).getStageNumber();
|
|
||||||
if( ! this.configuration.isStageActive(num)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate shapes:
|
// recurse into component's children
|
||||||
if( comp instanceof Rocket){
|
|
||||||
// no-op. no shapes
|
|
||||||
}else if( comp instanceof ComponentAssembly ){
|
|
||||||
// no-op; no shapes here, either.
|
|
||||||
}else{
|
|
||||||
// get all shapes for this component, add to return list.
|
|
||||||
RocketComponentShape[] childShapes = getThisShape( viewType, comp, componentAbsoluteLocation, viewTransform);
|
|
||||||
for ( RocketComponentShape curShape : childShapes ){
|
|
||||||
allShapes.add( curShape );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// recurse differently, depending on if this node has instances or not....
|
|
||||||
if( comp.isCenterline() ){
|
|
||||||
// recurse to each child with just the center
|
|
||||||
for( RocketComponent child: comp.getChildren() ){
|
for( RocketComponent child: comp.getChildren() ){
|
||||||
getShapeTree( allShapes, child, componentAbsoluteLocation);
|
if( child instanceof AxialStage ){
|
||||||
|
// recursing into BoosterSet here would double count its tree
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
// get the offsets for each component instance
|
|
||||||
Coordinate[] instanceOffsets = new Coordinate[]{ parentLocation };
|
|
||||||
instanceOffsets = comp.shiftCoordinates( instanceOffsets);
|
|
||||||
|
|
||||||
// recurse to each child with each instance of this component
|
for( Coordinate curLocation : locs){
|
||||||
for( RocketComponent child: comp.getChildren() ){
|
getShapeTree( allShapes, child, curLocation);
|
||||||
for( Coordinate curInstanceCoordinate : instanceOffsets){
|
|
||||||
getShapeTree( allShapes, child, curInstanceCoordinate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -494,11 +483,21 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
*
|
*
|
||||||
* @param component
|
* @param component
|
||||||
* @param params
|
* @param params
|
||||||
* @return
|
* @return the <code>ArrayList</code> containing all the shapes to draw.
|
||||||
*/
|
*/
|
||||||
private static RocketComponentShape[] getThisShape(final RocketPanel.VIEW_TYPE viewType, final RocketComponent component, final Coordinate instanceOffset, final Transformation transformation) {
|
private static ArrayList<RocketComponentShape> addThisShape(
|
||||||
|
ArrayList<RocketComponentShape> allShapes, // this is the output parameter
|
||||||
|
final RocketPanel.VIEW_TYPE viewType,
|
||||||
|
final RocketComponent component,
|
||||||
|
final Coordinate instanceOffset,
|
||||||
|
final Transformation transformation) {
|
||||||
Reflection.Method m;
|
Reflection.Method m;
|
||||||
|
|
||||||
|
if(( component instanceof Rocket)||( component instanceof ComponentAssembly )){
|
||||||
|
// no-op; no shapes here, either.
|
||||||
|
return allShapes;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the appropriate method
|
// Find the appropriate method
|
||||||
switch (viewType) {
|
switch (viewType) {
|
||||||
case SideView:
|
case SideView:
|
||||||
@ -518,10 +517,15 @@ public class RocketFigure extends AbstractScaleFigure {
|
|||||||
if (m == null) {
|
if (m == null) {
|
||||||
Application.getExceptionHandler().handleErrorCondition("ERROR: Rocket figure paint method not found for "
|
Application.getExceptionHandler().handleErrorCondition("ERROR: Rocket figure paint method not found for "
|
||||||
+ component);
|
+ component);
|
||||||
return new RocketComponentShape[0];
|
return allShapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (RocketComponentShape[]) m.invokeStatic(component, transformation, instanceOffset);
|
|
||||||
|
RocketComponentShape[] returnValue = (RocketComponentShape[]) m.invokeStatic(component, transformation, instanceOffset);
|
||||||
|
for ( RocketComponentShape curShape : returnValue ){
|
||||||
|
allShapes.add( curShape );
|
||||||
|
}
|
||||||
|
return allShapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user