mxcad_2d API 文档 / 2d / MxCompare
Class: MxCompare
2d.MxCompare
MxCompare 用于比较当前 CAD 显示内容与基准数据库之间的差异。
Description
该类会执行图纸比较操作,识别新增、删除、修改等对象差异,并返回对比结果。 它适用于版本审查、差异标注、变更检查等场景。 使用方法总结:
- 创建
MxCompare实例; - 调用
do(base_database)执行比较; - 调用
getResult()获取比较结果,并可使用regenDisplay()可视化差异。
Example
ts
import { MxCpp, MxCompare } from "mxcad";
function Mx_MxCompare() {
let mxcad = MxCpp.getCurrentMxCAD();
// 把要比较的图纸,当前背景加载当前内存中,方便查看不样的地方.
let fileUrl = new URL("../assets/testbj.dwg.mxweb", import.meta.url).href;
mxcad.mxdraw.makeCurrent();
mxcad.loadDwgBackground(fileUrl, (isok: boolean) => {
let backgroundEntity = mxcad.getBackgroundEntity();
// 暂时隐藏背景图纸的显示。
backgroundEntity.setShow(fileUrl, false);
let database = backgroundEntity.getBackgroundDatabase(fileUrl);
if (database == null) {
return;
}
// 开始把当前图纸与背景图纸进行比较。
let cmp = new MxCompare();
if (cmp.do(database)) {
// 得到比较结果.
let result = cmp.getResult();
if (result.length > 0) {
//比较有差别,把底图显示出来,方更查看不一样的地方。
backgroundEntity.setShow(fileUrl, true);
}
let colors = { "add_color": 0xFF0000, "erase_color": 0x00FF00, "modify_color": 0x0000FF, "not_modify_color": 0x505050 };
cmp.regenDisplay(JSON.stringify(colors));
mxcad.updateDisplay();
console.log(JSON.stringify(result));
}
}, 0xc90696969, false)
}Table of contents
Constructors
Methods
Constructors
constructor
• new MxCompare()
Methods
do
▸ do(base_database): boolean
把当前控件显示的内容和 base_database 的图纸进行比较。
其中 base_database 可视为原始图纸,当前控件上新增绘制的对象会被视为新增内容。
Parameters
| Name | Type | Description |
|---|---|---|
base_database | McDbDatabase | 原始图纸数据库。 |
Returns
boolean
是否成功执行比较。
getResult
▸ getResult(): any[]
得到图纸比较结果 返回结果[{"id":被修改对象的id,"id_current":当前图纸该对象id,"id_base":原始图纸,该对象id,"pos":修改位置,"type":修改方式,"str":修改说明},...]
Returns
any[]
regenDisplay
▸ regenDisplay(strColor?): boolean
根据当前比较结果重新生成显示,并以不同颜色标注差异位置。
- 修改对象用粉色标注;
- 新增对象用绿色标注;
- 删除对象用红色标注。
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
strColor | string | "" | 可选的颜色配置字符串,例如: |
Returns
boolean
是否成功执行重绘。
