尺寸标注用来在项目中显示距离和尺寸的专有元素。

7.3.1 尺寸标注类型

尺寸标注主要有五种类型:线性标注、连续线性标注、对齐标注、角度标注、弧长标注,具体标注对象类见表7-4。

表7-4 尺寸标注对象列表

线性标注对象 BPDimensionLinear
连续线性标注对象 BPDimensionLinearContinuous
对齐标注对象 BPDimensionAligned
角度标注对象 BPDimensionAngle
弧长标注对象 BPDimensionArcLength

7.3.2 尺寸标注样式

对于所有尺寸标注,可通过标注样式类BPDimensionStyle设置标注样式,常用接口见表7-5,可根据需要设置相应的样式。

表7-5 尺寸标注样式接口

方法 描述
getName,setName 标注样式名称
static BPDimensionStylePtr getByName(WCharCP name, BPProjectR project) 根据名称获取标注样式
static BPDimensionStylePtr getActive() 获取当前标注样式
static StatusInt setActive(BPDimensionStyleR dimStyle) 设置当前标注样式
dimclrd,setDimclrd 尺寸线-颜色
dimltype,setDimltyp 尺寸线-线型
dimlwd,setDimlwd 尺寸线-线宽
dimclre,setDimclre 尺寸界线-颜色
dimltex1, setDimltex1 尺寸界线-线型
dimlwe, setDimlwe 尺寸界线-线宽
dimse1,setDimse1 尺寸界线1-是否显示
dimse2,setDimse2 尺寸界线2-是否显示
dimasz,setDimasz 符号和箭头-箭头大小
dimtxtWidth, setDimtxtWidth 文字-文字外观-文字宽度
dimtxt,setDimtxt 文字-文字外观-文字高度
dimtxtsty,setDimtxtsty 文字-文字外观-文字样式
dimclrt,setDimclrt 文字-文字外观-文字颜色
dimgap1,setDimgap1 文字-文字外观-是否绘制文本框
dimtad,setDimtad 文字-文字位置-垂直
dimjust,setDimjust 文字-文字位置-水平

7.3.3 尺寸标注创建

尺寸标注创建的一般步骤为:如果没有符合需求的标注样式需先创建标注样式;然后通过尺寸标注的构造函数创建标注对象;设置标注对象的标注样式;最后根据需求使用该标注对象。

  • 线性标注
    示例代码7-3以绘制线段为例,在绘制线段过程中动态显示线性标注,示例代码中根据传入的点,绘制两点线段的线性标注。
BPGraphicsPtr ToolLayoutLineDemo::__dynamicDimension(GePoint3d ptFirst, GePoint3d ptSecond)
{
BIMBase::Core::BPProjectP pProject = BIMBase::Core::BPApplication::getInstance().getProjectManager()->getMainProject();
    if (pProject == nullptr)
        return nullptr;
    //标注样式
    BIMBase::Core::BPDimensionStylePtr ptrDimensionStyle = BIMBase::Core::BPDimensionStyle::create(L"线性标注样式范例", *pProject);
    if (ptrDimensionStyle.isNull())
        return nullptr;
    ptrDimensionStyle->setDimtad(1);
    ptrDimensionStyle->setDimse1(true);
    ptrDimensionStyle->setDimse2(true);
    ptrDimensionStyle->setDimdec(0);
    ptrDimensionStyle->setDimrnd(0);
    ptrDimensionStyle->setDimscale(1);
    ptrDimensionStyle->setDimtxt(1000);
    ptrDimensionStyle->setDimasz(500);

    BIMBase::BPColorDef colorDef;
    colorDef.m_rgba.red = 125;
    colorDef.m_rgba.green = 125;
    colorDef.m_rgba.blue = 125;
    UInt32 colorInt = BPColorUtil::getEntityColor(colorDef, *pProject, true);
    ptrDimensionStyle->setDimclrd(colorInt);
    ptrDimensionStyle->replace(L"线性标注样式范例", pProject);
    //绘制选中对象的标注
    BIMBase::Data::BPPlacement dimPlace;
    GePoint3d xLine1Point = ptFirst;
    GePoint3d xLine2Point = ptSecond;
    GeVec3d dirVec = GeVec3d::createByStartEndNormalize(xLine1Point, xLine2Point);
    double ang = GeVec3d::create(1., 0., 0.).angleTo2D(dirVec);
    GeVec3d vOffset = dirVec;
    vOffset.rotate2D(PI/2);
    vOffset = vOffset * 2000;
    GePoint3d textPoint = xLine1Point;
    dirVec = dirVec * 0.5;
    textPoint = textPoint + vOffset;
    //根据计算信息构造直线标注,第6个参数传入不为空时,标注上显示传入的值
    BIMBase::Data::BPDimensionLinear linearDim(dimPlace, textPoint, xLine1Point, xLine2Point, textPoint, L"", ang);
    linearDim.setDimstyle(L"线性标注样式范例");

    BPGraphicsPtr  ptrGraphics = linearDim.createPhysicalGraphics(*pProject, pProject->getActiveModel()->getModelId(), true);
    return ptrGraphics;
}

