天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 52|回复: 0

c++ Arx二次开发创建多段线

[复制链接]

该用户从未签到

主题

0

回帖

2912

积分

管理员

积分
2912
发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
[code]一、本节课程
c++ Arx二次开发创建多段线

二、本节要讲解的知识点
   如何应用C++ ARX二次开发创建多段线(AcDbPolyline、AcDb2dPolyLine、AcDb3dPolyline的使用)

三、具体内容
1、ARX提供了三种多段线相关的类:AcDbPolyline、AcDb2dPolyLine、AcDb3dPolyline。PLINE 创建的是AcDbPolyline,3DPOLY创建AcDb3dPolyline。创建一般的轻量多段线只需要调用AcDbPolyline的构造函数即可,创建矩形、正多边形、圆形、圆环对象,关键在于顶点和凸度的确定。

2、添加多段线对象的函数实现:

AcDbObjectId CPolylineUtil::Add(const AcGePoint2dArray &points,double width)

{

int numVertices=points.length();

AcDbPolyline *pPoly=new AcDbPolyline(numVertices);

for (int i=0;i<numVertices;i++)

{

pPoly->addVertexAt(i,points.at(i),0,width,width);

}

return CDwgDatabaseUtil::PostToModelSpace(pPoly);

}



AcDbObjectId CPolylineUtil::Add(const AcGePoint2d &ptStart,const AcGePoint2d &ptEnd,double width)

{

AcGePoint2dArray points;

points.append(ptStart);

points.append(ptEnd);

return Add(points,width);

}

AcDbObjectId CPolylineUtil::Add3dPolyline(const AcGePoint3dArray &points)

{

AcGePoint3dArray verts=points;

AcDb3dPolyline *pPoly3d=new AcDb3dPolyline(AcDb::k3dSimplePoly,verts);

return CDwgDatabaseUtil::PostToModelSpace(pPoly3d);

}

AcDbObjectId  CPolylineUtil::AddPolygon(const AcGePoint2d &ptCenter,int number,double radius,double rotation,double width)

{

double angle=2*CMathUtil::PI()/(double)number;

AcGePoint2dArray points;

for (int i=0;i<number;i++)

{

AcGePoint2d pt;

pt.x=ptCenter.x+radius*cos(i*angle);

pt.y=ptCenter.y+radius*sin(i*angle);

points.append(pt);



}

AcDbObjectId polyId=Add(points,width);



AcDbEntity *pEnt=NULL;

if (acdbOpenObject(pEnt,polyId,AcDb::kForWrite)==Acad::eOk)

{

AcDbPolyline *pPoly=AcDbPolyline::cast(pEnt);

if (pPoly!=NULL)

{

pPoly->setClosed(Adesk::kTrue);

}

pEnt->close();



}

EntityUtil::Rotate(polyId,ptCenter,rotation);

return polyId;

}

AcDbObjectId CPolylineUtil::AddRectangle(const AcGePoint2d &pt1,const AcGePoint2d &pt2,double width)

{



double x1=pt1.x,x2=pt2.x;

double y1=pt1.y,y2=pt2.y;



AcGePoint2d ptLeftBottom(min(x1,x2),min(y1,y2));

AcGePoint2d ptRightBottom(max(x1,x2),min(y1,y2));

AcGePoint2d ptRightTop(max(x1,x2),max(y1,y2));

AcGePoint2d ptLeftTop(min(x1,x2),max(y1,y2));



AcDbPolyline *pPoly=new AcDbPolyline(4);

pPoly->addVertexAt(0,ptLeftBottom,0,width,width);

pPoly->addVertexAt(1,ptRightBottom,0,width,width);

pPoly->addVertexAt(2,ptRightTop,0,width,width);

pPoly->addVertexAt(3,ptLeftTop,0,width,width);

pPoly->setClosed(true);

return CDwgDatabaseUtil::PostToModelSpace(pPoly);



}

AcDbObjectId CPolylineUtil::AddPolyCircle(const AcGePoint2d &ptCenter,double radius,double width)

{

AcGePoint2d pt1,pt2,pt3;

pt1.x=ptCenter.x+radius;

pt1.y=ptCenter.y;

pt2.x=ptCenter.x-radius;

pt2.y=ptCenter.y;

pt3.x=ptCenter.x+radius;

pt3.y=ptCenter.y;



AcDbPolyline *pPoly=new AcDbPolyline(3);

pPoly->addVertexAt(0,pt1,1,width,width);

pPoly->addVertexAt(1,pt2,1,width,width);

pPoly->addVertexAt(2,pt3,1,width,width);

pPoly->setClosed(Adesk::kTrue);



return CDwgDatabaseUtil::PostToModelSpace(pPoly);

}







四、总结
1、AUTOCAD的三种多段线对象:AcDbPolyline、AcDb2dPolyline、AcDb3dPolyline,我们重点实现了AcDbPolyline、AcDb3dPolyline。

2、如何创建多段线,利用多段线对象来创建正多边形、矩形、圆、圆弧(关键点在于顶点坐标的计算和顶点凸度的概念的掌握)。如果对凸度概念不是很清楚,自己可以用代码来验证。[/code]

 

 

 

 

c++ Arx二次开发创建多段线
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|中国膜结构网_中国空间膜结构协会

GMT+8, 2024-11-1 09:22 , Processed in 0.164778 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表