Added property::Group

Added property Group database
Property template group & group name access added
This commit is contained in:
Ralph Wessel
2024-10-22 20:09:01 +01:00
parent eeb4dab690
commit 2c6909e98e
14 changed files with 842 additions and 27 deletions
@@ -0,0 +1,129 @@
#include "Speckle/Database/BIMGroupDatabase.h"
#include "Active/Database/Storage/Storage.h"
#include "Active/Serialise/UnboxedTransport.h"
#include "Speckle/Database/Identity/RecordID.h"
#include "Speckle/Database/Storage/ArchicadDBase/Property/ArchicadGroupDBaseEngine.h"
#include "Speckle/Record/Property/Setting.h"
#include <array>
using namespace active::container;
using namespace active::database;
using namespace active::event;
using namespace active::serialise;
using namespace speckle::database;
using namespace speckle::record;
using namespace speckle::record::property;
using namespace speckle::database;
using namespace speckle::utility;
namespace speckle::database {
///Define other platform engines here as required
#ifdef ARCHICAD
using GroupDatabaseEngine = ArchicadGroupDBaseEngine;
#endif
///Group database engine declaration
class BIMGroupDatabase::Engine : public GroupDatabaseEngine {
using base = ArchicadGroupDBaseEngine;
using base::base;
};
///Group database storage declaration
class BIMGroupDatabase::Store : public Storage<Group, UnboxedTransport, BIMRecordID, BIMRecordID, BIMRecordID, BIMRecordID> {
using base = Storage<Group, UnboxedTransport, BIMRecordID, BIMRecordID, BIMRecordID, BIMRecordID>;
using base::base;
};
}
namespace {
///The database storage identifier for groups
const char* groupDBaseName = "speckle::database::BIMGroupDatabase";
///The primary groups table
const char* groupTableName = "Groups";
}
/*--------------------------------------------------------------------
Constructor
--------------------------------------------------------------------*/
BIMGroupDatabase::BIMGroupDatabase() {
m_engine = std::make_shared<Engine>(groupDBaseName,
//Schema
DBaseSchema{active::utility::String{groupDBaseName},
//Tables
{
//Model group table
{
groupTableName, 0, 0, {}
}
}
}
);
m_store = std::make_shared<Store>(m_engine);
} //BIMGroupDatabase::BIMGroupDatabase
/*--------------------------------------------------------------------
Destructor
--------------------------------------------------------------------*/
BIMGroupDatabase::~BIMGroupDatabase() {}
/*--------------------------------------------------------------------
Get a specified group
groupID: The ID of the target group
return: The requested group (nullptr on failure)
--------------------------------------------------------------------*/
Group::Unique BIMGroupDatabase::getGroup(const BIMRecordID& groupID, std::optional<BIMRecordID> tableID,
std::optional<BIMRecordID> documentID) const {
return m_engine->getObject(groupID, tableID, documentID);
} //BIMGroupDatabase::getGroup
/*--------------------------------------------------------------------
Get a specified group
link: A link to the target group
return: The requested group (nullptr on failure)
--------------------------------------------------------------------*/
Group::Unique BIMGroupDatabase::getGroup(const BIMLink& link) const {
return getGroup(link, link.tableID, link.docID);
} //BIMGroupDatabase::getGroup
/*--------------------------------------------------------------------
Get all groups
return: All the groups
--------------------------------------------------------------------*/
Vector<Group> BIMGroupDatabase::getGroups() const {
return m_store->getObjects();
} //BIMGroupDatabase::getGroups
/*--------------------------------------------------------------------
Write an group to storage
group: The group to write
--------------------------------------------------------------------*/
void BIMGroupDatabase::write(const Group& group) const {
m_store->write(group);
} //BIMGroupDatabase::write
/*--------------------------------------------------------------------
Erase an group
groupID: The ID of the group to erase
--------------------------------------------------------------------*/
void BIMGroupDatabase::erase(const Guid& groupID) const {
m_store->erase(groupID);
} //BIMGroupDatabase::erase
@@ -0,0 +1,77 @@
#ifndef CONNECTOR_DATABASE_BIM_GROUP_DATABASE
#define CONNECTOR_DATABASE_BIM_GROUP_DATABASE
#include "Speckle/Database/Identity/BIMLink.h"
#include "Speckle/Record/Property/Group.h"
#include "Speckle/Utility/Guid.h"
namespace active::event {
class Subscriber;
}
namespace speckle::database {
/*!
Database of group templates relating to a specific project
Note that this database manages just the group templates, not the values. Group values are attached to elements
*/
class BIMGroupDatabase {
public:
// MARK: - Constructors
/*!
Constructor
*/
BIMGroupDatabase();
BIMGroupDatabase(const BIMGroupDatabase&) = delete;
/*!
Destructor
*/
~BIMGroupDatabase();
// MARK: - Functions (const)
/*!
Get a specified group
@param groupID The ID of the target group
@param tableID Optional table ID (defaults to the floor plan)
@param documentID Optional document ID (when the object is bound to a specific document)
@return The requested group (nullptr on failure)
*/
record::property::Group::Unique getGroup(const BIMRecordID& groupID, std::optional<BIMRecordID> tableID = std::nullopt,
std::optional<BIMRecordID> documentID = std::nullopt) const;
/*!
Get a specified group
@param link A link to the target group
@return The requested group (nullptr on failure)
*/
record::property::Group::Unique getGroup(const BIMLink& link) const;
/*!
Get all model groups
@return All the groups
*/
active::container::Vector<record::property::Group> getGroups() const;
/*!
Write an group to storage
@param group The group to write
*/
void write(const record::property::Group& group) const;
/*!
Erase an group
@param groupID The ID of the group to erase
*/
void erase(const speckle::utility::Guid& groupID) const;
private:
class Engine;
class Store;
///Model group database storage
std::shared_ptr<Engine> m_engine;
std::shared_ptr<Store> m_store;
};
}
#endif //CONNECTOR_DATABASE_BIM_GROUP_DATABASE
@@ -43,8 +43,8 @@ namespace {
///The database storage identifier for properties
const char* propertyDBaseName = "speckle::database::BIMPropertyDatabase";
///The primary model table, e.g. floor plan in Archicad
const char* modelTableName = "Model";
///The primary properties table
const char* propertyTableName = "Properties";
}
@@ -59,7 +59,7 @@ BIMPropertyDatabase::BIMPropertyDatabase() {
{
//Model property table
{
modelTableName, 0, 0, {} //The primary model. Additonal tables could be linked to other drawings/layouts in future
propertyTableName, 0, 0, {}
}
}
}
@@ -0,0 +1,232 @@
#include "Speckle/Database/Storage/ArchicadDBase/Property/ArchicadGroupDBaseEngine.h"
#ifdef ARCHICAD
#include "Active/Utility/Memory.h"
#include "Speckle/Database/Identity/BIMLink.h"
#include "Speckle/Environment/Addon.h"
#include "Speckle/Environment/Project.h"
#include "Speckle/Event/Type/ProjectEvent.h"
#include "Speckle/Record/Property/Setting.h"
#include "Speckle/Utility/Guid.h"
#include "Speckle/Utility/String.h"
#include <ACAPinc.h>
#include <ACAPI_Database.h>
using namespace active::event;
using namespace active::setting;
using namespace speckle::database;
using namespace speckle::environment;
using namespace speckle::event;
using namespace speckle::record::property;
using namespace speckle::utility;
using enum ArchicadDBaseCore::Status;
namespace {
/*!
Make a new group object
@param groupData The API group representation
@return A new group object (nullptr on failure)
*/
Group::Shared makeGroup(const API_PropertyGroup& groupData) {
//NB: This function has been written to allow for the future possibility of different methods for constructing a group and/or
//failure to make one
return std::make_shared<Group>(groupData);
}
}
namespace speckle::database {
class ArchicadGroupDBaseEngine::Cache : public std::unordered_map<Guid, std::shared_ptr<Group>> {
public:
/*!
Default constructor
*/
Cache() { rebuild(); }
/*!
Rebuild the property group cache
*/
void rebuild() {
//Request all Archicad group groups
GS::Array<API_PropertyGroup> groups;
if (auto err = ACAPI_Property_GetPropertyGroups(groups); err != NoError)
return;
//Populate the group cache from the collected groups
for (auto iter = groups.Begin(); iter != groups.End(); ++iter)
if (auto propGroup = makeGroup(*iter); propGroup)
insert({propGroup->getBIMID(), propGroup});
}
};
}
/*--------------------------------------------------------------------
Constructor
id: The document storage identifier
schema: The document storage schema
--------------------------------------------------------------------*/
ArchicadGroupDBaseEngine::ArchicadGroupDBaseEngine(const active::utility::NameID& id, ArchicadDBaseSchema&& schema) :
ArchicadDBaseCore{id, std::move(schema)} {
} //ArchicadGroupDBaseEngine::ArchicadGroupDBaseEngine
/*--------------------------------------------------------------------
Destructor
--------------------------------------------------------------------*/
ArchicadGroupDBaseEngine::~ArchicadGroupDBaseEngine() {
} //ArchicadGroupDBaseEngine::~ArchicadGroupDBaseEngine
/*--------------------------------------------------------------------
Get an object by ID
objID: The object index
tableID: Optional table ID (defaults to the floor plan)
documentID: Optional document ID (when the object is bound to a specific document)
return: The requested object (nullptr on failure)
--------------------------------------------------------------------*/
std::unique_ptr<Group> ArchicadGroupDBaseEngine::getObject(const BIMRecordID& objID, std::optional<BIMRecordID> tableID,
std::optional<BIMRecordID> documentID) const {
if (!validateCache() || (tableID && (tableID != Group::propertyGroupTableID)))
return nullptr;
if (auto found = m_cache->find(objID); found != m_cache->end())
return std::make_unique<Group>(*found->second);
return nullptr;
} //ArchicadGroupDBaseEngine::getObject
/*--------------------------------------------------------------------
Get an object in a transportable form, e.g. packaged for serialisation
index: The object index
tableID: Optional table ID (defaults to the floor plan)
documentID: Optional document ID (when the object is bound to a specific document)
return: The requested wrapped cargo (nullptr on failure)
--------------------------------------------------------------------*/
active::serialise::Cargo::Unique ArchicadGroupDBaseEngine::getObjectCargo(const BIMRecordID& ID, std::optional<BIMRecordID> tableID,
std::optional<BIMRecordID> documentID) const {
return nullptr; //TODO: Implement
} //ArchicadGroupDBaseEngine::getObject
/*--------------------------------------------------------------------
Get all objects
tableID: Optional table ID (defaults to the floor plan)
documentID: Optional document ID (filter for this document only - nullopt = all objects)
return: The requested objects (nullptr on failure)
--------------------------------------------------------------------*/
active::container::Vector<Group> ArchicadGroupDBaseEngine::getObjects(std::optional<BIMRecordID> tableID,
std::optional<BIMRecordID> documentID) const {
return {}; //TODO: Implement
} //ArchicadGroupDBaseEngine::getObjects
/*--------------------------------------------------------------------
Get all objects
filter: The object filter
tableID: Optional table ID (defaults to the floor plan)
documentID: Optional document ID (filter for this document only - nullopt = all objects)
return: The requested objects (nullptr on failure)
--------------------------------------------------------------------*/
active::container::Vector<Group> ArchicadGroupDBaseEngine::getObjects(const Filter& filter, std::optional<BIMRecordID> tableID,
std::optional<BIMRecordID> documentID) const {
return {}; //TODO: Implement
} //ArchicadGroupDBaseEngine::getObjects
/*--------------------------------------------------------------------
Write an object to the database
object: The object to write
objID: The object ID
objDocID: The object document-specific ID (unique within a specific document - nullopt if not document-bound)
tableID: Optional table ID (defaults to the floor plan)
documentID: Optional document ID (when the object is bound to a specific document)
--------------------------------------------------------------------*/
void ArchicadGroupDBaseEngine::write(const Group& object, const BIMRecordID& objID, std::optional<BIMRecordID> objDocID,
std::optional<BIMRecordID> tableID, std::optional<BIMRecordID> documentID) const {
//TODO: Implement
} //ArchicadGroupDBaseEngine::write
/*--------------------------------------------------------------------
Erase an object by index
objID: The object ID
tableID: Optional table ID (defaults to the floor plan)
documentID: Optional document ID (when the object is bound to a specific document)
return: True if the object was successfully erased
--------------------------------------------------------------------*/
void ArchicadGroupDBaseEngine::erase(const BIMRecordID& ID, std::optional<BIMRecordID> tableID,
std::optional<BIMRecordID> documentID) const {
//TODO: Implement
} //ArchicadGroupDBaseEngine::erase
/*--------------------------------------------------------------------
Erase all objects
tableID: Optional table ID (defaults to the floor plan)
documentID: Optional document ID (filter for this document only - nullopt = all objects)
--------------------------------------------------------------------*/
void ArchicadGroupDBaseEngine::erase(std::optional<BIMRecordID> tableID, std::optional<BIMRecordID> documentID) const {
//TODO: Implement
} //ArchicadGroupDBaseEngine::erase
/*--------------------------------------------------------------------
Get the database outline
return: The database outline
--------------------------------------------------------------------*/
ArchicadGroupDBaseEngine::Outline ArchicadGroupDBaseEngine::getOutline() const {
return {}; //TODO: Implement
} //ArchicadGroupDBaseEngine::getOutline
/*--------------------------------------------------------------------
Handle a project event
event: The project event
return: True if the event should be closed
--------------------------------------------------------------------*/
bool ArchicadGroupDBaseEngine::handle(const event::ProjectEvent& event) {
using enum ProjectEvent::Type;
switch (event.getType()) {
case newDocument: case newAndReset: case open: case close: case quit:
//Reset the group cache on any event that changes the active project
m_cache.reset();
break;
default:
break;
}
return false;
} //ArchicadGroupDBaseEngine::handle
/*--------------------------------------------------------------------
Ensure the cache is current
return: True if the cache contains valid te groups
--------------------------------------------------------------------*/
bool ArchicadGroupDBaseEngine::validateCache() const {
if (!m_cache)
m_cache = std::make_unique<Cache>();
return !m_cache->empty();
} //ArchicadGroupDBaseEngine::validateCache
#endif //ARCHICAD
@@ -0,0 +1,136 @@
#ifndef SPECKLE_DATABASE_ARCHICAD_GROUP_DBASE_ENGINE
#define SPECKLE_DATABASE_ARCHICAD_GROUP_DBASE_ENGINE
#include "Active/Database/Storage/DBaseEngine.h"
#include "Active/Serialise/UnboxedTransport.h"
#include "Speckle/Database/Storage/ArchicadDBase/ArchicadDBaseCore.h"
#include "Speckle/Database/Identity/BIMLink.h"
#include "Speckle/Record/Property/Group.h"
#include "Speckle/Utility/Guid.h"
#include "Speckle/Utility/String.h"
#include <algorithm>
#include <ranges>
namespace speckle::database {
/*!
A database engine to read/write property groups in an Archicad project database (local file or cloud-based)
Property groups can be attached to property templates to support collections of types linked to a specific role
*/
class ArchicadGroupDBaseEngine : public ArchicadDBaseCore,
public active::database::DBaseEngine<record::property::Group, BIMRecordID, BIMRecordID, BIMRecordID> {
public:
// MARK: - Types
using base = active::database::DBaseEngine<record::property::Group, BIMRecordID, BIMRecordID, BIMRecordID>;
using Group = record::property::Group;
using Filter = base::Filter;
using Outline = base::Outline;
// MARK: - Constructors
/*!
Constructor
@param id The document storage identifier
@param schema The document storage schema
*/
ArchicadGroupDBaseEngine(const active::utility::NameID& id, ArchicadDBaseSchema&& schema);
ArchicadGroupDBaseEngine(const ArchicadGroupDBaseEngine&) = delete;
/*!
Destructor
*/
~ArchicadGroupDBaseEngine();
// MARK: - Functions (const)
/*!
Get an object by ID
@param objID The object ID
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@return The requested object (nullptr on failure)
*/
std::unique_ptr<Group> getObject(const BIMRecordID& objID, std::optional<BIMRecordID> tableID = std::nullopt, std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Get an object in a transportable form, e.g. packaged for serialisation
@param objID The object ID
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@return: The requested wrapped cargo (nullptr on failure)
*/
active::serialise::Cargo::Unique getObjectCargo(const BIMRecordID& objID, std::optional<BIMRecordID> tableID = std::nullopt, std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Get all objects
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (filter for this document only - nullopt = all objects)
@return The requested objects (nullptr on failure)
*/
active::container::Vector<Group> getObjects(std::optional<BIMRecordID> tableID = std::nullopt, std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Get a filtered list of objects
@param filter The object filter
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (filter for this document only - nullopt = all objects)
@return The filtered objects (nullptr on failure)
*/
active::container::Vector<Group> getObjects(const Filter& filter, std::optional<BIMRecordID> tableID = std::nullopt,
std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Write an object to the database
@param object The object to write
@param objID The object ID
@param objDocID The object document-specific ID (unique within a specific document - nullopt if not document-bound)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
*/
void write(const Group& object, const BIMRecordID& objID, std::optional<BIMRecordID> objDocID = std::nullopt,
std::optional<BIMRecordID> tableID = std::nullopt, std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Erase an object by index
@param ID The object ID
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@throw Exception thrown on SQL error
*/
void erase(const BIMRecordID& ID, std::optional<BIMRecordID> tableID = std::nullopt,
std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Erase all objects
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@throw Exception thrown on SQL error
*/
void erase(std::optional<BIMRecordID> tableID = std::nullopt, std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Get the database outline
@return The database outline
*/
Outline getOutline() const override;
// MARK: - Functions (mutating)
/*!
Handle a project event
@param event The project event
@return True if the event should be closed
*/
bool handle(const event::ProjectEvent& event) override;
private:
/*!
Ensure the cache is current
@return True if the cache contains valid te templates
*/
bool validateCache() const;
//Cached templates
class Cache;
mutable std::unique_ptr<Cache> m_cache;
};
}
#endif //SPECKLE_DATABASE_ARCHICAD_GROUP_DBASE_ENGINE
@@ -118,7 +118,7 @@ std::vector<std::shared_ptr<Template>> ArchicadPropertyDBaseEngine::findTemplate
--------------------------------------------------------------------*/
std::unique_ptr<Template> ArchicadPropertyDBaseEngine::getObject(const BIMRecordID& objID, std::optional<BIMRecordID> tableID,
std::optional<BIMRecordID> documentID) const {
if (!validateCache() || (tableID && (tableID != Template::propertyTableID)))
if (!validateCache() || (tableID && (tableID != Template::propertyTemplateTableID)))
return nullptr;
if (auto found = m_cache->find(objID); found != m_cache->end())
return std::make_unique<Template>(*found->second);
@@ -232,7 +232,7 @@ bool ArchicadPropertyDBaseEngine::handle(const event::ProjectEvent& event) {
using enum ProjectEvent::Type;
switch (event.getType()) {
case newDocument: case newAndReset: case open: case close: case quit:
//Reset the template template cache on any event that changes the active project
//Reset the template cache on any event that changes the active project
m_cache.reset();
break;
default:
@@ -56,7 +56,7 @@ namespace speckle::database {
/*!
Get an object by ID
@param objID The object ID
@param tableID Optional table ID (defaults to the floor plan)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@return The requested object (nullptr on failure)
*/
@@ -64,14 +64,14 @@ namespace speckle::database {
/*!
Get an object in a transportable form, e.g. packaged for serialisation
@param objID The object ID
@param tableID Optional table ID (defaults to the floor plan)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@return: The requested wrapped cargo (nullptr on failure)
*/
active::serialise::Cargo::Unique getObjectCargo(const BIMRecordID& objID, std::optional<BIMRecordID> tableID = std::nullopt, std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Get all objects
@param tableID Optional table ID (defaults to the floor plan)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (filter for this document only - nullopt = all objects)
@return The requested objects (nullptr on failure)
*/
@@ -79,7 +79,7 @@ namespace speckle::database {
/*!
Get a filtered list of objects
@param filter The object filter
@param tableID Optional table ID (defaults to the floor plan)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (filter for this document only - nullopt = all objects)
@return The filtered objects (nullptr on failure)
*/
@@ -90,7 +90,7 @@ namespace speckle::database {
@param object The object to write
@param objID The object ID
@param objDocID The object document-specific ID (unique within a specific document - nullopt if not document-bound)
@param tableID Optional table ID (defaults to the floor plan)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
*/
void write(const Template& object, const BIMRecordID& objID, std::optional<BIMRecordID> objDocID = std::nullopt,
@@ -98,7 +98,7 @@ namespace speckle::database {
/*!
Erase an object by index
@param ID The object ID
@param tableID Optional table ID (defaults to the floor plan)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@throw Exception thrown on SQL error
*/
@@ -106,7 +106,7 @@ namespace speckle::database {
std::optional<BIMRecordID> documentID = std::nullopt) const override;
/*!
Erase all objects
@param tableID Optional table ID (defaults to the floor plan)
@param tableID Optional table ID (default selected based on record type)
@param documentID Optional document ID (when the object is bound to a specific document)
@throw Exception thrown on SQL error
*/
@@ -2,6 +2,7 @@
#include "Speckle/Database/BIMAttributeDatabase.h"
#include "Speckle/Database/BIMElementDatabase.h"
#include "Speckle/Database/BIMGroupDatabase.h"
#include "Speckle/Database/BIMPropertyDatabase.h"
#include "Speckle/Environment/Addon.h"
#include "Speckle/SpeckleResource.h"
@@ -26,6 +27,7 @@ namespace {
Project::Project() {
m_attribute = std::make_unique<BIMAttributeDatabase>();
m_element = std::make_unique<BIMElementDatabase>();
m_group = std::make_unique<BIMGroupDatabase>();
m_property = std::make_unique<BIMPropertyDatabase>();
} //Project::Project
+12 -4
View File
@@ -7,6 +7,7 @@
namespace speckle::database {
class BIMAttributeDatabase;
class BIMElementDatabase;
class BIMGroupDatabase;
class BIMPropertyDatabase;
}
@@ -62,13 +63,18 @@ namespace speckle::environment {
*/
const database::BIMAttributeDatabase* getAttributeDatabase() const { return m_attribute.get(); }
/*!
Get the account database
@return The account database
Get the element database
@return The element database
*/
const database::BIMElementDatabase* getElementDatabase() const { return m_element.get(); }
/*!
Get the account database
@return The account database
Get the group database
@return The group database
*/
const database::BIMGroupDatabase* getGroupDatabase() const { return m_group.get(); }
/*!
Get the property database
@return The property database
*/
const database::BIMPropertyDatabase* getPropertyDatabase() const { return m_property.get(); }
@@ -89,6 +95,8 @@ namespace speckle::environment {
std::unique_ptr<database::BIMAttributeDatabase> m_attribute;
///The BIM element database
std::unique_ptr<database::BIMElementDatabase> m_element;
///The BIM group database
std::unique_ptr<database::BIMGroupDatabase> m_group;
///The BIM property database
std::unique_ptr<database::BIMPropertyDatabase> m_property;
};
@@ -0,0 +1,93 @@
#include "Speckle/Record/Property/Group.h"
#include "Speckle/Database/BIMPropertyDatabase.h"
#include "Speckle/Environment/Addon.h"
#include "Speckle/Environment/Project.h"
#include "Speckle/Record/Property/Setting.h"
#include "Speckle/Serialise/Types/Str256.h"
using namespace active::serialise;
using namespace speckle::database;
using namespace speckle::environment;
using namespace speckle::record::property;
using namespace speckle::utility;
#include <array>
#include <memory>
namespace {
///Serialisation fields
enum FieldIndex {
nameID,
};
///Serialisation field IDs
static std::array fieldID = {
Identity{"name"},
};
}
/*--------------------------------------------------------------------
Default constructor
--------------------------------------------------------------------*/
Group::Group() {
} //Group::Group
/*--------------------------------------------------------------------
Constructor
ID: The template ID
--------------------------------------------------------------------*/
Group::Group(const database::BIMRecordID& ID) : base{ID, propertyGroupTableID} {
} //Group::Group
/*--------------------------------------------------------------------
Constructor
ID: The record ID
tableID: The parent table ID
unit: The record unit type
--------------------------------------------------------------------*/
Group::Group(const speckle::utility::Guid& ID, const speckle::utility::Guid& tableID) : base{ID, tableID} {
} //Group::Group
#ifdef ARCHICAD
/*--------------------------------------------------------------------
Constructor
source: An Archicad property group to copy
--------------------------------------------------------------------*/
Group::Group(const API_PropertyGroup& source) : base{source.guid, propertyGroupTableID}, m_name(source.name), m_description(source.description) {
} //Group::Group
#endif
/*--------------------------------------------------------------------
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 Group::fillInventory(Inventory& inventory) const {
//Implement when required
return base::fillInventory(inventory);
} //Group::fillInventory
/*--------------------------------------------------------------------
Get the specified cargo
item: The inventory item to retrieve
return: The requested cargo (nullptr on failure)
--------------------------------------------------------------------*/
Cargo::Unique Group::getCargo(const Inventory::Item& item) const {
//Implement when required
return base::getCargo(item);
} //Group::getCargo
+100
View File
@@ -0,0 +1,100 @@
#ifndef SPECKLE_RECORD_PROPERTY_GROUP
#define SPECKLE_RECORD_PROPERTY_GROUP
#include "Speckle/Database/Content/BIMRecord.h"
#include "Speckle/Record/Property/Value.h"
#include "Speckle/Utility/Guid.h"
#include "Speckle/Utility/String.h"
namespace speckle::record::property {
class Setting;
/*!
Class defining the characteristics of a property group
Properties are typically associated with a group
Property groups are persisted in the BIM property database
*/
class Group : public speckle::database::BIMRecord {
public:
// MARK: - Types
using base = speckle::database::BIMRecord;
///Unique pointer
using Unique = std::unique_ptr<Group>;
///Shared pointer
using Shared = std::shared_ptr<Group>;
///Optional
using Option = std::optional<Group>;
// MARK: - Constants
///Identifier for a property group table
inline static utility::Guid propertyGroupTableID{utility::String{"cbe185dc-5011-4325-9651-1852056a04de"}};
// MARK: - Constructors
using base::base;
/*!
Default constructor
*/
Group();
#ifdef ARCHICAD
/*!
Constructor
@param source An Archicad property group to copy
*/
Group(const API_PropertyGroup& source);
#endif
/*!
Constructor
@param ID The group ID
*/
Group(const database::BIMRecordID& ID);
/*!
Constructor
@param ID The record ID
@param tableID The parent table ID
*/
Group(const speckle::utility::Guid& ID, const speckle::utility::Guid& tableID);
// MARK: - Functions (const)
/*!
Get the group name
@return The group name
*/
speckle::utility::String getName() const { return m_name; }
// MARK: - Functions (mutating)
//TODO: Add methods as required
// 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;
private:
///Name
speckle::utility::String m_name;
///Description
speckle::utility::String m_description;
};
}
#endif //SPECKLE_RECORD_PROPERTY_GROUP
@@ -1,6 +1,6 @@
#include "Speckle/Record/Property/Template.h"
#include "Speckle/Database/BIMPropertyDatabase.h"
#include "Speckle/Database/BIMGroupDatabase.h"
#include "Speckle/Environment/Addon.h"
#include "Speckle/Environment/Project.h"
#include "Speckle/Record/Property/Setting.h"
@@ -34,7 +34,7 @@ namespace {
ID: The template ID
--------------------------------------------------------------------*/
Template::Template(const database::BIMRecordID& ID) : base{ID, propertyTableID} {
Template::Template(const database::BIMRecordID& ID) : base{ID, propertyTemplateTableID} {
} //Template::Template
@@ -124,7 +124,7 @@ Template::Template() {
source: An Archicad property definition to copy
--------------------------------------------------------------------*/
Template::Template(const API_PropertyDefinition& source) : base{source.guid, propertyTableID},
Template::Template(const API_PropertyDefinition& source) : base{source.guid, propertyTemplateTableID},
m_group{source.groupGuid}, m_name(source.name), m_description(source.description) {
m_origin = static_cast<Origin>(source.definitionType);
m_type = static_cast<Type>(source.collectionType);
@@ -154,14 +154,22 @@ Template::Template(const API_PropertyDefinition& source) : base{source.guid, pro
--------------------------------------------------------------------*/
String Template::getGroupName() const {
String result;
auto project = addon()->getActiveProject().lock();
if (project) {
if (auto group = project->getPropertyDatabase()->getProperty(m_group); group)
result = group->getName();
}
if (auto group = getGroup(); group)
result = group->getName();
return result;
} //Template::getGroupName
/*--------------------------------------------------------------------
Get the template group. NB: This value is not cached in the object and drequires a database lookup - don't use casually
return: The template group (nullptr on failure)
--------------------------------------------------------------------*/
std::unique_ptr<Group> Template::getGroup() const {
auto project = addon()->getActiveProject().lock();
return (project) ? project->getGroupDatabase()->getGroup(m_group) : nullptr;
} //Template::getGroup
#ifdef ARCHICAD
/*--------------------------------------------------------------------
@@ -8,10 +8,11 @@
namespace speckle::record::property {
class Group;
class Setting;
/*!
Class defining the characteristics of a property value
Class defining the characteristics of a property template
Properties carry both a template (the property metadata) and a value. The template defines the value characteristics, e.g. name, type etc
and can be shared amongst any number of properties
@@ -71,8 +72,8 @@ namespace speckle::record::property {
// MARK: - Constants
///Identifier for a property table
inline static utility::Guid propertyTableID{utility::String{"ae66bc4a-9530-45c9-af57-628562a0d783"}};
///Identifier for a property template table
inline static utility::Guid propertyTemplateTableID{utility::String{"ae66bc4a-9530-45c9-af57-628562a0d783"}};
// MARK: - Constructors
@@ -125,6 +126,11 @@ namespace speckle::record::property {
@return The template group name
*/
speckle::utility::String getGroupName() const;
/*!
Get the template group. NB: This value is not cached in the object and drequires a database lookup - don't use casually
@return The template group (nullptr on failure)
*/
std::unique_ptr<Group> getGroup() const;
/*!
Get the classifications linked to the template
@return A set containing the IDs of classifications linked to the template
@@ -97,6 +97,12 @@
21AE19802CC7D265004DBCFC /* PropertiedWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 21AE197E2CC7D265004DBCFC /* PropertiedWrapper.h */; };
21AE19832CC7D517004DBCFC /* PropertyWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AE19812CC7D517004DBCFC /* PropertyWrapper.cpp */; };
21AE19842CC7D517004DBCFC /* PropertyWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 21AE19822CC7D517004DBCFC /* PropertyWrapper.h */; };
21AE19872CC7FF5F004DBCFC /* Group.h in Headers */ = {isa = PBXBuildFile; fileRef = 21AE19852CC7FF5F004DBCFC /* Group.h */; };
21AE19882CC7FF5F004DBCFC /* Group.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AE19862CC7FF5F004DBCFC /* Group.cpp */; };
21AE198F2CC80541004DBCFC /* ArchicadGroupDBaseEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = 21AE198D2CC80541004DBCFC /* ArchicadGroupDBaseEngine.h */; };
21AE19902CC80541004DBCFC /* ArchicadGroupDBaseEngine.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AE198E2CC80541004DBCFC /* ArchicadGroupDBaseEngine.cpp */; };
21AE19932CC82866004DBCFC /* BIMGroupDatabase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AE19912CC82866004DBCFC /* BIMGroupDatabase.cpp */; };
21AE19942CC82866004DBCFC /* BIMGroupDatabase.h in Headers */ = {isa = PBXBuildFile; fileRef = 21AE19922CC82866004DBCFC /* BIMGroupDatabase.h */; };
21AEF9BA2CA606B5000B8681 /* DetachedReference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9B92CA606B4000B8681 /* DetachedReference.cpp */; };
21AEF9BC2CA6DF84000B8681 /* DetachmentManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9BB2CA6DF84000B8681 /* DetachmentManager.cpp */; };
21AEF9BE2CA6FDA4000B8681 /* DetachedWrap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 21AEF9BD2CA6FDA4000B8681 /* DetachedWrap.cpp */; };
@@ -285,6 +291,12 @@
21AE197E2CC7D265004DBCFC /* PropertiedWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertiedWrapper.h; sourceTree = "<group>"; };
21AE19812CC7D517004DBCFC /* PropertyWrapper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PropertyWrapper.cpp; sourceTree = "<group>"; };
21AE19822CC7D517004DBCFC /* PropertyWrapper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PropertyWrapper.h; sourceTree = "<group>"; };
21AE19852CC7FF5F004DBCFC /* Group.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Group.h; sourceTree = "<group>"; };
21AE19862CC7FF5F004DBCFC /* Group.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Group.cpp; sourceTree = "<group>"; };
21AE198D2CC80541004DBCFC /* ArchicadGroupDBaseEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArchicadGroupDBaseEngine.h; sourceTree = "<group>"; };
21AE198E2CC80541004DBCFC /* ArchicadGroupDBaseEngine.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ArchicadGroupDBaseEngine.cpp; sourceTree = "<group>"; };
21AE19912CC82866004DBCFC /* BIMGroupDatabase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BIMGroupDatabase.cpp; sourceTree = "<group>"; };
21AE19922CC82866004DBCFC /* BIMGroupDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BIMGroupDatabase.h; sourceTree = "<group>"; };
21AEF9B32CA5F7CF000B8681 /* DetachedWrap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachedWrap.h; sourceTree = "<group>"; };
21AEF9B52CA5FA02000B8681 /* DetachedReference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachedReference.h; sourceTree = "<group>"; };
21AEF9B72CA5FCB6000B8681 /* DetachmentManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetachmentManager.h; sourceTree = "<group>"; };
@@ -635,6 +647,8 @@
21A890C12CC171D80087E732 /* Property */ = {
isa = PBXGroup;
children = (
21AE198E2CC80541004DBCFC /* ArchicadGroupDBaseEngine.cpp */,
21AE198D2CC80541004DBCFC /* ArchicadGroupDBaseEngine.h */,
21A890BF2CC171D80087E732 /* ArchicadPropertyDBaseEngine.cpp */,
21A890C02CC171D80087E732 /* ArchicadPropertyDBaseEngine.h */,
);
@@ -644,6 +658,8 @@
21AE194E2CC273F1004DBCFC /* Property */ = {
isa = PBXGroup;
children = (
21AE19862CC7FF5F004DBCFC /* Group.cpp */,
21AE19852CC7FF5F004DBCFC /* Group.h */,
21AE19672CC57832004DBCFC /* Propertied.cpp */,
21AE19682CC57832004DBCFC /* Propertied.h */,
21AE194A2CC273F1004DBCFC /* Property.cpp */,
@@ -713,6 +729,8 @@
2196F2F72CB51ED400450DFC /* BIMAttributeDatabase.h */,
215F08932CA19AF800CD343B /* BIMElementDatabase.cpp */,
215F08942CA19AF800CD343B /* BIMElementDatabase.h */,
21AE19912CC82866004DBCFC /* BIMGroupDatabase.cpp */,
21AE19922CC82866004DBCFC /* BIMGroupDatabase.h */,
21AE19632CC2F702004DBCFC /* BIMPropertyDatabase.cpp */,
21AE19642CC2F702004DBCFC /* BIMPropertyDatabase.h */,
21D0BD272C86FC350077E104 /* Content */,
@@ -897,6 +915,7 @@
21D0BD212C86F0280077E104 /* AccountDatabase.h in Headers */,
21A0FBB52CBA5E380023F24E /* Str256.h in Headers */,
210CC86F2C7E879700610F58 /* ArgumentBase.h in Headers */,
21AE19872CC7FF5F004DBCFC /* Group.h in Headers */,
210CC8A02C81E34400610F58 /* Platform.h in Headers */,
219246132CA34DCE00CF5703 /* Mesh.h in Headers */,
21A890CF2CC1B87C0087E732 /* GenericDrawingElement.h in Headers */,
@@ -930,11 +949,13 @@
215F08562C99DA8D00CD343B /* Project.h in Headers */,
219245FF2CA2CC4300CF5703 /* BIMRecord.h in Headers */,
210CC8802C80CD2A00610F58 /* BridgeChild.h in Headers */,
21AE198F2CC80541004DBCFC /* ArchicadGroupDBaseEngine.h in Headers */,
21D0BD4D2C8901A00077E104 /* ServerInfo.h in Headers */,
2196F3042CB57E8000450DFC /* Storey.h in Headers */,
21AE196F2CC64D37004DBCFC /* Classified.h in Headers */,
21AE19522CC273F1004DBCFC /* Property.h in Headers */,
21A0FBF92CBDB9A70023F24E /* BIMMemory.h in Headers */,
21AE19942CC82866004DBCFC /* BIMGroupDatabase.h in Headers */,
21AE19542CC273F1004DBCFC /* Template.h in Headers */,
21A0FBBC2CBBC04C0023F24E /* ArchicadRGB.h in Headers */,
21AE19842CC7D517004DBCFC /* PropertyWrapper.h in Headers */,
@@ -1083,6 +1104,7 @@
2196F2F02CB4823C00450DFC /* Attribute.cpp in Sources */,
21F69F612C6D0286008B6A06 /* GetBindingsMethodNames.cpp in Sources */,
215F08662C9B006800CD343B /* ProjectEvent.cpp in Sources */,
21AE19932CC82866004DBCFC /* BIMGroupDatabase.cpp in Sources */,
21D0BDBD2C90F2830077E104 /* DocStoreSubscriber.cpp in Sources */,
21AE197B2CC7CE1A004DBCFC /* PropsAndClassWrapper.cpp in Sources */,
21D0BDB32C8F8AB60077E104 /* DocumentStoreCore.cpp in Sources */,
@@ -1094,6 +1116,7 @@
21D0BD4E2C8901A00077E104 /* ServerInfo.cpp in Sources */,
21AE19512CC273F1004DBCFC /* Property.cpp in Sources */,
21B67D0E2C7E0E8D00FD64FC /* ErrorReport.cpp in Sources */,
21AE19902CC80541004DBCFC /* ArchicadGroupDBaseEngine.cpp in Sources */,
21AE19692CC57832004DBCFC /* Propertied.cpp in Sources */,
21F69F7E2C6FD9FC008B6A06 /* GetCallResult.cpp in Sources */,
2196F3052CB57E8000450DFC /* Storey.cpp in Sources */,
@@ -1127,6 +1150,7 @@
21A890D12CC1B87C0087E732 /* GenericModelElement.cpp in Sources */,
21AEF9BC2CA6DF84000B8681 /* DetachmentManager.cpp in Sources */,
215F08552C99DA8D00CD343B /* Project.cpp in Sources */,
21AE19882CC7FF5F004DBCFC /* Group.cpp in Sources */,
21F69F3B2C6B880C008B6A06 /* JSBaseTransport.cpp in Sources */,
2196F2EB2CB4816B00450DFC /* ArchicadAttributeDBaseEngine.cpp in Sources */,
21AE19532CC273F1004DBCFC /* Template.cpp in Sources */,