383 lines
9.7 KiB
C++
383 lines
9.7 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TGGeCurveSegment类
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TGGeCurveSegment类声明
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#ifndef _TGGECURVESEGMENT_H_
|
|
#define _TGGECURVESEGMENT_H_
|
|
|
|
#ifndef _TENTITYSET_H_
|
|
#include "TEntitySet.h"
|
|
#endif
|
|
|
|
#ifndef _TGGEPOLY2D_H_
|
|
#include "TGGePoly2D.h"
|
|
#endif
|
|
|
|
#ifndef _TADSGEPOINTDIR2D_H_
|
|
#include "TADSGePointDir2d.h"
|
|
#endif
|
|
|
|
class TGGePoly2D;
|
|
class GEOAPI TGGeCurveSegment : public TGGeLine
|
|
{
|
|
public:
|
|
|
|
TGGeCurveSegment(int flg = LS_FINITE);
|
|
TGGeCurveSegment(const TGGeCurveSegment &src);
|
|
TGGeCurveSegment(const TEntitySet & ent, int flg = LS_FINITE);
|
|
TGGeCurveSegment(const TADSGePoint3d &spt, const TADSGePoint3d &ept, ads_real dAng, int flg = LS_FINITE);
|
|
|
|
virtual ~TGGeCurveSegment();
|
|
|
|
TGGeCurveSegment & operator = (const TGGeLine &ln);
|
|
TGGeCurveSegment & operator = (const TGGeArc &arc);
|
|
TGGeCurveSegment & operator = (const TGGeCircle &cir);
|
|
TGGeCurveSegment & operator = (const TGGeCurveSegment &src);
|
|
|
|
bool operator == (const TGGeCurveSegment &src) const;
|
|
|
|
//lfy 2010-08-31 增加line,arc的set函数
|
|
TGGeCurveSegment & SetLine(const TADSGePoint3d& pt1, const TADSGePoint3d& pt2);
|
|
TGGeCurveSegment & SetArc(const TADSGePoint3d &spt, const TADSGePoint3d &ept, ads_real dang);
|
|
TGGeCurveSegment & SetCircle(const TADSGePoint3d& ptCen,double dRadius);
|
|
|
|
|
|
virtual bool IsKindOf(TEntityId entType) const;
|
|
virtual TEntityId Type() const;
|
|
virtual void CopyFrom(const TGGeEntity* pSrc);
|
|
|
|
virtual int Make(LPCTSTR lay = NULL) const;
|
|
virtual int MakeEntity(const TEntitySet &e);
|
|
|
|
virtual int HitTest2d(const TADSGePoint3d &ptTest) const;
|
|
|
|
virtual int OSnap(int nMode, TADSGePoint3d &ptPick) const;
|
|
|
|
virtual int GetExtend(TADSGePoint3d &low, TADSGePoint3d &up) 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 TransformBy(ads_matrix mat);
|
|
|
|
virtual void SetPoints(const TADSGePoint3d &ptStart, const TADSGePoint3d &ptEnd);
|
|
|
|
//图形长度,周长
|
|
virtual ads_real GetLength() const;
|
|
|
|
virtual TADSGePoint3d MidPoint() const;
|
|
|
|
// 与曲线方向有关的成员
|
|
virtual TGGeArc GetArc() const;
|
|
|
|
// 0--左(内);1-右(外);2-其他 ---> 枚举,下同
|
|
virtual int OnWhichSide(const TADSGePoint3d &src) const;
|
|
|
|
// 0-左;1-右;2-其他;与上面的区别是,弧段作为有限长,在圆外但在弦的左侧算左
|
|
virtual int OnWhichSide1(const TADSGePoint3d &src) const;
|
|
|
|
// 从端点开始沿曲线走过给定距离的点向量
|
|
virtual int Polar(ads_real nDist, TADSGePointDir2d &res, int bFromStart = 1) const;
|
|
|
|
virtual void AsPoly2D(TGGePoly2D &poly) const;
|
|
|
|
virtual ads_real PathArea(TADSGePoint3d &tmpt) const;
|
|
|
|
// 取得指向内部的方向,线和弧不支持圆。 pt--0:start; 1--end
|
|
virtual ads_real IDirection(int pt) const;
|
|
|
|
// 曲线上的点pt的方向(切向)
|
|
virtual ads_real Direction(const TADSGePoint3d &pt) const;
|
|
|
|
// 求通过pt点的法向
|
|
virtual ads_real OrthoDirection(const TADSGePoint3d &pt) const;
|
|
|
|
// 求到端点的沿曲线线位移, 在线内距离为正,否则为负, 和Polar配合使用
|
|
// pt如果不在线上的话则先投影
|
|
virtual ads_real PathDistance(const TADSGePoint3d &pt, int bFromStart = 1) const;
|
|
|
|
virtual bool IsDirectionCurve();
|
|
|
|
int Is(CurveType t) const;
|
|
|
|
int MakeArrow(TEntitySet &) const;
|
|
|
|
int ProjectToMe(const TADSGePoint3d &src, TADSGePoint3d &res) const;
|
|
|
|
int Intersection(const TGGeLine &, ads_point, ads_point) const ;
|
|
int Intersection(const TGGeCurveSegment &, ads_point pt1, ads_point pt2) const;
|
|
|
|
int GetSubSegment(const TADSGePoint3d &ptloc, ads_real dchordLen, TGGeCurveSegment &ptres) const;
|
|
|
|
//Wcs到展开坐标系
|
|
TADSGePoint3d Wcs2Ecs(TADSGePoint3d pt) const;
|
|
//展开坐标系到Wcs
|
|
TADSGePoint3d Ecs2Wcs(TADSGePoint3d pt) const;
|
|
|
|
void Wcs2Ecs(const TGGePoly2D &polyWcs, TGGePoly2D &polyEcs) const;
|
|
void Ecs2Wcs(const TGGePoly2D &polyEcs, TGGePoly2D &polyWcs) const;
|
|
|
|
TGGeCircle GetCircle() const;
|
|
TGGeLine GetLine() const;
|
|
|
|
//点到曲线的距离, 负数为内/左侧
|
|
double GetDist2Me(TADSGePoint3d ptMid) const;
|
|
|
|
double GetChordLength(double nArcLen) const;
|
|
|
|
CurveType GetCurveType() const;
|
|
|
|
static resbuf *Mask(LPCTSTR lay = NULL);
|
|
|
|
resbuf * AsFence(int nCirDiv = 20) const;
|
|
|
|
AcDbCurve *AsAcDbCurve() const;
|
|
|
|
TGGeCurveSegment Offset(ads_real dDist, int nflg) const;
|
|
TGGeCurveSegment Offset(int lr, ads_real dDist, int nflg) const;
|
|
|
|
double GetBulge() const;
|
|
void SetBulge(const double dBulge);
|
|
public:
|
|
|
|
ads_real m_dBulge;
|
|
};
|
|
|
|
inline bool TGGeCurveSegment::operator == (const TGGeCurveSegment &src) const
|
|
{
|
|
bool bRet = false;
|
|
if (src.GetCurveType() != GetCurveType())
|
|
{
|
|
bRet = false;
|
|
}
|
|
else if (Is(CURVE_LINE))
|
|
{
|
|
bRet = (GetLine() == src.GetLine());
|
|
}
|
|
else if (Is(CURVE_ARC))
|
|
{
|
|
bRet = (GetArc() == src.GetArc());
|
|
}
|
|
else
|
|
{
|
|
bRet = (GetCircle() == src.GetCircle());
|
|
}
|
|
|
|
return bRet;
|
|
}
|
|
|
|
inline int TGGeCurveSegment::Is(CurveType t) const
|
|
{
|
|
double dBulge = fabs(GetBulge());
|
|
return ((dBulge < 1E-6 && t == CURVE_LINE)
|
|
|| (fabs(2.0 * PI - dBulge) < 1E-5 && t == CURVE_CIRCLE)
|
|
|| (dBulge > 1E-6 && dBulge < 2.0 * PI - 1E-6 && t == CURVE_ARC));
|
|
}
|
|
|
|
inline CurveType TGGeCurveSegment::GetCurveType() const
|
|
{
|
|
CurveType t;
|
|
double dBulge = fabs(GetBulge());
|
|
if (dBulge < 1E-6)
|
|
{
|
|
t = CURVE_LINE;
|
|
}
|
|
else if (fabs(2.0 * PI - dBulge) < 1E-5)
|
|
{
|
|
t = CURVE_CIRCLE;
|
|
}
|
|
else
|
|
{
|
|
t = CURVE_ARC;
|
|
}
|
|
|
|
return t;
|
|
}
|
|
|
|
inline TGGeLine TGGeCurveSegment::GetLine() const
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
inline double TGGeCurveSegment::GetChordLength(double nArcLen) const
|
|
{
|
|
double nRes = nArcLen;
|
|
if (Is(CURVE_ARC))
|
|
{
|
|
TGGeArc ar = GetArc();
|
|
double dRadius = ar.GetRadius();
|
|
nRes = 2.0 * dRadius * sin(nArcLen / 2.0 / dRadius);
|
|
}
|
|
|
|
return fabs(nRes);
|
|
}
|
|
|
|
inline int TGGeCurveSegment::HitTest2d(const TADSGePoint3d &ptTest) const
|
|
{
|
|
CurveType t = GetCurveType();
|
|
int nHitFlag = 0;
|
|
if (t == CURVE_LINE)
|
|
{
|
|
nHitFlag = GetLine().HitTest2d(ptTest);
|
|
}
|
|
else if (t == CURVE_ARC)
|
|
{
|
|
nHitFlag = GetArc().HitTest2d(ptTest);
|
|
}
|
|
else if (t == CURVE_CIRCLE)
|
|
{
|
|
nHitFlag = GetCircle().HitTest2d(ptTest);
|
|
}
|
|
return nHitFlag;
|
|
}
|
|
|
|
inline int TGGeCurveSegment::MakeEntity(const TEntitySet &e)
|
|
{
|
|
if (Is(CURVE_LINE))
|
|
{
|
|
return GetLine().MakeEntity(&e);
|
|
}
|
|
|
|
if (Is(CURVE_ARC))
|
|
{
|
|
return GetArc().MakeEntity(&e);
|
|
}
|
|
|
|
if (Is(CURVE_CIRCLE))
|
|
{
|
|
return GetCircle().MakeEntity(&e);
|
|
}
|
|
return RTERROR;
|
|
}
|
|
|
|
inline int TGGeCurveSegment::GetExtend(TADSGePoint3d &lowPt, TADSGePoint3d &upPt) const
|
|
{
|
|
if (Is(CURVE_LINE))
|
|
{
|
|
return TGGeLine::GetExtend(lowPt, upPt);
|
|
}
|
|
else if (Is(CURVE_ARC))
|
|
{
|
|
return GetArc().GetExtend(lowPt, upPt);
|
|
}
|
|
else
|
|
{
|
|
return GetCircle().GetExtend(lowPt, upPt);
|
|
}
|
|
}
|
|
|
|
inline TGGeCurveSegment & TGGeCurveSegment::operator = (const TGGeCurveSegment &src)
|
|
{
|
|
if (this != &src)
|
|
{
|
|
m_nFlag = src.m_nFlag;
|
|
m_startPoint = src.m_startPoint;
|
|
m_endPoint = src.m_endPoint;
|
|
m_dBulge = src.m_dBulge;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
inline TGGeCurveSegment & TGGeCurveSegment::operator = (const TGGeLine &ln)
|
|
{
|
|
m_nFlag = ln.m_nFlag;
|
|
m_startPoint = ln.m_startPoint;
|
|
m_endPoint = ln.m_endPoint;
|
|
m_dBulge = 0.0;
|
|
return *this;
|
|
}
|
|
|
|
inline TGGeCurveSegment & TGGeCurveSegment::operator = (const TGGeArc &arc)
|
|
{
|
|
//SetLineFlag(LS_FINITE);
|
|
m_nFlag = LS_FINITE;
|
|
|
|
TADSGePoint3d ptStart, ptEnd;
|
|
TADSGePoint3d ptCen = arc.GetCenterPt();
|
|
double dRadius = arc.GetRadius();
|
|
|
|
ads_polar(ptCen, arc.GetStarAngle(), dRadius, ptStart);
|
|
ads_polar(ptCen, arc.GetEndAngle(), dRadius, ptEnd);
|
|
|
|
m_startPoint = ptStart;
|
|
m_endPoint = ptEnd;
|
|
m_dBulge = arc.Bulge();
|
|
|
|
return *this;
|
|
}
|
|
|
|
inline TGGeCurveSegment & TGGeCurveSegment::operator = (const TGGeCircle &cir)
|
|
{
|
|
TADSGePoint3d ptStart, ptEnd;
|
|
TADSGePoint3d ptCen = cir.GetCenterPt();
|
|
double dRadius = cir.GetRadius();
|
|
|
|
ads_polar(ptCen, 0.0, dRadius, ptStart);
|
|
ads_polar(ptCen, PI, dRadius, ptEnd);
|
|
|
|
m_startPoint = ptStart;
|
|
m_endPoint = ptEnd;
|
|
m_dBulge = 2.0 * PI;
|
|
|
|
return *this;
|
|
}
|
|
|
|
class GEOAPI TGGeDirectionCurve : public TGGeCurveSegment
|
|
{
|
|
public:
|
|
TGGeDirectionCurve(int flg = LS_FINITE);
|
|
TGGeDirectionCurve(const TGGeArc &ar, int bMinus = 0);
|
|
TGGeDirectionCurve(const TGGeDirectionCurve &src);
|
|
TGGeDirectionCurve(const TADSGePoint3d &spt, const TADSGePoint3d &ept, ads_real dAng = 0.0, int flg = LS_FINITE);
|
|
|
|
virtual ~TGGeDirectionCurve();
|
|
|
|
virtual int IsMinusArc() const;
|
|
|
|
// 与曲线方向有关的成员
|
|
virtual int OnWhichSide(const TADSGePoint3d &src) const;
|
|
virtual int OnWhichSide1(const TADSGePoint3d &src) const;
|
|
|
|
// 从端点开始沿曲线走过给定距离的点向量
|
|
virtual int Polar(ads_real nDist, TADSGePointDir2d &res, BOOL bFromStart = TRUE) const;
|
|
|
|
virtual void Reverse();
|
|
|
|
virtual void TransUCS(ads_matrix mat);
|
|
virtual void TransUCS(const resbuf *, const resbuf *);
|
|
|
|
virtual void AsPoly2D(TGGePoly2D &poly) const;
|
|
|
|
virtual void SetPoints(const TADSGePoint3d &ptStart, const TADSGePoint3d &ptEnd);
|
|
|
|
// 端点处朝曲线段内部的方向
|
|
virtual ads_real IDirection(int pt) const;
|
|
|
|
// 取得指向内部的方向支持Line,Arc,不支持Cir。 pt--0:start; 1--end
|
|
virtual ads_real PathArea(TADSGePoint3d &tmpt) const;
|
|
|
|
virtual ads_real Direction(const TADSGePoint3d &pt) const;
|
|
|
|
// 求到端点的沿曲线线位移, 在线内距离为正,否则为负, 和Polar配合使用
|
|
// pt如果不在线上的话则先投影
|
|
virtual ads_real PathDistance(const TADSGePoint3d &pt, BOOL bFromStart = TRUE) const;
|
|
|
|
// 求通过pt点的法向
|
|
virtual ads_real OrthoDirection(const TADSGePoint3d &pt) const;
|
|
|
|
// dist left<0 / right>0
|
|
virtual TGGeCurveSegment GetCurve() const;
|
|
virtual TGGeDirectionCurve Offset(ads_real dist, int flg) const;
|
|
|
|
virtual bool IsDirectionCurve();
|
|
|
|
TGGeArc GetArc() const;
|
|
};
|
|
|
|
#endif |