@thatopen/components 2.1.1 → 2.1.2

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/dist/index.mjs CHANGED
@@ -2968,7 +2968,7 @@ const Fs = class Fs {
2968
2968
  /**
2969
2969
  * The version of the @thatopen/components library.
2970
2970
  */
2971
- I(Fs, "release", "2.1.1");
2971
+ I(Fs, "release", "2.1.2");
2972
2972
  let pi = Fs;
2973
2973
  class Rr {
2974
2974
  constructor(s) {
@@ -7145,6 +7145,30 @@ const Xr = /* @__PURE__ */ new Map([
7145
7145
  dispose() {
7146
7146
  this.relationMaps = {}, this.components.get(ht).onFragmentsDisposed.remove(this.onFragmentsDisposed), this.onDisposed.trigger(Ye.uuid), this.onDisposed.reset();
7147
7147
  }
7148
+ /**
7149
+ * Gets the children of the given element recursively. E.g. in a model with project - site - building - storeys - rooms, passing a storey will include all its children and the children of the rooms contained in it.
7150
+ *
7151
+ * @param model The BIM model whose children to get.
7152
+ * @param id The expressID of the item whose children to get.
7153
+ * @param found An optional parameter that includes a set of expressIDs where the found element IDs will be added.
7154
+ *
7155
+ * @returns A `Set` with the expressIDs of the found items.
7156
+ */
7157
+ getElementsChildren(t, e, i = /* @__PURE__ */ new Set()) {
7158
+ if (i.add(e), this.relationMaps[t.uuid] === void 0)
7159
+ throw new Error(
7160
+ "The provided model has no indices. You have to generate them first."
7161
+ );
7162
+ const n = this.getEntityRelations(t, e, "IsDecomposedBy");
7163
+ if (n)
7164
+ for (const a of n)
7165
+ this.getElementsChildren(t, a, i);
7166
+ const r = this.getEntityRelations(t, e, "ContainsElements");
7167
+ if (r)
7168
+ for (const a of r)
7169
+ this.getElementsChildren(t, a, i);
7170
+ return i;
7171
+ }
7148
7172
  };
7149
7173
  /**
7150
7174
  * A unique identifier for the component.
@@ -10071,7 +10095,7 @@ const Ls = class Ls extends et {
10071
10095
  for (const a of r) {
10072
10096
  const c = n[a];
10073
10097
  for (const h of i)
10074
- delete c[h];
10098
+ delete c.map[h];
10075
10099
  Object.values(c).length === 0 && delete n[a];
10076
10100
  }
10077
10101
  }
@@ -10093,7 +10117,7 @@ const Ls = class Ls extends et {
10093
10117
  const i = this.list[e];
10094
10118
  for (const o in i) {
10095
10119
  const n = i[o];
10096
- delete n[t];
10120
+ delete n.map[t];
10097
10121
  }
10098
10122
  }
10099
10123
  }
@@ -10128,9 +10152,9 @@ const Ls = class Ls extends et {
10128
10152
  for (const c of a) {
10129
10153
  const h = this.list[r][c];
10130
10154
  if (h)
10131
- for (const d in h) {
10155
+ for (const d in h.map) {
10132
10156
  o[d] || (o[d] = /* @__PURE__ */ new Map());
10133
- for (const E of h[d]) {
10157
+ for (const E of h.map[d]) {
10134
10158
  const u = o[d].get(E);
10135
10159
  u === void 0 ? o[d].set(E, 1) : o[d].set(E, u + 1);
10136
10160
  }
@@ -10164,13 +10188,13 @@ const Ls = class Ls extends et {
10164
10188
  byModel(t, e) {
10165
10189
  this.list.models || (this.list.models = {});
10166
10190
  const i = this.list.models;
10167
- i[t] || (i[t] = {});
10191
+ i[t] || (i[t] = { map: {}, id: null, name: t });
10168
10192
  const o = i[t];
10169
10193
  for (const [n, r] of e.data) {
10170
10194
  const a = r[0];
10171
10195
  for (const c of a) {
10172
10196
  const h = e.keyFragments.get(c);
10173
- h && (o[h] || (o[h] = /* @__PURE__ */ new Set()), o[h].add(n));
10197
+ h && (o.map[h] || (o.map[h] = /* @__PURE__ */ new Set()), o.map[h].add(n));
10174
10198
  }
10175
10199
  }
10176
10200
  }
@@ -10196,7 +10220,11 @@ const Ls = class Ls extends et {
10196
10220
  if (!r)
10197
10221
  continue;
10198
10222
  const a = String((o = r.PredefinedType) == null ? void 0 : o.value).toUpperCase();
10199
- e[a] || (e[a] = {});
10223
+ e[a] || (e[a] = {
10224
+ map: {},
10225
+ id: null,
10226
+ name: a
10227
+ });
10200
10228
  const c = e[a];
10201
10229
  for (const [h, d] of t.data) {
10202
10230
  const E = d[0];
@@ -10204,7 +10232,7 @@ const Ls = class Ls extends et {
10204
10232
  const f = t.keyFragments.get(u);
10205
10233
  if (!f)
10206
10234
  throw new Error("Fragment ID not found!");
10207
- c[f] || (c[f] = /* @__PURE__ */ new Set()), c[f].add(r.expressID);
10235
+ c.map[f] || (c.map[f] = /* @__PURE__ */ new Set()), c.map[f].add(r.expressID);
10208
10236
  }
10209
10237
  }
10210
10238
  }
@@ -10267,6 +10295,7 @@ const Ls = class Ls extends et {
10267
10295
  * Classifies fragments based on their spatial structure in the IFC model.
10268
10296
  *
10269
10297
  * @param model - The FragmentsGroup containing the fragments to be classified.
10298
+ * @param config - The configuration for the classifier. It includes "useProperties" (if false, the classification will use the expressIDs instead of the names)
10270
10299
  *
10271
10300
  * @remarks
10272
10301
  * This method iterates through the relations of the fragments in the provided group,
@@ -10276,49 +10305,55 @@ const Ls = class Ls extends et {
10276
10305
  *
10277
10306
  * @throws Will throw an error if the fragment ID is not found or if the model relations do not exist.
10278
10307
  */
10279
- async bySpatialStructure(t) {
10280
- var n, r;
10281
- const e = this.components.get(ke), i = e.relationMaps[t.uuid];
10282
- if (!i)
10308
+ async bySpatialStructure(t, e = { useProperties: !0 }) {
10309
+ var r, a;
10310
+ const i = this.components.get(ke), o = i.relationMaps[t.uuid];
10311
+ if (!o)
10283
10312
  throw new Error(
10284
10313
  `Classifier: model relations of ${t.name || t.uuid} have to exists to group by spatial structure.`
10285
10314
  );
10286
- const o = "spatialStructures";
10287
- for (const [a] of i) {
10288
- const c = e.getEntityRelations(
10315
+ const n = "spatialStructures";
10316
+ for (const [c] of o) {
10317
+ const h = i.getEntityRelations(
10289
10318
  t,
10290
- a,
10319
+ c,
10291
10320
  "Decomposes"
10292
10321
  );
10293
- if (c)
10294
- for (const u of c) {
10295
- const f = await t.getProperties(u);
10296
- if (!f)
10297
- continue;
10298
- const R = (n = f.Name) == null ? void 0 : n.value;
10299
- this.saveItem(t, o, R, a);
10322
+ if (h)
10323
+ for (const u of h) {
10324
+ let f = u.toString();
10325
+ if (e.useProperties) {
10326
+ const R = await t.getProperties(u);
10327
+ if (!R)
10328
+ continue;
10329
+ f = (r = R.Name) == null ? void 0 : r.value;
10330
+ }
10331
+ this.saveItem(t, n, f, c, u);
10300
10332
  }
10301
- const h = e.getEntityRelations(
10333
+ const d = i.getEntityRelations(
10302
10334
  t,
10303
- a,
10335
+ c,
10304
10336
  "ContainsElements"
10305
10337
  );
10306
- if (!h)
10307
- continue;
10308
- const d = await t.getProperties(a);
10309
10338
  if (!d)
10310
10339
  continue;
10311
- const E = (r = d.Name) == null ? void 0 : r.value;
10312
- for (const u of h) {
10313
- this.saveItem(t, o, E, u);
10314
- const f = e.getEntityRelations(
10340
+ let E = c.toString();
10341
+ if (e.useProperties) {
10342
+ const u = await t.getProperties(c);
10343
+ if (!u)
10344
+ continue;
10345
+ E = (a = u.Name) == null ? void 0 : a.value;
10346
+ }
10347
+ for (const u of d) {
10348
+ this.saveItem(t, n, E, u, c);
10349
+ const f = i.getEntityRelations(
10315
10350
  t,
10316
10351
  Number(u),
10317
10352
  "IsDecomposedBy"
10318
10353
  );
10319
10354
  if (f)
10320
10355
  for (const R of f)
10321
- this.saveItem(t, o, E, R);
10356
+ this.saveItem(t, n, E, R, c);
10322
10357
  }
10323
10358
  }
10324
10359
  }
@@ -10366,15 +10401,15 @@ const Ls = class Ls extends et {
10366
10401
  o.resetColor(n);
10367
10402
  }
10368
10403
  }
10369
- saveItem(t, e, i, o) {
10404
+ saveItem(t, e, i, o, n = null) {
10370
10405
  this.list[e] || (this.list[e] = {});
10371
- const n = t.data.get(o);
10372
- if (n)
10373
- for (const r of n[0]) {
10374
- const a = t.keyFragments.get(r);
10375
- if (a) {
10376
- const c = this.list[e];
10377
- c[i] || (c[i] = {}), c[i][a] || (c[i][a] = /* @__PURE__ */ new Set()), c[i][a].add(o);
10406
+ const r = t.data.get(o);
10407
+ if (r)
10408
+ for (const a of r[0]) {
10409
+ const c = t.keyFragments.get(a);
10410
+ if (c) {
10411
+ const h = this.list[e];
10412
+ h[i] || (h[i] = { map: {}, id: n, name: i }), h[i].map[c] || (h[i].map[c] = /* @__PURE__ */ new Set()), h[i].map[c].add(o);
10378
10413
  }
10379
10414
  }
10380
10415
  }
@@ -10442,7 +10477,7 @@ const ys = class ys extends et {
10442
10477
  if (!d || t && u || !t && !u)
10443
10478
  continue;
10444
10479
  t ? this.list.add(E) : this.list.delete(E);
10445
- const f = r[c][h];
10480
+ const f = r[c].map[h];
10446
10481
  d.applyTransform(f, a);
10447
10482
  }
10448
10483
  n++;