码迷,mamicode.com
首页 > 其他好文 > 详细

梦想CAD控件关于比较问题

时间:2019-05-14 10:59:58      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:链表   sage   res   mode   内容   center   toolbar   alt   ESS   

全图比较

怎么比较两个CAD图纸文件修改前后的不同部分呢?在工程图纸设计中,我们更多情况下可能需要对同一张工程图的前后修改部分进行对比,以确定工程图纸的改动部分及追溯原因,本教程演示了几种常见的比较方法。


实现图纸比较功能,首先将两个控件放入网页中,js代码如下:


<p align="center">
 
  <object classid="clsid:74A777F8-7A8F-4e7c-AF47-7074828086E2" id="MxDrawXCtrl1"  codebase="http://www.mxdraw.com/MxDrawX52.CAB#version=7.0.0.1" width=48% height=85% align="left">
    <param name="_Version" value="65536">
    <param name="_ExtentX" value="24262">
    <param name="_ExtentY" value="16219">
    <param name="_StockProps" value="0">
    <param name="IsRuningAtIE" value="1">
    <param name="EnablePrintCmd" value="1">
    <param name="ShowStatusBar" value="1">
    <param name="ShowMenuBar" value="1">
    <param name="ShowToolBars"  value="1">
    <param name="ShowCommandWindow" value="1">
    <param name="ShowModelBar" value="1">
    <param name="Iniset" value="AutoActive=N,LoadMrx=PropertyEditor">
 
    <param name="ToolBarFiles" value="MxDraw-ToolBar.mxt,MxDraw-ToolBar-DrawParam.mxt,MxDraw-ToolBar-Draw.mxt,MxDraw-ToolBar-Edit.mxt">
    <SPAN STYLE="color:red">不能装载CAD控件。请确认你可以连接网络或者检查浏览器的选项中安全设置。<a href="http://www.mxdraw.com/MxDrawX52.msi">http://www.mxdraw.com/MxDrawX52.msi 安载CAD控件</a></SPAN>
  </object>
  <object classid="clsid:74A777F8-7A8F-4e7c-AF47-7074828086E2" id="MxDrawXCtrl2"  codebase="http://www.mxdraw.com/MxDrawX52.CAB#version=7.0.0.1"width=48% height=85% align="right">
    <param name="_Version" value="65536">
    <param name="_ExtentX" value="24262">
    <param name="_ExtentY" value="16219">
    <param name="_StockProps" value="0">
    <param name="IsRuningAtIE" value="1">
    <param name="EnablePrintCmd" value="1">
    <param name="ShowStatusBar" value="1">
    <param name="ShowMenuBar" value="1">
    <param name="ShowToolBars"  value="1">
    <param name="ShowCommandWindow" value="1">
    <param name="ShowModelBar" value="1">
    <param name="Iniset" value="AutoActive=N,LoadMrx=PropertyEditor">
 
    <param name="ToolBarFiles" value="MxDraw-ToolBar.mxt,MxDraw-ToolBar-DrawParam.mxt,MxDraw-ToolBar-Draw.mxt,MxDraw-ToolBar-Edit.mxt">
    <SPAN STYLE="color:red">不能装载CAD控件。请确认你可以连接网络或者检查浏览器的选项中安全设置。<a href="http://www.mxdraw.com/MxDrawX52.msi">http://www.mxdraw.com/MxDrawX52.msi 安载CAD控件</a></SPAN>
  </object>


首先通过id得到两个控件,返回控件的数据库对象,把两个控件里面不同的内容标记出来,具体实现js代码如下:


function AllCompare() {
    var ocx1 = document.getElementById("MxDrawXCtrl1");
    var ocx2 = document.getElementById("MxDrawXCtrl2");
 
    var database1 = ocx1.GetDatabase();
    var database2 = ocx2.GetDatabase();
 
    var filter = ocx1.NewResbuf();
    var compare1 = ocx1.NewComObject("IMxDrawCompare");
    //开始比较
    //参数一为比较时使用的原始文件 参数二为修改后的,新的文件 参数三为过滤条件
    compare1.Do(database1, database2, filter);
    //返回比较后,被修改的曲线id
    var aryDifferent1 = compare1.GetCurveIdsOfTheDifferent();
    //把修改的地方,标记出来
    //参数一为缩放比例
    //参数二为当前图纸,是新修改的图纸,该变量为true,那么在原图不能找到的对象,为新增加对象
    compare1.DrawFlag(1.0,false);
    // 反过来比较一下,用来确定,那些对象是新增加的。
    var compare2 = ocx1.NewComObject("IMxDrawCompare");
 
    compare2.Do(database2, database1, filter);
 
    var aryDifferent2 = compare2.GetCurveIdsOfTheDifferent();
 
    compare2.DrawFlag(1.0,true);
 
    var iErase = 0;
    var iModify = 0;
    var iAdd = 0;
 
    for (var i = 0;i < aryDifferent1.Count; i++)
    {
        //返回链表中的指定位置的对象id
        var lId = aryDifferent1.AtObjectId(i);
        //返回比较后,被修改的曲线的位置。用于图上标记被修改的对象
        if(compare1.GetIsErase(lId))
        {
            iErase = iErase + 1;
        }
        else
        {
            iModify = iModify +1;
        }
    }
    for(var i = 0; i < aryDifferent2.Count;i++)
    {
        var lId = aryDifferent2.AtObjectId(i);
        if(compare2.GetIsErase(lId))
        {
            iAdd = iAdd + 1;
        }
    }
 
    var modfColor = ocx1.NewComObject("IMxDrawModifyTheColor");
    modfColor.Do(ocx1.GetDatabase(),3289650);
    //把指定实体颜色
    modfColor.DoEntity(aryDifferent1,255);
 
    alert(iModify + "对象修改," + iErase + "对象删除," + iAdd + "对象被增加");
}


