Close

Relief for ODA Team in Ukraine

Learn more
ODA IFC SDK
Source Code for Access to a Representation Body Geometry Documentation

Return to the documentation topic

      
#include "IfcFile.h"
#include "IfcModel.h"
#include "Entities/IfcProduct.h"
#include "Entities/IfcGeometricRepresentationItem.h"

void handleFacetModelerBody(const FacetModeler::Body* pFmBody);
void handleBrepModelerBody(const OdMdBody* pMdBody);
void handleAcisModelerBody(const BODY* pAcisBody);
void handleIfcBrep(const OdBrBrep& brep);

void handleBodiesFromIfcFile(OdIfcFilePtr pIfcFile)
{
  if (pIfcFile.isNull())
  {
    return;
  }
  
  OdIfcModelPtr pModel = pIfcFile->getModel();
  if (pModel.isNull())
  {
    return;
  }

  // Get all products of model.
  OdDAI::OdDAIObjectIdSet* productIdSet = pModel->getEntityExtent("IfcProduct");
  
  if (!productIdSet)
  {
    return;
  }
  
  // Alternatively productIds may be filled by specified ids.
  const OdDAIObjectIds& productIds = productIdSet->getArray();

  for (OdDAIObjectIds::size_type iProduct = 0; iProduct < productIds.size(); ++iProduct)
  {
    OdIfc::OdIfcEntityPtr pEntity = productIds[iProduct].openObject();
    
    if (pEntity.isNull()) 
    {
      continue;
    }
    
    OdIfc::OdIfcProductPtr pProduct = OdIfc::OdIfcEntity::asCompound(pEntity);
    
    if (pProduct.isNull()) 
    {
      continue;
    }

    // get geometry items of product (may be emppty)
    const OdIfc::OdIfcGeometricRepresentationItemPtrArray geomItems = pProduct->getGeometricRepresentationItems();
    
    for (OdDAIObjectIds::size_type iItem = 0; iItem < geomItems.size(); ++iItem)
    {
      OdIfc::OdIfcGeometricRepresentationItemPtr pGeomItem = geomItems[iItem];

      OdDAI::OdBodyVariant bodyContainer = pGeomItem->bodyContainer();
      
      // Don't save pointer from bodyContainer. The pointer make sense only at this place. Body should be copied if needed to use it later.
      switch (bodyContainer.kind())
      {
        case OdDAI::OdBodyVariant::kFacetModelerBody: 
        {
          handleFacetModelerBody(bodyContainer.facetModelerBody()); 
          break;
        }
        
        case OdDAI::OdBodyVariant::kMdBody: 
        {
          handleBrepModelerBody(bodyContainer.mdBody()); 
          break;
        }
        
        case OdDAI::OdBodyVariant::kAcisBody: 
        {
          handleAcisModelerBody(bodyContainer.acisBody()); 
          break;
        }
        
        case OdDAI::OdBodyVariant::kIfcBrep: 
        {
          handleIfcBrep(bodyContainer.ifcBrep()); 
          break;
        }
      }
      // bodyContainer may not contain a body. For example, when underlying geometry is curve.
    }
  }
}
      
    

Return to the documentation topic

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.