@itwin/presentation-backend 4.0.0-dev.8 → 4.0.0-dev.81

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +47 -1
  2. package/lib/cjs/assets/primary-presentation-rules/ElementProperties.PresentationRuleSet.json +14 -14
  3. package/lib/cjs/assets/supplemental-presentation-rules/BisCore.PresentationRuleSet.json +726 -762
  4. package/lib/cjs/assets/supplemental-presentation-rules/Functional.PresentationRuleSet.json +139 -139
  5. package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts +41 -41
  6. package/lib/cjs/presentation-backend/BackendLoggerCategory.js +50 -50
  7. package/lib/cjs/presentation-backend/BackendLoggerCategory.js.map +1 -1
  8. package/lib/cjs/presentation-backend/Constants.d.ts +8 -8
  9. package/lib/cjs/presentation-backend/Constants.js +40 -36
  10. package/lib/cjs/presentation-backend/Constants.js.map +1 -1
  11. package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +11 -11
  12. package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +272 -274
  13. package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -1
  14. package/lib/cjs/presentation-backend/NativePlatform.d.ts +87 -87
  15. package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -1
  16. package/lib/cjs/presentation-backend/NativePlatform.js +147 -140
  17. package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
  18. package/lib/cjs/presentation-backend/Presentation.d.ts +106 -106
  19. package/lib/cjs/presentation-backend/Presentation.d.ts.map +1 -1
  20. package/lib/cjs/presentation-backend/Presentation.js +148 -150
  21. package/lib/cjs/presentation-backend/Presentation.js.map +1 -1
  22. package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts +11 -12
  23. package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts.map +1 -1
  24. package/lib/cjs/presentation-backend/PresentationIpcHandler.js +30 -41
  25. package/lib/cjs/presentation-backend/PresentationIpcHandler.js.map +1 -1
  26. package/lib/cjs/presentation-backend/PresentationManager.d.ts +463 -445
  27. package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -1
  28. package/lib/cjs/presentation-backend/PresentationManager.js +317 -311
  29. package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
  30. package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts +61 -61
  31. package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts.map +1 -1
  32. package/lib/cjs/presentation-backend/PresentationManagerDetail.js +442 -430
  33. package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -1
  34. package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +62 -62
  35. package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -1
  36. package/lib/cjs/presentation-backend/PresentationRpcImpl.js +388 -388
  37. package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
  38. package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts +102 -102
  39. package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts.map +1 -1
  40. package/lib/cjs/presentation-backend/RulesetEmbedder.js +287 -282
  41. package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -1
  42. package/lib/cjs/presentation-backend/RulesetManager.d.ts +53 -53
  43. package/lib/cjs/presentation-backend/RulesetManager.js +73 -73
  44. package/lib/cjs/presentation-backend/RulesetManager.js.map +1 -1
  45. package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts +140 -140
  46. package/lib/cjs/presentation-backend/RulesetVariablesManager.js +129 -129
  47. package/lib/cjs/presentation-backend/RulesetVariablesManager.js.map +1 -1
  48. package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +28 -28
  49. package/lib/cjs/presentation-backend/SelectionScopesHelper.js +226 -229
  50. package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -1
  51. package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +123 -123
  52. package/lib/cjs/presentation-backend/TemporaryStorage.js +151 -151
  53. package/lib/cjs/presentation-backend/TemporaryStorage.js.map +1 -1
  54. package/lib/cjs/presentation-backend/UpdatesTracker.d.ts +27 -27
  55. package/lib/cjs/presentation-backend/UpdatesTracker.js +54 -54
  56. package/lib/cjs/presentation-backend/UpdatesTracker.js.map +1 -1
  57. package/lib/cjs/presentation-backend/Utils.d.ts +49 -49
  58. package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -1
  59. package/lib/cjs/presentation-backend/Utils.js +107 -106
  60. package/lib/cjs/presentation-backend/Utils.js.map +1 -1
  61. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts +16 -16
  62. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js +55 -51
  63. package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js.map +1 -1
  64. package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts +21 -21
  65. package/lib/cjs/presentation-backend/domain/RulesetElements.js +38 -38
  66. package/lib/cjs/presentation-backend/domain/RulesetElements.js.map +1 -1
  67. package/lib/cjs/presentation-backend.d.ts +19 -19
  68. package/lib/cjs/presentation-backend.js +39 -35
  69. package/lib/cjs/presentation-backend.js.map +1 -1
  70. package/package.json +20 -18
