@itwin/core-frontend 5.0.0-dev.20 → 5.0.0-dev.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/lib/cjs/AccuDraw.d.ts +19 -2
  2. package/lib/cjs/AccuDraw.d.ts.map +1 -1
  3. package/lib/cjs/AccuDraw.js +19 -2
  4. package/lib/cjs/AccuDraw.js.map +1 -1
  5. package/lib/cjs/GraphicalEditingScope.js +1 -1
  6. package/lib/cjs/GraphicalEditingScope.js.map +1 -1
  7. package/lib/cjs/SelectionSet.d.ts +84 -35
  8. package/lib/cjs/SelectionSet.d.ts.map +1 -1
  9. package/lib/cjs/SelectionSet.js +430 -166
  10. package/lib/cjs/SelectionSet.js.map +1 -1
  11. package/lib/cjs/tools/ClipViewTool.js +8 -8
  12. package/lib/cjs/tools/ClipViewTool.js.map +1 -1
  13. package/lib/cjs/tools/ElementSetTool.d.ts.map +1 -1
  14. package/lib/cjs/tools/ElementSetTool.js +11 -4
  15. package/lib/cjs/tools/ElementSetTool.js.map +1 -1
  16. package/lib/cjs/tools/MeasureTool.js +3 -3
  17. package/lib/cjs/tools/MeasureTool.js.map +1 -1
  18. package/lib/cjs/tools/SelectTool.js +2 -2
  19. package/lib/cjs/tools/SelectTool.js.map +1 -1
  20. package/lib/cjs/tools/ToolAdmin.d.ts.map +1 -1
  21. package/lib/cjs/tools/ToolAdmin.js +17 -5
  22. package/lib/cjs/tools/ToolAdmin.js.map +1 -1
  23. package/lib/esm/AccuDraw.d.ts +19 -2
  24. package/lib/esm/AccuDraw.d.ts.map +1 -1
  25. package/lib/esm/AccuDraw.js +19 -2
  26. package/lib/esm/AccuDraw.js.map +1 -1
  27. package/lib/esm/GraphicalEditingScope.js +1 -1
  28. package/lib/esm/GraphicalEditingScope.js.map +1 -1
  29. package/lib/esm/SelectionSet.d.ts +84 -35
  30. package/lib/esm/SelectionSet.d.ts.map +1 -1
  31. package/lib/esm/SelectionSet.js +429 -165
  32. package/lib/esm/SelectionSet.js.map +1 -1
  33. package/lib/esm/tools/ClipViewTool.js +8 -8
  34. package/lib/esm/tools/ClipViewTool.js.map +1 -1
  35. package/lib/esm/tools/ElementSetTool.d.ts.map +1 -1
  36. package/lib/esm/tools/ElementSetTool.js +11 -4
  37. package/lib/esm/tools/ElementSetTool.js.map +1 -1
  38. package/lib/esm/tools/MeasureTool.js +3 -3
  39. package/lib/esm/tools/MeasureTool.js.map +1 -1
  40. package/lib/esm/tools/SelectTool.js +2 -2
  41. package/lib/esm/tools/SelectTool.js.map +1 -1
  42. package/lib/esm/tools/ToolAdmin.d.ts.map +1 -1
  43. package/lib/esm/tools/ToolAdmin.js +17 -5
  44. package/lib/esm/tools/ToolAdmin.js.map +1 -1
  45. package/lib/public/locales/en/CoreTools.json +1 -0
  46. package/lib/public/scripts/parse-imdl-worker.js +1 -1
  47. package/lib/workers/webpack/parse-imdl-worker.js +1 -1
  48. package/package.json +18 -18
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
7
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
8
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
9
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
10
+ };
11
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
12
+ if (kind === "m") throw new TypeError("Private method is not writable");
13
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
14
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
15
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
16
+ };
17
+ var _HiliteSet_instances, _HiliteSet_mode, _HiliteSet_selectionChangesListener, _HiliteSet_changing, _HiliteSet_onChanged, _HiliteSet_change, _HiliteSet_processSelectionSetEvent, _SelectionSet_instances, _SelectionSet_selection, _SelectionSet_sendChangedEvent, _SelectionSet_add, _SelectionSet_remove;
2
18
  Object.defineProperty(exports, "__esModule", { value: true });
3
19
  exports.SelectionSet = exports.HiliteSet = exports.SelectionSetEventType = void 0;
4
- /*---------------------------------------------------------------------------------------------
5
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
6
- * See LICENSE.md in the project root for license terms and full copyright notice.
7
- *--------------------------------------------------------------------------------------------*/
8
20
  /** @packageDocumentation
9
21
  * @module SelectionSet
10
22
  */
