From e5c20a009d10f2ea402639a4004c8f4ebdc2f4aa Mon Sep 17 00:00:00 2001 From: aothms Date: Sat, 12 Sep 2015 14:27:58 +0200 Subject: [PATCH] Add convenience method for relating objects to types. As suggested by Cadline St2. --- src/examples/IfcOpenHouse.cpp | 4 ++++ src/ifcparse/IfcHierarchyHelper.h | 32 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/examples/IfcOpenHouse.cpp b/src/examples/IfcOpenHouse.cpp index 5cfb523f63..9f4887c5f9 100644 --- a/src/examples/IfcOpenHouse.cpp +++ b/src/examples/IfcOpenHouse.cpp @@ -381,6 +381,10 @@ int main(int argc, char** argv) { file.setSurfaceColour(door->Representation(), 0.9, 0.9, 0.9); file.addEntity(new IfcSchema::IfcRelFillsElement(guid(), file.getSingle(), null, null, door_opening, door)); + IfcSchema::IfcDoorStyle* door_style = new IfcSchema::IfcDoorStyle(guid(), file.getSingle(), S("Door type"), null, null, null, null, null, + IfcSchema::IfcDoorStyleOperationEnum::IfcDoorStyleOperation_SINGLE_SWING_LEFT, IfcSchema::IfcDoorStyleConstructionEnum::IfcDoorStyleConstruction_WOOD, false, false); + file.addRelatedObject(door_style, door); + // Surface styles are assigned to representation items, hence there is no real limitation to // assign different colours within the same representation. However, some viewers have // difficulties rendering products with representation items with different surface styles. diff --git a/src/ifcparse/IfcHierarchyHelper.h b/src/ifcparse/IfcHierarchyHelper.h index f5d52b62ce..7a1393632b 100644 --- a/src/ifcparse/IfcHierarchyHelper.h +++ b/src/ifcparse/IfcHierarchyHelper.h @@ -205,4 +205,36 @@ inline void IfcHierarchyHelper::addRelatedObject +inline void IfcHierarchyHelper::addRelatedObject (IfcSchema::IfcObjectDefinition* relating_type, + IfcSchema::IfcObjectDefinition* related_object, IfcSchema::IfcOwnerHistory* owner_hist) +{ + IfcSchema::IfcRelDefinesByType::list::ptr li = entitiesByType(); + bool found = false; + for (IfcSchema::IfcRelDefinesByType::list::it i = li->begin(); i != li->end(); ++i) { + IfcSchema::IfcRelDefinesByType* rel = *i; + if (rel->RelatingType() == relating_type) { + IfcSchema::IfcObject::list::ptr objects = rel->RelatedObjects(); + objects->push((IfcSchema::IfcObject*)related_object); + rel->setRelatedObjects(objects); + found = true; + break; + } + } + if (! found) { + if (! owner_hist) { + owner_hist = getSingle(); + } + if (! owner_hist) { + owner_hist = addOwnerHistory(); + } + IfcSchema::IfcObject::list::ptr related_objects (new IfcTemplatedEntityList()); + related_objects->push((IfcSchema::IfcObject*)related_object); + IfcSchema::IfcRelDefinesByType* t = new IfcSchema::IfcRelDefinesByType(IfcParse::IfcGlobalId(), owner_hist, + boost::none, boost::none, related_objects, (IfcSchema::IfcTypeObject*)relating_type); + + addEntity(t); + } +} + #endif \ No newline at end of file