一些概念

  • 尺寸标注倾斜度
    相对于水平X轴而言

  • 尺寸标注样式字段
    40 DIMSCALE 设置应用于标注变量(可指定大小、距离或偏移量)的全局比例因子
    41 DIMASZ 控制尺寸线、引线箭头的大小
    42 DIMEXO 指定尺寸界线偏离原点的距离
    44 DIMEXE 指定尺寸线超出尺寸界线的距离
    140 DIMTXT 指定标注文字的高度(除非当前文字样式具有固定的高度)

  • 箭头
    箭头大小为长度,高度则为0.2*箭头大小,若放不下,增加的引线长也为箭头长度即可。

  • 文字倾斜角度
    在文字样式中增加了倾斜角度

  • 尺寸标注箭头太大时,autocad的处理方式

  • 标注样式替代

代码实现

代码只是用来演示绘制思路,依赖其他一些代码,故不可直接运行。

  • 总体思路
 //标注点auto pDimPointGeom = DrawDimPoints();if (pDimPointGeom) pRtOsgGeode->addDrawable(pDimPointGeom);//绘制尺寸标注线auto pDimLineGeom = DrawDimLine();if (pDimLineGeom) pRtOsgGeode->addDrawable(pDimLineGeom);//绘制两根尺寸界线auto pDimBorderLineGeom = DrawDimBorderLine();if (pDimBorderLineGeom) pRtOsgGeode->addDrawable(pDimBorderLineGeom);//绘制箭头auto pArrowGeom = DrawArrow();if (pArrowGeom) pRtOsgGeode->addDrawable(pArrowGeom);//绘制文字DrawDimText(nModelFlag, pRtOsgGeode);
  • 部分代码
