From 8cccf49a8fe0411c3acadfcdd7d805ef35268f8c Mon Sep 17 00:00:00 2001 From: SiboVG Date: Sat, 8 Apr 2023 23:43:56 +0200 Subject: [PATCH] Throw error when wrong component in booster stage --- core/resources/l10n/messages.properties | 12 ++++++------ .../file/rasaero/export/BoosterDTO.java | 19 ++++++++----------- .../file/rasaero/export/RocketDesignDTO.java | 2 +- .../file/rasaero/export/SimulationDTO.java | 6 +++--- .../rasaero/importt/SimulationHandler.java | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/core/resources/l10n/messages.properties b/core/resources/l10n/messages.properties index dc66d9ae5..2844bd5b6 100644 --- a/core/resources/l10n/messages.properties +++ b/core/resources/l10n/messages.properties @@ -1378,12 +1378,10 @@ RASAeroExport.warning6 = Already added a launch lug, ignoring rail button '%s'. RASAeroExport.warning7 = Already added a launch shoe, ignoring rail button '%s'. RASAeroExport.warning8 = Instance count of '%s' equals %d, defaulting to 2. RASAeroExport.warning9 = Unsupported component '%s', ignoring. -RASAeroExport.warning10 = Stage '%s' can only contain a body tube, ignoring other %d component(s). -RASAeroExport.warning11 = Stage '%s' can only contain a body tube and transition shoulder, ignoring other %d component(s). -RASAeroExport.warning12 = Rocket should have no more then 3 stages (excl. boosters) in total.\nIgnoring other stage(s). -RASAeroExport.warning13 = Empty simulation '%s', ignoring. -RASAeroExport.warning14 = No motors found in simulation '%s', ignoring. -RASAeroExport.warning15 = Stage %s has no motor.
  --> When adding a motor in RASAero, don't forget to update the stage mass and CG. +RASAeroExport.warning10 = Rocket should have no more then 3 stages (excl. boosters) in total.\nIgnoring other stage(s). +RASAeroExport.warning11 = Empty simulation '%s', ignoring. +RASAeroExport.warning12 = No motors found in simulation '%s', ignoring. +RASAeroExport.warning13 = Stage %s has no motor.
  --> When adding a motor in RASAero, don't forget to update the stage mass and CG. RASAeroExport.error1 = Unsupported component: %s. RASAeroExport.error2 = Length of '%s' must be greater than 0. RASAeroExport.error3 = Diameter of '%s' must be greater than 0. @@ -1414,6 +1412,8 @@ RASAeroExport.error27 = Transition '%s' has no previous component. RASAeroExport.error28 = Transition '%s' should have the same fore radius as the aft radius (%f) of its previous component, not %f. RASAeroExport.error29 = Boattail length may not be zero. RASAeroExport.error30 = Boattail rear diameter may not be zero. +RASAeroExport.error31 = Stage '%s' can only contain a body tube (incl. shoulder transition), ignoring other %d component(s). +RASAeroExport.error32 = Boattails can only be added to the last stage. ! SaveAsFileChooser SaveAsFileChooser.illegalFilename.title = Illegal filename diff --git a/core/src/net/sf/openrocket/file/rasaero/export/BoosterDTO.java b/core/src/net/sf/openrocket/file/rasaero/export/BoosterDTO.java index 9b52bf818..3cba7be79 100644 --- a/core/src/net/sf/openrocket/file/rasaero/export/BoosterDTO.java +++ b/core/src/net/sf/openrocket/file/rasaero/export/BoosterDTO.java @@ -169,24 +169,21 @@ public class BoosterDTO implements BodyTubeDTOAdapter { } } else { // If this booster is the last stage, and the last component is a transition, it could be a boattail - if (stageNr == rocket.getChildCount() - 1 && (comp instanceof Transition && !(comp instanceof NoseCone)) && - i == stage.getChildCount() - 1) { + boolean isBoattail = (comp instanceof Transition && !(comp instanceof NoseCone)) && i == stage.getChildCount() - 1; + if (stageNr == rocket.getChildCount() - 1 && isBoattail) { Transition transition = (Transition) comp; setBoattailLength(transition.getLength() * RASAeroCommonConstants.OPENROCKET_TO_RASAERO_LENGTH); setBoattailRearDiameter(transition.getAftRadius() * 2 * RASAeroCommonConstants.OPENROCKET_TO_RASAERO_LENGTH); } - // Case: normal body tube - if (stage.getChildPosition(firstTube) == 0) { - warnings.add(String.format(trans.get("RASAeroExport.warning10"), - stage.getName(), stage.getChildCount() - i)); - } - // Case: body tube with transition shoulder - else { - warnings.add(String.format(trans.get("RASAeroExport.warning11"), - stage.getName(), stage.getChildCount() - i)); + String msg = String.format(trans.get("RASAeroExport.error31"), stage.getName(), stage.getChildCount() - i); + + if (isBoattail) { + msg = "" + msg + "
 " + trans.get("RASAeroExport.error32") + ""; } + errors.add(msg); + break; } } diff --git a/core/src/net/sf/openrocket/file/rasaero/export/RocketDesignDTO.java b/core/src/net/sf/openrocket/file/rasaero/export/RocketDesignDTO.java index d2a36ddda..1b6fe6367 100644 --- a/core/src/net/sf/openrocket/file/rasaero/export/RocketDesignDTO.java +++ b/core/src/net/sf/openrocket/file/rasaero/export/RocketDesignDTO.java @@ -76,7 +76,7 @@ public class RocketDesignDTO { public RocketDesignDTO(Rocket rocket, WarningSet warnings, ErrorSet errors) { setComments(rocket.getComment()); if (rocket.getChildCount() > 3) { - warnings.add(trans.get("RASAeroExport.warning12")); + warnings.add(trans.get("RASAeroExport.warning10")); } setUseBooster1(rocket.getChildCount() >= 2); setUseBooster2(rocket.getChildCount() == 3); diff --git a/core/src/net/sf/openrocket/file/rasaero/export/SimulationDTO.java b/core/src/net/sf/openrocket/file/rasaero/export/SimulationDTO.java index 00df03c80..b21a715b0 100644 --- a/core/src/net/sf/openrocket/file/rasaero/export/SimulationDTO.java +++ b/core/src/net/sf/openrocket/file/rasaero/export/SimulationDTO.java @@ -130,12 +130,12 @@ public class SimulationDTO { FlightConfigurationId fcid = simulation != null ? simulation.getFlightConfigurationId() : null; if (simulation != null && fcid == null) { - warnings.add(String.format(trans.get("RASAeroExport.warning13"), simulationName)); + warnings.add(String.format(trans.get("RASAeroExport.warning11"), simulationName)); return; } if (mounts.isEmpty()) { - warnings.add(String.format(trans.get("RASAeroExport.warning14"), simulationName)); + warnings.add(String.format(trans.get("RASAeroExport.warning12"), simulationName)); return; } @@ -170,7 +170,7 @@ public class SimulationDTO { // Add friendly reminder to user if (motor == null) { - warnings.add(String.format(trans.get("RASAeroExport.warning15"), stage.getName())); + warnings.add(String.format(trans.get("RASAeroExport.warning13"), stage.getName())); } // Add the simulation info for each stage diff --git a/core/src/net/sf/openrocket/file/rasaero/importt/SimulationHandler.java b/core/src/net/sf/openrocket/file/rasaero/importt/SimulationHandler.java index 1bdff7c1a..730f730ea 100644 --- a/core/src/net/sf/openrocket/file/rasaero/importt/SimulationHandler.java +++ b/core/src/net/sf/openrocket/file/rasaero/importt/SimulationHandler.java @@ -160,7 +160,7 @@ public class SimulationHandler extends AbstractElementHandler { } MotorMount mount = getMotorMountForStage(stageNr); if (mount == null) { - warnings.add("No motor mount found for stage " + stageNr + ". Ignoring motor."); + warnings.add("No motor mount found for stage " + stageNr + ". Ignoring motor."); return null; } MotorConfiguration motorConfig = new MotorConfiguration(mount, id);