@@ -16,85 +28,38 @@ const IModelApp_1 = require("./IModelApp");
16
28
  */
17
29
  var SelectionSetEventType;
18
30
  (function (SelectionSetEventType) {
19
- /** Elements have been added to the set. */
31
+ /** Ids have been added to the set. */
20
32
  SelectionSetEventType[SelectionSetEventType["Add"] = 0] = "Add";
21
- /** Elements have been removed from the set. */
33
+ /** Ids have been removed from the set. */
22
34
  SelectionSetEventType[SelectionSetEventType["Remove"] = 1] = "Remove";
23
- /** Some elements have been added to the set and others have been removed. */
35
+ /** Some ids have been added to the set and others have been removed. */
24
36
  SelectionSetEventType[SelectionSetEventType["Replace"] = 2] = "Replace";
25
- /** All elements are about to be removed from the set. */
37
+ /** All ids have been removed from the set. */
26
38
  SelectionSetEventType[SelectionSetEventType["Clear"] = 3] = "Clear";
27
39
  })(SelectionSetEventType || (exports.SelectionSetEventType = SelectionSetEventType = {}));
28
- /** Tracks a set of hilited entities. When the set changes, notifies ViewManager so that symbology overrides can be updated in active Viewports.
40
+ /** Holds a set of hilited entities and makes any changes to the set by passing the change
41
+ * function to given `change` callback.
29
42
  * @internal
30
43
  */
31
44
  class HilitedIds extends core_bentley_1.Id64.Uint32Set {
32
- constructor(iModel) {
45
+ constructor(_change) {
33
46
  super();
34
- this._changing = false;
35
- this._iModel = iModel;
47
+ this._change = _change;
36
48
  }
37
49
  add(low, high) {
38
- super.add(low, high);
39
- this.onChanged();
50
+ this._change(() => super.add(low, high));
40
51
  }
41
52
  delete(low, high) {
42
- super.delete(low, high);
43
- this.onChanged();
53
+ this._change(() => super.delete(low, high));
44
54
  }
45
55
  clear() {
46
- super.clear();
47
- this.onChanged();
56
+ this._change(() => super.clear());
48
57
  }
49
58
  addIds(ids) {
50
- this.change(() => super.addIds(ids));
59
+ this._change(() => super.addIds(ids));
51
60
  }
52
61
  deleteIds(ids) {
53
- this.change(() => super.deleteIds(ids));
54
- }
55
- onChanged() {
56
- if (!this._changing)
57
- IModelApp_1.IModelApp.viewManager.onSelectionSetChanged(this._iModel);
58
- }
59
- change(func) {
60
- const changing = this._changing;
61
- this._changing = false;
62
- func();
63
- this._changing = changing;
64
- this.onChanged();
65
- }
66
- }
67
- /** Keeps the set of hilited elements in sync with the selection set.
68
- * @internal
69
- */
70
- class HilitedElementIds extends HilitedIds {
71
- constructor(iModel, syncWithSelectionSet = true) {
72
- super(iModel);
73
- this.wantSyncWithSelectionSet = syncWithSelectionSet;
74
- }
75
- get wantSyncWithSelectionSet() { return undefined !== this._removeListener; }
76
- set wantSyncWithSelectionSet(want) {
77
- if (want === this.wantSyncWithSelectionSet)
78
- return;
79
- if (want) {
80
- const set = this._iModel.selectionSet;
81
- this._removeListener = set.onChanged.addListener((ev) => this.change(() => this.processSelectionSetEvent(ev)));
82
- this.processSelectionSetEvent({
83
- set,
84
- type: SelectionSetEventType.Add,
85
- added: set.elements,
86
- });
87
- }
88
- else {
89
- this._removeListener();
90
- this._removeListener = undefined;
91
- }
92
- }
93
- processSelectionSetEvent(ev) {
94
- if (SelectionSetEventType.Add !== ev.type)
95
- this.deleteIds(ev.removed);
96
- if (ev.type === SelectionSetEventType.Add || ev.type === SelectionSetEventType.Replace)
97
- this.addIds(ev.added);
62
+ this._change(() => super.deleteIds(ids));
98
63
  }
99
64
  }
100
65
  /** A set of *hilited* elements for an [[IModelConnection]], by element id.
@@ -116,8 +81,6 @@ class HilitedElementIds extends HilitedIds {
116
81
  * @extensions
117
82
  */
118
83
  class HiliteSet {
119
- /** The set of hilited elements. */
120
- get elements() { return this._elements; }
121
84
  /** Controls how the sets of hilited [[models]] and [[subcategories]] interact with one another.
122
85
  * By default they are treated as a union: a [Feature]($common) is hilited if either its model **or** its subcategory is hilited.
123
86
  * This can be changed to an intersection such that a [Feature]($common) is hilited only if both its model **and** subcategory are hilited.
@@ -125,61 +88,134 @@ class HiliteSet {
125
88
  * [[elements]] is always hilited regardless of its model or subcategories.
126
89
  */
127
90
  get modelSubCategoryMode() {
128
- return this._mode;
91
+ return __classPrivateFieldGet(this, _HiliteSet_mode, "f");
129
92
  }
130
93
  set modelSubCategoryMode(mode) {
131
- if (mode === this._mode)
94
+ if (mode === __classPrivateFieldGet(this, _HiliteSet_mode, "f")) {
132
95
  return;
96
+ }
133
97
  this.onModelSubCategoryModeChanged.raiseEvent(mode);
134
- this._mode = mode;
98
+ __classPrivateFieldSet(this, _HiliteSet_mode, mode, "f");
135
99
  }
136
100
  /** Construct a HiliteSet
137
101
  * @param iModel The iModel containing the entities to be hilited.
138
- * @param syncWithSelectionSet If true, the contents of the `elements` set will be synchronized with those in the `iModel`'s [[SelectionSet]].
102
+ * @param syncWithSelectionSet If true, the hilite set contents will be synchronized with those in the `iModel`'s [[SelectionSet]].
139
103
  */
140
104
  constructor(iModel, syncWithSelectionSet = true) {
105
+ _HiliteSet_instances.add(this);
141
106
  this.iModel = iModel;
142
- this._mode = "union";
107
+ _HiliteSet_mode.set(this, "union");
108
+ _HiliteSet_selectionChangesListener.set(this, void 0);
109
+ _HiliteSet_changing.set(this, false);
143
110
  /** Event raised just before changing the value of [[modelSubCategoryMode]]. */
144
111
  this.onModelSubCategoryModeChanged = new core_bentley_1.BeEvent();
145
- this._elements = new HilitedElementIds(iModel, syncWithSelectionSet);
146
- this.subcategories = new HilitedIds(iModel);
147
- this.models = new HilitedIds(iModel);
112
+ this.elements = new HilitedIds((func) => __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, func));
113
+ this.subcategories = new HilitedIds((func) => __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, func));
114
+ this.models = new HilitedIds((func) => __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, func));
115
+ this.wantSyncWithSelectionSet = syncWithSelectionSet;
148
116
  }
149
- /** Control whether the hilited elements will be synchronized with the contents of the [[SelectionSet]].
117
+ /** Control whether the hilite set will be synchronized with the contents of the [[SelectionSet]].
150
118
  * By default they are synchronized. Applications that override this take responsibility for managing the set of hilited entities.
151
119
  * When turning synchronization off, the contents of the HiliteSet will remain unchanged.
152
120
  * When turning synchronization on, the current contents of the HiliteSet will be preserved, and the contents of the selection set will be added to them.
153
121
  */
154
- get wantSyncWithSelectionSet() { return this._elements.wantSyncWithSelectionSet; }
155
- set wantSyncWithSelectionSet(want) { this._elements.wantSyncWithSelectionSet = want; }
122
+ get wantSyncWithSelectionSet() {
123
+ return !!__classPrivateFieldGet(this, _HiliteSet_selectionChangesListener, "f");
124
+ }
125
+ set wantSyncWithSelectionSet(want) {
126
+ if (want === this.wantSyncWithSelectionSet) {
127
+ return;
128
+ }
129
+ if (want) {
130
+ const set = this.iModel.selectionSet;
131
+ __classPrivateFieldSet(this, _HiliteSet_selectionChangesListener, set.onChanged.addListener((ev) => __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_processSelectionSetEvent).call(this, ev)), "f");
132
+ this.add(set.active);
133
+ }
134
+ else {
135
+ __classPrivateFieldGet(this, _HiliteSet_selectionChangesListener, "f")();
136
+ __classPrivateFieldSet(this, _HiliteSet_selectionChangesListener, undefined, "f");
137
+ }
138
+ }
139
+ /** Adds a collection of geometric element, model and subcategory ids to this hilite set. */
140
+ add(additions) {
141
+ __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, () => {
142
+ additions.elements && this.elements.addIds(additions.elements);
143
+ additions.models && this.models.addIds(additions.models);
144
+ additions.subcategories && this.subcategories.addIds(additions.subcategories);
145
+ });
146
+ }
147
+ /** Removes a collection of geometric element, model and subcategory ids from this hilite set. */
148
+ remove(removals) {
149
+ __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, () => {
150
+ removals.elements && this.elements.deleteIds(removals.elements);
151
+ removals.models && this.models.deleteIds(removals.models);
152
+ removals.subcategories && this.subcategories.deleteIds(removals.subcategories);
153
+ });
154
+ }
155
+ /** Replaces ids currently in the hilite set with the given collection. */
156
+ replace(ids) {
157
+ __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, () => {
158
+ this.clear();
159
+ this.add(ids);
160
+ });
161
+ }
156
162
  /** Remove all elements from the hilited set. */
