|
- 本篇将介绍 12 个用于尺寸标注的函数,包括了转角标注、对齐标注、角度标注、半径标注、直径标注和坐标标注的创建函数。这些函数分别封装了系统提供的一些基本方法,并在实用性上进行了扩充。
- 2. 思路
- A. AcDbAlignedDimension 类对应的是对齐标注,该类的构造函数接受 5 个参数:
- (1)第一条尺寸边界线的起点、 (2)第二条尺寸边界线的起点、
- (3)通过尺寸线的一点、(4)标注文字、 (5)样式。
- 本节创建一个函数,对该类的构造函数直接进行封装,另外创建一个函数,可以在创建标注时修改标注文字的位置。
- B. AcDbRotatedDimension 类对应转角标注,该类的构造函数接受 6 个参数:
- (1)标注的旋转角度、 (2)第一条尺寸边界线的起点、 (3)第二条尺寸边界线的起点、
- (4)通过尺寸线的一点、 (5)标注文字 (6)样式。
- 本节创建的函数直接对该函数进行封装。
- C. AcDbRadialDimension 类对应半径标注,该类的构造函数需要输入5 个参数:
- (1)标注曲线的中心点、 (2)引线附着的坐标、 (3)引线长度、
- (4)标注文字 (5)样式
- 本节除了对构造函数进行封装之外,提供了根据 (1)圆心、(2)半径、(3)标注尺寸线旋转角度(4)引线长度 来创建半径标注的函数,其关键点就在于根据已知的参数计算出构造函数需要的参数。
- D. AcDbDiametricDimension 类对应直径标注,其构造函数需要输入5 个参数:
- (1)+(2)标注直径的两个端点、(3)引线长度、
- (4)标注文字(5)样式
- 本节除对其构造函数直接封装之外,还提供了根据(1)圆弧的圆心、 (2)半径、
- (3)引线放置角度(4)引线长度 创建标注的方法。
- E. AcDb2LineAngularDimension 类对应角度标注,对这个类的构造函数进行封装。
- F. AcDb3PointAngularDimension类对应角度标注,对这个类的构造函数进行封装。
- G. AcDbOrdinateDimension 类对应坐标标注,其构造函数需要输入5 个参数:
- (1)是否是 X 轴标注(布尔类型变量)、 (2)标注箭头的起始位置、
- (3)标注箭头的终止位置、 (4)标注文字 (5)样式
- 本篇对该函数封装之后,又创建了两个新函数,能够同时创建 X、Y 两个坐标值,并且根据相对坐标修改引线端点的位置。
- 3. 步骤
- A. AcDbAlignedDimension 类对应的是对齐标注,该类的构造函数接受 5 个参数:
- (1)第一条尺寸边界线的起点、 (2)第二条尺寸边界线的起点、
- (3)通过尺寸线的一点、(4)标注文字、 (5)样式。
- 本节创建一个函数,对该类的构造函数直接进行封装,另外创建一个函数,可以在创建标注时修改标注文字的位置。
- (1)创建对齐标注:添加一个新函数 CreateDimAligned
- //创建对齐标注
- static AcDbObjectId CreateDimAligned(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptLine, const char* dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
- //创建对齐标注
- //(1)第一条尺寸边界线的起点(2)第二条尺寸边界线的起点(3)通过尺寸线的一点(4)标注文字(5)样式。
- AcDbObjectId CCreateEnt::CreateDimAligned(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptLine, const char* dimText, AcDbObjectId dimStyle)
- { AcDbAlignedDimension *pDim = new AcDbAlignedDimension(pt1, pt2, ptLine, dimText, dimStyle); return CCreateEnt::PostToModelSpace(pDim);
- }
- (2)创建对齐标注:创建一个重载的函数,允许用户输入 vecOffset 作为标注文字位置的偏移量
- //创建对齐标注, 创建一个重载的函数,允许用户输入 vecOffset 作为标注文字位置的偏移量static AcDbObjectId CreateDimAligned(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptLine, const AcGeVector3d& vecOffset = AcGeVector3d::kIdentity, const TCHAR* dimText = NULL);
- //创建对齐标注
- //重载函数,允许输入 vecOffset 作为标注文字位置的偏移量
- AcDbObjectId CCreateEnt::CreateDimAligned(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptLine, const AcGeVector3d& vecOffset, const TCHAR* dimText)
- { AcDbAlignedDimension *pDim = new AcDbAlignedDimension(pt1, pt2, ptLine, dimText, AcDbObjectId::kNull);AcDbObjectId dimensionId;dimensionId = CCreateEnt::PostToModelSpace(pDim);// 打开已经创建的标注,对文字的位置进行修改AcDbEntity *pEnt;Acad::ErrorStatus es;es = acdbOpenAcDbEntity(pEnt, dimensionId, AcDb::kForWrite);AcDbAlignedDimension *pDimension = AcDbAlignedDimension::cast(pEnt);if (pDimension != NULL) { // 移动文字位置前,需先指定尺寸线的变化情况(这里指定为:// 尺寸线不动,在文字和尺寸线之间加箭头)pDimension->setDimtmove(1); // 根据偏移向量修正文字插入点的位置AcGePoint3d ptText = pDimension->textPosition(); ptText = ptText + vecOffset; pDimension->setTextPosition(ptText); } pEnt->close(); return dimensionId;
- }
- B. AcDbRotatedDimension 类对应转角标注,该类的构造函数接受 6 个参数:
- (1)标注的旋转角度、 (2)第一条尺寸边界线的起点、 (3)第二条尺寸边界线的起点、
- (4)通过尺寸线的一点、 (5)标注文字 (6)样式。
- 本节创建的函数直接对该函数进行封装。
- (3)创建转角标注:添加一个新函数 CreateDimRotated
- //创建转角标注static AcDbObjectId CreateDimRotated(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptLine, double rotation, const TCHAR* dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
- //创建转角标注
- //(1)标注的旋转角度、(2)第一条尺寸边界线的起点、(3)第二条尺寸边界线的起点、(4)通过尺寸线的一点、(5)标注文字 (6)样式。
- AcDbObjectId CCreateEnt::CreateDimRotated(const AcGePoint3d& pt1, const AcGePoint3d& pt2, const AcGePoint3d& ptLine, double rotation, const TCHAR* dimText, AcDbObjectId dimStyle)
- { AcDbRotatedDimension *pDim = new AcDbRotatedDimension(rotation, pt1, pt2, ptLine, dimText, dimStyle); return CCreateEnt::PostToModelSpace(pDim);
- }
- C. AcDbRadialDimension 类对应半径标注,该类的构造函数需要输入5 个参数:
- (1)标注曲线的中心点、 (2)引线附着的坐标、 (3)引线长度、
- (4)标注文字 (5)样式
- 本节除了对构造函数进行封装之外,提供了根据 (1)圆心、(2)半径、(3)标注尺寸线旋转角度(4)引线长度 来创建半径标注的函数,其关键点就在于根据已知的参数计算出构造函数需要的参数。
- (4)创建半径标注:添加一个新函数 CreateDimRadial
- //创建半径标注static AcDbObjectId CreateDimRadial(const AcGePoint3d& ptCenter, const AcGePoint3d& ptChord, double leaderLength, const TCHAR* dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
- //创建半径标注
- //(1)标注曲线的中心点、(2)引线附着的坐标、(3)引线长度、(4)标注文字(5)样式
- AcDbObjectId CCreateEnt::CreateDimRadial(const AcGePoint3d& ptCenter, const AcGePoint3d& ptChord, double leaderLength, const TCHAR* dimText, AcDbObjectId dimStyle)
- { AcDbRadialDimension *pDim = new AcDbRadialDimension(ptCenter, ptChord, leaderLength, dimText, dimStyle); return CCreateEnt::PostToModelSpace(pDim);
- }
- (5)创建半径标注:创建一个重载的函数,用于根据圆心、半径、标注尺寸线的旋转角度和引线长度来创建半径标注
- //创建半径标注
- static AcDbObjectId CreateDimRadial(const AcGePoint3d& ptCenter, double radius, double angle, double leaderLength = 5);
- //创建半径标注
- //重载函数,(圆心、半径、标注尺寸线的旋转角度和引线长度)
- AcDbObjectId CCreateEnt::CreateDimRadial(const AcGePoint3d& ptCenter, double radius, double angle, double leaderLength)
- { CGeometryOper m采用geometryOper;AcGePoint3d ptChord = m采用geometryOper.PolarPoint(ptCenter, angle, radius); return CCreateEnt::CreateDimRadial(ptCenter, ptChord, leaderLength);
- }
- 其中,CCalculation::PolarPoint 是一个自定义函数,能够根据相对极坐标来确定一个点的位置:
- //根据相对极坐标来确定一个点的位置
- AcGePoint3d PolarPoint(const AcGePoint3d& pt, double angle, double distance);
- //根据相对极坐标来确定一个点的位置
- AcGePoint3d CGeometryOper::PolarPoint(const AcGePoint3d& pt, double angle, double distance)
- { ads采用point ptForm, ptTo; ptForm[X] = pt.x; ptForm[Y] = pt.y; ptForm[Z] = pt.z;//acutPolar: 计算某个角度上距离某个点一定距离的点acutPolar(ptForm, angle, distance, ptTo); return asPnt3d(ptTo);
- }
- D. AcDbDiametricDimension 类对应直径标注,其构造函数需要输入5 个参数:
- (1)+(2)标注直径的两个端点、(3)引线长度、
- (4)标注文字(5)样式
- 本节除对其构造函数直接封装之外,还提供了根据(1)圆弧的圆心、 (2)半径、
- (3)引线放置角度(4)引线长度 创建标注的方法。
- (6)创建直径标注:创建一个函数 CreateDimDiametric
- //创建直径标注static AcDbObjectId CreateDimDiametric(const AcGePoint3d& ptChord1, const AcGePoint3d& ptChord2, double leaderLength, const TCHAR* dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
- //创建直径标注
- //(1)+(2)标注直径的两个端点、(3)引线长度、(4)标注文字(5)样式
- AcDbObjectId CCreateEnt::CreateDimDiametric(const AcGePoint3d& ptChord1, const AcGePoint3d& ptChord2, double leaderLength, const TCHAR* dimText, AcDbObjectId dimStyle)
- { AcDbDiametricDimension *pDim = new AcDbDiametricDimension(ptChord1, ptChord2, leaderLength, dimText, dimStyle); return CCreateEnt::PostToModelSpace(pDim);
- }
- (7)创建直径标注:创建一个重载的函数,根据圆心、半径、标注尺寸线的旋转角度和引线长度
- //创建直径标注
- static AcDbObjectId CreateDimDiametric(const AcGePoint3d& ptCenter, double radius, double angle, double leaderLength = 5);
- //创建直径标注
- //重载函数,(圆心、半径、标注尺寸线的旋转角度和引线长度)
- AcDbObjectId CCreateEnt::CreateDimDiametric(const AcGePoint3d& ptCenter, double radius, double angle, double leaderLength)
- { CGeometryOper m采用geometryOper;// 计算标注通过点的位置AcGePoint3d ptChord1, ptChord2; ptChord1 = m采用geometryOper.PolarPoint(ptCenter, angle, radius); ptChord2 = m采用geometryOper.PolarPoint(ptCenter, angle + m采用geometryOper.PI(), radius); return CCreateEnt::CreateDimDiametric(ptChord1, ptChord2, leaderLength);
- }
- E. AcDb2LineAngularDimension 类对应角度标注,对这个类的构造函数进行封装。
- (8)创建角度标注:根据两条直线的关系创建一个函数
- //创建角度标注static AcDbObjectId CreateDim2LineAngular(const AcGePoint3d& ptStart1, const AcGePoint3d& ptEnd1, const AcGePoint3d& ptStart2, const AcGePoint3d& ptEnd2, const AcGePoint3d& ptArc, const TCHAR* dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
- //创建二维角度标注
- //根据两条直线的关系创建一个函数
- AcDbObjectId CCreateEnt::CreateDim2LineAngular(const AcGePoint3d& ptStart1, const AcGePoint3d& ptEnd1, const AcGePoint3d& ptStart2, const AcGePoint3d& ptEnd2, const AcGePoint3d& ptArc, const TCHAR* dimText, AcDbObjectId dimStyle)
- { AcDb2LineAngularDimension *pDim = new AcDb2LineAngularDimension(ptStart1, ptEnd1, ptStart2, ptEnd2, ptArc, dimText, dimStyle); return CCreateEnt::PostToModelSpace(pDim);
- }
- F. AcDb3PointAngularDimension类对应角度标注,对这个类的构造函数进行封装。
- (9)创建角度标注:创建一个重载的函数,根据顶点、起始点、终止点和标注尺寸线通过点来创建
- //创建三维角度标注static AcDbObjectId CreateDim3PtAngular(const AcGePoint3d& ptCenter, const AcGePoint3d& ptEnd1, const AcGePoint3d& ptEnd2, const AcGePoint3d& ptArc, const TCHAR* dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
- //创建三维角度标注
- //重载函数,(顶点、起始点、终止点和标注尺寸线通过点)
- AcDbObjectId CCreateEnt::CreateDim3PtAngular(const AcGePoint3d& ptCenter, const AcGePoint3d& ptEnd1, const AcGePoint3d& ptEnd2, const AcGePoint3d& ptArc, const TCHAR* dimText, AcDbObjectId dimStyle)
- { AcDb3PointAngularDimension *pDim = new AcDb3PointAngularDimension(ptCenter, ptEnd1, ptEnd2, ptArc, dimText, dimStyle); return CCreateEnt::PostToModelSpace(pDim);
- }
- G. AcDbOrdinateDimension 类对应坐标标注,其构造函数需要输入5 个参数:
- (1)是否是 X 轴标注(布尔类型变量)、 (2)标注箭头的起始位置、
- (3)标注箭头的终止位置、 (4)标注文字 (5)样式
- 本篇对该函数封装之后,又创建了两个新函数,能够同时创建 X、Y 两个坐标值,并且根据相对坐标修改引线端点的位置。
- (10)创建坐标标注:创建一个函数 CreateDimOrdinate,直接封装类的构造函数
- //创建坐标标注static AcDbObjectId CreateDimOrdinate(Adesk::Boolean xAxis, const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd, const TCHAR* dimText = NULL, AcDbObjectId dimStyle = AcDbObjectId::kNull);
- //创建坐标标注
- //(1)是否是 X 轴标注(布尔类型变量)、(2)标注箭头的起始位置、(3)标注箭头的终止位置、(4)标注文字、(5)样式
- AcDbObjectId CCreateEnt::CreateDimOrdinate(Adesk::Boolean xAxis, const AcGePoint3d& ptStart, const AcGePoint3d& ptEnd, const TCHAR* dimText, AcDbObjectId dimStyle)
- { AcDbOrdinateDimension *pDim = new AcDbOrdinateDimension(xAxis, ptStart, ptEnd, dimText, dimStyle); return CCreateEnt::PostToModelSpace(pDim);
- }
- (11)创建坐标标注:创建一个重载的函数,能够同时创建一个点的 X、Y 坐标标注
- //创建坐标标注
- static AcDbObjectIdArray CreateDimOrdinate(const AcGePoint3d& ptDef, const AcGePoint3d& ptTextX, const AcGePoint3d& ptTextY);
- //创建坐标标注
- //重载函数,能够同时创建一个点的 X、Y 坐标标注
- AcDbObjectIdArray CCreateEnt::CreateDimOrdinate(const AcGePoint3d& ptDef, const AcGePoint3d& ptTextX, const AcGePoint3d& ptTextY)
- { AcDbObjectId dimId; AcDbObjectIdArray dimIds; dimId = CCreateEnt::CreateDimOrdinate(Adesk::kTrue, ptDef, ptTextX); dimIds.append(dimId); dimId = CCreateEnt::CreateDimOrdinate(Adesk::kFalse, ptDef, ptTextY); dimIds.append(dimId); return dimIds;
- }
- (12)创建坐标标注:能够根据点的偏移位置来创建坐标标注
- //创建坐标标注
- static AcDbObjectIdArray CreateDimOrdinate(const AcGePoint3d& ptDef, const AcGeVector3d& vecOffsetX, const AcGeVector3d& vecOffsetY);
- //创建坐标标注
- //重载函数,能够根据点的偏移位置来创建坐标标注
- AcDbObjectIdArray CCreateEnt::CreateDimOrdinate(const AcGePoint3d& ptDef, const AcGeVector3d& vecOffsetX, const AcGeVector3d& vecOffsetY)
- { AcGePoint3d ptTextX = ptDef + vecOffsetX; AcGePoint3d ptTextY = ptDef + vecOffsetY; return CCreateEnt::CreateDimOrdinate(ptDef, ptTextX, ptTextY);
- }
- 4. 实体操作
- (1)在 CCalculation 类中增加一个函数 RelativePoint,用于根据相对直角坐标来计算一个点的位置:
- //根据相对直角坐标来计算一个点的位置AcGePoint3d RelativePoint(const AcGePoint3d& pt, double x, double y);
- //根据相对直角坐标来计算一个点的位置
- AcGePoint3d CGeometryOper::RelativePoint(const AcGePoint3d& pt, double x, double y)
- {AcGePoint3d ptReturn(pt.x + x, pt.y + y, pt.z); return ptReturn;
- }
- 5. 在acrxEntryPoint.cpp中
- ACED采用ARXCOMMAND采用ENTRY采用AUTO(CArxConfigApp, MidasMyGroup, MyCreateDimAligned, MyCreateDimAligned, ACRX采用CMD采用MODAL, NULL) 创建对齐标注
- //当前项目中注册一个命令 MyCreateDimAlignedstatic void MidasMyGroupMyCreateDimAligned(){CGeometryOper m采用geometryOper;// 指定起始点位置AcGePoint3d pt1(200, 160, 0); AcGePoint3d pt2= m采用geometryOper.RelativePoint(pt1, -40, 0); AcGePoint3d pt3 = m采用geometryOper.PolarPoint(pt2, 7 * m采用geometryOper.PI() / 6, 20); AcGePoint3d pt4 = m采用geometryOper.RelativePoint(pt3, 6, -10); AcGePoint3d pt5 = m采用geometryOper.RelativePoint(pt1, 0, -20); // 绘制外轮廓线CCreateEnt::CreateLine(pt1, pt2); CCreateEnt::CreateLine(pt2, pt3);CCreateEnt::CreateLine(pt3, pt4); CCreateEnt::CreateLine(pt4, pt5); CCreateEnt::CreateLine(pt5, pt1); // 绘制圆形AcGePoint3d ptCenter1, ptCenter2; ptCenter1 = m采用geometryOper.RelativePoint(pt3, 16, 0); ptCenter2 = m采用geometryOper.RelativePoint(ptCenter1, 25, 0); CCreateEnt::CreateCircle(ptCenter1, 3); CCreateEnt::CreateCircle(ptCenter2, 4); AcGePoint3d ptTemp1, ptTemp2; // 水平标注ptTemp1 = m采用geometryOper.RelativePoint(pt1, -20, 3); CCreateEnt::CreateDimRotated(pt1, pt2, ptTemp1, 0); // 垂直标注ptTemp1 = m采用geometryOper.RelativePoint(pt1, 4, 10); CCreateEnt::CreateDimRotated(pt1, pt5, ptTemp1, m采用geometryOper.PI() / 2); // 转角标注ptTemp1 = m采用geometryOper.RelativePoint(pt3, -3, -6); CCreateEnt::CreateDimRotated(pt3, pt4, ptTemp1, 7 * m采用geometryOper.PI() / 4); // 对齐标注ptTemp1 = m采用geometryOper.RelativePoint(pt2, -3, 4); CCreateEnt::CreateDimAligned(pt2, pt3, ptTemp1, AcGeVector3d(4, 10, 0), 采用T("new position")); // 角度标注ptTemp1 = m采用geometryOper.RelativePoint(pt5, -5, 5); CCreateEnt::CreateDim3PtAngular(pt5, pt1, pt4, ptTemp1); // 半径标注ptTemp1 = m采用geometryOper.PolarPoint(ptCenter1, m采用geometryOper.PI() / 4, 3); CCreateEnt::CreateDimRadial(ptCenter1, ptTemp1, -3);// 直径标注ptTemp1 = m采用geometryOper.PolarPoint(ptCenter2, m采用geometryOper.PI() / 4, 4); ptTemp2 = m采用geometryOper.PolarPoint(ptCenter2, m采用geometryOper.PI() / 4, -4); CCreateEnt::CreateDimDiametric(ptTemp1, ptTemp2, 0); // 坐标标注CCreateEnt::CreateDimOrdinate(ptCenter2, AcGeVector3d(0, -10, 0), AcGeVector3d(10, 0, 0)); }
-
复制代码 |
|