@@ -53,12 +53,12 @@ IfcSchema::IfcAxis2Placement2D* IfcHierarchyHelper::addPlacement2d(
5353 return p2d;
5454}
5555
56- IfcSchema::IfcLocalPlacement* IfcHierarchyHelper::addLocalPlacement (
56+ IfcSchema::IfcLocalPlacement* IfcHierarchyHelper::addLocalPlacement (IfcSchema::IfcObjectPlacement* parent,
5757 double ox, double oy, double oz,
5858 double zx, double zy, double zz,
5959 double xx, double xy, double xz)
6060{
61- IfcSchema::IfcLocalPlacement* lp = new IfcSchema::IfcLocalPlacement (0 ,
61+ IfcSchema::IfcLocalPlacement* lp = new IfcSchema::IfcLocalPlacement (parent ,
6262 addPlacement3d (ox, oy, oz, zx, zy, zz, xx, xy, xz));
6363
6464 AddEntity (lp);
@@ -78,7 +78,7 @@ IfcSchema::IfcOwnerHistory* IfcHierarchyHelper::addOwnerHistory() {
7878
7979 int timestamp = (int ) time (0 );
8080 IfcSchema::IfcOwnerHistory* owner_hist = new IfcSchema::IfcOwnerHistory (person_and_org, application,
81- boost::none, IfcSchema::IfcChangeActionEnum::IfcChangeAction_ADDED, boost::none , person_and_org, application, timestamp);
81+ boost::none, IfcSchema::IfcChangeActionEnum::IfcChangeAction_ADDED, timestamp , person_and_org, application, timestamp);
8282
8383 AddEntity (person);
8484 AddEntity (organization);
@@ -91,10 +91,6 @@ IfcSchema::IfcOwnerHistory* IfcHierarchyHelper::addOwnerHistory() {
9191
9292IfcSchema::IfcProject* IfcHierarchyHelper::addProject (IfcSchema::IfcOwnerHistory* owner_hist) {
9393 IfcSchema::IfcRepresentationContext::list::ptr rep_contexts (new IfcSchema::IfcRepresentationContext::list);
94- IfcSchema::IfcGeometricRepresentationContext* rep_context = new IfcSchema::IfcGeometricRepresentationContext (
95- std::string (" Plan" ), std::string (" Model" ), 3 , 1e-5 , addPlacement3d (), addTriplet<IfcSchema::IfcDirection>(0 , 1 , 0 ));
96-
97- rep_contexts->push (rep_context);
9894
9995 IfcEntityList::ptr units (new IfcEntityList);
10096 IfcSchema::IfcDimensionalExponents* dimexp = new IfcSchema::IfcDimensionalExponents (0 , 0 , 0 , 0 , 0 , 0 , 0 );
@@ -115,7 +111,6 @@ IfcSchema::IfcProject* IfcHierarchyHelper::addProject(IfcSchema::IfcOwnerHistory
115111 IfcSchema::IfcProject* project = new IfcSchema::IfcProject (IfcWrite::IfcGuidHelper (), owner_hist, boost::none, boost::none,
116112 boost::none, boost::none, boost::none, rep_contexts, unit_assignment);
117113
118- AddEntity (rep_context);
119114 AddEntity (dimexp);
120115 AddEntity (unit1);
121116 AddEntity (unit2a);
@@ -227,8 +222,24 @@ IfcSchema::IfcBuildingStorey* IfcHierarchyHelper::addBuildingProduct(IfcSchema::
227222 storey = addBuildingStorey (0 , owner_hist);
228223 }
229224 AddEntity (product);
230- addRelatedObject<IfcSchema::IfcRelContainedInSpatialStructure>(storey, product);
231- relatePlacements (storey, product);
225+ // CV-2x3-158: Don't add decompositions directly to a building storey
226+ bool is_decomposition = false ;
227+ #ifdef USE_IFC4
228+ IfcSchema::IfcRelAggregates::list::ptr decomposes = product->Decomposes ();
229+ for (IfcSchema::IfcRelAggregates::list::it it = decomposes->begin (); it != decomposes->end (); ++it) {
230+ #else
231+ IfcSchema::IfcRelDecomposes::list::ptr decomposes = product->Decomposes ();
232+ for (IfcSchema::IfcRelDecomposes::list::it it = decomposes->begin (); it != decomposes->end (); ++it) {
233+ #endif
234+ if ((*it)->RelatingObject () != product) {
235+ is_decomposition = true ;
236+ break ;
237+ }
238+ }
239+ if (!is_decomposition) {
240+ addRelatedObject<IfcSchema::IfcRelContainedInSpatialStructure>(storey, product);
241+ relatePlacements (storey, product);
242+ }
232243 return storey;
233244}
234245
@@ -265,7 +276,7 @@ IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addExtrudedPolyline(co
265276 IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
266277 IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation (context
267278 ? context
268- : getSingle<IfcSchema::IfcRepresentationContext>( ), std::string (" Body" ), std::string (" SweptSolid" ), items);
279+ : getRepresentationContext ( " Model " ), std::string (" Body" ), std::string (" SweptSolid" ), items);
269280 reps->push (rep);
270281 IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape (0 , 0 , reps);
271282 AddEntity (rep);
@@ -301,13 +312,26 @@ void IfcHierarchyHelper::addBox(IfcSchema::IfcShapeRepresentation* rep, double w
301312 }
302313}
303314
315+ void IfcHierarchyHelper::addAxis (IfcSchema::IfcShapeRepresentation* rep, double l, IfcSchema::IfcRepresentationContext* context) {
316+ IfcSchema::IfcCartesianPoint* p1 = addDoublet<IfcSchema::IfcCartesianPoint>(-l / 2 ., 0 .);
317+ IfcSchema::IfcCartesianPoint* p2 = addDoublet<IfcSchema::IfcCartesianPoint>(+l / 2 ., 0 .);
318+ IfcSchema::IfcCartesianPoint::list::ptr pts (new IfcSchema::IfcCartesianPoint::list);
319+ pts->push (p1); pts->push (p2);
320+ IfcSchema::IfcPolyline* poly = new IfcSchema::IfcPolyline (pts);
321+ AddEntity (poly);
322+
323+ IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items ();
324+ items->push (poly);
325+ rep->setItems (items);
326+ }
327+
304328IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addBox (double w, double d, double h, IfcSchema::IfcAxis2Placement2D* place,
305329 IfcSchema::IfcAxis2Placement3D* place2, IfcSchema::IfcDirection* dir, IfcSchema::IfcRepresentationContext* context)
306330{
307331 IfcSchema::IfcRepresentation::list::ptr reps (new IfcSchema::IfcRepresentation::list);
308332 IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
309333 IfcSchema::IfcShapeRepresentation* rep = new IfcSchema::IfcShapeRepresentation (
310- context ? context : getSingle<IfcSchema::IfcRepresentationContext>( ), std::string (" Body" ), std::string (" SweptSolid" ), items);
334+ context ? context : getRepresentationContext ( " Model " ), std::string (" Body" ), std::string (" SweptSolid" ), items);
311335 reps->push (rep);
312336 IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape (0 , 0 , reps);
313337 AddEntity (rep);
@@ -316,34 +340,61 @@ IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addBox(double w, doubl
316340 return shape;
317341}
318342
343+ IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addAxisBox (double w, double d, double h, IfcSchema::IfcRepresentationContext* context)
344+ {
345+ IfcSchema::IfcRepresentation::list::ptr reps (new IfcSchema::IfcRepresentation::list);
346+ IfcSchema::IfcRepresentationItem::list::ptr body_items (new IfcSchema::IfcRepresentationItem::list);
347+ IfcSchema::IfcRepresentationItem::list::ptr axis_items (new IfcSchema::IfcRepresentationItem::list);
348+ IfcSchema::IfcShapeRepresentation* body_rep = new IfcSchema::IfcShapeRepresentation (
349+ context ? context : getRepresentationContext (" Model" ), std::string (" Body" ), std::string (" SweptSolid" ), body_items);
350+
351+ IfcSchema::IfcShapeRepresentation* axis_rep = new IfcSchema::IfcShapeRepresentation (
352+ context ? context : getRepresentationContext (" Plan" ), std::string (" Axis" ), std::string (" Curve2D" ), axis_items);
353+
354+ reps->push (axis_rep);
355+ reps->push (body_rep);
356+
357+ IfcSchema::IfcProductDefinitionShape* shape = new IfcSchema::IfcProductDefinitionShape (0 , 0 , reps);
358+ AddEntity (shape);
359+ AddEntity (body_rep);
360+ addBox (body_rep, w, d, h, 0 , 0 , 0 , context);
361+ AddEntity (axis_rep);
362+ addAxis (axis_rep, w);
363+
364+ return shape;
365+ }
366+
319367void IfcHierarchyHelper::clipRepresentation (IfcSchema::IfcProductRepresentation* shape,
320368 IfcSchema::IfcAxis2Placement3D* place, bool agree)
321369{
322- IfcSchema::IfcPlane* plane = new IfcSchema::IfcPlane (place);
323- IfcSchema::IfcHalfSpaceSolid* half_space = new IfcSchema::IfcHalfSpaceSolid (plane, agree);
324370 IfcSchema::IfcRepresentation::list::ptr reps = shape->Representations ();
325371 for (IfcSchema::IfcRepresentation::list::it j = reps->begin (); j != reps->end (); ++j) {
326- IfcSchema::IfcRepresentation* rep = *j;
327- if (rep->RepresentationIdentifier () != " Body" ) continue ;
328- rep->setRepresentationType (" Clipping" );
329- IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items ();
330- IfcSchema::IfcRepresentationItem::list::ptr new_items (new IfcSchema::IfcRepresentationItem::list);
331- AddEntity (plane);
332- AddEntity (half_space);
333- for (IfcSchema::IfcRepresentationItem::list::it i = items->begin (); i != items->end (); ++i) {
334- IfcSchema::IfcRepresentationItem* item = *i;
335- IfcSchema::IfcBooleanClippingResult* clip = new IfcSchema::IfcBooleanClippingResult (
336- IfcSchema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE, item, half_space);
337- AddEntity (clip);
338- new_items->push (clip);
339- }
340- rep->setItems (new_items);
372+ clipRepresentation (*j, place, agree);
341373 }
342374}
343375
344- IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::setSurfaceColour (
345- IfcSchema::IfcProductRepresentation* shape, double r, double g, double b, double a )
376+ void IfcHierarchyHelper::clipRepresentation (IfcSchema::IfcRepresentation* rep,
377+ IfcSchema::IfcAxis2Placement3D* place, bool agree )
346378{
379+ if (rep->RepresentationIdentifier () != " Body" ) return ;
380+ IfcSchema::IfcPlane* plane = new IfcSchema::IfcPlane (place);
381+ IfcSchema::IfcHalfSpaceSolid* half_space = new IfcSchema::IfcHalfSpaceSolid (plane, agree);
382+ AddEntity (plane);
383+ AddEntity (half_space);
384+ rep->setRepresentationType (" Clipping" );
385+ IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items ();
386+ IfcSchema::IfcRepresentationItem::list::ptr new_items (new IfcSchema::IfcRepresentationItem::list);
387+ for (IfcSchema::IfcRepresentationItem::list::it i = items->begin (); i != items->end (); ++i) {
388+ IfcSchema::IfcRepresentationItem* item = *i;
389+ IfcSchema::IfcBooleanClippingResult* clip = new IfcSchema::IfcBooleanClippingResult (
390+ IfcSchema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE, item, half_space);
391+ AddEntity (clip);
392+ new_items->push (clip);
393+ }
394+ rep->setItems (new_items);
395+ }
396+
397+ IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::addStyleAssignment (double r, double g, double b, double a) {
347398 IfcSchema::IfcColourRgb* colour = new IfcSchema::IfcColourRgb (boost::none, r, g, b);
348399 IfcSchema::IfcSurfaceStyleRendering* rendering = a == 1.0
349400 ? new IfcSchema::IfcSurfaceStyleRendering (colour, boost::none, boost::none, boost::none, boost::none, boost::none,
@@ -363,28 +414,120 @@ IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::setSurfaceColour(
363414 AddEntity (rendering);
364415 AddEntity (surface_style);
365416 AddEntity (style_assignment);
417+ return style_assignment;
418+ }
419+
420+ IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::setSurfaceColour (
421+ IfcSchema::IfcProductRepresentation* shape, double r, double g, double b, double a)
422+ {
423+ IfcSchema::IfcPresentationStyleAssignment* style_assignment = addStyleAssignment (r, g, b, a);
424+ setSurfaceColour (shape, style_assignment);
425+ return style_assignment;
426+ }
427+
428+ IfcSchema::IfcPresentationStyleAssignment* IfcHierarchyHelper::setSurfaceColour (
429+ IfcSchema::IfcRepresentation* shape, double r, double g, double b, double a)
430+ {
431+ IfcSchema::IfcPresentationStyleAssignment* style_assignment = addStyleAssignment (r, g, b, a);
366432 setSurfaceColour (shape, style_assignment);
367433 return style_assignment;
368434}
369435
370436void IfcHierarchyHelper::setSurfaceColour (IfcSchema::IfcProductRepresentation* shape,
371437 IfcSchema::IfcPresentationStyleAssignment* style_assignment)
438+ {
439+ IfcSchema::IfcRepresentation::list::ptr reps = shape->Representations ();
440+ for (IfcSchema::IfcRepresentation::list::it j = reps->begin (); j != reps->end (); ++j) {
441+ setSurfaceColour (*j, style_assignment);
442+ }
443+ }
444+
445+ void IfcHierarchyHelper::setSurfaceColour (IfcSchema::IfcRepresentation* rep,
446+ IfcSchema::IfcPresentationStyleAssignment* style_assignment)
372447{
373448#ifdef USE_IFC4
374449 IfcEntityList::ptr style_assignments (new IfcEntityList);
375450#else
376451 IfcSchema::IfcPresentationStyleAssignment::list::ptr style_assignments (new IfcSchema::IfcPresentationStyleAssignment::list);
377452#endif
378453 style_assignments->push (style_assignment);
379- IfcSchema::IfcRepresentation::list::ptr reps = shape->Representations ();
380- for (IfcSchema::IfcRepresentation::list::it j = reps->begin (); j != reps->end (); ++j) {
381- IfcSchema::IfcRepresentation* rep = *j;
382- if (rep->RepresentationIdentifier () != " Body" && rep->RepresentationIdentifier () != " Facetation" ) continue ;
383- IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items ();
384- for (IfcSchema::IfcRepresentationItem::list::it i = items->begin (); i != items->end (); ++i) {
385- IfcSchema::IfcRepresentationItem* item = *i;
386- IfcSchema::IfcStyledItem* styled_item = new IfcSchema::IfcStyledItem (item, style_assignments, boost::none);
387- AddEntity (styled_item);
388- }
454+ IfcSchema::IfcRepresentationItem::list::ptr items = rep->Items ();
455+ for (IfcSchema::IfcRepresentationItem::list::it i = items->begin (); i != items->end (); ++i) {
456+ IfcSchema::IfcRepresentationItem* item = *i;
457+ IfcSchema::IfcStyledItem* styled_item = new IfcSchema::IfcStyledItem (item, style_assignments, boost::none);
458+ AddEntity (styled_item);
389459 }
390460}
461+
462+ IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addMappedItem (
463+ IfcSchema::IfcShapeRepresentation* rep,
464+ IfcSchema::IfcCartesianTransformationOperator3D* transform,
465+ IfcSchema::IfcProductDefinitionShape* def)
466+ {
467+ IfcSchema::IfcRepresentationMap::list::ptr maps = rep->RepresentationMap ();
468+ IfcSchema::IfcRepresentationMap* map;
469+ if (maps->Size () == 1 ) {
470+ map = *maps->begin ();
471+ } else {
472+ map = new IfcSchema::IfcRepresentationMap (addPlacement3d (), rep);
473+ AddEntity (map);
474+ }
475+
476+ IfcSchema::IfcRepresentation::list::ptr representations (new IfcSchema::IfcRepresentation::list);
477+ if (def) representations = def->Representations ();
478+
479+ if (!transform) {
480+ transform = new IfcSchema::IfcCartesianTransformationOperator3D (0 , 0 , addTriplet<IfcSchema::IfcCartesianPoint>(0 ,0 ,0 ), boost::none, 0 );
481+ AddEntity (transform);
482+ }
483+ IfcSchema::IfcMappedItem* item = new IfcSchema::IfcMappedItem (map, transform);
484+ IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
485+ items->push (item);
486+ IfcSchema::IfcRepresentation* new_rep = new IfcSchema::IfcShapeRepresentation (rep->ContextOfItems (), boost::none, std::string (" MappedRepresentation" ), items);
487+ if (rep->hasRepresentationIdentifier ()) {
488+ new_rep->setRepresentationIdentifier (rep->RepresentationIdentifier ());
489+ }
490+ AddEntity (item);
491+ AddEntity (new_rep);
492+ representations->push (new_rep);
493+ if (!def) {
494+ def = new IfcSchema::IfcProductDefinitionShape (boost::none, boost::none, representations);
495+ AddEntity (def);
496+ } else {
497+ def->setRepresentations (representations);
498+ }
499+ return def;
500+ }
501+
502+ IfcSchema::IfcProductDefinitionShape* IfcHierarchyHelper::addMappedItem (
503+ IfcSchema::IfcShapeRepresentation::list::ptr reps,
504+ IfcSchema::IfcCartesianTransformationOperator3D* transform)
505+ {
506+ IfcSchema::IfcProductDefinitionShape* def = 0 ;
507+ for (IfcSchema::IfcShapeRepresentation::list::it it = reps->begin (); it != reps->end (); ++it) {
508+ def = addMappedItem (*it, transform, def);
509+ }
510+ return def;
511+ }
512+
513+ IfcSchema::IfcShapeRepresentation* IfcHierarchyHelper::addEmptyRepresentation (const std::string& repid, const std::string& reptype) {
514+ IfcSchema::IfcRepresentationItem::list::ptr items (new IfcSchema::IfcRepresentationItem::list);
515+ IfcSchema::IfcShapeRepresentation* shape_rep = new IfcSchema::IfcShapeRepresentation (getRepresentationContext (reptype == " Curve2D" ? " Plan" : " Model" ), repid, reptype, items);
516+ AddEntity (shape_rep);
517+ return shape_rep;
518+ }
519+
520+ IfcSchema::IfcGeometricRepresentationContext* IfcHierarchyHelper::getRepresentationContext (const std::string& s) {
521+ std::map<std::string, IfcSchema::IfcGeometricRepresentationContext*>::const_iterator it = contexts.find (s);
522+ if (it != contexts.end ()) return it->second ;
523+ else {
524+ IfcSchema::IfcProject* project = getSingle<IfcSchema::IfcProject>();
525+ IfcSchema::IfcRepresentationContext::list::ptr project_contexts = project->RepresentationContexts ();
526+ IfcSchema::IfcGeometricRepresentationContext* context = new IfcSchema::IfcGeometricRepresentationContext (
527+ boost::none, s, 3 , 1e-5 , addPlacement3d (), addDoublet<IfcSchema::IfcDirection>(0 , 1 ));
528+ AddEntity (context);
529+ project_contexts->push (context);
530+ project->setRepresentationContexts (project_contexts);
531+ return contexts[s] = context;
532+ }
533+ }
0 commit comments