[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.Pair;
import java.util.Objects;
public class DeploymentConfiguration implements FlightConfigurableParameter<DeploymentConfiguration> {
@ -154,5 +156,17 @@ public class DeploymentConfiguration implements FlightConfigurableParameter<Depl
@Override
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.util.MathUtil;
import java.util.Objects;
public class StageSeparationConfiguration implements FlightConfigurableParameter<StageSeparationConfiguration> {
public static enum SeparationEvent {
@ -144,8 +146,20 @@ public class StageSeparationConfiguration implements FlightConfigurableParameter
clone.separationDelay = this.separationDelay;
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() {
}

View File

@ -54,10 +54,14 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
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 selectedColumn = table.getSelectedColumn();
this.rocket.fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
this.rocket.fireComponentChangeEvent(cce);
((AbstractTableModel)table.getModel()).fireTableDataChanged();
restoreSelection(selectedRow,selectedColumn);
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.main.BasicFrame;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfigurableComponent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
@ -79,7 +80,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
int lastCol = motorConfigurationPanel.table.getColumnCount() - 1;
motorConfigurationPanel.table.setRowSelectionInterval(lastRow, lastRow);
motorConfigurationPanel.table.setColumnSelectionInterval(lastCol, lastCol);
configurationChanged();
configurationChanged(ComponentChangeEvent.MOTOR_CHANGE);
}
});
@ -91,7 +92,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
@Override
public void actionPerformed(ActionEvent e) {
renameConfiguration();
configurationChanged();
configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
});
this.add(renameConfButton,"gapright para");
@ -101,7 +102,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
@Override
public void actionPerformed(ActionEvent e) {
removeConfiguration();
configurationChanged();
configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
});
this.add(removeConfButton,"gapright para");
@ -111,7 +112,7 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
@Override
public void actionPerformed(ActionEvent e) {
addOrCopyConfiguration(true);
configurationChanged();
configurationChanged(ComponentChangeEvent.MOTOR_CHANGE);
}
});
this.add(copyConfButton, "wrap");
@ -172,13 +173,13 @@ public class FlightConfigurationPanel extends JPanel implements StateChangeListe
if (currentId == null)
return;
document.removeFlightConfigurationAndSimulations(currentId);
configurationChanged();
configurationChanged(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
private void configurationChanged() {
motorConfigurationPanel.fireTableDataChanged();
recoveryConfigurationPanel.fireTableDataChanged();
separationConfigurationPanel.fireTableDataChanged();
private void configurationChanged(int cce) {
motorConfigurationPanel.fireTableDataChanged(cce);
recoveryConfigurationPanel.fireTableDataChanged(cce);
separationConfigurationPanel.fireTableDataChanged(cce);
}
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.Motor;
import net.sf.openrocket.motor.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfiguration;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.startup.Application;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Chars;
@ -207,14 +209,17 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
Motor mtr = motorChooserDialog.getSelectedMotor();
double d = motorChooserDialog.getSelectedDelay();
if (mtr != null) {
if (mtr == curMount.getMotorConfig(fcid).getMotor()) {
return;
}
final MotorConfiguration templateConfig = curMount.getMotorConfig(fcid);
final MotorConfiguration newConfig = new MotorConfiguration( curMount, fcid, templateConfig);
newConfig.setMotor(mtr);
newConfig.setEjectionDelay(d);
curMount.setMotorConfig( newConfig, fcid);
}
fireTableDataChanged();
fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
}
}
private void removeMotor() {
@ -226,24 +231,30 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
curMount.setMotorConfig( null, fcid);
fireTableDataChanged();
fireTableDataChanged(ComponentChangeEvent.MOTOR_CHANGE);
}
private void selectIgnition() {
MotorMount curMount = getSelectedComponent();
FlightConfigurationId fcid= getSelectedConfigurationId();
if ( (null == fcid )||( null == curMount )){
return;
}
MotorMount curMount = getSelectedComponent();
FlightConfigurationId fcid = getSelectedConfigurationId();
if ((null == fcid) || (null == curMount)) {
return;
}
MotorConfiguration curInstance = curMount.getMotorConfig(fcid);
IgnitionEvent initialIgnitionEvent = curInstance.getIgnitionEvent();
double initialIgnitionDelay = curInstance.getIgnitionDelay();
// this call also performs the update changes
IgnitionSelectionDialog ignitionDialog = new IgnitionSelectionDialog(
SwingUtilities.getWindowAncestor(this.flightConfigurationPanel),
fcid,
curMount);
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;
}
MotorConfiguration curInstance = curMount.getMotorConfig(fcid);
IgnitionEvent initialIgnitionEvent = curInstance.getIgnitionEvent();
double initialIgnitionDelay = curInstance.getIgnitionDelay();
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() {
RecoveryDevice c = getSelectedComponent();
if (c == null) {
FlightConfigurationId fcid = getSelectedConfigurationId();
if ((c == null) || (fcid == null)) {
return;
}
DeploymentConfiguration initialConfig = c.getDeploymentConfigurations().get(fcid).copy(fcid);
JDialog d = new DeploymentSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, c);
d.setVisible(true);
fireTableDataChanged();
if (!initialConfig.equals(c.getDeploymentConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AERODYNAMIC_CHANGE);
}
}
private void resetDeployment() {
RecoveryDevice c = getSelectedComponent();
if (c == null) {
FlightConfigurationId fcid = getSelectedConfigurationId();
if ((c == null) || (fcid == null)) {
return;
}
DeploymentConfiguration initialConfig = c.getDeploymentConfigurations().get(fcid).copy(fcid);
FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
c.getDeploymentConfigurations().reset(id);
fireTableDataChanged();
if (!initialConfig.equals(c.getDeploymentConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AERODYNAMIC_CHANGE);
}
}
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.l10n.Translator;
import net.sf.openrocket.rocketcomponent.AxialStage;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FlightConfigurationId;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.StageSeparationConfiguration;
@ -46,7 +47,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
selectSeparationButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selectDeployment();
selectSeparation();
}
});
this.add(selectSeparationButton, "split, align right, sizegroup button");
@ -57,7 +58,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
resetDeploymentButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
resetDeployment();
resetSeparation();
}
});
this.add(resetDeploymentButton, "sizegroup button, wrap");
@ -86,7 +87,7 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
updateButtonState();
if (e.getClickCount() == 2) {
// Double-click edits
selectDeployment();
selectSeparation();
}
}
});
@ -95,27 +96,35 @@ public class SeparationConfigurationPanel extends FlightConfigurablePanel<AxialS
return separationTable;
}
private void selectDeployment() {
private void selectSeparation() {
AxialStage stage = getSelectedComponent();
if (stage == null) {
FlightConfigurationId fcid = getSelectedConfigurationId();
if ((stage == null) || (fcid == null)) {
return;
}
StageSeparationConfiguration initialConfig = stage.getSeparationConfigurations().get(fcid).copy(fcid);
JDialog d = new SeparationSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, stage);
d.setVisible(true);
fireTableDataChanged();
if (!initialConfig.equals(stage.getSeparationConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AEROMASS_CHANGE);
}
}
private void resetDeployment() {
private void resetSeparation() {
AxialStage stage = getSelectedComponent();
if (stage == null) {
FlightConfigurationId fcid = getSelectedConfigurationId();
if ((stage == null) || (fcid == null)) {
return;
}
StageSeparationConfiguration initialConfig = stage.getSeparationConfigurations().get(fcid).copy(fcid);
// why?
FlightConfigurationId id = rocket.getSelectedConfiguration().getFlightConfigurationID();
stage.getSeparationConfigurations().reset(id);
fireTableDataChanged();
if (!initialConfig.equals(stage.getSeparationConfigurations().get(fcid))) {
fireTableDataChanged(ComponentChangeEvent.AEROMASS_CHANGE);
}
}
public void updateButtonState() {
boolean componentSelected = getSelectedComponent() != null;