mxcad 1.0.151 → 1.0.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mxcad.d.ts CHANGED
@@ -2787,6 +2787,15 @@ export declare class McDbRasterImageDef extends McDbObject {
2787
2787
  set sourceFileName(sPathName: string);
2788
2788
  get sourceFileName(): string;
2789
2789
  }
2790
+ declare class MxAI {
2791
+ private serverUrl;
2792
+ private mapFun;
2793
+ init(serverUrl: string): void;
2794
+ addFunction(name: string, call: any): void;
2795
+ registTool(tool: any): void;
2796
+ reloadTools(param: any): void;
2797
+ chat_tool(str: string): void;
2798
+ }
2790
2799
  export declare enum FetchAttributes {
2791
2800
  EMSCRIPTEN_FETCH_LOAD_TO_MEMORY = 1,
2792
2801
  EMSCRIPTEN_FETCH_PERSIST_FILE = 4,
@@ -2810,7 +2819,18 @@ export declare class McObject {
2810
2819
  * @param imp 对象实现
2811
2820
  */
2812
2821
  constructor(imp: any);
2813
- on(name: string, fun: object): void;
2822
+ /** 监听对象选择事件
2823
+ * @example
2824
+ * ```ts
2825
+ * import { MxCpp } from mxdraw
2826
+ * MxCpp.getCurrentMxCAD().on("selectChange", (ids)=> {
2827
+ * let ent = id.getMcDbEntity()
2828
+ * if(!ent) return
2829
+ * console.log(ent.objectName)
2830
+ * })
2831
+ * ```
2832
+ * */
2833
+ on(name: "selectChange", fun: (ids: McObjectId[]) => void | ((ids: McObjectId[]) => void)[]): void;
2814
2834
  private callEvent;
2815
2835
  /**
2816
2836
  * 初始化对象模型
@@ -2853,6 +2873,10 @@ export declare class McObject {
2853
2873
  * @returns void
2854
2874
  * @example
2855
2875
  * ```typescript
2876
+ * import { McApp } from "mxcad"
2877
+ * let mxcad = MxCpp.getCurrentMxCAD();
2878
+ * let id = mxcad.drawLine(0,0,1000,1000);
2879
+ * mxcad.addCurrentSelect(id);
2856
2880
  * ```
2857
2881
  */
2858
2882
  addCurrentSelect(id: McObjectId): void;
@@ -2864,6 +2888,9 @@ export declare class McObject {
2864
2888
  * @returns void
2865
2889
  * @example
2866
2890
  * ```typescript
2891
+ * import { McApp, McGePoint3d } from "mxcad"
2892
+ * const mxcad = MxCpp.getCurrentMxCAD()
2893
+ * mxcad.zoomW(new McGePoint3d(0, 0), new McGePoint3d(30, 30))
2867
2894
  * ```
2868
2895
  */
2869
2896
  zoomW(minPt: McGePoint3d, maxPt: McGePoint3d): void;
@@ -2872,14 +2899,21 @@ export declare class McObject {
2872
2899
  * @returns void
2873
2900
  * @example
2874
2901
  * ```typescript
2902
+ * import { McApp, McGePoint3d } from "mxcad"
2903
+ * const mxcad = MxCpp.getCurrentMxCAD()
2904
+ * mxcad.zoomCenter(0, 0)
2875
2905
  * ```
2876
2906
  */
2877
2907
  zoomCenter(dCenX: number, dCenY: number): void;
2878
2908
  /**
2879
2909
  * 设置显示视区的角度,单位是PI.
2880
2910
  * @returns void
2911
+ * @param viewangle 旋转角度 Math.PI
2881
2912
  * @example
2882
2913
  * ```typescript
2914
+ * import { McApp } from "mxcad"
2915
+ * const mxcad = MxCpp.getCurrentMxCAD()
2916
+ * mxcad.zoomAngle(Math.PI / 2)
2883
2917
  * ```
2884
2918
  */
2885
2919
  zoomAngle(viewangle: number): void;
@@ -2898,11 +2932,17 @@ export declare class McObject {
2898
2932
  newFile(): boolean;
2899
2933
  /**
2900
2934
  * 插件图块文件
2901
- * @param sFileUrl 网络文件路径
2935
+ * @param sFileUrl 网络文件路径 该文件为mxweb格式
2902
2936
  * @param sBlkName 插入的图块的块名
2903
2937
  * @param isWorkThread 是否使用工作线程打开文件,默认为 true
2904
2938
  * @param fetchAttributes 1:EMSCRIPTEN_FETCH_LOAD_TO_MEMORY,把图纸数据加载内存中,0:EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_PERSIST_FILE | EMSCRIPTEN_FETCH_APPEND,把图纸数据加到IndexedDB。
2905
- */
2939
+ * @example
2940
+ * ```ts
2941
+ * import { MxCpp } from "mxcad"
2942
+ * const mxcad = MxCpp.getCurrentMxCAD()
2943
+ * const blkrecId = await mxcad.insertBlock("./blkrec.mxweb", "sBlkName");
2944
+ * ```
2945
+ */
2906
2946
  insertBlock(sFileUrl: string, sBlkName: string, isWorkThread?: boolean, fetchAttributes?: number): Promise<McObjectId>;
2907
2947
  /**
2908
2948
  * 获取当前文件名
@@ -2911,9 +2951,22 @@ export declare class McObject {
2911
2951
  getCurrentFileName(): string;
2912
2952
  /**
2913
2953
  * 将文件保存并转换为网络路径下载
2914
- * @param sSaveProgramUrl 要保存文件的路径
2915
- * @param call 保存文件的结果回调
2954
+ * @param sSaveProgramUrl 后端 POST请求接口, 接口具体实现: 先下载MxDraw云图开发包<https://www.mxdraw.com/download.html>并解压
2955
+ * 找到MxDrawCloudServer\Bin\MxCAD\MxCADSaveFile\server.js 可以找到对应的实现接口"/mxcad/savefiledwg",
2956
+ * 如果没有找到则在该项目下寻找这个接口的定义, 必须符合该接口的定义才能作为参数
2957
+ * @param call 保存文件的结果回调 这里接收到的参数请自己根据接口定义中保存图纸的位置, ref.file 不是完整请求路径,只是保存后的图纸名称
2916
2958
  * @returns 是否成功保存文件
2959
+ * @example
2960
+ * ```ts
2961
+ * import { MxCpp } from "mxcad"
2962
+ * const mxcad = MxCpp.getCurrentMxCAD()
2963
+ * MxCpp.getCurrentMxCAD().saveFileToUrl("http://localhost:3337/mxcad/savefiledwg", (iResult, sserverResult) => {
2964
+ * let ret = JSON.parse(sserverResult);
2965
+ * if (ret.ret == "ok") {
2966
+ * console.log(ret.file)
2967
+ * }
2968
+ * })
2969
+ * ```
2917
2970
  */
2918
2971
  saveFileToUrl(sSaveProgramUrl: string, call: (iResult: number, sServerResult: string) => void): boolean;
2919
2972
  /**
@@ -2923,6 +2976,15 @@ export declare class McObject {
2923
2976
  * @param isDownland 是否下载文件,默认为 true
2924
2977
  * @param isShowSaveFileDialog 是否显示保存文件对话框,默认为 true
2925
2978
  * @returns 是否成功保存文件
2979
+ * @example
2980
+ * ```ts
2981
+ * import { MxCpp } from "mxcad"
2982
+ * const mxcad = MxCpp.App.getCurrentMxCAD()
2983
+ * const fileName = mxcad.getCurrentFileName()
2984
+ * mxcad.saveFile("test", (data)=> {
2985
+ * const blob = new Blob([data.buffer], { type: "application/octet-stream" });
2986
+ * }, false, false)
2987
+ * ```
2926
2988
  */
2927
2989
  saveFile(filename?: string, call?: (data: any) => void, isDownland?: boolean, isShowSaveFileDialog?: boolean, parameter?: object): boolean;
2928
2990
  /**
@@ -3070,6 +3132,12 @@ export declare class McObject {
3070
3132
  /**
3071
3133
  * 添加图层
3072
3134
  * @param pszName 图层名称
3135
+ * @example
3136
+ * ```ts
3137
+ * import { McApp } from "mxcad"
3138
+ * const mxcad = McApp.getCurrentMxCAD()
3139
+ * mxcad.addLayer("图层名称")
3140
+ * ```
3073
3141
  */
3074
3142
  addLayer(string: string): McObjectId;
3075
3143
  /**
@@ -3403,7 +3471,7 @@ export declare class McObject {
3403
3471
  */
3404
3472
  getAllLayoutName(): McGeStringArray;
3405
3473
  /**
3406
- * 设置所有布局名
3474
+ * 设置当前布局名
3407
3475
  */
3408
3476
  setCurrentLayout(layoutName: string): void;
3409
3477
  /**
@@ -3449,6 +3517,12 @@ export declare class McObject {
3449
3517
  isTryVersion(): boolean;
3450
3518
  /**
3451
3519
  * 设置视区的背景色.
3520
+ * @example
3521
+ * ```ts
3522
+ * import { McApp } from "mxcad"
3523
+ * const mxcad = McApp.getCurrentMxCAD()
3524
+ * mxcad.setViewBackgroundColor(255, 255, 255)
3525
+ * ```
3452
3526
  */
3453
3527
  setViewBackgroundColor(red: number, green: number, blue: number): void;
3454
3528
  /**
@@ -3560,6 +3634,10 @@ export declare class MxCppType {
3560
3634
  */
3561
3635
  PropertiesWindow: MxPropertiesWindowCustom;
3562
3636
  /**
3637
+ * Mx AI实例
3638
+ */
3639
+ Ai: MxAI;
3640
+ /**
3563
3641
  * 获取上一次调用的结果
3564
3642
  * @returns {number} 调用结果
3565
3643
  */
package/dist/mxcad.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MxFun, MrxDbgUiPrPoint, MrxDbgUiPrDist, MrxDbgUiPrAngle, MrxDbgUiPrInt, MrxDbgUiPrKeyWord, MrxDbgUiPrString, DynamicInputType, MxCursorType, MrxDbgUtils, DetailedResult, MxDrawObject, store, loadCoreCode, MxPaintBrush, MrxDbgUiPrBaseReturn, MxDbCircleShape, MxDbEllipseShape } from 'mxdraw';
1
+ import { MxFun, MrxDbgUiPrPoint, MrxDbgUiPrDist, MrxDbgUiPrAngle, MrxDbgUiPrInt, MrxDbgUiPrKeyWord, MrxDbgUiPrString, DynamicInputType, MxCursorType, MrxDbgUtils, DetailedResult, MrxDbgUiPrBaseReturn, MxDrawObject, store, loadCoreCode, MxPaintBrush, MxDbCircleShape, MxDbEllipseShape } from 'mxdraw';
2
2
 
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
4
4
  try {
@@ -692,7 +692,7 @@ var MxG2312 = /*#__PURE__*/function () {
692
692
  }();
693
693
  var MxG2312Obj = new MxG2312();
694
694
 
695
- const version$1 = "1.0.151";
695
+ const version$1 = "1.0.152";
696
696
 
697
697
  var isSharedArrayBuffer = ("SharedArrayBuffer" in window);
698
698
  var isCdn = document.currentScript && /unpkg\.com\/mxcad/.test(document.currentScript.src);
@@ -4966,6 +4966,133 @@ var McDbRasterImage = /*#__PURE__*/function (_McDbEntity9) {
4966
4966
  return McDbRasterImage;
4967
4967
  }(McDbEntity);
4968
4968
 
4969
+ function angleTo(x1, y1, x2, y2) {
4970
+ var x = x1 - x2;
4971
+ var y = y1 - y2;
4972
+ var angle_temp = 0;
4973
+ if (x == 0) {
4974
+ angle_temp = Math.PI / 2;
4975
+ } else {
4976
+ angle_temp = Math.atan(Math.abs(y / x));
4977
+ }
4978
+ if (x < 0 && y >= 0) {
4979
+ angle_temp = Math.PI - angle_temp;
4980
+ } else if (x < 0 && y < 0) {
4981
+ angle_temp = Math.PI + angle_temp;
4982
+ } else if (x >= 0 && y < 0) {
4983
+ angle_temp = Math.PI * 2 - angle_temp;
4984
+ }
4985
+ return angle_temp;
4986
+ }
4987
+ var createProcess = function createProcess(getPoint, kOkCall, kKeyWordCall) {
4988
+ var fun = function fun() {
4989
+ getPoint.go(function (status) {
4990
+ if (status === MrxDbgUiPrBaseReturn.kKeyWord) {
4991
+ if (kKeyWordCall()) fun();
4992
+ }
4993
+ if (status === MrxDbgUiPrBaseReturn.kOk) {
4994
+ if (kOkCall()) fun();
4995
+ }
4996
+ if (status === MrxDbgUiPrBaseReturn.kNone) {
4997
+ fun();
4998
+ }
4999
+ if (status === MrxDbgUiPrBaseReturn.kCancel) {
5000
+ return {
5001
+ exit: true
5002
+ };
5003
+ }
5004
+ });
5005
+ };
5006
+ return fun;
5007
+ };
5008
+ function getHostUrl() {
5009
+ var host = window.location.hostname;
5010
+ if (host.substring(0, 4) != "http") {
5011
+ host = document.location.protocol + "//" + host;
5012
+ }
5013
+ return host;
5014
+ }
5015
+
5016
+ var MxAI = /*#__PURE__*/function () {
5017
+ function MxAI() {
5018
+ _classCallCheck(this, MxAI);
5019
+ _defineProperty(this, "serverUrl", "");
5020
+ _defineProperty(this, "mapFun", {});
5021
+ }
5022
+ _createClass(MxAI, [{
5023
+ key: "init",
5024
+ value: function init(serverUrl) {
5025
+ if (serverUrl.substring(0, 16) == "http://localhost") {
5026
+ serverUrl = getHostUrl() + serverUrl.substring(16);
5027
+ }
5028
+ this.serverUrl = serverUrl;
5029
+ }
5030
+ }, {
5031
+ key: "addFunction",
5032
+ value: function addFunction(name, call) {
5033
+ this.mapFun[name] = call;
5034
+ }
5035
+ }, {
5036
+ key: "registTool",
5037
+ value: function registTool(tool) {
5038
+ if (this.serverUrl.length == 0) return;
5039
+ var xhr = new XMLHttpRequest();
5040
+ var url = this.serverUrl + "/add_toolfun";
5041
+ xhr.open("POST", url);
5042
+ xhr.setRequestHeader("Content-Type", "application/json");
5043
+ xhr.send(JSON.stringify(tool));
5044
+ xhr.onreadystatechange = function () {
5045
+ if (xhr.readyState === 4 && xhr.status === 200) {
5046
+ console.log(xhr.responseText);
5047
+ }
5048
+ };
5049
+ }
5050
+ }, {
5051
+ key: "reloadTools",
5052
+ value: function reloadTools(param) {
5053
+ if (this.serverUrl.length == 0) return;
5054
+ var xhr = new XMLHttpRequest();
5055
+ var url = this.serverUrl + "/reload_toolfun";
5056
+ xhr.open("POST", url);
5057
+ xhr.setRequestHeader("Content-Type", "application/json");
5058
+ xhr.send(JSON.stringify(param));
5059
+ xhr.onreadystatechange = function () {
5060
+ if (xhr.readyState === 4 && xhr.status === 200) {
5061
+ console.log(xhr.responseText);
5062
+ }
5063
+ };
5064
+ }
5065
+ }, {
5066
+ key: "chat_tool",
5067
+ value: function chat_tool(str) {
5068
+ if (this.serverUrl.length == 0) return;
5069
+ var myThis = this;
5070
+ var data = {
5071
+ text: str
5072
+ };
5073
+ var xhr = new XMLHttpRequest();
5074
+ var url = this.serverUrl + "/post";
5075
+ xhr.open("POST", url);
5076
+ xhr.setRequestHeader("Content-Type", "application/json");
5077
+ xhr.send(JSON.stringify(data));
5078
+ xhr.onreadystatechange = function () {
5079
+ if (xhr.readyState === 4 && xhr.status === 200) {
5080
+ try {
5081
+ var ret = JSON.parse(xhr.responseText);
5082
+ var result = ret.results;
5083
+ if (result && result.name && myThis.mapFun[result.name]) {
5084
+ myThis.mapFun[result.name](result.parameters);
5085
+ }
5086
+ } catch (error) {
5087
+ console.log(error);
5088
+ }
5089
+ }
5090
+ };
5091
+ }
5092
+ }]);
5093
+ return MxAI;
5094
+ }();
5095
+
4969
5096
  var FetchAttributes = /* @__PURE__ */function (FetchAttributes2) {
4970
5097
  FetchAttributes2[FetchAttributes2["EMSCRIPTEN_FETCH_LOAD_TO_MEMORY"] = 1] = "EMSCRIPTEN_FETCH_LOAD_TO_MEMORY";
4971
5098
  FetchAttributes2[FetchAttributes2["EMSCRIPTEN_FETCH_PERSIST_FILE"] = 4] = "EMSCRIPTEN_FETCH_PERSIST_FILE";
@@ -5959,6 +6086,7 @@ var MxCppType = /*#__PURE__*/function () {
5959
6086
  _defineProperty(this, "mxcadassemblyimp", void 0);
5960
6087
  _defineProperty(this, "App", new McAppType());
5961
6088
  _defineProperty(this, "PropertiesWindow", new MxPropertiesWindowCustom());
6089
+ _defineProperty(this, "Ai", new MxAI());
5962
6090
  }
5963
6091
  _createClass(MxCppType, [{
5964
6092
  key: "getCallResult",
@@ -11315,46 +11443,6 @@ function _drawPolygon() {
11315
11443
  }
11316
11444
  MxFun.addCommand("Mx_Polygon", drawPolygon);
11317
11445
 
11318
- function angleTo(x1, y1, x2, y2) {
11319
- var x = x1 - x2;
11320
- var y = y1 - y2;
11321
- var angle_temp = 0;
11322
- if (x == 0) {
11323
- angle_temp = Math.PI / 2;
11324
- } else {
11325
- angle_temp = Math.atan(Math.abs(y / x));
11326
- }
11327
- if (x < 0 && y >= 0) {
11328
- angle_temp = Math.PI - angle_temp;
11329
- } else if (x < 0 && y < 0) {
11330
- angle_temp = Math.PI + angle_temp;
11331
- } else if (x >= 0 && y < 0) {
11332
- angle_temp = Math.PI * 2 - angle_temp;
11333
- }
11334
- return angle_temp;
11335
- }
11336
- var createProcess = function createProcess(getPoint, kOkCall, kKeyWordCall) {
11337
- var fun = function fun() {
11338
- getPoint.go(function (status) {
11339
- if (status === MrxDbgUiPrBaseReturn.kKeyWord) {
11340
- if (kKeyWordCall()) fun();
11341
- }
11342
- if (status === MrxDbgUiPrBaseReturn.kOk) {
11343
- if (kOkCall()) fun();
11344
- }
11345
- if (status === MrxDbgUiPrBaseReturn.kNone) {
11346
- fun();
11347
- }
11348
- if (status === MrxDbgUiPrBaseReturn.kCancel) {
11349
- return {
11350
- exit: true
11351
- };
11352
- }
11353
- });
11354
- };
11355
- return fun;
11356
- };
11357
-
11358
11446
  function calculateEndPoint(centerX, centerY, startX, startY, chordLength, radius) {
11359
11447
  var vectorX = startX - centerX;
11360
11448
  var vectorY = startY - centerY;