@inweb/viewer-visualize 25.3.13
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/LICENSE +20 -0
- package/README.md +63 -0
- package/dist/viewer-visualize.js +16982 -0
- package/dist/viewer-visualize.js.map +1 -0
- package/dist/viewer-visualize.min.js +1 -0
- package/dist/viewer-visualize.module.js +5267 -0
- package/dist/viewer-visualize.module.js.map +1 -0
- package/lib/Viewer/Commands/ApplyModelTransform.d.ts +1 -0
- package/lib/Viewer/Commands/ClearMarkup.d.ts +1 -0
- package/lib/Viewer/Commands/ClearSlices.d.ts +1 -0
- package/lib/Viewer/Commands/CreatePreview.d.ts +1 -0
- package/lib/Viewer/Commands/Explode.d.ts +1 -0
- package/lib/Viewer/Commands/GetDefaultViewPositions.d.ts +1 -0
- package/lib/Viewer/Commands/GetModels.d.ts +1 -0
- package/lib/Viewer/Commands/GetSelected.d.ts +1 -0
- package/lib/Viewer/Commands/HideSelected.d.ts +1 -0
- package/lib/Viewer/Commands/IsolateSelected.d.ts +1 -0
- package/lib/Viewer/Commands/RegenerateAll.d.ts +1 -0
- package/lib/Viewer/Commands/ResetView.d.ts +1 -0
- package/lib/Viewer/Commands/SelectModel.d.ts +1 -0
- package/lib/Viewer/Commands/SetActiveDragger.d.ts +1 -0
- package/lib/Viewer/Commands/SetDefaultViewPosition.d.ts +1 -0
- package/lib/Viewer/Commands/SetMarkupColor.d.ts +1 -0
- package/lib/Viewer/Commands/SetSelected.d.ts +1 -0
- package/lib/Viewer/Commands/ShowAll.d.ts +1 -0
- package/lib/Viewer/Commands/Unselect.d.ts +1 -0
- package/lib/Viewer/Commands/ZoomToExtents.d.ts +1 -0
- package/lib/Viewer/Commands/ZoomToObjects.d.ts +1 -0
- package/lib/Viewer/Commands/ZoomToSelected.d.ts +1 -0
- package/lib/Viewer/Commands/index.d.ts +22 -0
- package/lib/Viewer/Draggers/Actions/OrbitAction.d.ts +21 -0
- package/lib/Viewer/Draggers/Actions/PanAction.d.ts +17 -0
- package/lib/Viewer/Draggers/Actions/ZoomAction.d.ts +7 -0
- package/lib/Viewer/Draggers/Common/Geometry.d.ts +114 -0
- package/lib/Viewer/Draggers/Common/GestureManager.d.ts +40 -0
- package/lib/Viewer/Draggers/Common/OdBaseDragger.d.ts +53 -0
- package/lib/Viewer/Draggers/Common/OdaGeAction.d.ts +29 -0
- package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +30 -0
- package/lib/Viewer/Draggers/MeasureLineDragger/MeasureUtils.d.ts +19 -0
- package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +23 -0
- package/lib/Viewer/Draggers/OdBaseCuttingPlaneDragger.d.ts +26 -0
- package/lib/Viewer/Draggers/OdCuttingPlaneXAxisDragger.d.ts +7 -0
- package/lib/Viewer/Draggers/OdCuttingPlaneYAxisDragger.d.ts +7 -0
- package/lib/Viewer/Draggers/OdCuttingPlaneZAxisDragger.d.ts +7 -0
- package/lib/Viewer/Draggers/OdOrbitDragger.d.ts +14 -0
- package/lib/Viewer/Draggers/OdPanDragger.d.ts +11 -0
- package/lib/Viewer/Draggers/OdZoomDragger.d.ts +11 -0
- package/lib/Viewer/Draggers/OdZoomWheelDragger.d.ts +10 -0
- package/lib/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.d.ts +18 -0
- package/lib/Viewer/Draggers/OdZoomWindowDragger/index.d.ts +13 -0
- package/lib/Viewer/Draggers/OdaLineDragger.d.ts +14 -0
- package/lib/Viewer/Draggers/OdaTextDragger.d.ts +15 -0
- package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +29 -0
- package/lib/Viewer/Draggers/OrbitAroundBuildingDragger.d.ts +18 -0
- package/lib/Viewer/Loaders/BaseLoader.d.ts +10 -0
- package/lib/Viewer/Loaders/LoaderFactory.d.ts +10 -0
- package/lib/Viewer/Loaders/TCSLoader.d.ts +4 -0
- package/lib/Viewer/Loaders/UpdaterController.d.ts +14 -0
- package/lib/Viewer/Loaders/VsfXLoader.d.ts +4 -0
- package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +4 -0
- package/lib/Viewer/Loaders/VsfXStreamingLoader.d.ts +4 -0
- package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +21 -0
- package/lib/Viewer/Markup/Api/IMarkupCloud.d.ts +14 -0
- package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +4 -0
- package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +14 -0
- package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +14 -0
- package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +12 -0
- package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +11 -0
- package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +14 -0
- package/lib/Viewer/Markup/Api/IMarkupText.d.ts +12 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +46 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaCloud.d.ts +35 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +40 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +36 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +36 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +38 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +37 -0
- package/lib/Viewer/Markup/IMarkup.d.ts +39 -0
- package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +70 -0
- package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +18 -0
- package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +33 -0
- package/lib/Viewer/Markup/MarkupFactory.d.ts +6 -0
- package/lib/Viewer/Viewer.d.ts +346 -0
- package/lib/Viewer/utils.d.ts +3 -0
- package/lib/index.d.ts +3 -0
- package/package.json +44 -0
- package/src/Viewer/Commands/ApplyModelTransform.ts +69 -0
- package/src/Viewer/Commands/ClearMarkup.ts +28 -0
- package/src/Viewer/Commands/ClearSlices.ts +27 -0
- package/src/Viewer/Commands/CreatePreview.ts +33 -0
- package/src/Viewer/Commands/Explode.ts +38 -0
- package/src/Viewer/Commands/GetDefaultViewPositions.ts +36 -0
- package/src/Viewer/Commands/GetModels.ts +43 -0
- package/src/Viewer/Commands/GetSelected.ts +58 -0
- package/src/Viewer/Commands/HideSelected.ts +37 -0
- package/src/Viewer/Commands/IsolateSelected.ts +37 -0
- package/src/Viewer/Commands/RegenerateAll.ts +37 -0
- package/src/Viewer/Commands/ResetView.ts +43 -0
- package/src/Viewer/Commands/SelectModel.ts +52 -0
- package/src/Viewer/Commands/SetActiveDragger.ts +29 -0
- package/src/Viewer/Commands/SetDefaultViewPosition.ts +50 -0
- package/src/Viewer/Commands/SetMarkupColor.ts +29 -0
- package/src/Viewer/Commands/SetSelected.ts +47 -0
- package/src/Viewer/Commands/ShowAll.ts +37 -0
- package/src/Viewer/Commands/Unselect.ts +37 -0
- package/src/Viewer/Commands/ZoomToExtents.ts +43 -0
- package/src/Viewer/Commands/ZoomToObjects.ts +47 -0
- package/src/Viewer/Commands/ZoomToSelected.ts +39 -0
- package/src/Viewer/Commands/index.ts +45 -0
- package/src/Viewer/Draggers/Actions/OrbitAction.ts +250 -0
- package/src/Viewer/Draggers/Actions/PanAction.ts +102 -0
- package/src/Viewer/Draggers/Actions/ZoomAction.ts +45 -0
- package/src/Viewer/Draggers/Common/Geometry.ts +152 -0
- package/src/Viewer/Draggers/Common/GestureManager.ts +263 -0
- package/src/Viewer/Draggers/Common/OdBaseDragger.ts +270 -0
- package/src/Viewer/Draggers/Common/OdaGeAction.ts +146 -0
- package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +248 -0
- package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +182 -0
- package/src/Viewer/Draggers/MeasureLineDragger/index.ts +166 -0
- package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +182 -0
- package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +53 -0
- package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +53 -0
- package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +53 -0
- package/src/Viewer/Draggers/OdOrbitDragger.ts +70 -0
- package/src/Viewer/Draggers/OdPanDragger.ts +62 -0
- package/src/Viewer/Draggers/OdZoomDragger.ts +59 -0
- package/src/Viewer/Draggers/OdZoomWheelDragger.ts +103 -0
- package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +123 -0
- package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +75 -0
- package/src/Viewer/Draggers/OdaLineDragger.ts +80 -0
- package/src/Viewer/Draggers/OdaTextDragger.ts +118 -0
- package/src/Viewer/Draggers/OdaWalkDragger.ts +278 -0
- package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +184 -0
- package/src/Viewer/Loaders/BaseLoader.ts +40 -0
- package/src/Viewer/Loaders/LoaderFactory.ts +48 -0
- package/src/Viewer/Loaders/TCSLoader.ts +82 -0
- package/src/Viewer/Loaders/UpdaterController.ts +36 -0
- package/src/Viewer/Loaders/VsfXLoader.ts +65 -0
- package/src/Viewer/Loaders/VsfXPartialLoader.ts +208 -0
- package/src/Viewer/Loaders/VsfXStreamingLoader.ts +87 -0
- package/src/Viewer/Markup/Api/IMarkupArrow.ts +12 -0
- package/src/Viewer/Markup/Api/IMarkupCloud.ts +15 -0
- package/src/Viewer/Markup/Api/IMarkupColorable.ts +4 -0
- package/src/Viewer/Markup/Api/IMarkupEllipse.ts +15 -0
- package/src/Viewer/Markup/Api/IMarkupImage.ts +15 -0
- package/src/Viewer/Markup/Api/IMarkupLine.ts +13 -0
- package/src/Viewer/Markup/Api/IMarkupObject.ts +15 -0
- package/src/Viewer/Markup/Api/IMarkupRectangle.ts +15 -0
- package/src/Viewer/Markup/Api/IMarkupText.ts +12 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +117 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +208 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +118 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +123 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +131 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +119 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +110 -0
- package/src/Viewer/Markup/IMarkup.ts +42 -0
- package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +1144 -0
- package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +39 -0
- package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +229 -0
- package/src/Viewer/Markup/MarkupFactory.ts +32 -0
- package/src/Viewer/Viewer.ts +1183 -0
- package/src/Viewer/utils.ts +74 -0
- package/src/index.ts +26 -0
|
@@ -0,0 +1,1144 @@
|
|
|
1
|
+
import Konva from "konva";
|
|
2
|
+
import { ChangeActiveDraggerEvent, IViewpoint, LineType, PanEvent } from "@inweb/viewer-core";
|
|
3
|
+
|
|
4
|
+
import { IMarkup, MarkupMode } from "../../IMarkup";
|
|
5
|
+
import { Viewer } from "../../../Viewer";
|
|
6
|
+
import { MarkupColor } from "./MarkupColor";
|
|
7
|
+
import * as utils from "../../../Draggers/MeasureLineDragger/MeasureUtils";
|
|
8
|
+
import { OdBaseDragger } from "../../../Draggers/Common/OdBaseDragger";
|
|
9
|
+
import { IMarkupObject } from "../../Api/IMarkupObject";
|
|
10
|
+
import { KonvaLine } from "../../Api/Impl/Konva/KonvaLine";
|
|
11
|
+
import { KonvaText } from "../../Api/Impl/Konva/KonvaText";
|
|
12
|
+
import { KonvaRectangle } from "../../Api/Impl/Konva/KonvaRectangle";
|
|
13
|
+
import { KonvaEllipse } from "../../Api/Impl/Konva/KonvaEllipse";
|
|
14
|
+
import { KonvaArrow } from "../../Api/Impl/Konva/KonvaArrow";
|
|
15
|
+
import { KonvaImage } from "../../Api/Impl/Konva/KonvaImage";
|
|
16
|
+
import { KonvaCloud } from "../../Api/Impl/Konva/KonvaCloud";
|
|
17
|
+
|
|
18
|
+
class KonvaShape {
|
|
19
|
+
name: string;
|
|
20
|
+
initializer: (ref: any) => any;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// move to separate class and create factory with enum?
|
|
24
|
+
const MarkupMode2Konva = new Map<MarkupMode, KonvaShape>([
|
|
25
|
+
[
|
|
26
|
+
MarkupMode.Line,
|
|
27
|
+
{
|
|
28
|
+
name: "Line",
|
|
29
|
+
initializer: (ref) => {
|
|
30
|
+
return new KonvaLine(null, ref);
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
MarkupMode.Text,
|
|
36
|
+
{
|
|
37
|
+
name: "Text",
|
|
38
|
+
initializer: (ref) => {
|
|
39
|
+
return new KonvaText(null, ref);
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
[
|
|
44
|
+
MarkupMode.Rectangle,
|
|
45
|
+
{
|
|
46
|
+
name: "Rect",
|
|
47
|
+
initializer: (ref) => {
|
|
48
|
+
return new KonvaRectangle(null, ref);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
MarkupMode.Ellipse,
|
|
54
|
+
{
|
|
55
|
+
name: "Ellipse",
|
|
56
|
+
initializer: (ref) => {
|
|
57
|
+
return new KonvaEllipse(null, ref);
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
[
|
|
62
|
+
MarkupMode.Arrow,
|
|
63
|
+
{
|
|
64
|
+
name: "Arrow",
|
|
65
|
+
initializer: (ref) => {
|
|
66
|
+
return new KonvaArrow(null, ref);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
MarkupMode.Image,
|
|
72
|
+
{
|
|
73
|
+
name: "Image",
|
|
74
|
+
initializer: (ref) => {
|
|
75
|
+
return new KonvaImage(null, ref);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
MarkupMode.Cloud,
|
|
81
|
+
{
|
|
82
|
+
name: "Cloud",
|
|
83
|
+
initializer: (ref) => {
|
|
84
|
+
return new KonvaCloud(null, ref);
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
export class KonvaMarkup implements IMarkup {
|
|
91
|
+
private _isInitialized = false;
|
|
92
|
+
private _viewer: Viewer;
|
|
93
|
+
private _canvasOriginal: HTMLCanvasElement;
|
|
94
|
+
private _canvasEvents: string[];
|
|
95
|
+
private _markupIsActive: boolean;
|
|
96
|
+
private _markupMode: MarkupMode;
|
|
97
|
+
private _markupColor: MarkupColor;
|
|
98
|
+
private _konvaStage: Konva.Stage;
|
|
99
|
+
private _konvaLayer: Konva.Layer;
|
|
100
|
+
private _konvaTransformer: Konva.Transformer;
|
|
101
|
+
|
|
102
|
+
private _textInputRef: HTMLTextAreaElement;
|
|
103
|
+
private _textInputPos: Konva.Vector2d;
|
|
104
|
+
private _textInputAngle: number;
|
|
105
|
+
private _markupContainer: HTMLDivElement;
|
|
106
|
+
private _zIndex = 1;
|
|
107
|
+
|
|
108
|
+
private readonly _markupContainerName = "markupContainer";
|
|
109
|
+
|
|
110
|
+
public lineWidth = 4;
|
|
111
|
+
|
|
112
|
+
initialize(viewer: Viewer, canvas: HTMLCanvasElement, canvasEvents: string[] = []): void {
|
|
113
|
+
if (!Konva)
|
|
114
|
+
throw new Error(
|
|
115
|
+
'Konva Markup: Error during Markup Initialization. Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"></script>'
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
this._viewer = viewer;
|
|
119
|
+
|
|
120
|
+
this._canvasOriginal = canvas;
|
|
121
|
+
this._canvasEvents = canvasEvents;
|
|
122
|
+
|
|
123
|
+
this._markupContainer = document.createElement("div");
|
|
124
|
+
this._markupContainer.id = this._markupContainerName;
|
|
125
|
+
this._markupContainer.style.position = "absolute";
|
|
126
|
+
this._markupContainer.style.top = "0px";
|
|
127
|
+
this._markupContainer.style.left = "0px";
|
|
128
|
+
// to eliminate grey box during delete elements
|
|
129
|
+
this._markupContainer.style.outline = "0px";
|
|
130
|
+
|
|
131
|
+
const parentDiv = this._canvasOriginal.parentElement;
|
|
132
|
+
parentDiv.appendChild(this._markupContainer);
|
|
133
|
+
|
|
134
|
+
this._markupColor = new MarkupColor(255, 0, 0);
|
|
135
|
+
this._markupIsActive = false;
|
|
136
|
+
|
|
137
|
+
this.initializeKonva();
|
|
138
|
+
this.resize();
|
|
139
|
+
|
|
140
|
+
this._canvasEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
|
|
141
|
+
|
|
142
|
+
this._viewer.addEventListener("resize", this.resize);
|
|
143
|
+
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
144
|
+
this._viewer.addEventListener("pan", this.pan);
|
|
145
|
+
|
|
146
|
+
this._isInitialized = true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
dispose(): void {
|
|
150
|
+
if (!this._isInitialized) return;
|
|
151
|
+
|
|
152
|
+
this._canvasEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
|
|
153
|
+
|
|
154
|
+
this._viewer.removeEventListener("pan", this.pan);
|
|
155
|
+
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
156
|
+
this._viewer.removeEventListener("resize", this.resize);
|
|
157
|
+
|
|
158
|
+
this.destroyKonva();
|
|
159
|
+
|
|
160
|
+
this._markupContainer.remove();
|
|
161
|
+
|
|
162
|
+
this._markupContainer = undefined;
|
|
163
|
+
this._canvasOriginal = undefined;
|
|
164
|
+
this._viewer = undefined;
|
|
165
|
+
|
|
166
|
+
this._isInitialized = false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
changeActiveDragger = (event: ChangeActiveDraggerEvent) => {
|
|
170
|
+
const draggerName = event.data;
|
|
171
|
+
|
|
172
|
+
this._markupContainer.className = this._canvasOriginal.className
|
|
173
|
+
.split(" ")
|
|
174
|
+
.filter((x) => !x.startsWith("oda-cursor-"))
|
|
175
|
+
.filter((x) => x)
|
|
176
|
+
.concat(`oda-cursor-${draggerName.toLowerCase()}`)
|
|
177
|
+
.join(" ");
|
|
178
|
+
|
|
179
|
+
this.removeTextInput();
|
|
180
|
+
|
|
181
|
+
const markupMode = MarkupMode[draggerName];
|
|
182
|
+
const konvaMode = MarkupMode2Konva.get(markupMode);
|
|
183
|
+
if (konvaMode) {
|
|
184
|
+
this._markupMode = markupMode;
|
|
185
|
+
this._markupIsActive = true;
|
|
186
|
+
} else {
|
|
187
|
+
this._markupIsActive = false;
|
|
188
|
+
this._konvaTransformer.nodes([]);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
resize = () => {
|
|
193
|
+
this._konvaStage?.width(this._canvasOriginal.clientWidth);
|
|
194
|
+
this._konvaStage?.height(this._canvasOriginal.clientHeight);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
pan = (event: PanEvent) => {
|
|
198
|
+
const dX = event.dX / window.devicePixelRatio;
|
|
199
|
+
const dY = event.dY / window.devicePixelRatio;
|
|
200
|
+
|
|
201
|
+
Object.values(MarkupMode).forEach((mode) => this.konvaLayerFind(mode).forEach((x) => x.move({ x: dX, y: dY })));
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
redirectToViewer = (event) => {
|
|
205
|
+
this._viewer.emit(event);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
getDraggers(): Map<string, typeof OdBaseDragger> {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
clearOverlay(): void {
|
|
213
|
+
this.removeTextInput();
|
|
214
|
+
this._konvaTransformer.nodes([]);
|
|
215
|
+
Object.values(MarkupMode).forEach((mode) => this.konvaLayerFind(mode).forEach((x) => x.destroy()));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
getMarkupColor(): { r: number; g: number; b: number } {
|
|
219
|
+
return this._markupColor.RGB;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
setMarkupColor(r: number, g: number, b: number): void {
|
|
223
|
+
this._markupColor.setColor(r, g, b);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
colorizeAllMarkup(r = 255, g = 0, b = 0): void {
|
|
227
|
+
const hex = new MarkupColor(r, g, b).HexColor;
|
|
228
|
+
Object.values(MarkupMode).forEach((mode) => {
|
|
229
|
+
this.konvaLayerFind(mode).forEach((x) => {
|
|
230
|
+
const konvaObj = MarkupMode2Konva.get(mode).initializer(x);
|
|
231
|
+
if (konvaObj.setColor) konvaObj.setColor(hex);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
this._konvaLayer.draw();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
setViewpoint(viewpoint: IViewpoint): void {
|
|
239
|
+
const markupColor = viewpoint.custom_fields.markup_color || { r: 255, g: 0, b: 0 };
|
|
240
|
+
this.setMarkupColor(markupColor.r, markupColor.g, markupColor.b);
|
|
241
|
+
|
|
242
|
+
this.loadMarkup(viewpoint);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getViewpoint(): IViewpoint {
|
|
246
|
+
// TODO: at the current 25.2 state we need VisualizeJS here and below. In the future we need to use it as an external interface.
|
|
247
|
+
if (!this._viewer.visualizeJs) return {};
|
|
248
|
+
|
|
249
|
+
const viewpoint: IViewpoint = {
|
|
250
|
+
lines: [],
|
|
251
|
+
texts: [],
|
|
252
|
+
arrows: [],
|
|
253
|
+
clouds: [],
|
|
254
|
+
ellipses: [],
|
|
255
|
+
images: [],
|
|
256
|
+
rectangles: [],
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
viewpoint.snapshot = {
|
|
260
|
+
data: this.combineMarkupWithDrawing(),
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
viewpoint.custom_fields = {
|
|
264
|
+
markup_color: this.getMarkupColor(),
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
this.fillViewpointShapes(viewpoint);
|
|
268
|
+
|
|
269
|
+
viewpoint.description = new Date().toDateString();
|
|
270
|
+
return viewpoint;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
createObject(type: string, params: any): IMarkupObject {
|
|
274
|
+
let object;
|
|
275
|
+
let zIndex = this._zIndex;
|
|
276
|
+
|
|
277
|
+
// TODO: factory?
|
|
278
|
+
switch (type) {
|
|
279
|
+
case "line":
|
|
280
|
+
object = new KonvaLine(params);
|
|
281
|
+
zIndex = 1;
|
|
282
|
+
break;
|
|
283
|
+
case "text":
|
|
284
|
+
object = new KonvaText(params);
|
|
285
|
+
break;
|
|
286
|
+
case "rectangle":
|
|
287
|
+
object = new KonvaRectangle(params);
|
|
288
|
+
zIndex = 1;
|
|
289
|
+
break;
|
|
290
|
+
case "ellipse":
|
|
291
|
+
object = new KonvaEllipse(params);
|
|
292
|
+
zIndex = 1;
|
|
293
|
+
break;
|
|
294
|
+
case "arrow":
|
|
295
|
+
object = new KonvaArrow(params);
|
|
296
|
+
break;
|
|
297
|
+
case "image":
|
|
298
|
+
object = new KonvaImage(params);
|
|
299
|
+
zIndex = 0;
|
|
300
|
+
break;
|
|
301
|
+
case "cloud":
|
|
302
|
+
object = new KonvaCloud(params);
|
|
303
|
+
zIndex = 1;
|
|
304
|
+
break;
|
|
305
|
+
default:
|
|
306
|
+
throw new Error("Markup CreateObject - unsupported type has been detected.");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this.addObject(object);
|
|
310
|
+
|
|
311
|
+
// Set zIndex only when shape has been added to Layer else we will get "Konva warning: Node has no parent. zIndex parameter is ignored."
|
|
312
|
+
object.setZIndex(zIndex);
|
|
313
|
+
this._zIndex++;
|
|
314
|
+
return object;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
getObjects(): IMarkupObject[] {
|
|
318
|
+
const objects = [];
|
|
319
|
+
this.konvaLayerFind(MarkupMode.Line).forEach((line) => {
|
|
320
|
+
objects.push(new KonvaLine(null, line));
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
this.konvaLayerFind(MarkupMode.Text).forEach((text) => {
|
|
324
|
+
objects.push(new KonvaText(null, text));
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
this.konvaLayerFind(MarkupMode.Rectangle).forEach((rectangle) => {
|
|
328
|
+
objects.push(new KonvaRectangle(null, rectangle));
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse) => {
|
|
332
|
+
objects.push(new KonvaEllipse(null, ellipse));
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow) => {
|
|
336
|
+
objects.push(new KonvaArrow(null, arrow));
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
this.konvaLayerFind(MarkupMode.Image).forEach((image) => {
|
|
340
|
+
objects.push(new KonvaImage(null, image));
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud) => {
|
|
344
|
+
objects.push(new KonvaCloud(null, cloud));
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
return objects;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
getSelectedObjects(): IMarkupObject[] {
|
|
351
|
+
const objects = [];
|
|
352
|
+
|
|
353
|
+
this._konvaTransformer.nodes().forEach((obj) => {
|
|
354
|
+
const konvaShapeName = obj.className;
|
|
355
|
+
switch (konvaShapeName) {
|
|
356
|
+
case "Line":
|
|
357
|
+
objects.push(new KonvaLine(null, obj));
|
|
358
|
+
break;
|
|
359
|
+
case "Text":
|
|
360
|
+
objects.push(new KonvaText(null, obj));
|
|
361
|
+
break;
|
|
362
|
+
case "Rect":
|
|
363
|
+
objects.push(new KonvaRectangle(null, obj));
|
|
364
|
+
break;
|
|
365
|
+
case "Ellipse":
|
|
366
|
+
objects.push(new KonvaEllipse(null, obj));
|
|
367
|
+
break;
|
|
368
|
+
case "Arrow":
|
|
369
|
+
objects.push(new KonvaArrow(null, obj));
|
|
370
|
+
break;
|
|
371
|
+
case "Image":
|
|
372
|
+
objects.push(new KonvaImage(null, obj));
|
|
373
|
+
break;
|
|
374
|
+
case "Cloud":
|
|
375
|
+
objects.push(new KonvaCloud(null, obj));
|
|
376
|
+
break;
|
|
377
|
+
default:
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
return objects;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
selectObjects(objects: IMarkupObject[]) {
|
|
386
|
+
const selectedObjs = this._konvaTransformer.nodes().concat(objects.map((x) => x.ref()));
|
|
387
|
+
this._konvaTransformer.nodes(selectedObjs);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
clearSelected(): void {
|
|
391
|
+
this._konvaTransformer.nodes([]);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
private getPoint3dFromArray(array) {
|
|
395
|
+
return { x: array[0], y: array[1], z: array[2] };
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
private fillViewpointShapes(viewpoint) {
|
|
399
|
+
const markupLines = this.getMarkupLines();
|
|
400
|
+
if (markupLines && markupLines.length > 0) {
|
|
401
|
+
markupLines?.forEach((line) => {
|
|
402
|
+
viewpoint.lines.push(line);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const markupTexts = this.getMarkupTexts();
|
|
407
|
+
if (markupTexts && markupTexts.length > 0) {
|
|
408
|
+
markupTexts?.forEach((text) => {
|
|
409
|
+
viewpoint.texts.push(text);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const markupRectangles = this.getMarkupRectangles();
|
|
414
|
+
if (markupRectangles && markupRectangles.length > 0) {
|
|
415
|
+
markupRectangles?.forEach((rectangle) => {
|
|
416
|
+
viewpoint.rectangles.push(rectangle);
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const markupEllipses = this.getMarkupEllipses();
|
|
421
|
+
if (markupEllipses && markupEllipses.length > 0) {
|
|
422
|
+
markupEllipses?.forEach((ellipse) => {
|
|
423
|
+
viewpoint.ellipses.push(ellipse);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const markupArrows = this.getMarkupArrows();
|
|
428
|
+
if (markupArrows && markupArrows.length > 0) {
|
|
429
|
+
markupArrows?.forEach((arrow) => {
|
|
430
|
+
viewpoint.arrows.push(arrow);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
const markupImages = this.getMarkupImages();
|
|
435
|
+
if (markupImages && markupImages.length > 0) {
|
|
436
|
+
markupImages?.forEach((image) => {
|
|
437
|
+
viewpoint.images.push(image);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const markupClouds = this.getMarkupClouds();
|
|
442
|
+
if (markupClouds && markupClouds.length > 0) {
|
|
443
|
+
markupClouds?.forEach((cloud) => {
|
|
444
|
+
viewpoint.clouds.push(cloud);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
private addObject(object: IMarkupObject): void {
|
|
450
|
+
this._konvaLayer.add(object.ref());
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
private konvaLayerFind(markupShape: MarkupMode): any {
|
|
454
|
+
const konvaShape = MarkupMode2Konva.get(markupShape);
|
|
455
|
+
if (konvaShape) {
|
|
456
|
+
// for "draggable" Konva uses Rectangles in Transformer. We need only Shapes from Layer.
|
|
457
|
+
const konvaShapes = this._konvaLayer.find(konvaShape.name).filter((x) => x.parent instanceof Konva.Layer);
|
|
458
|
+
return konvaShapes;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
private initializeKonva(): any {
|
|
463
|
+
// first we need Konva core things: stage and layer
|
|
464
|
+
this._konvaStage = new Konva.Stage({
|
|
465
|
+
container: this._markupContainerName,
|
|
466
|
+
width: this._canvasOriginal.clientWidth,
|
|
467
|
+
height: this._canvasOriginal.clientHeight,
|
|
468
|
+
});
|
|
469
|
+
const stage = this._konvaStage;
|
|
470
|
+
const layer = new Konva.Layer({ pixelRation: window.devicePixelRatio });
|
|
471
|
+
stage.add(layer);
|
|
472
|
+
this._konvaLayer = layer;
|
|
473
|
+
|
|
474
|
+
const transformer = new Konva.Transformer({
|
|
475
|
+
shouldOverdrawWholeArea: false,
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
this._konvaTransformer = transformer;
|
|
479
|
+
layer.add(transformer);
|
|
480
|
+
|
|
481
|
+
let isPaint = false;
|
|
482
|
+
let lastLine;
|
|
483
|
+
|
|
484
|
+
stage.on("mousedown touchstart", (e) => {
|
|
485
|
+
// do nothing if we mousedown on any shape
|
|
486
|
+
if (!this._markupIsActive || e.target !== stage || this._markupMode === MarkupMode.Text) return;
|
|
487
|
+
|
|
488
|
+
if (e.target === stage && transformer.nodes().length > 0) {
|
|
489
|
+
transformer.nodes([]);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const pos = stage.getPointerPosition();
|
|
494
|
+
|
|
495
|
+
if (this._markupMode === MarkupMode.Line) {
|
|
496
|
+
// add point twice, so we have some drawings even on a simple click
|
|
497
|
+
lastLine = this.addLine([pos.x, pos.y, pos.x, pos.y]);
|
|
498
|
+
|
|
499
|
+
isPaint = true;
|
|
500
|
+
}
|
|
501
|
+
// 25.2 - currently only for debug purposes:
|
|
502
|
+
else if (this._markupMode === MarkupMode.Rectangle) {
|
|
503
|
+
this.addRectangle({ x: pos.x, y: pos.y }, 50, 50);
|
|
504
|
+
} else if (this._markupMode === MarkupMode.Ellipse) {
|
|
505
|
+
this.addEllipse({ x: pos.x, y: pos.y }, { x: 50, y: 50 });
|
|
506
|
+
} else if (this._markupMode === MarkupMode.Arrow) {
|
|
507
|
+
this.addArrow({ x: pos.x, y: pos.y }, { x: pos.x + 50, y: pos.y + 50 });
|
|
508
|
+
} else if (this._markupMode === MarkupMode.Cloud) {
|
|
509
|
+
this.addCloud({ x: pos.x, y: pos.y }, 200, 400);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
stage.on("mouseup touchend", (e) => {
|
|
514
|
+
if (!this._markupIsActive) return;
|
|
515
|
+
isPaint = false;
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
stage.on("mousemove touchmove", (e) => {
|
|
519
|
+
if (!this._markupIsActive) return;
|
|
520
|
+
if (!isPaint) {
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// prevent scrolling on touch devices
|
|
525
|
+
//e.evt.preventDefault();
|
|
526
|
+
|
|
527
|
+
const pos = stage.getPointerPosition();
|
|
528
|
+
const newPoints = lastLine.points().concat([pos.x, pos.y]);
|
|
529
|
+
lastLine.points(newPoints);
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
// clicks should select/deselect shapes
|
|
533
|
+
stage.on("click tap", (e) => {
|
|
534
|
+
if (!this._markupIsActive) return;
|
|
535
|
+
|
|
536
|
+
// if click on empty area - remove all selections
|
|
537
|
+
if (e.target === stage) {
|
|
538
|
+
if (this._markupMode === MarkupMode.Text) {
|
|
539
|
+
if (this._textInputRef) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
|
|
540
|
+
else if (transformer.nodes().length === 0) {
|
|
541
|
+
const pos = stage.getPointerPosition();
|
|
542
|
+
this.createTextInput(pos, e.evt.pageX, e.evt.pageY, 0, null);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
transformer.nodes([]);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
if (e.target.className === "Text" && transformer.nodes().length === 1 && transformer.nodes()[0] === e.target) {
|
|
550
|
+
if (this._textInputRef) this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
|
|
551
|
+
else
|
|
552
|
+
this.createTextInput(
|
|
553
|
+
{ x: e.target.attrs.x, y: e.target.attrs.y },
|
|
554
|
+
e.evt.pageX,
|
|
555
|
+
e.evt.pageY,
|
|
556
|
+
e.target.attrs.rotation,
|
|
557
|
+
e.target.attrs.text
|
|
558
|
+
);
|
|
559
|
+
return;
|
|
560
|
+
} else {
|
|
561
|
+
this.removeTextInput();
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
if (transformer.nodes().filter((x) => x.className === "Cloud").length > 0 || e.target.className === "Cloud") {
|
|
565
|
+
transformer.rotateEnabled(false);
|
|
566
|
+
} else {
|
|
567
|
+
transformer.rotateEnabled(true);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// do we pressed shift or ctrl?
|
|
571
|
+
const metaPressed = e.evt.shiftKey || e.evt.ctrlKey || e.evt.metaKey;
|
|
572
|
+
const isSelected = transformer.nodes().indexOf(e.target) >= 0;
|
|
573
|
+
|
|
574
|
+
if (!metaPressed && !isSelected) {
|
|
575
|
+
// if no key pressed and the node is not selected
|
|
576
|
+
// select just one
|
|
577
|
+
transformer.nodes([e.target]);
|
|
578
|
+
} else if (metaPressed && isSelected) {
|
|
579
|
+
// if we pressed keys and node was selected
|
|
580
|
+
// we need to remove it from selection:
|
|
581
|
+
const nodes = transformer.nodes().slice(); // use slice to have new copy of array
|
|
582
|
+
// remove node from array
|
|
583
|
+
nodes.splice(nodes.indexOf(e.target), 1);
|
|
584
|
+
transformer.nodes(nodes);
|
|
585
|
+
} else if (metaPressed && !isSelected) {
|
|
586
|
+
// add the node into selection
|
|
587
|
+
const nodes = transformer.nodes().concat([e.target]);
|
|
588
|
+
transformer.nodes(nodes);
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
const container = stage.container();
|
|
593
|
+
container.tabIndex = 1;
|
|
594
|
+
// focus it
|
|
595
|
+
// also stage will be in focus on its click
|
|
596
|
+
container.focus();
|
|
597
|
+
|
|
598
|
+
container.addEventListener("keydown", (e) => {
|
|
599
|
+
if (!this._markupIsActive) return;
|
|
600
|
+
if (e.code === "Delete") {
|
|
601
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
602
|
+
if (trNodes.length > 0) {
|
|
603
|
+
this._konvaTransformer.nodes().forEach((x) => x.destroy());
|
|
604
|
+
this._konvaTransformer.nodes([]);
|
|
605
|
+
}
|
|
606
|
+
layer.draw();
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
e.preventDefault();
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
private destroyKonva() {
|
|
614
|
+
this.clearOverlay();
|
|
615
|
+
|
|
616
|
+
this._konvaStage.destroy();
|
|
617
|
+
|
|
618
|
+
this._konvaLayer = undefined;
|
|
619
|
+
this._konvaTransformer = undefined;
|
|
620
|
+
this._konvaStage = undefined;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
private getMarkupLines() {
|
|
624
|
+
const lines = [];
|
|
625
|
+
this.konvaLayerFind(MarkupMode.Line).forEach((line) => {
|
|
626
|
+
const linePoints = line.points();
|
|
627
|
+
if (!linePoints) return;
|
|
628
|
+
const worldPoints = [];
|
|
629
|
+
const absoluteTransform = line.getAbsoluteTransform();
|
|
630
|
+
for (let i = 0; i < linePoints.length; i += 2) {
|
|
631
|
+
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
632
|
+
// https://stackoverflow.com/a/57641487 - check answer's comments
|
|
633
|
+
const atPoint = absoluteTransform.point({ x: linePoints[i], y: linePoints[i + 1] });
|
|
634
|
+
const worldPoint = this._viewer
|
|
635
|
+
.visViewer()
|
|
636
|
+
.screenToWorld(atPoint.x * window.devicePixelRatio, atPoint.y * window.devicePixelRatio);
|
|
637
|
+
worldPoints.push(worldPoint);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const konvaLine = new KonvaLine(null, line);
|
|
641
|
+
lines.push({
|
|
642
|
+
id: konvaLine.id(),
|
|
643
|
+
points: worldPoints.map((p) => this.getPoint3dFromArray(p)),
|
|
644
|
+
color: konvaLine.getColor() || "ff0000",
|
|
645
|
+
type: konvaLine.getLineType() || "solid",
|
|
646
|
+
width: konvaLine.getLineWidth() || 3,
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
return lines;
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
private getMarkupTexts() {
|
|
654
|
+
const texts = [];
|
|
655
|
+
|
|
656
|
+
const textSize = 0.02;
|
|
657
|
+
let textScale = 1.0;
|
|
658
|
+
|
|
659
|
+
const projMtrx = this._viewer.visViewer().activeView.projectionMatrix;
|
|
660
|
+
const mtrxNumber = projMtrx.get(1, 1);
|
|
661
|
+
const tol = 1.0e-6;
|
|
662
|
+
if (mtrxNumber > tol || mtrxNumber < -tol) {
|
|
663
|
+
textScale = 1 / mtrxNumber;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
this.konvaLayerFind(MarkupMode.Text).forEach((text) => {
|
|
667
|
+
if (!text) return;
|
|
668
|
+
|
|
669
|
+
const position = this._viewer
|
|
670
|
+
.visViewer()
|
|
671
|
+
.screenToWorld(text.x() * window.devicePixelRatio, text.y() * window.devicePixelRatio);
|
|
672
|
+
|
|
673
|
+
const shape = new KonvaText(null, text);
|
|
674
|
+
texts.push({
|
|
675
|
+
id: shape.id(),
|
|
676
|
+
position: this.getPoint3dFromArray(position),
|
|
677
|
+
text: shape.getText(),
|
|
678
|
+
text_size: textSize * textScale,
|
|
679
|
+
angle: shape.getRotation(),
|
|
680
|
+
color: shape.getColor(),
|
|
681
|
+
font_size: shape.getFontSize(),
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
return texts;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
private getMarkupRectangles() {
|
|
689
|
+
const rectangles = [];
|
|
690
|
+
this.konvaLayerFind(MarkupMode.Rectangle).forEach((rect) => {
|
|
691
|
+
const position = rect.position();
|
|
692
|
+
const worldPoint = this._viewer
|
|
693
|
+
.visViewer()
|
|
694
|
+
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
695
|
+
|
|
696
|
+
const shape = new KonvaRectangle(null, rect);
|
|
697
|
+
rectangles.push({
|
|
698
|
+
id: shape.id(),
|
|
699
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
700
|
+
width: shape.getWidth(),
|
|
701
|
+
height: shape.getHeigth(),
|
|
702
|
+
line_width: shape.getLineWidth(),
|
|
703
|
+
color: shape.getColor(),
|
|
704
|
+
});
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
return rectangles;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
private getMarkupEllipses() {
|
|
711
|
+
const ellipses = [];
|
|
712
|
+
this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse) => {
|
|
713
|
+
const position = ellipse.position();
|
|
714
|
+
const worldPoint = this._viewer
|
|
715
|
+
.visViewer()
|
|
716
|
+
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
717
|
+
|
|
718
|
+
const shape = new KonvaEllipse(null, ellipse);
|
|
719
|
+
ellipses.push({
|
|
720
|
+
id: shape.id(),
|
|
721
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
722
|
+
radius: { x: ellipse.getRadiusX(), y: ellipse.getRadiusY() },
|
|
723
|
+
line_width: shape.getLineWidth(),
|
|
724
|
+
color: shape.getColor(),
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
return ellipses;
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
private getMarkupArrows() {
|
|
732
|
+
const arrows = [];
|
|
733
|
+
this.konvaLayerFind(MarkupMode.Arrow).forEach((arrow) => {
|
|
734
|
+
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
735
|
+
const absoluteTransform = arrow.getAbsoluteTransform();
|
|
736
|
+
|
|
737
|
+
const atStartPoint = absoluteTransform.point({ x: arrow.points()[0], y: arrow.points()[1] });
|
|
738
|
+
const worldStartPoint = this._viewer
|
|
739
|
+
.visViewer()
|
|
740
|
+
.screenToWorld(atStartPoint.x * window.devicePixelRatio, atStartPoint.y * window.devicePixelRatio);
|
|
741
|
+
|
|
742
|
+
const atEndPoint = absoluteTransform.point({ x: arrow.points()[2], y: arrow.points()[3] });
|
|
743
|
+
const worldEndPoint = this._viewer
|
|
744
|
+
.visViewer()
|
|
745
|
+
.screenToWorld(atEndPoint.x * window.devicePixelRatio, atEndPoint.y * window.devicePixelRatio);
|
|
746
|
+
|
|
747
|
+
const shape = new KonvaArrow(null, arrow);
|
|
748
|
+
arrows.push({
|
|
749
|
+
id: shape.id(),
|
|
750
|
+
start: this.getPoint3dFromArray(worldStartPoint),
|
|
751
|
+
end: this.getPoint3dFromArray(worldEndPoint),
|
|
752
|
+
color: shape.getColor(),
|
|
753
|
+
});
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
return arrows;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
private getMarkupImages() {
|
|
760
|
+
const images = [];
|
|
761
|
+
this.konvaLayerFind(MarkupMode.Image).forEach((image) => {
|
|
762
|
+
const position = image.position();
|
|
763
|
+
const worldPoint = this._viewer
|
|
764
|
+
.visViewer()
|
|
765
|
+
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
766
|
+
|
|
767
|
+
const shape = new KonvaImage(null, image);
|
|
768
|
+
images.push({
|
|
769
|
+
id: shape.id(),
|
|
770
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
771
|
+
src: shape.getSrc(),
|
|
772
|
+
width: shape.getWidth(),
|
|
773
|
+
height: shape.getHeight(),
|
|
774
|
+
});
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
return images;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
private getMarkupClouds() {
|
|
781
|
+
const clouds = [];
|
|
782
|
+
this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud) => {
|
|
783
|
+
const position = cloud.position();
|
|
784
|
+
const worldPoint = this._viewer
|
|
785
|
+
.visViewer()
|
|
786
|
+
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
787
|
+
|
|
788
|
+
const shape = new KonvaCloud(null, cloud);
|
|
789
|
+
clouds.push({
|
|
790
|
+
id: shape.id(),
|
|
791
|
+
position: this.getPoint3dFromArray(worldPoint),
|
|
792
|
+
width: shape.getWidth(),
|
|
793
|
+
height: shape.getHeigth(),
|
|
794
|
+
line_width: shape.getLineWidth(),
|
|
795
|
+
color: shape.getColor(),
|
|
796
|
+
});
|
|
797
|
+
});
|
|
798
|
+
|
|
799
|
+
return clouds;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
private loadMarkup(viewpoint: IViewpoint) {
|
|
803
|
+
viewpoint.lines?.forEach((vpLine) => {
|
|
804
|
+
const linePoints = [];
|
|
805
|
+
vpLine.points.forEach((point) => {
|
|
806
|
+
const screenPoint = utils.worldToScreen(
|
|
807
|
+
[point.x, point.y, point.z],
|
|
808
|
+
this._viewer.visualizeJs,
|
|
809
|
+
this._viewer.visViewer()
|
|
810
|
+
);
|
|
811
|
+
linePoints.push(screenPoint.x);
|
|
812
|
+
linePoints.push(screenPoint.y);
|
|
813
|
+
});
|
|
814
|
+
|
|
815
|
+
this.addLine(linePoints, vpLine.color, vpLine.type, vpLine.width, vpLine.id);
|
|
816
|
+
});
|
|
817
|
+
|
|
818
|
+
viewpoint.texts?.forEach((vpText) => {
|
|
819
|
+
const screenPoint = utils.worldToScreen(
|
|
820
|
+
[vpText.position.x, vpText.position.y, vpText.position.z],
|
|
821
|
+
this._viewer.visualizeJs,
|
|
822
|
+
this._viewer.visViewer()
|
|
823
|
+
);
|
|
824
|
+
this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
viewpoint.rectangles?.forEach((vpRect) => {
|
|
828
|
+
const screenPoint = utils.worldToScreen(
|
|
829
|
+
[vpRect.position.x, vpRect.position.y, vpRect.position.z],
|
|
830
|
+
this._viewer.visualizeJs,
|
|
831
|
+
this._viewer.visViewer()
|
|
832
|
+
);
|
|
833
|
+
|
|
834
|
+
this.addRectangle(
|
|
835
|
+
{ x: screenPoint.x, y: screenPoint.y },
|
|
836
|
+
vpRect.width,
|
|
837
|
+
vpRect.height,
|
|
838
|
+
vpRect.line_width,
|
|
839
|
+
vpRect.color,
|
|
840
|
+
vpRect.id
|
|
841
|
+
);
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
viewpoint.ellipses?.forEach((vpEllipse) => {
|
|
845
|
+
const screenPoint = utils.worldToScreen(
|
|
846
|
+
[vpEllipse.position.x, vpEllipse.position.y, vpEllipse.position.z],
|
|
847
|
+
this._viewer.visualizeJs,
|
|
848
|
+
this._viewer.visViewer()
|
|
849
|
+
);
|
|
850
|
+
|
|
851
|
+
this.addEllipse(
|
|
852
|
+
{ x: screenPoint.x, y: screenPoint.y },
|
|
853
|
+
{ x: vpEllipse.radius.x, y: vpEllipse.radius.y },
|
|
854
|
+
vpEllipse.line_width,
|
|
855
|
+
vpEllipse.color,
|
|
856
|
+
vpEllipse.id
|
|
857
|
+
);
|
|
858
|
+
});
|
|
859
|
+
|
|
860
|
+
viewpoint.arrows?.forEach((vpArrow) => {
|
|
861
|
+
const startPoint = utils.worldToScreen(
|
|
862
|
+
[vpArrow.start.x, vpArrow.start.y, vpArrow.start.z],
|
|
863
|
+
this._viewer.visualizeJs,
|
|
864
|
+
this._viewer.visViewer()
|
|
865
|
+
);
|
|
866
|
+
|
|
867
|
+
const endPoint = utils.worldToScreen(
|
|
868
|
+
[vpArrow.end.x, vpArrow.end.y, vpArrow.end.z],
|
|
869
|
+
this._viewer.visualizeJs,
|
|
870
|
+
this._viewer.visViewer()
|
|
871
|
+
);
|
|
872
|
+
|
|
873
|
+
this.addArrow({ x: startPoint.x, y: startPoint.y }, { x: endPoint.x, y: endPoint.y }, vpArrow.color, vpArrow.id);
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
viewpoint.clouds?.forEach((vpCloud) => {
|
|
877
|
+
const screenPoint = utils.worldToScreen(
|
|
878
|
+
[vpCloud.position.x, vpCloud.position.y, vpCloud.position.z],
|
|
879
|
+
this._viewer.visualizeJs,
|
|
880
|
+
this._viewer.visViewer()
|
|
881
|
+
);
|
|
882
|
+
|
|
883
|
+
this.addCloud(
|
|
884
|
+
{ x: screenPoint.x, y: screenPoint.y },
|
|
885
|
+
vpCloud.width,
|
|
886
|
+
vpCloud.height,
|
|
887
|
+
vpCloud.line_width,
|
|
888
|
+
vpCloud.color,
|
|
889
|
+
vpCloud.id
|
|
890
|
+
);
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
viewpoint.images?.forEach((vpImage) => {
|
|
894
|
+
const screenPoint = utils.worldToScreen(
|
|
895
|
+
[vpImage.position.x, vpImage.position.y, vpImage.position.z],
|
|
896
|
+
this._viewer.visualizeJs,
|
|
897
|
+
this._viewer.visViewer()
|
|
898
|
+
);
|
|
899
|
+
|
|
900
|
+
this.addImage({ x: screenPoint.x, y: screenPoint.y }, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
private combineMarkupWithDrawing() {
|
|
905
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
906
|
+
if (trNodes.length > 0) {
|
|
907
|
+
this._konvaTransformer.nodes([]);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
const tempCanvas = document.createElement("canvas");
|
|
911
|
+
tempCanvas.height = this._canvasOriginal.height;
|
|
912
|
+
tempCanvas.width = this._canvasOriginal.width;
|
|
913
|
+
const ctx = tempCanvas.getContext("2d");
|
|
914
|
+
ctx.drawImage(this._canvasOriginal, 0, 0);
|
|
915
|
+
ctx.drawImage(this._konvaStage.toCanvas({ pixelRatio: window.devicePixelRatio }), 0, 0);
|
|
916
|
+
return tempCanvas.toDataURL("image/jpeg", 0.25);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
private addLine(
|
|
920
|
+
linePoints: number[],
|
|
921
|
+
color?: string,
|
|
922
|
+
type?: LineType,
|
|
923
|
+
width?: number,
|
|
924
|
+
id?: string
|
|
925
|
+
): Konva.Line | void {
|
|
926
|
+
if (!linePoints || linePoints.length === 0) return;
|
|
927
|
+
const points: { x: number; y: number }[] = [];
|
|
928
|
+
for (let i = 0; i < linePoints.length; i += 2) {
|
|
929
|
+
points.push({ x: linePoints[i], y: linePoints[i + 1] });
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
const konvaLine = new KonvaLine({
|
|
933
|
+
points,
|
|
934
|
+
type: type || "solid",
|
|
935
|
+
width: width || this.lineWidth,
|
|
936
|
+
color: color || this._markupColor.HexColor,
|
|
937
|
+
id,
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
const obj = konvaLine.ref();
|
|
941
|
+
this._konvaLayer.add(obj);
|
|
942
|
+
return obj;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
private createTextInput(pos: Konva.Vector2d, inputX: number, inputY: number, angle: number, text: string): void {
|
|
946
|
+
if (!this._textInputRef) {
|
|
947
|
+
this._textInputPos = pos;
|
|
948
|
+
this._textInputAngle = angle;
|
|
949
|
+
this._textInputRef = document.createElement("textarea");
|
|
950
|
+
this._textInputRef.style.zIndex = "9999";
|
|
951
|
+
this._textInputRef.style.position = "absolute";
|
|
952
|
+
this._textInputRef.style.display = "block";
|
|
953
|
+
this._textInputRef.style.top = inputY + "px";
|
|
954
|
+
this._textInputRef.style.left = inputX + "px";
|
|
955
|
+
this._textInputRef.onkeydown = (event) => {
|
|
956
|
+
if (event.key === "Enter") {
|
|
957
|
+
event.preventDefault();
|
|
958
|
+
this.addText(this._textInputRef.value, this._textInputPos, this._textInputAngle);
|
|
959
|
+
}
|
|
960
|
+
if (event.key === "Escape") {
|
|
961
|
+
event.preventDefault();
|
|
962
|
+
this.removeTextInput();
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
if (text) this._textInputRef.value = text;
|
|
966
|
+
document.body.appendChild(this._textInputRef);
|
|
967
|
+
|
|
968
|
+
setTimeout(() => {
|
|
969
|
+
this._textInputRef.focus();
|
|
970
|
+
}, 50);
|
|
971
|
+
} else {
|
|
972
|
+
this.removeTextInput();
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
private removeTextInput(): void {
|
|
977
|
+
this._textInputRef?.remove();
|
|
978
|
+
this._textInputRef = null;
|
|
979
|
+
this._textInputPos = null;
|
|
980
|
+
this._textInputAngle = 0;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
private addText(
|
|
984
|
+
specifiedText: string,
|
|
985
|
+
position: Konva.Vector2d,
|
|
986
|
+
angle?: number,
|
|
987
|
+
color?: string,
|
|
988
|
+
textSize?: number,
|
|
989
|
+
fontSize?: number,
|
|
990
|
+
id?: string
|
|
991
|
+
): void {
|
|
992
|
+
if (specifiedText) {
|
|
993
|
+
const tol = 1.0e-6;
|
|
994
|
+
|
|
995
|
+
// in case we have old viewpoint without font_size
|
|
996
|
+
if (textSize && textSize > tol && (!fontSize || fontSize < tol)) {
|
|
997
|
+
const size = 0.02;
|
|
998
|
+
let scale = 1.0;
|
|
999
|
+
|
|
1000
|
+
const projMtrx = this._viewer.visViewer().activeView.projectionMatrix;
|
|
1001
|
+
const mtrxNumber = projMtrx.get(1, 1);
|
|
1002
|
+
|
|
1003
|
+
if (mtrxNumber > tol || mtrxNumber < -tol) {
|
|
1004
|
+
scale = 1 / mtrxNumber;
|
|
1005
|
+
}
|
|
1006
|
+
fontSize = textSize / (scale / size) / 34;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
const konvaText = new KonvaText({
|
|
1010
|
+
position: { x: position.x, y: position.y },
|
|
1011
|
+
text: specifiedText,
|
|
1012
|
+
rotation: angle,
|
|
1013
|
+
fontSize,
|
|
1014
|
+
color: color || this._markupColor.HexColor,
|
|
1015
|
+
id,
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
this._konvaLayer.add(konvaText.ref());
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
1022
|
+
if (trNodes.length > 0) {
|
|
1023
|
+
// in case of edit - remove old Konva.Text object
|
|
1024
|
+
trNodes[0].destroy();
|
|
1025
|
+
this._konvaTransformer.nodes([]);
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
this.removeTextInput();
|
|
1029
|
+
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
private addRectangle(
|
|
1034
|
+
position: Konva.Vector2d,
|
|
1035
|
+
width: number,
|
|
1036
|
+
height: number,
|
|
1037
|
+
lineWidth?: number,
|
|
1038
|
+
color?: string,
|
|
1039
|
+
id?: string
|
|
1040
|
+
): Konva.Rect | void {
|
|
1041
|
+
if (!position) return;
|
|
1042
|
+
|
|
1043
|
+
const konvaRectangle = new KonvaRectangle({
|
|
1044
|
+
position,
|
|
1045
|
+
width,
|
|
1046
|
+
height,
|
|
1047
|
+
lineWidth: lineWidth || this.lineWidth,
|
|
1048
|
+
color: color || this._markupColor.HexColor,
|
|
1049
|
+
id,
|
|
1050
|
+
});
|
|
1051
|
+
|
|
1052
|
+
const obj = konvaRectangle.ref();
|
|
1053
|
+
this._konvaLayer.add(obj);
|
|
1054
|
+
return obj;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
private addEllipse(
|
|
1058
|
+
position: { x: number; y: number },
|
|
1059
|
+
radius: { x: number; y: number },
|
|
1060
|
+
lineWidth?: number,
|
|
1061
|
+
color?: string,
|
|
1062
|
+
id?: string
|
|
1063
|
+
): Konva.Ellipse | void {
|
|
1064
|
+
if (!position) return;
|
|
1065
|
+
|
|
1066
|
+
const konvaEllipse = new KonvaEllipse({
|
|
1067
|
+
position,
|
|
1068
|
+
radius,
|
|
1069
|
+
lineWidth,
|
|
1070
|
+
color: color || this._markupColor.HexColor,
|
|
1071
|
+
id,
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
const obj = konvaEllipse.ref();
|
|
1075
|
+
this._konvaLayer.add(obj);
|
|
1076
|
+
return obj;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
private addArrow(
|
|
1080
|
+
start: { x: number; y: number },
|
|
1081
|
+
end: { x: number; y: number },
|
|
1082
|
+
color?: string,
|
|
1083
|
+
id?: string
|
|
1084
|
+
): Konva.Arrow | void {
|
|
1085
|
+
if (!start || !end) return;
|
|
1086
|
+
|
|
1087
|
+
const konvaArrow = new KonvaArrow({
|
|
1088
|
+
start,
|
|
1089
|
+
end,
|
|
1090
|
+
color: color || this._markupColor.HexColor,
|
|
1091
|
+
id,
|
|
1092
|
+
});
|
|
1093
|
+
|
|
1094
|
+
const obj = konvaArrow.ref();
|
|
1095
|
+
this._konvaLayer.add(obj);
|
|
1096
|
+
return obj;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
private addCloud(
|
|
1100
|
+
position: { x: number; y: number },
|
|
1101
|
+
width: number,
|
|
1102
|
+
height: number,
|
|
1103
|
+
lineWidth?: number,
|
|
1104
|
+
color?: string,
|
|
1105
|
+
id?: string
|
|
1106
|
+
): Konva.Shape | void {
|
|
1107
|
+
if (!position || !width || !height) return;
|
|
1108
|
+
|
|
1109
|
+
const konvaCloud = new KonvaCloud({
|
|
1110
|
+
position,
|
|
1111
|
+
width,
|
|
1112
|
+
height,
|
|
1113
|
+
color: color || this._markupColor.HexColor,
|
|
1114
|
+
lineWidth: lineWidth || this.lineWidth,
|
|
1115
|
+
id,
|
|
1116
|
+
});
|
|
1117
|
+
|
|
1118
|
+
const obj = konvaCloud.ref();
|
|
1119
|
+
this._konvaLayer.add(obj);
|
|
1120
|
+
return obj;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
private addImage(
|
|
1124
|
+
position: { x: number; y: number },
|
|
1125
|
+
src: string,
|
|
1126
|
+
width: number,
|
|
1127
|
+
height: number,
|
|
1128
|
+
id?: string
|
|
1129
|
+
): Konva.Image | void {
|
|
1130
|
+
if (!position || !width || !height) return;
|
|
1131
|
+
|
|
1132
|
+
const konvaImage = new KonvaImage({
|
|
1133
|
+
position,
|
|
1134
|
+
src,
|
|
1135
|
+
width,
|
|
1136
|
+
height,
|
|
1137
|
+
id,
|
|
1138
|
+
});
|
|
1139
|
+
|
|
1140
|
+
const obj = konvaImage.ref();
|
|
1141
|
+
this._konvaLayer.add(obj);
|
|
1142
|
+
return obj;
|
|
1143
|
+
}
|
|
1144
|
+
}
|