Files
speckle-cpp-connectors/SpeckleLib/Speckle/Event/Subscriber/SelectionSubscriber.cpp
T
2024-11-13 15:05:22 +00:00

93 lines
3.0 KiB
C++

#include "Speckle/Event/Subscriber/SelectionSubscriber.h"
#include "Speckle/Environment/Addon.h"
#include "Speckle/Database/Identity/BIMLink.h"
#include "Speckle/Database/Storage/ArchicadDBase/Element/ArchicadElementDBaseEngine.h"
#include "Speckle/Event/Type/SelectionEvent.h"
#ifdef ARCHICAD
#include <ACAPinc.h>
#endif
using namespace active::environment;
using namespace active::event;
using namespace speckle::database;
using namespace speckle::environment;
using namespace speckle::event;
namespace {
#ifdef ARCHICAD
/*!
Callback for an Archicad selection change
@param params Info about the last selected element
*/
GSErrCode __ACENV_CALL selectionCallback(const API_Neig* params) {
if (addon() != nullptr) {
if (auto tableID = ArchicadElementDBaseEngine::getActiveTable(); tableID) {
auto selection = (params == nullptr) ? BIMLink{} : BIMLink{*params, *tableID};
addon()->publishExternal(SelectionEvent{selection});
}
}
return NoError;
}
#endif
}
/*--------------------------------------------------------------------
Get the event subscription list
return: The subscription list (an empty list will put the subscriber into a suspended state)
--------------------------------------------------------------------*/
Subscriber::Subscription SelectionSubscriber::subscription() const {
return { {SelectionEvent::ID} };
} //SelectionSubscriber::subscription
/*--------------------------------------------------------------------
Receive a subscribed event
event: The incoming event
return: True if the event should be closed
--------------------------------------------------------------------*/
bool SelectionSubscriber::receive(const Event& event) {
//Pass a menu event to the specified handler function
if (auto selectEvent = dynamic_cast<const SelectionEvent*>(&event); selectEvent != nullptr)
return handle(*selectEvent);
return false;
} //SelectionSubscriber::receive
/*--------------------------------------------------------------------
Start the participant operation
return: True if the participant is able to continue
--------------------------------------------------------------------*/
bool SelectionSubscriber::start() {
#ifdef ARCHICAD
#ifdef ServerMainVers_2700
return (ACAPI_Notification_CatchSelectionChange(selectionCallback) == NoError);
#else
return (ACAPI_Notify_CatchSelectionChange(selectionCallback) == NoError);
#endif //ServerMainVers_2600
#else //ARCHICAD
return false;
#endif //ARCHICAD
} //SelectionSubscriber::start
/*--------------------------------------------------------------------
Stop participation (release resources etc)
--------------------------------------------------------------------*/
void SelectionSubscriber::stop() {
#ifdef ARCHICAD
#ifdef ServerMainVers_2700
ACAPI_Notification_CatchSelectionChange(nullptr);
#else
ACAPI_Notify_CatchSelectionChange(nullptr);
#endif //ServerMainVers_2600
#endif //ARCHICAD
} //SelectionSubscriber::stop