From 5bf8a7af15d15052b9afdc91e2b70c1fafdcae5c Mon Sep 17 00:00:00 2001 From: Billy Olsen Date: Mon, 16 Mar 2020 20:51:22 -0700 Subject: [PATCH] Update stage logic for DesignReport Stages need to be activated correctly in order to properly calculate the mass for all components that contribute to the current launch scenario. This change ensures that all of the stages from the top-most stage to the currently active stage are set as activated when stage mass is being calculated. Signed-off-by: Billy Olsen --- .../rocketcomponent/FlightConfiguration.java | 28 ++++++++++++++++++- .../FlightConfigurationTest.java | 15 ++++++++++ .../sf/openrocket/gui/print/DesignReport.java | 5 +--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 4bb7fdc8d..803013df3 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -105,7 +105,7 @@ public class FlightConfiguration implements FlightConfigurableParameter + *
  • StageA - top most stage, containing nose cone etc.
  • + *
  • StageB - middle stage
  • + *
  • StageC - bottom stage
  • + * + * + * invoking FlightConfiguration.activateStagesThrough(StageB) + * will cause both StageA and StageB to be marked as active, and StageC + * will be marked as inactive. + * + * @param stage the AxialStage to activate all stages up to (inclusive) + */ + public void activateStagesThrough(final AxialStage stage) { + clearAllStages(); + for (int i=0; i <= stage.getStageNumber(); i++) { + _setStageActive(i, true); + } + updateMotors(); + } + /** * This method flags the specified stage as active, and all other stages as inactive. * diff --git a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java index d9267ec2c..fe11df0dc 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java +++ b/core/test/net/sf/openrocket/rocketcomponent/FlightConfigurationTest.java @@ -294,6 +294,21 @@ public class FlightConfigurationTest extends BaseTestCase { config.toggleStage(0); assertThat(" toggle stage #0: ", config.isStageActive(0), equalTo(false)); + + AxialStage sustainer = rkt.getTopmostStage(); + AxialStage booster = rkt.getBottomCoreStage(); + assertThat(" sustainer stage is stage #0: ", sustainer.getStageNumber(), equalTo(0)); + assertThat(" booster stage is stage #1: ", booster.getStageNumber(), equalTo(1)); + + config.clearAllStages(); + config.activateStagesThrough(sustainer); + assertThat(" sustainer stage is active: ", config.isStageActive(sustainer.getStageNumber()), equalTo(true)); + assertThat(" booster stage is inactive: ", config.isStageActive(booster.getStageNumber()), equalTo(false)); + + config.clearAllStages(); + config.activateStagesThrough(booster); + assertThat(" sustainer stage is active: ", config.isStageActive(sustainer.getStageNumber()), equalTo(true)); + assertThat(" booster stage is active: ", config.isStageActive(booster.getStageNumber()), equalTo(true)); } diff --git a/swing/src/net/sf/openrocket/gui/print/DesignReport.java b/swing/src/net/sf/openrocket/gui/print/DesignReport.java index 12094b560..dda55bd73 100644 --- a/swing/src/net/sf/openrocket/gui/print/DesignReport.java +++ b/swing/src/net/sf/openrocket/gui/print/DesignReport.java @@ -341,16 +341,13 @@ public class DesignReport { double totalImpulse = 0; double totalTTW = 0; - int stage = 0; double stageMass = 0; boolean topBorder = false; for (RocketComponent c : rocket) { if (c instanceof AxialStage) { - config.clearAllStages(); - config.setOnlyStage(stage); - stage++; + config.activateStagesThrough((AxialStage) c); RigidBody launchInfo = MassCalculator.calculateLaunch(config); stageMass = launchInfo.getMass(); // Calculate total thrust-to-weight from only lowest stage motors