@itwin/saved-views-react 0.4.1 → 0.5.0
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 +64 -0
- package/lib/applySavedView.js +47 -0
- package/lib/captureSavedViewData.d.ts +1 -6
- package/lib/captureSavedViewData.js +2 -7
- package/lib/createViewState.d.ts +15 -2
- package/lib/createViewState.js +24 -22
- package/lib/experimental.d.ts +0 -3
- package/lib/experimental.js +0 -3
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/translation/SavedViewTypes.d.ts +0 -2
- package/lib/translation/SavedViewsExtensionHandlers.d.ts +14 -9
- package/lib/translation/SavedViewsExtensionHandlers.js +23 -26
- package/lib/translation/extensionExtractor.d.ts +0 -6
- package/lib/translation/extensionExtractor.js +0 -24
- package/package.json +1 -1
- package/lib/ModelCategoryOverrideProvider.d.ts +0 -31
- package/lib/ModelCategoryOverrideProvider.js +0 -88
- package/lib/translation/SavedViewTranslation.d.ts +0 -4
- package/lib/translation/SavedViewTranslation.js +0 -25
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ViewState, type IModelConnection, type Viewport } from "@itwin/core-frontend";
|
|
2
|
+
import { type SavedViewRepresentation } from "@itwin/saved-views-client";
|
|
3
|
+
export interface ApplySavedViewSettings {
|
|
4
|
+
/**
|
|
5
|
+
* Strategy to use when other setting does not specify one. By default, viewport is reset to default state and then
|
|
6
|
+
* all captured Saved View data is applied on top.
|
|
7
|
+
* @default "apply"
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* await applySavedView(iModel, viewport, savedView, { all: "keep", viewState: "apply" });
|
|
11
|
+
*/
|
|
12
|
+
all?: ApplyStrategy | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* How to handle captured {@link ViewState} data. The default behavior is to generate a new `ViewState` object and
|
|
15
|
+
* apply it to viewport.
|
|
16
|
+
*
|
|
17
|
+
* You can optionally provide a pre-made `ViewState` instance to conserve resources. It is usually obtained from
|
|
18
|
+
* {@link createViewState} result.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* import { applySavedView, createViewState } from "@itwin/saved-views-react";
|
|
22
|
+
*
|
|
23
|
+
* const viewState = await createViewState(iModel, savedView);
|
|
24
|
+
* await Promise.all([
|
|
25
|
+
* applySavedView(iModel, viewport1, savedView, { viewState }),
|
|
26
|
+
* applySavedView(iModel, viewport2, savedView, { viewState }),
|
|
27
|
+
* ]);
|
|
28
|
+
*/
|
|
29
|
+
viewState?: Exclude<ApplyStrategy, "reset"> | ViewState | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* How to handle visibility of models and categories that exist in iModel but are not captured in Saved View data. Has
|
|
32
|
+
* effect only when `modelAndCategoryVisibility` strategy is set to `"apply"`.
|
|
33
|
+
* @default "hidden"
|
|
34
|
+
*/
|
|
35
|
+
modelAndCategoryVisibilityFallback?: "visible" | "hidden" | undefined;
|
|
36
|
+
/** How to handle captured element emphasis data. In default state emphasis is turned off. */
|
|
37
|
+
emphasis?: ApplyStrategy | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* How to handle captured {@link Viewport.perModelCategoryVisibility} data. In default state no overrides are present.
|
|
40
|
+
*/
|
|
41
|
+
perModelCategoryVisibility?: ApplyStrategy | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Controls how viewport state is going to be altered.
|
|
45
|
+
*
|
|
46
|
+
* * `"apply"` – Apply captured Saved View state. Falls back to `"reset"` on failure (e.g. missing Saved View data).
|
|
47
|
+
* * `"reset"` – Reset to the default viewport state
|
|
48
|
+
* * `"keep"` – Keep the current viewport state
|
|
49
|
+
*/
|
|
50
|
+
type ApplyStrategy = "apply" | "reset" | "keep";
|
|
51
|
+
/**
|
|
52
|
+
* Updates {@linkcode viewport} state to match captured Saved View.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Optionally, you can create and manage ViewState object yourself to avoid redundant work,
|
|
56
|
+
* // e.g. when applying the same Saved View to multiple viewports
|
|
57
|
+
* const viewState = await createViewState(iModel, savedView);
|
|
58
|
+
* await Promise.all([
|
|
59
|
+
* applySavedView(iModel, firstViewport, savedView, { viewState }),
|
|
60
|
+
* applySavedView(iModel, secondViewport, savedView, { viewState }),
|
|
61
|
+
* ]);
|
|
62
|
+
*/
|
|
63
|
+
export declare function applySavedView(iModel: IModelConnection, viewport: Viewport, savedView: Pick<SavedViewRepresentation, "savedViewData" | "extensions">, settings?: ApplySavedViewSettings | undefined): Promise<void>;
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
import { ViewState } from "@itwin/core-frontend";
|
|
6
|
+
import { createViewState } from "./createViewState.js";
|
|
7
|
+
import { extensionHandlers } from "./translation/SavedViewsExtensionHandlers.js";
|
|
8
|
+
/**
|
|
9
|
+
* Updates {@linkcode viewport} state to match captured Saved View.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Optionally, you can create and manage ViewState object yourself to avoid redundant work,
|
|
13
|
+
* // e.g. when applying the same Saved View to multiple viewports
|
|
14
|
+
* const viewState = await createViewState(iModel, savedView);
|
|
15
|
+
* await Promise.all([
|
|
16
|
+
* applySavedView(iModel, firstViewport, savedView, { viewState }),
|
|
17
|
+
* applySavedView(iModel, secondViewport, savedView, { viewState }),
|
|
18
|
+
* ]);
|
|
19
|
+
*/
|
|
20
|
+
export async function applySavedView(iModel, viewport, savedView, settings = {}) {
|
|
21
|
+
const defaultStrategy = settings.all ?? "apply";
|
|
22
|
+
if ((settings.viewState ?? defaultStrategy) !== "keep") {
|
|
23
|
+
if (settings.viewState instanceof ViewState) {
|
|
24
|
+
viewport.changeView(settings.viewState);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const { modelAndCategoryVisibilityFallback } = settings;
|
|
28
|
+
const viewState = await createViewState(iModel, savedView.savedViewData, { modelAndCategoryVisibilityFallback });
|
|
29
|
+
viewport.changeView(viewState);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const extensions = new Map(savedView.extensions?.map(({ extensionName, data }) => [extensionName, data]));
|
|
33
|
+
const processExtension = (extensionHandler, strategy = defaultStrategy) => {
|
|
34
|
+
if (strategy === "keep") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
extensionHandler.reset(viewport);
|
|
38
|
+
if (strategy === "apply") {
|
|
39
|
+
const extensionData = extensions.get(extensionHandler.extensionName);
|
|
40
|
+
if (extensionData) {
|
|
41
|
+
extensionHandler.apply(extensionData, viewport);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
processExtension(extensionHandlers.emphasizeElements, settings.emphasis);
|
|
46
|
+
processExtension(extensionHandlers.perModelCategoryVisibility, settings.perModelCategoryVisibility);
|
|
47
|
+
}
|
|
@@ -2,13 +2,8 @@ import { Id64Array } from "@itwin/core-bentley";
|
|
|
2
2
|
import { type IModelConnection, type Viewport } from "@itwin/core-frontend";
|
|
3
3
|
import { type ViewData } from "@itwin/saved-views-client";
|
|
4
4
|
interface CaptureSavedViewDataArgs {
|
|
5
|
-
/** Viewport to capture
|
|
5
|
+
/** Viewport to capture. */
|
|
6
6
|
viewport: Viewport;
|
|
7
|
-
/**
|
|
8
|
-
* Collect a list of models and categories that are currently not enabled in the {@linkcode viewport}.
|
|
9
|
-
* @default true
|
|
10
|
-
*/
|
|
11
|
-
captureHiddenModelsAndCategories?: boolean | undefined;
|
|
12
7
|
}
|
|
13
8
|
export declare function captureSavedViewData(args: CaptureSavedViewDataArgs): Promise<ViewData>;
|
|
14
9
|
export declare function getMissingModels(iModel: IModelConnection, knownModels: Set<string>): Promise<string[]>;
|
|
@@ -2,16 +2,11 @@ import { QueryRowFormat } from "@itwin/core-common";
|
|
|
2
2
|
import { extractClipVectorsFromLegacy } from "./translation/clipVectorsLegacyExtractor.js";
|
|
3
3
|
import { extractDisplayStyle2dFromLegacy, extractDisplayStyle3dFromLegacy, } from "./translation/displayStyleExtractor.js";
|
|
4
4
|
export async function captureSavedViewData(args) {
|
|
5
|
-
const
|
|
6
|
-
const hiddenCategoriesPromise = captureHiddenModelsAndCategories
|
|
7
|
-
? getMissingCategories(args.viewport.iModel, new Set(args.viewport.view.categorySelector.toJSON().categories))
|
|
8
|
-
: undefined;
|
|
5
|
+
const hiddenCategoriesPromise = getMissingCategories(args.viewport.iModel, new Set(args.viewport.view.categorySelector.toJSON().categories));
|
|
9
6
|
if (args.viewport.view.isSpatialView()) {
|
|
10
7
|
const [hiddenCategories, hiddenModels] = await Promise.all([
|
|
11
8
|
hiddenCategoriesPromise,
|
|
12
|
-
|
|
13
|
-
? getMissingModels(args.viewport.iModel, new Set(args.viewport.view.modelSelector.toJSON().models))
|
|
14
|
-
: undefined,
|
|
9
|
+
getMissingModels(args.viewport.iModel, new Set(args.viewport.view.modelSelector.toJSON().models)),
|
|
15
10
|
]);
|
|
16
11
|
return createSpatialSavedViewObject(args.viewport, hiddenCategories, hiddenModels);
|
|
17
12
|
}
|
package/lib/createViewState.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import { type IModelConnection, type ViewState } from "@itwin/core-frontend";
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { ViewData } from "@itwin/saved-views-client";
|
|
3
|
+
export interface ViewStateCreateSettings {
|
|
4
|
+
/**
|
|
5
|
+
* Normally before {@link createViewState} function returns a {@link ViewState}, its {@linkcode ViewState.load} method
|
|
6
|
+
* is called and awaited. You may skip this step if you intend to perform it later.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
skipViewStateLoad?: boolean | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* How to handle visibility of models and categories that exist in iModel but are not captured in Saved View data.
|
|
12
|
+
* @default "hidden"
|
|
13
|
+
*/
|
|
14
|
+
modelAndCategoryVisibilityFallback?: "visible" | "hidden" | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare function createViewState(iModel: IModelConnection, savedViewData: ViewData, settings?: ViewStateCreateSettings): Promise<ViewState>;
|
package/lib/createViewState.js
CHANGED
|
@@ -8,22 +8,24 @@ import { isViewDataITwin3d, isViewDataITwinDrawing, isViewDataITwinSheet, } from
|
|
|
8
8
|
import { getMissingCategories, getMissingModels } from "./captureSavedViewData.js";
|
|
9
9
|
import { extractClipVectors } from "./translation/clipVectorsExtractor.js";
|
|
10
10
|
import { extractDisplayStyle, extractDisplayStyle3d } from "./translation/displayStyleExtractor.js";
|
|
11
|
-
export async function createViewState(iModel,
|
|
12
|
-
const viewState = await createViewStateVariant(iModel,
|
|
13
|
-
if (
|
|
14
|
-
await
|
|
11
|
+
export async function createViewState(iModel, savedViewData, settings = {}) {
|
|
12
|
+
const viewState = await createViewStateVariant(iModel, savedViewData);
|
|
13
|
+
if (settings.modelAndCategoryVisibilityFallback === "visible") {
|
|
14
|
+
await unhideNewModelsAndCategories(iModel, viewState, savedViewData);
|
|
15
|
+
}
|
|
16
|
+
if (!settings.skipViewStateLoad) {
|
|
17
|
+
await viewState.load();
|
|
15
18
|
}
|
|
16
|
-
await viewState.load();
|
|
17
19
|
return viewState;
|
|
18
20
|
}
|
|
19
|
-
async function createViewStateVariant(iModel,
|
|
20
|
-
if (isViewDataITwinDrawing(
|
|
21
|
-
return createDrawingViewState(iModel,
|
|
21
|
+
async function createViewStateVariant(iModel, savedViewData) {
|
|
22
|
+
if (isViewDataITwinDrawing(savedViewData)) {
|
|
23
|
+
return createDrawingViewState(iModel, savedViewData.itwinDrawingView);
|
|
22
24
|
}
|
|
23
|
-
if (isViewDataITwinSheet(
|
|
24
|
-
return createSheetViewState(iModel,
|
|
25
|
+
if (isViewDataITwinSheet(savedViewData)) {
|
|
26
|
+
return createSheetViewState(iModel, savedViewData.itwinSheetView);
|
|
25
27
|
}
|
|
26
|
-
return createSpatialViewState(iModel,
|
|
28
|
+
return createSpatialViewState(iModel, savedViewData.itwin3dView);
|
|
27
29
|
}
|
|
28
30
|
async function createSpatialViewState(iModel, viewData) {
|
|
29
31
|
const seedViewState = await fetchIModelViewData(iModel, SpatialViewState.classFullName);
|
|
@@ -217,29 +219,29 @@ async function getDefaultViewIdFromClassName(iModel, viewClassName) {
|
|
|
217
219
|
function cloneCode({ spec, scope, value }) {
|
|
218
220
|
return { spec, scope, value };
|
|
219
221
|
}
|
|
220
|
-
async function
|
|
221
|
-
if (isViewDataITwin3d(
|
|
222
|
+
async function unhideNewModelsAndCategories(iModel, viewState, savedViewData) {
|
|
223
|
+
if (isViewDataITwin3d(savedViewData)) {
|
|
222
224
|
if (!viewState.isSpatialView()) {
|
|
223
225
|
return;
|
|
224
226
|
}
|
|
225
|
-
const
|
|
226
|
-
if (!
|
|
227
|
+
const viewData = savedViewData.itwin3dView;
|
|
228
|
+
if (!viewData.categories?.disabled || !viewData.models?.disabled) {
|
|
227
229
|
return;
|
|
228
230
|
}
|
|
229
231
|
const [visibleCategories, visibleModels] = await Promise.all([
|
|
230
|
-
getMissingCategories(iModel, new Set(
|
|
231
|
-
getMissingModels(iModel, new Set(
|
|
232
|
+
getMissingCategories(iModel, new Set(viewData.categories.disabled)),
|
|
233
|
+
getMissingModels(iModel, new Set(viewData.models.disabled)),
|
|
232
234
|
]);
|
|
233
235
|
viewState.categorySelector.addCategories(visibleCategories);
|
|
234
236
|
viewState.modelSelector.addModels(visibleModels);
|
|
235
237
|
return;
|
|
236
238
|
}
|
|
237
|
-
const
|
|
238
|
-
?
|
|
239
|
-
:
|
|
240
|
-
if (!
|
|
239
|
+
const viewData = isViewDataITwinDrawing(savedViewData)
|
|
240
|
+
? savedViewData.itwinDrawingView
|
|
241
|
+
: savedViewData.itwinSheetView;
|
|
242
|
+
if (!viewData.categories?.disabled) {
|
|
241
243
|
return;
|
|
242
244
|
}
|
|
243
|
-
const visibleCategories = await getMissingCategories(iModel, new Set(
|
|
245
|
+
const visibleCategories = await getMissingCategories(iModel, new Set(viewData.categories.disabled));
|
|
244
246
|
viewState.categorySelector.addCategories(visibleCategories);
|
|
245
247
|
}
|
package/lib/experimental.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { createSavedViewOptions, type CreateSavedViewOptionsParams } from "./SavedViewTile/SavedViewOptions.js";
|
|
2
2
|
export { SavedViewsExpandableBlockWidget } from "./SavedViewsWidget/SavedViewsExpandableBlockWidget.js";
|
|
3
3
|
export { SavedViewsFolderWidget } from "./SavedViewsWidget/SavedViewsFolderWidget.js";
|
|
4
|
-
export { applyExtensionsToViewport } from "./translation/SavedViewTranslation.js";
|
|
5
|
-
export { createViewState } from "./createViewState.js";
|
|
6
|
-
export { ModelCategoryOverrideProvider } from "./ModelCategoryOverrideProvider.js";
|
package/lib/experimental.js
CHANGED
|
@@ -5,6 +5,3 @@
|
|
|
5
5
|
export { createSavedViewOptions } from "./SavedViewTile/SavedViewOptions.js";
|
|
6
6
|
export { SavedViewsExpandableBlockWidget } from "./SavedViewsWidget/SavedViewsExpandableBlockWidget.js";
|
|
7
7
|
export { SavedViewsFolderWidget } from "./SavedViewsWidget/SavedViewsFolderWidget.js";
|
|
8
|
-
export { applyExtensionsToViewport } from "./translation/SavedViewTranslation.js";
|
|
9
|
-
export { createViewState } from "./createViewState.js";
|
|
10
|
-
export { ModelCategoryOverrideProvider } from "./ModelCategoryOverrideProvider.js";
|
package/lib/index.d.ts
CHANGED
|
@@ -8,7 +8,9 @@ export type { CreateGroupParams, CreateSavedViewParams, CreateTagParams, DeleteG
|
|
|
8
8
|
export { SavedViewsContextProvider, type SavedViewsContext } from "./SavedViewsContext.js";
|
|
9
9
|
export { StickyExpandableBlock } from "./StickyExpandableBlock/StickyExpandableBlock.js";
|
|
10
10
|
export { TileGrid } from "./TileGrid/TileGrid.js";
|
|
11
|
+
export { applySavedView, type ApplySavedViewSettings } from "./applySavedView.js";
|
|
11
12
|
export { captureSavedViewData } from "./captureSavedViewData.js";
|
|
12
13
|
export { captureSavedViewThumbnail } from "./captureSavedViewThumbnail.js";
|
|
14
|
+
export { createViewState, type ViewStateCreateSettings } from "./createViewState.js";
|
|
13
15
|
export { defaultLocalization, type LocalizationStrings } from "./localization.js";
|
|
14
16
|
export { useSavedViews, type SavedViewActions } from "./useSavedViews.js";
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,9 @@ export { ITwinSavedViewsClient } from "./SavedViewsClient/ITwinSavedViewsClient.
|
|
|
10
10
|
export { SavedViewsContextProvider } from "./SavedViewsContext.js";
|
|
11
11
|
export { StickyExpandableBlock } from "./StickyExpandableBlock/StickyExpandableBlock.js";
|
|
12
12
|
export { TileGrid } from "./TileGrid/TileGrid.js";
|
|
13
|
+
export { applySavedView } from "./applySavedView.js";
|
|
13
14
|
export { captureSavedViewData } from "./captureSavedViewData.js";
|
|
14
15
|
export { captureSavedViewThumbnail } from "./captureSavedViewThumbnail.js";
|
|
16
|
+
export { createViewState } from "./createViewState.js";
|
|
15
17
|
export { defaultLocalization } from "./localization.js";
|
|
16
18
|
export { useSavedViews } from "./useSavedViews.js";
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Id64Array } from "@itwin/core-bentley";
|
|
2
2
|
import type { CategorySelectorProps, DisplayStyle3dProps, DisplayStyleProps, EmphasizeElementsProps, ModelSelectorProps, SectionDrawingViewProps, SheetProps, SpatialViewDefinitionProps, ViewDefinition2dProps } from "@itwin/core-common";
|
|
3
3
|
import type { Range3dProps } from "@itwin/core-geometry";
|
|
4
|
-
import type { ModelCategoryOverrideProviderProps } from "../ModelCategoryOverrideProvider.js";
|
|
5
4
|
export interface LegacySavedView3d extends LegacySavedViewBase {
|
|
6
5
|
displayStyleProps: DisplayStyle3dProps;
|
|
7
6
|
modelSelectorProps: ModelSelectorProps;
|
|
@@ -33,7 +32,6 @@ export interface LegacySavedViewBase {
|
|
|
33
32
|
thumbnail?: string;
|
|
34
33
|
categorySelectorProps: CategorySelectorProps;
|
|
35
34
|
emphasizeElementsProps?: EmphasizeElementsProps;
|
|
36
|
-
visibilityOverrideProps?: ModelCategoryOverrideProviderProps;
|
|
37
35
|
tags?: LegacyTag[];
|
|
38
36
|
hiddenCategories?: Id64Array;
|
|
39
37
|
extensions?: Map<string, string>;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { type Viewport } from "@itwin/core-frontend";
|
|
2
2
|
export interface ExtensionHandler {
|
|
3
3
|
extensionName: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Collection of default extension handlers
|
|
8
|
-
*/
|
|
9
|
-
export declare class SavedViewsExtensionHandlers {
|
|
10
|
-
static EmphasizeElements: ExtensionHandler;
|
|
11
|
-
static PerModelCategoryVisibility: ExtensionHandler;
|
|
12
|
-
static VisibilityOverride: ExtensionHandler;
|
|
4
|
+
apply: (extensionData: string, viewport: Viewport) => void;
|
|
5
|
+
reset: (viewport: Viewport) => void;
|
|
13
6
|
}
|
|
7
|
+
export declare const extensionHandlers: {
|
|
8
|
+
emphasizeElements: {
|
|
9
|
+
extensionName: string;
|
|
10
|
+
apply: (extensionData: string, viewport: Viewport) => void;
|
|
11
|
+
reset: (viewport: Viewport) => void;
|
|
12
|
+
};
|
|
13
|
+
perModelCategoryVisibility: {
|
|
14
|
+
extensionName: string;
|
|
15
|
+
apply: (extensionData: string, viewport: Viewport) => void;
|
|
16
|
+
reset: (viewport: Viewport) => void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -1,42 +1,39 @@
|
|
|
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
|
+
*--------------------------------------------------------------------------------------------*/
|
|
1
5
|
import { EmphasizeElements, PerModelCategoryVisibility } from "@itwin/core-frontend";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Collection of default extension handlers
|
|
6
|
-
*/
|
|
7
|
-
export class SavedViewsExtensionHandlers {
|
|
8
|
-
static EmphasizeElements = {
|
|
6
|
+
import { extractEmphasizeElements, extractPerModelCategoryVisibility } from "./extensionExtractor.js";
|
|
7
|
+
export const extensionHandlers = {
|
|
8
|
+
emphasizeElements: {
|
|
9
9
|
extensionName: "EmphasizeElements",
|
|
10
|
-
|
|
10
|
+
apply: (extensionData, viewport) => {
|
|
11
11
|
if (extensionData) {
|
|
12
12
|
const props = extractEmphasizeElements(extensionData);
|
|
13
13
|
if (props !== undefined) {
|
|
14
|
-
EmphasizeElements.getOrCreate(
|
|
14
|
+
EmphasizeElements.getOrCreate(viewport).fromJSON(props, viewport);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
reset: (viewport) => {
|
|
19
|
+
if (EmphasizeElements.get(viewport)) {
|
|
20
|
+
EmphasizeElements.clear(viewport);
|
|
21
|
+
viewport.isFadeOutActive = false;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
perModelCategoryVisibility: {
|
|
20
26
|
extensionName: "PerModelCategoryVisibility",
|
|
21
|
-
|
|
27
|
+
apply: (extensionData, viewport) => {
|
|
22
28
|
const props = extractPerModelCategoryVisibility(extensionData) ?? [];
|
|
23
|
-
vp.perModelCategoryVisibility.clearOverrides();
|
|
24
29
|
for (const override of props) {
|
|
25
|
-
|
|
30
|
+
viewport.perModelCategoryVisibility.setOverride(override.modelId, override.categoryId, override.visible
|
|
26
31
|
? PerModelCategoryVisibility.Override.Show
|
|
27
32
|
: PerModelCategoryVisibility.Override.Hide);
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
extensionName: "VisibilityOverride",
|
|
33
|
-
onViewApply: async (extensionData, vp) => {
|
|
34
|
-
if (extensionData) {
|
|
35
|
-
const props = extractVisibilityOverride(extensionData);
|
|
36
|
-
if (props !== undefined) {
|
|
37
|
-
ModelCategoryOverrideProvider.getOrCreate(vp).fromJSON(props);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
35
|
+
reset: (viewport) => {
|
|
36
|
+
viewport.perModelCategoryVisibility.clearOverrides();
|
|
40
37
|
},
|
|
41
|
-
}
|
|
42
|
-
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type EmphasizeElementsProps } from "@itwin/core-common";
|
|
2
|
-
import { ModelCategoryOverrideProviderProps } from "../ModelCategoryOverrideProvider.js";
|
|
3
2
|
import type { PerModelCategoryVisibilityProps } from "./SavedViewTypes.js";
|
|
4
3
|
/**
|
|
5
4
|
* Extracts the EmphasizeElementsProps from string data in an extension
|
|
@@ -11,8 +10,3 @@ export declare const extractEmphasizeElements: (extensionData: string) => Emphas
|
|
|
11
10
|
* @param extensionData
|
|
12
11
|
*/
|
|
13
12
|
export declare const extractPerModelCategoryVisibility: (extensionData: string) => PerModelCategoryVisibilityProps[];
|
|
14
|
-
/**
|
|
15
|
-
* Extracts the VisibilityOverrideProps (ie ModelCategoryOverrideProviderProps) from string data in an extension
|
|
16
|
-
* @param extensionData
|
|
17
|
-
*/
|
|
18
|
-
export declare const extractVisibilityOverride: (extensionData: string) => ModelCategoryOverrideProviderProps | undefined;
|
|
@@ -6,11 +6,6 @@ const appearanceOverrideEmphElemMappings = [
|
|
|
6
6
|
extractColor("color"),
|
|
7
7
|
extractSimpleArray(simpleTypeOf("string"), "ids"),
|
|
8
8
|
];
|
|
9
|
-
/** Appearance Override type for VisibilityOverrides (ie ModelCategoryOverrideProviderProps) */
|
|
10
|
-
const appearanceOverrideVisibOvrMappings = [
|
|
11
|
-
extractSimpleArray(simpleTypeOf("string"), "ids"),
|
|
12
|
-
extractObject(featureAppearanceMappings, "app"),
|
|
13
|
-
];
|
|
14
9
|
const emphasizeElementsMapping = [
|
|
15
10
|
extractSimpleArray(simpleTypeOf("string"), "neverDrawn"),
|
|
16
11
|
extractSimpleArray(simpleTypeOf("string"), "alwaysDrawn"),
|
|
@@ -26,12 +21,6 @@ const perModelCategoryVisibilityMapping = [
|
|
|
26
21
|
extractString("categoryId"),
|
|
27
22
|
extractBoolean("visible"),
|
|
28
23
|
];
|
|
29
|
-
const visibilityOverrideMapping = [
|
|
30
|
-
extractArray(appearanceOverrideVisibOvrMappings, "subCategoryOverrides"),
|
|
31
|
-
extractArray(appearanceOverrideVisibOvrMappings, "modelOverrides"),
|
|
32
|
-
extractObject(appearanceOverrideVisibOvrMappings, "catEmphasizeOverride"),
|
|
33
|
-
extractObject(appearanceOverrideVisibOvrMappings, "modelEmphasizeOverride"),
|
|
34
|
-
];
|
|
35
24
|
/**
|
|
36
25
|
* Extracts the EmphasizeElementsProps from string data in an extension
|
|
37
26
|
* @param extensionData
|
|
@@ -64,16 +53,3 @@ export const extractPerModelCategoryVisibility = (extensionData) => {
|
|
|
64
53
|
}
|
|
65
54
|
return outputArray;
|
|
66
55
|
};
|
|
67
|
-
/**
|
|
68
|
-
* Extracts the VisibilityOverrideProps (ie ModelCategoryOverrideProviderProps) from string data in an extension
|
|
69
|
-
* @param extensionData
|
|
70
|
-
*/
|
|
71
|
-
export const extractVisibilityOverride = (extensionData) => {
|
|
72
|
-
const dataObj = JSON.parse(extensionData);
|
|
73
|
-
if (dataObj === undefined || dataObj.visibilityOverrideProps === undefined) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
const output = {};
|
|
77
|
-
applyExtraction(dataObj.visibilityOverrideProps, output, visibilityOverrideMapping);
|
|
78
|
-
return output;
|
|
79
|
-
};
|
package/package.json
CHANGED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type FeatureAppearanceProps } from "@itwin/core-common";
|
|
2
|
-
import type { FeatureOverrideProvider, FeatureSymbology, Viewport } from "@itwin/core-frontend";
|
|
3
|
-
interface AppearanceOverrideProps {
|
|
4
|
-
ids: string[];
|
|
5
|
-
app: FeatureAppearanceProps;
|
|
6
|
-
}
|
|
7
|
-
/** Overrides given categories to provide emphasize functionality
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
export interface ModelCategoryOverrideProviderProps {
|
|
11
|
-
subCategoryOverrides?: AppearanceOverrideProps[];
|
|
12
|
-
modelOverrides?: AppearanceOverrideProps[];
|
|
13
|
-
catEmphasizeOverride?: AppearanceOverrideProps;
|
|
14
|
-
modelEmphasizeOverride?: AppearanceOverrideProps;
|
|
15
|
-
}
|
|
16
|
-
/** Model & Category override provider (override plus emphasize)
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
19
|
-
export declare class ModelCategoryOverrideProvider implements FeatureOverrideProvider {
|
|
20
|
-
private readonly _subCategoryOverrides;
|
|
21
|
-
private readonly _modelOverrides;
|
|
22
|
-
private readonly _emphasizedSubcats;
|
|
23
|
-
private readonly _emphasizedModels;
|
|
24
|
-
private _catDefaultAppearance?;
|
|
25
|
-
private _modelDefaultAppearance?;
|
|
26
|
-
static get(vp: Viewport): ModelCategoryOverrideProvider | undefined;
|
|
27
|
-
static getOrCreate(vp: Viewport): ModelCategoryOverrideProvider;
|
|
28
|
-
addFeatureOverrides(overrides: FeatureSymbology.Overrides, _vp: Viewport): void;
|
|
29
|
-
fromJSON(props: ModelCategoryOverrideProviderProps): boolean;
|
|
30
|
-
}
|
|
31
|
-
export {};
|
|
@@ -1,88 +0,0 @@
|
|
|
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
|
-
import { FeatureAppearance } from "@itwin/core-common";
|
|
6
|
-
/** Model & Category override provider (override plus emphasize)
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export class ModelCategoryOverrideProvider {
|
|
10
|
-
_subCategoryOverrides = new Map();
|
|
11
|
-
_modelOverrides = new Map();
|
|
12
|
-
_emphasizedSubcats = [];
|
|
13
|
-
_emphasizedModels = [];
|
|
14
|
-
_catDefaultAppearance;
|
|
15
|
-
_modelDefaultAppearance;
|
|
16
|
-
static get(vp) {
|
|
17
|
-
return vp.findFeatureOverrideProviderOfType(ModelCategoryOverrideProvider);
|
|
18
|
-
}
|
|
19
|
-
static getOrCreate(vp) {
|
|
20
|
-
let provider = this.get(vp);
|
|
21
|
-
if (!provider) {
|
|
22
|
-
provider = new ModelCategoryOverrideProvider();
|
|
23
|
-
vp.addFeatureOverrideProvider(provider);
|
|
24
|
-
}
|
|
25
|
-
return provider;
|
|
26
|
-
}
|
|
27
|
-
addFeatureOverrides(overrides, _vp) {
|
|
28
|
-
this._subCategoryOverrides.forEach((appearance, ids, _map) => {
|
|
29
|
-
ids.forEach((id) => {
|
|
30
|
-
overrides.override({ subCategoryId: id, appearance });
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
this._modelOverrides.forEach((appearance, ids, _map) => {
|
|
34
|
-
ids.forEach((id) => {
|
|
35
|
-
overrides.override({ modelId: id, appearance });
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
if (0 !== this._emphasizedSubcats.length) {
|
|
39
|
-
if (this._catDefaultAppearance) {
|
|
40
|
-
overrides.setDefaultOverrides(this._catDefaultAppearance, true);
|
|
41
|
-
}
|
|
42
|
-
// Override with nothing so that we keep the category looking normal and override the default appearance of everything else
|
|
43
|
-
const override = FeatureAppearance.fromJSON({});
|
|
44
|
-
this._emphasizedSubcats.forEach((id) => {
|
|
45
|
-
overrides.override({
|
|
46
|
-
subCategoryId: id,
|
|
47
|
-
appearance: override,
|
|
48
|
-
onConflict: "replace",
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
if (0 !== this._emphasizedModels.length) {
|
|
53
|
-
if (this._modelDefaultAppearance) {
|
|
54
|
-
overrides.setDefaultOverrides(this._modelDefaultAppearance, true);
|
|
55
|
-
}
|
|
56
|
-
// Override with nothing so that we keep the category looking normal and override the default appearance of everything else
|
|
57
|
-
const override = FeatureAppearance.fromJSON({});
|
|
58
|
-
this._emphasizedModels.forEach((id) => {
|
|
59
|
-
overrides.override({
|
|
60
|
-
modelId: id,
|
|
61
|
-
appearance: override,
|
|
62
|
-
onConflict: "replace",
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
fromJSON(props) {
|
|
68
|
-
if (props.subCategoryOverrides) {
|
|
69
|
-
props.subCategoryOverrides.forEach((appProps) => {
|
|
70
|
-
this._subCategoryOverrides.set(appProps.ids, FeatureAppearance.fromJSON(appProps.app));
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
if (props.modelOverrides) {
|
|
74
|
-
props.modelOverrides.forEach((appProps) => {
|
|
75
|
-
this._modelOverrides.set(appProps.ids, FeatureAppearance.fromJSON(appProps.app));
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (props.catEmphasizeOverride) {
|
|
79
|
-
this._emphasizedSubcats.push(...props.catEmphasizeOverride.ids);
|
|
80
|
-
this._catDefaultAppearance = FeatureAppearance.fromJSON(props.catEmphasizeOverride.app);
|
|
81
|
-
}
|
|
82
|
-
if (props.modelEmphasizeOverride) {
|
|
83
|
-
this._emphasizedModels.push(...props.modelEmphasizeOverride.ids);
|
|
84
|
-
this._modelDefaultAppearance = FeatureAppearance.fromJSON(props.modelEmphasizeOverride.app);
|
|
85
|
-
}
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type Viewport } from "@itwin/core-frontend";
|
|
2
|
-
import type { SavedView } from "../SavedView.js";
|
|
3
|
-
/** Apply extension data (overrides) onto the supplied viewport. Only works with legacy-formatted extension data. */
|
|
4
|
-
export declare function applyExtensionsToViewport(viewport: Viewport, savedView: SavedView): Promise<void>;
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
import { EmphasizeElements } from "@itwin/core-frontend";
|
|
6
|
-
import { SavedViewsExtensionHandlers } from "./SavedViewsExtensionHandlers.js";
|
|
7
|
-
/** Apply extension data (overrides) onto the supplied viewport. Only works with legacy-formatted extension data. */
|
|
8
|
-
export async function applyExtensionsToViewport(viewport, savedView) {
|
|
9
|
-
// Clear the current if there's any (this should always happen, even if there are no extensions)
|
|
10
|
-
if (EmphasizeElements.get(viewport)) {
|
|
11
|
-
EmphasizeElements.clear(viewport);
|
|
12
|
-
viewport.isFadeOutActive = false;
|
|
13
|
-
}
|
|
14
|
-
const defaultHandlers = [
|
|
15
|
-
SavedViewsExtensionHandlers.EmphasizeElements,
|
|
16
|
-
SavedViewsExtensionHandlers.PerModelCategoryVisibility,
|
|
17
|
-
SavedViewsExtensionHandlers.VisibilityOverride,
|
|
18
|
-
];
|
|
19
|
-
for (const extHandler of defaultHandlers) {
|
|
20
|
-
const extData = savedView.extensions?.get(extHandler.extensionName);
|
|
21
|
-
if (extData) {
|
|
22
|
-
await extHandler.onViewApply(extData, viewport);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|