@labelbee/lb-annotation 1.8.0 → 1.9.0-alpha.2
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/README.md +65 -0
- package/dist/index.js +20 -9
- package/dist/types/constant/tool.d.ts +3 -1
- package/dist/types/core/index.d.ts +24 -4
- package/dist/types/core/pointCloud/OrbitControls.d.ts +60 -0
- package/dist/types/core/pointCloud/PCDLoader.d.ts +11 -0
- package/dist/types/core/pointCloud/annotation.d.ts +47 -0
- package/dist/types/core/pointCloud/cache.d.ts +16 -0
- package/dist/types/core/pointCloud/index.d.ts +325 -0
- package/dist/types/core/scheduler.d.ts +71 -0
- package/dist/types/core/toolOperation/basicToolOperation.d.ts +20 -2
- package/dist/types/core/toolOperation/eventListener.d.ts +2 -2
- package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +80 -0
- package/dist/types/core/toolOperation/polygonOperation.d.ts +21 -7
- package/dist/types/core/toolOperation/segmentByRect.d.ts +31 -0
- package/dist/types/index.d.ts +9 -3
- package/dist/types/newCore/CanvasScheduler.d.ts +31 -0
- package/dist/types/newCore/index.d.ts +1 -0
- package/dist/types/utils/MathUtils.d.ts +6 -0
- package/dist/types/utils/tool/CommonToolUtils.d.ts +0 -13
- package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +20 -0
- package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
- package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -0
- package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editLV.svg.js +3 -0
- package/es/assets/attributeIcon/icon_editQING.svg.js +3 -0
- package/es/constant/annotation.js +68 -0
- package/es/constant/annotationTask.js +25 -0
- package/es/constant/defaultConfig.js +260 -0
- package/es/constant/keyCode.js +36 -0
- package/es/constant/style.js +67 -0
- package/es/constant/tool.js +183 -0
- package/es/core/index.js +145 -0
- package/es/core/pointCloud/OrbitControls.js +661 -0
- package/es/core/pointCloud/PCDLoader.js +238 -0
- package/es/core/pointCloud/annotation.js +98 -0
- package/es/core/pointCloud/cache.js +42 -0
- package/es/core/pointCloud/index.js +771 -0
- package/es/core/scheduler.js +184 -0
- package/es/core/toolOperation/LineToolOperation.js +1369 -0
- package/es/core/toolOperation/TextToolOperation.js +129 -0
- package/es/core/toolOperation/ViewOperation.js +410 -0
- package/es/core/toolOperation/basicToolOperation.js +817 -0
- package/es/core/toolOperation/checkOperation.js +206 -0
- package/es/core/toolOperation/eventListener.js +35 -0
- package/es/core/toolOperation/measureOperation.js +39 -0
- package/es/core/toolOperation/pointCloud2dOperation.js +197 -0
- package/es/core/toolOperation/pointOperation.js +603 -0
- package/es/core/toolOperation/polygonOperation.js +1201 -0
- package/es/core/toolOperation/rectOperation.js +1170 -0
- package/es/core/toolOperation/segmentByRect.js +172 -0
- package/es/core/toolOperation/tagOperation.js +215 -0
- package/es/core/toolOperation/textAttributeClass.js +201 -0
- package/es/index.js +25 -14
- package/es/locales/constants.js +21 -0
- package/es/locales/en_US/message.js +22 -0
- package/es/locales/index.js +17 -0
- package/es/locales/zh_CN/message.js +22 -0
- package/es/newCore/CanvasScheduler.js +31 -0
- package/es/utils/ActionsHistory.js +78 -0
- package/es/utils/ImgUtils.js +20 -0
- package/es/utils/MathUtils.js +283 -0
- package/es/utils/VectorUtils.js +23 -0
- package/es/utils/tool/AttributeUtils.js +196 -0
- package/es/utils/tool/AxisUtils.js +254 -0
- package/es/utils/tool/CanvasUtils.js +60 -0
- package/es/utils/tool/CommonToolUtils.js +172 -0
- package/es/utils/tool/CurrentOperation.js +35 -0
- package/es/utils/tool/DblClickEventListener.js +100 -0
- package/es/utils/tool/DrawUtils.js +424 -0
- package/es/utils/tool/EnhanceCommonToolUtils.js +39 -0
- package/es/utils/tool/ImgPosUtils.js +56 -0
- package/es/utils/tool/LineToolUtils.js +255 -0
- package/es/utils/tool/MarkerUtils.js +9 -0
- package/es/utils/tool/PolygonUtils.js +458 -0
- package/es/utils/tool/RectUtils.js +153 -0
- package/es/utils/tool/RenderDomClass.js +68 -0
- package/es/utils/tool/RenderDomUtils.js +29 -0
- package/es/utils/tool/StyleUtils.js +29 -0
- package/es/utils/tool/TagUtils.js +127 -0
- package/es/utils/tool/UnitUtils.js +10 -0
- package/es/utils/tool/ZoomUtils.js +70 -0
- package/es/utils/tool/polygonTool.js +126 -0
- package/es/utils/uuid.js +24 -0
- package/package.json +6 -4
|
@@ -0,0 +1,1201 @@
|
|
|
1
|
+
import { i18n } from '@labelbee/lb-utils';
|
|
2
|
+
import MathUtils from '../../utils/MathUtils.js';
|
|
3
|
+
import RectUtils from '../../utils/tool/RectUtils.js';
|
|
4
|
+
import { ERotateDirection, EDragStatus, ESortDirection, EDragTarget, TEXT_ATTRIBUTE_OFFSET, DEFAULT_TEXT_OFFSET } from '../../constant/annotation.js';
|
|
5
|
+
import EKeyCode from '../../constant/keyCode.js';
|
|
6
|
+
import { EPolygonPattern, edgeAdsorptionScope, ELineTypes, EToolName } from '../../constant/tool.js';
|
|
7
|
+
import Locale from '../../locales/index.js';
|
|
8
|
+
import { EMessage } from '../../locales/constants.js';
|
|
9
|
+
import ActionsHistory from '../../utils/ActionsHistory.js';
|
|
10
|
+
import AttributeUtils from '../../utils/tool/AttributeUtils.js';
|
|
11
|
+
import AxisUtils from '../../utils/tool/AxisUtils.js';
|
|
12
|
+
import CanvasUtils from '../../utils/tool/CanvasUtils.js';
|
|
13
|
+
import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
|
|
14
|
+
import DrawUtils from '../../utils/tool/DrawUtils.js';
|
|
15
|
+
import PolygonUtils from '../../utils/tool/PolygonUtils.js';
|
|
16
|
+
import StyleUtils from '../../utils/tool/StyleUtils.js';
|
|
17
|
+
import uuid from '../../utils/uuid.js';
|
|
18
|
+
import { BasicToolOperation } from './basicToolOperation.js';
|
|
19
|
+
import TextAttributeClass from './textAttributeClass.js';
|
|
20
|
+
|
|
21
|
+
var __defProp = Object.defineProperty;
|
|
22
|
+
var __defProps = Object.defineProperties;
|
|
23
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
24
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
25
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
26
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
27
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
|
|
28
|
+
var __spreadValues = (a, b) => {
|
|
29
|
+
for (var prop in b || (b = {}))
|
|
30
|
+
if (__hasOwnProp.call(b, prop))
|
|
31
|
+
__defNormalProp(a, prop, b[prop]);
|
|
32
|
+
if (__getOwnPropSymbols)
|
|
33
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
34
|
+
if (__propIsEnum.call(b, prop))
|
|
35
|
+
__defNormalProp(a, prop, b[prop]);
|
|
36
|
+
}
|
|
37
|
+
return a;
|
|
38
|
+
};
|
|
39
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
40
|
+
const TEXT_MAX_WIDTH = 164;
|
|
41
|
+
class PolygonOperation extends BasicToolOperation {
|
|
42
|
+
constructor(props) {
|
|
43
|
+
super(props);
|
|
44
|
+
this.isAllowDouble = (e) => {
|
|
45
|
+
const {selectedID} = this;
|
|
46
|
+
const currentSelectedID = this.getHoverID(e);
|
|
47
|
+
if (selectedID && selectedID === currentSelectedID) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
this.textChange = (v) => {
|
|
53
|
+
if (this.config.textConfigurable === false || !this.selectedID) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
this.setPolygonList(AttributeUtils.textChange(v, this.selectedID, this.polygonList));
|
|
57
|
+
this.emit("selectedChange");
|
|
58
|
+
this.render();
|
|
59
|
+
};
|
|
60
|
+
this.config = CommonToolUtils.jsonParser(props.config);
|
|
61
|
+
this.drawingPointList = [];
|
|
62
|
+
this.polygonList = [];
|
|
63
|
+
this.hoverPointIndex = -1;
|
|
64
|
+
this.hoverEdgeIndex = -1;
|
|
65
|
+
this.drawingHistory = new ActionsHistory();
|
|
66
|
+
this.isCtrl = false;
|
|
67
|
+
this.isAlt = false;
|
|
68
|
+
this.isCombined = false;
|
|
69
|
+
this.pattern = EPolygonPattern.Normal;
|
|
70
|
+
this.getCurrentSelectedData = this.getCurrentSelectedData.bind(this);
|
|
71
|
+
this.updateSelectedTextAttribute = this.updateSelectedTextAttribute.bind(this);
|
|
72
|
+
}
|
|
73
|
+
eventBinding() {
|
|
74
|
+
super.eventBinding();
|
|
75
|
+
this.container.removeEventListener("mouseup", this.onMouseUp);
|
|
76
|
+
this.container.addEventListener("mouseup", this.dragMouseUp);
|
|
77
|
+
this.dblClickListener.addEvent(this.onMouseUp, this.onLeftDblClick, this.onRightDblClick, this.isAllowDouble);
|
|
78
|
+
}
|
|
79
|
+
eventUnbinding() {
|
|
80
|
+
super.eventUnbinding();
|
|
81
|
+
this.container.removeEventListener("mouseup", this.dragMouseUp);
|
|
82
|
+
}
|
|
83
|
+
destroy() {
|
|
84
|
+
super.destroy();
|
|
85
|
+
if (this._textAttributInstance) {
|
|
86
|
+
this._textAttributInstance.clearTextAttribute();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
get selectedPolygon() {
|
|
90
|
+
return PolygonUtils.getPolygonByID(this.polygonList, this.selectedID);
|
|
91
|
+
}
|
|
92
|
+
get hoverPolygon() {
|
|
93
|
+
return this.polygonList.find((v) => v.id === this.hoverID && v.id !== this.selectedID);
|
|
94
|
+
}
|
|
95
|
+
get polygonListUnderZoom() {
|
|
96
|
+
return this.polygonList.map((polygon) => __spreadProps(__spreadValues({}, polygon), {
|
|
97
|
+
pointList: AxisUtils.changePointListByZoom(polygon.pointList, this.zoom)
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
get selectedText() {
|
|
101
|
+
var _a;
|
|
102
|
+
return (_a = this.selectedPolygon) == null ? void 0 : _a.textAttribute;
|
|
103
|
+
}
|
|
104
|
+
get dataList() {
|
|
105
|
+
return this.polygonList;
|
|
106
|
+
}
|
|
107
|
+
setPattern(pattern, isForce = false) {
|
|
108
|
+
var _a;
|
|
109
|
+
if (((_a = this.drawingPointList) == null ? void 0 : _a.length) > 0 && isForce === true) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.pattern = pattern;
|
|
113
|
+
}
|
|
114
|
+
get currentShowList() {
|
|
115
|
+
let polygon = [];
|
|
116
|
+
const [showingPolygon, selectdPolygon] = CommonToolUtils.getRenderResultList(this.polygonList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
|
|
117
|
+
polygon = showingPolygon;
|
|
118
|
+
if (this.isHidden) {
|
|
119
|
+
polygon = [];
|
|
120
|
+
}
|
|
121
|
+
if (selectdPolygon) {
|
|
122
|
+
polygon.push(selectdPolygon);
|
|
123
|
+
}
|
|
124
|
+
return polygon;
|
|
125
|
+
}
|
|
126
|
+
get currentPageResult() {
|
|
127
|
+
const [showingPolygon] = CommonToolUtils.getRenderResultList(this.polygonList, CommonToolUtils.getSourceID(this.basicResult), []);
|
|
128
|
+
return showingPolygon;
|
|
129
|
+
}
|
|
130
|
+
setResultAndSelectedID(polygonList, selectedID) {
|
|
131
|
+
this.setPolygonList(polygonList);
|
|
132
|
+
if (selectedID) {
|
|
133
|
+
this.selectedID = selectedID;
|
|
134
|
+
}
|
|
135
|
+
this.render();
|
|
136
|
+
}
|
|
137
|
+
setResult(polygonList) {
|
|
138
|
+
this.clearActiveStatus();
|
|
139
|
+
this.setPolygonList(polygonList);
|
|
140
|
+
this.render();
|
|
141
|
+
}
|
|
142
|
+
setPolygonDataByID(newPolygonData, id) {
|
|
143
|
+
return this.polygonList.map((polygon) => {
|
|
144
|
+
if (polygon.id === id) {
|
|
145
|
+
return __spreadValues(__spreadValues({}, polygon), newPolygonData);
|
|
146
|
+
}
|
|
147
|
+
return polygon;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
rotatePolygon(angle = 1, direction = ERotateDirection.Clockwise, selectedID = this.selectedID) {
|
|
151
|
+
if (!selectedID) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const selectedPolygon = PolygonUtils.getPolygonByID(this.polygonList, selectedID);
|
|
155
|
+
if (!selectedPolygon) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const rotatePointList = PolygonUtils.updatePolygonByRotate(direction, angle, selectedPolygon == null ? void 0 : selectedPolygon.pointList);
|
|
159
|
+
this.setPolygonList(this.setPolygonDataByID({pointList: rotatePointList}, selectedID));
|
|
160
|
+
this.render();
|
|
161
|
+
}
|
|
162
|
+
addPointInDrawing(e) {
|
|
163
|
+
if (!this.imgInfo) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const {upperLimitPointNum, edgeAdsorption} = this.config;
|
|
167
|
+
if (upperLimitPointNum && this.drawingPointList.length >= upperLimitPointNum) {
|
|
168
|
+
this.emit("messageInfo", `${Locale.getMessagesByLocale(EMessage.UpperLimitErrorNotice, this.lang)}${upperLimitPointNum}`);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.deleteSelectedID();
|
|
172
|
+
const coordinateZoom = this.getCoordinateUnderZoom(e);
|
|
173
|
+
const coordinate = AxisUtils.changeDrawOutsideTarget(coordinateZoom, {x: 0, y: 0}, this.imgInfo, this.config.drawOutsideTarget, this.basicResult, this.zoom);
|
|
174
|
+
const calculateHoverPointIndex = AxisUtils.returnClosePointIndex(coordinate, AxisUtils.changePointListByZoom(this.drawingPointList, this.zoom));
|
|
175
|
+
if (calculateHoverPointIndex === 0) {
|
|
176
|
+
this.addDrawingPointToPolygonList();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const {dropFoot} = PolygonUtils.getClosestPoint(coordinate, this.polygonListUnderZoom, this.config.lineType, edgeAdsorptionScope);
|
|
180
|
+
const coordinateWithOrigin = AxisUtils.changePointByZoom(dropFoot && e.altKey === false && edgeAdsorption ? dropFoot : coordinate, 1 / this.zoom);
|
|
181
|
+
if (this.pattern === EPolygonPattern.Rect && this.drawingPointList.length === 2) {
|
|
182
|
+
const rect = MathUtils.getRectangleByRightAngle(coordinateWithOrigin, this.drawingPointList);
|
|
183
|
+
this.drawingPointList = rect;
|
|
184
|
+
if (this.config.drawOutsideTarget === false && this.imgInfo) {
|
|
185
|
+
const isOutSide = this.isPolygonOutSide(this.drawingPointList);
|
|
186
|
+
if (isOutSide) {
|
|
187
|
+
this.emit("messageInfo", `${Locale.getMessagesByLocale(EMessage.ForbiddenCreationOutsideBoundary, this.lang)}`);
|
|
188
|
+
this.drawingPointList = [];
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
this.addDrawingPointToPolygonList(true);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
this.drawingPointList.push(coordinateWithOrigin);
|
|
196
|
+
if (this.drawingPointList.length === 1) {
|
|
197
|
+
this.drawingHistory.initRecord(this.drawingPointList);
|
|
198
|
+
} else {
|
|
199
|
+
this.drawingHistory.pushHistory(this.drawingPointList);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
clearResult() {
|
|
203
|
+
this.setPolygonList([]);
|
|
204
|
+
this.deleteSelectedID();
|
|
205
|
+
this.render();
|
|
206
|
+
}
|
|
207
|
+
clearPolygonDrag() {
|
|
208
|
+
this.drawingPointList = [];
|
|
209
|
+
this.dragInfo = void 0;
|
|
210
|
+
this.dragInfo = void 0;
|
|
211
|
+
this.dragStatus = EDragStatus.Wait;
|
|
212
|
+
this.hoverEdgeIndex = -1;
|
|
213
|
+
this.hoverPointIndex = -1;
|
|
214
|
+
this.hoverID = "";
|
|
215
|
+
}
|
|
216
|
+
clearActiveStatus() {
|
|
217
|
+
this.clearPolygonDrag();
|
|
218
|
+
this.deleteSelectedID();
|
|
219
|
+
}
|
|
220
|
+
clearDrawingStatus() {
|
|
221
|
+
this.drawingPointList = [];
|
|
222
|
+
}
|
|
223
|
+
setPolygonList(polygonList) {
|
|
224
|
+
const oldLen = this.polygonList.length;
|
|
225
|
+
this.polygonList = polygonList;
|
|
226
|
+
if (oldLen !== polygonList.length) {
|
|
227
|
+
this.emit("updatePageNumber");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
setSelectedID(newID) {
|
|
231
|
+
var _a, _b;
|
|
232
|
+
const oldID = this.selectedID;
|
|
233
|
+
if (newID !== oldID && oldID) {
|
|
234
|
+
(_a = this._textAttributInstance) == null ? void 0 : _a.changeSelected();
|
|
235
|
+
}
|
|
236
|
+
if (!newID) {
|
|
237
|
+
(_b = this._textAttributInstance) == null ? void 0 : _b.clearTextAttribute();
|
|
238
|
+
}
|
|
239
|
+
this.selectedID = newID;
|
|
240
|
+
this.render();
|
|
241
|
+
this.emit("selectedChange");
|
|
242
|
+
}
|
|
243
|
+
setDefaultAttribute(defaultAttribute = "") {
|
|
244
|
+
const oldDefault = this.defaultAttribute;
|
|
245
|
+
this.defaultAttribute = defaultAttribute;
|
|
246
|
+
if (oldDefault !== defaultAttribute) {
|
|
247
|
+
this.changeStyle(defaultAttribute);
|
|
248
|
+
this.emit("changeAttributeSidebar");
|
|
249
|
+
const {selectedID} = this;
|
|
250
|
+
if (selectedID) {
|
|
251
|
+
if (this.selectedPolygon) {
|
|
252
|
+
this.selectedPolygon.attribute = defaultAttribute;
|
|
253
|
+
}
|
|
254
|
+
this.history.pushHistory(this.polygonList);
|
|
255
|
+
this.render();
|
|
256
|
+
}
|
|
257
|
+
if (this._textAttributInstance) {
|
|
258
|
+
if (this.attributeLockList.length > 0 && !this.attributeLockList.includes(defaultAttribute)) {
|
|
259
|
+
this._textAttributInstance.clearTextAttribute();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this._textAttributInstance.updateIcon(this.getTextIconSvg(defaultAttribute));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
setStyle(toolStyle) {
|
|
267
|
+
var _a;
|
|
268
|
+
super.setStyle(toolStyle);
|
|
269
|
+
if (this._textAttributInstance && this.config.attributeConfigurable === false) {
|
|
270
|
+
(_a = this._textAttributInstance) == null ? void 0 : _a.updateIcon(this.getTextIconSvg());
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
setPolygonValidAndRender(id) {
|
|
274
|
+
if (!id) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
const newPolygonList = this.polygonList.map((polygon) => {
|
|
278
|
+
if (polygon.id === id) {
|
|
279
|
+
return __spreadProps(__spreadValues({}, polygon), {
|
|
280
|
+
valid: !polygon.valid
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
return polygon;
|
|
284
|
+
});
|
|
285
|
+
this.setPolygonList(newPolygonList);
|
|
286
|
+
this.history.pushHistory(this.polygonList);
|
|
287
|
+
this.render();
|
|
288
|
+
this.emit("updateResult");
|
|
289
|
+
}
|
|
290
|
+
addDrawingPointToPolygonList(isRect) {
|
|
291
|
+
let {lowerLimitPointNum = 3} = this.config;
|
|
292
|
+
if (lowerLimitPointNum < 3) {
|
|
293
|
+
lowerLimitPointNum = 3;
|
|
294
|
+
}
|
|
295
|
+
if (this.drawingPointList.length < lowerLimitPointNum) {
|
|
296
|
+
this.drawingPointList = [];
|
|
297
|
+
this.editPolygonID = "";
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const basicSourceID = CommonToolUtils.getSourceID(this.basicResult);
|
|
301
|
+
const polygonList = [...this.polygonList];
|
|
302
|
+
if (this.editPolygonID) {
|
|
303
|
+
const samePolygon = polygonList.find((polygon) => polygon.id === this.editPolygonID);
|
|
304
|
+
if (!samePolygon) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
samePolygon.pointList = this.drawingPointList;
|
|
308
|
+
this.editPolygonID = "";
|
|
309
|
+
} else {
|
|
310
|
+
const id = uuid(8, 62);
|
|
311
|
+
let newPolygon = {
|
|
312
|
+
id,
|
|
313
|
+
sourceID: basicSourceID,
|
|
314
|
+
valid: !this.isCtrl,
|
|
315
|
+
textAttribute: "",
|
|
316
|
+
pointList: this.drawingPointList,
|
|
317
|
+
attribute: this.defaultAttribute,
|
|
318
|
+
order: CommonToolUtils.getMaxOrder(polygonList.filter((v) => CommonToolUtils.isSameSourceID(v.sourceID, basicSourceID))) + 1
|
|
319
|
+
};
|
|
320
|
+
if (this.config.textConfigurable) {
|
|
321
|
+
let textAttribute = "";
|
|
322
|
+
textAttribute = AttributeUtils.getTextAttribute(this.polygonList.filter((polygon) => CommonToolUtils.isSameSourceID(polygon.sourceID, basicSourceID)), this.config.textCheckType);
|
|
323
|
+
newPolygon = __spreadProps(__spreadValues({}, newPolygon), {
|
|
324
|
+
textAttribute
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (this.pattern === EPolygonPattern.Rect && isRect === true) {
|
|
328
|
+
newPolygon = __spreadProps(__spreadValues({}, newPolygon), {
|
|
329
|
+
isRect: true
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
polygonList.push(newPolygon);
|
|
333
|
+
this.emit("polygonCreated", newPolygon, this.zoom, this.currentPos);
|
|
334
|
+
this.setSelectedIdAfterAddingDrawing(id);
|
|
335
|
+
}
|
|
336
|
+
this.setPolygonList(polygonList);
|
|
337
|
+
this.isCtrl = false;
|
|
338
|
+
this.drawingPointList = [];
|
|
339
|
+
this.history.pushHistory(polygonList);
|
|
340
|
+
}
|
|
341
|
+
setSelectedIdAfterAddingDrawing(newID) {
|
|
342
|
+
if (this.drawingPointList.length === 0) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (this.config.textConfigurable) {
|
|
346
|
+
this.setSelectedID(newID);
|
|
347
|
+
} else {
|
|
348
|
+
this.deleteSelectedID();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
getHoverID(e) {
|
|
352
|
+
var _a;
|
|
353
|
+
const coordinate = this.getCoordinateUnderZoom(e);
|
|
354
|
+
const polygonListWithZoom = this.currentShowList.map((polygon) => __spreadProps(__spreadValues({}, polygon), {
|
|
355
|
+
pointList: AxisUtils.changePointListByZoom(polygon.pointList, this.zoom)
|
|
356
|
+
}));
|
|
357
|
+
return PolygonUtils.getHoverPolygonID(coordinate, polygonListWithZoom, 10, (_a = this.config) == null ? void 0 : _a.lineType);
|
|
358
|
+
}
|
|
359
|
+
getHoverEdgeIndex(e) {
|
|
360
|
+
var _a;
|
|
361
|
+
if (!this.selectedID) {
|
|
362
|
+
return -1;
|
|
363
|
+
}
|
|
364
|
+
const selectPolygon = this.selectedPolygon;
|
|
365
|
+
if (!selectPolygon) {
|
|
366
|
+
return -1;
|
|
367
|
+
}
|
|
368
|
+
const currentCoord = this.getCoordinateUnderZoom(e);
|
|
369
|
+
const editPointListUnderZoom = AxisUtils.changePointListByZoom(selectPolygon.pointList, this.zoom);
|
|
370
|
+
return PolygonUtils.getHoverEdgeIndex(currentCoord, editPointListUnderZoom, (_a = this.config) == null ? void 0 : _a.lineType);
|
|
371
|
+
}
|
|
372
|
+
getHoverPointIndex(e) {
|
|
373
|
+
if (!this.selectedID) {
|
|
374
|
+
return -1;
|
|
375
|
+
}
|
|
376
|
+
const selectPolygon = this.selectedPolygon;
|
|
377
|
+
if (!selectPolygon) {
|
|
378
|
+
return -1;
|
|
379
|
+
}
|
|
380
|
+
const currentCoord = this.getCoordinateUnderZoom(e);
|
|
381
|
+
const editPointListUnderZoom = AxisUtils.changePointListByZoom(selectPolygon.pointList, this.zoom);
|
|
382
|
+
return AxisUtils.returnClosePointIndex(currentCoord, editPointListUnderZoom);
|
|
383
|
+
}
|
|
384
|
+
deletePolygon(id) {
|
|
385
|
+
var _a;
|
|
386
|
+
if (!id) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const deletedPolygon = this.polygonList.find((p) => p.id === id);
|
|
390
|
+
this.emit("deletedObject", {deletedObject: deletedPolygon, id});
|
|
391
|
+
this.setPolygonList(this.polygonList.filter((polygon) => polygon.id !== id));
|
|
392
|
+
this.history.pushHistory(this.polygonList);
|
|
393
|
+
(_a = this._textAttributInstance) == null ? void 0 : _a.clearTextAttribute();
|
|
394
|
+
this.emit("selectedChange");
|
|
395
|
+
this.render();
|
|
396
|
+
}
|
|
397
|
+
deletePolygonPoint(index) {
|
|
398
|
+
if (!this.selectedID) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const {selectedPolygon} = this;
|
|
402
|
+
if (!selectedPolygon) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
let {lowerLimitPointNum} = this.config;
|
|
406
|
+
if (lowerLimitPointNum < 3) {
|
|
407
|
+
lowerLimitPointNum = 3;
|
|
408
|
+
}
|
|
409
|
+
if (selectedPolygon.pointList.length <= lowerLimitPointNum) {
|
|
410
|
+
this.emit("messageInfo", `${Locale.getMessagesByLocale(EMessage.LowerLimitErrorNotice, this.lang)}${lowerLimitPointNum}`);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
selectedPolygon == null ? void 0 : selectedPolygon.pointList.splice(index, 1);
|
|
414
|
+
this.history.pushHistory(this.polygonList);
|
|
415
|
+
this.render();
|
|
416
|
+
}
|
|
417
|
+
spaceKeydown() {
|
|
418
|
+
var _a, _b, _c;
|
|
419
|
+
if (this.selectedID) {
|
|
420
|
+
if (((_a = this.selectedPolygon) == null ? void 0 : _a.isRect) === true) {
|
|
421
|
+
this.emit("messageInfo", `${Locale.getMessagesByLocale(EMessage.UnableToReannotation, this.lang)}`);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
this.editPolygonID = this.selectedID;
|
|
425
|
+
this.drawingPointList = (_c = (_b = this.selectedPolygon) == null ? void 0 : _b.pointList) != null ? _c : [];
|
|
426
|
+
this.drawingHistory.empty();
|
|
427
|
+
this.drawingHistory.initRecord(this.drawingPointList);
|
|
428
|
+
this.hoverID = "";
|
|
429
|
+
this.deleteSelectedID();
|
|
430
|
+
this.render();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
onTabKeyDown(e) {
|
|
434
|
+
e.preventDefault();
|
|
435
|
+
let sort = ESortDirection.ascend;
|
|
436
|
+
if (e.shiftKey) {
|
|
437
|
+
sort = ESortDirection.descend;
|
|
438
|
+
}
|
|
439
|
+
this.switchToNextPolygon(sort);
|
|
440
|
+
}
|
|
441
|
+
switchToNextPolygon(sort) {
|
|
442
|
+
if (this.drawingPointList.length > 0) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const [showingResult, selectedResult] = CommonToolUtils.getRenderResultList(this.polygonList, CommonToolUtils.getSourceID(this.basicResult), this.attributeLockList, this.selectedID);
|
|
446
|
+
let polygonList = [...showingResult];
|
|
447
|
+
if (selectedResult) {
|
|
448
|
+
polygonList = [...polygonList, selectedResult];
|
|
449
|
+
}
|
|
450
|
+
const viewPort = CanvasUtils.getViewPort(this.canvas, this.currentPos, this.zoom);
|
|
451
|
+
const sortList = polygonList.map((v) => {
|
|
452
|
+
var _a, _b, _c, _d;
|
|
453
|
+
return __spreadProps(__spreadValues({}, v), {
|
|
454
|
+
x: (_b = (_a = v.pointList[0]) == null ? void 0 : _a.x) != null ? _b : 0,
|
|
455
|
+
y: (_d = (_c = v.pointList[0]) == null ? void 0 : _c.y) != null ? _d : 0
|
|
456
|
+
});
|
|
457
|
+
}).filter((polygon) => CanvasUtils.inViewPort({x: polygon.x, y: polygon.y}, viewPort));
|
|
458
|
+
const nextSelectedResult = CommonToolUtils.getNextSelectedRectID(sortList, sort, this.selectedID);
|
|
459
|
+
if (nextSelectedResult) {
|
|
460
|
+
this.setSelectedID(nextSelectedResult.id);
|
|
461
|
+
const {selectedPolygon} = this;
|
|
462
|
+
if (selectedPolygon) {
|
|
463
|
+
this.setDefaultAttribute(selectedPolygon.attribute);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
this.render();
|
|
467
|
+
}
|
|
468
|
+
onKeyDown(e) {
|
|
469
|
+
if (!CommonToolUtils.hotkeyFilter(e)) {
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
if (super.onKeyDown(e) === false) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const {keyCode} = e;
|
|
476
|
+
switch (keyCode) {
|
|
477
|
+
case EKeyCode.Space:
|
|
478
|
+
this.spaceKeydown();
|
|
479
|
+
break;
|
|
480
|
+
case EKeyCode.Esc:
|
|
481
|
+
this.drawingPointList = [];
|
|
482
|
+
this.editPolygonID = "";
|
|
483
|
+
break;
|
|
484
|
+
case EKeyCode.F:
|
|
485
|
+
if (this.selectedID) {
|
|
486
|
+
this.setPolygonValidAndRender(this.selectedID);
|
|
487
|
+
}
|
|
488
|
+
break;
|
|
489
|
+
case EKeyCode.Z:
|
|
490
|
+
if (e.altKey) {
|
|
491
|
+
this.onCombinedExecute();
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
this.setIsHidden(!this.isHidden);
|
|
495
|
+
this.render();
|
|
496
|
+
break;
|
|
497
|
+
case EKeyCode.Delete:
|
|
498
|
+
this.deletePolygon(this.selectedID);
|
|
499
|
+
this.render();
|
|
500
|
+
break;
|
|
501
|
+
case EKeyCode.Ctrl:
|
|
502
|
+
this.isCtrl = true;
|
|
503
|
+
break;
|
|
504
|
+
case EKeyCode.Alt:
|
|
505
|
+
if (this.isAlt === false) {
|
|
506
|
+
e.preventDefault();
|
|
507
|
+
this.isAlt = true;
|
|
508
|
+
this.render();
|
|
509
|
+
}
|
|
510
|
+
break;
|
|
511
|
+
case EKeyCode.Tab: {
|
|
512
|
+
this.onTabKeyDown(e);
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
case EKeyCode.X:
|
|
516
|
+
if (e.altKey) {
|
|
517
|
+
this.segment();
|
|
518
|
+
}
|
|
519
|
+
break;
|
|
520
|
+
default: {
|
|
521
|
+
if (this.config.attributeConfigurable) {
|
|
522
|
+
const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
|
|
523
|
+
if (keyCode2Attribute !== void 0) {
|
|
524
|
+
this.setDefaultAttribute(keyCode2Attribute);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
break;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
onKeyUp(e) {
|
|
532
|
+
super.onKeyUp(e);
|
|
533
|
+
switch (e.keyCode) {
|
|
534
|
+
case EKeyCode.Ctrl:
|
|
535
|
+
this.isCtrl = false;
|
|
536
|
+
break;
|
|
537
|
+
case EKeyCode.Alt: {
|
|
538
|
+
const oldAlt = this.isAlt;
|
|
539
|
+
this.isAlt = false;
|
|
540
|
+
if (oldAlt === true) {
|
|
541
|
+
this.render();
|
|
542
|
+
}
|
|
543
|
+
break;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
rightMouseUp(e) {
|
|
548
|
+
if (this.drawingPointList.length > 0) {
|
|
549
|
+
this.addDrawingPointToPolygonList();
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
this.setSelectedID(this.hoverID);
|
|
553
|
+
const {selectedPolygon} = this;
|
|
554
|
+
if (selectedPolygon) {
|
|
555
|
+
this.setDefaultAttribute(selectedPolygon.attribute);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
onLeftDblClick(e) {
|
|
559
|
+
if (this.hoverEdgeIndex > -1) {
|
|
560
|
+
const currentCoord = this.getCoordinateUnderZoom(e);
|
|
561
|
+
const {selectedPolygon} = this;
|
|
562
|
+
if (!selectedPolygon) {
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const {dropFoot} = PolygonUtils.getClosestPoint(currentCoord, this.polygonListUnderZoom, this.config.lineType, edgeAdsorptionScope);
|
|
566
|
+
if (!dropFoot) {
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
const {upperLimitPointNum} = this.config;
|
|
570
|
+
if (upperLimitPointNum && selectedPolygon.pointList.length >= upperLimitPointNum) {
|
|
571
|
+
this.emit("messageInfo", `${Locale.getMessagesByLocale(EMessage.UpperLimitErrorNotice, this.lang)}${upperLimitPointNum}`);
|
|
572
|
+
this.clearPolygonDrag();
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
selectedPolygon == null ? void 0 : selectedPolygon.pointList.splice(this.hoverEdgeIndex + 1, 0, AxisUtils.changePointByZoom(dropFoot, 1 / this.zoom));
|
|
576
|
+
this.setPolygonDataByID(selectedPolygon, this.selectedID);
|
|
577
|
+
this.history.pushHistory(this.polygonList);
|
|
578
|
+
this.hoverPointIndex = -1;
|
|
579
|
+
this.hoverEdgeIndex = -1;
|
|
580
|
+
this.render();
|
|
581
|
+
}
|
|
582
|
+
this.dragInfo = void 0;
|
|
583
|
+
}
|
|
584
|
+
onRightDblClick(e) {
|
|
585
|
+
this.dragInfo = void 0;
|
|
586
|
+
this.clearImgDrag();
|
|
587
|
+
const hoverID = this.getHoverID(e);
|
|
588
|
+
const hoverPointIndex = this.getHoverPointIndex(e);
|
|
589
|
+
if (this.hoverPointIndex > -1 && this.hoverPointIndex === hoverPointIndex) {
|
|
590
|
+
this.deletePolygonPoint(hoverPointIndex);
|
|
591
|
+
this.dragInfo = void 0;
|
|
592
|
+
this.hoverPointIndex = -1;
|
|
593
|
+
this.render();
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (this.hoverID === this.selectedID) {
|
|
597
|
+
this.deletePolygon(hoverID);
|
|
598
|
+
}
|
|
599
|
+
this.render();
|
|
600
|
+
}
|
|
601
|
+
onMouseDown(e) {
|
|
602
|
+
if (super.onMouseDown(e) || this.forbidMouseOperation || e.ctrlKey === true) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const firstPolygon = this.selectedPolygon;
|
|
606
|
+
if (!firstPolygon || e.button !== 0) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const hoverID = this.getHoverID(e);
|
|
610
|
+
if (hoverID !== this.selectedID) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
const initPointList = firstPolygon.pointList;
|
|
614
|
+
const dragStartCoord = this.getCoordinateUnderZoom(e);
|
|
615
|
+
let changePointIndex = [0];
|
|
616
|
+
let dragTarget = EDragTarget.Plane;
|
|
617
|
+
this.dragStatus = EDragStatus.Start;
|
|
618
|
+
const closePointIndex = this.getHoverPointIndex(e);
|
|
619
|
+
const closeEdgeIndex = this.getHoverEdgeIndex(e);
|
|
620
|
+
if (closePointIndex > -1) {
|
|
621
|
+
dragTarget = EDragTarget.Point;
|
|
622
|
+
changePointIndex = [closePointIndex];
|
|
623
|
+
} else if (closeEdgeIndex > -1 && this.hoverEdgeIndex > -1) {
|
|
624
|
+
dragTarget = EDragTarget.Line;
|
|
625
|
+
changePointIndex = [closeEdgeIndex, (closeEdgeIndex + 1) % initPointList.length];
|
|
626
|
+
}
|
|
627
|
+
this.dragInfo = {
|
|
628
|
+
dragStartCoord,
|
|
629
|
+
dragTarget,
|
|
630
|
+
initPointList,
|
|
631
|
+
changePointIndex,
|
|
632
|
+
originPolygon: this.selectedPolygon
|
|
633
|
+
};
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
segment() {
|
|
637
|
+
var _a;
|
|
638
|
+
if (!this.selectedID) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
if (((_a = this.config) == null ? void 0 : _a.lineType) !== ELineTypes.Line) {
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
const selectedPointList = PolygonUtils.getPolygonPointList(this.selectedID, this.currentShowList);
|
|
645
|
+
const backgroundPolygonList = this.currentShowList.filter((v) => v.id !== this.selectedID);
|
|
646
|
+
if (backgroundPolygonList.length === 0 || selectedPointList.length === 0) {
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const wrapIndex = PolygonUtils.getWrapPolygonIndex(selectedPointList, backgroundPolygonList);
|
|
650
|
+
let newPolygonList = [...this.polygonList];
|
|
651
|
+
if (wrapIndex === -1) {
|
|
652
|
+
const newPointListArray = PolygonUtils.segmentPolygonByPolygon(selectedPointList, backgroundPolygonList);
|
|
653
|
+
if (!newPointListArray) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
const newPointList = newPointListArray.shift();
|
|
657
|
+
if (!newPointList) {
|
|
658
|
+
return;
|
|
659
|
+
}
|
|
660
|
+
let defaultAttribute = "";
|
|
661
|
+
let valid = true;
|
|
662
|
+
const sourceID = CommonToolUtils.getSourceID(this.basicResult);
|
|
663
|
+
let textAttribute = "";
|
|
664
|
+
newPolygonList = this.polygonList.map((v) => {
|
|
665
|
+
var _a2, _b;
|
|
666
|
+
if (v.id === this.selectedID) {
|
|
667
|
+
defaultAttribute = v.attribute;
|
|
668
|
+
valid = (_a2 = v == null ? void 0 : v.valid) != null ? _a2 : true;
|
|
669
|
+
textAttribute = (_b = v == null ? void 0 : v.textAttribute) != null ? _b : "";
|
|
670
|
+
return __spreadProps(__spreadValues({}, v), {
|
|
671
|
+
pointList: newPointList
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
return v;
|
|
675
|
+
});
|
|
676
|
+
if (newPointListArray.length > 0) {
|
|
677
|
+
newPointListArray.forEach((v, i) => {
|
|
678
|
+
newPolygonList.push({
|
|
679
|
+
sourceID,
|
|
680
|
+
id: uuid(8, 62),
|
|
681
|
+
pointList: v,
|
|
682
|
+
valid,
|
|
683
|
+
order: CommonToolUtils.getMaxOrder(this.currentShowList) + 1 + i,
|
|
684
|
+
attribute: defaultAttribute,
|
|
685
|
+
textAttribute
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
} else {
|
|
690
|
+
newPolygonList[wrapIndex].pointList = PolygonUtils.clipPolygonFromWrapPolygon(selectedPointList, newPolygonList[wrapIndex].pointList);
|
|
691
|
+
newPolygonList = newPolygonList.filter((v) => v.id !== this.selectedID);
|
|
692
|
+
}
|
|
693
|
+
this.setPolygonList(newPolygonList);
|
|
694
|
+
this.history.pushHistory(newPolygonList);
|
|
695
|
+
this.render();
|
|
696
|
+
}
|
|
697
|
+
onCombinedExecute() {
|
|
698
|
+
if (!this.selectedID) {
|
|
699
|
+
this.emit("messageInfo", i18n.t("PolygonsToBeCombinedNeedToBeSelected"));
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
this.isCombined = !this.isCombined;
|
|
703
|
+
}
|
|
704
|
+
combine(e) {
|
|
705
|
+
var _a;
|
|
706
|
+
const hoverID = this.getHoverID(e);
|
|
707
|
+
if (!hoverID || !this.selectedID || this.selectedID === hoverID) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
if (((_a = this.config) == null ? void 0 : _a.lineType) !== ELineTypes.Line) {
|
|
711
|
+
this.emit("messageInfo", i18n.t("CurveModeDoesNotSupportCutting"));
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
const selectedPolygon = this.polygonList.find((v) => v.id === this.selectedID);
|
|
715
|
+
const combinedPolygon = this.currentShowList.find((v) => v.id === hoverID);
|
|
716
|
+
if (!combinedPolygon || !selectedPolygon) {
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
const composeData = PolygonUtils.combinePolygonWithPolygon(selectedPolygon, combinedPolygon);
|
|
720
|
+
if (!composeData) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
const {newPolygon, unionList} = composeData;
|
|
724
|
+
if (unionList.length === 1 && newPolygon) {
|
|
725
|
+
const newPolygonList = this.polygonList.filter((v) => !unionList.includes(v.id)).map((v) => {
|
|
726
|
+
if (v.id === this.selectedID) {
|
|
727
|
+
return newPolygon;
|
|
728
|
+
}
|
|
729
|
+
return v;
|
|
730
|
+
});
|
|
731
|
+
this.setPolygonList(newPolygonList);
|
|
732
|
+
this.history.pushHistory(newPolygonList);
|
|
733
|
+
this.render();
|
|
734
|
+
this.emit("messageInfo", i18n.t("CombineSuccess"));
|
|
735
|
+
} else {
|
|
736
|
+
this.emit("messageInfo", i18n.t("CombiningFailedNotify"));
|
|
737
|
+
}
|
|
738
|
+
this.isCombined = false;
|
|
739
|
+
}
|
|
740
|
+
isPolygonOutSide(selectedPointList) {
|
|
741
|
+
if (this.dependToolName && this.basicCanvas && this.basicResult) {
|
|
742
|
+
let isOutSide = false;
|
|
743
|
+
switch (this.dependToolName) {
|
|
744
|
+
case EToolName.Rect: {
|
|
745
|
+
isOutSide = selectedPointList.filter((v) => !RectUtils.isInRect(v, this.basicResult)).length > 0;
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
case EToolName.Polygon: {
|
|
749
|
+
isOutSide = PolygonUtils.isPointListOutSidePolygon(selectedPointList, this.basicResult.pointList, this.config.lineType);
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return isOutSide;
|
|
754
|
+
}
|
|
755
|
+
if (!this.imgInfo) {
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
const {left, top, right, bottom} = MathUtils.calcViewportBoundaries(AxisUtils.changePointListByZoom(selectedPointList, this.zoom));
|
|
759
|
+
const scope = 1e-5;
|
|
760
|
+
if (left < 0 || top < 0 || right > this.imgInfo.width + scope || bottom > this.imgInfo.height + scope) {
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
onDragMove(e) {
|
|
766
|
+
if (!this.dragInfo || !this.selectedID) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
769
|
+
const {selectedPolygon} = this;
|
|
770
|
+
let selectedPointList = selectedPolygon == null ? void 0 : selectedPolygon.pointList;
|
|
771
|
+
if (!selectedPointList) {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const {initPointList, dragStartCoord, dragTarget, changePointIndex} = this.dragInfo;
|
|
775
|
+
const coordinate = this.getCoordinateUnderZoom(e);
|
|
776
|
+
let offset = {
|
|
777
|
+
x: (coordinate.x - dragStartCoord.x) / this.zoom,
|
|
778
|
+
y: (coordinate.y - dragStartCoord.y) / this.zoom
|
|
779
|
+
};
|
|
780
|
+
if (this.pattern === EPolygonPattern.Rect && (selectedPolygon == null ? void 0 : selectedPolygon.isRect) === true && changePointIndex && [EDragTarget.Line].includes(dragTarget)) {
|
|
781
|
+
const firstPointIndex = MathUtils.getArrayIndex(changePointIndex[0] - 2, 4);
|
|
782
|
+
const secondPointIndex = MathUtils.getArrayIndex(changePointIndex[0] - 1, 4);
|
|
783
|
+
const basicLine = [initPointList[firstPointIndex], initPointList[secondPointIndex]];
|
|
784
|
+
offset = MathUtils.getRectPerpendicularOffset(dragStartCoord, coordinate, basicLine);
|
|
785
|
+
offset = {
|
|
786
|
+
x: offset.x / this.zoom,
|
|
787
|
+
y: offset.y / this.zoom
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
this.dragStatus = EDragStatus.Move;
|
|
791
|
+
switch (dragTarget) {
|
|
792
|
+
case EDragTarget.Plane:
|
|
793
|
+
selectedPointList = selectedPointList.map((v, i) => __spreadProps(__spreadValues({}, v), {
|
|
794
|
+
x: initPointList[i].x + offset.x,
|
|
795
|
+
y: initPointList[i].y + offset.y
|
|
796
|
+
}));
|
|
797
|
+
break;
|
|
798
|
+
case EDragTarget.Point:
|
|
799
|
+
case EDragTarget.Line:
|
|
800
|
+
selectedPointList = selectedPointList.map((n, i) => {
|
|
801
|
+
if (changePointIndex && changePointIndex.includes(i)) {
|
|
802
|
+
return __spreadProps(__spreadValues({}, n), {
|
|
803
|
+
x: initPointList[i].x + offset.x,
|
|
804
|
+
y: initPointList[i].y + offset.y
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
return n;
|
|
808
|
+
});
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
if (this.pattern === EPolygonPattern.Rect && (selectedPolygon == null ? void 0 : selectedPolygon.isRect) === true && dragTarget === EDragTarget.Point && changePointIndex) {
|
|
812
|
+
const newPointList = MathUtils.getPointListFromPointOffset(initPointList, changePointIndex[0], offset);
|
|
813
|
+
selectedPointList = newPointList;
|
|
814
|
+
}
|
|
815
|
+
if (this.config.drawOutsideTarget === false && this.imgInfo) {
|
|
816
|
+
const isOutSide = this.isPolygonOutSide(selectedPointList);
|
|
817
|
+
if (isOutSide) {
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
const newPolygonList = this.polygonList.map((v) => {
|
|
822
|
+
if (v.id === this.selectedID) {
|
|
823
|
+
const newData = __spreadProps(__spreadValues({}, v), {
|
|
824
|
+
pointList: selectedPointList
|
|
825
|
+
});
|
|
826
|
+
if (v.isRect === true && this.pattern === EPolygonPattern.Normal) {
|
|
827
|
+
Object.assign(newData, {isRect: false});
|
|
828
|
+
}
|
|
829
|
+
return newData;
|
|
830
|
+
}
|
|
831
|
+
return v;
|
|
832
|
+
});
|
|
833
|
+
this.setPolygonList(newPolygonList);
|
|
834
|
+
this.render();
|
|
835
|
+
}
|
|
836
|
+
onMouseMove(e) {
|
|
837
|
+
if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
if (this.selectedID && this.dragInfo) {
|
|
841
|
+
this.onDragMove(e);
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
let hoverPointIndex = -1;
|
|
845
|
+
let hoverEdgeIndex = -1;
|
|
846
|
+
const {selectedID} = this;
|
|
847
|
+
if (selectedID) {
|
|
848
|
+
this.hoverEdgeIndex = -1;
|
|
849
|
+
this.hoverPointIndex = -1;
|
|
850
|
+
hoverPointIndex = this.getHoverPointIndex(e);
|
|
851
|
+
if (hoverPointIndex > -1) {
|
|
852
|
+
this.hoverPointIndex = hoverPointIndex;
|
|
853
|
+
} else {
|
|
854
|
+
hoverEdgeIndex = this.getHoverEdgeIndex(e);
|
|
855
|
+
this.hoverEdgeIndex = hoverEdgeIndex;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (this.drawingPointList.length > 0) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
const newHoverID = this.getHoverID(e);
|
|
862
|
+
if (this.hoverID !== newHoverID) {
|
|
863
|
+
this.hoverID = newHoverID;
|
|
864
|
+
this.render();
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
leftMouseUp(e) {
|
|
868
|
+
const hoverID = this.getHoverID(e);
|
|
869
|
+
if (this.drawingPointList.length === 0 && e.ctrlKey === true && hoverID) {
|
|
870
|
+
this.setPolygonValidAndRender(hoverID);
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
this.addPointInDrawing(e);
|
|
874
|
+
}
|
|
875
|
+
onMouseUp(e) {
|
|
876
|
+
if (this.isCombined) {
|
|
877
|
+
switch (e.button) {
|
|
878
|
+
case 0:
|
|
879
|
+
this.combine(e);
|
|
880
|
+
break;
|
|
881
|
+
case 2:
|
|
882
|
+
this.isCombined = false;
|
|
883
|
+
break;
|
|
884
|
+
default:
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
889
|
+
if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
|
|
890
|
+
return void 0;
|
|
891
|
+
}
|
|
892
|
+
if (this.dragInfo && this.dragStatus === EDragStatus.Move) {
|
|
893
|
+
const {originPolygon} = this.dragInfo;
|
|
894
|
+
this.dragInfo = void 0;
|
|
895
|
+
this.dragStatus = EDragStatus.Wait;
|
|
896
|
+
this.history.pushHistory(this.polygonList);
|
|
897
|
+
this.emit("updateResult");
|
|
898
|
+
this.emit("updatePolygonByDrag", {newPolygon: this.selectedPolygon, originPolygon});
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
switch (e.button) {
|
|
902
|
+
case 0: {
|
|
903
|
+
this.leftMouseUp(e);
|
|
904
|
+
break;
|
|
905
|
+
}
|
|
906
|
+
case 2: {
|
|
907
|
+
this.rightMouseUp(e);
|
|
908
|
+
break;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
this.render();
|
|
912
|
+
}
|
|
913
|
+
dragMouseUp() {
|
|
914
|
+
if (this.dragStatus === EDragStatus.Start) {
|
|
915
|
+
this.dragInfo = void 0;
|
|
916
|
+
this.dragStatus = EDragStatus.Wait;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
exportData() {
|
|
920
|
+
const {polygonList} = this;
|
|
921
|
+
return [polygonList, this.basicImgInfo];
|
|
922
|
+
}
|
|
923
|
+
getTextIconSvg(attribute = "") {
|
|
924
|
+
return AttributeUtils.getTextIconSvg(attribute, this.config.attributeList, this.config.attributeConfigurable, this.baseIcon);
|
|
925
|
+
}
|
|
926
|
+
getCurrentSelectedData() {
|
|
927
|
+
const {selectedPolygon} = this;
|
|
928
|
+
if (!selectedPolygon) {
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
const toolColor = this.getColor(selectedPolygon.attribute);
|
|
932
|
+
const color = selectedPolygon.valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
|
|
933
|
+
return {
|
|
934
|
+
width: TEXT_MAX_WIDTH,
|
|
935
|
+
textAttribute: selectedPolygon.textAttribute,
|
|
936
|
+
color
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
updateSelectedTextAttribute(newTextAttribute) {
|
|
940
|
+
if (this._textAttributInstance && newTextAttribute && this.selectedID) {
|
|
941
|
+
let textAttribute = newTextAttribute;
|
|
942
|
+
if (AttributeUtils.textAttributeValidate(this.config.textCheckType, "", textAttribute) === false) {
|
|
943
|
+
this.emit("messageError", AttributeUtils.getErrorNotice(this.config.textCheckType, this.lang));
|
|
944
|
+
textAttribute = "";
|
|
945
|
+
}
|
|
946
|
+
this.setPolygonList(AttributeUtils.textChange(textAttribute, this.selectedID, this.polygonList));
|
|
947
|
+
this.emit("updateTextAttribute");
|
|
948
|
+
this.render();
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
renderTextAttribute() {
|
|
952
|
+
var _a;
|
|
953
|
+
const {selectedPolygon} = this;
|
|
954
|
+
if (!this.ctx || this.config.textConfigurable === false || !selectedPolygon) {
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
const {pointList, attribute, valid, textAttribute} = selectedPolygon;
|
|
958
|
+
const {x, y} = pointList[pointList.length - 1];
|
|
959
|
+
const newWidth = TEXT_MAX_WIDTH;
|
|
960
|
+
const coordinate = AxisUtils.getOffsetCoordinate({x, y}, this.currentPos, this.zoom);
|
|
961
|
+
const toolColor = this.getColor(attribute);
|
|
962
|
+
const color = valid ? toolColor == null ? void 0 : toolColor.valid.stroke : toolColor == null ? void 0 : toolColor.invalid.stroke;
|
|
963
|
+
if (!this._textAttributInstance) {
|
|
964
|
+
this._textAttributInstance = new TextAttributeClass({
|
|
965
|
+
width: newWidth,
|
|
966
|
+
container: this.container,
|
|
967
|
+
icon: this.getTextIconSvg(attribute),
|
|
968
|
+
color,
|
|
969
|
+
getCurrentSelectedData: this.getCurrentSelectedData,
|
|
970
|
+
updateSelectedTextAttribute: this.updateSelectedTextAttribute
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
if (this._textAttributInstance && !((_a = this._textAttributInstance) == null ? void 0 : _a.isExit)) {
|
|
974
|
+
this._textAttributInstance.appendToContainer();
|
|
975
|
+
}
|
|
976
|
+
this._textAttributInstance.update(`${textAttribute}`, {
|
|
977
|
+
left: coordinate.x,
|
|
978
|
+
top: coordinate.y,
|
|
979
|
+
color,
|
|
980
|
+
width: newWidth
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
renderStaticPolygon() {
|
|
984
|
+
var _a;
|
|
985
|
+
if (this.isHidden === false) {
|
|
986
|
+
(_a = this.polygonList) == null ? void 0 : _a.forEach((polygon) => {
|
|
987
|
+
var _a2, _b, _c, _d, _e;
|
|
988
|
+
if ([this.selectedID, this.editPolygonID].includes(polygon.id)) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
const {textAttribute, attribute} = polygon;
|
|
992
|
+
const toolColor = this.getColor(attribute);
|
|
993
|
+
const toolData = StyleUtils.getStrokeAndFill(toolColor, polygon.valid);
|
|
994
|
+
const transformPointList = AxisUtils.changePointListByZoom(polygon.pointList || [], this.zoom, this.currentPos);
|
|
995
|
+
DrawUtils.drawPolygonWithFillAndLine(this.canvas, transformPointList, {
|
|
996
|
+
fillColor: toolData.fill,
|
|
997
|
+
strokeColor: toolData.stroke,
|
|
998
|
+
pointColor: "white",
|
|
999
|
+
thickness: (_b = (_a2 = this.style) == null ? void 0 : _a2.width) != null ? _b : 2,
|
|
1000
|
+
lineCap: "round",
|
|
1001
|
+
isClose: true,
|
|
1002
|
+
lineType: (_c = this.config) == null ? void 0 : _c.lineType
|
|
1003
|
+
});
|
|
1004
|
+
let showText = `${(_d = AttributeUtils.getAttributeShowText(attribute, this.config.attributeList)) != null ? _d : ""}`;
|
|
1005
|
+
if (((_e = this.config) == null ? void 0 : _e.isShowOrder) && (polygon == null ? void 0 : polygon.order) > 0) {
|
|
1006
|
+
showText = `${polygon.order} ${showText}`;
|
|
1007
|
+
}
|
|
1008
|
+
DrawUtils.drawText(this.canvas, transformPointList[0], showText, __spreadValues({
|
|
1009
|
+
color: toolData.stroke
|
|
1010
|
+
}, DEFAULT_TEXT_OFFSET));
|
|
1011
|
+
const endPoint = transformPointList[transformPointList.length - 1];
|
|
1012
|
+
DrawUtils.drawText(this.canvas, {x: endPoint.x + TEXT_ATTRIBUTE_OFFSET.x, y: endPoint.y + TEXT_ATTRIBUTE_OFFSET.y}, textAttribute, __spreadValues({
|
|
1013
|
+
color: toolData.stroke
|
|
1014
|
+
}, DEFAULT_TEXT_OFFSET));
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
renderSelectedPolygon() {
|
|
1019
|
+
var _a, _b, _c;
|
|
1020
|
+
if (this.selectedID) {
|
|
1021
|
+
const selectdPolygon = this.selectedPolygon;
|
|
1022
|
+
if (selectdPolygon) {
|
|
1023
|
+
const toolColor = this.getColor(selectdPolygon.attribute);
|
|
1024
|
+
const toolData = StyleUtils.getStrokeAndFill(toolColor, selectdPolygon.valid, {isSelected: true});
|
|
1025
|
+
DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas, AxisUtils.changePointListByZoom(selectdPolygon.pointList, this.zoom, this.currentPos), {
|
|
1026
|
+
fillColor: toolData.fill,
|
|
1027
|
+
strokeColor: toolData.stroke,
|
|
1028
|
+
pointColor: "white",
|
|
1029
|
+
thickness: 2,
|
|
1030
|
+
lineCap: "round",
|
|
1031
|
+
isClose: true,
|
|
1032
|
+
lineType: (_a = this.config) == null ? void 0 : _a.lineType
|
|
1033
|
+
});
|
|
1034
|
+
let showText = `${(_b = AttributeUtils.getAttributeShowText(selectdPolygon.attribute, this.config.attributeList)) != null ? _b : ""}`;
|
|
1035
|
+
if (((_c = this.config) == null ? void 0 : _c.isShowOrder) && (selectdPolygon == null ? void 0 : selectdPolygon.order) > 0) {
|
|
1036
|
+
showText = `${selectdPolygon.order} ${showText}`;
|
|
1037
|
+
}
|
|
1038
|
+
DrawUtils.drawText(this.canvas, AxisUtils.changePointByZoom(selectdPolygon.pointList[0], this.zoom, this.currentPos), showText, __spreadValues({
|
|
1039
|
+
color: toolData.stroke
|
|
1040
|
+
}, DEFAULT_TEXT_OFFSET));
|
|
1041
|
+
this.renderTextAttribute();
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
renderHoverPolygon() {
|
|
1046
|
+
var _a;
|
|
1047
|
+
if (this.hoverID && this.hoverID !== this.editPolygonID) {
|
|
1048
|
+
const {hoverPolygon} = this;
|
|
1049
|
+
if (hoverPolygon) {
|
|
1050
|
+
let color = "";
|
|
1051
|
+
const toolColor = this.getColor(hoverPolygon.attribute);
|
|
1052
|
+
if (hoverPolygon.valid) {
|
|
1053
|
+
color = toolColor.validHover.fill;
|
|
1054
|
+
} else {
|
|
1055
|
+
color = StyleUtils.getStrokeAndFill(toolColor, false, {isHover: true}).fill;
|
|
1056
|
+
}
|
|
1057
|
+
DrawUtils.drawPolygonWithFill(this.canvas, AxisUtils.changePointListByZoom(hoverPolygon.pointList, this.zoom, this.currentPos), {
|
|
1058
|
+
color,
|
|
1059
|
+
lineType: (_a = this.config) == null ? void 0 : _a.lineType
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
renderPolygon() {
|
|
1065
|
+
var _a, _b, _c, _d;
|
|
1066
|
+
this.renderStaticPolygon();
|
|
1067
|
+
this.renderHoverPolygon();
|
|
1068
|
+
this.renderSelectedPolygon();
|
|
1069
|
+
const defaultColor = this.getColor(this.defaultAttribute);
|
|
1070
|
+
const toolData = StyleUtils.getStrokeAndFill(defaultColor, !this.isCtrl);
|
|
1071
|
+
if (((_a = this.drawingPointList) == null ? void 0 : _a.length) > 0) {
|
|
1072
|
+
let drawingPointList = [...this.drawingPointList];
|
|
1073
|
+
let coordinate = AxisUtils.getOriginCoordinateWithOffsetCoordinate(this.coord, this.zoom, this.currentPos);
|
|
1074
|
+
if (this.pattern === EPolygonPattern.Rect && drawingPointList.length === 2) {
|
|
1075
|
+
drawingPointList = MathUtils.getRectangleByRightAngle(coordinate, drawingPointList);
|
|
1076
|
+
} else {
|
|
1077
|
+
if (((_b = this.config) == null ? void 0 : _b.edgeAdsorption) && this.isAlt === false) {
|
|
1078
|
+
const {dropFoot} = PolygonUtils.getClosestPoint(coordinate, this.polygonList, (_c = this.config) == null ? void 0 : _c.lineType, edgeAdsorptionScope / this.zoom);
|
|
1079
|
+
if (dropFoot) {
|
|
1080
|
+
coordinate = dropFoot;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
drawingPointList.push(coordinate);
|
|
1084
|
+
}
|
|
1085
|
+
DrawUtils.drawSelectedPolygonWithFillAndLine(this.canvas, AxisUtils.changePointListByZoom(drawingPointList, this.zoom, this.currentPos), {
|
|
1086
|
+
fillColor: toolData.fill,
|
|
1087
|
+
strokeColor: toolData.stroke,
|
|
1088
|
+
pointColor: "white",
|
|
1089
|
+
thickness: 2,
|
|
1090
|
+
lineCap: "round",
|
|
1091
|
+
isClose: false,
|
|
1092
|
+
lineType: this.config.lineType
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
if (this.hoverPointIndex > -1 && this.selectedID) {
|
|
1096
|
+
const selectdPolygon = this.selectedPolygon;
|
|
1097
|
+
if (!selectdPolygon) {
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
const hoverColor = StyleUtils.getStrokeAndFill(defaultColor, selectdPolygon.valid, {isSelected: true});
|
|
1101
|
+
const point = selectdPolygon == null ? void 0 : selectdPolygon.pointList[this.hoverPointIndex];
|
|
1102
|
+
if (point) {
|
|
1103
|
+
const {x, y} = AxisUtils.changePointByZoom(point, this.zoom, this.currentPos);
|
|
1104
|
+
DrawUtils.drawCircleWithFill(this.canvas, {x, y}, 5, {
|
|
1105
|
+
color: hoverColor.fill
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
if (this.hoverEdgeIndex > -1 && this.selectedID) {
|
|
1110
|
+
const selectdPolygon = this.selectedPolygon;
|
|
1111
|
+
if (!selectdPolygon) {
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
const selectedColor = StyleUtils.getStrokeAndFill(defaultColor, selectdPolygon.valid, {isSelected: true});
|
|
1115
|
+
DrawUtils.drawLineWithPointList(this.canvas, AxisUtils.changePointListByZoom(selectdPolygon.pointList, this.zoom, this.currentPos), {
|
|
1116
|
+
color: selectedColor.stroke,
|
|
1117
|
+
thickness: 10,
|
|
1118
|
+
hoverEdgeIndex: this.hoverEdgeIndex,
|
|
1119
|
+
lineType: (_d = this.config) == null ? void 0 : _d.lineType
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
render() {
|
|
1124
|
+
if (!this.ctx) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
super.render();
|
|
1128
|
+
this.renderPolygon();
|
|
1129
|
+
this.renderCursorLine(this.getLineColor(this.defaultAttribute));
|
|
1130
|
+
}
|
|
1131
|
+
renderCursorLine(lineColor) {
|
|
1132
|
+
super.renderCursorLine(lineColor);
|
|
1133
|
+
if (this.isCombined) {
|
|
1134
|
+
const {x, y} = this.coord;
|
|
1135
|
+
const padding = 10;
|
|
1136
|
+
const rectWidth = 186;
|
|
1137
|
+
const rectHeight = 32;
|
|
1138
|
+
DrawUtils.drawRectWithFill(this.canvas, {
|
|
1139
|
+
x: x + padding,
|
|
1140
|
+
y: y - padding * 4 - 1,
|
|
1141
|
+
width: rectWidth,
|
|
1142
|
+
height: rectHeight
|
|
1143
|
+
}, {color: "black"});
|
|
1144
|
+
DrawUtils.drawText(this.canvas, {x, y}, i18n.t("ClickAnotherPolygon"), {
|
|
1145
|
+
textAlign: "center",
|
|
1146
|
+
color: "white",
|
|
1147
|
+
offsetX: rectWidth / 2 + padding,
|
|
1148
|
+
offsetY: -(rectHeight / 2 + padding / 2)
|
|
1149
|
+
});
|
|
1150
|
+
DrawUtils.drawRect(this.canvas, {
|
|
1151
|
+
x: x - padding,
|
|
1152
|
+
y: y - padding,
|
|
1153
|
+
width: padding * 2,
|
|
1154
|
+
height: padding * 2
|
|
1155
|
+
}, {lineDash: [6], color: "white"});
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
undo() {
|
|
1159
|
+
if (this.drawingPointList.length > 0) {
|
|
1160
|
+
const drawingPointList = this.drawingHistory.undo();
|
|
1161
|
+
if (!drawingPointList) {
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
this.drawingPointList = drawingPointList;
|
|
1165
|
+
this.render();
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
const polygonList = this.history.undo();
|
|
1169
|
+
if (polygonList) {
|
|
1170
|
+
if (polygonList.length !== this.polygonList.length) {
|
|
1171
|
+
this.deleteSelectedID();
|
|
1172
|
+
}
|
|
1173
|
+
this.setPolygonList(polygonList);
|
|
1174
|
+
this.render();
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
redo() {
|
|
1178
|
+
if (this.drawingPointList.length > 0) {
|
|
1179
|
+
const drawingPointList = this.drawingHistory.redo();
|
|
1180
|
+
if (!drawingPointList) {
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
this.drawingPointList = drawingPointList;
|
|
1184
|
+
this.render();
|
|
1185
|
+
return;
|
|
1186
|
+
}
|
|
1187
|
+
const polygonList = this.history.redo();
|
|
1188
|
+
if (polygonList) {
|
|
1189
|
+
if (polygonList.length !== this.polygonList.length) {
|
|
1190
|
+
this.deleteSelectedID();
|
|
1191
|
+
}
|
|
1192
|
+
this.setPolygonList(polygonList);
|
|
1193
|
+
this.render();
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
deleteSelectedID() {
|
|
1197
|
+
this.setSelectedID("");
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
export { PolygonOperation as default };
|