@itwin/tree-widget-react 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.d.ts +20 -0
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +121 -0
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -0
- package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +0 -10
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js +1 -28
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +10 -5
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.d.ts +2 -6
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +10 -87
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/Hierarchy.GroupedByClass.json +1 -2
- package/lib/cjs/components/trees/models-tree/Hierarchy.json +1 -2
- package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +0 -6
- package/lib/cjs/components/trees/models-tree/ModelsTree.js +4 -22
- package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +13 -3
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/CategoriesVisibilityUtils.d.ts +20 -0
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js +113 -0
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -0
- package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +0 -10
- package/lib/esm/components/trees/category-tree/CategoriesTree.js +1 -26
- package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +11 -6
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.d.ts +2 -6
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +8 -84
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/models-tree/Hierarchy.GroupedByClass.json +1 -2
- package/lib/esm/components/trees/models-tree/Hierarchy.json +1 -2
- package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +0 -6
- package/lib/esm/components/trees/models-tree/ModelsTree.js +4 -22
- package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +13 -3
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/package.json +1 -1
|
@@ -5,7 +5,6 @@ import { ClassGroupingOption } from "../Common";
|
|
|
5
5
|
import { ModelsVisibilityHandler } from "./ModelsVisibilityHandler";
|
|
6
6
|
import type { VisibilityTreeFilterInfo } from "../Common";
|
|
7
7
|
import type { ModelsTreeSelectionPredicate } from "./ModelsVisibilityHandler";
|
|
8
|
-
import type { Id64Array } from "@itwin/core-bentley";
|
|
9
8
|
import type { IModelConnection, Viewport } from "@itwin/core-frontend";
|
|
10
9
|
import type { Ruleset } from "@itwin/presentation-common";
|
|
11
10
|
import type { IPresentationTreeDataProvider } from "@itwin/presentation-components";
|
|
@@ -47,11 +46,6 @@ export interface ModelsTreeProps {
|
|
|
47
46
|
* @alpha
|
|
48
47
|
*/
|
|
49
48
|
filterInfo?: VisibilityTreeFilterInfo;
|
|
50
|
-
/**
|
|
51
|
-
* Filter the hierarchy by given element IDs.
|
|
52
|
-
* @alpha
|
|
53
|
-
*/
|
|
54
|
-
filteredElementIds?: Id64Array;
|
|
55
49
|
/**
|
|
56
50
|
* Callback invoked when tree is filtered.
|
|
57
51
|
*/
|
|
@@ -29,7 +29,6 @@ const React = __importStar(require("react"));
|
|
|
29
29
|
const components_react_1 = require("@itwin/components-react");
|
|
30
30
|
const core_react_1 = require("@itwin/core-react");
|
|
31
31
|
const presentation_components_1 = require("@itwin/presentation-components");
|
|
32
|
-
const presentation_frontend_1 = require("@itwin/presentation-frontend");
|
|
33
32
|
const TreeWidget_1 = require("../../../TreeWidget");
|
|
34
33
|
const Common_1 = require("../Common");
|
|
35
34
|
const VisibilityTreeEventHandler_1 = require("../VisibilityTreeEventHandler");
|
|
@@ -76,18 +75,10 @@ function ModelsTree(props) {
|
|
|
76
75
|
exports.ModelsTree = ModelsTree;
|
|
77
76
|
function useModelsTreeNodeLoader(props) {
|
|
78
77
|
var _a, _b;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
general: (!props.enableElementsClassGrouping) ? { ...exports.RULESET_MODELS } : /* istanbul ignore next */ { ...exports.RULESET_MODELS_GROUPED_BY_CLASS },
|
|
84
|
-
search: { ...RULESET_MODELS_SEARCH },
|
|
85
|
-
};
|
|
86
|
-
}, [props.filteredElementIds]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
87
|
-
// const rulesets = {
|
|
88
|
-
// general: (!props.enableElementsClassGrouping) ? RULESET_MODELS : /* istanbul ignore next */ RULESET_MODELS_GROUPED_BY_CLASS,
|
|
89
|
-
// search: RULESET_MODELS_SEARCH,
|
|
90
|
-
// };
|
|
78
|
+
const rulesets = {
|
|
79
|
+
general: (!props.enableElementsClassGrouping) ? exports.RULESET_MODELS : /* istanbul ignore next */ exports.RULESET_MODELS_GROUPED_BY_CLASS,
|
|
80
|
+
search: RULESET_MODELS_SEARCH,
|
|
81
|
+
};
|
|
91
82
|
const { nodeLoader, onItemsRendered } = presentation_components_1.usePresentationTreeNodeLoader({
|
|
92
83
|
imodel: props.iModel,
|
|
93
84
|
ruleset: rulesets.general,
|
|
@@ -103,15 +94,6 @@ function useModelsTreeNodeLoader(props) {
|
|
|
103
94
|
});
|
|
104
95
|
const activeNodeLoader = ((_a = props.filterInfo) === null || _a === void 0 ? void 0 : _a.filter) ? searchNodeLoader : nodeLoader;
|
|
105
96
|
const activeItemsRenderedCallback = ((_b = props.filterInfo) === null || _b === void 0 ? void 0 : _b.filter) ? onSearchItemsRendered : onItemsRendered;
|
|
106
|
-
const vars = presentation_frontend_1.Presentation.presentation.vars(activeNodeLoader.dataProvider.rulesetId);
|
|
107
|
-
if (props.filteredElementIds) {
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
109
|
-
vars.setId64s("filtered-element-ids", props.filteredElementIds);
|
|
110
|
-
}
|
|
111
|
-
else {
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
113
|
-
vars.unset("filtered-element-ids");
|
|
114
|
-
}
|
|
115
97
|
return {
|
|
116
98
|
nodeLoader: activeNodeLoader,
|
|
117
99
|
onItemsRendered: activeItemsRenderedCallback,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelsTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/models-tree/ModelsTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,6BAA2B;AAC3B,6CAA+B;AAC/B,8DAAsF;AACtF,kDAAyE;AACzE,4EAA+E;AAC/E,wEAA4D;AAC5D,oDAAiD;AACjD,sCAAgD;AAChD,8EAA2E;AAC3E,sEAAgI;AAChI,uEAA0F;AAS1F,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,gBAAgB;AACH,QAAA,cAAc,GAAY,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,yDAAyD;AAC7H,gBAAgB;AACH,QAAA,+BAA+B,GAAY,OAAO,CAAC,iCAAiC,CAAC,CAAC,CAAC,yDAAyD;AAE7J,MAAM,qBAAqB,GAAY,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,yDAAyD;AA8DpI;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAsB;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,EAAE,UAAU,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,CAAC,CAAC;AAC5H,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,YAAmF,EAAyD,EAAE;IAC5K,MAAM,gBAAgB,GAAG,YAAqD,CAAC;IAC/E,OAAO,gBAAgB,CAAC,iBAAiB,KAAK,SAAS,IAAI,gBAAgB,CAAC,cAAc,KAAK,SAAS,IAAI,gBAAgB,CAAC,qBAAqB,KAAK,SAAS,CAAC;AACnK,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,YAAmF,EAAqD,EAAE;IACzK,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport \"./ModelsTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { useDisposable, useOptionalDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { ClassGroupingOption } from \"../Common\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { ModelsVisibilityHandler, SubjectModelIdsCache } from \"./ModelsVisibilityHandler\";\nimport type { VisibilityTreeFilterInfo } from \"../Common\";\nimport type { ModelsTreeSelectionPredicate } from \"./ModelsVisibilityHandler\";\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { Id64Array } from \"@itwin/core-bentley\";\nimport type { IModelConnection, Viewport } from \"@itwin/core-frontend\";\nimport type { NodeKey, Ruleset } from \"@itwin/presentation-common\";\nimport type { IFilteredPresentationTreeDataProvider, IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\n\nconst PAGING_SIZE = 20;\n\n/** @internal */\nexport const RULESET_MODELS: Ruleset = require(\"./Hierarchy.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n/** @internal */\nexport const RULESET_MODELS_GROUPED_BY_CLASS: Ruleset = require(\"./Hierarchy.GroupedByClass.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\nconst RULESET_MODELS_SEARCH: Ruleset = require(\"./ModelsTreeSearch.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/** Props for [[ModelsTree]] component\n * @public\n */\nexport interface ModelsTreeProps {\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Selection mode in the tree\n */\n selectionMode?: SelectionMode;\n /**\n * Predicate which indicates whether node can be selected or no\n * @alpha\n */\n selectionPredicate?: ModelsTreeSelectionPredicate;\n /**\n * Active view used to determine and control visibility\n */\n activeView?: Viewport;\n /**\n * Ref to the root HTML element used by this component\n */\n rootElementRef?: React.Ref<HTMLDivElement>;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Filter the hierarchy by given element IDs.\n * @alpha\n */\n filteredElementIds?: Id64Array;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Should the tree group displayed element nodes by class.\n * @beta\n */\n enableElementsClassGrouping?: ClassGroupingOption;\n /**\n * Auto-update the hierarchy when data in the iModel changes.\n * @alpha\n */\n enableHierarchyAutoUpdate?: boolean;\n /**\n * Custom visibility handler.\n * @alpha\n */\n modelsVisibilityHandler?: ModelsVisibilityHandler;\n}\n\n/**\n * A tree component that shows a subject - model - category - element\n * hierarchy along with checkboxes that represent and allow changing\n * the display of those instances.\n * @public\n */\nexport function ModelsTree(props: ModelsTreeProps) {\n const { nodeLoader, onItemsRendered } = useModelsTreeNodeLoader(props);\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const { activeView, modelsVisibilityHandler, selectionPredicate } = props;\n const nodeSelectionPredicate = React.useCallback((key: NodeKey, node: TreeNodeItem) => {\n return !selectionPredicate ? true : selectionPredicate(key, ModelsVisibilityHandler.getNodeType(node, nodeLoader.dataProvider));\n }, [selectionPredicate, nodeLoader.dataProvider]);\n\n const visibilityHandler = useVisibilityHandler(\n nodeLoader.dataProvider.rulesetId,\n props.iModel,\n activeView,\n modelsVisibilityHandler,\n getFilteredDataProvider(filteredNodeLoader.dataProvider),\n props.enableHierarchyAutoUpdate);\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n selectionPredicate: nodeSelectionPredicate,\n }), [filteredNodeLoader, visibilityHandler, nodeSelectionPredicate]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(true, false);\n\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n\n // istanbul ignore next\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"modelTree.noModelFound\")}\n message={TreeWidget.translate(\"modelTree.noMatchingModelNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-models-tree\" ref={props.rootElementRef}>\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={props.selectionMode || SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n onItemsRendered={onItemsRendered}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useModelsTreeNodeLoader(props: ModelsTreeProps) {\n // note: this is a temporary workaround for auto-update not working on ruleset variable changes - instead\n // of auto-updating we just re-create the node loader by re-creating the ruleset\n const rulesets = React.useMemo(() => {\n return {\n general: (!props.enableElementsClassGrouping) ? { ...RULESET_MODELS } : /* istanbul ignore next */ { ...RULESET_MODELS_GROUPED_BY_CLASS },\n search: { ...RULESET_MODELS_SEARCH },\n };\n }, [props.filteredElementIds]); // eslint-disable-line react-hooks/exhaustive-deps\n // const rulesets = {\n // general: (!props.enableElementsClassGrouping) ? RULESET_MODELS : /* istanbul ignore next */ RULESET_MODELS_GROUPED_BY_CLASS,\n // search: RULESET_MODELS_SEARCH,\n // };\n\n const { nodeLoader, onItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.general,\n appendChildrenCountForGroupingNodes: (props.enableElementsClassGrouping === ClassGroupingOption.YesWithCounts),\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n const { nodeLoader: searchNodeLoader, onItemsRendered: onSearchItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.search,\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n\n const activeNodeLoader = props.filterInfo?.filter ? searchNodeLoader : nodeLoader;\n const activeItemsRenderedCallback = props.filterInfo?.filter ? onSearchItemsRendered : onItemsRendered;\n\n const vars = Presentation.presentation.vars(activeNodeLoader.dataProvider.rulesetId);\n if (props.filteredElementIds) {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n vars.setId64s(\"filtered-element-ids\", props.filteredElementIds);\n } else {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n vars.unset(\"filtered-element-ids\");\n }\n\n return {\n nodeLoader: activeNodeLoader,\n onItemsRendered: activeItemsRenderedCallback,\n };\n}\n\nfunction useVisibilityHandler(\n rulesetId: string,\n iModel: IModelConnection,\n activeView?: Viewport,\n visibilityHandler?: ModelsVisibilityHandler,\n filteredDataProvider?: IFilteredPresentationTreeDataProvider,\n hierarchyAutoUpdateEnabled?: boolean,\n) {\n const subjectModelIdsCache = React.useMemo(() => new SubjectModelIdsCache(iModel), [iModel]);\n const defaultVisibilityHandler = useOptionalDisposable(React.useCallback(() => {\n if (activeView)\n return createVisibilityHandler(rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled);\n return undefined;\n }, [rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled]));\n\n const handler = visibilityHandler ?? defaultVisibilityHandler;\n\n React.useEffect(() => {\n handler && handler.setFilteredDataProvider(filteredDataProvider);\n }, [handler, filteredDataProvider]);\n\n return handler;\n}\n\nconst createVisibilityHandler = (rulesetId: string, activeView: Viewport, subjectModelIdsCache: SubjectModelIdsCache, hierarchyAutoUpdateEnabled?: boolean): ModelsVisibilityHandler | undefined => {\n // istanbul ignore next\n return new ModelsVisibilityHandler({ rulesetId, viewport: activeView, hierarchyAutoUpdateEnabled, subjectModelIdsCache });\n};\n\nconst isFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): dataProvider is IFilteredPresentationTreeDataProvider => {\n const filteredProvider = dataProvider as IFilteredPresentationTreeDataProvider;\n return filteredProvider.nodeMatchesFilter !== undefined && filteredProvider.getActiveMatch !== undefined && filteredProvider.countFilteringResults !== undefined;\n};\n\nconst getFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): IFilteredPresentationTreeDataProvider | undefined => {\n return isFilteredDataProvider(dataProvider) ? dataProvider : undefined;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ModelsTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/models-tree/ModelsTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;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CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,YAAmF,EAAyD,EAAE;IAC5K,MAAM,gBAAgB,GAAG,YAAqD,CAAC;IAC/E,OAAO,gBAAgB,CAAC,iBAAiB,KAAK,SAAS,IAAI,gBAAgB,CAAC,cAAc,KAAK,SAAS,IAAI,gBAAgB,CAAC,qBAAqB,KAAK,SAAS,CAAC;AACnK,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,YAAmF,EAAqD,EAAE;IACzK,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport \"./ModelsTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { useDisposable, useOptionalDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { ClassGroupingOption } from \"../Common\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { ModelsVisibilityHandler, SubjectModelIdsCache } from \"./ModelsVisibilityHandler\";\n\nimport type { VisibilityTreeFilterInfo } from \"../Common\";\nimport type { ModelsTreeSelectionPredicate } from \"./ModelsVisibilityHandler\";\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IModelConnection, Viewport } from \"@itwin/core-frontend\";\nimport type { NodeKey, Ruleset } from \"@itwin/presentation-common\";\nimport type { IFilteredPresentationTreeDataProvider, IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\n\nconst PAGING_SIZE = 20;\n\n/** @internal */\nexport const RULESET_MODELS: Ruleset = require(\"./Hierarchy.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n/** @internal */\nexport const RULESET_MODELS_GROUPED_BY_CLASS: Ruleset = require(\"./Hierarchy.GroupedByClass.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\nconst RULESET_MODELS_SEARCH: Ruleset = require(\"./ModelsTreeSearch.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/** Props for [[ModelsTree]] component\n * @public\n */\nexport interface ModelsTreeProps {\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Selection mode in the tree\n */\n selectionMode?: SelectionMode;\n /**\n * Predicate which indicates whether node can be selected or no\n * @alpha\n */\n selectionPredicate?: ModelsTreeSelectionPredicate;\n /**\n * Active view used to determine and control visibility\n */\n activeView?: Viewport;\n /**\n * Ref to the root HTML element used by this component\n */\n rootElementRef?: React.Ref<HTMLDivElement>;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Should the tree group displayed element nodes by class.\n * @beta\n */\n enableElementsClassGrouping?: ClassGroupingOption;\n /**\n * Auto-update the hierarchy when data in the iModel changes.\n * @alpha\n */\n enableHierarchyAutoUpdate?: boolean;\n /**\n * Custom visibility handler.\n * @alpha\n */\n modelsVisibilityHandler?: ModelsVisibilityHandler;\n}\n\n/**\n * A tree component that shows a subject - model - category - element\n * hierarchy along with checkboxes that represent and allow changing\n * the display of those instances.\n * @public\n */\nexport function ModelsTree(props: ModelsTreeProps) {\n const { nodeLoader, onItemsRendered } = useModelsTreeNodeLoader(props);\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const { activeView, modelsVisibilityHandler, selectionPredicate } = props;\n const nodeSelectionPredicate = React.useCallback((key: NodeKey, node: TreeNodeItem) => {\n return !selectionPredicate ? true : selectionPredicate(key, ModelsVisibilityHandler.getNodeType(node, nodeLoader.dataProvider));\n }, [selectionPredicate, nodeLoader.dataProvider]);\n\n const visibilityHandler = useVisibilityHandler(\n nodeLoader.dataProvider.rulesetId,\n props.iModel,\n activeView,\n modelsVisibilityHandler,\n getFilteredDataProvider(filteredNodeLoader.dataProvider),\n props.enableHierarchyAutoUpdate);\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n selectionPredicate: nodeSelectionPredicate,\n }), [filteredNodeLoader, visibilityHandler, nodeSelectionPredicate]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(true, false);\n\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n\n // istanbul ignore next\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"modelTree.noModelFound\")}\n message={TreeWidget.translate(\"modelTree.noMatchingModelNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-models-tree\" ref={props.rootElementRef}>\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={props.selectionMode || SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n onItemsRendered={onItemsRendered}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useModelsTreeNodeLoader(props: ModelsTreeProps) {\n const rulesets = {\n general: (!props.enableElementsClassGrouping) ? RULESET_MODELS : /* istanbul ignore next */ RULESET_MODELS_GROUPED_BY_CLASS,\n search: RULESET_MODELS_SEARCH,\n };\n\n const { nodeLoader, onItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.general,\n appendChildrenCountForGroupingNodes: (props.enableElementsClassGrouping === ClassGroupingOption.YesWithCounts),\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n const { nodeLoader: searchNodeLoader, onItemsRendered: onSearchItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.search,\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n\n const activeNodeLoader = props.filterInfo?.filter ? searchNodeLoader : nodeLoader;\n const activeItemsRenderedCallback = props.filterInfo?.filter ? onSearchItemsRendered : onItemsRendered;\n\n return {\n nodeLoader: activeNodeLoader,\n onItemsRendered: activeItemsRenderedCallback,\n };\n}\n\nfunction useVisibilityHandler(\n rulesetId: string,\n iModel: IModelConnection,\n activeView?: Viewport,\n visibilityHandler?: ModelsVisibilityHandler,\n filteredDataProvider?: IFilteredPresentationTreeDataProvider,\n hierarchyAutoUpdateEnabled?: boolean,\n) {\n const subjectModelIdsCache = React.useMemo(() => new SubjectModelIdsCache(iModel), [iModel]);\n const defaultVisibilityHandler = useOptionalDisposable(React.useCallback(() => {\n if (activeView)\n return createVisibilityHandler(rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled);\n return undefined;\n }, [rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled]));\n\n const handler = visibilityHandler ?? defaultVisibilityHandler;\n\n React.useEffect(() => {\n handler && handler.setFilteredDataProvider(filteredDataProvider);\n }, [handler, filteredDataProvider]);\n\n return handler;\n}\n\nconst createVisibilityHandler = (rulesetId: string, activeView: Viewport, subjectModelIdsCache: SubjectModelIdsCache, hierarchyAutoUpdateEnabled?: boolean): ModelsVisibilityHandler | undefined => {\n // istanbul ignore next\n return new ModelsVisibilityHandler({ rulesetId, viewport: activeView, hierarchyAutoUpdateEnabled, subjectModelIdsCache });\n};\n\nconst isFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): dataProvider is IFilteredPresentationTreeDataProvider => {\n const filteredProvider = dataProvider as IFilteredPresentationTreeDataProvider;\n return filteredProvider.nodeMatchesFilter !== undefined && filteredProvider.getActiveMatch !== undefined && filteredProvider.countFilteringResults !== undefined;\n};\n\nconst getFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): IFilteredPresentationTreeDataProvider | undefined => {\n return isFilteredDataProvider(dataProvider) ? dataProvider : undefined;\n};\n"]}
|
|
@@ -25,12 +25,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.ModelsTreeComponent = void 0;
|
|
27
27
|
const react_1 = __importStar(require("react"));
|
|
28
|
+
const core_frontend_1 = require("@itwin/core-frontend");
|
|
28
29
|
const appui_react_1 = require("@itwin/appui-react");
|
|
29
30
|
const TreeFilteringState_1 = require("../../TreeFilteringState");
|
|
30
31
|
require("./ModelsTree.scss");
|
|
31
32
|
const TreeHeader_1 = require("../../header/TreeHeader");
|
|
32
33
|
const AutoSizer_1 = require("../../utils/AutoSizer");
|
|
33
34
|
const ModelsTree_1 = require("./ModelsTree");
|
|
35
|
+
const CategoriesVisibilityUtils_1 = require("../CategoriesVisibilityUtils");
|
|
34
36
|
const ModelsTreeComponent = (props) => {
|
|
35
37
|
const [is2dToggleActive, setIs2dToggleActive] = react_1.useState(false);
|
|
36
38
|
const [is3dToggleActive, setIs3dToggleActive] = react_1.useState(false);
|
|
@@ -85,14 +87,22 @@ const ModelsTreeComponent = (props) => {
|
|
|
85
87
|
viewport === null || viewport === void 0 ? void 0 : viewport.changeModelDisplay(models, false);
|
|
86
88
|
viewport === null || viewport === void 0 ? void 0 : viewport.invalidateScene();
|
|
87
89
|
}, [viewport, availableModels]);
|
|
88
|
-
const hideAll = react_1.useCallback(() => {
|
|
90
|
+
const hideAll = react_1.useCallback(async () => {
|
|
89
91
|
viewport === null || viewport === void 0 ? void 0 : viewport.changeModelDisplay(availableModels, false);
|
|
92
|
+
viewport === null || viewport === void 0 ? void 0 : viewport.clearAlwaysDrawn();
|
|
93
|
+
if (iModel) {
|
|
94
|
+
await CategoriesVisibilityUtils_1.toggleAllCategories(core_frontend_1.IModelApp.viewManager, iModel, false, viewport, false, undefined);
|
|
95
|
+
}
|
|
90
96
|
viewport === null || viewport === void 0 ? void 0 : viewport.invalidateScene();
|
|
91
|
-
}, [viewport, availableModels]);
|
|
97
|
+
}, [viewport, availableModels, iModel]);
|
|
92
98
|
const showAll = react_1.useCallback(async () => {
|
|
93
99
|
await (viewport === null || viewport === void 0 ? void 0 : viewport.addViewedModels(availableModels));
|
|
100
|
+
viewport === null || viewport === void 0 ? void 0 : viewport.clearNeverDrawn();
|
|
101
|
+
if (iModel) {
|
|
102
|
+
await CategoriesVisibilityUtils_1.toggleAllCategories(core_frontend_1.IModelApp.viewManager, iModel, true, viewport, false, undefined);
|
|
103
|
+
}
|
|
94
104
|
viewport === null || viewport === void 0 ? void 0 : viewport.invalidateScene();
|
|
95
|
-
}, [viewport, availableModels]);
|
|
105
|
+
}, [viewport, availableModels, iModel]);
|
|
96
106
|
const viewToggle2D = react_1.useCallback(async () => {
|
|
97
107
|
if (is2dToggleActive) {
|
|
98
108
|
viewport === null || viewport === void 0 ? void 0 : viewport.changeModelDisplay(available2dModels, false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelsTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/models-tree/ModelsTreeComponent.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,+CAAgE;AAEhE,oDAAkF;AAClF,iEAAiE;AACjE,6BAA2B;AAK3B,wDAA8D;AAE9D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B,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,YAAY,GAC1B;YACF,8BAAC,qBAAS,QACP,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CACtB,8BAAC,uBAAU,OACL,KAAK,EACT,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,QAAQ,EACpB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,EACtD,eAAe,EAAE,eAAe,GAChC,CACH,CACS,CACX,CAEJ,CACJ,CAAC;AACJ,CAAC,CAAC;AAjIW,QAAA,mBAAmB,uBAiI9B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport \"./ModelsTree.scss\";\nimport type {\n GeometricModel3dProps,\n ModelQueryParams,\n} from \"@itwin/core-common\";\nimport { TreeHeaderComponent } from \"../../header/TreeHeader\";\nimport type { ModelTreeProps } from \"../../../types\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { ModelsTree } from \"./ModelsTree\";\n\ninterface TreeViewModelInfo {\n id: string;\n isPlanProjection?: boolean;\n}\n\nexport const ModelsTreeComponent = (props: ModelTreeProps) => {\n const [is2dToggleActive, setIs2dToggleActive] = useState<boolean>(false);\n const [is3dToggleActive, setIs3dToggleActive] = useState<boolean>(false);\n const [icon2dToggle, setIcon2dToggle] = useState<string>(\"icon-visibility\");\n const [icon3dToggle, setIcon3dToggle] = useState<string>(\"icon-visibility\");\n\n const [available2dModels, setAvailable2dModels] = useState<string[]>([]);\n const [available3dModels, setAvailable3dModels] = useState<string[]>([]);\n const [availableModels, setAvailableModels] = useState<string[]>([]);\n\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n const { searchOptions, filterString, activeMatchIndex, onFilterApplied } =\n useTreeFilteringState();\n\n const queryModels = useCallback(async (\n vp: Viewport | undefined\n ): Promise<TreeViewModelInfo[]> => {\n if (vp === undefined) return [];\n\n const queryParams: ModelQueryParams = {\n from: \"BisCore.GeometricModel3d\",\n wantPrivate: false,\n };\n const modelProps = await iModel?.models.queryProps(queryParams) ?? [];\n return modelProps\n .map(({ id, isPlanProjection }: GeometricModel3dProps) => ({ id, isPlanProjection }))\n .filter(({ id }) => id) as TreeViewModelInfo[];\n }, [iModel]);\n\n useEffect(() => {\n queryModels(viewport)\n .then((modelInfos: TreeViewModelInfo[]) => {\n setAvailableModels(modelInfos.map(({ id }) => id));\n\n const { models2d, models3d } = modelInfos.reduce((acc, { id, isPlanProjection }) => {\n isPlanProjection ? acc.models2d.push(id) : acc.models3d.push(id);\n return acc;\n }, { models2d: [] as string[], models3d: [] as string[] });\n\n setAvailable2dModels(models2d);\n setAvailable3dModels(models3d);\n })\n .catch((_e) => {\n setAvailableModels([]);\n });\n }, [queryModels, viewport]);\n\n const invert = useCallback(async () => {\n if (availableModels.length === 0) return;\n const notViewedModels: string[] = [];\n const models: string[] = [];\n availableModels.forEach((id: string) => {\n if (viewport?.viewsModel(id)) models.push(id);\n else notViewedModels.push(id);\n });\n await viewport?.addViewedModels(notViewedModels);\n viewport?.changeModelDisplay(models, false);\n viewport?.invalidateScene();\n }, [viewport, availableModels]);\n\n const hideAll = useCallback(() => {\n viewport?.changeModelDisplay(availableModels, false);\n viewport?.invalidateScene();\n }, [viewport, availableModels]);\n\n const showAll = useCallback(async () => {\n await viewport?.addViewedModels(availableModels);\n viewport?.invalidateScene();\n }, [viewport, availableModels]);\n\n const viewToggle2D = useCallback(async () => {\n if (is2dToggleActive) {\n viewport?.changeModelDisplay(available2dModels, false);\n setIs2dToggleActive(false);\n setIcon2dToggle(\"icon-visibility-hide-2\");\n } else {\n await viewport?.addViewedModels(available2dModels);\n setIs2dToggleActive(true);\n setIcon2dToggle(\"icon-visibility\");\n }\n viewport?.invalidateScene();\n }, [is2dToggleActive, viewport, available2dModels]);\n\n const viewToggle3D = useCallback(async () => {\n if (is3dToggleActive) {\n viewport?.changeModelDisplay(available3dModels, false);\n setIs3dToggleActive(false);\n setIcon3dToggle(\"icon-visibility-hide-2\");\n } else {\n await viewport?.addViewedModels(available3dModels);\n setIs3dToggleActive(true);\n setIcon3dToggle(\"icon-visibility\");\n }\n viewport?.invalidateScene();\n }, [is3dToggleActive, viewport, available3dModels]);\n\n return (\n <>\n {iModel && viewport &&\n <>\n <TreeHeaderComponent\n searchOptions={searchOptions}\n showAll={showAll}\n hideAll={hideAll}\n invert={invert}\n toggle2D={viewToggle2D}\n toggle2DIcon={icon2dToggle}\n toggle3D={viewToggle3D}\n toggle3DIcon={icon3dToggle}\n />\n <AutoSizer>\n {({ width, height }) => (\n <ModelsTree\n {...props}\n iModel={iModel}\n activeView={viewport}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n }\n </>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ModelsTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/models-tree/ModelsTreeComponent.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,+CAAgE;AAEhE,wDAAiD;AACjD,oDAAkF;AAClF,iEAAiE;AACjE,6BAA2B;AAK3B,wDAA8D;AAE9D,qDAAkD;AAClD,6CAA0C;AAC1C,4EAAmE;AAO5D,MA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C3C;aAAM;YACL,MAAM,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,eAAe,CAAC,iBAAiB,CAAC,CAAA,CAAC;YACnD,mBAAmB,CAAC,IAAI,CAAC,CAAC;YAC1B,eAAe,CAAC,iBAAiB,CAAC,CAAC;SACpC;QACD,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,eAAe,EAAE,CAAC;IAC9B,CAAC,EAAE,CAAC,gBAAgB,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAEpD,OAAO,CACL,8DACG,MAAM,IAAI,QAAQ;QACjB;YACE,8BAAC,gCAAmB,IAClB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,YAAY,EACtB,YAAY,EAAE,YAAY,GAC1B;YACF,8BAAC,qBAAS,QACP,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CACtB,8BAAC,uBAAU,OACL,KAAK,EACT,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,QAAQ,EACpB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,EACtD,eAAe,EAAE,eAAe,GAChC,CACH,CACS,CACX,CAEJ,CACJ,CAAC;AACJ,CAAC,CAAC;AAvJW,QAAA,mBAAmB,uBAuJ9B","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport React, { useCallback, useEffect, useState } from \"react\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport \"./ModelsTree.scss\";\nimport type {\n GeometricModel3dProps,\n ModelQueryParams,\n} from \"@itwin/core-common\";\nimport { TreeHeaderComponent } from \"../../header/TreeHeader\";\nimport type { ModelTreeProps } from \"../../../types\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { ModelsTree } from \"./ModelsTree\";\nimport { toggleAllCategories } from \"../CategoriesVisibilityUtils\";\n\ninterface TreeViewModelInfo {\n id: string;\n isPlanProjection?: boolean;\n}\n\nexport const ModelsTreeComponent = (props: ModelTreeProps) => {\n const [is2dToggleActive, setIs2dToggleActive] = useState<boolean>(false);\n const [is3dToggleActive, setIs3dToggleActive] = useState<boolean>(false);\n const [icon2dToggle, setIcon2dToggle] = useState<string>(\"icon-visibility\");\n const [icon3dToggle, setIcon3dToggle] = useState<string>(\"icon-visibility\");\n\n const [available2dModels, setAvailable2dModels] = useState<string[]>([]);\n const [available3dModels, setAvailable3dModels] = useState<string[]>([]);\n const [availableModels, setAvailableModels] = useState<string[]>([]);\n\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n const { searchOptions, filterString, activeMatchIndex, onFilterApplied } =\n useTreeFilteringState();\n\n const queryModels = useCallback(async (\n vp: Viewport | undefined\n ): Promise<TreeViewModelInfo[]> => {\n if (vp === undefined) return [];\n\n const queryParams: ModelQueryParams = {\n from: \"BisCore.GeometricModel3d\",\n wantPrivate: false,\n };\n const modelProps = await iModel?.models.queryProps(queryParams) ?? [];\n return modelProps\n .map(({ id, isPlanProjection }: GeometricModel3dProps) => ({ id, isPlanProjection }))\n .filter(({ id }) => id) as TreeViewModelInfo[];\n }, [iModel]);\n\n useEffect(() => {\n queryModels(viewport)\n .then((modelInfos: TreeViewModelInfo[]) => {\n setAvailableModels(modelInfos.map(({ id }) => id));\n\n const { models2d, models3d } = modelInfos.reduce((acc, { id, isPlanProjection }) => {\n isPlanProjection ? acc.models2d.push(id) : acc.models3d.push(id);\n return acc;\n }, { models2d: [] as string[], models3d: [] as string[] });\n\n setAvailable2dModels(models2d);\n setAvailable3dModels(models3d);\n })\n .catch((_e) => {\n setAvailableModels([]);\n });\n }, [queryModels, viewport]);\n\n const invert = useCallback(async () => {\n if (availableModels.length === 0) return;\n const notViewedModels: string[] = [];\n const models: string[] = [];\n availableModels.forEach((id: string) => {\n if (viewport?.viewsModel(id)) models.push(id);\n else notViewedModels.push(id);\n });\n await viewport?.addViewedModels(notViewedModels);\n viewport?.changeModelDisplay(models, false);\n viewport?.invalidateScene();\n }, [viewport, availableModels]);\n\n const hideAll = useCallback(async () => {\n viewport?.changeModelDisplay(availableModels, false);\n viewport?.clearAlwaysDrawn();\n if (iModel) {\n await toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n false,\n viewport,\n false,\n undefined\n );\n }\n viewport?.invalidateScene();\n }, [viewport, availableModels, iModel]);\n\n const showAll = useCallback(async () => {\n await viewport?.addViewedModels(availableModels);\n viewport?.clearNeverDrawn();\n if (iModel) {\n await toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n true,\n viewport,\n false,\n undefined\n );\n }\n viewport?.invalidateScene();\n }, [viewport, availableModels, iModel]);\n\n const viewToggle2D = useCallback(async () => {\n if (is2dToggleActive) {\n viewport?.changeModelDisplay(available2dModels, false);\n setIs2dToggleActive(false);\n setIcon2dToggle(\"icon-visibility-hide-2\");\n } else {\n await viewport?.addViewedModels(available2dModels);\n setIs2dToggleActive(true);\n setIcon2dToggle(\"icon-visibility\");\n }\n viewport?.invalidateScene();\n }, [is2dToggleActive, viewport, available2dModels]);\n\n const viewToggle3D = useCallback(async () => {\n if (is3dToggleActive) {\n viewport?.changeModelDisplay(available3dModels, false);\n setIs3dToggleActive(false);\n setIcon3dToggle(\"icon-visibility-hide-2\");\n } else {\n await viewport?.addViewedModels(available3dModels);\n setIs3dToggleActive(true);\n setIcon3dToggle(\"icon-visibility\");\n }\n viewport?.invalidateScene();\n }, [is3dToggleActive, viewport, available3dModels]);\n\n return (\n <>\n {iModel && viewport &&\n <>\n <TreeHeaderComponent\n searchOptions={searchOptions}\n showAll={showAll}\n hideAll={hideAll}\n invert={invert}\n toggle2D={viewToggle2D}\n toggle2DIcon={icon2dToggle}\n toggle3D={viewToggle3D}\n toggle3DIcon={icon3dToggle}\n />\n <AutoSizer>\n {({ width, height }) => (\n <ModelsTree\n {...props}\n iModel={iModel}\n activeView={viewport}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n }\n </>\n );\n};\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
|
|
2
|
+
import type { Category } from "./category-tree/CategoryVisibilityHandler";
|
|
3
|
+
import type { Id64String } from "@itwin/core-bentley";
|
|
4
|
+
/**
|
|
5
|
+
* Toggles visibility of categories to show or hide.
|
|
6
|
+
* @alpha
|
|
7
|
+
*/
|
|
8
|
+
export declare function toggleAllCategories(viewManager: ViewManager, imodel: IModelConnection, display: boolean, viewport?: Viewport, forAllViewports?: boolean, categoryIds?: Id64String[]): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Gets ids of all categories from specified imodel and viewport.
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCategories(imodel: IModelConnection, viewport?: Viewport): Promise<string[]>;
|
|
14
|
+
/** Changes category display in the viewport */
|
|
15
|
+
export declare function enableCategory(viewManager: ViewManager, imodel: IModelConnection, ids: string[], enabled: boolean, forAllViewports: boolean, enableAllSubCategories?: boolean): void;
|
|
16
|
+
/** Changes subcategory display in the viewport */
|
|
17
|
+
export declare function enableSubCategory(viewManager: ViewManager, key: string, enabled: boolean, forAllViewports?: boolean): void;
|
|
18
|
+
/** @internal */
|
|
19
|
+
export declare function loadCategoriesFromViewport(iModel?: IModelConnection, vp?: Viewport): Promise<Category[]>;
|
|
20
|
+
//# sourceMappingURL=CategoriesVisibilityUtils.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { PerModelCategoryVisibility } from "@itwin/core-frontend";
|
|
6
|
+
import { QueryRowFormat } from "@itwin/core-common";
|
|
7
|
+
const EMPTY_CATEGORIES_ARRAY = [];
|
|
8
|
+
/**
|
|
9
|
+
* Toggles visibility of categories to show or hide.
|
|
10
|
+
* @alpha
|
|
11
|
+
*/
|
|
12
|
+
export async function toggleAllCategories(viewManager, imodel, display, viewport, forAllViewports, categoryIds) {
|
|
13
|
+
if (categoryIds) {
|
|
14
|
+
enableCategory(viewManager, imodel, categoryIds, display, forAllViewports !== null && forAllViewports !== void 0 ? forAllViewports : false);
|
|
15
|
+
}
|
|
16
|
+
// istanbul ignore next
|
|
17
|
+
const activeView = viewport !== null && viewport !== void 0 ? viewport : viewManager.getFirstOpenView();
|
|
18
|
+
const ids = await getCategories(imodel, activeView);
|
|
19
|
+
// istanbul ignore else
|
|
20
|
+
if (ids.length > 0) {
|
|
21
|
+
enableCategory(viewManager, imodel, ids, display, forAllViewports !== null && forAllViewports !== void 0 ? forAllViewports : false);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets ids of all categories from specified imodel and viewport.
|
|
26
|
+
* @alpha
|
|
27
|
+
*/
|
|
28
|
+
export async function getCategories(imodel, viewport) {
|
|
29
|
+
const categories = await loadCategoriesFromViewport(imodel, viewport);
|
|
30
|
+
return categories.map((category) => category.key);
|
|
31
|
+
}
|
|
32
|
+
/** Changes category display in the viewport */
|
|
33
|
+
export function enableCategory(viewManager, imodel, ids, enabled, forAllViewports, enableAllSubCategories = true) {
|
|
34
|
+
if (!viewManager.selectedView)
|
|
35
|
+
return;
|
|
36
|
+
const updateViewport = (vp) => {
|
|
37
|
+
// Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we
|
|
38
|
+
// are using 'allViewports' property
|
|
39
|
+
if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {
|
|
40
|
+
vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);
|
|
41
|
+
// remove category overrides per model
|
|
42
|
+
const modelsContainingOverrides = [];
|
|
43
|
+
for (const ovr of vp.perModelCategoryVisibility) {
|
|
44
|
+
// istanbul ignore else
|
|
45
|
+
if (ids.findIndex((id) => id === ovr.categoryId) !== -1)
|
|
46
|
+
modelsContainingOverrides.push(ovr.modelId);
|
|
47
|
+
}
|
|
48
|
+
vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);
|
|
49
|
+
// changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.
|
|
50
|
+
if (false === enabled) {
|
|
51
|
+
ids.forEach((id) => {
|
|
52
|
+
const subCategoryIds = imodel.subcategories.getSubCategories(id);
|
|
53
|
+
// istanbul ignore else
|
|
54
|
+
if (subCategoryIds) {
|
|
55
|
+
subCategoryIds.forEach((subCategoryId) => enableSubCategory(viewManager, subCategoryId, false, forAllViewports));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
// This property let us act on all viewports or just on the selected one, configurable by the app
|
|
62
|
+
if (forAllViewports) {
|
|
63
|
+
for (const viewport of viewManager) {
|
|
64
|
+
updateViewport(viewport);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
updateViewport(viewManager.selectedView);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** Changes subcategory display in the viewport */
|
|
72
|
+
export function enableSubCategory(viewManager, key, enabled, forAllViewports) {
|
|
73
|
+
if (!viewManager.selectedView)
|
|
74
|
+
return;
|
|
75
|
+
const updateViewport = (vp) => {
|
|
76
|
+
// Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we
|
|
77
|
+
// are using 'allViewports' property
|
|
78
|
+
if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {
|
|
79
|
+
vp.changeSubCategoryDisplay(key, enabled);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
// This property let us act on all viewports or just on the selected one, configurable by the app
|
|
83
|
+
if (forAllViewports) {
|
|
84
|
+
for (const viewport of viewManager) {
|
|
85
|
+
updateViewport(viewport);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
updateViewport(viewManager.selectedView);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** @internal */
|
|
93
|
+
export async function loadCategoriesFromViewport(iModel, vp) {
|
|
94
|
+
if (!vp)
|
|
95
|
+
return EMPTY_CATEGORIES_ARRAY;
|
|
96
|
+
// Query categories and add them to state
|
|
97
|
+
const selectUsedSpatialCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)";
|
|
98
|
+
const selectUsedDrawingCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)";
|
|
99
|
+
const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;
|
|
100
|
+
const ecsql2 = `SELECT ECInstanceId as id, UserLabel as label, CodeValue as code FROM ${vp.view.is3d() ? "BisCore.SpatialCategory" : "BisCore.DrawingCategory"} WHERE ECInstanceId IN (${ecsql})`;
|
|
101
|
+
const categories = [];
|
|
102
|
+
// istanbul ignore else
|
|
103
|
+
if (iModel) {
|
|
104
|
+
const rowIterator = iModel.query(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames });
|
|
105
|
+
// istanbul ignore next
|
|
106
|
+
for await (const row of rowIterator) {
|
|
107
|
+
const subCategoryIds = iModel.subcategories.getSubCategories(row.id);
|
|
108
|
+
categories.push({ key: row.id, children: (subCategoryIds) ? [...subCategoryIds] : undefined });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return categories;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=CategoriesVisibilityUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../src/components/trees/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAIlE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,sBAAsB,GAAe,EAAE,CAAC;AAE9C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAAwB,EAAE,MAAwB,EAAE,OAAgB,EAAE,QAAmB,EAAE,eAAyB,EAAE,WAA0B;IACxL,IAAI,WAAW,EAAE;QACf,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,KAAK,CAAC,CAAC;KACrF;IAED,uBAAuB;IACvB,MAAM,UAAU,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC9D,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAEpD,uBAAuB;IACvB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QAClB,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,KAAK,CAAC,CAAC;KAC7E;AACH,CAA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,KAAK,UAAU,0BAA0B,CAAC,MAAyB,EAAE,EAAa;IACvF,IAAI,CAAC,EAAE;QACL,OAAO,sBAAsB,CAAC;IAEhC,yCAAyC;IACzC,MAAM,4BAA4B,GAAG,2IAA2I,CAAC;IACjL,MAAM,4BAA4B,GAAG,0JAA0J,CAAC;IAChM,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,4BAA4B,CAAC;IAC3F,MAAM,MAAM,GAAG,yEAAyE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,yBAAyB,2BAA2B,KAAK,GAAG,CAAC;IAElM,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,uBAAuB;IACvB,IAAI,MAAM,EAAE;QACV,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,cAAc,CAAC,kBAAkB,EAAE,CAAC,CAAC;QACtG,uBAAuB;QACvB,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,WAAW,EAAE;YACnC,MAAM,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACrE,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;SAChG;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { PerModelCategoryVisibility } from \"@itwin/core-frontend\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { Category } from \"./category-tree/CategoryVisibilityHandler\";\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\n\nconst EMPTY_CATEGORIES_ARRAY: Category[] = [];\n\n/**\n * Toggles visibility of categories to show or hide.\n * @alpha\n */\nexport async function toggleAllCategories(viewManager: ViewManager, imodel: IModelConnection, display: boolean, viewport?: Viewport, forAllViewports?: boolean, categoryIds?: Id64String[]) {\n if (categoryIds) {\n enableCategory(viewManager, imodel, categoryIds, display, forAllViewports ?? false);\n }\n\n // istanbul ignore next\n const activeView = viewport ?? viewManager.getFirstOpenView();\n const ids = await getCategories(imodel, activeView);\n\n // istanbul ignore else\n if (ids.length > 0) {\n enableCategory(viewManager, imodel, ids, display, forAllViewports ?? false);\n }\n}\n\n/**\n * Gets ids of all categories from specified imodel and viewport.\n * @alpha\n */\nexport async function getCategories(imodel: IModelConnection, viewport?: Viewport) {\n const categories = await loadCategoriesFromViewport(imodel, viewport);\n return categories.map((category) => category.key);\n}\n\n/** Changes category display in the viewport */\nexport function enableCategory(viewManager: ViewManager, imodel: IModelConnection, ids: string[], enabled: boolean, forAllViewports: boolean, enableAllSubCategories = true) {\n if (!viewManager.selectedView)\n return;\n\n const updateViewport = (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of vp.perModelCategoryVisibility) {\n // istanbul ignore else\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1)\n modelsContainingOverrides.push(ovr.modelId);\n }\n vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);\n\n // changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.\n if (false === enabled) {\n ids.forEach((id) => {\n const subCategoryIds = imodel.subcategories.getSubCategories(id);\n // istanbul ignore else\n if (subCategoryIds) {\n subCategoryIds.forEach((subCategoryId) => enableSubCategory(viewManager, subCategoryId, false, forAllViewports));\n }\n });\n }\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n updateViewport(viewport);\n }\n } else {\n updateViewport(viewManager.selectedView);\n }\n}\n\n/** Changes subcategory display in the viewport */\nexport function enableSubCategory(viewManager: ViewManager, key: string, enabled: boolean, forAllViewports?: boolean) {\n if (!viewManager.selectedView)\n return;\n\n const updateViewport = (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeSubCategoryDisplay(key, enabled);\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n updateViewport(viewport);\n }\n } else {\n updateViewport(viewManager.selectedView);\n }\n}\n\n/** @internal */\nexport async function loadCategoriesFromViewport(iModel?: IModelConnection, vp?: Viewport) {\n if (!vp)\n return EMPTY_CATEGORIES_ARRAY;\n\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds = \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds = \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)\";\n const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;\n const ecsql2 = `SELECT ECInstanceId as id, UserLabel as label, CodeValue as code FROM ${vp.view.is3d() ? \"BisCore.SpatialCategory\" : \"BisCore.DrawingCategory\"} WHERE ECInstanceId IN (${ecsql})`;\n\n const categories: Category[] = [];\n\n // istanbul ignore else\n if (iModel) {\n const rowIterator = iModel.query(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames });\n // istanbul ignore next\n for await (const row of rowIterator) {\n const subCategoryIds = iModel.subcategories.getSubCategories(row.id);\n categories.push({ key: row.id, children: (subCategoryIds) ? [...subCategoryIds] : undefined });\n }\n }\n\n return categories;\n}\n"]}
|
|
@@ -52,14 +52,4 @@ export interface CategoryTreeProps {
|
|
|
52
52
|
* @public
|
|
53
53
|
*/
|
|
54
54
|
export declare function CategoryTree(props: CategoryTreeProps): JSX.Element;
|
|
55
|
-
/**
|
|
56
|
-
* Toggles visibility of categories to show or hide.
|
|
57
|
-
* @alpha
|
|
58
|
-
*/
|
|
59
|
-
export declare function toggleAllCategories(viewManager: ViewManager, imodel: IModelConnection, display: boolean, viewport?: Viewport, forAllViewports?: boolean, filteredProvider?: IPresentationTreeDataProvider): Promise<void>;
|
|
60
|
-
/**
|
|
61
|
-
* Gets ids of all categories or categories from filtered data provider.
|
|
62
|
-
* @alpha
|
|
63
|
-
*/
|
|
64
|
-
export declare function getCategories(imodel: IModelConnection, viewport?: Viewport, filteredProvider?: IPresentationTreeDataProvider): Promise<string[]>;
|
|
65
55
|
//# sourceMappingURL=CategoriesTree.d.ts.map
|
|
@@ -12,7 +12,7 @@ import { Presentation } from "@itwin/presentation-frontend";
|
|
|
12
12
|
import { TreeWidget } from "../../../TreeWidget";
|
|
13
13
|
import { VisibilityTreeEventHandler } from "../VisibilityTreeEventHandler";
|
|
14
14
|
import { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from "../VisibilityTreeRenderer";
|
|
15
|
-
import { CategoryVisibilityHandler,
|
|
15
|
+
import { CategoryVisibilityHandler, useCategories } from "./CategoryVisibilityHandler";
|
|
16
16
|
const PAGING_SIZE = 20;
|
|
17
17
|
/**
|
|
18
18
|
* Presentation rules used by ControlledCategoriesTree
|
|
@@ -68,29 +68,4 @@ async function setViewType(activeView) {
|
|
|
68
68
|
const viewType = view.is3d() ? "3d" : "2d";
|
|
69
69
|
await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString("ViewType", viewType);
|
|
70
70
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Toggles visibility of categories to show or hide.
|
|
73
|
-
* @alpha
|
|
74
|
-
*/
|
|
75
|
-
export async function toggleAllCategories(viewManager, imodel, display, viewport, forAllViewports, filteredProvider) {
|
|
76
|
-
// istanbul ignore next
|
|
77
|
-
const activeView = viewport !== null && viewport !== void 0 ? viewport : viewManager.getFirstOpenView();
|
|
78
|
-
const ids = await getCategories(imodel, activeView, filteredProvider);
|
|
79
|
-
// istanbul ignore else
|
|
80
|
-
if (ids.length > 0) {
|
|
81
|
-
CategoryVisibilityHandler.enableCategory(viewManager, imodel, ids, display, forAllViewports !== null && forAllViewports !== void 0 ? forAllViewports : false);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Gets ids of all categories or categories from filtered data provider.
|
|
86
|
-
* @alpha
|
|
87
|
-
*/
|
|
88
|
-
export async function getCategories(imodel, viewport, filteredProvider) {
|
|
89
|
-
if (filteredProvider) {
|
|
90
|
-
const nodes = await filteredProvider.getNodes();
|
|
91
|
-
return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));
|
|
92
|
-
}
|
|
93
|
-
const categories = await loadCategoriesFromViewport(imodel, viewport);
|
|
94
|
-
return categories.map((category) => category.key);
|
|
95
|
-
}
|
|
96
71
|
//# sourceMappingURL=CategoriesTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,uBAAuB,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B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AC,CAAC;AAC9F,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAAwB,EAAE,MAAwB,EAAE,OAAgB,EAAE,QAAmB,EAAE,eAAyB,EAAE,gBAAgD;IAC9M,uBAAuB;IACvB,MAAM,UAAU,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC9D,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAEtE,uBAAuB;IACvB,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;QAClB,yBAAyB,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,KAAK,CAAC,CAAC;KACvG;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAwB,EAAE,QAAmB,EAAE,gBAAgD;IACjI,IAAI,gBAAgB,EAAE;QACpB,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,yBAAyB,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACvH;IAED,MAAM,UAAU,GAAG,MAAM,0BAA0B,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport \"./CategoriesTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryVisibilityHandler, loadCategoriesFromViewport, useCategories } from \"./CategoryVisibilityHandler\";\nimport type { IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { Ruleset } from \"@itwin/presentation-common\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { VisibilityTreeFilterInfo } from \"../Common\";\nimport type { Category } from \"./CategoryVisibilityHandler\";\n\nconst PAGING_SIZE = 20;\n\n/**\n * Presentation rules used by ControlledCategoriesTree\n * @internal\n */\nexport const RULESET_CATEGORIES: Ruleset = require(\"./Categories.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/**\n * Properties for the [[CategoryTree]] component\n * @public\n */\nexport interface CategoryTreeProps {\n /** Flag for accommodating all viewports */\n allViewports?: boolean;\n /** Active viewport */\n activeView?: Viewport;\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Custom category visibility handler to use for testing\n * @internal\n */\n categoryVisibilityHandler?: CategoryVisibilityHandler;\n /**\n * Custom view manager to use for testing\n * @internal\n */\n viewManager?: ViewManager;\n}\n\n/**\n * Tree which displays and manages categories contained in an iModel.\n * @public\n */\nexport function CategoryTree(props: CategoryTreeProps) {\n const { nodeLoader } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: RULESET_CATEGORIES,\n pagingSize: PAGING_SIZE,\n });\n\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n // istanbul ignore next\n const viewManager = props.viewManager ?? IModelApp.viewManager;\n const { activeView, allViewports, categoryVisibilityHandler } = props;\n const currentActiveView = activeView ?? viewManager.getFirstOpenView();\n const categories = useCategories(viewManager, props.iModel, currentActiveView);\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, categories, currentActiveView, allViewports, categoryVisibilityHandler);\n\n React.useEffect(() => {\n setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises\n }, [currentActiveView]);\n\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n }), [filteredNodeLoader, visibilityHandler]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(false, true);\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"categoriesTree.noCategoryFound\")}\n message={TreeWidget.translate(\"categoriesTree.noMatchingCategoryNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-categories-tree\">\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n descriptionsEnabled={true}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useCategoryVisibilityHandler(viewManager: ViewManager, imodel: IModelConnection, categories: Category[], activeView?: Viewport, allViewports?: boolean, visibilityHandler?: CategoryVisibilityHandler) {\n return useDisposable(React.useCallback(\n () =>\n // istanbul ignore next\n visibilityHandler ?? new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }),\n [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]),\n );\n}\n\nasync function setViewType(activeView?: Viewport) {\n if (!activeView)\n return;\n\n const view = activeView.view as SpatialViewState;\n const viewType = view.is3d() ? \"3d\" : \"2d\";\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\n\n/**\n * Toggles visibility of categories to show or hide.\n * @alpha\n */\nexport async function toggleAllCategories(viewManager: ViewManager, imodel: IModelConnection, display: boolean, viewport?: Viewport, forAllViewports?: boolean, filteredProvider?: IPresentationTreeDataProvider) {\n // istanbul ignore next\n const activeView = viewport ?? viewManager.getFirstOpenView();\n const ids = await getCategories(imodel, activeView, filteredProvider);\n\n // istanbul ignore else\n if (ids.length > 0) {\n CategoryVisibilityHandler.enableCategory(viewManager, imodel, ids, display, forAllViewports ?? false);\n }\n}\n\n/**\n * Gets ids of all categories or categories from filtered data provider.\n * @alpha\n */\nexport async function getCategories(imodel: IModelConnection, viewport?: Viewport, filteredProvider?: IPresentationTreeDataProvider) {\n if (filteredProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));\n }\n\n const categories = await loadCategoriesFromViewport(imodel, viewport);\n return categories.map((category) => category.key);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,uBAAuB,CAAC;AAC/B,OAAO,KAA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U,EAAE,QAAQ,CAAC,CAAC;AAC9F,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport \"./CategoriesTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryVisibilityHandler, useCategories } from \"./CategoryVisibilityHandler\";\nimport type { IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { Ruleset } from \"@itwin/presentation-common\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { VisibilityTreeFilterInfo } from \"../Common\";\nimport type { Category } from \"./CategoryVisibilityHandler\";\n\nconst PAGING_SIZE = 20;\n\n/**\n * Presentation rules used by ControlledCategoriesTree\n * @internal\n */\nexport const RULESET_CATEGORIES: Ruleset = require(\"./Categories.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/**\n * Properties for the [[CategoryTree]] component\n * @public\n */\nexport interface CategoryTreeProps {\n /** Flag for accommodating all viewports */\n allViewports?: boolean;\n /** Active viewport */\n activeView?: Viewport;\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Custom category visibility handler to use for testing\n * @internal\n */\n categoryVisibilityHandler?: CategoryVisibilityHandler;\n /**\n * Custom view manager to use for testing\n * @internal\n */\n viewManager?: ViewManager;\n}\n\n/**\n * Tree which displays and manages categories contained in an iModel.\n * @public\n */\nexport function CategoryTree(props: CategoryTreeProps) {\n const { nodeLoader } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: RULESET_CATEGORIES,\n pagingSize: PAGING_SIZE,\n });\n\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n // istanbul ignore next\n const viewManager = props.viewManager ?? IModelApp.viewManager;\n const { activeView, allViewports, categoryVisibilityHandler } = props;\n const currentActiveView = activeView ?? viewManager.getFirstOpenView();\n const categories = useCategories(viewManager, props.iModel, currentActiveView);\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, categories, currentActiveView, allViewports, categoryVisibilityHandler);\n\n React.useEffect(() => {\n setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises\n }, [currentActiveView]);\n\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n }), [filteredNodeLoader, visibilityHandler]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(false, true);\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"categoriesTree.noCategoryFound\")}\n message={TreeWidget.translate(\"categoriesTree.noMatchingCategoryNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-categories-tree\">\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n descriptionsEnabled={true}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useCategoryVisibilityHandler(viewManager: ViewManager, imodel: IModelConnection, categories: Category[], activeView?: Viewport, allViewports?: boolean, visibilityHandler?: CategoryVisibilityHandler) {\n return useDisposable(React.useCallback(\n () =>\n // istanbul ignore next\n visibilityHandler ?? new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }),\n [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]),\n );\n}\n\nasync function setViewType(activeView?: Viewport) {\n if (!activeView)\n return;\n\n const view = activeView.view as SpatialViewState;\n const viewType = view.is3d() ? \"3d\" : \"2d\";\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\n"]}
|
|
@@ -6,8 +6,9 @@ import "./CategoriesTree.scss";
|
|
|
6
6
|
import React, { useCallback } from "react";
|
|
7
7
|
import { useActiveIModelConnection, useActiveViewport } from "@itwin/appui-react";
|
|
8
8
|
import { IModelApp } from "@itwin/core-frontend";
|
|
9
|
-
import { CategoryTree
|
|
9
|
+
import { CategoryTree } from "./CategoriesTree";
|
|
10
10
|
import { CategoryVisibilityHandler } from "./CategoryVisibilityHandler";
|
|
11
|
+
import { enableCategory, getCategories, toggleAllCategories } from "../CategoriesVisibilityUtils";
|
|
11
12
|
import { TreeHeaderComponent } from "../../header/TreeHeader";
|
|
12
13
|
import { useTreeFilteringState } from "../../TreeFilteringState";
|
|
13
14
|
import { AutoSizer } from "../../utils/AutoSizer";
|
|
@@ -18,17 +19,17 @@ export function CategoriesTreeComponent(props) {
|
|
|
18
19
|
const showAll = useCallback(async () => {
|
|
19
20
|
if (!iModel)
|
|
20
21
|
return;
|
|
21
|
-
return toggleAllCategories(IModelApp.viewManager, iModel, true, undefined, true, filteredProvider);
|
|
22
|
+
return toggleAllCategories(IModelApp.viewManager, iModel, true, undefined, true, filteredProvider ? await getFilteredCategories(filteredProvider) : undefined);
|
|
22
23
|
}, [iModel, filteredProvider]);
|
|
23
24
|
const hideAll = useCallback(async () => {
|
|
24
25
|
if (!iModel)
|
|
25
26
|
return;
|
|
26
|
-
return toggleAllCategories(IModelApp.viewManager, iModel, false, undefined, true, filteredProvider);
|
|
27
|
+
return toggleAllCategories(IModelApp.viewManager, iModel, false, undefined, true, filteredProvider ? await getFilteredCategories(filteredProvider) : undefined);
|
|
27
28
|
}, [iModel, filteredProvider]);
|
|
28
29
|
const invert = useCallback(async () => {
|
|
29
30
|
if (!iModel || !viewport)
|
|
30
31
|
return;
|
|
31
|
-
const ids = await getCategories(iModel, viewport
|
|
32
|
+
const ids = filteredProvider ? await getFilteredCategories(filteredProvider) : await getCategories(iModel, viewport);
|
|
32
33
|
const enabled = [];
|
|
33
34
|
const disabled = [];
|
|
34
35
|
for (const id of ids) {
|
|
@@ -40,13 +41,17 @@ export function CategoriesTreeComponent(props) {
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
// Disable enabled
|
|
43
|
-
|
|
44
|
+
enableCategory(IModelApp.viewManager, iModel, enabled, false, true);
|
|
44
45
|
// Enable disabled
|
|
45
|
-
|
|
46
|
+
enableCategory(IModelApp.viewManager, iModel, disabled, true, true);
|
|
46
47
|
}, [iModel, viewport, filteredProvider]);
|
|
47
48
|
return (React.createElement(React.Fragment, null, iModel && viewport &&
|
|
48
49
|
React.createElement(React.Fragment, null,
|
|
49
50
|
React.createElement(TreeHeaderComponent, { searchOptions: searchOptions, showAll: showAll, hideAll: hideAll, invert: invert }),
|
|
50
51
|
React.createElement(AutoSizer, null, ({ width, height }) => (React.createElement(CategoryTree, { ...props, iModel: iModel, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex }, onFilterApplied: onFilterApplied }))))));
|
|
51
52
|
}
|
|
53
|
+
async function getFilteredCategories(filteredProvider) {
|
|
54
|
+
const nodes = await filteredProvider.getNodes();
|
|
55
|
+
return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));
|
|
56
|
+
}
|
|
52
57
|
//# sourceMappingURL=CategoriesTreeComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,O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,CAAC,IAAI,EAAE,EAAE,CAAC,yBAAyB,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACxH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport \"./CategoriesTree.scss\";\nimport React, { useCallback } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\nimport { enableCategory, getCategories, toggleAllCategories } from \"../CategoriesVisibilityUtils\";\nimport { TreeHeaderComponent } from \"../../header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport type { CategoriesTreeProps } from \"../../../types\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n const {\n searchOptions,\n filterString,\n activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n const showAll = useCallback(async () => {\n if (!iModel) return;\n\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n true,\n undefined,\n true,\n filteredProvider ? await getFilteredCategories(filteredProvider) : undefined,\n );\n }, [iModel, filteredProvider]);\n\n const hideAll = useCallback(async () => {\n if (!iModel) return;\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n false,\n undefined,\n true,\n filteredProvider ? await getFilteredCategories(filteredProvider) : undefined,\n );\n }, [iModel, filteredProvider]);\n\n const invert = useCallback(async () => {\n if (!iModel || !viewport) return;\n const ids = filteredProvider ? await getFilteredCategories(filteredProvider) : await getCategories(iModel, viewport);\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n enableCategory(\n IModelApp.viewManager,\n iModel,\n enabled,\n false,\n true\n );\n // Enable disabled\n enableCategory(\n IModelApp.viewManager,\n iModel,\n disabled,\n true,\n true\n );\n }, [iModel, viewport, filteredProvider]);\n\n return (\n <>\n {iModel && viewport &&\n <>\n <TreeHeaderComponent\n searchOptions={searchOptions}\n showAll={showAll}\n hideAll={hideAll}\n invert={invert}\n />\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n iModel={iModel}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n }\n </>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));\n}\n"]}
|