Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

259 lines
5.2 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, SH Software Co. Ltd.
// = FileName : XDcClip 类
// = Version : ver2.0
// = Author : zjq
// = CreateDate : 2002-09-09
// = Description: XDcClip 定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "XDcClip.h"
#include "XConfigBase.h"
#include "XGlobalCurveFunc.h"
#include "XPrivateGlobalFunc.h"
#include "XCurveInline.h"
XDcClip::XDcClip(const XPoly2D& poly,int flag)
: m_poly(poly), m_clipType(flag)
{
if ((m_clipType & XDcClip::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;
}
XDcClip::~XDcClip()
{
if (m_pAcGiClip != NULL)
{
delete m_pAcGiClip;
m_pAcGiClip = NULL;
}
}
AcGiClipBoundary* XDcClip::GetAcGiClip()const
{
return m_pAcGiClip;
}
int XDcClip::GetClipType()const
{
return m_clipType;
}
XPoly2D XDcClip::GetClipPoly()const
{
return m_poly;
}
bool XDcClip::DoClip(DList<XCurveSegment> &lstCurve)const
{
DList<XCurveSegment> lstIn,lstOut,lstEdge;
PolyClip(lstCurve,m_poly,lstIn,lstOut,lstEdge);
lstCurve.Reset();
if ((m_clipType & XDcClip::kClipOut) != 0)
{
lstCurve << lstIn;
}
else
{
lstCurve << lstOut;
}
if ((m_clipType & XDcClip::kNoClipEdge) != 0)
{
lstCurve << lstEdge;
}
return (lstIn.Length() > 0 || lstOut.Length() > 0) ? true : false;
}
bool XDcClip::DoClip(DList<XPoly2D> &lstRegion)const
{
DList<XPoly2D> lstRes;
for (long i = 0; i < lstRegion.Length(); i++)
{
const XPoly2D& poly = *lstRegion[i];
if ((m_clipType & XDcClip::kClipOut) != 0)
{
if ( XPrivate::GetGlobalConfigBase() != NULL)
{
XPrivate::GetGlobalConfigBase()->BoolOper(AcDb::kBoolIntersect,(LPVOID)&poly,(LPVOID)&m_poly,(LPVOID)&lstRes);
}
}
else
{
DList<XPoly2D> buf;
#ifdef NEW_GEOMETRY
if ( XPrivate::GetGlobalConfigBase() != NULL)
{
XPrivate::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 XPoly2D(poly));
}
}
}
#endif
lstRes << buf;
}
}
lstRegion.Reset();
lstRegion << lstRes;
return lstRes.Length() > 0 ? true : false;
}
bool XDcClip::DoClip(DList<XDcObject> &lstCurve)const
{
DList<XDcObject> lstIn,lstOut,lstEdge;
for (long i = 0; i < lstCurve.Length(); i++)
{
lstCurve[i]->CutBy(m_poly,lstIn,lstOut,lstEdge);
}
lstCurve.Reset();
if ((m_clipType & XDcClip::kClipOut) != 0)
{
lstCurve << lstIn;
}
else
{
lstCurve << lstOut;
}
if ((m_clipType & XDcClip::kNoClipEdge) != 0)
{
lstCurve << lstEdge;
}
return (lstIn.Length() > 0 || lstOut.Length() > 0) ? true : false;
}
bool XDcClip::DoClip(DList<AcDbEntity> &lstEnt)const
{
DList<AcDbEntity> buf;
for (long i = 0; i < lstEnt.Length(); i++)
{
AcDbEntity *pEnt = lstEnt[i];
XDcObject *pXEnt = XDcObject::CreateFrom(*pEnt);
if (pXEnt != NULL)//基本对象
{
DList<XDcObject> 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 XDcClip::IsClip(const XPoint&pt)const
{
int iRet = pt & m_poly;
if (iRet == PR_OUTSIDE && (m_clipType & XDcClip::kClipOut) != 0) //点在外且裁外部
{
return true;
}
else if (iRet == PR_INSIDE && (m_clipType & XDcClip::kClipOut) == 0) //点在内且裁内部
{
return true;
}
else if (iRet == PR_EDGE && (m_clipType & XDcClip::kNoClipEdge) == 0)//点在边且裁边
{
return true;
}
return false;
}
bool XDcClip::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 zjq 100513这里精度取大点,防止有线重合时不进行裁剪操作
if (ptMin.x - m_ptUpp[X] > _DIST_SNAP*3)
{
return false;
}
if (ptMax.x - m_ptLow[X] < -_DIST_SNAP*3)
{
return false;
}
if (ptMin.y - m_ptUpp[Y] > _DIST_SNAP*3)
{
return false;
}
if (ptMax.y - m_ptLow[Y] < -_DIST_SNAP*3)
{
return false;
}
return true;
}