测试模型:模型中在面上开了三个标准圆孔,一个椭圆孔
代码:如果你需要获取具体几何对象的信息,将指针强制类型转换以下就可以。没错,这里我又偷懒了!!!
HRESULT CAAStarterCmd::GetGeometryObjectType(CATBody_var &ispBody){//检验输入Body是否为nullif(!ispBody)return S_FALSE;//get all CATLoop,因为Loop是用来限制Face的,//那么你所获取的几何曲线的直接基类应该是CATPCurve//首先必须明确这一点,在之后的操作中我们都使用GetGeometryOnFace方法来获取曲线。//虽然我们采用GetCurve也可以获取到曲线,没方法将曲线类型区分开。CATLocation location;CATUnicodeString str;CATLISTP(CATDomain)olistDomain;ispBody->GetAllDomains(1,2,olistDomain);//这里偷了下懒,//要想能够测试CATCircleType、CATEllipseType等空间曲线的类型,要自己改一下,才能通用。CATLISTP(CATCell)olistCell;//get all edgefor (int i=1;i<=olistDomain.Size();i++){if (olistDomain[i]->IsATypeOf(CATLoopType)){olistDomain[i]->GetAllCells(olistCell,1);location=olistDomain[i]->GetLocation();if (location==CATLocationInner){str="Inner";}else{str="outer";}CATCell*pDomainOwner=olistDomain[i]->GetOwningCell(ispBody);for (int j=1;j<=olistCell.Size();j++){CATEdge*pEdge=(CATEdge*)olistCell[j];CATSide side=pEdge->GetSideOnFace((CATFace*)pDomainOwner);CATPCurve*pCurve=pEdge->GetGeometryOnFace((CATFace*)pDomainOwner,side);if(!pCurve)return S_FALSE;if (pCurve->IsATypeOf(CATPCircleType)){cout<<"this curve is a circle :"<<str<<endl;}if (pCurve->IsATypeOf(CATPEllipseType)){cout<<"this curve is a Ellipse:"<<str<<endl;}if (pCurve->IsATypeOf(CATPLineType)){cout<<"this curve is a Line:"<<str<<endl;}}}if (olistDomain[i]->IsATypeOf(CATWireType)){olistDomain[i]->GetAllCells(olistCell,1);CATCell*pDomainOwner=olistDomain[i]->GetOwningCell(ispBody);for (int j=1;j<=olistCell.Size();j++){CATEdge*pEdge=(CATEdge*)olistCell[j];CATGeometry*pGeo=pEdge->GetGeometry();if(!pGeo)return S_FALSE;if (pGeo->IsATypeOf(CATCircleType)){cout<<"this is a circle"<<endl;}if (pGeo->IsATypeOf(CATEllipseType)){cout<<"this is a Ellipse"<<endl;}}}}return S_OK;}
输出结果: