@itwin/presentation-frontend 5.0.0-dev.25 → 5.0.0-dev.28
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/selection/SelectionManager.d.ts +14 -1
- package/lib/cjs/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
- package/lib/cjs/presentation-frontend/selection/SelectionManager.js +32 -21
- package/lib/cjs/presentation-frontend/selection/SelectionManager.js.map +1 -1
- package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts +14 -1
- package/lib/esm/presentation-frontend/selection/SelectionManager.d.ts.map +1 -1
- package/lib/esm/presentation-frontend/selection/SelectionManager.js +32 -21
- package/lib/esm/presentation-frontend/selection/SelectionManager.js.map +1 -1
- package/package.json +16 -16
|
@@ -21,13 +21,21 @@ export interface SelectionManagerProps {
|
|
|
21
21
|
* and maintains storage.
|
|
22
22
|
*/
|
|
23
23
|
selectionStorage?: SelectionStorage;
|
|
24
|
+
/**
|
|
25
|
+
* An optional function that returns a key for the given iModel. The key is what "glues" iModel selection
|
|
26
|
+
* changes made in `selectionStorage`, where iModels are identified by key, and `SelectionManager`, where
|
|
27
|
+
* iModels are specified as `IModelConnection`.
|
|
28
|
+
*
|
|
29
|
+
* If not provided, [IModelConnection.key]($core-frontend) or [IModelConnection.name]($core-frontend) is used.
|
|
30
|
+
*/
|
|
31
|
+
imodelKeyFactory?: (imodel: IModelConnection) => string;
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* The selection manager which stores the overall selection.
|
|
27
35
|
* @public
|
|
28
36
|
*/
|
|
29
37
|
export declare class SelectionManager implements ISelectionProvider {
|
|
30
|
-
private
|
|
38
|
+
private _imodelKeyFactory;
|
|
31
39
|
private _imodelToolSelectionSyncHandlers;
|
|
32
40
|
private _hiliteSetProviders;
|
|
33
41
|
private _ownsStorage;
|
|
@@ -36,6 +44,11 @@ export declare class SelectionManager implements ISelectionProvider {
|
|
|
36
44
|
private _selectionChanges;
|
|
37
45
|
private _selectionEventsSubscription;
|
|
38
46
|
private _listeners;
|
|
47
|
+
/**
|
|
48
|
+
* Underlying selection storage used by this selection manager. Ideally, consumers should use
|
|
49
|
+
* the storage directly instead of using this manager to manipulate selection.
|
|
50
|
+
*/
|
|
51
|
+
readonly selectionStorage: SelectionStorage;
|
|
39
52
|
/** An event which gets broadcasted on selection changes */
|
|
40
53
|
readonly selectionChange: SelectionChangeEvent;
|
|
41
54
|
/** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionManager.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAQ,OAAO,EAAa,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAA2D,MAAM,sBAAsB,CAAC;AACjH,OAAO,EAAoD,IAAI,EAAE,MAAM,EAAW,cAAc,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC1J,OAAO,EAKL,gBAAgB,EAIjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAAqB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAiD,MAAM,wBAAwB,CAAC;AAC7G,OAAO,EAA6B,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,oGAAoG;IACpG,MAAM,EAAE,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"SelectionManager.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAQ,OAAO,EAAa,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACnF,OA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34
|
constructor(props) {
|
|
35
35
|
this._imodelToolSelectionSyncHandlers = new Map();
|
|
36
36
|
this._hiliteSetProviders = new Map();
|
|
37
|
-
this._knownIModels = new
|
|
37
|
+
this._knownIModels = new Set();
|
|
38
38
|
this._currentSelection = new CurrentSelectionStorage();
|
|
39
39
|
this._selectionChanges = new rxjs_1.Subject();
|
|
40
40
|
this._listeners = [];
|
|
41
41
|
this.selectionChange = new SelectionChangeEvent_1.SelectionChangeEvent();
|
|
42
42
|
this.scopes = props.scopes;
|
|
43
|
-
this.
|
|
43
|
+
this.selectionStorage = props.selectionStorage ?? (0, unified_selection_1.createStorage)();
|
|
44
|
+
this._imodelKeyFactory = props.imodelKeyFactory ?? ((imodel) => (imodel.key.length ? imodel.key : imodel.name));
|
|
44
45
|
this._ownsStorage = props.selectionStorage === undefined;
|
|
45
|
-
this.
|
|
46
|
+
this.selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));
|
|
46
47
|
this._selectionEventsSubscription = this.streamSelectionEvents();
|
|
47
48
|
this._listeners.push(core_frontend_1.IModelConnection.onOpen.addListener((imodel) => {
|
|
48
|
-
this._knownIModels.
|
|
49
|
+
this._knownIModels.add(imodel);
|
|
49
50
|
}));
|
|
50
51
|
this._listeners.push(core_frontend_1.IModelConnection.onClose.addListener((imodel) => {
|
|
51
52
|
this.onConnectionClose(imodel);
|
|
@@ -56,12 +57,13 @@ class SelectionManager {
|
|
|
56
57
|
this._listeners.forEach((dispose) => dispose());
|
|
57
58
|
}
|
|
58
59
|
onConnectionClose(imodel) {
|
|
60
|
+
const imodelKey = this._imodelKeyFactory(imodel);
|
|
59
61
|
this._hiliteSetProviders.delete(imodel);
|
|
60
|
-
this._knownIModels.delete(imodel
|
|
61
|
-
this._currentSelection.clear(
|
|
62
|
+
this._knownIModels.delete(imodel);
|
|
63
|
+
this._currentSelection.clear(imodelKey);
|
|
62
64
|
if (this._ownsStorage) {
|
|
63
65
|
this.clearSelection("Connection Close Event", imodel);
|
|
64
|
-
this.
|
|
66
|
+
this.selectionStorage.clearStorage({ imodelKey });
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
/** @internal */
|
|
@@ -110,7 +112,8 @@ class SelectionManager {
|
|
|
110
112
|
}
|
|
111
113
|
/** Get the selection levels currently stored in this manager for the specified imodel */
|
|
112
114
|
getSelectionLevels(imodel) {
|
|
113
|
-
|
|
115
|
+
const imodelKey = this._imodelKeyFactory(imodel);
|
|
116
|
+
return this.selectionStorage.getSelectionLevels({ imodelKey });
|
|
114
117
|
}
|
|
115
118
|
/**
|
|
116
119
|
* Get the selection currently stored in this manager
|
|
@@ -120,39 +123,39 @@ class SelectionManager {
|
|
|
120
123
|
* latest selection after changes.
|
|
121
124
|
*/
|
|
122
125
|
getSelection(imodel, level = 0) {
|
|
123
|
-
|
|
126
|
+
const imodelKey = this._imodelKeyFactory(imodel);
|
|
127
|
+
return this._currentSelection.getSelection(imodelKey, level);
|
|
124
128
|
}
|
|
125
129
|
handleEvent(evt) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
130
|
+
const imodelKey = this._imodelKeyFactory(evt.imodel);
|
|
131
|
+
this._knownIModels.add(evt.imodel);
|
|
129
132
|
switch (evt.changeType) {
|
|
130
133
|
case SelectionChangeEvent_1.SelectionChangeType.Add:
|
|
131
|
-
this.
|
|
132
|
-
|
|
134
|
+
this.selectionStorage.addToSelection({
|
|
135
|
+
imodelKey,
|
|
133
136
|
source: evt.source,
|
|
134
137
|
level: evt.level,
|
|
135
138
|
selectables: keysToSelectable(evt.imodel, evt.keys),
|
|
136
139
|
});
|
|
137
140
|
break;
|
|
138
141
|
case SelectionChangeEvent_1.SelectionChangeType.Remove:
|
|
139
|
-
this.
|
|
140
|
-
|
|
142
|
+
this.selectionStorage.removeFromSelection({
|
|
143
|
+
imodelKey,
|
|
141
144
|
source: evt.source,
|
|
142
145
|
level: evt.level,
|
|
143
146
|
selectables: keysToSelectable(evt.imodel, evt.keys),
|
|
144
147
|
});
|
|
145
148
|
break;
|
|
146
149
|
case SelectionChangeEvent_1.SelectionChangeType.Replace:
|
|
147
|
-
this.
|
|
148
|
-
|
|
150
|
+
this.selectionStorage.replaceSelection({
|
|
151
|
+
imodelKey,
|
|
149
152
|
source: evt.source,
|
|
150
153
|
level: evt.level,
|
|
151
154
|
selectables: keysToSelectable(evt.imodel, evt.keys),
|
|
152
155
|
});
|
|
153
156
|
break;
|
|
154
157
|
case SelectionChangeEvent_1.SelectionChangeType.Clear:
|
|
155
|
-
this.
|
|
158
|
+
this.selectionStorage.clearSelection({ imodelKey, source: evt.source, level: evt.level });
|
|
156
159
|
break;
|
|
157
160
|
}
|
|
158
161
|
}
|
|
@@ -299,9 +302,9 @@ class SelectionManager {
|
|
|
299
302
|
streamSelectionEvents() {
|
|
300
303
|
return this._selectionChanges
|
|
301
304
|
.pipe((0, rxjs_1.mergeMap)((args) => {
|
|
302
|
-
const currentSelectables = this.
|
|
305
|
+
const currentSelectables = this.selectionStorage.getSelection({ imodelKey: args.imodelKey, level: args.level });
|
|
303
306
|
return this._currentSelection.computeSelection(args.imodelKey, args.level, currentSelectables, args.selectables).pipe((0, rxjs_1.mergeMap)(({ level, changedSelection }) => {
|
|
304
|
-
const imodel = this._knownIModels.
|
|
307
|
+
const imodel = findIModel(this._knownIModels, this._imodelKeyFactory, args.imodelKey);
|
|
305
308
|
// istanbul ignore if
|
|
306
309
|
if (!imodel) {
|
|
307
310
|
return rxjs_1.EMPTY;
|
|
@@ -324,6 +327,14 @@ class SelectionManager {
|
|
|
324
327
|
}
|
|
325
328
|
}
|
|
326
329
|
exports.SelectionManager = SelectionManager;
|
|
330
|
+
function findIModel(set, imodelKeyFactory, key) {
|
|
331
|
+
for (const imodel of set) {
|
|
332
|
+
if (imodelKeyFactory(imodel) === key) {
|
|
333
|
+
return imodel;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
327
338
|
/** @internal */
|
|
328
339
|
class ToolSelectionSyncHandler {
|
|
329
340
|
constructor(imodel, logicalSelection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionManager.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;AAEH,+BAAqG;AACrG,sDAAmF;AACnF,wDAAiH;AACjH,oEAA0J;AAC1J,gEASkC;AAClC,kDAA+C;AAC/C,2DAAmE;AAEnE,iEAA6G;AAC7G,qEAA6F;AAgB7F;;;GAGG;AACH,MAAa,gBAAgB;IAkB3B;;OAEG;IACH,YAAY,KAA4B;QAnBhC,qCAAgC,GAAG,IAAI,GAAG,EAAoF,CAAC;QAC/H,wBAAmB,GAAG,IAAI,GAAG,EAAuC,CAAC;QAGrE,kBAAa,GAAG,IAAI,GAAG,EAA4B,CAAC;QACpD,sBAAiB,GAAG,IAAI,uBAAuB,EAAE,CAAC;QAClD,sBAAiB,GAAG,IAAI,cAAO,EAAmC,CAAC;QAEnE,eAAU,GAAsB,EAAE,CAAC;QAYzC,IAAI,CAAC,eAAe,GAAG,IAAI,2CAAoB,EAAE,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,IAAI,IAAA,iCAAa,GAAE,CAAC;QACnE,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,gBAAgB,KAAK,SAAS,CAAC;QACzD,IAAI,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACrG,IAAI,CAAC,4BAA4B,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACjE,IAAI,CAAC,UAAU,CAAC,IAAI,CAClB,gCAAgB,CAAC,MAAM,CAAC,WAAW,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AAO,CAAC,CAAC;QAC3B,WAAW,EAAE;YACX,EAAE,EAAE,mBAAmB;YACvB,KAAK,EAAE;gBACL;oBACE,QAAQ,EAAE,SAAS;oBACnB,cAAc,EAAE;wBACd;4BACE,QAAQ,EAAE,uBAAuB;yBAClC;qBACF;iBACF;aACF;SACF;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC9B,MAAM,GAAG,GAAG,IAAmB,CAAC;IAChC,OAAO,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC;AAClE,CAAC;AAED,SAAS,aAAa,CAAC,IAAgC;IACrD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK;YACR,OAAO,0CAAmB,CAAC,GAAG,CAAC;QACjC,KAAK,QAAQ;YACX,OAAO,0CAAmB,CAAC,MAAM,CAAC;QACpC,KAAK,SAAS;YACZ,OAAO,0CAAmB,CAAC,OAAO,CAAC;QACrC,KAAK,OAAO;YACV,OAAO,0CAAmB,CAAC,KAAK,CAAC;IACrC,CAAC;AACH,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 UnifiedSelection\r\n */\r\n\r\nimport { defer, EMPTY, mergeMap, Observable, of, Subject, Subscription, takeUntil, tap } from \"rxjs\";\r\nimport { Id64, Id64Arg, Id64Array, IDisposable, using } from \"@itwin/core-bentley\";\r\nimport { IModelConnection, SelectableIds, SelectionSetEvent, SelectionSetEventType } from \"@itwin/core-frontend\";\r\nimport { AsyncTasksTracker, BaseNodeKey, InstanceKey, Key, Keys, KeySet, NodeKey, SelectionScope, SelectionScopeProps } from \"@itwin/presentation-common\";\r\nimport {\r\n createStorage,\r\n CustomSelectable,\r\n Selectable,\r\n Selectables,\r\n SelectionStorage,\r\n StorageSelectionChangeEventArgs,\r\n StorageSelectionChangeType,\r\n TRANSIENT_ELEMENT_CLASSNAME,\r\n} from \"@itwin/unified-selection\";\r\nimport { Presentation } from \"../Presentation\";\r\nimport { HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider\";\r\nimport { ISelectionProvider } from \"./ISelectionProvider\";\r\nimport { SelectionChangeEvent, SelectionChangeEventArgs, SelectionChangeType } from \"./SelectionChangeEvent\";\r\nimport { createSelectionScopeProps, SelectionScopesManager } from \"./SelectionScopesManager\";\r\n\r\n/**\r\n * Properties for creating [[SelectionManager]].\r\n * @public\r\n */\r\nexport interface SelectionManagerProps {\r\n /** A manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n scopes: SelectionScopesManager;\r\n /**\r\n * Custom unified selection storage to be used by [[SelectionManager]]. If not provided [[SelectionManager]] creates\r\n * and maintains storage.\r\n */\r\n selectionStorage?: SelectionStorage;\r\n}\r\n\r\n/**\r\n * The selection manager which stores the overall selection.\r\n * @public\r\n */\r\nexport class SelectionManager implements ISelectionProvider {\r\n private _selectionStorage: SelectionStorage;\r\n private _imodelToolSelectionSyncHandlers = new Map<IModelConnection, { requestorsCount: number; handler: ToolSelectionSyncHandler }>();\r\n private _hiliteSetProviders = new Map<IModelConnection, HiliteSetProvider>();\r\n private _ownsStorage: boolean;\r\n\r\n private _knownIModels = new Map<string, IModelConnection>();\r\n private _currentSelection = new CurrentSelectionStorage();\r\n private _selectionChanges = new Subject<StorageSelectionChangeEventArgs>();\r\n private _selectionEventsSubscription: Subscription;\r\n private _listeners: Array<() => void> = [];\r\n\r\n /** An event which gets broadcasted on selection changes */\r\n public readonly selectionChange: SelectionChangeEvent;\r\n\r\n /** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n public readonly scopes: SelectionScopesManager;\r\n\r\n /**\r\n * Creates an instance of SelectionManager.\r\n */\r\n constructor(props: SelectionManagerProps) {\r\n this.selectionChange = new SelectionChangeEvent();\r\n this.scopes = props.scopes;\r\n this._selectionStorage = props.selectionStorage ?? createStorage();\r\n this._ownsStorage = props.selectionStorage === undefined;\r\n this._selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));\r\n this._selectionEventsSubscription = this.streamSelectionEvents();\r\n this._listeners.push(\r\n IModelConnection.onOpen.addListener((imodel) => {\r\n this._knownIModels.set(imodel.key, imodel);\r\n }),\r\n );\r\n this._listeners.push(\r\n IModelConnection.onClose.addListener((imodel: IModelConnection) => {\r\n this.onConnectionClose(imodel);\r\n }),\r\n );\r\n }\r\n\r\n public dispose() {\r\n this._selectionEventsSubscription.unsubscribe();\r\n this._listeners.forEach((dispose) => dispose());\r\n }\r\n\r\n private onConnectionClose(imodel: IModelConnection): void {\r\n this._hiliteSetProviders.delete(imodel);\r\n this._knownIModels.delete(imodel.key);\r\n this._currentSelection.clear(imodel.key);\r\n if (this._ownsStorage) {\r\n this.clearSelection(\"Connection Close Event\", imodel);\r\n this._selectionStorage.clearStorage({ iModelKey: imodel.key });\r\n }\r\n }\r\n\r\n /** @internal */\r\n // istanbul ignore next\r\n public getToolSelectionSyncHandler(imodel: IModelConnection) {\r\n return this._imodelToolSelectionSyncHandlers.get(imodel)?.handler;\r\n }\r\n\r\n /**\r\n * Request the manager to sync with imodel's tool selection (see `IModelConnection.selectionSet`).\r\n */\r\n public setSyncWithIModelToolSelection(imodel: IModelConnection, sync = true) {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (sync) {\r\n if (!registration || registration.requestorsCount === 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { requestorsCount: 1, handler: new ToolSelectionSyncHandler(imodel, this) });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount: registration.requestorsCount + 1 });\r\n }\r\n } else {\r\n if (registration && registration.requestorsCount > 0) {\r\n const requestorsCount = registration.requestorsCount - 1;\r\n if (requestorsCount > 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.delete(imodel);\r\n registration.handler.dispose();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Temporarily suspends tool selection synchronization until the returned `IDisposable`\r\n * is disposed.\r\n */\r\n public suspendIModelToolSelectionSync(imodel: IModelConnection): IDisposable {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (!registration) {\r\n return { dispose: () => {} };\r\n }\r\n\r\n const wasSuspended = registration.handler.isSuspended;\r\n registration.handler.isSuspended = true;\r\n return { dispose: () => (registration.handler.isSuspended = wasSuspended) };\r\n }\r\n\r\n /** Get the selection levels currently stored in this manager for the specified imodel */\r\n public getSelectionLevels(imodel: IModelConnection): number[] {\r\n return this._selectionStorage.getSelectionLevels({ iModelKey: imodel.key });\r\n }\r\n\r\n /**\r\n * Get the selection currently stored in this manager\r\n *\r\n * @note Calling immediately after `add*`|`replace*`|`remove*`|`clear*` method call does not guarantee\r\n * that returned `KeySet` will include latest changes. Listen for `selectionChange` event to get the\r\n * latest selection after changes.\r\n */\r\n public getSelection(imodel: IModelConnection, level: number = 0): Readonly<KeySet> {\r\n return this._currentSelection.getSelection(imodel.key, level);\r\n }\r\n\r\n private handleEvent(evt: SelectionChangeEventArgs): void {\r\n if (!this._knownIModels.has(evt.imodel.key)) {\r\n this._knownIModels.set(evt.imodel.key, evt.imodel);\r\n }\r\n\r\n switch (evt.changeType) {\r\n case SelectionChangeType.Add:\r\n this._selectionStorage.addToSelection({\r\n iModelKey: evt.imodel.key,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Remove:\r\n this._selectionStorage.removeFromSelection({\r\n iModelKey: evt.imodel.key,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Replace:\r\n this._selectionStorage.replaceSelection({\r\n iModelKey: evt.imodel.key,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Clear:\r\n this._selectionStorage.clearSelection({ iModelKey: evt.imodel.key, source: evt.source, level: evt.level });\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Add keys to the selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public addToSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Add,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to remove\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public removeFromSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Remove,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Replace current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public replaceSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Replace,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Clear current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public clearSelection(source: string, imodel: IModelConnection, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Clear,\r\n keys: new KeySet(),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Add keys to selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to add\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async addToSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.addToSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to remove\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async removeFromSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.removeFromSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Replace current selection with keys after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to replace with\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async replaceSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.replaceSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Get the current hilite set for the specified imodel\r\n * @public\r\n */\r\n public async getHiliteSet(imodel: IModelConnection): Promise<HiliteSet> {\r\n return this.getHiliteSetProvider(imodel).getHiliteSet(this.getSelection(imodel));\r\n }\r\n\r\n /**\r\n * Get the current hilite set iterator for the specified imodel.\r\n * @public\r\n */\r\n public getHiliteSetIterator(imodel: IModelConnection) {\r\n return this.getHiliteSetProvider(imodel).getHiliteSetIterator(this.getSelection(imodel));\r\n }\r\n\r\n private getHiliteSetProvider(imodel: IModelConnection) {\r\n let provider = this._hiliteSetProviders.get(imodel);\r\n if (!provider) {\r\n provider = HiliteSetProvider.create({ imodel });\r\n this._hiliteSetProviders.set(imodel, provider);\r\n }\r\n return provider;\r\n }\r\n\r\n private streamSelectionEvents() {\r\n return this._selectionChanges\r\n .pipe(\r\n mergeMap((args) => {\r\n const currentSelectables = this._selectionStorage.getSelection({ iModelKey: args.imodelKey, level: args.level });\r\n return this._currentSelection.computeSelection(args.imodelKey, args.level, currentSelectables, args.selectables).pipe(\r\n mergeMap(({ level, changedSelection }): Observable<SelectionChangeEventArgs> => {\r\n const imodel = this._knownIModels.get(args.imodelKey);\r\n // istanbul ignore if\r\n if (!imodel) {\r\n return EMPTY;\r\n }\r\n return of({\r\n imodel,\r\n keys: changedSelection,\r\n level,\r\n source: args.source,\r\n timestamp: args.timestamp,\r\n changeType: getChangeType(args.changeType),\r\n });\r\n }),\r\n );\r\n }),\r\n )\r\n .subscribe({\r\n next: (args) => {\r\n this.selectionChange.raiseEvent(args, this);\r\n },\r\n });\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class ToolSelectionSyncHandler implements IDisposable {\r\n private _selectionSourceName = \"Tool\";\r\n private _logicalSelection: SelectionManager;\r\n private _imodel: IModelConnection;\r\n private _imodelToolSelectionListenerDisposeFunc: () => void;\r\n private _asyncsTracker = new AsyncTasksTracker();\r\n public isSuspended?: boolean;\r\n\r\n public constructor(imodel: IModelConnection, logicalSelection: SelectionManager) {\r\n this._imodel = imodel;\r\n this._logicalSelection = logicalSelection;\r\n this._imodelToolSelectionListenerDisposeFunc = imodel.selectionSet.onChanged.addListener(this.onToolSelectionChanged);\r\n }\r\n\r\n public dispose() {\r\n this._imodelToolSelectionListenerDisposeFunc();\r\n }\r\n\r\n /** note: used only it tests */\r\n public get pendingAsyncs() {\r\n return this._asyncsTracker.pendingAsyncs;\r\n }\r\n\r\n private onToolSelectionChanged = async (ev: SelectionSetEvent): Promise<void> => {\r\n // ignore selection change event if the handler is suspended\r\n if (this.isSuspended) {\r\n return;\r\n }\r\n\r\n // this component only cares about its own imodel\r\n const imodel = ev.set.iModel;\r\n if (imodel !== this._imodel) {\r\n return;\r\n }\r\n\r\n // determine the level of selection changes\r\n // wip: may want to allow selecting at different levels?\r\n const selectionLevel = 0;\r\n\r\n let ids: SelectableIds;\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n ids = ev.additions;\r\n break;\r\n case SelectionSetEventType.Replace:\r\n ids = ev.set.active;\r\n break;\r\n default:\r\n ids = ev.removals;\r\n break;\r\n }\r\n\r\n // we're always using scoped selection changer even if the scope is set to \"element\" - that\r\n // makes sure we're adding to selection keys with concrete classes and not \"BisCore:Element\", which\r\n // we can't because otherwise our keys compare fails (presentation components load data with\r\n // concrete classes)\r\n const changer = new ScopedSelectionChanger(\r\n this._selectionSourceName,\r\n this._imodel,\r\n this._logicalSelection,\r\n createSelectionScopeProps(this._logicalSelection.scopes.activeScope),\r\n );\r\n\r\n await using(this._asyncsTracker.trackAsyncTask(), async (_r) => {\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n await changer.add(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Replace:\r\n await changer.replace(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Remove:\r\n await changer.remove(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Clear:\r\n await changer.clear(selectionLevel);\r\n break;\r\n }\r\n });\r\n };\r\n}\r\n\r\nconst parseElementIds = (ids: Id64Arg): { persistent: Id64Arg; transient: Id64Arg } => {\r\n let allPersistent = true;\r\n let allTransient = true;\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n allPersistent = false;\r\n } else {\r\n allTransient = false;\r\n }\r\n\r\n if (!allPersistent && !allTransient) {\r\n break;\r\n }\r\n }\r\n\r\n // avoid making a copy if ids are only persistent or only transient\r\n if (allPersistent) {\r\n return { persistent: ids, transient: [] };\r\n } else if (allTransient) {\r\n return { persistent: [], transient: ids };\r\n }\r\n\r\n // if `ids` contain mixed ids, we have to copy.. use Array instead of\r\n // a Set for performance\r\n const persistentElementIds: Id64Array = [];\r\n const transientElementIds: Id64Array = [];\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n transientElementIds.push(id);\r\n } else {\r\n persistentElementIds.push(id);\r\n }\r\n }\r\n\r\n return { persistent: persistentElementIds, transient: transientElementIds };\r\n};\r\n\r\nfunction addKeys(target: KeySet, className: string, ids: Id64Arg) {\r\n for (const id of Id64.iterable(ids)) {\r\n target.add({ className, id });\r\n }\r\n}\r\n\r\nclass ScopedSelectionChanger {\r\n public readonly name: string;\r\n public readonly imodel: IModelConnection;\r\n public readonly manager: SelectionManager;\r\n public readonly scope: SelectionScopeProps | SelectionScope | string;\r\n public constructor(name: string, imodel: IModelConnection, manager: SelectionManager, scope: SelectionScopeProps | SelectionScope | string) {\r\n this.name = name;\r\n this.imodel = imodel;\r\n this.manager = manager;\r\n this.scope = scope;\r\n }\r\n public async clear(level: number): Promise<void> {\r\n this.manager.clearSelection(this.name, this.imodel, level);\r\n }\r\n public async add(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.addToSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async remove(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.removeFromSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async replace(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.replaceSelection(this.name, this.imodel, keys, level);\r\n }\r\n async #computeSelection(ids: SelectableIds) {\r\n let keys = new KeySet();\r\n if (ids.elements) {\r\n const { persistent, transient } = parseElementIds(ids.elements);\r\n keys = await this.manager.scopes.computeSelection(this.imodel, persistent, this.scope);\r\n addKeys(keys, TRANSIENT_ELEMENT_CLASSNAME, transient);\r\n }\r\n if (ids.models) {\r\n addKeys(keys, \"BisCore.Model\", ids.models);\r\n }\r\n if (ids.subcategories) {\r\n addKeys(keys, \"BisCore.SubCategory\", ids.subcategories);\r\n }\r\n return keys;\r\n }\r\n}\r\n\r\n/** Stores current selection in `KeySet` format per iModel. */\r\nclass CurrentSelectionStorage {\r\n private _currentSelection = new Map<string, IModelSelectionStorage>();\r\n\r\n private getCurrentSelectionStorage(imodelKey: string) {\r\n let storage = this._currentSelection.get(imodelKey);\r\n if (!storage) {\r\n storage = new IModelSelectionStorage();\r\n this._currentSelection.set(imodelKey, storage);\r\n }\r\n return storage;\r\n }\r\n\r\n public getSelection(imodelKey: string, level: number) {\r\n return this.getCurrentSelectionStorage(imodelKey).getSelection(level);\r\n }\r\n\r\n public clear(imodelKey: string) {\r\n this._currentSelection.delete(imodelKey);\r\n }\r\n\r\n public computeSelection(imodelKey: string, level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n return this.getCurrentSelectionStorage(imodelKey).computeSelection(level, currSelectables, changedSelectables);\r\n }\r\n}\r\n\r\ninterface StorageEntry {\r\n value: KeySet;\r\n ongoingComputationDisposers: Set<Subject<void>>;\r\n}\r\n\r\n/**\r\n * Computes and stores current selection in `KeySet` format.\r\n * It always stores result of latest resolved call to `computeSelection`.\r\n */\r\nclass IModelSelectionStorage {\r\n private _currentSelection = new Map<number, StorageEntry>();\r\n\r\n public getSelection(level: number): KeySet {\r\n let entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n entry = { value: new KeySet(), ongoingComputationDisposers: new Set() };\r\n this._currentSelection.set(level, entry);\r\n }\r\n return entry.value;\r\n }\r\n\r\n private clearSelections(level: number) {\r\n const clearedLevels = [];\r\n for (const [storedLevel] of this._currentSelection.entries()) {\r\n if (storedLevel > level) {\r\n clearedLevels.push(storedLevel);\r\n }\r\n }\r\n clearedLevels.forEach((storedLevel) => {\r\n const entry = this._currentSelection.get(storedLevel);\r\n // istanbul ignore if\r\n if (!entry) {\r\n return;\r\n }\r\n\r\n for (const disposer of entry.ongoingComputationDisposers) {\r\n disposer.next();\r\n }\r\n this._currentSelection.delete(storedLevel);\r\n });\r\n }\r\n\r\n private addDisposer(level: number, disposer: Subject<void>) {\r\n const entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n this._currentSelection.set(level, { value: new KeySet(), ongoingComputationDisposers: new Set([disposer]) });\r\n return;\r\n }\r\n entry.ongoingComputationDisposers.add(disposer);\r\n }\r\n\r\n private setSelection(level: number, keys: KeySet, disposer: Subject<void>) {\r\n const currEntry = this._currentSelection.get(level);\r\n // istanbul ignore else\r\n if (currEntry) {\r\n currEntry.ongoingComputationDisposers.delete(disposer);\r\n }\r\n this._currentSelection.set(level, {\r\n value: keys,\r\n ongoingComputationDisposers: currEntry?.ongoingComputationDisposers ?? /* istanbul ignore next */ new Set(),\r\n });\r\n }\r\n\r\n public computeSelection(level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n this.clearSelections(level);\r\n\r\n const prevComputationsDisposers = [...(this._currentSelection.get(level)?.ongoingComputationDisposers ?? [])];\r\n const currDisposer = new Subject<void>();\r\n this.addDisposer(level, currDisposer);\r\n\r\n return defer(async () => {\r\n const convertedSelectables: SelectableKeys[] = [];\r\n const [current, changed] = await Promise.all([\r\n selectablesToKeys(currSelectables, convertedSelectables),\r\n selectablesToKeys(changedSelectables, convertedSelectables),\r\n ]);\r\n\r\n const currentSelection = new KeySet([...current.keys, ...current.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n const changedSelection = new KeySet([...changed.keys, ...changed.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n\r\n return {\r\n level,\r\n currentSelection,\r\n changedSelection,\r\n };\r\n }).pipe(\r\n takeUntil(currDisposer),\r\n tap({\r\n next: (val) => {\r\n prevComputationsDisposers.forEach((disposer) => disposer.next());\r\n this.setSelection(val.level, val.currentSelection, currDisposer);\r\n },\r\n }),\r\n );\r\n }\r\n}\r\n\r\nfunction keysToSelectable(imodel: IModelConnection, keys: Readonly<KeySet>) {\r\n const selectables: Selectable[] = [];\r\n keys.forEach((key) => {\r\n if (\"id\" in key) {\r\n selectables.push(key);\r\n return;\r\n }\r\n\r\n const customSelectable: CustomSelectable = {\r\n identifier: key.pathFromRoot.join(\"/\"),\r\n data: key,\r\n loadInstanceKeys: () => createInstanceKeysIterator(imodel, key),\r\n };\r\n selectables.push(customSelectable);\r\n });\r\n return selectables;\r\n}\r\n\r\ninterface SelectableKeys {\r\n identifier: string;\r\n keys: Key[];\r\n}\r\n\r\nasync function selectablesToKeys(selectables: Selectables, convertedList: SelectableKeys[]) {\r\n const keys: Key[] = [];\r\n const selectableKeys: SelectableKeys[] = [];\r\n\r\n for (const [className, ids] of selectables.instanceKeys) {\r\n for (const id of ids) {\r\n keys.push({ id, className });\r\n }\r\n }\r\n\r\n for (const [_, selectable] of selectables.custom) {\r\n if (isNodeKey(selectable.data)) {\r\n selectableKeys.push({ identifier: selectable.identifier, keys: [selectable.data] });\r\n continue;\r\n }\r\n const converted = convertedList.find((con) => con.identifier === selectable.identifier);\r\n if (converted) {\r\n selectableKeys.push(converted);\r\n continue;\r\n }\r\n\r\n const newConverted: SelectableKeys = { identifier: selectable.identifier, keys: [] };\r\n convertedList.push(newConverted);\r\n for await (const instanceKey of selectable.loadInstanceKeys()) {\r\n newConverted.keys.push(instanceKey);\r\n }\r\n selectableKeys.push(newConverted);\r\n }\r\n\r\n return { keys, selectableKeys };\r\n}\r\n\r\nasync function* createInstanceKeysIterator(imodel: IModelConnection, nodeKey: NodeKey): AsyncIterableIterator<InstanceKey> {\r\n if (NodeKey.isInstancesNodeKey(nodeKey)) {\r\n for (const key of nodeKey.instanceKeys) {\r\n yield key;\r\n }\r\n return;\r\n }\r\n\r\n const content = await Presentation.presentation.getContentInstanceKeys({\r\n imodel,\r\n keys: new KeySet([nodeKey]),\r\n rulesetOrId: {\r\n id: \"grouped-instances\",\r\n rules: [\r\n {\r\n ruleType: \"Content\",\r\n specifications: [\r\n {\r\n specType: \"SelectedNodeInstances\",\r\n },\r\n ],\r\n },\r\n ],\r\n },\r\n });\r\n\r\n for await (const key of content.items()) {\r\n yield key;\r\n }\r\n}\r\n\r\nfunction isNodeKey(data: unknown): data is NodeKey {\r\n const key = data as BaseNodeKey;\r\n return key.pathFromRoot !== undefined && key.type !== undefined;\r\n}\r\n\r\nfunction getChangeType(type: StorageSelectionChangeType): SelectionChangeType {\r\n switch (type) {\r\n case \"add\":\r\n return SelectionChangeType.Add;\r\n case \"remove\":\r\n return SelectionChangeType.Remove;\r\n case \"replace\":\r\n return SelectionChangeType.Replace;\r\n case \"clear\":\r\n return SelectionChangeType.Clear;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"SelectionManager.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;AAEH,+BAAqG;AACrG,sDAAmF;AACnF,wDAAiH;AACjH,oEAA0J;AAC1J,gEASkC;AAClC,kDAA+C;AAC/C,2DAAmE;AAEnE,iEAA6G;AAC7G,qEAA6F;AA0B7F;;;GAGG;AACH,MAAa,gBAAgB;IAwB3B;;OAEG;IACH,YAAY,KAA4B;QAzBhC,qCAAgC,GAAG,IAAI,GAAG,EAAoF,CAAC;QAC/H,wBAAmB,GAAG,IAAI,GAAG,EAAuC,CAAC;QAGrE,kBAAa,GAAG,IAAI,GAAG,EAAoB,CAAC;QAC5C,sBAAiB,GAAG,IAAI,uBAAuB,EAAE,CAAC;QAClD,sBAAiB,GAAG,IAAI,cAAO,EAAmC,CAAC;QAEnE,eAAU,GAAsB,EAAE,CAAC;QAkBzC,IAAI,CAAC,eAAe,GAAG,IAAI,2CAAoB,EAAE,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,gBAAgB,IAAI,IAAA,iCAAa,GAAE,CAAC;QAClE,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,gBAAgB,IAAI,CAAC,C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,KAAK,KAAK;YACR,OAAO,0CAAmB,CAAC,GAAG,CAAC;QACjC,KAAK,QAAQ;YACX,OAAO,0CAAmB,CAAC,MAAM,CAAC;QACpC,KAAK,SAAS;YACZ,OAAO,0CAAmB,CAAC,OAAO,CAAC;QACrC,KAAK,OAAO;YACV,OAAO,0CAAmB,CAAC,KAAK,CAAC;IACrC,CAAC;AACH,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 UnifiedSelection\r\n */\r\n\r\nimport { defer, EMPTY, mergeMap, Observable, of, Subject, Subscription, takeUntil, tap } from \"rxjs\";\r\nimport { Id64, Id64Arg, Id64Array, IDisposable, using } from \"@itwin/core-bentley\";\r\nimport { IModelConnection, SelectableIds, SelectionSetEvent, SelectionSetEventType } from \"@itwin/core-frontend\";\r\nimport { AsyncTasksTracker, BaseNodeKey, InstanceKey, Key, Keys, KeySet, NodeKey, SelectionScope, SelectionScopeProps } from \"@itwin/presentation-common\";\r\nimport {\r\n createStorage,\r\n CustomSelectable,\r\n Selectable,\r\n Selectables,\r\n SelectionStorage,\r\n StorageSelectionChangeEventArgs,\r\n StorageSelectionChangeType,\r\n TRANSIENT_ELEMENT_CLASSNAME,\r\n} from \"@itwin/unified-selection\";\r\nimport { Presentation } from \"../Presentation\";\r\nimport { HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider\";\r\nimport { ISelectionProvider } from \"./ISelectionProvider\";\r\nimport { SelectionChangeEvent, SelectionChangeEventArgs, SelectionChangeType } from \"./SelectionChangeEvent\";\r\nimport { createSelectionScopeProps, SelectionScopesManager } from \"./SelectionScopesManager\";\r\n\r\n/**\r\n * Properties for creating [[SelectionManager]].\r\n * @public\r\n */\r\nexport interface SelectionManagerProps {\r\n /** A manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n scopes: SelectionScopesManager;\r\n\r\n /**\r\n * Custom unified selection storage to be used by [[SelectionManager]]. If not provided [[SelectionManager]] creates\r\n * and maintains storage.\r\n */\r\n selectionStorage?: SelectionStorage;\r\n\r\n /**\r\n * An optional function that returns a key for the given iModel. The key is what \"glues\" iModel selection\r\n * changes made in `selectionStorage`, where iModels are identified by key, and `SelectionManager`, where\r\n * iModels are specified as `IModelConnection`.\r\n *\r\n * If not provided, [IModelConnection.key]($core-frontend) or [IModelConnection.name]($core-frontend) is used.\r\n */\r\n imodelKeyFactory?: (imodel: IModelConnection) => string;\r\n}\r\n\r\n/**\r\n * The selection manager which stores the overall selection.\r\n * @public\r\n */\r\nexport class SelectionManager implements ISelectionProvider {\r\n private _imodelKeyFactory: (imodel: IModelConnection) => string;\r\n private _imodelToolSelectionSyncHandlers = new Map<IModelConnection, { requestorsCount: number; handler: ToolSelectionSyncHandler }>();\r\n private _hiliteSetProviders = new Map<IModelConnection, HiliteSetProvider>();\r\n private _ownsStorage: boolean;\r\n\r\n private _knownIModels = new Set<IModelConnection>();\r\n private _currentSelection = new CurrentSelectionStorage();\r\n private _selectionChanges = new Subject<StorageSelectionChangeEventArgs>();\r\n private _selectionEventsSubscription: Subscription;\r\n private _listeners: Array<() => void> = [];\r\n\r\n /**\r\n * Underlying selection storage used by this selection manager. Ideally, consumers should use\r\n * the storage directly instead of using this manager to manipulate selection.\r\n */\r\n public readonly selectionStorage: SelectionStorage;\r\n\r\n /** An event which gets broadcasted on selection changes */\r\n public readonly selectionChange: SelectionChangeEvent;\r\n\r\n /** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n public readonly scopes: SelectionScopesManager;\r\n\r\n /**\r\n * Creates an instance of SelectionManager.\r\n */\r\n constructor(props: SelectionManagerProps) {\r\n this.selectionChange = new SelectionChangeEvent();\r\n this.scopes = props.scopes;\r\n this.selectionStorage = props.selectionStorage ?? createStorage();\r\n this._imodelKeyFactory = props.imodelKeyFactory ?? ((imodel) => (imodel.key.length ? imodel.key : imodel.name));\r\n this._ownsStorage = props.selectionStorage === undefined;\r\n this.selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));\r\n this._selectionEventsSubscription = this.streamSelectionEvents();\r\n this._listeners.push(\r\n IModelConnection.onOpen.addListener((imodel) => {\r\n this._knownIModels.add(imodel);\r\n }),\r\n );\r\n this._listeners.push(\r\n IModelConnection.onClose.addListener((imodel: IModelConnection) => {\r\n this.onConnectionClose(imodel);\r\n }),\r\n );\r\n }\r\n\r\n public dispose() {\r\n this._selectionEventsSubscription.unsubscribe();\r\n this._listeners.forEach((dispose) => dispose());\r\n }\r\n\r\n private onConnectionClose(imodel: IModelConnection): void {\r\n const imodelKey = this._imodelKeyFactory(imodel);\r\n this._hiliteSetProviders.delete(imodel);\r\n this._knownIModels.delete(imodel);\r\n this._currentSelection.clear(imodelKey);\r\n if (this._ownsStorage) {\r\n this.clearSelection(\"Connection Close Event\", imodel);\r\n this.selectionStorage.clearStorage({ imodelKey });\r\n }\r\n }\r\n\r\n /** @internal */\r\n // istanbul ignore next\r\n public getToolSelectionSyncHandler(imodel: IModelConnection) {\r\n return this._imodelToolSelectionSyncHandlers.get(imodel)?.handler;\r\n }\r\n\r\n /**\r\n * Request the manager to sync with imodel's tool selection (see `IModelConnection.selectionSet`).\r\n */\r\n public setSyncWithIModelToolSelection(imodel: IModelConnection, sync = true) {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (sync) {\r\n if (!registration || registration.requestorsCount === 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { requestorsCount: 1, handler: new ToolSelectionSyncHandler(imodel, this) });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount: registration.requestorsCount + 1 });\r\n }\r\n } else {\r\n if (registration && registration.requestorsCount > 0) {\r\n const requestorsCount = registration.requestorsCount - 1;\r\n if (requestorsCount > 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.delete(imodel);\r\n registration.handler.dispose();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Temporarily suspends tool selection synchronization until the returned `IDisposable`\r\n * is disposed.\r\n */\r\n public suspendIModelToolSelectionSync(imodel: IModelConnection): IDisposable {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (!registration) {\r\n return { dispose: () => {} };\r\n }\r\n\r\n const wasSuspended = registration.handler.isSuspended;\r\n registration.handler.isSuspended = true;\r\n return { dispose: () => (registration.handler.isSuspended = wasSuspended) };\r\n }\r\n\r\n /** Get the selection levels currently stored in this manager for the specified imodel */\r\n public getSelectionLevels(imodel: IModelConnection): number[] {\r\n const imodelKey = this._imodelKeyFactory(imodel);\r\n return this.selectionStorage.getSelectionLevels({ imodelKey });\r\n }\r\n\r\n /**\r\n * Get the selection currently stored in this manager\r\n *\r\n * @note Calling immediately after `add*`|`replace*`|`remove*`|`clear*` method call does not guarantee\r\n * that returned `KeySet` will include latest changes. Listen for `selectionChange` event to get the\r\n * latest selection after changes.\r\n */\r\n public getSelection(imodel: IModelConnection, level: number = 0): Readonly<KeySet> {\r\n const imodelKey = this._imodelKeyFactory(imodel);\r\n return this._currentSelection.getSelection(imodelKey, level);\r\n }\r\n\r\n private handleEvent(evt: SelectionChangeEventArgs): void {\r\n const imodelKey = this._imodelKeyFactory(evt.imodel);\r\n this._knownIModels.add(evt.imodel);\r\n switch (evt.changeType) {\r\n case SelectionChangeType.Add:\r\n this.selectionStorage.addToSelection({\r\n imodelKey,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Remove:\r\n this.selectionStorage.removeFromSelection({\r\n imodelKey,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Replace:\r\n this.selectionStorage.replaceSelection({\r\n imodelKey,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Clear:\r\n this.selectionStorage.clearSelection({ imodelKey, source: evt.source, level: evt.level });\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Add keys to the selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public addToSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Add,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to remove\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public removeFromSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Remove,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Replace current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public replaceSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Replace,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Clear current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public clearSelection(source: string, imodel: IModelConnection, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Clear,\r\n keys: new KeySet(),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Add keys to selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to add\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async addToSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.addToSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to remove\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async removeFromSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.removeFromSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Replace current selection with keys after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to replace with\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async replaceSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.replaceSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Get the current hilite set for the specified imodel\r\n * @public\r\n */\r\n public async getHiliteSet(imodel: IModelConnection): Promise<HiliteSet> {\r\n return this.getHiliteSetProvider(imodel).getHiliteSet(this.getSelection(imodel));\r\n }\r\n\r\n /**\r\n * Get the current hilite set iterator for the specified imodel.\r\n * @public\r\n */\r\n public getHiliteSetIterator(imodel: IModelConnection) {\r\n return this.getHiliteSetProvider(imodel).getHiliteSetIterator(this.getSelection(imodel));\r\n }\r\n\r\n private getHiliteSetProvider(imodel: IModelConnection) {\r\n let provider = this._hiliteSetProviders.get(imodel);\r\n if (!provider) {\r\n provider = HiliteSetProvider.create({ imodel });\r\n this._hiliteSetProviders.set(imodel, provider);\r\n }\r\n return provider;\r\n }\r\n\r\n private streamSelectionEvents() {\r\n return this._selectionChanges\r\n .pipe(\r\n mergeMap((args) => {\r\n const currentSelectables = this.selectionStorage.getSelection({ imodelKey: args.imodelKey, level: args.level });\r\n return this._currentSelection.computeSelection(args.imodelKey, args.level, currentSelectables, args.selectables).pipe(\r\n mergeMap(({ level, changedSelection }): Observable<SelectionChangeEventArgs> => {\r\n const imodel = findIModel(this._knownIModels, this._imodelKeyFactory, args.imodelKey);\r\n // istanbul ignore if\r\n if (!imodel) {\r\n return EMPTY;\r\n }\r\n return of({\r\n imodel,\r\n keys: changedSelection,\r\n level,\r\n source: args.source,\r\n timestamp: args.timestamp,\r\n changeType: getChangeType(args.changeType),\r\n });\r\n }),\r\n );\r\n }),\r\n )\r\n .subscribe({\r\n next: (args) => {\r\n this.selectionChange.raiseEvent(args, this);\r\n },\r\n });\r\n }\r\n}\r\n\r\nfunction findIModel(set: Set<IModelConnection>, imodelKeyFactory: (imodel: IModelConnection) => string, key: string) {\r\n for (const imodel of set) {\r\n if (imodelKeyFactory(imodel) === key) {\r\n return imodel;\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\n/** @internal */\r\nexport class ToolSelectionSyncHandler implements IDisposable {\r\n private _selectionSourceName = \"Tool\";\r\n private _logicalSelection: SelectionManager;\r\n private _imodel: IModelConnection;\r\n private _imodelToolSelectionListenerDisposeFunc: () => void;\r\n private _asyncsTracker = new AsyncTasksTracker();\r\n public isSuspended?: boolean;\r\n\r\n public constructor(imodel: IModelConnection, logicalSelection: SelectionManager) {\r\n this._imodel = imodel;\r\n this._logicalSelection = logicalSelection;\r\n this._imodelToolSelectionListenerDisposeFunc = imodel.selectionSet.onChanged.addListener(this.onToolSelectionChanged);\r\n }\r\n\r\n public dispose() {\r\n this._imodelToolSelectionListenerDisposeFunc();\r\n }\r\n\r\n /** note: used only it tests */\r\n public get pendingAsyncs() {\r\n return this._asyncsTracker.pendingAsyncs;\r\n }\r\n\r\n private onToolSelectionChanged = async (ev: SelectionSetEvent): Promise<void> => {\r\n // ignore selection change event if the handler is suspended\r\n if (this.isSuspended) {\r\n return;\r\n }\r\n\r\n // this component only cares about its own imodel\r\n const imodel = ev.set.iModel;\r\n if (imodel !== this._imodel) {\r\n return;\r\n }\r\n\r\n // determine the level of selection changes\r\n // wip: may want to allow selecting at different levels?\r\n const selectionLevel = 0;\r\n\r\n let ids: SelectableIds;\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n ids = ev.additions;\r\n break;\r\n case SelectionSetEventType.Replace:\r\n ids = ev.set.active;\r\n break;\r\n default:\r\n ids = ev.removals;\r\n break;\r\n }\r\n\r\n // we're always using scoped selection changer even if the scope is set to \"element\" - that\r\n // makes sure we're adding to selection keys with concrete classes and not \"BisCore:Element\", which\r\n // we can't because otherwise our keys compare fails (presentation components load data with\r\n // concrete classes)\r\n const changer = new ScopedSelectionChanger(\r\n this._selectionSourceName,\r\n this._imodel,\r\n this._logicalSelection,\r\n createSelectionScopeProps(this._logicalSelection.scopes.activeScope),\r\n );\r\n\r\n await using(this._asyncsTracker.trackAsyncTask(), async (_r) => {\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n await changer.add(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Replace:\r\n await changer.replace(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Remove:\r\n await changer.remove(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Clear:\r\n await changer.clear(selectionLevel);\r\n break;\r\n }\r\n });\r\n };\r\n}\r\n\r\nconst parseElementIds = (ids: Id64Arg): { persistent: Id64Arg; transient: Id64Arg } => {\r\n let allPersistent = true;\r\n let allTransient = true;\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n allPersistent = false;\r\n } else {\r\n allTransient = false;\r\n }\r\n\r\n if (!allPersistent && !allTransient) {\r\n break;\r\n }\r\n }\r\n\r\n // avoid making a copy if ids are only persistent or only transient\r\n if (allPersistent) {\r\n return { persistent: ids, transient: [] };\r\n } else if (allTransient) {\r\n return { persistent: [], transient: ids };\r\n }\r\n\r\n // if `ids` contain mixed ids, we have to copy.. use Array instead of\r\n // a Set for performance\r\n const persistentElementIds: Id64Array = [];\r\n const transientElementIds: Id64Array = [];\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n transientElementIds.push(id);\r\n } else {\r\n persistentElementIds.push(id);\r\n }\r\n }\r\n\r\n return { persistent: persistentElementIds, transient: transientElementIds };\r\n};\r\n\r\nfunction addKeys(target: KeySet, className: string, ids: Id64Arg) {\r\n for (const id of Id64.iterable(ids)) {\r\n target.add({ className, id });\r\n }\r\n}\r\n\r\nclass ScopedSelectionChanger {\r\n public readonly name: string;\r\n public readonly imodel: IModelConnection;\r\n public readonly manager: SelectionManager;\r\n public readonly scope: SelectionScopeProps | SelectionScope | string;\r\n public constructor(name: string, imodel: IModelConnection, manager: SelectionManager, scope: SelectionScopeProps | SelectionScope | string) {\r\n this.name = name;\r\n this.imodel = imodel;\r\n this.manager = manager;\r\n this.scope = scope;\r\n }\r\n public async clear(level: number): Promise<void> {\r\n this.manager.clearSelection(this.name, this.imodel, level);\r\n }\r\n public async add(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.addToSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async remove(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.removeFromSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async replace(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.replaceSelection(this.name, this.imodel, keys, level);\r\n }\r\n async #computeSelection(ids: SelectableIds) {\r\n let keys = new KeySet();\r\n if (ids.elements) {\r\n const { persistent, transient } = parseElementIds(ids.elements);\r\n keys = await this.manager.scopes.computeSelection(this.imodel, persistent, this.scope);\r\n addKeys(keys, TRANSIENT_ELEMENT_CLASSNAME, transient);\r\n }\r\n if (ids.models) {\r\n addKeys(keys, \"BisCore.Model\", ids.models);\r\n }\r\n if (ids.subcategories) {\r\n addKeys(keys, \"BisCore.SubCategory\", ids.subcategories);\r\n }\r\n return keys;\r\n }\r\n}\r\n\r\n/** Stores current selection in `KeySet` format per iModel. */\r\nclass CurrentSelectionStorage {\r\n private _currentSelection = new Map<string, IModelSelectionStorage>();\r\n\r\n private getCurrentSelectionStorage(imodelKey: string) {\r\n let storage = this._currentSelection.get(imodelKey);\r\n if (!storage) {\r\n storage = new IModelSelectionStorage();\r\n this._currentSelection.set(imodelKey, storage);\r\n }\r\n return storage;\r\n }\r\n\r\n public getSelection(imodelKey: string, level: number) {\r\n return this.getCurrentSelectionStorage(imodelKey).getSelection(level);\r\n }\r\n\r\n public clear(imodelKey: string) {\r\n this._currentSelection.delete(imodelKey);\r\n }\r\n\r\n public computeSelection(imodelKey: string, level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n return this.getCurrentSelectionStorage(imodelKey).computeSelection(level, currSelectables, changedSelectables);\r\n }\r\n}\r\n\r\ninterface StorageEntry {\r\n value: KeySet;\r\n ongoingComputationDisposers: Set<Subject<void>>;\r\n}\r\n\r\n/**\r\n * Computes and stores current selection in `KeySet` format.\r\n * It always stores result of latest resolved call to `computeSelection`.\r\n */\r\nclass IModelSelectionStorage {\r\n private _currentSelection = new Map<number, StorageEntry>();\r\n\r\n public getSelection(level: number): KeySet {\r\n let entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n entry = { value: new KeySet(), ongoingComputationDisposers: new Set() };\r\n this._currentSelection.set(level, entry);\r\n }\r\n return entry.value;\r\n }\r\n\r\n private clearSelections(level: number) {\r\n const clearedLevels = [];\r\n for (const [storedLevel] of this._currentSelection.entries()) {\r\n if (storedLevel > level) {\r\n clearedLevels.push(storedLevel);\r\n }\r\n }\r\n clearedLevels.forEach((storedLevel) => {\r\n const entry = this._currentSelection.get(storedLevel);\r\n // istanbul ignore if\r\n if (!entry) {\r\n return;\r\n }\r\n\r\n for (const disposer of entry.ongoingComputationDisposers) {\r\n disposer.next();\r\n }\r\n this._currentSelection.delete(storedLevel);\r\n });\r\n }\r\n\r\n private addDisposer(level: number, disposer: Subject<void>) {\r\n const entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n this._currentSelection.set(level, { value: new KeySet(), ongoingComputationDisposers: new Set([disposer]) });\r\n return;\r\n }\r\n entry.ongoingComputationDisposers.add(disposer);\r\n }\r\n\r\n private setSelection(level: number, keys: KeySet, disposer: Subject<void>) {\r\n const currEntry = this._currentSelection.get(level);\r\n // istanbul ignore else\r\n if (currEntry) {\r\n currEntry.ongoingComputationDisposers.delete(disposer);\r\n }\r\n this._currentSelection.set(level, {\r\n value: keys,\r\n ongoingComputationDisposers: currEntry?.ongoingComputationDisposers ?? /* istanbul ignore next */ new Set(),\r\n });\r\n }\r\n\r\n public computeSelection(level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n this.clearSelections(level);\r\n\r\n const prevComputationsDisposers = [...(this._currentSelection.get(level)?.ongoingComputationDisposers ?? [])];\r\n const currDisposer = new Subject<void>();\r\n this.addDisposer(level, currDisposer);\r\n\r\n return defer(async () => {\r\n const convertedSelectables: SelectableKeys[] = [];\r\n const [current, changed] = await Promise.all([\r\n selectablesToKeys(currSelectables, convertedSelectables),\r\n selectablesToKeys(changedSelectables, convertedSelectables),\r\n ]);\r\n\r\n const currentSelection = new KeySet([...current.keys, ...current.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n const changedSelection = new KeySet([...changed.keys, ...changed.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n\r\n return {\r\n level,\r\n currentSelection,\r\n changedSelection,\r\n };\r\n }).pipe(\r\n takeUntil(currDisposer),\r\n tap({\r\n next: (val) => {\r\n prevComputationsDisposers.forEach((disposer) => disposer.next());\r\n this.setSelection(val.level, val.currentSelection, currDisposer);\r\n },\r\n }),\r\n );\r\n }\r\n}\r\n\r\nfunction keysToSelectable(imodel: IModelConnection, keys: Readonly<KeySet>) {\r\n const selectables: Selectable[] = [];\r\n keys.forEach((key) => {\r\n if (\"id\" in key) {\r\n selectables.push(key);\r\n return;\r\n }\r\n\r\n const customSelectable: CustomSelectable = {\r\n identifier: key.pathFromRoot.join(\"/\"),\r\n data: key,\r\n loadInstanceKeys: () => createInstanceKeysIterator(imodel, key),\r\n };\r\n selectables.push(customSelectable);\r\n });\r\n return selectables;\r\n}\r\n\r\ninterface SelectableKeys {\r\n identifier: string;\r\n keys: Key[];\r\n}\r\n\r\nasync function selectablesToKeys(selectables: Selectables, convertedList: SelectableKeys[]) {\r\n const keys: Key[] = [];\r\n const selectableKeys: SelectableKeys[] = [];\r\n\r\n for (const [className, ids] of selectables.instanceKeys) {\r\n for (const id of ids) {\r\n keys.push({ id, className });\r\n }\r\n }\r\n\r\n for (const [_, selectable] of selectables.custom) {\r\n if (isNodeKey(selectable.data)) {\r\n selectableKeys.push({ identifier: selectable.identifier, keys: [selectable.data] });\r\n continue;\r\n }\r\n const converted = convertedList.find((con) => con.identifier === selectable.identifier);\r\n if (converted) {\r\n selectableKeys.push(converted);\r\n continue;\r\n }\r\n\r\n const newConverted: SelectableKeys = { identifier: selectable.identifier, keys: [] };\r\n convertedList.push(newConverted);\r\n for await (const instanceKey of selectable.loadInstanceKeys()) {\r\n newConverted.keys.push(instanceKey);\r\n }\r\n selectableKeys.push(newConverted);\r\n }\r\n\r\n return { keys, selectableKeys };\r\n}\r\n\r\nasync function* createInstanceKeysIterator(imodel: IModelConnection, nodeKey: NodeKey): AsyncIterableIterator<InstanceKey> {\r\n if (NodeKey.isInstancesNodeKey(nodeKey)) {\r\n for (const key of nodeKey.instanceKeys) {\r\n yield key;\r\n }\r\n return;\r\n }\r\n\r\n const content = await Presentation.presentation.getContentInstanceKeys({\r\n imodel,\r\n keys: new KeySet([nodeKey]),\r\n rulesetOrId: {\r\n id: \"grouped-instances\",\r\n rules: [\r\n {\r\n ruleType: \"Content\",\r\n specifications: [\r\n {\r\n specType: \"SelectedNodeInstances\",\r\n },\r\n ],\r\n },\r\n ],\r\n },\r\n });\r\n\r\n for await (const key of content.items()) {\r\n yield key;\r\n }\r\n}\r\n\r\nfunction isNodeKey(data: unknown): data is NodeKey {\r\n const key = data as BaseNodeKey;\r\n return key.pathFromRoot !== undefined && key.type !== undefined;\r\n}\r\n\r\nfunction getChangeType(type: StorageSelectionChangeType): SelectionChangeType {\r\n switch (type) {\r\n case \"add\":\r\n return SelectionChangeType.Add;\r\n case \"remove\":\r\n return SelectionChangeType.Remove;\r\n case \"replace\":\r\n return SelectionChangeType.Replace;\r\n case \"clear\":\r\n return SelectionChangeType.Clear;\r\n }\r\n}\r\n"]}
|
|
@@ -21,13 +21,21 @@ export interface SelectionManagerProps {
|
|
|
21
21
|
* and maintains storage.
|
|
22
22
|
*/
|
|
23
23
|
selectionStorage?: SelectionStorage;
|
|
24
|
+
/**
|
|
25
|
+
* An optional function that returns a key for the given iModel. The key is what "glues" iModel selection
|
|
26
|
+
* changes made in `selectionStorage`, where iModels are identified by key, and `SelectionManager`, where
|
|
27
|
+
* iModels are specified as `IModelConnection`.
|
|
28
|
+
*
|
|
29
|
+
* If not provided, [IModelConnection.key]($core-frontend) or [IModelConnection.name]($core-frontend) is used.
|
|
30
|
+
*/
|
|
31
|
+
imodelKeyFactory?: (imodel: IModelConnection) => string;
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* The selection manager which stores the overall selection.
|
|
27
35
|
* @public
|
|
28
36
|
*/
|
|
29
37
|
export declare class SelectionManager implements ISelectionProvider {
|
|
30
|
-
private
|
|
38
|
+
private _imodelKeyFactory;
|
|
31
39
|
private _imodelToolSelectionSyncHandlers;
|
|
32
40
|
private _hiliteSetProviders;
|
|
33
41
|
private _ownsStorage;
|
|
@@ -36,6 +44,11 @@ export declare class SelectionManager implements ISelectionProvider {
|
|
|
36
44
|
private _selectionChanges;
|
|
37
45
|
private _selectionEventsSubscription;
|
|
38
46
|
private _listeners;
|
|
47
|
+
/**
|
|
48
|
+
* Underlying selection storage used by this selection manager. Ideally, consumers should use
|
|
49
|
+
* the storage directly instead of using this manager to manipulate selection.
|
|
50
|
+
*/
|
|
51
|
+
readonly selectionStorage: SelectionStorage;
|
|
39
52
|
/** An event which gets broadcasted on selection changes */
|
|
40
53
|
readonly selectionChange: SelectionChangeEvent;
|
|
41
54
|
/** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionManager.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAQ,OAAO,EAAa,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAA2D,MAAM,sBAAsB,CAAC;AACjH,OAAO,EAAoD,IAAI,EAAE,MAAM,EAAW,cAAc,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAC1J,OAAO,EAKL,gBAAgB,EAIjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAAqB,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAiD,MAAM,wBAAwB,CAAC;AAC7G,OAAO,EAA6B,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAE7F;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,oGAAoG;IACpG,MAAM,EAAE,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"SelectionManager.d.ts","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAQ,OAAO,EAAa,WAAW,EAAS,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAA2D,MAAM,sBAAsB,CAAC;AACjH,OAAO,EAAoD,IAAI,EAAE,MAAM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AC,IAAI,CAAC;IAKhB;;;;;;;;OAQG;IACU,4BAA4B,CACvC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,mBAAmB,GAAG,cAAc,GAAG,MAAM,EACpD,KAAK,GAAE,MAAU,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;;;;OAQG;IACU,yBAAyB,CACpC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,mBAAmB,GAAG,cAAc,GAAG,MAAM,EACpD,KAAK,GAAE,MAAU,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC;IAKhB;;;OAGG;IACU,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAIvE;;;OAGG;IACI,oBAAoB,CAAC,MAAM,EAAE,gBAAgB;IAIpD,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,qBAAqB;CA8B9B;AAWD,gBAAgB;AAChB,qBAAa,wBAAyB,YAAW,WAAW;IAC1D,OAAO,CAAC,oBAAoB,CAAU;IACtC,OAAO,CAAC,iBAAiB,CAAmB;IAC5C,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,uCAAuC,CAAa;IAC5D,OAAO,CAAC,cAAc,CAA2B;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;gBAEV,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB;IAMxE,OAAO;IAId,+BAA+B;IAC/B,IAAW,aAAa,gBAEvB;IAED,OAAO,CAAC,sBAAsB,CAwD5B;CACH"}
|
|
@@ -31,18 +31,19 @@ export class SelectionManager {
|
|
|
31
31
|
constructor(props) {
|
|
32
32
|
this._imodelToolSelectionSyncHandlers = new Map();
|
|
33
33
|
this._hiliteSetProviders = new Map();
|
|
34
|
-
this._knownIModels = new
|
|
34
|
+
this._knownIModels = new Set();
|
|
35
35
|
this._currentSelection = new CurrentSelectionStorage();
|
|
36
36
|
this._selectionChanges = new Subject();
|
|
37
37
|
this._listeners = [];
|
|
38
38
|
this.selectionChange = new SelectionChangeEvent();
|
|
39
39
|
this.scopes = props.scopes;
|
|
40
|
-
this.
|
|
40
|
+
this.selectionStorage = props.selectionStorage ?? createStorage();
|
|
41
|
+
this._imodelKeyFactory = props.imodelKeyFactory ?? ((imodel) => (imodel.key.length ? imodel.key : imodel.name));
|
|
41
42
|
this._ownsStorage = props.selectionStorage === undefined;
|
|
42
|
-
this.
|
|
43
|
+
this.selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));
|
|
43
44
|
this._selectionEventsSubscription = this.streamSelectionEvents();
|
|
44
45
|
this._listeners.push(IModelConnection.onOpen.addListener((imodel) => {
|
|
45
|
-
this._knownIModels.
|
|
46
|
+
this._knownIModels.add(imodel);
|
|
46
47
|
}));
|
|
47
48
|
this._listeners.push(IModelConnection.onClose.addListener((imodel) => {
|
|
48
49
|
this.onConnectionClose(imodel);
|
|
@@ -53,12 +54,13 @@ export class SelectionManager {
|
|
|
53
54
|
this._listeners.forEach((dispose) => dispose());
|
|
54
55
|
}
|
|
55
56
|
onConnectionClose(imodel) {
|
|
57
|
+
const imodelKey = this._imodelKeyFactory(imodel);
|
|
56
58
|
this._hiliteSetProviders.delete(imodel);
|
|
57
|
-
this._knownIModels.delete(imodel
|
|
58
|
-
this._currentSelection.clear(
|
|
59
|
+
this._knownIModels.delete(imodel);
|
|
60
|
+
this._currentSelection.clear(imodelKey);
|
|
59
61
|
if (this._ownsStorage) {
|
|
60
62
|
this.clearSelection("Connection Close Event", imodel);
|
|
61
|
-
this.
|
|
63
|
+
this.selectionStorage.clearStorage({ imodelKey });
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
/** @internal */
|
|
@@ -107,7 +109,8 @@ export class SelectionManager {
|
|
|
107
109
|
}
|
|
108
110
|
/** Get the selection levels currently stored in this manager for the specified imodel */
|
|
109
111
|
getSelectionLevels(imodel) {
|
|
110
|
-
|
|
112
|
+
const imodelKey = this._imodelKeyFactory(imodel);
|
|
113
|
+
return this.selectionStorage.getSelectionLevels({ imodelKey });
|
|
111
114
|
}
|
|
112
115
|
/**
|
|
113
116
|
* Get the selection currently stored in this manager
|
|
@@ -117,39 +120,39 @@ export class SelectionManager {
|
|
|
117
120
|
* latest selection after changes.
|
|
118
121
|
*/
|
|
119
122
|
getSelection(imodel, level = 0) {
|
|
120
|
-
|
|
123
|
+
const imodelKey = this._imodelKeyFactory(imodel);
|
|
124
|
+
return this._currentSelection.getSelection(imodelKey, level);
|
|
121
125
|
}
|
|
122
126
|
handleEvent(evt) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
127
|
+
const imodelKey = this._imodelKeyFactory(evt.imodel);
|
|
128
|
+
this._knownIModels.add(evt.imodel);
|
|
126
129
|
switch (evt.changeType) {
|
|
127
130
|
case SelectionChangeType.Add:
|
|
128
|
-
this.
|
|
129
|
-
|
|
131
|
+
this.selectionStorage.addToSelection({
|
|
132
|
+
imodelKey,
|
|
130
133
|
source: evt.source,
|
|
131
134
|
level: evt.level,
|
|
132
135
|
selectables: keysToSelectable(evt.imodel, evt.keys),
|
|
133
136
|
});
|
|
134
137
|
break;
|
|
135
138
|
case SelectionChangeType.Remove:
|
|
136
|
-
this.
|
|
137
|
-
|
|
139
|
+
this.selectionStorage.removeFromSelection({
|
|
140
|
+
imodelKey,
|
|
138
141
|
source: evt.source,
|
|
139
142
|
level: evt.level,
|
|
140
143
|
selectables: keysToSelectable(evt.imodel, evt.keys),
|
|
141
144
|
});
|
|
142
145
|
break;
|
|
143
146
|
case SelectionChangeType.Replace:
|
|
144
|
-
this.
|
|
145
|
-
|
|
147
|
+
this.selectionStorage.replaceSelection({
|
|
148
|
+
imodelKey,
|
|
146
149
|
source: evt.source,
|
|
147
150
|
level: evt.level,
|
|
148
151
|
selectables: keysToSelectable(evt.imodel, evt.keys),
|
|
149
152
|
});
|
|
150
153
|
break;
|
|
151
154
|
case SelectionChangeType.Clear:
|
|
152
|
-
this.
|
|
155
|
+
this.selectionStorage.clearSelection({ imodelKey, source: evt.source, level: evt.level });
|
|
153
156
|
break;
|
|
154
157
|
}
|
|
155
158
|
}
|
|
@@ -296,9 +299,9 @@ export class SelectionManager {
|
|
|
296
299
|
streamSelectionEvents() {
|
|
297
300
|
return this._selectionChanges
|
|
298
301
|
.pipe(mergeMap((args) => {
|
|
299
|
-
const currentSelectables = this.
|
|
302
|
+
const currentSelectables = this.selectionStorage.getSelection({ imodelKey: args.imodelKey, level: args.level });
|
|
300
303
|
return this._currentSelection.computeSelection(args.imodelKey, args.level, currentSelectables, args.selectables).pipe(mergeMap(({ level, changedSelection }) => {
|
|
301
|
-
const imodel = this._knownIModels.
|
|
304
|
+
const imodel = findIModel(this._knownIModels, this._imodelKeyFactory, args.imodelKey);
|
|
302
305
|
// istanbul ignore if
|
|
303
306
|
if (!imodel) {
|
|
304
307
|
return EMPTY;
|
|
@@ -320,6 +323,14 @@ export class SelectionManager {
|
|
|
320
323
|
});
|
|
321
324
|
}
|
|
322
325
|
}
|
|
326
|
+
function findIModel(set, imodelKeyFactory, key) {
|
|
327
|
+
for (const imodel of set) {
|
|
328
|
+
if (imodelKeyFactory(imodel) === key) {
|
|
329
|
+
return imodel;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
323
334
|
/** @internal */
|
|
324
335
|
export class ToolSelectionSyncHandler {
|
|
325
336
|
constructor(imodel, logicalSelection) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionManager.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;AAEH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,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,CAAC;QACD,OAAO;IACT,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC,sBAAsB,CAAC;QACrE,MAAM;QACN,IAAI,EAAE,IAAI,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC;QAC3B,WAAW,EAAE;YACX,EAAE,EAAE,mBAAmB;YACvB,KAAK,EAAE;gBACL;oBACE,QAAQ,EAAE,SAAS;oBACnB,cAAc,EAAE;wBACd;4BACE,QAAQ,EAAE,uBAAuB;yBAClC;qBACF;iBACF;aACF;SACF;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC9B,MAAM,GAAG,GAAG,IAAmB,CAAC;IAChC,OAAO,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC;AAClE,CAAC;AAED,SAAS,aAAa,CAAC,IAAgC;IACrD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK;YACR,OAAO,mBAAmB,CAAC,GAAG,CAAC;QACjC,KAAK,QAAQ;YACX,OAAO,mBAAmB,CAAC,MAAM,CAAC;QACpC,KAAK,SAAS;YACZ,OAAO,mBAAmB,CAAC,OAAO,CAAC;QACrC,KAAK,OAAO;YACV,OAAO,mBAAmB,CAAC,KAAK,CAAC;IACrC,CAAC;AACH,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 UnifiedSelection\r\n */\r\n\r\nimport { defer, EMPTY, mergeMap, Observable, of, Subject, Subscription, takeUntil, tap } from \"rxjs\";\r\nimport { Id64, Id64Arg, Id64Array, IDisposable, using } from \"@itwin/core-bentley\";\r\nimport { IModelConnection, SelectableIds, SelectionSetEvent, SelectionSetEventType } from \"@itwin/core-frontend\";\r\nimport { AsyncTasksTracker, BaseNodeKey, InstanceKey, Key, Keys, KeySet, NodeKey, SelectionScope, SelectionScopeProps } from \"@itwin/presentation-common\";\r\nimport {\r\n createStorage,\r\n CustomSelectable,\r\n Selectable,\r\n Selectables,\r\n SelectionStorage,\r\n StorageSelectionChangeEventArgs,\r\n StorageSelectionChangeType,\r\n TRANSIENT_ELEMENT_CLASSNAME,\r\n} from \"@itwin/unified-selection\";\r\nimport { Presentation } from \"../Presentation\";\r\nimport { HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider\";\r\nimport { ISelectionProvider } from \"./ISelectionProvider\";\r\nimport { SelectionChangeEvent, SelectionChangeEventArgs, SelectionChangeType } from \"./SelectionChangeEvent\";\r\nimport { createSelectionScopeProps, SelectionScopesManager } from \"./SelectionScopesManager\";\r\n\r\n/**\r\n * Properties for creating [[SelectionManager]].\r\n * @public\r\n */\r\nexport interface SelectionManagerProps {\r\n /** A manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n scopes: SelectionScopesManager;\r\n /**\r\n * Custom unified selection storage to be used by [[SelectionManager]]. If not provided [[SelectionManager]] creates\r\n * and maintains storage.\r\n */\r\n selectionStorage?: SelectionStorage;\r\n}\r\n\r\n/**\r\n * The selection manager which stores the overall selection.\r\n * @public\r\n */\r\nexport class SelectionManager implements ISelectionProvider {\r\n private _selectionStorage: SelectionStorage;\r\n private _imodelToolSelectionSyncHandlers = new Map<IModelConnection, { requestorsCount: number; handler: ToolSelectionSyncHandler }>();\r\n private _hiliteSetProviders = new Map<IModelConnection, HiliteSetProvider>();\r\n private _ownsStorage: boolean;\r\n\r\n private _knownIModels = new Map<string, IModelConnection>();\r\n private _currentSelection = new CurrentSelectionStorage();\r\n private _selectionChanges = new Subject<StorageSelectionChangeEventArgs>();\r\n private _selectionEventsSubscription: Subscription;\r\n private _listeners: Array<() => void> = [];\r\n\r\n /** An event which gets broadcasted on selection changes */\r\n public readonly selectionChange: SelectionChangeEvent;\r\n\r\n /** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n public readonly scopes: SelectionScopesManager;\r\n\r\n /**\r\n * Creates an instance of SelectionManager.\r\n */\r\n constructor(props: SelectionManagerProps) {\r\n this.selectionChange = new SelectionChangeEvent();\r\n this.scopes = props.scopes;\r\n this._selectionStorage = props.selectionStorage ?? createStorage();\r\n this._ownsStorage = props.selectionStorage === undefined;\r\n this._selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));\r\n this._selectionEventsSubscription = this.streamSelectionEvents();\r\n this._listeners.push(\r\n IModelConnection.onOpen.addListener((imodel) => {\r\n this._knownIModels.set(imodel.key, imodel);\r\n }),\r\n );\r\n this._listeners.push(\r\n IModelConnection.onClose.addListener((imodel: IModelConnection) => {\r\n this.onConnectionClose(imodel);\r\n }),\r\n );\r\n }\r\n\r\n public dispose() {\r\n this._selectionEventsSubscription.unsubscribe();\r\n this._listeners.forEach((dispose) => dispose());\r\n }\r\n\r\n private onConnectionClose(imodel: IModelConnection): void {\r\n this._hiliteSetProviders.delete(imodel);\r\n this._knownIModels.delete(imodel.key);\r\n this._currentSelection.clear(imodel.key);\r\n if (this._ownsStorage) {\r\n this.clearSelection(\"Connection Close Event\", imodel);\r\n this._selectionStorage.clearStorage({ iModelKey: imodel.key });\r\n }\r\n }\r\n\r\n /** @internal */\r\n // istanbul ignore next\r\n public getToolSelectionSyncHandler(imodel: IModelConnection) {\r\n return this._imodelToolSelectionSyncHandlers.get(imodel)?.handler;\r\n }\r\n\r\n /**\r\n * Request the manager to sync with imodel's tool selection (see `IModelConnection.selectionSet`).\r\n */\r\n public setSyncWithIModelToolSelection(imodel: IModelConnection, sync = true) {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (sync) {\r\n if (!registration || registration.requestorsCount === 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { requestorsCount: 1, handler: new ToolSelectionSyncHandler(imodel, this) });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount: registration.requestorsCount + 1 });\r\n }\r\n } else {\r\n if (registration && registration.requestorsCount > 0) {\r\n const requestorsCount = registration.requestorsCount - 1;\r\n if (requestorsCount > 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.delete(imodel);\r\n registration.handler.dispose();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Temporarily suspends tool selection synchronization until the returned `IDisposable`\r\n * is disposed.\r\n */\r\n public suspendIModelToolSelectionSync(imodel: IModelConnection): IDisposable {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (!registration) {\r\n return { dispose: () => {} };\r\n }\r\n\r\n const wasSuspended = registration.handler.isSuspended;\r\n registration.handler.isSuspended = true;\r\n return { dispose: () => (registration.handler.isSuspended = wasSuspended) };\r\n }\r\n\r\n /** Get the selection levels currently stored in this manager for the specified imodel */\r\n public getSelectionLevels(imodel: IModelConnection): number[] {\r\n return this._selectionStorage.getSelectionLevels({ iModelKey: imodel.key });\r\n }\r\n\r\n /**\r\n * Get the selection currently stored in this manager\r\n *\r\n * @note Calling immediately after `add*`|`replace*`|`remove*`|`clear*` method call does not guarantee\r\n * that returned `KeySet` will include latest changes. Listen for `selectionChange` event to get the\r\n * latest selection after changes.\r\n */\r\n public getSelection(imodel: IModelConnection, level: number = 0): Readonly<KeySet> {\r\n return this._currentSelection.getSelection(imodel.key, level);\r\n }\r\n\r\n private handleEvent(evt: SelectionChangeEventArgs): void {\r\n if (!this._knownIModels.has(evt.imodel.key)) {\r\n this._knownIModels.set(evt.imodel.key, evt.imodel);\r\n }\r\n\r\n switch (evt.changeType) {\r\n case SelectionChangeType.Add:\r\n this._selectionStorage.addToSelection({\r\n iModelKey: evt.imodel.key,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Remove:\r\n this._selectionStorage.removeFromSelection({\r\n iModelKey: evt.imodel.key,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Replace:\r\n this._selectionStorage.replaceSelection({\r\n iModelKey: evt.imodel.key,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Clear:\r\n this._selectionStorage.clearSelection({ iModelKey: evt.imodel.key, source: evt.source, level: evt.level });\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Add keys to the selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public addToSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Add,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to remove\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public removeFromSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Remove,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Replace current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public replaceSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Replace,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Clear current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public clearSelection(source: string, imodel: IModelConnection, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Clear,\r\n keys: new KeySet(),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Add keys to selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to add\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async addToSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.addToSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to remove\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async removeFromSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.removeFromSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Replace current selection with keys after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to replace with\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async replaceSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.replaceSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Get the current hilite set for the specified imodel\r\n * @public\r\n */\r\n public async getHiliteSet(imodel: IModelConnection): Promise<HiliteSet> {\r\n return this.getHiliteSetProvider(imodel).getHiliteSet(this.getSelection(imodel));\r\n }\r\n\r\n /**\r\n * Get the current hilite set iterator for the specified imodel.\r\n * @public\r\n */\r\n public getHiliteSetIterator(imodel: IModelConnection) {\r\n return this.getHiliteSetProvider(imodel).getHiliteSetIterator(this.getSelection(imodel));\r\n }\r\n\r\n private getHiliteSetProvider(imodel: IModelConnection) {\r\n let provider = this._hiliteSetProviders.get(imodel);\r\n if (!provider) {\r\n provider = HiliteSetProvider.create({ imodel });\r\n this._hiliteSetProviders.set(imodel, provider);\r\n }\r\n return provider;\r\n }\r\n\r\n private streamSelectionEvents() {\r\n return this._selectionChanges\r\n .pipe(\r\n mergeMap((args) => {\r\n const currentSelectables = this._selectionStorage.getSelection({ iModelKey: args.imodelKey, level: args.level });\r\n return this._currentSelection.computeSelection(args.imodelKey, args.level, currentSelectables, args.selectables).pipe(\r\n mergeMap(({ level, changedSelection }): Observable<SelectionChangeEventArgs> => {\r\n const imodel = this._knownIModels.get(args.imodelKey);\r\n // istanbul ignore if\r\n if (!imodel) {\r\n return EMPTY;\r\n }\r\n return of({\r\n imodel,\r\n keys: changedSelection,\r\n level,\r\n source: args.source,\r\n timestamp: args.timestamp,\r\n changeType: getChangeType(args.changeType),\r\n });\r\n }),\r\n );\r\n }),\r\n )\r\n .subscribe({\r\n next: (args) => {\r\n this.selectionChange.raiseEvent(args, this);\r\n },\r\n });\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport class ToolSelectionSyncHandler implements IDisposable {\r\n private _selectionSourceName = \"Tool\";\r\n private _logicalSelection: SelectionManager;\r\n private _imodel: IModelConnection;\r\n private _imodelToolSelectionListenerDisposeFunc: () => void;\r\n private _asyncsTracker = new AsyncTasksTracker();\r\n public isSuspended?: boolean;\r\n\r\n public constructor(imodel: IModelConnection, logicalSelection: SelectionManager) {\r\n this._imodel = imodel;\r\n this._logicalSelection = logicalSelection;\r\n this._imodelToolSelectionListenerDisposeFunc = imodel.selectionSet.onChanged.addListener(this.onToolSelectionChanged);\r\n }\r\n\r\n public dispose() {\r\n this._imodelToolSelectionListenerDisposeFunc();\r\n }\r\n\r\n /** note: used only it tests */\r\n public get pendingAsyncs() {\r\n return this._asyncsTracker.pendingAsyncs;\r\n }\r\n\r\n private onToolSelectionChanged = async (ev: SelectionSetEvent): Promise<void> => {\r\n // ignore selection change event if the handler is suspended\r\n if (this.isSuspended) {\r\n return;\r\n }\r\n\r\n // this component only cares about its own imodel\r\n const imodel = ev.set.iModel;\r\n if (imodel !== this._imodel) {\r\n return;\r\n }\r\n\r\n // determine the level of selection changes\r\n // wip: may want to allow selecting at different levels?\r\n const selectionLevel = 0;\r\n\r\n let ids: SelectableIds;\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n ids = ev.additions;\r\n break;\r\n case SelectionSetEventType.Replace:\r\n ids = ev.set.active;\r\n break;\r\n default:\r\n ids = ev.removals;\r\n break;\r\n }\r\n\r\n // we're always using scoped selection changer even if the scope is set to \"element\" - that\r\n // makes sure we're adding to selection keys with concrete classes and not \"BisCore:Element\", which\r\n // we can't because otherwise our keys compare fails (presentation components load data with\r\n // concrete classes)\r\n const changer = new ScopedSelectionChanger(\r\n this._selectionSourceName,\r\n this._imodel,\r\n this._logicalSelection,\r\n createSelectionScopeProps(this._logicalSelection.scopes.activeScope),\r\n );\r\n\r\n await using(this._asyncsTracker.trackAsyncTask(), async (_r) => {\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n await changer.add(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Replace:\r\n await changer.replace(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Remove:\r\n await changer.remove(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Clear:\r\n await changer.clear(selectionLevel);\r\n break;\r\n }\r\n });\r\n };\r\n}\r\n\r\nconst parseElementIds = (ids: Id64Arg): { persistent: Id64Arg; transient: Id64Arg } => {\r\n let allPersistent = true;\r\n let allTransient = true;\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n allPersistent = false;\r\n } else {\r\n allTransient = false;\r\n }\r\n\r\n if (!allPersistent && !allTransient) {\r\n break;\r\n }\r\n }\r\n\r\n // avoid making a copy if ids are only persistent or only transient\r\n if (allPersistent) {\r\n return { persistent: ids, transient: [] };\r\n } else if (allTransient) {\r\n return { persistent: [], transient: ids };\r\n }\r\n\r\n // if `ids` contain mixed ids, we have to copy.. use Array instead of\r\n // a Set for performance\r\n const persistentElementIds: Id64Array = [];\r\n const transientElementIds: Id64Array = [];\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n transientElementIds.push(id);\r\n } else {\r\n persistentElementIds.push(id);\r\n }\r\n }\r\n\r\n return { persistent: persistentElementIds, transient: transientElementIds };\r\n};\r\n\r\nfunction addKeys(target: KeySet, className: string, ids: Id64Arg) {\r\n for (const id of Id64.iterable(ids)) {\r\n target.add({ className, id });\r\n }\r\n}\r\n\r\nclass ScopedSelectionChanger {\r\n public readonly name: string;\r\n public readonly imodel: IModelConnection;\r\n public readonly manager: SelectionManager;\r\n public readonly scope: SelectionScopeProps | SelectionScope | string;\r\n public constructor(name: string, imodel: IModelConnection, manager: SelectionManager, scope: SelectionScopeProps | SelectionScope | string) {\r\n this.name = name;\r\n this.imodel = imodel;\r\n this.manager = manager;\r\n this.scope = scope;\r\n }\r\n public async clear(level: number): Promise<void> {\r\n this.manager.clearSelection(this.name, this.imodel, level);\r\n }\r\n public async add(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.addToSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async remove(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.removeFromSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async replace(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.replaceSelection(this.name, this.imodel, keys, level);\r\n }\r\n async #computeSelection(ids: SelectableIds) {\r\n let keys = new KeySet();\r\n if (ids.elements) {\r\n const { persistent, transient } = parseElementIds(ids.elements);\r\n keys = await this.manager.scopes.computeSelection(this.imodel, persistent, this.scope);\r\n addKeys(keys, TRANSIENT_ELEMENT_CLASSNAME, transient);\r\n }\r\n if (ids.models) {\r\n addKeys(keys, \"BisCore.Model\", ids.models);\r\n }\r\n if (ids.subcategories) {\r\n addKeys(keys, \"BisCore.SubCategory\", ids.subcategories);\r\n }\r\n return keys;\r\n }\r\n}\r\n\r\n/** Stores current selection in `KeySet` format per iModel. */\r\nclass CurrentSelectionStorage {\r\n private _currentSelection = new Map<string, IModelSelectionStorage>();\r\n\r\n private getCurrentSelectionStorage(imodelKey: string) {\r\n let storage = this._currentSelection.get(imodelKey);\r\n if (!storage) {\r\n storage = new IModelSelectionStorage();\r\n this._currentSelection.set(imodelKey, storage);\r\n }\r\n return storage;\r\n }\r\n\r\n public getSelection(imodelKey: string, level: number) {\r\n return this.getCurrentSelectionStorage(imodelKey).getSelection(level);\r\n }\r\n\r\n public clear(imodelKey: string) {\r\n this._currentSelection.delete(imodelKey);\r\n }\r\n\r\n public computeSelection(imodelKey: string, level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n return this.getCurrentSelectionStorage(imodelKey).computeSelection(level, currSelectables, changedSelectables);\r\n }\r\n}\r\n\r\ninterface StorageEntry {\r\n value: KeySet;\r\n ongoingComputationDisposers: Set<Subject<void>>;\r\n}\r\n\r\n/**\r\n * Computes and stores current selection in `KeySet` format.\r\n * It always stores result of latest resolved call to `computeSelection`.\r\n */\r\nclass IModelSelectionStorage {\r\n private _currentSelection = new Map<number, StorageEntry>();\r\n\r\n public getSelection(level: number): KeySet {\r\n let entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n entry = { value: new KeySet(), ongoingComputationDisposers: new Set() };\r\n this._currentSelection.set(level, entry);\r\n }\r\n return entry.value;\r\n }\r\n\r\n private clearSelections(level: number) {\r\n const clearedLevels = [];\r\n for (const [storedLevel] of this._currentSelection.entries()) {\r\n if (storedLevel > level) {\r\n clearedLevels.push(storedLevel);\r\n }\r\n }\r\n clearedLevels.forEach((storedLevel) => {\r\n const entry = this._currentSelection.get(storedLevel);\r\n // istanbul ignore if\r\n if (!entry) {\r\n return;\r\n }\r\n\r\n for (const disposer of entry.ongoingComputationDisposers) {\r\n disposer.next();\r\n }\r\n this._currentSelection.delete(storedLevel);\r\n });\r\n }\r\n\r\n private addDisposer(level: number, disposer: Subject<void>) {\r\n const entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n this._currentSelection.set(level, { value: new KeySet(), ongoingComputationDisposers: new Set([disposer]) });\r\n return;\r\n }\r\n entry.ongoingComputationDisposers.add(disposer);\r\n }\r\n\r\n private setSelection(level: number, keys: KeySet, disposer: Subject<void>) {\r\n const currEntry = this._currentSelection.get(level);\r\n // istanbul ignore else\r\n if (currEntry) {\r\n currEntry.ongoingComputationDisposers.delete(disposer);\r\n }\r\n this._currentSelection.set(level, {\r\n value: keys,\r\n ongoingComputationDisposers: currEntry?.ongoingComputationDisposers ?? /* istanbul ignore next */ new Set(),\r\n });\r\n }\r\n\r\n public computeSelection(level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n this.clearSelections(level);\r\n\r\n const prevComputationsDisposers = [...(this._currentSelection.get(level)?.ongoingComputationDisposers ?? [])];\r\n const currDisposer = new Subject<void>();\r\n this.addDisposer(level, currDisposer);\r\n\r\n return defer(async () => {\r\n const convertedSelectables: SelectableKeys[] = [];\r\n const [current, changed] = await Promise.all([\r\n selectablesToKeys(currSelectables, convertedSelectables),\r\n selectablesToKeys(changedSelectables, convertedSelectables),\r\n ]);\r\n\r\n const currentSelection = new KeySet([...current.keys, ...current.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n const changedSelection = new KeySet([...changed.keys, ...changed.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n\r\n return {\r\n level,\r\n currentSelection,\r\n changedSelection,\r\n };\r\n }).pipe(\r\n takeUntil(currDisposer),\r\n tap({\r\n next: (val) => {\r\n prevComputationsDisposers.forEach((disposer) => disposer.next());\r\n this.setSelection(val.level, val.currentSelection, currDisposer);\r\n },\r\n }),\r\n );\r\n }\r\n}\r\n\r\nfunction keysToSelectable(imodel: IModelConnection, keys: Readonly<KeySet>) {\r\n const selectables: Selectable[] = [];\r\n keys.forEach((key) => {\r\n if (\"id\" in key) {\r\n selectables.push(key);\r\n return;\r\n }\r\n\r\n const customSelectable: CustomSelectable = {\r\n identifier: key.pathFromRoot.join(\"/\"),\r\n data: key,\r\n loadInstanceKeys: () => createInstanceKeysIterator(imodel, key),\r\n };\r\n selectables.push(customSelectable);\r\n });\r\n return selectables;\r\n}\r\n\r\ninterface SelectableKeys {\r\n identifier: string;\r\n keys: Key[];\r\n}\r\n\r\nasync function selectablesToKeys(selectables: Selectables, convertedList: SelectableKeys[]) {\r\n const keys: Key[] = [];\r\n const selectableKeys: SelectableKeys[] = [];\r\n\r\n for (const [className, ids] of selectables.instanceKeys) {\r\n for (const id of ids) {\r\n keys.push({ id, className });\r\n }\r\n }\r\n\r\n for (const [_, selectable] of selectables.custom) {\r\n if (isNodeKey(selectable.data)) {\r\n selectableKeys.push({ identifier: selectable.identifier, keys: [selectable.data] });\r\n continue;\r\n }\r\n const converted = convertedList.find((con) => con.identifier === selectable.identifier);\r\n if (converted) {\r\n selectableKeys.push(converted);\r\n continue;\r\n }\r\n\r\n const newConverted: SelectableKeys = { identifier: selectable.identifier, keys: [] };\r\n convertedList.push(newConverted);\r\n for await (const instanceKey of selectable.loadInstanceKeys()) {\r\n newConverted.keys.push(instanceKey);\r\n }\r\n selectableKeys.push(newConverted);\r\n }\r\n\r\n return { keys, selectableKeys };\r\n}\r\n\r\nasync function* createInstanceKeysIterator(imodel: IModelConnection, nodeKey: NodeKey): AsyncIterableIterator<InstanceKey> {\r\n if (NodeKey.isInstancesNodeKey(nodeKey)) {\r\n for (const key of nodeKey.instanceKeys) {\r\n yield key;\r\n }\r\n return;\r\n }\r\n\r\n const content = await Presentation.presentation.getContentInstanceKeys({\r\n imodel,\r\n keys: new KeySet([nodeKey]),\r\n rulesetOrId: {\r\n id: \"grouped-instances\",\r\n rules: [\r\n {\r\n ruleType: \"Content\",\r\n specifications: [\r\n {\r\n specType: \"SelectedNodeInstances\",\r\n },\r\n ],\r\n },\r\n ],\r\n },\r\n });\r\n\r\n for await (const key of content.items()) {\r\n yield key;\r\n }\r\n}\r\n\r\nfunction isNodeKey(data: unknown): data is NodeKey {\r\n const key = data as BaseNodeKey;\r\n return key.pathFromRoot !== undefined && key.type !== undefined;\r\n}\r\n\r\nfunction getChangeType(type: StorageSelectionChangeType): SelectionChangeType {\r\n switch (type) {\r\n case \"add\":\r\n return SelectionChangeType.Add;\r\n case \"remove\":\r\n return SelectionChangeType.Remove;\r\n case \"replace\":\r\n return SelectionChangeType.Replace;\r\n case \"clear\":\r\n return SelectionChangeType.Clear;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"SelectionManager.js","sourceRoot":"","sources":["../../../../src/presentation-frontend/selection/SelectionManager.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;AAEH,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAc,EAAE,EAAE,OAAO,EAAgB,SAAS,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACrG,OAAO,EAAE,IAAI,EAAmC,KAAK,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAoC,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAuC,MAAM,EAAE,OAAO,EAAuC,MAAM,4BAA4B,CAAC;AAC1J,OAAO,EACL,aAAa,EAOb,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAa,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,oBAAoB,EAA4B,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7G,OAA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C;QAC3B,WAAW,EAAE;YACX,EAAE,EAAE,mBAAmB;YACvB,KAAK,EAAE;gBACL;oBACE,QAAQ,EAAE,SAAS;oBACnB,cAAc,EAAE;wBACd;4BACE,QAAQ,EAAE,uBAAuB;yBAClC;qBACF;iBACF;aACF;SACF;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QACxC,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,IAAa;IAC9B,MAAM,GAAG,GAAG,IAAmB,CAAC;IAChC,OAAO,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC;AAClE,CAAC;AAED,SAAS,aAAa,CAAC,IAAgC;IACrD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,KAAK;YACR,OAAO,mBAAmB,CAAC,GAAG,CAAC;QACjC,KAAK,QAAQ;YACX,OAAO,mBAAmB,CAAC,MAAM,CAAC;QACpC,KAAK,SAAS;YACZ,OAAO,mBAAmB,CAAC,OAAO,CAAC;QACrC,KAAK,OAAO;YACV,OAAO,mBAAmB,CAAC,KAAK,CAAC;IACrC,CAAC;AACH,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 UnifiedSelection\r\n */\r\n\r\nimport { defer, EMPTY, mergeMap, Observable, of, Subject, Subscription, takeUntil, tap } from \"rxjs\";\r\nimport { Id64, Id64Arg, Id64Array, IDisposable, using } from \"@itwin/core-bentley\";\r\nimport { IModelConnection, SelectableIds, SelectionSetEvent, SelectionSetEventType } from \"@itwin/core-frontend\";\r\nimport { AsyncTasksTracker, BaseNodeKey, InstanceKey, Key, Keys, KeySet, NodeKey, SelectionScope, SelectionScopeProps } from \"@itwin/presentation-common\";\r\nimport {\r\n createStorage,\r\n CustomSelectable,\r\n Selectable,\r\n Selectables,\r\n SelectionStorage,\r\n StorageSelectionChangeEventArgs,\r\n StorageSelectionChangeType,\r\n TRANSIENT_ELEMENT_CLASSNAME,\r\n} from \"@itwin/unified-selection\";\r\nimport { Presentation } from \"../Presentation\";\r\nimport { HiliteSet, HiliteSetProvider } from \"./HiliteSetProvider\";\r\nimport { ISelectionProvider } from \"./ISelectionProvider\";\r\nimport { SelectionChangeEvent, SelectionChangeEventArgs, SelectionChangeType } from \"./SelectionChangeEvent\";\r\nimport { createSelectionScopeProps, SelectionScopesManager } from \"./SelectionScopesManager\";\r\n\r\n/**\r\n * Properties for creating [[SelectionManager]].\r\n * @public\r\n */\r\nexport interface SelectionManagerProps {\r\n /** A manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n scopes: SelectionScopesManager;\r\n\r\n /**\r\n * Custom unified selection storage to be used by [[SelectionManager]]. If not provided [[SelectionManager]] creates\r\n * and maintains storage.\r\n */\r\n selectionStorage?: SelectionStorage;\r\n\r\n /**\r\n * An optional function that returns a key for the given iModel. The key is what \"glues\" iModel selection\r\n * changes made in `selectionStorage`, where iModels are identified by key, and `SelectionManager`, where\r\n * iModels are specified as `IModelConnection`.\r\n *\r\n * If not provided, [IModelConnection.key]($core-frontend) or [IModelConnection.name]($core-frontend) is used.\r\n */\r\n imodelKeyFactory?: (imodel: IModelConnection) => string;\r\n}\r\n\r\n/**\r\n * The selection manager which stores the overall selection.\r\n * @public\r\n */\r\nexport class SelectionManager implements ISelectionProvider {\r\n private _imodelKeyFactory: (imodel: IModelConnection) => string;\r\n private _imodelToolSelectionSyncHandlers = new Map<IModelConnection, { requestorsCount: number; handler: ToolSelectionSyncHandler }>();\r\n private _hiliteSetProviders = new Map<IModelConnection, HiliteSetProvider>();\r\n private _ownsStorage: boolean;\r\n\r\n private _knownIModels = new Set<IModelConnection>();\r\n private _currentSelection = new CurrentSelectionStorage();\r\n private _selectionChanges = new Subject<StorageSelectionChangeEventArgs>();\r\n private _selectionEventsSubscription: Subscription;\r\n private _listeners: Array<() => void> = [];\r\n\r\n /**\r\n * Underlying selection storage used by this selection manager. Ideally, consumers should use\r\n * the storage directly instead of using this manager to manipulate selection.\r\n */\r\n public readonly selectionStorage: SelectionStorage;\r\n\r\n /** An event which gets broadcasted on selection changes */\r\n public readonly selectionChange: SelectionChangeEvent;\r\n\r\n /** Manager for [selection scopes]($docs/presentation/unified-selection/index#selection-scopes) */\r\n public readonly scopes: SelectionScopesManager;\r\n\r\n /**\r\n * Creates an instance of SelectionManager.\r\n */\r\n constructor(props: SelectionManagerProps) {\r\n this.selectionChange = new SelectionChangeEvent();\r\n this.scopes = props.scopes;\r\n this.selectionStorage = props.selectionStorage ?? createStorage();\r\n this._imodelKeyFactory = props.imodelKeyFactory ?? ((imodel) => (imodel.key.length ? imodel.key : imodel.name));\r\n this._ownsStorage = props.selectionStorage === undefined;\r\n this.selectionStorage.selectionChangeEvent.addListener((args) => this._selectionChanges.next(args));\r\n this._selectionEventsSubscription = this.streamSelectionEvents();\r\n this._listeners.push(\r\n IModelConnection.onOpen.addListener((imodel) => {\r\n this._knownIModels.add(imodel);\r\n }),\r\n );\r\n this._listeners.push(\r\n IModelConnection.onClose.addListener((imodel: IModelConnection) => {\r\n this.onConnectionClose(imodel);\r\n }),\r\n );\r\n }\r\n\r\n public dispose() {\r\n this._selectionEventsSubscription.unsubscribe();\r\n this._listeners.forEach((dispose) => dispose());\r\n }\r\n\r\n private onConnectionClose(imodel: IModelConnection): void {\r\n const imodelKey = this._imodelKeyFactory(imodel);\r\n this._hiliteSetProviders.delete(imodel);\r\n this._knownIModels.delete(imodel);\r\n this._currentSelection.clear(imodelKey);\r\n if (this._ownsStorage) {\r\n this.clearSelection(\"Connection Close Event\", imodel);\r\n this.selectionStorage.clearStorage({ imodelKey });\r\n }\r\n }\r\n\r\n /** @internal */\r\n // istanbul ignore next\r\n public getToolSelectionSyncHandler(imodel: IModelConnection) {\r\n return this._imodelToolSelectionSyncHandlers.get(imodel)?.handler;\r\n }\r\n\r\n /**\r\n * Request the manager to sync with imodel's tool selection (see `IModelConnection.selectionSet`).\r\n */\r\n public setSyncWithIModelToolSelection(imodel: IModelConnection, sync = true) {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (sync) {\r\n if (!registration || registration.requestorsCount === 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { requestorsCount: 1, handler: new ToolSelectionSyncHandler(imodel, this) });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount: registration.requestorsCount + 1 });\r\n }\r\n } else {\r\n if (registration && registration.requestorsCount > 0) {\r\n const requestorsCount = registration.requestorsCount - 1;\r\n if (requestorsCount > 0) {\r\n this._imodelToolSelectionSyncHandlers.set(imodel, { ...registration, requestorsCount });\r\n } else {\r\n this._imodelToolSelectionSyncHandlers.delete(imodel);\r\n registration.handler.dispose();\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Temporarily suspends tool selection synchronization until the returned `IDisposable`\r\n * is disposed.\r\n */\r\n public suspendIModelToolSelectionSync(imodel: IModelConnection): IDisposable {\r\n const registration = this._imodelToolSelectionSyncHandlers.get(imodel);\r\n if (!registration) {\r\n return { dispose: () => {} };\r\n }\r\n\r\n const wasSuspended = registration.handler.isSuspended;\r\n registration.handler.isSuspended = true;\r\n return { dispose: () => (registration.handler.isSuspended = wasSuspended) };\r\n }\r\n\r\n /** Get the selection levels currently stored in this manager for the specified imodel */\r\n public getSelectionLevels(imodel: IModelConnection): number[] {\r\n const imodelKey = this._imodelKeyFactory(imodel);\r\n return this.selectionStorage.getSelectionLevels({ imodelKey });\r\n }\r\n\r\n /**\r\n * Get the selection currently stored in this manager\r\n *\r\n * @note Calling immediately after `add*`|`replace*`|`remove*`|`clear*` method call does not guarantee\r\n * that returned `KeySet` will include latest changes. Listen for `selectionChange` event to get the\r\n * latest selection after changes.\r\n */\r\n public getSelection(imodel: IModelConnection, level: number = 0): Readonly<KeySet> {\r\n const imodelKey = this._imodelKeyFactory(imodel);\r\n return this._currentSelection.getSelection(imodelKey, level);\r\n }\r\n\r\n private handleEvent(evt: SelectionChangeEventArgs): void {\r\n const imodelKey = this._imodelKeyFactory(evt.imodel);\r\n this._knownIModels.add(evt.imodel);\r\n switch (evt.changeType) {\r\n case SelectionChangeType.Add:\r\n this.selectionStorage.addToSelection({\r\n imodelKey,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Remove:\r\n this.selectionStorage.removeFromSelection({\r\n imodelKey,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Replace:\r\n this.selectionStorage.replaceSelection({\r\n imodelKey,\r\n source: evt.source,\r\n level: evt.level,\r\n selectables: keysToSelectable(evt.imodel, evt.keys),\r\n });\r\n break;\r\n case SelectionChangeType.Clear:\r\n this.selectionStorage.clearSelection({ imodelKey, source: evt.source, level: evt.level });\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Add keys to the selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public addToSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Add,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to remove\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public removeFromSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Remove,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Replace current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param keys Keys to add\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public replaceSelection(source: string, imodel: IModelConnection, keys: Keys, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Replace,\r\n keys: new KeySet(keys),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Clear current selection\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public clearSelection(source: string, imodel: IModelConnection, level: number = 0, rulesetId?: string): void {\r\n const evt: SelectionChangeEventArgs = {\r\n source,\r\n level,\r\n imodel,\r\n changeType: SelectionChangeType.Clear,\r\n keys: new KeySet(),\r\n timestamp: new Date(),\r\n rulesetId,\r\n };\r\n this.handleEvent(evt);\r\n }\r\n\r\n /**\r\n * Add keys to selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to add\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async addToSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.addToSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Remove keys from current selection after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to remove\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async removeFromSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.removeFromSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Replace current selection with keys after applying [selection scope]($docs/presentation/unified-selection/index#selection-scopes) on them.\r\n * @param source Name of the selection source\r\n * @param imodel iModel associated with the selection\r\n * @param ids Element IDs to replace with\r\n * @param scope Selection scope to apply\r\n * @param level Selection level (see [selection levels documentation section]($docs/presentation/unified-selection/index#selection-levels))\r\n * @param rulesetId ID of the ruleset in case the selection was changed from a rules-driven control\r\n */\r\n public async replaceSelectionWithScope(\r\n source: string,\r\n imodel: IModelConnection,\r\n ids: Id64Arg,\r\n scope: SelectionScopeProps | SelectionScope | string,\r\n level: number = 0,\r\n rulesetId?: string,\r\n ): Promise<void> {\r\n const scopedKeys = await this.scopes.computeSelection(imodel, ids, scope);\r\n this.replaceSelection(source, imodel, scopedKeys, level, rulesetId);\r\n }\r\n\r\n /**\r\n * Get the current hilite set for the specified imodel\r\n * @public\r\n */\r\n public async getHiliteSet(imodel: IModelConnection): Promise<HiliteSet> {\r\n return this.getHiliteSetProvider(imodel).getHiliteSet(this.getSelection(imodel));\r\n }\r\n\r\n /**\r\n * Get the current hilite set iterator for the specified imodel.\r\n * @public\r\n */\r\n public getHiliteSetIterator(imodel: IModelConnection) {\r\n return this.getHiliteSetProvider(imodel).getHiliteSetIterator(this.getSelection(imodel));\r\n }\r\n\r\n private getHiliteSetProvider(imodel: IModelConnection) {\r\n let provider = this._hiliteSetProviders.get(imodel);\r\n if (!provider) {\r\n provider = HiliteSetProvider.create({ imodel });\r\n this._hiliteSetProviders.set(imodel, provider);\r\n }\r\n return provider;\r\n }\r\n\r\n private streamSelectionEvents() {\r\n return this._selectionChanges\r\n .pipe(\r\n mergeMap((args) => {\r\n const currentSelectables = this.selectionStorage.getSelection({ imodelKey: args.imodelKey, level: args.level });\r\n return this._currentSelection.computeSelection(args.imodelKey, args.level, currentSelectables, args.selectables).pipe(\r\n mergeMap(({ level, changedSelection }): Observable<SelectionChangeEventArgs> => {\r\n const imodel = findIModel(this._knownIModels, this._imodelKeyFactory, args.imodelKey);\r\n // istanbul ignore if\r\n if (!imodel) {\r\n return EMPTY;\r\n }\r\n return of({\r\n imodel,\r\n keys: changedSelection,\r\n level,\r\n source: args.source,\r\n timestamp: args.timestamp,\r\n changeType: getChangeType(args.changeType),\r\n });\r\n }),\r\n );\r\n }),\r\n )\r\n .subscribe({\r\n next: (args) => {\r\n this.selectionChange.raiseEvent(args, this);\r\n },\r\n });\r\n }\r\n}\r\n\r\nfunction findIModel(set: Set<IModelConnection>, imodelKeyFactory: (imodel: IModelConnection) => string, key: string) {\r\n for (const imodel of set) {\r\n if (imodelKeyFactory(imodel) === key) {\r\n return imodel;\r\n }\r\n }\r\n return undefined;\r\n}\r\n\r\n/** @internal */\r\nexport class ToolSelectionSyncHandler implements IDisposable {\r\n private _selectionSourceName = \"Tool\";\r\n private _logicalSelection: SelectionManager;\r\n private _imodel: IModelConnection;\r\n private _imodelToolSelectionListenerDisposeFunc: () => void;\r\n private _asyncsTracker = new AsyncTasksTracker();\r\n public isSuspended?: boolean;\r\n\r\n public constructor(imodel: IModelConnection, logicalSelection: SelectionManager) {\r\n this._imodel = imodel;\r\n this._logicalSelection = logicalSelection;\r\n this._imodelToolSelectionListenerDisposeFunc = imodel.selectionSet.onChanged.addListener(this.onToolSelectionChanged);\r\n }\r\n\r\n public dispose() {\r\n this._imodelToolSelectionListenerDisposeFunc();\r\n }\r\n\r\n /** note: used only it tests */\r\n public get pendingAsyncs() {\r\n return this._asyncsTracker.pendingAsyncs;\r\n }\r\n\r\n private onToolSelectionChanged = async (ev: SelectionSetEvent): Promise<void> => {\r\n // ignore selection change event if the handler is suspended\r\n if (this.isSuspended) {\r\n return;\r\n }\r\n\r\n // this component only cares about its own imodel\r\n const imodel = ev.set.iModel;\r\n if (imodel !== this._imodel) {\r\n return;\r\n }\r\n\r\n // determine the level of selection changes\r\n // wip: may want to allow selecting at different levels?\r\n const selectionLevel = 0;\r\n\r\n let ids: SelectableIds;\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n ids = ev.additions;\r\n break;\r\n case SelectionSetEventType.Replace:\r\n ids = ev.set.active;\r\n break;\r\n default:\r\n ids = ev.removals;\r\n break;\r\n }\r\n\r\n // we're always using scoped selection changer even if the scope is set to \"element\" - that\r\n // makes sure we're adding to selection keys with concrete classes and not \"BisCore:Element\", which\r\n // we can't because otherwise our keys compare fails (presentation components load data with\r\n // concrete classes)\r\n const changer = new ScopedSelectionChanger(\r\n this._selectionSourceName,\r\n this._imodel,\r\n this._logicalSelection,\r\n createSelectionScopeProps(this._logicalSelection.scopes.activeScope),\r\n );\r\n\r\n await using(this._asyncsTracker.trackAsyncTask(), async (_r) => {\r\n switch (ev.type) {\r\n case SelectionSetEventType.Add:\r\n await changer.add(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Replace:\r\n await changer.replace(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Remove:\r\n await changer.remove(ids, selectionLevel);\r\n break;\r\n case SelectionSetEventType.Clear:\r\n await changer.clear(selectionLevel);\r\n break;\r\n }\r\n });\r\n };\r\n}\r\n\r\nconst parseElementIds = (ids: Id64Arg): { persistent: Id64Arg; transient: Id64Arg } => {\r\n let allPersistent = true;\r\n let allTransient = true;\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n allPersistent = false;\r\n } else {\r\n allTransient = false;\r\n }\r\n\r\n if (!allPersistent && !allTransient) {\r\n break;\r\n }\r\n }\r\n\r\n // avoid making a copy if ids are only persistent or only transient\r\n if (allPersistent) {\r\n return { persistent: ids, transient: [] };\r\n } else if (allTransient) {\r\n return { persistent: [], transient: ids };\r\n }\r\n\r\n // if `ids` contain mixed ids, we have to copy.. use Array instead of\r\n // a Set for performance\r\n const persistentElementIds: Id64Array = [];\r\n const transientElementIds: Id64Array = [];\r\n for (const id of Id64.iterable(ids)) {\r\n if (Id64.isTransient(id)) {\r\n transientElementIds.push(id);\r\n } else {\r\n persistentElementIds.push(id);\r\n }\r\n }\r\n\r\n return { persistent: persistentElementIds, transient: transientElementIds };\r\n};\r\n\r\nfunction addKeys(target: KeySet, className: string, ids: Id64Arg) {\r\n for (const id of Id64.iterable(ids)) {\r\n target.add({ className, id });\r\n }\r\n}\r\n\r\nclass ScopedSelectionChanger {\r\n public readonly name: string;\r\n public readonly imodel: IModelConnection;\r\n public readonly manager: SelectionManager;\r\n public readonly scope: SelectionScopeProps | SelectionScope | string;\r\n public constructor(name: string, imodel: IModelConnection, manager: SelectionManager, scope: SelectionScopeProps | SelectionScope | string) {\r\n this.name = name;\r\n this.imodel = imodel;\r\n this.manager = manager;\r\n this.scope = scope;\r\n }\r\n public async clear(level: number): Promise<void> {\r\n this.manager.clearSelection(this.name, this.imodel, level);\r\n }\r\n public async add(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.addToSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async remove(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.removeFromSelection(this.name, this.imodel, keys, level);\r\n }\r\n public async replace(ids: SelectableIds, level: number): Promise<void> {\r\n const keys = await this.#computeSelection(ids);\r\n this.manager.replaceSelection(this.name, this.imodel, keys, level);\r\n }\r\n async #computeSelection(ids: SelectableIds) {\r\n let keys = new KeySet();\r\n if (ids.elements) {\r\n const { persistent, transient } = parseElementIds(ids.elements);\r\n keys = await this.manager.scopes.computeSelection(this.imodel, persistent, this.scope);\r\n addKeys(keys, TRANSIENT_ELEMENT_CLASSNAME, transient);\r\n }\r\n if (ids.models) {\r\n addKeys(keys, \"BisCore.Model\", ids.models);\r\n }\r\n if (ids.subcategories) {\r\n addKeys(keys, \"BisCore.SubCategory\", ids.subcategories);\r\n }\r\n return keys;\r\n }\r\n}\r\n\r\n/** Stores current selection in `KeySet` format per iModel. */\r\nclass CurrentSelectionStorage {\r\n private _currentSelection = new Map<string, IModelSelectionStorage>();\r\n\r\n private getCurrentSelectionStorage(imodelKey: string) {\r\n let storage = this._currentSelection.get(imodelKey);\r\n if (!storage) {\r\n storage = new IModelSelectionStorage();\r\n this._currentSelection.set(imodelKey, storage);\r\n }\r\n return storage;\r\n }\r\n\r\n public getSelection(imodelKey: string, level: number) {\r\n return this.getCurrentSelectionStorage(imodelKey).getSelection(level);\r\n }\r\n\r\n public clear(imodelKey: string) {\r\n this._currentSelection.delete(imodelKey);\r\n }\r\n\r\n public computeSelection(imodelKey: string, level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n return this.getCurrentSelectionStorage(imodelKey).computeSelection(level, currSelectables, changedSelectables);\r\n }\r\n}\r\n\r\ninterface StorageEntry {\r\n value: KeySet;\r\n ongoingComputationDisposers: Set<Subject<void>>;\r\n}\r\n\r\n/**\r\n * Computes and stores current selection in `KeySet` format.\r\n * It always stores result of latest resolved call to `computeSelection`.\r\n */\r\nclass IModelSelectionStorage {\r\n private _currentSelection = new Map<number, StorageEntry>();\r\n\r\n public getSelection(level: number): KeySet {\r\n let entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n entry = { value: new KeySet(), ongoingComputationDisposers: new Set() };\r\n this._currentSelection.set(level, entry);\r\n }\r\n return entry.value;\r\n }\r\n\r\n private clearSelections(level: number) {\r\n const clearedLevels = [];\r\n for (const [storedLevel] of this._currentSelection.entries()) {\r\n if (storedLevel > level) {\r\n clearedLevels.push(storedLevel);\r\n }\r\n }\r\n clearedLevels.forEach((storedLevel) => {\r\n const entry = this._currentSelection.get(storedLevel);\r\n // istanbul ignore if\r\n if (!entry) {\r\n return;\r\n }\r\n\r\n for (const disposer of entry.ongoingComputationDisposers) {\r\n disposer.next();\r\n }\r\n this._currentSelection.delete(storedLevel);\r\n });\r\n }\r\n\r\n private addDisposer(level: number, disposer: Subject<void>) {\r\n const entry = this._currentSelection.get(level);\r\n if (!entry) {\r\n this._currentSelection.set(level, { value: new KeySet(), ongoingComputationDisposers: new Set([disposer]) });\r\n return;\r\n }\r\n entry.ongoingComputationDisposers.add(disposer);\r\n }\r\n\r\n private setSelection(level: number, keys: KeySet, disposer: Subject<void>) {\r\n const currEntry = this._currentSelection.get(level);\r\n // istanbul ignore else\r\n if (currEntry) {\r\n currEntry.ongoingComputationDisposers.delete(disposer);\r\n }\r\n this._currentSelection.set(level, {\r\n value: keys,\r\n ongoingComputationDisposers: currEntry?.ongoingComputationDisposers ?? /* istanbul ignore next */ new Set(),\r\n });\r\n }\r\n\r\n public computeSelection(level: number, currSelectables: Selectables, changedSelectables: Selectables) {\r\n this.clearSelections(level);\r\n\r\n const prevComputationsDisposers = [...(this._currentSelection.get(level)?.ongoingComputationDisposers ?? [])];\r\n const currDisposer = new Subject<void>();\r\n this.addDisposer(level, currDisposer);\r\n\r\n return defer(async () => {\r\n const convertedSelectables: SelectableKeys[] = [];\r\n const [current, changed] = await Promise.all([\r\n selectablesToKeys(currSelectables, convertedSelectables),\r\n selectablesToKeys(changedSelectables, convertedSelectables),\r\n ]);\r\n\r\n const currentSelection = new KeySet([...current.keys, ...current.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n const changedSelection = new KeySet([...changed.keys, ...changed.selectableKeys.flatMap((selectable) => selectable.keys)]);\r\n\r\n return {\r\n level,\r\n currentSelection,\r\n changedSelection,\r\n };\r\n }).pipe(\r\n takeUntil(currDisposer),\r\n tap({\r\n next: (val) => {\r\n prevComputationsDisposers.forEach((disposer) => disposer.next());\r\n this.setSelection(val.level, val.currentSelection, currDisposer);\r\n },\r\n }),\r\n );\r\n }\r\n}\r\n\r\nfunction keysToSelectable(imodel: IModelConnection, keys: Readonly<KeySet>) {\r\n const selectables: Selectable[] = [];\r\n keys.forEach((key) => {\r\n if (\"id\" in key) {\r\n selectables.push(key);\r\n return;\r\n }\r\n\r\n const customSelectable: CustomSelectable = {\r\n identifier: key.pathFromRoot.join(\"/\"),\r\n data: key,\r\n loadInstanceKeys: () => createInstanceKeysIterator(imodel, key),\r\n };\r\n selectables.push(customSelectable);\r\n });\r\n return selectables;\r\n}\r\n\r\ninterface SelectableKeys {\r\n identifier: string;\r\n keys: Key[];\r\n}\r\n\r\nasync function selectablesToKeys(selectables: Selectables, convertedList: SelectableKeys[]) {\r\n const keys: Key[] = [];\r\n const selectableKeys: SelectableKeys[] = [];\r\n\r\n for (const [className, ids] of selectables.instanceKeys) {\r\n for (const id of ids) {\r\n keys.push({ id, className });\r\n }\r\n }\r\n\r\n for (const [_, selectable] of selectables.custom) {\r\n if (isNodeKey(selectable.data)) {\r\n selectableKeys.push({ identifier: selectable.identifier, keys: [selectable.data] });\r\n continue;\r\n }\r\n const converted = convertedList.find((con) => con.identifier === selectable.identifier);\r\n if (converted) {\r\n selectableKeys.push(converted);\r\n continue;\r\n }\r\n\r\n const newConverted: SelectableKeys = { identifier: selectable.identifier, keys: [] };\r\n convertedList.push(newConverted);\r\n for await (const instanceKey of selectable.loadInstanceKeys()) {\r\n newConverted.keys.push(instanceKey);\r\n }\r\n selectableKeys.push(newConverted);\r\n }\r\n\r\n return { keys, selectableKeys };\r\n}\r\n\r\nasync function* createInstanceKeysIterator(imodel: IModelConnection, nodeKey: NodeKey): AsyncIterableIterator<InstanceKey> {\r\n if (NodeKey.isInstancesNodeKey(nodeKey)) {\r\n for (const key of nodeKey.instanceKeys) {\r\n yield key;\r\n }\r\n return;\r\n }\r\n\r\n const content = await Presentation.presentation.getContentInstanceKeys({\r\n imodel,\r\n keys: new KeySet([nodeKey]),\r\n rulesetOrId: {\r\n id: \"grouped-instances\",\r\n rules: [\r\n {\r\n ruleType: \"Content\",\r\n specifications: [\r\n {\r\n specType: \"SelectedNodeInstances\",\r\n },\r\n ],\r\n },\r\n ],\r\n },\r\n });\r\n\r\n for await (const key of content.items()) {\r\n yield key;\r\n }\r\n}\r\n\r\nfunction isNodeKey(data: unknown): data is NodeKey {\r\n const key = data as BaseNodeKey;\r\n return key.pathFromRoot !== undefined && key.type !== undefined;\r\n}\r\n\r\nfunction getChangeType(type: StorageSelectionChangeType): SelectionChangeType {\r\n switch (type) {\r\n case \"add\":\r\n return SelectionChangeType.Add;\r\n case \"remove\":\r\n return SelectionChangeType.Remove;\r\n case \"replace\":\r\n return SelectionChangeType.Replace;\r\n case \"clear\":\r\n return SelectionChangeType.Clear;\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-frontend",
|
|
3
|
-
"version": "5.0.0-dev.
|
|
3
|
+
"version": "5.0.0-dev.28",
|
|
4
4
|
"description": "Frontend of iModel.js Presentation library",
|
|
5
5
|
"main": "lib/cjs/presentation-frontend.js",
|
|
6
6
|
"module": "lib/esm/presentation-frontend.js",
|
|
@@ -23,17 +23,17 @@
|
|
|
23
23
|
"url": "http://www.bentley.com"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@itwin/unified-selection": "^1.
|
|
26
|
+
"@itwin/unified-selection": "^1.2.0",
|
|
27
27
|
"rxjs": "^7.8.1",
|
|
28
28
|
"rxjs-for-await": "^1.0.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@itwin/core-bentley": "5.0.0-dev.
|
|
32
|
-
"@itwin/core-
|
|
33
|
-
"@itwin/core-
|
|
34
|
-
"@itwin/
|
|
35
|
-
"@itwin/
|
|
36
|
-
"@itwin/presentation-common": "5.0.0-dev.
|
|
31
|
+
"@itwin/core-bentley": "5.0.0-dev.28",
|
|
32
|
+
"@itwin/core-frontend": "5.0.0-dev.28",
|
|
33
|
+
"@itwin/core-common": "5.0.0-dev.28",
|
|
34
|
+
"@itwin/ecschema-metadata": "5.0.0-dev.28",
|
|
35
|
+
"@itwin/core-quantity": "5.0.0-dev.28",
|
|
36
|
+
"@itwin/presentation-common": "5.0.0-dev.28"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
@@ -65,14 +65,14 @@
|
|
|
65
65
|
"source-map-support": "^0.5.6",
|
|
66
66
|
"typemoq": "^2.1.0",
|
|
67
67
|
"typescript": "~5.6.2",
|
|
68
|
-
"@itwin/build-tools": "5.0.0-dev.
|
|
69
|
-
"@itwin/core-
|
|
70
|
-
"@itwin/core-
|
|
71
|
-
"@itwin/core-frontend": "5.0.0-dev.
|
|
72
|
-
"@itwin/core-i18n": "5.0.0-dev.
|
|
73
|
-
"@itwin/core-quantity": "5.0.0-dev.
|
|
74
|
-
"@itwin/
|
|
75
|
-
"@itwin/
|
|
68
|
+
"@itwin/build-tools": "5.0.0-dev.28",
|
|
69
|
+
"@itwin/core-bentley": "5.0.0-dev.28",
|
|
70
|
+
"@itwin/core-common": "5.0.0-dev.28",
|
|
71
|
+
"@itwin/core-frontend": "5.0.0-dev.28",
|
|
72
|
+
"@itwin/core-i18n": "5.0.0-dev.28",
|
|
73
|
+
"@itwin/core-quantity": "5.0.0-dev.28",
|
|
74
|
+
"@itwin/ecschema-metadata": "5.0.0-dev.28",
|
|
75
|
+
"@itwin/presentation-common": "5.0.0-dev.28"
|
|
76
76
|
},
|
|
77
77
|
"nyc": {
|
|
78
78
|
"extends": "./node_modules/@itwin/build-tools/.nycrc"
|