242 lines
7.4 KiB
C++
242 lines
7.4 KiB
C++
#ifndef _KTCADUtilityEx_H__
|
|
#define _KTCADUtilityEx_H__
|
|
|
|
#if _MSC_VER > 1000
|
|
#pragma once
|
|
#endif // _MSC_VER > 1000
|
|
|
|
#define XD_INT 1070
|
|
#define XD_REAL 1040
|
|
#define XD_POINT1 1010
|
|
#define XD_POINT2 1011
|
|
#define XD_STR 1000
|
|
#define XD_HANDLE 1005
|
|
#define XD_APPNAME 1001
|
|
|
|
#ifdef EARTHWORM_EXPORT
|
|
#define DLLIMPEXP __declspec(dllexport)
|
|
#else
|
|
#define DLLIMPEXP __declspec(dllimport)
|
|
#endif
|
|
|
|
class DxfList
|
|
{
|
|
public:
|
|
DxfList(AcDbObjectId id);
|
|
DxfList(ads_name sName);
|
|
~DxfList();
|
|
bool isNull();
|
|
const resbuf* getDxfField(AcDb::DxfCode nCode);
|
|
const resbuf* NextDxfField(AcDb::DxfCode nCode);
|
|
protected:
|
|
private:
|
|
resbuf* m_pBuf;
|
|
resbuf* m_pCur;
|
|
};
|
|
|
|
template <typename T> class CObjSmartPtr
|
|
{
|
|
public:
|
|
CObjSmartPtr(AcDbObjectId idObj, AcDb::OpenMode eMode, bool bOpenErase)
|
|
: m_pObjPtr(NULL)
|
|
{
|
|
Acad::ErrorStatus es;
|
|
AcDbObject* pObj = NULL;
|
|
if (Acad::eOk == (es = acdbOpenAcDbObject(pObj, idObj, eMode, bOpenErase)))
|
|
{
|
|
m_pObjPtr = T::cast(pObj);
|
|
if (m_pObjPtr == NULL)
|
|
pObj->close();
|
|
}
|
|
}
|
|
|
|
CObjSmartPtr(ads_name ent, AcDb::OpenMode eMode, bool bOpenErase)
|
|
: m_pObjPtr(NULL)
|
|
{
|
|
Acad::ErrorStatus es;
|
|
AcDbObjectId idObj;
|
|
if (acdbGetObjectId(idObj, ent) == Acad::eOk)
|
|
{
|
|
AcDbObject *pObj = NULL;
|
|
if (Acad::eOk == (es = acdbOpenAcDbObject(pObj, idObj, eMode, bOpenErase)))
|
|
{
|
|
m_pObjPtr = T::cast(pObj);
|
|
if (m_pObjPtr == NULL)
|
|
pObj->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
~CObjSmartPtr()
|
|
{
|
|
if (m_pObjPtr != NULL)
|
|
{
|
|
m_pObjPtr->close();
|
|
m_pObjPtr = NULL;
|
|
}
|
|
}
|
|
|
|
operator T*()
|
|
{
|
|
ASSERT(m_pObjPtr != NULL);
|
|
return m_pObjPtr;
|
|
}
|
|
|
|
T* operator&()
|
|
{
|
|
return m_pObjPtr;
|
|
}
|
|
|
|
T* operator->()
|
|
{
|
|
ASSERT(m_pObjPtr != NULL);
|
|
return m_pObjPtr;
|
|
}
|
|
|
|
bool operator==(int iNull)
|
|
{
|
|
ASSERT(iNull == NULL);
|
|
return (m_pObjPtr == NULL);
|
|
}
|
|
|
|
bool operator!=(int iNull)
|
|
{
|
|
return operator==(iNull);
|
|
}
|
|
|
|
friend bool operator==(int iNull, const CObjSmartPtr& Ptr)
|
|
{
|
|
return (Ptr == iNull);
|
|
}
|
|
|
|
friend bool operator!=(int iNull, const CObjSmartPtr& Ptr)
|
|
{
|
|
return (Ptr != iNull);
|
|
}
|
|
|
|
protected:
|
|
T* m_pObjPtr;
|
|
};
|
|
|
|
#define OPENOBJ_BEGIN(ObjId, eOpenMode, ObjClass, pPtr) \
|
|
{ \
|
|
CObjSmartPtr<ObjClass> pPtr##Obj(ObjId, eOpenMode, FALSE); \
|
|
ObjClass* pPtr = &pPtr##Obj; \
|
|
|
|
#define OPENOBJ_END() \
|
|
} \
|
|
|
|
class DLLIMPEXP KTCADUtilityEx
|
|
{
|
|
public:
|
|
//PtOnCur
|
|
typedef struct PtOnCrItem
|
|
{
|
|
AcGePoint3d m_ptGeOn;
|
|
AcDbCurve * m_pCurve;
|
|
AcDbObjectId m_ID;
|
|
} PTONCRITEM,* PPTONCRITEM;
|
|
public:
|
|
KTCADUtilityEx();
|
|
virtual ~KTCADUtilityEx();
|
|
|
|
|
|
// 通过一墙线,在给定点附近取得另一墙线和轴线, 1有另一墙线,2墙线轴线都有
|
|
static int GetWallParamByWallLine(AcDbObjectId& idCur, const AcGePoint3d& ptTest,
|
|
AcDbObjectId& idOth,AcDbObjectId& idAxis);
|
|
|
|
static int DoubleCompare(const double& dArg1, const double& dArg2);
|
|
|
|
// 根据T1类型数据,对CSortPair数组快速排序,T2类型数据是与T1关联的对应值
|
|
#define QuickSort(pData, iLen) QuickSortEx(pData, iLen, (pData)[0].Compare)
|
|
#define QuickSortEx(pData, iLen, pfnCompare) qsort((pData), (iLen), sizeof((pData)[0]), (int (__cdecl *)(const void *,const void *))(pfnCompare))
|
|
|
|
static void SortPointByDirect(AcGePoint3dArray& arpt, const AcGeVector3d& vecDir);
|
|
|
|
template <typename T1, typename T2, int (*pfnCompare)(const T1 &, const T1 &)>
|
|
class CSortPair
|
|
{
|
|
public:
|
|
CSortPair() {ZeroMemory(this, sizeof(CSortPair));}
|
|
CSortPair(const CSortPair& data) {CopyMemory(this, &data, sizeof(CSortPair));}
|
|
CSortPair& operator=(const CSortPair& data) {CopyMemory(this, &data, sizeof(CSortPair)); return (*this);}
|
|
T1 compare;
|
|
T2 value;
|
|
|
|
static int Compare(const CSortPair* pPair1, const CSortPair* pPair2)
|
|
{
|
|
if (pfnCompare == NULL)
|
|
{
|
|
if (pPair1->compare < pPair2->compare)
|
|
return -1;
|
|
if (pPair1->compare > pPair2->compare)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
typedef int (*lpfnCompare)(const T1& arg1, const T1& arg2);
|
|
return ((lpfnCompare)pfnCompare)(pPair1->compare, pPair2->compare);
|
|
}
|
|
}
|
|
};
|
|
|
|
// 返回边界类型1-垂直相交,2-平行相交,3-成夹角
|
|
static int FindMaxBoundAxis(ads_name& entTest, ads_name& ent1, ads_name& ent2, ads_point& pt1, ads_point& pt2);
|
|
|
|
static int GetAxisRelationShip(ads_name ent1, ads_name ent2);
|
|
|
|
static int SortParallelAxisLine(AcDbObjectIdArray& ssResult);
|
|
|
|
static BOOL GetAttribute(AcDbBlockReference* pRef, LPCTSTR pszTag, CString& sValue);
|
|
|
|
// 轴标前缀或后缀增加或减小
|
|
static CString GetNewAxisLabel(CString sLabel, BOOL bPostfix, int iStep = 1);
|
|
|
|
static AcDbObjectId InsertBlock(LPCTSTR pszFileName, LPCTSTR pszSrcName = NULL, LPCTSTR pszDestName = NULL, AcDbDatabase* pDb = NULL, BOOL bReplace = FALSE);
|
|
|
|
// 取得平行线标注初始参数
|
|
static BOOL GetParallelAxisLineInitParam(const AcGePoint3d& ptPick, AcDbObjectId& entBL, AcDbObjectId& entTR, BOOL bCrossSelect,
|
|
AcGePoint3d& ptCurStart, AcGePoint3d& ptCurEnd, AcGePoint3d& ptOthStart, AcGePoint3d& ptOthEnd,
|
|
AcGeVector3d& vecCur, AcGeVector3d& vecOth);
|
|
|
|
static double GetParallelAxisLineInterval(AcDbObjectId& ent1, AcDbObjectId& ent2);
|
|
|
|
static BOOL IsLinesIntersect(const AcGePoint3d& ptBase, const AcGeVector3d& vecDir, AcDbObjectId& ent);
|
|
|
|
static AcGePoint3d GetCenterPoint(const AcGePoint3d& pt1, const AcGePoint3d& pt2);
|
|
|
|
static AcDbObjectId AppendAttribute(AcDbBlockReference* pRef, LPCTSTR pszTag, LPCTSTR pszValue);
|
|
|
|
static AcDbObjectId CreateGroup(const AcDbObjectIdArray& aridObj, LPCTSTR pszGroupName, bool bSelectable = true, BOOL* bOver = NULL, AcDbDatabase* pDb = NULL);
|
|
|
|
// 判断点是否在边界线内,边界点必须连续
|
|
static BOOL IsPointInBoundary(const AcGePoint3d& ptTest, const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& pt3, const AcGePoint3d& pt4);
|
|
static BOOL IsPointInBoundary(const AcGePoint3d& ptTest, const AcGePoint3d& pt1, const AcGePoint3d& pt2);
|
|
|
|
static BOOL BreakCurve(AcDbObjectId& ent, const AcGePoint3d& pt1, const AcGePoint3d& pt2, AcDbObjectIdArray& arid, const AcGePoint3d* ptHit);
|
|
|
|
static int WallParamAngleSortCompare(double* arg1, double* arg2);
|
|
|
|
static BOOL EraseColumn(ads_name ent);
|
|
|
|
static AcDbCurve* ConvertBoundCurve(const AcDbVoidPtrArray& arpCurve, AcDbVoidPtrArray& arpResult);
|
|
|
|
static BOOL Sort2ArcPoint(const AcGePoint3d& ptOrg, const AcGePoint3d& pt1S, const AcGePoint3d& pt1E, const AcGePoint3d& pt1,
|
|
const AcGePoint3d& pt2S, const AcGePoint3d& pt2E, const AcGePoint3d& pt2, AcGePoint3dArray& arpt,
|
|
BOOL bJointAtMinAngle);
|
|
static BOOL IsConnectToOther(const AcGePoint3d& pt, double dExt,AcDbObjectId idEntT, const struct resbuf* pRb);
|
|
static BOOL IsCurveAreParallel(AcDbObjectId& ent1, AcDbObjectId& ent2);
|
|
static AcDbObjectId Connect2CurveNearPt(const AcGePoint3d& pt, AcDbObjectId ent1, AcDbObjectId ent2);
|
|
static AcDbCurve* Connect2CurveNearPt(const AcGePoint3d& pt, AcDbCurve* pCurve1, AcDbCurve* pCurve2);
|
|
static BOOL IsPointAtSameSide(const AcGePlane& plane, const AcGePoint3d& pt1, const AcGePoint3d& pt2);
|
|
static BOOL GetIntsectCurves(AcDbBlockReference* pRef, AcDbObjectIdArray& arRes);
|
|
static double GetBulge(const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd, double dRadius, BOOL bClockWise);
|
|
static double GetBulge(const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd, const AcGePoint3d& ptSample);
|
|
static AcDbArc* FormatArc(const AcGePoint3d& ptGe1,const AcGePoint3d& ptGe2,const AcGePoint3d& ptGe3);
|
|
static AcDbArc* FormatArc(const AcGeVector3d& vtMaj,const AcGeVector3d& vtMin,const AcGePoint3d& ptMid,AcGePoint3d& ptFr,double dSweepAngle,double dR,double dRatio, BOOL bdRisL = FALSE);
|
|
static int IsPointInPoly(int nvert, float *vertx, float *verty, float testx, float testy);
|
|
};
|
|
|
|
#endif // !defined _KTCADUtilityEx_H__
|