osg::ref_ptr<osg::Drawable> DrawerGMAlignedDimension::DrawDimPoints()
{osg::Geometry* pDimPointGeom = new osg::Geometry();osg::Vec3dArray* pVertexArray = new osg::Vec3dArray();pVertexArray->push_back(osg::Vec3d(m_ptDimPoint1.x,m_ptDimPoint1.y, m_ptDimPoint1.z));pVertexArray->push_back(osg::Vec3d(m_ptDimPoint2.x,m_ptDimPoint2.y, m_ptDimPoint2.z));pDimPointGeom->setVertexArray(pVertexArray);pDimPointGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0, pVertexArray->size()));return pDimPointGeom;
}osg::ref_ptr<osg::Drawable> DrawerGMAlignedDimension::DrawDimLine()
{AcGeVector3d vDimPtToDimLineOffset = m_ptDimLinePoint - m_ptDimPoint2;//标注点到标注线的偏移向量AcGePoint3d ptDimLineStart = m_ptDimPoint1 + vDimPtToDimLineOffset;//标注线起点AcGePoint3d ptDimLineEnd = m_ptDimPoint2 + vDimPtToDimLineOffset;//标注线末点osg::Geometry* pDimLineGeom = new osg::Geometry();osg::Vec3dArray* pVertexArray = new osg::Vec3dArray();pVertexArray->push_back(osg::Vec3d(ptDimLineStart.x,ptDimLineStart.y, ptDimLineStart.z));pVertexArray->push_back(osg::Vec3d(ptDimLineEnd.x,ptDimLineEnd.y, ptDimLineEnd.z));pDimLineGeom->setVertexArray(pVertexArray);pDimLineGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0, pVertexArray->size()));return pDimLineGeom;
}osg::ref_ptr<osg::Drawable> DrawerGMAlignedDimension::DrawDimBorderLine()
{//标注点到标注线的偏移向量AcGeVector3d vDimPtToDimLineOffset = m_ptDimLinePoint - m_ptDimPoint2;//dxf文档中说标注点在第二根线上,不能由倾斜度纠正出标注点,//因为autocad带倾斜的标注就没导出这个倾斜度AcGeVector3d vBorderDir = m_ptDimLinePoint - m_ptDimPoint2;vBorderDir.normalize();//第一根界线AcGePoint3d ptBorder1Start = m_ptDimPoint1 + vBorderDir * (m_dDIMSCALE*m_dDIMEXO);AcGePoint3d ptBorder1End = m_ptDimPoint1 + vDimPtToDimLineOffset + vBorderDir *m_dDIMSCALE * m_dDIMEXE;//第二根界线AcGePoint3d ptBorder2Start = m_ptDimPoint2 + vBorderDir * (m_dDIMSCALE*m_dDIMEXO);AcGePoint3d ptBorder2End = m_ptDimPoint2 + vDimPtToDimLineOffset + vBorderDir *m_dDIMSCALE * m_dDIMEXE;osg::Geometry* pBorderLineGeom = new osg::Geometry();osg::Vec3dArray* pVertexArray = new osg::Vec3dArray();pVertexArray->push_back(osg::Vec3d(ptBorder1Start.x,ptBorder1Start.y, ptBorder1Start.z));pVertexArray->push_back(osg::Vec3d(ptBorder1End.x,ptBorder1End.y, ptBorder1End.z));pVertexArray->push_back(osg::Vec3d(ptBorder2Start.x,ptBorder2Start.y, ptBorder2Start.z));pVertexArray->push_back(osg::Vec3d(ptBorder2End.x,ptBorder2End.y, ptBorder2End.z));pBorderLineGeom->setVertexArray(pVertexArray);pBorderLineGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0, pVertexArray->size()));return pBorderLineGeom;
}osg::ref_ptr<osg::Drawable> DrawerGMAlignedDimension::DrawArrow()
{AcGeVector3d vDimPtToDimLineOffset = m_ptDimLinePoint - m_ptDimPoint2;标注点到标注线的偏移向量//获取箭头大小//箭头大小为长度,高度的一半为0.2*大小,若放不下,增加的引线长也为箭头长度即可。double dArrowSize = m_dDIMASZ * m_dDIMSCALE;//计算箭头水平、垂直方向需要的偏移向量AcGeVector3d vDimLineDir = m_ptDimPoint2 - m_ptDimPoint1;//标注线方向 AcGeVector3d vArrowHOffset = vDimLineDir; //箭头水平方向 AcGeVector3d vArrowVOffset = vDimLineDir; //箭头垂直方向vArrowVOffset.rotateBy(PI / 2.0, AcGeVector3d::kZAxis);vArrowHOffset.normalize();vArrowVOffset.normalize();vArrowHOffset = vArrowHOffset * dArrowSize; //箭头水平偏移向量vArrowVOffset = vArrowVOffset * dArrowSize * 0.2; //箭头垂直方向偏移向量osg::Geometry* pArrowGeom = new osg::Geometry();osg::Vec3dArray* pVertexArray = new osg::Vec3dArray();//起点箭头{AcGePoint3d ptDimLineStart = m_ptDimPoint1 + vDimPtToDimLineOffset;//标注线起点AcGePoint3d ptFirst, ptSencond, ptThird;ptFirst = (ptDimLineStart + vArrowHOffset) + vArrowVOffset;ptSencond = (ptDimLineStart + vArrowHOffset) - vArrowVOffset;ptThird = ptDimLineStart;pVertexArray->push_back( osg::Vec3d(ptFirst.x, ptFirst.y, ptFirst.z)); //start pointpVertexArray->push_back(osg::Vec3d(ptSencond.x, ptSencond.y, ptSencond.z)); //same as start pointpVertexArray->push_back(osg::Vec3d(ptThird.x, ptThird.y, ptThird.z));}//末点箭头{AcGePoint3d ptDimLineEnd = m_ptDimPoint2 + vDimPtToDimLineOffset;//标注线末点AcGePoint3d ptFirst, ptSencond, ptThird;ptFirst = (ptDimLineEnd - vArrowHOffset) + vArrowVOffset;ptSencond = (ptDimLineEnd - vArrowHOffset) - vArrowVOffset;ptThird = ptDimLineEnd;pVertexArray->push_back(osg::Vec3d(ptFirst.x, ptFirst.y, ptFirst.z)); //start pointpVertexArray->push_back(osg::Vec3d(ptSencond.x, ptSencond.y, ptSencond.z)); //same as start pointpVertexArray->push_back(osg::Vec3d(ptThird.x, ptThird.y, ptThird.z));}pArrowGeom->setVertexArray(pVertexArray);pArrowGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, pVertexArray->size()));return pArrowGeom;
}void DrawerGMAlignedDimension::DrawDimText(INT nModelFlag,osg::ref_ptr<osg::Geode>& pRtOsgGeode)
{if (!m_pGRSolidFactoryImp){return;}////暂只实现了文字居中、放置上标注线上方的逻辑////标注文字值,要处理使用测量值的情况CString strDimText = m_strDimText;if (strDimText.IsEmpty())//文字替换为空,则使用测量值{double dDistance = m_ptDimPoint1.distanceTo(m_ptDimPoint2);switch (m_nDIMDEC){case 0:strDimText.Format(_T("%.0f"), dDistance);break;case 1:strDimText.Format(_T("%.1f"), dDistance);break;case 2:strDimText.Format(_T("%.2f"), dDistance);break;case 3:strDimText.Format(_T("%.3f"), dDistance);break;case 4:strDimText.Format(_T("%.4f"), dDistance);break;case 5:strDimText.Format(_T("%.5f"), dDistance);break;case 6:strDimText.Format(_T("%.6f"), dDistance);break;default:strDimText.Format(_T("%.0f"), dDistance);}RemoveBackZero(strDimText);}//文字标注方向AcGeVector3d vDimTextDir = (m_ptDimPoint2 - m_ptDimPoint1).normal();//实现居中、上方的文字位置 shanql 2022.7.25//文字延着标注线垂直方向向上偏移指定距离。//标注线方向的确定: 标注方向 = 标注第二点 - 标注第一点//1、使用点积判断//若标注方向与x轴正向平行,标注方向取+x;//否则,若标注方向与x轴垂直,标注方向取+y;//否则,若标注方向与x轴点积 < 0, 则标注方向取反//否则标注方向不变////2、使用angleTo求出两向量[0-pi]的夹角//若为0或pi,则表示与x轴平行,标注方向取+x//否则若为pi/2, 则表示与x轴垂直,标注方向取+y;//否则若>pi/2, 则标注方向取反//否则标注方向不变//ptTextPosTemp = ptDimMid + (m_dDIMGAP + m_dDIMTXT / 2.0) * m_dDIMSCALE * vecTextOffsetDir;if (vDimTextDir.isCodirectionalTo(AcGeVector3d::kXAxis)){//平行x轴vDimTextDir = AcGeVector3d::kXAxis;}else if (vDimTextDir.isPerpendicularTo(AcGeVector3d::kXAxis)){//垂直x轴vDimTextDir = AcGeVector3d::kYAxis;}else{if (vDimTextDir.angleTo(AcGeVector3d::kXAxis) > PI / 2.0){vDimTextDir = -vDimTextDir;}}std::shared_ptr<GMText> pGMText = std::make_shared<GMText>(strDimText);pGMText->SetExtendDir(vDimTextDir);pGMText->SetNormal(AcGeVector3d::kZAxis);AcGePoint3d ptTextPosTemp = m_ptTextPos;if (ptTextPosTemp.isEqualTo(AcGePoint3d::kOrigin)){AcGeVector3d vecTextOffsetDir = vDimTextDir;vecTextOffsetDir.rotateBy(PI / 2.0, AcGeVector3d::kZAxis);//求出标注中点AcGeVector3d vDimPtToDimLineOffset = m_ptDimLinePoint - m_ptDimPoint2;//标注点到标注线的偏移向量AcGePoint3d ptDimLineStart = m_ptDimPoint1 + vDimPtToDimLineOffset;//标注线起点AcGePoint3d ptDimLineEnd = m_ptDimPoint2 + vDimPtToDimLineOffset;//标注线末点AcGePoint3d ptDimMid = (ptDimLineStart + ptDimLineEnd.asVector()) / 2.0;//求出文字位置ptTextPosTemp = ptDimMid + (m_dDIMGAP + m_dDIMTXT / 2.0) * m_dDIMSCALE * vecTextOffsetDir;}pGMText->SetPosition(ptTextPosTemp);//文字位置 pGMText->SetAttachment(GMText::AttachmentType::MiddleCenter);double dTextHeight = m_dDIMTXT * m_dDIMSCALE;pGMText->SetHeight(dTextHeight);//文字高度pGMText->SetWidth(dTextHeight*1.0);m_pGRSolidFactoryImp->Create(pGMText, nModelFlag, pRtOsgGeode);
}

