Skip to content

Commit e5c20a0

Browse files
committed
Add convenience method for relating objects to types. As suggested by Cadline St2.
1 parent b590747 commit e5c20a0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/examples/IfcOpenHouse.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ int main(int argc, char** argv) {
381381
file.setSurfaceColour(door->Representation(), 0.9, 0.9, 0.9);
382382
file.addEntity(new IfcSchema::IfcRelFillsElement(guid(), file.getSingle<IfcSchema::IfcOwnerHistory>(), null, null, door_opening, door));
383383

384+
IfcSchema::IfcDoorStyle* door_style = new IfcSchema::IfcDoorStyle(guid(), file.getSingle<IfcSchema::IfcOwnerHistory>(), S("Door type"), null, null, null, null, null,
385+
IfcSchema::IfcDoorStyleOperationEnum::IfcDoorStyleOperation_SINGLE_SWING_LEFT, IfcSchema::IfcDoorStyleConstructionEnum::IfcDoorStyleConstruction_WOOD, false, false);
386+
file.addRelatedObject<IfcSchema::IfcRelDefinesByType>(door_style, door);
387+
384388
// Surface styles are assigned to representation items, hence there is no real limitation to
385389
// assign different colours within the same representation. However, some viewers have
386390
// difficulties rendering products with representation items with different surface styles.

src/ifcparse/IfcHierarchyHelper.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,36 @@ inline void IfcHierarchyHelper::addRelatedObject <IfcSchema::IfcRelContainedInSp
205205
}
206206
}
207207

208+
template <>
209+
inline void IfcHierarchyHelper::addRelatedObject <IfcSchema::IfcRelDefinesByType> (IfcSchema::IfcObjectDefinition* relating_type,
210+
IfcSchema::IfcObjectDefinition* related_object, IfcSchema::IfcOwnerHistory* owner_hist)
211+
{
212+
IfcSchema::IfcRelDefinesByType::list::ptr li = entitiesByType<IfcSchema::IfcRelDefinesByType>();
213+
bool found = false;
214+
for (IfcSchema::IfcRelDefinesByType::list::it i = li->begin(); i != li->end(); ++i) {
215+
IfcSchema::IfcRelDefinesByType* rel = *i;
216+
if (rel->RelatingType() == relating_type) {
217+
IfcSchema::IfcObject::list::ptr objects = rel->RelatedObjects();
218+
objects->push((IfcSchema::IfcObject*)related_object);
219+
rel->setRelatedObjects(objects);
220+
found = true;
221+
break;
222+
}
223+
}
224+
if (! found) {
225+
if (! owner_hist) {
226+
owner_hist = getSingle<IfcSchema::IfcOwnerHistory>();
227+
}
228+
if (! owner_hist) {
229+
owner_hist = addOwnerHistory();
230+
}
231+
IfcSchema::IfcObject::list::ptr related_objects (new IfcTemplatedEntityList<IfcSchema::IfcObject>());
232+
related_objects->push((IfcSchema::IfcObject*)related_object);
233+
IfcSchema::IfcRelDefinesByType* t = new IfcSchema::IfcRelDefinesByType(IfcParse::IfcGlobalId(), owner_hist,
234+
boost::none, boost::none, related_objects, (IfcSchema::IfcTypeObject*)relating_type);
235+
236+
addEntity(t);
237+
}
238+
}
239+
208240
#endif

0 commit comments

Comments
 (0)