@itwin/saved-views-react 1.0.0 → 1.1.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/applySavedView.d.ts +6 -1
- package/lib/applySavedView.js +9 -1
- package/lib/createViewState.d.ts +19 -2
- package/lib/createViewState.js +22 -7
- package/lib/translation/displayStyleExtractor.js +2 -2
- package/lib/translation/extractionUtilities.d.ts +10 -0
- package/lib/translation/extractionUtilities.js +28 -0
- package/package.json +1 -1
package/lib/applySavedView.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ViewChangeOptions, ViewPose, ViewState, type IModelConnection, type Viewport } from "@itwin/core-frontend";
|
|
2
2
|
import type { SavedViewData } from "./SavedView.js";
|
|
3
|
-
import { type ApplyVisibilitySettings } from "./createViewState.js";
|
|
3
|
+
import { ShowStrategy, type ApplyVisibilitySettings } from "./createViewState.js";
|
|
4
4
|
import { type DefaultExtensionHandlersApplyOverrides } from "./translation/SavedViewsExtensionHandlers.js";
|
|
5
5
|
export interface ApplySavedViewSettings {
|
|
6
6
|
/**
|
|
@@ -49,6 +49,11 @@ export interface ApplySavedViewSettings {
|
|
|
49
49
|
* @default '{ enabled: "ignore", disabled: "ignore", other: "ignore" }'
|
|
50
50
|
*/
|
|
51
51
|
categories?: ApplyVisibilitySettings | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* How to handle the visibility of subcategories that exist in iModel.
|
|
54
|
+
* @default "reset"
|
|
55
|
+
*/
|
|
56
|
+
subcategories?: ShowStrategy | undefined;
|
|
52
57
|
/**
|
|
53
58
|
* Options forwarded to {@link Viewport.changeView}.
|
|
54
59
|
* @default undefined
|
package/lib/applySavedView.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { Camera, } from "@itwin/core-common";
|
|
6
6
|
import { ViewPose, ViewPose2d, ViewPose3d, ViewState, } from "@itwin/core-frontend";
|
|
7
7
|
import { YawPitchRollAngles } from "@itwin/core-geometry";
|
|
8
|
-
import { createViewStateFromProps, createViewStateProps, } from "./createViewState.js";
|
|
8
|
+
import { createViewStateFromProps, createViewStateProps, sortCategories, } from "./createViewState.js";
|
|
9
9
|
import { extensionHandlers, } from "./translation/SavedViewsExtensionHandlers.js";
|
|
10
10
|
async function createSeedViewStateProps(iModel, viewport, savedViewData, settings = {}) {
|
|
11
11
|
if (settings.viewState !== "keep") {
|
|
@@ -78,8 +78,16 @@ async function applyViewStateProps(viewStateProps, iModel, viewport, savedViewDa
|
|
|
78
78
|
const viewState = await createViewStateFromProps(viewStateProps, iModel, savedViewData.viewData, {
|
|
79
79
|
models,
|
|
80
80
|
categories,
|
|
81
|
+
subcategories: settings.subcategories ?? "ignore",
|
|
81
82
|
});
|
|
82
83
|
viewport.changeView(viewState, settings.viewChangeOptions);
|
|
84
|
+
if (settings.subcategories !== "ignore") {
|
|
85
|
+
// If subcategories are not ignored, we need to reset them here,
|
|
86
|
+
// otherwise we might end up with subcategories not shown correctly
|
|
87
|
+
const { addCategories, dropCategories } = await sortCategories(iModel, savedViewData.viewData, categories);
|
|
88
|
+
viewport.changeCategoryDisplay(dropCategories, false);
|
|
89
|
+
viewport.changeCategoryDisplay(addCategories, true, settings.subcategories === "show");
|
|
90
|
+
}
|
|
83
91
|
}
|
|
84
92
|
/**
|
|
85
93
|
* Updates {@linkcode viewport} state to match captured Saved View.
|
package/lib/createViewState.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ViewStateProps } from "@itwin/core-common";
|
|
2
2
|
import { type IModelConnection, type ViewState } from "@itwin/core-frontend";
|
|
3
3
|
import type { ViewData } from "./SavedView.js";
|
|
4
|
+
import { Id64Array } from "@itwin/core-bentley";
|
|
4
5
|
/**
|
|
5
6
|
* Settings for how to handle the visibility of elements (models or categories) in iModel.
|
|
6
7
|
* * `enabled` – Enabled is the set of enabled elements (models or categories) that are stored in the saved view. Default is ignore.
|
|
@@ -20,7 +21,7 @@ export interface ApplyVisibilitySettings {
|
|
|
20
21
|
* * `"hide"` – Hide (ie do not show) the elements in this list
|
|
21
22
|
* * `"ignore"` – Preserve current elements that are shown in viewport
|
|
22
23
|
*/
|
|
23
|
-
type ShowStrategy = "show" | "hide" | "ignore";
|
|
24
|
+
export type ShowStrategy = "show" | "hide" | "ignore";
|
|
24
25
|
export interface ViewStateCreateSettings {
|
|
25
26
|
/**
|
|
26
27
|
* Normally {@link createViewState} function invokes and awaits {@linkcode ViewState.load}
|
|
@@ -53,6 +54,11 @@ export interface ViewStateCreateSettings {
|
|
|
53
54
|
* @default '{ enabled: "ignore", disabled: "ignore", other: "ignore" }'
|
|
54
55
|
*/
|
|
55
56
|
categories?: ApplyVisibilitySettings | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* How to handle the visibility of subcategories that exist in iModel.
|
|
59
|
+
* @default "reset"
|
|
60
|
+
*/
|
|
61
|
+
subcategories?: ShowStrategy | undefined;
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
58
64
|
* Creates {@link ViewStateProps} object out of Saved View data. It provides a lower-level
|
|
@@ -94,4 +100,15 @@ export declare function createViewStateFromProps(props: ViewStateProps, iModel:
|
|
|
94
100
|
* await applySavedView(iModel, viewport, savedViewData);
|
|
95
101
|
*/
|
|
96
102
|
export declare function createViewState(iModel: IModelConnection, viewData: ViewData, settings?: ViewStateCreateSettings): Promise<ViewState>;
|
|
97
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Determine, out of all categories in the iModel, which ones should be added or dropped
|
|
105
|
+
* (ie visible or hidden) based on the provided settings.
|
|
106
|
+
* @param iModel The current IModelConnection.
|
|
107
|
+
* @param viewData The view data containing the lists of enabled and disabled categories that will be applied.
|
|
108
|
+
* @param settings The settings for how to handle the visibility of enabled, disabled, and other category lists. Default is 'ignore' for all.
|
|
109
|
+
* @returns A list of categories that should be added or dropped (ie visible or hidden).
|
|
110
|
+
*/
|
|
111
|
+
export declare function sortCategories(iModel: IModelConnection, viewData: ViewData, settings?: ApplyVisibilitySettings): Promise<{
|
|
112
|
+
addCategories: Id64Array;
|
|
113
|
+
dropCategories: Id64Array;
|
|
114
|
+
}>;
|
package/lib/createViewState.js
CHANGED
|
@@ -26,7 +26,10 @@ export async function createViewStateProps(iModel, viewData) {
|
|
|
26
26
|
}
|
|
27
27
|
async function applyViewStateOptions(viewState, iModel, viewData, settings = {}) {
|
|
28
28
|
await applyModelSettings(iModel, viewState, viewData, settings.models);
|
|
29
|
-
|
|
29
|
+
if (settings.subcategories === "ignore") {
|
|
30
|
+
// If subcategories are ignored, we apply category settings here instead of on the viewport.
|
|
31
|
+
await applyCategorySettings(iModel, viewState, viewData, settings.categories);
|
|
32
|
+
}
|
|
30
33
|
if (!settings.skipViewStateLoad) {
|
|
31
34
|
await viewState.load();
|
|
32
35
|
}
|
|
@@ -351,15 +354,14 @@ async function applyModelSettings(iModel, viewState, viewData, settings) {
|
|
|
351
354
|
}
|
|
352
355
|
}
|
|
353
356
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
357
|
+
* Determine, out of all categories in the iModel, which ones should be added or dropped
|
|
358
|
+
* (ie visible or hidden) based on the provided settings.
|
|
356
359
|
* @param iModel The current IModelConnection.
|
|
357
|
-
* @param viewState The view state to modify.
|
|
358
360
|
* @param viewData The view data containing the lists of enabled and disabled categories that will be applied.
|
|
359
361
|
* @param settings The settings for how to handle the visibility of enabled, disabled, and other category lists. Default is 'ignore' for all.
|
|
360
|
-
* @returns A
|
|
362
|
+
* @returns A list of categories that should be added or dropped (ie visible or hidden).
|
|
361
363
|
*/
|
|
362
|
-
async function
|
|
364
|
+
export async function sortCategories(iModel, viewData, settings) {
|
|
363
365
|
const addCategories = [];
|
|
364
366
|
const dropCategories = [];
|
|
365
367
|
if (settings?.enabled === "show") {
|
|
@@ -386,10 +388,23 @@ async function applyCategorySettings(iModel, viewState, viewData, settings) {
|
|
|
386
388
|
dropCategories.push(...otherCategories);
|
|
387
389
|
}
|
|
388
390
|
}
|
|
391
|
+
return { addCategories, dropCategories };
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Apply the category settings to the view state.
|
|
395
|
+
* This function modifies the category selector of the view state based on the provided settings.
|
|
396
|
+
* @param iModel The current IModelConnection.
|
|
397
|
+
* @param viewState The view state to modify.
|
|
398
|
+
* @param viewData The view data containing the lists of enabled and disabled categories that will be applied.
|
|
399
|
+
* @param settings The settings for how to handle the visibility of enabled, disabled, and other category lists. Default is 'ignore' for all.
|
|
400
|
+
* @returns A promise that resolves when the category settings have been applied.
|
|
401
|
+
*/
|
|
402
|
+
async function applyCategorySettings(iModel, viewState, viewData, settings) {
|
|
403
|
+
const { addCategories, dropCategories } = await sortCategories(iModel, viewData, settings);
|
|
389
404
|
if (addCategories.length === 0 && dropCategories.length === 0) {
|
|
390
405
|
return;
|
|
391
406
|
}
|
|
392
|
-
// Update
|
|
407
|
+
// Update category selector
|
|
393
408
|
const categorySelector = viewState.categorySelector.clone();
|
|
394
409
|
categorySelector.addCategories(addCategories);
|
|
395
410
|
categorySelector.dropCategories(dropCategories);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyExtraction, extractArray, extractArrayConditionally, extractBoolean, extractColor, extractColorLegacy, extractConditionally, extractLinePixels, extractNumber, extractNumberOrBool, extractObject, extractPlainTypedMap, extractRGB, extractSimpleArray, extractString, extractStringOrArray, extractStringOrNumber, extractStringOrNumberArray, isAnyColorFormat, simpleTypeOf, } from "./extractionUtilities.js";
|
|
1
|
+
import { applyExtraction, extractArray, extractArrayConditionally, extractArrayElementsConditionally, extractBoolean, extractColor, extractColorLegacy, extractConditionally, extractLinePixels, extractNumber, extractNumberOrBool, extractObject, extractPlainTypedMap, extractRGB, extractSimpleArray, extractString, extractStringOrArray, extractStringOrNumber, extractStringOrNumberArray, isAnyColorFormat, simpleTypeOf, } from "./extractionUtilities.js";
|
|
2
2
|
const viewFlagMappings = [
|
|
3
3
|
extractNumber("renderMode"),
|
|
4
4
|
extractBoolean("noConstructions", "noConstruct"),
|
|
@@ -411,7 +411,7 @@ const displayStylesLegacyMapping = [
|
|
|
411
411
|
extractNumber("timePoint"),
|
|
412
412
|
extractArray(displayStyleSubCategoryLegacyMappings, "subCategoryOvr", "subCategoryOverrides"),
|
|
413
413
|
extractObject(backgroundMapMappings, "backgroundMap"),
|
|
414
|
-
|
|
414
|
+
extractArrayElementsConditionally((value) => value && !value.invisible, contextRealityModelsLegacyMappings, "contextRealityModels"),
|
|
415
415
|
extractStringOrArray("excludedElements"),
|
|
416
416
|
extractObject(mapImageryLegacyMapping, "mapImagery"),
|
|
417
417
|
extractArray(displayStyleModelAppearanceLegacyMappings, "modelOvr", "modelOverrides"),
|
|
@@ -185,6 +185,16 @@ export declare const extractConditionally: (params: ConditionalExtractParams[],
|
|
|
185
185
|
* @param extractionFunc
|
|
186
186
|
*/
|
|
187
187
|
export declare const extractArray: (extractionFunc: ExtractionFunc<void, void>[], from: string, to?: string) => (input: any, output: any) => void;
|
|
188
|
+
/**
|
|
189
|
+
* Creates an extraction function that will extract each value of an array if it meets the given condition
|
|
190
|
+
* by using a single extraction function on each of the array values
|
|
191
|
+
* @param condition Function that checks if the value should be extracted
|
|
192
|
+
* @param extractionFunc Array of extraction functions to apply to each value in the array that meets the condition
|
|
193
|
+
* @param from Accessor string where the array is in the input object
|
|
194
|
+
* @param to Accessor string to store it in the output object
|
|
195
|
+
* @returns Function that extracts an array of values conditionally
|
|
196
|
+
*/
|
|
197
|
+
export declare const extractArrayElementsConditionally: (condition: (value: any) => boolean, extractionFunc: ExtractionFunc<void, void>[], from: string, to?: string) => (input: any, output: any) => void;
|
|
188
198
|
/**
|
|
189
199
|
* Creates an extraction function that will extract the values inside a 2D array from the given accessor
|
|
190
200
|
* @param extractionFunc Extraction functions to apply to each entry in the array
|
|
@@ -439,6 +439,34 @@ export const extractArray = (extractionFunc, from, to) => {
|
|
|
439
439
|
}
|
|
440
440
|
};
|
|
441
441
|
};
|
|
442
|
+
/**
|
|
443
|
+
* Creates an extraction function that will extract each value of an array if it meets the given condition
|
|
444
|
+
* by using a single extraction function on each of the array values
|
|
445
|
+
* @param condition Function that checks if the value should be extracted
|
|
446
|
+
* @param extractionFunc Array of extraction functions to apply to each value in the array that meets the condition
|
|
447
|
+
* @param from Accessor string where the array is in the input object
|
|
448
|
+
* @param to Accessor string to store it in the output object
|
|
449
|
+
* @returns Function that extracts an array of values conditionally
|
|
450
|
+
*/
|
|
451
|
+
export const extractArrayElementsConditionally = (
|
|
452
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
453
|
+
condition, extractionFunc, from, to) => {
|
|
454
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
455
|
+
return (input, output) => {
|
|
456
|
+
const adjustedTo = to ?? from;
|
|
457
|
+
if (input[from] !== undefined && Array.isArray(input[from])) {
|
|
458
|
+
output[adjustedTo] = [];
|
|
459
|
+
let outputIndex = 0;
|
|
460
|
+
input[from].forEach((_, index) => {
|
|
461
|
+
if (condition(input[from][index])) {
|
|
462
|
+
output[adjustedTo].push({});
|
|
463
|
+
extractionFunc.forEach((func) => func(input[from][index], output[adjustedTo][outputIndex]));
|
|
464
|
+
outputIndex++;
|
|
465
|
+
}
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
};
|
|
442
470
|
/**
|
|
443
471
|
* Creates an extraction function that will extract the values inside a 2D array from the given accessor
|
|
444
472
|
* @param extractionFunc Extraction functions to apply to each entry in the array
|