From 993cd3169aa796169bb61de405ac951312981be8 Mon Sep 17 00:00:00 2001 From: SiboVG Date: Mon, 16 Jan 2023 03:25:36 +0100 Subject: [PATCH] Fix sims going out-of-date on stage activeness change --- .../sf/openrocket/rocketcomponent/Rocket.java | 16 ++++++++++++++-- .../openrocket/gui/components/StageSelector.java | 6 ++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java index 63c8f6314..9422f0ba5 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/Rocket.java +++ b/core/src/net/sf/openrocket/rocketcomponent/Rocket.java @@ -476,11 +476,23 @@ public class Rocket extends ComponentAssembly { * @param ids IDs of the flight configurations to update, or null to update all. * @see #fireComponentChangeEvent(ComponentChangeEvent) */ - public void fireComponentChangeEvent(int type, FlightConfigurationId[] ids) { + public void fireComponentChangeEvent(int type, final FlightConfigurationId[] ids) { fireComponentChangeEvent(new ComponentChangeEvent(this, type), ids); } - protected void fireComponentChangeEvent(ComponentChangeEvent cce, FlightConfigurationId[] ids) { + /** + * Fires a ComponentChangeEvent of the given type. The source of the event is set to + * this rocket. + * + * @param type Type of event + * @param id ID of the flight configurations to update, or null to update all. + * @see #fireComponentChangeEvent(ComponentChangeEvent) + */ + public void fireComponentChangeEvent(int type, FlightConfigurationId id) { + fireComponentChangeEvent(type, new FlightConfigurationId[]{ id }); + } + + protected void fireComponentChangeEvent(ComponentChangeEvent cce, final FlightConfigurationId[] ids) { if (!this.eventsEnabled) { return; } diff --git a/swing/src/net/sf/openrocket/gui/components/StageSelector.java b/swing/src/net/sf/openrocket/gui/components/StageSelector.java index f0e9ce289..1609c16d9 100644 --- a/swing/src/net/sf/openrocket/gui/components/StageSelector.java +++ b/swing/src/net/sf/openrocket/gui/components/StageSelector.java @@ -96,8 +96,10 @@ public class StageSelector extends JPanel implements StateChangeListener { setEnabled(true); putValue(SHORT_DESCRIPTION, trans.get("RocketPanel.btn.Stages.Toggle.ttip")); } - rocket.getSelectedConfiguration().toggleStage(stage.getStageNumber()); - rocket.fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE | ComponentChangeEvent.MOTOR_CHANGE ); + FlightConfiguration config = rocket.getSelectedConfiguration(); + config.toggleStage(stage.getStageNumber()); + rocket.fireComponentChangeEvent(ComponentChangeEvent.AEROMASS_CHANGE | ComponentChangeEvent.MOTOR_CHANGE, + config.getFlightConfigurationID()); } }