@labelbee/lb-annotation 1.13.0 → 1.13.1
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/core/pointCloud/index.js +2 -2
- package/dist/types/core/pointCloud/index.d.ts +8 -3
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -0
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -0
- package/es/core/pointCloud/index.js +2 -2
- package/es/core/pointCloud/render/index.js +131 -0
- package/es/core/pointCloud/segmentation.js +95 -0
- package/es/core/pointCloud/selector/Sse3dLassoSelector.js +23 -0
- package/es/core/pointCloud/selector/Sse3dSelector.js +15 -0
- package/es/core/pointCloud/selector/circleSelector.js +39 -0
- package/es/core/pointCloud/selector/lassoSelector.js +22 -0
- package/es/core/pointCloud/selector/selector.js +16 -0
- package/es/core/pointCloud/store/fsm.js +41 -0
- package/es/core/pointCloud/store/index.js +376 -0
- package/es/core/toolOperation/Selection.js +101 -0
- package/es/core/toolOperation/cuboidOperation.js +752 -0
- package/es/core/toolOperation/cuboidToggleButtonClass.js +174 -0
- package/es/core/toolOperation/scribbleTool2.js +249 -0
- package/es/utils/tool/CuboidUtils.js +680 -0
- package/package.json +3 -3
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
2
|
+
import AxisUtils from '../../utils/tool/AxisUtils.js';
|
|
3
|
+
import uuid from '../../utils/uuid.js';
|
|
4
|
+
import { getCuboidHoverRange, getPlainPointsByDiagonalPoints, getPointsByBottomRightPoint, getCuboidDragMove, isCuboidWithInLimits, getHighlightPoints, getHighlightLines, getToggleDirectionButtonOffset, getCuboidTextAttributeOffset } from '../../utils/tool/CuboidUtils.js';
|
|
5
|
+
import PolygonUtils from '../../utils/tool/PolygonUtils.js';
|
|
6
|
+
import { EDragStatus, EDragTarget, ECuboidDirection } from '../../constant/annotation.js';
|
|
7
|
+
import AttributeUtils from '../../utils/tool/AttributeUtils.js';
|
|
8
|
+
import { DEFAULT_TEXT_MAX_WIDTH } from '../../constant/tool.js';
|
|
9
|
+
import EKeyCode from '../../constant/keyCode.js';
|
|
10
|
+
import { BasicToolOperation } from './basicToolOperation.js';
|
|
11
|
+
import DrawUtils from '../../utils/tool/DrawUtils.js';
|
|
12
|
+
import CuboidToggleButtonClass from './cuboidToggleButtonClass.js';
|
|
13
|
+
import TextAttributeClass from './textAttributeClass.js';
|
|
14
|
+
import Locale from '../../locales/index.js';
|
|
15
|
+
import { EMessage } from '../../locales/constants.js';
|
|
16
|
+
|
|
17
|
+
var __defProp = Object.defineProperty;
|
|
18
|
+
var __defProps = Object.defineProperties;
|
|
19
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
20
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
21
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
22
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
23
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
24
|
+
var __spreadValues = (a, b) => {
|
|
25
|
+
for (var prop in b || (b = {}))
|
|
26
|
+
if (__hasOwnProp.call(b, prop))
|
|
27
|
+
__defNormalProp(a, prop, b[prop]);
|
|
28
|
+
if (__getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
30
|
+
if (__propIsEnum.call(b, prop))
|
|
31
|
+
__defNormalProp(a, prop, b[prop]);
|
|
32
|
+
}
|
|
33
|
+
return a;
|
|
34
|
+
};
|
|
35
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
36
|
+
var EDrawingStatus;
|
|
37
|
+
(function(EDrawingStatus2) {
|
|
38
|
+
EDrawingStatus2[EDrawingStatus2["Ready"] = 1] = "Ready";
|
|
39
|
+
EDrawingStatus2[EDrawingStatus2["FirstPoint"] = 2] = "FirstPoint";
|
|
40
|
+
EDrawingStatus2[EDrawingStatus2["Cuboid"] = 3] = "Cuboid";
|
|
41
|
+
})(EDrawingStatus || (EDrawingStatus = {}));
|
|
42
|
+
const TEXT_MAX_WIDTH = 164;
|
|
43
|
+
class CuboidOperation extends BasicToolOperation {
|
|
44
|
+
constructor(props) {
|
|
45
|
+
super(props);
|
|
46
|
+
this.drawingStatus = 1;
|
|
47
|
+
this.cuboidList = [];
|
|
48
|
+
this.hoverID = "";
|
|
49
|
+
this.getHoverData = (e) => {
|
|
50
|
+
const coordinate = this.getCoordinateUnderZoom(e);
|
|
51
|
+
const {currentShowList} = this;
|
|
52
|
+
if ((currentShowList == null ? void 0 : currentShowList.length) > 0) {
|
|
53
|
+
const polygonList = currentShowList.map((cuboid) => {
|
|
54
|
+
return {id: cuboid.id, pointList: AxisUtils.changePointListByZoom(getCuboidHoverRange(cuboid), this.zoom)};
|
|
55
|
+
});
|
|
56
|
+
const hoverID = PolygonUtils.getHoverPolygonID(coordinate, polygonList);
|
|
57
|
+
if (hoverID) {
|
|
58
|
+
return {
|
|
59
|
+
hoverID,
|
|
60
|
+
hoverCuboid: currentShowList.find((cuboid) => cuboid.id === hoverID)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {};
|
|
65
|
+
};
|
|
66
|
+
this.textChange = (v) => {
|
|
67
|
+
if (this.config.textConfigurable === false || !this.selectedID) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.setCuboidList(AttributeUtils.textChange(v, this.selectedID, this.cuboidList));
|
|
71
|
+
this.emit("selectedChange");
|
|
72
|
+
this.render();
|
|
73
|
+
};
|
|
74
|
+
this.config = CommonToolUtils.jsonParser(props.config);
|
|
75
|
+
this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
|
|
76
|
+
this.updateSelectedTextAttribute = this.updateSelectedTextAttribute.bind(this);
|
|
77
|
+
}
|
|
78
|
+
get selectedText() {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
return (_b = (_a = this.selectedCuboid) == null ? void 0 : _a.textAttribute) != null ? _b : "";
|
|
81
|
+
}
|
|
82
|
+
destroy() {
|
|
83
|
+
super.destroy();
|
|
84
|
+
if (this._textAttributeInstance) {
|
|
85
|
+
this._textAttributeInstance.clearTextAttribute();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
get currentShowList() {
|
|
89
|
+
let cuboidList = [];
|
|
90
|
+
const [showingCuboid, selectedCuboid] = CommonToolUtils.getRenderResultList(this.cuboidList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
|
|
91
|
+
cuboidList = showingCuboid;
|
|
92
|
+
if (this.isHidden) {
|
|
93
|
+
cuboidList = [];
|
|
94
|
+
}
|
|
95
|
+
if (selectedCuboid) {
|
|
96
|
+
cuboidList.push(selectedCuboid);
|
|
97
|
+
}
|
|
98
|
+
return cuboidList;
|
|
99
|
+
}
|
|
100
|
+
get selectedCuboid() {
|
|
101
|
+
return this.cuboidList.find((v) => v.id === this.selectedID);
|
|
102
|
+
}
|
|
103
|
+
get dataList() {
|
|
104
|
+
return this.cuboidList;
|
|
105
|
+
}
|
|
106
|
+
get isNeedCheckCuboidSize() {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
return ((_a = this.config) == null ? void 0 : _a.minWidth) >= 0 && ((_b = this.config) == null ? void 0 : _b.minHeight) >= 0;
|
|
109
|
+
}
|
|
110
|
+
getIsHoverSelectedCuboid(e) {
|
|
111
|
+
const currentCoord = this.getCoordinateUnderZoom(e);
|
|
112
|
+
const {selectedCuboid} = this;
|
|
113
|
+
return selectedCuboid && AxisUtils.isCloseCuboid(currentCoord, AxisUtils.changeCuboidByZoom(selectedCuboid, this.zoom));
|
|
114
|
+
}
|
|
115
|
+
isForbiddenMove(e, cuboid) {
|
|
116
|
+
const coord = this.getCoordinateInOrigin(e);
|
|
117
|
+
if (coord.y > cuboid.frontPoints.br.y) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
updateSelectedCuboid(newCuboid) {
|
|
123
|
+
this.cuboidList = this.cuboidList.map((cuboid) => {
|
|
124
|
+
if (cuboid.id === this.selectedID) {
|
|
125
|
+
return newCuboid;
|
|
126
|
+
}
|
|
127
|
+
return cuboid;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
getStylesToRender(attribute, valid) {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
const toolColor = this.getColor(attribute);
|
|
133
|
+
const strokeColor = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
|
|
134
|
+
const fillColor = valid ? toolColor == null ? void 0 : toolColor.valid.fill : toolColor == null ? void 0 : toolColor.invalid.fill;
|
|
135
|
+
const lineWidth = (_b = (_a = this.style) == null ? void 0 : _a.width) != null ? _b : 2;
|
|
136
|
+
return {strokeColor, toolColor, fillColor, lineWidth};
|
|
137
|
+
}
|
|
138
|
+
getCurrentSelectedData() {
|
|
139
|
+
const {selectedCuboid} = this;
|
|
140
|
+
if (!selectedCuboid) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const {strokeColor: color} = this.getStylesToRender(selectedCuboid.attribute, selectedCuboid.valid);
|
|
144
|
+
return {
|
|
145
|
+
width: TEXT_MAX_WIDTH,
|
|
146
|
+
textAttribute: selectedCuboid.textAttribute,
|
|
147
|
+
color
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
updateSelectedTextAttribute(newTextAttribute) {
|
|
151
|
+
if (this._textAttributeInstance && newTextAttribute && this.selectedID) {
|
|
152
|
+
let textAttribute = newTextAttribute;
|
|
153
|
+
if (AttributeUtils.textAttributeValidate(this.config.textCheckType, "", textAttribute) === false) {
|
|
154
|
+
this.emit("messageError", AttributeUtils.getErrorNotice(this.config.textCheckType, this.lang));
|
|
155
|
+
textAttribute = "";
|
|
156
|
+
}
|
|
157
|
+
this.setCuboidList(AttributeUtils.textChange(textAttribute, this.selectedID, this.cuboidList));
|
|
158
|
+
this.history.pushHistory(this.cuboidList);
|
|
159
|
+
this.emit("updateTextAttribute");
|
|
160
|
+
this.render();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
setResult(cuboidList) {
|
|
164
|
+
this.clearActiveStatus();
|
|
165
|
+
this.setCuboidList(cuboidList);
|
|
166
|
+
this.render();
|
|
167
|
+
}
|
|
168
|
+
get currentPageResult() {
|
|
169
|
+
return this.cuboidList;
|
|
170
|
+
}
|
|
171
|
+
clearResult() {
|
|
172
|
+
this.setCuboidList([], true);
|
|
173
|
+
this.deleteSelectedID();
|
|
174
|
+
this.render();
|
|
175
|
+
}
|
|
176
|
+
exportData() {
|
|
177
|
+
const {cuboidList} = this;
|
|
178
|
+
return [cuboidList, this.basicImgInfo];
|
|
179
|
+
}
|
|
180
|
+
setSelectedID(newID) {
|
|
181
|
+
var _a, _b;
|
|
182
|
+
const oldID = this.selectedID;
|
|
183
|
+
if (newID !== oldID && oldID) {
|
|
184
|
+
(_a = this._textAttributeInstance) == null ? void 0 : _a.changeSelected();
|
|
185
|
+
}
|
|
186
|
+
if (!newID) {
|
|
187
|
+
(_b = this._textAttributeInstance) == null ? void 0 : _b.clearTextAttribute();
|
|
188
|
+
}
|
|
189
|
+
this.selectedID = newID;
|
|
190
|
+
this.emit("selectedChange");
|
|
191
|
+
}
|
|
192
|
+
setSelectedIDAndRender(newID) {
|
|
193
|
+
this.setSelectedID(newID);
|
|
194
|
+
this.render();
|
|
195
|
+
}
|
|
196
|
+
setCuboidValidAndRender(id) {
|
|
197
|
+
if (!id) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const newPolygonList = this.cuboidList.map((cuboid) => {
|
|
201
|
+
if (cuboid.id === id) {
|
|
202
|
+
return __spreadProps(__spreadValues({}, cuboid), {
|
|
203
|
+
valid: !cuboid.valid
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return cuboid;
|
|
207
|
+
});
|
|
208
|
+
this.setCuboidList(newPolygonList, true);
|
|
209
|
+
this.history.pushHistory(this.cuboidList);
|
|
210
|
+
this.render();
|
|
211
|
+
}
|
|
212
|
+
onRightDblClick(e) {
|
|
213
|
+
super.onRightDblClick(e);
|
|
214
|
+
const {hoverID} = this.getHoverData(e);
|
|
215
|
+
if (this.selectedID && this.selectedID === hoverID) {
|
|
216
|
+
this.deleteCuboid(hoverID);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
setCuboidList(cuboidList, isUpload = false) {
|
|
220
|
+
const oldLen = this.cuboidList.length;
|
|
221
|
+
this.cuboidList = cuboidList;
|
|
222
|
+
if (oldLen !== cuboidList.length) {
|
|
223
|
+
this.emit("updatePageNumber");
|
|
224
|
+
}
|
|
225
|
+
if (isUpload) {
|
|
226
|
+
this.emit("updateResult");
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
deleteCuboid(id) {
|
|
230
|
+
var _a;
|
|
231
|
+
if (!id) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.setCuboidList(this.cuboidList.filter((v) => v.id !== id));
|
|
235
|
+
this.history.pushHistory(this.cuboidList);
|
|
236
|
+
this.setSelectedID("");
|
|
237
|
+
(_a = this._textAttributeInstance) == null ? void 0 : _a.clearTextAttribute();
|
|
238
|
+
this.render();
|
|
239
|
+
}
|
|
240
|
+
onKeyDown(e) {
|
|
241
|
+
if (!CommonToolUtils.hotkeyFilter(e)) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (super.onKeyDown(e) === false) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const {keyCode} = e;
|
|
248
|
+
switch (keyCode) {
|
|
249
|
+
case EKeyCode.Ctrl:
|
|
250
|
+
if (this.drawingCuboid) {
|
|
251
|
+
this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
|
|
252
|
+
valid: false
|
|
253
|
+
});
|
|
254
|
+
this.render();
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
case EKeyCode.Delete:
|
|
258
|
+
if (this.selectedID) {
|
|
259
|
+
this.deleteCuboid(this.selectedID);
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
case EKeyCode.Z:
|
|
263
|
+
this.setIsHidden(!this.isHidden);
|
|
264
|
+
this.render();
|
|
265
|
+
break;
|
|
266
|
+
case EKeyCode.F:
|
|
267
|
+
if (this.selectedID) {
|
|
268
|
+
this.setCuboidValidAndRender(this.selectedID);
|
|
269
|
+
}
|
|
270
|
+
break;
|
|
271
|
+
default: {
|
|
272
|
+
if (this.config.attributeConfigurable) {
|
|
273
|
+
const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
|
|
274
|
+
if (keyCode2Attribute !== void 0) {
|
|
275
|
+
this.setDefaultAttribute(keyCode2Attribute);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
onKeyUp(e) {
|
|
282
|
+
super.onKeyUp(e);
|
|
283
|
+
switch (e.keyCode) {
|
|
284
|
+
case EKeyCode.Ctrl:
|
|
285
|
+
if (this.drawingCuboid) {
|
|
286
|
+
this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
|
|
287
|
+
valid: true
|
|
288
|
+
});
|
|
289
|
+
this.render();
|
|
290
|
+
}
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
onMouseDown(e) {
|
|
295
|
+
if (super.onMouseDown(e) || this.forbidMouseOperation || e.ctrlKey === true) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const {selectedCuboid} = this;
|
|
299
|
+
if (!selectedCuboid || e.button === 2 || e.button === 0 && this.isSpaceKey === true) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (!this.getIsHoverSelectedCuboid(e)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
this.dragStatus = EDragStatus.Start;
|
|
306
|
+
const dragStartCoord = this.getCoordinateUnderZoom(e);
|
|
307
|
+
const DEFAULT_DRAG_INFO = {
|
|
308
|
+
initCuboid: selectedCuboid,
|
|
309
|
+
dragStartCoord
|
|
310
|
+
};
|
|
311
|
+
const highlightInfo = AxisUtils.returnClosePointOrLineInCuboid(dragStartCoord, AxisUtils.changeCuboidByZoom(selectedCuboid, this.zoom));
|
|
312
|
+
const firstHighlightInfo = highlightInfo == null ? void 0 : highlightInfo[0];
|
|
313
|
+
switch (firstHighlightInfo == null ? void 0 : firstHighlightInfo.type) {
|
|
314
|
+
case "point":
|
|
315
|
+
this.dragInfo = __spreadProps(__spreadValues({}, DEFAULT_DRAG_INFO), {
|
|
316
|
+
dragTarget: EDragTarget.Point,
|
|
317
|
+
positions: firstHighlightInfo.positions
|
|
318
|
+
});
|
|
319
|
+
break;
|
|
320
|
+
case "line":
|
|
321
|
+
this.dragInfo = __spreadProps(__spreadValues({}, DEFAULT_DRAG_INFO), {
|
|
322
|
+
dragTarget: EDragTarget.Line,
|
|
323
|
+
positions: firstHighlightInfo.positions
|
|
324
|
+
});
|
|
325
|
+
break;
|
|
326
|
+
default: {
|
|
327
|
+
this.dragInfo = __spreadProps(__spreadValues({}, DEFAULT_DRAG_INFO), {
|
|
328
|
+
dragTarget: EDragTarget.Cuboid
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
onMouseUp(e) {
|
|
334
|
+
if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
335
|
+
return void 0;
|
|
336
|
+
}
|
|
337
|
+
if (this.dragInfo && this.dragStatus === EDragStatus.Move) {
|
|
338
|
+
this.dragInfo = void 0;
|
|
339
|
+
this.dragStatus = EDragStatus.Wait;
|
|
340
|
+
this.history.pushHistory(this.cuboidList);
|
|
341
|
+
this.emit("updateResult");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
|
|
345
|
+
if (e.button === 0) {
|
|
346
|
+
if (this.hoverID && e.ctrlKey && !this.drawingCuboid) {
|
|
347
|
+
this.setCuboidValidAndRender(this.hoverID);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (!this.drawingCuboid) {
|
|
351
|
+
this.createNewDrawingCuboid(e, basicSourceID);
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (this.drawingCuboid) {
|
|
355
|
+
switch (this.drawingStatus) {
|
|
356
|
+
case 2:
|
|
357
|
+
this.closeNewDrawingFrontPlane();
|
|
358
|
+
break;
|
|
359
|
+
case 3:
|
|
360
|
+
this.closeAndCreateNewCuboid();
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
if (e.button === 2) {
|
|
366
|
+
this.rightMouseUp(e);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
onMouseMove(e) {
|
|
370
|
+
var _a;
|
|
371
|
+
if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
if (this.selectedID && this.dragInfo) {
|
|
375
|
+
this.onDragMove(e);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
if (this.drawingCuboid) {
|
|
379
|
+
if (this.drawingFrontPlanesMove(e)) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
this.drawingBackPlaneMove(e);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
this.hoverID = (_a = this.getHoverData(e).hoverID) != null ? _a : "";
|
|
386
|
+
this.onHoverMove(e);
|
|
387
|
+
}
|
|
388
|
+
drawingFrontPlanesMove(e) {
|
|
389
|
+
if (this.drawingCuboid && this.firstClickCoord && this.drawingStatus === 2) {
|
|
390
|
+
const coord = this.getCoordinateInOrigin(e);
|
|
391
|
+
this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
|
|
392
|
+
frontPoints: getPlainPointsByDiagonalPoints(this.firstClickCoord, coord)
|
|
393
|
+
});
|
|
394
|
+
this.render();
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
drawingBackPlaneMove(e) {
|
|
399
|
+
if (this.drawingCuboid && this.firstClickCoord && this.drawingStatus === 3) {
|
|
400
|
+
const coord = this.getCoordinateInOrigin(e);
|
|
401
|
+
if (this.isForbiddenMove(e, this.drawingCuboid)) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
|
|
405
|
+
backPoints: getPointsByBottomRightPoint({coord, points: this.drawingCuboid.frontPoints})
|
|
406
|
+
});
|
|
407
|
+
this.render();
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
onDragMove(e) {
|
|
411
|
+
if (!this.dragInfo || !this.selectedID) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const {dragTarget, initCuboid, dragStartCoord, positions} = this.dragInfo;
|
|
415
|
+
const coordinate = this.getCoordinateUnderZoom(e);
|
|
416
|
+
const offset = {
|
|
417
|
+
x: (coordinate.x - dragStartCoord.x) / this.zoom,
|
|
418
|
+
y: (coordinate.y - dragStartCoord.y) / this.zoom
|
|
419
|
+
};
|
|
420
|
+
this.dragStatus = EDragStatus.Move;
|
|
421
|
+
const newCuboid = getCuboidDragMove({offset, cuboid: initCuboid, dragTarget, positions});
|
|
422
|
+
if ((newCuboid == null ? void 0 : newCuboid.backPoints) && (newCuboid == null ? void 0 : newCuboid.backPoints.br.y) > (newCuboid == null ? void 0 : newCuboid.frontPoints.br.y)) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (newCuboid) {
|
|
426
|
+
this.updateSelectedCuboid(newCuboid);
|
|
427
|
+
}
|
|
428
|
+
this.render();
|
|
429
|
+
}
|
|
430
|
+
onHoverMove(e) {
|
|
431
|
+
const {selectedCuboid} = this;
|
|
432
|
+
if (selectedCuboid) {
|
|
433
|
+
const currentCoord = this.getCoordinateUnderZoom(e);
|
|
434
|
+
const highlightInfo = AxisUtils.returnClosePointOrLineInCuboid(currentCoord, AxisUtils.changeCuboidByZoom(selectedCuboid, this.zoom), {
|
|
435
|
+
zoom: 1 / this.zoom,
|
|
436
|
+
scope: 5
|
|
437
|
+
});
|
|
438
|
+
this.highlightInfo = highlightInfo;
|
|
439
|
+
this.render();
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
createNewDrawingCuboid(e, basicSourceID) {
|
|
443
|
+
if (!this.imgInfo) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
const coordinate = this.getCoordinateInOrigin(e);
|
|
447
|
+
this.drawingCuboid = {
|
|
448
|
+
attribute: this.defaultAttribute,
|
|
449
|
+
direction: ECuboidDirection.Front,
|
|
450
|
+
valid: !e.ctrlKey,
|
|
451
|
+
id: uuid(8, 62),
|
|
452
|
+
sourceID: basicSourceID,
|
|
453
|
+
textAttribute: "",
|
|
454
|
+
order: CommonToolUtils.getMaxOrder(this.cuboidList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID))) + 1,
|
|
455
|
+
frontPoints: {
|
|
456
|
+
tl: coordinate,
|
|
457
|
+
bl: coordinate,
|
|
458
|
+
tr: coordinate,
|
|
459
|
+
br: coordinate
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
this.firstClickCoord = __spreadValues({}, coordinate);
|
|
463
|
+
this.drawingStatus = 2;
|
|
464
|
+
if (this.config.textConfigurable) {
|
|
465
|
+
let textAttribute = "";
|
|
466
|
+
textAttribute = AttributeUtils.getTextAttribute(this.cuboidList.filter((cuboid) => CommonToolUtils.isSameSourceID(cuboid.sourceID, basicSourceID)), this.config.textCheckType);
|
|
467
|
+
this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
|
|
468
|
+
textAttribute
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
closeNewDrawingFrontPlane() {
|
|
473
|
+
this.drawingStatus = 3;
|
|
474
|
+
}
|
|
475
|
+
closeAndCreateNewCuboid() {
|
|
476
|
+
var _a, _b;
|
|
477
|
+
if (!((_a = this.drawingCuboid) == null ? void 0 : _a.frontPoints) || !this.drawingCuboid.backPoints) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
if (this.isNeedCheckCuboidSize && isCuboidWithInLimits({cuboid: this.drawingCuboid, config: this.config}) === false) {
|
|
481
|
+
this.emit("messageInfo", Locale.getMessagesByLocale(EMessage.RectErrorSizeNotice, this.lang));
|
|
482
|
+
} else {
|
|
483
|
+
this.setCuboidList([...this.cuboidList, this.drawingCuboid]);
|
|
484
|
+
this.setSelectedID((_b = this.drawingCuboid) == null ? void 0 : _b.id);
|
|
485
|
+
this.history.pushHistory(this.cuboidList);
|
|
486
|
+
}
|
|
487
|
+
this.clearDrawingStatus();
|
|
488
|
+
this.render();
|
|
489
|
+
}
|
|
490
|
+
deleteSelectedID() {
|
|
491
|
+
this.setSelectedID("");
|
|
492
|
+
}
|
|
493
|
+
clearDrawingStatus() {
|
|
494
|
+
if (this.drawingCuboid) {
|
|
495
|
+
this.drawingCuboid = void 0;
|
|
496
|
+
this.drawingStatus = 1;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
clearActiveStatus() {
|
|
500
|
+
this.clearDrawingStatus();
|
|
501
|
+
this.deleteSelectedID();
|
|
502
|
+
}
|
|
503
|
+
rightMouseUp(e) {
|
|
504
|
+
const {hoverID, hoverCuboid} = this.getHoverData(e);
|
|
505
|
+
this.setSelectedID(hoverID);
|
|
506
|
+
if (hoverCuboid) {
|
|
507
|
+
this.setDefaultAttribute(hoverCuboid.attribute);
|
|
508
|
+
}
|
|
509
|
+
if (this.drawingCuboid) {
|
|
510
|
+
this.clearDrawingStatus();
|
|
511
|
+
}
|
|
512
|
+
this.render();
|
|
513
|
+
}
|
|
514
|
+
renderHighlightCuboidCom(cuboid) {
|
|
515
|
+
const transformCuboid = AxisUtils.changeCuboidByZoom(cuboid, this.zoom, this.currentPos);
|
|
516
|
+
const isHover = transformCuboid.id === this.hoverID;
|
|
517
|
+
const isSelected = transformCuboid.id === this.selectedID;
|
|
518
|
+
const {strokeColor, lineWidth} = this.getStylesToRender(transformCuboid.attribute, transformCuboid.valid);
|
|
519
|
+
const defaultStyle = {
|
|
520
|
+
color: strokeColor,
|
|
521
|
+
thickness: lineWidth
|
|
522
|
+
};
|
|
523
|
+
if (isHover || isSelected) {
|
|
524
|
+
const hoverPointList = getHighlightPoints(transformCuboid);
|
|
525
|
+
hoverPointList.forEach((data) => {
|
|
526
|
+
DrawUtils.drawCircleWithFill(this.canvas, data.point, 5, __spreadValues({}, defaultStyle));
|
|
527
|
+
});
|
|
528
|
+
if (isSelected) {
|
|
529
|
+
const highlightLine = getHighlightLines(transformCuboid);
|
|
530
|
+
highlightLine.forEach((line) => {
|
|
531
|
+
DrawUtils.drawLine(this.canvas, line.p1, line.p2, {color: strokeColor, thickness: lineWidth + 2});
|
|
532
|
+
});
|
|
533
|
+
hoverPointList.forEach((data) => {
|
|
534
|
+
DrawUtils.drawCircleWithFill(this.canvas, data.point, 3, {color: "white"});
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
renderSingleCuboid(cuboid) {
|
|
540
|
+
var _a, _b;
|
|
541
|
+
const transformCuboid = AxisUtils.changeCuboidByZoom(cuboid, this.zoom, this.currentPos);
|
|
542
|
+
const {strokeColor, fillColor} = this.getStylesToRender(transformCuboid.attribute, transformCuboid.valid);
|
|
543
|
+
const lineWidth = (_b = (_a = this.style) == null ? void 0 : _a.width) != null ? _b : 2;
|
|
544
|
+
const {hiddenText = false} = this.style;
|
|
545
|
+
DrawUtils.drawCuboidWithText(this.canvas, transformCuboid, {strokeColor, fillColor, thickness: lineWidth}, {
|
|
546
|
+
config: this.config,
|
|
547
|
+
hiddenText,
|
|
548
|
+
selectedID: this.selectedID
|
|
549
|
+
});
|
|
550
|
+
this.renderTextAttribute();
|
|
551
|
+
}
|
|
552
|
+
setDefaultAttribute(defaultAttribute) {
|
|
553
|
+
const oldDefault = this.defaultAttribute;
|
|
554
|
+
this.defaultAttribute = defaultAttribute != null ? defaultAttribute : "";
|
|
555
|
+
if (oldDefault !== defaultAttribute) {
|
|
556
|
+
this.changeStyle(defaultAttribute);
|
|
557
|
+
this.emit("changeAttributeSidebar");
|
|
558
|
+
const {selectedCuboid} = this;
|
|
559
|
+
if (this._textAttributeInstance) {
|
|
560
|
+
if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(this.defaultAttribute)) {
|
|
561
|
+
this._textAttributeInstance.clearTextAttribute();
|
|
562
|
+
} else {
|
|
563
|
+
this._textAttributeInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (selectedCuboid) {
|
|
567
|
+
this.setCuboidList(this.cuboidList.map((v) => {
|
|
568
|
+
if (v.id === this.selectedID) {
|
|
569
|
+
return __spreadProps(__spreadValues({}, v), {
|
|
570
|
+
attribute: this.defaultAttribute
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
return v;
|
|
574
|
+
}));
|
|
575
|
+
this.history.pushHistory(this.cuboidList);
|
|
576
|
+
this.render();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (this.drawingCuboid) {
|
|
580
|
+
this.drawingCuboid = __spreadProps(__spreadValues({}, this.drawingCuboid), {
|
|
581
|
+
attribute: this.defaultAttribute
|
|
582
|
+
});
|
|
583
|
+
this.render();
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
renderToggleButton() {
|
|
588
|
+
const {selectedCuboid} = this;
|
|
589
|
+
if (!this.ctx || !selectedCuboid) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
const {attribute, valid} = selectedCuboid;
|
|
593
|
+
const {strokeColor: color} = this.getStylesToRender(attribute, valid);
|
|
594
|
+
if (!this.toggleButtonInstance) {
|
|
595
|
+
this.toggleButtonInstance = new CuboidToggleButtonClass({
|
|
596
|
+
container: this.container,
|
|
597
|
+
cuboidButtonMove: (type) => this.updateMouseOperation(type),
|
|
598
|
+
toggleDirection: (direction) => this.toggleDirection(direction)
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
const toggleOffset = getToggleDirectionButtonOffset({
|
|
602
|
+
cuboid: selectedCuboid,
|
|
603
|
+
zoom: this.zoom,
|
|
604
|
+
currentPos: this.currentPos
|
|
605
|
+
});
|
|
606
|
+
this.toggleButtonInstance.update({
|
|
607
|
+
left: toggleOffset.left,
|
|
608
|
+
top: toggleOffset.top,
|
|
609
|
+
color
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
renderTextAttribute() {
|
|
613
|
+
var _a;
|
|
614
|
+
const {selectedCuboid} = this;
|
|
615
|
+
if (!this.ctx || this.config.textConfigurable === false || !selectedCuboid) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const {strokeColor: color} = this.getStylesToRender(selectedCuboid.attribute, selectedCuboid.valid);
|
|
619
|
+
const {attribute, textAttribute, frontPoints} = selectedCuboid;
|
|
620
|
+
const offset = getCuboidTextAttributeOffset({
|
|
621
|
+
cuboid: selectedCuboid,
|
|
622
|
+
currentPos: this.currentPos,
|
|
623
|
+
zoom: this.zoom
|
|
624
|
+
});
|
|
625
|
+
const newWidth = (frontPoints.br.x - frontPoints.bl.x) * this.zoom * 0.8;
|
|
626
|
+
if (!this._textAttributeInstance) {
|
|
627
|
+
this._textAttributeInstance = new TextAttributeClass({
|
|
628
|
+
width: DEFAULT_TEXT_MAX_WIDTH,
|
|
629
|
+
container: this.container,
|
|
630
|
+
icon: this.getTextIconSvg(attribute),
|
|
631
|
+
color,
|
|
632
|
+
getCurrentSelectedData: this.getCurrentSelectedData,
|
|
633
|
+
updateSelectedTextAttribute: this.updateSelectedTextAttribute
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
if (this._textAttributeInstance && !((_a = this._textAttributeInstance) == null ? void 0 : _a.isExit)) {
|
|
637
|
+
this._textAttributeInstance.appendToContainer();
|
|
638
|
+
}
|
|
639
|
+
this._textAttributeInstance.update(`${textAttribute}`, {
|
|
640
|
+
left: offset.left,
|
|
641
|
+
top: offset.top,
|
|
642
|
+
color,
|
|
643
|
+
width: newWidth
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
renderDrawing() {
|
|
647
|
+
if (this.drawingCuboid) {
|
|
648
|
+
this.renderSingleCuboid(this.drawingCuboid);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
renderStatic() {
|
|
652
|
+
if (!this.isHidden) {
|
|
653
|
+
this.currentShowList.forEach((cuboid) => this.renderSingleCuboid(cuboid));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
renderSelected() {
|
|
657
|
+
var _a;
|
|
658
|
+
const {selectedCuboid} = this;
|
|
659
|
+
if (selectedCuboid) {
|
|
660
|
+
this.renderSingleCuboid(selectedCuboid);
|
|
661
|
+
this.renderHighlightCuboidCom(selectedCuboid);
|
|
662
|
+
this.renderToggleButton();
|
|
663
|
+
} else {
|
|
664
|
+
(_a = this.toggleButtonInstance) == null ? void 0 : _a.clearCuboidButtonDOM();
|
|
665
|
+
this.toggleButtonInstance = void 0;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
updateMouseOperation(type) {
|
|
669
|
+
if (type === "in") {
|
|
670
|
+
this.setForbidCursorLine(true);
|
|
671
|
+
this.setForbidOperation(true);
|
|
672
|
+
this.setShowDefaultCursor(true);
|
|
673
|
+
} else {
|
|
674
|
+
this.setForbidCursorLine(false);
|
|
675
|
+
this.setShowDefaultCursor(false);
|
|
676
|
+
this.setForbidOperation(false);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
toggleDirection(direction) {
|
|
680
|
+
if (this.cuboidList && this.selectedCuboid) {
|
|
681
|
+
this.setCuboidList(this.cuboidList.map((i) => {
|
|
682
|
+
var _a;
|
|
683
|
+
return i.id === ((_a = this.selectedCuboid) == null ? void 0 : _a.id) ? __spreadProps(__spreadValues({}, i), {direction}) : i;
|
|
684
|
+
}));
|
|
685
|
+
this.history.pushHistory(this.cuboidList);
|
|
686
|
+
this.render();
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
renderHover() {
|
|
690
|
+
var _a;
|
|
691
|
+
if (this.dragInfo) {
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
(_a = this.highlightInfo) == null ? void 0 : _a.forEach((data) => {
|
|
695
|
+
var _a2, _b;
|
|
696
|
+
const {strokeColor} = this.getStylesToRender(data.originCuboid.attribute, data.originCuboid.valid);
|
|
697
|
+
const thickness = 8;
|
|
698
|
+
switch (data.type) {
|
|
699
|
+
case "point":
|
|
700
|
+
(_a2 = data.points) == null ? void 0 : _a2.forEach((point) => {
|
|
701
|
+
DrawUtils.drawCircleWithFill(this.canvas, AxisUtils.changePointByZoom(point, this.zoom, this.currentPos), thickness, {
|
|
702
|
+
color: strokeColor
|
|
703
|
+
});
|
|
704
|
+
});
|
|
705
|
+
break;
|
|
706
|
+
case "line": {
|
|
707
|
+
const pointList = (_b = data.points) == null ? void 0 : _b.map((point) => AxisUtils.changePointByZoom(point, this.zoom, this.currentPos));
|
|
708
|
+
if (pointList) {
|
|
709
|
+
DrawUtils.drawLineWithPointList(this.canvas, pointList, {color: strokeColor, thickness});
|
|
710
|
+
}
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
renderCuboid() {
|
|
717
|
+
this.renderStatic();
|
|
718
|
+
this.renderDrawing();
|
|
719
|
+
this.renderSelected();
|
|
720
|
+
this.renderHover();
|
|
721
|
+
}
|
|
722
|
+
render() {
|
|
723
|
+
if (!this.ctx) {
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
super.render();
|
|
727
|
+
this.renderCuboid();
|
|
728
|
+
this.renderCursorLine(this.getLineColor(this.defaultAttribute));
|
|
729
|
+
}
|
|
730
|
+
undo() {
|
|
731
|
+
const cuboidList = this.history.undo();
|
|
732
|
+
if (cuboidList) {
|
|
733
|
+
if (cuboidList.length !== this.cuboidList.length) {
|
|
734
|
+
this.setSelectedID("");
|
|
735
|
+
}
|
|
736
|
+
this.setCuboidList(cuboidList, true);
|
|
737
|
+
this.render();
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
redo() {
|
|
741
|
+
const cuboidList = this.history.redo();
|
|
742
|
+
if (cuboidList) {
|
|
743
|
+
if (cuboidList.length !== this.cuboidList.length) {
|
|
744
|
+
this.setSelectedID("");
|
|
745
|
+
}
|
|
746
|
+
this.setCuboidList(cuboidList, true);
|
|
747
|
+
this.render();
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
export { CuboidOperation as default };
|