157
163
  clear() {
158
- this.elements.clear();
159
- this.subcategories.clear();
160
- this.models.clear();
164
+ __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, () => {
165
+ this.elements.clear();
166
+ this.models.clear();
167
+ this.subcategories.clear();
168
+ });
161
169
  }
162
170
  /** Returns true if nothing is hilited. */
163
- get isEmpty() { return this.elements.isEmpty && this.subcategories.isEmpty && this.models.isEmpty; }
171
+ get isEmpty() {
172
+ return this.elements.isEmpty && this.subcategories.isEmpty && this.models.isEmpty;
173
+ }
164
174
  /** Toggle the hilited state of one or more elements.
165
175
  * @param arg the ID(s) of the elements whose state is to be toggled.
166
176
  * @param onOff True to add the elements to the hilited set, false to remove them.
177
+ * @deprecated in 5.0. Use [[add]], [[remove]], [[replace]] instead.
167
178
  */
168
179
  setHilite(arg, onOff) {
169
- const oldSize = this.elements.size;
170
- for (const id of core_bentley_1.Id64.iterable(arg)) {
171
- if (onOff)
172
- this.elements.addId(id);
173
- else
174
- this.elements.deleteId(id);
180
+ if (onOff) {
181
+ this.add({ elements: arg });
182
+ }
183
+ else {
184
+ this.remove({ elements: arg });
175
185
  }
176
- if (oldSize !== this.elements.size)
177
- IModelApp_1.IModelApp.viewManager.onSelectionSetChanged(this.iModel);
178
186
  }
179
187
  }
180
188
  exports.HiliteSet = HiliteSet;
181
- /** A set of *currently selected* elements for an IModelConnection.
182
- * Selected elements are displayed with a customizable hilite effect within a [[Viewport]].
189
+ _HiliteSet_mode = new WeakMap(), _HiliteSet_selectionChangesListener = new WeakMap(), _HiliteSet_changing = new WeakMap(), _HiliteSet_instances = new WeakSet(), _HiliteSet_onChanged = function _HiliteSet_onChanged() {
190
+ if (!__classPrivateFieldGet(this, _HiliteSet_changing, "f")) {
191
+ IModelApp_1.IModelApp.viewManager.onSelectionSetChanged(this.iModel);
192
+ }
193
+ }, _HiliteSet_change = function _HiliteSet_change(func) {
194
+ const changing = __classPrivateFieldGet(this, _HiliteSet_changing, "f");
195
+ __classPrivateFieldSet(this, _HiliteSet_changing, true, "f");
196
+ try {
197
+ func();
198
+ }
199
+ finally {
200
+ __classPrivateFieldSet(this, _HiliteSet_changing, changing, "f");
201
+ }
202
+ __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_onChanged).call(this);
203
+ }, _HiliteSet_processSelectionSetEvent = function _HiliteSet_processSelectionSetEvent(ev) {
204
+ switch (ev.type) {
205
+ case SelectionSetEventType.Add:
206
+ return this.add(ev.additions);
207
+ case SelectionSetEventType.Replace:
208
+ return __classPrivateFieldGet(this, _HiliteSet_instances, "m", _HiliteSet_change).call(this, () => {
209
+ this.add(ev.additions);
210
+ this.remove(ev.removals);
211
+ });
212
+ case SelectionSetEventType.Remove:
213
+ case SelectionSetEventType.Clear:
214
+ return this.remove(ev.removals);
215
+ }
216
+ };
217
+ /** A set of *currently selected* geometric elements, models and subcategories for an `IModelConnection`.
218
+ * Generally, selected elements are displayed with a customizable hilite effect within a [[Viewport]], see [[HiliteSet]].
183
219
  * @see [Hilite.Settings]($common) for customization of the hilite effect.
184
220
  * @public
185
221
  * @extensions
@@ -188,126 +224,354 @@ class SelectionSet {
188
224
  /** The IDs of the selected elements.
189
225
  * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]].
190
226
  */