@@ -1,29 +1,29 @@
1
- /** @packageDocumentation
2
- * @module Core
3
- */
4
- import { IModelDb } from "@itwin/core-backend";
5
- import { Id64String } from "@itwin/core-bentley";
6
- import { ComputeSelectionRequestOptions, KeySet, SelectionScope, SelectionScopeRequestOptions } from "@itwin/presentation-common";
7
- /**
8
- * Contains helper methods for computing selection scopes. Will get removed
9
- * once rules-driven scopes are implemented.
10
- *
11
- * @internal
12
- */
13
- export declare class SelectionScopesHelper {
14
- private constructor();
15
- static getSelectionScopes(): SelectionScope[];
16
- private static getElementKey;
17
- private static computeElementSelection;
18
- private static computeCategorySelection;
19
- private static computeModelSelection;
20
- private static getRelatedFunctionalElementKey;
21
- private static findFirstRelatedFunctionalElementKey;
22
- private static elementClassDerivesFrom;
23
- private static computeFunctionalElementSelection;
24
- private static computeFunctionalAssemblySelection;
25
- private static computeFunctionalTopAssemblySelection;
26
- static computeSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[], scopeId: string): Promise<KeySet>;
27
- static computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb>): Promise<KeySet>;
28
- }
1
+ /** @packageDocumentation
2
+ * @module Core
3
+ */
4
+ import { IModelDb } from "@itwin/core-backend";
5
+ import { Id64String } from "@itwin/core-bentley";
6
+ import { ComputeSelectionRequestOptions, KeySet, SelectionScope, SelectionScopeRequestOptions } from "@itwin/presentation-common";
7
+ /**
8
+ * Contains helper methods for computing selection scopes. Will get removed
9
+ * once rules-driven scopes are implemented.
10
+ *
11
+ * @internal
12
+ */
13
+ export declare class SelectionScopesHelper {
14
+ private constructor();
15
+ static getSelectionScopes(): SelectionScope[];
16
+ private static getElementKey;
17
+ private static computeElementSelection;
18
+ private static computeCategorySelection;
19
+ private static computeModelSelection;
20
+ private static getRelatedFunctionalElementKey;
21
+ private static findFirstRelatedFunctionalElementKey;
22
+ private static elementClassDerivesFrom;
23
+ private static computeFunctionalElementSelection;
24
+ private static computeFunctionalAssemblySelection;
25
+ private static computeFunctionalTopAssemblySelection;
26
+ static computeSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[], scopeId: string): Promise<KeySet>;
27
+ static computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb>): Promise<KeySet>;
28
+ }
29
29
  //# sourceMappingURL=SelectionScopesHelper.d.ts.map
