|
AcDbExtents CEntity::GetRefBoundingBox (AcDbBlockReference *pRef, const AcGeMatrix3d & mat)
{
AcDbExtents ext;
AcDbExtents RetExt;
AcDbObjectId recId = pRef->blockTableRecord();
AcDbBlockTableRecordPointer block(recId,AcDb::kForRead);
Acad::ErrorStatus es = block.openStatus();
if (es == eOk)
{
AcDbBlockTableRecordIterator *pItr = NULL;
block->newIterator(pItr);
AcDbObjectId id;
AcDbEntity *pEnt = NULL;
for (pItr->start();!pItr->done();pItr->step())
{
es = pItr->getEntity(pEnt,AcDb::kForWrite);
if (es == eOk)
{
pEnt->transformBy(mat);
if (pEnt->isKindOf(AcDbBlockReference::desc()))
{
AcGeMatrix3d blkmat=((AcDbBlockReference*)pEnt)->blockTransform();
ext = GetRefBoundingBox((AcDbBlockReference *)pEnt,blkmat);
}
else
{
pEnt->getGeomExtents(ext);
}
pEnt->transformBy(mat.inverse());
RetExt.addExt(ext);
pEnt->close();
}
}
delete pItr;
pItr = NULL;
}
return RetExt;
}
譬如:
AcDbObjectPointer<AcDbBlockReference> blkref(id,AcDb::kForRead); //id块参照的id
AcDbExtents ext = CEntity::GetRefBoundingBox(blkref.object(),blkref->blockTransform());
这个代码得到的box跟geomExtentsBestFit是一致的。 |
|