From 3e7b78e50db23dc39f8ec6a22377a1e2c0310253 Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Wed, 16 Oct 2024 10:31:11 +0100 Subject: [PATCH] Allow SelectionSubscriber to start/stop outside initialisation phase --- .../Event/Subscriber/SelectionSubscriber.cpp | 13 ++++++++++--- .../Speckle/Event/Subscriber/SelectionSubscriber.h | 14 +++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.cpp b/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.cpp index 48b5f04..a428000 100644 --- a/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.cpp +++ b/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.cpp @@ -69,12 +69,19 @@ bool SelectionSubscriber::receive(const Event& event) { return: True if the participant is able to continue --------------------------------------------------------------------*/ bool SelectionSubscriber::start() { - if (m_isStarted) - return true; - m_isStarted = true; #ifdef ARCHICAD return (ACAPI_Notification_CatchSelectionChange(selectionCallback) == NoError); #else return false; #endif } //SelectionSubscriber::start + + +/*-------------------------------------------------------------------- + Stop participation (release resources etc) + --------------------------------------------------------------------*/ +void SelectionSubscriber::stop() { +#ifdef ARCHICAD + ACAPI_Notification_CatchSelectionChange(nullptr); +#endif +} diff --git a/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.h b/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.h index 6ed904b..b4a7e64 100644 --- a/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.h +++ b/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.h @@ -35,7 +35,7 @@ namespace speckle::event { Get the event subscription list @return The subscription list (an empty list will put the subscriber into a suspended state) */ - virtual Subscription subscription() const override; + Subscription subscription() const override; // MARK: - Functions (mutating) @@ -44,24 +44,24 @@ namespace speckle::event { @param event The incoming event @return True if the event should be closed */ - virtual bool receive(const active::event::Event& event) override; + bool receive(const active::event::Event& event) override; protected: /*! Start the participant operation @return True if the participant is able to continue */ - virtual bool start() override; + bool start() override; + /*! + Stop participation (release resources etc) + */ + void stop() override; /*! Handle a selection change @param event The selection event @return True if the event should be closed */ virtual bool handle(const SelectionEvent& event) = 0; - - private: - ///True if a selection change subscriber has already started (only one is required - there are no variants) - static bool m_isStarted; }; }