找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 42|回复: 0

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

[复制链接]

0

主题

0

回帖

26

积分

管理员

积分
26
发表于 2024-7-30 08:28:58 | 显示全部楼层 |阅读模式
  1. 4、c++ Arx二次开发创建多段线
  2. 一、本节课程
  3. c++ Arx二次开发创建多段线
  4. 二、本节要讲解的知识点
  5.    如何应用C++ ARX二次开发创建多段线(AcDbPolyline、AcDb2dPolyLine、AcDb3dPolyline的使用)
  6. 三、具体内容
  7. 1、ARX提供了三种多段线相关的类:AcDbPolyline、AcDb2dPolyLine、AcDb3dPolyline。PLINE 创建的是AcDbPolyline,3DPOLY创建AcDb3dPolyline。创建一般的轻量多段线只需要调用AcDbPolyline的构造函数即可,创建矩形、正多边形、圆形、圆环对象,关键在于顶点和凸度的确定。
  8. 2、添加多段线对象的函数实现:
  9. AcDbObjectId CPolylineUtil::Add(const AcGePoint2dArray &points,double width)
  10. {
  11. int numVertices=points.length();
  12. AcDbPolyline *pPoly=new AcDbPolyline(numVertices);
  13. for (int i=0;i<numVertices;i++)
  14. {
  15. pPoly->addVertexAt(i,points.at(i),0,width,width);
  16. }
  17. return CDwgDatabaseUtil::PostToModelSpace(pPoly);
  18. }
  19. AcDbObjectId CPolylineUtil::Add(const AcGePoint2d &ptStart,const AcGePoint2d &ptEnd,double width)
  20. {
  21. AcGePoint2dArray points;
  22. points.append(ptStart);
  23. points.append(ptEnd);
  24. return Add(points,width);
  25. }
  26. AcDbObjectId CPolylineUtil::Add3dPolyline(const AcGePoint3dArray &points)
  27. {
  28. AcGePoint3dArray verts=points;
  29. AcDb3dPolyline *pPoly3d=new AcDb3dPolyline(AcDb::k3dSimplePoly,verts);
  30. return CDwgDatabaseUtil::PostToModelSpace(pPoly3d);
  31. }
  32. AcDbObjectId  CPolylineUtil::AddPolygon(const AcGePoint2d &ptCenter,int number,double radius,double rotation,double width)
  33. {
  34. double angle=2*CMathUtil::PI()/(double)number;
  35. AcGePoint2dArray points;
  36. for (int i=0;i<number;i++)
  37. {
  38. AcGePoint2d pt;
  39. pt.x=ptCenter.x+radius*cos(i*angle);
  40. pt.y=ptCenter.y+radius*sin(i*angle);
  41. points.append(pt);
  42. }
  43. AcDbObjectId polyId=Add(points,width);
  44. AcDbEntity *pEnt=NULL;
  45. if (acdbOpenObject(pEnt,polyId,AcDb::kForWrite)==Acad::eOk)
  46. {
  47. AcDbPolyline *pPoly=AcDbPolyline::cast(pEnt);
  48. if (pPoly!=NULL)
  49. {
  50. pPoly->setClosed(Adesk::kTrue);
  51. }
  52. pEnt->close();
  53. }
  54. EntityUtil::Rotate(polyId,ptCenter,rotation);
  55. return polyId;
  56. }
  57. AcDbObjectId CPolylineUtil::AddRectangle(const AcGePoint2d &pt1,const AcGePoint2d &pt2,double width)
  58. {
  59. double x1=pt1.x,x2=pt2.x;
  60. double y1=pt1.y,y2=pt2.y;
  61. AcGePoint2d ptLeftBottom(min(x1,x2),min(y1,y2));
  62. AcGePoint2d ptRightBottom(max(x1,x2),min(y1,y2));
  63. AcGePoint2d ptRightTop(max(x1,x2),max(y1,y2));
  64. AcGePoint2d ptLeftTop(min(x1,x2),max(y1,y2));
  65. AcDbPolyline *pPoly=new AcDbPolyline(4);
  66. pPoly->addVertexAt(0,ptLeftBottom,0,width,width);
  67. pPoly->addVertexAt(1,ptRightBottom,0,width,width);
  68. pPoly->addVertexAt(2,ptRightTop,0,width,width);
  69. pPoly->addVertexAt(3,ptLeftTop,0,width,width);
  70. pPoly->setClosed(true);
  71. return CDwgDatabaseUtil::PostToModelSpace(pPoly);
  72. }
  73. AcDbObjectId CPolylineUtil::AddPolyCircle(const AcGePoint2d &ptCenter,double radius,double width)
  74. {
  75. AcGePoint2d pt1,pt2,pt3;
  76. pt1.x=ptCenter.x+radius;
  77. pt1.y=ptCenter.y;
  78. pt2.x=ptCenter.x-radius;
  79. pt2.y=ptCenter.y;
  80. pt3.x=ptCenter.x+radius;
  81. pt3.y=ptCenter.y;
  82. AcDbPolyline *pPoly=new AcDbPolyline(3);
  83. pPoly->addVertexAt(0,pt1,1,width,width);
  84. pPoly->addVertexAt(1,pt2,1,width,width);
  85. pPoly->addVertexAt(2,pt3,1,width,width);
  86. pPoly->setClosed(Adesk::kTrue);
  87. return CDwgDatabaseUtil::PostToModelSpace(pPoly);
  88. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2024-12-27 21:35 , Processed in 0.132231 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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