选择范围比较

首先通过id得到两个控件,返回控件的数据库对象,把两个控件里面不同的内容标记出来,具体实现js代码如下:


function DoImpCompare(points, filter) {
 
    var ocx1 = document.getElementById("MxDrawXCtrl1");
    var ocx2 = document.getElementById("MxDrawXCtrl2");
 
    var database1 = ocx1.GetDatabase();
    var database2 = ocx2.GetDatabase();
 
    var compare1 = ocx1.NewComObject("IMxDrawCompare");
    compare1.Bound = points;
 
    compare1.Do(database1, database2, filter);
 
    var aryDifferent1 = compare1.GetCurveIdsOfTheDifferent();
 
    compare1.DrawFlag(1.0, false);
    // 反过来比较一下,用来确定,那些对象是新增加的。
    var compare2 = ocx1.NewComObject("IMxDrawCompare");
    compare2.Bound = points;
    compare2.Do(database2, database1, filter);
 
    var aryDifferent2 = compare2.GetCurveIdsOfTheDifferent();
     
    compare2.DrawFlag(1.0, true);
     
    var iErase = 0;
    var iModify = 0;
    var iAdd = 0;
    for (var i = 0; i < aryDifferent1.Count; i++) {
        var lId = aryDifferent1.AtObjectId(i);
        if (compare1.GetIsErase(lId)) {
            iErase = iErase + 1;
        }
        else {
            iModify = iModify + 1;
        }
    }
    for (var i = 0; i < aryDifferent2.Count; i++) {
        var lId = aryDifferent2.AtObjectId(i);
        if (compare2.GetIsErase(lId)) {
            iAdd = iAdd + 1;
        }
    }
    alert(iModify + "对象修改," + iErase + "对象删除," + iAdd + "对象被增加");
}


用户可以选取范围内的图纸作比较,具体实现js代码如下:


function BoundCompare() {
 
    var ocx1  = document.getElementById("MxDrawXCtrl1");
    var getPt = ocx1.NewComObject("IMxDrawUiPrPoint");
    getPt.message = "点取第一点";
    if(getPt.go() != 1)
        return;
    var frstPt = getPt.value();
    var getCorner = ocx1.NewUtility();
    var secondPt =  getCorner.GetCorner(frstPt,"点取第二点:");
    if(secondPt == null)
        return;
    var points = ocx1.NewComObject("IMxDrawPoints");
    points.Add2(frstPt);
    points.Add2(secondPt);
    var filter = ocx1.NewResbuf();
    DoImpCompare( points, filter);
}


选择圆形范围比较

通过圆形范围把两个控件里面不同的内容标记出来,首先需要动态画一个圆,具体实现js代码如下:


  function DoDynWorldDrawFun(dX, dY, pWorldDraw, pData) {
    var sGuid = pData.Guid;
    var ocx1 = document.getElementById("MxDrawXCtrl1");
    ocx1.SetEventRet(0);
    if (sGuid == "DrawCircle") {
        var pt1 = pData.GetPoint("pt1");
        if (pt1 == null)
            return;
        var pt2 = ocx1.NewPoint();
        pt2.x = dX;
        pt2.y = dY;
        var dR = pt1.DistanceTo(pt2);
        pWorldDraw.DrawCircle(pt1.x, pt1.y, dR);
    }
 
}


用户可以选取圆形范围内的图纸作比较,具体实现js代码如下:


function CircleCompare() {
    var mxOcx  = document.getElementById("MxDrawXCtrl1");
    var getPt1 = mxOcx.NewComObject("IMxDrawUiPrPoint");
    getPt1.message = "指定圆心";
    if (getPt1.go() != 1) {
        return;
    }
    var getPt2 = mxOcx.NewComObject("IMxDrawUiPrPoint");
    getPt2.message = "指定圆上一点";
    getPt2.basePoint = getPt1.value();
    var spDrawData = getPt2.InitUserDraw("DrawCircle");
    spDrawData.SetPoint("pt1", getPt1.value());
    getPt2.setUseBasePt(true);
    if (getPt2.go() != 1) {
        return;
    }
    var cen = getPt1.value();
    var pt2 = getPt2.value();
    var dR = cen.DistanceTo(pt2);
    var circle = mxOcx.NewEntity("IMxDrawCircle");
    circle.Center = cen;
    circle.Radius = dR;
    var points = circle.GetSamplePoints(0.1);
 
    if (points.Count < 3) {
        alert("圆太小");
    }
    var filter = mxOcx.NewResbuf();
    DoImpCompare(points, filter);
}

梦想CAD控件关于比较问题

标签:链表   sage   res   mode   内容   center   toolbar   alt   ESS   

原文地址:https://www.cnblogs.com/yzy0224/p/10860937.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!