@itwin/hypermodeling-frontend 3.7.17 → 3.8.0-dev.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/lib/cjs/HyperModeling.d.ts +114 -114
- package/lib/cjs/HyperModeling.js +240 -240
- package/lib/cjs/HyperModelingConfig.d.ts +54 -54
- package/lib/cjs/HyperModelingConfig.js +9 -9
- package/lib/cjs/HyperModelingConfig.js.map +1 -1
- package/lib/cjs/HyperModelingDecorator.d.ts +110 -110
- package/lib/cjs/HyperModelingDecorator.js +337 -337
- package/lib/cjs/HyperModelingDecorator.js.map +1 -1
- package/lib/cjs/PopupToolbar.d.ts +24 -24
- package/lib/cjs/PopupToolbar.js +57 -57
- package/lib/cjs/PopupToolbar.js.map +1 -1
- package/lib/cjs/SectionDrawingLocationState.d.ts +90 -90
- package/lib/cjs/SectionDrawingLocationState.js +137 -137
- package/lib/cjs/SectionDrawingLocationState.js.map +1 -1
- package/lib/cjs/SectionGraphicsProvider.d.ts +13 -13
- package/lib/cjs/SectionGraphicsProvider.js +273 -273
- package/lib/cjs/SectionGraphicsProvider.js.map +1 -1
- package/lib/cjs/SectionMarkerHandler.d.ts +52 -52
- package/lib/cjs/SectionMarkerHandler.js +112 -112
- package/lib/cjs/SectionMarkerHandler.js.map +1 -1
- package/lib/cjs/SectionMarkers.d.ts +82 -82
- package/lib/cjs/SectionMarkers.js +174 -174
- package/lib/cjs/SectionMarkers.js.map +1 -1
- package/lib/cjs/Tools.d.ts +5 -5
- package/lib/cjs/Tools.js +170 -170
- package/lib/cjs/hypermodeling-frontend.d.ts +13 -13
- package/lib/cjs/hypermodeling-frontend.js +29 -29
- package/lib/cjs/hypermodeling-frontend.js.map +1 -1
- package/lib/esm/HyperModeling.d.ts +114 -114
- package/lib/esm/HyperModeling.js +236 -236
- package/lib/esm/HyperModelingConfig.d.ts +54 -54
- package/lib/esm/HyperModelingConfig.js +8 -8
- package/lib/esm/HyperModelingConfig.js.map +1 -1
- package/lib/esm/HyperModelingDecorator.d.ts +110 -110
- package/lib/esm/HyperModelingDecorator.js +333 -333
- package/lib/esm/HyperModelingDecorator.js.map +1 -1
- package/lib/esm/PopupToolbar.d.ts +24 -24
- package/lib/esm/PopupToolbar.js +53 -53
- package/lib/esm/PopupToolbar.js.map +1 -1
- package/lib/esm/SectionDrawingLocationState.d.ts +90 -90
- package/lib/esm/SectionDrawingLocationState.js +133 -133
- package/lib/esm/SectionDrawingLocationState.js.map +1 -1
- package/lib/esm/SectionGraphicsProvider.d.ts +13 -13
- package/lib/esm/SectionGraphicsProvider.js +269 -269
- package/lib/esm/SectionGraphicsProvider.js.map +1 -1
- package/lib/esm/SectionMarkerHandler.d.ts +52 -52
- package/lib/esm/SectionMarkerHandler.js +108 -108
- package/lib/esm/SectionMarkerHandler.js.map +1 -1
- package/lib/esm/SectionMarkers.d.ts +82 -82
- package/lib/esm/SectionMarkers.js +168 -168
- package/lib/esm/SectionMarkers.js.map +1 -1
- package/lib/esm/Tools.d.ts +5 -5
- package/lib/esm/Tools.js +166 -166
- package/lib/esm/hypermodeling-frontend.d.ts +13 -13
- package/lib/esm/hypermodeling-frontend.js +17 -17
- package/lib/esm/hypermodeling-frontend.js.map +1 -1
- package/lib/public/locales/en/HyperModeling.json +32 -32
- package/package.json +13 -13
|
@@ -1,334 +1,334 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module HyperModeling
|
|
7
|
-
*/
|
|
8
|
-
import { Transform } from "@itwin/core-geometry";
|
|
9
|
-
import { IModelApp, ViewClipTool, } from "@itwin/core-frontend";
|
|
10
|
-
import { SectionMarker, SectionMarkerSet } from "./SectionMarkers";
|
|
11
|
-
import { SectionDrawingLocationState } from "./SectionDrawingLocationState";
|
|
12
|
-
import { createSectionGraphicsProvider } from "./SectionGraphicsProvider";
|
|
13
|
-
import { PopupToolbarManager } from "./PopupToolbar";
|
|
14
|
-
import { HyperModeling } from "./HyperModeling";
|
|
15
|
-
async function createMarkers(vp) {
|
|
16
|
-
if (!vp.view.isSpatialView())
|
|
17
|
-
return undefined;
|
|
18
|
-
const states = await SectionDrawingLocationState.queryAll(vp.iModel);
|
|
19
|
-
if (0 === states.length)
|
|
20
|
-
return undefined;
|
|
21
|
-
const markers = states.map((state) => new SectionMarker(state));
|
|
22
|
-
return new SectionMarkerSet(vp, markers);
|
|
23
|
-
}
|
|
24
|
-
class MarkerToolbarProvider {
|
|
25
|
-
constructor(marker, decorator) {
|
|
26
|
-
this.marker = marker;
|
|
27
|
-
this._viewport = decorator.viewport;
|
|
28
|
-
this.toolbarProps = HyperModeling.markerHandler.getToolbarProps(marker, decorator);
|
|
29
|
-
this.onToolbarItemExecuted = (id) => HyperModeling.markerHandler.executeCommand(id, marker, decorator); // eslint-disable-line @typescript-eslint/promise-function-async
|
|
30
|
-
}
|
|
31
|
-
get overToolbarHotspot() {
|
|
32
|
-
return this.marker.isHilited;
|
|
33
|
-
}
|
|
34
|
-
get toolbarLocation() {
|
|
35
|
-
return IModelApp.uiAdmin.createXAndY(this.marker.rect.right, this.marker.rect.top);
|
|
36
|
-
}
|
|
37
|
-
get htmlElement() {
|
|
38
|
-
return this._viewport.canvas;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/** A [Decorator]($frontend) that displays a [[SectionMarker]] for each [SectionDrawingLocation]($backend) in the view.
|
|
42
|
-
* Clicking on a marker toggles the section and the display of associated 2d graphics.
|
|
43
|
-
* Hovering over a marker opens a mini toolbar with additional interactions.
|
|
44
|
-
* @see [[SectionMarkerHandler]] to customize the marker interactions.
|
|
45
|
-
* @see [[HyperModeling.startOrStop]] to enable or disable the decorator for a viewport.
|
|
46
|
-
* @public
|
|
47
|
-
*/
|
|
48
|
-
export class HyperModelingDecorator {
|
|
49
|
-
constructor(markers, config) {
|
|
50
|
-
this._removeEventListeners = new Array();
|
|
51
|
-
this._needSync = false;
|
|
52
|
-
/** @internal */
|
|
53
|
-
this.syncImmediately = false;
|
|
54
|
-
/** @internal */
|
|
55
|
-
this.useCachedDecorations = true;
|
|
56
|
-
this.markers = markers;
|
|
57
|
-
this._config = { ...config };
|
|
58
|
-
this._iModel = this.viewport.iModel;
|
|
59
|
-
this.viewport.onChangeView.addOnce(() => {
|
|
60
|
-
this.requestSync();
|
|
61
|
-
});
|
|
62
|
-
this._removeEventListeners.push(this.viewport.onViewportChanged.addListener((_, changeFlags) => this.onViewportChanged(changeFlags)));
|
|
63
|
-
this._removeEventListeners.push(this.viewport.onDisposed.addListener(() => this.dispose()));
|
|
64
|
-
for (const marker of markers.markers) {
|
|
65
|
-
marker.onMouseEnterEvent.addListener((mkr) => this.showToolbarAfterTimeout(mkr));
|
|
66
|
-
marker.onMouseButtonEvent.addListener((mkr) => this.toggleMarker(mkr)); // eslint-disable-line @typescript-eslint/promise-function-async
|
|
67
|
-
}
|
|
68
|
-
this.updateMarkerVisibility();
|
|
69
|
-
IModelApp.viewManager.addDecorator(this);
|
|
70
|
-
}
|
|
71
|
-
/** Create a new decorator and register it with the [ViewManager]($frontend). Typically invoked indirectly via [[HyperModeling.startOrStop]]. */
|
|
72
|
-
static async create(vp, config) {
|
|
73
|
-
const markers = await createMarkers(vp);
|
|
74
|
-
return undefined !== markers ? new HyperModelingDecorator(markers, config) : undefined;
|
|
75
|
-
}
|
|
76
|
-
/** Obtain the decorator associated with the specified viewport, if any. */
|
|
77
|
-
static getForViewport(vp) {
|
|
78
|
-
for (const decorator of IModelApp.viewManager.decorators)
|
|
79
|
-
if (decorator instanceof HyperModelingDecorator && decorator.viewport === vp)
|
|
80
|
-
return decorator;
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
/** The viewport into which this decorator draws its [[SectionMarker]]s. */
|
|
84
|
-
get viewport() {
|
|
85
|
-
return this.markers.viewport;
|
|
86
|
-
}
|
|
87
|
-
/** The currently active marker. A marker typically becomes active when the user clicks on it.
|
|
88
|
-
* @see [[setActiveMarker]] to change the active marker without user interaction.
|
|
89
|
-
*/
|
|
90
|
-
get activeMarker() {
|
|
91
|
-
return this._activeMarker;
|
|
92
|
-
}
|
|
93
|
-
/** @internal */
|
|
94
|
-
get config() {
|
|
95
|
-
return this._config;
|
|
96
|
-
}
|
|
97
|
-
/** Replaces the current marker display configuration, overwriting all previous settings. Passing `undefined` resets all settings to defaults.
|
|
98
|
-
* @see [[updateConfiguration]] to override specific aspects of the configuration
|
|
99
|
-
* @see [[HyperModeling.replaceConfiguration]] to replace the global configuration.
|
|
100
|
-
*/
|
|
101
|
-
replaceConfiguration(config) {
|
|
102
|
-
this._config = config ? { ...config } : {};
|
|
103
|
-
this.requestSync();
|
|
104
|
-
}
|
|
105
|
-
/** Overrides specific aspects of the current marker display configuration.
|
|
106
|
-
* Any field that is not `undefined` will be replaced in the current configuration; the rest will retain their current values.
|
|
107
|
-
* @see [[replaceConfiguration]] to override all settings.
|
|
108
|
-
* @see [[HyperModeling.updateConfiguration]] to update the global configuration.
|
|
109
|
-
*/
|
|
110
|
-
updateConfiguration(config) {
|
|
111
|
-
var _a, _b, _c;
|
|
112
|
-
this._config = {
|
|
113
|
-
ignoreModelSelector: (_a = config.ignoreModelSelector) !== null && _a !== void 0 ? _a : this._config.ignoreModelSelector,
|
|
114
|
-
ignoreCategorySelector: (_b = config.ignoreCategorySelector) !== null && _b !== void 0 ? _b : this._config.ignoreCategorySelector,
|
|
115
|
-
hiddenSectionTypes: (_c = config.hiddenSectionTypes) !== null && _c !== void 0 ? _c : this._config.hiddenSectionTypes,
|
|
116
|
-
};
|
|
117
|
-
this.requestSync();
|
|
118
|
-
}
|
|
119
|
-
/** Sets the currently active marker. This function is invoked when the user clicks on a marker, but may also be called manually to produce the same result.
|
|
120
|
-
* Changing the active marker first deactivates the currently active marker, if any; then activates the specified marker, if supplied.
|
|
121
|
-
* Returns false if marker activation fails.
|
|
122
|
-
* @see [[activeMarker]] to obtain the currently active section marker.
|
|
123
|
-
* @see [[SectionMarkerHandler.activateMarker]] to control what happens when a marker is activated.
|
|
124
|
-
* @see [[SectionMarkerHandler.deactivateMarker]] to control what happens when a marker is deactivated.
|
|
125
|
-
*/
|
|
126
|
-
async setActiveMarker(marker) {
|
|
127
|
-
if (marker === this.activeMarker)
|
|
128
|
-
return true;
|
|
129
|
-
if (this.activeMarker) {
|
|
130
|
-
this.activeMarker.setActive(false);
|
|
131
|
-
await HyperModeling.markerHandler.deactivateMarker(this.activeMarker, this);
|
|
132
|
-
this._activeMarker = undefined;
|
|
133
|
-
}
|
|
134
|
-
if (marker) {
|
|
135
|
-
if (!await HyperModeling.markerHandler.activateMarker(marker, this)) {
|
|
136
|
-
this.requestSync();
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
marker.setActive(true);
|
|
140
|
-
this._activeMarker = marker;
|
|
141
|
-
}
|
|
142
|
-
this.requestSync();
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
/** @internal */
|
|
146
|
-
decorate(context) {
|
|
147
|
-
if (this.viewport.view.is3d())
|
|
148
|
-
this.markers.addDecoration(context);
|
|
149
|
-
}
|
|
150
|
-
onViewportChanged(changeFlags) {
|
|
151
|
-
if (this.viewport.iModel !== this._iModel) {
|
|
152
|
-
this.dispose();
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (changeFlags.viewedCategories || changeFlags.viewedModels || changeFlags.viewedCategoriesPerModel)
|
|
156
|
-
this.requestSync();
|
|
157
|
-
if (changeFlags.viewState) {
|
|
158
|
-
// If we're looking at a different view now, and we did not initiate that, turn off the active marker.
|
|
159
|
-
if (this.viewport.view !== this._appliedSpatialView)
|
|
160
|
-
this.setActiveMarker(undefined); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
161
|
-
else
|
|
162
|
-
this._appliedSpatialView = undefined;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
async toggleMarker(marker) {
|
|
166
|
-
await this.setActiveMarker(marker === this.activeMarker ? undefined : marker);
|
|
167
|
-
}
|
|
168
|
-
dropTiledGraphicsProvider() {
|
|
169
|
-
if (undefined === this._tiledGraphicsProvider)
|
|
170
|
-
return;
|
|
171
|
-
this.viewport.dropTiledGraphicsProvider(this._tiledGraphicsProvider);
|
|
172
|
-
this._tiledGraphicsProvider = undefined;
|
|
173
|
-
}
|
|
174
|
-
/** @internal */
|
|
175
|
-
dispose() {
|
|
176
|
-
if (!IModelApp.viewManager.dropDecorator(this))
|
|
177
|
-
return;
|
|
178
|
-
for (const remove of this._removeEventListeners)
|
|
179
|
-
remove();
|
|
180
|
-
this.dropTiledGraphicsProvider();
|
|
181
|
-
}
|
|
182
|
-
showToolbarAfterTimeout(marker) {
|
|
183
|
-
var _a;
|
|
184
|
-
if (((_a = this._toolbarProvider) === null || _a === void 0 ? void 0 : _a.marker) !== marker)
|
|
185
|
-
this._toolbarProvider = new MarkerToolbarProvider(marker, this);
|
|
186
|
-
PopupToolbarManager.showToolbarAfterTimeout(this._toolbarProvider);
|
|
187
|
-
}
|
|
188
|
-
/** Toggles whether the clip volume associated with the specified marker is applied to the view. */
|
|
189
|
-
toggleClipVolume(marker, enable) {
|
|
190
|
-
ViewClipTool.enableClipVolume(this.viewport);
|
|
191
|
-
ViewClipTool.setViewClip(this.viewport, enable ? marker.state.clip : undefined);
|
|
192
|
-
}
|
|
193
|
-
/** Toggles the specified section marker.
|
|
194
|
-
* Enabling the section applies the frustum and clip volume of the marker's spatial view to the viewport, and displays the 2d section graphics and sheet annotations.
|
|
195
|
-
* Disabling the section disables the clip volume and 2d graphics.
|
|
196
|
-
* @see [[toggleClipVolume]] to toggle only the clip volume.
|
|
197
|
-
* @see [[toggleAttachment]] to toggle only the attachment graphics.
|
|
198
|
-
*/
|
|
199
|
-
async toggleSection(marker, enable) {
|
|
200
|
-
if (enable) {
|
|
201
|
-
if (this.viewport.view.is3d()) {
|
|
202
|
-
// Preserve the view settings; apply only the frustum and clip volume
|
|
203
|
-
const spatialView = await marker.state.tryLoadSpatialView();
|
|
204
|
-
if (!spatialView)
|
|
205
|
-
return false;
|
|
206
|
-
const aligned = await this.alignToSpatialView(marker);
|
|
207
|
-
if (!aligned)
|
|
208
|
-
return false;
|
|
209
|
-
this.toggleClipVolume(marker, true);
|
|
210
|
-
}
|
|
211
|
-
else if (!await this.applySpatialView(marker)) {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
this.toggleClipVolume(marker, false);
|
|
217
|
-
}
|
|
218
|
-
this.requestSync();
|
|
219
|
-
return this.toggleAttachment(marker, enable);
|
|
220
|
-
}
|
|
221
|
-
/** Toggles display of 2d section graphics and sheet annotations for the specified marker.
|
|
222
|
-
* @see [[toggleSection]] to apply the spatial view and clip volume in addition to the attachment graphics.
|
|
223
|
-
*/
|
|
224
|
-
async toggleAttachment(marker, enable) {
|
|
225
|
-
this.dropTiledGraphicsProvider();
|
|
226
|
-
if (enable) {
|
|
227
|
-
this._tiledGraphicsProvider = await createSectionGraphicsProvider(marker.state);
|
|
228
|
-
this.viewport.addTiledGraphicsProvider(this._tiledGraphicsProvider);
|
|
229
|
-
}
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
/** Aligns the viewport to face the specified marker's section plane. */
|
|
233
|
-
alignView(marker) {
|
|
234
|
-
const placement = marker.state.placement.transform;
|
|
235
|
-
const origin = placement.origin;
|
|
236
|
-
const matrix = placement.matrix;
|
|
237
|
-
const vp = this.viewport;
|
|
238
|
-
const targetMatrix = matrix.multiplyMatrixMatrix(vp.rotation);
|
|
239
|
-
const rotateTransform = Transform.createFixedPointAndMatrix(origin, targetMatrix);
|
|
240
|
-
const startFrustum = vp.getFrustum();
|
|
241
|
-
const newFrustum = startFrustum.clone();
|
|
242
|
-
newFrustum.multiply(rotateTransform);
|
|
243
|
-
if (startFrustum.equals(newFrustum))
|
|
244
|
-
return;
|
|
245
|
-
vp.view.setupFromFrustum(newFrustum);
|
|
246
|
-
vp.synchWithView();
|
|
247
|
-
vp.animateFrustumChange();
|
|
248
|
-
}
|
|
249
|
-
/** Opens the marker's drawing view in the decorator's viewport. Returns false if the drawing view could not be loaded. */
|
|
250
|
-
async openSection(marker) {
|
|
251
|
-
const viewState = await marker.state.tryLoadDrawingView();
|
|
252
|
-
if (viewState)
|
|
253
|
-
this.viewport.changeView(viewState);
|
|
254
|
-
return undefined !== viewState;
|
|
255
|
-
}
|
|
256
|
-
/** Opens marker's sheet view in the decorator's viewport and zooms in on the associated [ViewAttachment]($backend). Returns false if no view
|
|
257
|
-
* attachment exists or the sheet view could not be loaded.
|
|
258
|
-
*/
|
|
259
|
-
async openSheet(marker) {
|
|
260
|
-
if (undefined === marker.state.viewAttachment)
|
|
261
|
-
return false;
|
|
262
|
-
const viewState = await marker.state.tryLoadSheetView();
|
|
263
|
-
if (!viewState)
|
|
264
|
-
return false;
|
|
265
|
-
this.viewport.changeView(viewState);
|
|
266
|
-
await this.viewport.zoomToElements(marker.state.viewAttachment.id);
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
/** Aligns the view to match the frustum of the spatial view associated with the specified marker.
|
|
270
|
-
* @param marker The marker whose spatial view's frustum should be applied.
|
|
271
|
-
* @returns false if the frustum could not be applied, e.g. because the spatial view could not be loaded or the viewport is viewing a 2d model.
|
|
272
|
-
* @see [[alignView]] to align to the *section plane*, which may differ.
|
|
273
|
-
* @see [[toggleSection]] to also apply the clip volume.
|
|
274
|
-
*/
|
|
275
|
-
async alignToSpatialView(marker) {
|
|
276
|
-
if (!this.viewport.view.is3d())
|
|
277
|
-
return false;
|
|
278
|
-
const spatialView = await marker.state.tryLoadSpatialView();
|
|
279
|
-
if (!spatialView)
|
|
280
|
-
return false;
|
|
281
|
-
this.viewport.view.setOrigin(spatialView.getOrigin());
|
|
282
|
-
this.viewport.view.setExtents(spatialView.getExtents());
|
|
283
|
-
this.viewport.view.setRotation(spatialView.getRotation());
|
|
284
|
-
this.viewport.synchWithView({ animateFrustumChange: true });
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
/** Applies the marker's spatial view - including its clip volume - to the decorator's viewport.
|
|
288
|
-
* Returns false if the spatial view could not be loaded.
|
|
289
|
-
* @see [[toggleSection]].
|
|
290
|
-
* @see [[toggleClipVolume]].
|
|
291
|
-
*/
|
|
292
|
-
async applySpatialView(marker) {
|
|
293
|
-
const viewState = await marker.state.tryLoadSpatialView();
|
|
294
|
-
if (viewState) {
|
|
295
|
-
this._appliedSpatialView = viewState;
|
|
296
|
-
this.viewport.changeView(viewState);
|
|
297
|
-
}
|
|
298
|
-
return undefined !== viewState;
|
|
299
|
-
}
|
|
300
|
-
/** Request that the visibility of the section markers be recomputed. It is only necessary to call this if you have overridden [[SectionMarkerHandler.isMarkerVisible]]; if so, you should invoke
|
|
301
|
-
* this method when the criteria governing your `isMarkerVisible` method have changed.
|
|
302
|
-
*/
|
|
303
|
-
requestSync() {
|
|
304
|
-
if (this.syncImmediately) {
|
|
305
|
-
this.sync();
|
|
306
|
-
}
|
|
307
|
-
else if (!this._needSync) {
|
|
308
|
-
this._needSync = true;
|
|
309
|
-
requestAnimationFrame(() => this.sync());
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
sync() {
|
|
313
|
-
this._needSync = false;
|
|
314
|
-
if (HyperModeling.isInitialized && this.viewport.view.is3d() && this.updateMarkerVisibility()) {
|
|
315
|
-
this.markers.markDirty();
|
|
316
|
-
this.viewport.invalidateCachedDecorations(this);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
isMarkerVisible(marker) {
|
|
320
|
-
if (undefined !== this.activeMarker)
|
|
321
|
-
return marker === this.activeMarker;
|
|
322
|
-
return HyperModeling.markerHandler.isMarkerVisible(marker, this, this._config);
|
|
323
|
-
}
|
|
324
|
-
updateMarkerVisibility() {
|
|
325
|
-
let changed = false;
|
|
326
|
-
for (const marker of this.markers.markers) {
|
|
327
|
-
const wasVisible = marker.visible;
|
|
328
|
-
marker.visible = this.isMarkerVisible(marker);
|
|
329
|
-
changed = changed || (marker.visible !== wasVisible);
|
|
330
|
-
}
|
|
331
|
-
return changed;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module HyperModeling
|
|
7
|
+
*/
|
|
8
|
+
import { Transform } from "@itwin/core-geometry";
|
|
9
|
+
import { IModelApp, ViewClipTool, } from "@itwin/core-frontend";
|
|
10
|
+
import { SectionMarker, SectionMarkerSet } from "./SectionMarkers";
|
|
11
|
+
import { SectionDrawingLocationState } from "./SectionDrawingLocationState";
|
|
12
|
+
import { createSectionGraphicsProvider } from "./SectionGraphicsProvider";
|
|
13
|
+
import { PopupToolbarManager } from "./PopupToolbar";
|
|
14
|
+
import { HyperModeling } from "./HyperModeling";
|
|
15
|
+
async function createMarkers(vp) {
|
|
16
|
+
if (!vp.view.isSpatialView())
|
|
17
|
+
return undefined;
|
|
18
|
+
const states = await SectionDrawingLocationState.queryAll(vp.iModel);
|
|
19
|
+
if (0 === states.length)
|
|
20
|
+
return undefined;
|
|
21
|
+
const markers = states.map((state) => new SectionMarker(state));
|
|
22
|
+
return new SectionMarkerSet(vp, markers);
|
|
23
|
+
}
|
|
24
|
+
class MarkerToolbarProvider {
|
|
25
|
+
constructor(marker, decorator) {
|
|
26
|
+
this.marker = marker;
|
|
27
|
+
this._viewport = decorator.viewport;
|
|
28
|
+
this.toolbarProps = HyperModeling.markerHandler.getToolbarProps(marker, decorator);
|
|
29
|
+
this.onToolbarItemExecuted = (id) => HyperModeling.markerHandler.executeCommand(id, marker, decorator); // eslint-disable-line @typescript-eslint/promise-function-async
|
|
30
|
+
}
|
|
31
|
+
get overToolbarHotspot() {
|
|
32
|
+
return this.marker.isHilited;
|
|
33
|
+
}
|
|
34
|
+
get toolbarLocation() {
|
|
35
|
+
return IModelApp.uiAdmin.createXAndY(this.marker.rect.right, this.marker.rect.top);
|
|
36
|
+
}
|
|
37
|
+
get htmlElement() {
|
|
38
|
+
return this._viewport.canvas;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** A [Decorator]($frontend) that displays a [[SectionMarker]] for each [SectionDrawingLocation]($backend) in the view.
|
|
42
|
+
* Clicking on a marker toggles the section and the display of associated 2d graphics.
|
|
43
|
+
* Hovering over a marker opens a mini toolbar with additional interactions.
|
|
44
|
+
* @see [[SectionMarkerHandler]] to customize the marker interactions.
|
|
45
|
+
* @see [[HyperModeling.startOrStop]] to enable or disable the decorator for a viewport.
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export class HyperModelingDecorator {
|
|
49
|
+
constructor(markers, config) {
|
|
50
|
+
this._removeEventListeners = new Array();
|
|
51
|
+
this._needSync = false;
|
|
52
|
+
/** @internal */
|
|
53
|
+
this.syncImmediately = false;
|
|
54
|
+
/** @internal */
|
|
55
|
+
this.useCachedDecorations = true;
|
|
56
|
+
this.markers = markers;
|
|
57
|
+
this._config = { ...config };
|
|
58
|
+
this._iModel = this.viewport.iModel;
|
|
59
|
+
this.viewport.onChangeView.addOnce(() => {
|
|
60
|
+
this.requestSync();
|
|
61
|
+
});
|
|
62
|
+
this._removeEventListeners.push(this.viewport.onViewportChanged.addListener((_, changeFlags) => this.onViewportChanged(changeFlags)));
|
|
63
|
+
this._removeEventListeners.push(this.viewport.onDisposed.addListener(() => this.dispose()));
|
|
64
|
+
for (const marker of markers.markers) {
|
|
65
|
+
marker.onMouseEnterEvent.addListener((mkr) => this.showToolbarAfterTimeout(mkr));
|
|
66
|
+
marker.onMouseButtonEvent.addListener((mkr) => this.toggleMarker(mkr)); // eslint-disable-line @typescript-eslint/promise-function-async
|
|
67
|
+
}
|
|
68
|
+
this.updateMarkerVisibility();
|
|
69
|
+
IModelApp.viewManager.addDecorator(this);
|
|
70
|
+
}
|
|
71
|
+
/** Create a new decorator and register it with the [ViewManager]($frontend). Typically invoked indirectly via [[HyperModeling.startOrStop]]. */
|
|
72
|
+
static async create(vp, config) {
|
|
73
|
+
const markers = await createMarkers(vp);
|
|
74
|
+
return undefined !== markers ? new HyperModelingDecorator(markers, config) : undefined;
|
|
75
|
+
}
|
|
76
|
+
/** Obtain the decorator associated with the specified viewport, if any. */
|
|
77
|
+
static getForViewport(vp) {
|
|
78
|
+
for (const decorator of IModelApp.viewManager.decorators)
|
|
79
|
+
if (decorator instanceof HyperModelingDecorator && decorator.viewport === vp)
|
|
80
|
+
return decorator;
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
/** The viewport into which this decorator draws its [[SectionMarker]]s. */
|
|
84
|
+
get viewport() {
|
|
85
|
+
return this.markers.viewport;
|
|
86
|
+
}
|
|
87
|
+
/** The currently active marker. A marker typically becomes active when the user clicks on it.
|
|
88
|
+
* @see [[setActiveMarker]] to change the active marker without user interaction.
|
|
89
|
+
*/
|
|
90
|
+
get activeMarker() {
|
|
91
|
+
return this._activeMarker;
|
|
92
|
+
}
|
|
93
|
+
/** @internal */
|
|
94
|
+
get config() {
|
|
95
|
+
return this._config;
|
|
96
|
+
}
|
|
97
|
+
/** Replaces the current marker display configuration, overwriting all previous settings. Passing `undefined` resets all settings to defaults.
|
|
98
|
+
* @see [[updateConfiguration]] to override specific aspects of the configuration
|
|
99
|
+
* @see [[HyperModeling.replaceConfiguration]] to replace the global configuration.
|
|
100
|
+
*/
|
|
101
|
+
replaceConfiguration(config) {
|
|
102
|
+
this._config = config ? { ...config } : {};
|
|
103
|
+
this.requestSync();
|
|
104
|
+
}
|
|
105
|
+
/** Overrides specific aspects of the current marker display configuration.
|
|
106
|
+
* Any field that is not `undefined` will be replaced in the current configuration; the rest will retain their current values.
|
|
107
|
+
* @see [[replaceConfiguration]] to override all settings.
|
|
108
|
+
* @see [[HyperModeling.updateConfiguration]] to update the global configuration.
|
|
109
|
+
*/
|
|
110
|
+
updateConfiguration(config) {
|
|
111
|
+
var _a, _b, _c;
|
|
112
|
+
this._config = {
|
|
113
|
+
ignoreModelSelector: (_a = config.ignoreModelSelector) !== null && _a !== void 0 ? _a : this._config.ignoreModelSelector,
|
|
114
|
+
ignoreCategorySelector: (_b = config.ignoreCategorySelector) !== null && _b !== void 0 ? _b : this._config.ignoreCategorySelector,
|
|
115
|
+
hiddenSectionTypes: (_c = config.hiddenSectionTypes) !== null && _c !== void 0 ? _c : this._config.hiddenSectionTypes,
|
|
116
|
+
};
|
|
117
|
+
this.requestSync();
|
|
118
|
+
}
|
|
119
|
+
/** Sets the currently active marker. This function is invoked when the user clicks on a marker, but may also be called manually to produce the same result.
|
|
120
|
+
* Changing the active marker first deactivates the currently active marker, if any; then activates the specified marker, if supplied.
|
|
121
|
+
* Returns false if marker activation fails.
|
|
122
|
+
* @see [[activeMarker]] to obtain the currently active section marker.
|
|
123
|
+
* @see [[SectionMarkerHandler.activateMarker]] to control what happens when a marker is activated.
|
|
124
|
+
* @see [[SectionMarkerHandler.deactivateMarker]] to control what happens when a marker is deactivated.
|
|
125
|
+
*/
|
|
126
|
+
async setActiveMarker(marker) {
|
|
127
|
+
if (marker === this.activeMarker)
|
|
128
|
+
return true;
|
|
129
|
+
if (this.activeMarker) {
|
|
130
|
+
this.activeMarker.setActive(false);
|
|
131
|
+
await HyperModeling.markerHandler.deactivateMarker(this.activeMarker, this);
|
|
132
|
+
this._activeMarker = undefined;
|
|
133
|
+
}
|
|
134
|
+
if (marker) {
|
|
135
|
+
if (!await HyperModeling.markerHandler.activateMarker(marker, this)) {
|
|
136
|
+
this.requestSync();
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
marker.setActive(true);
|
|
140
|
+
this._activeMarker = marker;
|
|
141
|
+
}
|
|
142
|
+
this.requestSync();
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
/** @internal */
|
|
146
|
+
decorate(context) {
|
|
147
|
+
if (this.viewport.view.is3d())
|
|
148
|
+
this.markers.addDecoration(context);
|
|
149
|
+
}
|
|
150
|
+
onViewportChanged(changeFlags) {
|
|
151
|
+
if (this.viewport.iModel !== this._iModel) {
|
|
152
|
+
this.dispose();
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (changeFlags.viewedCategories || changeFlags.viewedModels || changeFlags.viewedCategoriesPerModel)
|
|
156
|
+
this.requestSync();
|
|
157
|
+
if (changeFlags.viewState) {
|
|
158
|
+
// If we're looking at a different view now, and we did not initiate that, turn off the active marker.
|
|
159
|
+
if (this.viewport.view !== this._appliedSpatialView)
|
|
160
|
+
this.setActiveMarker(undefined); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
161
|
+
else
|
|
162
|
+
this._appliedSpatialView = undefined;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async toggleMarker(marker) {
|
|
166
|
+
await this.setActiveMarker(marker === this.activeMarker ? undefined : marker);
|
|
167
|
+
}
|
|
168
|
+
dropTiledGraphicsProvider() {
|
|
169
|
+
if (undefined === this._tiledGraphicsProvider)
|
|
170
|
+
return;
|
|
171
|
+
this.viewport.dropTiledGraphicsProvider(this._tiledGraphicsProvider);
|
|
172
|
+
this._tiledGraphicsProvider = undefined;
|
|
173
|
+
}
|
|
174
|
+
/** @internal */
|
|
175
|
+
dispose() {
|
|
176
|
+
if (!IModelApp.viewManager.dropDecorator(this))
|
|
177
|
+
return;
|
|
178
|
+
for (const remove of this._removeEventListeners)
|
|
179
|
+
remove();
|
|
180
|
+
this.dropTiledGraphicsProvider();
|
|
181
|
+
}
|
|
182
|
+
showToolbarAfterTimeout(marker) {
|
|
183
|
+
var _a;
|
|
184
|
+
if (((_a = this._toolbarProvider) === null || _a === void 0 ? void 0 : _a.marker) !== marker)
|
|
185
|
+
this._toolbarProvider = new MarkerToolbarProvider(marker, this);
|
|
186
|
+
PopupToolbarManager.showToolbarAfterTimeout(this._toolbarProvider);
|
|
187
|
+
}
|
|
188
|
+
/** Toggles whether the clip volume associated with the specified marker is applied to the view. */
|
|
189
|
+
toggleClipVolume(marker, enable) {
|
|
190
|
+
ViewClipTool.enableClipVolume(this.viewport);
|
|
191
|
+
ViewClipTool.setViewClip(this.viewport, enable ? marker.state.clip : undefined);
|
|
192
|
+
}
|
|
193
|
+
/** Toggles the specified section marker.
|
|
194
|
+
* Enabling the section applies the frustum and clip volume of the marker's spatial view to the viewport, and displays the 2d section graphics and sheet annotations.
|
|
195
|
+
* Disabling the section disables the clip volume and 2d graphics.
|
|
196
|
+
* @see [[toggleClipVolume]] to toggle only the clip volume.
|
|
197
|
+
* @see [[toggleAttachment]] to toggle only the attachment graphics.
|
|
198
|
+
*/
|
|
199
|
+
async toggleSection(marker, enable) {
|
|
200
|
+
if (enable) {
|
|
201
|
+
if (this.viewport.view.is3d()) {
|
|
202
|
+
// Preserve the view settings; apply only the frustum and clip volume
|
|
203
|
+
const spatialView = await marker.state.tryLoadSpatialView();
|
|
204
|
+
if (!spatialView)
|
|
205
|
+
return false;
|
|
206
|
+
const aligned = await this.alignToSpatialView(marker);
|
|
207
|
+
if (!aligned)
|
|
208
|
+
return false;
|
|
209
|
+
this.toggleClipVolume(marker, true);
|
|
210
|
+
}
|
|
211
|
+
else if (!await this.applySpatialView(marker)) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
this.toggleClipVolume(marker, false);
|
|
217
|
+
}
|
|
218
|
+
this.requestSync();
|
|
219
|
+
return this.toggleAttachment(marker, enable);
|
|
220
|
+
}
|
|
221
|
+
/** Toggles display of 2d section graphics and sheet annotations for the specified marker.
|
|
222
|
+
* @see [[toggleSection]] to apply the spatial view and clip volume in addition to the attachment graphics.
|
|
223
|
+
*/
|
|
224
|
+
async toggleAttachment(marker, enable) {
|
|
225
|
+
this.dropTiledGraphicsProvider();
|
|
226
|
+
if (enable) {
|
|
227
|
+
this._tiledGraphicsProvider = await createSectionGraphicsProvider(marker.state);
|
|
228
|
+
this.viewport.addTiledGraphicsProvider(this._tiledGraphicsProvider);
|
|
229
|
+
}
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
/** Aligns the viewport to face the specified marker's section plane. */
|
|
233
|
+
alignView(marker) {
|
|
234
|
+
const placement = marker.state.placement.transform;
|
|
235
|
+
const origin = placement.origin;
|
|
236
|
+
const matrix = placement.matrix;
|
|
237
|
+
const vp = this.viewport;
|
|
238
|
+
const targetMatrix = matrix.multiplyMatrixMatrix(vp.rotation);
|
|
239
|
+
const rotateTransform = Transform.createFixedPointAndMatrix(origin, targetMatrix);
|
|
240
|
+
const startFrustum = vp.getFrustum();
|
|
241
|
+
const newFrustum = startFrustum.clone();
|
|
242
|
+
newFrustum.multiply(rotateTransform);
|
|
243
|
+
if (startFrustum.equals(newFrustum))
|
|
244
|
+
return;
|
|
245
|
+
vp.view.setupFromFrustum(newFrustum);
|
|
246
|
+
vp.synchWithView();
|
|
247
|
+
vp.animateFrustumChange();
|
|
248
|
+
}
|
|
249
|
+
/** Opens the marker's drawing view in the decorator's viewport. Returns false if the drawing view could not be loaded. */
|
|
250
|
+
async openSection(marker) {
|
|
251
|
+
const viewState = await marker.state.tryLoadDrawingView();
|
|
252
|
+
if (viewState)
|
|
253
|
+
this.viewport.changeView(viewState);
|
|
254
|
+
return undefined !== viewState;
|
|
255
|
+
}
|
|
256
|
+
/** Opens marker's sheet view in the decorator's viewport and zooms in on the associated [ViewAttachment]($backend). Returns false if no view
|
|
257
|
+
* attachment exists or the sheet view could not be loaded.
|
|
258
|
+
*/
|
|
259
|
+
async openSheet(marker) {
|
|
260
|
+
if (undefined === marker.state.viewAttachment)
|
|
261
|
+
return false;
|
|
262
|
+
const viewState = await marker.state.tryLoadSheetView();
|
|
263
|
+
if (!viewState)
|
|
264
|
+
return false;
|
|
265
|
+
this.viewport.changeView(viewState);
|
|
266
|
+
await this.viewport.zoomToElements(marker.state.viewAttachment.id);
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
/** Aligns the view to match the frustum of the spatial view associated with the specified marker.
|
|
270
|
+
* @param marker The marker whose spatial view's frustum should be applied.
|
|
271
|
+
* @returns false if the frustum could not be applied, e.g. because the spatial view could not be loaded or the viewport is viewing a 2d model.
|
|
272
|
+
* @see [[alignView]] to align to the *section plane*, which may differ.
|
|
273
|
+
* @see [[toggleSection]] to also apply the clip volume.
|
|
274
|
+
*/
|
|
275
|
+
async alignToSpatialView(marker) {
|
|
276
|
+
if (!this.viewport.view.is3d())
|
|
277
|
+
return false;
|
|
278
|
+
const spatialView = await marker.state.tryLoadSpatialView();
|
|
279
|
+
if (!spatialView)
|
|
280
|
+
return false;
|
|
281
|
+
this.viewport.view.setOrigin(spatialView.getOrigin());
|
|
282
|
+
this.viewport.view.setExtents(spatialView.getExtents());
|
|
283
|
+
this.viewport.view.setRotation(spatialView.getRotation());
|
|
284
|
+
this.viewport.synchWithView({ animateFrustumChange: true });
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
/** Applies the marker's spatial view - including its clip volume - to the decorator's viewport.
|
|
288
|
+
* Returns false if the spatial view could not be loaded.
|
|
289
|
+
* @see [[toggleSection]].
|
|
290
|
+
* @see [[toggleClipVolume]].
|
|
291
|
+
*/
|
|
292
|
+
async applySpatialView(marker) {
|
|
293
|
+
const viewState = await marker.state.tryLoadSpatialView();
|
|
294
|
+
if (viewState) {
|
|
295
|
+
this._appliedSpatialView = viewState;
|
|
296
|
+
this.viewport.changeView(viewState);
|
|
297
|
+
}
|
|
298
|
+
return undefined !== viewState;
|
|
299
|
+
}
|
|
300
|
+
/** Request that the visibility of the section markers be recomputed. It is only necessary to call this if you have overridden [[SectionMarkerHandler.isMarkerVisible]]; if so, you should invoke
|
|
301
|
+
* this method when the criteria governing your `isMarkerVisible` method have changed.
|
|
302
|
+
*/
|
|
303
|
+
requestSync() {
|
|
304
|
+
if (this.syncImmediately) {
|
|
305
|
+
this.sync();
|
|
306
|
+
}
|
|
307
|
+
else if (!this._needSync) {
|
|
308
|
+
this._needSync = true;
|
|
309
|
+
requestAnimationFrame(() => this.sync());
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
sync() {
|
|
313
|
+
this._needSync = false;
|
|
314
|
+
if (HyperModeling.isInitialized && this.viewport.view.is3d() && this.updateMarkerVisibility()) {
|
|
315
|
+
this.markers.markDirty();
|
|
316
|
+
this.viewport.invalidateCachedDecorations(this);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
isMarkerVisible(marker) {
|
|
320
|
+
if (undefined !== this.activeMarker)
|
|
321
|
+
return marker === this.activeMarker;
|
|
322
|
+
return HyperModeling.markerHandler.isMarkerVisible(marker, this, this._config);
|
|
323
|
+
}
|
|
324
|
+
updateMarkerVisibility() {
|
|
325
|
+
let changed = false;
|
|
326
|
+
for (const marker of this.markers.markers) {
|
|
327
|
+
const wasVisible = marker.visible;
|
|
328
|
+
marker.visible = this.isMarkerVisible(marker);
|
|
329
|
+
changed = changed || (marker.visible !== wasVisible);
|
|
330
|
+
}
|
|
331
|
+
return changed;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
334
|
//# sourceMappingURL=HyperModelingDecorator.js.map
|