Merge pull request #1059 from SiboVG/issue-1058

[fixes #1058] Launch info dialog for no simulations GeneralOptimizer
This commit is contained in:
Joe Pfeiffer 2021-11-21 15:07:00 -07:00 committed by GitHub
commit 459d4ab4ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View File

@ -1877,7 +1877,8 @@ optimization.modifier.motormount.delay.desc = Optimize the motor ignition delay.
! General rocket design optimization dialog
GeneralOptimizationDialog.info.noSims.title = No simulations
GeneralOptimizationDialog.info.noSims.message = No simulations created yet to optimize
GeneralOptimizationDialog.title = Rocket optimization
GeneralOptimizationDialog.goal.maximize = Maximize value
GeneralOptimizationDialog.goal.minimize = Minimize value

View File

@ -190,12 +190,13 @@ public class GeneralOptimizationDialog extends JDialog {
* @param document the document
* @param parent the parent window
*/
public GeneralOptimizationDialog(OpenRocketDocument document, Window parent) {
public GeneralOptimizationDialog(OpenRocketDocument document, Window parent) throws InterruptedException {
super(parent, trans.get("title"));
this.baseDocument = document;
this.documentCopy = document.copy();
checkExistingSimulations();
loadOptimizationParameters();
loadSimulationModifiers();
@ -905,6 +906,19 @@ public class GeneralOptimizationDialog extends JDialog {
}
/**
* Checks whether there are simulations present in the document. If not, a pop-up information
* dialog launches stating that the optimizer cannot be launched.
* @throws InterruptedException when no simulations present
*/
private void checkExistingSimulations() throws InterruptedException {
if (documentCopy.getSimulations().size() == 0) {
JOptionPane.showMessageDialog(null, trans.get("GeneralOptimizationDialog.info.noSims.message"),
trans.get("GeneralOptimizationDialog.info.noSims.title"), JOptionPane.INFORMATION_MESSAGE);
throw new InterruptedException("No simulations to optimize");
}
}
private void populateSimulations() {
String current = null;
Object selection = simulationSelectionCombo.getSelectedItem();

View File

@ -716,7 +716,11 @@ public class BasicFrame extends JFrame {
@Override
public void actionPerformed(ActionEvent e) {
log.info(Markers.USER_MARKER, "Rocket optimization selected");
try {
new GeneralOptimizationDialog(document, BasicFrame.this).setVisible(true);
} catch (InterruptedException ex) {
log.warn(ex.getMessage());
}
}
});
menu.add(item);