@inweb/viewer-visualize 25.6.7 → 25.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/dist/viewer-visualize.js +330 -295
- package/dist/viewer-visualize.js.map +1 -1
- package/dist/viewer-visualize.min.js +1 -1
- package/dist/viewer-visualize.module.js +164 -149
- package/dist/viewer-visualize.module.js.map +1 -1
- package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +4 -0
- package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +2 -3
- package/lib/Viewer/Markup/IMarkup.d.ts +28 -32
- package/lib/Viewer/Markup/IWorldTransform.d.ts +39 -0
- package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +11 -6
- package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +3 -0
- package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +4 -4
- package/lib/Viewer/Markup/MarkupFactory.d.ts +10 -10
- package/lib/Viewer/Viewer.d.ts +60 -42
- package/lib/index.d.ts +12 -0
- package/package.json +5 -5
- package/src/Viewer/Commands/ApplyModelTransform.ts +2 -2
- package/src/Viewer/Commands/ClearMarkup.ts +2 -2
- package/src/Viewer/Commands/ClearSlices.ts +2 -2
- package/src/Viewer/Commands/CreatePreview.ts +2 -2
- package/src/Viewer/Commands/Explode.ts +2 -2
- package/src/Viewer/Commands/GetDefaultViewPositions.ts +2 -2
- package/src/Viewer/Commands/GetModels.ts +2 -2
- package/src/Viewer/Commands/GetSelected.ts +2 -2
- package/src/Viewer/Commands/HideSelected.ts +2 -2
- package/src/Viewer/Commands/IsolateSelected.ts +2 -2
- package/src/Viewer/Commands/RegenerateAll.ts +2 -2
- package/src/Viewer/Commands/ResetView.ts +2 -2
- package/src/Viewer/Commands/SelectModel.ts +2 -2
- package/src/Viewer/Commands/SetActiveDragger.ts +2 -2
- package/src/Viewer/Commands/SetDefaultViewPosition.ts +2 -2
- package/src/Viewer/Commands/SetMarkupColor.ts +2 -2
- package/src/Viewer/Commands/SetSelected.ts +2 -2
- package/src/Viewer/Commands/ShowAll.ts +2 -2
- package/src/Viewer/Commands/Unselect.ts +2 -2
- package/src/Viewer/Commands/ZoomToExtents.ts +2 -2
- package/src/Viewer/Commands/ZoomToObjects.ts +2 -2
- package/src/Viewer/Commands/ZoomToSelected.ts +2 -2
- package/src/Viewer/Commands/index.ts +2 -2
- package/src/Viewer/Draggers/Actions/OrbitAction.ts +2 -2
- package/src/Viewer/Draggers/Actions/PanAction.ts +2 -2
- package/src/Viewer/Draggers/Actions/ZoomAction.ts +2 -2
- package/src/Viewer/Draggers/Common/Geometry.ts +2 -2
- package/src/Viewer/Draggers/Common/GestureManager.ts +2 -2
- package/src/Viewer/Draggers/Common/OdBaseDragger.ts +2 -2
- package/src/Viewer/Draggers/Common/OdaGeAction.ts +2 -2
- package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +2 -2
- package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +2 -2
- package/src/Viewer/Draggers/MeasureLineDragger/index.ts +2 -2
- package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +2 -2
- package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +2 -2
- package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +2 -2
- package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +2 -2
- package/src/Viewer/Draggers/OdOrbitDragger.ts +2 -2
- package/src/Viewer/Draggers/OdPanDragger.ts +2 -2
- package/src/Viewer/Draggers/OdZoomDragger.ts +2 -2
- package/src/Viewer/Draggers/OdZoomWheelDragger.ts +2 -2
- package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +2 -2
- package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +2 -2
- package/src/Viewer/Draggers/OdaLineDragger.ts +2 -2
- package/src/Viewer/Draggers/OdaTextDragger.ts +2 -2
- package/src/Viewer/Draggers/OdaWalkDragger.ts +2 -2
- package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +2 -2
- package/src/Viewer/Loaders/BaseLoader.ts +2 -2
- package/src/Viewer/Loaders/LoaderFactory.ts +2 -2
- package/src/Viewer/Loaders/TCSLoader.ts +2 -2
- package/src/Viewer/Loaders/VsfXLoader.ts +2 -2
- package/src/Viewer/Loaders/VsfXPartialLoader.ts +2 -2
- package/src/Viewer/Loaders/VsfXStreamingLoader.ts +2 -2
- package/src/Viewer/Markup/Api/IMarkupLine.ts +5 -0
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +1 -1
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +1 -1
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +1 -1
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +4 -5
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +1 -1
- package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +1 -1
- package/src/Viewer/Markup/IMarkup.ts +34 -35
- package/src/Viewer/Markup/IWorldTransform.ts +46 -0
- package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +85 -161
- package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +3 -0
- package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +45 -10
- package/src/Viewer/Markup/MarkupFactory.ts +16 -20
- package/src/Viewer/Viewer.ts +103 -95
- package/src/Viewer/utils.ts +2 -2
- package/src/index.ts +14 -2
|
@@ -22,13 +22,12 @@
|
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
24
|
import Konva from "konva";
|
|
25
|
-
import {
|
|
25
|
+
import { IEventEmitter } from "@inweb/eventemitter2";
|
|
26
|
+
import { ChangeActiveDraggerEvent, IViewpoint, PanEvent } from "@inweb/viewer-core";
|
|
26
27
|
|
|
27
28
|
import { IMarkup, MarkupMode } from "../../IMarkup";
|
|
28
|
-
import {
|
|
29
|
+
import { IWorldTransform } from "../../IWorldTransform";
|
|
29
30
|
import { MarkupColor } from "./MarkupColor";
|
|
30
|
-
import * as utils from "../../../Draggers/MeasureLineDragger/MeasureUtils";
|
|
31
|
-
import { OdBaseDragger } from "../../../Draggers/Common/OdBaseDragger";
|
|
32
31
|
import { IMarkupObject } from "../../Api/IMarkupObject";
|
|
33
32
|
import { IMarkupColorable } from "../../Api/IMarkupColorable";
|
|
34
33
|
import { KonvaLine } from "../../Api/Impl/Konva/KonvaLine";
|
|
@@ -38,12 +37,13 @@ import { KonvaEllipse } from "../../Api/Impl/Konva/KonvaEllipse";
|
|
|
38
37
|
import { KonvaArrow } from "../../Api/Impl/Konva/KonvaArrow";
|
|
39
38
|
import { KonvaImage } from "../../Api/Impl/Konva/KonvaImage";
|
|
40
39
|
import { KonvaCloud } from "../../Api/Impl/Konva/KonvaCloud";
|
|
41
|
-
import { IMarkupLine } from "../../Api/IMarkupLine";
|
|
40
|
+
import { IMarkupLine, MarkupLineType } from "../../Api/IMarkupLine";
|
|
42
41
|
import { IMarkupArrow } from "../../Api/IMarkupArrow";
|
|
43
42
|
import { IMarkupEllipse } from "../../Api/IMarkupEllipse";
|
|
44
43
|
import { IMarkupRectangle } from "../../Api/IMarkupRectangle";
|
|
45
44
|
import { IMarkupCloud } from "../../Api/IMarkupCloud";
|
|
46
45
|
import { IMarkupImage } from "../../Api/IMarkupImage";
|
|
46
|
+
import { IMarkupText } from "../../Api/IMarkupText";
|
|
47
47
|
|
|
48
48
|
class KonvaShape {
|
|
49
49
|
name: string;
|
|
@@ -124,14 +124,18 @@ const MarkupMode2Konva = new Map<MarkupMode, KonvaShape>([
|
|
|
124
124
|
],
|
|
125
125
|
]);
|
|
126
126
|
|
|
127
|
+
/**
|
|
128
|
+
* 2D markup core.
|
|
129
|
+
*/
|
|
127
130
|
export class KonvaMarkup implements IMarkup {
|
|
128
131
|
private _isInitialized = false;
|
|
129
|
-
private _viewer:
|
|
132
|
+
private _viewer: IEventEmitter;
|
|
133
|
+
private _worldTransformer: IWorldTransform;
|
|
130
134
|
private _canvasOriginal: HTMLCanvasElement;
|
|
131
135
|
private _canvasEvents: string[];
|
|
132
|
-
private _markupIsActive
|
|
136
|
+
private _markupIsActive = false;
|
|
133
137
|
private _markupMode: MarkupMode;
|
|
134
|
-
private _markupColor
|
|
138
|
+
private _markupColor = new MarkupColor(255, 0, 0);
|
|
135
139
|
private _konvaStage: Konva.Stage;
|
|
136
140
|
private _konvaLayer: Konva.Layer;
|
|
137
141
|
private _konvaTransformer: Konva.Transformer;
|
|
@@ -147,19 +151,24 @@ export class KonvaMarkup implements IMarkup {
|
|
|
147
151
|
private readonly _markupContainerName = "markupContainer";
|
|
148
152
|
|
|
149
153
|
public lineWidth = 4;
|
|
150
|
-
public lineType:
|
|
154
|
+
public lineType: MarkupLineType = "solid";
|
|
151
155
|
public fontSize = 34;
|
|
152
156
|
|
|
153
|
-
initialize(
|
|
157
|
+
initialize(
|
|
158
|
+
canvas: HTMLCanvasElement,
|
|
159
|
+
canvasEvents: string[],
|
|
160
|
+
viewer?: IEventEmitter,
|
|
161
|
+
worldTransformer?: IWorldTransform
|
|
162
|
+
): void {
|
|
154
163
|
if (!Konva)
|
|
155
164
|
throw new Error(
|
|
156
|
-
'
|
|
165
|
+
'Markup: Error during initialization. Konva is not initialized. Update node_modules or add to your page <script src="https://unpkg.com/konva@9/konva.min.js"></script>'
|
|
157
166
|
);
|
|
158
167
|
|
|
159
168
|
this._viewer = viewer;
|
|
160
|
-
|
|
169
|
+
this._worldTransformer = worldTransformer;
|
|
161
170
|
this._canvasOriginal = canvas;
|
|
162
|
-
this._canvasEvents = canvasEvents;
|
|
171
|
+
this._canvasEvents = canvasEvents ?? [];
|
|
163
172
|
|
|
164
173
|
this._markupContainer = document.createElement("div");
|
|
165
174
|
this._markupContainer.id = this._markupContainerName;
|
|
@@ -172,17 +181,18 @@ export class KonvaMarkup implements IMarkup {
|
|
|
172
181
|
const parentDiv = this._canvasOriginal.parentElement;
|
|
173
182
|
parentDiv.appendChild(this._markupContainer);
|
|
174
183
|
|
|
175
|
-
this._markupColor
|
|
176
|
-
this._markupIsActive = false;
|
|
184
|
+
this._markupColor.setColor(255, 0, 0);
|
|
177
185
|
|
|
178
186
|
this.initializeKonva();
|
|
179
187
|
this.resize();
|
|
180
188
|
|
|
181
189
|
this._canvasEvents.forEach((x) => this._markupContainer.addEventListener(x, this.redirectToViewer));
|
|
182
190
|
|
|
183
|
-
this._viewer
|
|
184
|
-
|
|
185
|
-
|
|
191
|
+
if (this._viewer) {
|
|
192
|
+
this._viewer.addEventListener("resize", this.resize);
|
|
193
|
+
this._viewer.addEventListener("changeactivedragger", this.changeActiveDragger);
|
|
194
|
+
this._viewer.addEventListener("pan", this.pan);
|
|
195
|
+
}
|
|
186
196
|
|
|
187
197
|
this._isInitialized = true;
|
|
188
198
|
}
|
|
@@ -190,20 +200,24 @@ export class KonvaMarkup implements IMarkup {
|
|
|
190
200
|
dispose(): void {
|
|
191
201
|
if (!this._isInitialized) return;
|
|
192
202
|
|
|
193
|
-
|
|
203
|
+
if (this._viewer) {
|
|
204
|
+
this._viewer.removeEventListener("pan", this.pan);
|
|
205
|
+
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
206
|
+
this._viewer.removeEventListener("resize", this.resize);
|
|
207
|
+
}
|
|
194
208
|
|
|
195
|
-
this.
|
|
196
|
-
this._viewer.removeEventListener("changeactivedragger", this.changeActiveDragger);
|
|
197
|
-
this._viewer.removeEventListener("resize", this.resize);
|
|
209
|
+
this._canvasEvents.forEach((x) => this._markupContainer.removeEventListener(x, this.redirectToViewer));
|
|
198
210
|
|
|
199
211
|
this.destroyKonva();
|
|
200
212
|
|
|
201
213
|
this._markupContainer.remove();
|
|
202
|
-
|
|
203
214
|
this._markupContainer = undefined;
|
|
215
|
+
|
|
204
216
|
this._canvasOriginal = undefined;
|
|
205
217
|
this._viewer = undefined;
|
|
218
|
+
this._worldTransformer = undefined;
|
|
206
219
|
|
|
220
|
+
this._markupIsActive = false;
|
|
207
221
|
this._isInitialized = false;
|
|
208
222
|
}
|
|
209
223
|
|
|
@@ -243,13 +257,11 @@ export class KonvaMarkup implements IMarkup {
|
|
|
243
257
|
Object.values(MarkupMode).forEach((mode) => this.konvaLayerFind(mode).forEach((x) => x.move({ x: dX, y: dY })));
|
|
244
258
|
};
|
|
245
259
|
|
|
246
|
-
redirectToViewer = (event) => {
|
|
247
|
-
this._viewer.emit(event);
|
|
260
|
+
redirectToViewer = (event: any) => {
|
|
261
|
+
if (this._viewer) this._viewer.emit(event);
|
|
248
262
|
};
|
|
249
263
|
|
|
250
|
-
|
|
251
|
-
return null;
|
|
252
|
-
}
|
|
264
|
+
syncOverlay(): void {}
|
|
253
265
|
|
|
254
266
|
clearOverlay(): void {
|
|
255
267
|
this.removeTextInput();
|
|
@@ -295,9 +307,6 @@ export class KonvaMarkup implements IMarkup {
|
|
|
295
307
|
}
|
|
296
308
|
|
|
297
309
|
getViewpoint(): IViewpoint {
|
|
298
|
-
// 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.
|
|
299
|
-
if (!this._viewer.visualizeJs) return {};
|
|
300
|
-
|
|
301
310
|
const viewpoint: IViewpoint = {
|
|
302
311
|
lines: [],
|
|
303
312
|
texts: [],
|
|
@@ -323,7 +332,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
323
332
|
}
|
|
324
333
|
|
|
325
334
|
createObject(type: string, params: any): IMarkupObject {
|
|
326
|
-
let object;
|
|
335
|
+
let object = null;
|
|
327
336
|
let zIndex = this._zIndex;
|
|
328
337
|
|
|
329
338
|
// TODO: factory?
|
|
@@ -767,9 +776,8 @@ export class KonvaMarkup implements IMarkup {
|
|
|
767
776
|
// we need getAbsoluteTransform because inside Konva position starts from {0, 0}
|
|
768
777
|
// https://stackoverflow.com/a/57641487 - check answer's comments
|
|
769
778
|
const atPoint = absoluteTransform.point({ x: linePoints[i], y: linePoints[i + 1] });
|
|
770
|
-
const worldPoint = this.
|
|
771
|
-
|
|
772
|
-
.screenToWorld(atPoint.x * window.devicePixelRatio, atPoint.y * window.devicePixelRatio);
|
|
779
|
+
const worldPoint = this._worldTransformer.screenToWorld(atPoint);
|
|
780
|
+
|
|
773
781
|
worldPoints.push(worldPoint);
|
|
774
782
|
}
|
|
775
783
|
|
|
@@ -790,28 +798,22 @@ export class KonvaMarkup implements IMarkup {
|
|
|
790
798
|
const texts = [];
|
|
791
799
|
|
|
792
800
|
const textSize = 0.02;
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
const projMtrx = this._viewer.visViewer().activeView.projectionMatrix;
|
|
796
|
-
const mtrxNumber = projMtrx.get(1, 1);
|
|
797
|
-
const tol = 1.0e-6;
|
|
798
|
-
if (mtrxNumber > tol || mtrxNumber < -tol) {
|
|
799
|
-
textScale = 1 / mtrxNumber;
|
|
800
|
-
}
|
|
801
|
+
const textScale = this._worldTransformer.getScale();
|
|
801
802
|
|
|
802
803
|
this.konvaLayerFind(MarkupMode.Text).forEach((text) => {
|
|
803
804
|
if (!text) return;
|
|
804
805
|
|
|
805
|
-
const position = this.
|
|
806
|
-
.
|
|
807
|
-
|
|
806
|
+
const position = this._worldTransformer.screenToWorld({
|
|
807
|
+
x: text.x(),
|
|
808
|
+
y: text.y(),
|
|
809
|
+
});
|
|
808
810
|
|
|
809
811
|
const shape = new KonvaText(null, text);
|
|
810
812
|
texts.push({
|
|
811
813
|
id: shape.id(),
|
|
812
814
|
position: this.getPoint3dFromArray(position),
|
|
813
815
|
text: shape.getText(),
|
|
814
|
-
text_size: textSize * textScale,
|
|
816
|
+
text_size: textSize * textScale.y,
|
|
815
817
|
angle: shape.getRotation(),
|
|
816
818
|
color: shape.getColor(),
|
|
817
819
|
font_size: shape.getFontSize(),
|
|
@@ -825,9 +827,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
825
827
|
const rectangles = [];
|
|
826
828
|
this.konvaLayerFind(MarkupMode.Rectangle).forEach((rect) => {
|
|
827
829
|
const position = rect.position();
|
|
828
|
-
const worldPoint = this.
|
|
829
|
-
.visViewer()
|
|
830
|
-
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
830
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
831
831
|
|
|
832
832
|
const shape = new KonvaRectangle(null, rect);
|
|
833
833
|
rectangles.push({
|
|
@@ -847,9 +847,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
847
847
|
const ellipses = [];
|
|
848
848
|
this.konvaLayerFind(MarkupMode.Ellipse).forEach((ellipse) => {
|
|
849
849
|
const position = ellipse.position();
|
|
850
|
-
const worldPoint = this.
|
|
851
|
-
.visViewer()
|
|
852
|
-
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
850
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
853
851
|
|
|
854
852
|
const shape = new KonvaEllipse(null, ellipse);
|
|
855
853
|
ellipses.push({
|
|
@@ -871,14 +869,10 @@ export class KonvaMarkup implements IMarkup {
|
|
|
871
869
|
const absoluteTransform = arrow.getAbsoluteTransform();
|
|
872
870
|
|
|
873
871
|
const atStartPoint = absoluteTransform.point({ x: arrow.points()[0], y: arrow.points()[1] });
|
|
874
|
-
const worldStartPoint = this.
|
|
875
|
-
.visViewer()
|
|
876
|
-
.screenToWorld(atStartPoint.x * window.devicePixelRatio, atStartPoint.y * window.devicePixelRatio);
|
|
872
|
+
const worldStartPoint = this._worldTransformer.screenToWorld(atStartPoint);
|
|
877
873
|
|
|
878
874
|
const atEndPoint = absoluteTransform.point({ x: arrow.points()[2], y: arrow.points()[3] });
|
|
879
|
-
const worldEndPoint = this.
|
|
880
|
-
.visViewer()
|
|
881
|
-
.screenToWorld(atEndPoint.x * window.devicePixelRatio, atEndPoint.y * window.devicePixelRatio);
|
|
875
|
+
const worldEndPoint = this._worldTransformer.screenToWorld(atEndPoint);
|
|
882
876
|
|
|
883
877
|
const shape = new KonvaArrow(null, arrow);
|
|
884
878
|
arrows.push({
|
|
@@ -896,9 +890,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
896
890
|
const images = [];
|
|
897
891
|
this.konvaLayerFind(MarkupMode.Image).forEach((image) => {
|
|
898
892
|
const position = image.position();
|
|
899
|
-
const worldPoint = this.
|
|
900
|
-
.visViewer()
|
|
901
|
-
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
893
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
902
894
|
|
|
903
895
|
const shape = new KonvaImage(null, image);
|
|
904
896
|
images.push({
|
|
@@ -917,9 +909,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
917
909
|
const clouds = [];
|
|
918
910
|
this.konvaLayerFind(MarkupMode.Cloud).forEach((cloud) => {
|
|
919
911
|
const position = cloud.position();
|
|
920
|
-
const worldPoint = this.
|
|
921
|
-
.visViewer()
|
|
922
|
-
.screenToWorld(position.x * window.devicePixelRatio, position.y * window.devicePixelRatio);
|
|
912
|
+
const worldPoint = this._worldTransformer.screenToWorld(position);
|
|
923
913
|
|
|
924
914
|
const shape = new KonvaCloud(null, cloud);
|
|
925
915
|
clouds.push({
|
|
@@ -939,101 +929,43 @@ export class KonvaMarkup implements IMarkup {
|
|
|
939
929
|
viewpoint.lines?.forEach((vpLine) => {
|
|
940
930
|
const linePoints = [];
|
|
941
931
|
vpLine.points.forEach((point) => {
|
|
942
|
-
const screenPoint =
|
|
943
|
-
[point.x, point.y, point.z],
|
|
944
|
-
this._viewer.visualizeJs,
|
|
945
|
-
this._viewer.visViewer()
|
|
946
|
-
);
|
|
932
|
+
const screenPoint = this._worldTransformer.worldToScreen(point);
|
|
947
933
|
linePoints.push(screenPoint.x);
|
|
948
934
|
linePoints.push(screenPoint.y);
|
|
949
935
|
});
|
|
950
936
|
|
|
951
|
-
this.addLine(linePoints, vpLine.color, vpLine.type, vpLine.width, vpLine.id);
|
|
937
|
+
this.addLine(linePoints, vpLine.color, vpLine.type as MarkupLineType, vpLine.width, vpLine.id);
|
|
952
938
|
});
|
|
953
939
|
|
|
954
940
|
viewpoint.texts?.forEach((vpText) => {
|
|
955
|
-
const screenPoint =
|
|
956
|
-
[vpText.position.x, vpText.position.y, vpText.position.z],
|
|
957
|
-
this._viewer.visualizeJs,
|
|
958
|
-
this._viewer.visViewer()
|
|
959
|
-
);
|
|
941
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpText.position);
|
|
960
942
|
this.addText(vpText.text, screenPoint, vpText.angle, vpText.color, vpText.text_size, vpText.font_size, vpText.id);
|
|
961
943
|
});
|
|
962
944
|
|
|
963
945
|
viewpoint.rectangles?.forEach((vpRect) => {
|
|
964
|
-
const screenPoint =
|
|
965
|
-
|
|
966
|
-
this._viewer.visualizeJs,
|
|
967
|
-
this._viewer.visViewer()
|
|
968
|
-
);
|
|
969
|
-
|
|
970
|
-
this.addRectangle(
|
|
971
|
-
{ x: screenPoint.x, y: screenPoint.y },
|
|
972
|
-
vpRect.width,
|
|
973
|
-
vpRect.height,
|
|
974
|
-
vpRect.line_width,
|
|
975
|
-
vpRect.color,
|
|
976
|
-
vpRect.id
|
|
977
|
-
);
|
|
946
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpRect.position);
|
|
947
|
+
this.addRectangle(screenPoint, vpRect.width, vpRect.height, vpRect.line_width, vpRect.color, vpRect.id);
|
|
978
948
|
});
|
|
979
949
|
|
|
980
950
|
viewpoint.ellipses?.forEach((vpEllipse) => {
|
|
981
|
-
const screenPoint =
|
|
982
|
-
|
|
983
|
-
this._viewer.visualizeJs,
|
|
984
|
-
this._viewer.visViewer()
|
|
985
|
-
);
|
|
986
|
-
|
|
987
|
-
this.addEllipse(
|
|
988
|
-
{ x: screenPoint.x, y: screenPoint.y },
|
|
989
|
-
{ x: vpEllipse.radius.x, y: vpEllipse.radius.y },
|
|
990
|
-
vpEllipse.line_width,
|
|
991
|
-
vpEllipse.color,
|
|
992
|
-
vpEllipse.id
|
|
993
|
-
);
|
|
951
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpEllipse.position);
|
|
952
|
+
this.addEllipse(screenPoint, vpEllipse.radius, vpEllipse.line_width, vpEllipse.color, vpEllipse.id);
|
|
994
953
|
});
|
|
995
954
|
|
|
996
955
|
viewpoint.arrows?.forEach((vpArrow) => {
|
|
997
|
-
const startPoint =
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
this._viewer.visViewer()
|
|
1001
|
-
);
|
|
1002
|
-
|
|
1003
|
-
const endPoint = utils.worldToScreen(
|
|
1004
|
-
[vpArrow.end.x, vpArrow.end.y, vpArrow.end.z],
|
|
1005
|
-
this._viewer.visualizeJs,
|
|
1006
|
-
this._viewer.visViewer()
|
|
1007
|
-
);
|
|
1008
|
-
|
|
1009
|
-
this.addArrow({ x: startPoint.x, y: startPoint.y }, { x: endPoint.x, y: endPoint.y }, vpArrow.color, vpArrow.id);
|
|
956
|
+
const startPoint = this._worldTransformer.worldToScreen(vpArrow.start);
|
|
957
|
+
const endPoint = this._worldTransformer.worldToScreen(vpArrow.end);
|
|
958
|
+
this.addArrow(startPoint, endPoint, vpArrow.color, vpArrow.id);
|
|
1010
959
|
});
|
|
1011
960
|
|
|
1012
961
|
viewpoint.clouds?.forEach((vpCloud) => {
|
|
1013
|
-
const screenPoint =
|
|
1014
|
-
|
|
1015
|
-
this._viewer.visualizeJs,
|
|
1016
|
-
this._viewer.visViewer()
|
|
1017
|
-
);
|
|
1018
|
-
|
|
1019
|
-
this.addCloud(
|
|
1020
|
-
{ x: screenPoint.x, y: screenPoint.y },
|
|
1021
|
-
vpCloud.width,
|
|
1022
|
-
vpCloud.height,
|
|
1023
|
-
vpCloud.line_width,
|
|
1024
|
-
vpCloud.color,
|
|
1025
|
-
vpCloud.id
|
|
1026
|
-
);
|
|
962
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpCloud.position);
|
|
963
|
+
this.addCloud(screenPoint, vpCloud.width, vpCloud.height, vpCloud.line_width, vpCloud.color, vpCloud.id);
|
|
1027
964
|
});
|
|
1028
965
|
|
|
1029
966
|
viewpoint.images?.forEach((vpImage) => {
|
|
1030
|
-
const screenPoint =
|
|
1031
|
-
|
|
1032
|
-
this._viewer.visualizeJs,
|
|
1033
|
-
this._viewer.visViewer()
|
|
1034
|
-
);
|
|
1035
|
-
|
|
1036
|
-
this.addImage({ x: screenPoint.x, y: screenPoint.y }, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
|
|
967
|
+
const screenPoint = this._worldTransformer.worldToScreen(vpImage.position);
|
|
968
|
+
this.addImage(screenPoint, vpImage.src, vpImage.width, vpImage.height, vpImage.id);
|
|
1037
969
|
});
|
|
1038
970
|
}
|
|
1039
971
|
|
|
@@ -1055,7 +987,7 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1055
987
|
private addLine(
|
|
1056
988
|
linePoints: number[],
|
|
1057
989
|
color?: string,
|
|
1058
|
-
type?:
|
|
990
|
+
type?: MarkupLineType,
|
|
1059
991
|
width?: number,
|
|
1060
992
|
id?: string
|
|
1061
993
|
): IMarkupLine | void {
|
|
@@ -1170,22 +1102,24 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1170
1102
|
textSize?: number,
|
|
1171
1103
|
fontSize?: number,
|
|
1172
1104
|
id?: string
|
|
1173
|
-
): void {
|
|
1105
|
+
): IMarkupText | void {
|
|
1106
|
+
const trNodes = this._konvaTransformer.nodes();
|
|
1107
|
+
if (trNodes.length > 0) {
|
|
1108
|
+
// in case of edit - remove old Konva.Text object
|
|
1109
|
+
trNodes[0].destroy();
|
|
1110
|
+
this._konvaTransformer.nodes([]);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
this.removeTextInput();
|
|
1114
|
+
|
|
1174
1115
|
if (specifiedText) {
|
|
1175
|
-
const
|
|
1116
|
+
const tolerance = 1.0e-6;
|
|
1176
1117
|
|
|
1177
1118
|
// in case we have old viewpoint without font_size
|
|
1178
|
-
if (textSize && textSize >
|
|
1119
|
+
if (textSize && textSize > tolerance && (!fontSize || fontSize < tolerance)) {
|
|
1179
1120
|
const size = 0.02;
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
const projMtrx = this._viewer.visViewer().activeView.projectionMatrix;
|
|
1183
|
-
const mtrxNumber = projMtrx.get(1, 1);
|
|
1184
|
-
|
|
1185
|
-
if (mtrxNumber > tol || mtrxNumber < -tol) {
|
|
1186
|
-
scale = 1 / mtrxNumber;
|
|
1187
|
-
}
|
|
1188
|
-
fontSize = textSize / (scale / size) / 34;
|
|
1121
|
+
const scale = this._worldTransformer.getScale();
|
|
1122
|
+
fontSize = textSize / (scale.y / size) / 34;
|
|
1189
1123
|
}
|
|
1190
1124
|
|
|
1191
1125
|
const konvaText = new KonvaText({
|
|
@@ -1198,18 +1132,8 @@ export class KonvaMarkup implements IMarkup {
|
|
|
1198
1132
|
});
|
|
1199
1133
|
|
|
1200
1134
|
this._konvaLayer.add(konvaText.ref());
|
|
1135
|
+
return konvaText;
|
|
1201
1136
|
}
|
|
1202
|
-
|
|
1203
|
-
const trNodes = this._konvaTransformer.nodes();
|
|
1204
|
-
if (trNodes.length > 0) {
|
|
1205
|
-
// in case of edit - remove old Konva.Text object
|
|
1206
|
-
trNodes[0].destroy();
|
|
1207
|
-
this._konvaTransformer.nodes([]);
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
this.removeTextInput();
|
|
1211
|
-
|
|
1212
|
-
return;
|
|
1213
1137
|
}
|
|
1214
1138
|
|
|
1215
1139
|
private addRectangle(
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { IEventEmitter } from "@inweb/eventemitter2";
|
|
1
2
|
import { ILine, IText, IViewpoint } from "@inweb/viewer-core";
|
|
2
|
-
|
|
3
|
-
import {
|
|
3
|
+
import { IMarkup } from "../../IMarkup";
|
|
4
|
+
import { IWorldTransform } from "../../IWorldTransform";
|
|
4
5
|
import { Viewer } from "../../../Viewer";
|
|
5
|
-
import { OdBaseDragger } from "../../../Draggers/Common/OdBaseDragger";
|
|
6
6
|
import { MARKUP_ENTITY_LINE, OdaLineDragger } from "../../../Draggers/OdaLineDragger";
|
|
7
7
|
import { MARKUP_ENTITY_TEXT, OdaTextDragger } from "../../../Draggers/OdaTextDragger";
|
|
8
8
|
import { IMarkupObject } from "../../Api/IMarkupObject";
|
|
9
9
|
|
|
10
|
+
const OVERLAY_VIEW_NAME = "$OVERLAY_VIEW_NAME";
|
|
11
|
+
|
|
10
12
|
export class VisualizeMarkup implements IMarkup {
|
|
11
13
|
private _viewer: Viewer;
|
|
12
14
|
protected _markupColor = { r: 255, g: 0, b: 0 };
|
|
@@ -15,17 +17,50 @@ export class VisualizeMarkup implements IMarkup {
|
|
|
15
17
|
public lineType: "solid";
|
|
16
18
|
public fontSize = 34;
|
|
17
19
|
|
|
18
|
-
initialize(
|
|
19
|
-
|
|
20
|
+
initialize(
|
|
21
|
+
canvas: HTMLCanvasElement,
|
|
22
|
+
canvasEvents: string[],
|
|
23
|
+
viewer?: IEventEmitter,
|
|
24
|
+
worldTransformer?: IWorldTransform
|
|
25
|
+
): void {
|
|
26
|
+
this._viewer = viewer as Viewer;
|
|
27
|
+
this._viewer.registerDragger("Line", OdaLineDragger);
|
|
28
|
+
this._viewer.registerDragger("Text", OdaTextDragger);
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
dispose(): void {}
|
|
23
32
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
syncOverlay(): void {
|
|
34
|
+
if (!this._viewer.visualizeJs) return;
|
|
35
|
+
|
|
36
|
+
const visViewer = this._viewer.visViewer();
|
|
37
|
+
const activeView = visViewer.activeView;
|
|
38
|
+
|
|
39
|
+
let overlayView = visViewer.getViewByName(OVERLAY_VIEW_NAME);
|
|
40
|
+
if (!overlayView) {
|
|
41
|
+
const overlayModel = visViewer.getMarkupModel();
|
|
42
|
+
const pDevice = visViewer.getActiveDevice();
|
|
43
|
+
|
|
44
|
+
overlayView = pDevice.createView(OVERLAY_VIEW_NAME, false);
|
|
45
|
+
overlayView.addModel(overlayModel);
|
|
46
|
+
|
|
47
|
+
activeView.addSibling(overlayView);
|
|
48
|
+
pDevice.addView(overlayView);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
overlayView.viewPosition = activeView.viewPosition;
|
|
52
|
+
overlayView.viewTarget = activeView.viewTarget;
|
|
53
|
+
overlayView.upVector = activeView.upVector;
|
|
54
|
+
overlayView.viewFieldWidth = activeView.viewFieldWidth;
|
|
55
|
+
overlayView.viewFieldHeight = activeView.viewFieldHeight;
|
|
56
|
+
|
|
57
|
+
const viewPort = overlayView.getViewport();
|
|
58
|
+
overlayView.setViewport(viewPort.lowerLeft, viewPort.upperRight);
|
|
59
|
+
overlayView.vportRect = activeView.vportRect;
|
|
60
|
+
|
|
61
|
+
this._viewer.update();
|
|
62
|
+
|
|
63
|
+
return overlayView;
|
|
29
64
|
}
|
|
30
65
|
|
|
31
66
|
clearOverlay(): void {
|
|
@@ -21,41 +21,37 @@
|
|
|
21
21
|
// acknowledge and accept the above terms.
|
|
22
22
|
///////////////////////////////////////////////////////////////////////////////
|
|
23
23
|
|
|
24
|
-
import { IMarkup
|
|
24
|
+
import { IMarkup } from "./IMarkup";
|
|
25
25
|
import { KonvaMarkup } from "./Impl/Konva/KonvaMarkup";
|
|
26
26
|
import { VisualizeMarkup } from "./Impl/Visualize/VisualizeMarkup";
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* The markup type: `Visualize` (deprecated) or `Konva`.
|
|
30
|
+
*/
|
|
31
|
+
export enum MarkupType {
|
|
32
|
+
Unknown,
|
|
33
|
+
Konva = "Konva",
|
|
34
|
+
Visualize = "Visualize",
|
|
35
|
+
}
|
|
36
|
+
|
|
28
37
|
export class MarkupFactory {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* @param markupType - Specifies version of the markup support. Two variants of markup
|
|
33
|
-
* support are implemented: old "Visualize" and new "Konva". Default is "Konva". {@link MarkupType}
|
|
34
|
-
*/
|
|
35
|
-
public static createMarkup(markupType: MarkupType): IMarkup {
|
|
36
|
-
let markup;
|
|
38
|
+
public static createMarkup(markupType: MarkupType = MarkupType.Konva): IMarkup {
|
|
39
|
+
let markup: IMarkup;
|
|
40
|
+
|
|
37
41
|
switch (markupType) {
|
|
38
42
|
case MarkupType.Konva:
|
|
39
|
-
markup =
|
|
43
|
+
markup = new KonvaMarkup();
|
|
40
44
|
break;
|
|
41
45
|
|
|
42
46
|
case MarkupType.Visualize:
|
|
43
|
-
markup =
|
|
47
|
+
markup = new VisualizeMarkup();
|
|
44
48
|
break;
|
|
45
49
|
|
|
46
50
|
default:
|
|
47
|
-
throw new Error("Error during Markup
|
|
51
|
+
throw new Error("Error during Markup initialization. Unknown Markup type.");
|
|
48
52
|
break;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
return markup;
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
private static createKonva(): IMarkup {
|
|
55
|
-
return new KonvaMarkup();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private static createVisualize(): IMarkup {
|
|
59
|
-
return new VisualizeMarkup();
|
|
60
|
-
}
|
|
61
57
|
}
|