191
- get elements() { return this._elements; }
227
+ get elements() {
228
+ return __classPrivateFieldGet(this, _SelectionSet_selection, "f").elements;
229
+ }
230
+ /** The IDs of the selected models.
231
+ * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]].
232
+ */
233
+ get models() {
234
+ return __classPrivateFieldGet(this, _SelectionSet_selection, "f").models;
235
+ }
236
+ /** The IDs of the selected subcategories.
237
+ * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]].
238
+ */
239
+ get subcategories() {
240
+ return __classPrivateFieldGet(this, _SelectionSet_selection, "f").subcategories;
241
+ }
242
+ /** Get the active selection as a collection of geometric element, model and subcategory ids.
243
+ * @note Do not modify the sets in returned collection directly. Instead, use methods like [[SelectionSet.add]].
244
+ */
245
+ get active() {
246
+ return { ...__classPrivateFieldGet(this, _SelectionSet_selection, "f") };
247
+ }
192
248
  constructor(iModel) {
249
+ _SelectionSet_instances.add(this);
193
250
  this.iModel = iModel;
194
- this._elements = new Set();
195
- /** Called whenever elements are added or removed from this SelectionSet */
251
+ _SelectionSet_selection.set(this, void 0);
252
+ /** Called whenever ids are added or removed from this `SelectionSet` */
196
253
  this.onChanged = new core_bentley_1.BeEvent();
197
- }
198
- sendChangedEvent(ev) {
199
- IModelApp_1.IModelApp.viewManager.onSelectionSetChanged(this.iModel);
200
- this.onChanged.raiseEvent(ev);
254
+ __classPrivateFieldSet(this, _SelectionSet_selection, {
255
+ elements: new Set(),
256
+ models: new Set(),
257
+ subcategories: new Set(),
258
+ }, "f");
201
259
  }
202
260
  /** Get the number of entries in this selection set. */
203
- get size() { return this.elements.size; }
204
- /** Check whether there are any selected elements. */
205
- get isActive() { return this.size !== 0; }
206
- /** Return true if elemId is in this SelectionSet.
261
+ get size() {
262
+ return this.elements.size + this.models.size + this.subcategories.size;
263
+ }
264
+ /** Check whether there are any ids in this selection set. */
265
+ get isActive() {
266
+ return this.elements.size > 0 || this.models.size > 0 || this.subcategories.size > 0;
267
+ }
268
+ /** Return true if elemId is in this `SelectionSet`.
207
269
  * @see [[isSelected]]
270
+ * @deprecated in 5.0. Use `SelectionSet.elements.has(elemId)` instead.
208
271
  */
209
- has(elemId) { return !!elemId && this.elements.has(elemId); }
272
+ has(elemId) {
273
+ return !!elemId && this.elements.has(elemId);
274
+ }
210
275
  /** Query whether an Id is in the selection set.
211
276
  * @see [[has]]
277
+ * @deprecated in 5.0. Use `SelectionSet.elements.has(elemId)` instead.
212
278
  */
213
- isSelected(elemId) { return !!elemId && this.elements.has(elemId); }
279
+ isSelected(elemId) {
280
+ return !!elemId && this.elements.has(elemId);
281
+ }
214
282
  /** Clear current selection set.
215
283
  * @note raises the [[onChanged]] event with [[SelectionSetEventType.Clear]].
216
284
  */
217
285
  emptyAll() {
218
- if (!this.isActive)
286
+ if (!this.isActive) {
219
287
  return;
220
- const removed = this._elements;
221
- this._elements = new Set();
222
- this.sendChangedEvent({ set: this, type: SelectionSetEventType.Clear, removed });
288
+ }
289
+ const removals = __classPrivateFieldGet(this, _SelectionSet_selection, "f");
290
+ __classPrivateFieldSet(this, _SelectionSet_selection, {
291
+ elements: new Set(),
292
+ models: new Set(),
293
+ subcategories: new Set(),
294
+ }, "f");
295
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_sendChangedEvent).call(this, { set: this, type: SelectionSetEventType.Clear, removals, removed: removals.elements });
223
296
  }
224
297
  /**
225
298
  * Add one or more Ids to the current selection set.
226
299
  * @param elem The set of Ids to add.
227
300
  * @returns true if any elements were added.
228
301
  */