代码7-3:线性标注创建

线性标注效果如图所示:


图7-2 线性标注范例效果图
  • 对齐标注
    对齐标注接口类似线性标注,可参考线性标注进行创建。
  • 连续线性标注
    示例代码7-4以连续绘制线段为例,根据传入的点,绘制连续线性标注。
void ToolLayoutLineDemo::__dynamicContinueDimension(vector<GePoint3d> vctPoints)
{
    if (vctPoints.size() <= 1)
        return;
    BIMBase::Core::BPProjectP pProject = BIMBase::Core::BPApplication::getInstance().getProjectManager()->getMainProject();
    if (pProject == NULL)
        return;
    //标注样式
    BIMBase::Core::BPDimensionStylePtr ptrDimensionStyle = BIMBase::Core::BPDimensionStyle::create(L"连续线性标注样式范例",*pProject);
    if (ptrDimensionStyle.isNull())
        return;
    ptrDimensionStyle->setDimtad(1);
    ptrDimensionStyle->setDimse1(true);
    ptrDimensionStyle->setDimse2(true);
    ptrDimensionStyle->setDimdec(0);
    ptrDimensionStyle->setDimrnd(0);
    ptrDimensionStyle->setDimscale(1);
    ptrDimensionStyle->setDimtxt(1000);
    ptrDimensionStyle->setDimasz(500);

    BIMBase::BPColorDef colorDef;
    colorDef.m_rgba.red = 125;
    colorDef.m_rgba.green = 125;
    colorDef.m_rgba.blue = 125;

    UInt32 colorInt = BPColorUtil::getEntityColor(colorDef, *pProject, true);
    ptrDimensionStyle->setDimclrd(colorInt);
    ptrDimensionStyle->replace(L"连续线性标注样式范例", pProject);

    //参数计算
    BIMBase::Data::BPPlacement dimPlace;
    vector<GePoint3d> vctTextPoint;
    vector<PString> vctText;
    for (int i = 1; i < vctPoints.size(); i++)
    {
        GeVec3d dirVec = GeVec3d::createByStartEndNormalize(vctPoints[i - 1], vctPoints[i]);
        GeVec3d vOffset = dirVec;
        vOffset.rotate2D(PI / 2);
        vOffset = vOffset * 2000;
        GePoint3d textPoint = vctPoints[i - 1] + vOffset;
        vctTextPoint.push_back(textPoint);
        vctText.push_back(L"");
    }
    //根据计算信息构造连续线性标注
    BIMBase::Data::BPDimensionLinearContinuous linearDim(dimPlace, vctTextPoint,vctPoints, vctTextPoint.back(), vctText, 0);
    linearDim.setDimstyle(L"连续线性标注样式范例");
    linearDim.addToProject(*pProject,pProject->getActiveModel()->getModelId());
    }

代码7-4:连续线性标注创建

连续线性标注效果如图所示:



图7-3 连续线性标注范例效果图

