码迷,mamicode.com
首页 > 其他好文 > 详细

多段线动态切割闭合区域

时间:2016-01-15 15:58:11      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 


#include "StdAfx.h"
#include "StdArx.h"
#include <dbpl.h>
#include "..\..\Common\Others\ConvertUtil.h"
#include "..\..\Common\Document\DwgDatabaseUtil.h"
#include <dbents.h>
#include <dbregion.h>
#include "..\..\Common\Entity\RegionUtil.h"

// This is command ‘INTERSECT1‘
void ZffMyProjectintersect1()
{
// TODO: Implement the command
ads_name polyLinename;
ads_name polyLinename2;
ads_point pnt;
ads_point pnt2;

AcDbPolyline *pPolyline=NULL;
AcDbPolyline *pPoly=NULL;
AcDbRegion *pRegion1=NULL;
AcDbRegion *pRegion2=NULL;
acedEntSel("\n请选择截取多段线!",polyLinename,pnt);
AcDbObjectId polyLineId;
acdbGetObjectId(polyLineId,polyLinename);
AcDbEntity *pEnt=NULL;
AcGePoint3dArray pts,pts2;
acdbOpenObject(pEnt,polyLineId,AcDb::kForWrite);

if (pEnt->isKindOf(AcDbPolyline::desc()))
{
pPolyline=AcDbPolyline::cast(pEnt);
pEnt->close();
}
AcDbVoidPtrArray curves;
int num=pPolyline->numVerts();
for (int i=0;i<num;i++)
{
AcGePoint2d pt;
pPolyline->getPointAt(i,pt);
pts.append(CConvertUtil::ToPoint3d(pt));
}
pPolyline->getSplitCurves(pts,curves);
pPolyline->close();
AcDbObjectIdArray curvesId;
AcDbCurve *pCurve=NULL;
for (i=0;i<curves.length();i++)
{
pCurve=static_cast<AcDbCurve*>(curves[i]);
curvesId.append(CDwgDatabaseUtil::PostToModelSpace(pCurve));
}
pCurve->close();

acedEntSel("\n请选择被截取多段线!",polyLinename2,pnt2);
acdbGetObjectId(polyLineId,polyLinename2);
acdbOpenObject(pEnt,polyLineId,AcDb::kForWrite);
if (pEnt->isKindOf(AcDbPolyline::desc()))
{
pPoly=AcDbPolyline::cast(pEnt);
pEnt->close();
//pPoly->intersectWith(pPolyline,AcDb::kOnBothOperands,pts,0,0);
}
AcDbVoidPtrArray curves2;
num=pPoly->numVerts();
for (i=0;i<num;i++)
{
AcGePoint2d pt2;
pPoly->getPointAt(i,pt2);
pts2.append(CConvertUtil::ToPoint3d(pt2));
}
pPoly->getSplitCurves(pts2,curves2);
pPoly->close();
AcDbObjectIdArray curvesId2;
AcDbCurve *pCurve2=NULL;
for (i=0;i<curves2.length();i++)
{
pCurve2=static_cast<AcDbCurve*>(curves2[i]);
curvesId2.append(CDwgDatabaseUtil::PostToModelSpace(pCurve2));
}
pCurve2->close();
AcDbObjectIdArray regId=CRegionUtil::Add(curvesId);
AcDbObjectIdArray regId2=CRegionUtil::Add(curvesId2);
for (i=0;i<curvesId.length();i++)
{
acdbOpenObject(pCurve,curvesId[i],AcDb::kForWrite);
pCurve->erase();
pCurve->close();
}
for (i=0;i<curvesId2.length();i++)
{
acdbOpenObject(pCurve2,curvesId2[i],AcDb::kForWrite);
pCurve2->erase();
pCurve2->close();
}
acdbOpenObject(pRegion1,regId[0],AcDb::kForWrite);
acdbOpenObject(pRegion2,regId2[0],AcDb::kForWrite);
pRegion1->booleanOper(AcDb::kBoolIntersect,pRegion2);
pRegion1->close();
pRegion2->close();
}

 

多段线动态切割闭合区域

标签:

原文地址:http://www.cnblogs.com/NewAutoMan/p/5133346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!