天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 5|回复: 0

arx 文字对齐

[复制链接]
  • TA的每日心情
    开心
    昨天 15:23
  • 签到天数: 69 天

    [LV.6]常住居民II

    410

    主题

    167

    回帖

    2704

    积分

    管理员

    积分
    2704
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    Acad::ErrorStatus setAlignmentPoint(AcDbText &text, const AcGePoint3d &pt)
    {
            if (!text.isWriteEnabled())
                    return Acad::eNotOpenForWrite;

            AcDb::TextHorzMode hmode = text.horizontalMode();
            AcDb::TextVertMode vmode = text.verticalMode();

            if ((hmode == AcDb::kTextLeft) && (vmode == AcDb::kTextBase))
                    return text.setPosition(pt);                // only here position() is relevant and alignmentPoint() not
            else
                    return text.setAlignmentPoint(pt);        // here alignmentPoint() is relevant
    }

    AcGePoint3d getAlignmentPoint(const AcDbText &text)
    {
            AcDb::TextHorzMode hmode = text.horizontalMode();
            AcDb::TextVertMode vmode = text.verticalMode();

            if ((hmode == AcDb::kTextLeft) && (vmode == AcDb::kTextBase))
                    return text.position();                  // only here position() is relevant and alignmentPoint() not
            else
                    return text.alignmentPoint(); // here alignmentPoint() is relevant
    }

    void cmdTestText()
    {
            ads_point    pt;
            ads_name     ent;
            AcDbObjectId objId;

            if (acedEntSel(_T("\nSelect Text: "), ent, pt) != RTNORM)
                    return;

            if (acdbGetObjectId(objId, ent) != Acad::eOk) //ads_name-->AcDbObjectId
                    return;

            Acad::ErrorStatus es;
            AcDbText *pText = NULL;
            AcDbText *pText2 = NULL;
            AcGePoint3d     ptAlign;
            AcGeVector3d        vNormal;
            double          rot = 0.0;
            Adesk::Boolean bMirrX=false, bMirrY=false;

            if ( (es=acdbOpenObject(pText, objId, AcDb::kForRead)) == Acad::eOk )
            {
                    pText2 = AcDbText::cast(pText->clone()); // Create a clone
                    pText2->setDatabaseDefaults();
                    pText2->setColorIndex(1); //red
                    pText2->mirrorInX(false);
                    pText2->mirrorInY(false);

                    ptAlign = getAlignmentPoint(*pText);
                    vNormal = pText->normal();
                    rot = pText->rotation();

                    bMirrX = pText->isMirroredInX();
                    bMirrY = pText->isMirroredInY();
                    pText->close();               
            }

            AcGeVector3d vx, vy, vz(vNormal);
            vx = vz.perpVector();
            vy = (vz.crossProduct(vx)).normalize();

            AcGeVector3d vxRot(vx);
            vxRot.rotateBy(rot, vz); // The rotated x-Axis

            AcGeMatrix3d mat;
            mat.setCoordSystem(ptAlign, vx, vy, vz);

            bool bNeedZMirror = false;

            if (bMirrX)
            {
                    bNeedZMirror = !bNeedZMirror;
                    AcGePlane planeXZ(ptAlign, AcGeVector3d::kYAxis);
                    AcGeMatrix3d matMirrY;
                    matMirrY.setToMirroring(planeXZ);
                    mat.preMultBy(matMirrY);
            }
            if (bMirrY)
            {
                    bNeedZMirror = !bNeedZMirror;
                    AcGePlane plane(ptAlign, AcGeVector3d::kXAxis);
                    AcGeMatrix3d matMirr;
                    matMirr.setToMirroring(plane);
                    mat.preMultBy(matMirr);
            }
            if (bNeedZMirror)
            {
                    // Make sure that mat is not mirroring
                    AcGePlane plane(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis);
                    AcGeMatrix3d matMirr;
                    matMirr.setToMirroring(plane);
                    mat.preMultBy(matMirr);
            }

            AcGeVector3d vx2, vy2, vz2;
            AcGePoint3d origin;
            mat.getCoordSystem(origin, vx2, vy2, vz2);

            // Calculate rotation value of vxRot with respect to vx2 and vz2
            double rot2 = vx2.angleTo(vxRot, vz2);

            // Create a second Text entity without mirroring
            pText2->setNormal(vz2);
            pText2->setRotation(rot2);
            postToDb(pText2);
            es = setAlignmentPoint(*pText2, ptAlign);
            es = pText2->adjustAlignment();
            pText2->close();

     

     

     

     

    arx 文字对齐
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池|

    GMT+8, 2024-7-1 05:52 , Processed in 0.062503 second(s), 23 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表