|
二、本节课程
C++ ARX二次开发-创建三维实体
二、本节要讲解的知识点
1、arx提供的三类创建三维实体的方法:创建标准形状的实体、拉伸面域创建实体、旋转面域创建实体的例子。
2、布尔运算的使用例子。
三、具体内容
1、思路:AcDb3dSolid类,提供一个不包含任何参数的构造函数,用来创建一个“空”的实体,在构建对象AcDb3dSolid之后,要使用其成员函数来完成实体的创建。
(1)长方体:createBox函数用于创建长方体的,定义:
virtual Acad::ErrorStatus createBox(
double xLen,
double yLen,
double zLen
);
创建的是一个中心位于世界坐标系原点的长方体,长、宽和高分别平行于X、Y和Z轴。
(2)圆锥体:
virtual Acad::ErrorStatus createFrustum(
double height,
double xRadius,
double yRadius,
double topXRadius
);//创建平截头体
Height表示平截头体的高度,xRadius表示底面在X轴方向的半径,yRadius表示底面在y轴方向的半径,topXRadius表示顶面在X轴方向的半径。要创建圆锥体的话,topXRadius=0,xRadius=yRadius。
(3)拉伸面域来创建实体
virtual Acad::ErrorStatus extrudeAlongPath(
const AcDbRegion* region,
const AcDbCurve* path,
double taperAngle = 0.0
);
(4)旋转面域来创建实体
virtual Acad::ErrorStatus revolve(
const AcDbRegion* region,
const AcGePoint3d& axisPoint,
const AcGeVector3d& axisDir,
double angleOfRevolution
);
(5)布尔运算:
virtual Acad::ErrorStatus booleanOper(
AcDb::BoolOperType operation,
AcDb3dSolid* solid
);
AcDb::kBoolUnite
AcDb::kBoolIntersect
AcDb::kBoolSubtract
2、如何实现:
ACED采用ARXCOMMAND采用ENTRY采用AUTO(CArxProject1App, YunyouMyGroup,AddBox ,AddBox, ACRX采用CMD采用MODAL, NULL)
ACED采用ARXCOMMAND采用ENTRY采用AUTO(CArxProject1App, YunyouMyGroup,AddCylinder ,AddCylinder, ACRX采用CMD采用MODAL, NULL)
ACED采用ARXCOMMAND采用ENTRY采用AUTO(CArxProject1App, YunyouMyGroup,AddSpire ,AddSpire, ACRX采用CMD采用MODAL, NULL)
//创建长方体
static void YunyouMyGroupAddBox()
{
AcDb3dSolid *pSolid=new AcDb3dSolid();
Acad::ErrorStatus es=pSolid->createBox(40,50,30);
if (es!=Acad::eOk)
{
acedAlert(TEXT("创建长方体失败!"));
delete pSolid;
return;
}
AcGeMatrix3d xform;
AcGeVector3d vec(100,100,100);
xform.setToTranslation(vec);
es=pSolid->transformBy(xform);
CDwgDatabaseUtil:ostToModelSpace(pSolid);
}
//创建圆锥体
static void YunyouMyGroupAddCylinder()
{
AcDb3dSolid *pSolid=new AcDb3dSolid();
Acad::ErrorStatus es=pSolid->createFrustum(30,10,10,0);
if (es!=Acad::eOk)
{
acedAlert(TEXT("创建失败!"));
delete pSolid;
return;
}
CDwgDatabaseUtil:ostToModelSpace(pSolid);
}
//创建弹簧螺旋线
static void YunyouMyGroupAddSpire()
{
double radius,deltaVertical;
int number,segment;
radius=30,deltaVertical=12;
number=5,segment=30;
int n=number*segment;
double angle=8*atan(1)/segment;
AcGePoint3dArray points;
for (int i=0;i<n+1;i++)
{
AcGePoint3d vertex;
vertex[X]=radius*cos(8*i*atan(1)/segment);
vertex[Y]=radius*sin(8*i*atan(1)/segment);
vertex[Z]=i*deltaVertical/segment;
points.append(vertex);
}
AcDb3dPolyline *p3dPoly=new AcDb3dPolyline(AcDb::k3dSimplePoly,points);
AcDbObjectId spireId=CDwgDatabaseUtil:ostToModelSpace(p3dPoly);
AcGeVector3d vec(0,1,0);
AcGePoint3d ptCenter(30,0,0);
AcDbCircle *pCircle=new AcDbCircle(ptCenter,vec,3);
AcDbObjectId circleId=CDwgDatabaseUtil:ostToModelSpace(pCircle);
AcDbObjectIdArray boundaryIds,regionIds;
boundaryIds.append(circleId);
regionIds=CRegionUtil::Add(boundaryIds);
AcDbRegion *pRegion=NULL;
if (acdbOpenObject(pRegion,regionIds.at(0),AcDb::kForRead)==Acad::eOk)
{
AcDb3dPolyline *pPoly=NULL;
if (acdbOpenObject(pPoly,spireId,AcDb::kForRead)==Acad::eOk)
{
AcDb3dSolid *pSolid=new AcDb3dSolid();
pSolid->extrudeAlongPath(pRegion,pPoly);
CDwgDatabaseUtil:ostToModelSpace(pSolid);
pPoly->close();
}
pRegion->close();
}
}
|
|