运行截图

与autocad的对比图

DXF笔记:对齐尺寸标注的绘制相关推荐

  1. DXF笔记:线性与对齐尺寸标注(2)

    线性尺寸标注 创建线性标注时,使用自定义角度,输入的是30度,dxf中保存的却是120度,由此可得知,标注线方向为正X轴旋转120度或标注界线则为正Y轴旋转120度. 对齐尺寸标注 倾斜后,标注点连线 ...

  2. OpenGL学习笔记(一)绘制点线面及多面体

    OpenGL学习笔记(一)绘制点线面及多面体 绘制点线面 #include <iostream> #include <GL/GLUT.h> #define PI 3.14159 ...

  3. OpenCV学习笔记(5)_ ellipse绘制函数浅析

    OpenCV学习笔记(5)_ ellipse绘制函数浅析 文章目录 OpenCV学习笔记(5)_ ellipse绘制函数浅析 1. ellipse第一种重载--绘制椭圆弧 1.1 函数原型 1.2 参 ...

  4. R绘图笔记 | 火山图的绘制

    参考前文:R绘图笔记 | R语言绘图系统与常见绘图函数及参数 关于绘图,前面介绍了一些: R绘图笔记 | 一般的散点图绘制 R绘图笔记 | 柱状图绘制 R绘图笔记 | 直方图和核密度估计图的绘制 R绘 ...

  5. Flutter学习笔记 —— CustomPainter自定义画布绘制爱心

    Flutter学习笔记 -- CustomPainter自定义画布绘制爱心 前言 效果图 代码示例 温馨提示 结束语 前言 最近在学习Flutter中 Canvas相关内容,今天尝试写了一个爱心Dem ...

  6. DXF笔记:线型CENTER的格式及绘制思想

    线型CENTER 查看线型文件acadiso.lin, 本次关注的是CENTER线型 *CENTER,Center ____ _ ____ _ ____ _ ____ _ ____ _ ____ A, ...

  7. DXF笔记:文字对齐的研究

    文字基线的概念 AutoCAD文字对齐类型 下表详细说明了组码 72(水平对齐)和组码 73(垂直对齐). 如果组 72 和/或 73 的值非零,则第一对齐点的值将被忽略,AutoCAD 将根据第二对 ...

  8. DXF笔记:多义线线宽的绘制思路

    线宽处理思路 核心思想为使用填充模式的多边形来模拟线宽 注:圆弧暂只支持等宽 绘制思路: 若是直线: 点线宽大于0,则沿直线垂直方向平移0.5线宽得到两点,否则直接取这个点.处理好后,直线有3种结果: ...

  9. DXF读写:对齐尺寸标注文字居中、上方的位置计算

    AutoCAD文字位置的规律 观察以下图形,得出结论 首先计算出文字中点,然后延着标注线垂直方向向上偏移指定距离.此处的关键是标注线的方向如何确定,通过研究,标注线方向并不等于标注第二点减去标注第一点 ...

