@itwin/tree-widget-react 3.17.0 → 3.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +3 -2
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +3 -3
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +22 -21
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +57 -107
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +22 -12
- package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/internal/Utils.d.ts +25 -0
- package/lib/cjs/tree-widget-react/components/trees/common/internal/Utils.js +83 -0
- package/lib/cjs/tree-widget-react/components/trees/common/internal/Utils.js.map +1 -0
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +1 -0
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +78 -23
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.d.ts +5 -3
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.js +5 -14
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +5 -4
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +7 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +52 -0
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +15 -0
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +134 -3
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +241 -120
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/cjs/tree-widget-react-internal.d.ts +1 -1
- package/lib/cjs/tree-widget-react-internal.js +1 -1
- package/lib/cjs/tree-widget-react-internal.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +3 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +3 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +23 -22
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +59 -109
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +23 -13
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.d.ts +25 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js +74 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +74 -19
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.d.ts +5 -3
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js +4 -13
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +4 -3
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +7 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +52 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +15 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +133 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +224 -103
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react-internal.d.ts +1 -1
- package/lib/esm/tree-widget-react-internal.js +1 -1
- package/lib/esm/tree-widget-react-internal.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlwaysAndNeverDrawnElementInfo.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,KAAK,EACL,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,gBAAgB,EAChB,GAAG,EACH,QAAQ,EACR,EAAE,EACF,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACT,IAAI,EACJ,SAAS,EACT,GAAG,GACJ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAOhF,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAuC3C,MAAM,OAAO,8BAA8B;IACzC,cAAc,CAAiB;IAC/B,YAAY,CAAwF;IACpG,WAAW,CAAwF;IACnG,eAAe,GAAG,IAAI,OAAO,EAAQ,CAAC;IAC7B,SAAS,CAAW;IAC7B,YAAY,CAAa;IACzB,cAAc,CAAS;IAEvB,YAAY,CAAqB;IACjC,SAAS,GAAG,IAAI,OAAO,EAAW,CAAC;IAEnC,YAAY,QAAkB,EAAE,WAAwB;QACtD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;QAC1B,IAAI,CAAC,YAAY,GAAG,EAAE,aAAa,EAAE,IAAI,CAAC,0BAA0B,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjF,IAAI,CAAC,WAAW,GAAG,EAAE,aAAa,EAAE,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/E,IAAI,CAAC,YAAY,GAAG,IAA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,QAAQ,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YACjE,OAAO,QAAQ,CAAC,iBAAiB,CAC/B;gBACE,IAAI,EAAE;oBACJ;;;;;;;;;;;;;;;;;;;;;;aAsBC;iBACF;gBACD,KAAK,EAAE;;;;WAIN;gBACD,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;aACjD,EACD;gBACE,SAAS,EAAE,oBAAoB;gBAC/B,YAAY,EAAE,GAAG,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,YAAY,IAAI,SAAS,EAAE;aACzE,CACF,CAAC;QACJ,CAAC,CAAC,CAAC,IAAI,CACL,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;YACV,OAAO,EAAE,YAAY,EAAE,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,CAAC,cAAc,EAAE,CAAC;QAC7I,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF","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 {\n BehaviorSubject,\n bufferCount,\n debounceTime,\n defer,\n EMPTY,\n filter,\n first,\n from,\n fromEventPattern,\n map,\n mergeMap,\n of,\n reduce,\n scan,\n share,\n shareReplay,\n startWith,\n Subject,\n switchMap,\n take,\n takeUntil,\n tap,\n} from \"rxjs\";\nimport { Guid, Id64 } from \"@itwin/core-bentley\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { releaseMainThreadOnItemsCount, updateChildrenTree } from \"../Utils.js\";\n\nimport type { Observable, Subscription } from \"rxjs\";\nimport type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { ChildrenTree } from \"../Utils.js\";\n\n/** @internal */\nexport const SET_CHANGE_DEBOUNCE_TIME = 20;\n\ntype SetType = \"always\" | \"never\";\n\ninterface GetElementsTreeByModelProps {\n /** Only always/never drawn elements that have the specified models will be returned. */\n modelIds: Id64Arg;\n /**\n * The type of set from which tree should be retrieved.\n * `always` - ChildrenTree will be created from `alwaysDrawn` set.\n * `never` - ChildrenTree will be created from `neverDrawn` set.\n */\n setType: SetType;\n}\ninterface GetElementsTreeByCategoryProps extends GetElementsTreeByModelProps {\n /**\n * Categories of root elements.\n *\n * Elements are filtered by given categories. Children of those elements are also included, no matter their category.\n */\n categoryIds: Id64Arg;\n}\ninterface GetElementsTreeByElementProps extends GetElementsTreeByCategoryProps {\n /** Path to element for which to get its' child always/never drawn elements. When undefined, models and categories will be used to get the always/never drawn elements. */\n parentElementIdsPath: Array<Id64Arg>;\n}\n\n/** @internal */\nexport type GetElementsTreeProps = GetElementsTreeByModelProps | GetElementsTreeByCategoryProps | GetElementsTreeByElementProps;\n\n/**\n * - `categoryId` is assigned only to the elements in always/never drawn set.\n * - `isInAlwaysOrNeverDrawnSet` flag determines if key (ECInstanceId) is in always/never set.\n * @internal\n */\nexport type MapEntry = { isInAlwaysOrNeverDrawnSet: true; categoryId: Id64String } | { isInAlwaysOrNeverDrawnSet: false };\n\ntype CachedNodesMap = ChildrenTree<MapEntry>;\n\nexport class AlwaysAndNeverDrawnElementInfo implements Disposable {\n #subscriptions: Subscription[];\n #alwaysDrawn: { cacheEntryObs: Observable<CachedNodesMap>; latestCacheEntryValue?: CachedNodesMap };\n #neverDrawn: { cacheEntryObs: Observable<CachedNodesMap>; latestCacheEntryValue?: CachedNodesMap };\n #disposeSubject = new Subject<void>();\n readonly #viewport: Viewport;\n #componentId: GuidString;\n #componentName: string;\n\n #suppressors: Observable<number>;\n #suppress = new Subject<boolean>();\n\n constructor(viewport: Viewport, componentId?: GuidString) {\n this.#viewport = viewport;\n this.#alwaysDrawn = { cacheEntryObs: this.createCacheEntryObservable(\"always\") };\n this.#neverDrawn = { cacheEntryObs: this.createCacheEntryObservable(\"never\") };\n this.#suppressors = this.#suppress.pipe(\n scan((acc, suppress) => acc + (suppress ? 1 : -1), 0),\n startWith(0),\n shareReplay(1),\n );\n this.#subscriptions = [this.#alwaysDrawn.cacheEntryObs.subscribe(), this.#neverDrawn.cacheEntryObs.subscribe()];\n this.#componentId = componentId ?? Guid.createValue();\n this.#componentName = \"AlwaysAndNeverDrawnElementInfo\";\n }\n\n public suppressChangeEvents() {\n this.#suppress.next(true);\n }\n\n public resumeChangeEvents() {\n this.#suppress.next(false);\n }\n\n public getElementsTree({ setType, modelIds, ...props }: GetElementsTreeProps): Observable<CachedNodesMap> {\n const cache = setType === \"always\" ? this.#alwaysDrawn : this.#neverDrawn;\n const getElements = (rootTreeNodes: CachedNodesMap | undefined): CachedNodesMap => {\n if (!rootTreeNodes) {\n return new Map();\n }\n const pathToElements = [modelIds];\n if (\"categoryIds\" in props && props.categoryIds) {\n pathToElements.push(props.categoryIds);\n if (\"parentElementIdsPath\" in props && props.parentElementIdsPath) {\n props.parentElementIdsPath.forEach((parentElementIds) => pathToElements.push(parentElementIds));\n }\n }\n return this.getChildrenTree({ currentChildrenTree: rootTreeNodes, pathToElements, currentIdsIndex: 0 });\n };\n\n return !cache.latestCacheEntryValue\n ? cache.cacheEntryObs.pipe(map(getElements))\n : this.#suppressors.pipe(\n take(1),\n mergeMap((suppressionCount) =>\n suppressionCount > 0 ? of(cache.latestCacheEntryValue).pipe(map(getElements)) : cache.cacheEntryObs.pipe(map(getElements)),\n ),\n );\n }\n\n private getChildrenTree<T extends object>({\n currentChildrenTree,\n pathToElements,\n currentIdsIndex,\n }: {\n currentChildrenTree: ChildrenTree<T>;\n pathToElements: Array<Id64Arg>;\n currentIdsIndex: number;\n }): ChildrenTree<T> {\n if (currentIdsIndex >= pathToElements.length) {\n return currentChildrenTree;\n }\n const result: ChildrenTree<T> = new Map();\n for (const parentId of Id64.iterable(pathToElements[currentIdsIndex])) {\n const entry = currentChildrenTree.get(parentId);\n if (entry?.children) {\n const childrenTreeOfChildren = this.getChildrenTree({\n currentChildrenTree: entry.children,\n pathToElements,\n currentIdsIndex: currentIdsIndex + 1,\n });\n childrenTreeOfChildren.forEach((val, childId) => result.set(childId, val));\n }\n }\n return result;\n }\n\n private createCacheEntryObservable(setType: SetType): Observable<CachedNodesMap> {\n const event = setType === \"always\" ? this.#viewport.onAlwaysDrawnChanged : this.#viewport.onNeverDrawnChanged;\n const getIds = setType === \"always\" ? () => this.#viewport.alwaysDrawn : () => this.#viewport.neverDrawn;\n\n const resultSubject = new BehaviorSubject<CachedNodesMap | undefined>(undefined);\n\n const obs: Observable<CachedNodesMap> = fromEventPattern(\n (handler) => event.addListener(handler),\n (handler) => event.removeListener(handler),\n ).pipe(\n // Fire the observable once at the beginning\n startWith(undefined),\n // Reset result subject as soon as a new event is emitted.\n // This will make newly subscribed observers wait for the debounce period to pass\n // instead of consuming the cached value which at this point becomes invalid.\n tap(() => resultSubject.next(undefined)),\n // Check if cache updates are not suppressed.\n switchMap(() =>\n this.#suppressors.pipe(\n filter((suppressors) => suppressors === 0),\n take(1),\n ),\n ),\n debounceTime(SET_CHANGE_DEBOUNCE_TIME),\n // Cancel pending request if dispose() is called.\n takeUntil(this.#disposeSubject),\n // If multiple requests are sent at once, preserve only the result of the newest.\n switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(getIds(), `${setType}Drawn`)),\n tap((cacheEntry) => {\n const value = setType === \"always\" ? this.#alwaysDrawn : this.#neverDrawn;\n value.latestCacheEntryValue = cacheEntry;\n }),\n // Share the result by using a subject which always emits the saved result.\n share({\n connector: () => resultSubject,\n resetOnRefCountZero: false,\n }),\n // Wait until the result is available.\n first((x): x is CachedNodesMap => !!x, new Map()),\n );\n return obs;\n }\n\n public [Symbol.dispose]() {\n this.#subscriptions.forEach((x) => x.unsubscribe());\n this.#subscriptions = [];\n this.#disposeSubject.next();\n }\n\n private queryAlwaysOrNeverDrawnElementInfo(set: Id64Set | undefined, requestId: string): Observable<CachedNodesMap> {\n const elementInfo = set?.size\n ? from(set).pipe(\n bufferCount(Math.ceil(set.size / Math.ceil(set.size / 5000))),\n mergeMap((block, index) => this.queryElementInfo(block, `${requestId}-${index}`), 10),\n )\n : EMPTY;\n return elementInfo.pipe(\n releaseMainThreadOnItemsCount(1000),\n reduce(\n (acc, { categoryId, rootCategoryId, modelId, elementsPath }) => {\n const elementIdInList = elementsPath[elementsPath.length - 1];\n const additionalPropsGetter = (id: Id64String, additionalProps?: MapEntry): MapEntry => {\n if (id === elementIdInList) {\n // Last element in elementsPath is in always/never drawn set. We want to mark, that it is in the set, and save it's categoryId.\n return { isInAlwaysOrNeverDrawnSet: true, categoryId };\n }\n // Existing entries can keep their value, if it's a new entry it's not in the list.\n return additionalProps ?? { isInAlwaysOrNeverDrawnSet: false };\n };\n updateChildrenTree({ tree: acc, idsToAdd: [modelId, rootCategoryId, ...elementsPath], additionalPropsGetter });\n return acc;\n },\n ((): CachedNodesMap => new Map())(),\n ),\n );\n }\n\n private queryElementInfo(\n elementIds: Id64Array,\n requestId: string,\n ): Observable<{\n rootCategoryId: Id64String;\n modelId: Id64String;\n categoryId: Id64String;\n elementsPath: Id64Array;\n }> {\n return defer(() => {\n const executor = createECSqlQueryExecutor(this.#viewport.iModel);\n return executor.createQueryReader(\n {\n ctes: [\n `\n ElementInfo(modelId, rootCategoryId, categoryId, parentId, elementsPath) AS (\n SELECT\n Model.Id modelId,\n Category.Id rootCategoryId,\n Category.Id categoryId,\n Parent.Id parentId,\n CAST(IdToHex(ECInstanceId) AS TEXT) elementsPath\n FROM bis.GeometricElement3d\n WHERE InVirtualSet(?, ECInstanceId)\n\n UNION ALL\n\n SELECT\n e.modelId modelId,\n p.Category.Id rootCategoryId,\n e.categoryId categoryId,\n p.Parent.Id parentId,\n CAST(IdToHex(p.ECInstanceId) AS TEXT) || ';' || e.elementsPath\n FROM bis.GeometricElement3d p\n JOIN ElementInfo e ON p.ECInstanceId = e.parentId\n )\n `,\n ],\n ecsql: `\n SELECT elementsPath elementsPath, modelId modelId, categoryId categoryId, rootCategoryId rootCategoryId\n FROM ElementInfo\n WHERE parentId IS NULL\n `,\n bindings: [{ type: \"idset\", value: elementIds }],\n },\n {\n rowFormat: \"ECSqlPropertyNames\",\n restartToken: `${this.#componentName}/${this.#componentId}/${requestId}`,\n },\n );\n }).pipe(\n map((row) => {\n return { elementsPath: row.elementsPath.split(\";\"), modelId: row.modelId, categoryId: row.categoryId, rootCategoryId: row.rootCategoryId };\n }),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AlwaysAndNeverDrawnElementInfo.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,KAAK,EACL,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,gBAAgB,EAChB,GAAG,EACH,QAAQ,EACR,EAAE,EACF,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACT,IAAI,EACJ,SAAS,EACT,GAAG,GACJ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AACpG,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAOjD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAuC3C,MAAM,OAAO,8BAA8B;IACzC,c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C7I,CAAC,CAAC,CACH,CAAC;IACJ,CAAC;CACF","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 {\n BehaviorSubject,\n bufferCount,\n debounceTime,\n defer,\n EMPTY,\n filter,\n first,\n from,\n fromEventPattern,\n map,\n mergeMap,\n of,\n reduce,\n scan,\n share,\n shareReplay,\n startWith,\n Subject,\n switchMap,\n take,\n takeUntil,\n tap,\n} from \"rxjs\";\nimport { Guid, Id64 } from \"@itwin/core-bentley\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { getOptimalBatchSize, releaseMainThreadOnItemsCount } from \"../../common/internal/Utils.js\";\nimport { updateChildrenTree } from \"../Utils.js\";\n\nimport type { Observable, Subscription } from \"rxjs\";\nimport type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { ChildrenTree } from \"../Utils.js\";\n\n/** @internal */\nexport const SET_CHANGE_DEBOUNCE_TIME = 20;\n\ntype SetType = \"always\" | \"never\";\n\ninterface GetElementsTreeByModelProps {\n /** Only always/never drawn elements that have the specified models will be returned. */\n modelIds: Id64Arg;\n /**\n * The type of set from which tree should be retrieved.\n * `always` - ChildrenTree will be created from `alwaysDrawn` set.\n * `never` - ChildrenTree will be created from `neverDrawn` set.\n */\n setType: SetType;\n}\ninterface GetElementsTreeByCategoryProps extends GetElementsTreeByModelProps {\n /**\n * Categories of root elements.\n *\n * Elements are filtered by given categories. Children of those elements are also included, no matter their category.\n */\n categoryIds: Id64Arg;\n}\ninterface GetElementsTreeByElementProps extends GetElementsTreeByCategoryProps {\n /** Path to element for which to get its' child always/never drawn elements. When undefined, models and categories will be used to get the always/never drawn elements. */\n parentElementIdsPath: Array<Id64Arg>;\n}\n\n/** @internal */\nexport type GetElementsTreeProps = GetElementsTreeByModelProps | GetElementsTreeByCategoryProps | GetElementsTreeByElementProps;\n\n/**\n * - `categoryId` is assigned only to the elements in always/never drawn set.\n * - `isInAlwaysOrNeverDrawnSet` flag determines if key (ECInstanceId) is in always/never set.\n * @internal\n */\nexport type MapEntry = { isInAlwaysOrNeverDrawnSet: true; categoryId: Id64String } | { isInAlwaysOrNeverDrawnSet: false };\n\ntype CachedNodesMap = ChildrenTree<MapEntry>;\n\nexport class AlwaysAndNeverDrawnElementInfo implements Disposable {\n #subscriptions: Subscription[];\n #alwaysDrawn: { cacheEntryObs: Observable<CachedNodesMap>; latestCacheEntryValue?: CachedNodesMap };\n #neverDrawn: { cacheEntryObs: Observable<CachedNodesMap>; latestCacheEntryValue?: CachedNodesMap };\n #disposeSubject = new Subject<void>();\n readonly #viewport: Viewport;\n #componentId: GuidString;\n #componentName: string;\n\n #suppressors: Observable<number>;\n #suppress = new Subject<boolean>();\n\n constructor(viewport: Viewport, componentId?: GuidString) {\n this.#viewport = viewport;\n this.#alwaysDrawn = { cacheEntryObs: this.createCacheEntryObservable(\"always\") };\n this.#neverDrawn = { cacheEntryObs: this.createCacheEntryObservable(\"never\") };\n this.#suppressors = this.#suppress.pipe(\n scan((acc, suppress) => acc + (suppress ? 1 : -1), 0),\n startWith(0),\n shareReplay(1),\n );\n this.#subscriptions = [this.#alwaysDrawn.cacheEntryObs.subscribe(), this.#neverDrawn.cacheEntryObs.subscribe()];\n this.#componentId = componentId ?? Guid.createValue();\n this.#componentName = \"AlwaysAndNeverDrawnElementInfo\";\n }\n\n public suppressChangeEvents() {\n this.#suppress.next(true);\n }\n\n public resumeChangeEvents() {\n this.#suppress.next(false);\n }\n\n public getElementsTree({ setType, modelIds, ...props }: GetElementsTreeProps): Observable<CachedNodesMap> {\n const cache = setType === \"always\" ? this.#alwaysDrawn : this.#neverDrawn;\n const getElements = (rootTreeNodes: CachedNodesMap | undefined): CachedNodesMap => {\n if (!rootTreeNodes) {\n return new Map();\n }\n const pathToElements = [modelIds];\n if (\"categoryIds\" in props && props.categoryIds) {\n pathToElements.push(props.categoryIds);\n if (\"parentElementIdsPath\" in props && props.parentElementIdsPath) {\n props.parentElementIdsPath.forEach((parentElementIds) => pathToElements.push(parentElementIds));\n }\n }\n return this.getChildrenTree({ currentChildrenTree: rootTreeNodes, pathToElements, currentIdsIndex: 0 });\n };\n\n return !cache.latestCacheEntryValue\n ? cache.cacheEntryObs.pipe(map(getElements))\n : this.#suppressors.pipe(\n take(1),\n mergeMap((suppressionCount) =>\n suppressionCount > 0 ? of(cache.latestCacheEntryValue).pipe(map(getElements)) : cache.cacheEntryObs.pipe(map(getElements)),\n ),\n );\n }\n\n private getChildrenTree<T extends object>({\n currentChildrenTree,\n pathToElements,\n currentIdsIndex,\n }: {\n currentChildrenTree: ChildrenTree<T>;\n pathToElements: Array<Id64Arg>;\n currentIdsIndex: number;\n }): ChildrenTree<T> {\n if (currentIdsIndex >= pathToElements.length) {\n return currentChildrenTree;\n }\n const result: ChildrenTree<T> = new Map();\n for (const parentId of Id64.iterable(pathToElements[currentIdsIndex])) {\n const entry = currentChildrenTree.get(parentId);\n if (entry?.children) {\n const childrenTreeOfChildren = this.getChildrenTree({\n currentChildrenTree: entry.children,\n pathToElements,\n currentIdsIndex: currentIdsIndex + 1,\n });\n childrenTreeOfChildren.forEach((val, childId) => result.set(childId, val));\n }\n }\n return result;\n }\n\n private createCacheEntryObservable(setType: SetType): Observable<CachedNodesMap> {\n const event = setType === \"always\" ? this.#viewport.onAlwaysDrawnChanged : this.#viewport.onNeverDrawnChanged;\n const getIds = setType === \"always\" ? () => this.#viewport.alwaysDrawn : () => this.#viewport.neverDrawn;\n\n const resultSubject = new BehaviorSubject<CachedNodesMap | undefined>(undefined);\n\n const obs: Observable<CachedNodesMap> = fromEventPattern(\n (handler) => event.addListener(handler),\n (handler) => event.removeListener(handler),\n ).pipe(\n // Fire the observable once at the beginning\n startWith(undefined),\n // Reset result subject as soon as a new event is emitted.\n // This will make newly subscribed observers wait for the debounce period to pass\n // instead of consuming the cached value which at this point becomes invalid.\n tap(() => resultSubject.next(undefined)),\n // Check if cache updates are not suppressed.\n switchMap(() =>\n this.#suppressors.pipe(\n filter((suppressors) => suppressors === 0),\n take(1),\n ),\n ),\n debounceTime(SET_CHANGE_DEBOUNCE_TIME),\n // Cancel pending request if dispose() is called.\n takeUntil(this.#disposeSubject),\n // If multiple requests are sent at once, preserve only the result of the newest.\n switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(getIds(), `${setType}Drawn`)),\n tap((cacheEntry) => {\n const value = setType === \"always\" ? this.#alwaysDrawn : this.#neverDrawn;\n value.latestCacheEntryValue = cacheEntry;\n }),\n // Share the result by using a subject which always emits the saved result.\n share({\n connector: () => resultSubject,\n resetOnRefCountZero: false,\n }),\n // Wait until the result is available.\n first((x): x is CachedNodesMap => !!x, new Map()),\n );\n return obs;\n }\n\n public [Symbol.dispose]() {\n this.#subscriptions.forEach((x) => x.unsubscribe());\n this.#subscriptions = [];\n this.#disposeSubject.next();\n }\n\n private queryAlwaysOrNeverDrawnElementInfo(set: Id64Set | undefined, requestId: string): Observable<CachedNodesMap> {\n const elementInfo = set?.size\n ? from(set).pipe(\n bufferCount(getOptimalBatchSize({ totalSize: set.size, maximumBatchSize: 1000 })),\n releaseMainThreadOnItemsCount(2),\n mergeMap((block, index) => this.queryElementInfo(block, `${requestId}-${index}`), 10),\n )\n : EMPTY;\n return elementInfo.pipe(\n releaseMainThreadOnItemsCount(500),\n reduce(\n (acc, { categoryId, rootCategoryId, modelId, elementsPath }) => {\n const elementIdInList = elementsPath[elementsPath.length - 1];\n const additionalPropsGetter = (id: Id64String, additionalProps?: MapEntry): MapEntry => {\n if (id === elementIdInList) {\n // Last element in elementsPath is in always/never drawn set. We want to mark, that it is in the set, and save it's categoryId.\n return { isInAlwaysOrNeverDrawnSet: true, categoryId };\n }\n // Existing entries can keep their value, if it's a new entry it's not in the list.\n return additionalProps ?? { isInAlwaysOrNeverDrawnSet: false };\n };\n updateChildrenTree({ tree: acc, idsToAdd: [modelId, rootCategoryId, ...elementsPath], additionalPropsGetter });\n return acc;\n },\n ((): CachedNodesMap => new Map())(),\n ),\n );\n }\n\n private queryElementInfo(\n elementIds: Id64Array,\n requestId: string,\n ): Observable<{\n rootCategoryId: Id64String;\n modelId: Id64String;\n categoryId: Id64String;\n elementsPath: Id64Array;\n }> {\n return defer(() => {\n const executor = createECSqlQueryExecutor(this.#viewport.iModel);\n return executor.createQueryReader(\n {\n ctes: [\n `\n ElementInfo(modelId, rootCategoryId, categoryId, parentId, elementsPath) AS (\n SELECT\n Model.Id modelId,\n Category.Id rootCategoryId,\n Category.Id categoryId,\n Parent.Id parentId,\n CAST(IdToHex(ECInstanceId) AS TEXT) elementsPath\n FROM bis.GeometricElement3d\n WHERE InVirtualSet(?, ECInstanceId)\n\n UNION ALL\n\n SELECT\n e.modelId modelId,\n p.Category.Id rootCategoryId,\n e.categoryId categoryId,\n p.Parent.Id parentId,\n CAST(IdToHex(p.ECInstanceId) AS TEXT) || ';' || e.elementsPath\n FROM bis.GeometricElement3d p\n JOIN ElementInfo e ON p.ECInstanceId = e.parentId\n )\n `,\n ],\n ecsql: `\n SELECT elementsPath elementsPath, modelId modelId, categoryId categoryId, rootCategoryId rootCategoryId\n FROM ElementInfo\n WHERE parentId IS NULL\n `,\n bindings: [{ type: \"idset\", value: elementIds }],\n },\n {\n rowFormat: \"ECSqlPropertyNames\",\n restartToken: `${this.#componentName}/${this.#componentId}/${requestId}`,\n },\n );\n }).pipe(\n map((row) => {\n return { elementsPath: row.elementsPath.split(\";\"), modelId: row.modelId, categoryId: row.categoryId, rootCategoryId: row.rootCategoryId };\n }),\n );\n }\n}\n"]}
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { HierarchyFilteringPath, HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
-
import type { Id64String } from "@itwin/core-bentley";
|
|
2
|
+
import type { Id64Arg, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
3
3
|
import type { ClassGroupingNodeKey, InstancesNodeKey } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import type { ECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
5
|
+
import type { ChildrenTree } from "../Utils.js";
|
|
6
|
+
interface GetElementsFromUnfilteredChildrenTreeProps {
|
|
7
|
+
childrenTree: ChildrenTree;
|
|
8
|
+
parentIdsPath: Array<Id64Arg>;
|
|
9
|
+
}
|
|
5
10
|
/** @internal */
|
|
6
11
|
export interface FilteredTree {
|
|
7
12
|
getVisibilityChangeTargets(node: HierarchyNode & {
|
|
8
13
|
key: ClassGroupingNodeKey | InstancesNodeKey;
|
|
9
14
|
}): VisibilityChangeTargets;
|
|
15
|
+
getElementsFromUnfilteredChildrenTree(props: GetElementsFromUnfilteredChildrenTreeProps): Id64Set | undefined;
|
|
10
16
|
}
|
|
11
17
|
export declare const SUBJECT_CLASS_NAME: "BisCore.Subject";
|
|
12
18
|
export declare const MODEL_CLASS_NAME: "BisCore.GeometricModel3d";
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { assert, Id64 } from "@itwin/core-bentley";
|
|
6
6
|
import { HierarchyFilteringPath, HierarchyNode, HierarchyNodeIdentifier, HierarchyNodeKey } from "@itwin/presentation-hierarchies";
|
|
7
|
+
import { getIdsFromChildrenTree } from "../Utils.js";
|
|
7
8
|
export const SUBJECT_CLASS_NAME = "BisCore.Subject";
|
|
8
9
|
export const MODEL_CLASS_NAME = "BisCore.GeometricModel3d";
|
|
9
10
|
export const CATEGORY_CLASS_NAME = "BisCore.SpatialCategory";
|
|
@@ -50,8 +51,59 @@ export async function createFilteredTree(imodelAccess, filteringPaths) {
|
|
|
50
51
|
}
|
|
51
52
|
return {
|
|
52
53
|
getVisibilityChangeTargets: (node) => getVisibilityChangeTargets(root, node),
|
|
54
|
+
getElementsFromUnfilteredChildrenTree: ({ childrenTree, parentIdsPath }) => getElementsFromUnfilteredChildrenTree({ parentIdsPath, root, childrenTree }),
|
|
53
55
|
};
|
|
54
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Unfiltered tree can contain ids of models/categories/elements which are not present in the filtered tree.
|
|
59
|
+
* This function retrieves only those ids which are either filter tree targets, or are their children (direct and indirect).
|
|
60
|
+
*/
|
|
61
|
+
function getElementsFromUnfilteredChildrenTree(props) {
|
|
62
|
+
if (props.childrenTree.size === 0 || props.parentIdsPath.length === 0) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
let lookupParents = [props.root];
|
|
66
|
+
for (const parentIds of props.parentIdsPath) {
|
|
67
|
+
// When filtered node does not have children, it is filter target and because of this, all elements in the childrenTree are in the filtered tree
|
|
68
|
+
if (lookupParents.every((parent) => !parent.children)) {
|
|
69
|
+
return getIdsFromChildrenTree({ tree: props.childrenTree });
|
|
70
|
+
}
|
|
71
|
+
const parentNodes = findMatchingFilteredNodes(lookupParents, parentIds);
|
|
72
|
+
if (parentNodes.length === 0) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
lookupParents = parentNodes;
|
|
76
|
+
}
|
|
77
|
+
// We have unfiltered children tree and filtered nodes that are parents of first level nodes in unfiltered children tree.
|
|
78
|
+
// We can start filtering unfiltered children tree based on filtered nodes.
|
|
79
|
+
const result = getChildrenTreeIdsMatchingFilteredNodes({ tree: props.childrenTree, filteredNodes: lookupParents });
|
|
80
|
+
return result.size > 0 ? result : undefined;
|
|
81
|
+
}
|
|
82
|
+
function getChildrenTreeIdsMatchingFilteredNodes({ tree, filteredNodes, }) {
|
|
83
|
+
const getIdsRecursively = (childrenTree, parentFilteredNodes) => {
|
|
84
|
+
// If one of the parent filtered nodes does not have children, it is filter target and because of this, all elements in the childrenTree are in the filtered tree.
|
|
85
|
+
const hasParentFilterTarget = parentFilteredNodes.some((filteredNode) => "isFilterTarget" in filteredNode && filteredNode.isFilterTarget);
|
|
86
|
+
if (hasParentFilterTarget) {
|
|
87
|
+
return getIdsFromChildrenTree({ tree: childrenTree });
|
|
88
|
+
}
|
|
89
|
+
const result = new Set();
|
|
90
|
+
childrenTree.forEach((entry, id) => {
|
|
91
|
+
const nodes = findMatchingFilteredNodes(parentFilteredNodes, id);
|
|
92
|
+
// If no filtered nodes match this id, skip it since it's not in the filtered tree.
|
|
93
|
+
if (nodes.length === 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Id was found in filtered nodes children, add it to the result.
|
|
97
|
+
result.add(id);
|
|
98
|
+
if (entry.children) {
|
|
99
|
+
// Continue recursively for children
|
|
100
|
+
getIdsRecursively(entry.children, nodes).forEach((childId) => result.add(childId));
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
return getIdsRecursively(tree, filteredNodes);
|
|
106
|
+
}
|
|
55
107
|
function getVisibilityChangeTargets(root, node) {
|
|
56
108
|
let lookupParents = [root];
|
|
57
109
|
const changeTargets = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilteredTree.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/FilteredTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAsCnI,MAAM,CAAC,MAAM,kBAAkB,GAAG,iBAA0B,CAAC;AAC7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,0BAAmC,CAAC;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAkC,CAAC;AACtE,MAAM,CAAC,MAAM,kBAAkB,GAAG,4BAAqC,CAAC;AAIxE,SAAS,iBAAiB,CAAC,OAAe,EAAE,UAAkB;IAC5D,OAAO,GAAG,OAAO,IAAI,UAAU,EAAE,CAAC;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,CAAC,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,CAAC,EAAE,CAAC;QACzE,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,MAAM,gBAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,EAAE,CAAC;QAC5E,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,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 { assert, Id64 } from \"@itwin/core-bentley\";\nimport { HierarchyFilteringPath, HierarchyNode, HierarchyNodeIdentifier, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\n\nimport type { Id64Arg, Id64String } from \"@itwin/core-bentley\";\nimport type { ClassGroupingNodeKey, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport type { ECClassHierarchyInspector } from \"@itwin/presentation-shared\";\n\ninterface FilteredTreeRootNode {\n children: Map<Id64String, FilteredTreeNode>;\n}\n\ninterface BaseFilteredTreeNode {\n id: string;\n children?: Map<Id64String, FilteredTreeNode>;\n isFilterTarget: boolean;\n}\n\ninterface GenericFilteredTreeNode extends BaseFilteredTreeNode {\n type: \"subject\" | \"model\";\n}\n\ninterface CategoryFilteredTreeNode extends BaseFilteredTreeNode {\n type: \"category\";\n modelId: Id64String;\n}\n\ninterface ElementFilteredTreeNode extends BaseFilteredTreeNode {\n type: \"element\";\n modelId: Id64String;\n categoryId: Id64String;\n}\n\ntype FilteredTreeNode = GenericFilteredTreeNode | CategoryFilteredTreeNode | ElementFilteredTreeNode;\n\n/** @internal */\nexport interface FilteredTree {\n getVisibilityChangeTargets(node: HierarchyNode & { key: ClassGroupingNodeKey | InstancesNodeKey }): VisibilityChangeTargets;\n}\n\nexport const SUBJECT_CLASS_NAME = \"BisCore.Subject\" as const;\nexport const MODEL_CLASS_NAME = \"BisCore.GeometricModel3d\" as const;\nexport const CATEGORY_CLASS_NAME = \"BisCore.SpatialCategory\" as const;\nexport const ELEMENT_CLASS_NAME = \"BisCore.GeometricElement3d\" as const;\n\ntype CategoryKey = `${Id64String}-${Id64String}`;\n\nfunction createCategoryKey(modelId: string, categoryId: string): CategoryKey {\n return `${modelId}-${categoryId}`;\n}\n\n/** @internal */\nexport function parseCategoryKey(key: CategoryKey) {\n const [modelId, categoryId] = key.split(\"-\");\n return { modelId, categoryId };\n}\n\n/** @internal */\nexport interface VisibilityChangeTargets {\n subjects?: Set<Id64String>;\n models?: Set<Id64String>;\n categories?: Set<CategoryKey>;\n elements?: Map<CategoryKey, Map<Id64String, { isFilterTarget: boolean }>>;\n}\n\n/** @internal */\nexport async function createFilteredTree(imodelAccess: ECClassHierarchyInspector, filteringPaths: HierarchyFilteringPath[]): Promise<FilteredTree> {\n const root: FilteredTreeRootNode = {\n children: new Map(),\n };\n\n for (const filteringPath of filteringPaths) {\n const normalizedPath = HierarchyFilteringPath.normalize(filteringPath).path;\n\n let parentNode: FilteredTreeRootNode | FilteredTreeNode = root;\n for (let i = 0; i < normalizedPath.length; i++) {\n if (\"type\" in parentNode && parentNode.isFilterTarget) {\n break;\n }\n\n const identifier = normalizedPath[i];\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {\n break;\n }\n\n const currentNode: FilteredTreeNode | undefined = parentNode.children?.get(identifier.id);\n if (currentNode !== undefined) {\n parentNode = currentNode;\n continue;\n }\n\n const type = await getType(imodelAccess, identifier.className);\n const newNode: FilteredTreeNode = createFilteredTreeNode({\n type,\n id: identifier.id,\n isFilterTarget: i === normalizedPath.length - 1,\n parent: parentNode as FilteredTreeNode,\n });\n (parentNode.children ??= new Map()).set(identifier.id, newNode);\n parentNode = newNode;\n }\n }\n\n return {\n getVisibilityChangeTargets: (node) => getVisibilityChangeTargets(root, node),\n };\n}\n\nfunction getVisibilityChangeTargets(root: FilteredTreeRootNode, node: HierarchyNode & { key: ClassGroupingNodeKey | InstancesNodeKey }) {\n let lookupParents: Array<FilteredTreeRootNode | FilteredTreeNode> = [root];\n const changeTargets: VisibilityChangeTargets = {};\n\n // find the filtered parent nodes of the `node`\n for (const parentKey of node.parentKeys) {\n if (!HierarchyNodeKey.isInstances(parentKey)) {\n continue;\n }\n\n // tree node might be merged from multiple instances. As filtered tree stores only one instance per node, we need to find all matching nodes\n // and use them when checking for matching node in one level deeper.\n const parentNodes = findMatchingFilteredNodes(\n lookupParents,\n parentKey.instanceKeys.map((key) => key.id),\n );\n if (parentNodes.length === 0) {\n return changeTargets;\n }\n lookupParents = parentNodes;\n }\n const ids = HierarchyNode.isInstancesNode(node) ? node.key.instanceKeys.map(({ id }) => id) : node.groupedInstanceKeys.map(({ id }) => id);\n // find filtered nodes that match the `node`\n const filteredNodes = findMatchingFilteredNodes(lookupParents, ids);\n if (filteredNodes.length === 0) {\n return changeTargets;\n }\n\n filteredNodes.forEach((filteredNode) => collectVisibilityChangeTargets(changeTargets, filteredNode));\n return changeTargets;\n}\n\nfunction findMatchingFilteredNodes(lookupParents: Array<FilteredTreeRootNode | FilteredTreeNode>, ids: Id64Arg): Array<FilteredTreeNode> {\n return lookupParents.flatMap((lookup) => {\n const childrenArray = Array<FilteredTreeNode>();\n for (const id of Id64.iterable(ids)) {\n const node = lookup.children?.get(id);\n if (node) {\n childrenArray.push(node);\n }\n }\n return childrenArray;\n });\n}\n\nfunction collectVisibilityChangeTargets(changeTargets: VisibilityChangeTargets, node: FilteredTreeNode) {\n if (node.isFilterTarget) {\n addTarget(changeTargets, node);\n return;\n }\n\n if (node.type === \"element\") {\n // need to add parent ids as filter target will be an element\n addTarget(changeTargets, node);\n }\n\n if (!node.children) {\n return;\n }\n\n for (const child of node.children.values()) {\n collectVisibilityChangeTargets(changeTargets, child);\n }\n}\n\nfunction addTarget(filterTargets: VisibilityChangeTargets, node: FilteredTreeNode) {\n switch (node.type) {\n case \"subject\":\n (filterTargets.subjects ??= new Set()).add(node.id);\n return;\n case \"model\":\n (filterTargets.models ??= new Set()).add(node.id);\n return;\n case \"category\":\n (filterTargets.categories ??= new Set()).add(createCategoryKey(node.modelId, node.id));\n return;\n case \"element\":\n const categoryKey = createCategoryKey(node.modelId, node.categoryId);\n const elements = (filterTargets.elements ??= new Map()).get(categoryKey);\n if (elements) {\n elements.set(node.id, { isFilterTarget: node.isFilterTarget });\n } else {\n filterTargets.elements.set(categoryKey, new Map([[node.id, { isFilterTarget: node.isFilterTarget }]]));\n }\n }\n}\n\nfunction createFilteredTreeNode({\n type,\n id,\n isFilterTarget,\n parent,\n}: {\n type: FilteredTreeNode[\"type\"];\n id: string;\n isFilterTarget: boolean;\n parent: FilteredTreeNode | FilteredTreeRootNode;\n}): FilteredTreeNode {\n if (type === \"subject\" || type === \"model\") {\n return {\n id,\n isFilterTarget,\n type,\n };\n }\n\n if (type === \"category\") {\n assert(\"type\" in parent && parent.type === \"model\");\n return {\n id,\n isFilterTarget,\n type,\n modelId: parent.id,\n };\n }\n\n if (\"type\" in parent && parent.type === \"category\") {\n return {\n id,\n isFilterTarget,\n type,\n modelId: parent.modelId,\n categoryId: parent.id,\n };\n }\n\n if (\"type\" in parent && parent.type === \"element\") {\n return {\n id,\n isFilterTarget,\n type,\n modelId: parent.modelId,\n categoryId: parent.categoryId,\n };\n }\n\n throw new Error(\"Invalid parent node type\");\n}\n\nasync function getType(hierarchyChecker: ECClassHierarchyInspector, className: string) {\n if (await hierarchyChecker.classDerivesFrom(className, SUBJECT_CLASS_NAME)) {\n return \"subject\";\n }\n if (await hierarchyChecker.classDerivesFrom(className, MODEL_CLASS_NAME)) {\n return \"model\";\n }\n if (await hierarchyChecker.classDerivesFrom(className, CATEGORY_CLASS_NAME)) {\n return \"category\";\n }\n return \"element\";\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FilteredTree.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/FilteredTree.ts"],"names":[],"mappings":"AAAA;;;g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9B,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAC9C,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,gBAA2C,EAAE,SAAiB;IACnF,IAAI,MAAM,gBAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,kBAAkB,CAAC,EAAE,CAAC;QAC3E,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,MAAM,gBAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,gBAAgB,CAAC,EAAE,CAAC;QACzE,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,MAAM,gBAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,EAAE,CAAC;QAC5E,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,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 { assert, Id64 } from \"@itwin/core-bentley\";\nimport { HierarchyFilteringPath, HierarchyNode, HierarchyNodeIdentifier, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { getIdsFromChildrenTree } from \"../Utils.js\";\n\nimport type { Id64Arg, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { ClassGroupingNodeKey, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport type { ECClassHierarchyInspector } from \"@itwin/presentation-shared\";\nimport type { ChildrenTree } from \"../Utils.js\";\n\ninterface FilteredTreeRootNode {\n children: Map<Id64String, FilteredTreeNode>;\n}\n\ninterface BaseFilteredTreeNode {\n id: string;\n children?: Map<Id64String, FilteredTreeNode>;\n isFilterTarget: boolean;\n}\n\ninterface GenericFilteredTreeNode extends BaseFilteredTreeNode {\n type: \"subject\" | \"model\";\n}\n\ninterface CategoryFilteredTreeNode extends BaseFilteredTreeNode {\n type: \"category\";\n modelId: Id64String;\n}\n\ninterface ElementFilteredTreeNode extends BaseFilteredTreeNode {\n type: \"element\";\n modelId: Id64String;\n categoryId: Id64String;\n}\n\ntype FilteredTreeNode = GenericFilteredTreeNode | CategoryFilteredTreeNode | ElementFilteredTreeNode;\n\ninterface GetElementsFromUnfilteredChildrenTreeProps {\n childrenTree: ChildrenTree;\n parentIdsPath: Array<Id64Arg>;\n}\n\n/** @internal */\nexport interface FilteredTree {\n getVisibilityChangeTargets(node: HierarchyNode & { key: ClassGroupingNodeKey | InstancesNodeKey }): VisibilityChangeTargets;\n getElementsFromUnfilteredChildrenTree(props: GetElementsFromUnfilteredChildrenTreeProps): Id64Set | undefined;\n}\n\nexport const SUBJECT_CLASS_NAME = \"BisCore.Subject\" as const;\nexport const MODEL_CLASS_NAME = \"BisCore.GeometricModel3d\" as const;\nexport const CATEGORY_CLASS_NAME = \"BisCore.SpatialCategory\" as const;\nexport const ELEMENT_CLASS_NAME = \"BisCore.GeometricElement3d\" as const;\n\ntype CategoryKey = `${Id64String}-${Id64String}`;\n\nfunction createCategoryKey(modelId: string, categoryId: string): CategoryKey {\n return `${modelId}-${categoryId}`;\n}\n\n/** @internal */\nexport function parseCategoryKey(key: CategoryKey) {\n const [modelId, categoryId] = key.split(\"-\");\n return { modelId, categoryId };\n}\n\n/** @internal */\nexport interface VisibilityChangeTargets {\n subjects?: Set<Id64String>;\n models?: Set<Id64String>;\n categories?: Set<CategoryKey>;\n elements?: Map<CategoryKey, Map<Id64String, { isFilterTarget: boolean }>>;\n}\n\n/** @internal */\nexport async function createFilteredTree(imodelAccess: ECClassHierarchyInspector, filteringPaths: HierarchyFilteringPath[]): Promise<FilteredTree> {\n const root: FilteredTreeRootNode = {\n children: new Map(),\n };\n\n for (const filteringPath of filteringPaths) {\n const normalizedPath = HierarchyFilteringPath.normalize(filteringPath).path;\n\n let parentNode: FilteredTreeRootNode | FilteredTreeNode = root;\n for (let i = 0; i < normalizedPath.length; i++) {\n if (\"type\" in parentNode && parentNode.isFilterTarget) {\n break;\n }\n\n const identifier = normalizedPath[i];\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(identifier)) {\n break;\n }\n\n const currentNode: FilteredTreeNode | undefined = parentNode.children?.get(identifier.id);\n if (currentNode !== undefined) {\n parentNode = currentNode;\n continue;\n }\n\n const type = await getType(imodelAccess, identifier.className);\n const newNode: FilteredTreeNode = createFilteredTreeNode({\n type,\n id: identifier.id,\n isFilterTarget: i === normalizedPath.length - 1,\n parent: parentNode as FilteredTreeNode,\n });\n (parentNode.children ??= new Map()).set(identifier.id, newNode);\n parentNode = newNode;\n }\n }\n\n return {\n getVisibilityChangeTargets: (node) => getVisibilityChangeTargets(root, node),\n getElementsFromUnfilteredChildrenTree: ({ childrenTree, parentIdsPath }) => getElementsFromUnfilteredChildrenTree({ parentIdsPath, root, childrenTree }),\n };\n}\n\n/**\n * Unfiltered tree can contain ids of models/categories/elements which are not present in the filtered tree.\n * This function retrieves only those ids which are either filter tree targets, or are their children (direct and indirect).\n */\nfunction getElementsFromUnfilteredChildrenTree(props: GetElementsFromUnfilteredChildrenTreeProps & { root: FilteredTreeRootNode }): Id64Set | undefined {\n if (props.childrenTree.size === 0 || props.parentIdsPath.length === 0) {\n return undefined;\n }\n\n let lookupParents: Array<FilteredTreeRootNode | FilteredTreeNode> = [props.root];\n for (const parentIds of props.parentIdsPath) {\n // When filtered node does not have children, it is filter target and because of this, all elements in the childrenTree are in the filtered tree\n if (lookupParents.every((parent) => !parent.children)) {\n return getIdsFromChildrenTree({ tree: props.childrenTree });\n }\n\n const parentNodes = findMatchingFilteredNodes(lookupParents, parentIds);\n if (parentNodes.length === 0) {\n return undefined;\n }\n lookupParents = parentNodes;\n }\n\n // We have unfiltered children tree and filtered nodes that are parents of first level nodes in unfiltered children tree.\n // We can start filtering unfiltered children tree based on filtered nodes.\n const result = getChildrenTreeIdsMatchingFilteredNodes({ tree: props.childrenTree, filteredNodes: lookupParents });\n return result.size > 0 ? result : undefined;\n}\n\nfunction getChildrenTreeIdsMatchingFilteredNodes({\n tree,\n filteredNodes,\n}: {\n tree: ChildrenTree;\n filteredNodes: Array<FilteredTreeNode | FilteredTreeRootNode>;\n}): Id64Set {\n const getIdsRecursively = (childrenTree: ChildrenTree, parentFilteredNodes: Array<FilteredTreeNode | FilteredTreeRootNode>): Id64Set => {\n // If one of the parent filtered nodes does not have children, it is filter target and because of this, all elements in the childrenTree are in the filtered tree.\n const hasParentFilterTarget = parentFilteredNodes.some((filteredNode) => \"isFilterTarget\" in filteredNode && filteredNode.isFilterTarget);\n if (hasParentFilterTarget) {\n return getIdsFromChildrenTree({ tree: childrenTree });\n }\n const result = new Set<Id64String>();\n childrenTree.forEach((entry, id) => {\n const nodes = findMatchingFilteredNodes(parentFilteredNodes, id);\n // If no filtered nodes match this id, skip it since it's not in the filtered tree.\n if (nodes.length === 0) {\n return;\n }\n // Id was found in filtered nodes children, add it to the result.\n result.add(id);\n if (entry.children) {\n // Continue recursively for children\n getIdsRecursively(entry.children, nodes).forEach((childId) => result.add(childId));\n }\n });\n return result;\n };\n\n return getIdsRecursively(tree, filteredNodes);\n}\n\nfunction getVisibilityChangeTargets(root: FilteredTreeRootNode, node: HierarchyNode & { key: ClassGroupingNodeKey | InstancesNodeKey }) {\n let lookupParents: Array<FilteredTreeRootNode | FilteredTreeNode> = [root];\n const changeTargets: VisibilityChangeTargets = {};\n\n // find the filtered parent nodes of the `node`\n for (const parentKey of node.parentKeys) {\n if (!HierarchyNodeKey.isInstances(parentKey)) {\n continue;\n }\n\n // tree node might be merged from multiple instances. As filtered tree stores only one instance per node, we need to find all matching nodes\n // and use them when checking for matching node in one level deeper.\n const parentNodes = findMatchingFilteredNodes(\n lookupParents,\n parentKey.instanceKeys.map((key) => key.id),\n );\n if (parentNodes.length === 0) {\n return changeTargets;\n }\n lookupParents = parentNodes;\n }\n const ids = HierarchyNode.isInstancesNode(node) ? node.key.instanceKeys.map(({ id }) => id) : node.groupedInstanceKeys.map(({ id }) => id);\n // find filtered nodes that match the `node`\n const filteredNodes = findMatchingFilteredNodes(lookupParents, ids);\n if (filteredNodes.length === 0) {\n return changeTargets;\n }\n\n filteredNodes.forEach((filteredNode) => collectVisibilityChangeTargets(changeTargets, filteredNode));\n return changeTargets;\n}\n\nfunction findMatchingFilteredNodes(lookupParents: Array<FilteredTreeRootNode | FilteredTreeNode>, ids: Id64Arg): Array<FilteredTreeNode> {\n return lookupParents.flatMap((lookup) => {\n const childrenArray = Array<FilteredTreeNode>();\n for (const id of Id64.iterable(ids)) {\n const node = lookup.children?.get(id);\n if (node) {\n childrenArray.push(node);\n }\n }\n return childrenArray;\n });\n}\n\nfunction collectVisibilityChangeTargets(changeTargets: VisibilityChangeTargets, node: FilteredTreeNode) {\n if (node.isFilterTarget) {\n addTarget(changeTargets, node);\n return;\n }\n\n if (node.type === \"element\") {\n // need to add parent ids as filter target will be an element\n addTarget(changeTargets, node);\n }\n\n if (!node.children) {\n return;\n }\n\n for (const child of node.children.values()) {\n collectVisibilityChangeTargets(changeTargets, child);\n }\n}\n\nfunction addTarget(filterTargets: VisibilityChangeTargets, node: FilteredTreeNode) {\n switch (node.type) {\n case \"subject\":\n (filterTargets.subjects ??= new Set()).add(node.id);\n return;\n case \"model\":\n (filterTargets.models ??= new Set()).add(node.id);\n return;\n case \"category\":\n (filterTargets.categories ??= new Set()).add(createCategoryKey(node.modelId, node.id));\n return;\n case \"element\":\n const categoryKey = createCategoryKey(node.modelId, node.categoryId);\n const elements = (filterTargets.elements ??= new Map()).get(categoryKey);\n if (elements) {\n elements.set(node.id, { isFilterTarget: node.isFilterTarget });\n } else {\n filterTargets.elements.set(categoryKey, new Map([[node.id, { isFilterTarget: node.isFilterTarget }]]));\n }\n }\n}\n\nfunction createFilteredTreeNode({\n type,\n id,\n isFilterTarget,\n parent,\n}: {\n type: FilteredTreeNode[\"type\"];\n id: string;\n isFilterTarget: boolean;\n parent: FilteredTreeNode | FilteredTreeRootNode;\n}): FilteredTreeNode {\n if (type === \"subject\" || type === \"model\") {\n return {\n id,\n isFilterTarget,\n type,\n };\n }\n\n if (type === \"category\") {\n assert(\"type\" in parent && parent.type === \"model\");\n return {\n id,\n isFilterTarget,\n type,\n modelId: parent.id,\n };\n }\n\n if (\"type\" in parent && parent.type === \"category\") {\n return {\n id,\n isFilterTarget,\n type,\n modelId: parent.modelId,\n categoryId: parent.id,\n };\n }\n\n if (\"type\" in parent && parent.type === \"element\") {\n return {\n id,\n isFilterTarget,\n type,\n modelId: parent.modelId,\n categoryId: parent.categoryId,\n };\n }\n\n throw new Error(\"Invalid parent node type\");\n}\n\nasync function getType(hierarchyChecker: ECClassHierarchyInspector, className: string) {\n if (await hierarchyChecker.classDerivesFrom(className, SUBJECT_CLASS_NAME)) {\n return \"subject\";\n }\n if (await hierarchyChecker.classDerivesFrom(className, MODEL_CLASS_NAME)) {\n return \"model\";\n }\n if (await hierarchyChecker.classDerivesFrom(className, CATEGORY_CLASS_NAME)) {\n return \"category\";\n }\n return \"element\";\n}\n"]}
|
package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Observable } from "rxjs";
|
|
|
2
2
|
import type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
3
3
|
import type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import type { ModelsTreeDefinition } from "../ModelsTreeDefinition.js";
|
|
5
|
+
import type { ChildrenTree } from "../Utils.js";
|
|
5
6
|
type ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0]["hierarchyConfig"];
|
|
6
7
|
/** @internal */
|
|
7
8
|
export declare class ModelsTreeIdsCache implements Disposable {
|
|
@@ -10,6 +11,20 @@ export declare class ModelsTreeIdsCache implements Disposable {
|
|
|
10
11
|
[Symbol.dispose](): void;
|
|
11
12
|
private querySubjects;
|
|
12
13
|
private queryModels;
|
|
14
|
+
private queryChildren;
|
|
15
|
+
private getChildrenTreeFromMap;
|
|
16
|
+
private getChildrenCountMap;
|
|
17
|
+
/**
|
|
18
|
+
* Populates #childrenLoadingMap with promises. When these promises resolve, they will populate #childrenMap with values and delete entries from #childrenLoadingMap.
|
|
19
|
+
*/
|
|
20
|
+
private createChildrenLoadingMapEntries;
|
|
21
|
+
private createChildrenMapEntries;
|
|
22
|
+
getChildrenTree({ elementIds }: {
|
|
23
|
+
elementIds: Id64Arg;
|
|
24
|
+
}): Observable<ChildrenTree>;
|
|
25
|
+
getAllChildrenCount({ elementIds }: {
|
|
26
|
+
elementIds: Id64Arg;
|
|
27
|
+
}): Observable<Map<Id64String, number>>;
|
|
13
28
|
private getSubjectInfos;
|
|
14
29
|
/** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */
|
|
15
30
|
getParentSubjectIds(): Observable<Id64Array>;
|
package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import { bufferCount, bufferTime, defer, filter, forkJoin, from, map, mergeAll, mergeMap, reduce, ReplaySubject, shareReplay, Subject, take, toArray, } from "rxjs";
|
|
5
|
+
import { bufferCount, bufferTime, defaultIfEmpty, defer, EMPTY, filter, firstValueFrom, forkJoin, from, map, mergeAll, mergeMap, reduce, ReplaySubject, shareReplay, Subject, take, tap, toArray, } from "rxjs";
|
|
6
6
|
import { assert, Guid, Id64 } from "@itwin/core-bentley";
|
|
7
7
|
import { IModel } from "@itwin/core-common";
|
|
8
|
+
import { releaseMainThreadOnItemsCount } from "../../common/internal/Utils.js";
|
|
8
9
|
import { pushToMap } from "../../common/Utils.js";
|
|
10
|
+
import { getOptimalBatchSize } from "../Utils.js";
|
|
9
11
|
/** @internal */
|
|
10
12
|
export class ModelsTreeIdsCache {
|
|
11
13
|
#categoryElementCounts;
|
|
@@ -18,6 +20,9 @@ export class ModelsTreeIdsCache {
|
|
|
18
20
|
#categoryKeyPaths;
|
|
19
21
|
#queryExecutor;
|
|
20
22
|
#hierarchyConfig;
|
|
23
|
+
#childrenMap;
|
|
24
|
+
/** Stores element ids which have children query scheduled to execute. */
|
|
25
|
+
#childrenLoadingMap;
|
|
21
26
|
#componentId;
|
|
22
27
|
#componentName;
|
|
23
28
|
constructor(queryExecutor, hierarchyConfig, componentId) {
|
|
@@ -27,6 +32,8 @@ export class ModelsTreeIdsCache {
|
|
|
27
32
|
this.#modelKeyPaths = new Map();
|
|
28
33
|
this.#subjectKeyPaths = new Map();
|
|
29
34
|
this.#categoryKeyPaths = new Map();
|
|
35
|
+
this.#childrenMap = new Map();
|
|
36
|
+
this.#childrenLoadingMap = new Map();
|
|
30
37
|
this.#componentId = componentId ?? Guid.createValue();
|
|
31
38
|
this.#componentName = "ModelsTreeIdsCache";
|
|
32
39
|
}
|
|
@@ -75,6 +82,130 @@ export class ModelsTreeIdsCache {
|
|
|
75
82
|
return { id: row.id, parentId: row.parentId };
|
|
76
83
|
}));
|
|
77
84
|
}
|
|
85
|
+
queryChildren({ elementIds }) {
|
|
86
|
+
if (elementIds.length === 0) {
|
|
87
|
+
return EMPTY;
|
|
88
|
+
}
|
|
89
|
+
return defer(() => {
|
|
90
|
+
const ctes = [
|
|
91
|
+
`
|
|
92
|
+
ElementChildren(id, parentId) AS (
|
|
93
|
+
SELECT ECInstanceId id, Parent.Id parentId
|
|
94
|
+
FROM ${this.#hierarchyConfig.elementClassSpecification}
|
|
95
|
+
WHERE Parent.Id IN (${elementIds.join(", ")})
|
|
96
|
+
|
|
97
|
+
UNION ALL
|
|
98
|
+
|
|
99
|
+
SELECT c.ECInstanceId id, c.Parent.Id
|
|
100
|
+
FROM ${this.#hierarchyConfig.elementClassSpecification} c
|
|
101
|
+
JOIN ElementChildren p ON c.Parent.Id = p.id
|
|
102
|
+
)
|
|
103
|
+
`,
|
|
104
|
+
];
|
|
105
|
+
const ecsql = `
|
|
106
|
+
SELECT id, parentId
|
|
107
|
+
FROM ElementChildren
|
|
108
|
+
`;
|
|
109
|
+
return this.#queryExecutor.createQueryReader({ ecsql, ctes }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/children/${Guid.createValue()}` });
|
|
110
|
+
}).pipe(map((row) => {
|
|
111
|
+
return { id: row.id, parentId: row.parentId };
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
getChildrenTreeFromMap({ elementIds }) {
|
|
115
|
+
const result = new Map();
|
|
116
|
+
if (Id64.sizeOf(elementIds) === 0 || this.#childrenMap.size === 0) {
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
for (const elementId of Id64.iterable(elementIds)) {
|
|
120
|
+
const entry = this.#childrenMap.get(elementId);
|
|
121
|
+
if (!entry?.children) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const elementChildrenTree = new Map();
|
|
125
|
+
result.set(elementId, { children: elementChildrenTree });
|
|
126
|
+
entry.children.forEach((childId) => {
|
|
127
|
+
const childrenTreeOfChild = this.getChildrenTreeFromMap({ elementIds: childId });
|
|
128
|
+
// Need to add children tree created from childId. This tree includes childId as root element
|
|
129
|
+
// If child does not have children, children tree won't be created. Need to add childId with undefined children
|
|
130
|
+
elementChildrenTree.set(childId, { children: childrenTreeOfChild.size > 0 ? childrenTreeOfChild : undefined });
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
getChildrenCountMap({ elementIds }) {
|
|
136
|
+
const result = new Map();
|
|
137
|
+
for (const elementId of Id64.iterable(elementIds)) {
|
|
138
|
+
const entry = this.#childrenMap.get(elementId);
|
|
139
|
+
if (entry?.children) {
|
|
140
|
+
let totalChildrenCount = entry.children.length;
|
|
141
|
+
this.getChildrenCountMap({ elementIds: entry.children }).forEach((childrenOfChildCount) => (totalChildrenCount += childrenOfChildCount));
|
|
142
|
+
result.set(elementId, totalChildrenCount);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Populates #childrenLoadingMap with promises. When these promises resolve, they will populate #childrenMap with values and delete entries from #childrenLoadingMap.
|
|
149
|
+
*/
|
|
150
|
+
createChildrenLoadingMapEntries({ elementsToQuery }) {
|
|
151
|
+
const getElementsToQueryPromise = async (batchedElementsToQuery) => firstValueFrom(this.queryChildren({ elementIds: batchedElementsToQuery }).pipe(
|
|
152
|
+
// Want to have void at the end instead of void[], so using reduce
|
|
153
|
+
reduce((acc, { parentId, id }) => {
|
|
154
|
+
let entry = this.#childrenMap.get(parentId);
|
|
155
|
+
if (!entry) {
|
|
156
|
+
entry = { children: [] };
|
|
157
|
+
this.#childrenMap.set(parentId, entry);
|
|
158
|
+
}
|
|
159
|
+
if (!entry.children) {
|
|
160
|
+
entry.children = [];
|
|
161
|
+
}
|
|
162
|
+
// Add child to parent's entry and add child to children map
|
|
163
|
+
entry.children.push(id);
|
|
164
|
+
if (!this.#childrenMap.has(id)) {
|
|
165
|
+
this.#childrenMap.set(id, { children: undefined });
|
|
166
|
+
}
|
|
167
|
+
return acc;
|
|
168
|
+
}, (() => { })()), tap({ complete: () => batchedElementsToQuery.forEach((elementId) => this.#childrenLoadingMap.delete(elementId)) }), defaultIfEmpty((() => { })())));
|
|
169
|
+
const maximumBatchSize = 1000;
|
|
170
|
+
const totalSize = elementsToQuery.length;
|
|
171
|
+
const optimalBatchSize = getOptimalBatchSize({ totalSize, maximumBatchSize });
|
|
172
|
+
const loadingMapEntries = new Array();
|
|
173
|
+
// Don't want to slice if its not necessary
|
|
174
|
+
if (totalSize <= maximumBatchSize) {
|
|
175
|
+
loadingMapEntries.push(getElementsToQueryPromise(elementsToQuery));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
for (let i = 0; i < elementsToQuery.length; i += optimalBatchSize) {
|
|
179
|
+
loadingMapEntries.push(getElementsToQueryPromise(elementsToQuery.slice(i, i + optimalBatchSize)));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
elementsToQuery.forEach((elementId, index) => this.#childrenLoadingMap.set(elementId, loadingMapEntries[Math.floor(index / optimalBatchSize)]));
|
|
183
|
+
return { loadingMapEntries: Promise.all(loadingMapEntries).then(() => { }) };
|
|
184
|
+
}
|
|
185
|
+
createChildrenMapEntries({ elementIds }) {
|
|
186
|
+
return from(Id64.iterable(elementIds)).pipe(reduce((acc, elementId) => {
|
|
187
|
+
if (this.#childrenMap.has(elementId)) {
|
|
188
|
+
return acc;
|
|
189
|
+
}
|
|
190
|
+
const loadingPromise = this.#childrenLoadingMap.get(elementId);
|
|
191
|
+
if (loadingPromise) {
|
|
192
|
+
acc.existingPromises.push(loadingPromise);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
acc.elementsToQuery.push(elementId);
|
|
196
|
+
}
|
|
197
|
+
return acc;
|
|
198
|
+
}, { existingPromises: new Array(), elementsToQuery: new Array() }), mergeMap(async ({ elementsToQuery, existingPromises }) => {
|
|
199
|
+
existingPromises.push(this.createChildrenLoadingMapEntries({ elementsToQuery }).loadingMapEntries);
|
|
200
|
+
return Promise.all(existingPromises);
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
getChildrenTree({ elementIds }) {
|
|
204
|
+
return this.createChildrenMapEntries({ elementIds }).pipe(map(() => this.getChildrenTreeFromMap({ elementIds })));
|
|
205
|
+
}
|
|
206
|
+
getAllChildrenCount({ elementIds }) {
|
|
207
|
+
return this.createChildrenMapEntries({ elementIds }).pipe(map(() => this.getChildrenCountMap({ elementIds })));
|
|
208
|
+
}
|
|
78
209
|
getSubjectInfos() {
|
|
79
210
|
this.#subjectInfos ??= forkJoin({
|
|
80
211
|
subjectInfos: this.querySubjects().pipe(reduce((acc, subject) => {
|
|
@@ -355,7 +486,7 @@ export class ModelsTreeIdsCache {
|
|
|
355
486
|
rowFormat: "ECSqlPropertyNames",
|
|
356
487
|
limit: "unbounded",
|
|
357
488
|
restartToken: `${this.#componentName}/${this.#componentId}/category-element-counts/${Guid.createValue()}`,
|
|
358
|
-
}))), reduce(({ acc, createKey }, row) => {
|
|
489
|
+
}))), releaseMainThreadOnItemsCount(500), reduce(({ acc, createKey }, row) => {
|
|
359
490
|
acc.set(createKey({ modelId: row.modelId, categoryId: row.categoryId }), {
|
|
360
491
|
modelId: row.modelId,
|
|
361
492
|
categoryId: row.categoryId,
|