229
- add(elem) {
230
- return this._add(elem);
231
- }
232
- _add(elem, sendEvent = true) {
233
- const oldSize = this.elements.size;
234
- for (const id of core_bentley_1.Id64.iterable(elem))
235
- this.elements.add(id);
236
- const changed = oldSize !== this.elements.size;
237
- if (sendEvent && changed)
238
- this.sendChangedEvent({ type: SelectionSetEventType.Add, set: this, added: elem });
239
- return changed;
302
+ add(adds) {
303
+ return !!__classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_add).call(this, adds);
240
304
  }
241
305
  /**
242
306
  * Remove one or more Ids from the current selection set.
243
307
  * @param elem The set of Ids to remove.
244
308
  * @returns true if any elements were removed.
245
309
  */
246
- remove(elem) {
247
- return this._remove(elem);
248
- }
249
- _remove(elem, sendEvent = true) {
250
- const oldSize = this.elements.size;
251
- for (const id of core_bentley_1.Id64.iterable(elem))
252
- this.elements.delete(id);
253
- const changed = oldSize !== this.elements.size;
254
- if (sendEvent && changed)
255
- this.sendChangedEvent({ type: SelectionSetEventType.Remove, set: this, removed: elem });
256
- return changed;
310
+ remove(removes) {
311
+ return !!__classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_remove).call(this, removes);
257
312
  }
258
313
  /**
259
314
  * Add one set of Ids, and remove another set of Ids. Any Ids that are in both sets are removed.
260
315
  * @returns True if any Ids were either added or removed.
261
316
  */
262
317
  addAndRemove(adds, removes) {
263
- const added = this._add(adds, false);
264
- const removed = this._remove(removes, false);
265
- if (added && removed)
266
- this.sendChangedEvent({ type: SelectionSetEventType.Replace, set: this, added: adds, removed: removes });
267
- else if (added)
268
- this.sendChangedEvent({ type: SelectionSetEventType.Add, set: this, added: adds });
269
- else if (removed)
270
- this.sendChangedEvent({ type: SelectionSetEventType.Remove, set: this, removed: removes });
271
- return (added || removed);
272
- }
273
- /** Invert the state of a set of Ids in the SelectionSet */
274
- invert(elem) {
275
- const elementsToAdd = new Set();
276
- const elementsToRemove = new Set();
277
- for (const id of core_bentley_1.Id64.iterable(elem)) {
278
- if (this.elements.has(id))
279
- elementsToRemove.add(id);
280
- else
281
- elementsToAdd.add(id);
318
+ const additions = __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_add).call(this, adds, false);
319
+ const removals = __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_remove).call(this, removes, false);
320
+ const addedElements = additions?.elements ?? [];
321
+ const removedElements = removals?.elements ?? [];
322
+ if (additions && removals) {
323
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_sendChangedEvent).call(this, {
324
+ type: SelectionSetEventType.Replace,
325
+ set: this,
326
+ additions,
327
+ added: addedElements,
328
+ removals,
329
+ removed: removedElements,
330
+ });
331
+ }
332
+ else if (additions) {
333
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_sendChangedEvent).call(this, {
334
+ type: SelectionSetEventType.Add,
335
+ set: this,
336
+ additions,
337
+ added: addedElements,
338
+ });
339
+ }
340
+ else if (removals) {
341
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_sendChangedEvent).call(this, {
342
+ type: SelectionSetEventType.Remove,
343
+ set: this,
344
+ removals,
345
+ removed: removedElements,
346
+ });
282
347
  }
283
- return this.addAndRemove(elementsToAdd, elementsToRemove);
348
+ return !!additions || !!removals;
349
+ }
350
+ /** Invert the state of a set of Ids in the `SelectionSet` */
351
+ invert(ids) {
352
+ const adds = {};
353
+ const removes = {};
354
+ forEachSelectableType({
355
+ ids,
356
+ elements: (elementIds) => {
357
+ for (const id of core_bentley_1.Id64.iterable(elementIds)) {
358
+ ((this.elements.has(id) ? removes : adds).elements ??= new Set()).add(id);
359
+ }
360
+ },
361
+ models: (modelIds) => {
362
+ for (const id of core_bentley_1.Id64.iterable(modelIds)) {
363
+ ((this.models.has(id) ? removes : adds).models ??= new Set()).add(id);
364
+ }
365
+ },
366
+ subcategories: (subcategoryIds) => {
367
+ for (const id of core_bentley_1.Id64.iterable(subcategoryIds)) {
368
+ ((this.subcategories.has(id) ? removes : adds).subcategories ??= new Set()).add(id);
369
+ }
370
+ },
371
+ });
372
+ return this.addAndRemove(adds, removes);
284
373
  }
