@labelbee/lb-annotation 1.14.0-alpha.3 → 1.14.0-alpha.5
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/_virtual/MathUtilsWorker.js +1 -8
- package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -35
- package/dist/_virtual/filterBoxWorker.js +1 -8
- package/dist/_virtual/highlightWorker.js +1 -8
- package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -5
- package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
- package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +12 -5
- package/dist/assets/attributeIcon/icon_editFEN.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editHUANG.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editLAN.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editLV.svg.js +1 -5
- package/dist/assets/attributeIcon/icon_editQING.svg.js +1 -5
- package/dist/constant/annotation.js +1 -127
- package/dist/constant/annotationTask.js +1 -30
- package/dist/constant/defaultConfig.js +1 -266
- package/dist/constant/keyCode.js +1 -38
- package/dist/constant/style.js +1 -98
- package/dist/constant/tool.js +1 -236
- package/dist/core/index.js +1 -150
- package/dist/core/pointCloud/OrbitControls.js +1 -665
- package/dist/core/pointCloud/PCDLoader.js +2 -260
- package/dist/core/pointCloud/annotation.js +1 -215
- package/dist/core/pointCloud/cache.js +1 -53
- package/dist/core/pointCloud/index.js +5 -991
- package/dist/core/pointCloud/matrix.js +1 -138
- package/dist/core/scheduler.js +1 -233
- package/dist/core/toolOperation/LineToolOperation.js +1 -1434
- package/dist/core/toolOperation/ScribbleTool.js +1 -292
- package/dist/core/toolOperation/TextToolOperation.js +1 -131
- package/dist/core/toolOperation/ViewOperation.js +1 -556
- package/dist/core/toolOperation/basicToolOperation.js +1 -881
- package/dist/core/toolOperation/checkOperation.js +1 -208
- package/dist/core/toolOperation/cuboidOperation.js +1 -754
- package/dist/core/toolOperation/cuboidToggleButtonClass.js +7 -152
- package/dist/core/toolOperation/eventListener.js +1 -37
- package/dist/core/toolOperation/measureOperation.js +1 -41
- package/dist/core/toolOperation/pointCloud2dOperation.js +1 -365
- package/dist/core/toolOperation/pointOperation.js +1 -696
- package/dist/core/toolOperation/polygonOperation.js +1 -1251
- package/dist/core/toolOperation/rectOperation.js +1 -1233
- package/dist/core/toolOperation/segmentByRect.js +1 -174
- package/dist/core/toolOperation/tagOperation.js +3 -201
- package/dist/core/toolOperation/textAttributeClass.js +16 -182
- package/dist/index.js +1 -185
- package/dist/locales/constants.js +1 -24
- package/dist/locales/en_US/message.js +1 -25
- package/dist/locales/index.js +1 -19
- package/dist/locales/zh_CN/message.js +1 -25
- package/dist/newCore/CanvasScheduler.js +1 -35
- package/dist/utils/ActionsHistory.js +1 -84
- package/dist/utils/ImgUtils.js +1 -23
- package/dist/utils/MathUtils.js +2 -385
- package/dist/utils/VectorUtils.js +1 -25
- package/dist/utils/tool/AttributeUtils.js +1 -218
- package/dist/utils/tool/AxisUtils.js +1 -340
- package/dist/utils/tool/CanvasUtils.js +1 -62
- package/dist/utils/tool/CommonToolUtils.js +1 -174
- package/dist/utils/tool/CuboidUtils.js +1 -704
- package/dist/utils/tool/DblClickEventListener.js +1 -102
- package/dist/utils/tool/DrawUtils.js +3 -492
- package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -53
- package/dist/utils/tool/ImgPosUtils.js +1 -58
- package/dist/utils/tool/LineToolUtils.js +1 -261
- package/dist/utils/tool/MarkerUtils.js +1 -56
- package/dist/utils/tool/PolygonUtils.js +1 -460
- package/dist/utils/tool/RectUtils.js +1 -155
- package/dist/utils/tool/RenderDomClass.js +7 -57
- package/dist/utils/tool/RenderDomUtils.js +4 -21
- package/dist/utils/tool/StyleUtils.js +1 -31
- package/dist/utils/tool/TagUtils.js +1 -129
- package/dist/utils/tool/UnitUtils.js +1 -12
- package/dist/utils/tool/ZoomUtils.js +1 -72
- package/dist/utils/tool/polygonTool.js +1 -133
- package/dist/utils/uuid.js +1 -26
- package/es/_virtual/MathUtilsWorker.js +1 -6
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -31
- package/es/_virtual/filterBoxWorker.js +1 -6
- package/es/_virtual/highlightWorker.js +1 -6
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -3
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -3
- package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -3
- package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -3
- package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -3
- package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -3
- package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -3
- package/es/assets/attributeIcon/icon_editFEN.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editLAN.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editLV.svg.js +1 -3
- package/es/assets/attributeIcon/icon_editQING.svg.js +1 -3
- package/es/constant/annotation.js +1 -113
- package/es/constant/annotationTask.js +1 -25
- package/es/constant/defaultConfig.js +1 -260
- package/es/constant/keyCode.js +1 -36
- package/es/constant/style.js +1 -74
- package/es/constant/tool.js +1 -220
- package/es/core/index.js +1 -148
- package/es/core/pointCloud/OrbitControls.js +1 -661
- package/es/core/pointCloud/PCDLoader.js +2 -256
- package/es/core/pointCloud/annotation.js +1 -211
- package/es/core/pointCloud/cache.js +1 -49
- package/es/core/pointCloud/index.js +5 -962
- package/es/core/pointCloud/matrix.js +1 -109
- package/es/core/scheduler.js +1 -228
- package/es/core/toolOperation/LineToolOperation.js +1 -1421
- package/es/core/toolOperation/ScribbleTool.js +1 -290
- package/es/core/toolOperation/TextToolOperation.js +1 -129
- package/es/core/toolOperation/ViewOperation.js +1 -549
- package/es/core/toolOperation/basicToolOperation.js +1 -877
- package/es/core/toolOperation/checkOperation.js +1 -206
- package/es/core/toolOperation/cuboidOperation.js +1 -752
- package/es/core/toolOperation/cuboidToggleButtonClass.js +7 -150
- package/es/core/toolOperation/eventListener.js +1 -35
- package/es/core/toolOperation/measureOperation.js +1 -39
- package/es/core/toolOperation/pointCloud2dOperation.js +1 -359
- package/es/core/toolOperation/pointOperation.js +1 -690
- package/es/core/toolOperation/polygonOperation.js +1 -1245
- package/es/core/toolOperation/rectOperation.js +1 -1228
- package/es/core/toolOperation/segmentByRect.js +1 -172
- package/es/core/toolOperation/tagOperation.js +3 -199
- package/es/core/toolOperation/textAttributeClass.js +16 -180
- package/es/index.js +1 -46
- package/es/locales/constants.js +1 -22
- package/es/locales/en_US/message.js +1 -23
- package/es/locales/index.js +1 -17
- package/es/locales/zh_CN/message.js +1 -23
- package/es/newCore/CanvasScheduler.js +1 -31
- package/es/utils/ActionsHistory.js +1 -78
- package/es/utils/ImgUtils.js +1 -21
- package/es/utils/MathUtils.js +2 -380
- package/es/utils/VectorUtils.js +1 -23
- package/es/utils/tool/AttributeUtils.js +1 -212
- package/es/utils/tool/AxisUtils.js +1 -335
- package/es/utils/tool/CanvasUtils.js +1 -60
- package/es/utils/tool/CommonToolUtils.js +1 -172
- package/es/utils/tool/CuboidUtils.js +1 -680
- package/es/utils/tool/DblClickEventListener.js +1 -100
- package/es/utils/tool/DrawUtils.js +3 -490
- package/es/utils/tool/EnhanceCommonToolUtils.js +1 -48
- package/es/utils/tool/ImgPosUtils.js +1 -56
- package/es/utils/tool/LineToolUtils.js +1 -255
- package/es/utils/tool/MarkerUtils.js +1 -54
- package/es/utils/tool/PolygonUtils.js +1 -458
- package/es/utils/tool/RectUtils.js +1 -153
- package/es/utils/tool/RenderDomClass.js +7 -55
- package/es/utils/tool/RenderDomUtils.js +4 -19
- package/es/utils/tool/StyleUtils.js +1 -29
- package/es/utils/tool/TagUtils.js +1 -127
- package/es/utils/tool/UnitUtils.js +1 -10
- package/es/utils/tool/ZoomUtils.js +1 -70
- package/es/utils/tool/polygonTool.js +1 -126
- package/es/utils/uuid.js +1 -24
- package/package.json +3 -4
- package/LICENSE +0 -203
- package/dist/core/pointCloud/segmentation.js +0 -144
- package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +0 -26
- package/dist/core/pointCloud/selector/Sse3dSelector.js +0 -16
- package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
- package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
- package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
- package/es/core/pointCloud/segmentation.js +0 -120
- package/es/core/pointCloud/selector/Sse3dLassoSelector.js +0 -24
- package/es/core/pointCloud/selector/Sse3dSelector.js +0 -14
- package/es/core/toolOperation/scribbleTool2.js +0 -249
|
@@ -1,102 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var AxisUtils = require('./AxisUtils.js');
|
|
4
|
-
|
|
5
|
-
class DblClickEventListener {
|
|
6
|
-
constructor(dom, delay) {
|
|
7
|
-
this.rcTime = 0;
|
|
8
|
-
this.mouseDownTime = 0;
|
|
9
|
-
this.onMouseDown = () => {
|
|
10
|
-
this.mouseDownTime = new Date().getTime();
|
|
11
|
-
};
|
|
12
|
-
this.dom = dom;
|
|
13
|
-
this.isDoubleClick = false;
|
|
14
|
-
this.delay = delay;
|
|
15
|
-
}
|
|
16
|
-
getRcTime() {
|
|
17
|
-
return this.rcTime;
|
|
18
|
-
}
|
|
19
|
-
getCoord(e) {
|
|
20
|
-
return {
|
|
21
|
-
x: e.clientX,
|
|
22
|
-
y: e.clientY
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
removeEvent() {
|
|
26
|
-
if (!this.dom) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
this.dom.removeEventListener("mouseup", this.mouseUp);
|
|
30
|
-
this.dom.removeEventListener("mousemove", this.mouseMove);
|
|
31
|
-
this.dom.removeEventListener("dblclick", this.dblclick);
|
|
32
|
-
this.dom.removeEventListener("mousedown", this.onMouseDown);
|
|
33
|
-
}
|
|
34
|
-
addEvent(singleClickFun, leftDblClick, rightDblClick, isAllowDouble) {
|
|
35
|
-
if (!this.dom) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this.removeEvent();
|
|
39
|
-
this.mouseUp = (e) => {
|
|
40
|
-
const cTime = new Date().getTime();
|
|
41
|
-
const isDoubleClick = isAllowDouble ? isAllowDouble(e) : true;
|
|
42
|
-
if (cTime - this.mouseDownTime > this.delay || isDoubleClick !== true) {
|
|
43
|
-
singleClickFun(e);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (e.button === 2) {
|
|
47
|
-
if (this.rcTime === 0) {
|
|
48
|
-
setTimeout(() => {
|
|
49
|
-
this.rcTime = 0;
|
|
50
|
-
}, this.delay);
|
|
51
|
-
this.rcTime = cTime;
|
|
52
|
-
} else {
|
|
53
|
-
if (cTime - this.rcTime < this.delay) {
|
|
54
|
-
rightDblClick(e);
|
|
55
|
-
clearTimeout(this.setTimeFun);
|
|
56
|
-
this.cacheFunction = void 0;
|
|
57
|
-
}
|
|
58
|
-
this.rcTime = 0;
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (this.setTimeFun) {
|
|
63
|
-
clearTimeout(this.setTimeFun);
|
|
64
|
-
}
|
|
65
|
-
this.clickCoord = this.getCoord(e);
|
|
66
|
-
this.cacheFunction = () => singleClickFun(e);
|
|
67
|
-
this.setTimeFun = setTimeout(() => {
|
|
68
|
-
if (this.isDoubleClick) {
|
|
69
|
-
this.isDoubleClick = false;
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.cacheFunction();
|
|
73
|
-
this.clickCoord = void 0;
|
|
74
|
-
}, this.delay);
|
|
75
|
-
};
|
|
76
|
-
this.mouseMove = (e) => {
|
|
77
|
-
const currentCoord = this.getCoord(e);
|
|
78
|
-
if (this.clickCoord && !AxisUtils["default"].getIsInScope(currentCoord, this.clickCoord, 10)) {
|
|
79
|
-
if (this.cacheFunction) {
|
|
80
|
-
this.cacheFunction();
|
|
81
|
-
}
|
|
82
|
-
this.clickCoord = void 0;
|
|
83
|
-
this.cacheFunction = null;
|
|
84
|
-
clearTimeout(this.setTimeFun);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
this.dblclick = (e) => {
|
|
88
|
-
this.isDoubleClick = true;
|
|
89
|
-
this.clickCoord = void 0;
|
|
90
|
-
leftDblClick(e);
|
|
91
|
-
};
|
|
92
|
-
this.dom.addEventListener("mouseup", this.mouseUp);
|
|
93
|
-
this.dom.addEventListener("mousemove", this.mouseMove);
|
|
94
|
-
this.dom.addEventListener("dblclick", this.dblclick);
|
|
95
|
-
this.dom.addEventListener("mousedown", this.onMouseDown);
|
|
96
|
-
}
|
|
97
|
-
clearRightDblClick() {
|
|
98
|
-
this.rcTime = 0;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = DblClickEventListener;
|
|
1
|
+
"use strict";var AxisUtils=require("./AxisUtils.js");class DblClickEventListener{constructor(e,s){this.rcTime=0,this.mouseDownTime=0,this.onMouseDown=()=>{this.mouseDownTime=new Date().getTime()},this.dom=e,this.isDoubleClick=!1,this.delay=s}getRcTime(){return this.rcTime}getCoord(e){return{x:e.clientX,y:e.clientY}}removeEvent(){!this.dom||(this.dom.removeEventListener("mouseup",this.mouseUp),this.dom.removeEventListener("mousemove",this.mouseMove),this.dom.removeEventListener("dblclick",this.dblclick),this.dom.removeEventListener("mousedown",this.onMouseDown))}addEvent(e,s,c,o){!this.dom||(this.removeEvent(),this.mouseUp=i=>{const t=new Date().getTime(),h=o?o(i):!0;if(t-this.mouseDownTime>this.delay||h!==!0){e(i);return}if(i.button===2)if(this.rcTime===0)setTimeout(()=>{this.rcTime=0},this.delay),this.rcTime=t;else{t-this.rcTime<this.delay&&(c(i),clearTimeout(this.setTimeFun),this.cacheFunction=void 0),this.rcTime=0;return}this.setTimeFun&&clearTimeout(this.setTimeFun),this.clickCoord=this.getCoord(i),this.cacheFunction=()=>e(i),this.setTimeFun=setTimeout(()=>{if(this.isDoubleClick){this.isDoubleClick=!1;return}this.cacheFunction(),this.clickCoord=void 0},this.delay)},this.mouseMove=i=>{const t=this.getCoord(i);this.clickCoord&&!AxisUtils.default.getIsInScope(t,this.clickCoord,10)&&(this.cacheFunction&&this.cacheFunction(),this.clickCoord=void 0,this.cacheFunction=null,clearTimeout(this.setTimeFun))},this.dblclick=i=>{this.isDoubleClick=!0,this.clickCoord=void 0,s(i)},this.dom.addEventListener("mouseup",this.mouseUp),this.dom.addEventListener("mousemove",this.mouseMove),this.dom.addEventListener("dblclick",this.dblclick),this.dom.addEventListener("mousedown",this.onMouseDown))}clearRightDblClick(){this.rcTime=0}}module.exports=DblClickEventListener;
|
|
@@ -1,492 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var PolygonUtils = require('./PolygonUtils.js');
|
|
5
|
-
var UnitUtils = require('./UnitUtils.js');
|
|
6
|
-
var AxisUtils = require('./AxisUtils.js');
|
|
7
|
-
var CuboidUtils = require('./CuboidUtils.js');
|
|
8
|
-
var AttributeUtils = require('./AttributeUtils.js');
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __defProps = Object.defineProperties;
|
|
12
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
13
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
14
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
16
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
17
|
-
var __spreadValues = (a, b) => {
|
|
18
|
-
for (var prop in b || (b = {}))
|
|
19
|
-
if (__hasOwnProp.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
if (__getOwnPropSymbols)
|
|
22
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
23
|
-
if (__propIsEnum.call(b, prop))
|
|
24
|
-
__defNormalProp(a, prop, b[prop]);
|
|
25
|
-
}
|
|
26
|
-
return a;
|
|
27
|
-
};
|
|
28
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
29
|
-
const DEFAULT_ZOOM = 1;
|
|
30
|
-
const DEFAULT_CURRENT_POS = {
|
|
31
|
-
x: 0,
|
|
32
|
-
y: 0
|
|
33
|
-
};
|
|
34
|
-
const DEFAULT_ROTATE = 0;
|
|
35
|
-
const DEFAULT_COLOR = "";
|
|
36
|
-
const _DrawUtils = class {
|
|
37
|
-
static drawLine(canvas, startPoint, endPoint, options = {}) {
|
|
38
|
-
const ctx = canvas.getContext("2d");
|
|
39
|
-
const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", lineDash} = options;
|
|
40
|
-
ctx.save();
|
|
41
|
-
ctx.strokeStyle = color;
|
|
42
|
-
ctx.lineWidth = thickness;
|
|
43
|
-
ctx.lineCap = lineCap;
|
|
44
|
-
if (lineDash) {
|
|
45
|
-
ctx.setLineDash(lineDash);
|
|
46
|
-
}
|
|
47
|
-
ctx.beginPath();
|
|
48
|
-
ctx.moveTo(startPoint.x, startPoint.y);
|
|
49
|
-
ctx.lineTo(endPoint.x + 1, endPoint.y + 1);
|
|
50
|
-
ctx.stroke();
|
|
51
|
-
ctx.restore();
|
|
52
|
-
}
|
|
53
|
-
static drawRect(canvas, rect, options = {}) {
|
|
54
|
-
const ctx = canvas.getContext("2d");
|
|
55
|
-
const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", hiddenText = false, lineDash} = options;
|
|
56
|
-
ctx.save();
|
|
57
|
-
ctx.strokeStyle = color;
|
|
58
|
-
ctx.lineWidth = thickness;
|
|
59
|
-
ctx.lineCap = lineCap;
|
|
60
|
-
if (Array.isArray(lineDash)) {
|
|
61
|
-
ctx.setLineDash(lineDash);
|
|
62
|
-
}
|
|
63
|
-
ctx.fillStyle = color;
|
|
64
|
-
ctx.strokeRect(rect.x, rect.y, rect.width, rect.height);
|
|
65
|
-
if (hiddenText === false) {
|
|
66
|
-
let showText = "";
|
|
67
|
-
if (rect.attribute) {
|
|
68
|
-
showText = `${showText} ${rect.attribute}`;
|
|
69
|
-
}
|
|
70
|
-
this.drawText(canvas, {x: rect.x, y: rect.y - 5}, showText);
|
|
71
|
-
if (rect.textAttribute) {
|
|
72
|
-
const text = `${~~rect.width} * ${~~rect.height}`;
|
|
73
|
-
const textSizeWidth = text.length * 7;
|
|
74
|
-
const marginTop = 0;
|
|
75
|
-
const textWidth = Math.max(20, rect.width - textSizeWidth);
|
|
76
|
-
this.drawText(canvas, {x: rect.x, y: rect.y + rect.height + 20 + marginTop}, rect.textAttribute, {
|
|
77
|
-
textMaxWidth: textWidth
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
ctx.restore();
|
|
82
|
-
}
|
|
83
|
-
static drawRectWithFill(canvas, rect, options = {}) {
|
|
84
|
-
const ctx = canvas.getContext("2d");
|
|
85
|
-
const {color = DEFAULT_COLOR} = options;
|
|
86
|
-
ctx.save();
|
|
87
|
-
ctx.fillStyle = color;
|
|
88
|
-
ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
89
|
-
ctx.restore();
|
|
90
|
-
}
|
|
91
|
-
static drawTagByDom(parent, text, id) {
|
|
92
|
-
const parentNode = parent;
|
|
93
|
-
if (!((text == null ? void 0 : text.length) > 0)) {
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const dom = document.createElement("div");
|
|
97
|
-
dom.innerHTML = text;
|
|
98
|
-
dom.setAttribute("id", id);
|
|
99
|
-
parentNode == null ? void 0 : parentNode.appendChild(dom);
|
|
100
|
-
return dom;
|
|
101
|
-
}
|
|
102
|
-
static drawTag(canvas, tagList) {
|
|
103
|
-
var _a;
|
|
104
|
-
const parentNode = canvas == null ? void 0 : canvas.parentNode;
|
|
105
|
-
const oldDom = window.self.document.getElementById("tagToolTag");
|
|
106
|
-
if (oldDom && parentNode && parentNode.contains(oldDom)) {
|
|
107
|
-
parentNode == null ? void 0 : parentNode.removeChild(oldDom);
|
|
108
|
-
}
|
|
109
|
-
if (!((tagList == null ? void 0 : tagList.length) > 0)) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const dom = document.createElement("div");
|
|
113
|
-
dom.innerHTML = (_a = tagList.reduce((acc, cur) => {
|
|
114
|
-
return `${acc}${cur.keyName}: ${cur.value.join(` \u3001 `)}
|
|
115
|
-
`;
|
|
116
|
-
}, "")) != null ? _a : "";
|
|
117
|
-
dom.setAttribute("id", "tagToolTag");
|
|
118
|
-
parentNode == null ? void 0 : parentNode.appendChild(dom);
|
|
119
|
-
return dom;
|
|
120
|
-
}
|
|
121
|
-
static drawLineWithPointList(canvas, pointList, options = {}) {
|
|
122
|
-
if (pointList.length < 2) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const ctx = canvas.getContext("2d");
|
|
126
|
-
const {
|
|
127
|
-
color = DEFAULT_COLOR,
|
|
128
|
-
thickness = 1,
|
|
129
|
-
lineCap = "round",
|
|
130
|
-
lineType = tool.ELineTypes.Line,
|
|
131
|
-
lineDash,
|
|
132
|
-
hoverEdgeIndex
|
|
133
|
-
} = options;
|
|
134
|
-
ctx.save();
|
|
135
|
-
const setStyle = () => {
|
|
136
|
-
ctx.strokeStyle = color;
|
|
137
|
-
ctx.lineWidth = thickness;
|
|
138
|
-
ctx.lineCap = lineCap;
|
|
139
|
-
if (Array.isArray(lineDash)) {
|
|
140
|
-
ctx.setLineDash(lineDash);
|
|
141
|
-
} else {
|
|
142
|
-
ctx.setLineDash([]);
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
setStyle();
|
|
146
|
-
if (lineType === tool.ELineTypes.Curve) {
|
|
147
|
-
if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
|
|
148
|
-
pointList.push(pointList[0]);
|
|
149
|
-
}
|
|
150
|
-
pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList], tool.SEGMENT_NUMBER);
|
|
151
|
-
if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
|
|
152
|
-
pointList = pointList.slice((tool.SEGMENT_NUMBER + 1) * hoverEdgeIndex, (tool.SEGMENT_NUMBER + 1) * (hoverEdgeIndex + 1));
|
|
153
|
-
}
|
|
154
|
-
} else if (hoverEdgeIndex !== void 0 && hoverEdgeIndex > -1) {
|
|
155
|
-
pointList = [...pointList, pointList[0]];
|
|
156
|
-
pointList = pointList.slice(hoverEdgeIndex, hoverEdgeIndex + 2);
|
|
157
|
-
}
|
|
158
|
-
const specialEdgeList = [];
|
|
159
|
-
ctx.beginPath();
|
|
160
|
-
ctx.moveTo(pointList[0].x, pointList[0].y);
|
|
161
|
-
for (let i = 0; i < pointList.length - 1; i++) {
|
|
162
|
-
if (pointList[i].specialEdge) {
|
|
163
|
-
specialEdgeList.push({
|
|
164
|
-
i1: i,
|
|
165
|
-
i2: i + 1
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
ctx.lineTo(pointList[i + 1].x, pointList[i + 1].y);
|
|
169
|
-
}
|
|
170
|
-
ctx.stroke();
|
|
171
|
-
ctx.save();
|
|
172
|
-
ctx.lineWidth = thickness * 0.8;
|
|
173
|
-
ctx.lineCap = "butt";
|
|
174
|
-
ctx.strokeStyle = "white";
|
|
175
|
-
ctx.setLineDash([3, 3]);
|
|
176
|
-
specialEdgeList.forEach((v) => {
|
|
177
|
-
const point1 = pointList[v.i1];
|
|
178
|
-
const point2 = pointList[v.i2];
|
|
179
|
-
ctx.beginPath();
|
|
180
|
-
ctx.moveTo(point1.x, point1.y);
|
|
181
|
-
ctx.lineTo(point2.x, point2.y);
|
|
182
|
-
ctx.stroke();
|
|
183
|
-
});
|
|
184
|
-
ctx.restore();
|
|
185
|
-
const DEFAULT_SPECIAL_POINT_RADIUS = 4;
|
|
186
|
-
const DEFAULT_BORDER = 2;
|
|
187
|
-
pointList.forEach((p) => {
|
|
188
|
-
if (p.specialPoint) {
|
|
189
|
-
this.drawSpecialPoint(canvas, p, DEFAULT_SPECIAL_POINT_RADIUS + DEFAULT_BORDER, color);
|
|
190
|
-
this.drawSpecialPoint(canvas, p, DEFAULT_SPECIAL_POINT_RADIUS, "white");
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
ctx.restore();
|
|
194
|
-
return pointList;
|
|
195
|
-
}
|
|
196
|
-
static drawCircle(canvas, anchorPoint, radius, options = {}) {
|
|
197
|
-
const ctx = canvas.getContext("2d");
|
|
198
|
-
const {
|
|
199
|
-
startAngleDeg = 0,
|
|
200
|
-
endAngleDeg = 360,
|
|
201
|
-
thickness = 1,
|
|
202
|
-
color = DEFAULT_COLOR,
|
|
203
|
-
fill = DEFAULT_COLOR
|
|
204
|
-
} = options;
|
|
205
|
-
const startAngleRad = UnitUtils.deg2rad(startAngleDeg);
|
|
206
|
-
const endAngleRad = UnitUtils.deg2rad(endAngleDeg);
|
|
207
|
-
ctx.save();
|
|
208
|
-
ctx.beginPath();
|
|
209
|
-
ctx.strokeStyle = color;
|
|
210
|
-
ctx.fillStyle = fill;
|
|
211
|
-
ctx.lineWidth = thickness;
|
|
212
|
-
ctx.arc(anchorPoint.x, anchorPoint.y, radius, startAngleRad, endAngleRad, false);
|
|
213
|
-
ctx.stroke();
|
|
214
|
-
if (fill) {
|
|
215
|
-
ctx.fill();
|
|
216
|
-
}
|
|
217
|
-
ctx.closePath();
|
|
218
|
-
ctx.restore();
|
|
219
|
-
}
|
|
220
|
-
static drawCircleWithFill(canvas, anchorPoint, radius = 3, options = {}) {
|
|
221
|
-
const ctx = canvas.getContext("2d");
|
|
222
|
-
const {color = DEFAULT_COLOR} = options;
|
|
223
|
-
ctx.save();
|
|
224
|
-
const startAngleRad = UnitUtils.deg2rad(0);
|
|
225
|
-
const endAngleRad = UnitUtils.deg2rad(360);
|
|
226
|
-
ctx.fillStyle = color;
|
|
227
|
-
ctx.beginPath();
|
|
228
|
-
ctx.arc(anchorPoint.x, anchorPoint.y, radius, startAngleRad, endAngleRad, false);
|
|
229
|
-
ctx.fill();
|
|
230
|
-
ctx.restore();
|
|
231
|
-
}
|
|
232
|
-
static drawSpecialPoint(canvas, point, pointRadius = 6, fillStyle) {
|
|
233
|
-
const ctx = canvas.getContext("2d");
|
|
234
|
-
const {x, y} = point;
|
|
235
|
-
ctx.save();
|
|
236
|
-
ctx.beginPath();
|
|
237
|
-
ctx.fillStyle = fillStyle;
|
|
238
|
-
const newPointRadius = pointRadius * 1.5;
|
|
239
|
-
const xl = newPointRadius * Math.sqrt(3) / 2;
|
|
240
|
-
const yl = newPointRadius / 2;
|
|
241
|
-
ctx.moveTo(x, y - newPointRadius);
|
|
242
|
-
ctx.lineTo(x - xl, y + yl);
|
|
243
|
-
ctx.lineTo(x + xl, y + yl);
|
|
244
|
-
ctx.closePath();
|
|
245
|
-
ctx.fill();
|
|
246
|
-
ctx.restore();
|
|
247
|
-
}
|
|
248
|
-
static drawPolygon(canvas, pointList, options = {}) {
|
|
249
|
-
const {isClose = false, lineType = tool.ELineTypes.Line} = options;
|
|
250
|
-
if (isClose === true) {
|
|
251
|
-
pointList = [...pointList, pointList[0]];
|
|
252
|
-
}
|
|
253
|
-
if (lineType === tool.ELineTypes.Curve) {
|
|
254
|
-
pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList]);
|
|
255
|
-
}
|
|
256
|
-
this.drawLineWithPointList(canvas, pointList, __spreadProps(__spreadValues({}, options), {
|
|
257
|
-
lineType: tool.ELineTypes.Line
|
|
258
|
-
}));
|
|
259
|
-
return pointList;
|
|
260
|
-
}
|
|
261
|
-
static drawPolygonWithFill(canvas, pointList, options = {}) {
|
|
262
|
-
if (pointList.length < 2) {
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
const ctx = canvas.getContext("2d");
|
|
266
|
-
const {color = DEFAULT_COLOR, lineType = tool.ELineTypes.Line} = options;
|
|
267
|
-
ctx.save();
|
|
268
|
-
ctx.fillStyle = color;
|
|
269
|
-
ctx.beginPath();
|
|
270
|
-
if (lineType === tool.ELineTypes.Curve) {
|
|
271
|
-
pointList = PolygonUtils.createSmoothCurvePointsFromPointList([...pointList, pointList[0]]);
|
|
272
|
-
}
|
|
273
|
-
const [startPoint, ...otherPointList] = pointList;
|
|
274
|
-
ctx.moveTo(startPoint.x, startPoint.y);
|
|
275
|
-
otherPointList.forEach((point) => {
|
|
276
|
-
ctx.lineTo(point.x, point.y);
|
|
277
|
-
});
|
|
278
|
-
ctx.fill();
|
|
279
|
-
ctx.restore();
|
|
280
|
-
return pointList;
|
|
281
|
-
}
|
|
282
|
-
static drawPolygonWithFillAndLine(canvas, pointList, options = {}) {
|
|
283
|
-
const {strokeColor, fillColor, thickness, lineCap, isClose, lineType} = options;
|
|
284
|
-
const newPointList = this.drawPolygon(canvas, pointList, {
|
|
285
|
-
color: strokeColor,
|
|
286
|
-
thickness,
|
|
287
|
-
lineCap,
|
|
288
|
-
isClose,
|
|
289
|
-
lineType
|
|
290
|
-
});
|
|
291
|
-
this.drawPolygonWithFill(canvas, pointList, {color: fillColor, lineType});
|
|
292
|
-
return newPointList;
|
|
293
|
-
}
|
|
294
|
-
static drawPolygonWithKeyPoint(canvas, pointList, options = {}) {
|
|
295
|
-
const {pointColor = "white", strokeColor} = options;
|
|
296
|
-
const newPointList = this.drawPolygon(canvas, pointList, options);
|
|
297
|
-
newPointList.forEach((point) => {
|
|
298
|
-
this.drawCircleWithFill(canvas, point, 4, {color: strokeColor});
|
|
299
|
-
this.drawCircleWithFill(canvas, point, 3, {color: pointColor});
|
|
300
|
-
});
|
|
301
|
-
return newPointList;
|
|
302
|
-
}
|
|
303
|
-
static drawSelectedPolygonWithFillAndLine(canvas, pointList, options = {}) {
|
|
304
|
-
const {pointColor = "white", strokeColor} = options;
|
|
305
|
-
const newPointList = this.drawPolygonWithFillAndLine(canvas, pointList, options);
|
|
306
|
-
newPointList.forEach((point) => {
|
|
307
|
-
this.drawCircleWithFill(canvas, point, 4, {color: strokeColor});
|
|
308
|
-
this.drawCircleWithFill(canvas, point, 3, {color: pointColor});
|
|
309
|
-
});
|
|
310
|
-
return newPointList;
|
|
311
|
-
}
|
|
312
|
-
static drawText(canvas, startPoint, text, options = {}) {
|
|
313
|
-
if (!text) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
const ctx = canvas.getContext("2d");
|
|
317
|
-
const {
|
|
318
|
-
color = DEFAULT_COLOR,
|
|
319
|
-
font = tool.DEFAULT_FONT,
|
|
320
|
-
shadowColor = "",
|
|
321
|
-
shadowBlur = 0,
|
|
322
|
-
shadowOffsetX = 0,
|
|
323
|
-
shadowOffsetY = 0,
|
|
324
|
-
textMaxWidth = 164,
|
|
325
|
-
offsetX = 0,
|
|
326
|
-
offsetY = 0,
|
|
327
|
-
textAlign = "start",
|
|
328
|
-
lineHeight
|
|
329
|
-
} = options;
|
|
330
|
-
ctx.save();
|
|
331
|
-
ctx.textAlign = textAlign;
|
|
332
|
-
ctx.fillStyle = color != null ? color : "white";
|
|
333
|
-
ctx.font = font;
|
|
334
|
-
ctx.shadowColor = shadowColor;
|
|
335
|
-
ctx.shadowOffsetX = shadowOffsetX;
|
|
336
|
-
ctx.shadowOffsetY = shadowOffsetY;
|
|
337
|
-
ctx.shadowBlur = shadowBlur;
|
|
338
|
-
this.wrapText(canvas, `${text}`, startPoint.x + offsetX, startPoint.y + offsetY, textMaxWidth, lineHeight);
|
|
339
|
-
ctx.restore();
|
|
340
|
-
}
|
|
341
|
-
static wrapText(canvas, text, x, y, maxWidth, lineHeight) {
|
|
342
|
-
if (typeof text !== "string" || typeof x !== "number" || typeof y !== "number") {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
const context = canvas.getContext("2d");
|
|
346
|
-
if (typeof maxWidth === "undefined") {
|
|
347
|
-
maxWidth = canvas && canvas.width || 300;
|
|
348
|
-
}
|
|
349
|
-
if (typeof lineHeight === "undefined") {
|
|
350
|
-
lineHeight = canvas && parseInt(window.getComputedStyle(canvas).lineHeight, 10) || parseInt(window.getComputedStyle(document.body).lineHeight, 10);
|
|
351
|
-
}
|
|
352
|
-
const arrParagraph = text.split("\n");
|
|
353
|
-
for (let i = 0; i < arrParagraph.length; i++) {
|
|
354
|
-
const arrText = arrParagraph[i].split("");
|
|
355
|
-
let line = "";
|
|
356
|
-
for (let n = 0; n < arrText.length; n++) {
|
|
357
|
-
const testLine = line + arrText[n];
|
|
358
|
-
const metrics = context.measureText(testLine);
|
|
359
|
-
const testWidth = metrics.width;
|
|
360
|
-
if (!maxWidth) {
|
|
361
|
-
maxWidth = 300;
|
|
362
|
-
}
|
|
363
|
-
if (testWidth > maxWidth && n > 0) {
|
|
364
|
-
context.fillText(line, x, y);
|
|
365
|
-
line = arrText[n];
|
|
366
|
-
y += lineHeight;
|
|
367
|
-
} else {
|
|
368
|
-
line = testLine;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
context.fillText(line, x, y);
|
|
372
|
-
y += lineHeight;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
static drawArrow(ctx, startPoint, endPoint, options = {}) {
|
|
376
|
-
const {color = DEFAULT_COLOR, thickness = 1, lineCap = "round", theta = 30, headLen = 10} = options;
|
|
377
|
-
const angle = Math.atan2(startPoint.y - endPoint.y, startPoint.x - endPoint.x) * 180 / Math.PI;
|
|
378
|
-
const angle1 = (angle + theta) * Math.PI / 180;
|
|
379
|
-
const angle2 = (angle - theta) * Math.PI / 180;
|
|
380
|
-
const topX = headLen * Math.cos(angle1);
|
|
381
|
-
const topY = headLen * Math.sin(angle1);
|
|
382
|
-
const botX = headLen * Math.cos(angle2);
|
|
383
|
-
const botY = headLen * Math.sin(angle2);
|
|
384
|
-
ctx.save();
|
|
385
|
-
ctx.strokeStyle = color;
|
|
386
|
-
ctx.lineWidth = thickness;
|
|
387
|
-
ctx.lineCap = lineCap;
|
|
388
|
-
ctx.beginPath();
|
|
389
|
-
ctx.moveTo(endPoint.x + topX, endPoint.y + topY);
|
|
390
|
-
ctx.lineTo(endPoint.x, endPoint.y);
|
|
391
|
-
ctx.lineTo(endPoint.x + botX, endPoint.y + botY);
|
|
392
|
-
ctx.stroke();
|
|
393
|
-
ctx.restore();
|
|
394
|
-
}
|
|
395
|
-
static drawArrowByCanvas(canvas, startPoint, endPoint, options = {}) {
|
|
396
|
-
const ctx = canvas.getContext("2d");
|
|
397
|
-
this.drawArrow(ctx, startPoint, endPoint, options);
|
|
398
|
-
}
|
|
399
|
-
static drawCuboid(canvas, cuboid, options = {}) {
|
|
400
|
-
const {backPoints, direction, frontPoints} = cuboid;
|
|
401
|
-
const {strokeColor, thickness, fillColor} = options;
|
|
402
|
-
const defaultStyle = {
|
|
403
|
-
color: strokeColor,
|
|
404
|
-
thickness
|
|
405
|
-
};
|
|
406
|
-
if (backPoints) {
|
|
407
|
-
const backPointList = AxisUtils["default"].transformPlain2PointList(backPoints);
|
|
408
|
-
_DrawUtils.drawPolygon(canvas, backPointList, __spreadProps(__spreadValues({}, defaultStyle), {isClose: true}));
|
|
409
|
-
const sideLine = CuboidUtils.getCuboidAllSideLine(cuboid);
|
|
410
|
-
sideLine == null ? void 0 : sideLine.forEach((line) => {
|
|
411
|
-
_DrawUtils.drawLine(canvas, line.p1, line.p2, __spreadValues({}, defaultStyle));
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
const pointList = AxisUtils["default"].transformPlain2PointList(frontPoints);
|
|
415
|
-
if (direction && backPoints && frontPoints) {
|
|
416
|
-
const points = CuboidUtils.getPointListsByDirection({direction, frontPoints, backPoints});
|
|
417
|
-
if (points) {
|
|
418
|
-
_DrawUtils.drawPolygonWithFill(canvas, points, {color: fillColor});
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
_DrawUtils.drawPolygon(canvas, pointList, __spreadProps(__spreadValues({}, defaultStyle), {isClose: true}));
|
|
422
|
-
}
|
|
423
|
-
static drawCuboidWithText(canvas, cuboid, options, dataConfig) {
|
|
424
|
-
const {strokeColor} = options;
|
|
425
|
-
const textColor = strokeColor;
|
|
426
|
-
const {config, hiddenText, selectedID, headerText, bottomText} = dataConfig;
|
|
427
|
-
const {backPoints, frontPoints, textAttribute} = cuboid;
|
|
428
|
-
const frontPointsSizeWidth = frontPoints.br.x - frontPoints.bl.x;
|
|
429
|
-
_DrawUtils.drawCuboid(canvas, cuboid, options);
|
|
430
|
-
let showText = "";
|
|
431
|
-
if ((config == null ? void 0 : config.isShowOrder) && cuboid.order && (cuboid == null ? void 0 : cuboid.order) > 0) {
|
|
432
|
-
showText = `${cuboid.order}`;
|
|
433
|
-
}
|
|
434
|
-
if (cuboid.attribute) {
|
|
435
|
-
showText = `${showText} ${AttributeUtils["default"].getAttributeShowText(cuboid.attribute, config == null ? void 0 : config.attributeList)}`;
|
|
436
|
-
}
|
|
437
|
-
if (!hiddenText && backPoints && showText) {
|
|
438
|
-
_DrawUtils.drawText(canvas, {x: backPoints.tl.x, y: backPoints.tl.y - 5}, headerText != null ? headerText : showText, {
|
|
439
|
-
color: strokeColor,
|
|
440
|
-
textMaxWidth: 300
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
const textPosition = CuboidUtils.getCuboidTextAttributeOffset({
|
|
444
|
-
cuboid,
|
|
445
|
-
currentPos: {x: 0, y: 0},
|
|
446
|
-
zoom: 1,
|
|
447
|
-
topOffset: 16,
|
|
448
|
-
leftOffset: 0
|
|
449
|
-
});
|
|
450
|
-
if (!hiddenText && textAttribute && cuboid.id !== selectedID) {
|
|
451
|
-
const textWidth = Math.max(20, frontPointsSizeWidth * 0.8);
|
|
452
|
-
_DrawUtils.drawText(canvas, {x: textPosition.left, y: textPosition.top}, bottomText != null ? bottomText : textAttribute, {
|
|
453
|
-
color: textColor,
|
|
454
|
-
textMaxWidth: textWidth
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
let DrawUtils = _DrawUtils;
|
|
460
|
-
DrawUtils.drawImg = (canvas, imgNode, options = {}) => {
|
|
461
|
-
const ctx = canvas.getContext("2d");
|
|
462
|
-
const {zoom = DEFAULT_ZOOM, currentPos = DEFAULT_CURRENT_POS, rotate = DEFAULT_ROTATE, imgAttribute} = options;
|
|
463
|
-
ctx.save();
|
|
464
|
-
switch (rotate) {
|
|
465
|
-
case 0:
|
|
466
|
-
ctx.translate(currentPos.x, currentPos.y);
|
|
467
|
-
break;
|
|
468
|
-
case 90:
|
|
469
|
-
ctx.translate(currentPos.x + imgNode.height * zoom, currentPos.y);
|
|
470
|
-
ctx.rotate(90 * Math.PI / 180);
|
|
471
|
-
break;
|
|
472
|
-
case 180:
|
|
473
|
-
ctx.translate(currentPos.x + imgNode.width * zoom, currentPos.y + imgNode.height * zoom);
|
|
474
|
-
ctx.rotate(Math.PI);
|
|
475
|
-
break;
|
|
476
|
-
case 270:
|
|
477
|
-
ctx.translate(currentPos.x, currentPos.y + imgNode.width * zoom);
|
|
478
|
-
ctx.rotate(270 * Math.PI / 180);
|
|
479
|
-
break;
|
|
480
|
-
default:
|
|
481
|
-
ctx.translate(currentPos.x, currentPos.y);
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
if (imgAttribute) {
|
|
485
|
-
const {contrast, saturation, brightness} = imgAttribute;
|
|
486
|
-
ctx.filter = `saturate(${saturation + 100}%) contrast(${contrast + 100}%) brightness(${brightness + 100}%)`;
|
|
487
|
-
}
|
|
488
|
-
ctx.drawImage(imgNode, 0, 0, imgNode.width * zoom, imgNode.height * zoom);
|
|
489
|
-
ctx.restore();
|
|
490
|
-
};
|
|
491
|
-
|
|
492
|
-
module.exports = DrawUtils;
|
|
1
|
+
"use strict";var tool=require("../../constant/tool.js"),PolygonUtils=require("./PolygonUtils.js"),UnitUtils=require("./UnitUtils.js"),AxisUtils=require("./AxisUtils.js"),CuboidUtils=require("./CuboidUtils.js"),AttributeUtils=require("./AttributeUtils.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(r,t,i)=>t in r?__defProp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):r[t]=i,__spreadValues=(r,t)=>{for(var i in t||(t={}))__hasOwnProp.call(t,i)&&__defNormalProp(r,i,t[i]);if(__getOwnPropSymbols)for(var i of __getOwnPropSymbols(t))__propIsEnum.call(t,i)&&__defNormalProp(r,i,t[i]);return r},__spreadProps=(r,t)=>__defProps(r,__getOwnPropDescs(t));const DEFAULT_ZOOM=1,DEFAULT_CURRENT_POS={x:0,y:0},DEFAULT_ROTATE=0,DEFAULT_COLOR="",_DrawUtils=class{static drawLine(r,t,i,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,thickness:s=1,lineCap:a="round",lineDash:d}=e;o.save(),o.strokeStyle=l,o.lineWidth=s,o.lineCap=a,d&&o.setLineDash(d),o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(i.x+1,i.y+1),o.stroke(),o.restore()}static drawRect(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",hiddenText:a=!1,lineDash:d}=i;if(e.save(),e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)&&e.setLineDash(d),e.fillStyle=o,e.strokeRect(t.x,t.y,t.width,t.height),a===!1){let n="";if(t.attribute&&(n=`${n} ${t.attribute}`),this.drawText(r,{x:t.x,y:t.y-5},n),t.textAttribute){const c=`${~~t.width} * ${~~t.height}`.length*7,u=0,y=Math.max(20,t.width-c);this.drawText(r,{x:t.x,y:t.y+t.height+20+u},t.textAttribute,{textMaxWidth:y})}}e.restore()}static drawRectWithFill(r,t,i={}){const e=r.getContext("2d"),{color:o=DEFAULT_COLOR}=i;e.save(),e.fillStyle=o,e.fillRect(t.x,t.y,t.width,t.height),e.restore()}static drawTagByDom(r,t,i){const e=r;if(!((t==null?void 0:t.length)>0))return;const o=document.createElement("div");return o.innerHTML=t,o.setAttribute("id",i),e==null||e.appendChild(o),o}static drawTag(r,t){var i;const e=r==null?void 0:r.parentNode,o=window.self.document.getElementById("tagToolTag");if(o&&e&&e.contains(o)&&(e==null||e.removeChild(o)),!((t==null?void 0:t.length)>0))return;const l=document.createElement("div");return l.innerHTML=(i=t.reduce((s,a)=>`${s}${a.keyName}: ${a.value.join(" \u3001 ")}
|
|
2
|
+
`,""))!=null?i:"",l.setAttribute("id","tagToolTag"),e==null||e.appendChild(l),l}static drawLineWithPointList(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",lineType:a=tool.ELineTypes.Line,lineDash:d,hoverEdgeIndex:n}=i;e.save(),(()=>{e.strokeStyle=o,e.lineWidth=l,e.lineCap=s,Array.isArray(d)?e.setLineDash(d):e.setLineDash([])})(),a===tool.ELineTypes.Curve?(n!==void 0&&n>-1&&t.push(t[0]),t=PolygonUtils.createSmoothCurvePointsFromPointList([...t],tool.SEGMENT_NUMBER),n!==void 0&&n>-1&&(t=t.slice((tool.SEGMENT_NUMBER+1)*n,(tool.SEGMENT_NUMBER+1)*(n+1)))):n!==void 0&&n>-1&&(t=[...t,t[0]],t=t.slice(n,n+2));const c=[];e.beginPath(),e.moveTo(t[0].x,t[0].y);for(let h=0;h<t.length-1;h++)t[h].specialEdge&&c.push({i1:h,i2:h+1}),e.lineTo(t[h+1].x,t[h+1].y);e.stroke(),e.save(),e.lineWidth=l*.8,e.lineCap="butt",e.strokeStyle="white",e.setLineDash([3,3]),c.forEach(h=>{const w=t[h.i1],g=t[h.i2];e.beginPath(),e.moveTo(w.x,w.y),e.lineTo(g.x,g.y),e.stroke()}),e.restore();const u=4,y=2;return t.forEach(h=>{h.specialPoint&&(this.drawSpecialPoint(r,h,u+y,o),this.drawSpecialPoint(r,h,u,"white"))}),e.restore(),t}static drawCircle(r,t,i,e={}){const o=r.getContext("2d"),{startAngleDeg:l=0,endAngleDeg:s=360,thickness:a=1,color:d=DEFAULT_COLOR,fill:n=DEFAULT_COLOR}=e,f=UnitUtils.deg2rad(l),c=UnitUtils.deg2rad(s);o.save(),o.beginPath(),o.strokeStyle=d,o.fillStyle=n,o.lineWidth=a,o.arc(t.x,t.y,i,f,c,!1),o.stroke(),n&&o.fill(),o.closePath(),o.restore()}static drawCircleWithFill(r,t,i=3,e={}){const o=r.getContext("2d"),{color:l=DEFAULT_COLOR}=e;o.save();const s=UnitUtils.deg2rad(0),a=UnitUtils.deg2rad(360);o.fillStyle=l,o.beginPath(),o.arc(t.x,t.y,i,s,a,!1),o.fill(),o.restore()}static drawSpecialPoint(r,t,i=6,e){const o=r.getContext("2d"),{x:l,y:s}=t;o.save(),o.beginPath(),o.fillStyle=e;const a=i*1.5,d=a*Math.sqrt(3)/2,n=a/2;o.moveTo(l,s-a),o.lineTo(l-d,s+n),o.lineTo(l+d,s+n),o.closePath(),o.fill(),o.restore()}static drawPolygon(r,t,i={}){const{isClose:e=!1,lineType:o=tool.ELineTypes.Line}=i;return e===!0&&(t=[...t,t[0]]),o===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t])),this.drawLineWithPointList(r,t,__spreadProps(__spreadValues({},i),{lineType:tool.ELineTypes.Line})),t}static drawPolygonWithFill(r,t,i={}){if(t.length<2)return;const e=r.getContext("2d"),{color:o=DEFAULT_COLOR,lineType:l=tool.ELineTypes.Line}=i;e.save(),e.fillStyle=o,e.beginPath(),l===tool.ELineTypes.Curve&&(t=PolygonUtils.createSmoothCurvePointsFromPointList([...t,t[0]]));const[s,...a]=t;return e.moveTo(s.x,s.y),a.forEach(d=>{e.lineTo(d.x,d.y)}),e.fill(),e.restore(),t}static drawPolygonWithFillAndLine(r,t,i={}){const{strokeColor:e,fillColor:o,thickness:l,lineCap:s,isClose:a,lineType:d}=i,n=this.drawPolygon(r,t,{color:e,thickness:l,lineCap:s,isClose:a,lineType:d});return this.drawPolygonWithFill(r,t,{color:o,lineType:d}),n}static drawPolygonWithKeyPoint(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygon(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawSelectedPolygonWithFillAndLine(r,t,i={}){const{pointColor:e="white",strokeColor:o}=i,l=this.drawPolygonWithFillAndLine(r,t,i);return l.forEach(s=>{this.drawCircleWithFill(r,s,4,{color:o}),this.drawCircleWithFill(r,s,3,{color:e})}),l}static drawText(r,t,i,e={}){if(!i)return;const o=r.getContext("2d"),{color:l=DEFAULT_COLOR,font:s=tool.DEFAULT_FONT,shadowColor:a="",shadowBlur:d=0,shadowOffsetX:n=0,shadowOffsetY:f=0,textMaxWidth:c=164,offsetX:u=0,offsetY:y=0,textAlign:h="start",lineHeight:w}=e;o.save(),o.textAlign=h,o.fillStyle=l!=null?l:"white",o.font=s,o.shadowColor=a,o.shadowOffsetX=n,o.shadowOffsetY=f,o.shadowBlur=d,this.wrapText(r,`${i}`,t.x+u,t.y+y,c,w),o.restore()}static wrapText(r,t,i,e,o,l){if(typeof t!="string"||typeof i!="number"||typeof e!="number")return;const s=r.getContext("2d");typeof o=="undefined"&&(o=r&&r.width||300),typeof l=="undefined"&&(l=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=t.split(`
|
|
3
|
+
`);for(let d=0;d<a.length;d++){const n=a[d].split("");let f="";for(let c=0;c<n.length;c++){const u=f+n[c],h=s.measureText(u).width;o||(o=300),h>o&&c>0?(s.fillText(f,i,e),f=n[c],e+=l):f=u}s.fillText(f,i,e),e+=l}}static drawArrow(r,t,i,e={}){const{color:o=DEFAULT_COLOR,thickness:l=1,lineCap:s="round",theta:a=30,headLen:d=10}=e,n=Math.atan2(t.y-i.y,t.x-i.x)*180/Math.PI,f=(n+a)*Math.PI/180,c=(n-a)*Math.PI/180,u=d*Math.cos(f),y=d*Math.sin(f),h=d*Math.cos(c),w=d*Math.sin(c);r.save(),r.strokeStyle=o,r.lineWidth=l,r.lineCap=s,r.beginPath(),r.moveTo(i.x+u,i.y+y),r.lineTo(i.x,i.y),r.lineTo(i.x+h,i.y+w),r.stroke(),r.restore()}static drawArrowByCanvas(r,t,i,e={}){const o=r.getContext("2d");this.drawArrow(o,t,i,e)}static drawCuboid(r,t,i={}){const{backPoints:e,direction:o,frontPoints:l}=t,{strokeColor:s,thickness:a,fillColor:d}=i,n={color:s,thickness:a};if(e){const c=AxisUtils.default.transformPlain2PointList(e);_DrawUtils.drawPolygon(r,c,__spreadProps(__spreadValues({},n),{isClose:!0}));const u=CuboidUtils.getCuboidAllSideLine(t);u==null||u.forEach(y=>{_DrawUtils.drawLine(r,y.p1,y.p2,__spreadValues({},n))})}const f=AxisUtils.default.transformPlain2PointList(l);if(o&&e&&l){const c=CuboidUtils.getPointListsByDirection({direction:o,frontPoints:l,backPoints:e});c&&_DrawUtils.drawPolygonWithFill(r,c,{color:d})}_DrawUtils.drawPolygon(r,f,__spreadProps(__spreadValues({},n),{isClose:!0}))}static drawCuboidWithText(r,t,i,e){const{strokeColor:o}=i,l=o,{config:s,hiddenText:a,selectedID:d,headerText:n,bottomText:f}=e,{backPoints:c,frontPoints:u,textAttribute:y}=t,h=u.br.x-u.bl.x;_DrawUtils.drawCuboid(r,t,i);let w="";(s==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(w=`${t.order}`),t.attribute&&(w=`${w} ${AttributeUtils.default.getAttributeShowText(t.attribute,s==null?void 0:s.attributeList)}`),!a&&c&&w&&_DrawUtils.drawText(r,{x:c.tl.x,y:c.tl.y-5},n!=null?n:w,{color:o,textMaxWidth:300});const g=CuboidUtils.getCuboidTextAttributeOffset({cuboid:t,currentPos:{x:0,y:0},zoom:1,topOffset:16,leftOffset:0});if(!a&&y&&t.id!==d){const x=Math.max(20,h*.8);_DrawUtils.drawText(r,{x:g.left,y:g.top},f!=null?f:y,{color:l,textMaxWidth:x})}}};let DrawUtils=_DrawUtils;DrawUtils.drawImg=(r,t,i={})=>{const e=r.getContext("2d"),{zoom:o=DEFAULT_ZOOM,currentPos:l=DEFAULT_CURRENT_POS,rotate:s=DEFAULT_ROTATE,imgAttribute:a}=i;switch(e.save(),s){case 0:e.translate(l.x,l.y);break;case 90:e.translate(l.x+t.height*o,l.y),e.rotate(90*Math.PI/180);break;case 180:e.translate(l.x+t.width*o,l.y+t.height*o),e.rotate(Math.PI);break;case 270:e.translate(l.x,l.y+t.width*o),e.rotate(270*Math.PI/180);break;default:e.translate(l.x,l.y);break}if(a){const{contrast:d,saturation:n,brightness:f}=a;e.filter=`saturate(${n+100}%) contrast(${d+100}%) brightness(${f+100}%)`}e.drawImage(t,0,0,t.width*o,t.height*o),e.restore()},module.exports=DrawUtils;
|
|
@@ -1,53 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var tool = require('../../constant/tool.js');
|
|
6
|
-
var ScribbleTool = require('../../core/toolOperation/ScribbleTool.js');
|
|
7
|
-
var cuboidOperation = require('../../core/toolOperation/cuboidOperation.js');
|
|
8
|
-
var pointCloud2dOperation = require('../../core/toolOperation/pointCloud2dOperation.js');
|
|
9
|
-
var checkOperation = require('../../core/toolOperation/checkOperation.js');
|
|
10
|
-
var polygonOperation = require('../../core/toolOperation/polygonOperation.js');
|
|
11
|
-
var rectOperation = require('../../core/toolOperation/rectOperation.js');
|
|
12
|
-
var tagOperation = require('../../core/toolOperation/tagOperation.js');
|
|
13
|
-
var LineToolOperation = require('../../core/toolOperation/LineToolOperation.js');
|
|
14
|
-
var pointOperation = require('../../core/toolOperation/pointOperation.js');
|
|
15
|
-
var TextToolOperation = require('../../core/toolOperation/TextToolOperation.js');
|
|
16
|
-
var segmentByRect = require('../../core/toolOperation/segmentByRect.js');
|
|
17
|
-
var CommonToolUtils = require('./CommonToolUtils.js');
|
|
18
|
-
|
|
19
|
-
const getCurrentOperation = (toolName) => {
|
|
20
|
-
switch (toolName) {
|
|
21
|
-
case tool.EToolName.Rect:
|
|
22
|
-
case tool.EToolName.RectTrack:
|
|
23
|
-
return rectOperation.RectOperation;
|
|
24
|
-
case tool.EToolName.SegmentByRect:
|
|
25
|
-
return segmentByRect;
|
|
26
|
-
case tool.EToolName.Tag:
|
|
27
|
-
return tagOperation;
|
|
28
|
-
case tool.EToolName.Polygon:
|
|
29
|
-
return polygonOperation;
|
|
30
|
-
case tool.ECheckModel.Check:
|
|
31
|
-
return checkOperation;
|
|
32
|
-
case tool.EToolName.Line:
|
|
33
|
-
return LineToolOperation["default"];
|
|
34
|
-
case tool.EToolName.Point:
|
|
35
|
-
return pointOperation;
|
|
36
|
-
case tool.EToolName.Text:
|
|
37
|
-
return TextToolOperation;
|
|
38
|
-
case tool.EToolName.ScribbleTool:
|
|
39
|
-
return ScribbleTool;
|
|
40
|
-
case tool.EToolName.Cuboid:
|
|
41
|
-
return cuboidOperation;
|
|
42
|
-
case tool.EToolName.PointCloudPolygon:
|
|
43
|
-
return pointCloud2dOperation;
|
|
44
|
-
default:
|
|
45
|
-
throw new Error("not match tool");
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
class EnhanceCommonToolUtils extends CommonToolUtils {
|
|
49
|
-
}
|
|
50
|
-
EnhanceCommonToolUtils.getCurrentOperation = getCurrentOperation;
|
|
51
|
-
|
|
52
|
-
exports["default"] = EnhanceCommonToolUtils;
|
|
53
|
-
exports.getCurrentOperation = getCurrentOperation;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tool=require("../../constant/tool.js"),ScribbleTool=require("../../core/toolOperation/ScribbleTool.js"),cuboidOperation=require("../../core/toolOperation/cuboidOperation.js"),pointCloud2dOperation=require("../../core/toolOperation/pointCloud2dOperation.js"),checkOperation=require("../../core/toolOperation/checkOperation.js"),polygonOperation=require("../../core/toolOperation/polygonOperation.js"),rectOperation=require("../../core/toolOperation/rectOperation.js"),tagOperation=require("../../core/toolOperation/tagOperation.js"),LineToolOperation=require("../../core/toolOperation/LineToolOperation.js"),pointOperation=require("../../core/toolOperation/pointOperation.js"),TextToolOperation=require("../../core/toolOperation/TextToolOperation.js"),segmentByRect=require("../../core/toolOperation/segmentByRect.js"),CommonToolUtils=require("./CommonToolUtils.js");const getCurrentOperation=e=>{switch(e){case tool.EToolName.Rect:case tool.EToolName.RectTrack:return rectOperation.RectOperation;case tool.EToolName.SegmentByRect:return segmentByRect;case tool.EToolName.Tag:return tagOperation;case tool.EToolName.Polygon:return polygonOperation;case tool.ECheckModel.Check:return checkOperation;case tool.EToolName.Line:return LineToolOperation.default;case tool.EToolName.Point:return pointOperation;case tool.EToolName.Text:return TextToolOperation;case tool.EToolName.ScribbleTool:return ScribbleTool;case tool.EToolName.Cuboid:return cuboidOperation;case tool.EToolName.PointCloudPolygon:return pointCloud2dOperation;default:throw new Error("not match tool")}};class EnhanceCommonToolUtils extends CommonToolUtils{}EnhanceCommonToolUtils.getCurrentOperation=getCurrentOperation,exports.default=EnhanceCommonToolUtils,exports.getCurrentOperation=getCurrentOperation;
|