348 lines
7.4 KiB
C++
348 lines
7.4 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, SH Software Co. Ltd.
|
|
// = FileName : XLine直线类
|
|
// = Version : ver2.0
|
|
// = Author : zjq
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: XLine类声明
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#ifndef _XLINE_H_
|
|
#define _XLINE_H_
|
|
|
|
#ifndef _XLINEARENT_H_
|
|
#include "XLinearEnt.h"
|
|
#endif
|
|
|
|
#ifndef _XARC_H_
|
|
#include "XArc.h"
|
|
#endif
|
|
|
|
#ifndef _XCIRCLE_H_
|
|
#include "XCircle.h"
|
|
#endif
|
|
|
|
#ifndef _ENTITY_H_
|
|
#include "Entity.h"
|
|
#endif
|
|
|
|
class XPoly;
|
|
class GEOAPI XLine : public XLinearEnt
|
|
{
|
|
public:
|
|
XLine(const XLine& src);
|
|
XLine(int nflag = LS_INFINITE);
|
|
XLine(const XPoint& ptThrough, ads_real dDrt);
|
|
XLine(const ads_point p1, const ads_point p2, int _flag = LS_INFINITE);
|
|
XLine(const Entity& entLine, int _flag = LS_INFINITE, ads_matrix tranMat = NULL);
|
|
|
|
virtual ~XLine();
|
|
|
|
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(XPoint &ptlow, XPoint &ptup) const;
|
|
//图形长度,周长
|
|
virtual ads_real GetLength() const;
|
|
|
|
virtual int Make(const TCHAR *szlay = NULL) const;
|
|
virtual int MakeEntity(const Entity* pEntity) const;
|
|
|
|
virtual int HitTest2d(const XPoint &ptTest) const;
|
|
|
|
virtual void SetPoints(const XPoint& pt1, const XPoint& pt2);
|
|
virtual int OSnap(int nMode, XPoint &ptPick) const;
|
|
|
|
virtual int Intersection(const XArc* pArc, ads_point ptrp1 = NULL, ads_point ptrp2 = NULL) const;
|
|
virtual int Intersection(const XCircle* pCircle, ads_point ptrp1 = NULL, ads_point ptrp2 = NULL) const;
|
|
// virtual void CopyFrom(const XEntity* pImpSrc);
|
|
|
|
virtual int Intersection(const XLine* pLine, ads_point ptrp = NULL) const;
|
|
virtual int Intersection(XPoly* pPoly, class PointList& pts) const;
|
|
|
|
int operator ! () const;
|
|
XLine& operator = (const XLine& aLine);
|
|
int operator != (const XLine & aLine) const;
|
|
bool operator == (const XLine & aLine) const;
|
|
|
|
virtual int OnWhichSide(const XPoint &ptsrc) const;
|
|
virtual int Modify(const Entity* pEntity) const;
|
|
virtual int GetSubLine(const XPoint &loc, ads_real dist, XLine &res) const;
|
|
|
|
virtual void SetElevation(ads_real delev);
|
|
|
|
virtual ads_real Direction() const;
|
|
virtual XVector3D Direction3d() const;
|
|
|
|
virtual ads_real* NearPoint(const ads_point pt0);
|
|
virtual ads_real* FarPoint(const ads_point pt0);
|
|
|
|
virtual XLine Offset(ads_real dist) const;
|
|
|
|
virtual void SetLineFlag(int nFlag);
|
|
virtual int GetLineFlag() const;
|
|
|
|
void SetStartPoint(XPoint ptStart);
|
|
void GetStartPoint(XPoint& ptStart);
|
|
XPoint GetStartPoint() const;
|
|
|
|
void SetEndPoint(XPoint ptEnd);
|
|
void GetEndPoint(XPoint& ptEnd);
|
|
XPoint GetEndPoint() const;
|
|
|
|
XPoint& StartPoint();
|
|
XPoint& EndPoint();
|
|
|
|
XPoint& StartPoint() const;
|
|
XPoint& EndPoint() const;
|
|
|
|
void MidPoint(XPoint &ptres) const;
|
|
XPoint MidPoint() const;
|
|
|
|
public:
|
|
XPoint m_startPoint;
|
|
XPoint m_endPoint;
|
|
int m_nFlag;
|
|
};
|
|
|
|
|
|
inline int XLine::operator != (const XLine& aLine) const
|
|
{
|
|
return !((*this) == aLine);
|
|
}
|
|
|
|
inline void XLine::SetStartPoint(XPoint ptStart)
|
|
{
|
|
m_startPoint = ptStart;
|
|
}
|
|
|
|
inline void XLine::GetStartPoint(XPoint& ptStart)
|
|
{
|
|
ptStart = m_startPoint;
|
|
}
|
|
|
|
inline XPoint XLine::GetStartPoint() const
|
|
{
|
|
return m_startPoint;
|
|
}
|
|
|
|
inline void XLine::SetEndPoint(XPoint ptEnd)
|
|
{
|
|
m_endPoint = ptEnd;
|
|
}
|
|
|
|
inline void XLine::GetEndPoint(XPoint& ptEnd)
|
|
{
|
|
ptEnd = m_endPoint;
|
|
}
|
|
|
|
inline XPoint XLine::GetEndPoint() const
|
|
{
|
|
return m_endPoint;
|
|
}
|
|
|
|
inline XPoint& XLine::StartPoint()
|
|
{
|
|
return m_startPoint;
|
|
}
|
|
|
|
inline XPoint& XLine::EndPoint()
|
|
{
|
|
return m_endPoint;
|
|
}
|
|
|
|
inline XPoint& XLine::StartPoint() const
|
|
{
|
|
return (XPoint&)m_startPoint;
|
|
}
|
|
|
|
inline XPoint& XLine::EndPoint() const
|
|
{
|
|
return (XPoint&)m_endPoint;
|
|
}
|
|
|
|
inline void XLine::SetLineFlag(int nFlag)
|
|
{
|
|
m_nFlag = nFlag;
|
|
}
|
|
|
|
inline int XLine::GetLineFlag() const
|
|
{
|
|
return m_nFlag;
|
|
}
|
|
|
|
inline void XLine::SetPoints(const XPoint& pt1, const XPoint& pt2)
|
|
{
|
|
m_startPoint = pt1;
|
|
m_endPoint = pt2;
|
|
}
|
|
|
|
inline void XLine::SetElevation(ads_real delev)
|
|
{
|
|
m_startPoint.z = delev;
|
|
m_endPoint.z = delev;
|
|
}
|
|
|
|
inline void XLine::Reverse()
|
|
{
|
|
XPoint pttmp = m_startPoint;
|
|
m_startPoint = m_endPoint;
|
|
m_endPoint = pttmp;
|
|
}
|
|
|
|
inline ads_real* XLine::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* XLine::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 XPoint XLine::MidPoint() const
|
|
{
|
|
XPoint 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 XLine::MidPoint(XPoint& 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 XLine::TransUCS(const resbuf *pfrom, const resbuf *pto)
|
|
{
|
|
XPoint spt = m_startPoint, ept = m_endPoint;
|
|
ads_trans(spt, pfrom, pto, 0, m_startPoint);
|
|
ads_trans(ept, pfrom, pto, 0, m_endPoint);
|
|
}
|
|
|
|
inline void XLine::TransformBy(ads_matrix mat)
|
|
{
|
|
m_startPoint.TransformBy(mat);
|
|
m_endPoint.TransformBy(mat);
|
|
}
|
|
|
|
inline bool XLine::IsKindOf(XEntity::TEntityId entType) const
|
|
{
|
|
switch(entType)
|
|
{
|
|
case XEntity::eEntity:
|
|
case XEntity::eCurve:
|
|
case XEntity::eLinearEnt:
|
|
case XEntity::eLine:
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
inline XEntity::TEntityId XLine::Type() const
|
|
{
|
|
return XEntity::eLine;
|
|
}
|
|
|
|
inline int XLine::GetExtend(XPoint &ptlow, XPoint &ptup) const
|
|
{
|
|
XPoint ptStart = m_startPoint;
|
|
XPoint ptEnd = m_endPoint;
|
|
|
|
ptlow = Min(ptStart, ptEnd);
|
|
ptup = Max(ptStart, ptEnd);
|
|
|
|
return RTNORM;
|
|
}
|
|
|
|
inline ads_real XLine::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 XLine::Direction() const
|
|
{
|
|
return ads_angle(m_startPoint,
|
|
m_endPoint);
|
|
}
|
|
|
|
inline XVector3D XLine::Direction3d() const
|
|
{
|
|
ASSERT(GetLength() > _DIST_SNAP);
|
|
|
|
XVector3D vt = m_endPoint - m_startPoint;
|
|
vt.Normalize();
|
|
|
|
return vt;
|
|
}
|
|
|
|
inline ads_real XLine::PathArea() const
|
|
{
|
|
XPoint ptStart = m_startPoint;
|
|
XPoint ptEnd = m_endPoint;
|
|
|
|
return (ptEnd.x - ptStart.x) * (ptStart.y + ptEnd.y) / 2.0;
|
|
}
|
|
|
|
inline int XLine::operator !() const
|
|
{
|
|
return m_endPoint == m_startPoint;
|
|
}
|
|
|
|
inline bool XLine::operator == (const XLine& aLine) const
|
|
{
|
|
XPoint ptStart = m_startPoint;
|
|
XPoint ptEnd = m_endPoint;
|
|
int nFlag = m_nFlag;
|
|
|
|
XPoint ptStartSrc = aLine.GetStartPoint();
|
|
XPoint ptEndSrc = aLine.GetEndPoint();
|
|
int nFlagSrc = aLine.GetLineFlag();
|
|
|
|
return (nFlag == nFlagSrc
|
|
&& (ptStart == ptStartSrc && ptEnd == ptEndSrc)
|
|
|| (ptStart == ptEndSrc && ptEnd == ptStartSrc));
|
|
}
|
|
|
|
inline XLine& XLine::operator = (const XLine& aLine)
|
|
{
|
|
if (this != &aLine)
|
|
{
|
|
m_startPoint = aLine.m_startPoint;
|
|
m_endPoint = aLine.m_endPoint;
|
|
m_nFlag = aLine.m_nFlag;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
#endif
|