@itwin/presentation-frontend 4.0.0-dev.21 → 4.0.0-dev.23
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/lib/cjs/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
- package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js +47 -47
- package/lib/cjs/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
- package/lib/cjs/presentation-frontend/Diagnostics.d.ts +14 -14
- package/lib/cjs/presentation-frontend/Diagnostics.js +61 -61
- package/lib/cjs/presentation-frontend/Diagnostics.js.map +1 -1
- package/lib/cjs/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
- package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js +20 -20
- package/lib/cjs/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
- package/lib/cjs/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
- package/lib/cjs/presentation-frontend/IpcRequestsHandler.js +41 -41
- package/lib/cjs/presentation-frontend/IpcRequestsHandler.js.map +1 -1
- package/lib/cjs/presentation-frontend/LocalizationHelper.d.ts +10 -10
- package/lib/cjs/presentation-frontend/LocalizationHelper.js +31 -31
- package/lib/cjs/presentation-frontend/LocalizationHelper.js.map +1 -1
- package/lib/cjs/presentation-frontend/Presentation.d.ts +73 -73
- package/lib/cjs/presentation-frontend/Presentation.js +160 -160
- package/lib/cjs/presentation-frontend/Presentation.js.map +1 -1
- package/lib/cjs/presentation-frontend/PresentationManager.d.ts +186 -186
- package/lib/cjs/presentation-frontend/PresentationManager.js +436 -436
- package/lib/cjs/presentation-frontend/PresentationManager.js.map +1 -1
- package/lib/cjs/presentation-frontend/RulesetManager.d.ts +63 -63
- package/lib/cjs/presentation-frontend/RulesetManager.js +85 -85
- package/lib/cjs/presentation-frontend/RulesetManager.js.map +1 -1
- package/lib/cjs/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
- package/lib/cjs/presentation-frontend/RulesetVariablesManager.js +195 -195
- package/lib/cjs/presentation-frontend/RulesetVariablesManager.js.map +1 -1
- package/lib/cjs/presentation-frontend/StateTracker.d.ts +38 -38
- package/lib/cjs/presentation-frontend/StateTracker.js +129 -129
- package/lib/cjs/presentation-frontend/StateTracker.js.map +1 -1
- package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
- package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +525 -525
- package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
- package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
- package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +293 -293
- package/lib/cjs/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
- package/lib/cjs/presentation-frontend/selection/HiliteRules.json +172 -172
- package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
- package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js +97 -97
- package/lib/cjs/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
- package/lib/cjs/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
- package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js +9 -9
- package/lib/cjs/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
- package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
- package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js +33 -33
- package/lib/cjs/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
- package/lib/cjs/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
- package/lib/cjs/presentation-frontend/selection/SelectionHandler.js +108 -108
- package/lib/cjs/presentation-frontend/selection/SelectionHandler.js.map +1 -1
- package/lib/cjs/presentation-frontend/selection/SelectionHelper.d.ts +17 -17
- package/lib/cjs/presentation-frontend/selection/SelectionHelper.js +40 -40
- package/lib/cjs/presentation-frontend/selection/SelectionHelper.js.map +1 -1
- package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts +139 -139
- package/lib/cjs/presentation-frontend/selection/SelectionManager.js +414 -414
- package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
- package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
- package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js +91 -91
- package/lib/cjs/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
- package/lib/cjs/presentation-frontend.d.ts +34 -34
- package/lib/cjs/presentation-frontend.js +50 -50
- package/lib/cjs/presentation-frontend.js.map +1 -1
- package/lib/esm/presentation-frontend/ConnectivityInformationProvider.d.ts +29 -29
- package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js +43 -43
- package/lib/esm/presentation-frontend/ConnectivityInformationProvider.js.map +1 -1
- package/lib/esm/presentation-frontend/Diagnostics.d.ts +14 -14
- package/lib/esm/presentation-frontend/Diagnostics.js +56 -56
- package/lib/esm/presentation-frontend/Diagnostics.js.map +1 -1
- package/lib/esm/presentation-frontend/FrontendLoggerCategory.d.ts +12 -12
- package/lib/esm/presentation-frontend/FrontendLoggerCategory.js +17 -17
- package/lib/esm/presentation-frontend/FrontendLoggerCategory.js.map +1 -1
- package/lib/esm/presentation-frontend/IpcRequestsHandler.d.ts +10 -10
- package/lib/esm/presentation-frontend/IpcRequestsHandler.js +37 -37
- package/lib/esm/presentation-frontend/IpcRequestsHandler.js.map +1 -1
- package/lib/esm/presentation-frontend/LocalizationHelper.d.ts +10 -10
- package/lib/esm/presentation-frontend/LocalizationHelper.js +27 -27
- package/lib/esm/presentation-frontend/LocalizationHelper.js.map +1 -1
- package/lib/esm/presentation-frontend/Presentation.d.ts +73 -73
- package/lib/esm/presentation-frontend/Presentation.js +156 -156
- package/lib/esm/presentation-frontend/Presentation.js.map +1 -1
- package/lib/esm/presentation-frontend/PresentationManager.d.ts +186 -186
- package/lib/esm/presentation-frontend/PresentationManager.js +431 -431
- package/lib/esm/presentation-frontend/PresentationManager.js.map +1 -1
- package/lib/esm/presentation-frontend/RulesetManager.d.ts +63 -63
- package/lib/esm/presentation-frontend/RulesetManager.js +81 -81
- package/lib/esm/presentation-frontend/RulesetManager.js.map +1 -1
- package/lib/esm/presentation-frontend/RulesetVariablesManager.d.ts +143 -143
- package/lib/esm/presentation-frontend/RulesetVariablesManager.js +191 -191
- package/lib/esm/presentation-frontend/RulesetVariablesManager.js.map +1 -1
- package/lib/esm/presentation-frontend/StateTracker.d.ts +38 -38
- package/lib/esm/presentation-frontend/StateTracker.js +125 -125
- package/lib/esm/presentation-frontend/StateTracker.js.map +1 -1
- package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.d.ts +132 -132
- package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js +519 -519
- package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesManager.js.map +1 -1
- package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.d.ts +111 -111
- package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js +285 -285
- package/lib/esm/presentation-frontend/favorite-properties/FavoritePropertiesStorage.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/HiliteRules.json +172 -172
- package/lib/esm/presentation-frontend/selection/HiliteSetProvider.d.ts +52 -52
- package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js +93 -93
- package/lib/esm/presentation-frontend/selection/HiliteSetProvider.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/ISelectionProvider.d.ts +19 -19
- package/lib/esm/presentation-frontend/selection/ISelectionProvider.js +8 -8
- package/lib/esm/presentation-frontend/selection/ISelectionProvider.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.d.ts +52 -52
- package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js +29 -29
- package/lib/esm/presentation-frontend/selection/SelectionChangeEvent.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/SelectionHandler.d.ts +103 -103
- package/lib/esm/presentation-frontend/selection/SelectionHandler.js +104 -104
- package/lib/esm/presentation-frontend/selection/SelectionHandler.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/SelectionHelper.d.ts +17 -17
- package/lib/esm/presentation-frontend/selection/SelectionHelper.js +36 -36
- package/lib/esm/presentation-frontend/selection/SelectionHelper.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +139 -139
- package/lib/esm/presentation-frontend/selection/SelectionManager.js +409 -409
- package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/SelectionScopesManager.d.ts +59 -59
- package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js +85 -85
- package/lib/esm/presentation-frontend/selection/SelectionScopesManager.js.map +1 -1
- package/lib/esm/presentation-frontend.d.ts +34 -34
- package/lib/esm/presentation-frontend.js +38 -38
- package/lib/esm/presentation-frontend.js.map +1 -1
- package/package.json +14 -14
|
@@ -1,415 +1,415 @@
|
|
|
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 UnifiedSelection
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.ToolSelectionSyncHandler = exports.TRANSIENT_ELEMENT_CLASSNAME = exports.SelectionManager = void 0;
|
|
11
|
-
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
-
const core_frontend_1 = require("@itwin/core-frontend");
|
|
13
|
-
const presentation_common_1 = require("@itwin/presentation-common");
|
|
14
|
-
const HiliteSetProvider_1 = require("./HiliteSetProvider");
|
|
15
|
-
const SelectionChangeEvent_1 = require("./SelectionChangeEvent");
|
|
16
|
-
const SelectionScopesManager_1 = require("./SelectionScopesManager");
|
|
17
|
-
/**
|
|
18
|
-
* The selection manager which stores the overall selection.
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
class SelectionManager {
|
|
22
|
-
/**
|
|
23
|
-
* Creates an instance of SelectionManager.
|
|
24
|
-
*/
|
|
25
|
-
constructor(props) {
|
|
26
|
-
this._selectionContainerMap = new Map();
|
|
27
|
-
this._imodelToolSelectionSyncHandlers = new Map();
|
|
28
|
-
this._hiliteSetProviders = new Map();
|
|
29
|
-
this.selectionChange = new SelectionChangeEvent_1.SelectionChangeEvent();
|
|
30
|
-
this.scopes = props.scopes;
|
|
31
|
-
core_frontend_1.IModelConnection.onClose.addListener((imodel) => {
|
|
32
|
-
this.onConnectionClose(imodel);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
onConnectionClose(imodel) {
|
|
36
|
-
this.clearSelection("Connection Close Event", imodel);
|
|
37
|
-
this._selectionContainerMap.delete(imodel);
|
|
38
|
-
this._hiliteSetProviders.delete(imodel);
|
|
39
|
-
}
|
|
40
|
-
getContainer(imodel) {
|
|
41
|
-
let selectionContainer = this._selectionContainerMap.get(imodel);
|
|
42
|
-
if (!selectionContainer) {
|
|
43
|
-
selectionContainer = new SelectionContainer();
|
|
44
|
-
this._selectionContainerMap.set(imodel, selectionContainer);
|
|
45
|
-
}
|
|
46
|
-
return selectionContainer;
|
|
47
|
-
}
|
|
48
|
-
/** @internal */
|
|
49
|
-
// istanbul ignore next
|
|
50
|
-
getToolSelectionSyncHandler(imodel) { var _a; return (_a = this._imodelToolSelectionSyncHandlers.get(imodel)) === null || _a === void 0 ? void 0 : _a.handler; }
|
|
51
|
-
/**
|
|
52
|
-
* Request the manager to sync with imodel's tool selection (see `IModelConnection.selectionSet`).
|
|
53
|
-
*/
|
|
54
|
-
setSyncWithIModelToolSelection(imodel, sync = true) {
|
|
55
|
-
const registration = this._imodelToolSelectionSyncHandlers.get(imodel);
|
|
56
|
-
if (sync) {
|
|
57
|
-
if (!registration || registration.requestorsCount === 0) {
|
|
58
|
-
this._imodelToolSelectionSyncHandlers.set(imodel, { requestorsCount: 1, handler: new ToolSelectionSyncHandler(imodel, this) });
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount: registration.requestorsCount + 1 });
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
if (registration && registration.requestorsCount > 0) {
|
|
66
|
-
const requestorsCount = registration.requestorsCount - 1;
|
|
67
|
-
if (requestorsCount > 0) {
|
|
68
|
-
this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount });
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
this._imodelToolSelectionSyncHandlers.delete(imodel);
|
|
72
|
-
registration.handler.dispose();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Temporarily suspends tool selection synchronization until the returned `IDisposable`
|
|
79
|
-
* is disposed.
|
|
80
|
-
*/
|
|
81
|
-
suspendIModelToolSelectionSync(imodel) {
|
|
82
|
-
const registration = this._imodelToolSelectionSyncHandlers.get(imodel);
|
|
83
|
-
if (!registration)
|
|
84
|
-
return { dispose: () => { } };
|
|
85
|
-
const wasSuspended = registration.handler.isSuspended;
|
|
86
|
-
registration.handler.isSuspended = true;
|
|
87
|
-
return { dispose: () => (registration.handler.isSuspended = wasSuspended) };
|
|
88
|
-
}
|
|
89
|
-
/** Get the selection levels currently stored in this manager for the specified imodel */
|
|
90
|
-
getSelectionLevels(imodel) {
|
|
91
|
-
return this.getContainer(imodel).getSelectionLevels();
|
|
92
|
-
}
|
|
93
|
-
/** Get the selection currently stored in this manager */
|
|
94
|
-
getSelection(imodel, level = 0) {
|
|
95
|
-
return this.getContainer(imodel).getSelection(level);
|
|
96
|
-
}
|
|
97
|
-
handleEvent(evt) {
|
|
98
|
-
const container = this.getContainer(evt.imodel);
|
|
99
|
-
const selectedItemsSet = container.getSelection(evt.level);
|
|
100
|
-
const guidBefore = selectedItemsSet.guid;
|
|
101
|
-
switch (evt.changeType) {
|
|
102
|
-
case SelectionChangeEvent_1.SelectionChangeType.Add:
|
|
103
|
-
selectedItemsSet.add(evt.keys);
|
|
104
|
-
break;
|
|
105
|
-
case SelectionChangeEvent_1.SelectionChangeType.Remove:
|
|
106
|
-
selectedItemsSet.delete(evt.keys);
|
|
107
|
-
break;
|
|
108
|
-
case SelectionChangeEvent_1.SelectionChangeType.Replace:
|
|
109
|
-
if (selectedItemsSet.size !== evt.keys.size || !selectedItemsSet.hasAll(evt.keys)) {
|
|
110
|
-
// note: the above check is only needed to avoid changing
|
|
111
|
-
// guid of the keyset if we're replacing keyset with the same keys
|
|
112
|
-
selectedItemsSet.clear().add(evt.keys);
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
case SelectionChangeEvent_1.SelectionChangeType.Clear:
|
|
116
|
-
selectedItemsSet.clear();
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
if (selectedItemsSet.guid === guidBefore)
|
|
120
|
-
return;
|
|
121
|
-
container.clear(evt.level + 1);
|
|
122
|
-
this.selectionChange.raiseEvent(evt, this);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Add keys to the selection
|
|
126
|
-
* @param source Name of the selection source
|
|
127
|
-
* @param imodel iModel associated with the selection
|
|
128
|
-
* @param keys Keys to add
|
|
129
|
-
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
130
|
-
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
131
|
-
*/
|
|
132
|
-
addToSelection(source, imodel, keys, level = 0, rulesetId) {
|
|
133
|
-
const evt = {
|
|
134
|
-
source,
|
|
135
|
-
level,
|
|
136
|
-
imodel,
|
|
137
|
-
changeType: SelectionChangeEvent_1.SelectionChangeType.Add,
|
|
138
|
-
keys: new presentation_common_1.KeySet(keys),
|
|
139
|
-
timestamp: new Date(),
|
|
140
|
-
rulesetId,
|
|
141
|
-
};
|
|
142
|
-
this.handleEvent(evt);
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Remove keys from current selection
|
|
146
|
-
* @param source Name of the selection source
|
|
147
|
-
* @param imodel iModel associated with the selection
|
|
148
|
-
* @param keys Keys to remove
|
|
149
|
-
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
150
|
-
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
151
|
-
*/
|
|
152
|
-
removeFromSelection(source, imodel, keys, level = 0, rulesetId) {
|
|
153
|
-
const evt = {
|
|
154
|
-
source,
|
|
155
|
-
level,
|
|
156
|
-
imodel,
|
|
157
|
-
changeType: SelectionChangeEvent_1.SelectionChangeType.Remove,
|
|
158
|
-
keys: new presentation_common_1.KeySet(keys),
|
|
159
|
-
timestamp: new Date(),
|
|
160
|
-
rulesetId,
|
|
161
|
-
};
|
|
162
|
-
this.handleEvent(evt);
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Replace current selection
|
|
166
|
-
* @param source Name of the selection source
|
|
167
|
-
* @param imodel iModel associated with the selection
|
|
168
|
-
* @param keys Keys to add
|
|
169
|
-
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
170
|
-
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
171
|
-
*/
|
|
172
|
-
replaceSelection(source, imodel, keys, level = 0, rulesetId) {
|
|
173
|
-
const evt = {
|
|
174
|
-
source,
|
|
175
|
-
level,
|
|
176
|
-
imodel,
|
|
177
|
-
changeType: SelectionChangeEvent_1.SelectionChangeType.Replace,
|
|
178
|
-
keys: new presentation_common_1.KeySet(keys),
|
|
179
|
-
timestamp: new Date(),
|
|
180
|
-
rulesetId,
|
|
181
|
-
};
|
|
182
|
-
this.handleEvent(evt);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Clear current selection
|
|
186
|
-
* @param source Name of the selection source
|
|
187
|
-
* @param imodel iModel associated with the selection
|
|
188
|
-
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
189
|
-
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
190
|
-
*/
|
|
191
|
-
clearSelection(source, imodel, level = 0, rulesetId) {
|
|
192
|
-
const evt = {
|
|
193
|
-
source,
|
|
194
|
-
level,
|
|
195
|
-
imodel,
|
|
196
|
-
changeType: SelectionChangeEvent_1.SelectionChangeType.Clear,
|
|
197
|
-
keys: new presentation_common_1.KeySet(),
|
|
198
|
-
timestamp: new Date(),
|
|
199
|
-
rulesetId,
|
|
200
|
-
};
|
|
201
|
-
this.handleEvent(evt);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Add keys to selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.
|
|
205
|
-
* @param source Name of the selection source
|
|
206
|
-
* @param imodel iModel associated with the selection
|
|
207
|
-
* @param ids Element IDs to add
|
|
208
|
-
* @param scope Selection scope to apply
|
|
209
|
-
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
210
|
-
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
211
|
-
*/
|
|
212
|
-
async addToSelectionWithScope(source, imodel, ids, scope, level = 0, rulesetId) {
|
|
213
|
-
const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);
|
|
214
|
-
this.addToSelection(source, imodel, scopedKeys, level, rulesetId);
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Remove keys from current selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.
|
|
218
|
-
* @param source Name of the selection source
|
|
219
|
-
* @param imodel iModel associated with the selection
|
|
220
|
-
* @param ids Element IDs to remove
|
|
221
|
-
* @param scope Selection scope to apply
|
|
222
|
-
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
223
|
-
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
224
|
-
*/
|
|
225
|
-
async removeFromSelectionWithScope(source, imodel, ids, scope, level = 0, rulesetId) {
|
|
226
|
-
const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);
|
|
227
|
-
this.removeFromSelection(source, imodel, scopedKeys, level, rulesetId);
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Replace current selection with keys after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.
|
|
231
|
-
* @param source Name of the selection source
|
|
232
|
-
* @param imodel iModel associated with the selection
|
|
233
|
-
* @param ids Element IDs to replace with
|
|
234
|
-
* @param scope Selection scope to apply
|
|
235
|
-
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
236
|
-
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
237
|
-
*/
|
|
238
|
-
async replaceSelectionWithScope(source, imodel, ids, scope, level = 0, rulesetId) {
|
|
239
|
-
const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);
|
|
240
|
-
this.replaceSelection(source, imodel, scopedKeys, level, rulesetId);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Get the current hilite set for the specified imodel
|
|
244
|
-
* @public
|
|
245
|
-
*/
|
|
246
|
-
async getHiliteSet(imodel) {
|
|
247
|
-
let provider = this._hiliteSetProviders.get(imodel);
|
|
248
|
-
if (!provider) {
|
|
249
|
-
provider = HiliteSetProvider_1.HiliteSetProvider.create({ imodel });
|
|
250
|
-
this._hiliteSetProviders.set(imodel, provider);
|
|
251
|
-
}
|
|
252
|
-
return provider.getHiliteSet(this.getSelection(imodel));
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
exports.SelectionManager = SelectionManager;
|
|
256
|
-
/** @internal */
|
|
257
|
-
class SelectionContainer {
|
|
258
|
-
constructor() {
|
|
259
|
-
this._selectedItemsSetMap = new Map();
|
|
260
|
-
}
|
|
261
|
-
getSelection(level) {
|
|
262
|
-
let selectedItemsSet = this._selectedItemsSetMap.get(level);
|
|
263
|
-
if (!selectedItemsSet) {
|
|
264
|
-
selectedItemsSet = new presentation_common_1.KeySet();
|
|
265
|
-
this._selectedItemsSetMap.set(level, selectedItemsSet);
|
|
266
|
-
}
|
|
267
|
-
return selectedItemsSet;
|
|
268
|
-
}
|
|
269
|
-
getSelectionLevels() {
|
|
270
|
-
const levels = new Array();
|
|
271
|
-
for (const entry of this._selectedItemsSetMap.entries()) {
|
|
272
|
-
if (!entry[1].isEmpty)
|
|
273
|
-
levels.push(entry[0]);
|
|
274
|
-
}
|
|
275
|
-
return levels.sort();
|
|
276
|
-
}
|
|
277
|
-
clear(level) {
|
|
278
|
-
const keys = this._selectedItemsSetMap.keys();
|
|
279
|
-
for (const key of keys) {
|
|
280
|
-
if (key >= level) {
|
|
281
|
-
const selectedItemsSet = this._selectedItemsSetMap.get(key);
|
|
282
|
-
selectedItemsSet.clear();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/** @internal */
|
|
288
|
-
exports.TRANSIENT_ELEMENT_CLASSNAME = "/TRANSIENT";
|
|
289
|
-
/** @internal */
|
|
290
|
-
class ToolSelectionSyncHandler {
|
|
291
|
-
constructor(imodel, logicalSelection) {
|
|
292
|
-
this._selectionSourceName = "Tool";
|
|
293
|
-
this._asyncsTracker = new presentation_common_1.AsyncTasksTracker();
|
|
294
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
295
|
-
this.onToolSelectionChanged = async (ev) => {
|
|
296
|
-
// ignore selection change event if the handler is suspended
|
|
297
|
-
if (this.isSuspended)
|
|
298
|
-
return;
|
|
299
|
-
// this component only cares about its own imodel
|
|
300
|
-
const imodel = ev.set.iModel;
|
|
301
|
-
if (imodel !== this._imodel)
|
|
302
|
-
return;
|
|
303
|
-
// determine the level of selection changes
|
|
304
|
-
// wip: may want to allow selecting at different levels?
|
|
305
|
-
const selectionLevel = 0;
|
|
306
|
-
let ids;
|
|
307
|
-
switch (ev.type) {
|
|
308
|
-
case core_frontend_1.SelectionSetEventType.Add:
|
|
309
|
-
ids = ev.added;
|
|
310
|
-
break;
|
|
311
|
-
case core_frontend_1.SelectionSetEventType.Replace:
|
|
312
|
-
ids = ev.set.elements;
|
|
313
|
-
break;
|
|
314
|
-
default:
|
|
315
|
-
ids = ev.removed;
|
|
316
|
-
break;
|
|
317
|
-
}
|
|
318
|
-
// we're always using scoped selection changer even if the scope is set to "element" - that
|
|
319
|
-
// makes sure we're adding to selection keys with concrete classes and not "BisCore:Element", which
|
|
320
|
-
// we can't because otherwise our keys compare fails (presentation components load data with
|
|
321
|
-
// concrete classes)
|
|
322
|
-
const changer = new ScopedSelectionChanger(this._selectionSourceName, this._imodel, this._logicalSelection, (0, SelectionScopesManager_1.createSelectionScopeProps)(this._logicalSelection.scopes.activeScope));
|
|
323
|
-
// we know what to do immediately on `clear` events
|
|
324
|
-
if (core_frontend_1.SelectionSetEventType.Clear === ev.type) {
|
|
325
|
-
await changer.clear(selectionLevel);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
const parsedIds = parseIds(ids);
|
|
329
|
-
await (0, core_bentley_1.using)(this._asyncsTracker.trackAsyncTask(), async (_r) => {
|
|
330
|
-
switch (ev.type) {
|
|
331
|
-
case core_frontend_1.SelectionSetEventType.Add:
|
|
332
|
-
await changer.add(parsedIds.transient, parsedIds.persistent, selectionLevel);
|
|
333
|
-
break;
|
|
334
|
-
case core_frontend_1.SelectionSetEventType.Replace:
|
|
335
|
-
await changer.replace(parsedIds.transient, parsedIds.persistent, selectionLevel);
|
|
336
|
-
break;
|
|
337
|
-
case core_frontend_1.SelectionSetEventType.Remove:
|
|
338
|
-
await changer.remove(parsedIds.transient, parsedIds.persistent, selectionLevel);
|
|
339
|
-
break;
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
};
|
|
343
|
-
this._imodel = imodel;
|
|
344
|
-
this._logicalSelection = logicalSelection;
|
|
345
|
-
this._imodelToolSelectionListenerDisposeFunc = imodel.selectionSet.onChanged.addListener(this.onToolSelectionChanged);
|
|
346
|
-
}
|
|
347
|
-
dispose() {
|
|
348
|
-
this._imodelToolSelectionListenerDisposeFunc();
|
|
349
|
-
}
|
|
350
|
-
/** note: used only it tests */
|
|
351
|
-
get pendingAsyncs() { return this._asyncsTracker.pendingAsyncs; }
|
|
352
|
-
}
|
|
353
|
-
exports.ToolSelectionSyncHandler = ToolSelectionSyncHandler;
|
|
354
|
-
const parseIds = (ids) => {
|
|
355
|
-
let allPersistent = true;
|
|
356
|
-
let allTransient = true;
|
|
357
|
-
for (const id of core_bentley_1.Id64.iterable(ids)) {
|
|
358
|
-
if (core_bentley_1.Id64.isTransient(id))
|
|
359
|
-
allPersistent = false;
|
|
360
|
-
else
|
|
361
|
-
allTransient = false;
|
|
362
|
-
if (!allPersistent && !allTransient)
|
|
363
|
-
break;
|
|
364
|
-
}
|
|
365
|
-
// avoid making a copy if ids are only persistent or only transient
|
|
366
|
-
if (allPersistent) {
|
|
367
|
-
return { persistent: ids, transient: [] };
|
|
368
|
-
}
|
|
369
|
-
else if (allTransient) {
|
|
370
|
-
return { persistent: [], transient: ids };
|
|
371
|
-
}
|
|
372
|
-
// if `ids` contain mixed ids, we have to copy.. use Array instead of
|
|
373
|
-
// a Set for performance
|
|
374
|
-
const persistentElementIds = [];
|
|
375
|
-
const transientElementIds = [];
|
|
376
|
-
for (const id of core_bentley_1.Id64.iterable(ids)) {
|
|
377
|
-
if (core_bentley_1.Id64.isTransient(id))
|
|
378
|
-
transientElementIds.push(id);
|
|
379
|
-
else
|
|
380
|
-
persistentElementIds.push(id);
|
|
381
|
-
}
|
|
382
|
-
return { persistent: persistentElementIds, transient: transientElementIds };
|
|
383
|
-
};
|
|
384
|
-
function addTransientKeys(transientIds, keys) {
|
|
385
|
-
for (const id of core_bentley_1.Id64.iterable(transientIds))
|
|
386
|
-
keys.add({ className: exports.TRANSIENT_ELEMENT_CLASSNAME, id });
|
|
387
|
-
}
|
|
388
|
-
/** @internal */
|
|
389
|
-
class ScopedSelectionChanger {
|
|
390
|
-
constructor(name, imodel, manager, scope) {
|
|
391
|
-
this.name = name;
|
|
392
|
-
this.imodel = imodel;
|
|
393
|
-
this.manager = manager;
|
|
394
|
-
this.scope = scope;
|
|
395
|
-
}
|
|
396
|
-
async clear(level) {
|
|
397
|
-
this.manager.clearSelection(this.name, this.imodel, level);
|
|
398
|
-
}
|
|
399
|
-
async add(transientIds, persistentIds, level) {
|
|
400
|
-
const keys = await this.manager.scopes.computeSelection(this.imodel, persistentIds, this.scope);
|
|
401
|
-
addTransientKeys(transientIds, keys);
|
|
402
|
-
this.manager.addToSelection(this.name, this.imodel, keys, level);
|
|
403
|
-
}
|
|
404
|
-
async remove(transientIds, persistentIds, level) {
|
|
405
|
-
const keys = await this.manager.scopes.computeSelection(this.imodel, persistentIds, this.scope);
|
|
406
|
-
addTransientKeys(transientIds, keys);
|
|
407
|
-
this.manager.removeFromSelection(this.name, this.imodel, keys, level);
|
|
408
|
-
}
|
|
409
|
-
async replace(transientIds, persistentIds, level) {
|
|
410
|
-
const keys = await this.manager.scopes.computeSelection(this.imodel, persistentIds, this.scope);
|
|
411
|
-
addTransientKeys(transientIds, keys);
|
|
412
|
-
this.manager.replaceSelection(this.name, this.imodel, keys, level);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
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 UnifiedSelection
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ToolSelectionSyncHandler = exports.TRANSIENT_ELEMENT_CLASSNAME = exports.SelectionManager = void 0;
|
|
11
|
+
const core_bentley_1 = require("@itwin/core-bentley");
|
|
12
|
+
const core_frontend_1 = require("@itwin/core-frontend");
|
|
13
|
+
const presentation_common_1 = require("@itwin/presentation-common");
|
|
14
|
+
const HiliteSetProvider_1 = require("./HiliteSetProvider");
|
|
15
|
+
const SelectionChangeEvent_1 = require("./SelectionChangeEvent");
|
|
16
|
+
const SelectionScopesManager_1 = require("./SelectionScopesManager");
|
|
17
|
+
/**
|
|
18
|
+
* The selection manager which stores the overall selection.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
class SelectionManager {
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instance of SelectionManager.
|
|
24
|
+
*/
|
|
25
|
+
constructor(props) {
|
|
26
|
+
this._selectionContainerMap = new Map();
|
|
27
|
+
this._imodelToolSelectionSyncHandlers = new Map();
|
|
28
|
+
this._hiliteSetProviders = new Map();
|
|
29
|
+
this.selectionChange = new SelectionChangeEvent_1.SelectionChangeEvent();
|
|
30
|
+
this.scopes = props.scopes;
|
|
31
|
+
core_frontend_1.IModelConnection.onClose.addListener((imodel) => {
|
|
32
|
+
this.onConnectionClose(imodel);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
onConnectionClose(imodel) {
|
|
36
|
+
this.clearSelection("Connection Close Event", imodel);
|
|
37
|
+
this._selectionContainerMap.delete(imodel);
|
|
38
|
+
this._hiliteSetProviders.delete(imodel);
|
|
39
|
+
}
|
|
40
|
+
getContainer(imodel) {
|
|
41
|
+
let selectionContainer = this._selectionContainerMap.get(imodel);
|
|
42
|
+
if (!selectionContainer) {
|
|
43
|
+
selectionContainer = new SelectionContainer();
|
|
44
|
+
this._selectionContainerMap.set(imodel, selectionContainer);
|
|
45
|
+
}
|
|
46
|
+
return selectionContainer;
|
|
47
|
+
}
|
|
48
|
+
/** @internal */
|
|
49
|
+
// istanbul ignore next
|
|
50
|
+
getToolSelectionSyncHandler(imodel) { var _a; return (_a = this._imodelToolSelectionSyncHandlers.get(imodel)) === null || _a === void 0 ? void 0 : _a.handler; }
|
|
51
|
+
/**
|
|
52
|
+
* Request the manager to sync with imodel's tool selection (see `IModelConnection.selectionSet`).
|
|
53
|
+
*/
|
|
54
|
+
setSyncWithIModelToolSelection(imodel, sync = true) {
|
|
55
|
+
const registration = this._imodelToolSelectionSyncHandlers.get(imodel);
|
|
56
|
+
if (sync) {
|
|
57
|
+
if (!registration || registration.requestorsCount === 0) {
|
|
58
|
+
this._imodelToolSelectionSyncHandlers.set(imodel, { requestorsCount: 1, handler: new ToolSelectionSyncHandler(imodel, this) });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount: registration.requestorsCount + 1 });
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (registration && registration.requestorsCount > 0) {
|
|
66
|
+
const requestorsCount = registration.requestorsCount - 1;
|
|
67
|
+
if (requestorsCount > 0) {
|
|
68
|
+
this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount });
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this._imodelToolSelectionSyncHandlers.delete(imodel);
|
|
72
|
+
registration.handler.dispose();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Temporarily suspends tool selection synchronization until the returned `IDisposable`
|
|
79
|
+
* is disposed.
|
|
80
|
+
*/
|
|
81
|
+
suspendIModelToolSelectionSync(imodel) {
|
|
82
|
+
const registration = this._imodelToolSelectionSyncHandlers.get(imodel);
|
|
83
|
+
if (!registration)
|
|
84
|
+
return { dispose: () => { } };
|
|
85
|
+
const wasSuspended = registration.handler.isSuspended;
|
|
86
|
+
registration.handler.isSuspended = true;
|
|
87
|
+
return { dispose: () => (registration.handler.isSuspended = wasSuspended) };
|
|
88
|
+
}
|
|
89
|
+
/** Get the selection levels currently stored in this manager for the specified imodel */
|
|
90
|
+
getSelectionLevels(imodel) {
|
|
91
|
+
return this.getContainer(imodel).getSelectionLevels();
|
|
92
|
+
}
|
|
93
|
+
/** Get the selection currently stored in this manager */
|
|
94
|
+
getSelection(imodel, level = 0) {
|
|
95
|
+
return this.getContainer(imodel).getSelection(level);
|
|
96
|
+
}
|
|
97
|
+
handleEvent(evt) {
|
|
98
|
+
const container = this.getContainer(evt.imodel);
|
|
99
|
+
const selectedItemsSet = container.getSelection(evt.level);
|
|
100
|
+
const guidBefore = selectedItemsSet.guid;
|
|
101
|
+
switch (evt.changeType) {
|
|
102
|
+
case SelectionChangeEvent_1.SelectionChangeType.Add:
|
|
103
|
+
selectedItemsSet.add(evt.keys);
|
|
104
|
+
break;
|
|
105
|
+
case SelectionChangeEvent_1.SelectionChangeType.Remove:
|
|
106
|
+
selectedItemsSet.delete(evt.keys);
|
|
107
|
+
break;
|
|
108
|
+
case SelectionChangeEvent_1.SelectionChangeType.Replace:
|
|
109
|
+
if (selectedItemsSet.size !== evt.keys.size || !selectedItemsSet.hasAll(evt.keys)) {
|
|
110
|
+
// note: the above check is only needed to avoid changing
|
|
111
|
+
// guid of the keyset if we're replacing keyset with the same keys
|
|
112
|
+
selectedItemsSet.clear().add(evt.keys);
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
case SelectionChangeEvent_1.SelectionChangeType.Clear:
|
|
116
|
+
selectedItemsSet.clear();
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
if (selectedItemsSet.guid === guidBefore)
|
|
120
|
+
return;
|
|
121
|
+
container.clear(evt.level + 1);
|
|
122
|
+
this.selectionChange.raiseEvent(evt, this);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Add keys to the selection
|
|
126
|
+
* @param source Name of the selection source
|
|
127
|
+
* @param imodel iModel associated with the selection
|
|
128
|
+
* @param keys Keys to add
|
|
129
|
+
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
130
|
+
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
131
|
+
*/
|
|
132
|
+
addToSelection(source, imodel, keys, level = 0, rulesetId) {
|
|
133
|
+
const evt = {
|
|
134
|
+
source,
|
|
135
|
+
level,
|
|
136
|
+
imodel,
|
|
137
|
+
changeType: SelectionChangeEvent_1.SelectionChangeType.Add,
|
|
138
|
+
keys: new presentation_common_1.KeySet(keys),
|
|
139
|
+
timestamp: new Date(),
|
|
140
|
+
rulesetId,
|
|
141
|
+
};
|
|
142
|
+
this.handleEvent(evt);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Remove keys from current selection
|
|
146
|
+
* @param source Name of the selection source
|
|
147
|
+
* @param imodel iModel associated with the selection
|
|
148
|
+
* @param keys Keys to remove
|
|
149
|
+
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
150
|
+
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
151
|
+
*/
|
|
152
|
+
removeFromSelection(source, imodel, keys, level = 0, rulesetId) {
|
|
153
|
+
const evt = {
|
|
154
|
+
source,
|
|
155
|
+
level,
|
|
156
|
+
imodel,
|
|
157
|
+
changeType: SelectionChangeEvent_1.SelectionChangeType.Remove,
|
|
158
|
+
keys: new presentation_common_1.KeySet(keys),
|
|
159
|
+
timestamp: new Date(),
|
|
160
|
+
rulesetId,
|
|
161
|
+
};
|
|
162
|
+
this.handleEvent(evt);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Replace current selection
|
|
166
|
+
* @param source Name of the selection source
|
|
167
|
+
* @param imodel iModel associated with the selection
|
|
168
|
+
* @param keys Keys to add
|
|
169
|
+
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
170
|
+
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
171
|
+
*/
|
|
172
|
+
replaceSelection(source, imodel, keys, level = 0, rulesetId) {
|
|
173
|
+
const evt = {
|
|
174
|
+
source,
|
|
175
|
+
level,
|
|
176
|
+
imodel,
|
|
177
|
+
changeType: SelectionChangeEvent_1.SelectionChangeType.Replace,
|
|
178
|
+
keys: new presentation_common_1.KeySet(keys),
|
|
179
|
+
timestamp: new Date(),
|
|
180
|
+
rulesetId,
|
|
181
|
+
};
|
|
182
|
+
this.handleEvent(evt);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Clear current selection
|
|
186
|
+
* @param source Name of the selection source
|
|
187
|
+
* @param imodel iModel associated with the selection
|
|
188
|
+
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
189
|
+
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
190
|
+
*/
|
|
191
|
+
clearSelection(source, imodel, level = 0, rulesetId) {
|
|
192
|
+
const evt = {
|
|
193
|
+
source,
|
|
194
|
+
level,
|
|
195
|
+
imodel,
|
|
196
|
+
changeType: SelectionChangeEvent_1.SelectionChangeType.Clear,
|
|
197
|
+
keys: new presentation_common_1.KeySet(),
|
|
198
|
+
timestamp: new Date(),
|
|
199
|
+
rulesetId,
|
|
200
|
+
};
|
|
201
|
+
this.handleEvent(evt);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Add keys to selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.
|
|
205
|
+
* @param source Name of the selection source
|
|
206
|
+
* @param imodel iModel associated with the selection
|
|
207
|
+
* @param ids Element IDs to add
|
|
208
|
+
* @param scope Selection scope to apply
|
|
209
|
+
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
210
|
+
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
211
|
+
*/
|
|
212
|
+
async addToSelectionWithScope(source, imodel, ids, scope, level = 0, rulesetId) {
|
|
213
|
+
const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);
|
|
214
|
+
this.addToSelection(source, imodel, scopedKeys, level, rulesetId);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Remove keys from current selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.
|
|
218
|
+
* @param source Name of the selection source
|
|
219
|
+
* @param imodel iModel associated with the selection
|
|
220
|
+
* @param ids Element IDs to remove
|
|
221
|
+
* @param scope Selection scope to apply
|
|
222
|
+
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
223
|
+
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
224
|
+
*/
|
|
225
|
+
async removeFromSelectionWithScope(source, imodel, ids, scope, level = 0, rulesetId) {
|
|
226
|
+
const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);
|
|
227
|
+
this.removeFromSelection(source, imodel, scopedKeys, level, rulesetId);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Replace current selection with keys after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.
|
|
231
|
+
* @param source Name of the selection source
|
|
232
|
+
* @param imodel iModel associated with the selection
|
|
233
|
+
* @param ids Element IDs to replace with
|
|
234
|
+
* @param scope Selection scope to apply
|
|
235
|
+
* @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))
|
|
236
|
+
* @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control
|
|
237
|
+
*/
|
|
238
|
+
async replaceSelectionWithScope(source, imodel, ids, scope, level = 0, rulesetId) {
|
|
239
|
+
const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);
|
|
240
|
+
this.replaceSelection(source, imodel, scopedKeys, level, rulesetId);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Get the current hilite set for the specified imodel
|
|
244
|
+
* @public
|
|
245
|
+
*/
|
|
246
|
+
async getHiliteSet(imodel) {
|
|
247
|
+
let provider = this._hiliteSetProviders.get(imodel);
|
|
248
|
+
if (!provider) {
|
|
249
|
+
provider = HiliteSetProvider_1.HiliteSetProvider.create({ imodel });
|
|
250
|
+
this._hiliteSetProviders.set(imodel, provider);
|
|
251
|
+
}
|
|
252
|
+
return provider.getHiliteSet(this.getSelection(imodel));
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.SelectionManager = SelectionManager;
|
|
256
|
+
/** @internal */
|
|
257
|
+
class SelectionContainer {
|
|
258
|
+
constructor() {
|
|
259
|
+
this._selectedItemsSetMap = new Map();
|
|
260
|
+
}
|
|
261
|
+
getSelection(level) {
|
|
262
|
+
let selectedItemsSet = this._selectedItemsSetMap.get(level);
|
|
263
|
+
if (!selectedItemsSet) {
|
|
264
|
+
selectedItemsSet = new presentation_common_1.KeySet();
|
|
265
|
+
this._selectedItemsSetMap.set(level, selectedItemsSet);
|
|
266
|
+
}
|
|
267
|
+
return selectedItemsSet;
|
|
268
|
+
}
|
|
269
|
+
getSelectionLevels() {
|
|
270
|
+
const levels = new Array();
|
|
271
|
+
for (const entry of this._selectedItemsSetMap.entries()) {
|
|
272
|
+
if (!entry[1].isEmpty)
|
|
273
|
+
levels.push(entry[0]);
|
|
274
|
+
}
|
|
275
|
+
return levels.sort();
|
|
276
|
+
}
|
|
277
|
+
clear(level) {
|
|
278
|
+
const keys = this._selectedItemsSetMap.keys();
|
|
279
|
+
for (const key of keys) {
|
|
280
|
+
if (key >= level) {
|
|
281
|
+
const selectedItemsSet = this._selectedItemsSetMap.get(key);
|
|
282
|
+
selectedItemsSet.clear();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/** @internal */
|
|
288
|
+
exports.TRANSIENT_ELEMENT_CLASSNAME = "/TRANSIENT";
|
|
289
|
+
/** @internal */
|
|
290
|
+
class ToolSelectionSyncHandler {
|
|
291
|
+
constructor(imodel, logicalSelection) {
|
|
292
|
+
this._selectionSourceName = "Tool";
|
|
293
|
+
this._asyncsTracker = new presentation_common_1.AsyncTasksTracker();
|
|
294
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
295
|
+
this.onToolSelectionChanged = async (ev) => {
|
|
296
|
+
// ignore selection change event if the handler is suspended
|
|
297
|
+
if (this.isSuspended)
|
|
298
|
+
return;
|
|
299
|
+
// this component only cares about its own imodel
|
|
300
|
+
const imodel = ev.set.iModel;
|
|
301
|
+
if (imodel !== this._imodel)
|
|
302
|
+
return;
|
|
303
|
+
// determine the level of selection changes
|
|
304
|
+
// wip: may want to allow selecting at different levels?
|
|
305
|
+
const selectionLevel = 0;
|
|
306
|
+
let ids;
|
|
307
|
+
switch (ev.type) {
|
|
308
|
+
case core_frontend_1.SelectionSetEventType.Add:
|
|
309
|
+
ids = ev.added;
|
|
310
|
+
break;
|
|
311
|
+
case core_frontend_1.SelectionSetEventType.Replace:
|
|
312
|
+
ids = ev.set.elements;
|
|
313
|
+
break;
|
|
314
|
+
default:
|
|
315
|
+
ids = ev.removed;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
// we're always using scoped selection changer even if the scope is set to "element" - that
|
|
319
|
+
// makes sure we're adding to selection keys with concrete classes and not "BisCore:Element", which
|
|
320
|
+
// we can't because otherwise our keys compare fails (presentation components load data with
|
|
321
|
+
// concrete classes)
|
|
322
|
+
const changer = new ScopedSelectionChanger(this._selectionSourceName, this._imodel, this._logicalSelection, (0, SelectionScopesManager_1.createSelectionScopeProps)(this._logicalSelection.scopes.activeScope));
|
|
323
|
+
// we know what to do immediately on `clear` events
|
|
324
|
+
if (core_frontend_1.SelectionSetEventType.Clear === ev.type) {
|
|
325
|
+
await changer.clear(selectionLevel);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const parsedIds = parseIds(ids);
|
|
329
|
+
await (0, core_bentley_1.using)(this._asyncsTracker.trackAsyncTask(), async (_r) => {
|
|
330
|
+
switch (ev.type) {
|
|
331
|
+
case core_frontend_1.SelectionSetEventType.Add:
|
|
332
|
+
await changer.add(parsedIds.transient, parsedIds.persistent, selectionLevel);
|
|
333
|
+
break;
|
|
334
|
+
case core_frontend_1.SelectionSetEventType.Replace:
|
|
335
|
+
await changer.replace(parsedIds.transient, parsedIds.persistent, selectionLevel);
|
|
336
|
+
break;
|
|
337
|
+
case core_frontend_1.SelectionSetEventType.Remove:
|
|
338
|
+
await changer.remove(parsedIds.transient, parsedIds.persistent, selectionLevel);
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
this._imodel = imodel;
|
|
344
|
+
this._logicalSelection = logicalSelection;
|
|
345
|
+
this._imodelToolSelectionListenerDisposeFunc = imodel.selectionSet.onChanged.addListener(this.onToolSelectionChanged);
|
|
346
|
+
}
|
|
347
|
+
dispose() {
|
|
348
|
+
this._imodelToolSelectionListenerDisposeFunc();
|
|
349
|
+
}
|
|
350
|
+
/** note: used only it tests */
|
|
351
|
+
get pendingAsyncs() { return this._asyncsTracker.pendingAsyncs; }
|
|
352
|
+
}
|
|
353
|
+
exports.ToolSelectionSyncHandler = ToolSelectionSyncHandler;
|
|
354
|
+
const parseIds = (ids) => {
|
|
355
|
+
let allPersistent = true;
|
|
356
|
+
let allTransient = true;
|
|
357
|
+
for (const id of core_bentley_1.Id64.iterable(ids)) {
|
|
358
|
+
if (core_bentley_1.Id64.isTransient(id))
|
|
359
|
+
allPersistent = false;
|
|
360
|
+
else
|
|
361
|
+
allTransient = false;
|
|
362
|
+
if (!allPersistent && !allTransient)
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
// avoid making a copy if ids are only persistent or only transient
|
|
366
|
+
if (allPersistent) {
|
|
367
|
+
return { persistent: ids, transient: [] };
|
|
368
|
+
}
|
|
369
|
+
else if (allTransient) {
|
|
370
|
+
return { persistent: [], transient: ids };
|
|
371
|
+
}
|
|
372
|
+
// if `ids` contain mixed ids, we have to copy.. use Array instead of
|
|
373
|
+
// a Set for performance
|
|
374
|
+
const persistentElementIds = [];
|
|
375
|
+
const transientElementIds = [];
|
|
376
|
+
for (const id of core_bentley_1.Id64.iterable(ids)) {
|
|
377
|
+
if (core_bentley_1.Id64.isTransient(id))
|
|
378
|
+
transientElementIds.push(id);
|
|
379
|
+
else
|
|
380
|
+
persistentElementIds.push(id);
|
|
381
|
+
}
|
|
382
|
+
return { persistent: persistentElementIds, transient: transientElementIds };
|
|
383
|
+
};
|
|
384
|
+
function addTransientKeys(transientIds, keys) {
|
|
385
|
+
for (const id of core_bentley_1.Id64.iterable(transientIds))
|
|
386
|
+
keys.add({ className: exports.TRANSIENT_ELEMENT_CLASSNAME, id });
|
|
387
|
+
}
|
|
388
|
+
/** @internal */
|
|
389
|
+
class ScopedSelectionChanger {
|
|
390
|
+
constructor(name, imodel, manager, scope) {
|
|
391
|
+
this.name = name;
|
|
392
|
+
this.imodel = imodel;
|
|
393
|
+
this.manager = manager;
|
|
394
|
+
this.scope = scope;
|
|
395
|
+
}
|
|
396
|
+
async clear(level) {
|
|
397
|
+
this.manager.clearSelection(this.name, this.imodel, level);
|
|
398
|
+
}
|
|
399
|
+
async add(transientIds, persistentIds, level) {
|
|
400
|
+
const keys = await this.manager.scopes.computeSelection(this.imodel, persistentIds, this.scope);
|
|
401
|
+
addTransientKeys(transientIds, keys);
|
|
402
|
+
this.manager.addToSelection(this.name, this.imodel, keys, level);
|
|
403
|
+
}
|
|
404
|
+
async remove(transientIds, persistentIds, level) {
|
|
405
|
+
const keys = await this.manager.scopes.computeSelection(this.imodel, persistentIds, this.scope);
|
|
406
|
+
addTransientKeys(transientIds, keys);
|
|
407
|
+
this.manager.removeFromSelection(this.name, this.imodel, keys, level);
|
|
408
|
+
}
|
|
409
|
+
async replace(transientIds, persistentIds, level) {
|
|
410
|
+
const keys = await this.manager.scopes.computeSelection(this.imodel, persistentIds, this.scope);
|
|
411
|
+
addTransientKeys(transientIds, keys);
|
|
412
|
+
this.manager.replaceSelection(this.name, this.imodel, keys, level);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
415
|
//# sourceMappingURL=SelectionManager.js.map
|