Allow SelectionSubscriber to start/stop outside initialisation phase

This commit is contained in:
Ralph Wessel
2024-10-16 10:31:11 +01:00
parent 2d23eb6b28
commit 3e7b78e50d
2 changed files with 17 additions and 10 deletions
@@ -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
}
@@ -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;
};
}