Added lookup for AC storeys using an element floor index

This commit is contained in:
Ralph Wessel
2024-10-10 13:02:57 +01:00
parent f7112a407c
commit cc64d7df44
7 changed files with 90 additions and 6 deletions
@@ -140,4 +140,16 @@ std::optional<API_Attribute> BIMAttributeDatabase::getAPIData(const BIMLink& lin
std::optional<API_StoryType> BIMAttributeDatabase::getAPIStorey(const BIMLink& link) const {
return m_engine->getAPIStorey(link);
} //BIMAttributeDatabase::getAPIData
/*--------------------------------------------------------------------
Get the ID of a storey from a specified index
index: The storey index
return: The storey ID (nullopt on failure)
--------------------------------------------------------------------*/
std::optional<BIMRecordID> BIMAttributeDatabase::getStoreyID(short index) const {
return m_engine->getStoreyID(index);
} //BIMAttributeDatabase::getStoreyID
#endif
@@ -80,6 +80,12 @@ namespace speckle::database {
@return The AC API storey data
*/
std::optional<API_StoryType> getAPIStorey(const BIMLink& link) const;
/*!
Get the ID of a storey from a specified index
@param index The storey index
@return The storey ID (nullopt on failure)
*/
std::optional<BIMRecordID> getStoreyID(short index) const;
#endif
private:
@@ -3,6 +3,7 @@
#include "Active/Setting/Values/Measurement/Units/LengthUnit.h"
#include "Speckle/Database/Content/Record.h"
#include "Speckle/Database/Identity/BIMIndex.h"
#include "Speckle/Database/Identity/BIMLink.h"
#include "Speckle/Database/Identity/BIMRecordID.h"
@@ -94,12 +95,22 @@ namespace speckle::database {
Set to the default package content
*/
void setDefault() override;
protected:
/*!
Reset the BIM index (used in lazy loading contexts where the index cannot otherwise be established)
@param index The BIM application index
*/
void resetIndex(const BIMIndex& index) const {
m_applicationID = index;
m_applicationTableID = index.tableID;
}
private:
///The BIM application record ID
BIMRecordID m_applicationID;
mutable BIMRecordID m_applicationID;
///The BIM application parent table ID
BIMRecordID m_applicationTableID;
mutable BIMRecordID m_applicationTableID;
///The BIM record unit of length measurement
std::optional<active::measure::LengthType> m_unit = active::measure::LengthType::metre;
};
@@ -279,4 +279,19 @@ std::optional<API_StoryType> ArchicadAttributeDBaseEngine::getAPIStorey(const BI
return std::nullopt;
} //ArchicadAttributeDBaseEngine::getAPIStorey
/*--------------------------------------------------------------------
Get the ID of a storey from a specified index
index: The storey index
return: The storey ID (nullopt on failure)
--------------------------------------------------------------------*/
std::optional<BIMRecordID> ArchicadAttributeDBaseEngine::getStoreyID(short index) const {
if (!m_storeyCache)
m_storeyCache = std::make_unique<StoreyCache>();
if (auto iter = m_storeyCache->find(index); iter != m_storeyCache->end())
return Guid::fromInt(iter->floorId);
return std::nullopt;
} //ArchicadAttributeDBaseEngine::getStoreyID
#endif
@@ -127,6 +127,12 @@ namespace speckle::database {
@return The AC API storey data
*/
std::optional<API_StoryType> getAPIStorey(const BIMLink& link) const;
/*!
Get the ID of a storey from a specified index
@param index The storey index
@return The storey ID (nullopt on failure)
*/
std::optional<BIMRecordID> getStoreyID(short index) const;
#endif
private:
+30 -4
View File
@@ -69,6 +69,18 @@ Storey::Storey() {
} //Storey::Storey
#ifdef ARCHICAD
/*--------------------------------------------------------------------
Constructor
index: An index into the Archicad storey array
--------------------------------------------------------------------*/
Storey::Storey(short index) {
} //Storey::Storey
#endif
/*--------------------------------------------------------------------
Constructor
@@ -172,21 +184,35 @@ void Storey::setDefault() {
void Storey::confirmData() const {
if (m_data)
return;
#ifdef ARCHICAD
m_data = std::make_unique<Data>(getStoreyData());
#endif
} //Storey::confirmData
#ifdef ARCHICAD
/*--------------------------------------------------------------------
Get the storey data from the host BIM application
return: The storey data (for internal use to populate derived classes)
--------------------------------------------------------------------*/
API_StoryType Storey::getStoreyData() const {
if (auto project = addon()->getActiveProject().lock(); project) {
if (auto storey = project->getAttributeDatabase()->getAPIStorey(getBIMLink()); storey)
return *storey;
}
do {
if (auto project = addon()->getActiveProject().lock(); project) {
auto attributeDatabase = project->getAttributeDatabase();
if (m_storeyIndex) {
auto storeyID = attributeDatabase->getStoreyID(*m_storeyIndex);
m_storeyIndex.reset();
if (!storeyID)
break;
resetIndex({Attribute::storeyTableID, Attribute::storeyTableID});
}
if (auto storey = attributeDatabase->getAPIStorey(getBIMLink()); storey)
return *storey;
}
} while (false);
API_StoryType storey;
active::utility::Memory::erase(storey);
return storey;
} //Storey::getStoreyData
#endif
@@ -37,6 +37,11 @@ namespace speckle::record::attribute {
*/
Storey(const database::BIMRecordID& ID);
#ifdef ARCHICAD
/*!
Constructor
@param index An index into the Archicad storey array
*/
Storey(short index);
/*!
Constructor
@param attrData Archicad attribute data
@@ -117,6 +122,9 @@ namespace speckle::record::attribute {
@return The storey data (for internal use to populate derived classes)
*/
API_StoryType getStoreyData() const;
///An index into the Archicad storey array - used temporarily for looking up the storey data on demand
mutable std::optional<short> m_storeyIndex;
#endif
class Data;