From 7fe5ba6e9dc12220b23cb9b11d211ef23d4ab430 Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Mon, 9 Sep 2024 16:45:41 +0100 Subject: [PATCH] Defined CardSetting and ModelCard classes --- .../Connector.xcodeproj/project.pbxproj | 12 ++ .../Database/Model/Card/CardSetting.cpp | 93 +++++++++++++++ .../Database/Model/Card/CardSetting.h | 107 ++++++++++++++++++ .../Database/Model/Card/ModelCard.cpp | 100 ++++++++++++++++ .../Connector/Database/Model/Card/ModelCard.h | 105 +++++++++++++++++ 5 files changed, 417 insertions(+) create mode 100644 SpeckleConnector/Connector/Database/Model/Card/CardSetting.cpp create mode 100644 SpeckleConnector/Connector/Database/Model/Card/CardSetting.h create mode 100644 SpeckleConnector/Connector/Database/Model/Card/ModelCard.cpp create mode 100644 SpeckleConnector/Connector/Database/Model/Card/ModelCard.h diff --git a/SpeckleConnector/Connector.xcodeproj/project.pbxproj b/SpeckleConnector/Connector.xcodeproj/project.pbxproj index 028a510..66e1975 100644 --- a/SpeckleConnector/Connector.xcodeproj/project.pbxproj +++ b/SpeckleConnector/Connector.xcodeproj/project.pbxproj @@ -48,6 +48,8 @@ 21D0BD8E2C8EE4490077E104 /* Send.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21D0BD8D2C8EE4490077E104 /* Send.cpp */; }; 21D0BD972C8F13F30077E104 /* GetSendFilters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21D0BD962C8F13F30077E104 /* GetSendFilters.cpp */; }; 21D0BD9B2C8F154B0077E104 /* SendFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21D0BD982C8F154B0077E104 /* SendFilter.cpp */; }; + 21D0BDA82C8F33AC0077E104 /* ModelCard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21D0BDA72C8F33AC0077E104 /* ModelCard.cpp */; }; + 21D0BDAB2C8F363E0077E104 /* CardSetting.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21D0BDAA2C8F363E0077E104 /* CardSetting.cpp */; }; 21D1E9AD2BF14AF200957EAA /* BIMData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9152BF14AEC00957EAA /* BIMData.framework */; }; 21D1E9AE2BF14AF200957EAA /* TeamworkPortalServerClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9162BF14AEC00957EAA /* TeamworkPortalServerClient.framework */; }; 21D1E9AF2BF14AF200957EAA /* GDL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21D1E9172BF14AEC00957EAA /* GDL.framework */; }; @@ -321,6 +323,10 @@ 21D0BD962C8F13F30077E104 /* GetSendFilters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetSendFilters.cpp; sourceTree = ""; }; 21D0BD982C8F154B0077E104 /* SendFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SendFilter.cpp; sourceTree = ""; }; 21D0BD992C8F154B0077E104 /* SendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SendFilter.h; sourceTree = ""; }; + 21D0BDA42C8F33AC0077E104 /* ModelCard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModelCard.h; sourceTree = ""; }; + 21D0BDA72C8F33AC0077E104 /* ModelCard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModelCard.cpp; sourceTree = ""; }; + 21D0BDA92C8F363E0077E104 /* CardSetting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CardSetting.h; sourceTree = ""; }; + 21D0BDAA2C8F363E0077E104 /* CardSetting.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CardSetting.cpp; sourceTree = ""; }; 21D1E9152BF14AEC00957EAA /* BIMData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = BIMData.framework; path = "../Archicad 27/Support/Frameworks/BIMData.framework"; sourceTree = ""; }; 21D1E9162BF14AEC00957EAA /* TeamworkPortalServerClient.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TeamworkPortalServerClient.framework; path = "../Archicad 27/Support/Frameworks/TeamworkPortalServerClient.framework"; sourceTree = ""; }; 21D1E9172BF14AEC00957EAA /* GDL.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GDL.framework; path = "../Archicad 27/Support/Frameworks/GDL.framework"; sourceTree = ""; }; @@ -918,6 +924,10 @@ 21B67CC92C77670400FD64FC /* Card */ = { isa = PBXGroup; children = ( + 21D0BDAA2C8F363E0077E104 /* CardSetting.cpp */, + 21D0BDA92C8F363E0077E104 /* CardSetting.h */, + 21D0BDA72C8F33AC0077E104 /* ModelCard.cpp */, + 21D0BDA42C8F33AC0077E104 /* ModelCard.h */, 21B67CC72C77670400FD64FC /* ModelCardDatabase.cpp */, 21B67CC82C77670400FD64FC /* ModelCardDatabase.h */, ); @@ -1324,6 +1334,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 21D0BDAB2C8F363E0077E104 /* CardSetting.cpp in Sources */, 21B67CE32C78D1FB00FD64FC /* SayHiArg.cpp in Sources */, 21F69FBB2C762EF0008B6A06 /* ConfigBridge.cpp in Sources */, 21F69F8A2C70D2C4008B6A06 /* AccountBridge.cpp in Sources */, @@ -1344,6 +1355,7 @@ 21B67CC02C775A0D00FD64FC /* GetDocumentInfo.cpp in Sources */, 21B67CE72C78D23B00FD64FC /* ConnectorConfig.cpp in Sources */, 21B67CAD2C77329800FD64FC /* GetSourceApplicationName.cpp in Sources */, + 21D0BDA82C8F33AC0077E104 /* ModelCard.cpp in Sources */, 21B67CDC2C78C88000FD64FC /* SayHi.cpp in Sources */, 21F69F122C677BC0008B6A06 /* ConnectorMenu.cpp in Sources */, 21F69F8D2C70D7EE008B6A06 /* GetAccounts.cpp in Sources */, diff --git a/SpeckleConnector/Connector/Database/Model/Card/CardSetting.cpp b/SpeckleConnector/Connector/Database/Model/Card/CardSetting.cpp new file mode 100644 index 0000000..e38db56 --- /dev/null +++ b/SpeckleConnector/Connector/Database/Model/Card/CardSetting.cpp @@ -0,0 +1,93 @@ +#include "Connector/Database/Model/Card/CardSetting.h" + +#include "Active/Serialise/Item/Wrapper/ValueWrap.h" +#include "Active/Serialise/Item/Wrapper/AnyValueWrap.h" + +#include + +using namespace active::serialise; +using namespace connector::database; +using namespace speckle::utility; + +namespace { + + ///Serialisation fields + enum FieldIndex { + idID, + titleID, + typeID, + valueID, + enumID, + }; + + ///Serialisation field IDs + static std::array fieldID = { + Identity{"id"}, + Identity{"title"}, + Identity{"type"}, + Identity{"value"}, + Identity{"enum"}, + }; + +} + +/*-------------------------------------------------------------------- + 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 CardSetting::fillInventory(Inventory& inventory) const { + using enum Entry::Type; + inventory.merge(Inventory{ + { + { fieldID[idID], idID, element }, + { fieldID[titleID], titleID, element }, + { fieldID[typeID], typeID, element }, + { fieldID[valueID], valueID, element }, + { fieldID[enumID], enumID, element }, + }, + }.withType(&typeid(CardSetting))); + return true; +} //CardSetting::fillInventory + + +/*-------------------------------------------------------------------- + Get the specified cargo + + item: The inventory item to retrieve + + return: The requested cargo (nullptr on failure) + --------------------------------------------------------------------*/ +Cargo::Unique CardSetting::getCargo(const Inventory::Item& item) const { + if (item.ownerType != &typeid(CardSetting)) + return nullptr; + using namespace active::serialise; + switch (item.index) { + case idID: + return std::make_unique>(m_ID); + case titleID: + return std::make_unique>(m_title); + case typeID: + return std::make_unique>(m_type); + case valueID: + return std::make_unique(*m_value); + case enumID: + return std::make_unique>(m_type); + default: + return nullptr; //Requested an unknown index + } +} //CardSetting::getCargo + + +/*-------------------------------------------------------------------- + Set to the default package content + --------------------------------------------------------------------*/ +void CardSetting::setDefault() { + m_ID.clear(); + m_title.clear(); + m_type.clear(); + m_value->setDefault(); + m_enum.clear(); +} //CardSetting::setDefault diff --git a/SpeckleConnector/Connector/Database/Model/Card/CardSetting.h b/SpeckleConnector/Connector/Database/Model/Card/CardSetting.h new file mode 100644 index 0000000..752dc51 --- /dev/null +++ b/SpeckleConnector/Connector/Database/Model/Card/CardSetting.h @@ -0,0 +1,107 @@ +#ifndef CONNECTOR_DATABASE_MODEL_CARD_SETTING +#define CONNECTOR_DATABASE_MODEL_CARD_SETTING + +#include "Active/Serialise/Package/Package.h" +#include "Active/Setting/ValueSetting.h" +#include "Active/Setting/Values/StringValue.h" +#include "Active/Utility/Cloner.h" +#include "Speckle/Utility/Guid.h" +#include "Speckle/Utility/String.h" + +namespace connector::database { + + /*! + A setting attached to a model card, capturing rendering/view states of the model at the time of sending, e.g. level of detail (LoD) + */ + class CardSetting : public active::serialise::Package, public active::utility::Cloner { + public: + + // MARK: - Types + + using base = active::serialise::Package; + + // MARK: - Constructors + + /*! + Default constructor + */ + CardSetting() {} + /*! + Copy constructor + @param source The object to copy + */ + CardSetting(const CardSetting& source) : + m_title{source.m_title}, m_type{source.m_type}, m_value{clone(*source.m_value)}, m_enum{source.m_enum} {} + /*! + Destructor + */ + ~CardSetting() {} + /*! + Record cloning + @return A clone of this record + */ + virtual CardSetting* clonePtr() const override { return new CardSetting(*this); }; + + // MARK: - Functions (const) + + /*! + Get the setting ID + @return The setting ID + */ + const speckle::utility::String& getID() const { return m_ID; } + /*! + Get the setting title + @return The setting title + */ + const speckle::utility::String& getTitle() const { return m_title; } + /*! + Get the setting type + @return The setting type + */ + const speckle::utility::String& getType() const { return m_type; } + /*! + Get the setting value + @return The setting value + */ + const active::setting::Value& getValue() const { return *m_value; } + /*! + Get the options for the value, i.e. possible values it can hold + @return Possible setting values + */ + std::vector getEnum() const { return m_enum; } + + // 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; + /*! + Set to the default package content + */ + void setDefault() override; + + private: + ///A unique ID for the setting + speckle::utility::String m_ID = {speckle::utility::Guid{true}}; + ///The model ID + speckle::utility::String m_title; + ///The project ID + speckle::utility::String m_type; + ///The setting value + active::setting::Value::Unique m_value = std::make_unique(); + ///Possible values for the setting (as strings) + std::vector m_enum; + }; + +} + +#endif //CONNECTOR_DATABASE_MODEL_CARD_SETTING diff --git a/SpeckleConnector/Connector/Database/Model/Card/ModelCard.cpp b/SpeckleConnector/Connector/Database/Model/Card/ModelCard.cpp new file mode 100644 index 0000000..d6030d0 --- /dev/null +++ b/SpeckleConnector/Connector/Database/Model/Card/ModelCard.cpp @@ -0,0 +1,100 @@ +#include "Connector/Database/Model/Card/ModelCard.h" + +#include "Active/Serialise/Item/Wrapper/ValueWrap.h" +#include "Active/Serialise/Package/Wrapper/ContainerWrap.h" + +#include + +using namespace active::container; +using namespace active::serialise; +using namespace connector::database; +using namespace speckle::utility; + +namespace { + + ///Serialisation fields + enum FieldIndex { + idID, + modelID, + projectID, + accountID, + serverURLID, + settingsID, + }; + + ///Serialisation field IDs + static std::array fieldID = { + Identity{"id"}, + Identity{"modelId"}, + Identity{"projectId"}, + Identity{"accountId"}, + Identity{"serverURL"}, + Identity{"settings"}, + }; + +} + +/*-------------------------------------------------------------------- + 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 ModelCard::fillInventory(Inventory& inventory) const { + using enum Entry::Type; + inventory.merge(Inventory{ + { + { fieldID[idID], idID, element }, + { fieldID[modelID], modelID, element }, + { fieldID[projectID], projectID, element }, + { fieldID[accountID], accountID, element }, + { fieldID[serverURLID], serverURLID, element }, + { fieldID[settingsID], settingsID, element }, + }, + }.withType(&typeid(ModelCard))); + return true; +} //ModelCard::fillInventory + + +/*-------------------------------------------------------------------- + Get the specified cargo + + item: The inventory item to retrieve + + return: The requested cargo (nullptr on failure) + --------------------------------------------------------------------*/ +Cargo::Unique ModelCard::getCargo(const Inventory::Item& item) const { + if (item.ownerType != &typeid(ModelCard)) + return nullptr; + using namespace active::serialise; + switch (item.index) { + case idID: + return std::make_unique>(m_ID); + case modelID: + return std::make_unique>(m_modelID); + case projectID: + return std::make_unique>(m_projectID); + case accountID: + return std::make_unique>(m_accountID); + case serverURLID: + return std::make_unique>(m_serverURL); + case settingsID: + return std::make_unique>(m_settings); + default: + return nullptr; //Requested an unknown index + } +} //ModelCard::getCargo + + +/*-------------------------------------------------------------------- + Set to the default package content + --------------------------------------------------------------------*/ +void ModelCard::setDefault() { + m_ID.clear(); + m_modelID.clear(); + m_projectID.clear(); + m_accountID.clear(); + m_serverURL.clear(); + m_settings.clear(); +} //ModelCard::setDefault diff --git a/SpeckleConnector/Connector/Database/Model/Card/ModelCard.h b/SpeckleConnector/Connector/Database/Model/Card/ModelCard.h new file mode 100644 index 0000000..23339f8 --- /dev/null +++ b/SpeckleConnector/Connector/Database/Model/Card/ModelCard.h @@ -0,0 +1,105 @@ +#ifndef CONNECTOR_DATABASE_MODEL_CARD +#define CONNECTOR_DATABASE_MODEL_CARD + +#include "Active/Container/Vector.h" +#include "Active/Serialise/Package/Package.h" +#include "Active/Utility/Cloner.h" +#include "Connector/Database/Model/Card/CardSetting.h" +#include "Speckle/Utility/String.h" + +namespace connector::database { + + /*! + A connector send filter + */ + class ModelCard : public active::serialise::Package, public active::utility::Cloner { + public: + + // MARK: - Types + + using base = active::serialise::Package; + //List of card settings + using SettingList = active::container::Vector; + + // MARK: - Constructors + + /*! + Default constructor + */ + ModelCard() {} + /*! + Record cloning + @return A clone of this record + */ + virtual ModelCard* clonePtr() const override { return new ModelCard(*this); }; + + // MARK: - Functions (const) + + /*! + Get the card ID + @return The card ID + */ + const speckle::utility::String& getID() const { return m_ID; } + /*! + Get the model ID + @return The model ID + */ + const speckle::utility::String& getModelID() const { return m_modelID; } + /*! + Get the setting type + @return The setting type + */ + const speckle::utility::String& getProjectID() const { return m_projectID; } + /*! + Get the setting type + @return The setting type + */ + const speckle::utility::String& getAccountID() const { return m_accountID; } + /*! + Get the setting type + @return The setting type + */ + const speckle::utility::String& getServerURL() const { return m_serverURL; } + /*! + Get the card settings + @return The card settings + */ + const SettingList& getSettings() const { return m_settings; } + + // 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; + /*! + Set to the default package content + */ + void setDefault() override; + + private: + ///A unique ID for the card (not the ID of the linked model) + speckle::utility::String m_ID; + ///The model ID + speckle::utility::String m_modelID; + ///The project ID + speckle::utility::String m_projectID; + ///The user account ID + speckle::utility::String m_accountID; + ///The server URL + speckle::utility::String m_serverURL; + ///Settings for the model rendering, e.g. level of detail (LoD) + SettingList m_settings; + }; + +} + +#endif //CONNECTOR_DATABASE_MODEL_CARD