From 9a77baf643dac3bb80dd8dac9d7ff674bb154f5e Mon Sep 17 00:00:00 2001 From: SiboVG Date: Fri, 18 Feb 2022 18:36:55 +0100 Subject: [PATCH] [fixes #358] Fix multi-component recovery device deployment --- .../DeploymentConfiguration.java | 41 +++++++++++++++++++ .../rocketcomponent/RecoveryDevice.java | 29 +++++++++++++ 2 files changed, 70 insertions(+) diff --git a/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java index f30885a60..3a21493f4 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/DeploymentConfiguration.java @@ -5,9 +5,11 @@ import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.simulation.FlightEvent; import net.sf.openrocket.startup.Application; import net.sf.openrocket.unit.UnitGroup; +import net.sf.openrocket.util.ArrayList; import net.sf.openrocket.util.MathUtil; import net.sf.openrocket.util.Pair; +import java.util.List; import java.util.Objects; public class DeploymentConfiguration implements FlightConfigurableParameter { @@ -87,6 +89,8 @@ public class DeploymentConfiguration implements FlightConfigurableParameter configListeners = new ArrayList<>(); public boolean isActivationEvent(FlightEvent e, RocketComponent source) { return deployEvent.isActivationEvent(this, e, source); @@ -97,6 +101,10 @@ public class DeploymentConfiguration implements FlightConfigurableParameter getConfigListeners() { + return configListeners; + } } \ No newline at end of file diff --git a/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java b/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java index a2785c551..0d4562fb2 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RecoveryDevice.java @@ -138,4 +138,33 @@ public abstract class RecoveryDevice extends MassObject implements FlightConfigu copy.deploymentConfigurations = new FlightConfigurableParameterSet(deploymentConfigurations); return copy; } + + @Override + public boolean addConfigListener(RocketComponent listener) { + boolean success = super.addConfigListener(listener); + if (listener instanceof RecoveryDevice) { + DeploymentConfiguration thisConfig = getDeploymentConfigurations().getDefault(); + DeploymentConfiguration listenerConfig = ((RecoveryDevice) listener).getDeploymentConfigurations().getDefault(); + success = success && thisConfig.addConfigListener(listenerConfig); + return success; + } + return false; + } + + @Override + public void removeConfigListener(RocketComponent listener) { + super.removeConfigListener(listener); + if (listener instanceof RecoveryDevice) { + DeploymentConfiguration thisConfig = getDeploymentConfigurations().getDefault(); + DeploymentConfiguration listenerConfig = ((RecoveryDevice) listener).getDeploymentConfigurations().getDefault(); + thisConfig.removeConfigListener(listenerConfig); + } + } + + @Override + public void clearConfigListeners() { + super.clearConfigListeners(); + DeploymentConfiguration thisConfig = getDeploymentConfigurations().getDefault(); + thisConfig.clearConfigListeners(); + } }