- 弧线、角度标注
示例代码7-4以绘制弧线为例,在绘制线段过程中动态显示弧长或角度标注,示例代码中根据传入的弧线的起点、终点、弧上点确定标注。
BPGraphicsPtr ToolLayoutArcDemo::__dynamicDimension(GePoint3dCR ptFir, GePoint3dCR ptSec, GePoint3dCR ptArc, BPProjectP pProject, BPModelP pModel)
{
    //标注样式
    BIMBase::Core::BPDimensionStylePtr ptrDimensionStyle = BIMBase::Core::BPDimensionStyle::create(L"弧线标注样式范例", *pProject);
    if (ptrDimensionStyle.isNull())
        return NULL;
    ptrDimensionStyle->setDimtad(1);
    ptrDimensionStyle->setDimse1(true);
    ptrDimensionStyle->setDimse2(true);
    ptrDimensionStyle->setDimdec(0);
    ptrDimensionStyle->setDimrnd(0);
    ptrDimensionStyle->setDimscale(1);
    ptrDimensionStyle->setDimtxt(200);
    ptrDimensionStyle->setDimasz(500);

    BIMBase::BPColorDef colorDef;
    colorDef.m_rgba.red = 125;
    colorDef.m_rgba.green = 125;
    colorDef.m_rgba.blue = 125;
    UInt32 colorInt = BPColorUtil::getEntityColor(colorDef, *pProject, true);
    ptrDimensionStyle->setDimclrd(colorInt);
    ptrDimensionStyle->replace(L"弧线标注样式范例", pProject);
    //绘制选中对象的标注
    GePoint3d xLine1Point = ptFir;
    GePoint3d xLine2Point = ptSec;
    GeVec3d dirVec = GeVec3d::createByStartEndNormalize(xLine1Point, xLine2Point);
    GeVec3d dirVec1 = GeVec3d::createByStartEndNormalize(ptFir, ptArc);
    GeVec3d vOffset = dirVec;
    vOffset.rotate2D(PI / 2);
    vOffset = vOffset * 200;
    GePoint3d midPoint = xLine1Point + vOffset;
    //确保起点到终点为逆时针
    GeEllipse3d ell = GeEllipse3d::createByPointsOnEllipse(ptFir, ptArc, ptSec);
    GeVec3d vec0 = ell.vector0;
    GeVec3d vec90 = ell.vector90;
    double dSweep = ell.sweep;
    GeVec3d cf = GeVec3d::createByStartEnd(ell.center, ptFir);
    GeVec3d cs = GeVec3d::createByStartEnd(ell.center, ptSec);
    double ang1 = cf.signedAngleTo(cs, GeVec3d::create(0, 0, 1));
    if (ang1 < 0)
        ang1 = ang1 + 2 * PI;
    //弧长标注
    BIMBase::Data::BPDimensionArcLength arclength;
    arclength.setDimstyle(L"弧线标注样式范例");
    //角度标注
    BIMBase::Data::BPDimension3PAngle angledim;
    angledim.setDimstyle(L"弧线标注样式范例");
    if (abs(abs(ang1) - abs(dSweep)) > 0.001)//说明这个弧是顺时针
    {
        arclength.setPoints(ell.center, midPoint, ptSec, ptFir);
        angledim.setPoints(ell.center, midPoint, ptSec, ptFir);
    }
    else
    {
        arclength.setPoints(ell.center, midPoint, ptFir, ptSec);
        angledim.setPoints(ell.center, midPoint, ptFir, ptSec);
    }
    BPGraphicsPtr  ptrGraphics;
    if (m_nType == 0)
        ptrGraphics = angledim.createPhysicalGraphics(*pProject, pProject->getActiveModel()->getModelId(), true);
    else
        ptrGraphics = arclength.createPhysicalGraphics(*pProject, pProject->getActiveModel()->getModelId(), true);
    return ptrGraphics;
}

代码7-4:弧线、角度标注创建

角度标注效果如图所示:



图7-4 角度标注范例效果图