知识库 / Java开发 / 详情
如何实现自定义实体?
如何实现自定义实体?
Java开发|大少爷|2017-07-26 14:45
回答:

参考例子 :Src\MxDraw5.2\samples\ie\iedemoTest.htm

 

1) 增加自定义实体对象

调用DrawCustomEntity函数,绘制一个自定义实体对象

函数说明如下:

1.png 

JS例子,下面代码绘制一个自定义实体,设置了两个属性,属性名分别 startpoint, endpoint的两个点坐标,

 

// 插入自定义实体函数

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);

};

 

2) 响应自定义事件,绘制自定义实体

需要响应DMxDrawXEvents::CustomEntity_Explode事件

帮助如下:

 1.png

 

JS例子,下面例子,得到自实体的数据,根据自定义实体的两个必属,开始点,和结束点绘制一个直线

      

// 自定义实体绘制函数

function ExplodeFun(pCustomEntity, pWorldDraw) {

 

 

    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=" + formatNumber(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);

 

    }

}

3) 响应自定义事件,返回自定义实体夹点

 

需要响应_DMxDrawXEvents::CustomEntity_getGripPoints事件

帮助如下:

 1.png

JS例子,返回自定义实体的开始夹点,和结束夹点。

// 返回自定义实体夹点

function GetGripPointsFun(pCustomEntity) {

 

    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 ret = mxOcx.NewResbuf();

 

        ret.AddPoint(stp);

        ret.AddPoint(ept);

 

        mxOcx.SetEventRetEx(ret);

    }

}

4) 响应自定义事件,夹点移动后的处理

 

需要响应CustomEntity_moveGripPointsAt事件

帮助如下:

1.png 

JS例子,夹点移动后,修改自定义实体的属性

  // 移动自定义实体夹点

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

 

    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;

 

 

        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);

    }

}


相关问题
如何设置动态提示?
如何设置光标矩形框大小?
如何设置光标长度?
如何设置对象夹点显示颜色?
如何把DWG文件当着背景导入?
如何设置绘光栅图到背景?
如何设置视区背景色为渐变色?
如何设置设置视区背景色?
如何设置进度条的范围?
如何设置进度条显示的位置?
梦想CAD是专业的CAD插件(控件),可轻松在网页、手机及BS/CS程序中浏览编辑DWG文件,不需安装AutoCAD即可运行。经十余年累积已非常稳定可靠,有关键的空间搜索算法,并使用汇编优化,可同时处理50万级实体,有非常高的图形显示和处理效率。
技术服务
TEL:400-888-5703
185-8173-1060
客服I QQ: 3570505660
技术I QQ: 827867134
技术II QQ:6884123
产品购买
TEL:156-8136-8971
QQ:710714273
用户交流
控件QQ交流群1:73281982
控件QQ交流群2:112199959
MxCAD软件群 1:515771658
技术I:QQ
827867134
客服I:QQ
3570505660
销售QQ
710714273
联系电话400-888-5703