Move FlightDataBranch from SimulationException to SimulationCalculationException (since those are the only SimulationExceptions that make use of it).

Require FlightDataBranch when throwing SimulationCalculationException

Don't allow setting FlightDataBranch in SimulationCalculationException when exception is rethrown.
This commit is contained in:
JoePfeiffer 2024-04-22 15:13:42 -06:00
parent bcfa73eb21
commit 64832fe8d6
5 changed files with 26 additions and 35 deletions

View File

@ -291,8 +291,8 @@ public class BasicEventSimulationEngine implements SimulationEngine {
flightData.getWarningSet().addAll(currentStatus.getWarnings());
e.setFlightData(flightData);
e.setFlightDataBranch(currentStatus.getFlightDataBranch());
//e.setFlightData(flightData);
//e.setFlightDataBranch(currentStatus.getFlightDataBranch());
throw e;
}
@ -731,7 +731,8 @@ public class BasicEventSimulationEngine implements SimulationEngine {
" rocketOrientationQuaternion=" + currentStatus.getRocketOrientationQuaternion() +
" rocketRotationVelocity=" + currentStatus.getRocketRotationVelocity() +
" effectiveLaunchRodLength=" + currentStatus.getEffectiveLaunchRodLength());
throw new SimulationCalculationException(trans.get("BasicEventSimulationEngine.error.NaNResult"));
throw new SimulationCalculationException(trans.get("BasicEventSimulationEngine.error.NaNResult"),
currentStatus.getFlightDataBranch());
}
}

View File

@ -247,7 +247,7 @@ public class RK4SimulationStepper extends AbstractSimulationStepper {
if (status.getRocketVelocity().length2() > 1e18 ||
status.getRocketPosition().length2() > 1e18 ||
status.getRocketRotationVelocity().length2() > 1e18) {
throw new SimulationCalculationException(trans.get("error.valuesTooLarge"));
throw new SimulationCalculationException(trans.get("error.valuesTooLarge"), status.getFlightDataBranch());
}
}

View File

@ -1,5 +1,7 @@
package info.openrocket.core.simulation.exception;
import info.openrocket.core.simulation.FlightDataBranch;
/**
* An exception that indicates that a computation problem has occurred during
* the simulation, for example that some values have exceed reasonable bounds.
@ -8,19 +10,27 @@ package info.openrocket.core.simulation.exception;
*/
public class SimulationCalculationException extends SimulationException {
private FlightDataBranch flightDataBranch;
public SimulationCalculationException() {
}
public SimulationCalculationException(String message) {
public SimulationCalculationException(String message, FlightDataBranch dataBranch) {
super(message);
flightDataBranch = dataBranch;
}
public SimulationCalculationException(Throwable cause) {
public SimulationCalculationException(Throwable cause, FlightDataBranch dataBranch) {
super(cause);
flightDataBranch = dataBranch;
}
public SimulationCalculationException(String message, Throwable cause) {
public SimulationCalculationException(String message, Throwable cause, FlightDataBranch dataBranch) {
super(message, cause);
flightDataBranch = dataBranch;
}
public FlightDataBranch getFlightDataBranch() {
return flightDataBranch;
}
}

View File

@ -1,15 +1,9 @@
package info.openrocket.core.simulation.exception;
import info.openrocket.core.simulation.FlightData;
import info.openrocket.core.simulation.FlightDataBranch;
public class SimulationException extends Exception {
private FlightData flightData = null;
private FlightDataBranch flightDataBranch = null;
public SimulationException() {
super();
}
public SimulationException(String message) {
@ -23,21 +17,4 @@ public class SimulationException extends Exception {
public SimulationException(String message, Throwable cause) {
super(message, cause);
}
public void setFlightData(FlightData f) {
flightData = f;
}
public FlightData getFlightData() {
return flightData;
}
public void setFlightDataBranch(FlightDataBranch f) {
flightDataBranch = f;
}
public FlightDataBranch getFlightDataBranch() {
return flightDataBranch;
}
}

View File

@ -36,6 +36,7 @@ import info.openrocket.core.simulation.FlightEvent;
import info.openrocket.core.simulation.SimulationStatus;
import info.openrocket.core.simulation.customexpression.CustomExpression;
import info.openrocket.core.simulation.customexpression.CustomExpressionSimulationListener;
import info.openrocket.core.simulation.exception.SimulationCalculationException;
import info.openrocket.core.simulation.exception.SimulationCancelledException;
import info.openrocket.core.simulation.exception.SimulationException;
import info.openrocket.core.simulation.listeners.AbstractSimulationListener;
@ -426,14 +427,16 @@ public class SimulationRunDialog extends JDialog {
// Analyze the exception type
if (t instanceof SimulationException) {
String title = simulation.getName();
FlightDataBranch dataBranch = ((SimulationException) t).getFlightDataBranch();
FlightDataBranch dataBranch = null;
if (t instanceof SimulationCalculationException) {
dataBranch = ((SimulationCalculationException) t).getFlightDataBranch();
}
String message;
if (dataBranch != null) {
message = trans.get("SimuRunDlg.msg.branchErrorOccurred") + "\"" + dataBranch.getName() + "\"";
message = trans.get("SimuRunDlg.msg.branchErrorOccurred") + " \"" + dataBranch.getName() + "\"";
} else {
message = trans.get("SimuRunDlg.msg.errorOccurred");
}
}
DetailDialog.showDetailedMessageDialog(SimulationRunDialog.this,
new Object[] {
//// A error occurred during the simulation: