[mxcad_2d API documentation] (../README. md)/[2d] (../modules/2d. md)/MxCompare
Class: MxCompare
2d.MxCompare
MxCompare is used to compare the differences between the current CAD display content and the benchmark database.
Description
This class will perform drawing comparison operations, identify differences in objects such as adding, deleting, and modifying, and return comparison results. It is suitable for scenarios such as version review, difference labeling, and change checking. Summary of usage:
- Create an 'MxCompare' instance;
- Call 'do (base_database)' to perform comparison;
- Call
getResult()to obtain the comparison result, and useregenDisplay ()to visualize the differences.
Example
import { MxCpp, MxCompare } from "mxcad";
function Mx_MxCompare() {
let mxcad = MxCpp.getCurrentMxCAD();
//Load the drawings to be compared and the current background into the current memory for easy viewing of differences
let fileUrl = new URL("../assets/testbj.dwg.mxweb", import.meta.url).href;
mxcad.mxdraw.makeCurrent();
mxcad.loadDwgBackground(fileUrl, (isok: boolean) => {
let backgroundEntity = mxcad.getBackgroundEntity();
//Temporarily hide the display of background drawings.
backgroundEntity.setShow(fileUrl, false);
let database = backgroundEntity.getBackgroundDatabase(fileUrl);
if (database == null) {
return;
}
//Start comparing the current drawing with the background drawing.
let cmp = new MxCompare();
if (cmp.do(database)) {
//Obtain comparative results
let result = cmp.getResult();
if (result.length > 0) {
//If there are differences, display the base map to better see the differences.
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
Compare the content displayed by the current control with the base_database drawing.
Among them, base_database can be regarded as the original drawing, and newly drawn objects on the current control will be considered as new content.
Parameters
| Name | Type | Description |
|---|---|---|
| Base_database | [McDbDatabase] (2d. McDbDatabase. md) | Original drawing database. |
Returns
boolean
Whether the comparison was successfully executed.
getResult
▸ getResult(): any[]
Obtain the comparison results of the drawings Return result [{"id": ID of the modified object, "id_current": ID of the object on the current drawing, "id_mase": ID of the object on the original drawing, "pos": modification location, "type": modification method, "str": modification description} ..]
Returns
any[]
regenDisplay
▸ regenDisplay(strColor?): boolean
Generate a new display based on the current comparison results and label the differences with different colors.
-Modify objects with pink annotations; -New objects are marked in green; -Delete objects marked in red.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
strColor | string | " | Optional color configuration string, for example: |
Returns
boolean
Whether the redraw was successfully executed.
