From 9a13e4de5cf73f7ba2adfc67a19a94ce4c90c041 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 21 Mar 2024 17:42:01 +0500 Subject: [PATCH] expose ifc file identity to entity mapping to python api Can be useful for debugging or identifying entities that were already added to the ifc file. E.g. if entity was added before and adding it again won't update it but with identity map it's possible to know that entity will need to be updated manually. --- src/ifcparse/IfcFile.h | 4 +++- src/ifcparse/IfcParse.cpp | 8 ++++++++ src/ifcwrap/IfcParseWrapper.i | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ifcparse/IfcFile.h b/src/ifcparse/IfcFile.h index 88bed3c065..e88c637e17 100644 --- a/src/ifcparse/IfcFile.h +++ b/src/ifcparse/IfcFile.h @@ -122,9 +122,9 @@ public: static bool guid_map() { return guid_map_; } static void guid_map(bool b) { guid_map_ = b; } -private: typedef std::map entity_entity_map_t; +private: bool parsing_complete_; file_open_status good_ = file_open_status::SUCCESS; @@ -276,6 +276,8 @@ public: void recalculate_id_counter(); + entity_entity_map_t getEntityFileMapCopy() const; + IfcUtil::IfcBaseClass* addEntity(IfcUtil::IfcBaseClass* entity, int id=-1); void addEntities(aggregate_of_instance::ptr es); diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index d0ccb44aa6..d9d49fe164 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1839,6 +1839,14 @@ void IfcFile::addEntities(aggregate_of_instance::ptr es) { } } +IfcFile::entity_entity_map_t IfcFile::getEntityFileMapCopy() const { + std::map copy_map; + for (const auto& pair : entity_file_map) { + copy_map[pair.first] = pair.second; + } + return copy_map; +} + IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id) { if (id != -1 && byid.find((unsigned)id) != byid.end()) { throw IfcParse::IfcException("An instance with id " + boost::lexical_cast(id) + " is already part of this file"); diff --git a/src/ifcwrap/IfcParseWrapper.i b/src/ifcwrap/IfcParseWrapper.i index b9fcd5aadd..308f334772 100644 --- a/src/ifcwrap/IfcParseWrapper.i +++ b/src/ifcwrap/IfcParseWrapper.i @@ -593,6 +593,15 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas return f; } + PyObject* get_identity_mapping(IfcParse::IfcFile* f) { + PyObject* pyDict = PyDict_New(); + for (const auto& pair : f->getEntityFileMapCopy()) { + PyDict_SetItem(pyDict, pythonize(pair.first), pythonize(pair.second)); + } + + return pyDict; + } + const char* version() { return IFCOPENSHELL_VERSION; }