www.mxdraw.com
内容索引主面
前一个向上下一个
IMxDrawCompare 接口

用于图纸比较

IDL
[ object, uuid(1ADB8B40-FE30-4407-9D6E-C432E5FA6EA6), dual, nonextensible, helpstring("IMxDrawCompare interface"), pointer_default(unique) ]
interface IMxDrawCompare : IDispatch;

MxDrawCompare.idl

例如: 选择一个范围,进行比较 VC2005

        CString CCompareGraphics2Dlg::GetCompareLayer()
        {

            IDispatchPtr spDispatch(m_ocx1.GetDatabase(),false);
            IMxDrawDatabasePtr spDatabase1;
            spDispatch->QueryInterface(&spDatabase1);
            if(spDatabase1 == NULL)
                return _T("");

            // 得到所有图层名

            CString sRet;
            IMxDrawLayerTablePtr spLayerTable = spDatabase1->GetLayerTable();

            IMxDrawLayerTableIteratorPtr spIter = spLayerTable->NewIterator();

            for(;!spIter->Done();spIter->Step(VARIANT_TRUE,VARIANT_TRUE))
            {
                IMxDrawLayerTableRecordPtr spLayerRec = spIter->GetRecord();
                CString sName = spLayerRec->GetName();
                // 0零层不参加比较

                if(sName != "0")
                {
                    if(sRet.IsEmpty())
                        sRet = sName;
                    else
                    {
                        CString sTmp;
                        sTmp.Format(_T("%s,%s"),sRet,sName);
                        sRet = sTmp;
                    }
                }

            }

            return sRet;
        }

        CString sLayers = GetCompareLayer();

            IMxDrawResbufPtr spFilter;
            spFilter.CreateInstance(__uuidof( MxDrawXLib::MxDrawResbuf ));
            if(!sLayers.IsEmpty())
            {
                _bstr_t sBsLayers = sLayers.AllocSysString();
                spFilter->AddStringEx(sBsLayers,8);
            }




            MxDrawXLib::IMxDrawUiPrPointPtr getPt;
            getPt.CreateInstance(__uuidof( MxDrawXLib::MxDrawUiPrPoint ));

            IMxDrawUiPrPoint* pGetPt = getPt;
            pGetPt->put_message(_T("点取第一点"));
            if(pGetPt->go() != mcOk)
                return;

            IMxDrawPointPtr frstPt = pGetPt->value();
            if(frstPt == NULL)
                return;


            MxDrawXLib::IMxDrawUtilityPtr getCorner;
            getCorner.CreateInstance(__uuidof( MxDrawXLib::MxDrawUtility ));

            IMxDrawPointPtr secondPt =  getCorner->GetCorner(frstPt,_T("点取第二点:") );

            if(secondPt == NULL)
                return;

            MxDrawXLib::IMxDrawPointsPtr points;
            points.CreateInstance(__uuidof( MxDrawXLib::MxDrawPoints ));

            points->Add2(frstPt);
            points->Add2(secondPt);

            IDispatchPtr spDispatch(m_ocx1.GetDatabase(),false);
            IMxDrawDatabasePtr spDatabase1;
            spDispatch->QueryInterface(&spDatabase1);
            if(spDatabase1 == NULL)
                return;


            IDispatchPtr spDispatch2(m_ocx2.GetDatabase(),false);
            IMxDrawDatabasePtr spDatabase2;
            spDispatch2->QueryInterface(&spDatabase2);
            if(spDatabase2 == NULL)
                return;

            IMxDrawComparePtr compare;
            compare.CreateInstance(__uuidof( MxDrawXLib::MxDrawCompare));

            // 设置比较范围。
            compare->PutBound(points);

            // 开始比较。
            compare->Do(spDatabase1,spDatabase2,spFilter);

            IMxDrawResbufPtr aryDifferent = compare->GetCurveIdsOfTheDifferent();

            compare->DrawFlag(1.0);

            CString sT;
            sT.Format(_T("发现:%d个不同对象"),aryDifferent->GetCount() );
            AfxMessageBox(sT);

例如: JS代码,全图比较

    // 返回比较图层,除0层外。0层上的实体,不参加比较.
    function GetCompareLayer()
    {
        var mxocx = document.getElementById("MxDrawXCtrl1")
        var database = mxocx.GetDatabase();

        // 得到所有图层名
        var sRet = null;

        var spLayerTable = database.GetLayerTable();

        var spIter = spLayerTable.NewIterator();

        for(;!spIter.Done();spIter.Step(true,true))
        {
            var spLayerRec = spIter.GetRecord();
            var sName = spLayerRec.Name;
            // 0零层不参加比较

            if(sName != "0")
            {
                if(sRet == null)
                    sRet = sName;
                else
                {
    
                    sRet = sRet +","+sName;
                }
            }

        }

        return sRet;
    }
    function AllCompareDWG() {

        var ocx1 = document.getElementById("MxDrawXCtrl1");
        var ocx2 = document.getElementById("MxDrawXCtrl2");

        var database1 = ocx1.GetDatabase();
        var database2 = ocx2.GetDatabase();

        var filter = ocx1.NewResbuf();

        // 得到过滤的图层名
        var layers = GetCompareLayer();

        // 增加图层过滤.
        if (layers != null) {
            filter.AddStringEx(layers, 8);
        }


        var compare1 = ocx1.NewComObject("IMxDrawCompare");

        compare1.Do(database1, database2, filter);

        var aryDifferent1 = compare1.GetCurveIdsOfTheDifferent();

        compare1.DrawFlag(1.0);


        // 反过来比较一下,用来确定,那些对象是新增加的。
        var compare2 = ocx1.NewComObject("IMxDrawCompare");

        compare2.Do(database2, database1, filter);

        var aryDifferent2 = compare2.GetCurveIdsOfTheDifferent();

        compare2.DrawFlag(1.0);



        var iErase = 0;
        var iModify = 0;
        var iAdd = 0;
        var i = 0;

        for (;i < aryDifferent1.Count; i++)
        {
            var lId = aryDifferent1.AtObjectId(i);
            if(compare1.GetIsErase(lId))
            {
                iErase = iErase + 1;
            }
            else
            {
                iModify = iModify +1;
            }
        }

        i = 0;
        for(; 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 ocx2 = document.getElementById("MxDrawXCtrl2");
    var filter = ocx1.NewResbuf();
    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 database1 = ocx1.GetDatabase();
    var database2 = ocx2.GetDatabase();

    var compare = ocx1.NewComObject("IMxDrawCompare");

    compare.Bound = points;

    compare.Do(database1, database2, filter);

    var aryDifferent = compare.GetCurveIdsOfTheDifferent();

    compare.DrawFlag(1.0);

    alert("发现:" + aryDifferent.Count + "个不同对象");
}
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!