@itwin/presentation-backend 3.0.0-dev.100
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 +936 -0
- package/LICENSE.md +9 -0
- package/README.md +12 -0
- package/lib/cjs/assets/primary-presentation-rules/ElementProperties.PresentationRuleSet.json +14 -0
- package/lib/cjs/assets/supplemental-presentation-rules/BisCore.PresentationRuleSet.json +739 -0
- package/lib/cjs/assets/supplemental-presentation-rules/Functional.PresentationRuleSet.json +139 -0
- package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts +42 -0
- package/lib/cjs/presentation-backend/BackendLoggerCategory.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/BackendLoggerCategory.js +51 -0
- package/lib/cjs/presentation-backend/BackendLoggerCategory.js.map +1 -0
- package/lib/cjs/presentation-backend/Constants.d.ts +14 -0
- package/lib/cjs/presentation-backend/Constants.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/Constants.js +44 -0
- package/lib/cjs/presentation-backend/Constants.js.map +1 -0
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts +12 -0
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js +256 -0
- package/lib/cjs/presentation-backend/ElementPropertiesHelper.js.map +1 -0
- package/lib/cjs/presentation-backend/NativePlatform.d.ts +86 -0
- package/lib/cjs/presentation-backend/NativePlatform.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/NativePlatform.js +153 -0
- package/lib/cjs/presentation-backend/NativePlatform.js.map +1 -0
- package/lib/cjs/presentation-backend/Presentation.d.ts +98 -0
- package/lib/cjs/presentation-backend/Presentation.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/Presentation.js +135 -0
- package/lib/cjs/presentation-backend/Presentation.js.map +1 -0
- package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts +13 -0
- package/lib/cjs/presentation-backend/PresentationIpcHandler.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js +41 -0
- package/lib/cjs/presentation-backend/PresentationIpcHandler.js.map +1 -0
- package/lib/cjs/presentation-backend/PresentationManager.d.ts +379 -0
- package/lib/cjs/presentation-backend/PresentationManager.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/PresentationManager.js +635 -0
- package/lib/cjs/presentation-backend/PresentationManager.js.map +1 -0
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts +58 -0
- package/lib/cjs/presentation-backend/PresentationRpcImpl.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js +271 -0
- package/lib/cjs/presentation-backend/PresentationRpcImpl.js.map +1 -0
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts +105 -0
- package/lib/cjs/presentation-backend/RulesetEmbedder.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/RulesetEmbedder.js +283 -0
- package/lib/cjs/presentation-backend/RulesetEmbedder.js.map +1 -0
- package/lib/cjs/presentation-backend/RulesetManager.d.ts +54 -0
- package/lib/cjs/presentation-backend/RulesetManager.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/RulesetManager.js +74 -0
- package/lib/cjs/presentation-backend/RulesetManager.js.map +1 -0
- package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts +141 -0
- package/lib/cjs/presentation-backend/RulesetVariablesManager.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js +130 -0
- package/lib/cjs/presentation-backend/RulesetVariablesManager.js.map +1 -0
- package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts +38 -0
- package/lib/cjs/presentation-backend/SelectionScopesHelper.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js +257 -0
- package/lib/cjs/presentation-backend/SelectionScopesHelper.js.map +1 -0
- package/lib/cjs/presentation-backend/TemporaryStorage.d.ts +73 -0
- package/lib/cjs/presentation-backend/TemporaryStorage.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/TemporaryStorage.js +92 -0
- package/lib/cjs/presentation-backend/TemporaryStorage.js.map +1 -0
- package/lib/cjs/presentation-backend/UpdatesTracker.d.ts +28 -0
- package/lib/cjs/presentation-backend/UpdatesTracker.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/UpdatesTracker.js +55 -0
- package/lib/cjs/presentation-backend/UpdatesTracker.js.map +1 -0
- package/lib/cjs/presentation-backend/Utils.d.ts +11 -0
- package/lib/cjs/presentation-backend/Utils.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/Utils.js +39 -0
- package/lib/cjs/presentation-backend/Utils.js.map +1 -0
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts +17 -0
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js +52 -0
- package/lib/cjs/presentation-backend/domain/PresentationRulesDomain.js.map +1 -0
- package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts +22 -0
- package/lib/cjs/presentation-backend/domain/RulesetElements.d.ts.map +1 -0
- package/lib/cjs/presentation-backend/domain/RulesetElements.js +39 -0
- package/lib/cjs/presentation-backend/domain/RulesetElements.js.map +1 -0
- package/lib/cjs/presentation-backend.d.ts +20 -0
- package/lib/cjs/presentation-backend.d.ts.map +1 -0
- package/lib/cjs/presentation-backend.js +36 -0
- package/lib/cjs/presentation-backend.js.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,130 @@
|
|
|
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.RulesetVariablesManagerImpl = void 0;
|
|
11
|
+
const presentation_common_1 = require("@itwin/presentation-common");
|
|
12
|
+
/**
|
|
13
|
+
* Presentation ruleset variables registry implementation.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
class RulesetVariablesManagerImpl {
|
|
17
|
+
constructor(getNativeAddon, rulesetId) {
|
|
18
|
+
this._getNativePlatform = getNativeAddon;
|
|
19
|
+
this._rulesetId = rulesetId;
|
|
20
|
+
}
|
|
21
|
+
setValueInternal(variableId, type, value) {
|
|
22
|
+
this._getNativePlatform().setRulesetVariableValue(this._rulesetId, variableId, type, value);
|
|
23
|
+
}
|
|
24
|
+
getValueInternal(variableId, type) {
|
|
25
|
+
return this._getNativePlatform().getRulesetVariableValue(this._rulesetId, variableId, type).result;
|
|
26
|
+
}
|
|
27
|
+
setValue(variableId, type, value) {
|
|
28
|
+
switch (type) {
|
|
29
|
+
case presentation_common_1.VariableValueTypes.Bool: return this.setBool(variableId, value);
|
|
30
|
+
case presentation_common_1.VariableValueTypes.Id64: return this.setId64(variableId, value);
|
|
31
|
+
case presentation_common_1.VariableValueTypes.Id64Array: return this.setId64s(variableId, value);
|
|
32
|
+
case presentation_common_1.VariableValueTypes.Int: return this.setInt(variableId, value);
|
|
33
|
+
case presentation_common_1.VariableValueTypes.IntArray: return this.setInts(variableId, value);
|
|
34
|
+
case presentation_common_1.VariableValueTypes.String: return this.setString(variableId, value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
unset(variableId) {
|
|
38
|
+
this._getNativePlatform().unsetRulesetVariableValue(this._rulesetId, variableId);
|
|
39
|
+
}
|
|
40
|
+
getValue(variableId, type) {
|
|
41
|
+
switch (type) {
|
|
42
|
+
case presentation_common_1.VariableValueTypes.Bool: return this.getBool(variableId);
|
|
43
|
+
case presentation_common_1.VariableValueTypes.Id64: return this.getId64(variableId);
|
|
44
|
+
case presentation_common_1.VariableValueTypes.Id64Array: return this.getId64s(variableId);
|
|
45
|
+
case presentation_common_1.VariableValueTypes.Int: return this.getInt(variableId);
|
|
46
|
+
case presentation_common_1.VariableValueTypes.IntArray: return this.getInts(variableId);
|
|
47
|
+
case presentation_common_1.VariableValueTypes.String: return this.getString(variableId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves `string` variable value.
|
|
52
|
+
* Returns empty string if variable does not exist or does not convert to string.
|
|
53
|
+
*/
|
|
54
|
+
getString(variableId) {
|
|
55
|
+
return (this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.String));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets `string` variable value
|
|
59
|
+
*/
|
|
60
|
+
setString(variableId, value) {
|
|
61
|
+
this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.String, value);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Retrieves `boolean` variable value.
|
|
65
|
+
* Returns `false` if variable does not exist or does not convert to boolean.
|
|
66
|
+
*/
|
|
67
|
+
getBool(variableId) {
|
|
68
|
+
return (this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Bool));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Sets `boolean` variable value
|
|
72
|
+
*/
|
|
73
|
+
setBool(variableId, value) {
|
|
74
|
+
this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Bool, value);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves `number` variable value.
|
|
78
|
+
* Returns `0` if variable does not exist or does not convert to integer.
|
|
79
|
+
*/
|
|
80
|
+
getInt(variableId) {
|
|
81
|
+
return (this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Int));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Sets `number` variable value
|
|
85
|
+
*/
|
|
86
|
+
setInt(variableId, value) {
|
|
87
|
+
this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Int, value);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves `number[]` variable value.
|
|
91
|
+
* Returns empty array if variable does not exist or does not convert to integer array.
|
|
92
|
+
*/
|
|
93
|
+
getInts(variableId) {
|
|
94
|
+
return (this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.IntArray));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Sets `number[]` variable value
|
|
98
|
+
*/
|
|
99
|
+
setInts(variableId, value) {
|
|
100
|
+
this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.IntArray, value);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves `Id64String` variable value.
|
|
104
|
+
* Returns invalid Id64String if variable does not exist or does not convert to Id64String.
|
|
105
|
+
*/
|
|
106
|
+
getId64(variableId) {
|
|
107
|
+
return (this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Sets `Id64String` variable value
|
|
111
|
+
*/
|
|
112
|
+
setId64(variableId, value) {
|
|
113
|
+
this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64, value);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Retrieves `Id64String[]` variable value.
|
|
117
|
+
* Returns empty array if variable does not exist or does not convert to Id64String array.
|
|
118
|
+
*/
|
|
119
|
+
getId64s(variableId) {
|
|
120
|
+
return (this.getValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64Array));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Sets `Id64String[]` variable value
|
|
124
|
+
*/
|
|
125
|
+
setId64s(variableId, value) {
|
|
126
|
+
this.setValueInternal(variableId, presentation_common_1.VariableValueTypes.Id64Array, value);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.RulesetVariablesManagerImpl = RulesetVariablesManagerImpl;
|
|
130
|
+
//# sourceMappingURL=RulesetVariablesManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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AkB;QAChC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,SAAS,CAAC,CAAiB,CAAC;IAC3F,CAAC;IAED;;OAEG;IACI,QAAQ,CAAC,UAAkB,EAAE,KAAmB;QACrD,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,wCAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;CACF;AApID,kEAoIC","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 { Id64String } from \"@itwin/core-bentley\";\r\nimport { VariableValue, VariableValueTypes } from \"@itwin/presentation-common\";\r\nimport { NativePlatformDefinition } from \"./NativePlatform\";\r\n\r\n/**\r\n * Presentation ruleset variables registry.\r\n * @public\r\n */\r\nexport interface RulesetVariablesManager {\r\n /** Gets a value of the specified type and ID */\r\n getValue(variableId: string, type: VariableValueTypes): VariableValue;\r\n /** Sets a value of the specified type */\r\n setValue(variableId: string, type: VariableValueTypes, value: VariableValue): void;\r\n /** Unsets variable with given id. */\r\n unset(variableId: string): void;\r\n\r\n /**\r\n * Retrieves `string` variable value.\r\n * Returns empty string if variable does not exist or does not convert to string.\r\n */\r\n getString(variableId: string): string;\r\n /**\r\n * Sets `string` variable value\r\n */\r\n setString(variableId: string, value: string): void;\r\n\r\n /**\r\n * Retrieves `boolean` variable value.\r\n * Returns `false` if variable does not exist or does not convert to boolean.\r\n */\r\n getBool(variableId: string): boolean;\r\n /**\r\n * Sets `boolean` variable value\r\n */\r\n setBool(variableId: string, value: boolean): void;\r\n\r\n /**\r\n * Retrieves `number` variable value.\r\n * Returns `0` if variable does not exist or does not convert to integer.\r\n */\r\n getInt(variableId: string): number;\r\n /**\r\n * Sets `number` variable value\r\n */\r\n setInt(variableId: string, value: number): void;\r\n\r\n /**\r\n * Retrieves `number[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to integer array.\r\n */\r\n getInts(variableId: string): number[];\r\n /**\r\n * Sets `number[]` variable value\r\n */\r\n setInts(variableId: string, value: number[]): void;\r\n\r\n /**\r\n * Retrieves `Id64String` variable value.\r\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\r\n */\r\n getId64(variableId: string): Id64String;\r\n /**\r\n * Sets `Id64String` variable value\r\n */\r\n setId64(variableId: string, value: Id64String): void;\r\n\r\n /**\r\n * Retrieves `Id64String[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to Id64String array.\r\n */\r\n getId64s(variableId: string): Id64String[];\r\n /**\r\n * Sets `Id64String[]` variable value\r\n */\r\n setId64s(variableId: string, value: Id64String[]): void;\r\n}\r\n\r\n/**\r\n * Presentation ruleset variables registry implementation.\r\n * @internal\r\n */\r\nexport class RulesetVariablesManagerImpl implements RulesetVariablesManager {\r\n private _getNativePlatform: () => NativePlatformDefinition;\r\n private _rulesetId: string;\r\n\r\n constructor(getNativeAddon: () => NativePlatformDefinition, rulesetId: string) {\r\n this._getNativePlatform = getNativeAddon;\r\n this._rulesetId = rulesetId;\r\n }\r\n\r\n public setValueInternal(variableId: string, type: VariableValueTypes, value: VariableValue): void {\r\n this._getNativePlatform().setRulesetVariableValue(this._rulesetId, variableId, type, value);\r\n }\r\n\r\n public getValueInternal(variableId: string, type: VariableValueTypes): VariableValue {\r\n return this._getNativePlatform().getRulesetVariableValue(this._rulesetId, variableId, type).result;\r\n }\r\n\r\n public setValue(variableId: string, type: VariableValueTypes, value: VariableValue): void {\r\n switch (type) {\r\n case VariableValueTypes.Bool: return this.setBool(variableId, value as boolean);\r\n case VariableValueTypes.Id64: return this.setId64(variableId, value as Id64String);\r\n case VariableValueTypes.Id64Array: return this.setId64s(variableId, value as Id64String[]);\r\n case VariableValueTypes.Int: return this.setInt(variableId, value as number);\r\n case VariableValueTypes.IntArray: return this.setInts(variableId, value as number[]);\r\n case VariableValueTypes.String: return this.setString(variableId, value as string);\r\n }\r\n }\r\n\r\n public unset(variableId: string): void {\r\n this._getNativePlatform().unsetRulesetVariableValue(this._rulesetId, variableId);\r\n }\r\n\r\n public getValue(variableId: string, type: VariableValueTypes): VariableValue {\r\n switch (type) {\r\n case VariableValueTypes.Bool: return this.getBool(variableId);\r\n case VariableValueTypes.Id64: return this.getId64(variableId);\r\n case VariableValueTypes.Id64Array: return this.getId64s(variableId);\r\n case VariableValueTypes.Int: return this.getInt(variableId);\r\n case VariableValueTypes.IntArray: return this.getInts(variableId);\r\n case VariableValueTypes.String: return this.getString(variableId);\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves `string` variable value.\r\n * Returns empty string if variable does not exist or does not convert to string.\r\n */\r\n public getString(variableId: string): string {\r\n return (this.getValueInternal(variableId, VariableValueTypes.String)) as string;\r\n }\r\n\r\n /**\r\n * Sets `string` variable value\r\n */\r\n public setString(variableId: string, value: string): void {\r\n this.setValueInternal(variableId, VariableValueTypes.String, value);\r\n }\r\n\r\n /**\r\n * Retrieves `boolean` variable value.\r\n * Returns `false` if variable does not exist or does not convert to boolean.\r\n */\r\n public getBool(variableId: string): boolean {\r\n return (this.getValueInternal(variableId, VariableValueTypes.Bool)) as boolean;\r\n }\r\n\r\n /**\r\n * Sets `boolean` variable value\r\n */\r\n public setBool(variableId: string, value: boolean): void {\r\n this.setValueInternal(variableId, VariableValueTypes.Bool, value);\r\n }\r\n\r\n /**\r\n * Retrieves `number` variable value.\r\n * Returns `0` if variable does not exist or does not convert to integer.\r\n */\r\n public getInt(variableId: string): number {\r\n return (this.getValueInternal(variableId, VariableValueTypes.Int)) as number;\r\n }\r\n\r\n /**\r\n * Sets `number` variable value\r\n */\r\n public setInt(variableId: string, value: number): void {\r\n this.setValueInternal(variableId, VariableValueTypes.Int, value);\r\n }\r\n\r\n /**\r\n * Retrieves `number[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to integer array.\r\n */\r\n public getInts(variableId: string): number[] {\r\n return (this.getValueInternal(variableId, VariableValueTypes.IntArray)) as number[];\r\n }\r\n\r\n /**\r\n * Sets `number[]` variable value\r\n */\r\n public setInts(variableId: string, value: number[]): void {\r\n this.setValueInternal(variableId, VariableValueTypes.IntArray, value);\r\n }\r\n\r\n /**\r\n * Retrieves `Id64String` variable value.\r\n * Returns invalid Id64String if variable does not exist or does not convert to Id64String.\r\n */\r\n public getId64(variableId: string): Id64String {\r\n return (this.getValueInternal(variableId, VariableValueTypes.Id64)) as Id64String;\r\n }\r\n\r\n /**\r\n * Sets `Id64String` variable value\r\n */\r\n public setId64(variableId: string, value: Id64String): void {\r\n this.setValueInternal(variableId, VariableValueTypes.Id64, value);\r\n }\r\n\r\n /**\r\n * Retrieves `Id64String[]` variable value.\r\n * Returns empty array if variable does not exist or does not convert to Id64String array.\r\n */\r\n public getId64s(variableId: string): Id64String[] {\r\n return (this.getValueInternal(variableId, VariableValueTypes.Id64Array)) as Id64String[];\r\n }\r\n\r\n /**\r\n * Sets `Id64String[]` variable value\r\n */\r\n public setId64s(variableId: string, value: Id64String[]): void {\r\n this.setValueInternal(variableId, VariableValueTypes.Id64Array, value);\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Core
|
|
3
|
+
*/
|
|
4
|
+
import { Id64String } from "@itwin/core-bentley";
|
|
5
|
+
import { IModelDb } from "@itwin/core-backend";
|
|
6
|
+
import { 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 computeElementSelection;
|
|
17
|
+
private static getParentInstanceKey;
|
|
18
|
+
private static getAssemblyKey;
|
|
19
|
+
private static computeAssemblySelection;
|
|
20
|
+
private static getTopAssemblyKey;
|
|
21
|
+
private static computeTopAssemblySelection;
|
|
22
|
+
private static computeCategorySelection;
|
|
23
|
+
private static computeModelSelection;
|
|
24
|
+
private static getRelatedFunctionalElementKey;
|
|
25
|
+
private static findFirstRelatedFunctionalElementKey;
|
|
26
|
+
private static elementClassDerivesFrom;
|
|
27
|
+
private static computeFunctionalElementSelection;
|
|
28
|
+
private static computeFunctionalAssemblySelection;
|
|
29
|
+
private static computeFunctionalTopAssemblySelection;
|
|
30
|
+
/**
|
|
31
|
+
* Computes selection set based on provided selection scope.
|
|
32
|
+
* @param requestOptions Options for the request
|
|
33
|
+
* @param keys Keys of elements to get the content for.
|
|
34
|
+
* @param scopeId ID of selection scope to use for computing selection
|
|
35
|
+
*/
|
|
36
|
+
static computeSelection(requestOptions: SelectionScopeRequestOptions<IModelDb>, ids: Id64String[], scopeId: string): Promise<KeySet>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=SelectionScopesHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectionScopesHelper.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/SelectionScopesHelper.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAkB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,EAAwC,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACrF,OAAO,EACQ,MAAM,EAAyC,cAAc,EAAE,4BAA4B,EACzG,MAAM,4BAA4B,CAAC;AAGpC;;;;;GAKG;AACH,qBAAa,qBAAqB;IAGhC,OAAO;WAEO,kBAAkB,IAAI,cAAc,EAAE;IAgBpD,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAUtC,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAOnC,OAAO,CAAC,MAAM,CAAC,cAAc;IAO7B,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAUvC,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAUhC,OAAO,CAAC,MAAM,CAAC,2BAA2B;IAU1C,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAavC,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAWpC,OAAO,CAAC,MAAM,CAAC,8BAA8B;IAuB7C,OAAO,CAAC,MAAM,CAAC,oCAAoC;IAWnD,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAgBtC,OAAO,CAAC,MAAM,CAAC,iCAAiC;IAwBhD,OAAO,CAAC,MAAM,CAAC,kCAAkC;IAyBjD,OAAO,CAAC,MAAM,CAAC,qCAAqC;IAyBpD;;;;;OAKG;WACiB,gBAAgB,CAAC,cAAc,EAAE,4BAA4B,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAgBlJ"}
|
|
@@ -0,0 +1,257 @@
|
|
|
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_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const core_backend_1 = require("@itwin/core-backend");
|
|
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 computeElementSelection(requestOptions, ids) {
|
|
40
|
+
const keys = new presentation_common_1.KeySet();
|
|
41
|
+
ids.forEach(skipTransients((id) => {
|
|
42
|
+
const key = (0, Utils_1.getElementKey)(requestOptions.imodel, id);
|
|
43
|
+
if (key)
|
|
44
|
+
keys.add(key);
|
|
45
|
+
}));
|
|
46
|
+
return keys;
|
|
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);
|
|
75
|
+
}
|
|
76
|
+
return currKey !== null && currKey !== void 0 ? currKey : (0, Utils_1.getElementKey)(imodel, id);
|
|
77
|
+
}
|
|
78
|
+
static computeTopAssemblySelection(requestOptions, ids) {
|
|
79
|
+
const parentKeys = new presentation_common_1.KeySet();
|
|
80
|
+
ids.forEach(skipTransients((id) => {
|
|
81
|
+
const key = this.getTopAssemblyKey(requestOptions.imodel, id);
|
|
82
|
+
if (key)
|
|
83
|
+
parentKeys.add(key);
|
|
84
|
+
}));
|
|
85
|
+
return parentKeys;
|
|
86
|
+
}
|
|
87
|
+
static computeCategorySelection(requestOptions, ids) {
|
|
88
|
+
const categoryKeys = new presentation_common_1.KeySet();
|
|
89
|
+
ids.forEach(skipTransients((id) => {
|
|
90
|
+
const el = requestOptions.imodel.elements.tryGetElement(id);
|
|
91
|
+
if (el instanceof core_backend_1.GeometricElement) {
|
|
92
|
+
const category = requestOptions.imodel.elements.tryGetElementProps(el.category);
|
|
93
|
+
if (category)
|
|
94
|
+
categoryKeys.add({ className: category.classFullName, id: category.id });
|
|
95
|
+
}
|
|
96
|
+
}));
|
|
97
|
+
return categoryKeys;
|
|
98
|
+
}
|
|
99
|
+
static computeModelSelection(requestOptions, ids) {
|
|
100
|
+
const modelKeys = new presentation_common_1.KeySet();
|
|
101
|
+
ids.forEach(skipTransients((id) => {
|
|
102
|
+
const el = requestOptions.imodel.elements.tryGetElementProps(id);
|
|
103
|
+
const model = el ? requestOptions.imodel.models.tryGetModelProps(el.model) : undefined;
|
|
104
|
+
if (model)
|
|
105
|
+
modelKeys.add({ className: model.classFullName, id: model.id });
|
|
106
|
+
}));
|
|
107
|
+
return modelKeys;
|
|
108
|
+
}
|
|
109
|
+
static getRelatedFunctionalElementKey(imodel, graphicalElementId) {
|
|
110
|
+
const query = `
|
|
111
|
+
SELECT funcSchemaDef.Name || '.' || funcClassDef.Name funcElClassName, fe.ECInstanceId funcElId
|
|
112
|
+
FROM bis.Element e
|
|
113
|
+
LEFT JOIN func.PhysicalElementFulfillsFunction rel1 ON rel1.SourceECInstanceId = e.ECInstanceId
|
|
114
|
+
LEFT JOIN func.DrawingGraphicRepresentsFunctionalElement rel2 ON rel2.SourceECInstanceId = e.ECInstanceId
|
|
115
|
+
LEFT JOIN func.FunctionalElement fe ON fe.ECInstanceId IN (rel1.TargetECInstanceId, rel2.TargetECInstanceId)
|
|
116
|
+
INNER JOIN meta.ECClassDef funcClassDef ON funcClassDef.ECInstanceId = fe.ECClassId
|
|
117
|
+
INNER JOIN meta.ECSchemaDef funcSchemaDef ON funcSchemaDef.ECInstanceId = funcClassDef.Schema.Id
|
|
118
|
+
WHERE e.ECInstanceId = ?
|
|
119
|
+
`;
|
|
120
|
+
return imodel.withPreparedStatement(query, (stmt) => {
|
|
121
|
+
stmt.bindId(1, graphicalElementId);
|
|
122
|
+
// istanbul ignore else
|
|
123
|
+
if (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step()) {
|
|
124
|
+
const row = stmt.getRow();
|
|
125
|
+
if (row.funcElClassName && row.funcElId)
|
|
126
|
+
return { className: row.funcElClassName.replace(".", ":"), id: row.funcElId };
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
static findFirstRelatedFunctionalElementKey(imodel, graphicalElementId) {
|
|
132
|
+
var _a;
|
|
133
|
+
let currId = graphicalElementId;
|
|
134
|
+
while (currId) {
|
|
135
|
+
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(imodel, currId);
|
|
136
|
+
if (relatedFunctionalKey)
|
|
137
|
+
return relatedFunctionalKey;
|
|
138
|
+
currId = (_a = this.getParentInstanceKey(imodel, currId)) === null || _a === void 0 ? void 0 : _a.id;
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
static elementClassDerivesFrom(imodel, elementId, baseClassFullName) {
|
|
143
|
+
const query = `
|
|
144
|
+
SELECT 1
|
|
145
|
+
FROM bis.Element e
|
|
146
|
+
INNER JOIN meta.ClassHasAllBaseClasses baseClassRels ON baseClassRels.SourceECInstanceId = e.ECClassId
|
|
147
|
+
INNER JOIN meta.ECClassDef baseClass ON baseClass.ECInstanceId = baseClassRels.TargetECInstanceId
|
|
148
|
+
INNER JOIN meta.ECSchemaDef baseSchema ON baseSchema.ECInstanceId = baseClass.Schema.Id
|
|
149
|
+
WHERE e.ECInstanceId = ? AND (baseSchema.Name || ':' || baseClass.Name) = ?
|
|
150
|
+
`;
|
|
151
|
+
return imodel.withPreparedStatement(query, (stmt) => {
|
|
152
|
+
stmt.bindId(1, elementId);
|
|
153
|
+
stmt.bindString(2, baseClassFullName);
|
|
154
|
+
return (core_bentley_1.DbResult.BE_SQLITE_ROW === stmt.step());
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
static computeFunctionalElementSelection(requestOptions, ids) {
|
|
158
|
+
const keys = new presentation_common_1.KeySet();
|
|
159
|
+
ids.forEach(skipTransients((id) => {
|
|
160
|
+
const is3d = this.elementClassDerivesFrom(requestOptions.imodel, id, core_backend_1.GeometricElement3d.classFullName);
|
|
161
|
+
if (!is3d) {
|
|
162
|
+
// if the input is not a 3d element, we try to find the first related functional element
|
|
163
|
+
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(requestOptions.imodel, id);
|
|
164
|
+
if (firstFunctionalKey) {
|
|
165
|
+
keys.add(firstFunctionalKey);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
let keyToAdd;
|
|
170
|
+
if (is3d) {
|
|
171
|
+
// if we're computing scope for a 3d element, try to switch to its related functional element
|
|
172
|
+
keyToAdd = this.getRelatedFunctionalElementKey(requestOptions.imodel, id);
|
|
173
|
+
}
|
|
174
|
+
if (!keyToAdd)
|
|
175
|
+
keyToAdd = (0, Utils_1.getElementKey)(requestOptions.imodel, id);
|
|
176
|
+
keyToAdd && keys.add(keyToAdd);
|
|
177
|
+
}));
|
|
178
|
+
return keys;
|
|
179
|
+
}
|
|
180
|
+
static computeFunctionalAssemblySelection(requestOptions, ids) {
|
|
181
|
+
const keys = new presentation_common_1.KeySet();
|
|
182
|
+
ids.forEach(skipTransients((id) => {
|
|
183
|
+
let idToGetAssemblyFor = id;
|
|
184
|
+
const is3d = this.elementClassDerivesFrom(requestOptions.imodel, id, core_backend_1.GeometricElement3d.classFullName);
|
|
185
|
+
if (!is3d) {
|
|
186
|
+
// if the input is not a 3d element, we try to find the first related functional element
|
|
187
|
+
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(requestOptions.imodel, id);
|
|
188
|
+
if (firstFunctionalKey)
|
|
189
|
+
idToGetAssemblyFor = firstFunctionalKey.id;
|
|
190
|
+
}
|
|
191
|
+
// find the assembly of either the given element or the functional element
|
|
192
|
+
const assemblyKey = this.getAssemblyKey(requestOptions.imodel, idToGetAssemblyFor);
|
|
193
|
+
let keyToAdd = assemblyKey;
|
|
194
|
+
if (is3d && keyToAdd) {
|
|
195
|
+
// if we're computing scope for a 3d element, try to switch to its related functional element
|
|
196
|
+
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(requestOptions.imodel, keyToAdd.id);
|
|
197
|
+
if (relatedFunctionalKey)
|
|
198
|
+
keyToAdd = relatedFunctionalKey;
|
|
199
|
+
}
|
|
200
|
+
keyToAdd && keys.add(keyToAdd);
|
|
201
|
+
}));
|
|
202
|
+
return keys;
|
|
203
|
+
}
|
|
204
|
+
static computeFunctionalTopAssemblySelection(requestOptions, ids) {
|
|
205
|
+
const keys = new presentation_common_1.KeySet();
|
|
206
|
+
ids.forEach(skipTransients((id) => {
|
|
207
|
+
let idToGetAssemblyFor = id;
|
|
208
|
+
const is3d = this.elementClassDerivesFrom(requestOptions.imodel, id, core_backend_1.GeometricElement3d.classFullName);
|
|
209
|
+
if (!is3d) {
|
|
210
|
+
// if the input is not a 3d element, we try to find the first related functional element
|
|
211
|
+
const firstFunctionalKey = this.findFirstRelatedFunctionalElementKey(requestOptions.imodel, id);
|
|
212
|
+
if (firstFunctionalKey)
|
|
213
|
+
idToGetAssemblyFor = firstFunctionalKey.id;
|
|
214
|
+
}
|
|
215
|
+
// find the top assembly of either the given element or the functional element
|
|
216
|
+
const topAssemblyKey = this.getTopAssemblyKey(requestOptions.imodel, idToGetAssemblyFor);
|
|
217
|
+
let keyToAdd = topAssemblyKey;
|
|
218
|
+
if (is3d && keyToAdd) {
|
|
219
|
+
// if we're computing scope for a 3d element, try to switch to its related functional element
|
|
220
|
+
const relatedFunctionalKey = this.getRelatedFunctionalElementKey(requestOptions.imodel, keyToAdd.id);
|
|
221
|
+
if (relatedFunctionalKey)
|
|
222
|
+
keyToAdd = relatedFunctionalKey;
|
|
223
|
+
}
|
|
224
|
+
keyToAdd && keys.add(keyToAdd);
|
|
225
|
+
}));
|
|
226
|
+
return keys;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Computes selection set based on provided selection scope.
|
|
230
|
+
* @param requestOptions Options for the request
|
|
231
|
+
* @param keys Keys of elements to get the content for.
|
|
232
|
+
* @param scopeId ID of selection scope to use for computing selection
|
|
233
|
+
*/
|
|
234
|
+
static async computeSelection(requestOptions, ids, scopeId) {
|
|
235
|
+
switch (scopeId) {
|
|
236
|
+
case "element": return this.computeElementSelection(requestOptions, ids);
|
|
237
|
+
case "assembly": return this.computeAssemblySelection(requestOptions, ids);
|
|
238
|
+
case "top-assembly": return this.computeTopAssemblySelection(requestOptions, ids);
|
|
239
|
+
case "category": return this.computeCategorySelection(requestOptions, ids);
|
|
240
|
+
case "model": return this.computeModelSelection(requestOptions, ids);
|
|
241
|
+
case "functional":
|
|
242
|
+
case "functional-element":
|
|
243
|
+
return this.computeFunctionalElementSelection(requestOptions, ids);
|
|
244
|
+
case "functional-assembly": return this.computeFunctionalAssemblySelection(requestOptions, ids);
|
|
245
|
+
case "functional-top-assembly": return this.computeFunctionalTopAssemblySelection(requestOptions, ids);
|
|
246
|
+
}
|
|
247
|
+
throw new presentation_common_1.PresentationError(presentation_common_1.PresentationStatus.InvalidArgument, "scopeId");
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.SelectionScopesHelper = SelectionScopesHelper;
|
|
251
|
+
const skipTransients = (callback) => {
|
|
252
|
+
return (id) => {
|
|
253
|
+
if (!core_bentley_1.Id64.isTransient(id))
|
|
254
|
+
callback(id);
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
//# sourceMappingURL=SelectionScopesHelper.js.map
|
|
@@ -0,0 +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;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,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G,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"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** @packageDocumentation
|
|
2
|
+
* @module Core
|
|
3
|
+
*/
|
|
4
|
+
import { IDisposable } from "@itwin/core-bentley";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration properties for [[TemporaryStorage]].
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export interface TemporaryStorageProps<T> {
|
|
10
|
+
/** A factory method that creates a stored value given it's identifier */
|
|
11
|
+
factory: (id: string) => T;
|
|
12
|
+
/** A method that's called for every value before it's removed from storage */
|
|
13
|
+
cleanupHandler?: (value: T) => void;
|
|
14
|
+
onCreated?: (id: string) => void;
|
|
15
|
+
onDisposedSingle?: (id: string) => void;
|
|
16
|
+
onDisposedAll?: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* An interval at which the storage attempts to clean up its values.
|
|
19
|
+
* When `0` or `undefined` is specified, values are not cleaned up
|
|
20
|
+
* automatically and cleanup has to be initiated manually by calling
|
|
21
|
+
* [[TemporaryStorage.disposeOutdatedValues]].
|
|
22
|
+
*/
|
|
23
|
+
cleanupInterval?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Shortest period of time which the value should be kept in storage
|
|
26
|
+
* unused before it's cleaned up. `0` or `undefined` means values
|
|
27
|
+
* are removed from the storage on every cleanup (either manual call to
|
|
28
|
+
* [[TemporaryStorage.disposeOutdatedValues]] or scheduled (controlled
|
|
29
|
+
* by [[cleanupInterval]]))
|
|
30
|
+
*/
|
|
31
|
+
valueLifetime?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Storage for values that get removed from it after being unused (not-requested
|
|
35
|
+
* for a specified amount of time).
|
|
36
|
+
*
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export declare class TemporaryStorage<T> implements IDisposable {
|
|
40
|
+
private _values;
|
|
41
|
+
private _timer?;
|
|
42
|
+
readonly props: TemporaryStorageProps<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Constructor. Creates the storage using supplied params.
|
|
45
|
+
*/
|
|
46
|
+
constructor(props: TemporaryStorageProps<T>);
|
|
47
|
+
/**
|
|
48
|
+
* Destructor. Must be called to clean up the stored values
|
|
49
|
+
* and other resources
|
|
50
|
+
*/
|
|
51
|
+
dispose(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Cleans up values that are currently outdated (based
|
|
54
|
+
* on their lifetime specified through [[Props]]).
|
|
55
|
+
*/
|
|
56
|
+
disposeOutdatedValues: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Get a value from the storage. If the value with the
|
|
59
|
+
* specified id doesn't exist, it gets created.
|
|
60
|
+
*
|
|
61
|
+
* **Note:** requesting a value with this method updates
|
|
62
|
+
* it's last used time.
|
|
63
|
+
*/
|
|
64
|
+
getValue(id: string): T;
|
|
65
|
+
/**
|
|
66
|
+
* Get all values currently in this storage.
|
|
67
|
+
*
|
|
68
|
+
* **Note:** requesting values with this method **doesn't**
|
|
69
|
+
* update their last used times.
|
|
70
|
+
*/
|
|
71
|
+
get values(): T[];
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=TemporaryStorage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemporaryStorage.d.ts","sourceRoot":"","sources":["../../../src/presentation-backend/TemporaryStorage.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,yEAAyE;IACzE,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,CAAC,CAAC;IAE3B,8EAA8E;IAC9E,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAEpC,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,gBAAgB,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAE3B;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAQD;;;;;GAKG;AACH,qBAAa,gBAAgB,CAAC,CAAC,CAAE,YAAW,WAAW;IAErD,OAAO,CAAC,OAAO,CAAiC;IAChD,OAAO,CAAC,MAAM,CAAC,CAAe;IAC9B,SAAgB,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAEhD;;OAEG;gBACS,KAAK,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAO3C;;;OAGG;IACI,OAAO;IAad;;;OAGG;IACI,qBAAqB,aAa1B;IAEF;;;;;;OAMG;IACI,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC;IAa9B;;;;;OAKG;IACH,IAAW,MAAM,IAAI,CAAC,EAAE,CAKvB;CAEF"}
|