285
374
  /** Change selection set to be the supplied set of Ids. */
286
- replace(elem) {
287
- if (areEqual(this.elements, elem))
288
- return;
289
- const removed = this._elements;
290
- this._elements = new Set();
291
- this._add(elem, false);
292
- if (0 < removed.size) {
293
- for (const id of core_bentley_1.Id64.iterable(elem)) {
294
- if (removed.has(id))
295
- removed.delete(id);
296
- }
375
+ replace(ids) {
376
+ if (areEqual(__classPrivateFieldGet(this, _SelectionSet_selection, "f"), ids)) {
377
+ return false;
297
378
  }
298
- this.sendChangedEvent({ type: SelectionSetEventType.Replace, set: this, added: elem, removed });
379
+ const previousSelection = __classPrivateFieldGet(this, _SelectionSet_selection, "f");
380
+ __classPrivateFieldSet(this, _SelectionSet_selection, {
381
+ elements: new Set(),
382
+ models: new Set(),
383
+ subcategories: new Set(),
384
+ }, "f");
385
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_add).call(this, ids, false);
386
+ const additions = {};
387
+ const removals = {};
388
+ forEachSelectableType({
389
+ ids: __classPrivateFieldGet(this, _SelectionSet_selection, "f"),
390
+ elements: (elementIds) => {
391
+ removeIds({
392
+ target: previousSelection.elements,
393
+ ids: elementIds,
394
+ onNotFound: (id) => (additions.elements ??= new Set()).add(id),
395
+ });
396
+ if (previousSelection.elements.size > 0) {
397
+ removals.elements = previousSelection.elements;
398
+ }
399
+ },
400
+ models: (modelIds) => {
401
+ removeIds({
402
+ target: previousSelection.models,
403
+ ids: modelIds,
404
+ onNotFound: (id) => (additions.models ??= new Set()).add(id),
405
+ });
406
+ if (previousSelection.models.size > 0) {
407
+ removals.models = previousSelection.models;
408
+ }
409
+ },
410
+ subcategories: (subcategoryIds) => {
411
+ removeIds({
412
+ target: previousSelection.subcategories,
413
+ ids: subcategoryIds,
414
+ onNotFound: (id) => (additions.subcategories ??= new Set()).add(id),
415
+ });
416
+ if (previousSelection.subcategories.size > 0) {
417
+ removals.subcategories = previousSelection.subcategories;
418
+ }
419
+ },
420
+ });
421
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_sendChangedEvent).call(this, {
422
+ type: SelectionSetEventType.Replace,
423
+ set: this,
424
+ additions,
425
+ added: additions.elements ?? [],
426
+ removals,
427
+ removed: removals.elements ?? [],
428
+ });
429
+ return true;
299
430
  }
300
431
  }
301
432
  exports.SelectionSet = SelectionSet;
