Create new SimulationStatus.addWarning() and SimulationStatus.addWarnings() methods. addWarning() adds a warning to the WarningSet, and adds a SIM_WARN FlightEvent to the data branch. addWarnings() uses addWarning() to merge two WarningSets.
Replace instances of status.getWarnings().add() (and similar code) with status.addWarning()
This commit is contained in:
parent
bbf38dd239
commit
47e7e017bb
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user