247 lines
5.1 KiB
C++
247 lines
5.1 KiB
C++
#include "StdAfx.h"
|
|
#include "TGGiClipBoundary.h"
|
|
#include "globalFunc.h"
|
|
#include "GeCurveInline.h"
|
|
|
|
TGGiClipBoundary::TGGiClipBoundary(const GePoly2D& poly,int flag)
|
|
: m_poly(poly), m_clipType(flag)
|
|
{
|
|
if ((m_clipType & TGGiClipBoundary::kAcGiClip) != 0)
|
|
{
|
|
m_pAcGiClip = new AcGiClipBoundary;
|
|
|
|
m_pAcGiClip->m_bDrawBoundary = false;
|
|
m_pAcGiClip->m_vNormal = AcGeVector3d::kZAxis;
|
|
m_pAcGiClip->m_ptPoint = AcGePoint3d::kOrigin;
|
|
|
|
for (long i = 0;i<poly.Length();i++)
|
|
{
|
|
m_pAcGiClip->m_aptPoints.append(poly[i].AsAcGePoint2d());
|
|
}
|
|
|
|
m_pAcGiClip->m_xToClipSpace.setToIdentity();
|
|
m_pAcGiClip->m_xInverseBlockRefXForm.setToIdentity();
|
|
|
|
m_pAcGiClip->m_bClippingBack = m_pAcGiClip->m_bClippingFront = false;
|
|
m_pAcGiClip->m_dFrontClipZ = m_pAcGiClip->m_dBackClipZ = 0;
|
|
}
|
|
else
|
|
{
|
|
m_pAcGiClip = NULL;
|
|
}
|
|
m_bExtExtracted = false;
|
|
}
|
|
|
|
TGGiClipBoundary::~TGGiClipBoundary()
|
|
{
|
|
if (m_pAcGiClip != NULL)
|
|
{
|
|
delete m_pAcGiClip;
|
|
m_pAcGiClip = NULL;
|
|
}
|
|
}
|
|
|
|
AcGiClipBoundary* TGGiClipBoundary::GetAcGiClip()const
|
|
{
|
|
return m_pAcGiClip;
|
|
}
|
|
|
|
int TGGiClipBoundary::GetClipType()const
|
|
{
|
|
return m_clipType;
|
|
}
|
|
|
|
GePoly2D TGGiClipBoundary::GetClipPoly()const
|
|
{
|
|
return m_poly;
|
|
}
|
|
|
|
bool TGGiClipBoundary::DoClip(PtrList<GeCurveSegment> &lstCurve)const
|
|
{
|
|
PtrList<GeCurveSegment> lstIn,lstOut,lstEdge;
|
|
GlobalFunc::PolyClip(lstCurve,m_poly,lstIn,lstOut,lstEdge);
|
|
lstCurve.Reset();
|
|
|
|
if ((m_clipType & TGGiClipBoundary::kClipOut) != 0)
|
|
{
|
|
lstCurve << lstIn;
|
|
}
|
|
else
|
|
{
|
|
lstCurve << lstOut;
|
|
}
|
|
|
|
if ((m_clipType & TGGiClipBoundary::kNoClipEdge) != 0)
|
|
{
|
|
lstCurve << lstEdge;
|
|
}
|
|
return (lstIn.Length() > 0 || lstOut.Length() > 0) ? true : false;
|
|
}
|
|
|
|
bool TGGiClipBoundary::DoClip(PtrList<GePoly2D> &lstRegion)const
|
|
{
|
|
PtrList<GePoly2D> lstRes;
|
|
|
|
for (long i = 0; i < lstRegion.Length(); i++)
|
|
{
|
|
const GePoly2D& poly = *lstRegion[i];
|
|
|
|
if ((m_clipType & TGGiClipBoundary::kClipOut) != 0)
|
|
{
|
|
//if ( TchPrivate::GetGlobalConfigBase() != NULL)
|
|
//{
|
|
// TchPrivate::GetGlobalConfigBase()->BoolOper(AcDb::kBoolIntersect,(LPVOID)&poly,(LPVOID)&m_poly,(LPVOID)&lstRes);
|
|
//}
|
|
}
|
|
else
|
|
{
|
|
// PtrList<GePoly2D> buf;
|
|
//#ifdef NEW_GEOMETRY
|
|
//
|
|
// if ( TchPrivate::GetGlobalConfigBase() != NULL)
|
|
// {
|
|
// TchPrivate::GetGlobalConfigBase()->BoolOper(AcDb::kBoolSubtract,(LPVOID)&poly,(LPVOID)&m_poly,(LPVOID)&buf);
|
|
// }
|
|
//#else
|
|
// if (Subtract(poly, m_poly, buf) != RTNORM || buf.Length() == 0)
|
|
// {
|
|
// buf.Reset();
|
|
// Intersect(poly,m_poly,buf);
|
|
//
|
|
// if (buf.Length() > 0)
|
|
// {
|
|
// if (poly.Area() > m_poly.Area())
|
|
// {
|
|
// buf.Append(new GePoly2D(poly));
|
|
// }
|
|
// }
|
|
// }
|
|
//#endif
|
|
// lstRes << buf;
|
|
}
|
|
}
|
|
|
|
lstRegion.Reset();
|
|
lstRegion << lstRes;
|
|
return lstRes.Length() > 0 ? true : false;
|
|
}
|
|
|
|
bool TGGiClipBoundary::DoClip(PtrList<GeDbCurveEntity> &lstCurve)const
|
|
{
|
|
PtrList<GeDbCurveEntity> lstIn,lstOut,lstEdge;
|
|
for (long i = 0; i < lstCurve.Length(); i++)
|
|
{
|
|
lstCurve[i]->CutBy(m_poly,lstIn,lstOut,lstEdge);
|
|
}
|
|
|
|
lstCurve.Reset();
|
|
if ((m_clipType & TGGiClipBoundary::kClipOut) != 0)
|
|
{
|
|
lstCurve << lstIn;
|
|
}
|
|
else
|
|
{
|
|
lstCurve << lstOut;
|
|
}
|
|
|
|
if ((m_clipType & TGGiClipBoundary::kNoClipEdge) != 0)
|
|
{
|
|
lstCurve << lstEdge;
|
|
}
|
|
return (lstIn.Length() > 0 || lstOut.Length() > 0) ? true : false;
|
|
}
|
|
|
|
bool TGGiClipBoundary::DoClip(PtrList<AcDbEntity> &lstEnt)const
|
|
{
|
|
PtrList<AcDbEntity> buf;
|
|
for (long i = 0; i < lstEnt.Length(); i++)
|
|
{
|
|
AcDbEntity *pEnt = lstEnt[i];
|
|
GeDbCurveEntity *pXEnt = GeDbCurveEntity::CreateFrom(*pEnt);
|
|
if (pXEnt != NULL)//基本对象
|
|
{
|
|
PtrList<GeDbCurveEntity> lstXEnt;
|
|
lstXEnt.Append(pXEnt);
|
|
|
|
DoClip(lstXEnt);
|
|
for (long j = 0; j < lstXEnt.Length(); j++)
|
|
{
|
|
AcDbEntity *pNewEnt = lstXEnt[j]->CreateAcDbEntity();
|
|
if (pNewEnt != NULL)
|
|
{
|
|
pNewEnt->setPropertiesFrom(pEnt);
|
|
buf.Append(pNewEnt);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AcDbVoidPtrArray ents;
|
|
pEnt->explode(ents);
|
|
|
|
for (long j = 0; j < ents.length(); j++)
|
|
{
|
|
lstEnt.Append((AcDbEntity*)ents[j]);
|
|
}
|
|
}
|
|
}
|
|
|
|
lstEnt.Reset();
|
|
lstEnt << buf;
|
|
return buf.Length() > 0 ? true : false;
|
|
}
|
|
|
|
bool TGGiClipBoundary::IsClip(const ADSGePoint3d&pt)const
|
|
{
|
|
int iRet = pt & m_poly;
|
|
if (iRet == PR_OUTSIDE && (m_clipType & TGGiClipBoundary::kClipOut) != 0) //点在外且裁外部
|
|
{
|
|
return true;
|
|
}
|
|
else if (iRet == PR_INSIDE && (m_clipType & TGGiClipBoundary::kClipOut) == 0) //点在内且裁内部
|
|
{
|
|
return true;
|
|
}
|
|
else if (iRet == PR_EDGE && (m_clipType & TGGiClipBoundary::kNoClipEdge) == 0)//点在边且裁边
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
bool TGGiClipBoundary::IsExtentsClip(AcDbExtents& ext)
|
|
{
|
|
if (!m_bExtExtracted)
|
|
{
|
|
m_poly.GetExtend(m_ptLow,m_ptUpp);
|
|
m_bExtExtracted = true;
|
|
}
|
|
|
|
AcGePoint3d ptMin = ext.minPoint();
|
|
AcGePoint3d ptMax = ext.maxPoint();
|
|
|
|
//add by xlc 100513这里精度取大点,防止有线重合时不进行裁剪操作
|
|
if (ptMin.x - m_ptUpp[X] > g_Option::instance()._DIST_SNAP*3)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (ptMax.x - m_ptLow[X] < -g_Option::instance()._DIST_SNAP*3)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (ptMin.y - m_ptUpp[Y] > g_Option::instance()._DIST_SNAP*3)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (ptMax.y - m_ptLow[Y] < -g_Option::instance()._DIST_SNAP*3)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|