Fix multi-comp deployment editing

This commit is contained in:
SiboVG 2023-08-26 23:20:30 +01:00
parent c026441a47
commit 1ed7354337
4 changed files with 36 additions and 11 deletions

View File

@ -30,8 +30,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
private FlightConfigurableParameterSet<DeploymentConfiguration> deploymentConfigurations; private FlightConfigurableParameterSet<DeploymentConfiguration> deploymentConfigurations;
public RecoveryDevice() { public RecoveryDevice() {
this.deploymentConfigurations = this.deploymentConfigurations = new FlightConfigurableParameterSet<>( new DeploymentConfiguration());
new FlightConfigurableParameterSet<DeploymentConfiguration>( new DeploymentConfiguration());
defaultMaterial = (Material.Surface) Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE); defaultMaterial = (Material.Surface) Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE);
setMaterial(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE)); setMaterial(Application.getPreferences().getDefaultComponentMaterial(RecoveryDevice.class, Material.Type.SURFACE));
} }
@ -148,7 +147,7 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu
@Override @Override
protected RocketComponent copyWithOriginalID() { protected RocketComponent copyWithOriginalID() {
RecoveryDevice copy = (RecoveryDevice) super.copyWithOriginalID(); RecoveryDevice copy = (RecoveryDevice) super.copyWithOriginalID();
copy.deploymentConfigurations = new FlightConfigurableParameterSet<DeploymentConfiguration>(deploymentConfigurations); copy.deploymentConfigurations = new FlightConfigurableParameterSet<>(deploymentConfigurations);
return copy; return copy;
} }

View File

@ -4,6 +4,7 @@ import java.awt.Dialog;
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.ItemEvent;
import javax.swing.ButtonGroup; import javax.swing.ButtonGroup;
import javax.swing.JButton; import javax.swing.JButton;
@ -47,6 +48,8 @@ public class DeploymentSelectionDialog extends JDialog {
private final UnitSelector altUnit; private final UnitSelector altUnit;
private final JSlider altSlider; private final JSlider altSlider;
private boolean isOverrideDefault;
public DeploymentSelectionDialog(Window parent, final Rocket rocket, final FlightConfigurationId id, final RecoveryDevice component) { public DeploymentSelectionDialog(Window parent, final Rocket rocket, final FlightConfigurationId id, final RecoveryDevice component) {
super(parent, trans.get("edtmotorconfdlg.title.Selectdeploymentconf"), Dialog.ModalityType.APPLICATION_MODAL); super(parent, trans.get("edtmotorconfdlg.title.Selectdeploymentconf"), Dialog.ModalityType.APPLICATION_MODAL);
@ -59,7 +62,9 @@ public class DeploymentSelectionDialog extends JDialog {
panel.add(defaultButton, "span, gapleft para, wrap rel"); panel.add(defaultButton, "span, gapleft para, wrap rel");
String str = trans.get("DeploymentSelectionDialog.opt.override"); String str = trans.get("DeploymentSelectionDialog.opt.override");
str = str.replace("{0}", descriptor.format(rocket, id)); str = str.replace("{0}", descriptor.format(rocket, id));
final JRadioButton overrideButton = new JRadioButton(str, false); final JRadioButton overrideButton = new JRadioButton(str);
overrideButton.addItemListener(e -> isOverrideDefault = e.getStateChange() == ItemEvent.SELECTED);
overrideButton.setSelected(false);
panel.add(overrideButton, "span, gapleft para, wrap para"); panel.add(overrideButton, "span, gapleft para, wrap para");
ButtonGroup buttonGroup = new ButtonGroup(); ButtonGroup buttonGroup = new ButtonGroup();
@ -157,5 +162,11 @@ public class DeploymentSelectionDialog extends JDialog {
altSlider.setEnabled(enabled); altSlider.setEnabled(enabled);
} }
/**
* Returns true if this dialog was used to override the default configuration.
* @return true if this dialog was used to override the default configuration.
*/
public boolean isOverrideDefault() {
return isOverrideDefault;
}
} }

View File

@ -253,7 +253,10 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
if (tableValue instanceof Pair) { if (tableValue instanceof Pair) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Pair<String, T> selectedComponent = (Pair<String, T>) tableValue; Pair<String, T> selectedComponent = (Pair<String, T>) tableValue;
components.add(selectedComponent.getV()); T comp = selectedComponent.getV();
if (!components.contains(comp)) {
components.add(comp);
}
} }
} }
} }
@ -292,13 +295,19 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Pair<FlightConfigurationId, T> selectedComponent = (Pair<FlightConfigurationId, T>) tableValue; Pair<FlightConfigurationId, T> selectedComponent = (Pair<FlightConfigurationId, T>) tableValue;
FlightConfigurationId fcid = selectedComponent.getU(); FlightConfigurationId fcid = selectedComponent.getU();
if (!Ids.contains(fcid)) {
Ids.add(fcid); Ids.add(fcid);
}
} else if (tableValue instanceof FlightConfigurationId) { } else if (tableValue instanceof FlightConfigurationId) {
if (!Ids.contains(tableValue)) {
Ids.add((FlightConfigurationId) tableValue); Ids.add((FlightConfigurationId) tableValue);
}
} else { } else {
if (!Ids.contains(FlightConfigurationId.ERROR_FCID)) {
Ids.add(FlightConfigurationId.ERROR_FCID); Ids.add(FlightConfigurationId.ERROR_FCID);
} }
} }
}
return Ids; return Ids;
} }

View File

@ -181,7 +181,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
document.addUndoPosition("Select deployment"); document.addUndoPosition("Select deployment");
// Open the configuration dialog // Open the configuration dialog
JDialog d = new DeploymentSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, initFcId, initDevice); DeploymentSelectionDialog d = new DeploymentSelectionDialog(SwingUtilities.getWindowAncestor(this), rocket, initFcId, initDevice);
d.setVisible(true); d.setVisible(true);
final DeploymentConfiguration modifiedConfig = initDevice.getDeploymentConfigurations().get(initFcId); final DeploymentConfiguration modifiedConfig = initDevice.getDeploymentConfigurations().get(initFcId);
@ -190,6 +190,7 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
double deployDelay = modifiedConfig.getDeployDelay(); double deployDelay = modifiedConfig.getDeployDelay();
double deployAltitude = modifiedConfig.getDeployAltitude(); double deployAltitude = modifiedConfig.getDeployAltitude();
DeployEvent deployEvent = modifiedConfig.getDeployEvent(); DeployEvent deployEvent = modifiedConfig.getDeployEvent();
boolean isOverrideDefault = d.isOverrideDefault();
for (RecoveryDevice device : devices) { for (RecoveryDevice device : devices) {
for (FlightConfigurationId fcId : fcIds) { for (FlightConfigurationId fcId : fcIds) {
@ -197,6 +198,11 @@ public class RecoveryConfigurationPanel extends FlightConfigurablePanel<Recovery
if ((device == initDevice) && (fcId == initFcId)) if ((device == initDevice) && (fcId == initFcId))
continue; continue;
// It could be that the current config is the default config, but the user has selected to override it.
if (isOverrideDefault && !device.getDeploymentConfigurations().containsId(fcId)) {
device.getDeploymentConfigurations().set(fcId, device.getDeploymentConfigurations().getDefault().clone());
}
DeploymentConfiguration currentConfig = device.getDeploymentConfigurations().get(fcId); DeploymentConfiguration currentConfig = device.getDeploymentConfigurations().get(fcId);
if (currentConfig.equals(modifiedConfig)) { if (currentConfig.equals(modifiedConfig)) {