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];
OdIfc::OdIfcBodyVariant 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 OdIfc::OdIfcBodyVariant::kFacetModelerBody:
{
handleFacetModelerBody(bodyContainer.facetModelerBody());
break;
}
case OdIfc::OdIfcBodyVariant::kMdBody:
{
handleBrepModelerBody(bodyContainer.mdBody());
break;
}
case OdIfc::OdIfcBodyVariant::kAcisBody:
{
handleAcisModelerBody(bodyContainer.acisBody());
break;
}
case OdIfc::OdIfcBodyVariant::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 – 2021. Open Design Alliance. All rights reserved.
|