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.
This commit is contained in:
Andrej730
2024-03-21 17:42:01 +05:00
parent 424b2589d9
commit 9a13e4de5c
3 changed files with 20 additions and 1 deletions
+3 -1
View File
@@ -122,9 +122,9 @@ public:
static bool guid_map() { return guid_map_; } static bool guid_map() { return guid_map_; }
static void guid_map(bool b) { guid_map_ = b; } static void guid_map(bool b) { guid_map_ = b; }
private:
typedef std::map<uint32_t, IfcUtil::IfcBaseClass*> entity_entity_map_t; typedef std::map<uint32_t, IfcUtil::IfcBaseClass*> entity_entity_map_t;
private:
bool parsing_complete_; bool parsing_complete_;
file_open_status good_ = file_open_status::SUCCESS; file_open_status good_ = file_open_status::SUCCESS;
@@ -276,6 +276,8 @@ public:
void recalculate_id_counter(); void recalculate_id_counter();
entity_entity_map_t getEntityFileMapCopy() const;
IfcUtil::IfcBaseClass* addEntity(IfcUtil::IfcBaseClass* entity, int id=-1); IfcUtil::IfcBaseClass* addEntity(IfcUtil::IfcBaseClass* entity, int id=-1);
void addEntities(aggregate_of_instance::ptr es); void addEntities(aggregate_of_instance::ptr es);
+8
View File
@@ -1839,6 +1839,14 @@ void IfcFile::addEntities(aggregate_of_instance::ptr es) {
} }
} }
IfcFile::entity_entity_map_t IfcFile::getEntityFileMapCopy() const {
std::map<uint32_t, IfcUtil::IfcBaseClass*> 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) { IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity, int id) {
if (id != -1 && byid.find((unsigned)id) != byid.end()) { if (id != -1 && byid.find((unsigned)id) != byid.end()) {
throw IfcParse::IfcException("An instance with id " + boost::lexical_cast<std::string>(id) + " is already part of this file"); throw IfcParse::IfcException("An instance with id " + boost::lexical_cast<std::string>(id) + " is already part of this file");
+9
View File
@@ -593,6 +593,15 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
return f; 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() { const char* version() {
return IFCOPENSHELL_VERSION; return IFCOPENSHELL_VERSION;
} }