TA的每日心情 | 开心 7 小时前 |
---|
签到天数: 20 天 [LV.4]偶尔看看III
管理员
- 积分
- 1393
|
- 代码:
- #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();
- }
复制代码 |
|