C++ ARX二次开发-BREP库
一、本节课程
C++ ARX二次开发-BREP库
二、本节要讲解的知识点
通过两个命令来演示BREP库的使用:获取圆柱体中圆柱面的特征参数;获取任何三维实体的边的采样曲线。
三、具体内容
1、思路:组合体(Complex)、壳(Shell)、面(Face)、边(Edge)和顶点(Vertex)都是BREP的常用对象。BREP访问组合体、壳、面、边、顶点,使用遍历的方法,可以通过子实体访问到某一个具体的对象。
2、实现:
(1)建立了一个新的项目,并且需要引用BREP库的LIB,INC目录,在附加依赖项里面链接对应的库。
(2)添加两个命令:
ACED_ARXCOMMAND_ENTRY_AUTO(CBrepTestApp, yunyouMyGroup, GetCylinderInfo, GetCylinderInfo, ACRX_CMD_MODAL, NULL)
ACED_ARXCOMMAND_ENTRY_AUTO(CBrepTestApp, yunyouMyGroup, GetBoundayCurves, GetBoundayCurves, ACRX_CMD_MODAL, NULL)
static void yunyouMyGroupGetCylinderInfo () {
AcDbEntity *pEnt=NULL;
AcGePoint3d pickPoint;
if (CSelectUtil::PromptSelctEnts(TEXT("\n选择三维实体:"),AcDb3dSolid::desc(),pEnt,pickPoint))
{
//建立一个BREP对象
AcBrBrep brepEnt;
brepEnt.set(*pEnt);
//创建一个面的遍历器
AcBr::ErrorStatus returnValue=AcBr::eOk;
AcBrBrepFaceTraverser brepFaceTrav;
returnValue=brepFaceTrav.setBrep(brepEnt);
while ((!brepFaceTrav.done()) &&(returnValue==AcBr::eOk) )
{
AcBrFace brFace;
AcBr::ErrorStatus es=brepFaceTrav.getFace(brFace);
if (es==AcBr::eOk)
{
AcGeSurface *pAcGeSurface;
brFace.getSurface(pAcGeSurface);
AcGeExternalBoundedSurface *ebSurf=(AcGeExternalBoundedSurface*)pAcGeSurface;
if(ebSurf!=NULL && ebSurf->isCylinder())
{
AcGeCylinder *pCylinder=(AcGeCylinder*)ebSurf;
acutPrintf(TEXT("\n圆柱面的信息:"));
acutPrintf(TEXT("\n半径:%.2f"),pCylinder->radius());
AcGePoint3d center=pCylinder->origin();
acutPrintf(TEXT("\n中心点:(%.2f,%2.f,%.2f)"),center.x,center.y,center.z);
AcGeVector3d axis=pCylinder->axisOfSymmetry();
acutPrintf(TEXT("\n轴线向量:(%.2f,%2.f,%.2f)"),axis.x,axis.y,axis.z);
}
delete pAcGeSurface;
}
returnValue=brepFaceTrav.next();
}
pEnt->close();
}
}
static void yunyouMyGroupGetBoundayCurves () {
AcDbEntity *pEnt=NULL;
AcGePoint3d pickPoint;
if (CSelectUtil::PromptSelctEnts(TEXT("\n选择三维实体:"),AcDb3dSolid::desc(),pEnt,pickPoint))
{
//建立一个BREP对象
AcBrBrep brepEnt;
brepEnt.set(*pEnt);
//创建一个面的遍历器
AcBr::ErrorStatus returnValue=AcBr::eOk;
AcBrBrepEdgeTraverser brepEdgeTrav;
returnValue=brepEdgeTrav.setBrep(brepEnt);
if(returnValue==AcBr::eOk)
{
while ((!brepEdgeTrav.done()) &&(returnValue==AcBr::eOk) )
{
AcBrEdge brEdge;
brepEdgeTrav.getEdge(brEdge);
AcGeCurve3d *pGeCurve=NULL;
if (brEdge.getCurve(pGeCurve)==AcBr::eOk)
{
AcGeCurve3d *pNativeCurve=NULL;
Adesk::Boolean bRet=((AcGeExternalCurve3d*)pGeCurve)->isNativeCurve(pNativeCurve);
int numSample=180;
AcGePoint3dArray points;
pNativeCurve->getSamplePoints(numSample,points);
if (pNativeCurve->isClosed()&& points.length()>0)
{
points.append(points[0]);
}
delete pNativeCurve;
delete pGeCurve;
if (points.length()>2)
{
CPolylineUtil::Add3dPolyline(points);
}
}
returnValue =brepEdgeTrav.next();
}
}
pEnt->close();
}
}
记得包含头文件:
#include "SelectUtil.h"
#include "brbrep.h"
#include "brbftrav.h"
#include "brbetrav.h"
#include "brface.h"
#include "bredge.h"
#include "PolylineUtil.h"
3、如何添加现有项:
解决方案资源管理器->右键->添加现有项,(事先从已有的代码目录中拷贝需要的头文件和源文件到目标项目中),选择.H和.CPP文件,添加即可。
4、测试效果:(1) GETCYLINDERINFO命令的效果:
命令: GETCYLINDERINFO
选择三维实体:
圆柱面的信息:
半径:814.03
中心点:(7005.37,968,1249.41)
轴线向量:(0.00, 0,1.00)
(2) GetBoundayCurves命令的效果
————————————————
版权声明:本文为CSDN博主「云幽学院」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liujiangtaocsu/article/details/82917720