@itwin/tree-widget-react 3.15.0 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -2
- package/lib/cjs/tree-widget-react/TreeWidget.d.ts +1 -2
- package/lib/cjs/tree-widget-react/TreeWidget.js +12 -12
- package/lib/cjs/tree-widget-react/TreeWidget.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.d.ts +2 -3
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +5 -4
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +4 -7
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +39 -31
- 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/UseCategoriesTree.js +6 -2
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +3 -11
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +45 -36
- 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.d.ts +1 -3
- package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +30 -30
- 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.d.ts +2 -7
- package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +8 -21
- package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.d.ts +3 -0
- package/lib/cjs/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js +7 -7
- package/lib/cjs/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/common/useGuid.d.ts +2 -0
- package/lib/cjs/tree-widget-react/components/trees/common/useGuid.js +14 -0
- package/lib/cjs/tree-widget-react/components/trees/common/useGuid.js.map +1 -0
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +4 -1
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.d.ts +4 -6
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +31 -26
- package/lib/cjs/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +4 -2
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +1 -5
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +44 -44
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.d.ts +3 -6
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js +20 -16
- package/lib/cjs/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +3 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +6 -10
- package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +107 -64
- 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/UseModelsTree.js +18 -8
- package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.d.ts +24 -0
- package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.js +46 -0
- 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.d.ts +40 -9
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +68 -39
- 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 +13 -5
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +20 -14
- 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 +5 -13
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +70 -60
- 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.d.ts +6 -2
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +189 -197
- package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/TreeWidget.d.ts +1 -2
- package/lib/esm/tree-widget-react/TreeWidget.js +12 -12
- package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.d.ts +2 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +5 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +4 -7
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +39 -31
- 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/UseCategoriesTree.js +6 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +3 -11
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +45 -36
- 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.d.ts +1 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +30 -30
- 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.d.ts +2 -7
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +8 -20
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.d.ts +3 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js +7 -7
- package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/useGuid.d.ts +2 -0
- package/lib/esm/tree-widget-react/components/trees/common/useGuid.js +11 -0
- package/lib/esm/tree-widget-react/components/trees/common/useGuid.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +4 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.d.ts +4 -6
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +31 -26
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +4 -2
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +1 -5
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +44 -44
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.d.ts +3 -6
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js +21 -17
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +3 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +6 -10
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +107 -64
- 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/UseModelsTree.js +18 -8
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.d.ts +24 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js +44 -0
- 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.d.ts +40 -9
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +70 -41
- 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 +13 -5
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +22 -16
- 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 +5 -13
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +71 -61
- 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.d.ts +6 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +192 -200
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/package.json +8 -8
package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Id64Arg, Id64Array, Id64String } from "@itwin/core-bentley";
|
|
1
|
+
import type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
3
2
|
import type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
|
|
3
|
+
import type { ModelsTreeDefinition } from "../ModelsTreeDefinition.js";
|
|
4
4
|
type ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0]["hierarchyConfig"];
|
|
5
5
|
/** @internal */
|
|
6
6
|
export declare class ModelsTreeIdsCache implements Disposable {
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
private readonly _categoryElementCounts;
|
|
10
|
-
private _subjectInfos;
|
|
11
|
-
private _parentSubjectIds;
|
|
12
|
-
private _modelInfos;
|
|
13
|
-
private _modelWithCategoryModeledElements;
|
|
14
|
-
private _modelKeyPaths;
|
|
15
|
-
private _subjectKeyPaths;
|
|
16
|
-
private _categoryKeyPaths;
|
|
17
|
-
constructor(_queryExecutor: LimitingECSqlQueryExecutor, _hierarchyConfig: ModelsTreeHierarchyConfiguration);
|
|
7
|
+
#private;
|
|
8
|
+
constructor(queryExecutor: LimitingECSqlQueryExecutor, hierarchyConfig: ModelsTreeHierarchyConfiguration, componentId?: GuidString);
|
|
18
9
|
[Symbol.dispose](): void;
|
|
19
10
|
private querySubjects;
|
|
20
11
|
private queryModels;
|
|
@@ -35,6 +26,7 @@ export declare class ModelsTreeIdsCache implements Disposable {
|
|
|
35
26
|
private queryModeledElements;
|
|
36
27
|
private getModelWithCategoryModeledElements;
|
|
37
28
|
private getModelInfos;
|
|
29
|
+
getAllCategories(): Promise<Id64Set>;
|
|
38
30
|
getModelCategories(modelId: Id64String): Promise<Id64Array>;
|
|
39
31
|
hasSubModel(elementId: Id64String): Promise<boolean>;
|
|
40
32
|
getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Arg): Promise<Id64Array>;
|
package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js
CHANGED
|
@@ -12,26 +12,30 @@ const Rxjs_js_1 = require("../../common/Rxjs.js");
|
|
|
12
12
|
const Utils_js_1 = require("../../common/Utils.js");
|
|
13
13
|
/** @internal */
|
|
14
14
|
class ModelsTreeIdsCache {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this
|
|
29
|
-
this
|
|
30
|
-
this
|
|
31
|
-
this
|
|
15
|
+
#categoryElementCounts;
|
|
16
|
+
#subjectInfos;
|
|
17
|
+
#parentSubjectIds; // the list should contain a subject id if its node should be shown as having children
|
|
18
|
+
#modelInfos;
|
|
19
|
+
#modelWithCategoryModeledElements;
|
|
20
|
+
#modelKeyPaths;
|
|
21
|
+
#subjectKeyPaths;
|
|
22
|
+
#categoryKeyPaths;
|
|
23
|
+
#queryExecutor;
|
|
24
|
+
#hierarchyConfig;
|
|
25
|
+
#componentId;
|
|
26
|
+
#componentName;
|
|
27
|
+
constructor(queryExecutor, hierarchyConfig, componentId) {
|
|
28
|
+
this.#hierarchyConfig = hierarchyConfig;
|
|
29
|
+
this.#queryExecutor = queryExecutor;
|
|
30
|
+
this.#categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));
|
|
31
|
+
this.#modelKeyPaths = new Map();
|
|
32
|
+
this.#subjectKeyPaths = new Map();
|
|
33
|
+
this.#categoryKeyPaths = new Map();
|
|
34
|
+
this.#componentId = componentId ?? core_bentley_1.Guid.createValue();
|
|
35
|
+
this.#componentName = "ModelsTreeIdsCache";
|
|
32
36
|
}
|
|
33
37
|
[Symbol.dispose]() {
|
|
34
|
-
this
|
|
38
|
+
this.#categoryElementCounts[Symbol.dispose]();
|
|
35
39
|
}
|
|
36
40
|
async *querySubjects() {
|
|
37
41
|
const subjectsQuery = `
|
|
@@ -43,7 +47,7 @@ class ModelsTreeIdsCache {
|
|
|
43
47
|
FROM bis.GeometricModel3d m
|
|
44
48
|
WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))
|
|
45
49
|
AND NOT m.IsPrivate
|
|
46
|
-
AND EXISTS (SELECT 1 FROM ${this.
|
|
50
|
+
AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)
|
|
47
51
|
) targetPartitionId,
|
|
48
52
|
CASE
|
|
49
53
|
WHEN (
|
|
@@ -54,7 +58,7 @@ class ModelsTreeIdsCache {
|
|
|
54
58
|
END hideInHierarchy
|
|
55
59
|
FROM bis.Subject s
|
|
56
60
|
`;
|
|
57
|
-
for await (const row of this.
|
|
61
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: subjectsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/subjects` })) {
|
|
58
62
|
yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };
|
|
59
63
|
}
|
|
60
64
|
}
|
|
@@ -65,14 +69,14 @@ class ModelsTreeIdsCache {
|
|
|
65
69
|
INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId
|
|
66
70
|
WHERE
|
|
67
71
|
NOT m.IsPrivate
|
|
68
|
-
${this.
|
|
72
|
+
${this.#hierarchyConfig.showEmptyModels ? "" : `AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}
|
|
69
73
|
`;
|
|
70
|
-
for await (const row of this.
|
|
74
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: modelsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/models` })) {
|
|
71
75
|
yield { id: row.id, parentId: row.parentId };
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
async getSubjectInfos() {
|
|
75
|
-
this
|
|
79
|
+
this.#subjectInfos ??= (async () => {
|
|
76
80
|
const [subjectInfos, targetPartitionSubjects] = await Promise.all([
|
|
77
81
|
(async () => {
|
|
78
82
|
const result = new Map();
|
|
@@ -114,11 +118,11 @@ class ModelsTreeIdsCache {
|
|
|
114
118
|
}
|
|
115
119
|
return subjectInfos;
|
|
116
120
|
})();
|
|
117
|
-
return this
|
|
121
|
+
return this.#subjectInfos;
|
|
118
122
|
}
|
|
119
123
|
/** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */
|
|
120
124
|
async getParentSubjectIds() {
|
|
121
|
-
this
|
|
125
|
+
this.#parentSubjectIds ??= (async () => {
|
|
122
126
|
const subjectInfos = await this.getSubjectInfos();
|
|
123
127
|
const parentSubjectIds = new Set();
|
|
124
128
|
subjectInfos.forEach((subjectInfo, subjectId) => {
|
|
@@ -133,7 +137,7 @@ class ModelsTreeIdsCache {
|
|
|
133
137
|
});
|
|
134
138
|
return [...parentSubjectIds];
|
|
135
139
|
})();
|
|
136
|
-
return this
|
|
140
|
+
return this.#parentSubjectIds;
|
|
137
141
|
}
|
|
138
142
|
/**
|
|
139
143
|
* Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into
|
|
@@ -193,14 +197,14 @@ class ModelsTreeIdsCache {
|
|
|
193
197
|
return modelIds;
|
|
194
198
|
}
|
|
195
199
|
async createSubjectInstanceKeysPath(targetSubjectId) {
|
|
196
|
-
let entry = this.
|
|
200
|
+
let entry = this.#subjectKeyPaths.get(targetSubjectId);
|
|
197
201
|
if (!entry) {
|
|
198
202
|
entry = (async () => {
|
|
199
203
|
const subjectInfos = await this.getSubjectInfos();
|
|
200
204
|
const result = new Array();
|
|
201
205
|
let currParentId = targetSubjectId;
|
|
202
206
|
while (currParentId) {
|
|
203
|
-
if (this.
|
|
207
|
+
if (this.#hierarchyConfig.hideRootSubject && currParentId === core_common_1.IModel.rootSubjectId) {
|
|
204
208
|
break;
|
|
205
209
|
}
|
|
206
210
|
const parentInfo = subjectInfos.get(currParentId);
|
|
@@ -211,7 +215,7 @@ class ModelsTreeIdsCache {
|
|
|
211
215
|
}
|
|
212
216
|
return result.reverse();
|
|
213
217
|
})();
|
|
214
|
-
this.
|
|
218
|
+
this.#subjectKeyPaths.set(targetSubjectId, entry);
|
|
215
219
|
}
|
|
216
220
|
return entry;
|
|
217
221
|
}
|
|
@@ -223,10 +227,10 @@ class ModelsTreeIdsCache {
|
|
|
223
227
|
m.IsPrivate isModelPrivate,
|
|
224
228
|
MAX(IIF(this.Parent.Id IS NULL, 1, 0)) isRootElementCategory
|
|
225
229
|
FROM BisCore.Model m
|
|
226
|
-
JOIN ${this.
|
|
230
|
+
JOIN ${this.#hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id
|
|
227
231
|
GROUP BY modelId, categoryId, isModelPrivate
|
|
228
232
|
`;
|
|
229
|
-
for await (const row of this.
|
|
233
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/model-categories` })) {
|
|
230
234
|
yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate, isRootElementCategory: !!row.isRootElementCategory };
|
|
231
235
|
}
|
|
232
236
|
}
|
|
@@ -237,17 +241,17 @@ class ModelsTreeIdsCache {
|
|
|
237
241
|
pe.Category.Id categoryId,
|
|
238
242
|
pe.Model.Id modelId
|
|
239
243
|
FROM BisCore.Model m
|
|
240
|
-
JOIN ${this.
|
|
244
|
+
JOIN ${this.#hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id
|
|
241
245
|
WHERE
|
|
242
246
|
m.IsPrivate = false
|
|
243
|
-
AND m.ECInstanceId IN (SELECT Model.Id FROM ${this.
|
|
247
|
+
AND m.ECInstanceId IN (SELECT Model.Id FROM ${this.#hierarchyConfig.elementClassSpecification})
|
|
244
248
|
`;
|
|
245
|
-
for await (const row of this.
|
|
249
|
+
for await (const row of this.#queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/modeled-elements` })) {
|
|
246
250
|
yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };
|
|
247
251
|
}
|
|
248
252
|
}
|
|
249
253
|
async getModelWithCategoryModeledElements() {
|
|
250
|
-
this
|
|
254
|
+
this.#modelWithCategoryModeledElements ??= (async () => {
|
|
251
255
|
const modelWithCategoryModeledElements = new Map();
|
|
252
256
|
for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {
|
|
253
257
|
const key = `${modelId}-${categoryId}`;
|
|
@@ -261,10 +265,10 @@ class ModelsTreeIdsCache {
|
|
|
261
265
|
}
|
|
262
266
|
return modelWithCategoryModeledElements;
|
|
263
267
|
})();
|
|
264
|
-
return this
|
|
268
|
+
return this.#modelWithCategoryModeledElements;
|
|
265
269
|
}
|
|
266
270
|
async getModelInfos() {
|
|
267
|
-
this
|
|
271
|
+
this.#modelInfos ??= (async () => {
|
|
268
272
|
const modelInfos = new Map();
|
|
269
273
|
for await (const { modelId, categoryId, isModelPrivate, isRootElementCategory } of this.queryModelCategories()) {
|
|
270
274
|
const entry = modelInfos.get(modelId);
|
|
@@ -278,7 +282,15 @@ class ModelsTreeIdsCache {
|
|
|
278
282
|
}
|
|
279
283
|
return modelInfos;
|
|
280
284
|
})();
|
|
281
|
-
return this
|
|
285
|
+
return this.#modelInfos;
|
|
286
|
+
}
|
|
287
|
+
async getAllCategories() {
|
|
288
|
+
const modelInfos = await this.getModelInfos();
|
|
289
|
+
const result = new Set();
|
|
290
|
+
modelInfos.forEach(({ categories }) => {
|
|
291
|
+
categories.forEach((_, categoryId) => result.add(categoryId));
|
|
292
|
+
});
|
|
293
|
+
return result;
|
|
282
294
|
}
|
|
283
295
|
async getModelCategories(modelId) {
|
|
284
296
|
const modelInfos = await this.getModelInfos();
|
|
@@ -305,7 +317,7 @@ class ModelsTreeIdsCache {
|
|
|
305
317
|
return result;
|
|
306
318
|
}
|
|
307
319
|
async createModelInstanceKeyPaths(modelId) {
|
|
308
|
-
let entry = this.
|
|
320
|
+
let entry = this.#modelKeyPaths.get(modelId);
|
|
309
321
|
if (!entry) {
|
|
310
322
|
entry = (async () => {
|
|
311
323
|
const result = new Array();
|
|
@@ -318,7 +330,7 @@ class ModelsTreeIdsCache {
|
|
|
318
330
|
}
|
|
319
331
|
return result;
|
|
320
332
|
})();
|
|
321
|
-
this.
|
|
333
|
+
this.#modelKeyPaths.set(modelId, entry);
|
|
322
334
|
}
|
|
323
335
|
return entry;
|
|
324
336
|
}
|
|
@@ -336,12 +348,12 @@ class ModelsTreeIdsCache {
|
|
|
336
348
|
// we may have thousands of where clauses here, and sending a single query with all of them could take a
|
|
337
349
|
// long time - instead, split it into smaller chunks
|
|
338
350
|
(0, rxjs_1.bufferCount)(100), (0, rxjs_1.mergeMap)(async (whereClauses) => {
|
|
339
|
-
const reader = this.
|
|
351
|
+
const reader = this.#queryExecutor.createQueryReader({
|
|
340
352
|
ctes: [
|
|
341
353
|
`
|
|
342
354
|
CategoryElements(id, modelId, categoryId) AS (
|
|
343
355
|
SELECT ECInstanceId, Model.Id, Category.Id
|
|
344
|
-
FROM ${this.
|
|
356
|
+
FROM ${this.#hierarchyConfig.elementClassSpecification}
|
|
345
357
|
WHERE
|
|
346
358
|
Parent.Id IS NULL
|
|
347
359
|
AND (
|
|
@@ -351,7 +363,7 @@ class ModelsTreeIdsCache {
|
|
|
351
363
|
UNION ALL
|
|
352
364
|
|
|
353
365
|
SELECT c.ECInstanceId, p.modelId, p.categoryId
|
|
354
|
-
FROM ${this.
|
|
366
|
+
FROM ${this.#hierarchyConfig.elementClassSpecification} c
|
|
355
367
|
JOIN CategoryElements p ON c.Parent.Id = p.id
|
|
356
368
|
)
|
|
357
369
|
`,
|
|
@@ -361,7 +373,7 @@ class ModelsTreeIdsCache {
|
|
|
361
373
|
FROM CategoryElements
|
|
362
374
|
GROUP BY modelId, categoryId
|
|
363
375
|
`,
|
|
364
|
-
}, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" });
|
|
376
|
+
}, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/category-element-counts` });
|
|
365
377
|
const result = new Array();
|
|
366
378
|
for await (const row of reader) {
|
|
367
379
|
result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });
|
|
@@ -375,10 +387,10 @@ class ModelsTreeIdsCache {
|
|
|
375
387
|
}), (0, rxjs_1.mergeAll)()));
|
|
376
388
|
}
|
|
377
389
|
async getCategoryElementsCount(modelId, categoryId) {
|
|
378
|
-
return this.
|
|
390
|
+
return this.#categoryElementCounts.getCategoryElementsCount(modelId, categoryId);
|
|
379
391
|
}
|
|
380
392
|
async createCategoryInstanceKeyPaths(categoryId) {
|
|
381
|
-
let entry = this.
|
|
393
|
+
let entry = this.#categoryKeyPaths.get(categoryId);
|
|
382
394
|
if (!entry) {
|
|
383
395
|
entry = (async () => {
|
|
384
396
|
const result = new Set();
|
|
@@ -398,7 +410,7 @@ class ModelsTreeIdsCache {
|
|
|
398
410
|
}
|
|
399
411
|
return categoryPaths;
|
|
400
412
|
})();
|
|
401
|
-
this.
|
|
413
|
+
this.#categoryKeyPaths.set(categoryId, entry);
|
|
402
414
|
}
|
|
403
415
|
return entry;
|
|
404
416
|
}
|
|
@@ -416,34 +428,32 @@ function forEachChildSubject(subjectInfos, parentSubject, cb) {
|
|
|
416
428
|
});
|
|
417
429
|
}
|
|
418
430
|
class ModelCategoryElementsCountCache {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
this._subscription = this._requestsStream
|
|
426
|
-
.pipe((0, rxjs_1.bufferTime)(20), (0, rxjs_1.filter)((requests) => requests.length > 0), (0, rxjs_1.mergeMap)(async (requests) => this._loader(requests)), (0, rxjs_1.mergeAll)())
|
|
431
|
+
#cache = new Map();
|
|
432
|
+
#requestsStream = new rxjs_1.Subject();
|
|
433
|
+
#subscription;
|
|
434
|
+
constructor(loader) {
|
|
435
|
+
this.#subscription = this.#requestsStream
|
|
436
|
+
.pipe((0, rxjs_1.bufferTime)(20), (0, rxjs_1.filter)((requests) => requests.length > 0), (0, rxjs_1.mergeMap)(async (requests) => loader(requests)), (0, rxjs_1.mergeAll)())
|
|
427
437
|
.subscribe({
|
|
428
438
|
next: ({ modelId, categoryId, elementsCount }) => {
|
|
429
|
-
const subject = this.
|
|
439
|
+
const subject = this.#cache.get(`${modelId}${categoryId}`);
|
|
430
440
|
(0, core_bentley_1.assert)(!!subject);
|
|
431
441
|
subject.next(elementsCount);
|
|
432
442
|
},
|
|
433
443
|
});
|
|
434
444
|
}
|
|
435
445
|
[Symbol.dispose]() {
|
|
436
|
-
this.
|
|
446
|
+
this.#subscription.unsubscribe();
|
|
437
447
|
}
|
|
438
448
|
async getCategoryElementsCount(modelId, categoryId) {
|
|
439
449
|
const cacheKey = `${modelId}${categoryId}`;
|
|
440
|
-
let result = this.
|
|
450
|
+
let result = this.#cache.get(cacheKey);
|
|
441
451
|
if (result !== undefined) {
|
|
442
452
|
return (0, rxjs_1.firstValueFrom)(result);
|
|
443
453
|
}
|
|
444
454
|
result = new rxjs_1.ReplaySubject(1);
|
|
445
|
-
this.
|
|
446
|
-
this.
|
|
455
|
+
this.#cache.set(cacheKey, result);
|
|
456
|
+
this.#requestsStream.next({ modelId, categoryId });
|
|
447
457
|
return (0, rxjs_1.firstValueFrom)(result);
|
|
448
458
|
}
|
|
449
459
|
}
|
package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelsTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,+BAAsI;AACtI,sDAAmD;AACnD,oDAA4C;AAC5C,kDAA+C;AAC/C,oDAAkD;AAsBlD,gBAAgB;AAChB,MAAa,kBAAkB;IAWnB;IACA;IAXO,sBAAsB,CAAkC;IACjE,aAAa,CAAoD;IACjE,iBAAiB,CAAiC,CAAC,sFAAsF;IACzI,WAAW,CAAkD;IAC7D,iCAAiC,CAA4C;IAC7E,cAAc,CAA2D;IACzE,gBAAgB,CAAyD;IACzE,iBAAiB,CAA2D;IAEpF,YACU,cAA0C,EAC1C,gBAAkD;QADlD,mBAAc,GAAd,cAAc,CAA4B;QAC1C,qBAAgB,GAAhB,gBAAgB,CAAkC;QAE1D,IAAI,CAAC,sBAAsB,GAAG,IAAI,+BAA+B,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3H,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACrC,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,CAAC,aAAa;QAC1B,MAAM,a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AAO,CAAC,CAAC;gBAClB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC9B,CAAC;SACF,CAAC,CAAC;IACP,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,OAAmB,EAAE,UAAsB;QAC/E,MAAM,QAAQ,GAAG,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC;QAC3C,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,IAAA,qBAAc,EAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,GAAG,IAAI,oBAAa,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACnD,OAAO,IAAA,qBAAc,EAAC,MAAM,CAAC,CAAC;IAChC,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 { bufferCount, bufferTime, filter, firstValueFrom, from, map, mergeAll, mergeMap, reduce, ReplaySubject, Subject } from \"rxjs\";\nimport { assert, Id64 } from \"@itwin/core-bentley\";\nimport { IModel } from \"@itwin/core-common\";\nimport { collect } from \"../../common/Rxjs.js\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { Subscription } from \"rxjs\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { ModelsTreeDefinition } from \"../ModelsTreeDefinition.js\";\nimport type { Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\n\ninterface SubjectInfo {\n parentSubject: Id64String | undefined;\n hideInHierarchy: boolean;\n childSubjects: Id64Set;\n childModels: Id64Set;\n}\n\ninterface ModelInfo {\n isModelPrivate: boolean;\n categories: Map<Id64String, { isRootElementCategory: boolean }>;\n}\n\ntype ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0][\"hierarchyConfig\"];\n\n/** @internal */\nexport class ModelsTreeIdsCache implements Disposable {\n private readonly _categoryElementCounts: ModelCategoryElementsCountCache;\n private _subjectInfos: Promise<Map<Id64String, SubjectInfo>> | undefined;\n private _parentSubjectIds: Promise<Id64Array> | undefined; // the list should contain a subject id if its node should be shown as having children\n private _modelInfos: Promise<Map<Id64String, ModelInfo>> | undefined;\n private _modelWithCategoryModeledElements: Promise<Map<string, Id64Set>> | undefined;\n private _modelKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n private _subjectKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath>>;\n private _categoryKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n private _hierarchyConfig: ModelsTreeHierarchyConfiguration,\n ) {\n this._categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));\n this._modelKeyPaths = new Map();\n this._subjectKeyPaths = new Map();\n this._categoryKeyPaths = new Map();\n }\n\n public [Symbol.dispose]() {\n this._categoryElementCounts[Symbol.dispose]();\n }\n\n private async *querySubjects(): AsyncIterableIterator<{ id: Id64String; parentId?: Id64String; targetPartitionId?: Id64String; hideInHierarchy: boolean }> {\n const subjectsQuery = `\n SELECT\n s.ECInstanceId id,\n s.Parent.Id parentId,\n (\n SELECT m.ECInstanceId\n FROM bis.GeometricModel3d m\n WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))\n AND NOT m.IsPrivate\n AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)\n ) targetPartitionId,\n CASE\n WHEN (\n json_extract(s.JsonProperties, '$.Subject.Job.Bridge') IS NOT NULL\n OR json_extract(s.JsonProperties, '$.Subject.Model.Type') = 'Hierarchy'\n ) THEN 1\n ELSE 0\n END hideInHierarchy\n FROM bis.Subject s\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: subjectsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };\n }\n }\n\n private async *queryModels(): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const modelsQuery = `\n SELECT p.ECInstanceId id, p.Parent.Id parentId\n FROM bis.InformationPartitionElement p\n INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId\n WHERE\n NOT m.IsPrivate\n ${this._hierarchyConfig.showEmptyModels ? \"\" : `AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: modelsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId };\n }\n }\n\n private async getSubjectInfos() {\n this._subjectInfos ??= (async () => {\n const [subjectInfos, targetPartitionSubjects] = await Promise.all([\n (async () => {\n const result = new Map<Id64String, SubjectInfo>();\n for await (const subject of this.querySubjects()) {\n const subjectInfo: SubjectInfo = {\n parentSubject: subject.parentId,\n hideInHierarchy: subject.hideInHierarchy,\n childSubjects: new Set(),\n childModels: new Set(),\n };\n if (subject.targetPartitionId) {\n subjectInfo.childModels.add(subject.targetPartitionId);\n }\n result.set(subject.id, subjectInfo);\n }\n return result;\n })(),\n (async () => {\n const result = new Map<Id64String, Set<Id64String>>();\n for await (const model of this.queryModels()) {\n pushToMap(result, model.id, model.parentId);\n }\n return result;\n })(),\n ]);\n\n for (const [subjectId, { parentSubject: parentSubjectId }] of subjectInfos.entries()) {\n if (parentSubjectId) {\n const parentSubjectInfo = subjectInfos.get(parentSubjectId);\n assert(!!parentSubjectInfo);\n parentSubjectInfo.childSubjects.add(subjectId);\n }\n }\n\n for (const [partitionId, subjectIds] of targetPartitionSubjects) {\n subjectIds.forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n assert(!!subjectInfo);\n subjectInfo.childModels.add(partitionId);\n });\n }\n\n return subjectInfos;\n })();\n return this._subjectInfos;\n }\n\n /** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */\n public async getParentSubjectIds(): Promise<Id64String[]> {\n this._parentSubjectIds ??= (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const parentSubjectIds = new Set<Id64String>();\n subjectInfos.forEach((subjectInfo, subjectId) => {\n if (subjectInfo.childModels.size > 0) {\n parentSubjectIds.add(subjectId);\n let currParentId = subjectInfo.parentSubject;\n while (currParentId) {\n parentSubjectIds.add(currParentId);\n currParentId = subjectInfos.get(currParentId)?.parentSubject;\n }\n }\n });\n return [...parentSubjectIds];\n })();\n return this._parentSubjectIds;\n }\n\n /**\n * Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into\n * account `hideInHierarchy` flag.\n */\n public async getChildSubjectIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const childSubjectIds = new Array<Id64String>();\n const subjectInfos = await this.getSubjectInfos();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (!childSubjectInfo.hideInHierarchy) {\n childSubjectIds.push(childSubjectId);\n return \"break\";\n }\n return \"continue\";\n });\n });\n return childSubjectIds;\n }\n\n /** Returns ECInstanceIDs of all Models under specific parent Subjects, including their child Subjects, etc. */\n public async getSubjectModelIds(subjectIds: Id64Array): Promise<Id64Array> {\n const subjectInfos = await this.getSubjectInfos();\n const subjectStack = [...subjectIds];\n const result = new Array<Id64String>();\n while (true) {\n const subjectId = subjectStack.pop();\n if (subjectId === undefined) {\n break;\n }\n const subjectInfo = subjectInfos.get(subjectId);\n if (!subjectInfo) {\n continue;\n }\n result.push(...subjectInfo.childModels);\n subjectStack.push(...subjectInfo.childSubjects);\n }\n return result;\n }\n\n /** Returns ECInstanceIDs of Models under specific parent Subjects as they are displayed in the hierarchy. */\n public async getChildSubjectModelIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const subjectInfos = await this.getSubjectInfos();\n\n const hiddenSubjectIds = new Array<Id64String>();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (childSubjectInfo.hideInHierarchy) {\n hiddenSubjectIds.push(childSubjectId);\n return \"continue\";\n }\n return \"break\";\n });\n });\n\n const modelIds = new Array<Id64String>();\n [...parentSubjectIds, ...hiddenSubjectIds].forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n subjectInfo && modelIds.push(...subjectInfo.childModels);\n });\n return modelIds;\n }\n\n public async createSubjectInstanceKeysPath(targetSubjectId: Id64String): Promise<HierarchyNodeIdentifiersPath> {\n let entry = this._subjectKeyPaths.get(targetSubjectId);\n if (!entry) {\n entry = (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const result = new Array<InstanceKey>();\n let currParentId: Id64String | undefined = targetSubjectId;\n while (currParentId) {\n if (this._hierarchyConfig.hideRootSubject && currParentId === IModel.rootSubjectId) {\n break;\n }\n const parentInfo = subjectInfos.get(currParentId);\n if (!parentInfo?.hideInHierarchy) {\n result.push({ className: \"BisCore.Subject\", id: currParentId });\n }\n currParentId = parentInfo?.parentSubject;\n }\n return result.reverse();\n })();\n this._subjectKeyPaths.set(targetSubjectId, entry);\n }\n return entry;\n }\n\n private async *queryModelCategories(): AsyncIterableIterator<{\n modelId: Id64String;\n categoryId: Id64String;\n isModelPrivate: boolean;\n isRootElementCategory: boolean;\n }> {\n const query = `\n SELECT\n this.Model.Id modelId,\n this.Category.Id categoryId,\n m.IsPrivate isModelPrivate,\n MAX(IIF(this.Parent.Id IS NULL, 1, 0)) isRootElementCategory\n FROM BisCore.Model m\n JOIN ${this._hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id\n GROUP BY modelId, categoryId, isModelPrivate\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate, isRootElementCategory: !!row.isRootElementCategory };\n }\n }\n\n private async *queryModeledElements() {\n const query = `\n SELECT\n pe.ECInstanceId modeledElementId,\n pe.Category.Id categoryId,\n pe.Model.Id modelId\n FROM BisCore.Model m\n JOIN ${this._hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id\n WHERE\n m.IsPrivate = false\n AND m.ECInstanceId IN (SELECT Model.Id FROM ${this._hierarchyConfig.elementClassSpecification})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };\n }\n }\n\n private async getModelWithCategoryModeledElements() {\n this._modelWithCategoryModeledElements ??= (async () => {\n const modelWithCategoryModeledElements = new Map<Id64String, Id64Set>();\n for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {\n const key = `${modelId}-${categoryId}`;\n const entry = modelWithCategoryModeledElements.get(key);\n if (entry === undefined) {\n modelWithCategoryModeledElements.set(key, new Set([modeledElementId]));\n } else {\n entry.add(modeledElementId);\n }\n }\n return modelWithCategoryModeledElements;\n })();\n return this._modelWithCategoryModeledElements;\n }\n\n private async getModelInfos() {\n this._modelInfos ??= (async () => {\n const modelInfos = new Map<Id64String, { categories: Map<Id64String, { isRootElementCategory: boolean }>; isModelPrivate: boolean }>();\n for await (const { modelId, categoryId, isModelPrivate, isRootElementCategory } of this.queryModelCategories()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.categories.set(categoryId, { isRootElementCategory });\n entry.isModelPrivate = isModelPrivate;\n } else {\n modelInfos.set(modelId, { categories: new Map([[categoryId, { isRootElementCategory }]]), isModelPrivate });\n }\n }\n return modelInfos;\n })();\n return this._modelInfos;\n }\n\n public async getModelCategories(modelId: Id64String): Promise<Id64Array> {\n const modelInfos = await this.getModelInfos();\n const categories = modelInfos.get(modelId)?.categories.keys();\n return categories ? [...categories] : [];\n }\n\n public async hasSubModel(elementId: Id64String): Promise<boolean> {\n const modelInfos = await this.getModelInfos();\n const modeledElementInfo = modelInfos.get(elementId);\n if (!modeledElementInfo) {\n return false;\n }\n return !modeledElementInfo.isModelPrivate;\n }\n\n public async getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Arg): Promise<Id64Array> {\n const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();\n const result = new Array<Id64String>();\n for (const categoryId of Id64.iterable(categoryIds)) {\n const entry = modelWithCategoryModeledElements.get(`${modelId}-${categoryId}`);\n if (entry !== undefined) {\n result.push(...entry);\n }\n }\n return result;\n }\n\n public async createModelInstanceKeyPaths(modelId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._modelKeyPaths.get(modelId);\n if (!entry) {\n entry = (async () => {\n const result = new Array<HierarchyNodeIdentifiersPath>();\n const subjectInfos = (await this.getSubjectInfos()).entries();\n for (const [modelSubjectId, subjectInfo] of subjectInfos) {\n if (subjectInfo.childModels.has(modelId)) {\n const subjectPath = await this.createSubjectInstanceKeysPath(modelSubjectId);\n result.push([...subjectPath, { className: \"BisCore.GeometricModel3d\", id: modelId }]);\n }\n }\n return result;\n })();\n\n this._modelKeyPaths.set(modelId, entry);\n }\n return entry;\n }\n\n private async queryCategoryElementCounts(\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ): Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>> {\n return collect(\n from(input).pipe(\n reduce((acc, { modelId, categoryId }) => {\n const entry = acc.get(modelId);\n if (!entry) {\n acc.set(modelId, new Set([categoryId]));\n } else {\n entry.add(categoryId);\n }\n return acc;\n }, new Map<Id64String, Id64Set>()),\n mergeMap((modelCategoryMap) => modelCategoryMap.entries()),\n map(([modelId, categoryIds]) => `Model.Id = ${modelId} AND Category.Id IN (${[...categoryIds].join(\", \")})`),\n // we may have thousands of where clauses here, and sending a single query with all of them could take a\n // long time - instead, split it into smaller chunks\n bufferCount(100),\n mergeMap(async (whereClauses) => {\n const reader = this._queryExecutor.createQueryReader(\n {\n ctes: [\n `\n CategoryElements(id, modelId, categoryId) AS (\n SELECT ECInstanceId, Model.Id, Category.Id\n FROM ${this._hierarchyConfig.elementClassSpecification}\n WHERE\n Parent.Id IS NULL\n AND (\n ${whereClauses.join(\" OR \")}\n )\n\n UNION ALL\n\n SELECT c.ECInstanceId, p.modelId, p.categoryId\n FROM ${this._hierarchyConfig.elementClassSpecification} c\n JOIN CategoryElements p ON c.Parent.Id = p.id\n )\n `,\n ],\n ecsql: `\n SELECT modelId, categoryId, COUNT(id) elementsCount\n FROM CategoryElements\n GROUP BY modelId, categoryId\n `,\n },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" },\n );\n\n const result = new Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>();\n for await (const row of reader) {\n result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });\n }\n\n input.forEach(({ modelId, categoryId }) => {\n if (!result.some((queriedResult) => queriedResult.categoryId === categoryId && queriedResult.modelId === modelId)) {\n result.push({ categoryId, modelId, elementsCount: 0 });\n }\n });\n\n return result;\n }),\n mergeAll(),\n ),\n );\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n return this._categoryElementCounts.getCategoryElementsCount(modelId, categoryId);\n }\n\n public async createCategoryInstanceKeyPaths(categoryId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._categoryKeyPaths.get(categoryId);\n if (!entry) {\n entry = (async () => {\n const result = new Set<Id64String>();\n const modelInfos = await this.getModelInfos();\n modelInfos?.forEach((modelInfo, modelId) => {\n const categoryEntry = modelInfo.categories.get(categoryId);\n if (categoryEntry?.isRootElementCategory) {\n result.add(modelId);\n }\n });\n\n const categoryPaths = new Array<HierarchyNodeIdentifiersPath>();\n for (const categoryModelId of [...result]) {\n const modelPaths = await this.createModelInstanceKeyPaths(categoryModelId);\n for (const modelPath of modelPaths) {\n categoryPaths.push([...modelPath, { className: \"BisCore.SpatialCategory\", id: categoryId }]);\n }\n }\n return categoryPaths;\n })();\n this._categoryKeyPaths.set(categoryId, entry);\n }\n return entry;\n }\n}\n\nfunction forEachChildSubject(\n subjectInfos: Map<Id64String, SubjectInfo>,\n parentSubject: Id64String | SubjectInfo,\n cb: (childSubjectId: Id64String, childSubjectInfo: SubjectInfo) => \"break\" | \"continue\",\n) {\n const parentSubjectInfo = typeof parentSubject === \"string\" ? subjectInfos.get(parentSubject) : parentSubject;\n parentSubjectInfo &&\n parentSubjectInfo.childSubjects.forEach((childSubjectId) => {\n const childSubjectInfo = subjectInfos.get(childSubjectId)!;\n if (cb(childSubjectId, childSubjectInfo) === \"break\") {\n return;\n }\n forEachChildSubject(subjectInfos, childSubjectInfo, cb);\n });\n}\n\nclass ModelCategoryElementsCountCache {\n private _cache = new Map<string, Subject<number>>();\n private _requestsStream = new Subject<{ modelId: Id64String; categoryId: Id64String }>();\n private _subscription: Subscription;\n\n public constructor(\n private _loader: (\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ) => Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>>,\n ) {\n this._subscription = this._requestsStream\n .pipe(\n bufferTime(20),\n filter((requests) => requests.length > 0),\n mergeMap(async (requests) => this._loader(requests)),\n mergeAll(),\n )\n .subscribe({\n next: ({ modelId, categoryId, elementsCount }) => {\n const subject = this._cache.get(`${modelId}${categoryId}`);\n assert(!!subject);\n subject.next(elementsCount);\n },\n });\n }\n\n public [Symbol.dispose]() {\n this._subscription.unsubscribe();\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n const cacheKey = `${modelId}${categoryId}`;\n let result = this._cache.get(cacheKey);\n if (result !== undefined) {\n return firstValueFrom(result);\n }\n\n result = new ReplaySubject(1);\n this._cache.set(cacheKey, result);\n this._requestsStream.next({ modelId, categoryId });\n return firstValueFrom(result);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ModelsTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,+BAAsI;AACtI,sDAAyD;AACzD,oDAA4C;AAC5C,kDAA+C;AAC/C,oDAAkD;AAsBlD,gBAAgB;AAChB,MAAa,kBAAkB;IACpB,sBAAsB,CAAkC;IACjE,aAAa,CAAoD;IACjE,iBAAiB,CAAiC,CAAC,sFAAsF;IACzI,WAAW,CAAkD;IAC7D,iCAAiC,CAA4C;IAC7E,cAAc,CAA2D;IACzE,gBAAgB,CAAyD;IACzE,iBAAiB,CAA2D;IAC5E,cAAc,CAA6B;IAC3C,gBAAgB,CAAmC;IACnD,YAAY,CAAa;IACzB,cAAc,CAAS;IAEvB,YAAY,aAAyC,EAAE,eAAiD,EAAE,WAAwB;QAChI,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QACxC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,sBAAsB,GAAG,IAAI,+BAA+B,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAA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I,CAAC,aAAa,CAAC,CAAC;YAC9B,CAAC;SACF,CAAC,CAAC;IACP,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,OAAmB,EAAE,UAAsB;QAC/E,MAAM,QAAQ,GAAG,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC;QAC3C,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,OAAO,IAAA,qBAAc,EAAC,MAAM,CAAC,CAAC;QAChC,CAAC;QAED,MAAM,GAAG,IAAI,oBAAa,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACnD,OAAO,IAAA,qBAAc,EAAC,MAAM,CAAC,CAAC;IAChC,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 { bufferCount, bufferTime, filter, firstValueFrom, from, map, mergeAll, mergeMap, reduce, ReplaySubject, Subject } from \"rxjs\";\nimport { assert, Guid, Id64 } from \"@itwin/core-bentley\";\nimport { IModel } from \"@itwin/core-common\";\nimport { collect } from \"../../common/Rxjs.js\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { Subscription } from \"rxjs\";\nimport type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { ModelsTreeDefinition } from \"../ModelsTreeDefinition.js\";\n\ninterface SubjectInfo {\n parentSubject: Id64String | undefined;\n hideInHierarchy: boolean;\n childSubjects: Id64Set;\n childModels: Id64Set;\n}\n\ninterface ModelInfo {\n isModelPrivate: boolean;\n categories: Map<Id64String, { isRootElementCategory: boolean }>;\n}\n\ntype ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0][\"hierarchyConfig\"];\n\n/** @internal */\nexport class ModelsTreeIdsCache implements Disposable {\n readonly #categoryElementCounts: ModelCategoryElementsCountCache;\n #subjectInfos: Promise<Map<Id64String, SubjectInfo>> | undefined;\n #parentSubjectIds: Promise<Id64Array> | undefined; // the list should contain a subject id if its node should be shown as having children\n #modelInfos: Promise<Map<Id64String, ModelInfo>> | undefined;\n #modelWithCategoryModeledElements: Promise<Map<string, Id64Set>> | undefined;\n #modelKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n #subjectKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath>>;\n #categoryKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n #queryExecutor: LimitingECSqlQueryExecutor;\n #hierarchyConfig: ModelsTreeHierarchyConfiguration;\n #componentId: GuidString;\n #componentName: string;\n\n constructor(queryExecutor: LimitingECSqlQueryExecutor, hierarchyConfig: ModelsTreeHierarchyConfiguration, componentId?: GuidString) {\n this.#hierarchyConfig = hierarchyConfig;\n this.#queryExecutor = queryExecutor;\n this.#categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));\n this.#modelKeyPaths = new Map();\n this.#subjectKeyPaths = new Map();\n this.#categoryKeyPaths = new Map();\n this.#componentId = componentId ?? Guid.createValue();\n this.#componentName = \"ModelsTreeIdsCache\";\n }\n\n public [Symbol.dispose]() {\n this.#categoryElementCounts[Symbol.dispose]();\n }\n\n private async *querySubjects(): AsyncIterableIterator<{ id: Id64String; parentId?: Id64String; targetPartitionId?: Id64String; hideInHierarchy: boolean }> {\n const subjectsQuery = `\n SELECT\n s.ECInstanceId id,\n s.Parent.Id parentId,\n (\n SELECT m.ECInstanceId\n FROM bis.GeometricModel3d m\n WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))\n AND NOT m.IsPrivate\n AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)\n ) targetPartitionId,\n CASE\n WHEN (\n json_extract(s.JsonProperties, '$.Subject.Job.Bridge') IS NOT NULL\n OR json_extract(s.JsonProperties, '$.Subject.Model.Type') = 'Hierarchy'\n ) THEN 1\n ELSE 0\n END hideInHierarchy\n FROM bis.Subject s\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: subjectsQuery },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/subjects` },\n )) {\n yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };\n }\n }\n\n private async *queryModels(): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const modelsQuery = `\n SELECT p.ECInstanceId id, p.Parent.Id parentId\n FROM bis.InformationPartitionElement p\n INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId\n WHERE\n NOT m.IsPrivate\n ${this.#hierarchyConfig.showEmptyModels ? \"\" : `AND EXISTS (SELECT 1 FROM ${this.#hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: modelsQuery },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/models` },\n )) {\n yield { id: row.id, parentId: row.parentId };\n }\n }\n\n private async getSubjectInfos() {\n this.#subjectInfos ??= (async () => {\n const [subjectInfos, targetPartitionSubjects] = await Promise.all([\n (async () => {\n const result = new Map<Id64String, SubjectInfo>();\n for await (const subject of this.querySubjects()) {\n const subjectInfo: SubjectInfo = {\n parentSubject: subject.parentId,\n hideInHierarchy: subject.hideInHierarchy,\n childSubjects: new Set(),\n childModels: new Set(),\n };\n if (subject.targetPartitionId) {\n subjectInfo.childModels.add(subject.targetPartitionId);\n }\n result.set(subject.id, subjectInfo);\n }\n return result;\n })(),\n (async () => {\n const result = new Map<Id64String, Set<Id64String>>();\n for await (const model of this.queryModels()) {\n pushToMap(result, model.id, model.parentId);\n }\n return result;\n })(),\n ]);\n\n for (const [subjectId, { parentSubject: parentSubjectId }] of subjectInfos.entries()) {\n if (parentSubjectId) {\n const parentSubjectInfo = subjectInfos.get(parentSubjectId);\n assert(!!parentSubjectInfo);\n parentSubjectInfo.childSubjects.add(subjectId);\n }\n }\n\n for (const [partitionId, subjectIds] of targetPartitionSubjects) {\n subjectIds.forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n assert(!!subjectInfo);\n subjectInfo.childModels.add(partitionId);\n });\n }\n\n return subjectInfos;\n })();\n return this.#subjectInfos;\n }\n\n /** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */\n public async getParentSubjectIds(): Promise<Id64String[]> {\n this.#parentSubjectIds ??= (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const parentSubjectIds = new Set<Id64String>();\n subjectInfos.forEach((subjectInfo, subjectId) => {\n if (subjectInfo.childModels.size > 0) {\n parentSubjectIds.add(subjectId);\n let currParentId = subjectInfo.parentSubject;\n while (currParentId) {\n parentSubjectIds.add(currParentId);\n currParentId = subjectInfos.get(currParentId)?.parentSubject;\n }\n }\n });\n return [...parentSubjectIds];\n })();\n return this.#parentSubjectIds;\n }\n\n /**\n * Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into\n * account `hideInHierarchy` flag.\n */\n public async getChildSubjectIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const childSubjectIds = new Array<Id64String>();\n const subjectInfos = await this.getSubjectInfos();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (!childSubjectInfo.hideInHierarchy) {\n childSubjectIds.push(childSubjectId);\n return \"break\";\n }\n return \"continue\";\n });\n });\n return childSubjectIds;\n }\n\n /** Returns ECInstanceIDs of all Models under specific parent Subjects, including their child Subjects, etc. */\n public async getSubjectModelIds(subjectIds: Id64Array): Promise<Id64Array> {\n const subjectInfos = await this.getSubjectInfos();\n const subjectStack = [...subjectIds];\n const result = new Array<Id64String>();\n while (true) {\n const subjectId = subjectStack.pop();\n if (subjectId === undefined) {\n break;\n }\n const subjectInfo = subjectInfos.get(subjectId);\n if (!subjectInfo) {\n continue;\n }\n result.push(...subjectInfo.childModels);\n subjectStack.push(...subjectInfo.childSubjects);\n }\n return result;\n }\n\n /** Returns ECInstanceIDs of Models under specific parent Subjects as they are displayed in the hierarchy. */\n public async getChildSubjectModelIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const subjectInfos = await this.getSubjectInfos();\n\n const hiddenSubjectIds = new Array<Id64String>();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (childSubjectInfo.hideInHierarchy) {\n hiddenSubjectIds.push(childSubjectId);\n return \"continue\";\n }\n return \"break\";\n });\n });\n\n const modelIds = new Array<Id64String>();\n [...parentSubjectIds, ...hiddenSubjectIds].forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n subjectInfo && modelIds.push(...subjectInfo.childModels);\n });\n return modelIds;\n }\n\n public async createSubjectInstanceKeysPath(targetSubjectId: Id64String): Promise<HierarchyNodeIdentifiersPath> {\n let entry = this.#subjectKeyPaths.get(targetSubjectId);\n if (!entry) {\n entry = (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const result = new Array<InstanceKey>();\n let currParentId: Id64String | undefined = targetSubjectId;\n while (currParentId) {\n if (this.#hierarchyConfig.hideRootSubject && currParentId === IModel.rootSubjectId) {\n break;\n }\n const parentInfo = subjectInfos.get(currParentId);\n if (!parentInfo?.hideInHierarchy) {\n result.push({ className: \"BisCore.Subject\", id: currParentId });\n }\n currParentId = parentInfo?.parentSubject;\n }\n return result.reverse();\n })();\n this.#subjectKeyPaths.set(targetSubjectId, entry);\n }\n return entry;\n }\n\n private async *queryModelCategories(): AsyncIterableIterator<{\n modelId: Id64String;\n categoryId: Id64String;\n isModelPrivate: boolean;\n isRootElementCategory: boolean;\n }> {\n const query = `\n SELECT\n this.Model.Id modelId,\n this.Category.Id categoryId,\n m.IsPrivate isModelPrivate,\n MAX(IIF(this.Parent.Id IS NULL, 1, 0)) isRootElementCategory\n FROM BisCore.Model m\n JOIN ${this.#hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id\n GROUP BY modelId, categoryId, isModelPrivate\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: query },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/model-categories` },\n )) {\n yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate, isRootElementCategory: !!row.isRootElementCategory };\n }\n }\n\n private async *queryModeledElements() {\n const query = `\n SELECT\n pe.ECInstanceId modeledElementId,\n pe.Category.Id categoryId,\n pe.Model.Id modelId\n FROM BisCore.Model m\n JOIN ${this.#hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id\n WHERE\n m.IsPrivate = false\n AND m.ECInstanceId IN (SELECT Model.Id FROM ${this.#hierarchyConfig.elementClassSpecification})\n `;\n for await (const row of this.#queryExecutor.createQueryReader(\n { ecsql: query },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/modeled-elements` },\n )) {\n yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };\n }\n }\n\n private async getModelWithCategoryModeledElements() {\n this.#modelWithCategoryModeledElements ??= (async () => {\n const modelWithCategoryModeledElements = new Map<Id64String, Id64Set>();\n for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {\n const key = `${modelId}-${categoryId}`;\n const entry = modelWithCategoryModeledElements.get(key);\n if (entry === undefined) {\n modelWithCategoryModeledElements.set(key, new Set([modeledElementId]));\n } else {\n entry.add(modeledElementId);\n }\n }\n return modelWithCategoryModeledElements;\n })();\n return this.#modelWithCategoryModeledElements;\n }\n\n private async getModelInfos() {\n this.#modelInfos ??= (async () => {\n const modelInfos = new Map<Id64String, { categories: Map<Id64String, { isRootElementCategory: boolean }>; isModelPrivate: boolean }>();\n for await (const { modelId, categoryId, isModelPrivate, isRootElementCategory } of this.queryModelCategories()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.categories.set(categoryId, { isRootElementCategory });\n entry.isModelPrivate = isModelPrivate;\n } else {\n modelInfos.set(modelId, { categories: new Map([[categoryId, { isRootElementCategory }]]), isModelPrivate });\n }\n }\n return modelInfos;\n })();\n return this.#modelInfos;\n }\n\n public async getAllCategories(): Promise<Id64Set> {\n const modelInfos = await this.getModelInfos();\n const result = new Set<Id64String>();\n modelInfos.forEach(({ categories }) => {\n categories.forEach((_, categoryId) => result.add(categoryId));\n });\n return result;\n }\n\n public async getModelCategories(modelId: Id64String): Promise<Id64Array> {\n const modelInfos = await this.getModelInfos();\n const categories = modelInfos.get(modelId)?.categories.keys();\n return categories ? [...categories] : [];\n }\n\n public async hasSubModel(elementId: Id64String): Promise<boolean> {\n const modelInfos = await this.getModelInfos();\n const modeledElementInfo = modelInfos.get(elementId);\n if (!modeledElementInfo) {\n return false;\n }\n return !modeledElementInfo.isModelPrivate;\n }\n\n public async getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Arg): Promise<Id64Array> {\n const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();\n const result = new Array<Id64String>();\n for (const categoryId of Id64.iterable(categoryIds)) {\n const entry = modelWithCategoryModeledElements.get(`${modelId}-${categoryId}`);\n if (entry !== undefined) {\n result.push(...entry);\n }\n }\n return result;\n }\n\n public async createModelInstanceKeyPaths(modelId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this.#modelKeyPaths.get(modelId);\n if (!entry) {\n entry = (async () => {\n const result = new Array<HierarchyNodeIdentifiersPath>();\n const subjectInfos = (await this.getSubjectInfos()).entries();\n for (const [modelSubjectId, subjectInfo] of subjectInfos) {\n if (subjectInfo.childModels.has(modelId)) {\n const subjectPath = await this.createSubjectInstanceKeysPath(modelSubjectId);\n result.push([...subjectPath, { className: \"BisCore.GeometricModel3d\", id: modelId }]);\n }\n }\n return result;\n })();\n\n this.#modelKeyPaths.set(modelId, entry);\n }\n return entry;\n }\n\n private async queryCategoryElementCounts(\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ): Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>> {\n return collect(\n from(input).pipe(\n reduce((acc, { modelId, categoryId }) => {\n const entry = acc.get(modelId);\n if (!entry) {\n acc.set(modelId, new Set([categoryId]));\n } else {\n entry.add(categoryId);\n }\n return acc;\n }, new Map<Id64String, Id64Set>()),\n mergeMap((modelCategoryMap) => modelCategoryMap.entries()),\n map(([modelId, categoryIds]) => `Model.Id = ${modelId} AND Category.Id IN (${[...categoryIds].join(\", \")})`),\n // we may have thousands of where clauses here, and sending a single query with all of them could take a\n // long time - instead, split it into smaller chunks\n bufferCount(100),\n mergeMap(async (whereClauses) => {\n const reader = this.#queryExecutor.createQueryReader(\n {\n ctes: [\n `\n CategoryElements(id, modelId, categoryId) AS (\n SELECT ECInstanceId, Model.Id, Category.Id\n FROM ${this.#hierarchyConfig.elementClassSpecification}\n WHERE\n Parent.Id IS NULL\n AND (\n ${whereClauses.join(\" OR \")}\n )\n\n UNION ALL\n\n SELECT c.ECInstanceId, p.modelId, p.categoryId\n FROM ${this.#hierarchyConfig.elementClassSpecification} c\n JOIN CategoryElements p ON c.Parent.Id = p.id\n )\n `,\n ],\n ecsql: `\n SELECT modelId, categoryId, COUNT(id) elementsCount\n FROM CategoryElements\n GROUP BY modelId, categoryId\n `,\n },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: `${this.#componentName}/${this.#componentId}/category-element-counts` },\n );\n\n const result = new Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>();\n for await (const row of reader) {\n result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });\n }\n\n input.forEach(({ modelId, categoryId }) => {\n if (!result.some((queriedResult) => queriedResult.categoryId === categoryId && queriedResult.modelId === modelId)) {\n result.push({ categoryId, modelId, elementsCount: 0 });\n }\n });\n\n return result;\n }),\n mergeAll(),\n ),\n );\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n return this.#categoryElementCounts.getCategoryElementsCount(modelId, categoryId);\n }\n\n public async createCategoryInstanceKeyPaths(categoryId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this.#categoryKeyPaths.get(categoryId);\n if (!entry) {\n entry = (async () => {\n const result = new Set<Id64String>();\n const modelInfos = await this.getModelInfos();\n modelInfos?.forEach((modelInfo, modelId) => {\n const categoryEntry = modelInfo.categories.get(categoryId);\n if (categoryEntry?.isRootElementCategory) {\n result.add(modelId);\n }\n });\n\n const categoryPaths = new Array<HierarchyNodeIdentifiersPath>();\n for (const categoryModelId of [...result]) {\n const modelPaths = await this.createModelInstanceKeyPaths(categoryModelId);\n for (const modelPath of modelPaths) {\n categoryPaths.push([...modelPath, { className: \"BisCore.SpatialCategory\", id: categoryId }]);\n }\n }\n return categoryPaths;\n })();\n this.#categoryKeyPaths.set(categoryId, entry);\n }\n return entry;\n }\n}\n\nfunction forEachChildSubject(\n subjectInfos: Map<Id64String, SubjectInfo>,\n parentSubject: Id64String | SubjectInfo,\n cb: (childSubjectId: Id64String, childSubjectInfo: SubjectInfo) => \"break\" | \"continue\",\n) {\n const parentSubjectInfo = typeof parentSubject === \"string\" ? subjectInfos.get(parentSubject) : parentSubject;\n parentSubjectInfo &&\n parentSubjectInfo.childSubjects.forEach((childSubjectId) => {\n const childSubjectInfo = subjectInfos.get(childSubjectId)!;\n if (cb(childSubjectId, childSubjectInfo) === \"break\") {\n return;\n }\n forEachChildSubject(subjectInfos, childSubjectInfo, cb);\n });\n}\n\nclass ModelCategoryElementsCountCache {\n #cache = new Map<string, Subject<number>>();\n #requestsStream = new Subject<{ modelId: Id64String; categoryId: Id64String }>();\n #subscription: Subscription;\n public constructor(\n loader: (\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ) => Promise<Array<{ modelId: Id64String; categoryId: Id64String; elementsCount: number }>>,\n ) {\n this.#subscription = this.#requestsStream\n .pipe(\n bufferTime(20),\n filter((requests) => requests.length > 0),\n mergeMap(async (requests) => loader(requests)),\n mergeAll(),\n )\n .subscribe({\n next: ({ modelId, categoryId, elementsCount }) => {\n const subject = this.#cache.get(`${modelId}${categoryId}`);\n assert(!!subject);\n subject.next(elementsCount);\n },\n });\n }\n\n public [Symbol.dispose]() {\n this.#subscription.unsubscribe();\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n const cacheKey = `${modelId}${categoryId}`;\n let result = this.#cache.get(cacheKey);\n if (result !== undefined) {\n return firstValueFrom(result);\n }\n\n result = new ReplaySubject(1);\n this.#cache.set(cacheKey, result);\n this.#requestsStream.next({ modelId, categoryId });\n return firstValueFrom(result);\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Id64Arg, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
1
|
+
import type { GuidString, Id64Arg, Id64Array, Id64Set, Id64String } from "@itwin/core-bentley";
|
|
2
2
|
import type { Viewport } from "@itwin/core-frontend";
|
|
3
3
|
import type { GroupingHierarchyNode, HierarchyFilteringPath } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import type { ECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
@@ -70,6 +70,7 @@ export interface ModelsTreeVisibilityHandlerProps {
|
|
|
70
70
|
imodelAccess: ECClassHierarchyInspector;
|
|
71
71
|
overrides?: ModelsTreeVisibilityHandlerOverrides;
|
|
72
72
|
filteredPaths?: HierarchyFilteringPath[];
|
|
73
|
+
componentId?: GuidString;
|
|
73
74
|
}
|
|
74
75
|
/**
|
|
75
76
|
* Creates an instance if `ModelsTreeVisibilityHandler`.
|
|
@@ -79,9 +80,12 @@ export declare function createModelsTreeVisibilityHandler(props: ModelsTreeVisib
|
|
|
79
80
|
/**
|
|
80
81
|
* Enables display of all given models. Also enables display of all categories and clears always and
|
|
81
82
|
* never drawn lists in the viewport.
|
|
83
|
+
*
|
|
84
|
+
* @param componentId Optional unique id of the component that consumes this function.
|
|
85
|
+
* It can be any string, as long as it is not shared across different components.
|
|
82
86
|
* @public
|
|
83
87
|
*/
|
|
84
|
-
export declare function showAllModels(models: string[], viewport: Viewport): Promise<void>;
|
|
88
|
+
export declare function showAllModels(models: string[], viewport: Viewport, componentId?: GuidString): Promise<void>;
|
|
85
89
|
/**
|
|
86
90
|
* Disables display of all given models.
|
|
87
91
|
* @public
|