332 lines
7.7 KiB
C++
332 lines
7.7 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, SH Software Co. Ltd.
|
|
// = FileName : XCurveSegment类
|
|
// = Version : ver2.0
|
|
// = Author : zjq
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: XCurveSegment类声明
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#ifndef _XCURVESEGMENT_H_
|
|
#define _XCURVESEGMENT_H_
|
|
|
|
#ifndef _ENTITY_H_
|
|
#include "Entity.h"
|
|
#endif
|
|
|
|
#ifndef _XPOLY2D_H_
|
|
#include "XPoly2D.h"
|
|
#endif
|
|
|
|
#ifndef _XPointDir2d_H_
|
|
#include "XPointDir2d.h"
|
|
#endif
|
|
|
|
class XPoly2D;
|
|
class GEOAPI XCurveSegment : public XLine
|
|
{
|
|
public:
|
|
|
|
XCurveSegment(int flg = LS_FINITE);
|
|
XCurveSegment(const XCurveSegment &src);
|
|
XCurveSegment(const Entity & ent, int flg = LS_FINITE);
|
|
XCurveSegment(const XPoint &spt, const XPoint &ept, ads_real dAng, int flg = LS_FINITE);
|
|
|
|
virtual ~XCurveSegment();
|
|
|
|
XCurveSegment & operator = (const XLine &ln);
|
|
XCurveSegment & operator = (const XArc &arc);
|
|
XCurveSegment & operator = (const XCircle &cir);
|
|
XCurveSegment & operator = (const XCurveSegment &src);
|
|
|
|
bool operator == (const XCurveSegment &src) const;
|
|
|
|
//zjq 2009-08-31 增加line,arc的set函数
|
|
XCurveSegment & SetLine(const XPoint& pt1, const XPoint& pt2);
|
|
XCurveSegment & SetArc(const XPoint &spt, const XPoint &ept, ads_real dang);
|
|
XCurveSegment & SetCircle(const XPoint& ptCen,double dRadius);
|
|
|
|
|
|
virtual bool IsKindOf(TEntityId entType) const;
|
|
virtual TEntityId Type() const;
|
|
virtual void CopyFrom(const XEntity* pSrc);
|
|
|
|
virtual int Make(LPCTSTR lay = NULL) const;
|
|
virtual int MakeEntity(const Entity &e);
|
|
|
|
virtual int HitTest2d(const XPoint &ptTest) const;
|
|
|
|
virtual int OSnap(int nMode, XPoint &ptPick) const;
|
|
|
|
virtual int GetExtend(XPoint &low, XPoint &up) 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 TransformBy(ads_matrix mat);
|
|
|
|
virtual void SetPoints(const XPoint &ptStart, const XPoint &ptEnd);
|
|
|
|
//图形长度,周长
|
|
virtual ads_real GetLength() const;
|
|
|
|
virtual XPoint MidPoint() const;
|
|
|
|
// 与曲线方向有关的成员
|
|
virtual XArc GetArc() const;
|
|
|
|
// 0--左(内);1-右(外);2-其他 ---> 枚举,下同
|
|
virtual int OnWhichSide(const XPoint &src) const;
|
|
|
|
// 0-左;1-右;2-其他;与上面的区别是,弧段作为有限长,在圆外但在弦的左侧算左
|
|
virtual int OnWhichSide1(const XPoint &src) const;
|
|
|
|
// 从端点开始沿曲线走过给定距离的点向量
|
|
virtual int Polar(ads_real nDist, XPointDir2d &res, int bFromStart = 1) const;
|
|
|
|
virtual void AsPoly2D(XPoly2D &poly) const;
|
|
|
|
virtual ads_real PathArea(XPoint &tmpt) const;
|
|
|
|
// 取得指向内部的方向,线和弧不支持圆。 pt--0:start; 1--end
|
|
virtual ads_real IDirection(int pt) const;
|
|
|
|
// 曲线上的点pt的方向(切向)
|
|
virtual ads_real Direction(const XPoint &pt) const;
|
|
|
|
// 求通过pt点的法向
|
|
virtual ads_real OrthoDirection(const XPoint &pt) const;
|
|
|
|
// 求到端点的沿曲线线位移, 在线内距离为正,否则为负, 和Polar配合使用
|
|
// pt如果不在线上的话则先投影
|
|
virtual ads_real PathDistance(const XPoint &pt, int bFromStart = 1) const;
|
|
|
|
virtual bool IsDirectionCurve();
|
|
|
|
int Is(CurveType t) const;
|
|
|
|
int MakeArrow(Entity &) const;
|
|
|
|
int ProjectToMe(const XPoint &src, XPoint &res) const;
|
|
|
|
int Intersection(const XLine &, ads_point, ads_point) const ;
|
|
int Intersection(const XCurveSegment &, ads_point pt1, ads_point pt2) const;
|
|
|
|
int GetSubSegment(const XPoint &ptloc, ads_real dchordLen, XCurveSegment &ptres) const;
|
|
|
|
//Wcs到展开坐标系
|
|
XPoint Wcs2Ecs(XPoint pt) const;
|
|
//展开坐标系到Wcs
|
|
XPoint Ecs2Wcs(XPoint pt) const;
|
|
|
|
void Wcs2Ecs(const XPoly2D &polyWcs, XPoly2D &polyEcs) const;
|
|
void Ecs2Wcs(const XPoly2D &polyEcs, XPoly2D &polyWcs) const;
|
|
|
|
XCircle GetCircle() const;
|
|
XLine GetLine() const;
|
|
|
|
//点到曲线的距离, 负数为内/左侧
|
|
double GetDist2Me(XPoint 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;
|
|
|
|
XCurveSegment Offset(ads_real dDist, int nflg) const;
|
|
XCurveSegment Offset(int lr, ads_real dDist, int nflg) const;
|
|
|
|
double GetBulge() const;
|
|
void SetBulge(const double dBulge);
|
|
public:
|
|
|
|
ads_real m_dBulge;
|
|
};
|
|
|
|
inline bool XCurveSegment::operator == (const XCurveSegment &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 XCurveSegment::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 XCurveSegment::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 XLine XCurveSegment::GetLine() const
|
|
{
|
|
return *this;
|
|
}
|
|
|
|
inline double XCurveSegment::GetChordLength(double nArcLen) const
|
|
{
|
|
double nRes = nArcLen;
|
|
if (Is(CURVE_ARC))
|
|
{
|
|
XArc ar = GetArc();
|
|
double dRadius = ar.GetRadius();
|
|
nRes = 2.0 * dRadius * sin(nArcLen / 2.0 / dRadius);
|
|
}
|
|
|
|
return fabs(nRes);
|
|
}
|
|
|
|
inline int XCurveSegment::HitTest2d(const XPoint &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 XCurveSegment::MakeEntity(const Entity &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 XCurveSegment::GetExtend(XPoint &lowPt, XPoint &upPt) const
|
|
{
|
|
if (Is(CURVE_LINE))
|
|
{
|
|
return XLine::GetExtend(lowPt, upPt);
|
|
}
|
|
else if (Is(CURVE_ARC))
|
|
{
|
|
return GetArc().GetExtend(lowPt, upPt);
|
|
}
|
|
else
|
|
{
|
|
return GetCircle().GetExtend(lowPt, upPt);
|
|
}
|
|
}
|
|
|
|
inline XCurveSegment & XCurveSegment::operator = (const XCurveSegment &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 XCurveSegment & XCurveSegment::operator = (const XLine &ln)
|
|
{
|
|
m_nFlag = ln.m_nFlag;
|
|
m_startPoint = ln.m_startPoint;
|
|
m_endPoint = ln.m_endPoint;
|
|
m_dBulge = 0.0;
|
|
return *this;
|
|
}
|
|
|
|
inline XCurveSegment & XCurveSegment::operator = (const XArc &arc)
|
|
{
|
|
//SetLineFlag(LS_FINITE);
|
|
m_nFlag = LS_FINITE;
|
|
|
|
XPoint ptStart, ptEnd;
|
|
XPoint 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 XCurveSegment & XCurveSegment::operator = (const XCircle &cir)
|
|
{
|
|
XPoint ptStart, ptEnd;
|
|
XPoint 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;
|
|
}
|
|
|
|
#endif
|