@@ -1,230 +1,227 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- /** @packageDocumentation
7
- * @module Core
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.SelectionScopesHelper = void 0;
11
- const core_backend_1 = require("@itwin/core-backend");
12
- const core_bentley_1 = require("@itwin/core-bentley");
13
- const presentation_common_1 = require("@itwin/presentation-common");
14
- const Utils_1 = require("./Utils");
15
- /**
16
- * Contains helper methods for computing selection scopes. Will get removed
17
- * once rules-driven scopes are implemented.
18
- *
19
- * @internal
20
- */
21
- class SelectionScopesHelper {
22
- // istanbul ignore next
23
- constructor() { }
24
- static getSelectionScopes() {
25
- const createSelectionScope = (scopeId, label, description) => ({
26
- id: scopeId,
27
- label,
28
- description,
29
- });
30
- return [
31
- createSelectionScope("element", "Element", "Select the picked element"),
32
- createSelectionScope("assembly", "Assembly", "Select parent of the picked element"),
33
- createSelectionScope("top-assembly", "Top Assembly", "Select the topmost parent of the picked element"),
34
- // WIP: temporarily comment-out "category" and "model" scopes since we can't hilite contents of them fast enough
35
- // createSelectionScope("category", "Category", "Select all elements in the picked element's category"),
36
- // createSelectionScope("model", "Model", "Select all elements in the picked element's model"),
37
- ];
38
- }
39
- static getElementKey(iModel, elementId, ancestorLevel) {
40
- var _a, _b, _c, _d;
41
- let currId = elementId;
42
- let parentId = (_b = (_a = iModel.elements.tryGetElementProps(currId)) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id;
43
- while (parentId && ancestorLevel !== 0) {
44
- currId = parentId;
45
- parentId = (_d = (_c = iModel.elements.tryGetElementProps(currId)) === null || _c === void 0 ? void 0 : _c.parent) === null || _d === void 0 ? void 0 : _d.id;
46
- --ancestorLevel;
47
- }
48
- return (0, Utils_1.getElementKey)(iModel, currId);
49
- }
50
- static computeElementSelection(iModel, elementIds, ancestorLevel) {
51
- const parentKeys = new presentation_common_1.KeySet();
52
- elementIds.forEach(skipTransients((id) => {
53
- const key = this.getElementKey(iModel, id, ancestorLevel);
54
- key && parentKeys.add(key);
55
- }));
56
- return parentKeys;
57
- }
58
- static computeCategorySelection(iModel, ids) {
59
- const categoryKeys = new presentation_common_1.KeySet();
60
- ids.forEach(skipTransients((id) => {
61
- const el = iModel.elements.tryGetElement(id);
62
- if (el instanceof core_backend_1.GeometricElement) {
63
- const category = iModel.elements.tryGetElementProps(el.category);
64
- if (category)
65
- categoryKeys.add({ className: category.classFullName, id: category.id });
66
- }
67
- }));
68
- return categoryKeys;
69
- }
70
- static computeModelSelection(iModel, ids) {
71
- const modelKeys = new presentation_common_1.KeySet();
72
- ids.forEach(skipTransients((id) => {
73
- const el = iModel.elements.tryGetElementProps(id);
74
- const model = el ? iModel.models.tryGetModelProps(el.model) : undefined;
75
- if (model)
76
- modelKeys.add({ className: model.classFullName, id: model.id });
77
- }));
78
- return modelKeys;
79
- }
80
- static getRelatedFunctionalElementKey(imodel, graphicalElementId) {
81
- const query = `
82
- SELECT funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId
83
- FROM bis.Element e
84
- LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId
85
- LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId
86
- LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)
87
- INNER JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId
88
- INNER JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id
89
- WHERE e.ECInstanceId = ?
90
- `;
91
- return imodel.withPreparedStatement(query, (stmt) => {
92
- stmt.bindId(1, graphicalElementId);
93
- // istanbul ignore else
94
- if (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step()) {
95
- const row = stmt.getRow();
96
- if (row.funcElClassName && row.funcElId)
97
- return { className: row.funcElClassName.replace(".", ":"), id: row.funcElId };
98
- }
99
- return undefined;
100
- });
101
- }
102
- static findFirstRelatedFunctionalElementKey(imodel, graphicalElementId) {
103
- var _a, _b;
104
- let currId = graphicalElementId;
105
- while (currId) {
106
- const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);
107
- if (relatedFunctionalKey)
108
- return relatedFunctionalKey;
109
- currId = (_b = (_a = imodel.elements.tryGetElementProps(currId)) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id;
110
- }
111
- return undefined;
112
- }
113
- static elementClassDerivesFrom(imodel, elementId, baseClassFullName) {
114
- const query = `
115
- SELECT 1
116
- FROM bis.Element e
117
- INNER JOIN meta.ClassHasAllBaseClasses baseClassRels ON baseClassRels.SourceECInstanceId = e.ECClassId
118
- INNER JOIN meta.ECClassDef baseClass ON baseClass.ECInstanceId = baseClassRels.TargetECInstanceId
119
- INNER JOIN meta.ECSchemaDef baseSchema ON baseSchema.ECInstanceId = baseClass.Schema.Id
120
- WHERE e.ECInstanceId = ? AND (baseSchema.Name || ':' || baseClass.Name) = ?
121
- `;
122
- return imodel.withPreparedStatement(query, (stmt) => {
123
- stmt.bindId(1, elementId);
124
- stmt.bindString(2, baseClassFullName);
125
- return (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step());
126
- });
127
- }
128
- static computeFunctionalElementSelection(iModel, ids) {
129
- const keys = new presentation_common_1.KeySet();
130
- ids.forEach(skipTransients((id) => {
131
- const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
132
- if (!is3d) {
133
- // if the input is not a 3d element, we try to find the first related functional element
134
- const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
135
- if (firstFunctionalKey) {
136
- keys.add(firstFunctionalKey);
137
- return;
138
- }
139
- }
140
- let keyToAdd;
141
- if (is3d) {
142
- // if we're computing scope for a 3d element, try to switch to its related functional element
143
- keyToAdd = this.getRelatedFunctionalElementKey(iModel, id);
144
- }
145
- if (!keyToAdd)
146
- keyToAdd = (0, Utils_1.getElementKey)(iModel, id);
147
- keyToAdd && keys.add(keyToAdd);
148
- }));
149
- return keys;
150
- }
151
- static computeFunctionalAssemblySelection(iModel, ids) {
152
- const keys = new presentation_common_1.KeySet();
153
- ids.forEach(skipTransients((id) => {
154
- let idToGetAssemblyFor = id;
155
- const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
156
- if (!is3d) {
157
- // if the input is not a 3d element, we try to find the first related functional element
158
- const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
159
- if (firstFunctionalKey)
160
- idToGetAssemblyFor = firstFunctionalKey.id;
161
- }
162
- // find the assembly of either the given element or the functional element
163
- const assemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, 1);
164
- let keyToAdd = assemblyKey;
165
- if (is3d && keyToAdd) {
166
- // if we're computing scope for a 3d element, try to switch to its related functional element
167
- const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);
168
- if (relatedFunctionalKey)
169
- keyToAdd = relatedFunctionalKey;
170
- }
171
- keyToAdd && keys.add(keyToAdd);
172
- }));
173
- return keys;
174
- }
175
- static computeFunctionalTopAssemblySelection(iModel, ids) {
176
- const keys = new presentation_common_1.KeySet();
177
- ids.forEach(skipTransients((id) => {
178
- let idToGetAssemblyFor = id;
179
- const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
180
- if (!is3d) {
181
- // if the input is not a 3d element, we try to find the first related functional element
182
- const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
183
- if (firstFunctionalKey)
184
- idToGetAssemblyFor = firstFunctionalKey.id;
185
- }
186
- // find the top assembly of either the given element or the functional element
187
- const topAssemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, Number.MAX_SAFE_INTEGER);
188
- let keyToAdd = topAssemblyKey;
189
- if (is3d && keyToAdd) {
190
- // if we're computing scope for a 3d element, try to switch to its related functional element
191
- const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);
192
- if (relatedFunctionalKey)
193
- keyToAdd = relatedFunctionalKey;
194
- }
195
- keyToAdd && keys.add(keyToAdd);
196
- }));
197
- return keys;
198
- }
199
- static async computeSelection(requestOptions, elementIds, scopeId) {
200
- var _a;
201
- if (!(0, presentation_common_1.isComputeSelectionRequestOptions)(requestOptions)) {
202
- return this.computeSelection({
203
- ...requestOptions,
204
- elementIds: elementIds,
205
- scope: { id: scopeId },
206
- });
207
- }
208
- switch (requestOptions.scope.id) {
209
- case "element": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, (_a = requestOptions.scope.ancestorLevel) !== null && _a !== void 0 ? _a : 0);
210
- case "assembly": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, 1);
211
- case "top-assembly": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, Number.MAX_SAFE_INTEGER);
212
- case "category": return this.computeCategorySelection(requestOptions.imodel, requestOptions.elementIds);
213
- case "model": return this.computeModelSelection(requestOptions.imodel, requestOptions.elementIds);
214
- case "functional":
215
- case "functional-element":
216
- return this.computeFunctionalElementSelection(requestOptions.imodel, requestOptions.elementIds);
217
- case "functional-assembly": return this.computeFunctionalAssemblySelection(requestOptions.imodel, requestOptions.elementIds);
218
- case "functional-top-assembly": return this.computeFunctionalTopAssemblySelection(requestOptions.imodel, requestOptions.elementIds);
219
- }
220
- throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "scopeId");
221
- }
222
- }
223
- exports.SelectionScopesHelper = SelectionScopesHelper;
224
- const skipTransients = (callback) => {
225
- return (id) => {
226
- if (!core_bentley_1.Id64.isTransient(id))
227
- callback(id);
228
- };
229
- };
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ /** @packageDocumentation
7
+ * @module Core
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SelectionScopesHelper = void 0;
11
+ const core_backend_1 = require("@itwin/core-backend");
12
+ const core_bentley_1 = require("@itwin/core-bentley");
13
+ const presentation_common_1 = require("@itwin/presentation-common");
14
+ const Utils_1 = require("./Utils");
15
+ /**
16
+ * Contains helper methods for computing selection scopes. Will get removed
17
+ * once rules-driven scopes are implemented.
18
+ *
19
+ * @internal
20
+ */
21
+ class SelectionScopesHelper {
22
+ // istanbul ignore next
23
+ constructor() { }
24
+ static getSelectionScopes() {
25
+ const createSelectionScope = (scopeId, label, description) => ({
26
+ id: scopeId,
27
+ label,
28
+ description,
29
+ });
30
+ return [
31
+ createSelectionScope("element", "Element", "Select the picked element"),
32
+ createSelectionScope("assembly", "Assembly", "Select parent of the picked element"),
33
+ createSelectionScope("top-assembly", "Top Assembly", "Select the topmost parent of the picked element"),
34
+ // WIP: temporarily comment-out "category" and "model" scopes since we can't hilite contents of them fast enough
35
+ // createSelectionScope("category", "Category", "Select all elements in the picked element's category"),
36
+ // createSelectionScope("model", "Model", "Select all elements in the picked element's model"),
37
+ ];
38
+ }
39
+ static getElementKey(iModel, elementId, ancestorLevel) {
40
+ let currId = elementId;
41
+ let parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;
42
+ while (parentId && ancestorLevel !== 0) {
43
+ currId = parentId;
44
+ parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;
45
+ --ancestorLevel;
46
+ }
47
+ return (0, Utils_1.getElementKey)(iModel, currId);
48
+ }
49
+ static computeElementSelection(iModel, elementIds, ancestorLevel) {
50
+ const parentKeys = new presentation_common_1.KeySet();
51
+ elementIds.forEach(skipTransients((id) => {
52
+ const key = this.getElementKey(iModel, id, ancestorLevel);
53
+ key && parentKeys.add(key);
54
+ }));
55
+ return parentKeys;
56
+ }
57
+ static computeCategorySelection(iModel, ids) {
58
+ const categoryKeys = new presentation_common_1.KeySet();
59
+ ids.forEach(skipTransients((id) => {
60
+ const el = iModel.elements.tryGetElement(id);
61
+ if (el instanceof core_backend_1.GeometricElement) {
62
+ const category = iModel.elements.tryGetElementProps(el.category);
63
+ if (category)
64
+ categoryKeys.add({ className: category.classFullName, id: category.id });
65
+ }
66
+ }));
67
+ return categoryKeys;
68
+ }
69
+ static computeModelSelection(iModel, ids) {
70
+ const modelKeys = new presentation_common_1.KeySet();
71
+ ids.forEach(skipTransients((id) => {
72
+ const el = iModel.elements.tryGetElementProps(id);
73
+ const model = el ? iModel.models.tryGetModelProps(el.model) : undefined;
74
+ if (model)
75
+ modelKeys.add({ className: model.classFullName, id: model.id });
76
+ }));
77
+ return modelKeys;
78
+ }
79
+ static getRelatedFunctionalElementKey(imodel, graphicalElementId) {
80
+ const query = `
81
+ SELECT funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId
82
+ FROM bis.Element e
83
+ LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId
84
+ LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId
85
+ LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)
86
+ INNER JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId
87
+ INNER JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id
88
+ WHERE e.ECInstanceId = ?
89
+ `;
90
+ return imodel.withPreparedStatement(query, (stmt) => {
91
+ stmt.bindId(1, graphicalElementId);
92
+ // istanbul ignore else
93
+ if (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step()) {
94
+ const row = stmt.getRow();
95
+ if (row.funcElClassName && row.funcElId)
96
+ return { className: row.funcElClassName.replace(".", ":"), id: row.funcElId };
97
+ }
98
+ return undefined;
99
+ });
100
+ }
101
+ static findFirstRelatedFunctionalElementKey(imodel, graphicalElementId) {
102
+ let currId = graphicalElementId;
103
+ while (currId) {
104
+ const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);
105
+ if (relatedFunctionalKey)
106
+ return relatedFunctionalKey;
107
+ currId = imodel.elements.tryGetElementProps(currId)?.parent?.id;
108
+ }
109
+ return undefined;
110
+ }
111
+ static elementClassDerivesFrom(imodel, elementId, baseClassFullName) {
112
+ const query = `
113
+ SELECT 1
114
+ FROM bis.Element e
115
+ INNER JOIN meta.ClassHasAllBaseClasses baseClassRels ON baseClassRels.SourceECInstanceId = e.ECClassId
116
+ INNER JOIN meta.ECClassDef baseClass ON baseClass.ECInstanceId = baseClassRels.TargetECInstanceId
117
+ INNER JOIN meta.ECSchemaDef baseSchema ON baseSchema.ECInstanceId = baseClass.Schema.Id
118
+ WHERE e.ECInstanceId = ? AND (baseSchema.Name || ':' || baseClass.Name) = ?
119
+ `;
120
+ return imodel.withPreparedStatement(query, (stmt) => {
121
+ stmt.bindId(1, elementId);
122
+ stmt.bindString(2, baseClassFullName);
123
+ return (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step());
124
+ });
125
+ }
126
+ static computeFunctionalElementSelection(iModel, ids) {
127
+ const keys = new presentation_common_1.KeySet();
128
+ ids.forEach(skipTransients((id) => {
129
+ const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
130
+ if (!is3d) {
131
+ // if the input is not a 3d element, we try to find the first related functional element
132
+ const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
133
+ if (firstFunctionalKey) {
134
+ keys.add(firstFunctionalKey);
135
+ return;
136
+ }
137
+ }
138
+ let keyToAdd;
139
+ if (is3d) {
140
+ // if we're computing scope for a 3d element, try to switch to its related functional element
141
+ keyToAdd = this.getRelatedFunctionalElementKey(iModel, id);
142
+ }
143
+ if (!keyToAdd)
144
+ keyToAdd = (0, Utils_1.getElementKey)(iModel, id);
145
+ keyToAdd && keys.add(keyToAdd);
146
+ }));
147
+ return keys;
148
+ }
149
+ static computeFunctionalAssemblySelection(iModel, ids) {
150
+ const keys = new presentation_common_1.KeySet();
151
+ ids.forEach(skipTransients((id) => {
152
+ let idToGetAssemblyFor = id;
153
+ const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
154
+ if (!is3d) {
155
+ // if the input is not a 3d element, we try to find the first related functional element
156
+ const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
157
+ if (firstFunctionalKey)
158
+ idToGetAssemblyFor = firstFunctionalKey.id;
159
+ }
160
+ // find the assembly of either the given element or the functional element
161
+ const assemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, 1);
162
+ let keyToAdd = assemblyKey;
163
+ if (is3d && keyToAdd) {
164
+ // if we're computing scope for a 3d element, try to switch to its related functional element
165
+ const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);
166
+ if (relatedFunctionalKey)
167
+ keyToAdd = relatedFunctionalKey;
168
+ }
169
+ keyToAdd && keys.add(keyToAdd);
170
+ }));
171
+ return keys;
172
+ }
173
+ static computeFunctionalTopAssemblySelection(iModel, ids) {
174
+ const keys = new presentation_common_1.KeySet();
175
+ ids.forEach(skipTransients((id) => {
176
+ let idToGetAssemblyFor = id;
177
+ const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
178
+ if (!is3d) {
179
+ // if the input is not a 3d element, we try to find the first related functional element
180
+ const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
181
+ if (firstFunctionalKey)
182
+ idToGetAssemblyFor = firstFunctionalKey.id;
183
+ }
184
+ // find the top assembly of either the given element or the functional element
185
+ const topAssemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, Number.MAX_SAFE_INTEGER);
186
+ let keyToAdd = topAssemblyKey;
187
+ if (is3d && keyToAdd) {
188
+ // if we're computing scope for a 3d element, try to switch to its related functional element
189
+ const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);
190
+ if (relatedFunctionalKey)
191
+ keyToAdd = relatedFunctionalKey;
192
+ }
193
+ keyToAdd && keys.add(keyToAdd);
194
+ }));
195
+ return keys;
196
+ }
197
+ static async computeSelection(requestOptions, elementIds, scopeId) {
198
+ if (!(0, presentation_common_1.isComputeSelectionRequestOptions)(requestOptions)) {
199
+ return this.computeSelection({
200
+ ...requestOptions,
201
+ elementIds: elementIds,
202
+ scope: { id: scopeId },
203
+ });
204
+ }
205
+ switch (requestOptions.scope.id) {
206
+ case "element": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, requestOptions.scope.ancestorLevel ?? 0);
207
+ case "assembly": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, 1);
208
+ case "top-assembly": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, Number.MAX_SAFE_INTEGER);
209
+ case "category": return this.computeCategorySelection(requestOptions.imodel, requestOptions.elementIds);
210
+ case "model": return this.computeModelSelection(requestOptions.imodel, requestOptions.elementIds);
211
+ case "functional":
212
+ case "functional-element":
213
+ return this.computeFunctionalElementSelection(requestOptions.imodel, requestOptions.elementIds);
214
+ case "functional-assembly": return this.computeFunctionalAssemblySelection(requestOptions.imodel, requestOptions.elementIds);
215
+ case "functional-top-assembly": return this.computeFunctionalTopAssemblySelection(requestOptions.imodel, requestOptions.elementIds);
216
+ }
217
+ throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "scopeId");
218
+ }
219
+ }
220
+ exports.SelectionScopesHelper = SelectionScopesHelper;
221
+ const skipTransients = (callback) => {
222
+ return (id) => {
223
+ if (!core_bentley_1.Id64.isTransient(id))
224
+ callback(id);
225
+ };
226
+ };
230
227
  //# sourceMappingURL=SelectionScopesHelper.js.map