mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
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:
@@ -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<uint32_t, IfcUtil::IfcBaseClass*> 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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
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");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user