最新文章

  1. iOS 设置View阴影
  2. 树上启动式合并问题 ---- D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths [状态压缩+树上启发式合并]
  3. 我所理解的Java NIO
  4. C语言signal()函数(通过设置一个函数(回调函数)来处理捕获到异常信号时需要执行的操作)
  5. SQL基础E-R图画法(一)
  6. 【Elasticsearch】改进布尔查询的搜索相关性
  7. 运行python脚本时出现no module named cv2怎么解决
  8. 分布式文件系统FastDFS架构辨析,分布式文件系统FastDFS_V4.06安装部署
  9. 解决Mybatis-plus高版本不向后兼容的问题
  10. C/C++ 安全编码 —— 不安全的函数
  11. Spring Boot 集成 MyBatis (注解版 与 xml 配置版)
  12. 直线回归和相关------(四)直线相关系数和决定系数(原理与公式推导)
  13. 今天正式入伏了,最全的三伏开运养生习俗都在这里了!!
  14. 程序识别验证码图片(一)
  15. vue屏幕分辨率适配实战解析
  16. 深度解析JavaScript原型链
  17. 一部适合有一点点lingo编程基础的人阅读的lingo入门教程——重学lingo,发现很多遗忘的小知识,并将其整理成册——运算符、数学函数、金融函数、概率密度函数、变量定界与集操作函数
  18. MATLAB入门教程(4):矩阵的生成
  19. 一分钟轻松解决阿里云盘无法分享压缩包问题
  20. nCode:DesignLife案例教程十三

热门文章

  1. C#对象序列化、反序列化、保存、读取、对象直接保存、读取
  2. 几何光学学习笔记(19)- 5.2光学系统的孔径光阑、入射光瞳和出射光瞳
  3. vue3警告: [Vue warn]: Component inside renders non-element root node that cannot be animat
  4. 樱花雨html,樱花雨
  5. DataGrid控件用法详解
  6. java url substring,Java截取字符串方法subString方法
  7. [信息学奥赛一本通][POJ 2251]地牢大师
  8. 练习——制作懂车帝-视频播放页面(导航栏定位布局+内容div布局且浮动)
  9. 课后作业--Python语言打印菱形(奇、偶数行效果)
  10. Python-自动化测试-多表单