From d8a8c1444939949cf9f33437371242bf804f8ca2 Mon Sep 17 00:00:00 2001 From: Daniel_M_Williams Date: Sun, 3 May 2020 15:01:56 -0400 Subject: [PATCH] [fix] get{Next|Prev}SymmetricComponent now searches across stages --- .../rocketcomponent/SymmetricComponent.java | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java index a0ae39c16..2baa47ad7 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/SymmetricComponent.java @@ -570,14 +570,30 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial return null; } - int pos = parent.getChildPosition(this); - while( 0 < pos ) { - --pos; - final RocketComponent comp = parent.getChild(pos); + // might be: (a) Rocket -- for centerline stages + // (b) BodyTube -- for Parallel Stages + final AxialStage stage = this.getStage(); + final RocketComponent stageParent = stage.getParent(); - if (comp instanceof SymmetricComponent) { - return (SymmetricComponent) comp; + // note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one. + int stageIndex = stageParent.getChildPosition(stage); + int symmetricIndex = this.parent.getChildPosition(this)-1; + + while( 0 <= stageIndex ) { + final RocketComponent prevStage = stageParent.getChild(stageIndex); + + if(prevStage instanceof AxialStage){ + while (0 <= symmetricIndex) { + final RocketComponent previousSymmetric = prevStage.getChild(symmetricIndex); + + if (previousSymmetric instanceof SymmetricComponent) { + return (SymmetricComponent) previousSymmetric; + } + --symmetricIndex; + } } + --stageIndex; + symmetricIndex = prevStage.getChildCount() - 1; } return null; } @@ -591,16 +607,31 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial if(null == this.parent) { return null; } - - int pos = parent.getChildPosition(this); - ++pos; - while( pos < parent.getChildCount() ) { - final RocketComponent comp = parent.getChild(pos); - ++pos; - if (comp instanceof SymmetricComponent) { - return (SymmetricComponent) comp; + // might be: (a) Rocket -- for centerline stages + // (b) BodyTube -- for Parallel Stages + final AxialStage stage = this.getStage(); + final RocketComponent stageParent = stage.getParent(); + + // note: this is not guaranteed to _contain_ a stage... but that we're _searching_ for one. + int stageIndex = stageParent.getChildPosition(stage); + int symmetricIndex = this.parent.getChildPosition(this) + 1; + + while(stageIndex < stageParent.getChildCount()) { + final RocketComponent nextStage = stageParent.getChild(stageIndex); + + if(nextStage instanceof AxialStage){ + while (symmetricIndex < nextStage.getChildCount()) { + final RocketComponent nextSymmetric = nextStage.getChild(symmetricIndex); + + if (nextSymmetric instanceof SymmetricComponent) { + return (SymmetricComponent) nextSymmetric; + } + ++symmetricIndex; + } } + ++stageIndex; + symmetricIndex = nextStage.getChildCount() - 1; } return null; }