mxdraw 0.1.7 → 0.1.10

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.
@@ -1,4 +1,9 @@
1
1
  "use strict";
2
+ ///////////////////////////////////////////////////////////////////////////////
3
+ //版权所有(C)2002-2022,成都梦想凯德科技有限公司。
4
+ //本软件代码及其文档和相关资料归成都梦想凯德科技有限公司,应用包含本软件的程序必须包括以下版权声明
5
+ //此应用程序与成都梦想凯德科技有限公司成协议。通过使用本软件、其文档或相关材料
6
+ ///////////////////////////////////////////////////////////////////////////////
2
7
  /** @module MxDbEntity*/
3
8
  Object.defineProperty(exports, "__esModule", { value: true });
4
9
  var MxType_1 = require("../MxType");
@@ -25,8 +30,16 @@ var store_1 = require("../store/store");
25
30
  */
26
31
  var MxDbEntity = /** @class */ (function () {
27
32
  function MxDbEntity() {
28
- this.iColor = 0xffffff;
29
- this.iRenderOrder = 30;
33
+ this.color = 0xffffff;
34
+ this.renderOrder = 30;
35
+ /**
36
+ * opacity 设置透明度 0 ~ 1,1表示完全不透明,0表示全透明.
37
+ * */
38
+ this.opacity = 1;
39
+ /**
40
+ * visible 该矩形对象是否可见
41
+ * */
42
+ this.visible = true;
30
43
  }
31
44
  /**
32
45
  * 自定义实体的坐标变换.
@@ -66,6 +79,34 @@ var MxDbEntity = /** @class */ (function () {
66
79
  return false;
67
80
  }
68
81
  };
82
+ /**
83
+ * 返回对象所在的控件对象。
84
+ * @param
85
+ * @returns boolean
86
+ * @example
87
+ * ``` typescript
88
+ *
89
+ * ```
90
+ */
91
+ MxDbEntity.prototype.getMxObject = function () {
92
+ var imp = this.getImp();
93
+ if (imp)
94
+ return imp.getMxObject();
95
+ else
96
+ return null;
97
+ };
98
+ /**
99
+ * 视区显示比较发生成变化,继承类可以向应该事件,更新显示大小。
100
+ * @param
101
+ * @returns boolean
102
+ * @example
103
+ * ``` typescript
104
+ *
105
+ * ```
106
+ */
107
+ MxDbEntity.prototype.onViewChange = function () {
108
+ return false;
109
+ };
69
110
  /**
70
111
  * 得到对象的id.
71
112
  * @param
@@ -111,8 +152,8 @@ var MxDbEntity = /** @class */ (function () {
111
152
  *
112
153
  * ```
113
154
  */
114
- MxDbEntity.prototype.setColor = function (iColor) {
115
- this.iColor = iColor;
155
+ MxDbEntity.prototype.setColor = function (color) {
156
+ this.color = color;
116
157
  };
117
158
  /**
118
159
  * 得到颜色
@@ -124,7 +165,7 @@ var MxDbEntity = /** @class */ (function () {
124
165
  * ```
125
166
  */
126
167
  MxDbEntity.prototype.getColor = function () {
127
- return this.iColor;
168
+ return this.color;
128
169
  };
129
170
  /**
130
171
  * 复制对象。
@@ -147,16 +188,16 @@ var MxDbEntity = /** @class */ (function () {
147
188
  * @param obj dwgIn抽象方法的回调数据
148
189
  */
149
190
  MxDbEntity.prototype.onDwgIn = function (obj) {
150
- this.iColor = obj['iColor'];
151
- this.iRenderOrder = obj['iRenderOrder'];
191
+ this.color = obj['color'];
192
+ this.renderOrder = obj['renderOrder'];
152
193
  };
153
194
  /**
154
195
  * 自定义对象内部数据输出同步(实现dwgIn抽象方法 必须在实现中调用 this.onDwgIn()
155
196
  * @param obj dwgOut抽象方法的回调数据
156
197
  */
157
198
  MxDbEntity.prototype.onDwgOut = function (obj) {
158
- obj['iColor'] = this.iColor;
159
- obj['iRenderOrder'] = this.iRenderOrder;
199
+ obj['color'] = this.color;
200
+ obj['renderOrder'] = this.renderOrder;
160
201
  };
161
202
  /**
162
203
  * 初始自定义对象的类型信息.
@@ -180,8 +221,8 @@ var MxDbEntity = /** @class */ (function () {
180
221
  *
181
222
  * ```
182
223
  */
183
- MxDbEntity.prototype.setRenderOrder = function (iRenderOrder) {
184
- this.iRenderOrder = iRenderOrder;
224
+ MxDbEntity.prototype.setRenderOrder = function (renderOrder) {
225
+ this.renderOrder = renderOrder;
185
226
  };
186
227
  /**
187
228
  * 得到显示顺序
@@ -193,7 +234,7 @@ var MxDbEntity = /** @class */ (function () {
193
234
  * ```
194
235
  */
195
236
  MxDbEntity.prototype.getRenderOrder = function () {
196
- return this.iRenderOrder;
237
+ return this.renderOrder;
197
238
  };
198
239
  return MxDbEntity;
199
240
  }());
@@ -70,6 +70,7 @@ var MxDbImage = /** @class */ (function (_super) {
70
70
  }
71
71
  else if (this.imagePath.length > 0 && this.isLoadMaterialFromPath) {
72
72
  var myThis_1 = this;
73
+ var mxobj_1 = pWorldDraw.getMxObject();
73
74
  MxFun_1.default.loadImageMaterial(this.imagePath, function (material) {
74
75
  _this.isLoadMaterialFromPath = false;
75
76
  if (!material) {
@@ -77,7 +78,7 @@ var MxDbImage = /** @class */ (function (_super) {
77
78
  }
78
79
  myThis_1.setMaterial(material);
79
80
  myThis_1.setNeedUpdateDisplay();
80
- MxFun_1.default.updateDisplay();
81
+ mxobj_1.updateDisplay();
81
82
  });
82
83
  }
83
84
  }
@@ -26,11 +26,17 @@ var __assign = (this && this.__assign) || function () {
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ ///////////////////////////////////////////////////////////////////////////////
30
+ //版权所有(C)2002-2022,成都梦想凯德科技有限公司。
31
+ //本软件代码及其文档和相关资料归成都梦想凯德科技有限公司,应用包含本软件的程序必须包括以下版权声明
32
+ //此应用程序与成都梦想凯德科技有限公司成协议。通过使用本软件、其文档或相关材料
33
+ ///////////////////////////////////////////////////////////////////////////////
29
34
  var MxDbEntity_1 = require("../MxDbEntity");
30
35
  var three_1 = require("three");
31
36
  var index_1 = require("../../tools/three/index");
32
- var _ = require("lodash");
37
+ // import * as _ from 'lodash'
33
38
  var MxFun_1 = require("../MxFun");
39
+ var McGiWorldDrawType_1 = require("../McGiWorldDrawType");
34
40
  /**
35
41
  * MxRectEntity 矩形对象.
36
42
  */
@@ -49,25 +55,11 @@ var MxDbRect = /** @class */ (function (_super) {
49
55
  * */
50
56
  _this.pt2 = new three_1.Vector3();
51
57
  /**
52
- * width: 在绘制时自动计算矩形像素宽度 单位px
58
+ * 是否需要颜色填充.
53
59
  * */
54
- _this.width = 0;
55
- /**
56
- * height: 在绘制时自动计算矩形像素高度 单位px
57
- * */
58
- _this.height = 0;
59
- /**
60
- * transparent 开启透明度
61
- * */
62
- _this.transparent = true;
63
- /**
64
- * opacity 设置透明度 0 ~ 1
65
- * */
66
- _this.opacity = 1;
67
- /**
68
- * visible 该矩形对象是否可见
69
- * */
70
- _this.visible = true;
60
+ _this.isSolidColorFill = false;
61
+ _this.isLoadMaterialFromPath = true;
62
+ _this.material = null;
71
63
  return _this;
72
64
  }
73
65
  MxDbRect.prototype.worldDraw = function (pWorldDraw) {
@@ -77,87 +69,95 @@ var MxDbRect = /** @class */ (function (_super) {
77
69
  if (this.cornerRadius.length > 0) {
78
70
  points = (0, index_1.getToGenerateRoundedCorners)(points, this.cornerRadius);
79
71
  }
80
- var geometry;
81
- var material;
82
- var line = new three_1.Object3D();
72
+ if (pWorldDraw.getType() != McGiWorldDrawType_1.default.kWorldDraw) {
73
+ // 动态拖动绘制,或选择绘制 。
74
+ // 组成闭合区域。
75
+ points.push(points[0]);
76
+ pWorldDraw.drawLines(points);
77
+ return;
78
+ }
83
79
  // 公共的material参数
84
80
  var materialParam = {
85
- transparent: this.transparent,
81
+ transparent: true,
82
+ depthTest: false,
86
83
  opacity: this.opacity,
87
84
  visible: this.visible
88
85
  };
89
86
  // 如果是填充模式
90
- if (this.fillColor || this.fillImageSrc) {
87
+ if (this.isSolidColorFill) {
91
88
  // 三维坐标转二位坐标
92
89
  points = points.map(function (_a) {
93
90
  var x = _a.x, y = _a.y;
94
91
  return new three_1.Vector2(x, y);
95
92
  });
96
93
  // 计算矩形宽高
94
+ var geometry = void 0;
97
95
  geometry = new three_1.ShapeGeometry(new three_1.Shape(points));
98
- geometry.computeBoundingBox();
99
- var size_1 = new three_1.Vector3();
100
- geometry.boundingBox.getSize(size_1);
101
- this.width = MxFun_1.default.docCoord2Screen(size_1.x).x;
102
- this.height = MxFun_1.default.docCoord2Screen(size_1.y).x;
103
- // 如果是图片填充
104
- if (this.fillImageSrc) {
105
- var imgSrc = this.fillImageSrc;
106
- MxFun_1.default.loadImageMaterial(imgSrc, function (mate) {
107
- if (!mate)
108
- return;
109
- material = mate;
110
- geometry = new three_1.ShapeGeometry(new three_1.Shape(points));
111
- // 修复集合体的uv坐标
112
- geometry = (0, index_1.repairGeometryFaceVertexUvs)(geometry);
96
+ // 颜色填充
97
+ var material = new three_1.MeshBasicMaterial(__assign({ color: this.filter
98
+ ? this.filter._getFilterColor(this.color, this.opacity)
99
+ : new three_1.Color(this.color) }, materialParam));
100
+ var mash = new three_1.Mesh(geometry, material);
101
+ pWorldDraw.drawEntity(mash);
102
+ }
103
+ else if (this.fillImageSrc) {
104
+ // 图片填充.
105
+ if (this.material) {
106
+ // 三维坐标转二位坐标
107
+ points = points.map(function (_a) {
108
+ var x = _a.x, y = _a.y;
109
+ return new three_1.Vector2(x, y);
110
+ });
111
+ var material = this.material;
112
+ var geometry = new three_1.ShapeGeometry(new three_1.Shape(points));
113
+ // 修复集合体的uv坐标
114
+ geometry = (0, index_1.repairGeometryFaceVertexUvs)(geometry);
115
+ // 有滤镜对象使用自定义着色器
116
+ if (this.filter) {
113
117
  // 纹理属性设置
118
+ var mate = material;
114
119
  var map = mate.map;
115
- if (_this.fillImageParam) {
116
- if (_this.fillImageParam.center)
117
- map.center = _this.fillImageParam.center;
118
- if (_this.fillImageParam.offset)
119
- map.offset = _this.fillImageParam.offset;
120
- if (_this.fillImageParam.repeat)
121
- map.repeat = _this.fillImageParam.repeat;
122
- if (_this.fillImageParam.rotation)
123
- map.rotation = _this.fillImageParam.rotation;
120
+ if (this.fillImageParam) {
121
+ if (this.fillImageParam.center)
122
+ map.center = this.fillImageParam.center;
123
+ if (this.fillImageParam.offset)
124
+ map.offset = this.fillImageParam.offset;
125
+ if (this.fillImageParam.repeat)
126
+ map.repeat = this.fillImageParam.repeat;
127
+ if (this.fillImageParam.rotation)
128
+ map.rotation = this.fillImageParam.rotation;
124
129
  }
125
- // 有滤镜对象使用自定义着色器
126
- if (_this.filter) {
127
- var data = _this.filter._getFilterShaderData(map);
128
- material = new three_1.ShaderMaterial(__assign(__assign({}, data), materialParam));
130
+ var data = this.filter._getFilterShaderData(map);
131
+ material = new three_1.ShaderMaterial(__assign(__assign({}, data), materialParam));
132
+ }
133
+ // 设置材质属性
134
+ material.depthTest = false;
135
+ material.transparent = true;
136
+ material.opacity = this.opacity;
137
+ material.visible = this.visible;
138
+ var mash = new three_1.Mesh(geometry, material);
139
+ pWorldDraw.drawEntity(mash);
140
+ }
141
+ else if (this.fillImageSrc.length > 0 && this.isLoadMaterialFromPath) {
142
+ var myThis_1 = this;
143
+ MxFun_1.default.loadImageMaterial(this.fillImageSrc, function (material) {
144
+ _this.isLoadMaterialFromPath = false;
145
+ if (!material) {
146
+ return;
129
147
  }
130
- // 设置材质属性
131
- material.depthTest = false;
132
- material.transparent = _this.transparent;
133
- material.opacity = _this.opacity;
134
- material.visible = _this.visible;
135
- line = new three_1.Mesh(geometry, material);
136
- pWorldDraw.drawEntity(line);
148
+ myThis_1.material = material;
149
+ myThis_1.setNeedUpdateDisplay();
150
+ MxFun_1.default.updateDisplay();
137
151
  });
138
- return;
139
- }
140
- else {
141
- // 颜色填充
142
- material = new three_1.MeshBasicMaterial(__assign({ color: this.filter
143
- ? this.filter._getFilterColor(this.fillColor, this.opacity)
144
- : new three_1.Color(this.fillColor) }, materialParam));
145
- line = new three_1.Mesh(geometry, material);
146
152
  }
147
153
  }
148
154
  else {
149
155
  // 线框模式
150
- geometry = new three_1.BufferGeometry().setFromPoints(points);
151
- material = new three_1.LineBasicMaterial(__assign({ color: this.getColor() }, materialParam));
152
- line = new three_1.LineLoop(geometry, material);
156
+ var geometry = new three_1.BufferGeometry().setFromPoints(points);
157
+ var material = new three_1.LineBasicMaterial(__assign({ color: this.getColor() }, materialParam));
158
+ var line = new three_1.LineLoop(geometry, material);
159
+ pWorldDraw.drawEntity(line);
153
160
  }
154
- // 计算矩形宽高
155
- geometry.computeBoundingBox();
156
- var size = new three_1.Vector3();
157
- geometry.boundingBox.getSize(size);
158
- this.width = MxFun_1.default.docCoord2Screen(size.x).x;
159
- this.height = MxFun_1.default.docCoord2Screen(size.y).x;
160
- pWorldDraw.drawEntity(line);
161
161
  };
162
162
  MxDbRect.prototype.getGripPoints = function () {
163
163
  var ret = [];
@@ -186,28 +186,24 @@ var MxDbRect = /** @class */ (function (_super) {
186
186
  this.onDwgIn(obj);
187
187
  this.pt1.copy(obj['pt1']);
188
188
  this.pt2.copy(obj['pt2']);
189
- this.fillColor = obj['fillColor'];
189
+ this.isSolidColorFill = obj['isSolidColorFill'];
190
190
  this.fillImageSrc = obj['fillImageSrc'];
191
- this.fillImageSrc = obj['fillImageParam'];
191
+ this.fillImageParam = obj['fillImageParam'];
192
192
  this.cornerRadius = obj['cornerRadius'];
193
193
  this.filter = obj['filter'];
194
- this.transparent = obj['transparent'];
195
- this.opacity = obj['opacity'];
196
- this.visible = obj['visible'];
194
+ this.isLoadMaterialFromPath = true;
195
+ this.material = null;
197
196
  return true;
198
197
  };
199
198
  MxDbRect.prototype.dwgOut = function (obj) {
200
199
  this.onDwgOut(obj);
201
200
  obj['pt1'] = this.pt1;
202
201
  obj['pt2'] = this.pt2;
203
- obj['fillColor'] = this.fillColor;
202
+ obj['isSolidColorFill'] = this.isSolidColorFill;
204
203
  obj['fillImageSrc'] = this.fillImageSrc;
205
204
  obj['fillImageParam'] = this.fillImageParam;
206
205
  obj['cornerRadius'] = this.cornerRadius;
207
206
  obj['filter'] = this.filter;
208
- obj['transparent'] = this.transparent;
209
- obj['opacity'] = this.opacity;
210
- obj['visible'] = this.visible;
211
207
  return obj;
212
208
  };
213
209
  MxDbRect.prototype.create = function () {
@@ -221,20 +217,29 @@ var MxDbRect = /** @class */ (function (_super) {
221
217
  * setRadius 设置圆角 圆角的半径 如[3, 2, 1, 4]分别对应左上角圆角半径3 右上角2 右下角1 左下角4
222
218
  * @param { number | number[] } radius 圆角半径 为数组时[3, 2, 1, 4]分别对应左上角圆角半径3 右上角2 右下角1 左下角4; 或者直接设置半径值 则四个角统一半径
223
219
  * */
224
- MxDbRect.prototype.setRadius = function (radius) {
225
- if (_.isArray(radius)) {
220
+ MxDbRect.prototype.setRadius = function (radius, isScreenCoord) {
221
+ if (isScreenCoord === void 0) { isScreenCoord = true; }
222
+ if (radius instanceof Array) {
226
223
  this.cornerRadius = radius.map(function (r) {
227
- return MxFun_1.default.screenCoordLong2Doc(r);
224
+ if (isScreenCoord)
225
+ return MxFun_1.default.screenCoordLong2Doc(r);
226
+ else
227
+ return r;
228
228
  });
229
229
  }
230
- else if (_.isNumber(radius)) {
230
+ else {
231
231
  if (radius > 0) {
232
- this.cornerRadius = [
233
- MxFun_1.default.screenCoordLong2Doc(radius),
234
- MxFun_1.default.screenCoordLong2Doc(radius),
235
- MxFun_1.default.screenCoordLong2Doc(radius),
236
- MxFun_1.default.screenCoordLong2Doc(radius)
237
- ];
232
+ if (isScreenCoord) {
233
+ this.cornerRadius = [
234
+ MxFun_1.default.screenCoordLong2Doc(radius),
235
+ MxFun_1.default.screenCoordLong2Doc(radius),
236
+ MxFun_1.default.screenCoordLong2Doc(radius),
237
+ MxFun_1.default.screenCoordLong2Doc(radius)
238
+ ];
239
+ }
240
+ else {
241
+ this.cornerRadius = [radius, radius, radius, radius];
242
+ }
238
243
  }
239
244
  else {
240
245
  this.cornerRadius = [];
@@ -244,6 +249,25 @@ var MxDbRect = /** @class */ (function (_super) {
244
249
  MxDbRect.prototype.getTypeName = function () {
245
250
  return 'MxDbRect';
246
251
  };
252
+ MxDbRect.prototype.getFilter = function () {
253
+ return this.filter;
254
+ };
255
+ MxDbRect.prototype.setFilter = function (filter) {
256
+ this.filter = filter;
257
+ this.isLoadMaterialFromPath = true;
258
+ this.material = null;
259
+ };
260
+ MxDbRect.prototype.setFillImagePath = function (sPath) {
261
+ this.fillImageSrc = sPath;
262
+ this.isLoadMaterialFromPath = true;
263
+ this.material = null;
264
+ if (this.fillImageSrc) {
265
+ this.isSolidColorFill = false;
266
+ }
267
+ };
268
+ MxDbRect.prototype.getFillImagePath = function () {
269
+ return this.fillImageSrc;
270
+ };
247
271
  return MxDbRect;
248
272
  }(MxDbEntity_1.default));
249
273
  exports.default = MxDbRect;