[fixes #771] Auto update simulations upon motor/recovery/stage configuration change

This commit is contained in:
Sibo Van Gool 2021-08-30 10:53:41 +02:00
parent 894ac89733
commit 9700c9fc86
7 changed files with 107 additions and 41 deletions

View File

@ -8,6 +8,8 @@ import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.Pair; import net.sf.openrocket.util.Pair;
import java.util.Objects;
public class DeploymentConfiguration implements FlightConfigurableParameter<DeploymentConfiguration> { public class DeploymentConfiguration implements FlightConfigurableParameter<DeploymentConfiguration> {
@ -155,4 +157,16 @@ public class DeploymentConfiguration implements FlightConfigurableParameter<Depl
public void update(){ public void update(){
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DeploymentConfiguration that = (DeploymentConfiguration) o;
return Double.compare(that.deployAltitude, deployAltitude) == 0 && Double.compare(that.deployDelay, deployDelay) == 0 && deployEvent == that.deployEvent;
}
@Override
public int hashCode() {
return Objects.hash(deployEvent, deployAltitude, deployDelay);
}
} }

View File

@ -5,6 +5,8 @@ import net.sf.openrocket.simulation.FlightEvent;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.MathUtil;
import java.util.Objects;
public class StageSeparationConfiguration implements FlightConfigurableParameter<StageSeparationConfiguration> { public class StageSeparationConfiguration implements FlightConfigurableParameter<StageSeparationConfiguration> {
public static enum SeparationEvent { public static enum SeparationEvent {
@ -145,6 +147,18 @@ public class StageSeparationConfiguration implements FlightConfigurableParameter
return clone; return clone;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StageSeparationConfiguration that = (StageSeparationConfiguration) o;
return Double.compare(that.separationDelay, separationDelay) == 0 && separationEvent == that.separationEvent;
}
@Override
public int hashCode() {
return Objects.hash(separationEvent, separationDelay);
}
private void fireChangeEvent() { private void fireChangeEvent() {

View File

@ -54,10 +54,14 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
synchronizeConfigurationSelection(); synchronizeConfigurationSelection();
} }
public void fireTableDataChanged() { /**
* Update the data in the table, with component change event type {cce}
* @param cce index of the ComponentChangeEvent to use (e.g. ComponentChangeEvent.NONFUNCTIONAL_CHANGE)
*/
public void fireTableDataChanged(int cce) {
int selectedRow = table.getSelectedRow(); int selectedRow = table.getSelectedRow();
int selectedColumn = table.getSelectedColumn(); int selectedColumn = table.getSelectedColumn();
this.rocket.fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); this.rocket.fireComponentChangeEvent(cce);
((AbstractTableModel)table.getModel()).fireTableDataChanged(); ((AbstractTableModel)table.getModel()).fireTableDataChanged();
restoreSelection(selectedRow,selectedColumn); restoreSelection(selectedRow,selectedColumn);
updateButtonState(); updateButtonState();

View File

@ -15,6 +15,7 @@ import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.gui.dialogs.flightconfiguration.RenameConfigDialog; import net.sf.openrocket.gui.dialogs.flightconfiguration.RenameConfigDialog;
import net.sf.openrocket.gui.main.BasicFrame; import net.sf.openrocket.gui.main.BasicFrame;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent; import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
@ -79,7 +80,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
int lastCol = motorConfigurationPanel.table.getColumnCount() - 1; int lastCol = motorConfigurationPanel.table.getColumnCount() - 1;
motorConfigurationPanel.table.setRowSelectionInterval(lastRow, lastRow); motorConfigurationPanel.table.setRowSelectionInterval(lastRow, lastRow);
motorConfigurationPanel.table.setColumnSelectionInterval(lastCol, lastCol); motorConfigurationPanel.table.setColumnSelectionInterval(lastCol, lastCol);
configurationChanged(); configurationChanged(ComponentChangeEvent.MOTOR_CHANGE);
} }
}); });
@ -91,7 +92,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
renameConfiguration(); renameConfiguration();
configurationChanged(); configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
} }
}); });
this.add(renameConfButton,"gapright para"); this.add(renameConfButton,"gapright para");
@ -101,7 +102,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
removeConfiguration(); removeConfiguration();
configurationChanged(); configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
} }
}); });
this.add(removeConfButton,"gapright para"); this.add(removeConfButton,"gapright para");
@ -111,7 +112,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
addOrCopyConfiguration(true); addOrCopyConfiguration(true);
configurationChanged(); configurationChanged(ComponentChangeEvent.MOTOR_CHANGE);
} }
}); });
this.add(copyConfButton, "wrap"); this.add(copyConfButton, "wrap");
@ -172,13 +173,13 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
if (currentId == null) if (currentId == null)
return; return;
document.removeFlightConfigurationAndSimulations(currentId); document.removeFlightConfigurationAndSimulations(currentId);
configurationChanged(); configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
} }
private void configurationChanged() { private void configurationChanged(int cce) {
motorConfigurationPanel.fireTableDataChanged(); motorConfigurationPanel.fireTableDataChanged(cce);
recoveryConfigurationPanel.fireTableDataChanged(); recoveryConfigurationPanel.fireTableDataChanged(cce);
separationConfigurationPanel.fireTableDataChanged(); separationConfigurationPanel.fireTableDataChanged(cce);
} }
private void updateButtonState() { private void updateButtonState() {

View File

@ -29,10 +29,12 @@ import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.motor.IgnitionEvent; import net.sf.openrocket.motor.IgnitionEvent;
import net.sf.openrocket.motor.Motor; import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.MotorConfiguration; import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration; import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount; import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup; import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Chars; import net.sf.openrocket.util.Chars;
@ -207,14 +209,17 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
Motor mtr = motorChooserDialog.getSelectedMotor(); Motor mtr = motorChooserDialog.getSelectedMotor();
double d = motorChooserDialog.getSelectedDelay(); double d = motorChooserDialog.getSelectedDelay();
if (mtr != null) { if (mtr != null) {
if (mtr == curMount.getMotorConfig(fcid).getMotor()) {
return;
}
final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid); final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid);
final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig); final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig);
newConfig.setMotor(mtr); newConfig.setMotor(mtr);
newConfig.setEjectionDelay(d); newConfig.setEjectionDelay(d);
curMount.setMotorConfig( newConfig, fcid); curMount.setMotorConfig( newConfig, fcid);
}
fireTableDataChanged(); fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
}
} }
private void removeMotor() { private void removeMotor() {
@ -226,16 +231,20 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
curMount.setMotorConfig( null, fcid); curMount.setMotorConfig( null, fcid);
fireTableDataChanged(); fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
} }
private void selectIgnition() { private void selectIgnition() {
MotorMount curMount = getSelectedComponent(); MotorMount curMount = getSelectedComponent();
FlightConfigurationId fcid= getSelectedConfigurationId(); FlightConfigurationId fcid = getSelectedConfigurationId();
if ( (null == fcid )||( null == curMount )){ if ((null == fcid) || (null == curMount)) {
return; return;
} }
MotorConfiguration curInstance = curMount.getMotorConfig(fcid);
IgnitionEvent initialIgnitionEvent = curInstance.getIgnitionEvent();
double initialIgnitionDelay = curInstance.getIgnitionDelay();
// this call also performs the update changes // this call also performs the update changes
IgnitionSelectionDialog ignitionDialog = new IgnitionSelectionDialog( IgnitionSelectionDialog ignitionDialog = new IgnitionSelectionDialog(
SwingUtilities.getWindowAncestor(this.flightConfigurationPanel), SwingUtilities.getWindowAncestor(this.flightConfigurationPanel),
@ -243,7 +252,9 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
curMount); curMount);
ignitionDialog.setVisible(true); ignitionDialog.setVisible(true);
fireTableDataChanged(); if (!initialIgnitionEvent.equals(curInstance.getIgnitionEvent()) || (initialIgnitionDelay != curInstance.getIgnitionDelay())) {
fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
}
} }
@ -254,10 +265,14 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
return; return;
} }
MotorConfiguration curInstance = curMount.getMotorConfig(fcid); MotorConfiguration curInstance = curMount.getMotorConfig(fcid);
IgnitionEvent initialIgnitionEvent = curInstance.getIgnitionEvent();
double initialIgnitionDelay = curInstance.getIgnitionDelay();
curInstance.useDefaultIgnition(); curInstance.useDefaultIgnition();
fireTableDataChanged(); if (!initialIgnitionEvent.equals(curInstance.getIgnitionEvent()) || (initialIgnitionDelay != curInstance.getIgnitionDelay())) {
fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
}
} }

