diff --git a/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java b/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java index aeae329b3..6ee1f5cb9 100644 --- a/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java +++ b/core/src/main/java/info/openrocket/core/simulation/BasicEventSimulationEngine.java @@ -108,7 +108,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { // No recovery device if (!simulationConfig.hasRecoveryDevice()) { - currentStatus.getWarnings().add(Warning.NO_RECOVERY_DEVICE); + currentStatus.addWarning(Warning.NO_RECOVERY_DEVICE); } currentStatus.getEventQueue().add(new FlightEvent(FlightEvent.Type.LAUNCH, 0, simulationConditions.getRocket())); @@ -315,7 +315,7 @@ public class BasicEventSimulationEngine implements SimulationEngine { if (currentStatus.isLanded() && (event.getType() != FlightEvent.Type.ALTITUDE) && (event.getType() != FlightEvent.Type.SIMULATION_END)) - currentStatus.getWarnings().add(new Warning.EventAfterLanding(event)); + currentStatus.addWarning(new Warning.EventAfterLanding(event)); // Check for motor ignition events, add ignition events to queue for (MotorClusterState state : currentStatus.getActiveMotors() ){ @@ -500,12 +500,12 @@ public class BasicEventSimulationEngine implements SimulationEngine { } } if (numActiveBelow != 1) { - currentStatus.getWarnings().add(Warning.SEPARATION_ORDER); + currentStatus.addWarning(Warning.SEPARATION_ORDER); } // If I haven't cleared the rail yet, flag a warning if (!currentStatus.isLaunchRodCleared()) { - currentStatus.getWarnings().add(Warning.EARLY_SEPARATION); + currentStatus.addWarning(Warning.EARLY_SEPARATION); } // Create a new simulation branch for the booster @@ -565,12 +565,12 @@ public class BasicEventSimulationEngine implements SimulationEngine { // Check for launch rod if (!currentStatus.isLaunchRodCleared()) { - currentStatus.getWarnings().add(Warning.RECOVERY_LAUNCH_ROD); + currentStatus.addWarning(Warning.RECOVERY_LAUNCH_ROD); } // Check current velocity if (currentStatus.getRocketVelocity().length() > 20) { - currentStatus.getWarnings().add(new Warning.HighSpeedDeployment(currentStatus.getRocketVelocity().length())); + currentStatus.addWarning(new Warning.HighSpeedDeployment(currentStatus.getRocketVelocity().length())); } currentStatus.setLiftoff(true); diff --git a/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java b/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java index 889e74d17..892c5000c 100644 --- a/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java +++ b/core/src/main/java/info/openrocket/core/simulation/RK4SimulationStepper.java @@ -403,7 +403,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { * launch rod or 0.25 seconds after departure, and when the velocity has dropped * below 20% of the max. velocity. */ - WarningSet warnings = status.getWarnings(); + WarningSet warnings = new WarningSet(); store.maxZvelocity = MathUtil.max(store.maxZvelocity, status.getRocketVelocity().z); if (!status.isLaunchRodCleared()) { @@ -423,7 +423,9 @@ public class RK4SimulationStepper extends AbstractSimulationStepper { // Calculate aerodynamic forces store.forces = status.getSimulationConditions().getAerodynamicCalculator() .getAerodynamicForces(status.getConfiguration(), store.flightConditions, warnings); - + if (null != warnings) { + status.addWarnings(warnings); + } // Add very small randomization to yaw & pitch moments to prevent over-perfect flight // TODO: HIGH: This should rather be performed as a listener diff --git a/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java b/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java index 953becf09..36f3d5512 100644 --- a/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java +++ b/core/src/main/java/info/openrocket/core/simulation/SimulationStatus.java @@ -9,6 +9,7 @@ import java.util.Set; import info.openrocket.core.aerodynamics.FlightConditions; import info.openrocket.core.logging.SimulationAbort; +import info.openrocket.core.logging.Warning; import info.openrocket.core.logging.WarningSet; import info.openrocket.core.motor.MotorConfiguration; import info.openrocket.core.motor.MotorConfigurationId; @@ -420,6 +421,23 @@ public class SimulationStatus implements Cloneable, Monitorable { this.warnings = warnings; } + public void addWarning(Warning warning) { + if (null == warnings) { + setWarnings(new WarningSet()); + } + if (!warnings.contains(warning)) { + log.trace("Add warning: \"" + warning + "\""); + getFlightDataBranch().addEvent(new FlightEvent(FlightEvent.Type.SIM_WARN, getSimulationTime(), null, warning)); + warnings.add(warning); + } + } + + public void addWarnings(WarningSet warnings) { + for (Warning warning : warnings) { + addWarning(warning); + } + } + public WarningSet getWarnings() { return warnings; } diff --git a/core/src/main/java/info/openrocket/core/simulation/listeners/SimulationListenerHelper.java b/core/src/main/java/info/openrocket/core/simulation/listeners/SimulationListenerHelper.java index 0b5ca9597..bd8ffb8b7 100644 --- a/core/src/main/java/info/openrocket/core/simulation/listeners/SimulationListenerHelper.java +++ b/core/src/main/java/info/openrocket/core/simulation/listeners/SimulationListenerHelper.java @@ -636,7 +636,7 @@ public class SimulationListenerHelper { private static void warn(SimulationStatus status, SimulationListener listener) { if (!listener.isSystemListener()) { log.info("Non-system listener " + listener + " affected the simulation"); - status.getWarnings().add(Warning.LISTENERS_AFFECTED); + status.addWarning(Warning.LISTENERS_AFFECTED); } } }