[#1820] Don't switch to simulation plot if "Simulate & Plot" resulted in faulty simulation

This commit is contained in:
SiboVG 2022-11-14 16:42:06 +01:00
parent f68189c3e2
commit baed200d27
3 changed files with 31 additions and 7 deletions

View File

@ -209,12 +209,10 @@ public class SimulationEditDialog extends JDialog {
@Override
public void actionPerformed(ActionEvent e) {
copyChangesToAllSims();
SimulationRunDialog.runSimulations(parentWindow, SimulationEditDialog.this.document, simulationList);
SimulationRunDialog dialog = SimulationRunDialog.runSimulations(parentWindow, SimulationEditDialog.this.document, simulationList);
if (allowsPlotMode() && dialog.isAllSimulationsSuccessful()) {
refreshView();
if (allowsPlotMode()) {
setPlotMode();
} else {
setVisible(false);
}
}
});

View File

@ -207,9 +207,12 @@ public class SimulationRunDialog extends JDialog {
* the parent Window of the dialog to use.
* @param simulations
* the simulations to run.
* @return the simulation run dialog instance.
*/
public static void runSimulations(Window parent, OpenRocketDocument document, Simulation... simulations) {
new SimulationRunDialog(parent, document, simulations).setVisible(true);
public static SimulationRunDialog runSimulations(Window parent, OpenRocketDocument document, Simulation... simulations) {
SimulationRunDialog dialog = new SimulationRunDialog(parent, document, simulations);
dialog.setVisible(true);
return dialog;
}
private void updateProgress() {
@ -257,6 +260,18 @@ public class SimulationRunDialog extends JDialog {
+ u.toStringUnit(simulationMaxVelocity[index]) + ")");
}
/**
* Returns true if all the simulations ran successfully. Returns false if the simulations encountered
* an exception, or were cancelled.
*/
public boolean isAllSimulationsSuccessful() {
for (SimulationWorker w : simulationWorkers) {
if (w.getThrowable() != null)
return false;
}
return true;
}
/**
* A SwingWorker that performs a flight simulation. It periodically updates
* the simulation statuses of the parent class and calls updateProgress().

View File

@ -71,6 +71,17 @@ public abstract class SimulationWorker extends SwingWorker<FlightData, Simulatio
return new SimulationListener[0];
}
/**
* Returns the throwable that caused the simulation to fail or cancel,
* or null if the simulation ran successfully.
*
* @return throwable that caused the simulation to fail or cancel,
* or null if the simulation ran successfully.
*/
public Throwable getThrowable() {
return throwable;
}
/**
* Called after a simulation is successfully simulated. This method is not