433
+ _SelectionSet_selection = new WeakMap(), _SelectionSet_instances = new WeakSet(), _SelectionSet_sendChangedEvent = function _SelectionSet_sendChangedEvent(ev) {
434
+ IModelApp_1.IModelApp.viewManager.onSelectionSetChanged(this.iModel);
435
+ this.onChanged.raiseEvent(ev);
436
+ }, _SelectionSet_add = function _SelectionSet_add(adds, sendEvent = true) {
437
+ const oldSize = this.size;
438
+ const additions = {};
439
+ forEachSelectableType({
440
+ ids: adds,
441
+ elements: (elementIds) => addIds({
442
+ target: __classPrivateFieldGet(this, _SelectionSet_selection, "f").elements,
443
+ ids: elementIds,
444
+ onAdd: (id) => (additions.elements ??= []).push(id),
445
+ }),
446
+ models: (modelIds) => addIds({
447
+ target: __classPrivateFieldGet(this, _SelectionSet_selection, "f").models,
448
+ ids: modelIds,
449
+ onAdd: (id) => (additions.models ??= []).push(id),
450
+ }),
451
+ subcategories: (subcategoryIds) => addIds({
452
+ target: __classPrivateFieldGet(this, _SelectionSet_selection, "f").subcategories,
453
+ ids: subcategoryIds,
454
+ onAdd: (id) => (additions.subcategories ??= []).push(id),
455
+ }),
456
+ });
457
+ const changed = oldSize !== this.size;
458
+ if (!changed) {
459
+ return undefined;
460
+ }
461
+ if (sendEvent) {
462
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_sendChangedEvent).call(this, {
463
+ type: SelectionSetEventType.Add,
464
+ set: this,
465
+ additions,
466
+ added: additions.elements ?? [],
467
+ });
468
+ }
469
+ return additions;
470
+ }, _SelectionSet_remove = function _SelectionSet_remove(removes, sendEvent = true) {
471
+ const oldSize = this.size;
472
+ const removals = {};
473
+ forEachSelectableType({
474
+ ids: removes,
475
+ elements: (elementIds) => removeIds({
476
+ target: __classPrivateFieldGet(this, _SelectionSet_selection, "f").elements,
477
+ ids: elementIds,
478
+ onRemove: (id) => (removals.elements ??= []).push(id),
479
+ }),
480
+ models: (modelIds) => removeIds({
481
+ target: __classPrivateFieldGet(this, _SelectionSet_selection, "f").models,
482
+ ids: modelIds,
483
+ onRemove: (id) => (removals.models ??= []).push(id),
484
+ }),
485
+ subcategories: (subcategoryIds) => removeIds({
486
+ target: __classPrivateFieldGet(this, _SelectionSet_selection, "f").subcategories,
487
+ ids: subcategoryIds,
488
+ onRemove: (id) => (removals.subcategories ??= []).push(id),
489
+ }),
490
+ });
491
+ const changed = oldSize !== this.size;
492
+ if (!changed) {
493
+ return undefined;
494
+ }
495
+ if (sendEvent) {
496
+ __classPrivateFieldGet(this, _SelectionSet_instances, "m", _SelectionSet_sendChangedEvent).call(this, {
497
+ type: SelectionSetEventType.Remove,
498
+ set: this,
499
+ removals,
500
+ removed: removals.elements ?? [],
501
+ });
502
+ }
503
+ return removals;
504
+ };
505
+ function forEachSelectableType({ ids, elements, models, subcategories, }) {
506
+ if (typeof ids === "string" || Array.isArray(ids) || ids instanceof Set) {
507
+ elements(ids);
508
+ return { elements: ids };
509
+ }
510
+ elements(ids.elements ?? []);
511
+ models(ids.models ?? []);
512
+ subcategories(ids.subcategories ?? []);
513
+ return ids;
514
+ }
302
515
  function areEqual(lhs, rhs) {
516
+ let result = true;
517
+ forEachSelectableType({
518
+ ids: rhs,
519
+ elements: (elementIds) => {
520
+ if (result && !areIdsEqual(lhs.elements, elementIds)) {
521
+ result = false;
522
+ }
523
+ },
524
+ models: (modelIds) => {
525
+ if (result && !areIdsEqual(lhs.models, modelIds)) {
526
+ result = false;
527
+ }
528
+ },
529
+ subcategories: (subcategoryIds) => {
530
+ if (result && !areIdsEqual(lhs.subcategories, subcategoryIds)) {
531
+ result = false;
532
+ }
533
+ },
534
+ });
535
+ return result;
536
+ }
537
+ function areIdsEqual(lhs, rhs) {
303
538
  // Size is unreliable if input can contain duplicates...
304
- if (Array.isArray(rhs))
539
+ if (Array.isArray(rhs)) {
305
540
  rhs = core_bentley_1.Id64.toIdSet(rhs);
306
- if (lhs.size !== core_bentley_1.Id64.sizeOf(rhs))
541
+ }
542
+ if (lhs.size !== core_bentley_1.Id64.sizeOf(rhs)) {
307
543
  return false;
308
- for (const id of core_bentley_1.Id64.iterable(rhs))
309
- if (!lhs.has(id))
544
+ }
545
+ for (const id of core_bentley_1.Id64.iterable(rhs)) {
546
+ if (!lhs.has(id)) {
310
547
  return false;
548
+ }
549
+ }
311
550
  return true;
312
551
  }
552
+ function addIds({ target, ids, onAdd }) {
553
+ let size = target.size;
554
+ for (const id of core_bentley_1.Id64.iterable(ids)) {
555
+ target.add(id);
556
+ const newSize = target.size;
557
+ if (newSize !== size) {
558
+ onAdd?.(id);
559
+ }
560
+ size = newSize;
561
+ }
562
+ }
563
+ function removeIds({ target, ids, onRemove, onNotFound, }) {
564
+ let size = target.size;
565
+ for (const id of core_bentley_1.Id64.iterable(ids)) {
566
+ target.delete(id);
567
+ const newSize = target.size;
568
+ if (newSize !== size) {
569
+ onRemove?.(id);
570
+ }
571
+ else {
572
+ onNotFound?.(id);
573
+ }
574
+ size = newSize;
575
+ }
576
+ }
313
577
  //# sourceMappingURL=SelectionSet.js.map