Files
envi-code/SourceCode/Code2026/inc/dimfactory.h
T
2026-09-28 15:28:50 +08:00

403 lines
11 KiB
C++

#pragma once
#define func_process(sfunc, ...)\
AcDbEntity *pEnt(NULL);\
func_##sfunc proc(NULL);\
HINSTANCE hmod(NULL);\
if (loadMkDimDll<func_##sfunc>(proc, #sfunc, hmod))\
{\
pEnt = proc(##__VA_ARGS__);\
::FreeLibrary(hmod);\
}\
return pEnt
#define func_process_bool(sfunc, ...)\
bool bRel(false);\
func_##sfunc proc(NULL);\
HINSTANCE hmod(NULL);\
if (loadMkDimDll<func_##sfunc>(proc, #sfunc, hmod))\
{\
bRel = proc(##__VA_ARGS__);\
::FreeLibrary(hmod);\
}\
return bRel
#define func_process_double(sfunc, ...)\
double d(.0);\
func_##sfunc proc(NULL);\
HINSTANCE hmod(NULL);\
if (loadMkDimDll<func_##sfunc>(proc, #sfunc, hmod))\
{\
d = proc(##__VA_ARGS__);\
::FreeLibrary(hmod);\
}\
return d
#define make_xdata_get_func(func_name, type)\
bool func_name(AcDbEntity *pEnt, LPCTSTR pszKey, type &v )\
{\
typedef bool (_cdecl *func_##func_name)(AcDbEntity*, LPCTSTR, type&);\
func_process_bool(func_name, pEnt, pszKey, v);\
}
#define make_xdata_set_func(func_name, type)\
bool func_name(AcDbEntity *pEnt, LPCTSTR pszKey, const type &v )\
{\
typedef bool (_cdecl *func_##func_name)(AcDbEntity*, LPCTSTR, const type&);\
func_process_bool(func_name, pEnt, pszKey, v);\
}
class DimFactory
{
public:
DimFactory(LPCTSTR psz): m_path(psz){}
private:
template <class T>
bool loadMkDimDll(T &proc, LPCSTR func, HINSTANCE &hmod)
{
if (!func) return false;
hmod = ::LoadLibrary(m_path);
if (!hmod) return false;
proc = (T)::GetProcAddress(hmod, func);
if (!proc)
{
::FreeLibrary(hmod);
return false;
}
return true;
}
CString m_path;
public:
enum ETYPE
{
// 角度
eAngle = 0,
// 弦长
eChord,
// 弧长
eArc,
// 绘图单位 mm-M
emmM,
// 绘图单位 M-M
eMM,
// 箭头样式 圆点
eNoneArrow,
// 箭头样式 圆点
eCircle,
// 箭头样式 箭头
eArrow,
// 箭头样式 半箭头
eHalfArrow,
// 箭头样式 十字
eCross,
// 坐标取值 世界坐标
eWCS,
// 坐标取值 用户坐标
eUCS,
// 坐标类型 测量坐标
eXY,
// 坐标类型 施工坐标
eAB,
// 图名标注 国标样式
eGB,
// 图名标注 传统样式
eOld,
// 引出标注 始端对齐
eBeginAlign,
// 引出标注 末端对齐
eEndAlign,
// 引出标注 居中对齐
eMidAlign,
// 箭头标注 齐线端
eSideLineAlign,
// 箭头标注 齐线中
eMidLineAlign,
// 箭头标注 在线端
eEndLineAlign,
// 剖切样式 正交剖切
eZJPQ,
// 剖切样式 断面剖切
eDMPQ,
// 剖切 标注位置 两端
e2Pos,
// 剖切 标注位置 末端
eEndPos,
// 剖切 标注位置 始端
eStartPos,
// 剖切 标注方向 沿剖切位置线
ePQWZX,
// 剖切 标注方向 沿剖视方向线
ePSFXX,
};
public:
AcDbEntity* makeRadius(
const AcGePoint3d &ptCnt
, const AcGePoint3d &ptEnd)
{
typedef AcDbEntity* (_cdecl *func_makeRadius)(const AcGePoint3d &, const AcGePoint3d &);
func_process(makeRadius, ptCnt, ptEnd);
}
AcDbEntity* makeDiameter(
const AcGePoint3d &ptCnt
, const AcGePoint3d &ptEnd)
{
typedef AcDbEntity* (_cdecl *func_makeDiameter)(const AcGePoint3d &, const AcGePoint3d &);
func_process(makeDiameter, ptCnt, ptEnd);
}
AcDbEntity* makeAngle(
const AcGePoint3d &ptCnt
, const AcGePoint3d &ptStart
, const AcGePoint3d &ptEnd)
{
typedef AcDbEntity* (_cdecl *func_makeAngle)(const AcGePoint3d &, const AcGePoint3d &, const AcGePoint3d &);
func_process(makeAngle, ptCnt, ptStart, ptEnd);
}
AcDbEntity* makeArc(
const AcGeCircArc3d &arc
, ETYPE type
, double toDimLine)
{
typedef AcDbEntity* (_cdecl *func_makeArc)(const AcGeCircArc3d &, int, double);
func_process(makeArc, arc, (int)type, toDimLine);
}
AcDbEntity* makeMPoint(
const std::vector<AcGePoint3d> &pts
, double toDimLine)
{
typedef AcDbEntity* (_cdecl *func_makeMPoint)(const std::vector<AcGePoint3d> &, double);
func_process(makeMPoint, pts, toDimLine);
}
AcDbEntity* make2Point(
const AcGePoint3d &ptS
, const AcGePoint3d &ptE
, double toDimLine)
{
typedef AcDbEntity* (_cdecl *func_make2Point)(const AcGePoint3d &, const AcGePoint3d &, double);
func_process(make2Point, ptS, ptE, toDimLine);
}
AcDbEntity* make2Point2(
const AcGePoint3d &ptS /* 要标注的起点 */
, const AcGePoint3d &ptE /* 要标注的终点 */
, LPCTSTR pszDim /* 标注文字 */
, double toDimLine /* 定位点到尺寸线的距离, 可以为负值, 图纸单位 */)
{
typedef AcDbEntity* (_cdecl *func_make2Point2)(const AcGePoint3d &, const AcGePoint3d &, LPCTSTR, double);
func_process(make2Point2, ptS, ptE, pszDim, toDimLine);
}
AcDbEntity* makeCoordDim(
const AcGePoint3d &ptLoc
, const AcGePoint3d &ptSec
, ETYPE Unit
, int precision
, ETYPE arrow
, ETYPE wcs
, ETYPE xy
, double NorthAng)
{
typedef AcDbEntity* (_cdecl *func_makeCoordDim)(const AcGePoint3d &, const AcGePoint3d &, int, int, int, int, int, double);
func_process(makeCoordDim, ptLoc, ptSec, Unit, precision, arrow, wcs, xy, NorthAng);
}
AcDbEntity* makeSymbCut(
const AcGePoint3d &ptS
, const AcGePoint3d &ptE
, double len)
{
typedef AcDbEntity* (_cdecl *func_makeSymbCut)(const AcGePoint3d &, const AcGePoint3d &, double);
func_process(makeSymbCut, ptS, ptE, len);
}
AcDbEntity* makeDrawingNameSymb(
const AcGePoint3d &pt
, LPCTSTR pszName
, LPCTSTR pszScale
, double nameheight
, double scaleheight
, LPCTSTR pszNameStyle
, LPCTSTR pszScaleStyle
, bool bShowScale
, ETYPE Gb)
{
typedef AcDbEntity* (_cdecl *func_makeDrawingNameSymb)(const AcGePoint3d &, LPCTSTR, LPCTSTR, double, double, LPCTSTR, LPCTSTR, bool, int);
func_process(makeDrawingNameSymb, pt, pszName, pszScale, nameheight, scaleheight, pszNameStyle, pszScaleStyle, bShowScale, (int)Gb);
}
AcDbEntity* makeSymbLeader(
const AcGePoint3d &pt1
, const AcGePoint3d &pt2
, double baseLen
, LPCTSTR pszUp
, LPCTSTR pszDown
, LPCTSTR pszStyle
, double height
, ETYPE arrow
, double arrowSize
, ETYPE align)
{
typedef AcDbEntity* (_cdecl *func_makeSymbLeader)(const AcGePoint3d &, const AcGePoint3d &, double, LPCTSTR, LPCTSTR, LPCTSTR, double, int, double, int);
func_process(makeSymbLeader, pt1, pt2, baseLen, pszUp, pszDown, pszStyle, height, (int)arrow, arrowSize, (int)align);
}
AcDbEntity* makeSymbNode(
const AcGePoint3d &pt1
, const AcGePoint3d &pt2
, double baseLen
, LPCTSTR pszUp
, LPCTSTR pszStyle
, double height
, ETYPE arrow
, double arrowSize
, ETYPE align)
{
typedef AcDbEntity* (_cdecl *func_makeSymbNode)(const AcGePoint3d &, const AcGePoint3d &, double, LPCTSTR, LPCTSTR, double, int, double, int);
func_process(makeSymbNode, pt1, pt2, baseLen, pszUp, pszStyle, height, (int)arrow, arrowSize, (int)align);
}
AcDbEntity* makeNorthThumb(
const AcGePoint3d &pt
, const AcGePoint3d &ptAng)
{
typedef AcDbEntity* (_cdecl *func_makeNorthThumb)(const AcGePoint3d &, const AcGePoint3d &);
func_process(makeNorthThumb, pt, ptAng);
}
AcDbEntity* makeSymbArrow(
const AcGePoint3d &ptS
, const AcGePoint3d &ptE
, LPCTSTR pszUp
, LPCTSTR pszDown
, LPCTSTR pszStyle
, double height
, double arrowSize
, ETYPE arrow
, ETYPE align)
{
typedef AcDbEntity* (_cdecl *func_makeSymbArrow)(const AcGePoint3d &, const AcGePoint3d &, LPCTSTR, LPCTSTR, LPCTSTR, double, double, int, int);
func_process(makeSymbArrow, ptS, ptE, pszUp, pszDown, pszStyle, height, arrowSize, (int)arrow, (int)align);
}
AcDbEntity* makeSymbIndex(
const AcGePoint3d &pt1
, double dRadius
, const AcGePoint3d &pt2
, double baseLen
, LPCTSTR pszIdxUp
, LPCTSTR pszIdxDown
, LPCTSTR pszDimUp
, LPCTSTR pszDimDown
, LPCTSTR pszIdxStyle
, LPCTSTR pszDimStyle
, double height
, ETYPE align)
{
typedef AcDbEntity* (_cdecl *func_makeSymbIndex)(const AcGePoint3d &, double, const AcGePoint3d &, double, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, double, int);
func_process(makeSymbIndex, pt1, dRadius, pt2, baseLen, pszIdxUp, pszIdxDown, pszDimUp, pszDimDown, pszIdxStyle, pszDimStyle, height, align);
}
AcDbEntity* makeSymbIndexDim(
const AcGePoint3d &pt
, LPCTSTR pszUp
, LPCTSTR pszDown
, LPCTSTR pszScale
, LPCTSTR pszStyleDim
, LPCTSTR pszStyleScale
, double height
, double radius
, double lw)
{
typedef AcDbEntity* (_cdecl *func_makeSymbIndexDim)(const AcGePoint3d &, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, LPCTSTR, double, double, double);
func_process(makeSymbIndexDim, pt, pszUp, pszDown, pszScale, pszStyleDim, pszStyleScale, height, radius, lw);
}
AcDbEntity* makeSymbSection(
const AcGePoint3d &pt1
, const AcGePoint3d &pt2
, const AcGePoint3d &ptDir
, LPCTSTR pszLable
, LPCTSTR pszDrawing
, ETYPE sectionType
, LPCTSTR pszStyleLable
, LPCTSTR pszStyleDrawing
, double heightLable
, double heightDrawing
, ETYPE drawingPos
, ETYPE drawingDir)
{
typedef AcDbEntity* (_cdecl *func_makeSymbSection)(const AcGePoint3d &, const AcGePoint3d &, const AcGePoint3d &, LPCTSTR, LPCTSTR, int, LPCTSTR, LPCTSTR, double, double, int, int);
func_process(makeSymbSection, pt1, pt2, ptDir, pszLable, pszDrawing, (int)sectionType, pszStyleLable, pszStyleDrawing, heightLable, heightDrawing, (int)drawingPos, (int)drawingDir);
}
AcDbEntity* makeSymbElevation1(
const AcGePoint3d &pt
, LPCTSTR pszText
, LPCTSTR pszStyle
, double height
, bool bHasBaseLine
, double baseLen
, bool bHasLeaderLine
, double leaderLen
, bool bPre2)
{
typedef AcDbEntity* (_cdecl *func_makeSymbElevation1)(const AcGePoint3d &, LPCTSTR, LPCTSTR, double, bool, double, bool, double, bool);
func_process(makeSymbElevation1, pt, pszText, pszStyle, height, bHasBaseLine, baseLen, bHasLeaderLine, leaderLen, bPre2);
}
AcDbEntity* makeSymbElevation2(
const AcGePoint3d &pt
, LPCTSTR pszText
, LPCTSTR pszStyle
, double height
, bool bPre2)
{
typedef AcDbEntity* (_cdecl *func_makeSymbElevation2)(const AcGePoint3d &, LPCTSTR, LPCTSTR, double, bool);
func_process(makeSymbElevation2, pt, pszText, pszStyle, height, bPre2);
}
double getElevation(AcDbEntity *pEnt)
{
typedef double (_cdecl *func_getElevation)(AcDbEntity*);
func_process_double(getElevation, pEnt);
}
bool modifyElevation(AcDbEntity *pEnt, LPCTSTR sElev)
{
typedef bool (_cdecl *func_modifyElevation)(AcDbEntity*, LPCTSTR);
func_process_bool(modifyElevation, pEnt, sElev);
}
make_xdata_set_func(setObjId2DataMap, AcDbObjectId);
make_xdata_get_func(getObjIdByDataMap, AcDbObjectId);
make_xdata_set_func(setInteger2DataMap, int);
make_xdata_get_func(getIntegerByDataMap, int);
make_xdata_set_func(setPt3d2DataMap, AcGePoint3d);
make_xdata_get_func(getPt3dByDataMap, AcGePoint3d);
make_xdata_set_func(setDouble2DataMap, double);
make_xdata_get_func(getDoubleByDataMap, double);
make_xdata_set_func(setStr2DataMap, CString);
make_xdata_get_func(getStrByDataMap, CString);
make_xdata_set_func(setVec3d2DataMap, AcGeVector3d);
make_xdata_get_func(getVec3dByDataMap, AcGeVector3d);
};