在网页中如何作比较?当有两个控件时。
MxDraw网页开发|黄洪辉|2018-05-07 10:03
-
回答:
实现图纸比较功能,首先将两个控件放入网页中,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代码如下:
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 + "对象被增加");