代码:
#include "StdAfx.h"
#include "StdArx.h"
#include <dbpl.h>
#include "..\..\Common\Others\ConvertUtil.h"
#include <geassign.h>
#include "..\..\Common\Entity\ArcUtil.h"
#include "..\..\Common\Document\DwgDatabaseUtil.h"
#include <afxwin.h>
#include <dbents.h>
void ZffMyProjectchangeline()
{
ads_name polyLinename;
ads_point pnt;
if (acedEntSel("\n请选择多段线的条直线段!",polyLinename,pnt)!=RTNORM)
{
return;
}
AcDbObjectId polyLineId;
acdbGetObjectId(polyLineId,polyLinename);
AcDbEntity *pEnt=NULL;
acdbOpenObject(pEnt,polyLineId,AcDb::kForWrite);
if (pEnt->isKindOf(AcDbPolyline::desc()))
{
AcDbPolyline *pPolyline=AcDbPolyline::cast(pEnt);
pEnt->close();
int vtnum=pPolyline->numVerts();
AcGePoint3dArray pts;
AcGePoint3d pt;
for(int i=0; i<vtnum; i++)
{
pPolyline->getPointAt(i, pt);
pts.append(pt);
}
AcDbVoidPtrArray curves;
pPolyline->getSplitCurves(pts,curves);
bool nRb=true;
for (i=0;i<curves.length();i++)
{
AcDbCurve *pCurve=static_cast<AcDbCurve*>(curves[i]);
if (nRb)
{
AcGeLine2d geLine;
AcGePoint3d pt1,pt2;
pCurve->getStartPoint(pt1);
pCurve->getEndPoint(pt2);
AcGePoint2d pt12d,pt22d,pnt2d,pt2d;
ads_point pt;
AcGePoint3d ptOnArc;
pt12d=CConvertUtil::ToPoint2d(pt1);
pt22d=CConvertUtil::ToPoint2d(pt2);
pnt2d=CConvertUtil::ToPoint2d(asPnt3d(pnt));
geLine.set(pt12d,pt22d);
double tol =1;
if (geLine.distanceTo(pnt2d)<tol)
{
nRb=false;
delete pCurve;
pCurve->close();
acedGetPoint(NULL,"\n输入一个点:",pt);
pt2d=CConvertUtil::ToPoint2d(asPnt3d(pt));
AcGeCircArc2d geArc(pt12d, pt2d, pt22d);
AcGePoint2d ptCenter = geArc.center();
double radius = geArc.radius();
AcGeVector2d vecStart(pt12d.x - ptCenter.x, pt12d.y - ptCenter.y);
AcGeVector2d vecEnd(pt22d.x - ptCenter.x, pt22d.y - ptCenter.y);
double startAngle = vecStart.angle();
double endAngle = vecEnd.angle();
AcDbArc *pArc=new AcDbArc(CConvertUtil::ToPoint3d(ptCenter), radius, startAngle, endAngle);
pArc->getClosestPointTo(asPnt3d(pt),ptOnArc);
if (CConvertUtil::ToPoint2d(ptOnArc).distanceTo(pt2d)<tol)
{
CDwgDatabaseUtil::PostToModelSpace(pArc);
}
else
{
AcDbArc *pArc2=new AcDbArc(CConvertUtil::ToPoint3d(ptCenter),radius,endAngle,startAngle);
CDwgDatabaseUtil::PostToModelSpace(pArc2);
delete pArc;
}
continue;
}
}
CDwgDatabaseUtil::PostToModelSpace(pCurve);
pCurve->close();
}
acdbOpenObject(pPolyline,polyLineId,AcDb::kForWrite);
pPolyline->erase();
pPolyline->close();
}
pEnt->close();
}