347 lines
8.0 KiB
C++
347 lines
8.0 KiB
C++
//-----------------------------------------------------------------------------+
|
|||
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
||
|
|
// = FileName : TGGeLine直线类
|
||
|
|
// = Version : ver2.0
|
||
|
|
// = Author : wlw
|
||
|
|
// = CreateDate : 2002-09-09
|
||
|
|
// = Description: TGGeLine类声明
|
||
|
|
// = Maintainers:
|
||
|
|
//
|
||
|
|
//-----------------------------------------------------------------------------+
|
||
|
|
#ifndef _TGGELINE_H_
|
||
|
|
#define _TGGELINE_H_
|
||
|
|
|
||
|
|
#ifndef _TGGELINEARENT_H_
|
||
|
|
#include "TGGeLinearEnt.h"
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef _TGGEARC_H_
|
||
|
|
#include "TGGeArc.h"
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef _TGGECIRCLE_H_
|
||
|
|
#include "TGGeCircle.h"
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef _TENTITYSET_H_
|
||
|
|
#include "TEntitySet.h"
|
||
|
|
#endif
|
||
|
|
|
||
|
|
class TGGePoly;
|
||
|
|
class GEOAPI TGGeLine : public TGGeLinearEnt
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
TGGeLine(const TGGeLine& src);
|
||
|
|
TGGeLine(int nflag = LS_INFINITE);
|
||
|
|
TGGeLine(const TADSGePoint3d& ptThrough, ads_real dDrt);
|
||
|
|
TGGeLine(const ads_point p1, const ads_point p2, int _flag = LS_INFINITE);
|
||
|
|
TGGeLine(const TEntitySet& entLine, int _flag = LS_INFINITE, ads_matrix tranMat = NULL);
|
||
|
|
|
||
|
|
virtual ~TGGeLine();
|
||
|
|
|
||
|
|
virtual bool IsKindOf(TEntityId entType) const;
|
||
|
|
virtual TEntityId Type() const;
|
||
|
|
|
||
|
|
virtual void TransUCS(const resbuf *pfrom, const resbuf *pto);
|
||
|
|
|
||
|
|
virtual void Reverse();
|
||
|
|
virtual ads_real PathArea() const;
|
||
|
|
|
||
|
|
virtual void TransformBy(ads_matrix mat);
|
||
|
|
virtual int GetExtend(TADSGePoint3d &ptlow, TADSGePoint3d &ptup) const;
|
||
|
|
//图形长度,周长
|
||
|
|
virtual ads_real GetLength() const;
|
||
|
|
|
||
|
|
virtual int Make(const TCHAR *szlay = NULL) const;
|
||
|
|
virtual int MakeEntity(const TEntitySet* pEntity) const;
|
||
|
|
|
||
|
|
virtual int HitTest2d(const TADSGePoint3d &ptTest) const;
|
||
|
|
|
||
|
|
virtual void SetPoints(const TADSGePoint3d& pt1, const TADSGePoint3d& pt2);
|
||
|
|
virtual int OSnap(int nMode, TADSGePoint3d &ptPick) const;
|
||
|
|
|
||
|
|
virtual int Intersection(const TGGeArc* pArc, ads_point ptrp1 = NULL, ads_point ptrp2 = NULL) const;
|
||
|
|
virtual int Intersection(const TGGeCircle* pCircle, ads_point ptrp1 = NULL, ads_point ptrp2 = NULL) const;
|
||
|
|
// virtual void CopyFrom(const TGGeEntity* pImpSrc);
|
||
|
|
|
||
|
|
virtual int Intersection(const TGGeLine* pLine, ads_point ptrp = NULL) const;
|
||
|
|
virtual int Intersection(TGGePoly* pPoly, class TPointList& pts) const;
|
||
|
|
|
||
|
|
int operator ! () const;
|
||
|
|
TGGeLine& operator = (const TGGeLine& aLine);
|
||
|
|
int operator != (const TGGeLine & aLine) const;
|
||
|
|
bool operator == (const TGGeLine & aLine) const;
|
||
|
|
|
||
|
|
virtual int OnWhichSide(const TADSGePoint3d &ptsrc) const;
|
||
|
|
virtual int Modify(const TEntitySet* pEntity) const;
|
||
|
|
virtual int GetSubLine(const TADSGePoint3d &loc, ads_real dist, TGGeLine &res) const;
|
||
|
|
|
||
|
|
virtual void SetElevation(ads_real delev);
|
||
|
|
|
||
|
|
virtual ads_real Direction() const;
|
||
|
|
virtual TVector3D Direction3d() const;
|
||
|
|
|
||
|
|
virtual ads_real* NearPoint(const ads_point pt0);
|
||
|
|
virtual ads_real* FarPoint(const ads_point pt0);
|
||
|
|
|
||
|
|
virtual TGGeLine Offset(ads_real dist) const;
|
||
|
|
|
||
|
|
virtual void SetLineFlag(int nFlag);
|
||
|
|
virtual int GetLineFlag() const;
|
||
|
|
|
||
|
|
void SetStartPoint(TADSGePoint3d ptStart);
|
||
|
|
void GetStartPoint(TADSGePoint3d& ptStart);
|
||
|
|
TADSGePoint3d GetStartPoint() const;
|
||
|
|
|
||
|
|
void SetEndPoint(TADSGePoint3d ptEnd);
|
||
|
|
void GetEndPoint(TADSGePoint3d& ptEnd);
|
||
|
|
TADSGePoint3d GetEndPoint() const;
|
||
|
|
|
||
|
|
TADSGePoint3d& StartPoint();
|
||
|
|
TADSGePoint3d& EndPoint();
|
||
|
|
|
||
|
|
TADSGePoint3d& StartPoint() const;
|
||
|
|
TADSGePoint3d& EndPoint() const;
|
||
|
|
|
||
|
|
void MidPoint(TADSGePoint3d &ptres) const;
|
||
|
|
TADSGePoint3d MidPoint() const;
|
||
|
|
|
||
|
|
public:
|
||
|
|
TADSGePoint3d m_startPoint;
|
||
|
|
TADSGePoint3d m_endPoint;
|
||
|
|
int m_nFlag;
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
inline int TGGeLine::operator != (const TGGeLine& aLine) const
|
||
|
|
{
|
||
|
|
return !((*this) == aLine);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::SetStartPoint(TADSGePoint3d ptStart)
|
||
|
|
{
|
||
|
|
m_startPoint = ptStart;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::GetStartPoint(TADSGePoint3d& ptStart)
|
||
|
|
{
|
||
|
|
ptStart = m_startPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TADSGePoint3d TGGeLine::GetStartPoint() const
|
||
|
|
{
|
||
|
|
return m_startPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::SetEndPoint(TADSGePoint3d ptEnd)
|
||
|
|
{
|
||
|
|
m_endPoint = ptEnd;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::GetEndPoint(TADSGePoint3d& ptEnd)
|
||
|
|
{
|
||
|
|
ptEnd = m_endPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TADSGePoint3d TGGeLine::GetEndPoint() const
|
||
|
|
{
|
||
|
|
return m_endPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TADSGePoint3d& TGGeLine::StartPoint()
|
||
|
|
{
|
||
|
|
return m_startPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TADSGePoint3d& TGGeLine::EndPoint()
|
||
|
|
{
|
||
|
|
return m_endPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TADSGePoint3d& TGGeLine::StartPoint() const
|
||
|
|
{
|
||
|
|
return (TADSGePoint3d&)m_startPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TADSGePoint3d& TGGeLine::EndPoint() const
|
||
|
|
{
|
||
|
|
return (TADSGePoint3d&)m_endPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::SetLineFlag(int nFlag)
|
||
|
|
{
|
||
|
|
m_nFlag = nFlag;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline int TGGeLine::GetLineFlag() const
|
||
|
|
{
|
||
|
|
return m_nFlag;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::SetPoints(const TADSGePoint3d& pt1, const TADSGePoint3d& pt2)
|
||
|
|
{
|
||
|
|
m_startPoint = pt1;
|
||
|
|
m_endPoint = pt2;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::SetElevation(ads_real delev)
|
||
|
|
{
|
||
|
|
m_startPoint.z = delev;
|
||
|
|
m_endPoint.z = delev;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::Reverse()
|
||
|
|
{
|
||
|
|
TADSGePoint3d pttmp = m_startPoint;
|
||
|
|
m_startPoint = m_endPoint;
|
||
|
|
m_endPoint = pttmp;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline ads_real* TGGeLine::NearPoint(const ads_point pt0)
|
||
|
|
{
|
||
|
|
if (ads_distance((ads_real *)pt0, (ads_real *)m_startPoint)
|
||
|
|
< ads_distance((ads_real *)pt0, (ads_real *)m_endPoint))
|
||
|
|
{
|
||
|
|
return &m_startPoint.x;
|
||
|
|
}
|
||
|
|
|
||
|
|
return &m_endPoint.x;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline ads_real* TGGeLine::FarPoint(const ads_point pt0)
|
||
|
|
{
|
||
|
|
if (ads_distance((ads_real *)pt0, m_startPoint)
|
||
|
|
> ads_distance((ads_real *)pt0,m_endPoint))
|
||
|
|
{
|
||
|
|
return &m_startPoint.x;
|
||
|
|
}
|
||
|
|
|
||
|
|
return &m_endPoint.x;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TADSGePoint3d TGGeLine::MidPoint() const
|
||
|
|
{
|
||
|
|
TADSGePoint3d ptMid;
|
||
|
|
ptMid.x = (m_startPoint.x + m_endPoint.x) / 2.0;
|
||
|
|
ptMid.y = (m_startPoint.y + m_endPoint.y) / 2.0;
|
||
|
|
ptMid.z = (m_startPoint.z + m_endPoint.z) / 2.0;
|
||
|
|
|
||
|
|
return ptMid;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::MidPoint(TADSGePoint3d& ptres) const
|
||
|
|
{
|
||
|
|
ptres.x = (m_startPoint.x + m_endPoint.x) / 2.0;
|
||
|
|
ptres.y = (m_startPoint.y + m_endPoint.y) / 2.0;
|
||
|
|
ptres.z = (m_startPoint.z + m_endPoint.z) / 2.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::TransUCS(const resbuf *pfrom, const resbuf *pto)
|
||
|
|
{
|
||
|
|
TADSGePoint3d spt = m_startPoint, ept = m_endPoint;
|
||
|
|
ads_trans(spt, pfrom, pto, 0, m_startPoint);
|
||
|
|
ads_trans(ept, pfrom, pto, 0, m_endPoint);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline void TGGeLine::TransformBy(ads_matrix mat)
|
||
|
|
{
|
||
|
|
m_startPoint.TransformBy(mat);
|
||
|
|
m_endPoint.TransformBy(mat);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool TGGeLine::IsKindOf(TGGeEntity::TEntityId entType) const
|
||
|
|
{
|
||
|
|
switch(entType)
|
||
|
|
{
|
||
|
|
case TGGeEntity::eEntity:
|
||
|
|
case TGGeEntity::eCurve:
|
||
|
|
case TGGeEntity::eLinearEnt:
|
||
|
|
case TGGeEntity::eLine:
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TGGeEntity::TEntityId TGGeLine::Type() const
|
||
|
|
{
|
||
|
|
return TGGeEntity::eLine;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline int TGGeLine::GetExtend(TADSGePoint3d &ptlow, TADSGePoint3d &ptup) const
|
||
|
|
{
|
||
|
|
TADSGePoint3d ptStart = m_startPoint;
|
||
|
|
TADSGePoint3d ptEnd = m_endPoint;
|
||
|
|
|
||
|
|
ptlow = Min(ptStart, ptEnd);
|
||
|
|
ptup = Max(ptStart, ptEnd);
|
||
|
|
|
||
|
|
return RTNORM;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline ads_real TGGeLine::GetLength() const
|
||
|
|
{
|
||
|
|
//return m_startPoint.AsAcGePoint3d().distanceTo(m_endPoint);
|
||
|
|
//return ads_distance(m_startPoint,m_endPoint);
|
||
|
|
|
||
|
|
double t1 = m_startPoint.x - m_endPoint.x;
|
||
|
|
double t2 = m_startPoint.y - m_endPoint.y;
|
||
|
|
double t3 = m_startPoint.z - m_endPoint.z;
|
||
|
|
return sqrt(t1 * t1 + t2 * t2 + t3 * t3);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline ads_real TGGeLine::Direction() const
|
||
|
|
{
|
||
|
|
return ads_angle(m_startPoint,
|
||
|
|
m_endPoint);
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TVector3D TGGeLine::Direction3d() const
|
||
|
|
{
|
||
|
|
ASSERT(GetLength() > _DIST_SNAP);
|
||
|
|
|
||
|
|
TVector3D vt = m_endPoint - m_startPoint;
|
||
|
|
vt.Normalize();
|
||
|
|
|
||
|
|
return vt;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline ads_real TGGeLine::PathArea() const
|
||
|
|
{
|
||
|
|
TADSGePoint3d ptStart = m_startPoint;
|
||
|
|
TADSGePoint3d ptEnd = m_endPoint;
|
||
|
|
|
||
|
|
return (ptEnd.x - ptStart.x) * (ptStart.y + ptEnd.y) / 2.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline int TGGeLine::operator !() const
|
||
|
|
{
|
||
|
|
return m_endPoint == m_startPoint;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline bool TGGeLine::operator == (const TGGeLine& aLine) const
|
||
|
|
{
|
||
|
|
TADSGePoint3d ptStart = m_startPoint;
|
||
|
|
TADSGePoint3d ptEnd = m_endPoint;
|
||
|
|
int nFlag = m_nFlag;
|
||
|
|
|
||
|
|
TADSGePoint3d ptStartSrc = aLine.GetStartPoint();
|
||
|
|
TADSGePoint3d ptEndSrc = aLine.GetEndPoint();
|
||
|
|
int nFlagSrc = aLine.GetLineFlag();
|
||
|
|
|
||
|
|
return (nFlag == nFlagSrc
|
||
|
|
&& (ptStart == ptStartSrc && ptEnd == ptEndSrc)
|
||
|
|
|| (ptStart == ptEndSrc && ptEnd == ptStartSrc));
|
||
|
|
}
|
||
|
|
|
||
|
|
inline TGGeLine& TGGeLine::operator = (const TGGeLine& aLine)
|
||
|
|
{
|
||
|
|
if (this != &aLine)
|
||
|
|
{
|
||
|
|
m_startPoint = aLine.m_startPoint;
|
||
|
|
m_endPoint = aLine.m_endPoint;
|
||
|
|
m_nFlag = aLine.m_nFlag;
|
||
|
|
}
|
||
|
|
return *this;
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|