@itwin/hypermodeling-frontend 4.0.0-dev.8 → 4.0.0-dev.80
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/CHANGELOG.md +43 -1
- package/lib/cjs/HyperModeling.d.ts +114 -114
- package/lib/cjs/HyperModeling.js +237 -239
- package/lib/cjs/HyperModeling.js.map +1 -1
- package/lib/cjs/HyperModelingConfig.d.ts +54 -54
- package/lib/cjs/HyperModelingConfig.js +9 -9
- package/lib/cjs/HyperModelingDecorator.d.ts +110 -110
- package/lib/cjs/HyperModelingDecorator.js +335 -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 +106 -107
- package/lib/cjs/SectionDrawingLocationState.js.map +1 -1
- package/lib/cjs/SectionGraphicsProvider.d.ts +13 -13
- package/lib/cjs/SectionGraphicsProvider.js +272 -273
- package/lib/cjs/SectionGraphicsProvider.js.map +1 -1
- package/lib/cjs/SectionMarkerHandler.d.ts +52 -52
- package/lib/cjs/SectionMarkerHandler.js +111 -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/Tools.d.ts +5 -5
- package/lib/cjs/Tools.js +170 -170
- package/lib/cjs/Tools.js.map +1 -1
- package/lib/cjs/hypermodeling-frontend.d.ts +13 -13
- package/lib/cjs/hypermodeling-frontend.js +33 -29
- package/lib/cjs/hypermodeling-frontend.js.map +1 -1
- package/lib/esm/HyperModeling.d.ts +114 -114
- package/lib/esm/HyperModeling.js +234 -235
- package/lib/esm/HyperModeling.js.map +1 -1
- package/lib/esm/HyperModelingConfig.d.ts +54 -54
- package/lib/esm/HyperModelingConfig.js +8 -8
- package/lib/esm/HyperModelingDecorator.d.ts +110 -110
- package/lib/esm/HyperModelingDecorator.js +331 -333
- package/lib/esm/HyperModelingDecorator.js.map +1 -1
- package/lib/esm/PopupToolbar.d.ts +24 -24
- package/lib/esm/PopupToolbar.js +54 -53
- package/lib/esm/PopupToolbar.js.map +1 -1
- package/lib/esm/SectionDrawingLocationState.d.ts +90 -90
- package/lib/esm/SectionDrawingLocationState.js +102 -103
- package/lib/esm/SectionDrawingLocationState.js.map +1 -1
- package/lib/esm/SectionGraphicsProvider.d.ts +13 -13
- package/lib/esm/SectionGraphicsProvider.js +268 -269
- package/lib/esm/SectionGraphicsProvider.js.map +1 -1
- package/lib/esm/SectionMarkerHandler.d.ts +52 -52
- package/lib/esm/SectionMarkerHandler.js +107 -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/Tools.d.ts +5 -5
- package/lib/esm/Tools.js +166 -166
- package/lib/esm/Tools.js.map +1 -1
- package/lib/esm/hypermodeling-frontend.d.ts +13 -13
- package/lib/esm/hypermodeling-frontend.js +17 -17
- package/package.json +20 -20
package/lib/cjs/HyperModeling.js
CHANGED
|
@@ -1,240 +1,238 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
/** @packageDocumentation
|
|
7
|
-
* @module HyperModeling
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.HyperModeling = void 0;
|
|
11
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
-
const core_common_1 = require("@itwin/core-common");
|
|
13
|
-
const core_frontend_1 = require("@itwin/core-frontend");
|
|
14
|
-
const Tools_1 = require("./Tools");
|
|
15
|
-
const HyperModelingDecorator_1 = require("./HyperModelingDecorator");
|
|
16
|
-
const SectionMarkerHandler_1 = require("./SectionMarkerHandler");
|
|
17
|
-
function assertInitialized(maybe) {
|
|
18
|
-
if (undefined === maybe.resources)
|
|
19
|
-
throw new Error("You must call HyperModeling.initialize before using the hypermodeling package");
|
|
20
|
-
}
|
|
21
|
-
/** The API entry point for the hypermodeling package. Applications must call [[initialize]] and await the result before using the package.
|
|
22
|
-
* The behavior of the package can be customized via a [[HyperModelingConfig]] supplied to [[initialize]], [[updateConfiguration]], or [[replaceConfiguration]].
|
|
23
|
-
* Hypermodeling mode can be enabled or disabled via [[startOrStop]], which returns a [[HyperModelingDecorator]] when enabling hypermodeling.
|
|
24
|
-
* Consult the package's `README.md` for a description of the available functionality.
|
|
25
|
-
* @public
|
|
26
|
-
*/
|
|
27
|
-
class HyperModeling {
|
|
28
|
-
static shutdown() {
|
|
29
|
-
this.resources = undefined;
|
|
30
|
-
this._markerHandler = undefined;
|
|
31
|
-
this._markerConfig = {};
|
|
32
|
-
this._graphicsConfig = {};
|
|
33
|
-
}
|
|
34
|
-
/** Returns whether the hypermodeling package is initialized.
|
|
35
|
-
* @see [[HyperModeling.initialize]] to initialize the package.
|
|
36
|
-
*/
|
|
37
|
-
static get isInitialized() {
|
|
38
|
-
return undefined !== this.resources;
|
|
39
|
-
}
|
|
40
|
-
/** Invoke this method to initialize the hypermodeling package for use. You *must* await the result before using any of this package's APIs.
|
|
41
|
-
* Typically an application would invoke this after [IModelApp.startup]($frontend), e.g.,
|
|
42
|
-
* ```ts
|
|
43
|
-
* await IModelApp.startup();
|
|
44
|
-
* await HyperModeling.initialize();
|
|
45
|
-
* ```
|
|
46
|
-
* Calling this method again after the first initialization behaves the same as calling [[HyperModeling.replaceConfiguration]].
|
|
47
|
-
* @note The hypermodeling package will be reset to uninitialized after [IModelApp.shutdown]($frontend) is invoked.
|
|
48
|
-
* @see [[replaceConfiguration]] and [[updateConfiguration]] to modify the configuration after initialization.
|
|
49
|
-
*/
|
|
50
|
-
static async initialize(config) {
|
|
51
|
-
if (undefined !== this.resources) {
|
|
52
|
-
this.replaceConfiguration(config);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
// clean up if we're being shut down
|
|
56
|
-
core_frontend_1.IModelApp.onBeforeShutdown.addListener(() => this.shutdown());
|
|
57
|
-
const namespace = "HyperModeling";
|
|
58
|
-
await core_frontend_1.IModelApp.localization.registerNamespace(namespace);
|
|
59
|
-
const loadImages = [
|
|
60
|
-
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}section-marker.svg`),
|
|
61
|
-
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}detail-marker.svg`),
|
|
62
|
-
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}elevation-marker.svg`),
|
|
63
|
-
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}plan-marker.svg`),
|
|
64
|
-
];
|
|
65
|
-
const images = await Promise.all(loadImages);
|
|
66
|
-
this.resources = {
|
|
67
|
-
namespace,
|
|
68
|
-
markers: {
|
|
69
|
-
section: { image: images[0], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.SectionCallout") },
|
|
70
|
-
detail: { image: images[1], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.DetailCallout") },
|
|
71
|
-
elevation: { image: images[2], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.ElevationCallout") },
|
|
72
|
-
plan: { image: images[3], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.PlanCallout") },
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
(0, Tools_1.registerTools)(namespace);
|
|
76
|
-
this.replaceConfiguration(config);
|
|
77
|
-
}
|
|
78
|
-
static async ensureInitialized() {
|
|
79
|
-
if (undefined === this.resources)
|
|
80
|
-
await this.initialize();
|
|
81
|
-
assertInitialized(this);
|
|
82
|
-
}
|
|
83
|
-
/** Replaces the current package configuration, overwriting all previous settings. Passing `undefined` resets all settings to defaults.
|
|
84
|
-
* @see [[HyperModeling.updateConfiguration]] for overriding specific aspects of the configuration.
|
|
85
|
-
*/
|
|
86
|
-
static replaceConfiguration(config) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.
|
|
90
|
-
this.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
* @see [[
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* @
|
|
164
|
-
* @
|
|
165
|
-
* @
|
|
166
|
-
* @
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
*
|
|
186
|
-
* @
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
viewport.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
case core_common_1.SectionType.
|
|
227
|
-
return this.resources.markers.
|
|
228
|
-
case core_common_1.SectionType.
|
|
229
|
-
return this.resources.markers.
|
|
230
|
-
|
|
231
|
-
return this.resources.markers.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
exports.HyperModeling = HyperModeling;
|
|
238
|
-
HyperModeling._markerConfig = {};
|
|
239
|
-
HyperModeling._graphicsConfig = {};
|
|
1
|
+
"use strict";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
/** @packageDocumentation
|
|
7
|
+
* @module HyperModeling
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.HyperModeling = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const core_common_1 = require("@itwin/core-common");
|
|
13
|
+
const core_frontend_1 = require("@itwin/core-frontend");
|
|
14
|
+
const Tools_1 = require("./Tools");
|
|
15
|
+
const HyperModelingDecorator_1 = require("./HyperModelingDecorator");
|
|
16
|
+
const SectionMarkerHandler_1 = require("./SectionMarkerHandler");
|
|
17
|
+
function assertInitialized(maybe) {
|
|
18
|
+
if (undefined === maybe.resources)
|
|
19
|
+
throw new Error("You must call HyperModeling.initialize before using the hypermodeling package");
|
|
20
|
+
}
|
|
21
|
+
/** The API entry point for the hypermodeling package. Applications must call [[initialize]] and await the result before using the package.
|
|
22
|
+
* The behavior of the package can be customized via a [[HyperModelingConfig]] supplied to [[initialize]], [[updateConfiguration]], or [[replaceConfiguration]].
|
|
23
|
+
* Hypermodeling mode can be enabled or disabled via [[startOrStop]], which returns a [[HyperModelingDecorator]] when enabling hypermodeling.
|
|
24
|
+
* Consult the package's `README.md` for a description of the available functionality.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
class HyperModeling {
|
|
28
|
+
static shutdown() {
|
|
29
|
+
this.resources = undefined;
|
|
30
|
+
this._markerHandler = undefined;
|
|
31
|
+
this._markerConfig = {};
|
|
32
|
+
this._graphicsConfig = {};
|
|
33
|
+
}
|
|
34
|
+
/** Returns whether the hypermodeling package is initialized.
|
|
35
|
+
* @see [[HyperModeling.initialize]] to initialize the package.
|
|
36
|
+
*/
|
|
37
|
+
static get isInitialized() {
|
|
38
|
+
return undefined !== this.resources;
|
|
39
|
+
}
|
|
40
|
+
/** Invoke this method to initialize the hypermodeling package for use. You *must* await the result before using any of this package's APIs.
|
|
41
|
+
* Typically an application would invoke this after [IModelApp.startup]($frontend), e.g.,
|
|
42
|
+
* ```ts
|
|
43
|
+
* await IModelApp.startup();
|
|
44
|
+
* await HyperModeling.initialize();
|
|
45
|
+
* ```
|
|
46
|
+
* Calling this method again after the first initialization behaves the same as calling [[HyperModeling.replaceConfiguration]].
|
|
47
|
+
* @note The hypermodeling package will be reset to uninitialized after [IModelApp.shutdown]($frontend) is invoked.
|
|
48
|
+
* @see [[replaceConfiguration]] and [[updateConfiguration]] to modify the configuration after initialization.
|
|
49
|
+
*/
|
|
50
|
+
static async initialize(config) {
|
|
51
|
+
if (undefined !== this.resources) {
|
|
52
|
+
this.replaceConfiguration(config);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// clean up if we're being shut down
|
|
56
|
+
core_frontend_1.IModelApp.onBeforeShutdown.addListener(() => this.shutdown());
|
|
57
|
+
const namespace = "HyperModeling";
|
|
58
|
+
await core_frontend_1.IModelApp.localization.registerNamespace(namespace);
|
|
59
|
+
const loadImages = [
|
|
60
|
+
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}section-marker.svg`),
|
|
61
|
+
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}detail-marker.svg`),
|
|
62
|
+
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}elevation-marker.svg`),
|
|
63
|
+
(0, core_frontend_1.tryImageElementFromUrl)(`${core_frontend_1.IModelApp.publicPath}plan-marker.svg`),
|
|
64
|
+
];
|
|
65
|
+
const images = await Promise.all(loadImages);
|
|
66
|
+
this.resources = {
|
|
67
|
+
namespace,
|
|
68
|
+
markers: {
|
|
69
|
+
section: { image: images[0], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.SectionCallout") },
|
|
70
|
+
detail: { image: images[1], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.DetailCallout") },
|
|
71
|
+
elevation: { image: images[2], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.ElevationCallout") },
|
|
72
|
+
plan: { image: images[3], label: core_frontend_1.IModelApp.localization.getLocalizedString("HyperModeling:Message.PlanCallout") },
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
(0, Tools_1.registerTools)(namespace);
|
|
76
|
+
this.replaceConfiguration(config);
|
|
77
|
+
}
|
|
78
|
+
static async ensureInitialized() {
|
|
79
|
+
if (undefined === this.resources)
|
|
80
|
+
await this.initialize();
|
|
81
|
+
assertInitialized(this);
|
|
82
|
+
}
|
|
83
|
+
/** Replaces the current package configuration, overwriting all previous settings. Passing `undefined` resets all settings to defaults.
|
|
84
|
+
* @see [[HyperModeling.updateConfiguration]] for overriding specific aspects of the configuration.
|
|
85
|
+
*/
|
|
86
|
+
static replaceConfiguration(config) {
|
|
87
|
+
config = config ?? {};
|
|
88
|
+
this._markerHandler = config.markerHandler ?? new SectionMarkerHandler_1.SectionMarkerHandler();
|
|
89
|
+
this._markerConfig = config.markers ? { ...config.markers } : {};
|
|
90
|
+
this._graphicsConfig = config.graphics ? { ...config.graphics } : {};
|
|
91
|
+
}
|
|
92
|
+
/** Overrides specific aspects of the current package configuration. Any field that is not `undefined` will be replaced in the current configuration;
|
|
93
|
+
* the rest will retain their current values.
|
|
94
|
+
* @see [[HyperModeling.replaceConfiguration]].
|
|
95
|
+
*/
|
|
96
|
+
static updateConfiguration(config) {
|
|
97
|
+
this._markerHandler = config.markerHandler ?? this._markerHandler;
|
|
98
|
+
if (config.markers) {
|
|
99
|
+
this._markerConfig = {
|
|
100
|
+
ignoreModelSelector: config.markers.ignoreModelSelector ?? this._markerConfig.ignoreModelSelector,
|
|
101
|
+
ignoreCategorySelector: config.markers.ignoreCategorySelector ?? this._markerConfig.ignoreCategorySelector,
|
|
102
|
+
hiddenSectionTypes: config.markers.hiddenSectionTypes ?? this._markerConfig.hiddenSectionTypes,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (config.graphics) {
|
|
106
|
+
this._graphicsConfig = {
|
|
107
|
+
ignoreClip: config.graphics.ignoreClip ?? this._graphicsConfig.ignoreClip,
|
|
108
|
+
debugClipVolumes: config.graphics.debugClipVolumes ?? this._graphicsConfig.debugClipVolumes,
|
|
109
|
+
hideSectionGraphics: config.graphics.hideSectionGraphics ?? this._graphicsConfig.hideSectionGraphics,
|
|
110
|
+
hideSheetAnnotations: config.graphics.hideSheetAnnotations ?? this._graphicsConfig.hideSheetAnnotations,
|
|
111
|
+
};
|
|
112
|
+
core_frontend_1.IModelApp.viewManager.invalidateViewportScenes();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** The handler that defines interactions with [[SectionMarker]]s.
|
|
116
|
+
* @see [[initialize]] to override the default handler at package initialization.
|
|
117
|
+
* @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current handler.
|
|
118
|
+
*/
|
|
119
|
+
static get markerHandler() {
|
|
120
|
+
assertInitialized(this);
|
|
121
|
+
(0, core_bentley_1.assert)(undefined !== this._markerHandler);
|
|
122
|
+
return this._markerHandler;
|
|
123
|
+
}
|
|
124
|
+
/** The current marker display configuration applied to any newly-created [[HyperModelingDecorator]]s.
|
|
125
|
+
* @see [[initialize]] to override the default configuration at package initialization.
|
|
126
|
+
* @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current configuration.
|
|
127
|
+
* @see [[HyperModelingDecorator.replaceConfiguration]] or [[HyperModelingDecorator.updateConfiguration]] to change the configuration for an existing decorator.
|
|
128
|
+
*/
|
|
129
|
+
static get markerConfig() {
|
|
130
|
+
return this._markerConfig;
|
|
131
|
+
}
|
|
132
|
+
/** This graphics options applied to graphics displayed by all [[HyperModelingDecorator]]s.
|
|
133
|
+
* @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current configuration.
|
|
134
|
+
*/
|
|
135
|
+
static get graphicsConfig() {
|
|
136
|
+
return this._graphicsConfig;
|
|
137
|
+
}
|
|
138
|
+
/** Returns true if the specified iModel contains any [SectionDrawingLocation]($backend)s. Hypermodeling is based on section drawing locations,
|
|
139
|
+
* so if none are present, hypermodeling features are not relevant to the iModel. Attempting to use those features with such an iModel is fine,
|
|
140
|
+
* but probably not useful.
|
|
141
|
+
*/
|
|
142
|
+
static async isSupportedForIModel(imodel) {
|
|
143
|
+
try {
|
|
144
|
+
const reader = imodel.createQueryReader("SELECT ECInstanceId FROM bis.SectionDrawingLocation LIMIT 1");
|
|
145
|
+
return await reader.step(); // i.e., are any results are returned?
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// An iModel with a version of BisCore older than 1.0.11 will produce an expected "table not found" on the SectionDrawingLocation ECClass.
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Returns whether hypermodeling is currently enabled for the specified viewport.
|
|
153
|
+
* @see [[startOrStop]] to enable or disable hypermodeling for a viewport.
|
|
154
|
+
*/
|
|
155
|
+
static isEnabledForViewport(viewport) {
|
|
156
|
+
return undefined !== HyperModelingDecorator_1.HyperModelingDecorator.getForViewport(viewport);
|
|
157
|
+
}
|
|
158
|
+
/** Start or stop hypermodeling mode for the specified viewport.
|
|
159
|
+
* Enabling hypermodeling registers and returns a [[HyperModelingDecorator]] to display [[SectionMarker]]s within the viewport.
|
|
160
|
+
* Disabling hypermodeling removes that decorator.
|
|
161
|
+
* @param viewport The hypermodeling viewport
|
|
162
|
+
* @param start `true` to enter hypermodeling mode, `false` to exit, or `undefined` to toggle the current mode.
|
|
163
|
+
* @returns The new decorator is hypermodeling was successfully enabled.
|
|
164
|
+
* @note Enabling hypermodeling may fail if the viewport is not viewing a spatial model or if the viewport's iModel does not support hypermodeling.
|
|
165
|
+
* @see [[start]] and [[stop]].
|
|
166
|
+
* @see [[isSupportedForIModel]].
|
|
167
|
+
*/
|
|
168
|
+
static async startOrStop(viewport, start) {
|
|
169
|
+
// Help out the caller since we're async anyway...
|
|
170
|
+
await this.ensureInitialized();
|
|
171
|
+
const decorator = HyperModelingDecorator_1.HyperModelingDecorator.getForViewport(viewport);
|
|
172
|
+
if (undefined === start)
|
|
173
|
+
start = undefined === decorator;
|
|
174
|
+
if (start) {
|
|
175
|
+
return this._start(viewport);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
decorator?.dispose();
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** Start hypermodeling mode for the specified viewport if it is not currently enabled.
|
|
183
|
+
* If hypermodeling is already enabled for the viewport, the existing decorator is returned; otherwise, a new decorator is created.
|
|
184
|
+
* @param viewport The viewport for which to enable hypermodeling
|
|
185
|
+
* @returns The decorator that implements hypermodeling features for the viewport, or `undefined` if hypermodeling could not be enabled.
|
|
186
|
+
* @note Enabling hypermodeling may fail if the viewport is not viewing a spatial model or if the viewport's iModel does not support hypermodeling.
|
|
187
|
+
*/
|
|
188
|
+
static async start(viewport) {
|
|
189
|
+
await this.ensureInitialized();
|
|
190
|
+
return this._start(viewport);
|
|
191
|
+
}
|
|
192
|
+
static async _start(viewport) {
|
|
193
|
+
assertInitialized(this);
|
|
194
|
+
if (!viewport.view.isSpatialView())
|
|
195
|
+
return undefined;
|
|
196
|
+
let decorator = HyperModelingDecorator_1.HyperModelingDecorator.getForViewport(viewport);
|
|
197
|
+
if (!decorator)
|
|
198
|
+
decorator = await HyperModelingDecorator_1.HyperModelingDecorator.create(viewport, this._markerConfig);
|
|
199
|
+
if (undefined !== decorator && viewport.view.isCameraOn) {
|
|
200
|
+
// We want the 2d graphics to align with the 3d geometry. Perspective ruins that.
|
|
201
|
+
viewport.view.turnCameraOff();
|
|
202
|
+
core_frontend_1.ViewManip.fitView(viewport, false, { noSaveInUndo: true });
|
|
203
|
+
viewport.clearViewUndo();
|
|
204
|
+
}
|
|
205
|
+
return decorator;
|
|
206
|
+
}
|
|
207
|
+
/** Stop hypermodeling mode for the specified viewport if it is currently enabled. This disposes of the [[HyperModelingDecorator]] associated with the viewport.
|
|
208
|
+
* @see [[start]] to enable hypermodeling for a viewport.
|
|
209
|
+
* @see [[startOrStop]] to toggle hypermodeling mode.
|
|
210
|
+
*/
|
|
211
|
+
static stop(viewport) {
|
|
212
|
+
const decorator = HyperModelingDecorator_1.HyperModelingDecorator.getForViewport(viewport);
|
|
213
|
+
decorator?.dispose();
|
|
214
|
+
}
|
|
215
|
+
/** @internal */
|
|
216
|
+
static get namespace() {
|
|
217
|
+
assertInitialized(this);
|
|
218
|
+
return this.resources.namespace;
|
|
219
|
+
}
|
|
220
|
+
/** @internal */
|
|
221
|
+
static getMarkerData(type) {
|
|
222
|
+
assertInitialized(this);
|
|
223
|
+
switch (type) {
|
|
224
|
+
case core_common_1.SectionType.Plan:
|
|
225
|
+
return this.resources.markers.plan;
|
|
226
|
+
case core_common_1.SectionType.Elevation:
|
|
227
|
+
return this.resources.markers.elevation;
|
|
228
|
+
case core_common_1.SectionType.Detail:
|
|
229
|
+
return this.resources.markers.detail;
|
|
230
|
+
default:
|
|
231
|
+
return this.resources.markers.section;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
HyperModeling._markerConfig = {};
|
|
236
|
+
HyperModeling._graphicsConfig = {};
|
|
237
|
+
exports.HyperModeling = HyperModeling;
|
|
240
238
|
//# sourceMappingURL=HyperModeling.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HyperModeling.js","sourceRoot":"","sources":["../../src/HyperModeling.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,oDAAiD;AACjD,wDAAsH;AACtH,mCAAwC;AACxC,qEAAkE;AAElE,iEAA8D;AA0B9D,SAAS,iBAAiB,CAAC,KAAuB;IAChD,IAAI,SAAS,KAAK,KAAK,CAAC,SAAS;QAC/B,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC,CAAC;AACrG,CAAC;AAED;;;;;GAKG;AACH,MAAa,aAAa;IAOhB,MAAM,CAAC,QAAQ;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CA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,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;YAC1C,KAAK,yBAAW,CAAC,MAAM;gBACrB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC;YACvC;gBACE,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;SACzC;IACH,CAAC;;AAhPH,sCAiPC;AA7OgB,2BAAa,GAAwB,EAAE,CAAC;AACxC,6BAAe,GAA0B,EAAE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module HyperModeling\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { SectionType } from \"@itwin/core-common\";\r\nimport { IModelApp, IModelConnection, ScreenViewport, tryImageElementFromUrl, ViewManip } from \"@itwin/core-frontend\";\r\nimport { registerTools } from \"./Tools\";\r\nimport { HyperModelingDecorator } from \"./HyperModelingDecorator\";\r\nimport { HyperModelingConfig, SectionGraphicsConfig, SectionMarkerConfig } from \"./HyperModelingConfig\";\r\nimport { SectionMarkerHandler } from \"./SectionMarkerHandler\";\r\n\r\n/** @internal */\r\nexport interface MarkerData {\r\n readonly label: string;\r\n readonly image: HTMLImageElement | undefined;\r\n}\r\n\r\ninterface Resources {\r\n readonly namespace?: string;\r\n readonly markers: {\r\n readonly section: MarkerData;\r\n readonly plan: MarkerData;\r\n readonly elevation: MarkerData;\r\n readonly detail: MarkerData;\r\n };\r\n}\r\n\r\ninterface MaybeInitialized {\r\n resources?: Resources;\r\n}\r\n\r\ninterface Initialized {\r\n resources: Resources;\r\n}\r\n\r\nfunction assertInitialized(maybe: MaybeInitialized): asserts maybe is Initialized {\r\n if (undefined === maybe.resources)\r\n throw new Error(\"You must call HyperModeling.initialize before using the hypermodeling package\");\r\n}\r\n\r\n/** The API entry point for the hypermodeling package. Applications must call [[initialize]] and await the result before using the package.\r\n * The behavior of the package can be customized via a [[HyperModelingConfig]] supplied to [[initialize]], [[updateConfiguration]], or [[replaceConfiguration]].\r\n * Hypermodeling mode can be enabled or disabled via [[startOrStop]], which returns a [[HyperModelingDecorator]] when enabling hypermodeling.\r\n * Consult the package's `README.md` for a description of the available functionality.\r\n * @public\r\n */\r\nexport class HyperModeling {\r\n /** @internal */\r\n public static resources?: Resources;\r\n private static _markerHandler?: SectionMarkerHandler;\r\n private static _markerConfig: SectionMarkerConfig = {};\r\n private static _graphicsConfig: SectionGraphicsConfig = {};\r\n\r\n private static shutdown() {\r\n this.resources = undefined;\r\n this._markerHandler = undefined;\r\n this._markerConfig = {};\r\n this._graphicsConfig = {};\r\n }\r\n\r\n /** Returns whether the hypermodeling package is initialized.\r\n * @see [[HyperModeling.initialize]] to initialize the package.\r\n */\r\n public static get isInitialized(): boolean {\r\n return undefined !== this.resources;\r\n }\r\n\r\n /** Invoke this method to initialize the hypermodeling package for use. You *must* await the result before using any of this package's APIs.\r\n * Typically an application would invoke this after [IModelApp.startup]($frontend), e.g.,\r\n * ```ts\r\n * await IModelApp.startup();\r\n * await HyperModeling.initialize();\r\n * ```\r\n * Calling this method again after the first initialization behaves the same as calling [[HyperModeling.replaceConfiguration]].\r\n * @note The hypermodeling package will be reset to uninitialized after [IModelApp.shutdown]($frontend) is invoked.\r\n * @see [[replaceConfiguration]] and [[updateConfiguration]] to modify the configuration after initialization.\r\n */\r\n public static async initialize(config?: HyperModelingConfig): Promise<void> {\r\n if (undefined !== this.resources) {\r\n this.replaceConfiguration(config);\r\n return;\r\n }\r\n\r\n // clean up if we're being shut down\r\n IModelApp.onBeforeShutdown.addListener(() => this.shutdown());\r\n\r\n const namespace = \"HyperModeling\";\r\n await IModelApp.localization.registerNamespace(namespace);\r\n\r\n const loadImages = [\r\n tryImageElementFromUrl(`${IModelApp.publicPath}section-marker.svg`),\r\n tryImageElementFromUrl(`${IModelApp.publicPath}detail-marker.svg`),\r\n tryImageElementFromUrl(`${IModelApp.publicPath}elevation-marker.svg`),\r\n tryImageElementFromUrl(`${IModelApp.publicPath}plan-marker.svg`),\r\n ];\r\n\r\n const images = await Promise.all(loadImages);\r\n this.resources = {\r\n namespace,\r\n markers: {\r\n section: { image: images[0], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.SectionCallout\") },\r\n detail: { image: images[1], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.DetailCallout\") },\r\n elevation: { image: images[2], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.ElevationCallout\") },\r\n plan: { image: images[3], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.PlanCallout\") },\r\n },\r\n };\r\n\r\n registerTools(namespace);\r\n this.replaceConfiguration(config);\r\n }\r\n\r\n private static async ensureInitialized(): Promise<void> {\r\n if (undefined === this.resources)\r\n await this.initialize();\r\n\r\n assertInitialized(this);\r\n }\r\n\r\n /** Replaces the current package configuration, overwriting all previous settings. Passing `undefined` resets all settings to defaults.\r\n * @see [[HyperModeling.updateConfiguration]] for overriding specific aspects of the configuration.\r\n */\r\n public static replaceConfiguration(config?: HyperModelingConfig): void {\r\n config = config ?? {};\r\n this._markerHandler = config.markerHandler ?? new SectionMarkerHandler();\r\n this._markerConfig = config.markers ? { ...config.markers } : {};\r\n this._graphicsConfig = config.graphics ? { ...config.graphics } : {};\r\n }\r\n\r\n /** Overrides specific aspects of the current package configuration. Any field that is not `undefined` will be replaced in the current configuration;\r\n * the rest will retain their current values.\r\n * @see [[HyperModeling.replaceConfiguration]].\r\n */\r\n public static updateConfiguration(config: HyperModelingConfig): void {\r\n this._markerHandler = config.markerHandler ?? this._markerHandler;\r\n\r\n if (config.markers) {\r\n this._markerConfig = {\r\n ignoreModelSelector: config.markers.ignoreModelSelector ?? this._markerConfig.ignoreModelSelector,\r\n ignoreCategorySelector: config.markers.ignoreCategorySelector ?? this._markerConfig.ignoreCategorySelector,\r\n hiddenSectionTypes: config.markers.hiddenSectionTypes ?? this._markerConfig.hiddenSectionTypes,\r\n };\r\n }\r\n\r\n if (config.graphics) {\r\n this._graphicsConfig = {\r\n ignoreClip: config.graphics.ignoreClip ?? this._graphicsConfig.ignoreClip,\r\n debugClipVolumes: config.graphics.debugClipVolumes ?? this._graphicsConfig.debugClipVolumes,\r\n hideSectionGraphics: config.graphics.hideSectionGraphics ?? this._graphicsConfig.hideSectionGraphics,\r\n hideSheetAnnotations: config.graphics.hideSheetAnnotations ?? this._graphicsConfig.hideSheetAnnotations,\r\n };\r\n\r\n IModelApp.viewManager.invalidateViewportScenes();\r\n }\r\n }\r\n\r\n /** The handler that defines interactions with [[SectionMarker]]s.\r\n * @see [[initialize]] to override the default handler at package initialization.\r\n * @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current handler.\r\n */\r\n public static get markerHandler(): SectionMarkerHandler {\r\n assertInitialized(this);\r\n assert(undefined !== this._markerHandler);\r\n return this._markerHandler;\r\n }\r\n\r\n /** The current marker display configuration applied to any newly-created [[HyperModelingDecorator]]s.\r\n * @see [[initialize]] to override the default configuration at package initialization.\r\n * @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current configuration.\r\n * @see [[HyperModelingDecorator.replaceConfiguration]] or [[HyperModelingDecorator.updateConfiguration]] to change the configuration for an existing decorator.\r\n */\r\n public static get markerConfig(): SectionMarkerConfig {\r\n return this._markerConfig;\r\n }\r\n\r\n /** This graphics options applied to graphics displayed by all [[HyperModelingDecorator]]s.\r\n * @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current configuration.\r\n */\r\n public static get graphicsConfig(): SectionGraphicsConfig {\r\n return this._graphicsConfig;\r\n }\r\n\r\n /** Returns true if the specified iModel contains any [SectionDrawingLocation]($backend)s. Hypermodeling is based on section drawing locations,\r\n * so if none are present, hypermodeling features are not relevant to the iModel. Attempting to use those features with such an iModel is fine,\r\n * but probably not useful.\r\n */\r\n public static async isSupportedForIModel(imodel: IModelConnection): Promise<boolean> {\r\n try {\r\n const nRows = await imodel.queryRowCount(\"SELECT ECInstanceId FROM bis.SectionDrawingLocation LIMIT 1\");\r\n return nRows > 0;\r\n } catch {\r\n // An iModel with a version of BisCore older than 1.0.11 will produce an expected \"table not found\" on the SectionDrawingLocation ECClass.\r\n return false;\r\n }\r\n }\r\n\r\n /** Returns whether hypermodeling is currently enabled for the specified viewport.\r\n * @see [[startOrStop]] to enable or disable hypermodeling for a viewport.\r\n */\r\n public static isEnabledForViewport(viewport: ScreenViewport): boolean {\r\n return undefined !== HyperModelingDecorator.getForViewport(viewport);\r\n }\r\n\r\n /** Start or stop hypermodeling mode for the specified viewport.\r\n * Enabling hypermodeling registers and returns a [[HyperModelingDecorator]] to display [[SectionMarker]]s within the viewport.\r\n * Disabling hypermodeling removes that decorator.\r\n * @param viewport The hypermodeling viewport\r\n * @param start `true` to enter hypermodeling mode, `false` to exit, or `undefined` to toggle the current mode.\r\n * @returns The new decorator is hypermodeling was successfully enabled.\r\n * @note Enabling hypermodeling may fail if the viewport is not viewing a spatial model or if the viewport's iModel does not support hypermodeling.\r\n * @see [[start]] and [[stop]].\r\n * @see [[isSupportedForIModel]].\r\n */\r\n public static async startOrStop(viewport: ScreenViewport, start?: boolean): Promise<HyperModelingDecorator | undefined> {\r\n // Help out the caller since we're async anyway...\r\n await this.ensureInitialized();\r\n\r\n const decorator = HyperModelingDecorator.getForViewport(viewport);\r\n if (undefined === start)\r\n start = undefined === decorator;\r\n\r\n if (start) {\r\n return this._start(viewport);\r\n } else {\r\n decorator?.dispose();\r\n return undefined;\r\n }\r\n }\r\n\r\n /** Start hypermodeling mode for the specified viewport if it is not currently enabled.\r\n * If hypermodeling is already enabled for the viewport, the existing decorator is returned; otherwise, a new decorator is created.\r\n * @param viewport The viewport for which to enable hypermodeling\r\n * @returns The decorator that implements hypermodeling features for the viewport, or `undefined` if hypermodeling could not be enabled.\r\n * @note Enabling hypermodeling may fail if the viewport is not viewing a spatial model or if the viewport's iModel does not support hypermodeling.\r\n */\r\n public static async start(viewport: ScreenViewport): Promise<HyperModelingDecorator | undefined> {\r\n await this.ensureInitialized();\r\n return this._start(viewport);\r\n }\r\n\r\n private static async _start(viewport: ScreenViewport): Promise<HyperModelingDecorator | undefined> {\r\n assertInitialized(this);\r\n if (!viewport.view.isSpatialView())\r\n return undefined;\r\n\r\n let decorator = HyperModelingDecorator.getForViewport(viewport);\r\n if (!decorator)\r\n decorator = await HyperModelingDecorator.create(viewport, this._markerConfig);\r\n\r\n if (undefined !== decorator && viewport.view.isCameraOn) {\r\n // We want the 2d graphics to align with the 3d geometry. Perspective ruins that.\r\n viewport.view.turnCameraOff();\r\n ViewManip.fitView(viewport, false, { noSaveInUndo: true });\r\n viewport.clearViewUndo();\r\n }\r\n\r\n return decorator;\r\n }\r\n\r\n /** Stop hypermodeling mode for the specified viewport if it is currently enabled. This disposes of the [[HyperModelingDecorator]] associated with the viewport.\r\n * @see [[start]] to enable hypermodeling for a viewport.\r\n * @see [[startOrStop]] to toggle hypermodeling mode.\r\n */\r\n public static stop(viewport: ScreenViewport): void {\r\n const decorator = HyperModelingDecorator.getForViewport(viewport);\r\n decorator?.dispose();\r\n }\r\n\r\n /** @internal */\r\n public static get namespace(): string | undefined {\r\n assertInitialized(this);\r\n return this.resources.namespace;\r\n }\r\n\r\n /** @internal */\r\n public static getMarkerData(type: SectionType): MarkerData {\r\n assertInitialized(this);\r\n switch (type) {\r\n case SectionType.Plan:\r\n return this.resources.markers.plan;\r\n case SectionType.Elevation:\r\n return this.resources.markers.elevation;\r\n case SectionType.Detail:\r\n return this.resources.markers.detail;\r\n default:\r\n return this.resources.markers.section;\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"HyperModeling.js","sourceRoot":"","sources":["../../src/HyperModeling.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA6C;AAC7C,oDAAiD;AACjD,wDAAsH;AACtH,mCAAwC;AACxC,qEAAkE;AAElE,iEAA8D;AA0B9D,S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gBACnB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC;YACrC,KAAK,yBAAW,CAAC,SAAS;gBACxB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC;YAC1C,KAAK,yBAAW,CAAC,MAAM;gBACrB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC;YACvC;gBACE,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;SACzC;IACH,CAAC;;AA5Oc,2BAAa,GAAwB,EAAE,CAAC;AACxC,6BAAe,GAA0B,EAAE,CAAC;AALhD,sCAAa","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module HyperModeling\r\n */\r\n\r\nimport { assert } from \"@itwin/core-bentley\";\r\nimport { SectionType } from \"@itwin/core-common\";\r\nimport { IModelApp, IModelConnection, ScreenViewport, tryImageElementFromUrl, ViewManip } from \"@itwin/core-frontend\";\r\nimport { registerTools } from \"./Tools\";\r\nimport { HyperModelingDecorator } from \"./HyperModelingDecorator\";\r\nimport { HyperModelingConfig, SectionGraphicsConfig, SectionMarkerConfig } from \"./HyperModelingConfig\";\r\nimport { SectionMarkerHandler } from \"./SectionMarkerHandler\";\r\n\r\n/** @internal */\r\nexport interface MarkerData {\r\n readonly label: string;\r\n readonly image: HTMLImageElement | undefined;\r\n}\r\n\r\ninterface Resources {\r\n readonly namespace?: string;\r\n readonly markers: {\r\n readonly section: MarkerData;\r\n readonly plan: MarkerData;\r\n readonly elevation: MarkerData;\r\n readonly detail: MarkerData;\r\n };\r\n}\r\n\r\ninterface MaybeInitialized {\r\n resources?: Resources;\r\n}\r\n\r\ninterface Initialized {\r\n resources: Resources;\r\n}\r\n\r\nfunction assertInitialized(maybe: MaybeInitialized): asserts maybe is Initialized {\r\n if (undefined === maybe.resources)\r\n throw new Error(\"You must call HyperModeling.initialize before using the hypermodeling package\");\r\n}\r\n\r\n/** The API entry point for the hypermodeling package. Applications must call [[initialize]] and await the result before using the package.\r\n * The behavior of the package can be customized via a [[HyperModelingConfig]] supplied to [[initialize]], [[updateConfiguration]], or [[replaceConfiguration]].\r\n * Hypermodeling mode can be enabled or disabled via [[startOrStop]], which returns a [[HyperModelingDecorator]] when enabling hypermodeling.\r\n * Consult the package's `README.md` for a description of the available functionality.\r\n * @public\r\n */\r\nexport class HyperModeling {\r\n /** @internal */\r\n public static resources?: Resources;\r\n private static _markerHandler?: SectionMarkerHandler;\r\n private static _markerConfig: SectionMarkerConfig = {};\r\n private static _graphicsConfig: SectionGraphicsConfig = {};\r\n\r\n private static shutdown() {\r\n this.resources = undefined;\r\n this._markerHandler = undefined;\r\n this._markerConfig = {};\r\n this._graphicsConfig = {};\r\n }\r\n\r\n /** Returns whether the hypermodeling package is initialized.\r\n * @see [[HyperModeling.initialize]] to initialize the package.\r\n */\r\n public static get isInitialized(): boolean {\r\n return undefined !== this.resources;\r\n }\r\n\r\n /** Invoke this method to initialize the hypermodeling package for use. You *must* await the result before using any of this package's APIs.\r\n * Typically an application would invoke this after [IModelApp.startup]($frontend), e.g.,\r\n * ```ts\r\n * await IModelApp.startup();\r\n * await HyperModeling.initialize();\r\n * ```\r\n * Calling this method again after the first initialization behaves the same as calling [[HyperModeling.replaceConfiguration]].\r\n * @note The hypermodeling package will be reset to uninitialized after [IModelApp.shutdown]($frontend) is invoked.\r\n * @see [[replaceConfiguration]] and [[updateConfiguration]] to modify the configuration after initialization.\r\n */\r\n public static async initialize(config?: HyperModelingConfig): Promise<void> {\r\n if (undefined !== this.resources) {\r\n this.replaceConfiguration(config);\r\n return;\r\n }\r\n\r\n // clean up if we're being shut down\r\n IModelApp.onBeforeShutdown.addListener(() => this.shutdown());\r\n\r\n const namespace = \"HyperModeling\";\r\n await IModelApp.localization.registerNamespace(namespace);\r\n\r\n const loadImages = [\r\n tryImageElementFromUrl(`${IModelApp.publicPath}section-marker.svg`),\r\n tryImageElementFromUrl(`${IModelApp.publicPath}detail-marker.svg`),\r\n tryImageElementFromUrl(`${IModelApp.publicPath}elevation-marker.svg`),\r\n tryImageElementFromUrl(`${IModelApp.publicPath}plan-marker.svg`),\r\n ];\r\n\r\n const images = await Promise.all(loadImages);\r\n this.resources = {\r\n namespace,\r\n markers: {\r\n section: { image: images[0], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.SectionCallout\") },\r\n detail: { image: images[1], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.DetailCallout\") },\r\n elevation: { image: images[2], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.ElevationCallout\") },\r\n plan: { image: images[3], label: IModelApp.localization.getLocalizedString(\"HyperModeling:Message.PlanCallout\") },\r\n },\r\n };\r\n\r\n registerTools(namespace);\r\n this.replaceConfiguration(config);\r\n }\r\n\r\n private static async ensureInitialized(): Promise<void> {\r\n if (undefined === this.resources)\r\n await this.initialize();\r\n\r\n assertInitialized(this);\r\n }\r\n\r\n /** Replaces the current package configuration, overwriting all previous settings. Passing `undefined` resets all settings to defaults.\r\n * @see [[HyperModeling.updateConfiguration]] for overriding specific aspects of the configuration.\r\n */\r\n public static replaceConfiguration(config?: HyperModelingConfig): void {\r\n config = config ?? {};\r\n this._markerHandler = config.markerHandler ?? new SectionMarkerHandler();\r\n this._markerConfig = config.markers ? { ...config.markers } : {};\r\n this._graphicsConfig = config.graphics ? { ...config.graphics } : {};\r\n }\r\n\r\n /** Overrides specific aspects of the current package configuration. Any field that is not `undefined` will be replaced in the current configuration;\r\n * the rest will retain their current values.\r\n * @see [[HyperModeling.replaceConfiguration]].\r\n */\r\n public static updateConfiguration(config: HyperModelingConfig): void {\r\n this._markerHandler = config.markerHandler ?? this._markerHandler;\r\n\r\n if (config.markers) {\r\n this._markerConfig = {\r\n ignoreModelSelector: config.markers.ignoreModelSelector ?? this._markerConfig.ignoreModelSelector,\r\n ignoreCategorySelector: config.markers.ignoreCategorySelector ?? this._markerConfig.ignoreCategorySelector,\r\n hiddenSectionTypes: config.markers.hiddenSectionTypes ?? this._markerConfig.hiddenSectionTypes,\r\n };\r\n }\r\n\r\n if (config.graphics) {\r\n this._graphicsConfig = {\r\n ignoreClip: config.graphics.ignoreClip ?? this._graphicsConfig.ignoreClip,\r\n debugClipVolumes: config.graphics.debugClipVolumes ?? this._graphicsConfig.debugClipVolumes,\r\n hideSectionGraphics: config.graphics.hideSectionGraphics ?? this._graphicsConfig.hideSectionGraphics,\r\n hideSheetAnnotations: config.graphics.hideSheetAnnotations ?? this._graphicsConfig.hideSheetAnnotations,\r\n };\r\n\r\n IModelApp.viewManager.invalidateViewportScenes();\r\n }\r\n }\r\n\r\n /** The handler that defines interactions with [[SectionMarker]]s.\r\n * @see [[initialize]] to override the default handler at package initialization.\r\n * @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current handler.\r\n */\r\n public static get markerHandler(): SectionMarkerHandler {\r\n assertInitialized(this);\r\n assert(undefined !== this._markerHandler);\r\n return this._markerHandler;\r\n }\r\n\r\n /** The current marker display configuration applied to any newly-created [[HyperModelingDecorator]]s.\r\n * @see [[initialize]] to override the default configuration at package initialization.\r\n * @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current configuration.\r\n * @see [[HyperModelingDecorator.replaceConfiguration]] or [[HyperModelingDecorator.updateConfiguration]] to change the configuration for an existing decorator.\r\n */\r\n public static get markerConfig(): SectionMarkerConfig {\r\n return this._markerConfig;\r\n }\r\n\r\n /** This graphics options applied to graphics displayed by all [[HyperModelingDecorator]]s.\r\n * @see [[updateConfiguration]] or [[replaceConfiguration]] to change the current configuration.\r\n */\r\n public static get graphicsConfig(): SectionGraphicsConfig {\r\n return this._graphicsConfig;\r\n }\r\n\r\n /** Returns true if the specified iModel contains any [SectionDrawingLocation]($backend)s. Hypermodeling is based on section drawing locations,\r\n * so if none are present, hypermodeling features are not relevant to the iModel. Attempting to use those features with such an iModel is fine,\r\n * but probably not useful.\r\n */\r\n public static async isSupportedForIModel(imodel: IModelConnection): Promise<boolean> {\r\n try {\r\n const reader = imodel.createQueryReader(\"SELECT ECInstanceId FROM bis.SectionDrawingLocation LIMIT 1\");\r\n return await reader.step(); // i.e., are any results are returned?\r\n } catch {\r\n // An iModel with a version of BisCore older than 1.0.11 will produce an expected \"table not found\" on the SectionDrawingLocation ECClass.\r\n return false;\r\n }\r\n }\r\n\r\n /** Returns whether hypermodeling is currently enabled for the specified viewport.\r\n * @see [[startOrStop]] to enable or disable hypermodeling for a viewport.\r\n */\r\n public static isEnabledForViewport(viewport: ScreenViewport): boolean {\r\n return undefined !== HyperModelingDecorator.getForViewport(viewport);\r\n }\r\n\r\n /** Start or stop hypermodeling mode for the specified viewport.\r\n * Enabling hypermodeling registers and returns a [[HyperModelingDecorator]] to display [[SectionMarker]]s within the viewport.\r\n * Disabling hypermodeling removes that decorator.\r\n * @param viewport The hypermodeling viewport\r\n * @param start `true` to enter hypermodeling mode, `false` to exit, or `undefined` to toggle the current mode.\r\n * @returns The new decorator is hypermodeling was successfully enabled.\r\n * @note Enabling hypermodeling may fail if the viewport is not viewing a spatial model or if the viewport's iModel does not support hypermodeling.\r\n * @see [[start]] and [[stop]].\r\n * @see [[isSupportedForIModel]].\r\n */\r\n public static async startOrStop(viewport: ScreenViewport, start?: boolean): Promise<HyperModelingDecorator | undefined> {\r\n // Help out the caller since we're async anyway...\r\n await this.ensureInitialized();\r\n\r\n const decorator = HyperModelingDecorator.getForViewport(viewport);\r\n if (undefined === start)\r\n start = undefined === decorator;\r\n\r\n if (start) {\r\n return this._start(viewport);\r\n } else {\r\n decorator?.dispose();\r\n return undefined;\r\n }\r\n }\r\n\r\n /** Start hypermodeling mode for the specified viewport if it is not currently enabled.\r\n * If hypermodeling is already enabled for the viewport, the existing decorator is returned; otherwise, a new decorator is created.\r\n * @param viewport The viewport for which to enable hypermodeling\r\n * @returns The decorator that implements hypermodeling features for the viewport, or `undefined` if hypermodeling could not be enabled.\r\n * @note Enabling hypermodeling may fail if the viewport is not viewing a spatial model or if the viewport's iModel does not support hypermodeling.\r\n */\r\n public static async start(viewport: ScreenViewport): Promise<HyperModelingDecorator | undefined> {\r\n await this.ensureInitialized();\r\n return this._start(viewport);\r\n }\r\n\r\n private static async _start(viewport: ScreenViewport): Promise<HyperModelingDecorator | undefined> {\r\n assertInitialized(this);\r\n if (!viewport.view.isSpatialView())\r\n return undefined;\r\n\r\n let decorator = HyperModelingDecorator.getForViewport(viewport);\r\n if (!decorator)\r\n decorator = await HyperModelingDecorator.create(viewport, this._markerConfig);\r\n\r\n if (undefined !== decorator && viewport.view.isCameraOn) {\r\n // We want the 2d graphics to align with the 3d geometry. Perspective ruins that.\r\n viewport.view.turnCameraOff();\r\n ViewManip.fitView(viewport, false, { noSaveInUndo: true });\r\n viewport.clearViewUndo();\r\n }\r\n\r\n return decorator;\r\n }\r\n\r\n /** Stop hypermodeling mode for the specified viewport if it is currently enabled. This disposes of the [[HyperModelingDecorator]] associated with the viewport.\r\n * @see [[start]] to enable hypermodeling for a viewport.\r\n * @see [[startOrStop]] to toggle hypermodeling mode.\r\n */\r\n public static stop(viewport: ScreenViewport): void {\r\n const decorator = HyperModelingDecorator.getForViewport(viewport);\r\n decorator?.dispose();\r\n }\r\n\r\n /** @internal */\r\n public static get namespace(): string | undefined {\r\n assertInitialized(this);\r\n return this.resources.namespace;\r\n }\r\n\r\n /** @internal */\r\n public static getMarkerData(type: SectionType): MarkerData {\r\n assertInitialized(this);\r\n switch (type) {\r\n case SectionType.Plan:\r\n return this.resources.markers.plan;\r\n case SectionType.Elevation:\r\n return this.resources.markers.elevation;\r\n case SectionType.Detail:\r\n return this.resources.markers.detail;\r\n default:\r\n return this.resources.markers.section;\r\n }\r\n }\r\n}\r\n"]}
|