diff --git a/SpeckleLib/Speckle/Primitive/Mesh/Mesh.cpp b/SpeckleLib/Speckle/Primitive/Mesh/Mesh.cpp index dfebf16..5251c28 100644 --- a/SpeckleLib/Speckle/Primitive/Mesh/Mesh.cpp +++ b/SpeckleLib/Speckle/Primitive/Mesh/Mesh.cpp @@ -4,6 +4,7 @@ #include "Active/Serialise/Package/Wrapper/PackageWrap.h" #include "Active/Serialise/Package/Wrapper/ContainerWrap.h" #include "Active/Serialise/Inventory/Identity.h" +#include "Speckle/Serialise/Collection/FinishProxy.h" #include @@ -17,6 +18,7 @@ namespace { vertexID, faceID, colorID, + proxyID, }; ///Serialisation field IDs @@ -24,6 +26,7 @@ namespace { Identity{"vertices"}, Identity{"faces"}, Identity{"colors"}, + Identity{"proxy"}, }; } @@ -42,6 +45,7 @@ bool Mesh::fillInventory(Inventory& inventory) const { { fieldID[vertexID], vertexID, element }, { fieldID[faceID], faceID, element }, { fieldID[colorID], colorID, element }, + { fieldID[proxyID], proxyID, element }, }, }.withType(&typeid(Mesh))); return base::fillInventory(inventory); @@ -66,6 +70,9 @@ Cargo::Unique Mesh::getCargo(const Inventory::Item& item) const { return std::make_unique>>(faces); case colorID: return std::make_unique>>(colors); + case proxyID: + return nullptr; //Activate the following line when the mesh material is available to add to the collector + //return std::make_unique(getBIMID(), material); default: return nullptr; //Requested an unknown index } diff --git a/SpeckleLib/Speckle/Record/Attribute/Finish.cpp b/SpeckleLib/Speckle/Record/Attribute/Finish.cpp index 3f346fd..448b9d4 100644 --- a/SpeckleLib/Speckle/Record/Attribute/Finish.cpp +++ b/SpeckleLib/Speckle/Record/Attribute/Finish.cpp @@ -1,7 +1,9 @@ #include "Speckle/Record/Attribute/Finish.h" #include "Active/Serialise/Item/Wrapper/ValueWrap.h" +#include "Active/Serialise/Management/Management.h" #include "Active/Utility/BufferOut.h" +#include "Speckle/Serialise/Collection/FinishCollector.h" #include "Speckle/Utility/Guid.h" #ifdef ARCHICAD @@ -11,6 +13,7 @@ using namespace active::serialise; using namespace speckle::database; using namespace speckle::record::attribute; +using namespace speckle::serialise; using namespace speckle::utility; #include diff --git a/SpeckleLib/Speckle/Serialise/Collection/FinishProxy.h b/SpeckleLib/Speckle/Serialise/Collection/FinishProxy.h new file mode 100644 index 0000000..97e29a0 --- /dev/null +++ b/SpeckleLib/Speckle/Serialise/Collection/FinishProxy.h @@ -0,0 +1,54 @@ +#ifndef SPECKLE_SERIALISE_FINISH_PROXY +#define SPECKLE_SERIALISE_FINISH_PROXY + +#include "Active/Serialise/Management/Management.h" + +#include "Speckle/Serialise/Collection/FinishCollector.h" + +#ifdef ARCHICAD +namespace ModelerAPI { + class Material; +} +#endif + +namespace speckle::serialise { + + /*! + Proxy cargo for tranporting a mesh finish + + Mesh finishes are currently not serialised with the mesh - instead, they are gathered into a 'material proxy' container that points back to + the target meshes. This proxy allows the mesh to inform the finishes collector (acting as a serialisation manager) to link the mesh with + its finish so the manager can build the 'material proxies' at the end of the project collection. + */ + class FinishProxy : public active::serialise::Package { + public: + FinishProxy(const database::BIMRecordID& meshID, const ModelerAPI::Material& material) : m_objectID{meshID}, m_material{material} {} + + /*! + 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 { + //NB: This object only exists to populate the finish collection - it doesn't carry any serialisable content + if (management() != nullptr) { + if (auto collector = management()->get(); collector != nullptr) + collector->addMaterialProxy(m_material, m_objectID); + } + return true; + } //DocumentInfo::fillInventory + /*! + 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 { return nullptr; } //Empty placeholder + + private: + const database::BIMRecordID& m_objectID; + const ModelerAPI::Material& m_material; + }; + +} + +#endif //SPECKLE_SERIALISE_FINISH_PROXY diff --git a/SpeckleLib/SpeckleLib.xcodeproj/project.pbxproj b/SpeckleLib/SpeckleLib.xcodeproj/project.pbxproj index 6c8998f..2a4d670 100644 --- a/SpeckleLib/SpeckleLib.xcodeproj/project.pbxproj +++ b/SpeckleLib/SpeckleLib.xcodeproj/project.pbxproj @@ -188,6 +188,7 @@ 2196F3032CB57E7F00450DFC /* Storey.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Storey.cpp; sourceTree = ""; }; 219712682BE7E2D500D9EF7E /* Serialisation.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Serialisation.md; sourceTree = ""; }; 21A0FB9F2CB880690023F24E /* FinishCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FinishCollector.h; sourceTree = ""; }; + 21A0FBA92CB9324A0023F24E /* FinishProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FinishProxy.h; sourceTree = ""; }; 21AEF9B32CA5F7CF000B8681 /* DetachedWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachedWrap.h; sourceTree = ""; }; 21AEF9B52CA5FA02000B8681 /* DetachedReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachedReference.h; sourceTree = ""; }; 21AEF9B72CA5FCB6000B8681 /* DetachmentManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachmentManager.h; sourceTree = ""; }; @@ -479,6 +480,7 @@ isa = PBXGroup; children = ( 21A0FB9F2CB880690023F24E /* FinishCollector.h */, + 21A0FBA92CB9324A0023F24E /* FinishProxy.h */, ); path = Collection; sourceTree = "";