@itwin/presentation-backend 3.3.0-dev.9 → 3.4.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -1
- package/lib/cjs/presentation-backend/NativePlatform.d.ts +2 -2
- package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/NativePlatform.js +5 -16
- package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.d.ts +32 -40
- package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManager.js +65 -322
- package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -1
- package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts +51 -0
- package/lib/cjs/presentation-backend/PresentationManagerDetail.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js +277 -0
- package/lib/cjs/presentation-backend/PresentationManagerDetail.js.map +1 -0
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +3 -2
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js +48 -13
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -1
- package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +5 -7
- package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js +60 -87
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -1
- package/lib/cjs/presentation-backend/Utils.d.ts +13 -2
- package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -1
- package/lib/cjs/presentation-backend/Utils.js +2 -2
- package/lib/cjs/presentation-backend/Utils.js.map +1 -1
- package/package.json +17 -17
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.SelectionScopesHelper = void 0;
|
|
11
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
11
|
const core_backend_1 = require("@itwin/core-backend");
|
|
12
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
13
13
|
const presentation_common_1 = require("@itwin/presentation-common");
|
|
14
14
|
const Utils_1 = require("./Utils");
|
|
15
15
|
/**
|
|
@@ -36,71 +36,42 @@ class SelectionScopesHelper {
|
|
|
36
36
|
// createSelectionScope("model", "Model", "Select all elements in the picked element's model"),
|
|
37
37
|
];
|
|
38
38
|
}
|
|
39
|
-
static
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
static getParentInstanceKey(imodel, id) {
|
|
49
|
-
const elementProps = imodel.elements.tryGetElementProps(id);
|
|
50
|
-
if (!(elementProps === null || elementProps === void 0 ? void 0 : elementProps.parent))
|
|
51
|
-
return undefined;
|
|
52
|
-
return (0, Utils_1.getElementKey)(imodel, elementProps.parent.id);
|
|
53
|
-
}
|
|
54
|
-
static getAssemblyKey(imodel, id) {
|
|
55
|
-
const parentKey = this.getParentInstanceKey(imodel, id);
|
|
56
|
-
if (parentKey)
|
|
57
|
-
return parentKey;
|
|
58
|
-
return (0, Utils_1.getElementKey)(imodel, id);
|
|
59
|
-
}
|
|
60
|
-
static computeAssemblySelection(requestOptions, ids) {
|
|
61
|
-
const parentKeys = new presentation_common_1.KeySet();
|
|
62
|
-
ids.forEach(skipTransients((id) => {
|
|
63
|
-
const key = this.getAssemblyKey(requestOptions.imodel, id);
|
|
64
|
-
if (key)
|
|
65
|
-
parentKeys.add(key);
|
|
66
|
-
}));
|
|
67
|
-
return parentKeys;
|
|
68
|
-
}
|
|
69
|
-
static getTopAssemblyKey(imodel, id) {
|
|
70
|
-
let currKey;
|
|
71
|
-
let parentKey = this.getParentInstanceKey(imodel, id);
|
|
72
|
-
while (parentKey) {
|
|
73
|
-
currKey = parentKey;
|
|
74
|
-
parentKey = this.getParentInstanceKey(imodel, currKey.id);
|
|
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;
|
|
75
47
|
}
|
|
76
|
-
return
|
|
48
|
+
return (0, Utils_1.getElementKey)(iModel, currId);
|
|
77
49
|
}
|
|
78
|
-
static
|
|
50
|
+
static computeElementSelection(iModel, elementIds, ancestorLevel) {
|
|
79
51
|
const parentKeys = new presentation_common_1.KeySet();
|
|
80
|
-
|
|
81
|
-
const key = this.
|
|
82
|
-
|
|
83
|
-
parentKeys.add(key);
|
|
52
|
+
elementIds.forEach(skipTransients((id) => {
|
|
53
|
+
const key = this.getElementKey(iModel, id, ancestorLevel);
|
|
54
|
+
key && parentKeys.add(key);
|
|
84
55
|
}));
|
|
85
56
|
return parentKeys;
|
|
86
57
|
}
|
|
87
|
-
static computeCategorySelection(
|
|
58
|
+
static computeCategorySelection(iModel, ids) {
|
|
88
59
|
const categoryKeys = new presentation_common_1.KeySet();
|
|
89
60
|
ids.forEach(skipTransients((id) => {
|
|
90
|
-
const el =
|
|
61
|
+
const el = iModel.elements.tryGetElement(id);
|
|
91
62
|
if (el instanceof core_backend_1.GeometricElement) {
|
|
92
|
-
const category =
|
|
63
|
+
const category = iModel.elements.tryGetElementProps(el.category);
|
|
93
64
|
if (category)
|
|
94
65
|
categoryKeys.add({ className: category.classFullName, id: category.id });
|
|
95
66
|
}
|
|
96
67
|
}));
|
|
97
68
|
return categoryKeys;
|
|
98
69
|
}
|
|
99
|
-
static computeModelSelection(
|
|
70
|
+
static computeModelSelection(iModel, ids) {
|
|
100
71
|
const modelKeys = new presentation_common_1.KeySet();
|
|
101
72
|
ids.forEach(skipTransients((id) => {
|
|
102
|
-
const el =
|
|
103
|
-
const model = el ?
|
|
73
|
+
const el = iModel.elements.tryGetElementProps(id);
|
|
74
|
+
const model = el ? iModel.models.tryGetModelProps(el.model) : undefined;
|
|
104
75
|
if (model)
|
|
105
76
|
modelKeys.add({ className: model.classFullName, id: model.id });
|
|
106
77
|
}));
|
|
@@ -129,24 +100,24 @@ class SelectionScopesHelper {
|
|
|
129
100
|
});
|
|
130
101
|
}
|
|
131
102
|
static findFirstRelatedFunctionalElementKey(imodel, graphicalElementId) {
|
|
132
|
-
var _a;
|
|
103
|
+
var _a, _b;
|
|
133
104
|
let currId = graphicalElementId;
|
|
134
105
|
while (currId) {
|
|
135
106
|
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);
|
|
136
107
|
if (relatedFunctionalKey)
|
|
137
108
|
return relatedFunctionalKey;
|
|
138
|
-
currId = (_a =
|
|
109
|
+
currId = (_b = (_a = imodel.elements.tryGetElementProps(currId)) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.id;
|
|
139
110
|
}
|
|
140
111
|
return undefined;
|
|
141
112
|
}
|
|
142
113
|
static elementClassDerivesFrom(imodel, elementId, baseClassFullName) {
|
|
143
114
|
const query = `
|
|
144
115
|
SELECT 1
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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) = ?
|
|
150
121
|
`;
|
|
151
122
|
return imodel.withPreparedStatement(query, (stmt) => {
|
|
152
123
|
stmt.bindId(1, elementId);
|
|
@@ -154,13 +125,13 @@ class SelectionScopesHelper {
|
|
|
154
125
|
return (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step());
|
|
155
126
|
});
|
|
156
127
|
}
|
|
157
|
-
static computeFunctionalElementSelection(
|
|
128
|
+
static computeFunctionalElementSelection(iModel, ids) {
|
|
158
129
|
const keys = new presentation_common_1.KeySet();
|
|
159
130
|
ids.forEach(skipTransients((id) => {
|
|
160
|
-
const is3d = this.elementClassDerivesFrom(
|
|
131
|
+
const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
|
|
161
132
|
if (!is3d) {
|
|
162
133
|
// if the input is not a 3d element, we try to find the first related functional element
|
|
163
|
-
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(
|
|
134
|
+
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
|
|
164
135
|
if (firstFunctionalKey) {
|
|
165
136
|
keys.add(firstFunctionalKey);
|
|
166
137
|
return;
|
|
@@ -169,31 +140,31 @@ class SelectionScopesHelper {
|
|
|
169
140
|
let keyToAdd;
|
|
170
141
|
if (is3d) {
|
|
171
142
|
// if we're computing scope for a 3d element, try to switch to its related functional element
|
|
172
|
-
keyToAdd = this.getRelatedFunctionalElementKey(
|
|
143
|
+
keyToAdd = this.getRelatedFunctionalElementKey(iModel, id);
|
|
173
144
|
}
|
|
174
145
|
if (!keyToAdd)
|
|
175
|
-
keyToAdd = (0, Utils_1.getElementKey)(
|
|
146
|
+
keyToAdd = (0, Utils_1.getElementKey)(iModel, id);
|
|
176
147
|
keyToAdd && keys.add(keyToAdd);
|
|
177
148
|
}));
|
|
178
149
|
return keys;
|
|
179
150
|
}
|
|
180
|
-
static computeFunctionalAssemblySelection(
|
|
151
|
+
static computeFunctionalAssemblySelection(iModel, ids) {
|
|
181
152
|
const keys = new presentation_common_1.KeySet();
|
|
182
153
|
ids.forEach(skipTransients((id) => {
|
|
183
154
|
let idToGetAssemblyFor = id;
|
|
184
|
-
const is3d = this.elementClassDerivesFrom(
|
|
155
|
+
const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
|
|
185
156
|
if (!is3d) {
|
|
186
157
|
// if the input is not a 3d element, we try to find the first related functional element
|
|
187
|
-
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(
|
|
158
|
+
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
|
|
188
159
|
if (firstFunctionalKey)
|
|
189
160
|
idToGetAssemblyFor = firstFunctionalKey.id;
|
|
190
161
|
}
|
|
191
162
|
// find the assembly of either the given element or the functional element
|
|
192
|
-
const assemblyKey = this.
|
|
163
|
+
const assemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, 1);
|
|
193
164
|
let keyToAdd = assemblyKey;
|
|
194
165
|
if (is3d && keyToAdd) {
|
|
195
166
|
// if we're computing scope for a 3d element, try to switch to its related functional element
|
|
196
|
-
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(
|
|
167
|
+
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);
|
|
197
168
|
if (relatedFunctionalKey)
|
|
198
169
|
keyToAdd = relatedFunctionalKey;
|
|
199
170
|
}
|
|
@@ -201,23 +172,23 @@ class SelectionScopesHelper {
|
|
|
201
172
|
}));
|
|
202
173
|
return keys;
|
|
203
174
|
}
|
|
204
|
-
static computeFunctionalTopAssemblySelection(
|
|
175
|
+
static computeFunctionalTopAssemblySelection(iModel, ids) {
|
|
205
176
|
const keys = new presentation_common_1.KeySet();
|
|
206
177
|
ids.forEach(skipTransients((id) => {
|
|
207
178
|
let idToGetAssemblyFor = id;
|
|
208
|
-
const is3d = this.elementClassDerivesFrom(
|
|
179
|
+
const is3d = this.elementClassDerivesFrom(iModel, id, core_backend_1.GeometricElement3d.classFullName);
|
|
209
180
|
if (!is3d) {
|
|
210
181
|
// if the input is not a 3d element, we try to find the first related functional element
|
|
211
|
-
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(
|
|
182
|
+
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);
|
|
212
183
|
if (firstFunctionalKey)
|
|
213
184
|
idToGetAssemblyFor = firstFunctionalKey.id;
|
|
214
185
|
}
|
|
215
186
|
// find the top assembly of either the given element or the functional element
|
|
216
|
-
const topAssemblyKey = this.
|
|
187
|
+
const topAssemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, Number.MAX_SAFE_INTEGER);
|
|
217
188
|
let keyToAdd = topAssemblyKey;
|
|
218
189
|
if (is3d && keyToAdd) {
|
|
219
190
|
// if we're computing scope for a 3d element, try to switch to its related functional element
|
|
220
|
-
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(
|
|
191
|
+
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);
|
|
221
192
|
if (relatedFunctionalKey)
|
|
222
193
|
keyToAdd = relatedFunctionalKey;
|
|
223
194
|
}
|
|
@@ -225,24 +196,26 @@ class SelectionScopesHelper {
|
|
|
225
196
|
}));
|
|
226
197
|
return keys;
|
|
227
198
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
case "
|
|
239
|
-
case "
|
|
240
|
-
case "
|
|
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);
|
|
241
214
|
case "functional":
|
|
242
215
|
case "functional-element":
|
|
243
|
-
return this.computeFunctionalElementSelection(requestOptions,
|
|
244
|
-
case "functional-assembly": return this.computeFunctionalAssemblySelection(requestOptions,
|
|
245
|
-
case "functional-top-assembly": return this.computeFunctionalTopAssemblySelection(requestOptions,
|
|
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);
|
|
246
219
|
}
|
|
247
220
|
throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "scopeId");
|
|
248
221
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionScopesHelper.js","sourceRoot":"","sources":["../../../src/presentation-backend/SelectionScopesHelper.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAiE;AACjE,sDAAqF;AACrF,oEAEoC;AACpC,mCAAwC;AAExC;;;;;GAKG;AACH,MAAa,qBAAqB;IA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,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YAC3E,KAAK,cAAc,CAAC,CAAC,OAAO,IAAI,CAAC,2BAA2B,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YAClF,KAAK,UAAU,CAAC,CAAC,OAAO,IAAI,CAAC,wBAAwB,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YAC3E,KAAK,OAAO,CAAC,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YACrE,KAAK,YAAY,CAAC;YAClB,KAAK,oBAAoB;gBACvB,OAAO,IAAI,CAAC,iCAAiC,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YACrE,KAAK,qBAAqB,CAAC,CAAC,OAAO,IAAI,CAAC,kCAAkC,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;YAChG,KAAK,yBAAyB,CAAC,CAAC,OAAO,IAAI,CAAC,qCAAqC,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;SACxG;QACD,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CAEF;AArPD,sDAqPC;AAED,MAAM,cAAc,GAAG,CAAC,QAAkC,EAAE,EAAE;IAC5D,OAAO,CAAC,EAAc,EAAE,EAAE;QACxB,IAAI,CAAC,mBAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACvB,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { GeometricElement, GeometricElement3d, IModelDb } from \"@itwin/core-backend\";\r\nimport {\r\n InstanceKey, KeySet, PresentationError, PresentationStatus, SelectionScope, SelectionScopeRequestOptions,\r\n} from \"@itwin/presentation-common\";\r\nimport { getElementKey } from \"./Utils\";\r\n\r\n/**\r\n * Contains helper methods for computing selection scopes. Will get removed\r\n * once rules-driven scopes are implemented.\r\n *\r\n * @internal\r\n */\r\nexport class SelectionScopesHelper {\r\n\r\n // istanbul ignore next\r\n private constructor() { }\r\n\r\n public static getSelectionScopes(): SelectionScope[] {\r\n const createSelectionScope = (scopeId: string, label: string, description: string): SelectionScope => ({\r\n id: scopeId,\r\n label,\r\n description,\r\n });\r\n return [\r\n createSelectionScope(\"element\", \"Element\", \"Select the picked element\"),\r\n createSelectionScope(\"assembly\", \"Assembly\", \"Select parent of the picked element\"),\r\n createSelectionScope(\"top-assembly\", \"Top Assembly\", \"Select the topmost parent of the picked element\"),\r\n // WIP: temporarily comment-out \"category\" and \"model\" scopes since we can't hilite contents of them fast enough\r\n // createSelectionScope(\"category\", \"Category\", \"Select all elements in the picked element's category\"),\r\n // createSelectionScope(\"model\", \"Model\", \"Select all elements in the picked element's model\"),\r\n ];\r\n }\r\n\r\n private static computeElementSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const key = getElementKey(requestOptions.imodel, id);\r\n if (key)\r\n keys.add(key);\r\n }));\r\n return keys;\r\n }\r\n\r\n private static getParentInstanceKey(imodel: IModelDb, id: Id64String): InstanceKey | undefined {\r\n const elementProps = imodel.elements.tryGetElementProps(id);\r\n if (!elementProps?.parent)\r\n return undefined;\r\n return getElementKey(imodel, elementProps.parent.id);\r\n }\r\n\r\n private static getAssemblyKey(imodel: IModelDb, id: Id64String) {\r\n const parentKey = this.getParentInstanceKey(imodel, id);\r\n if (parentKey)\r\n return parentKey;\r\n return getElementKey(imodel, id);\r\n }\r\n\r\n private static computeAssemblySelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const parentKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const key = this.getAssemblyKey(requestOptions.imodel, id);\r\n if (key)\r\n parentKeys.add(key);\r\n }));\r\n return parentKeys;\r\n }\r\n\r\n private static getTopAssemblyKey(imodel: IModelDb, id: Id64String) {\r\n let currKey: InstanceKey | undefined;\r\n let parentKey = this.getParentInstanceKey(imodel, id);\r\n while (parentKey) {\r\n currKey = parentKey;\r\n parentKey = this.getParentInstanceKey(imodel, currKey.id);\r\n }\r\n return currKey ?? getElementKey(imodel, id);\r\n }\r\n\r\n private static computeTopAssemblySelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const parentKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const key = this.getTopAssemblyKey(requestOptions.imodel, id);\r\n if (key)\r\n parentKeys.add(key);\r\n }));\r\n return parentKeys;\r\n }\r\n\r\n private static computeCategorySelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const categoryKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const el = requestOptions.imodel.elements.tryGetElement(id);\r\n if (el instanceof GeometricElement) {\r\n const category = requestOptions.imodel.elements.tryGetElementProps(el.category);\r\n if (category)\r\n categoryKeys.add({ className: category.classFullName, id: category.id! });\r\n }\r\n }));\r\n return categoryKeys;\r\n }\r\n\r\n private static computeModelSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const modelKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const el = requestOptions.imodel.elements.tryGetElementProps(id);\r\n const model = el ? requestOptions.imodel.models.tryGetModelProps(el.model) : undefined;\r\n if (model)\r\n modelKeys.add({ className: model.classFullName, id: model.id! });\r\n }));\r\n return modelKeys;\r\n }\r\n\r\n private static getRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\r\n const query = `\r\n SELECT funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId\r\n FROM bis.Element e\r\n LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId\r\n LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId\r\n LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)\r\n INNER JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId\r\n INNER JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id\r\n WHERE e.ECInstanceId = ?\r\n `;\r\n return imodel.withPreparedStatement(query, (stmt): InstanceKey | undefined => {\r\n stmt.bindId(1, graphicalElementId);\r\n // istanbul ignore else\r\n if (DbResult.BE_SQLITE_ROW === stmt.step()) {\r\n const row = stmt.getRow();\r\n if (row.funcElClassName && row.funcElId)\r\n return { className: row.funcElClassName.replace(\".\", \":\"), id: row.funcElId };\r\n }\r\n return undefined;\r\n });\r\n }\r\n\r\n private static findFirstRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\r\n let currId: Id64String | undefined = graphicalElementId;\r\n while (currId) {\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);\r\n if (relatedFunctionalKey)\r\n return relatedFunctionalKey;\r\n currId = this.getParentInstanceKey(imodel, currId)?.id;\r\n }\r\n return undefined;\r\n }\r\n\r\n private static elementClassDerivesFrom(imodel: IModelDb, elementId: Id64String, baseClassFullName: string): boolean {\r\n const query = `\r\n SELECT 1\r\n FROM bis.Element e\r\n INNER JOIN meta.ClassHasAllBaseClasses baseClassRels ON baseClassRels.SourceECInstanceId = e.ECClassId\r\n INNER JOIN meta.ECClassDef baseClass ON baseClass.ECInstanceId = baseClassRels.TargetECInstanceId\r\n INNER JOIN meta.ECSchemaDef baseSchema ON baseSchema.ECInstanceId = baseClass.Schema.Id\r\n WHERE e.ECInstanceId = ? AND (baseSchema.Name || ':' || baseClass.Name) = ?\r\n `;\r\n return imodel.withPreparedStatement(query, (stmt): boolean => {\r\n stmt.bindId(1, elementId);\r\n stmt.bindString(2, baseClassFullName);\r\n return (DbResult.BE_SQLITE_ROW === stmt.step());\r\n });\r\n }\r\n\r\n private static computeFunctionalElementSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n const is3d = this.elementClassDerivesFrom(requestOptions.imodel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(requestOptions.imodel, id);\r\n if (firstFunctionalKey) {\r\n keys.add(firstFunctionalKey);\r\n return;\r\n }\r\n }\r\n let keyToAdd: InstanceKey | undefined;\r\n if (is3d) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n keyToAdd = this.getRelatedFunctionalElementKey(requestOptions.imodel, id);\r\n }\r\n if (!keyToAdd)\r\n keyToAdd = getElementKey(requestOptions.imodel, id);\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n private static computeFunctionalAssemblySelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n let idToGetAssemblyFor = id;\r\n const is3d = this.elementClassDerivesFrom(requestOptions.imodel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(requestOptions.imodel, id);\r\n if (firstFunctionalKey)\r\n idToGetAssemblyFor = firstFunctionalKey.id;\r\n }\r\n // find the assembly of either the given element or the functional element\r\n const assemblyKey = this.getAssemblyKey(requestOptions.imodel, idToGetAssemblyFor);\r\n let keyToAdd = assemblyKey;\r\n if (is3d && keyToAdd) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(requestOptions.imodel, keyToAdd.id);\r\n if (relatedFunctionalKey)\r\n keyToAdd = relatedFunctionalKey;\r\n }\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n private static computeFunctionalTopAssemblySelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n let idToGetAssemblyFor = id;\r\n const is3d = this.elementClassDerivesFrom(requestOptions.imodel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(requestOptions.imodel, id);\r\n if (firstFunctionalKey)\r\n idToGetAssemblyFor = firstFunctionalKey.id;\r\n }\r\n // find the top assembly of either the given element or the functional element\r\n const topAssemblyKey = this.getTopAssemblyKey(requestOptions.imodel, idToGetAssemblyFor);\r\n let keyToAdd = topAssemblyKey;\r\n if (is3d && keyToAdd) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(requestOptions.imodel, keyToAdd.id);\r\n if (relatedFunctionalKey)\r\n keyToAdd = relatedFunctionalKey;\r\n }\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n /**\r\n * Computes selection set based on provided selection scope.\r\n * @param requestOptions Options for the request\r\n * @param keys Keys of elements to get the content for.\r\n * @param scopeId ID of selection scope to use for computing selection\r\n */\r\n public static async computeSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[], scopeId: string): Promise<KeySet> {\r\n switch (scopeId) {\r\n case \"element\": return this.computeElementSelection(requestOptions, ids);\r\n case \"assembly\": return this.computeAssemblySelection(requestOptions, ids);\r\n case \"top-assembly\": return this.computeTopAssemblySelection(requestOptions, ids);\r\n case \"category\": return this.computeCategorySelection(requestOptions, ids);\r\n case \"model\": return this.computeModelSelection(requestOptions, ids);\r\n case \"functional\":\r\n case \"functional-element\":\r\n return this.computeFunctionalElementSelection(requestOptions, ids);\r\n case \"functional-assembly\": return this.computeFunctionalAssemblySelection(requestOptions, ids);\r\n case \"functional-top-assembly\": return this.computeFunctionalTopAssemblySelection(requestOptions, ids);\r\n }\r\n throw new PresentationError(PresentationStatus.InvalidArgument, \"scopeId\");\r\n }\r\n\r\n}\r\n\r\nconst skipTransients = (callback: (id: Id64String) => void) => {\r\n return (id: Id64String) => {\r\n if (!Id64.isTransient(id))\r\n callback(id);\r\n };\r\n};\r\n"]}
|
|
1
|
+
{"version":3,"file":"SelectionScopesHelper.js","sourceRoot":"","sources":["../../../src/presentation-backend/SelectionScopesHelper.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAqF;AACrF,sDAAiE;AACjE,oEAGoC;AACpC,mCAAwC;AAExC;;;;;GAKG;AACH,MAAa,qBAAqB;IAEhC,uBAAuB;IACvB,gBAAwB,CAAC;IAElB,MAAM,CAAC,kBAAkB;QAC9B,MAAM,oBAAoB,GAAG,CAAC,OAAe,EAAE,KAAa,EAAE,WAAmB,EAAkB,EAAE,CAAC,CAAC;YACrG,EAAE,EAAE,OAAO;YACX,KAAK;YACL,WAAW;SACZ,CAAC,CAAC;QACH,OAAO;YACL,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,2BAA2B,CAAC;YACvE,oBAAoB,CAAC,UAAU,EAAE,UAAU,EAAE,qCAAqC,CAAC;YACnF,oBAAoB,CAAC,cAAc,EAAE,cAAc,EAAE,iDAAiD,CAAC;YACvG,gHAAgH;YAChH,wGAAwG;YACxG,+FAA+F;SAChG,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,MAAgB,EAAE,SAAqB,EAAE,aAAqB;;QACz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,qBAAqB,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;YAClG,KAAK,YAAY,CAAC;YAClB,KAAK,oBAAoB;gBACvB,OAAO,IAAI,CAAC,iCAAiC,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;YAClG,KAAK,qBAAqB,CAAC,CAAC,OAAO,IAAI,CAAC,kCAAkC,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;YAC7H,KAAK,yBAAyB,CAAC,CAAC,OAAO,IAAI,CAAC,qCAAqC,CAAC,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;SACrI;QACD,MAAM,IAAI,uCAAiB,CAAC,wCAAkB,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;IAC7E,CAAC;CAEF;AA9ND,sDA8NC;AAED,MAAM,cAAc,GAAG,CAAC,QAAkC,EAAE,EAAE;IAC5D,OAAO,CAAC,EAAc,EAAE,EAAE;QACxB,IAAI,CAAC,mBAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACvB,QAAQ,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport { GeometricElement, GeometricElement3d, IModelDb } from \"@itwin/core-backend\";\r\nimport { DbResult, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport {\r\n ComputeSelectionRequestOptions, ElementSelectionScopeProps, InstanceKey, isComputeSelectionRequestOptions, KeySet, PresentationError,\r\n PresentationStatus, SelectionScope, SelectionScopeRequestOptions,\r\n} from \"@itwin/presentation-common\";\r\nimport { getElementKey } from \"./Utils\";\r\n\r\n/**\r\n * Contains helper methods for computing selection scopes. Will get removed\r\n * once rules-driven scopes are implemented.\r\n *\r\n * @internal\r\n */\r\nexport class SelectionScopesHelper {\r\n\r\n // istanbul ignore next\r\n private constructor() { }\r\n\r\n public static getSelectionScopes(): SelectionScope[] {\r\n const createSelectionScope = (scopeId: string, label: string, description: string): SelectionScope => ({\r\n id: scopeId,\r\n label,\r\n description,\r\n });\r\n return [\r\n createSelectionScope(\"element\", \"Element\", \"Select the picked element\"),\r\n createSelectionScope(\"assembly\", \"Assembly\", \"Select parent of the picked element\"),\r\n createSelectionScope(\"top-assembly\", \"Top Assembly\", \"Select the topmost parent of the picked element\"),\r\n // WIP: temporarily comment-out \"category\" and \"model\" scopes since we can't hilite contents of them fast enough\r\n // createSelectionScope(\"category\", \"Category\", \"Select all elements in the picked element's category\"),\r\n // createSelectionScope(\"model\", \"Model\", \"Select all elements in the picked element's model\"),\r\n ];\r\n }\r\n\r\n private static getElementKey(iModel: IModelDb, elementId: Id64String, ancestorLevel: number) {\r\n let currId = elementId;\r\n let parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;\r\n while (parentId && ancestorLevel !== 0) {\r\n currId = parentId;\r\n parentId = iModel.elements.tryGetElementProps(currId)?.parent?.id;\r\n --ancestorLevel;\r\n }\r\n return getElementKey(iModel, currId);\r\n }\r\n\r\n private static computeElementSelection(iModel: IModelDb, elementIds: Id64String[], ancestorLevel: number) {\r\n const parentKeys = new KeySet();\r\n elementIds.forEach(skipTransients((id) => {\r\n const key = this.getElementKey(iModel, id, ancestorLevel);\r\n key && parentKeys.add(key);\r\n }));\r\n return parentKeys;\r\n }\r\n\r\n private static computeCategorySelection(iModel: IModelDb, ids: Id64String[]) {\r\n const categoryKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const el = iModel.elements.tryGetElement(id);\r\n if (el instanceof GeometricElement) {\r\n const category = iModel.elements.tryGetElementProps(el.category);\r\n if (category)\r\n categoryKeys.add({ className: category.classFullName, id: category.id! });\r\n }\r\n }));\r\n return categoryKeys;\r\n }\r\n\r\n private static computeModelSelection(iModel: IModelDb, ids: Id64String[]) {\r\n const modelKeys = new KeySet();\r\n ids.forEach(skipTransients((id) => {\r\n const el = iModel.elements.tryGetElementProps(id);\r\n const model = el ? iModel.models.tryGetModelProps(el.model) : undefined;\r\n if (model)\r\n modelKeys.add({ className: model.classFullName, id: model.id! });\r\n }));\r\n return modelKeys;\r\n }\r\n\r\n private static getRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\r\n const query = `\r\n SELECT funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId\r\n FROM bis.Element e\r\n LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId\r\n LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId\r\n LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)\r\n INNER JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId\r\n INNER JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id\r\n WHERE e.ECInstanceId = ?\r\n `;\r\n return imodel.withPreparedStatement(query, (stmt): InstanceKey | undefined => {\r\n stmt.bindId(1, graphicalElementId);\r\n // istanbul ignore else\r\n if (DbResult.BE_SQLITE_ROW === stmt.step()) {\r\n const row = stmt.getRow();\r\n if (row.funcElClassName && row.funcElId)\r\n return { className: row.funcElClassName.replace(\".\", \":\"), id: row.funcElId };\r\n }\r\n return undefined;\r\n });\r\n }\r\n\r\n private static findFirstRelatedFunctionalElementKey(imodel: IModelDb, graphicalElementId: Id64String): InstanceKey | undefined {\r\n let currId: Id64String | undefined = graphicalElementId;\r\n while (currId) {\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);\r\n if (relatedFunctionalKey)\r\n return relatedFunctionalKey;\r\n currId = imodel.elements.tryGetElementProps(currId)?.parent?.id;\r\n }\r\n return undefined;\r\n }\r\n\r\n private static elementClassDerivesFrom(imodel: IModelDb, elementId: Id64String, baseClassFullName: string): boolean {\r\n const query = `\r\n SELECT 1\r\n FROM bis.Element e\r\n INNER JOIN meta.ClassHasAllBaseClasses baseClassRels ON baseClassRels.SourceECInstanceId = e.ECClassId\r\n INNER JOIN meta.ECClassDef baseClass ON baseClass.ECInstanceId = baseClassRels.TargetECInstanceId\r\n INNER JOIN meta.ECSchemaDef baseSchema ON baseSchema.ECInstanceId = baseClass.Schema.Id\r\n WHERE e.ECInstanceId = ? AND (baseSchema.Name || ':' || baseClass.Name) = ?\r\n `;\r\n return imodel.withPreparedStatement(query, (stmt): boolean => {\r\n stmt.bindId(1, elementId);\r\n stmt.bindString(2, baseClassFullName);\r\n return (DbResult.BE_SQLITE_ROW === stmt.step());\r\n });\r\n }\r\n\r\n private static computeFunctionalElementSelection(iModel: IModelDb, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\r\n if (firstFunctionalKey) {\r\n keys.add(firstFunctionalKey);\r\n return;\r\n }\r\n }\r\n let keyToAdd: InstanceKey | undefined;\r\n if (is3d) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n keyToAdd = this.getRelatedFunctionalElementKey(iModel, id);\r\n }\r\n if (!keyToAdd)\r\n keyToAdd = getElementKey(iModel, id);\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n private static computeFunctionalAssemblySelection(iModel: IModelDb, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n let idToGetAssemblyFor = id;\r\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\r\n if (firstFunctionalKey)\r\n idToGetAssemblyFor = firstFunctionalKey.id;\r\n }\r\n // find the assembly of either the given element or the functional element\r\n const assemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, 1);\r\n let keyToAdd = assemblyKey;\r\n if (is3d && keyToAdd) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);\r\n if (relatedFunctionalKey)\r\n keyToAdd = relatedFunctionalKey;\r\n }\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n private static computeFunctionalTopAssemblySelection(iModel: IModelDb, ids: Id64String[]) {\r\n const keys = new KeySet();\r\n ids.forEach(skipTransients((id): void => {\r\n let idToGetAssemblyFor = id;\r\n const is3d = this.elementClassDerivesFrom(iModel, id, GeometricElement3d.classFullName);\r\n if (!is3d) {\r\n // if the input is not a 3d element, we try to find the first related functional element\r\n const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(iModel, id);\r\n if (firstFunctionalKey)\r\n idToGetAssemblyFor = firstFunctionalKey.id;\r\n }\r\n // find the top assembly of either the given element or the functional element\r\n const topAssemblyKey = this.getElementKey(iModel, idToGetAssemblyFor, Number.MAX_SAFE_INTEGER);\r\n let keyToAdd = topAssemblyKey;\r\n if (is3d && keyToAdd) {\r\n // if we're computing scope for a 3d element, try to switch to its related functional element\r\n const relatedFunctionalKey = this.getRelatedFunctionalElementKey(iModel, keyToAdd.id);\r\n if (relatedFunctionalKey)\r\n keyToAdd = relatedFunctionalKey;\r\n }\r\n keyToAdd && keys.add(keyToAdd);\r\n }));\r\n return keys;\r\n }\r\n\r\n /**\r\n * Computes selection set based on provided selection scope.\r\n * @param requestOptions Options for the request\r\n * @param keys Keys of elements to get the content for.\r\n * @param scopeId ID of selection scope to use for computing selection\r\n */\r\n public static async computeSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[], scopeId: string): Promise<KeySet>;\r\n /** @alpha */\r\n public static async computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb>): Promise<KeySet>;\r\n public static async computeSelection(requestOptions: ComputeSelectionRequestOptions<IModelDb> | SelectionScopeRequestOptions<IModelDb>, elementIds?: Id64String[], scopeId?: string): Promise<KeySet> {\r\n if (!isComputeSelectionRequestOptions(requestOptions)) {\r\n return this.computeSelection({\r\n ...requestOptions,\r\n elementIds: elementIds!,\r\n scope: { id: scopeId! },\r\n });\r\n }\r\n\r\n switch (requestOptions.scope.id) {\r\n case \"element\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, (requestOptions.scope as ElementSelectionScopeProps).ancestorLevel ?? 0);\r\n case \"assembly\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, 1);\r\n case \"top-assembly\": return this.computeElementSelection(requestOptions.imodel, requestOptions.elementIds, Number.MAX_SAFE_INTEGER);\r\n case \"category\": return this.computeCategorySelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"model\": return this.computeModelSelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"functional\":\r\n case \"functional-element\":\r\n return this.computeFunctionalElementSelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"functional-assembly\": return this.computeFunctionalAssemblySelection(requestOptions.imodel, requestOptions.elementIds);\r\n case \"functional-top-assembly\": return this.computeFunctionalTopAssemblySelection(requestOptions.imodel, requestOptions.elementIds);\r\n }\r\n throw new PresentationError(PresentationStatus.InvalidArgument, \"scopeId\");\r\n }\r\n\r\n}\r\n\r\nconst skipTransients = (callback: (id: Id64String) => void) => {\r\n return (id: Id64String) => {\r\n if (!Id64.isTransient(id))\r\n callback(id);\r\n };\r\n};\r\n"]}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
/** @packageDocumentation
|
|
2
2
|
* @module Core
|
|
3
3
|
*/
|
|
4
|
-
import { Id64String } from "@itwin/core-bentley";
|
|
5
4
|
import { IModelDb } from "@itwin/core-backend";
|
|
6
|
-
import {
|
|
5
|
+
import { Id64String } from "@itwin/core-bentley";
|
|
6
|
+
import { Diagnostics, DiagnosticsOptions, InstanceKey } from "@itwin/presentation-common";
|
|
7
7
|
/** @internal */
|
|
8
8
|
export declare function getElementKey(imodel: IModelDb, id: Id64String): InstanceKey | undefined;
|
|
9
9
|
/** @internal */
|
|
10
10
|
export declare function normalizeVersion(version?: string): string;
|
|
11
11
|
/** @internal */
|
|
12
12
|
export declare const getLocalesDirectory: (assetsDirectory: string) => string;
|
|
13
|
+
/** @alpha */
|
|
14
|
+
export declare type BackendDiagnosticsHandler = (logs: Diagnostics) => void;
|
|
15
|
+
/** @alpha */
|
|
16
|
+
export interface BackendDiagnosticsOptions extends DiagnosticsOptions {
|
|
17
|
+
handler: BackendDiagnosticsHandler;
|
|
18
|
+
}
|
|
19
|
+
/** @public */
|
|
20
|
+
export interface BackendDiagnosticsAttribute {
|
|
21
|
+
/** @alpha */
|
|
22
|
+
diagnostics?: BackendDiagnosticsOptions;
|
|
23
|
+
}
|
|
13
24
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/Utils.ts"],"names":[],"mappings":"AAIA;;GAEG;
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/Utils.ts"],"names":[],"mappings":"AAIA;;GAEG;AAIH,OAAO,EAAW,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAY,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE1F,gBAAgB;AAChB,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,CAWvF;AAED,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,UAOhD;AAED,gBAAgB;AAEhB,eAAO,MAAM,mBAAmB,oBAAqB,MAAM,WAA0C,CAAC;AAEtG,aAAa;AACb,oBAAY,yBAAyB,GAAG,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;AAEpE,aAAa;AACb,MAAM,WAAW,yBAA0B,SAAQ,kBAAkB;IACnE,OAAO,EAAE,yBAAyB,CAAC;CACpC;AAED,cAAc;AACd,MAAM,WAAW,2BAA2B;IAC1C,aAAa;IACb,WAAW,CAAC,EAAE,yBAAyB,CAAC;CACzC"}
|
|
@@ -11,10 +11,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.getLocalesDirectory = exports.normalizeVersion = exports.getElementKey = void 0;
|
|
14
|
+
const path_1 = __importDefault(require("path"));
|
|
14
15
|
const semver_1 = require("semver");
|
|
15
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
16
16
|
const core_backend_1 = require("@itwin/core-backend");
|
|
17
|
-
const
|
|
17
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
18
18
|
/** @internal */
|
|
19
19
|
function getElementKey(imodel, id) {
|
|
20
20
|
let key;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/presentation-backend/Utils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,mCAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../src/presentation-backend/Utils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;AAEH,gDAAwB;AACxB,mCAA+C;AAC/C,sDAAwD;AACxD,sDAA2D;AAG3D,gBAAgB;AAChB,SAAgB,aAAa,CAAC,MAAgB,EAAE,EAAc;IAC5D,IAAI,GAA4B,CAAC;IACjC,MAAM,KAAK,GAAG,yBAAyB,sBAAO,CAAC,aAAa,2BAA2B,CAAC;IACxF,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;QAC3C,IAAI;YACF,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACnB,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,uBAAQ,CAAC,aAAa;gBACxC,GAAG,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,sBAAsB,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC;SACxF;QAAC,MAAM,GAAG;IACb,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACb,CAAC;AAXD,sCAWC;AAED,gBAAgB;AAChB,SAAgB,gBAAgB,CAAC,OAAgB;IAC/C,IAAI,OAAO,EAAE;QACX,MAAM,aAAa,GAAG,IAAA,cAAY,EAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAClD,IAAI,aAAa;YACf,OAAO,GAAG,aAAa,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;KACjF;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAPD,4CAOC;AAED,gBAAgB;AAChB,uBAAuB;AAChB,MAAM,mBAAmB,GAAG,CAAC,eAAuB,EAAE,EAAE,CAAC,cAAI,CAAC,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;AAAzF,QAAA,mBAAmB,uBAAsE","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Core\r\n */\r\n\r\nimport path from \"path\";\r\nimport { parse as parseVersion } from \"semver\";\r\nimport { Element, IModelDb } from \"@itwin/core-backend\";\r\nimport { DbResult, Id64String } from \"@itwin/core-bentley\";\r\nimport { Diagnostics, DiagnosticsOptions, InstanceKey } from \"@itwin/presentation-common\";\r\n\r\n/** @internal */\r\nexport function getElementKey(imodel: IModelDb, id: Id64String): InstanceKey | undefined {\r\n let key: InstanceKey | undefined;\r\n const query = `SELECT ECClassId FROM ${Element.classFullName} e WHERE ECInstanceId = ?`;\r\n imodel.withPreparedStatement(query, (stmt) => {\r\n try {\r\n stmt.bindId(1, id);\r\n if (stmt.step() === DbResult.BE_SQLITE_ROW)\r\n key = { className: stmt.getValue(0).getClassNameForClassId().replace(\".\", \":\"), id };\r\n } catch { }\r\n });\r\n return key;\r\n}\r\n\r\n/** @internal */\r\nexport function normalizeVersion(version?: string) {\r\n if (version) {\r\n const parsedVersion = parseVersion(version, true);\r\n if (parsedVersion)\r\n return `${parsedVersion.major}.${parsedVersion.minor}.${parsedVersion.patch}`;\r\n }\r\n return \"0.0.0\";\r\n}\r\n\r\n/** @internal */\r\n// istanbul ignore next\r\nexport const getLocalesDirectory = (assetsDirectory: string) => path.join(assetsDirectory, \"locales\");\r\n\r\n/** @alpha */\r\nexport type BackendDiagnosticsHandler = (logs: Diagnostics) => void;\r\n\r\n/** @alpha */\r\nexport interface BackendDiagnosticsOptions extends DiagnosticsOptions {\r\n handler: BackendDiagnosticsHandler;\r\n}\r\n\r\n/** @public */\r\nexport interface BackendDiagnosticsAttribute {\r\n /** @alpha */\r\n diagnostics?: BackendDiagnosticsOptions;\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-backend",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-dev.2",
|
|
4
4
|
"description": "Backend of iTwin.js Presentation library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -22,21 +22,21 @@
|
|
|
22
22
|
"main": "lib/cjs/presentation-backend.js",
|
|
23
23
|
"typings": "lib/cjs/presentation-backend",
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@itwin/core-backend": "^3.
|
|
26
|
-
"@itwin/core-bentley": "^3.
|
|
27
|
-
"@itwin/core-common": "^3.
|
|
28
|
-
"@itwin/core-quantity": "^3.
|
|
29
|
-
"@itwin/presentation-common": "^3.
|
|
25
|
+
"@itwin/core-backend": "^3.4.0-dev.2",
|
|
26
|
+
"@itwin/core-bentley": "^3.4.0-dev.2",
|
|
27
|
+
"@itwin/core-common": "^3.4.0-dev.2",
|
|
28
|
+
"@itwin/core-quantity": "^3.4.0-dev.2",
|
|
29
|
+
"@itwin/presentation-common": "^3.4.0-dev.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@itwin/build-tools": "3.
|
|
33
|
-
"@itwin/core-backend": "3.
|
|
34
|
-
"@itwin/core-bentley": "3.
|
|
35
|
-
"@itwin/core-common": "3.
|
|
36
|
-
"@itwin/core-quantity": "3.
|
|
37
|
-
"@itwin/eslint-plugin": "3.
|
|
38
|
-
"@itwin/presentation-common": "3.
|
|
39
|
-
"@types/chai": "
|
|
32
|
+
"@itwin/build-tools": "3.4.0-dev.2",
|
|
33
|
+
"@itwin/core-backend": "3.4.0-dev.2",
|
|
34
|
+
"@itwin/core-bentley": "3.4.0-dev.2",
|
|
35
|
+
"@itwin/core-common": "3.4.0-dev.2",
|
|
36
|
+
"@itwin/core-quantity": "3.4.0-dev.2",
|
|
37
|
+
"@itwin/eslint-plugin": "3.4.0-dev.2",
|
|
38
|
+
"@itwin/presentation-common": "3.4.0-dev.2",
|
|
39
|
+
"@types/chai": "4.3.1",
|
|
40
40
|
"@types/chai-as-promised": "^7",
|
|
41
41
|
"@types/chai-jest-snapshot": "^1.3.0",
|
|
42
42
|
"@types/chai-subset": "1.3.1",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@types/mocha": "^8.2.2",
|
|
47
47
|
"@types/node": "16.11.7",
|
|
48
48
|
"@types/object-hash": "^1.3.0",
|
|
49
|
-
"@types/semver": "^
|
|
49
|
+
"@types/semver": "^7.3.9",
|
|
50
50
|
"@types/sinon": "^9.0.0",
|
|
51
51
|
"@types/sinon-chai": "^3.2.0",
|
|
52
52
|
"chai": "^4.1.2",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"eslint": "^7.11.0",
|
|
60
60
|
"faker": "^4.1.0",
|
|
61
61
|
"lolex": "^2.7.1",
|
|
62
|
-
"mocha": "^
|
|
62
|
+
"mocha": "^10.0.0",
|
|
63
63
|
"nyc": "^15.1.0",
|
|
64
64
|
"rimraf": "^3.0.2",
|
|
65
65
|
"sinon": "^9.0.2",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"object-hash": "^1.3.1",
|
|
72
|
-
"semver": "^
|
|
72
|
+
"semver": "^7.3.5"
|
|
73
73
|
},
|
|
74
74
|
"nyc": {
|
|
75
75
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|