打断多段线 输入长度 打断
#include "StdAfx.h" #include "FgPoly.h" #include "DwgDatabaseUtil.h" CFgPoly::CFgPoly() { } CFgPoly::~CFgPoly() { } AcDbObjectIdArray CFgPoly::FG(AcDbPolyline *pPolyline, double l) { AcDbObjectIdArray objArr; //获取多段线每个点 int num = pPolyline->numVerts(); //剩余点 int SYnum = num; //移除点 int YCnum = 1; //从序号中减去的数值 相当于已经减少了的点 int Item = 0; //循环求每2点间距离 for (int i = 0; i < num - 1; i++) { AcGePoint3d p1; pPolyline->getPointAt(i-Item, p1); double a = 0; pPolyline->getBulgeAt(i - Item, a); if (a!=0) { YCnum++; continue; } AcGePoint3d p2; pPolyline->getPointAt(i-Item + 1, p2); double distance; distance = p1.distanceTo(p2); acutPrintf(_T("\n多段线中第%d段直线的长度 %f"),i+1, distance); for (double temp = distance; temp > l; temp = temp - l) { AcGeVector3d vec; vec = p2 - p1; AcGePoint3d p3; vec = vec.normal(); p3 = p1 + vec * l; //输出p3点 acutPrintf(TEXT("\n截断点的坐标 %f,%f,%f"), p3.x, p3.y, p3.z); AcGePoint2d p12d = CDwgDatabaseUtil::converto2d(p1); AcGePoint2d p32d = CDwgDatabaseUtil::converto2d(p3); AcRxObject *obj = pPolyline->clone(); AcDbPolyline *newPoly = new AcDbPolyline(); newPoly =AcDbPolyline::cast(obj); for (int j = i; j < num-1; j++) { newPoly->removeVertexAt(YCnum); } newPoly->addVertexAt(YCnum, p32d); pPolyline->addVertexAt(0, p32d); Item = Item - 1; for (int k = YCnum; k > 0;k--) { pPolyline->removeVertexAt(1); Item += 1; YCnum--; if (YCnum<1) { YCnum = 1; } } CDwgDatabaseUtil::PostToModleSpace(newPoly); p1 = p3; } // if (distance>l) // { // 2 == pPolyline->numVerts(); // continue; // } YCnum=YCnum+1; } return objArr; }