From 1a901b0a6c1dd60f7e7b13eb3154b1a661bbf5c2 Mon Sep 17 00:00:00 2001 From: Ralph Wessel Date: Thu, 3 Oct 2024 12:05:48 +0100 Subject: [PATCH] Send bridge is updated: - total children removed - rootObject replaces batches (sent as an object rather than a string) --- .../Connector.xcodeproj/project.pbxproj | 6 ++ .../Browser/Bridge/Send/Arg/SendObject.cpp | 16 ++---- .../Browser/Bridge/Send/Arg/SendObject.h | 18 +++--- .../Bridge/Send/Arg/SendViaBrowserArgs.cpp | 5 +- .../Bridge/Send/Arg/SendViaBrowserArgs.h | 3 +- .../Interface/Browser/Bridge/Send/Send.cpp | 7 ++- .../Speckle/Database/Content/BIMRecord.cpp | 6 +- .../Speckle/Database/Content/BIMRecord.h | 17 +++--- .../Speckle/Database/Content/Record.cpp | 55 ++++++++++++++++++- SpeckleLib/Speckle/Database/Content/Record.h | 21 ++++++- 10 files changed, 115 insertions(+), 39 deletions(-) diff --git a/SpeckleConnector/Connector.xcodeproj/project.pbxproj b/SpeckleConnector/Connector.xcodeproj/project.pbxproj index 37e3043..bd78119 100644 --- a/SpeckleConnector/Connector.xcodeproj/project.pbxproj +++ b/SpeckleConnector/Connector.xcodeproj/project.pbxproj @@ -36,6 +36,7 @@ 21AEF9EF2CAB5720000B8681 /* SendObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9EE2CAB5720000B8681 /* SendObject.cpp */; }; 21AEF9F32CAC12D1000B8681 /* SendManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9F02CAC12D1000B8681 /* SendManager.cpp */; }; 21AEF9FA2CAC3897000B8681 /* ConversionResult.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9F92CAC3897000B8681 /* ConversionResult.cpp */; }; + 21AEF9FD2CAD3FD8000B8681 /* GetSendSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9FB2CAD3FD8000B8681 /* GetSendSettings.cpp */; }; 21B67CA32C769CB400FD64FC /* libActiveLib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F69EF52C64FE91008B6A06 /* libActiveLib.a */; }; 21B67CA42C769CB400FD64FC /* libArchicad27.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F69ECD2C64C035008B6A06 /* libArchicad27.a */; }; 21B67CAC2C77329800FD64FC /* BaseBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21B67CA52C77329800FD64FC /* BaseBridge.cpp */; }; @@ -321,6 +322,8 @@ 21AEF9F12CAC12D1000B8681 /* SendManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SendManager.h; sourceTree = ""; }; 21AEF9F82CAC3897000B8681 /* ConversionResult.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConversionResult.h; sourceTree = ""; }; 21AEF9F92CAC3897000B8681 /* ConversionResult.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConversionResult.cpp; sourceTree = ""; }; + 21AEF9FB2CAD3FD8000B8681 /* GetSendSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetSendSettings.cpp; sourceTree = ""; }; + 21AEF9FC2CAD3FD8000B8681 /* GetSendSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GetSendSettings.h; sourceTree = ""; }; 21B67CA52C77329800FD64FC /* BaseBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BaseBridge.cpp; sourceTree = ""; }; 21B67CA62C77329800FD64FC /* BaseBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BaseBridge.h; sourceTree = ""; }; 21B67CA72C77329800FD64FC /* GetSourceApplicationName.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetSourceApplicationName.cpp; sourceTree = ""; }; @@ -1071,6 +1074,8 @@ 21AEF9E72CAB56E5000B8681 /* Arg */, 21D0BD962C8F13F30077E104 /* GetSendFilters.cpp */, 21D0BD952C8F13F30077E104 /* GetSendFilters.h */, + 21AEF9FB2CAD3FD8000B8681 /* GetSendSettings.cpp */, + 21AEF9FC2CAD3FD8000B8681 /* GetSendSettings.h */, 21D0BD8D2C8EE4490077E104 /* Send.cpp */, 21D0BD8A2C8EE4490077E104 /* Send.h */, 21D0BD5B2C89BFEA0077E104 /* SendBridge.cpp */, @@ -1475,6 +1480,7 @@ 21B67CEB2C78D27200FD64FC /* DocumentInfo.cpp in Sources */, 21B67CB92C774BFA00FD64FC /* GetConnectorVersion.cpp in Sources */, 21B67CD92C78C83800FD64FC /* TestBridge.cpp in Sources */, + 21AEF9FD2CAD3FD8000B8681 /* GetSendSettings.cpp in Sources */, 214B7A372C764BCD00D586C1 /* UpdateConfig.cpp in Sources */, 21AEF9EC2CAB56E5000B8681 /* SendViaBrowserArgs.cpp in Sources */, 21FF70492CA1A7F400AAD99A /* RecordCollection.cpp in Sources */, diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp index fa8bca2..683d025 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.cpp @@ -1,6 +1,7 @@ #include "Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h" #include "Active/Serialise/Package/Wrapper/ContainerWrap.h" +#include "Active/Serialise/Item/Wrapper/ValueWrap.h" #include @@ -14,15 +15,13 @@ namespace { ///Serialisation fields enum FieldIndex { idID, - totChildID, - batchesID, + rootObjID, }; ///Serialisation field IDs static std::array fieldID = { Identity{"id"}, - Identity{"totalChildrenCount"}, - Identity{"batches"}, + Identity{"rootObject"}, }; } @@ -39,8 +38,7 @@ bool SendObject::fillInventory(active::serialise::Inventory& inventory) const { inventory.merge(Inventory{ { { fieldID[idID], idID, element }, - { fieldID[totChildID], totChildID, element }, - { fieldID[batchesID], batchesID, element }, + { fieldID[rootObjID], rootObjID, element }, }, }.withType(&typeid(SendObject))); return true; @@ -61,10 +59,8 @@ Cargo::Unique SendObject::getCargo(const active::serialise::Inventory::Item& ite switch (item.index) { case idID: return std::make_unique(id); - case totChildID: - return std::make_unique(totalChildrenCount); - case batchesID: - return std::make_unique>>(batches); + case rootObjID: + return std::make_unique(base::get()); default: return nullptr; //Requested an unknown index } diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h index 6640fa0..ae31520 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendObject.h @@ -11,26 +11,24 @@ namespace connector::interfac::browser::bridge { /*! Class defining the primary content of a send */ - class SendObject final : public active::serialise::Package { + class SendObject final : public active::serialise::Package, public std::reference_wrapper { public: + + using base = std::reference_wrapper; // MARK: - Constructors /*! - Constructor - @param errMess The error message - @param card The ID of the model card associated with the wrror - */ - SendObject() {} + Default constructor + @param objID The ID of the object to send + @param object A reference to the object + */ + SendObject(const speckle::utility::String& objID, active::serialise::Package& object) : base{object} {} // MARK: - Public variables ///The root object id which should be used for creating the version speckle::utility::String id = "1234"; - ///The total number of children - int32_t totalChildrenCount = 0; - ///JSON batches for the root object and child (detached) objects - std::vector batches; // MARK: - Serialisation diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp index 44eaccc..0e502e2 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.cpp @@ -46,10 +46,11 @@ namespace { modelCard: The model card to populate into the send info for the browser account: The account linked to the send + object: The object to be sent --------------------------------------------------------------------*/ -SendViaBrowserArgs::SendViaBrowserArgs(const ModelCard& modelCard, const Account& account) : +SendViaBrowserArgs::SendViaBrowserArgs(const ModelCard& modelCard, const Account& account, const SendObject& object) : modelCardID(modelCard.getID()), projectID(modelCard.getProjectID()), modelID(modelCard.getModelID()), token{account.getToken()}, - serverURL{account.getServerURL()}, accountID{account.getID()} { +serverURL{account.getServerURL()}, accountID{account.getID()}, sendObject{object} { } //SendViaBrowserArgs::SendViaBrowserArgs diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h index 6dac55d..0e82858 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h @@ -33,8 +33,9 @@ namespace connector::interfac::browser::bridge { Constructor @param modelCard The model card to populate into the send info for the browser @param account The account linked to the send + @param object The object to be sent */ - SendViaBrowserArgs(const connector::record::ModelCard& modelCard, const speckle::record::cred::Account& account); + SendViaBrowserArgs(const connector::record::ModelCard& modelCard, const speckle::record::cred::Account& account, const SendObject& object); // MARK: - Public variables diff --git a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp index 596eba4..4fa0250 100644 --- a/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp +++ b/SpeckleConnector/Connector/Interface/Browser/Bridge/Send/Send.cpp @@ -8,6 +8,7 @@ #include "Connector/Interface/Browser/Bridge/Send/Arg/SendError.h" #include "Connector/Interface/Browser/Bridge/Send/Arg/SendViaBrowserArgs.h" #include "Speckle/Database/AccountDatabase.h" +#include "Speckle/Database/Content/BIMRecord.h" #include "Speckle/Interface/Browser/Bridge/BrowserBridge.h" #include "Speckle/Record/Credentials/Account.h" #include "Speckle/Serialise/Detached/Storage/DetachedMemoryStore.h" @@ -61,7 +62,9 @@ void Send::run(const String& modelCardID) const { } //We currently collect all detached object serialised data into a memory-based store - in future may be able to batch send and cache locally DetachedMemoryStore detachedObjects; - auto result = std::make_unique(*modelCard, *account); - + //Collect targeted elements here + Record placeholder; //Using a placeholder as a test for now + SendObject toSend{placeholder.getID(), placeholder}; + auto result = std::make_unique(*modelCard, *account, toSend); getBridge()->sendEvent("sendByBrowser", std::move(result)); } //Send::run diff --git a/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp b/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp index 882a681..49ebd75 100644 --- a/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp +++ b/SpeckleLib/Speckle/Database/Content/BIMRecord.cpp @@ -1,4 +1,4 @@ -#include "Speckle/Database/Content/Record.h" +#include "Speckle/Database/Content/BIMRecord.h" #include "Speckle/Utility/Guid.h" @@ -13,7 +13,7 @@ using namespace speckle::utility; return: True if the package has added items to the inventory --------------------------------------------------------------------*/ -bool Record::fillInventory(active::serialise::Inventory& inventory) const { +bool BIMRecord::fillInventory(active::serialise::Inventory& inventory) const { using enum Entry::Type; inventory.merge(Inventory{ { @@ -21,4 +21,4 @@ bool Record::fillInventory(active::serialise::Inventory& inventory) const { }, }.withType(&typeid(base))); return true; -} //Record::fillInventory +} //BIMRecord::fillInventory diff --git a/SpeckleLib/Speckle/Database/Content/BIMRecord.h b/SpeckleLib/Speckle/Database/Content/BIMRecord.h index 0cd3db7..f202c40 100644 --- a/SpeckleLib/Speckle/Database/Content/BIMRecord.h +++ b/SpeckleLib/Speckle/Database/Content/BIMRecord.h @@ -1,5 +1,5 @@ -#ifndef SPECKLE_DATABASE_RECORD -#define SPECKLE_DATABASE_RECORD +#ifndef SPECKLE_DATABASE_BIM_RECORD +#define SPECKLE_DATABASE_BIM_RECORD #include "Active/Database/Content/Record.h" #include "Speckle/Database/Identity/Link.h" @@ -10,12 +10,12 @@ namespace speckle::database { /*! Base class for a database record */ - class BIMRecord : public active::database::BIMRecord { + class BIMRecord : public active::database::Record{ public: // MARK: - Types - using base = active::database::BIMRecord; + using base = active::database::Record; ///Unique pointer using Unique = std::unique_ptr; ///Shared pointer @@ -28,14 +28,13 @@ namespace speckle::database { /*! Default constructor */ - BIMRecord() : base{active::utility::Guid{true}.operator active::utility::String(), - active::utility::Guid{true}.operator active::utility::String()} {} //TODO: Implement a better default for the ID + BIMRecord() : base{active::utility::Guid{true}, active::utility::Guid{true}} {} //TODO: Implement a better default for the ID /*! Constructor @param ID The record ID */ - BIMRecord(speckle::utility::String ID, speckle::utility::String::Option globID = std::nullopt) : - base{ID, globID.value_or(active::utility::Guid{true}.operator active::utility::String())} {} + BIMRecord(speckle::utility::Guid ID, speckle::utility::Guid::Option globID = std::nullopt) : //TODO: Implement a better default for the ID + base{ID, globID.value_or(active::utility::Guid{true})} {} /*! Destructor */ @@ -59,4 +58,4 @@ namespace speckle::database { } -#endif //SPECKLE_DATABASE_RECORD +#endif //SPECKLE_DATABASE_BIM_RECORD diff --git a/SpeckleLib/Speckle/Database/Content/Record.cpp b/SpeckleLib/Speckle/Database/Content/Record.cpp index 882a681..c000641 100644 --- a/SpeckleLib/Speckle/Database/Content/Record.cpp +++ b/SpeckleLib/Speckle/Database/Content/Record.cpp @@ -6,6 +6,22 @@ using namespace active::serialise; using namespace speckle::database; using namespace speckle::utility; +namespace { + + ///Serialisation fields + enum FieldIndex { + speckleIDID, + speckleTypeID, + }; + + ///Serialisation field IDs + static std::array fieldID = { + Identity{"id"}, + Identity{"speckle_type"}, + }; + +} + /*-------------------------------------------------------------------- Fill an inventory with the package items @@ -17,8 +33,45 @@ bool Record::fillInventory(active::serialise::Inventory& inventory) const { using enum Entry::Type; inventory.merge(Inventory{ { - { Identity{"id"}, active::database::record::FieldIndex::idIndex, element }, + { Identity{fieldID[speckleIDID]}, active::database::record::FieldIndex::idIndex, element }, }, }.withType(&typeid(base))); + inventory.merge(Inventory{ + { + { Identity{fieldID[speckleTypeID]}, speckleTypeID, element }, + }, + }.withType(&typeid(Record))); return true; } //Record::fillInventory + + +/*-------------------------------------------------------------------- + Get the specified cargo + + item: The inventory item to retrieve + + return: The requested cargo (nullptr on failure) + --------------------------------------------------------------------*/ +Cargo::Unique Record::getCargo(const Inventory::Item& item) const { + if (item.ownerType != &typeid(Record)) + return base::getCargo(item); + using namespace active::serialise; + switch (item.index) { + case speckleTypeID: + //If the type is undefined, we're in a serialisation process and should populate it with whatever the object says it is + if (!m_type) + m_type = getSpeckleType(); + return std::make_unique(*m_type); + default: + return nullptr; //Requested an unknown index + } +} //Record::getCargo + + +/*-------------------------------------------------------------------- + Set to the default package content + --------------------------------------------------------------------*/ +void Record::setDefault() { + //Ensure the content starts with an empty (defined) string for deserialisation so we can discover the incoming type + m_type = String{}; +} //Record::setDefault diff --git a/SpeckleLib/Speckle/Database/Content/Record.h b/SpeckleLib/Speckle/Database/Content/Record.h index 5d70542..2cabaf9 100644 --- a/SpeckleLib/Speckle/Database/Content/Record.h +++ b/SpeckleLib/Speckle/Database/Content/Record.h @@ -42,7 +42,12 @@ namespace speckle::database { virtual ~Record() {} // MARK: - Functions (const) - + + /*! + Get the speckle type identifier + @return The speckle type (relevant objects should override as required, but "Base" is still considered a type on its own) + */ + virtual speckle::utility::String getSpeckleType() const { return "Base"; } // MARK: - Functions (mutating) @@ -55,6 +60,20 @@ namespace speckle::database { @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) + */ + active::serialise::Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override; + /*! + Set to the default package content + */ + void setDefault() override; + + private: + ///Cache for the speckle type during serialisation operations + mutable speckle::utility::String::Option m_type; }; }