diff --git a/SpeckleConnector/Connector.vcxproj b/SpeckleConnector/Connector.vcxproj index 9ac1fc7..acf33d4 100644 --- a/SpeckleConnector/Connector.vcxproj +++ b/SpeckleConnector/Connector.vcxproj @@ -111,6 +111,9 @@ + + + @@ -163,6 +166,9 @@ + + + diff --git a/SpeckleConnector/Connector.vcxproj.filters b/SpeckleConnector/Connector.vcxproj.filters index e879d95..374c759 100644 --- a/SpeckleConnector/Connector.vcxproj.filters +++ b/SpeckleConnector/Connector.vcxproj.filters @@ -65,6 +65,12 @@ {6693f9a9-5ece-4853-b008-4064d1c551ab} + + {806f4af5-fa02-49b8-ac01-297991fe90ea} + + + {8bb3df60-affe-4b66-8d78-f1b98e6ba8df} + @@ -228,6 +234,15 @@ Connector\Record\Collection + + Connector\Interface\Browser\Bridge\Selection + + + Connector\Interface\Browser\Bridge\Selection + + + Connector\Interface\Browser\Bridge\Selection\Arg + @@ -387,5 +402,14 @@ Connector\Record\Collection + + Connector\Interface\Browser\Bridge\Selection + + + Connector\Interface\Browser\Bridge\Selection + + + Connector\Interface\Browser\Bridge\Selection\Arg + \ No newline at end of file diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.cpp new file mode 100644 index 0000000..42611d6 --- /dev/null +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.cpp @@ -0,0 +1,60 @@ +#include "Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.h" + +#include "Active/Serialise/Item/Wrapper/ValueWrap.h" +#include "Active/Serialise/Package/Wrapper/PackageWrap.h" + +#include + +using namespace active::serialise; +using namespace connector::interfac::browser::bridge; + +namespace { + + ///Serialisation fields + enum FieldIndex { + summaryID, + }; + + ///Serialisation field IDs + static std::array fieldID = { + Identity{"summary"}, + }; + +} + +/*-------------------------------------------------------------------- + Fill an inventory with the package items + + inventory: The inventory to receive the package items + + return: True if the package has added items to the inventory + --------------------------------------------------------------------*/ +bool SelectionInfo::fillInventory(Inventory& inventory) const { + using enum Entry::Type; + inventory.merge(Inventory{ + { + { fieldID[summaryID], summaryID, element }, + }, + }.withType(&typeid(SelectionInfo))); + return true; +} //ConnectorConfig::fillInventory + + +/*-------------------------------------------------------------------- + Get the specified cargo + + item: The inventory item to retrieve + + return: The requested cargo (nullptr on failure) + --------------------------------------------------------------------*/ +Cargo::Unique SelectionInfo::getCargo(const Inventory::Item& item) const { + if (item.ownerType != &typeid(SelectionInfo)) + return nullptr; + using namespace active::serialise; + switch (item.index) { + case summaryID: + return std::make_unique>(summary); + default: + return nullptr; //Requested an unknown index + } +} //ConnectorConfig::getCargo diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.h b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.h new file mode 100644 index 0000000..2e81bea --- /dev/null +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.h @@ -0,0 +1,47 @@ +#ifndef CONNECTOR_INTERFACE_BRIDGE_SELECTION_INFO +#define CONNECTOR_INTERFACE_BRIDGE_SELECTION_INFO + +#include "Active/Serialise/Package/Package.h" +#include "Speckle/Interface/Browser/Bridge/ArgumentBase.h" + +namespace connector::interfac::browser::bridge { + + /*! + Configuration settings class + */ + class SelectionInfo : public active::serialise::Package { + public: + + // MARK: - Types + + using base = active::serialise::Package; + + // MARK: - Constructors + + /*! + Default constructor + */ + SelectionInfo() = default; + + active::utility::String summary = "Nothing is selected"; + std::vector selectedElementIds; + + // MARK: - Serialisation + + /*! + Fill an inventory with the package items + @param inventory The inventory to receive the package items + @return True if the package has added items to the inventory + */ + bool fillInventory(active::serialise::Inventory& inventory) const override; + /*! + Get the specified cargo + @param item The inventory item to retrieve + @return The requested cargo (nullptr on failure) + */ + Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override; + }; + +} + +#endif //CONNECTOR_INTERFACE_BRIDGE_SELECTION_INFO diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/GetSelection.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/GetSelection.cpp new file mode 100644 index 0000000..fc239a7 --- /dev/null +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/GetSelection.cpp @@ -0,0 +1,68 @@ +#include "Connector/Interface/Browser/Bridge/Selection/GetSelection.h" + +#include "Active/Serialise/CargoHold.h" +#include "Active/Serialise/Package/Wrapper/PackageWrap.h" +#include "Connector/Interface/Browser/Bridge/Selection/Arg/SelectionInfo.h" + +#include "Connector/Connector.h" +#include "Connector/Record/Collection/ProjectCollection.h" + +#include "Speckle/Database/BIMElementDatabase.h" +#include "Speckle/Environment/Project.h" +#include "Speckle/Record/Element/Element.h" +using namespace speckle::record::element; + +#include + +using namespace active::serialise; +using namespace connector::interfac::browser::bridge; +using namespace speckle::utility; +using namespace connector::record; + +namespace { + + ///Return type for retrieving the current configuration + using WrappedValue = CargoHold; + +} +/*-------------------------------------------------------------------- + Default constructor + --------------------------------------------------------------------*/ +GetSelection::GetSelection() : BridgeMethod{"GetSelection", [&]() { + return run(); +}} {} + + +/*-------------------------------------------------------------------- + Send a specified model + + modelCardID: The ID of the model to send + --------------------------------------------------------------------*/ +std::unique_ptr GetSelection::run() const { + + auto selectionInfo = std::make_unique(); + + auto project = connector()->getActiveProject().lock(); + if (!project) { + // TODO + } + + //Build a collection from the selected elements + auto collection = std::make_unique(project); + auto elementDatabase = project->getElementDatabase(); + auto selected = elementDatabase->getSelection(); + + active::utility::String summary(selected.size()); + summary += " objects selected."; + + selectionInfo->summary = summary; + + for (const auto& link : selected) { + if (auto element = elementDatabase->getElement(link); element) { + collection->addElement(*element); + selectionInfo->selectedElementIds.push_back(element->getBIMID()); + } + } + + return std::make_unique(std::move(selectionInfo)); +} //GetSelection::run diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/GetSelection.h b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/GetSelection.h new file mode 100644 index 0000000..8f9b73d --- /dev/null +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/GetSelection.h @@ -0,0 +1,30 @@ +#ifndef CONNECTOR_INTERFACE_BRIDGE_GETSELECTION +#define CONNECTOR_INTERFACE_BRIDGE_GETSELECTION + +#include "Speckle/Interface/Browser/Bridge/BridgeMethod.h" + +namespace connector::interfac::browser::bridge { + + class GetSelection : public speckle::interfac::browser::bridge::BridgeMethod { + public: + + // MARK: - Constructors + + /*! + Constructor + @param bridge The parent bridge object (provides access to bridge methods) + */ + GetSelection(); + + // MARK: - Functions (const) + + /*! + Send a specified model + @param modelCardID The ID of the model to send + */ + std::unique_ptr run() const; + }; + +} + +#endif //CONNECTOR_INTERFACE_BRIDGE_GETSELECTION diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/SelectionBridge.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/SelectionBridge.cpp new file mode 100644 index 0000000..5fa969f --- /dev/null +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/SelectionBridge.cpp @@ -0,0 +1,13 @@ +#include "Connector/Interface/Browser/Bridge/Selection/SelectionBridge.h" + +#include "Connector/Interface/Browser/Bridge/Selection/GetSelection.h" + +using namespace connector::interfac::browser::bridge; + +/*-------------------------------------------------------------------- + Default constructor + --------------------------------------------------------------------*/ +SelectionBridge::SelectionBridge() : BrowserBridge{"selectionBinding"} { + //Add bridge methods + addMethod(); +} //SelectionBridge::SelectionBridge diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/SelectionBridge.h b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/SelectionBridge.h new file mode 100644 index 0000000..053fba2 --- /dev/null +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Selection/SelectionBridge.h @@ -0,0 +1,29 @@ +#ifndef CONNECTOR_INTERFACE_BRIDGE_SELECTION_BRIDGE +#define CONNECTOR_INTERFACE_BRIDGE_SELECTION_BRIDGE + +#include "Speckle/Interface/Browser/Bridge/BrowserBridge.h" + +namespace connector::interfac::browser::bridge { + + /*! + A browser bridge to support sending model data to a Speckle server + */ + class SelectionBridge : public speckle::interfac::browser::bridge::BrowserBridge { + public: + + // MARK: - Types + + using base = speckle::interfac::browser::bridge::BrowserBridge; + + // MARK: - Constructors + + using base::base; + /*! + Default constructor + */ + SelectionBridge(); + }; + +} + +#endif //CONNECTOR_INTERFACE_BRIDGE_SELECTION_BRIDGE diff --git a/SpeckleConnector/Connector/Interface/ConnectorPalette.cpp b/SpeckleConnector/Connector/Interface/ConnectorPalette.cpp index 6810467..0800691 100644 --- a/SpeckleConnector/Connector/Interface/ConnectorPalette.cpp +++ b/SpeckleConnector/Connector/Interface/ConnectorPalette.cpp @@ -10,6 +10,7 @@ #include "Connector/Interface/Browser/Bridge/Base/BaseBridge.h" #include "Connector/Interface/Browser/Bridge/Config/ConfigBridge.h" #include "Connector/Interface/Browser/Bridge/Send/SendBridge.h" +#include "Connector/Interface/Browser/Bridge/Selection/SelectionBridge.h" #include "Connector/Interface/Browser/Bridge/Test/TestBridge.h" #include "Speckle/Environment/Addon.h" #include "Speckle/Event/Type/MenuEvent.h" @@ -170,6 +171,7 @@ BrowserPalette::BrowserPalette() : install(); install(); install(); + install(); install(); InitBrowserControl(); }