4635 lines
99 KiB
C++
4635 lines
99 KiB
C++
/*-----------------------------------------------------
|
||
//内部二维几何计算辅助,不可以导出
|
||
------------------------------------------------------*/
|
||
|
||
#ifndef __GEOM_H__
|
||
#define __GEOM_H__
|
||
|
||
#ifdef XGEEXP
|
||
#define XGEAPI
|
||
#else
|
||
#define XGEAPI
|
||
#endif
|
||
|
||
#define EX_INT 11000
|
||
#define EX_REAL 11100
|
||
#define EX_STRING 11200
|
||
#define EX_HANDLE 11300
|
||
#define EX_STRUCT 11400
|
||
#define EX_END 11500
|
||
|
||
#define EX_NEW 20000
|
||
#define EX_BIND 20000
|
||
|
||
#define TOL 0.0001
|
||
#define fTOL 1.e-8
|
||
|
||
#define XD_SHORT 1070
|
||
|
||
#ifndef __XDATA_H
|
||
#define XD_STR 1000
|
||
#define XD_REAL 1040
|
||
#define XD_LONG 1071
|
||
#define XD_POINT 1010
|
||
#define XD_HANDLE 1005
|
||
#endif
|
||
|
||
#define SS_CREATE 0x01
|
||
#define SS_FREE 0x02
|
||
#define SS_MARK 0x04
|
||
|
||
#define Q_YES 1
|
||
#define Q_NO 0
|
||
|
||
#define LAYSTAT_ON 0x01
|
||
#define LAYSTAT_OFF 0x02
|
||
#define LAYSTAT_THAW 0x04
|
||
#define LAYSTAT_FREEZE 0x08
|
||
#define LAYSTAT_UNLOCK 0x10
|
||
#define LAYSTAT_LOCK 0x20
|
||
#define LAYSTAT_CURRENT 0x40
|
||
|
||
#define RTSTRUCT 5011
|
||
|
||
#define XD_INT 1070
|
||
#define XD_REAL 1040
|
||
#define XD_POINT 1010
|
||
#define XD_STR 1000
|
||
#define XD_HANDLE 1005
|
||
|
||
#define MXYZ 0
|
||
#define SXYZ 1
|
||
#define RX 2
|
||
#define RY 3
|
||
#define RZ 4
|
||
#define NOP 5
|
||
#define EXIT 6
|
||
|
||
#define OFFSET_LEFT 0
|
||
#define OFFSET_RIGHT 1
|
||
|
||
#define LS_FINITE 1
|
||
#define LS_INFINITE 0
|
||
|
||
#define PR_OUTSIDE 0
|
||
#define PR_ONPT1 1
|
||
#define PR_ONCIRCLE 1
|
||
#define PR_ONPT2 2
|
||
#define PR_INSIDE 3
|
||
#define PR_EXTEND 4
|
||
#define PR_EDGE 5
|
||
#define PR_INTERS 6
|
||
|
||
#define OS_NON 0
|
||
#define OS_END 1
|
||
#define OS_MID 2
|
||
#define OS_CEN 4
|
||
#define OS_NOD 8
|
||
#define OS_QUA 16
|
||
#define OS_INT 32
|
||
#define OS_INS 64
|
||
#define OS_PER 128
|
||
#define OS_TAN 256
|
||
#define OS_NEA 512
|
||
#define OS_QUI 1024
|
||
#define OS_APP 2048
|
||
|
||
#define XD_INT 1070
|
||
#define XD_REAL 1040
|
||
#define XD_POINT 1010
|
||
#define XD_STR 1000
|
||
#define XD_HANDLE 1005
|
||
|
||
#ifndef PI
|
||
#define PI 3.1415926535897932384626433832795
|
||
#endif
|
||
|
||
#define DPI 0.017453292519943295
|
||
#define PIDD 57.295779513082323
|
||
#define PI2 6.2831853071796
|
||
|
||
#define LINE_SEGMENT (RTNORM + 1)
|
||
#define ARC_SEGMENT (RTNORM + 2)
|
||
|
||
#define SIDE1_INVISIBLE 0x01
|
||
#define SIDE2_INVISIBLE 0x02
|
||
#define SIDE3_INVISIBLE 0x04
|
||
|
||
#ifndef UNIT_SCALE
|
||
#define UNIT_SCALE 1.0
|
||
#endif
|
||
|
||
#define PRIV_STR(s) s
|
||
|
||
#define CMF_SHOWSHAPE 0x01
|
||
#define CMF_NO2D 0x02
|
||
#define CMF_NO3D 0x04
|
||
#define CMF_DIVIDE2D 0x08//TArch7用于二维散水
|
||
|
||
#define ELEMENTS(array) (sizeof(array) / sizeof((array)[0]))
|
||
#define Spoint(pt, x, y, z) {pt[0] = (x); pt[1] = (y); pt[2] = (z);}
|
||
#define Cpoint(to, from) {to[0] = from[0]; to[1] = from[1]; to[2] = from[2];}
|
||
|
||
#define Midpoint(p1, p2, dest) \
|
||
{ \
|
||
dest[0] = (p1[0] + p2[0]) / 2.0; \
|
||
dest[1] = (p1[1] + p2[1]) / 2.0; \
|
||
dest[2] = (p1[2] + p2[2]) / 2.0; \
|
||
}
|
||
|
||
#define MAX_MIN(mn, type) \
|
||
{ \
|
||
va_list vlst; \
|
||
va_start(vlst, r1); \
|
||
type res = r1; \
|
||
for(int i = 0; i < n-1; i++) { \
|
||
type r = va_arg(vlst, type); \
|
||
res = mn(res, r); \
|
||
} \
|
||
va_end(vlst); \
|
||
return res; \
|
||
}
|
||
|
||
#define NOT_FOUND -1
|
||
|
||
extern double _distSnap/* = 0.001;*/;
|
||
extern double _angSnap/* = 0.001;*/;
|
||
extern double _DIST_SNAP/* = 0.001;*/;
|
||
extern double g_nCirDeviation/* = 40*/;
|
||
|
||
namespace XGE
|
||
{
|
||
const Adesk::UInt16 kColorByLayer = 256;
|
||
|
||
enum FormatType
|
||
{
|
||
WS_CHAR,
|
||
WS_INT,
|
||
WS_DOUBLE,
|
||
WS_STRING,
|
||
WS_FORMAT
|
||
};
|
||
|
||
enum CurveType
|
||
{
|
||
CURVE_LINE,
|
||
CURVE_ARC,
|
||
CURVE_CIRCLE
|
||
};
|
||
|
||
enum ShapeType
|
||
{
|
||
SHAPE_UNKNOWN,
|
||
SHAPE_CIRCLE,
|
||
SHAPE_RECTANGLE,
|
||
SHAPE_POLY
|
||
};
|
||
|
||
//线段类型
|
||
enum BLType
|
||
{
|
||
BLINESEG, //直线段
|
||
BARCSEG //圆弧段
|
||
};
|
||
|
||
enum HitTestPos
|
||
{
|
||
POS_Error = 0, //错误
|
||
POS_Left = 1, //左边
|
||
POS_Rigth = 2, //右边
|
||
POS_Start = 3, //起始点
|
||
POS_End = 4, //终止点
|
||
POS_InLine = 5, //线内
|
||
POS_StartLineEx = 6, //起始侧延长线
|
||
POS_EndLineEx = 7 //终止侧延长线
|
||
};
|
||
|
||
typedef struct Binary
|
||
{
|
||
short length;
|
||
char *buffer;
|
||
}*STBINARY,*PSTBINARY;
|
||
|
||
class XGEAPI XPushPrec {
|
||
public:
|
||
ads_real oldDistSnap, oldAngSnap;
|
||
XPushPrec(ads_real dist, ads_real ang):oldDistSnap(_distSnap), oldAngSnap(_angSnap) {
|
||
_distSnap=dist, _angSnap=ang;
|
||
}
|
||
~XPushPrec() {_distSnap=oldDistSnap; _angSnap=oldAngSnap; }
|
||
};
|
||
|
||
class XGEAPI Groups
|
||
{
|
||
public:
|
||
Groups(int i=0);
|
||
Groups(ads_real r);
|
||
Groups(const ads_point p);
|
||
Groups(LPCTSTR s);
|
||
Groups(ads_name n);
|
||
Groups(long l);
|
||
|
||
Groups(const Groups& src);
|
||
|
||
//Extend data
|
||
Groups(int, int i);
|
||
Groups(int, ads_real r);
|
||
Groups(int strOrHandle, LPCTSTR s);
|
||
|
||
~Groups();
|
||
|
||
// 重新定义 new, delete操作符, 以便与ADS兼容
|
||
void *operator new(size_t);
|
||
void operator delete(void *a);
|
||
|
||
operator resbuf & ();
|
||
operator resbuf * ();
|
||
int operator == (const Groups &other) const;
|
||
int operator != (const Groups &other) const;
|
||
Groups& operator = (const Groups &src);
|
||
|
||
public:
|
||
Groups *next;
|
||
|
||
union {
|
||
short type;
|
||
short code;
|
||
};
|
||
|
||
union {
|
||
ads_real real;
|
||
ads_point point;
|
||
HALF_PTR shortInt;
|
||
LPTSTR string;
|
||
ads_name adsName;
|
||
long longInt;
|
||
#ifdef _WIN64
|
||
LONG_PTR longPtr;
|
||
#endif
|
||
Binary binary;
|
||
};
|
||
#ifdef _WIN64
|
||
Groups(LONG_PTR val) {longPtr=val; type=RTLONG_PTR;next=NULL;};
|
||
#endif
|
||
};
|
||
|
||
typedef Groups *PGroups;
|
||
typedef Groups *PList;
|
||
|
||
|
||
inline Groups::Groups(int i)
|
||
{
|
||
shortInt = i;
|
||
type = RTSHORT;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(ads_real r)
|
||
{
|
||
real = r;
|
||
type = RTREAL;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(const ads_point p)
|
||
{
|
||
memcpy(point, p, sizeof(ads_point));
|
||
type = RT3DPOINT;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(LPCTSTR s)
|
||
{
|
||
string = _tcsdup(s);
|
||
type = RTSTR;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(ads_name n)
|
||
{
|
||
adsName[0] = n[0];
|
||
adsName[1] = n[1];
|
||
type = RTENAME;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(long l)
|
||
{
|
||
longInt = l;
|
||
type = RTLONG;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(const Groups & src)
|
||
{
|
||
*this = src;
|
||
}
|
||
|
||
inline Groups::Groups(int, int i)
|
||
{
|
||
shortInt = i;
|
||
type = XD_SHORT;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(int, ads_real r)
|
||
{
|
||
real = r;
|
||
type = XD_REAL;
|
||
next = NULL;
|
||
}
|
||
|
||
inline Groups::Groups(int strOrHandle, LPCTSTR s)
|
||
{
|
||
string = _tcsdup(s);
|
||
type = strOrHandle;
|
||
next = NULL;
|
||
}
|
||
|
||
inline void* Groups::operator new(size_t)
|
||
{
|
||
return (void *)ads_newrb(0);
|
||
}
|
||
|
||
inline void Groups::operator delete(void *a)
|
||
{
|
||
ads_relrb((resbuf *)a);
|
||
}
|
||
|
||
inline Groups::operator resbuf & ()
|
||
{
|
||
return *((resbuf *)this);
|
||
}
|
||
|
||
inline Groups::operator resbuf * ()
|
||
{
|
||
return (resbuf *)this;
|
||
}
|
||
|
||
inline int Groups::operator != (const Groups &other) const
|
||
{
|
||
return !(*this == other);
|
||
}
|
||
|
||
inline double CT_std_angle(double dAngle)
|
||
{
|
||
double dAngleTmp = dAngle;
|
||
|
||
if ( fabs(dAngleTmp - 2.0 * PI) < 1.0E-9 )
|
||
{
|
||
dAngleTmp = 0.0;
|
||
return dAngleTmp;
|
||
}
|
||
|
||
while((dAngleTmp > (PI * 2.0 + 1.0E-9)) || (dAngleTmp < -1.0E-9))
|
||
{
|
||
if (dAngleTmp < -1.0E-9)
|
||
{
|
||
dAngleTmp = dAngleTmp + 2.0 * PI;
|
||
}
|
||
else if (dAngleTmp > (PI * 2.0 + 1.0E-9))
|
||
{
|
||
dAngleTmp = dAngleTmp - 2.0 * PI;
|
||
}
|
||
}
|
||
return dAngleTmp;
|
||
}
|
||
|
||
class XGEAPI RBList
|
||
{
|
||
public:
|
||
|
||
RBList();
|
||
|
||
RBList(int,...);
|
||
|
||
RBList(const resbuf *rb);
|
||
|
||
RBList (const RBList & src);
|
||
|
||
~RBList();
|
||
|
||
operator resbuf *();
|
||
|
||
operator void * ();
|
||
|
||
int operator !() const;
|
||
|
||
void operator = (const RBList & src);
|
||
|
||
void Append(resbuf * lst);
|
||
|
||
void FreeGroups();
|
||
|
||
Groups *SearchNode(int cd) const;
|
||
|
||
int GetData (int cd,void *buf) const;
|
||
|
||
int SetData(int cd,...);
|
||
|
||
static int TypeOfCode(int code);
|
||
|
||
static PGroups VBuildList(int *parguments);
|
||
|
||
public:
|
||
|
||
PGroups groups;
|
||
|
||
protected:
|
||
#ifdef _WIN64
|
||
int _SetData(int, va_list);
|
||
#else
|
||
int _SetData(int,void *); // to support Entity::SetData & RBList::SetData;
|
||
#endif
|
||
private:
|
||
|
||
int SizeOfType(int type)const;
|
||
};
|
||
|
||
class XGEAPI SymbolTable : public RBList
|
||
{
|
||
public:
|
||
|
||
SymbolTable();
|
||
|
||
SymbolTable(SymbolTable &);
|
||
|
||
SymbolTable(LPCTSTR tblname, LPCTSTR sym, int setnext = 0);
|
||
|
||
~SymbolTable();
|
||
|
||
static resbuf *tblsearch(LPCTSTR tblname, LPCTSTR sym, int setnext = 0);
|
||
|
||
resbuf * tblnext(int rewind = 0);
|
||
|
||
protected:
|
||
|
||
TCHAR *tblName;
|
||
};
|
||
|
||
typedef class SymbolTable XSymbolTable;
|
||
|
||
typedef ads_real ads_vector[3];
|
||
typedef struct resbuf rbtype;
|
||
typedef ads_real (* MatrixPointer)[4];
|
||
|
||
typedef struct plan_para
|
||
{
|
||
double A, B, C, D;
|
||
}PLAN_PARA;
|
||
|
||
template <class R>
|
||
class Node
|
||
{
|
||
public:
|
||
|
||
Node(Node<R> *p, Node<R> *n, R* d);
|
||
~Node(){}
|
||
|
||
public:
|
||
R * data;
|
||
Node<R> * previous;
|
||
Node<R> * next;
|
||
};
|
||
|
||
template <class R>
|
||
Node<R>::Node(Node<R> *p, Node<R> *n, R* d)
|
||
{
|
||
assert(d!=NULL);
|
||
previous=p;
|
||
next = n;
|
||
data = d;
|
||
}
|
||
|
||
template <class R>
|
||
class DList
|
||
{
|
||
public:
|
||
DList(int dFlag = 1);
|
||
DList(R * addr, int nCount);
|
||
~DList();
|
||
|
||
int operator !() const;
|
||
R * operator [](int n);
|
||
const R & operator [](int n) const;
|
||
|
||
void MoveToHead();
|
||
|
||
const R & GetAt(int n) const;
|
||
R * GetAt(int n);
|
||
|
||
//并入
|
||
DList<R>& operator << (DList<R>&listother);
|
||
|
||
//复制
|
||
DList<R>& copyFrom(const DList<R>& listother);
|
||
|
||
void Insert(R * node);
|
||
void Append(R * node);
|
||
void Replace(R * node, int n = -1);
|
||
void Reset();
|
||
|
||
int Remove();
|
||
int Remove(int n);
|
||
|
||
// 求当前指针的位置(-1: current 为 NULL)
|
||
int CurPosition() const;
|
||
|
||
int Length() const;
|
||
|
||
int GetDelFlag() const;
|
||
void SetDelFlag(int nFlag);
|
||
|
||
R * CurData() const;
|
||
void SetCurData(R* p);
|
||
|
||
int Find(const R * node);
|
||
int Exist(const R * node) const;
|
||
|
||
// 把指针移到最后,准备下一个插入
|
||
void MoveEnd();
|
||
|
||
R* Head() const;
|
||
R* Tail() const;
|
||
R* FindNode(const void *, int (*cmp)(const R *, const void *));
|
||
|
||
void QuickSort(int (*cmp)(const R *, const R *));
|
||
void Swap(int n1,int n2);
|
||
void Reverse();
|
||
void FindAndDel(const void *p, int (*cmp)(const R *, const void *));
|
||
|
||
private:
|
||
int m_nLen, m_nCurIndex;
|
||
Node<R>* m_pCurrent;
|
||
|
||
protected:
|
||
int m_nDelFlag;
|
||
Node<R>* head;
|
||
Node<R>* tail;
|
||
|
||
virtual int Compare(const R *, const R *) const;
|
||
|
||
private:
|
||
DList<R> & operator = (const DList<R> &src);
|
||
DList(const DList<R> &src);
|
||
};
|
||
|
||
template <class R>
|
||
DList<R>::DList(const DList<R> &src)
|
||
{
|
||
m_nDelFlag = src.m_nDelFlag;
|
||
for (int i = 0;i < src.Length();i++)
|
||
{
|
||
Append(new R( src[i] ) );
|
||
}
|
||
}
|
||
|
||
template <class R>
|
||
inline DList<R>::DList(int nFlag)
|
||
{
|
||
head = tail = m_pCurrent = NULL;
|
||
m_nDelFlag = nFlag;
|
||
m_nCurIndex = 0;
|
||
m_nLen = 0;
|
||
}
|
||
|
||
template <class R>
|
||
DList<R>::DList( R *pBeg, int nCount) : head(NULL), tail(NULL), m_pCurrent(NULL), m_nDelFlag(1), m_nCurIndex(0), m_nLen(0)
|
||
{
|
||
R *p = pBeg;
|
||
for (int i = 0; i < nCount; i++)
|
||
{
|
||
Append(new R(*p));
|
||
p++;
|
||
}
|
||
}
|
||
|
||
// 缺省方式下: R的分配和释放是由用户负责
|
||
template <class R> class DStack: public DList<R> {
|
||
public:
|
||
DStack() : DList<R> (0) {}
|
||
void Push(R *dat) {
|
||
this->MoveEnd();
|
||
this->Insert(dat);
|
||
// current=tail;
|
||
}
|
||
R * Pop() { // Use Tail() to get the Stack top
|
||
//current=tail;
|
||
R * res = this->Tail(); //CurData();
|
||
if(this->Length()) this->Remove(this->Length()-1);
|
||
// current=tail;
|
||
return res;
|
||
}
|
||
R * Top() { return this->Tail(); }
|
||
};
|
||
|
||
template <class R>
|
||
DList<R>::~DList()
|
||
{
|
||
Node<R> *p = head, *p1 = NULL;
|
||
while(p)
|
||
{
|
||
p1 = p->next;
|
||
if (m_nDelFlag)
|
||
{
|
||
if (p->data != NULL)
|
||
{
|
||
delete p->data;
|
||
}
|
||
}
|
||
delete p;
|
||
p = p1;
|
||
}
|
||
}
|
||
|
||
template <class R>
|
||
inline void DList<R>::Append(R * node)
|
||
{
|
||
m_pCurrent = NULL;
|
||
m_nCurIndex = m_nLen;
|
||
Insert(node);
|
||
}
|
||
|
||
template <class R>
|
||
inline void DList<R>::Replace(R * node, int n)
|
||
{
|
||
if (n >= 0)
|
||
{
|
||
(*this)[n];
|
||
}
|
||
|
||
if (m_pCurrent)
|
||
{
|
||
if (m_nDelFlag)
|
||
{
|
||
if (m_pCurrent->data != NULL)
|
||
{
|
||
delete m_pCurrent->data;
|
||
}
|
||
}
|
||
m_pCurrent->data = node;
|
||
}
|
||
}
|
||
|
||
template <class R>
|
||
inline int DList<R>::Remove(int n)
|
||
{
|
||
(*this)[n];
|
||
return Remove();
|
||
}
|
||
|
||
template <class R>
|
||
inline int DList<R>::CurPosition() const
|
||
{
|
||
return m_nCurIndex<m_nLen ? m_nCurIndex : -1;
|
||
}
|
||
|
||
template <class R>
|
||
inline int DList<R>::Length() const
|
||
{
|
||
return m_nLen;
|
||
}
|
||
|
||
template <class R>
|
||
inline void DList<R>::SetDelFlag(int nFlag)
|
||
{
|
||
m_nDelFlag = nFlag;
|
||
}
|
||
|
||
template <class R>
|
||
inline int DList<R>::GetDelFlag() const
|
||
{
|
||
return m_nDelFlag;
|
||
}
|
||
|
||
template <class R>
|
||
inline int DList<R>::operator !() const
|
||
{
|
||
if (head)
|
||
{
|
||
return 0;
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
template <class R>
|
||
inline const R & DList<R>::operator [](int n) const
|
||
{
|
||
DList<R> *pThis = (DList<R> *)this;
|
||
const R * pData = (*pThis)[n];
|
||
return *pData;
|
||
}
|
||
|
||
template <class R>
|
||
inline void DList<R>::MoveToHead()
|
||
{
|
||
m_pCurrent = head;
|
||
m_nCurIndex = 0;
|
||
}
|
||
|
||
// 移到当前指针到第 n 个节点, 并返回它
|
||
// 假如 n<0, exit; ||则移到倒数第 n个节点
|
||
template <class R>
|
||
inline R * DList<R>::operator [](int n)
|
||
{
|
||
int i = 0;
|
||
if (n >= 0 && n < m_nLen)
|
||
{
|
||
if (!m_pCurrent)
|
||
{
|
||
m_pCurrent=head;
|
||
m_nCurIndex=0;
|
||
}
|
||
|
||
int diff = n - m_nCurIndex;
|
||
if (diff >= 0)
|
||
{
|
||
if (m_nCurIndex == 0 && n == m_nLen - 1)
|
||
{
|
||
m_pCurrent=tail;
|
||
m_nCurIndex=m_nLen - 1;
|
||
}
|
||
else
|
||
{
|
||
for (i = 0; i < diff; i++)
|
||
{
|
||
assert(m_pCurrent != NULL);
|
||
m_pCurrent = m_pCurrent->next;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (m_nCurIndex == m_nLen - 1 && n == 0)
|
||
{
|
||
m_pCurrent=head;
|
||
m_nCurIndex=0;
|
||
}
|
||
else
|
||
{
|
||
for (i = 0; i < -diff; i++)
|
||
{
|
||
assert(m_pCurrent != NULL);
|
||
m_pCurrent = m_pCurrent->previous;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
assert(0);
|
||
}
|
||
m_nCurIndex = n;
|
||
|
||
if (m_pCurrent)
|
||
{
|
||
return m_pCurrent->data;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
template <class R>
|
||
inline const R & DList<R>::GetAt(int n) const
|
||
{
|
||
DList<R> *pThis = (DList<R> *)this;
|
||
const R * pData = (*pThis).GetAt(n);
|
||
return *pData;
|
||
}
|
||
|
||
// 移到当前指针到第 n 个节点, 并返回它
|
||
// 假如 n<0, exit; ||则移到倒数第 n个节点
|
||
template <class R>
|
||
inline R * DList<R>::GetAt(int n)
|
||
{
|
||
int i = 0;
|
||
if (n >= 0 && n < m_nLen)
|
||
{
|
||
if (!m_pCurrent)
|
||
{
|
||
m_pCurrent=head;
|
||
m_nCurIndex=0;
|
||
}
|
||
|
||
int diff = n - m_nCurIndex;
|
||
if (diff >= 0)
|
||
{
|
||
for (i = 0; i < diff; i++)
|
||
{
|
||
assert(m_pCurrent != NULL);
|
||
m_pCurrent = m_pCurrent->next;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (m_nCurIndex == m_nLen - 1 && n == 0)
|
||
{
|
||
m_pCurrent=head;
|
||
m_nCurIndex=0;
|
||
}
|
||
else
|
||
{
|
||
for (i = 0; i < -diff; i++)
|
||
{
|
||
assert(m_pCurrent != NULL);
|
||
m_pCurrent = m_pCurrent->previous;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
assert(0);
|
||
}
|
||
m_nCurIndex = n;
|
||
|
||
if (m_pCurrent)
|
||
{
|
||
return m_pCurrent->data;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
template <class R>
|
||
inline R * DList<R>::CurData() const
|
||
{
|
||
return m_pCurrent ? m_pCurrent->data : NULL;
|
||
}
|
||
|
||
template <class R>
|
||
inline void DList<R>::SetCurData(R* p)
|
||
{
|
||
if (m_pCurrent != NULL)
|
||
{
|
||
m_pCurrent->data = p;
|
||
}
|
||
}
|
||
|
||
template <class R>
|
||
inline void DList<R>::MoveEnd()
|
||
{
|
||
m_nCurIndex = -1;
|
||
m_pCurrent = NULL;
|
||
}
|
||
|
||
template <class R>
|
||
inline R* DList<R>::Head() const
|
||
{
|
||
if (head)
|
||
{
|
||
return head->data;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
template <class R>
|
||
inline R* DList<R>::Tail() const
|
||
{
|
||
if (tail)
|
||
{
|
||
return tail->data;
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
template <class R>
|
||
inline void DList<R>::FindAndDel(const void *p, int (*cmp)(const R *, const void *))
|
||
{
|
||
while(FindNode(p,cmp) != NULL)
|
||
{
|
||
Remove();
|
||
}
|
||
}
|
||
|
||
//并入链表,list被直接连接到this链表的末尾,成为this链表的一部分
|
||
//最后this链表的游标值不变,而list变为Reset状态
|
||
template <class R>
|
||
DList<R>& DList<R>::operator << (DList<R> &listother)
|
||
{
|
||
if (listother.Length() == 0)
|
||
{
|
||
return *this;
|
||
}
|
||
|
||
if (Length() > 0)
|
||
{
|
||
tail->next = listother.head;
|
||
listother.head->previous = tail;
|
||
}
|
||
else
|
||
{
|
||
head = listother.head;
|
||
}
|
||
|
||
//new tail
|
||
tail = listother.tail;
|
||
|
||
//increase length
|
||
m_nLen += listother.Length();
|
||
|
||
//reset list
|
||
listother.head = listother.tail = listother.m_pCurrent = NULL;
|
||
listother.m_nLen = listother.m_nCurIndex = 0;
|
||
|
||
return *this;
|
||
}
|
||
|
||
template <class R>
|
||
DList<R>& DList<R>::copyFrom(const DList<R>& listother)
|
||
{
|
||
m_nDelFlag = listother.m_nDelFlag;
|
||
if (this != &listother)
|
||
{
|
||
Reset();
|
||
for (int i = 0;i < listother.Length();i++)
|
||
{
|
||
Append(new R( listother[i] ) );
|
||
}
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
template <class R>
|
||
inline DList<R> & DList<R>::operator = (const DList<R> &src)
|
||
{
|
||
return copyFrom(src);
|
||
}
|
||
|
||
|
||
// 重新初始化
|
||
template <class R>
|
||
void DList<R>::Reset()
|
||
{
|
||
Node<R> *p = head, *p1 = NULL;
|
||
while(p)
|
||
{
|
||
p1 = p->next;
|
||
if (m_nDelFlag)
|
||
{
|
||
if (p->data != NULL)
|
||
{
|
||
delete p->data;
|
||
}
|
||
}
|
||
delete p;
|
||
p = p1;
|
||
}
|
||
head = tail = m_pCurrent = NULL;
|
||
m_nLen = 0; m_nCurIndex = 0;
|
||
}
|
||
|
||
template <class R>
|
||
int DList<R>::Exist(const R * node) const
|
||
{
|
||
for (Node<R> *p = head; p != NULL; p = p->next)
|
||
{
|
||
if (Compare(p->data, node) == 0)
|
||
{
|
||
return 1;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
template <class R>
|
||
int DList<R>::Find(const R * node)
|
||
{
|
||
for (m_nCurIndex = 0; m_nCurIndex < m_nLen; m_nCurIndex++)
|
||
{
|
||
if (Compare((*this)[m_nCurIndex], node) == 0)
|
||
{
|
||
return 1;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
template <class R>
|
||
inline int DList<R>::Compare(const R * node1, const R *node2) const
|
||
{
|
||
if (node1 == node2)
|
||
{
|
||
return 0;
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
// 删除当前节点
|
||
template <class R>
|
||
int DList<R>::Remove()
|
||
{
|
||
if (!m_pCurrent)
|
||
{
|
||
return 0;
|
||
}
|
||
|
||
Node<R> *p, *n;
|
||
p = m_pCurrent->previous;
|
||
n = m_pCurrent->next;
|
||
if (m_pCurrent == head)
|
||
{ //删除头节点
|
||
if (m_nDelFlag)
|
||
{
|
||
if (m_pCurrent->data != NULL)
|
||
{
|
||
delete m_pCurrent->data;
|
||
}
|
||
}
|
||
delete m_pCurrent;
|
||
head = m_pCurrent = n;
|
||
if (!n)
|
||
{
|
||
tail = NULL;
|
||
}
|
||
if (n)
|
||
{
|
||
n->previous = NULL;
|
||
}
|
||
}
|
||
else if (p)
|
||
{ // 当前节点变为下一个节点
|
||
if (m_nDelFlag)
|
||
{
|
||
if (m_pCurrent->data != NULL)
|
||
{
|
||
delete m_pCurrent->data;
|
||
}
|
||
}
|
||
delete m_pCurrent;
|
||
p->next = n;
|
||
if (n)
|
||
{
|
||
n->previous = p;
|
||
}
|
||
else
|
||
{
|
||
tail = p; //删除尾节点
|
||
}
|
||
m_pCurrent = n;
|
||
}
|
||
else
|
||
{
|
||
assert(0);
|
||
}
|
||
m_nLen--;
|
||
return 1;
|
||
}
|
||
|
||
// 在当前节点之前增加
|
||
template <class R>
|
||
void DList<R>::Insert( R *dat)
|
||
{
|
||
assert(dat != NULL);
|
||
|
||
if (head == NULL)
|
||
{
|
||
head = tail = new Node<R> (NULL, NULL, dat);
|
||
assert(head != NULL);
|
||
m_pCurrent = NULL; //缺省插入尾部
|
||
}
|
||
else if (m_pCurrent == NULL)
|
||
{ //加到尾部
|
||
Node<R> *tmp =new Node<R> (tail, NULL, dat);
|
||
assert(tmp != NULL);
|
||
tail->next = tmp;
|
||
tail = tmp;
|
||
}
|
||
else if (m_pCurrent->previous)
|
||
{ //插入中间
|
||
Node<R> *p = m_pCurrent->previous;
|
||
p->next = m_pCurrent->previous = new Node<R> (p,m_pCurrent,dat);
|
||
assert(p->next != NULL);
|
||
}
|
||
else if (m_pCurrent == head)
|
||
{ // 加到表头前 curren == head
|
||
head = new Node<R> (NULL, m_pCurrent, dat);
|
||
assert(head != NULL);
|
||
m_pCurrent->previous = head;
|
||
}
|
||
m_nLen++;
|
||
m_nCurIndex++;
|
||
}
|
||
|
||
template <class R>
|
||
void DList<R>::QuickSort(int (*cmp)(const R *, const R *))
|
||
{
|
||
int len = Length(), nsr = -1;
|
||
for (int i = 0; i < len - 1; i++)
|
||
{
|
||
for (int j = 0; j < len - 1 - i; j++)
|
||
{
|
||
R *s1 = (*this)[j];
|
||
Node<R> *n1 = m_pCurrent;
|
||
R *s2 = (*this)[j + 1];
|
||
Node<R> *n2 = m_pCurrent;
|
||
|
||
nsr = cmp(s1, s2);
|
||
if (nsr > 0)
|
||
{
|
||
R *tmp = s1;
|
||
n1->data = s2;
|
||
n2->data = tmp;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 可以用关键字查找链表中的某一项, 因此用 void *
|
||
template <class R>
|
||
R * DList<R>::FindNode(const void *target, int (*cmp)(const R *, const void *))
|
||
{
|
||
int len = Length(), nsr = -1;
|
||
for (int i = 0; i < len; i++)
|
||
{
|
||
R *s1 = (*this)[i];
|
||
nsr = cmp(s1, target);
|
||
if (!nsr)
|
||
{
|
||
return s1;
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
template <class R>
|
||
void DList<R>::Swap(int n1,int n2)
|
||
{
|
||
if ((n1 >= 0 && n1 < m_nLen) && ( n2 >= 0 && n2 < m_nLen))
|
||
{
|
||
R* swap1=(*this)[n1];
|
||
Node<R> *node1 = m_pCurrent;
|
||
R* swap2 = (*this)[n2];
|
||
Node<R> *node2 = m_pCurrent;
|
||
R *temp = swap1;
|
||
|
||
node1->data = swap2;
|
||
node2->data = temp;
|
||
}
|
||
else
|
||
{
|
||
assert(NULL);
|
||
}
|
||
}
|
||
|
||
template <class R>
|
||
void DList<R>::Reverse()
|
||
{
|
||
CPtrArray arPtrs;
|
||
int i = 0;
|
||
for (i = 0; i < m_nLen; i++)
|
||
{
|
||
arPtrs.Add((*this)[i]);
|
||
}
|
||
|
||
for (i = 0; i < m_nLen; i++)
|
||
{
|
||
(*this)[i];
|
||
m_pCurrent->data = (R*)arPtrs.GetAt(m_nLen - i - 1);
|
||
}
|
||
}
|
||
|
||
template <class K>
|
||
inline int Compare(K n1, K n2)
|
||
{
|
||
if (n1 > n2)
|
||
{
|
||
return 1;
|
||
}
|
||
else if (n1 < n2)
|
||
{
|
||
return -1;
|
||
}
|
||
else
|
||
{
|
||
return 0;
|
||
}
|
||
}
|
||
|
||
template<class T> inline void Exchange(T& t1,T&t2)
|
||
{
|
||
T temp = t1;
|
||
t1 = t2;
|
||
t2 = temp;
|
||
}
|
||
|
||
template<class T> inline T Min2(T t1,T t2)
|
||
{
|
||
return t2 < t1 ? t2:t1;
|
||
}
|
||
|
||
template<class T> inline T Max2(T t1,T t2)
|
||
{
|
||
return t2 > t1 ? t2 : t1;
|
||
}
|
||
|
||
class XCircle;
|
||
class XLine;
|
||
class XPlane;
|
||
class Entity;
|
||
class XGEAPI XPoint
|
||
{
|
||
public:
|
||
XPoint(const ads_point src);
|
||
XPoint(const AcGePoint3d &src);
|
||
XPoint(const AcGePoint2d &src);
|
||
XPoint(const AcGeVector3d &src);
|
||
XPoint(const AcGeVector2d &src);
|
||
XPoint(const XPoint &ptFrom, double dDrt, double dDist);
|
||
XPoint(ads_real dx = 0.0, ads_real dy = 0.0, ads_real dz = 0.0);
|
||
~XPoint();
|
||
|
||
XPoint& operator = (const AcGePoint3d &src);
|
||
XPoint& operator = (const AcGePoint2d &src);
|
||
XPoint& operator = (const AcGeVector3d &src);
|
||
XPoint& operator = (const AcGeVector2d &src);
|
||
XPoint& operator = (const XPoint & pt);
|
||
XPoint& operator = (const ads_point pt);
|
||
|
||
void operator > (ads_point pt) const;
|
||
bool operator > (const XPoint &pt) const;
|
||
bool operator < (const XPoint &pt)const;
|
||
void operator += (const XPoint &pt);
|
||
void operator -= (const XPoint &pt);
|
||
void operator *= (double dScale);
|
||
void operator /= (double dScale);
|
||
bool operator == (const XPoint & pt) const;
|
||
bool operator == (const ads_point pt) const;
|
||
bool operator != (const XPoint &pt) const;
|
||
|
||
operator ads_real* () const;
|
||
operator void* () const;
|
||
|
||
ads_real& operator [] (int i);
|
||
ads_real operator [] (int i) const;
|
||
|
||
int operator ! () const;
|
||
|
||
//3D属性;
|
||
//把当前点往线上投影, rp--结果
|
||
int Project(const AcGeLine3d& gLine,ads_point rp) const;
|
||
int Project(const XLine& aline, ads_point rp) const;
|
||
int Project(const XCircle& aCir, ads_point rp) const;
|
||
XPoint Project(const XPlane& plan) const;
|
||
|
||
double Distance(const XLine* pLine) const;
|
||
double Distance(const XPoint& pt) const;
|
||
double Distance2d(const XPoint& pt) const;
|
||
double Distance(const XPoint& ptSta,const XPoint& ptEnd) const;
|
||
|
||
void TransformBy(ads_matrix mat);
|
||
void TransformBy(const AcGeMatrix3d& mat);
|
||
XPoint TransformAs(ads_matrix mat) const;
|
||
|
||
void GetRotationMatrix(ads_real dRot, ads_matrix mat) const;
|
||
void GetScaleMatrix(ads_real dScale, ads_matrix mat) const;
|
||
void GetScaleMatrix(ads_real sx, ads_real sy, ads_real sz, ads_matrix mat) const;
|
||
void GetMoveMatrix(const XPoint& ptDest, ads_matrix mat) const;
|
||
|
||
void Mirror(const ads_point src, ads_point dest) const;
|
||
void Mirror(const XPoint& ptSrc, XPoint& ptDest) const;
|
||
|
||
void Rotate(ads_real dAng);
|
||
|
||
void Reverse();
|
||
|
||
void Normalize();
|
||
|
||
int Modify(const Entity* pEntity) const;
|
||
int MakeEntity(const Entity* pEntity) const;
|
||
|
||
ads_real Length() const;
|
||
|
||
void Scale(ads_real dScale);
|
||
|
||
operator const AcGePoint3d & ();
|
||
operator AcGePoint3d & () const;
|
||
AcGePoint3d AsAcGePoint3d() const;
|
||
|
||
operator const AcGeVector3d & ();
|
||
operator AcGeVector3d & () const;
|
||
AcGeVector3d AsAcGeVector3d() const;
|
||
|
||
operator const AcGePoint2d & ();
|
||
operator AcGePoint2d & () const;
|
||
AcGePoint2d AsAcGePoint2d() const;
|
||
|
||
operator const AcGeVector2d & ();
|
||
operator AcGeVector2d & () const;
|
||
AcGeVector2d AsAcGeVector2d() const;
|
||
|
||
void AT_xformpt(ads_matrix xform,ads_point pt,ads_point newpt) const;
|
||
|
||
public:
|
||
|
||
ads_real x,y,z;
|
||
};
|
||
|
||
typedef class XPoint Point;
|
||
typedef class XPoint Vector3D;
|
||
typedef class XPoint XVector3D;
|
||
|
||
inline XPoint::XPoint(ads_real dx, ads_real dy, ads_real dz)
|
||
{
|
||
x = dx;
|
||
y = dy;
|
||
z = dz;
|
||
}
|
||
|
||
inline XPoint::XPoint(const ads_point src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = src[2];
|
||
}
|
||
|
||
inline XPoint::XPoint(const XPoint &ptFrom, double dDrt, double dDist)
|
||
{
|
||
ads_polar(ptFrom, dDrt, dDist, *this);
|
||
}
|
||
|
||
inline XPoint::XPoint(const AcGePoint3d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = src[2];
|
||
}
|
||
|
||
inline XPoint::XPoint(const AcGePoint2d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = 0.0;
|
||
}
|
||
|
||
inline XPoint& XPoint::operator = (const AcGePoint3d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = src[2];
|
||
|
||
return *this;
|
||
}
|
||
|
||
inline XPoint& XPoint::operator = (const AcGePoint2d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = 0.0;
|
||
|
||
return *this;
|
||
}
|
||
|
||
inline XPoint::XPoint(const AcGeVector3d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = src[2];
|
||
}
|
||
|
||
inline XPoint::XPoint(const AcGeVector2d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = 0.0;
|
||
}
|
||
|
||
inline XPoint& XPoint::operator = (const AcGeVector3d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = src[2];
|
||
|
||
return *this;
|
||
}
|
||
|
||
inline XPoint& XPoint::operator = (const AcGeVector2d &src)
|
||
{
|
||
x = src[0];
|
||
y = src[1];
|
||
z = 0.0;
|
||
|
||
return *this;
|
||
}
|
||
|
||
inline XPoint& XPoint::operator = (const XPoint & pt)
|
||
{
|
||
x = pt.x;
|
||
y = pt.y;
|
||
z = pt.z;
|
||
|
||
return *this;
|
||
}
|
||
|
||
inline XPoint& XPoint::operator = (const ads_point pt)
|
||
{
|
||
x = pt[0];
|
||
y = pt[1];
|
||
z = pt[2];
|
||
|
||
return *this;
|
||
}
|
||
|
||
inline void XPoint::operator > (ads_point pt) const
|
||
{
|
||
pt[0] = x;
|
||
pt[1] = y;
|
||
pt[2] = z;
|
||
}
|
||
|
||
inline void XPoint::operator += (const XPoint &pt)
|
||
{
|
||
x += pt.x;
|
||
y += pt.y;
|
||
z += pt.z;
|
||
}
|
||
|
||
inline void XPoint::operator -= (const XPoint &pt)
|
||
{
|
||
x -= pt.x;
|
||
y -= pt.y;
|
||
z -= pt.z;
|
||
}
|
||
|
||
inline void XPoint::operator *= (double dScale)
|
||
{
|
||
x *= dScale;
|
||
y *= dScale;
|
||
z *= dScale;
|
||
}
|
||
|
||
inline void XPoint::operator /= (double dScale)
|
||
{
|
||
x /= dScale;
|
||
y /= dScale;
|
||
z /= dScale;
|
||
}
|
||
|
||
inline bool XPoint::operator == (const XPoint & pt) const
|
||
{
|
||
return (fabs(x - pt.x) < 1.e-6 && fabs(y - pt.y) < 1.e-6 && fabs(z - pt.z) < 1.e-6);
|
||
}
|
||
|
||
inline bool XPoint::operator != (const XPoint &pt) const
|
||
{
|
||
return !((*this) == pt);
|
||
}
|
||
|
||
inline bool XPoint::operator == (const ads_point pt) const
|
||
{
|
||
return (ads_distance(&x, pt) < 1.e-6);
|
||
}
|
||
|
||
inline bool XPoint::operator < (const XPoint &pt) const
|
||
{
|
||
return pt > (*this);
|
||
}
|
||
|
||
inline XPoint::operator ads_real*() const
|
||
{
|
||
return (ads_real *)&x;
|
||
}
|
||
|
||
inline XPoint::operator void* () const
|
||
{
|
||
return (void *)&x;
|
||
}
|
||
|
||
inline ads_real& XPoint::operator [] (int i)
|
||
{
|
||
return *(&x + i);
|
||
}
|
||
|
||
inline ads_real XPoint::operator [] (int i) const
|
||
{
|
||
return *(&x + i);
|
||
}
|
||
|
||
inline int XPoint::operator !() const
|
||
{
|
||
return (fabs(x) < 1E-6 && fabs(y) < 1E-6 && fabs(z) < 1E-6) ? 1 : 0;
|
||
}
|
||
|
||
inline double XPoint::Distance(const XPoint& pt) const
|
||
{
|
||
double t1 = pt.x - x;
|
||
double t2 = pt.y - y;
|
||
double t3 = pt.z - z;
|
||
|
||
return sqrt(t1 * t1 + t2 * t2 + t3 * t3);
|
||
}
|
||
|
||
inline double XPoint::Distance2d(const XPoint& pt) const
|
||
{
|
||
double XDis = x - pt.x;
|
||
double YDis = y - pt.y;
|
||
|
||
return sqrt(XDis * XDis + YDis * YDis);
|
||
}
|
||
|
||
inline void XPoint::TransformBy(const AcGeMatrix3d &mat)
|
||
{
|
||
((AcGePoint3d *)this)->transformBy(mat);
|
||
}
|
||
|
||
inline void XPoint::AT_xformpt(ads_matrix xform,ads_point pt,ads_point newpt) const
|
||
{
|
||
int i,j;
|
||
ads_point pt0;
|
||
|
||
newpt[X] = newpt[Y] = newpt[Z] = 0.0;
|
||
pt0[X] = pt[X];pt0[Y] = pt[Y];pt0[Z] = pt[Z];
|
||
|
||
for (i = X; i <= Z; i++)
|
||
{
|
||
for (j = X; j <= Z; j++)
|
||
{
|
||
newpt[i] += xform[i][j] * pt0[j];
|
||
}
|
||
|
||
newpt[i] += xform[i][T];
|
||
}
|
||
}
|
||
|
||
inline XPoint XPoint::TransformAs(ads_matrix mat) const
|
||
{
|
||
XPoint pt;
|
||
AT_xformpt(mat, (double *)&x, pt);
|
||
|
||
return pt;
|
||
}
|
||
|
||
inline void XPoint::TransformBy(ads_matrix mat)
|
||
{
|
||
XPoint pt;
|
||
AT_xformpt(mat, (double *)&x, pt);
|
||
|
||
*this = pt;
|
||
}
|
||
|
||
inline void XPoint::Mirror(const ads_point src, ads_point dest) const
|
||
{
|
||
dest[0] = 2 * x - src[0];
|
||
dest[1] = 2 * y - src[1];
|
||
dest[2] = 2 * z - src[2];
|
||
}
|
||
|
||
inline void XPoint::Mirror(const XPoint & src, XPoint &dest) const
|
||
{
|
||
dest.x = 2 * x - src.x;
|
||
dest.y = 2 * y - src.y;
|
||
dest.z = 2 * z - src.z;
|
||
}
|
||
|
||
inline void XPoint::Rotate(ads_real dang)
|
||
{
|
||
ads_real dewX = x * cos(dang) - y * sin(dang);
|
||
ads_real dewY = x * sin(dang) + y * cos(dang);
|
||
|
||
x = dewX;
|
||
y = dewY;
|
||
}
|
||
|
||
inline void XPoint::Reverse()
|
||
{
|
||
x = -x;
|
||
y = -y;
|
||
z = -z;
|
||
}
|
||
|
||
inline ads_real XPoint::Length() const
|
||
{
|
||
return sqrt(x * x + y * y + z * z);
|
||
}
|
||
|
||
inline void XPoint::Scale(ads_real dScale)
|
||
{
|
||
x *= dScale;
|
||
y *= dScale;
|
||
z *= dScale;
|
||
}
|
||
|
||
inline void XPoint::Normalize()
|
||
{
|
||
double nLen = Length();
|
||
if (nLen > 1.0E-9)
|
||
{
|
||
Scale(1.0 / nLen);
|
||
}
|
||
}
|
||
|
||
inline XPoint::operator const AcGePoint3d & ()
|
||
{
|
||
return *(const AcGePoint3d *)this;
|
||
}
|
||
|
||
inline XPoint::operator AcGePoint3d & () const
|
||
{
|
||
return *(AcGePoint3d *)this;
|
||
}
|
||
|
||
inline AcGePoint3d XPoint::AsAcGePoint3d() const
|
||
{
|
||
return AcGePoint3d(x, y, z);
|
||
}
|
||
|
||
inline XPoint::operator const AcGeVector3d& ()
|
||
{
|
||
return *(const AcGeVector3d *)this;
|
||
}
|
||
|
||
inline XPoint::operator AcGeVector3d& () const
|
||
{
|
||
return *(AcGeVector3d *)this;
|
||
}
|
||
|
||
inline AcGeVector3d XPoint::AsAcGeVector3d() const
|
||
{
|
||
return AcGeVector3d(x, y, z);
|
||
}
|
||
|
||
inline XPoint::operator const AcGePoint2d& ()
|
||
{
|
||
return *(const AcGePoint2d *)this;
|
||
}
|
||
|
||
inline XPoint::operator AcGePoint2d& () const
|
||
{
|
||
return *(AcGePoint2d *)this;
|
||
}
|
||
|
||
inline AcGePoint2d XPoint::AsAcGePoint2d() const
|
||
{
|
||
return AcGePoint2d(x, y);
|
||
}
|
||
|
||
inline XPoint::operator const AcGeVector2d& ()
|
||
{
|
||
return *(const AcGeVector2d *)this;
|
||
}
|
||
|
||
inline XPoint::operator AcGeVector2d& () const
|
||
{
|
||
return *(AcGeVector2d *)this;
|
||
}
|
||
|
||
inline AcGeVector2d XPoint::AsAcGeVector2d() const
|
||
{
|
||
return AcGeVector2d(x, y);
|
||
}
|
||
|
||
inline double XPoint::Distance(const XPoint& ptSta,const XPoint& ptEnd) const
|
||
{
|
||
ads_real* pt0 = *this;
|
||
ads_real* pt1 = ptSta;
|
||
ads_real* pt2 = ptEnd;
|
||
|
||
ads_point pt4;
|
||
|
||
struct plan_para plan;
|
||
XVector3D vt;
|
||
vt[0] = pt2[0] - pt1[0];
|
||
vt[1] = pt2[1] - pt1[1];
|
||
vt[2] = pt2[2] - pt1[2];
|
||
|
||
pt4[0]=pt0[0];
|
||
pt4[1]=pt0[1];
|
||
pt4[2]=pt0[2];
|
||
|
||
plan.A = vt[0];
|
||
plan.B = vt[1];
|
||
plan.C = vt[2];
|
||
plan.D = 0.0 - (vt[0] * pt0[0] + vt[1] * pt0[1] + vt[2] * pt0[2]);
|
||
|
||
double l, m, n, t;
|
||
double mid_var1, mid_var2;
|
||
|
||
l = pt2[0] - pt1[0];
|
||
m = pt2[1] - pt1[1];
|
||
n = pt2[2] - pt1[2];
|
||
|
||
mid_var1 = l * (plan.A) + m * (plan.B) + n * (plan.C);
|
||
if (fabs(mid_var1) < 0.000001)
|
||
{
|
||
return 0.0;
|
||
}
|
||
|
||
mid_var2 = (plan.D) + pt1[0] * (plan.A) + pt1[1] * (plan.B) + pt1[2] * (plan.C);
|
||
t = 0.0 - mid_var2 / mid_var1;
|
||
|
||
pt4[0] = pt1[0] + l * t;
|
||
pt4[1] = pt1[1] + m * t;
|
||
pt4[2] = pt1[2] + n * t;
|
||
|
||
double dist = ads_distance(pt0, pt4);
|
||
return dist;
|
||
}
|
||
|
||
inline XPoint operator + (const XPoint & pt1, const XPoint & pt2)
|
||
{
|
||
return Point(pt1.x + pt2.x, pt1.y + pt2.y, pt1.z + pt2.z);
|
||
}
|
||
|
||
inline XPoint operator - (const XPoint & pt1, const XPoint & pt2)
|
||
{
|
||
return Point(pt1.x - pt2.x, pt1.y - pt2.y, pt1.z - pt2.z);
|
||
}
|
||
|
||
inline XPoint Max(const XPoint &pt1, const XPoint &pt2)
|
||
{
|
||
XPoint upPt;
|
||
upPt.x = max(pt1.x, pt2.x);
|
||
upPt.y = max(pt1.y, pt2.y);
|
||
upPt.z = max(pt1.z, pt2.z);
|
||
return upPt;
|
||
}
|
||
|
||
inline XPoint Min(const XPoint &pt1, const XPoint &pt2)
|
||
{
|
||
XPoint lowPt;
|
||
lowPt.x = min(pt1.x, pt2.x);
|
||
lowPt.y = min(pt1.y, pt2.y);
|
||
lowPt.z = min(pt1.z, pt2.z);
|
||
return lowPt;
|
||
}
|
||
|
||
inline ads_real operator & (const XVector3D & pt1, const XVector3D & pt2)
|
||
{
|
||
return pt1.x * pt2.x + pt2.y * pt1.y + pt1.z * pt2.z;
|
||
}
|
||
|
||
inline XVector3D operator * (const XVector3D &pt1, const Vector3D &pt2)
|
||
{
|
||
XVector3D vt;
|
||
vt.x = pt1.y * pt2.z - pt1.z * pt2.y;
|
||
vt.y = pt1.z * pt2.x - pt1.x * pt2.z;
|
||
vt.z = pt1.x * pt2.y - pt1.y * pt2.x;
|
||
|
||
return vt;
|
||
}
|
||
|
||
inline XPoint Ucs2Wcs(XPoint ptSrc, BOOL bVector = FALSE)
|
||
{
|
||
XPoint ptDest;
|
||
Groups g1(1);
|
||
Groups g0(0);
|
||
ads_trans(ptSrc, (resbuf *)&g1, (resbuf *)&g0, bVector, ptDest);
|
||
return ptDest;
|
||
}
|
||
|
||
inline XPoint Wcs2Ucs(XPoint ptSrc, BOOL bVector = FALSE)
|
||
{
|
||
XPoint ptDest;
|
||
Groups g1(1);
|
||
Groups g0(0);
|
||
ads_trans(ptSrc, (resbuf *)&g0, (resbuf *)&g1, bVector, ptDest);
|
||
|
||
return ptDest;
|
||
}
|
||
inline XPoint Ecs2Wcs(XPoint ptSrc, XVector3D vtEcs, BOOL bVector = FALSE)
|
||
{
|
||
XPoint ptDest;
|
||
Groups g1(vtEcs);
|
||
Groups g0(0);
|
||
ads_trans(ptSrc, (resbuf *)&g1, (resbuf *)&g0, bVector, ptDest);
|
||
|
||
return ptDest;
|
||
}
|
||
|
||
inline XPoint Wcs2Ecs(XPoint ptSrc, XVector3D vtEcs, BOOL bVector = FALSE)
|
||
{
|
||
XPoint ptDest;
|
||
Groups g1(vtEcs);
|
||
Groups g0(0);
|
||
ads_trans(ptSrc, (resbuf *)&g0, (resbuf *)&g1, bVector, ptDest);
|
||
|
||
return ptDest;
|
||
}
|
||
|
||
inline XPoint Ucs2Ecs(XPoint ptSrc, XVector3D vtEcs, BOOL bVector = FALSE)
|
||
{
|
||
XPoint ptDest;
|
||
Groups g1(vtEcs);
|
||
Groups g0(1);
|
||
ads_trans(ptSrc, (resbuf *)&g0, (resbuf *)&g1, bVector, ptDest);
|
||
|
||
return ptDest;
|
||
}
|
||
|
||
inline XPoint Ecs2Ucs(XPoint ptSrc, XVector3D vtEcs, BOOL bVector = FALSE)
|
||
{
|
||
XPoint ptDest;
|
||
Groups v(vtEcs);
|
||
Groups g(1);
|
||
ads_trans(ptSrc, (resbuf *)&v, (resbuf *)&g, bVector, ptDest);
|
||
|
||
return ptDest;
|
||
}
|
||
|
||
inline double Ucs2Wcs(double nAng)
|
||
{
|
||
XVector3D vtUcs(cos(nAng), sin(nAng));
|
||
XVector3D vtWcs = Ucs2Wcs(vtUcs, TRUE);
|
||
|
||
return ads_angle(XPoint(), vtWcs);
|
||
}
|
||
|
||
class XGEAPI XPointDir2d : public XPoint
|
||
{
|
||
public:
|
||
|
||
XPointDir2d();
|
||
|
||
XPointDir2d(ads_real dDrt);
|
||
|
||
XPointDir2d(const XPointDir2d &src);
|
||
|
||
~XPointDir2d();
|
||
|
||
XPointDir2d & operator = (const XPointDir2d &src);
|
||
|
||
XPoint Polar(ads_real nDist) const;
|
||
|
||
void ShowMe();
|
||
|
||
void TransformBy(ads_matrix mat);
|
||
|
||
XPointDir2d TransformAs(ads_matrix mat) const;
|
||
|
||
public:
|
||
|
||
ads_real nDirection;
|
||
|
||
};
|
||
|
||
class XGEAPI XPointList : public DList<XPoint>
|
||
{
|
||
public:
|
||
|
||
XPointList();
|
||
|
||
XPointList(const XPointList &src);
|
||
|
||
~XPointList();
|
||
|
||
virtual void AppendNode(const XPoint &pt, ads_real dBulge = 0.0);
|
||
|
||
XPointList & operator = (const XPointList& src);
|
||
|
||
void TransUCS(const resbuf *pFrom, const resbuf *pTo);
|
||
|
||
void TransUCS(ads_matrix mat);
|
||
|
||
int GetExtend(ads_point ptMin, ads_point ptMax);
|
||
|
||
int GetExtend(ads_point ptMin, ads_point ptMax) const;
|
||
|
||
XPoint *FindPoint(const XPoint &ptSrc);
|
||
|
||
void Center(ads_point ptCen);
|
||
|
||
void AsPoly2D(XPointList &poly) const;
|
||
|
||
void SetElevation(ads_real dElev);
|
||
|
||
//如果不存在,则末尾添入, 返回点的位置序号
|
||
int NewAppend(const XPoint& ptSrc);
|
||
};
|
||
|
||
class XGEAPI XPolyFacet
|
||
{
|
||
public:
|
||
XPolyFacet(int v1, int v2, int v3, int v4 = 0);
|
||
virtual ~XPolyFacet();
|
||
|
||
int Make(const TCHAR *pszLay = NULL);
|
||
|
||
public:
|
||
int vt1;
|
||
int vt2;
|
||
int vt3;
|
||
int vt4;
|
||
};
|
||
|
||
class XGEAPI XPface: public XPointList
|
||
{
|
||
public:
|
||
~XPface();
|
||
|
||
int Make(const TCHAR *pazLay = NULL);
|
||
|
||
public:
|
||
|
||
DList<XPolyFacet> faces;
|
||
};
|
||
|
||
|
||
// 有序点组成的表
|
||
class XPoly2D;
|
||
class XGEAPI PointList : public XPointList
|
||
{
|
||
public:
|
||
|
||
PointList(const XPoint & startPoint, const XPoint & endPoint, ads_real bulge = 0);
|
||
virtual ~PointList();
|
||
|
||
int Insert(const XPoint & newPt, BOOL bExt = FALSE);
|
||
|
||
int Update(const ads_name ref);
|
||
|
||
void AsPoly2D(XPoly2D &poly) const;
|
||
|
||
public:
|
||
|
||
XPoint center;
|
||
|
||
CurveType curveType;
|
||
};
|
||
|
||
template <class K>
|
||
int xg_setvar(LPCTSTR sym, K val)
|
||
{
|
||
Groups g(val);
|
||
return ads_setvar(sym, (resbuf *)&g);
|
||
}
|
||
|
||
//获取系统变量
|
||
inline int xg_getvar(const TCHAR *var, int *res)
|
||
{
|
||
resbuf v;
|
||
if (ads_getvar(var, &v) != RTNORM || v.restype != RTSHORT )
|
||
{
|
||
return RTERROR;
|
||
}
|
||
*res = v.resval.rint;
|
||
return RTNORM;
|
||
}
|
||
|
||
inline int xg_getvar(const TCHAR *var, XPoint *res)
|
||
{
|
||
resbuf v;
|
||
if (ads_getvar(var, &v) != RTNORM || (v.restype != RT3DPOINT && v.restype != RTPOINT) )
|
||
{
|
||
return RTERROR;
|
||
}
|
||
*res = v.resval.rpoint;
|
||
return RTNORM;
|
||
}
|
||
|
||
inline int xg_getvar(LPCTSTR var, XPoint &res)
|
||
{
|
||
return xg_getvar(var,&res);
|
||
}
|
||
|
||
inline int xg_getvar(const TCHAR *var, double *res)
|
||
{
|
||
resbuf v;
|
||
if (ads_getvar(var, &v) != RTNORM || v.restype != RTREAL )
|
||
{
|
||
return RTERROR;
|
||
}
|
||
*res = v.resval.rreal;
|
||
return RTNORM;
|
||
}
|
||
|
||
inline int xg_getvar(const TCHAR *var, TCHAR *res)
|
||
{
|
||
resbuf v;
|
||
if (ads_getvar(var, &v) != RTNORM || v.restype != RTSTR )
|
||
{
|
||
return RTERROR;
|
||
}
|
||
_tcscpy(res, v.resval.rstring);
|
||
free(v.resval.rstring);
|
||
return RTNORM;
|
||
}
|
||
|
||
inline int xg_getsym(const TCHAR *var, int *res)
|
||
{
|
||
resbuf *v = NULL;
|
||
if (ads_getsym(var, &v) != RTNORM || !v)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
if ( v->restype != RTSHORT )
|
||
{
|
||
ads_relrb(v);
|
||
return RTERROR;
|
||
}
|
||
*res = v->resval.rint;
|
||
ads_relrb(v);
|
||
return RTNORM;
|
||
}
|
||
|
||
inline int xg_getsym(const TCHAR *var, XPoint *res)
|
||
{
|
||
resbuf *v = NULL;
|
||
if (ads_getsym(var, &v) != RTNORM || !v)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
if (v->restype != RT3DPOINT )
|
||
{
|
||
ads_relrb(v);
|
||
return RTERROR;
|
||
}
|
||
*res = v->resval.rpoint;
|
||
ads_relrb(v);
|
||
return RTNORM;
|
||
}
|
||
|
||
inline int xg_getsym(LPCTSTR var, XPoint &res)
|
||
{
|
||
return xg_getsym(var, &res);
|
||
}
|
||
|
||
inline int xg_getsym(const TCHAR *var, double *res)
|
||
{
|
||
resbuf *v = NULL;
|
||
if (ads_getsym(var, &v) != RTNORM || !v)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
if (v->restype != RTREAL )
|
||
{
|
||
ads_relrb(v);
|
||
return RTERROR;
|
||
}
|
||
*res = v->resval.rreal;
|
||
ads_relrb(v);
|
||
return RTNORM;
|
||
}
|
||
|
||
inline int xg_getsym(const TCHAR *var, TCHAR *res)
|
||
{
|
||
resbuf *v;
|
||
if (ads_getsym(var, &v) != RTNORM || !v)
|
||
{
|
||
return RTERROR;
|
||
}
|
||
if (v->restype != RTSTR )
|
||
{
|
||
ads_relrb(v);
|
||
return RTERROR;
|
||
}
|
||
_tcscpy(res, v->resval.rstring);
|
||
ads_relrb(v);
|
||
return RTNORM;
|
||
}
|
||
|
||
class PickSet;
|
||
class XGEAPI Entity : public RBList
|
||
{
|
||
public:
|
||
Entity();
|
||
Entity(const ads_name n);
|
||
Entity(const Entity &ent);
|
||
Entity(LPCTSTR handle);
|
||
~Entity();
|
||
|
||
void operator = (const ads_name n);
|
||
void operator = (const Entity &n);
|
||
int operator !() const;
|
||
|
||
void operator > (ads_name entother) const;
|
||
int operator == (const ads_name ent) const;
|
||
int operator == (const Entity &ent) const;
|
||
|
||
operator LONG_PTR *();
|
||
operator void *();
|
||
|
||
|
||
// 下列函数没有采用ADS命名规则,不建议使用
|
||
int In(const PickSet *pSelectionSet);
|
||
|
||
int Redraw(int mode = 1) const;
|
||
int RedrawAll(int mode = 1) const;
|
||
int Delete() const;
|
||
int Update() const;
|
||
int Erase() const;
|
||
int TypeOfCode(int code);
|
||
|
||
// member functions about groups
|
||
int Make();
|
||
int Modify() const;
|
||
int _GetGroups();
|
||
|
||
// member functions that can get a Entity Name;
|
||
int UserSelect(LPCTSTR prompt,ads_point pt);
|
||
int UserSelect(LPCTSTR prompt = NULL);
|
||
int UserSelect(LPCTSTR prompt,XPoint &pt);
|
||
|
||
int FilterSelect(LPCTSTR prompt, const RBList &mask, ads_point res);
|
||
int FilterSelect(LPCTSTR prompt, const RBList &mask);
|
||
int FilterSelect1(ads_real distPrec, LPCTSTR prmpt, const RBList &mask, ads_point res = NULL);
|
||
|
||
int GetLast();
|
||
int GetNext(const Entity &et);
|
||
int CreateByHandle(LPCTSTR handle);
|
||
|
||
int Handent(LPCTSTR handle);
|
||
int handent(LPCTSTR handle);
|
||
|
||
int GetData(int cd,void *buf);
|
||
int SetData(int cd,...);
|
||
|
||
int Make(int,...);
|
||
int MakeEx(int, ...);
|
||
int GetNext();
|
||
|
||
// member functions to implement Extended Data Access;
|
||
static const TCHAR *ApplicationName;
|
||
static int AssignAppName(const TCHAR *s);
|
||
|
||
// 不建议使用
|
||
int GetGroups(int getEx = 1);
|
||
int GetGroups(const TCHAR *appName);
|
||
void FreeGroups();
|
||
|
||
// 采用ADS命名规则, 建议使用
|
||
int entgetx();
|
||
int entgetx(const TCHAR *appName);
|
||
|
||
int Match(const RBList &exlist);
|
||
int MatchEx(const Groups *tag, const Groups *data);
|
||
int MatchEx(int tag, const TCHAR *data);
|
||
int MatchEx(int tag, int data) ;
|
||
int MatchEx(int tag, ads_real data);
|
||
int MatchEx(int tag, const Groups * data);
|
||
|
||
int MatchBase(const Groups &rb);
|
||
int MatchBase(const RBList &baseList);
|
||
|
||
int Is(const TCHAR *entType);
|
||
|
||
Groups * SearchByTagCode(int tag_code);
|
||
Groups * SearchDataByTag(int tag);
|
||
|
||
// 扩充实体的操作
|
||
int GetInt (int tag_code, int &buf);
|
||
int GetReal(int tag_code, ads_real &buf);
|
||
int GetRString(int tag_cdoe,TCHAR *&buf);
|
||
int GetString (int tag_code,TCHAR *buf);
|
||
int GetPoint(int tag_code, XPoint &buf);
|
||
int GetRBinary(int tag_code, short &nBufLen, const char * &buf);
|
||
|
||
int SetInt (int tag_code,int buf);
|
||
int SetReal(int tag_code,ads_real buf);
|
||
int SetString (int tag_code, const TCHAR *buf, int isHandle = 0);
|
||
int SetPoint(int tag_code, const XPoint &buf);
|
||
int SetBinary(int tag_code, short nBufLen, const char * buf);
|
||
|
||
// support simple type string & int & real
|
||
int SetExData(int tag_code,...);
|
||
int GetExData(int tag_code,void *buf);
|
||
|
||
// 删除指定的扩充实体数据
|
||
int DeleteTag(int tag_code);
|
||
int RemoveXData();
|
||
|
||
int SetStruct(void *buf,int len, int tag_code = EX_STRUCT);
|
||
int GetStruct(void *buf,int len, int tag_code = EX_STRUCT);
|
||
|
||
public:
|
||
ads_name name;
|
||
PGroups groupsEx;
|
||
|
||
private:
|
||
int CreateTag(void *buf,int tag_code,int type);
|
||
void _MakeExGroups();
|
||
};
|
||
|
||
typedef Entity EntityEx;
|
||
inline void Entity::operator = (const ads_name n)
|
||
{
|
||
FreeGroups();
|
||
name[0] = n[0];
|
||
name[1] = n[1];
|
||
}
|
||
|
||
inline void Entity::operator = (const Entity &n)
|
||
{
|
||
FreeGroups();
|
||
*this = n.name;
|
||
}
|
||
|
||
inline void Entity::operator > (ads_name entother) const
|
||
{
|
||
*entother = *name;
|
||
entother[1] = name[1];
|
||
}
|
||
|
||
inline int Entity::operator == (const ads_name ent) const
|
||
{
|
||
return *name == *ent && name[1] == ent[1];
|
||
}
|
||
|
||
inline int Entity::operator == (const Entity &ent) const
|
||
{
|
||
return *this == ent.name;
|
||
}
|
||
|
||
inline int Entity::operator !() const
|
||
{
|
||
return !*name && !name[1];
|
||
}
|
||
|
||
inline Entity::operator LONG_PTR *()
|
||
{
|
||
return name;
|
||
}
|
||
|
||
inline Entity::operator void *()
|
||
{
|
||
return name;
|
||
}
|
||
|
||
inline Entity::Entity() : groupsEx(0)
|
||
{
|
||
*name = name[1] = 0;
|
||
}
|
||
|
||
inline Entity::Entity(const ads_name n): groupsEx(0)
|
||
{
|
||
name[0] = n[0];
|
||
name[1] = n[1];
|
||
}
|
||
|
||
inline Entity::Entity(const Entity &ent): groupsEx(0)
|
||
{
|
||
name[0] = ent.name[0];
|
||
name[1] = ent.name[1];
|
||
}
|
||
|
||
inline Entity::Entity(LPCTSTR handle): groupsEx(0)
|
||
{
|
||
name[0] = name[1] = 0;
|
||
ads_handent((LPCTSTR)handle,name);
|
||
}
|
||
|
||
inline int Entity::Delete() const
|
||
{
|
||
return ads_entdel(name);
|
||
}
|
||
|
||
inline int Entity::UserSelect(LPCTSTR prompt,XPoint &pt)
|
||
{
|
||
return UserSelect(prompt,(double*)&pt);
|
||
}
|
||
|
||
inline int Entity::GetLast()
|
||
{
|
||
FreeGroups();
|
||
return (ads_entlast(name));
|
||
}
|
||
|
||
inline int Entity::Modify() const
|
||
{
|
||
return (ads_entmod((struct resbuf *)groups));
|
||
}
|
||
|
||
inline int Entity::Update() const
|
||
{
|
||
return (ads_entupd(name));
|
||
}
|
||
|
||
inline int Entity::GetNext(const Entity &et)
|
||
{
|
||
FreeGroups();
|
||
return (ads_entnext(et.name,name));
|
||
}
|
||
|
||
inline int Entity::CreateByHandle(LPCTSTR handle)
|
||
{
|
||
return (ads_handent(handle,name));
|
||
}
|
||
|
||
inline int Entity::UserSelect(LPCTSTR prompt,ads_point pt)
|
||
{
|
||
FreeGroups();
|
||
return (ads_entsel(prompt,name,pt));
|
||
}
|
||
|
||
inline int Entity::UserSelect(LPCTSTR prompt)
|
||
{
|
||
FreeGroups();
|
||
ads_point pt;
|
||
return (ads_entsel(prompt,name,pt));
|
||
}
|
||
|
||
inline int Entity::Redraw(int mode) const
|
||
{
|
||
return (ads_redraw(name,mode));
|
||
}
|
||
|
||
inline int Entity::Handent(LPCTSTR handle)
|
||
{
|
||
FreeGroups();
|
||
return ads_handent((LPCTSTR)handle,name);
|
||
}
|
||
|
||
inline int Entity::handent(LPCTSTR handle)
|
||
{
|
||
FreeGroups();
|
||
return ads_handent((LPTSTR)handle,name);
|
||
}
|
||
|
||
inline int Entity::GetData(int cd,void *buf)
|
||
{
|
||
if (!groups)
|
||
{
|
||
_GetGroups();
|
||
}
|
||
return RBList::GetData(cd,buf);
|
||
}
|
||
|
||
inline Groups * Entity::SearchDataByTag(int tag)
|
||
{
|
||
Groups *rbTag = SearchByTagCode(tag);
|
||
if(!rbTag)
|
||
{
|
||
return NULL;
|
||
}
|
||
|
||
return rbTag->next;
|
||
}
|
||
|
||
inline int Entity::GetNext()
|
||
{
|
||
Entity e = *this;
|
||
return GetNext(e);
|
||
}
|
||
|
||
inline void Entity::FreeGroups()
|
||
{
|
||
groupsEx = NULL;
|
||
RBList::FreeGroups();
|
||
}
|
||
|
||
inline int Entity::entgetx()
|
||
{
|
||
return GetGroups();
|
||
}
|
||
|
||
inline int Entity::entgetx(const TCHAR *appName)
|
||
{
|
||
return GetGroups((TCHAR *)appName);
|
||
}
|
||
|
||
inline int Entity::Is(const TCHAR *entType)
|
||
{
|
||
TCHAR eType[40];
|
||
if(GetData(0, eType) == RTNORM && _tcsicmp(eType, entType) == 0)
|
||
{
|
||
return 1;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
class XGEAPI PickSet
|
||
{
|
||
friend XGEAPI PickSet operator + (const PickSet &, const PickSet &);
|
||
|
||
friend XGEAPI PickSet operator - (const PickSet &, const PickSet &);
|
||
|
||
friend XGEAPI PickSet operator * (const PickSet &, const PickSet &);
|
||
|
||
public:
|
||
|
||
PickSet(int createMode = 0);
|
||
|
||
PickSet(const ads_name n);
|
||
|
||
PickSet(const PickSet & n);
|
||
|
||
virtual ~PickSet();
|
||
|
||
operator LONG_PTR *();
|
||
|
||
int operator !() const;
|
||
|
||
int operator += (const AcDbObjectId &);
|
||
|
||
int operator -= (const AcDbObjectId &);
|
||
|
||
int operator += (const Entity &);
|
||
|
||
int operator -= (const Entity &);
|
||
|
||
int operator += (const PickSet &);
|
||
|
||
int operator -= (const PickSet &);
|
||
|
||
PickSet & operator = (const ads_name n);
|
||
|
||
PickSet & operator = (const PickSet &n);
|
||
|
||
Entity operator [](long index) const;
|
||
|
||
int MakeUnnamedGroup();
|
||
|
||
int Get(LPCTSTR commandString = NULL, void *pt1 = NULL, const ads_point pt2 = NULL);
|
||
|
||
int Get(LPCTSTR commandString, void *pt1, const ads_point pt2, const RBList & entmask);
|
||
|
||
int Get(LPCTSTR commandString, void *pt1, const ads_point pt2, const resbuf * entmask);
|
||
|
||
int Transform(ads_matrix genmat) const;
|
||
|
||
void Get(XPoint ptUcs,const resbuf* entmask = NULL);
|
||
|
||
void GetPreSel(const resbuf* entmask = NULL);
|
||
|
||
void AsIdArray(AcDbObjectIdArray &idArray);
|
||
|
||
void Free();
|
||
|
||
long Length() const;
|
||
|
||
// New Tools
|
||
bool IsInclude(Entity ent)const;
|
||
|
||
void IncludeBegin();
|
||
|
||
void IncludeEnd();
|
||
|
||
void Redraw(int mode = 1) const;
|
||
|
||
void RedrawAll(int mode = 1) const;
|
||
|
||
void Delete() const;
|
||
|
||
int Erase() const;
|
||
|
||
void Bind(const Entity& key);
|
||
|
||
void ExFilter(const RBList &exList);
|
||
|
||
void ExTagFilter(const int *tagList, int sz);
|
||
|
||
//留下满足baseList的实体
|
||
void BaseFilter(RBList &baseList);
|
||
|
||
//排除掉满足baseList的实体
|
||
void BaseExclude(RBList &baseList);
|
||
|
||
int RemoveXData() const;
|
||
|
||
public:
|
||
|
||
ads_name name;
|
||
|
||
Entity mark;
|
||
|
||
unsigned char flag;
|
||
};
|
||
|
||
class XGEAPI XEntity
|
||
{
|
||
public:
|
||
enum TEntityId
|
||
{
|
||
eEntity,
|
||
e3DFace,
|
||
ePlane,
|
||
eHatch,
|
||
eCurve,
|
||
eShape,
|
||
eCircle,
|
||
eArc,
|
||
eLinearEnt,
|
||
eLine,
|
||
eCurveSegment,
|
||
eAFace3D,
|
||
eDbCurveSegEntity,
|
||
eRegionSide,
|
||
eDirectionCurve,
|
||
eCurveSegSeg,
|
||
eCurveSegunique,
|
||
ePoly,
|
||
ePolygonEx,
|
||
ePoly2D,
|
||
ePoly3D,
|
||
eRegion2D
|
||
};
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
virtual void CopyFrom(const XEntity* pImpSrc);
|
||
|
||
virtual void TransformBy(ads_matrix mat);
|
||
virtual int GetExtend(XPoint &ptlow, XPoint &ptup) const;
|
||
//图形长度,周长
|
||
virtual double 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 int OSnap(int nMode, XPoint &ptPick) const;
|
||
|
||
protected:
|
||
XEntity();
|
||
virtual ~XEntity();
|
||
};
|
||
|
||
class XGEAPI XPlane : public XEntity
|
||
{
|
||
public:
|
||
|
||
XPlane();
|
||
|
||
XPlane(double aa, double bb, double cc, double dd);
|
||
|
||
XPlane(const XPoint &ptOrg, const XVector3D &vtNorm);
|
||
|
||
XPlane(const XPlane &src);
|
||
|
||
virtual ~XPlane();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
virtual void CopyFrom(const XEntity* pImpSrc);
|
||
|
||
virtual BOOL IsValid() const;
|
||
|
||
// 3点确定一平面方程
|
||
virtual BOOL SetFrom3p(const XPoint &pt1, const XPoint &pt2, const XPoint &pt3);
|
||
|
||
// 平面与线求交,考虑了线是否为无限长
|
||
virtual BOOL Intersect(const XLine &ln, XPoint &ptInt) const;
|
||
|
||
// 平面与平面求交,求交线(无限长)
|
||
virtual BOOL Intersect(const XPlane &plan, XLine &ln) const;
|
||
|
||
int InitPlane(const XPoint &pt1, const XPoint &pt2, const XPoint &pt3);
|
||
int InitPlane(const XPoint &pt0, const XVector3D &vt);
|
||
|
||
virtual XVector3D GetNormal() const;
|
||
|
||
virtual double GetAngle(XVector3D vtLight)const;
|
||
|
||
virtual bool IsReflect(XVector3D vtLight)const;
|
||
|
||
virtual bool Reflect(XVector3D vtLight,XVector3D& vtRes)const;
|
||
|
||
virtual double GetParaA()const;
|
||
virtual void SetParaA(const double dVal);
|
||
|
||
virtual double GetParaB()const;
|
||
virtual void SetParaB(const double dVal);
|
||
|
||
virtual double GetParaC()const;
|
||
virtual void SetParaC(const double dVal);
|
||
|
||
virtual double GetParaD()const;
|
||
virtual void SetParaD(const double dVal);
|
||
|
||
XPlane & operator = (const XPlane &src);
|
||
|
||
BOOL operator !() const;
|
||
|
||
public:
|
||
|
||
double m_dParaA, m_dParaB, m_dParaC, m_dParaD;
|
||
};
|
||
|
||
class XGEAPI XCurve : public XEntity
|
||
{
|
||
public:
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() 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 int OSnap(int nMode, XPoint &ptPick) const;
|
||
|
||
protected:
|
||
XCurve();
|
||
virtual ~XCurve();
|
||
};
|
||
|
||
class XGEAPI XCell : public XCurve
|
||
{
|
||
public:
|
||
virtual ~XCell(){}
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const
|
||
{
|
||
switch(entType)
|
||
{
|
||
case XEntity::eEntity:
|
||
case XEntity::eCurve:
|
||
case XEntity::eShape:
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
virtual TEntityId Type() const {return XEntity::eShape;}
|
||
|
||
protected:
|
||
virtual ShapeType GetShapeType() const {return SHAPE_UNKNOWN;}
|
||
virtual void Center(ads_point ptCen){}
|
||
virtual ads_real Area(){return 0.0;}
|
||
};
|
||
|
||
class XLine;
|
||
class XGEAPI XPoly : public XCell, public XPointList
|
||
{
|
||
public:
|
||
|
||
XPoly();
|
||
XPoly(resbuf *pts);
|
||
XPoly(const Entity &entPLine);
|
||
XPoly(const XPoly &src);
|
||
|
||
virtual ~XPoly();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
virtual void CopyFrom(const XEntity* pSrc);
|
||
|
||
virtual ShapeType GetShapeType () const;
|
||
virtual void Center(ads_point ptCen);
|
||
|
||
virtual XPoly& operator = (const XPoly &src);
|
||
virtual int operator ! ();
|
||
|
||
virtual int IsPoint();
|
||
virtual int IsLinear();
|
||
virtual int IsRectAngle(ads_point ptcen = NULL, ads_real *pdwidth = NULL, ads_real *pdheight = NULL);
|
||
|
||
virtual int NthLine(int index, XLine &res);
|
||
virtual int CreatePface(const TCHAR *szlay = NULL);
|
||
|
||
virtual resbuf *Fence();
|
||
virtual resbuf *Polygon();
|
||
virtual resbuf *ResbufList(int nIsClosed = 0);
|
||
|
||
virtual ads_real PathArea();
|
||
virtual ads_real Area();
|
||
|
||
virtual int GetExtend(XPoint &ptlow, XPoint &ptup) const;
|
||
};
|
||
|
||
inline int LimitCycle(int n, int nLen)
|
||
{
|
||
if (n < 0)
|
||
{
|
||
n += nLen;
|
||
}
|
||
else if (n >= nLen)
|
||
{
|
||
n -= nLen;
|
||
}
|
||
else
|
||
{
|
||
return n;
|
||
}
|
||
return LimitCycle(n, nLen);
|
||
}
|
||
|
||
template <class R>
|
||
class LoopList : public DList<R>
|
||
{
|
||
public:
|
||
|
||
LoopList();
|
||
~LoopList(){}
|
||
|
||
R * operator [](int n);
|
||
|
||
const R & operator [](int n) const;
|
||
|
||
|
||
const R & GetAt(int n) const;
|
||
R * GetAt(int n);
|
||
|
||
void RemoveNode(int n);
|
||
|
||
};
|
||
|
||
template <class R>
|
||
LoopList<R>::LoopList()
|
||
{
|
||
|
||
}
|
||
|
||
template <class R>
|
||
R * LoopList<R>::operator [](int n)
|
||
{
|
||
int nLen=this->Length();
|
||
n = LimitCycle(n, nLen);
|
||
return DList<R>::operator[](n);
|
||
}
|
||
|
||
template <class R>
|
||
const R & LoopList<R>::operator [](int n) const
|
||
{
|
||
int nLen=this->Length();
|
||
n = LimitCycle(n, nLen);
|
||
const DList<R> &rThis=*this;
|
||
return rThis[n];
|
||
}
|
||
|
||
template <class R>
|
||
R * LoopList<R>::GetAt(int n)
|
||
{
|
||
int nLen = this->Length();
|
||
n = LimitCycle(n, nLen);
|
||
return DList<R>::GetAt(n);
|
||
}
|
||
|
||
template <class R>
|
||
const R & LoopList<R>::GetAt(int n) const
|
||
{
|
||
int nLen = this->Length();
|
||
n = LimitCycle(n, nLen);
|
||
const DList<R> &rThis = *this;
|
||
return rThis.GetAt(n);
|
||
}
|
||
|
||
template <class R>
|
||
void LoopList<R>::RemoveNode(int n)
|
||
{
|
||
(*this)[n];
|
||
this->Remove();
|
||
}
|
||
|
||
inline int Maximum(int n, int r1, ...)
|
||
{
|
||
MAX_MIN(max, int);
|
||
}
|
||
|
||
inline double Maximum(int n, double r1, ...)
|
||
{
|
||
MAX_MIN(max, double);
|
||
}
|
||
|
||
inline int Minimum(int n, int r1, ...)
|
||
{
|
||
MAX_MIN(min, int);
|
||
}
|
||
|
||
inline double Minimum(int n, double r1, ...)
|
||
{
|
||
MAX_MIN(min, double);
|
||
}
|
||
|
||
inline XPoint Maximum(int n, class XPoint r1, ...)
|
||
{
|
||
MAX_MIN(Max, XPoint);
|
||
}
|
||
|
||
inline XPoint Minimum(int n, class XPoint r1, ...)
|
||
{
|
||
MAX_MIN(Min, XPoint);
|
||
}
|
||
|
||
#define FLAG_UNNORMAL 0x10
|
||
#define FLAG_TRIANGLE 0x20 //此时0、3两点相等
|
||
|
||
class XPoly3D;
|
||
class XCurveSegment;
|
||
class X3DFace3Pt;
|
||
class XGEAPI X3DFace : public XEntity
|
||
{
|
||
public:
|
||
|
||
X3DFace(int tag = 0);
|
||
|
||
X3DFace(Entity &entFace, ads_matrix tranMat = NULL);
|
||
|
||
X3DFace(X3DFace3Pt &face1, X3DFace3Pt &face2);
|
||
|
||
X3DFace(const AcDbFace &face);
|
||
|
||
X3DFace(const X3DFace &face);
|
||
|
||
virtual ~X3DFace();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
virtual void CopyFrom(const XEntity* pImpSrc);
|
||
|
||
|
||
//如果是三角形,则移位使得首末点相同
|
||
virtual X3DFace & MakeBetter();
|
||
|
||
virtual int IsLinear() const;
|
||
|
||
virtual int IsPoint() const;
|
||
|
||
virtual int IsRectangular(ads_real *x = NULL, ads_real *y = NULL) const;
|
||
|
||
// nMethod: 0-采用标记来判断,1-采用首没点是否相同来判断,2-采用任意相邻2点相等来判断
|
||
// 执行速度依次递减
|
||
virtual BOOL IsTriangle(int nMethod) const;
|
||
|
||
virtual BOOL IsVisible(int nSide) const;
|
||
|
||
virtual void SetVisible(int nSide, BOOL bTrue);
|
||
|
||
virtual int GetExtend(ads_point lowPt, ads_point upPt) const;
|
||
|
||
virtual int Make(LPCTSTR lay = NULL) const;
|
||
|
||
virtual int Modify(Entity &entFace);
|
||
|
||
virtual void TransformBy(ads_matrix mat);
|
||
|
||
virtual void ExplodeEdge(DList<XCurveSegment> &lstSegs) const;
|
||
|
||
virtual void SetElevation(double nElev);
|
||
|
||
virtual XVector3D GetNormal() const;
|
||
|
||
virtual void Reverse();
|
||
|
||
virtual int GetFlag()const;
|
||
virtual void SetFlag(const int nFlag);
|
||
|
||
virtual XPoint& GetVertex(int nIndex);
|
||
virtual XPoint GetVertex(int nIndex)const;
|
||
virtual void SetVertex(int nIndex, XPoint pt);
|
||
|
||
AcDbFace *AsDbFace() const;
|
||
|
||
//0~3顶点向前/向后移位
|
||
void MoveShift(BOOL bForward);
|
||
|
||
// 对3dface进行切割
|
||
BOOL SectByPlane(const XPlane &plan, DList<X3DFace> &upFaces, DList<X3DFace> &downFaces) const;
|
||
|
||
//vtLight都必须是单位向量!
|
||
virtual XPoly3D GetPoly3D()const;
|
||
|
||
XPlane GetPlane()const;
|
||
|
||
int operator !() const;
|
||
|
||
X3DFace & operator= (const X3DFace &face);
|
||
|
||
X3DFace & operator << (int nBit);
|
||
|
||
X3DFace & operator >> (int nBit);
|
||
|
||
void SubSortVertex();
|
||
BOOL SubSectByX(double xSect, DList<X3DFace> &leftFaces, DList<X3DFace> &rightFaces) const;
|
||
public:
|
||
int m_nFlag;
|
||
XPoint m_ptVertex[4];
|
||
};
|
||
|
||
// 三个顶点的3DFACE, 仅用于特殊用途
|
||
class XGEAPI X3DFace3Pt : public X3DFace
|
||
{
|
||
public:
|
||
|
||
X3DFace3Pt(Entity &entFace);
|
||
~X3DFace3Pt();
|
||
|
||
int GetMergeLine(XLine *pLine);
|
||
|
||
// 返回值: 0~2
|
||
int MergeEdge();
|
||
|
||
// 返回值: 0~2
|
||
int OppHidePoint();
|
||
};
|
||
|
||
|
||
// 用三角形拼多边形
|
||
class XGEAPI XTriangle
|
||
{
|
||
public:
|
||
|
||
XTriangle(const XPoint &pt1, const XPoint &pt2, const XPoint &pt3, int nFlag=0);
|
||
virtual ~XTriangle();
|
||
|
||
void Ecs2Wcs(XVector3D vtEcs);
|
||
void Wcs2Ecs(XVector3D vtEcs);
|
||
|
||
void AsFace(X3DFace &face) const;
|
||
|
||
int IsLinear();
|
||
int IsInvisible();
|
||
|
||
// 1~3-命中1~3点;-1~-3 -命中1~3边;0-外部;4-内部
|
||
int HitTest2d(const XPoint &ptTest) const;
|
||
|
||
enum HitType
|
||
{
|
||
HIT_SIDE1 = -1, //边1
|
||
HIT_SIDE2 = -2, //边2
|
||
HIT_SIDE3 = -3, //边3
|
||
|
||
HIT_OUTSIDE = 0, //外部
|
||
|
||
HIT_VERTEX1 = 1, //顶点1
|
||
HIT_VERTEX2 = 2, //顶点2
|
||
HIT_VERTEX3 = 3, //顶点3
|
||
|
||
HIT_INSIDE = 4 //内部
|
||
};
|
||
|
||
public:
|
||
|
||
int m_nFlag;
|
||
|
||
XPoint vertex1, vertex2, vertex3;
|
||
};
|
||
|
||
class XGEAPI XTrianglePface : public DList< XTriangle >
|
||
{
|
||
|
||
public:
|
||
~XTrianglePface();
|
||
|
||
int MakePolyface(const TCHAR *pszLay = NULL);
|
||
|
||
int MakeSolid(const TCHAR *pszLay = NULL);
|
||
};
|
||
|
||
// 多边形的三角形化
|
||
class XGEAPI XPolygonEx : public XPoly
|
||
{
|
||
public:
|
||
XPolygonEx();
|
||
XPolygonEx(XPoly &src);
|
||
XPolygonEx(Entity &ent);
|
||
XPolygonEx(const XPolygonEx &src);
|
||
virtual ~XPolygonEx();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
virtual void CopyFrom(const XEntity* pSrc);
|
||
|
||
XPoint * operator [](int nIndex);
|
||
const XPoint & operator [](int nIndex) const;
|
||
XPolygonEx & operator = (const XPolygonEx &src);
|
||
|
||
// 求法向量,用来作为坐标变换
|
||
int GetNormal(XVector3D &vtNormal) const;
|
||
|
||
int Make(const TCHAR *szLay);
|
||
|
||
// b2D--TRUE, 已经是二维;否则是三维,需要坐标变换
|
||
int Trianglize(DList<XTriangle> &lstTris, BOOL b2D = FALSE) const;
|
||
int SubTrianglize(DList<XTriangle> &lstTris);
|
||
|
||
int GetInsidePoint(XPoint &ptRet, BOOL b2D = FALSE) const;
|
||
int SubGetInsidePoint(XPoint &ptRet);
|
||
|
||
//是否为凸多边形,2D
|
||
BOOL IsConvex() const;
|
||
BOOL IsVisible(int idx) const;
|
||
|
||
void Reset();
|
||
void Reverse();
|
||
void Ecs2Wcs(XVector3D vtEcs);
|
||
void Wcs2Ecs(XVector3D vtEcs);
|
||
|
||
void SetVisible(int idx, BOOL bVis);
|
||
|
||
void RemoveNode(int nIndex);
|
||
void AppendNode(const XPoint &pt, int nIndex = 1);
|
||
|
||
double GetEdgeLength(int idx) const;
|
||
double GetAngle(int idx) const;
|
||
XPoint GetVertex(int idx) const;
|
||
LoopList<int>& GetVisibleFlag();
|
||
|
||
public:
|
||
// 1--visible; 0-invisible
|
||
LoopList<int> m_lstVisibleFlag;
|
||
};
|
||
|
||
class XHoleModel
|
||
{
|
||
public:
|
||
XHoleModel();
|
||
|
||
virtual ~XHoleModel();
|
||
|
||
virtual void SetOutLine(const XPolygonEx &outline);
|
||
|
||
virtual void GetOutLine(XPolygonEx &outline);
|
||
virtual XPolygonEx &GetOutLine();
|
||
|
||
virtual void AppendHoleList(XPolygonEx *pHole);
|
||
|
||
virtual DList<XPolygonEx> &GetHoleList();
|
||
virtual int GetHoleList(DList<XPolygonEx> &lstPolygonEx);
|
||
|
||
virtual BOOL IsValid() const;
|
||
|
||
virtual BOOL Wcs2Ecs(XVector3D &vtEcs, double &nElev);
|
||
|
||
virtual BOOL Triangulate(BOOL bKeepConstant, DList<XTriangle> &lstTris, BOOL bAs3D = TRUE);
|
||
|
||
public:
|
||
XPolygonEx m_outline;
|
||
DList<XPolygonEx> m_holes;
|
||
};
|
||
|
||
class XArc;
|
||
class XLine;
|
||
class XGEAPI XCircle : public XCell
|
||
{
|
||
public:
|
||
XCircle();
|
||
XCircle(const XCircle &src);
|
||
XCircle(const ads_point, const ads_point);
|
||
XCircle(const ads_point ptcenter,double dradius);
|
||
XCircle(const Entity &entCircle, ads_matrix mat = NULL);
|
||
XCircle(const XPoint &pt1, const XPoint &pt2, const XPoint &pt3);
|
||
virtual ~XCircle();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
virtual void CopyFrom(const XEntity* pSrc);
|
||
|
||
virtual ShapeType GetShapeType() const;
|
||
|
||
virtual int Intersection(const XLine* pLine, ads_point ptrp1 = NULL, ads_point ptrp2 = NULL) const;
|
||
virtual int Intersection(const XArc* pArc, ads_point ptrp1 = NULL, ads_point ptrp2 = NULL) const;
|
||
virtual int Intersection(const XCircle* pCir, ads_point ptrp1 = NULL, ads_point ptrp2 = NULL) const;
|
||
|
||
virtual int GetExtend(ads_point lowPt, ads_point upPt) const;
|
||
virtual int GetSubArc(const XPoint& ptloc, ads_real dchordLen, XArc& xarcres) const;
|
||
|
||
virtual int Make(const TCHAR* szlay = NULL) const;
|
||
virtual int Modify(const Entity* pEntity) const;
|
||
virtual int MakeEntity(const Entity* pEntity) const;
|
||
|
||
virtual void Center(ads_point ptCen);
|
||
//图形长度,周长
|
||
virtual ads_real GetLength() const;
|
||
|
||
virtual ads_real Area() const;
|
||
|
||
virtual int HitTest2d(const XPoint &ptTest) const;
|
||
virtual int OSnap(int nMode, XPoint &ptPick) const;
|
||
|
||
//第一象限点圆心变换,求半径
|
||
virtual void TransUCS(ads_matrix mat);
|
||
|
||
int operator !() const;
|
||
XCircle& operator = (const XCircle &src);
|
||
bool operator == (const XCircle &src) const;
|
||
|
||
XCircle Offset(ads_real dist) const;
|
||
|
||
XPoint GetCenterPt();
|
||
XPoint GetCenterPt() const;
|
||
void SetCenterPt(XPoint pt);
|
||
|
||
double GetRadius() const;
|
||
double GetRadius();
|
||
void SetRadius(double dR);
|
||
bool Set(const XPoint &ptStart, const XPoint &ptOn, const XPoint &ptEnd);
|
||
void Set(const XPoint &diaPt1, const XPoint &diaPt2);
|
||
|
||
int PtOnCircle(const XPoint &pt);
|
||
public:
|
||
XPoint m_ptCenter;
|
||
double m_dRadius;
|
||
};
|
||
|
||
inline XEntity::TEntityId XCircle::Type() const
|
||
{
|
||
return XEntity::eCircle;
|
||
}
|
||
|
||
class XGEAPI XSector
|
||
{
|
||
public:
|
||
XSector();
|
||
XSector(ads_real dStAng, ads_real dEndAng);
|
||
XSector(const XSector & src);
|
||
XSector(const Entity & ent);
|
||
~XSector();
|
||
|
||
XSector& operator = (XSector &src);
|
||
|
||
bool operator == (const XSector &src) const;
|
||
int operator ! () const;
|
||
|
||
// 判断一平面向量是否在扇形区内
|
||
int AngleFlag(ads_real dAng) const;
|
||
|
||
// 找较近的一个角度
|
||
ads_real* NearAngle(ads_real dAng);
|
||
|
||
ads_real Bulge() const;
|
||
ads_real MidAngle() const;
|
||
|
||
void SetAngles(ads_real dStart, ads_real dEnd);
|
||
|
||
void TransUCS(ads_real dIncAngle);
|
||
|
||
void SetStarAngle(ads_real dAngle);
|
||
void SetEndAngle(ads_real dAngle);
|
||
|
||
ads_real GetStarAngle() const;
|
||
ads_real GetEndAngle() const;
|
||
|
||
public:
|
||
double m_dstartAngle;
|
||
double m_dendAngle;
|
||
};
|
||
|
||
class XGEAPI XArc : public XCircle, public XSector
|
||
{
|
||
public :
|
||
XArc(){}
|
||
XArc(const XArc &src): XCircle(src), XSector(src){}
|
||
XArc(const Entity &aCircle): XCircle(aCircle), XSector(aCircle){}
|
||
XArc(const Entity &aArc, ads_matrix mat);
|
||
XArc(const XPoint &spt, const XPoint &ept, ads_real dang);
|
||
XArc(const XPoint &ptStart, const XPoint &pt2, const XPoint &ptEnd);
|
||
XArc(ads_point ptcenter, double dradius, double ptstartAngle, double ptendAngle);
|
||
virtual ~XArc();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
virtual void CopyFrom(const XEntity* pImpSrc);
|
||
|
||
virtual int Make(const TCHAR *szlay = NULL) const;
|
||
virtual int Modify(const Entity* pEnt) const;
|
||
virtual int GetExtend(ads_point lowPt, ads_point upPt) const;
|
||
virtual int MakeEntity(const Entity* pEnt) const;
|
||
virtual int GetSubArc(const XPoint &ptloc, ads_real dchordLen, XArc &arcRes) const;
|
||
//图形长度,周长
|
||
virtual ads_real GetLength() const;
|
||
|
||
XArc& operator = (const XSector &src);
|
||
XArc& operator = (const XArc &src);
|
||
bool operator == (const XArc &src) const;
|
||
int operator ! () const;
|
||
|
||
virtual int HitTest2d(const XPoint &ptTest) const;
|
||
virtual int OSnap(int nMode, XPoint &ptPick) const;
|
||
|
||
bool Set(const XPoint &spt, const XPoint &ept, ads_real dang);
|
||
bool Set(const XPoint &ptStart, const XPoint &ptOn, const XPoint &ptEnd);
|
||
void SetAngleByPoints(const XPoint &ptStart, const XPoint &ptEnd);
|
||
|
||
void GetStartPoint(XPoint &ptStart) const;
|
||
void GetEndPoint(XPoint &ptEnd) const;
|
||
|
||
void MidPoint(XPoint &ptres) const;
|
||
XPoint MidPoint() const;
|
||
|
||
//求弦长
|
||
ads_real ChordLength() const;
|
||
// 扇形面积
|
||
ads_real Area() const;
|
||
//起点到终点的积分面积
|
||
ads_real PathArea() const;
|
||
|
||
XArc Offset(ads_real dist) const;
|
||
|
||
virtual void TransUCS(ads_matrix mat);
|
||
|
||
//$direction
|
||
ads_real IDirection(int pt) const;
|
||
ads_real ODirection(int pt) const;
|
||
|
||
virtual int Intersection(const XLine* pLine, ads_point ptRp1 = NULL, ads_point ptRp2 = NULL) const;
|
||
virtual int Intersection(const XArc* pArc, ads_point ptRp1 = NULL, ads_point ptRp2 = NULL) const;
|
||
virtual int Intersection(const XCircle* pCir, ads_point ptRp1 = NULL, ads_point ptRp2 = NULL) const;
|
||
|
||
ads_real * SelectNear(ads_point pt1, ads_point pt2) const;
|
||
int PtOnArc(const XPoint &pt) const;
|
||
};
|
||
|
||
inline XArc& XArc::operator = (const XSector &src)
|
||
{
|
||
m_dstartAngle = src.m_dstartAngle;
|
||
m_dendAngle = src.m_dendAngle;
|
||
return *this;
|
||
}
|
||
|
||
inline XArc& XArc::operator = (const XArc &src)
|
||
{
|
||
if (this != &src)
|
||
{
|
||
m_dstartAngle = src.m_dstartAngle;
|
||
m_dendAngle = src.m_dendAngle;
|
||
m_ptCenter = src.m_ptCenter;
|
||
m_dRadius = src.m_dRadius;
|
||
}
|
||
return *this;
|
||
}
|
||
|
||
inline int XArc::operator ! () const
|
||
{
|
||
return (XCircle::operator !() || GetLength() < _DIST_SNAP);
|
||
}
|
||
|
||
inline bool XArc::operator == (const XArc &src) const
|
||
{
|
||
return (XCircle::operator == (src) && XSector::operator == (src));
|
||
}
|
||
|
||
inline XArc XArc::Offset(ads_real dist) const
|
||
{
|
||
ads_real r = m_dRadius + dist;
|
||
if (r < _DIST_SNAP)
|
||
{
|
||
r = 0;
|
||
}
|
||
return XArc(m_ptCenter, r, m_dstartAngle, m_dendAngle);
|
||
}
|
||
|
||
inline ads_real XArc::GetLength() const
|
||
{
|
||
return Bulge() * m_dRadius;
|
||
}
|
||
|
||
inline ads_real XArc::ChordLength() const
|
||
{
|
||
return fabs(2.0 * m_dRadius * sin(Bulge() / 2.0));
|
||
}
|
||
|
||
inline void XArc::MidPoint(XPoint &ptres) const
|
||
{
|
||
ads_polar(m_ptCenter, MidAngle(), m_dRadius, ptres);
|
||
}
|
||
|
||
inline XPoint XArc::MidPoint() const
|
||
{
|
||
XPoint ptres;
|
||
ads_polar(m_ptCenter, MidAngle(), m_dRadius, ptres);
|
||
return ptres;
|
||
}
|
||
|
||
class XArc;
|
||
class XCircle;
|
||
class XGEAPI XLinearEnt : public XCurve
|
||
{
|
||
public:
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() 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;
|
||
|
||
// 0--错误;1-左边;2-右边;3-起始点;4-终止点;5-线内;6-起始侧延长线;7-终止侧延长线
|
||
virtual int HitTest2d(const XPoint &ptTest) const;
|
||
|
||
virtual XPoint MidPoint() 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);
|
||
|
||
protected:
|
||
XLinearEnt();
|
||
virtual ~XLinearEnt();
|
||
};
|
||
|
||
class XPoly;
|
||
class XGEAPI 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;
|
||
}
|
||
|
||
class XArc;
|
||
class XPoly2D;
|
||
class XGEAPI 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 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 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;
|
||
}
|
||
|
||
class XGEAPI XDirectionCurve : public XCurveSegment
|
||
{
|
||
public:
|
||
XDirectionCurve(int flg = LS_FINITE);
|
||
XDirectionCurve(const XArc &ar, int bMinus = 0);
|
||
XDirectionCurve(const XDirectionCurve &src);
|
||
XDirectionCurve(const XPoint &spt, const XPoint &ept, ads_real dAng = 0.0, int flg = LS_FINITE);
|
||
|
||
virtual ~XDirectionCurve();
|
||
|
||
virtual int IsMinusArc() const;
|
||
|
||
// 与曲线方向有关的成员
|
||
virtual int OnWhichSide(const XPoint &src) const;
|
||
virtual int OnWhichSide1(const XPoint &src) const;
|
||
|
||
// 从端点开始沿曲线走过给定距离的点向量
|
||
virtual int Polar(ads_real nDist, XPointDir2d &res, BOOL bFromStart = TRUE) const;
|
||
|
||
virtual void Reverse();
|
||
|
||
virtual void TransUCS(ads_matrix mat);
|
||
virtual void TransUCS(const resbuf *, const resbuf *);
|
||
|
||
virtual void AsPoly2D(XPoly2D &poly) const;
|
||
|
||
virtual void SetPoints(const XPoint &ptStart, const XPoint &ptEnd);
|
||
|
||
// 端点处朝曲线段内部的方向
|
||
virtual ads_real IDirection(int pt) const;
|
||
|
||
// 取得指向内部的方向支持Line,Arc,不支持Cir。 pt--0:start; 1--end
|
||
virtual ads_real PathArea(XPoint &tmpt) const;
|
||
|
||
virtual ads_real Direction(const XPoint &pt) const;
|
||
|
||
// 求到端点的沿曲线线位移, 在线内距离为正,否则为负, 和Polar配合使用
|
||
// pt如果不在线上的话则先投影
|
||
virtual ads_real PathDistance(const XPoint &pt, BOOL bFromStart = TRUE) const;
|
||
|
||
// 求通过pt点的法向
|
||
virtual ads_real OrthoDirection(const XPoint &pt) const;
|
||
|
||
// dist left<0 / right>0
|
||
virtual XCurveSegment GetCurve() const;
|
||
virtual XDirectionCurve Offset(ads_real dist, int flg) const;
|
||
|
||
virtual bool IsDirectionCurve();
|
||
|
||
XArc GetArc() const;
|
||
};
|
||
|
||
class XPoly3D;
|
||
class XGEAPI XPoly2D : public XPointList, public XCurve
|
||
{
|
||
public:
|
||
|
||
XPoly2D();
|
||
XPoly2D(const Entity& entPline);
|
||
XPoly2D(int nflg);
|
||
XPoly2D(const XPoly2D & src);
|
||
|
||
virtual ~XPoly2D();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
|
||
virtual double Area() const;
|
||
virtual void Reset();
|
||
virtual bool SetAcDbCurve(AcDbCurve* pCurve);
|
||
|
||
virtual AcDbCurve* AsAcDbCurve()const;
|
||
virtual AcDbRegion *AsRegion() const;
|
||
virtual void CopyFrom(const XEntity* pSrc);
|
||
virtual void AppendNode(const XPoint &pt, ads_real dBulge = 0.0);
|
||
|
||
int operator ! () const;
|
||
XPoly2D& operator = (const XPoly2D &src);
|
||
|
||
void SetFlag(int nFlag);
|
||
int GetFlag() const;
|
||
|
||
void AppendBugle(ads_real dBugle);
|
||
void RemoveBugle(int nIndex);
|
||
|
||
double GetBulge(int nIndex) const;
|
||
void SetBulge(int nIndex, double dBugle);
|
||
|
||
int SetBulges(DList<double>& ardbulges);
|
||
int GetBulges(DList<double>& ardbulges);
|
||
DList<double>& GetBulges();
|
||
|
||
|
||
ads_real Distance3d(int nIndex) const;
|
||
ads_real Distance3d() const;
|
||
ads_real Distance2d(int nIndex) const;
|
||
ads_real Distance2d() const;
|
||
|
||
ads_real PathArea() const;
|
||
|
||
double PathDistance2d(XPoint ptHit) const;
|
||
|
||
int Nth(int nIndex, XLine &xline, XArc &xarc) const;
|
||
int Nth(int nIndex, XCurveSegment & cvCurve) const;
|
||
int Nth(int nIndex, XDirectionCurve &curve) const;
|
||
|
||
//是否自交
|
||
BOOL IsSelfIntersect() const;
|
||
int IsValid(int nIndex) const;
|
||
|
||
int IsClosed() const;
|
||
bool SetClosed();
|
||
|
||
int HasArcSegment() const;
|
||
|
||
int TotalSegments() const;
|
||
|
||
int Polar2d(ads_real dis, XPoint &ptRes, ads_real *dDrt = NULL) const;
|
||
int Polar3d(ads_real dis, XPoint &ptRes, XVector3D & vt) const;
|
||
|
||
int Make(LPCTSTR szLay = NULL) const;
|
||
int MakeSegments(LPCTSTR szLay = NULL) const;
|
||
int MakeSegment(int nIndex, LPCTSTR szLay = NULL) const;
|
||
|
||
//取得封闭PLINE内的一点或外的一点
|
||
XPoint GetPoint(int nIOFlag, ads_real dist);
|
||
XPoint GetInsidePoint();
|
||
|
||
int AppendSegment(const XCurveSegment &cvCurve, int bMinus = 0, int bFinal = 0);
|
||
|
||
int Compress(bool bUnionCurve = true);
|
||
|
||
int Offset(ads_real nDist, XPoly2D &destPoly) const;
|
||
int QuickOffset(ads_real nDist, XPoly2D &destPoly) const;
|
||
|
||
int Reverse();
|
||
|
||
int MapToPolygon1(XPoly &pts, double dDeviation);
|
||
int MapToPolygon(XPoly &pts, int nCirDiv = 30);
|
||
|
||
resbuf *Fence(int nCirDiv = 30);
|
||
resbuf *Polygon(int nCirDiv = 30);
|
||
|
||
int AsOpenPoly1(XPoly &pts, double dDeviation) const;
|
||
int AsOpenPoly(XPoly &pts, int nCirDiv = 30) const;
|
||
|
||
//离散化
|
||
void Disperse1(XPoly2D &polydestPoly, double dDeviation) const;
|
||
void Disperse(XPoly2D &polydestPoly, int nCirDiv = 30) const;
|
||
|
||
int CreatePface(int cirDivSegs, const TCHAR *szLay = NULL);
|
||
|
||
int GetExtend(ads_point lowPt, ads_point upPt) const;
|
||
|
||
int HitTestOnCurve(const XPoint &ptTest, double dTol = _DIST_SNAP) const;
|
||
|
||
void RemoveNode(long nIndex);
|
||
|
||
void InsertNodeAt(int nIndex, const XPoint &pt, double dBulge = 0.0);
|
||
|
||
void SetPointListAt(int nIndex, const XPoint& pt);
|
||
|
||
XPoint* GetPointListAt(int nIndex);
|
||
const XPoint& GetPointListAt(int nIndex) const;
|
||
|
||
void RemovePointListAt(int nIndex);
|
||
void AppendPointListAt(XPoint* pPt);
|
||
|
||
void TransformBy(const AcGeMatrix3d &mat);
|
||
|
||
XPoly3D PlaneToWcs(const AcGeVector3d& normal)const;
|
||
|
||
bool IsRegionInclude(const XPoly2D& poly)const;
|
||
bool IsRegionOverlap(const XPoly2D& poly)const;
|
||
|
||
public:
|
||
|
||
int m_nFlag;
|
||
DList<double> m_ardbulges;
|
||
};
|
||
|
||
extern bool IsMeterfUnitDraw();
|
||
extern Acad::ErrorStatus ReadPoly2D(AcDbDwgFiler *pFiler, XPoly2D &poly);
|
||
extern Acad::ErrorStatus WritePoly2D(AcDbDwgFiler *pFiler, const XPoly2D &poly);
|
||
extern void Split(DList<XPoly2D>&lstLeft,DList<XPoly2D>&lstRight,XPoint ptRidge1,XPoint ptRidge2,const XPoly2D& polyOutline);
|
||
extern AcGeMatrix3d & AsAcGeMatrix3d(ads_matrix mat);
|
||
|
||
class XGEAPI XPoly3D : public XPoly2D
|
||
{
|
||
public:
|
||
|
||
XPoly3D(int nFlag = 0);
|
||
XPoly3D(const Entity & e);
|
||
XPoly3D(const XPoly2D& poly);
|
||
virtual ~XPoly3D();
|
||
|
||
virtual bool IsKindOf(TEntityId entType) const;
|
||
virtual TEntityId Type() const;
|
||
|
||
virtual AcDbCurve* AsAcDbCurve()const;
|
||
|
||
virtual bool SetAcDbCurve(AcDbCurve* pCurve);
|
||
|
||
bool IsPlanear()const;
|
||
|
||
AcGeVector3d GetNormal(bool bCheckConcave)const;
|
||
|
||
XPoly2D WcsToPlane()const;
|
||
|
||
XPoly2D WcsToPlane(const AcGeVector3d& vt)const;
|
||
};
|
||
|
||
class XIntDotPair {
|
||
public:
|
||
short nFrom;
|
||
short nTo;
|
||
public:
|
||
XIntDotPair() {}
|
||
XIntDotPair(short f, short t): nFrom(f), nTo(t) {}
|
||
XIntDotPair(const XIntDotPair &src) {
|
||
nFrom = src.nFrom;
|
||
nTo = src.nTo;
|
||
}
|
||
};
|
||
class XRoofEdge: public XLine {
|
||
public:
|
||
double m_nSlope;
|
||
};
|
||
|
||
class XRoofEdgeCompact {
|
||
public:
|
||
XPoint m_ptVertex;
|
||
double m_nSlope;
|
||
public:
|
||
XRoofEdgeCompact(const XPoint &pt, double nSlant): m_ptVertex(pt), m_nSlope(nSlant)
|
||
{}
|
||
XRoofEdgeCompact() {}
|
||
};
|
||
|
||
// 求标准周期内的整数
|
||
// nPeriod--周期 (>0)
|
||
// nIndex -- 给定的整数
|
||
// 返回: 0~nPeriod-1内的数值
|
||
inline int DePeriod(int nPeriod, int nIndex)
|
||
{
|
||
ASSERT(nPeriod>0);
|
||
while(nIndex>=nPeriod) {
|
||
nIndex -= nPeriod;
|
||
}
|
||
while(nIndex<0) {
|
||
nIndex += nPeriod;
|
||
}
|
||
return nIndex;
|
||
}
|
||
|
||
class XAecRoof {
|
||
public:
|
||
double m_nBottomElevation;
|
||
DList<XRoofEdgeCompact> m_lstEdges;
|
||
BOOL m_bBotVisible;
|
||
|
||
// Not Database Residential data member
|
||
DList<XPointList> m_lstSlopeFaces;
|
||
XPoly2D m_polyBoundry;
|
||
// 临时数据
|
||
DList<XLine> m_lstRidges;
|
||
public:
|
||
XAecRoof(BOOL bBotVis=FALSE) {m_bBotVisible=bBotVis;}
|
||
/*
|
||
XAecRoof(const XAecRoof &src) {
|
||
*this = src;
|
||
}
|
||
XAecRoof(const XPoly2D &poly, double nSlant);*/
|
||
int InitRoof(const XPoly2D &poly, double nSlant);
|
||
|
||
//XAecRoof & operator = (const XAecRoof &src);
|
||
|
||
int InitBottomPolyByEdge();
|
||
int Calculate();
|
||
int CalculateSlopeFace(int n, XPointList &slopeFace);
|
||
int DrawSlopeFaces();
|
||
double GetTotalSurfaceArea() const;
|
||
double GetBottomArea() const {
|
||
ASSERT(!!m_polyBoundry);
|
||
XPoly2D *p = (XPoly2D *)&m_polyBoundry;
|
||
return p->Area();
|
||
}
|
||
double GetSlopeArea(int n) const;
|
||
int GetEdge(int n, XRoofEdge &edge) const;
|
||
int GetPlane(int n, XPlane &slopePlan) const;
|
||
int GetRidge(int n, XLine &ln, int bQuickGet) const;
|
||
int GetTotalEdge() const { return m_lstEdges.Length(); }
|
||
|
||
int GetNext(int nThis, const XPlane &thisPlane,
|
||
int nLast, const XPlane &lastPlane, const XPoint &ptLast,
|
||
int *pNextIndex, XPlane &nextPlane, XPoint &ptNext);
|
||
|
||
int GetEdgeData(XPointList &lstVertices, DList<XIntDotPair> &lstEdgeData) const;
|
||
int GetSurfaceData(int *nVerticeNum, XPoint * &pVerticeList,
|
||
int *nFaceListLen, Adesk::Int32 * &pFaceList,
|
||
Adesk::UInt8 * &pEdgeVisArray) const;
|
||
};
|
||
|
||
typedef struct ShellDraw
|
||
{
|
||
Adesk::Int32 nFaceListLen;
|
||
Adesk::Int32 *pFaceList;
|
||
Adesk::Int32 nVerticeNum;
|
||
AcGePoint3d * pVerticeList;
|
||
AcGiEdgeData* pEdge;
|
||
Adesk::UInt16 nColorIndex;
|
||
AcDbObjectId idLayer;
|
||
}SHELLDRAW;
|
||
|
||
typedef struct MeshDraw
|
||
{
|
||
Adesk::Int32 nRow;
|
||
Adesk::Int32 nCol;
|
||
AcGePoint3d * pVerticeList;
|
||
AcGiEdgeData* pEdge;
|
||
Adesk::UInt16 nColorIndex;
|
||
AcDbObjectId idLayer;
|
||
}MESHDRAW;
|
||
|
||
class XDraw{
|
||
public:
|
||
XDraw(){m_pSubTraits = NULL;}//kColorByLayer
|
||
~XDraw()
|
||
{
|
||
for (int i = 0;i < m_arShells.length();i++)
|
||
{
|
||
ShellDraw& sDr = m_arShells.at(i);
|
||
if (sDr.pVerticeList != NULL)
|
||
delete []sDr.pVerticeList;
|
||
if (sDr.pFaceList != NULL)
|
||
delete []sDr.pFaceList;
|
||
|
||
if (sDr.pEdge != NULL)
|
||
delete sDr.pEdge;
|
||
}
|
||
if (m_pSubTraits != NULL)
|
||
delete m_pSubTraits;
|
||
}
|
||
|
||
Adesk::UInt16 GetColor() const
|
||
{
|
||
if (m_pSubTraits != NULL)
|
||
{
|
||
return m_pSubTraits->colorIndex();
|
||
}
|
||
return kColorByLayer;
|
||
}
|
||
|
||
void SetColor(Adesk::UInt16 nColor)
|
||
{
|
||
if (m_pSubTraits == NULL)
|
||
m_pSubTraits = new AcDbPoint;
|
||
m_pSubTraits->setColorIndex(nColor);
|
||
}
|
||
|
||
void SetColorLayer(Adesk::UInt16 nColor, const AcDbObjectId& id)
|
||
{
|
||
SetColor(nColor);
|
||
|
||
if (m_pSubTraits != NULL)
|
||
{
|
||
m_pSubTraits->setLayer(id);
|
||
}
|
||
}
|
||
|
||
void SetTransparency(bool bTrans)
|
||
{
|
||
|
||
}
|
||
|
||
AcDbObjectId GetColorLayer() const
|
||
{
|
||
if (m_pSubTraits != NULL)
|
||
{
|
||
return m_pSubTraits->layerId();
|
||
}
|
||
return AcDbObjectId::kNull;
|
||
}
|
||
|
||
bool DrawFace(const X3DFace& face)
|
||
{
|
||
m_arFaces.append(face);
|
||
return true;
|
||
}
|
||
|
||
bool DrawMesh(int nRow, int nCol, const AcGePoint3d * ptArray, AcGiEdgeData* pEdge = NULL);
|
||
|
||
void DrawPolyline(AcDbPolyline* pPline)
|
||
{
|
||
if (pPline != NULL)
|
||
{
|
||
m_arEntDraw.append(pPline->clone());
|
||
}
|
||
}
|
||
|
||
void DrawPoly2d(const XPoly2D& poly1)
|
||
{
|
||
AcDbCurve* pPl = poly1.AsAcDbCurve();
|
||
if (pPl != NULL)
|
||
{
|
||
m_arEntDraw.append(pPl);
|
||
}
|
||
}
|
||
|
||
bool DrawShell(const XPoly2D& polyOut1);
|
||
|
||
bool DrawShell(int nVerticeNum,
|
||
const AcGePoint3d *pVerticeList,
|
||
Adesk::Int32 nFaceListLen,
|
||
Adesk::Int32 *pFaceList,
|
||
AcGiEdgeData* pEdge = NULL);
|
||
|
||
bool DrawLine(const XLine& ln)
|
||
{
|
||
m_arLines.append(ln);
|
||
return true;
|
||
}
|
||
|
||
int GetDraw(AcDbVoidPtrArray& entSet);
|
||
|
||
protected:
|
||
|
||
AcArray<X3DFace> m_arFaces;
|
||
AcArray<ShellDraw> m_arShells;
|
||
AcArray<MeshDraw> m_arMeshs;
|
||
AcArray<XLine> m_arLines;
|
||
AcDbVoidPtrArray m_arEntDraw;
|
||
AcDbPoint* m_pSubTraits;
|
||
};
|
||
|
||
class TSlopeRoof {
|
||
public:
|
||
XPoly2D m_polyOutline; //轮廓
|
||
DList<double> m_slope; //倾角
|
||
|
||
//Aec7
|
||
double m_fMaxHeight;
|
||
public:
|
||
TSlopeRoof():m_polyOutline(1){}
|
||
TSlopeRoof(const TSlopeRoof &src);
|
||
TSlopeRoof & operator = (const TSlopeRoof &src);
|
||
|
||
int GetEdgeNum() const {
|
||
return m_slope.Length();
|
||
}
|
||
void Reset();
|
||
void AppendEdge(const XPoint &ptFrom, double nSlope);
|
||
void InitEqualSlope(const XPoly2D &poly, double nSlope);
|
||
double GetAngleToPrev(int idx) const;
|
||
XLine GetSlopeEdge(int idx) const;
|
||
BOOL OffsetIn(double *pDistArray, TSlopeRoof &result) const;
|
||
BOOL IsInOtherEdge(int idx) const;
|
||
void Compress();
|
||
|
||
BOOL GetGeometry(XDraw &dc, BOOL bBotVis) const;
|
||
BOOL GetGeometry1(XDraw &dc, BOOL bBotVis) const;
|
||
BOOL GetGeometry2d(XDraw &dc, BOOL bBotVis) const;
|
||
BOOL GetGeometry2d1(XDraw &dc, BOOL bBotVis) const;
|
||
|
||
double GetSlopeAngle(int idx) const;
|
||
void SetSlopeAngle(int idx, double nAngle);
|
||
void SetElevation(double h) {
|
||
m_polyOutline.SetElevation(h);
|
||
}
|
||
|
||
double GetElevation() const {
|
||
ASSERT(!!m_polyOutline);
|
||
return m_polyOutline[0].z;
|
||
}
|
||
// 底面积
|
||
double GetBottomArea() const {
|
||
return m_polyOutline.Area();
|
||
}
|
||
// 表面积
|
||
double GetSurfArea() const;
|
||
|
||
const XPoly2D & GetOutlinePoly() const {
|
||
return m_polyOutline;
|
||
}
|
||
|
||
void SetPolyPath(const XPoly2D &polyPath);
|
||
void GetPolyPath(XPoly2D &polyPath) const;
|
||
|
||
void SetPathPoly(const XPoly2D &polyPath,const AcGeVector3d&normal);
|
||
void GetPathPoly(XPoly2D &polyPath,AcGeVector3d&normal) const;
|
||
|
||
// 某一边消失时的HMin
|
||
double GetHMin() const;
|
||
|
||
double C(int n1) const {
|
||
int nEdgeNum=GetEdgeNum();
|
||
int n=DePeriod(nEdgeNum, n1);
|
||
const XPoly2D &poly=m_polyOutline;
|
||
return (poly[n].y*poly[DePeriod(nEdgeNum, n+1)].x - poly[n].x*poly[DePeriod(nEdgeNum, n+1)].y);
|
||
}
|
||
double A(int n1) const {
|
||
int nEdgeNum=GetEdgeNum();
|
||
int n=DePeriod(nEdgeNum, n1);
|
||
const XPoly2D &poly=m_polyOutline;
|
||
return (poly[DePeriod(nEdgeNum, n+1)].y - poly[n].y);
|
||
}
|
||
double B(int n1) const {
|
||
int nEdgeNum=GetEdgeNum();
|
||
int n=DePeriod(nEdgeNum, n1);
|
||
const XPoly2D &poly=m_polyOutline;
|
||
return (poly[n].x - poly[DePeriod(nEdgeNum, n+1)].x);
|
||
}
|
||
double E(int n) const { //必须不为0
|
||
double val=(A(n-1)*B(n) - A(n)*B(n-1));
|
||
ASSERT(fabs(val)>1.0E-6);
|
||
return val;
|
||
}
|
||
|
||
double a(int n1) const {
|
||
int nEdgeNum=GetEdgeNum();
|
||
int n=DePeriod(nEdgeNum, n1);
|
||
// return GetSlopeEdge(n).Length();
|
||
return GetSlopeEdge(n).GetLength();
|
||
}
|
||
double Ctan(int n1) const {
|
||
int nEdgeNum=GetEdgeNum();
|
||
int n=DePeriod(nEdgeNum, n1);
|
||
double nAng=GetSlopeAngle(n);
|
||
ASSERT(nAng>0);
|
||
return (fabs(PI/2-nAng)<1.0E-5? 0.0 : 1.0/tan(nAng));
|
||
}
|
||
double r(int n) const {
|
||
return (1.0/E(n)*(B(n-1)*a(n)*Ctan(n) - B(n)*a(n-1)*Ctan(n-1)));
|
||
}
|
||
double s(int n) const {
|
||
return (1.0/E(n)*(B(n-1)*C(n)-B(n)*C(n-1)));
|
||
}
|
||
double u(int n) const {
|
||
return (1.0/E(n)*(A(n)*a(n-1)*Ctan(n-1) - A(n-1)*a(n)*Ctan(n)));
|
||
}
|
||
double v(int n) const {
|
||
return (1.0/E(n)*(A(n)*C(n-1) - A(n-1)*C(n)));
|
||
}
|
||
|
||
double GetHMin(int i, int n) const;
|
||
double GetHMin(int i, int *n) const;
|
||
double GetHMin(int *i, int *n) const;
|
||
BOOL SplitRoof(int iVert, int nEdge, TSlopeRoof &roof1, TSlopeRoof &roof2) const;
|
||
|
||
static bool HitGetPlane(AcGePoint3d& ptHit,AcDbVoidPtrArray& entSet,AcGePlane& plane);
|
||
};
|
||
|
||
class XDormerPar {
|
||
public://老虎窗类型:三角坡、双坡、三坡、梯形坡、平顶窗
|
||
enum XDormerType {SLOPE_TRIANGLE=0,SLOPE_TWO=1,
|
||
SLOPE_THREE=2,SLOPE_TRAPEZIA=3,SLOPE_FLAT=4,};
|
||
public:
|
||
XDormerPar();
|
||
~XDormerPar();
|
||
public:
|
||
XDormerType m_dormerType;//老虎窗类型
|
||
double m_dWallHeight,m_dWallWidth,m_dWallThickness;//墙
|
||
double m_dWindowHeight,m_dWindowWidth;//窗
|
||
double m_dSlopeGrade,m_dSlopeHeight,m_dSlopeThickness;//坡
|
||
double m_dExtendEaves,m_dExtendHill;//伸出长度
|
||
|
||
//图层,外部必须已经建立!!
|
||
AcDbObjectId m_id3DRoof; //顶
|
||
AcDbObjectId m_id3DFloor; //底
|
||
AcDbObjectId m_id3DWall; //墙
|
||
AcDbObjectId m_id3DEaves; //檐
|
||
AcDbObjectId m_id3DGlass; //玻璃
|
||
AcDbObjectId m_id3DWindow; //窗
|
||
|
||
public:
|
||
XDormerPar & operator = (const XDormerPar &src) {
|
||
m_dormerType=src.m_dormerType;
|
||
m_dWallHeight=src.m_dWallHeight;
|
||
m_dWallWidth=src.m_dWallWidth;
|
||
m_dWallThickness=src.m_dWallThickness;
|
||
m_dSlopeGrade=src.m_dSlopeGrade;
|
||
m_dSlopeHeight=src.m_dSlopeHeight;
|
||
m_dSlopeThickness=src.m_dSlopeThickness;
|
||
m_dExtendEaves=src.m_dExtendEaves;
|
||
m_dExtendHill=src.m_dExtendHill;
|
||
m_dWindowHeight=src.m_dWindowHeight;
|
||
m_dWindowWidth=src.m_dWindowWidth;
|
||
m_id3DRoof=src.m_id3DRoof;
|
||
m_id3DFloor=src.m_id3DFloor;
|
||
m_id3DEaves=src.m_id3DEaves;
|
||
m_id3DWall=src.m_id3DWall;
|
||
m_id3DGlass=src.m_id3DGlass;
|
||
m_id3DWindow=src.m_id3DWindow;
|
||
return *this;
|
||
}
|
||
BOOL IsValid() const;
|
||
void SetDormerType(XDormerType dormerType);//老虎窗类型
|
||
void SetWallHeight(double dHeight);//墙
|
||
void SetWallWidth(double dWidth);
|
||
void SetWallThickness(double dThickness);
|
||
void SetWindowHeight(double dHeight);//窗
|
||
void SetWindowWidth(double dWidth);
|
||
void SetSlopeGrade(double dGrade);//坡
|
||
void SetSlopeHeight(double dHeight);
|
||
void SetSlopeThickness(double dThickness);
|
||
void SetExtendEaves(double dEaves);//伸出长度
|
||
void SetExtendHill(double dHill);
|
||
XDormerType GetDormerType() const;
|
||
double GetWallHeight() const;
|
||
double GetWallWidth() const;
|
||
double GetWallThickness() const;
|
||
double GetWindowHeight() const;
|
||
double GetWindowWidth() const;
|
||
double GetSlopeGrade() const;
|
||
double GetSlopeHeight() const;
|
||
double GetSlopeThickness() const;
|
||
double GetExtendEaves() const;
|
||
double GetExtendHill() const;
|
||
|
||
//图层
|
||
void SetRoof(AcDbObjectId idLayer);
|
||
void SetFloor(AcDbObjectId idLayer);
|
||
void SetWall(AcDbObjectId idLayer);
|
||
void SetEaves(AcDbObjectId idLayer);
|
||
void SetGlass(AcDbObjectId idLayer);
|
||
void SetWindow(AcDbObjectId idLayer);
|
||
void SetRoof(const TCHAR *sName);
|
||
void SetFloor(const TCHAR *sName);
|
||
void SetWall(const TCHAR *sName);
|
||
void SetEaves(const TCHAR *sName);
|
||
void SetGlass(const TCHAR *sName);
|
||
void SetWindow(const TCHAR *sName);
|
||
|
||
const TCHAR* GetRoofName() const;
|
||
const TCHAR* GetFloorName() const;
|
||
const TCHAR* GetWallName() const;
|
||
const TCHAR* GetEavesName() const;
|
||
const TCHAR* GetGlassName() const;
|
||
const TCHAR* GetWindowName() const;
|
||
|
||
AcDbObjectId GetRoofId() const;
|
||
AcDbObjectId GetFloorId() const;
|
||
AcDbObjectId GetWallId() const;
|
||
AcDbObjectId GetEavesId() const;
|
||
AcDbObjectId GetGlassId() const;
|
||
AcDbObjectId GetWindowId() const;
|
||
};
|
||
|
||
class XCurveMesh
|
||
{
|
||
public:
|
||
XCurveMesh(){}
|
||
~XCurveMesh(){}
|
||
|
||
protected:
|
||
XPoly2D m_polyBase;
|
||
XPoly2D m_polyShape;
|
||
XVector3D m_vtNormal;
|
||
XPoint m_ptShapeBase;
|
||
Adesk::UInt8 m_nCMFlag;
|
||
|
||
public:
|
||
void SetNormal(const XVector3D &vt);
|
||
void SetShapePoly(const XPoly2D &newShape);
|
||
void SetBasePoly(const XPoly2D &newBase);
|
||
void SetShapeBase(const XPoint &ptBase);
|
||
void ShowShape(BOOL bTrue);
|
||
void SetHas2D(BOOL bTrue);
|
||
void SetHas3D(BOOL bTrue);
|
||
void SetHasDivide2D(BOOL bTrue);
|
||
|
||
Acad::ErrorStatus SetPathPoly(const XPoly2D &polyPath,const AcGeVector3d &normal)
|
||
{
|
||
SetBasePoly(polyPath);
|
||
SetNormal(normal);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus GetPathPoly(XPoly2D &polyPath,AcGeVector3d &normal) const
|
||
{
|
||
polyPath=GetBasePoly();
|
||
normal=m_vtNormal.AsAcGeVector3d();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
XVector3D GetNormal() const;
|
||
const XPoly2D & GetShapePoly() const;
|
||
const XPoly2D & GetBasePoly() const;
|
||
XPoint GetShapeBase() const;
|
||
BOOL IsShapeShow() const;
|
||
BOOL Has2D() const;
|
||
BOOL Has3D() const;
|
||
BOOL HasDivide2D()const;
|
||
BOOL Get2DRegion(XPoly2D &poly2d) const;
|
||
|
||
Acad::ErrorStatus Draw3d(XDraw &dc) const;
|
||
Acad::ErrorStatus Draw2d(XDraw &dc) const;
|
||
};
|
||
|
||
class XDormerWindow
|
||
{
|
||
public:
|
||
XDormerWindow();
|
||
~XDormerWindow();
|
||
|
||
protected:
|
||
XDormerPar m_dormerPar; //老虎窗参数
|
||
XVector3D m_vtDormerDir; //老虎窗方向
|
||
XPoint m_ptDormerBase; //老虎窗基点
|
||
Adesk::Boolean m_bShowWindow; //显示窗户否
|
||
|
||
public:
|
||
//老虎窗基点
|
||
void SetDormerBase(XPoint ptBase);
|
||
XPoint GetDormerBase() const;
|
||
|
||
//老虎窗方向
|
||
void SetDormerDir(XVector3D vtDormerDir);
|
||
XVector3D GetDormerDir() const;
|
||
|
||
//老虎窗参数
|
||
void SetDormerPar(const XDormerPar& dormerPar);
|
||
const XDormerPar & GetDormerPar() const;
|
||
|
||
//显示窗户
|
||
void ShowWindow(BOOL bShow=TRUE);
|
||
BOOL IsShowWindow() const;
|
||
|
||
//老虎窗类型
|
||
const TCHAR* GetDormerType() const;
|
||
|
||
//老虎窗参数的放大和缩小
|
||
Acad::ErrorStatus DormerParTransformBy(const AcGeMatrix3d& xform);
|
||
|
||
public:
|
||
|
||
BOOL IsValid() const;
|
||
|
||
void CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag);
|
||
|
||
const TCHAR *GetDefaultLayer() const;
|
||
|
||
Acad::ErrorStatus getOsnapPoints(
|
||
AcDb::OsnapMode osnapMode,
|
||
INT_PTR gsSelectionMark,
|
||
const AcGePoint3d& ptPick,
|
||
const AcGePoint3d& lastPoint,
|
||
const AcGeMatrix3d& viewXform,
|
||
AcGePoint3dArray& snapPoints,
|
||
AcDbIntArray& geomIds) const;
|
||
|
||
Acad::ErrorStatus transformBy(const AcGeMatrix3d& xform);
|
||
|
||
Acad::ErrorStatus Draw3d(XDraw &dc) const;
|
||
|
||
Acad::ErrorStatus Draw2d(XDraw &dc) const;
|
||
|
||
Acad::ErrorStatus getGripPoints(AcGePoint3dArray& gripPoints,
|
||
AcDbIntArray& osnapModes,
|
||
AcDbIntArray& geomIds) const;
|
||
Acad::ErrorStatus moveGripPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset);
|
||
|
||
Acad::ErrorStatus dwgInFields (AcDbDwgFiler*);
|
||
Acad::ErrorStatus dwgOutFields(AcDbDwgFiler*) const;
|
||
|
||
private:
|
||
BOOL GetTriangleSlopeVertexs(const double dRoofGrade,
|
||
DList<XPoint>& lstVertex) const;
|
||
BOOL GetTwoSlopeVertexs(const double dRoofGrade,
|
||
DList<XPoint>& lstVertex) const;
|
||
BOOL GetThreeSlopeVertexs(const double dRoofGrade,
|
||
DList<XPoint>& lstVertex) const;
|
||
BOOL GetTrapeziaSlopeVertexs(const double dRoofGrade,
|
||
DList<XPoint>& lstVertex) const;
|
||
BOOL GetFlatWindowVertexs(const double dRoofGrade,
|
||
DList<XPoint>& lstVertex) const;
|
||
|
||
Acad::ErrorStatus DrawTriangleSlope3D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawTwoSlope3D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawThreeSlope3D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawTrapeziaSlope3D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawFlatWindow3D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
|
||
Acad::ErrorStatus DrawTriangleSlope2D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawTwoSlope2D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawThreeSlope2D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawTrapeziaSlope2D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
Acad::ErrorStatus DrawFlatWindow2D(XDraw &dc,
|
||
const AcGeMatrix3d &mat,const double dRoofGrade) const;
|
||
|
||
void DrawWindow(const XPoint& pt1,const XPoint& pt2,
|
||
const XPoint& pt3,XDraw &dc) const;
|
||
void DrawWindow(const XPoint& pt1,const XPoint& pt2,
|
||
const XPoint& pt3,const XPoint& pt4,
|
||
XDraw &dc) const;
|
||
};
|
||
|
||
|
||
//global funcs--------------------------------------------------------------------------------------------------------------------------------------------------
|
||
//裁剪
|
||
XGEAPI int PolyClip(const DList<XCurveSegment> &ss, XPoly2D &poly,DList<XCurveSegment> &ss1, DList<XCurveSegment> &ss2);
|
||
XGEAPI int PolyClip(const DList<XCurveSegment> &ss, const XPoly2D &poly1,DList<XCurveSegment> &ss1, DList<XCurveSegment> &ss2, DList<XCurveSegment> &ssOnEdge);
|
||
XGEAPI int PolyClip(PickSet &ss, XPoly2D &poly, PickSet &ss1, PickSet &ss2);
|
||
XGEAPI int PolyClip(PickSet &ss, XPoly2D &poly, PickSet &ss1, PickSet &ss2, PickSet &ss3);
|
||
|
||
//边界布尔运算
|
||
XGEAPI int Union(const XPoly2D &poly1, const XPoly2D &poly2, DList<XPoly2D> &lstResult);
|
||
XGEAPI int Subtract(const XPoly2D &poly1, const XPoly2D &poly2, DList<XPoly2D> &lstResult);
|
||
XGEAPI int Intersect(const XPoly2D &poly1, const XPoly2D &poly2, DList<XPoly2D> &lstDest);
|
||
|
||
XGEAPI int Union(const DList<XPoly2D> &lstSourcePolies, const DList<XPoly2D> &lstClipPolies, DList<XPoly2D> &lstResultPolies);
|
||
XGEAPI int Subtract(const DList<XPoly2D> &lstSourcePolies, const DList<XPoly2D> &lstClipPolies, DList<XPoly2D> &lstResultPolies);
|
||
XGEAPI int Intersect(const DList<XPoly2D> &lstSourcePolies, const DList<XPoly2D> &lstClipPolies, DList<XPoly2D> &lstResultPolies);
|
||
|
||
//三角化
|
||
//自动搜索最外边界
|
||
XGEAPI BOOL Triangulate(const DList<XPoly2D> &lstHole,DList<XTriangle> &lstRes);
|
||
//自动搜索最外边界
|
||
XGEAPI BOOL Triangulate(const DList<XPolygonEx> &lstHole,DList<XTriangle> &lstRes);
|
||
//给定最外边界
|
||
XGEAPI BOOL Triangulate(const XPoly2D &out,const DList<XPoly2D> &lstHole,DList<XTriangle> &lstRes);
|
||
//给定最外边界
|
||
XGEAPI BOOL Triangulate(const XPolygonEx &out,const DList<XPoly2D> &lstHole,DList<XTriangle> &lstRes);
|
||
//给定最外边界
|
||
XGEAPI BOOL Triangulate(const XPolygonEx &out,const DList<XPolygonEx> &lstHole,DList<XTriangle> &lstRes);
|
||
}
|
||
using namespace XGE;
|
||
#endif |