@itwin/core-frontend 5.0.0-dev.22 → 5.0.0-dev.24

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