427 lines
7.7 KiB
C++
427 lines
7.7 KiB
C++
#include "StdAfx.h"
|
|
#include "globalfunc.h"
|
|
#include "RBList.h"
|
|
#include "GeCurveInline.h"
|
|
#include "EntitySet.h"
|
|
|
|
using namespace GlobalFunc;
|
|
|
|
GeCircle::GeCircle()
|
|
{
|
|
|
|
}
|
|
|
|
GeCircle::GeCircle(const GeCircle &src)
|
|
{
|
|
m_ptCenter = src.m_ptCenter;
|
|
m_dRadius = src.m_dRadius;
|
|
}
|
|
|
|
GeCircle::GeCircle(const ADSGePoint3d &startPoint, const ADSGePoint3d &pt2, const ADSGePoint3d &endPoint)
|
|
:m_dRadius(0.0)
|
|
{
|
|
AcGeCircArc3d cir(startPoint,pt2,endPoint);
|
|
m_ptCenter = cir.center();
|
|
m_dRadius = cir.radius();
|
|
}
|
|
|
|
GeCircle::GeCircle(const ads_point diaPt1, const ads_point diaPt2)
|
|
{
|
|
ads_point ptcen;
|
|
Midpoint(diaPt1, diaPt2, ptcen);
|
|
|
|
m_ptCenter = ptcen;
|
|
m_dRadius = ads_distance(diaPt1, diaPt2) / 2.0;
|
|
}
|
|
|
|
GeCircle::GeCircle(const ads_point ptcenter, double dradius)
|
|
{
|
|
m_ptCenter = ptcenter;
|
|
m_dRadius = dradius;
|
|
}
|
|
|
|
GeCircle::GeCircle(const EntitySet& entCircle, ads_matrix mat)
|
|
{
|
|
EntitySet entCirTemp = entCircle;
|
|
entCirTemp.GetData(10, m_ptCenter);
|
|
entCirTemp.GetData(40, &m_dRadius);
|
|
|
|
if (mat)
|
|
{
|
|
ADSGePoint3d pt;
|
|
ads_polar(m_ptCenter, 0, m_dRadius, pt);
|
|
m_ptCenter.TransformBy(mat);
|
|
pt.TransformBy(mat);
|
|
m_dRadius = ads_distance(m_ptCenter, pt);
|
|
}
|
|
}
|
|
|
|
GeCircle::~GeCircle()
|
|
{
|
|
|
|
}
|
|
|
|
void GeCircle::Set(const ADSGePoint3d &diaPt1, const ADSGePoint3d &diaPt2)
|
|
{
|
|
ads_point ptcen;
|
|
Midpoint(diaPt1, diaPt2, ptcen);
|
|
|
|
m_ptCenter = ptcen;
|
|
m_dRadius = ads_distance(diaPt1, diaPt2) / 2.0;
|
|
}
|
|
|
|
ShapeType GeCircle::GetShapeType() const
|
|
{
|
|
return SHAPE_CIRCLE;
|
|
}
|
|
|
|
void GeCircle::Center(ads_point ptCen)
|
|
{
|
|
m_ptCenter > ptCen;
|
|
}
|
|
|
|
int GeCircle::HitTest2d(const ADSGePoint3d &ptTest) const
|
|
{
|
|
double dDist2d = ptTest.Distance2d(m_ptCenter);
|
|
if (fabs(dDist2d - m_dRadius) < g_Option::instance()._DIST_SNAP)
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
if (dDist2d < m_dRadius)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
return 2;
|
|
}
|
|
|
|
int GeCircle::Intersection(const GeLine* pLine, ads_point ptrp1, ads_point ptrp2) const
|
|
{
|
|
ASSERT(pLine != NULL);
|
|
return pLine->Intersection(this, ptrp1, ptrp2);
|
|
}
|
|
|
|
int GeCircle::Intersection(const GeArc* pArc, ads_point ptrp1, ads_point ptrp2) const
|
|
{
|
|
ASSERT(pArc != NULL);
|
|
AcGeCircArc3d cirT(m_ptCenter.AsAcGePoint3d(),
|
|
AcGeVector3d::kZAxis,m_dRadius);
|
|
|
|
//lfy 2010-08-31 修改存取方式
|
|
AcGeCircArc3d cirO(pArc->m_ptCenter.AsAcGePoint3d(),AcGeVector3d::kZAxis,pArc->m_dRadius);
|
|
|
|
int nInt = 0;
|
|
ADSGePoint3d pt1, pt2;
|
|
|
|
cirT.intersectWith(cirO,nInt,pt1,pt2);
|
|
if (nInt == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int nt1,nt2;
|
|
nt1 = ((pt1 & (*pArc)) != PR_OUTSIDE);
|
|
nt2 = ((pt2 & (*pArc)) != PR_OUTSIDE);
|
|
|
|
if (ptrp1)
|
|
{
|
|
if (nt1)
|
|
{
|
|
pt1 > ptrp1;
|
|
}
|
|
|
|
if (!nt1 && nt2)
|
|
{
|
|
pt2 > ptrp1;
|
|
}
|
|
}
|
|
|
|
if (ptrp2)
|
|
{
|
|
if (nt2 && nt1)
|
|
{
|
|
pt2 > ptrp2;
|
|
}
|
|
}
|
|
|
|
if (nt1 + nt2 == 2)
|
|
{
|
|
if (asPnt3d(ptrp1).distanceTo(asPnt3d(ptrp2)) < g_Option::instance()._DIST_SNAP)
|
|
{
|
|
nt2 = 0;
|
|
}
|
|
}
|
|
|
|
return nt1 + nt2;
|
|
|
|
}
|
|
|
|
int GeCircle::Intersection(const GeCircle* pCir, ads_point ptrp1, ads_point ptrp2) const
|
|
{
|
|
ASSERT(pCir != NULL);
|
|
if (!IsEqual(1.0E-5, 2, pCir->m_ptCenter.z, m_ptCenter.z))
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
//lfy 2010-08-31 修改存取方式
|
|
//同心
|
|
if ( m_ptCenter.AsAcGePoint3d().distanceTo(pCir->m_ptCenter.AsAcGePoint3d()) < 1.e-3)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
AcGeCircArc3d cirT(m_ptCenter.AsAcGePoint3d(),AcGeVector3d::kZAxis,m_dRadius);
|
|
AcGeCircArc3d cirO(pCir->m_ptCenter.AsAcGePoint3d(),AcGeVector3d::kZAxis,pCir->m_dRadius);
|
|
|
|
int nInt = 0;
|
|
ADSGePoint3d pt1, pt2;
|
|
|
|
cirT.intersectWith(cirO,nInt,pt1,pt2);
|
|
if (nInt == 0)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
if (ptrp1)
|
|
{
|
|
pt1 > ptrp1;
|
|
}
|
|
|
|
if (ptrp2)
|
|
{
|
|
pt2 > ptrp2;
|
|
}
|
|
|
|
if (asPnt3d(ptrp1).distanceTo(asPnt3d(ptrp2)) < g_Option::instance()._DIST_SNAP)
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
return 2;
|
|
}
|
|
|
|
int GeCircle::Make(const TCHAR *szlay) const
|
|
{
|
|
TCHAR szlayer[80] = _T("");
|
|
if (szlay)
|
|
{
|
|
_tcscpy(szlayer, szlay);
|
|
}
|
|
else
|
|
{
|
|
TGGetVar(_T("clayer"), szlayer);
|
|
}
|
|
|
|
return GlobalFunc::MakeEntity(RTDXF0, _T("CIRCLE"), 8, szlayer, 10, &m_ptCenter.x, 40, m_dRadius, NULL);
|
|
}
|
|
|
|
int GeCircle::Modify(const EntitySet* pEntity) const
|
|
{
|
|
ASSERT(pEntity != NULL);
|
|
EntitySet refEnt = *pEntity;
|
|
refEnt.SetData(10, &m_ptCenter.x);
|
|
refEnt.SetData(40, m_dRadius);
|
|
|
|
return refEnt.Modify();
|
|
}
|
|
|
|
int GeCircle::MakeEntity(const EntitySet* pEntity) const
|
|
{
|
|
ASSERT(pEntity != NULL);
|
|
EntitySet ent = *pEntity;
|
|
RBGroups g(_T("*"));
|
|
RBList ebuf = ads_entgetx(ent, (resbuf *)&g);
|
|
ebuf.SetData(10, &m_ptCenter.x);
|
|
ebuf.SetData(40, m_dRadius);
|
|
|
|
return ads_entmake(ebuf);
|
|
}
|
|
|
|
int GeCircle::GetSubArc(const ADSGePoint3d& ptloc, ads_real dchordLen, GeArc& arcres) const
|
|
{
|
|
if (m_dRadius < g_Option::instance()._DIST_SNAP
|
|
|| dchordLen > 2.0 * m_dRadius
|
|
|| (ptloc & (*this)) != PR_ONCIRCLE)
|
|
{
|
|
return RTERROR;
|
|
}
|
|
|
|
ads_real dsemiAng = asin(dchordLen / 2.0 / m_dRadius);
|
|
arcres.SetCenterPt(m_ptCenter);
|
|
arcres.SetRadius(m_dRadius);
|
|
arcres.SetStarAngle(AngleRangeTo2PI(ads_angle(m_ptCenter, ptloc) - dsemiAng));
|
|
arcres.SetEndAngle(AngleRangeTo2PI(ads_angle(m_ptCenter, ptloc) + dsemiAng));
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
int GeCircle::OSnap(int nMode, ADSGePoint3d &ptPick) const
|
|
{
|
|
switch(nMode)
|
|
{
|
|
case OS_CEN:
|
|
ptPick = m_ptCenter;
|
|
return nMode;
|
|
case OS_NEA:
|
|
ADSGePoint3d ptSrc = ptPick;
|
|
if (ptSrc.Project(this, ptPick) == RTNORM)
|
|
{
|
|
return nMode;
|
|
}
|
|
|
|
break;
|
|
}
|
|
|
|
return OS_NON;
|
|
}
|
|
|
|
void GeCircle::TransUCS(ads_matrix mat)
|
|
{
|
|
ADSGePoint3d ptOnEdge;
|
|
ads_polar(m_ptCenter, 0.0, m_dRadius, ptOnEdge);
|
|
m_ptCenter.TransformBy(mat);
|
|
ptOnEdge.z = m_ptCenter.z;
|
|
m_dRadius = ptOnEdge.Distance(m_ptCenter);
|
|
}
|
|
|
|
int GeCircle::PtOnCircle(const ADSGePoint3d &pt)
|
|
{
|
|
double r = pt.Distance(m_ptCenter) - m_dRadius;
|
|
if (fabs(r) < g_Option::instance()._DIST_SNAP)
|
|
{
|
|
return PR_ONCIRCLE;
|
|
}
|
|
|
|
if (r < 0)
|
|
{
|
|
return PR_INSIDE;
|
|
}
|
|
|
|
return PR_OUTSIDE;
|
|
}
|
|
|
|
ADSGePoint3d GeCircle::GetCenterPt()
|
|
{
|
|
return m_ptCenter;
|
|
}
|
|
|
|
ADSGePoint3d GeCircle::GetCenterPt() const
|
|
{
|
|
return m_ptCenter;
|
|
}
|
|
|
|
void GeCircle::SetCenterPt(ADSGePoint3d pt)
|
|
{
|
|
m_ptCenter = pt;
|
|
}
|
|
|
|
double GeCircle::GetRadius() const
|
|
{
|
|
return m_dRadius;
|
|
}
|
|
|
|
bool GeCircle::Set(const ADSGePoint3d &ptStart, const ADSGePoint3d &ptOn, const ADSGePoint3d &ptEnd)
|
|
{
|
|
AcGeVector3d v1 = ptStart - ptOn;
|
|
AcGeVector3d v2 = ptEnd - ptOn;
|
|
if (v2.isParallelTo(v1))
|
|
{
|
|
return false;
|
|
}
|
|
AcGeCircArc3d cir(ptStart,ptOn,ptEnd);
|
|
m_ptCenter = cir.center();
|
|
m_dRadius = cir.radius();
|
|
return true;
|
|
}
|
|
|
|
double GeCircle::GetRadius()
|
|
{
|
|
return m_dRadius;
|
|
}
|
|
|
|
void GeCircle::SetRadius(double dR)
|
|
{
|
|
m_dRadius = dR;
|
|
}
|
|
|
|
bool GeCircle::IsKindOf(GeEntity::TEntityId entType) const
|
|
{
|
|
switch(entType)
|
|
{
|
|
case GeEntity::eEntity:
|
|
case GeEntity::eCurve:
|
|
case GeEntity::eCircle:
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void GeCircle::CopyFrom(const GeEntity* pSrc)
|
|
{
|
|
if (this != pSrc && pSrc->IsKindOf(GeEntity::eCircle))
|
|
{
|
|
GeCircle* pArc = (GeCircle* )pSrc;
|
|
m_ptCenter = pArc->GetCenterPt();
|
|
m_dRadius = pArc->GetRadius();
|
|
}
|
|
}
|
|
|
|
|
|
int GeCircle::operator !() const
|
|
{
|
|
return m_dRadius < g_Option::instance()._DIST_SNAP;
|
|
}
|
|
|
|
GeCircle& GeCircle::operator = (const GeCircle &src)
|
|
{
|
|
if (this != &src)
|
|
{
|
|
m_ptCenter = src.GetCenterPt();
|
|
m_dRadius = src.GetRadius();
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
bool GeCircle::operator == (const GeCircle &src) const
|
|
{
|
|
return (m_ptCenter == src.GetCenterPt()
|
|
&& fabs(m_dRadius - src.GetRadius()) < g_Option::instance()._DIST_SNAP);
|
|
}
|
|
|
|
ads_real GeCircle::GetLength() const
|
|
{
|
|
return m_dRadius * 2.0 * PI;
|
|
}
|
|
|
|
GeCircle GeCircle::Offset(ads_real dist) const
|
|
{
|
|
double dRadius = m_dRadius;
|
|
dRadius = dRadius + dist;
|
|
if (dRadius < g_Option::instance()._DIST_SNAP)
|
|
{
|
|
dRadius = 0.0;
|
|
}
|
|
|
|
return GeCircle(m_ptCenter, dRadius);
|
|
}
|
|
|
|
ads_real GeCircle::Area() const
|
|
{
|
|
double dRadius = m_dRadius;
|
|
return PI * dRadius * dRadius;
|
|
}
|
|
|
|
int GeCircle::GetExtend(ads_point lowPt, ads_point upPt) const
|
|
{
|
|
ADSGePoint3d ptCenter = m_ptCenter;
|
|
double dRadius = m_dRadius;
|
|
*(ADSGePoint3d*)lowPt = ptCenter - ADSGePoint3d(dRadius, dRadius);
|
|
*(ADSGePoint3d*)upPt = ptCenter + ADSGePoint3d(dRadius, dRadius);
|
|
|
|
return RTNORM;
|
|
}
|
|
|