View File

@ -99,22 +99,31 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
private void selectDeployment() { private void selectDeployment() {
RecoveryDevice c = getSelectedComponent(); RecoveryDevice c = getSelectedComponent();
if (c == null) { FlightConfigurationId fcid = getSelectedConfigurationId();
if ((c == null) || (fcid == null)) {
return; return;
} }
DeploymentConfiguration initialConfig = c.getDeploymentConfigurations().get(fcid).copy(fcid);
JDialog d = new DeploymentSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, c); JDialog d = new DeploymentSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, c);
d.setVisible(true); d.setVisible(true);
fireTableDataChanged(); if (!initialConfig.equals(c.getDeploymentConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AERODYNAMIC_CHANGE);
}
} }
private void resetDeployment() { private void resetDeployment() {
RecoveryDevice c = getSelectedComponent(); RecoveryDevice c = getSelectedComponent();
if (c == null) { FlightConfigurationId fcid = getSelectedConfigurationId();
if ((c == null) || (fcid == null)) {
return; return;
} }
DeploymentConfiguration initialConfig = c.getDeploymentConfigurations().get(fcid).copy(fcid);
FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID(); FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
c.getDeploymentConfigurations().reset(id); c.getDeploymentConfigurations().reset(id);
fireTableDataChanged(); if (!initialConfig.equals(c.getDeploymentConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AERODYNAMIC_CHANGE);
}
} }
public void updateButtonState() { public void updateButtonState() {

View File

@ -17,6 +17,7 @@ import net.sf.openrocket.formatting.RocketDescriptor;
import net.sf.openrocket.gui.dialogs.flightconfiguration.SeparationSelectionDialog; import net.sf.openrocket.gui.dialogs.flightconfiguration.SeparationSelectionDialog;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage; import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId; import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.Rocket; import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration; import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
@ -46,7 +47,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
selectSeparationButton.addActionListener(new ActionListener() { selectSeparationButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
selectDeployment(); selectSeparation();
} }
}); });
this.add(selectSeparationButton, "split, align right, sizegroup button"); this.add(selectSeparationButton, "split, align right, sizegroup button");
@ -57,7 +58,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
resetDeploymentButton.addActionListener(new ActionListener() { resetDeploymentButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
resetDeployment(); resetSeparation();
} }
}); });
this.add(resetDeploymentButton, "sizegroup button, wrap"); this.add(resetDeploymentButton, "sizegroup button, wrap");
@ -86,7 +87,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
updateButtonState(); updateButtonState();
if (e.getClickCount() == 2) { if (e.getClickCount() == 2) {
// Double-click edits // Double-click edits
selectDeployment(); selectSeparation();
} }
} }
}); });
@ -95,27 +96,35 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
return separationTable; return separationTable;
} }
private void selectDeployment() { private void selectSeparation() {
AxialStage stage = getSelectedComponent(); AxialStage stage = getSelectedComponent();
if (stage == null) { FlightConfigurationId fcid = getSelectedConfigurationId();
if ((stage == null) || (fcid == null)) {
return; return;
} }
StageSeparationConfiguration initialConfig = stage.getSeparationConfigurations().get(fcid).copy(fcid);
JDialog d = new SeparationSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, stage); JDialog d = new SeparationSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, stage);
d.setVisible(true); d.setVisible(true);
fireTableDataChanged(); if (!initialConfig.equals(stage.getSeparationConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AEROMASS_CHANGE);
}
} }
private void resetDeployment() { private void resetSeparation() {
AxialStage stage = getSelectedComponent(); AxialStage stage = getSelectedComponent();
if (stage == null) { FlightConfigurationId fcid = getSelectedConfigurationId();
if ((stage == null) || (fcid == null)) {
return; return;
} }
StageSeparationConfiguration initialConfig = stage.getSeparationConfigurations().get(fcid).copy(fcid);
// why? // why?
FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID(); FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
stage.getSeparationConfigurations().reset(id); stage.getSeparationConfigurations().reset(id);
fireTableDataChanged(); if (!initialConfig.equals(stage.getSeparationConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AEROMASS_CHANGE);
}
} }
public void updateButtonState() { public void updateButtonState() {
boolean componentSelected = getSelectedComponent() != null; boolean componentSelected = getSelectedComponent() != null;