Merge pull request #2149 from SiboVG/issue-2140

[#2148] Apply sim changes when window closes & [#1826] Fill in gaps in multi-sim editing
This commit is contained in:
Sibo Van Gool 2023-03-30 15:54:28 +02:00 committed by GitHub
commit 556522c8ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 48 deletions

View File

@ -442,10 +442,6 @@ public class SimulationOptions implements ChangeSource, Cloneable {
isChanged = true; isChanged = true;
this.launchLongitude = src.launchLongitude; this.launchLongitude = src.launchLongitude;
} }
if (this.launchPressure != src.launchPressure) {
isChanged = true;
this.launchPressure = src.launchPressure;
}
if (this.launchRodAngle != src.launchRodAngle) { if (this.launchRodAngle != src.launchRodAngle) {
isChanged = true; isChanged = true;
this.launchRodAngle = src.launchRodAngle; this.launchRodAngle = src.launchRodAngle;
@ -458,19 +454,26 @@ public class SimulationOptions implements ChangeSource, Cloneable {
isChanged = true; isChanged = true;
this.launchRodLength = src.launchRodLength; this.launchRodLength = src.launchRodLength;
} }
if (this.launchIntoWind != src.launchIntoWind) {
isChanged = true;
this.launchIntoWind = src.launchIntoWind;
}
if (this.useISA != src.useISA) {
isChanged = true;
this.useISA = src.useISA;
}
if (this.launchTemperature != src.launchTemperature) { if (this.launchTemperature != src.launchTemperature) {
isChanged = true; isChanged = true;
this.launchTemperature = src.launchTemperature; this.launchTemperature = src.launchTemperature;
} }
if (this.launchPressure != src.launchPressure) {
isChanged = true;
this.launchPressure = src.launchPressure;
}
if (this.maximumAngle != src.maximumAngle) { if (this.maximumAngle != src.maximumAngle) {
isChanged = true; isChanged = true;
this.maximumAngle = src.maximumAngle; this.maximumAngle = src.maximumAngle;
} }
this.maximumAngle = src.maximumAngle;
if (this.timeStep != src.timeStep) {
isChanged = true;
this.timeStep = src.timeStep;
}
if (this.windAverage != src.windAverage) { if (this.windAverage != src.windAverage) {
isChanged = true; isChanged = true;
this.windAverage = src.windAverage; this.windAverage = src.windAverage;
@ -487,6 +490,14 @@ public class SimulationOptions implements ChangeSource, Cloneable {
isChanged = true; isChanged = true;
this.calculateExtras = src.calculateExtras; this.calculateExtras = src.calculateExtras;
} }
if (this.timeStep != src.timeStep) {
isChanged = true;
this.timeStep = src.timeStep;
}
if (this.geodeticComputation != src.geodeticComputation) {
isChanged = true;
this.geodeticComputation = src.geodeticComputation;
}
if (isChanged) { if (isChanged) {
// Only copy the randomSeed if something else has changed. // Only copy the randomSeed if something else has changed.

View File

@ -515,12 +515,12 @@ public class BasicFrame extends JFrame {
fileMenu.add(item); fileMenu.add(item);
//// Edit //// Edit
fileMenu = new JMenu(trans.get("main.menu.edit")); JMenu editMenu = new JMenu(trans.get("main.menu.edit"));
fileMenu.setMnemonic(KeyEvent.VK_E); editMenu.setMnemonic(KeyEvent.VK_E);
//// Rocket editing //// Rocket editing
fileMenu.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.edit.desc")); editMenu.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.edit.desc"));
menubar.add(fileMenu); menubar.add(editMenu);
Action action = UndoRedoAction.newUndoAction(document); Action action = UndoRedoAction.newUndoAction(document);
item = new JMenuItem(action); item = new JMenuItem(action);
@ -530,7 +530,7 @@ public class BasicFrame extends JFrame {
//// Undo the previous operation //// Undo the previous operation
item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.edit.undo.desc")); item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.edit.undo.desc"));
fileMenu.add(item); editMenu.add(item);
action = UndoRedoAction.newRedoAction(document); action = UndoRedoAction.newRedoAction(document);
item = new JMenuItem(action); item = new JMenuItem(action);
@ -539,42 +539,42 @@ public class BasicFrame extends JFrame {
//// Redo the previously undone operation //// Redo the previously undone operation
item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.edit.redo.desc")); item.getAccessibleContext().setAccessibleDescription(trans.get("main.menu.edit.redo.desc"));
fileMenu.add(item); editMenu.add(item);
fileMenu.addSeparator(); editMenu.addSeparator();
item = new JMenuItem(actions.getEditAction()); item = new JMenuItem(actions.getEditAction());
fileMenu.add(item); editMenu.add(item);
item = new JMenuItem(actions.getCutAction()); item = new JMenuItem(actions.getCutAction());
fileMenu.add(item); editMenu.add(item);
item = new JMenuItem(actions.getCopyAction()); item = new JMenuItem(actions.getCopyAction());
fileMenu.add(item); editMenu.add(item);
item = new JMenuItem(actions.getPasteAction()); item = new JMenuItem(actions.getPasteAction());
fileMenu.add(item); editMenu.add(item);
item = new JMenuItem(actions.getDuplicateAction()); item = new JMenuItem(actions.getDuplicateAction());
fileMenu.add(item); editMenu.add(item);
item = new JMenuItem(actions.getDeleteAction()); item = new JMenuItem(actions.getDeleteAction());
fileMenu.add(item); editMenu.add(item);
fileMenu.addSeparator(); editMenu.addSeparator();
JMenu subMenu = new JMenu(trans.get("RocketActions.Select")); JMenu subMenu = new JMenu(trans.get("RocketActions.Select"));
fileMenu.add(subMenu); editMenu.add(subMenu);
item = new JMenuItem(actions.getSelectSameColorAction()); item = new JMenuItem(actions.getSelectSameColorAction());
subMenu.add(item); subMenu.add(item);
item = new JMenuItem(actions.getDeselectAllAction()); item = new JMenuItem(actions.getDeselectAllAction());
subMenu.add(item); subMenu.add(item);
fileMenu.addSeparator(); editMenu.addSeparator();
item = new JMenuItem(actions.getScaleAction()); item = new JMenuItem(actions.getScaleAction());
fileMenu.add(item); editMenu.add(item);
//// Preferences //// Preferences
@ -590,7 +590,7 @@ public class BasicFrame extends JFrame {
PreferencesDialog.showPreferences(BasicFrame.this); PreferencesDialog.showPreferences(BasicFrame.this);
} }
}); });
fileMenu.add(item); editMenu.add(item);
//// Edit Component Preset File //// Edit Component Preset File
if (System.getProperty("openrocket.preseteditor.fileMenu") != null) { if (System.getProperty("openrocket.preseteditor.fileMenu") != null) {
@ -605,13 +605,13 @@ public class BasicFrame extends JFrame {
dialog.setVisible(true); dialog.setVisible(true);
} }
}); });
fileMenu.add(item); editMenu.add(item);
} }
// Tools // Tools
fileMenu = new JMenu(trans.get("main.menu.tools")); JMenu toolsMenu = new JMenu(trans.get("main.menu.tools"));
menubar.add(fileMenu); menubar.add(toolsMenu);
//// Component analysis //// Component analysis
item = new JMenuItem(trans.get("main.menu.tools.componentAnalysis"), KeyEvent.VK_C); item = new JMenuItem(trans.get("main.menu.tools.componentAnalysis"), KeyEvent.VK_C);
@ -625,7 +625,7 @@ public class BasicFrame extends JFrame {
ComponentAnalysisDialog.showDialog(rocketpanel); ComponentAnalysisDialog.showDialog(rocketpanel);
} }
}); });
fileMenu.add(item); toolsMenu.add(item);
//// Optimize //// Optimize
item = new JMenuItem(trans.get("main.menu.tools.optimization"), KeyEvent.VK_O); item = new JMenuItem(trans.get("main.menu.tools.optimization"), KeyEvent.VK_O);
@ -641,7 +641,7 @@ public class BasicFrame extends JFrame {
} }
} }
}); });
fileMenu.add(item); toolsMenu.add(item);
//// Custom expressions //// Custom expressions
item = new JMenuItem(trans.get("main.menu.tools.customExpressions"), KeyEvent.VK_E); item = new JMenuItem(trans.get("main.menu.tools.customExpressions"), KeyEvent.VK_E);
@ -653,7 +653,7 @@ public class BasicFrame extends JFrame {
new CustomExpressionDialog(document, BasicFrame.this).setVisible(true); new CustomExpressionDialog(document, BasicFrame.this).setVisible(true);
} }
}); });
fileMenu.add(item); toolsMenu.add(item);
item = new JMenuItem(trans.get("PhotoFrame.title"), KeyEvent.VK_P); item = new JMenuItem(trans.get("PhotoFrame.title"), KeyEvent.VK_P);
item.getAccessibleContext().setAccessibleDescription(trans.get("PhotoFrame.desc")); item.getAccessibleContext().setAccessibleDescription(trans.get("PhotoFrame.desc"));
@ -665,7 +665,7 @@ public class BasicFrame extends JFrame {
pa.setVisible(true); pa.setVisible(true);
} }
}); });
fileMenu.add(item); toolsMenu.add(item);
//// Debug //// Debug
// // (shown if openrocket.debug.fileMenu is defined) // // (shown if openrocket.debug.fileMenu is defined)
@ -1284,34 +1284,24 @@ public class BasicFrame extends JFrame {
//// Handle the document //// Handle the document
OpenRocketDocument doc = null; OpenRocketDocument doc = null;
try { try {
doc = worker.get(); doc = worker.get();
} catch (ExecutionException e) { } catch (ExecutionException e) {
Throwable cause = e.getCause(); Throwable cause = e.getCause();
if (cause instanceof FileNotFoundException) { if (cause instanceof FileNotFoundException) {
log.warn("File not found", cause); log.warn("File not found", cause);
JOptionPane.showMessageDialog(parent, JOptionPane.showMessageDialog(parent,
"File not found: " + displayName, "File not found: " + displayName,
"Error opening file", JOptionPane.ERROR_MESSAGE); "Error opening file", JOptionPane.ERROR_MESSAGE);
return null; return null;
} else if (cause instanceof RocketLoadException) { } else if (cause instanceof RocketLoadException) {
log.warn("Error loading the file", cause); log.warn("Error loading the file", cause);
JOptionPane.showMessageDialog(parent, JOptionPane.showMessageDialog(parent,
"Unable to open file '" + displayName + "': " "Unable to open file '" + displayName + "': "
+ cause.getMessage(), + cause.getMessage(),
"Error opening file", JOptionPane.ERROR_MESSAGE); "Error opening file", JOptionPane.ERROR_MESSAGE);
return null; return null;
} else { } else {
throw new BugException("Unknown error when opening file", e); throw new BugException("Unknown error when opening file", e);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -1322,7 +1312,6 @@ public class BasicFrame extends JFrame {
throw new BugException("Document loader returned null"); throw new BugException("Document loader returned null");
} }
//// Show warnings //// Show warnings
WarningSet warnings = worker.getRocketLoader().getWarnings(); WarningSet warnings = worker.getRocketLoader().getWarnings();
if (!warnings.isEmpty()) { if (!warnings.isEmpty()) {

View File

@ -107,7 +107,7 @@ public final class ExampleDesignFileAction extends JMenu {
/** /**
* When a user clicks on one of the recently used design files, open it. * When a user clicks on one of the recently used design files, open it.
* *
* @param file the design file name (absolute path) * @param example the design file name (absolute path)
* *
* @return the action to open a design file * @return the action to open a design file
*/ */

View File

@ -662,7 +662,7 @@ public class SimulationPanel extends JPanel {
@Override @Override
public void updateEnabledState() { public void updateEnabledState() {
setEnabled(simulationTable.getSelectedRowCount() == 1); setEnabled(simulationTable.getSelectedRowCount() > 0);
} }
} }

View File

@ -5,6 +5,9 @@ import java.awt.CardLayout;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComboBox; import javax.swing.JComboBox;
@ -42,6 +45,8 @@ public class SimulationEditDialog extends JDialog {
JPanel cards; JPanel cards;
private final static String EDITMODE = "EDIT"; private final static String EDITMODE = "EDIT";
private final static String PLOTMODE = "PLOT"; private final static String PLOTMODE = "PLOT";
private WindowListener applyChangesToSimsListener;
public SimulationEditDialog(Window parent, final OpenRocketDocument document, Simulation... sims) { public SimulationEditDialog(Window parent, final OpenRocketDocument document, Simulation... sims) {
//// Edit simulation //// Edit simulation
@ -59,6 +64,14 @@ public class SimulationEditDialog extends JDialog {
this.pack(); this.pack();
this.setLocationByPlatform(true); this.setLocationByPlatform(true);
this.applyChangesToSimsListener = new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
copyChangesToAllSims();
}
};
this.addWindowListener(applyChangesToSimsListener);
GUIUtil.setDisposableDialogOptions(this, null); GUIUtil.setDisposableDialogOptions(this, null);
} }
@ -75,12 +88,14 @@ public class SimulationEditDialog extends JDialog {
CardLayout cl = (CardLayout) (cards.getLayout()); CardLayout cl = (CardLayout) (cards.getLayout());
cl.show(cards, EDITMODE); cl.show(cards, EDITMODE);
cards.validate(); cards.validate();
this.addWindowListener(applyChangesToSimsListener);
} }
public void setPlotMode() { public void setPlotMode() {
if (!allowsPlotMode()) { if (!allowsPlotMode()) {
return; return;
} }
this.removeWindowListener(applyChangesToSimsListener);
setTitle(trans.get("simplotpanel.title.Plotsim")); setTitle(trans.get("simplotpanel.title.Plotsim"));
CardLayout cl = (CardLayout) (cards.getLayout()); CardLayout cl = (CardLayout) (cards.getLayout());
cl.show(cards, PLOTMODE); cl.show(cards, PLOTMODE);
@ -223,7 +238,6 @@ public class SimulationEditDialog extends JDialog {
close.addActionListener(new ActionListener() { close.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
copyChangesToAllSims();
SimulationEditDialog.this.dispose(); SimulationEditDialog.this.dispose();
} }
}); });