Only search active stages in substitutor

This commit is contained in:
SiboVG 2023-02-14 16:32:59 +00:00
parent 5fe03ed9f2
commit 813f0d5fc6
3 changed files with 12 additions and 19 deletions

View File

@ -13,6 +13,7 @@ import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.plugin.Plugin; import net.sf.openrocket.plugin.Plugin;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
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;
@ -57,22 +58,18 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
List<List<String>> list = new ArrayList<List<String>>(); List<List<String>> list = new ArrayList<List<String>>();
List<String> currentList = Collections.emptyList(); List<String> currentList = Collections.emptyList();
Iterator<RocketComponent> iterator = rocket.iterator(); FlightConfiguration config = rocket.getFlightConfiguration(fcid);
while (iterator.hasNext()) { for (RocketComponent c : rocket) {
RocketComponent c = iterator.next();
if (c instanceof AxialStage) { if (c instanceof AxialStage) {
currentList = new ArrayList<>();
currentList = new ArrayList<String>();
list.add(currentList); list.add(currentList);
} else if (c instanceof MotorMount) { } else if (c instanceof MotorMount) {
MotorMount mount = (MotorMount) c; MotorMount mount = (MotorMount) c;
MotorConfiguration inst = mount.getMotorConfig(fcid); MotorConfiguration inst = mount.getMotorConfig(fcid);
Motor motor = inst.getMotor(); Motor motor = inst.getMotor();
if (mount.isMotorMount() && motor != null) { if (mount.isMotorMount() && config.isComponentActive(mount) && motor != null) {
String designation = motor.getDesignation(inst.getEjectionDelay()); String designation = motor.getDesignation(inst.getEjectionDelay());
for (int i = 0; i < mount.getMotorCount(); i++) { for (int i = 0; i < mount.getMotorCount(); i++) {
@ -80,7 +77,6 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
motorCount++; motorCount++;
} }
} }
} }
} }
@ -99,11 +95,8 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
Collections.sort(stage); Collections.sort(stage);
for (String current : stage) { for (String current : stage) {
if (current.equals(previous)) { if (current.equals(previous)) {
count++; count++;
} else { } else {
if (previous != null) { if (previous != null) {
String s = ""; String s = "";
if (count > 1) { if (count > 1) {
@ -117,10 +110,8 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
else else
stageName = stageName + "," + s; stageName = stageName + "," + s;
} }
previous = current; previous = current;
count = 1; count = 1;
} }
} }
if (previous != null) { if (previous != null) {
@ -136,14 +127,13 @@ public class MotorDescriptionSubstitutor implements RocketSubstitutor {
else else
stageName = stageName + "," + s; stageName = stageName + "," + s;
} }
stages.add(stageName); stages.add(stageName);
} }
name = ""; name = "";
for (int i = 0; i < stages.size(); i++) { for (int i = 0; i < stages.size(); i++) {
String s = stages.get(i); String s = stages.get(i);
if (s.equals("")) if (s.equals("") && config.isStageActive(i))
s = trans.get("Rocket.motorCount.noStageMotors"); s = trans.get("Rocket.motorCount.noStageMotors");
if (i == 0) if (i == 0)
name = name + s; name = name + s;

View File

@ -7,6 +7,7 @@ import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.motor.ThrustCurveMotor; import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.plugin.Plugin; import net.sf.openrocket.plugin.Plugin;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
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;
@ -56,6 +57,7 @@ public class MotorManufacturerSubstitutor implements RocketSubstitutor {
List<List<String>> list = new ArrayList<>(); List<List<String>> list = new ArrayList<>();
List<String> currentList = Collections.emptyList(); List<String> currentList = Collections.emptyList();
FlightConfiguration config = rocket.getFlightConfiguration(fcid);
for (RocketComponent c : rocket) { for (RocketComponent c : rocket) {
if (c instanceof AxialStage) { if (c instanceof AxialStage) {
currentList = new ArrayList<>(); currentList = new ArrayList<>();
@ -66,7 +68,7 @@ public class MotorManufacturerSubstitutor implements RocketSubstitutor {
MotorConfiguration inst = mount.getMotorConfig(fcid); MotorConfiguration inst = mount.getMotorConfig(fcid);
Motor motor = inst.getMotor(); Motor motor = inst.getMotor();
if (mount.isMotorMount() && motor instanceof ThrustCurveMotor) { if (mount.isMotorMount() && config.isComponentActive(mount) && motor instanceof ThrustCurveMotor) {
String manufacturer = ((ThrustCurveMotor) motor).getManufacturer().getDisplayName(); String manufacturer = ((ThrustCurveMotor) motor).getManufacturer().getDisplayName();
for (int i = 0; i < mount.getMotorCount(); i++) { for (int i = 0; i < mount.getMotorCount(); i++) {
@ -131,7 +133,7 @@ public class MotorManufacturerSubstitutor implements RocketSubstitutor {
manufacturers = ""; manufacturers = "";
for (int i = 0; i < stages.size(); i++) { for (int i = 0; i < stages.size(); i++) {
String s = stages.get(i); String s = stages.get(i);
if (s.equals("")) if (s.equals("") && config.isStageActive(i))
s = trans.get("Rocket.motorCount.noStageMotors"); s = trans.get("Rocket.motorCount.noStageMotors");
if (i == 0) if (i == 0)
manufacturers = manufacturers + s; manufacturers = manufacturers + s;

View File

@ -584,6 +584,7 @@ public class FlightConfigurationTest extends BaseTestCase {
public void testCopy() throws NoSuchFieldException, IllegalAccessException { public void testCopy() throws NoSuchFieldException, IllegalAccessException {
Rocket rocket = TestRockets.makeFalcon9Heavy(); Rocket rocket = TestRockets.makeFalcon9Heavy();
FlightConfiguration original = rocket.getSelectedConfiguration(); FlightConfiguration original = rocket.getSelectedConfiguration();
original.setName("[{motors}] - [{manufacturers}]");
original.setOnlyStage(0); original.setOnlyStage(0);
// vvvv Test Target vvvv // vvvv Test Target vvvv