Fix issue in motor mount selection

First of all: inefficient implementation
Second of all: it could select children of body tubes, we don't want that
This commit is contained in:
SiboVG 2023-04-01 20:25:18 +02:00
parent 4e2801ea41
commit 518511bbd8

View File

@ -12,6 +12,7 @@ import net.sf.openrocket.motor.IgnitionEvent;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
@ -203,17 +204,18 @@ public class SimulationListHandler extends AbstractElementHandler {
/** /**
* Returns the furthest back motor mount in the stage. * Returns the furthest back motor mount in the stage.
* @param stage stage number * @param stageNr stage number
* @return furthest back motor mount of the stage * @return furthest back motor mount of the stage
*/ */
private MotorMount getMotorMountForStage(int stage) { private MotorMount getMotorMountForStage(int stageNr) {
MotorMount mount = null; AxialStage stage = (AxialStage) rocket.getChild(stageNr);
for (RocketComponent component : rocket.getStage(stage)) { for (int i = stage.getChildCount() - 1; i > 0; i--) {
RocketComponent component = stage.getChild(i);
if (component instanceof MotorMount) { if (component instanceof MotorMount) {
mount = (MotorMount) component; return (MotorMount) component;
} }
} }
return mount; return null;
} }
} }
} }