mxdraw 0.1.5 → 0.1.7
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/lib/MxModule/MrxDbgUiPrPoint/MrxDbgUiPrPointClass.js +18 -1
- package/dist/lib/MxModule/MxDbImage/MxDbImage.js +18 -6
- package/dist/lib/MxModule/MxDbRect/MxDbRect.js +50 -20
- package/dist/lib/MxModule/MxFun/MxFun.js +3 -2
- package/dist/lib/MxModule/store/store.js +1 -3
- package/dist/lib/MxModule/useCanvasResizeListener/useCanvasResizeListener.js +16 -9
- package/dist/lib/tools/three/index.js +21 -15
- package/dist/mxdraw.es5.js +2 -2
- package/dist/mxdraw.es5.js.map +1 -1
- package/dist/mxdraw.umd.js +2 -2
- package/dist/mxdraw.umd.js.map +1 -1
- package/dist/types/MxModule/MrxDbgUiPrPoint/MrxDbgUiPrPointClass.d.ts +1 -1
- package/dist/types/MxModule/MxDbRect/MxDbRect.d.ts +7 -9
- package/dist/types/MxModule/MxFun/MxFun.d.ts +2 -1
- package/dist/types/MxModule/store/store.d.ts +0 -1
- package/package.json +1 -1
|
@@ -109,7 +109,24 @@ var MrxDbgUiPrPoint = /** @class */ (function () {
|
|
|
109
109
|
* @returns void
|
|
110
110
|
*/
|
|
111
111
|
MrxDbgUiPrPoint.prototype.go = function (retcall) {
|
|
112
|
-
|
|
112
|
+
if (retcall) {
|
|
113
|
+
_MrxDbgUiPrPoint.go(retcall);
|
|
114
|
+
return new Promise(function (resolve, reject) {
|
|
115
|
+
resolve(null);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return new Promise(function (resolve, reject) {
|
|
120
|
+
_MrxDbgUiPrPoint.go(function (status) {
|
|
121
|
+
if (status != 0) {
|
|
122
|
+
resolve(null);
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
resolve(_MrxDbgUiPrPoint.value());
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
113
130
|
};
|
|
114
131
|
/**
|
|
115
132
|
* 动态拖动,连续取点,直到ESC退出。
|
|
@@ -47,11 +47,11 @@ var MxDbImage = /** @class */ (function (_super) {
|
|
|
47
47
|
var _this = this;
|
|
48
48
|
var pt3 = new THREE.Vector3(this.pt1.x, this.pt2.y);
|
|
49
49
|
var pt4 = new THREE.Vector3(this.pt2.x, this.pt1.y);
|
|
50
|
-
pWorldDraw.drawLine(this.pt1, pt3);
|
|
51
|
-
pWorldDraw.drawLine(pt3, this.pt2);
|
|
52
|
-
pWorldDraw.drawLine(this.pt2, pt4);
|
|
53
|
-
pWorldDraw.drawLine(pt4, this.pt1);
|
|
54
50
|
if (pWorldDraw.getType() == 1) {
|
|
51
|
+
pWorldDraw.drawSelectLine(this.pt1, pt3);
|
|
52
|
+
pWorldDraw.drawSelectLine(pt3, this.pt2);
|
|
53
|
+
pWorldDraw.drawSelectLine(this.pt2, pt4);
|
|
54
|
+
pWorldDraw.drawSelectLine(pt4, this.pt1);
|
|
55
55
|
// 图片正常的显示绘制.
|
|
56
56
|
if (this.material) {
|
|
57
57
|
var w = Math.abs(this.pt1.x - this.pt2.x);
|
|
@@ -70,7 +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
|
-
MxFun_1.default.loadImageMaterial(
|
|
73
|
+
MxFun_1.default.loadImageMaterial(this.imagePath, function (material) {
|
|
74
74
|
_this.isLoadMaterialFromPath = false;
|
|
75
75
|
if (!material) {
|
|
76
76
|
return;
|
|
@@ -81,6 +81,12 @@ var MxDbImage = /** @class */ (function (_super) {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
+
else {
|
|
85
|
+
pWorldDraw.drawLine(this.pt1, pt3);
|
|
86
|
+
pWorldDraw.drawLine(pt3, this.pt2);
|
|
87
|
+
pWorldDraw.drawLine(this.pt2, pt4);
|
|
88
|
+
pWorldDraw.drawLine(pt4, this.pt1);
|
|
89
|
+
}
|
|
84
90
|
};
|
|
85
91
|
MxDbImage.prototype.setImagePath = function (sPath) {
|
|
86
92
|
this.imagePath = sPath;
|
|
@@ -110,6 +116,8 @@ var MxDbImage = /** @class */ (function (_super) {
|
|
|
110
116
|
var ret = [];
|
|
111
117
|
ret.push(this.pt1);
|
|
112
118
|
ret.push(this.pt2);
|
|
119
|
+
var midPt = new THREE.Vector3(this.pt1.x + (this.pt2.x - this.pt1.x) * 0.5, this.pt1.y + (this.pt2.y - this.pt1.y) * 0.5);
|
|
120
|
+
ret.push(midPt);
|
|
113
121
|
return ret;
|
|
114
122
|
};
|
|
115
123
|
// 图片的夹点拖动编辑.
|
|
@@ -117,7 +125,11 @@ var MxDbImage = /** @class */ (function (_super) {
|
|
|
117
125
|
if (index == 0) {
|
|
118
126
|
this.pt1.add(offset);
|
|
119
127
|
}
|
|
120
|
-
else if (
|
|
128
|
+
else if (index == 1) {
|
|
129
|
+
this.pt2.add(offset);
|
|
130
|
+
}
|
|
131
|
+
else if (index == 2) {
|
|
132
|
+
this.pt1.add(offset);
|
|
121
133
|
this.pt2.add(offset);
|
|
122
134
|
}
|
|
123
135
|
return true;
|
|
@@ -29,6 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
var MxDbEntity_1 = require("../MxDbEntity");
|
|
30
30
|
var three_1 = require("three");
|
|
31
31
|
var index_1 = require("../../tools/three/index");
|
|
32
|
+
var _ = require("lodash");
|
|
32
33
|
var MxFun_1 = require("../MxFun");
|
|
33
34
|
/**
|
|
34
35
|
* MxRectEntity 矩形对象.
|
|
@@ -37,6 +38,8 @@ var MxDbRect = /** @class */ (function (_super) {
|
|
|
37
38
|
__extends(MxDbRect, _super);
|
|
38
39
|
function MxDbRect() {
|
|
39
40
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
41
|
+
// 圆角半径
|
|
42
|
+
_this.cornerRadius = [];
|
|
40
43
|
/**
|
|
41
44
|
* pt1: 构成矩形的第一个点
|
|
42
45
|
* */
|
|
@@ -53,10 +56,6 @@ var MxDbRect = /** @class */ (function (_super) {
|
|
|
53
56
|
* height: 在绘制时自动计算矩形像素高度 单位px
|
|
54
57
|
* */
|
|
55
58
|
_this.height = 0;
|
|
56
|
-
/**
|
|
57
|
-
* cornerRadius(优先级大于radius属性): 圆角的半径 如[3, 2, 1, 4]分别对应左上角圆角半径3 右上角2 右下角1 左下角4
|
|
58
|
-
* */
|
|
59
|
-
_this.cornerRadius = [];
|
|
60
59
|
/**
|
|
61
60
|
* transparent 开启透明度
|
|
62
61
|
* */
|
|
@@ -75,15 +74,6 @@ var MxDbRect = /** @class */ (function (_super) {
|
|
|
75
74
|
var _this = this;
|
|
76
75
|
// 根据第一个点和对角点 计算矩形的四个点位
|
|
77
76
|
var points = (0, index_1.computeRectPoints)(this.pt1, this.pt2);
|
|
78
|
-
// 计算圆角顶点坐标
|
|
79
|
-
if (this.cornerRadius.length <= 0 && this.radius) {
|
|
80
|
-
this.cornerRadius = [
|
|
81
|
-
MxFun_1.default.screenCoordLong2Doc(this.radius),
|
|
82
|
-
MxFun_1.default.screenCoordLong2Doc(this.radius),
|
|
83
|
-
MxFun_1.default.screenCoordLong2Doc(this.radius),
|
|
84
|
-
MxFun_1.default.screenCoordLong2Doc(this.radius)
|
|
85
|
-
];
|
|
86
|
-
}
|
|
87
77
|
if (this.cornerRadius.length > 0) {
|
|
88
78
|
points = (0, index_1.getToGenerateRoundedCorners)(points, this.cornerRadius);
|
|
89
79
|
}
|
|
@@ -106,10 +96,10 @@ var MxDbRect = /** @class */ (function (_super) {
|
|
|
106
96
|
// 计算矩形宽高
|
|
107
97
|
geometry = new three_1.ShapeGeometry(new three_1.Shape(points));
|
|
108
98
|
geometry.computeBoundingBox();
|
|
109
|
-
var
|
|
110
|
-
geometry.boundingBox.getSize(
|
|
111
|
-
this.width = MxFun_1.default.docCoord2Screen(
|
|
112
|
-
this.height = MxFun_1.default.docCoord2Screen(
|
|
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;
|
|
113
103
|
// 如果是图片填充
|
|
114
104
|
if (this.fillImageSrc) {
|
|
115
105
|
var imgSrc = this.fillImageSrc;
|
|
@@ -161,6 +151,12 @@ var MxDbRect = /** @class */ (function (_super) {
|
|
|
161
151
|
material = new three_1.LineBasicMaterial(__assign({ color: this.getColor() }, materialParam));
|
|
162
152
|
line = new three_1.LineLoop(geometry, material);
|
|
163
153
|
}
|
|
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;
|
|
164
160
|
pWorldDraw.drawEntity(line);
|
|
165
161
|
};
|
|
166
162
|
MxDbRect.prototype.getGripPoints = function () {
|
|
@@ -190,18 +186,28 @@ var MxDbRect = /** @class */ (function (_super) {
|
|
|
190
186
|
this.onDwgIn(obj);
|
|
191
187
|
this.pt1.copy(obj['pt1']);
|
|
192
188
|
this.pt2.copy(obj['pt2']);
|
|
189
|
+
this.fillColor = obj['fillColor'];
|
|
190
|
+
this.fillImageSrc = obj['fillImageSrc'];
|
|
191
|
+
this.fillImageSrc = obj['fillImageParam'];
|
|
193
192
|
this.cornerRadius = obj['cornerRadius'];
|
|
194
|
-
this.radius = obj['radius'];
|
|
195
193
|
this.filter = obj['filter'];
|
|
194
|
+
this.transparent = obj['transparent'];
|
|
195
|
+
this.opacity = obj['opacity'];
|
|
196
|
+
this.visible = obj['visible'];
|
|
196
197
|
return true;
|
|
197
198
|
};
|
|
198
199
|
MxDbRect.prototype.dwgOut = function (obj) {
|
|
199
200
|
this.onDwgOut(obj);
|
|
200
201
|
obj['pt1'] = this.pt1;
|
|
201
202
|
obj['pt2'] = this.pt2;
|
|
203
|
+
obj['fillColor'] = this.fillColor;
|
|
204
|
+
obj['fillImageSrc'] = this.fillImageSrc;
|
|
205
|
+
obj['fillImageParam'] = this.fillImageParam;
|
|
202
206
|
obj['cornerRadius'] = this.cornerRadius;
|
|
203
|
-
obj['radius'] = this.radius;
|
|
204
207
|
obj['filter'] = this.filter;
|
|
208
|
+
obj['transparent'] = this.transparent;
|
|
209
|
+
obj['opacity'] = this.opacity;
|
|
210
|
+
obj['visible'] = this.visible;
|
|
205
211
|
return obj;
|
|
206
212
|
};
|
|
207
213
|
MxDbRect.prototype.create = function () {
|
|
@@ -211,8 +217,32 @@ var MxDbRect = /** @class */ (function (_super) {
|
|
|
211
217
|
this.pt1.applyMatrix4(mat);
|
|
212
218
|
this.pt2.applyMatrix4(mat);
|
|
213
219
|
};
|
|
220
|
+
/**
|
|
221
|
+
* setRadius 设置圆角 圆角的半径 如[3, 2, 1, 4]分别对应左上角圆角半径3 右上角2 右下角1 左下角4
|
|
222
|
+
* @param { number | number[] } radius 圆角半径 为数组时[3, 2, 1, 4]分别对应左上角圆角半径3 右上角2 右下角1 左下角4; 或者直接设置半径值 则四个角统一半径
|
|
223
|
+
* */
|
|
224
|
+
MxDbRect.prototype.setRadius = function (radius) {
|
|
225
|
+
if (_.isArray(radius)) {
|
|
226
|
+
this.cornerRadius = radius.map(function (r) {
|
|
227
|
+
return MxFun_1.default.screenCoordLong2Doc(r);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
else if (_.isNumber(radius)) {
|
|
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
|
+
];
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
this.cornerRadius = [];
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
214
244
|
MxDbRect.prototype.getTypeName = function () {
|
|
215
|
-
return '
|
|
245
|
+
return 'MxDbRect';
|
|
216
246
|
};
|
|
217
247
|
return MxDbRect;
|
|
218
248
|
}(MxDbEntity_1.default));
|
|
@@ -51,7 +51,7 @@ var MxFun = /** @class */ (function () {
|
|
|
51
51
|
* ```
|
|
52
52
|
*/
|
|
53
53
|
MxFun.prototype.createMxObject = function (_a) {
|
|
54
|
-
var _b = _a.canvasId, canvasId = _b === void 0 ? (0, random_1.createReandomId)() : _b, _c = _a.cadFile, cadFile = _c === void 0 ? '' : _c, callback = _a.callback, _d = _a.isNewFile, isNewFile = _d === void 0 ? false : _d, _e = _a.useWebsocket, useWebsocket = _e === void 0 ? false : _e;
|
|
54
|
+
var _b = _a.canvasId, canvasId = _b === void 0 ? (0, random_1.createReandomId)() : _b, _c = _a.cadFile, cadFile = _c === void 0 ? '' : _c, callback = _a.callback, _d = _a.isNewFile, isNewFile = _d === void 0 ? false : _d, _e = _a.useWebsocket, useWebsocket = _e === void 0 ? false : _e, _f = _a.isAutoResize, isAutoResize = _f === void 0 ? true : _f;
|
|
55
55
|
// 获取canvas和其父级
|
|
56
56
|
var canvas = (0, create_1.createCanvas)(canvasId);
|
|
57
57
|
var canvasParent = (0, create_1.createCanvasParent)(canvas);
|
|
@@ -77,7 +77,8 @@ var MxFun = /** @class */ (function () {
|
|
|
77
77
|
};
|
|
78
78
|
});
|
|
79
79
|
// 使用canvas侦听器 监听canvas元素的大小变化
|
|
80
|
-
|
|
80
|
+
if (isAutoResize)
|
|
81
|
+
(0, useCanvasResizeListener_1.default)(mxdrawObj, canvas);
|
|
81
82
|
callback &&
|
|
82
83
|
callback(mxdrawObj, {
|
|
83
84
|
canvas: canvas,
|
|
@@ -55,7 +55,7 @@ function useCanvasResizeListener(mxdrawObj, canvas, time, autoAdjust, callback)
|
|
|
55
55
|
if (time === void 0) { time = 100; }
|
|
56
56
|
if (autoAdjust === void 0) { autoAdjust = true; }
|
|
57
57
|
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var MxFun;
|
|
58
|
+
var MxFun, mxObj;
|
|
59
59
|
return __generator(this, function (_a) {
|
|
60
60
|
switch (_a.label) {
|
|
61
61
|
case 0:
|
|
@@ -68,17 +68,24 @@ function useCanvasResizeListener(mxdrawObj, canvas, time, autoAdjust, callback)
|
|
|
68
68
|
console.error('请确保mxdrawObj参数 是通过调用MxFun.createMxObject的callback回调函数拿到的mxDraw对象');
|
|
69
69
|
return [2 /*return*/];
|
|
70
70
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
callback && callback(event);
|
|
75
|
-
autoAdjust && callResize(event);
|
|
76
|
-
}, time), false);
|
|
77
|
-
});
|
|
71
|
+
mxObj = mxdrawObj;
|
|
72
|
+
if (!!mxObj['isLoadCanvasResizeListene']) return [3 /*break*/, 2];
|
|
73
|
+
mxObj['isLoadCanvasResizeListene'] = true;
|
|
78
74
|
return [4 /*yield*/, (0, dynamicImport_1.dynamicImport)('element-resize-event-polyfill')];
|
|
79
75
|
case 1:
|
|
80
76
|
_a.sent();
|
|
81
|
-
|
|
77
|
+
mxdrawObj.addEvent('addResizeEvent', function (callResize) {
|
|
78
|
+
var parentdiv = (0, create_1.createCanvasParent)(canvas);
|
|
79
|
+
if (parentdiv['addEventListener']) {
|
|
80
|
+
(0, create_1.createCanvasParent)(canvas).addEventListener('resize', _.throttle(function (event) {
|
|
81
|
+
callback && callback(event);
|
|
82
|
+
autoAdjust && callResize(event);
|
|
83
|
+
}, time), false);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
console.log('mx: parentdiv[addEventListener] invalid');
|
|
87
|
+
}
|
|
88
|
+
});
|
|
82
89
|
_a.label = 2;
|
|
83
90
|
case 2: return [2 /*return*/];
|
|
84
91
|
}
|
|
@@ -57,6 +57,9 @@ function getToGenerateRoundedCorners(points, cornerRadius, isClose) {
|
|
|
57
57
|
if (isClose === void 0) { isClose = true; }
|
|
58
58
|
if (cornerRadius.length > 0) {
|
|
59
59
|
var curve = new three_1.CurvePath();
|
|
60
|
+
if (!isClose) {
|
|
61
|
+
points.push(points[0]);
|
|
62
|
+
}
|
|
60
63
|
for (var i = 0; i < points.length - 1; i++) {
|
|
61
64
|
//作为拐弯的弧度
|
|
62
65
|
var R = cornerRadius[i] || 0;
|
|
@@ -65,16 +68,17 @@ function getToGenerateRoundedCorners(points, cornerRadius, isClose) {
|
|
|
65
68
|
dir.normalize();
|
|
66
69
|
var p2_1 = points[1].clone();
|
|
67
70
|
p2_1.add(dir.clone().multiplyScalar(R));
|
|
68
|
-
var
|
|
69
|
-
curve.curves.push(
|
|
71
|
+
var line = new three_1.LineCurve3(points[0], p2_1);
|
|
72
|
+
curve.curves.push(line);
|
|
70
73
|
continue;
|
|
71
74
|
}
|
|
72
75
|
// 计算三个点构成的两条线的方向
|
|
73
|
-
var dir1 = !isClose
|
|
76
|
+
var dir1 = !isClose || points[i - 1]
|
|
74
77
|
? points[i - 1].clone().sub(points[i])
|
|
75
78
|
: points[points.length - 1].clone().sub(points[0]);
|
|
76
79
|
dir1.normalize();
|
|
77
|
-
|
|
80
|
+
/* istanbul ignore next */
|
|
81
|
+
var dir2 = !isClose || points[i + 1]
|
|
78
82
|
? points[i + 1].clone().sub(points[i])
|
|
79
83
|
: points[1].clone().sub(points[0]);
|
|
80
84
|
dir2.normalize();
|
|
@@ -84,24 +88,26 @@ function getToGenerateRoundedCorners(points, cornerRadius, isClose) {
|
|
|
84
88
|
var p2 = points[i].clone();
|
|
85
89
|
var p3 = points[i].clone().add(dir2.clone().multiplyScalar(R));
|
|
86
90
|
var beziercurve = new three_1.QuadraticBezierCurve3(p1, p2, p3);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
if (i === points.length - 2) {
|
|
92
|
+
var line1 = points[i].clone();
|
|
93
|
+
line1.add(dir2.clone().multiplyScalar(R));
|
|
94
|
+
var line2 = points[i + 1].clone();
|
|
95
|
+
isClose ? line2.add(dir2.clone().multiplyScalar(-R)) : line2.add(dir2.clone());
|
|
96
|
+
var line = new three_1.LineCurve3(line1, line2);
|
|
97
|
+
curve.curves.push(beziercurve, line);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// 把转换曲线和直线插入曲线中
|
|
101
|
+
curve.curves.push(beziercurve);
|
|
93
102
|
}
|
|
94
|
-
var line = new three_1.LineCurve3(line1, line2);
|
|
95
|
-
// 把转换曲线和直线插入曲线中
|
|
96
|
-
curve.curves.push(beziercurve, line);
|
|
97
103
|
if (i === 0) {
|
|
98
104
|
points.push(points[0]);
|
|
99
105
|
}
|
|
100
106
|
}
|
|
101
|
-
return curve.getPoints(
|
|
107
|
+
return curve.getPoints(50);
|
|
102
108
|
}
|
|
103
109
|
else {
|
|
104
|
-
return
|
|
110
|
+
return points;
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
113
|
exports.getToGenerateRoundedCorners = getToGenerateRoundedCorners;
|