返回介绍

绘制自定义实体

发布于 2023-08-09 23:10:34 字数 5233 浏览 0 评论 0 收藏 0

js中实现代码说明:

自定义实体绘制函数:

function ExplodeFun(pCustomEntity, pWorldDraw, txt) {
    var mxOcx = document.getElementById("MxDrawXCtrl");
    var sGuid = pCustomEntity.Guid;
    if (sGuid == "TestMxCustomEntity") {
        if (!pCustomEntity.IsHave("ept"))
            return;
        var stp = pCustomEntity.GetPoint("spt");
        if (stp == null)
            return;
        var ept = pCustomEntity.GetPoint("ept");
        if (ept == null)
            return;
        var mxUtility = mxOcx.NewUtility();
        var vec = ept.SumVector(stp);
        vec.Mult(0.5);
        var midPt = mxOcx.NewPoint();
        midPt.x = stp.x;
        midPt.y = stp.y;
        midPt.Add(vec);
        var dAng = vec.Angle();
        //计算一个标注角度,使用文字对象始终头朝上
        dAng = mxUtility.GetDimAngle(dAng);
        var dDis = 0.0;
        dDis = stp.DistanceTo(ept);
        var sTxt = "L=" + Number(dDis, '#.##');
        dAng = dAng * 180.0 / 3.14159265;
        vec.RotateByXyPlan(3.14159265 / 2.0);
        vec.Normalize();
        vec.Mult(10);
        stp.Add(vec);
        ept.Add(vec);
        pWorldDraw.DrawLine(stp.x, stp.y, ept.x, ept.y);
        vec.Mult(2);
        stp.Sum(vec);
        ept.Sum(vec);
        pWorldDraw.DrawLine(stp.x, stp.y, ept.x, ept.y);
        pWorldDraw.SetColorIndex(1);
        pWorldDraw.DrawText(midPt.x, midPt.y, sTxt, 5, dAng,
            1, 2);
        mxOcx.SetEventRet(1);

    }
}

动态绘制文字:

function InsertCustomEntity() {

    var getPt = mxOcx.NewComObject("IMxDrawUiPrPoint");
    getPt.message = "点取第一点";
    if (getPt.go() != 1)
        return;
    var frstPt = getPt.value();
    if (frstPt == null)
        return;
    var getSecondPt = mxOcx.NewComObject("IMxDrawUiPrPoint");
    getSecondPt.message = "点取第二点";
    getSecondPt.basePoint = frstPt;
    getSecondPt.setUseBasePt(true);
    if (getSecondPt.go() != 1)
        return;
    var secondPt = getSecondPt.value();
    if (secondPt == null)
        return;
    var ent = mxOcx.DrawCustomEntity("TestMxCustomEntity", "");
    ent.SetPoint("spt", frstPt);
    ent.SetPoint("ept", secondPt);
};

返回自定义实体夹点:

function GetGripPointsFun(pCustomEntity) {
    var sGuid = pCustomEntity.Guid;
    if (sGuid == "TestMxCustomEntity1") {
        if (!pCustomEntity.IsHave("First"))
            return;
        var stp = pCustomEntity.GetPoint("First");
        var ept = pCustomEntity.GetPoint("BasePoint");
        var dimpt = pCustomEntity.GetPoint("DimPoint");
        var ret = mxOcx.NewResbuf();
        ret.AddPoint(stp);
        ret.AddPoint(ept);
        ret.AddPoint(dimpt);
        mxOcx.SetEventRetEx(ret);
    }
    if (sGuid == "TestMxCustomEntity") {
        if (!pCustomEntity.IsHave("ept"))
            return;

        var stp = pCustomEntity.GetPoint("spt");
        if (stp == null)
            return;

        var ept = pCustomEntity.GetPoint("ept");
        if (ept == null)
            return;

        var ret = mxOcx.NewResbuf();

        ret.AddPoint(stp);
        ret.AddPoint(ept);

        mxOcx.SetEventRetEx(ret);
    }
}

移动自定义实体夹点:

function MoveGripPointsFun(pCustomEntity, lGridIndex, dOffsetX, dOffsetY) {

    var sGuid = pCustomEntity.Guid;
    if (sGuid == "TestMxCustomEntity1") {
        if (!pCustomEntity.IsHave("First"))
            return;
        var stp = pCustomEntity.GetPoint("First");
        var ept = pCustomEntity.GetPoint("BasePoint");
        var dimpt = pCustomEntity.GetPoint("DimPoint");
        if (lGridIndex == 0) {
            stp.x = stp.x + dOffsetX;
            stp.y = stp.y + dOffsetY;
            pCustomEntity.SetPoint("First", stp);
        }
        else if (lGridIndex == 1)
        {
            ept.x = ept.x + dOffsetX;
            ept.y = ept.y + dOffsetY;
            pCustomEntity.SetPoint("BasePoint", ept);
        }
        else
        {
            dimpt.x = dimpt.x + dOffsetX;
            dimpt.y = dimpt.y + dOffsetY;
            pCustomEntity.SetPoint("DimPoint", dimpt);
        }
        mxOcx.SetEventRet(1);
    }
    if (sGuid == "TestMxCustomEntity") {
        if (!pCustomEntity.IsHave("ept"))
            return;

        var stp = pCustomEntity.GetPoint("spt");
        if (stp == null)
            return;

        var ept = pCustomEntity.GetPoint("ept");
        if (ept == null)
            return;


        if (lGridIndex == 0) {
            stp.x = stp.x + dOffsetX;
            stp.y = stp.y + dOffsetY;
            pCustomEntity.SetPoint("spt", stp);
        }
        else {
            ept.x = ept.x + dOffsetX;
            ept.y = ept.y + dOffsetY;
            pCustomEntity.SetPoint("ept", ept);
        }

        mxOcx.SetEventRet(1);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文