From 8b50f1bcd67e4830e5cc3de92cd55ab05209d4d4 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 7 Feb 2024 16:56:06 +0500 Subject: [PATCH] Fix bug in `IfcHierarchyHelper.addRelatedObject` Noticed that `file.addRelatedObject(door_style, door);` was resulting in list with `door` assigned as RelatingObject and `door_style` assigned as RelatedObjects. --- src/examples/IfcOpenHouse.cpp | 2 ++ src/ifcparse/IfcHierarchyHelper.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/examples/IfcOpenHouse.cpp b/src/examples/IfcOpenHouse.cpp index 189dd4320e..463ec74261 100644 --- a/src/examples/IfcOpenHouse.cpp +++ b/src/examples/IfcOpenHouse.cpp @@ -411,6 +411,8 @@ int main() { IfcSchema::IfcDoorStyle* door_style = new IfcSchema::IfcDoorStyle(guid(), file.getSingle(), "Door type"s, null, null, null, null, null, IfcSchema::IfcDoorStyleOperationEnum::IfcDoorStyleOperation_SINGLE_SWING_LEFT, IfcSchema::IfcDoorStyleConstructionEnum::IfcDoorStyleConstruction_WOOD, false, false); + // NOTE: typing by IfcDoorStyle will cause validation errors in IFC4+ but it's allowed for backwards compatibility + // better to use IfcDoorType in the actual use case file.addRelatedObject(door_style, door); // Surface styles are assigned to representation items, hence there is no real limitation to diff --git a/src/ifcparse/IfcHierarchyHelper.h b/src/ifcparse/IfcHierarchyHelper.h index 006c25391b..7f0527347f 100644 --- a/src/ifcparse/IfcHierarchyHelper.h +++ b/src/ifcparse/IfcHierarchyHelper.h @@ -436,13 +436,13 @@ public: { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(IfcParse::IfcGlobalId()); data->setArgument(0, attr); } { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(owner_hist); data->setArgument(1, attr); } int relating_index = 4, related_index = 5; - if (T::Class().name() == "IfcRelContainedInSpatialStructure") { - // IfcRelContainedInSpatialStructure has attributes reversed. + if (T::Class().name() == "IfcRelContainedInSpatialStructure" || std::is_base_of::value) { + // some classes have attributes reversed. std::swap(relating_index, related_index); } { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(relating_object); data->setArgument(relating_index, attr); } { IfcWrite::IfcWriteArgument* attr = new IfcWrite::IfcWriteArgument(); attr->set(related_objects); data->setArgument(related_index, attr); } - + T* t = (T*)Schema::get_schema().instantiate(data); addEntity(t); }