@xeokit/xeokit-sdk 2.4.0-alpha-39 → 2.4.0-alpha-40

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.
@@ -33262,6 +33262,12 @@ class DataTextureSceneModel extends Component {
33262
33262
 
33263
33263
  this._edgeThreshold = cfg.edgeThreshold || 10;
33264
33264
 
33265
+ /**
33266
+ * True when this model has been finalized after a successful call to finalize().
33267
+ * @type {boolean}
33268
+ */
33269
+ this.finalized = false;
33270
+
33265
33271
  this.visible = cfg.visible;
33266
33272
  this.culled = cfg.culled;
33267
33273
  this.pickable = cfg.pickable;
@@ -34568,6 +34574,8 @@ class DataTextureSceneModel extends Component {
34568
34574
  const layer = this._layerList[i];
34569
34575
  layer.attachToRenderingEvent();
34570
34576
  }
34577
+
34578
+ this.finalized = true;
34571
34579
  }
34572
34580
 
34573
34581
  _rebuildAABB() {
@@ -96340,6 +96348,12 @@ class VBOSceneModel extends Component {
96340
96348
  /** @private **/
96341
96349
  this.renderFlags = new RenderFlags();
96342
96350
 
96351
+ /**
96352
+ * True when this model has been finalized after a successful call to finalize().
96353
+ * @type {boolean}
96354
+ */
96355
+ this.finalized = false;
96356
+
96343
96357
  /**
96344
96358
  * @private
96345
96359
  */
@@ -98157,6 +98171,8 @@ ${cfg.uv && cfg.uv.length > 0 ? 1 : 0}-${cfg.uvCompressed && cfg.uvCompressed.le
98157
98171
  this.glRedraw();
98158
98172
 
98159
98173
  this.scene._aabbDirty = true;
98174
+
98175
+ this.finalized = true;
98160
98176
  }
98161
98177
 
98162
98178
  _rebuildAABB() {
@@ -99335,13 +99351,17 @@ const getCanvasPosFromEvent$4 = function (event, canvasPos) {
99335
99351
  let element = event.target;
99336
99352
  let totalOffsetLeft = 0;
99337
99353
  let totalOffsetTop = 0;
99354
+ let totalScrollX = 0;
99355
+ let totalScrollY = 0;
99338
99356
  while (element.offsetParent) {
99339
- totalOffsetLeft += element.offsetLeft;
99340
- totalOffsetTop += element.offsetTop;
99341
- element = element.offsetParent;
99357
+ totalOffsetLeft += element.offsetLeft;
99358
+ totalOffsetTop += element.offsetTop;
99359
+ totalScrollX += element.scrollLeft;
99360
+ totalScrollY += element.scrollTop;
99361
+ element = element.offsetParent;
99342
99362
  }
99343
- canvasPos[0] = event.pageX - totalOffsetLeft;
99344
- canvasPos[1] = event.pageY - totalOffsetTop;
99363
+ canvasPos[0] = event.pageX + totalScrollX - totalOffsetLeft;
99364
+ canvasPos[1] = event.pageY + totalScrollY - totalOffsetTop;
99345
99365
  }
99346
99366
  return canvasPos;
99347
99367
  };
@@ -102822,7 +102842,7 @@ class MetaModel {
102822
102842
  /**
102823
102843
  * @private
102824
102844
  */
102825
- constructor(metaScene, id, projectId, revisionId, author, createdAt, creatingApplication, schema, propertySets) {
102845
+ constructor(params) {
102826
102846
 
102827
102847
  /**
102828
102848
  * Globally-unique ID.
@@ -102834,14 +102854,14 @@ class MetaModel {
102834
102854
  * @property id
102835
102855
  * @type {String|Number}
102836
102856
  */
102837
- this.id = id;
102857
+ this.id = params.id;
102838
102858
 
102839
102859
  /**
102840
102860
  * The project ID
102841
102861
  * @property projectId
102842
102862
  * @type {String|Number}
102843
102863
  */
102844
- this.projectId = projectId;
102864
+ this.projectId = params.projectId;
102845
102865
 
102846
102866
  /**
102847
102867
  * The revision ID, if available.
@@ -102851,7 +102871,7 @@ class MetaModel {
102851
102871
  * @property revisionId
102852
102872
  * @type {String|Number}
102853
102873
  */
102854
- this.revisionId = revisionId;
102874
+ this.revisionId = params.revisionId;
102855
102875
 
102856
102876
  /**
102857
102877
  * The model author, if available.
@@ -102861,7 +102881,7 @@ class MetaModel {
102861
102881
  * @property author
102862
102882
  * @type {String}
102863
102883
  */
102864
- this.author = author;
102884
+ this.author = params.author;
102865
102885
 
102866
102886
  /**
102867
102887
  * The date the model was created, if available.
@@ -102871,7 +102891,7 @@ class MetaModel {
102871
102891
  * @property createdAt
102872
102892
  * @type {String}
102873
102893
  */
102874
- this.createdAt = createdAt;
102894
+ this.createdAt = params.createdAt;
102875
102895
 
102876
102896
  /**
102877
102897
  * The application that created the model, if available.
@@ -102881,7 +102901,7 @@ class MetaModel {
102881
102901
  * @property creatingApplication
102882
102902
  * @type {String}
102883
102903
  */
102884
- this.creatingApplication = creatingApplication;
102904
+ this.creatingApplication = params.creatingApplication;
102885
102905
 
102886
102906
  /**
102887
102907
  * The model schema version, if available.
@@ -102891,7 +102911,7 @@ class MetaModel {
102891
102911
  * @property schema
102892
102912
  * @type {String}
102893
102913
  */
102894
- this.schema = schema;
102914
+ this.schema = params.schema;
102895
102915
 
102896
102916
  /**
102897
102917
  * Metadata on the {@link Scene}.
@@ -102899,15 +102919,15 @@ class MetaModel {
102899
102919
  * @property metaScene
102900
102920
  * @type {MetaScene}
102901
102921
  */
102902
- this.metaScene = metaScene;
102922
+ this.metaScene = params.metaScene;
102903
102923
 
102904
102924
  /**
102905
102925
  * The {@link PropertySet}s in this MetaModel.
102906
102926
  *
102907
102927
  * @property propertySets
102908
- * @type {{String:PropertySet}}
102928
+ * @type {PropertySet[]}
102909
102929
  */
102910
- this.propertySets = propertySets;
102930
+ this.propertySets = [];
102911
102931
 
102912
102932
  /**
102913
102933
  * The root {@link MetaObject} in this MetaModel's composition structure hierarchy.
@@ -102925,6 +102945,20 @@ class MetaModel {
102925
102945
  * @type {MetaObject[]}
102926
102946
  */
102927
102947
  this.rootMetaObjects = [];
102948
+
102949
+ /**
102950
+ * The {@link MetaObject}s in this MetaModel, each mapped to its ID.
102951
+ *
102952
+ * @property metaObjects
102953
+ * @type {MetaObject[]}
102954
+ */
102955
+ this.metaObjects=[];
102956
+
102957
+ /**
102958
+ * Connectivity graph.
102959
+ * @type {{}}
102960
+ */
102961
+ this.graph = params.graph || {};
102928
102962
  }
102929
102963
 
102930
102964
  getJSON() {
@@ -102983,7 +103017,7 @@ class MetaObject {
102983
103017
  /**
102984
103018
  * @private
102985
103019
  */
102986
- constructor(metaModel, id, originalSystemId, name, type, propertySets, parent, children, external) {
103020
+ constructor(params) {
102987
103021
 
102988
103022
  /**
102989
103023
  * Model metadata.
@@ -102992,13 +103026,13 @@ class MetaObject {
102992
103026
  * @type {MetaModel}
102993
103027
  * @deprecated
102994
103028
  */
102995
- this.metaModel = metaModel;
103029
+ this.metaModel = null;
102996
103030
 
102997
103031
  /**
102998
103032
  * The MetaModels that share this MetaObject.
102999
103033
  * @type {MetaModel[]}
103000
103034
  */
103001
- this.metaModels = [metaModel];
103035
+ this.metaModels = [];
103002
103036
 
103003
103037
  /**
103004
103038
  * Globally-unique ID.
@@ -103008,7 +103042,19 @@ class MetaObject {
103008
103042
  * @property id
103009
103043
  * @type {String|Number}
103010
103044
  */
103011
- this.id = id;
103045
+ this.id = params.id;
103046
+
103047
+ /**
103048
+ * ID of the parent MetaObject.
103049
+ * @type {String|Number}
103050
+ */
103051
+ this.parentId = params.parentId;
103052
+
103053
+ /**
103054
+ * The parent MetaObject.
103055
+ * @type {MetaObject | null}
103056
+ */
103057
+ this.parent = null;
103012
103058
 
103013
103059
  /**
103014
103060
  * ID of the corresponding object within the originating system, if any.
@@ -103016,7 +103062,7 @@ class MetaObject {
103016
103062
  * @type {String}
103017
103063
  * @abstract
103018
103064
  */
103019
- this.originalSystemId = originalSystemId;
103065
+ this.originalSystemId = params.originalSystemId;
103020
103066
 
103021
103067
  /**
103022
103068
  * Human-readable name.
@@ -103024,7 +103070,7 @@ class MetaObject {
103024
103070
  * @property name
103025
103071
  * @type {String}
103026
103072
  */
103027
- this.name = name;
103073
+ this.name = params.name;
103028
103074
 
103029
103075
  /**
103030
103076
  * Type - often an IFC product type.
@@ -103032,7 +103078,7 @@ class MetaObject {
103032
103078
  * @property type
103033
103079
  * @type {String}
103034
103080
  */
103035
- this.type = type;
103081
+ this.type = params.type;
103036
103082
 
103037
103083
  /**
103038
103084
  * Optional {@link PropertySet}s used by this MetaObject.
@@ -103040,46 +103086,20 @@ class MetaObject {
103040
103086
  * @property propertySets
103041
103087
  * @type {PropertySet[]}
103042
103088
  */
103043
- this.propertySets = propertySets;
103044
-
103045
- if (parent !== undefined && parent !== null) {
103046
-
103047
- /**
103048
- * The parent MetaObject within the structure hierarchy.
103049
- *
103050
- * Undefined when this is the root of its structure.
103051
- *
103052
- * @property parent
103053
- * @type {MetaObject}
103054
- */
103055
- this.parent = parent;
103056
- }
103089
+ this.propertySets = [];
103057
103090
 
103058
- if (children !== undefined && children !== null) {
103059
-
103060
- /**
103061
- * Child ObjectMeta instances within the structure hierarchy.
103062
- *
103063
- * Undefined when there are no children.
103064
- *
103065
- * @property children
103066
- * @type {Array}
103067
- */
103068
- this.children = children;
103069
- }
103070
-
103071
- if (external !== undefined && external !== null) {
103072
-
103073
- /**
103074
- * External application-specific metadata
103075
- *
103076
- * Undefined when there are is no external application-specific metadata.
103077
- *
103078
- * @property external
103079
- * @type {*}
103080
- */
103081
- this.external = external;
103082
- }
103091
+ // if (external !== undefined && external !== null) {
103092
+ //
103093
+ // /**
103094
+ // * External application-specific metadata
103095
+ // *
103096
+ // * Undefined when there are is no external application-specific metadata.
103097
+ // *
103098
+ // * @property external
103099
+ // * @type {*}
103100
+ // */
103101
+ // this.external = external;
103102
+ // }
103083
103103
  }
103084
103104
 
103085
103105
  /**
@@ -103269,6 +103289,12 @@ class PropertySet {
103269
103289
  */
103270
103290
  this.originalSystemId = originalSystemId;
103271
103291
 
103292
+ /**
103293
+ * The MetaModels that share this PropertySet.
103294
+ * @type {MetaModel[]}
103295
+ */
103296
+ this.metaModels = [];
103297
+
103272
103298
  /**
103273
103299
  * Human-readable name of this PropertySet.
103274
103300
  *
@@ -103365,12 +103391,6 @@ class MetaScene {
103365
103391
  */
103366
103392
  this.rootMetaObjects = {};
103367
103393
 
103368
- /**
103369
- * Tracks number of MetaObjects of each type.
103370
- * @private
103371
- */
103372
- this._typeCounts = {};
103373
-
103374
103394
  /**
103375
103395
  * Subscriptions to events sent with {@link fire}.
103376
103396
  * @private
@@ -103438,119 +103458,143 @@ class MetaScene {
103438
103458
  */
103439
103459
  createMetaModel(modelId, metaModelData, options = {}) {
103440
103460
 
103441
- const projectId = metaModelData.projectId || "none";
103442
- const revisionId = metaModelData.revisionId || "none";
103443
- const newPropertySets = metaModelData.propertySets || [];
103444
- const newObjects = metaModelData.metaObjects || [];
103445
- const author = metaModelData.author;
103446
- const createdAt = metaModelData.createdAt;
103447
- const creatingApplication = metaModelData.creatingApplication;
103448
- const schema = metaModelData.schema;
103449
- // if (options.excludeTypes) {
103450
- // excludeTypes = {};
103451
- // for (let i = 0, len = options.excludeTypes.length; i < len; i++) {
103452
- // includeTypes[options.excludeTypes[i]] = true;
103453
- // }
103454
- // }
103461
+ this._globalizeIDs(modelId, metaModelData, options);
103455
103462
 
103456
- const metaModel = new MetaModel(this, modelId, projectId, revisionId, author, createdAt, creatingApplication, schema, [], null);
103463
+ // Create MetaModel
103464
+
103465
+ const metaModel = new MetaModel({
103466
+ metaScene: this,
103467
+ id: modelId,
103468
+ projectId: metaModelData.projectId || "none",
103469
+ revisionId: metaModelData.revisionId || "none",
103470
+ author: metaModelData.author || "none",
103471
+ createdAt: metaModelData.createdAt || "none",
103472
+ creatingApplication: metaModelData.creatingApplication || "none",
103473
+ schema: metaModelData.schema || "none",
103474
+ propertySets: []
103475
+ });
103457
103476
 
103458
103477
  this.metaModels[modelId] = metaModel;
103459
103478
 
103460
- for (let i = 0, len = newPropertySets.length; i < len; i++) {
103461
- const propertySetCfg = newPropertySets[i];
103462
- const propertySetId = propertySetCfg.id;
103463
- const propertySet = new PropertySet(propertySetId, propertySetCfg.originalSystemId, propertySetCfg.name, propertySetCfg.type, propertySetCfg.properties);
103464
- metaModel.propertySets[propertySetId] = propertySet;
103465
- this.propertySets[propertySetId] = propertySet;
103479
+ // Create global Property Sets
103480
+
103481
+ for (let i = 0, len = metaModelData.propertySets.length; i < len; i++) {
103482
+ const propertySetData = metaModelData.propertySets[i];
103483
+ let propertySet = this.propertySets[propertySetData.id];
103484
+ if (!propertySet) {
103485
+ propertySet = new PropertySet({
103486
+ id: propertySetData.id,
103487
+ originalSystemId: propertySetData.originalSystemId,
103488
+ type: propertySetData.type,
103489
+ name: propertySetData.name,
103490
+ properties: propertySetData.properties
103491
+ });
103492
+ this.propertySets[propertySet.id] = propertySet;
103493
+ }
103494
+ propertySet.metaModels.push(metaModel);
103495
+ metaModel.propertySets.push(propertySet);
103466
103496
  }
103467
103497
 
103468
- const filteredObjectsParams = []; // Params for each new metaobject that passes our filters
103469
- const existingObjects = []; // List of our metaobjects that are already existing, to which we'll also append new metaobjects we'll create
103470
- const createObjectsParams = []; // List of params for metaobjects we'll create
103471
-
103472
-
103473
- // Filter out the parameters we'll create
103498
+ // Create MetaObjects
103499
+ // Don't re-create reused MetaObjects
103500
+ // Save root MetaObjects on MetaModel
103501
+ // Save root MetaObjects on MetaScene
103474
103502
 
103475
- for (let i = 0, len = newObjects.length; i < len; i++) {
103476
- const newObject = newObjects[i];
103477
- newObject.type;
103478
- filteredObjectsParams.push(newObject);
103503
+ for (let i = 0, len = metaModelData.metaObjects.length; i < len; i++) {
103504
+ const metaObjectData = metaModelData.metaObjects[i];
103505
+ const type = metaObjectData.type;
103506
+ const id = metaObjectData.id;
103507
+ let metaObject = this.metaObjects[id];
103508
+ if (!metaObject) {
103509
+ metaObject = new MetaObject({
103510
+ id,
103511
+ parentId: metaObjectData.parent,
103512
+ type,
103513
+ name: metaObjectData.name,
103514
+ propertySetIds: metaObjectData.propertySetIds
103515
+ });
103516
+ this.metaObjects[id] = metaObject;
103517
+ }
103518
+ metaObject.metaModels.push(metaModel);
103519
+ if (!metaObjectData.parent) {
103520
+ metaModel.rootMetaObjects.push(metaObject);
103521
+ this.rootMetaObjects[id] = metaObject;
103522
+ }
103523
+ metaModel.metaObjects.push(metaObject);
103479
103524
  }
103480
103525
 
103481
- // Build list of params for metaobjects we'll create
103526
+ // Re-link entire MetaObject parent/child hierarchy
103482
103527
 
103483
- for (let i = 0, len = filteredObjectsParams.length; i < len; i++) {
103484
- let filteredObject = filteredObjectsParams[i];
103485
- const existingObject = this.metaObjects[filteredObject.id];
103486
- if (existingObject) {
103487
- existingObject.metaModels.push(metaModel);
103488
- existingObjects.push(existingObject);
103489
- continue;
103528
+ for (let objectId in this.metaObjects) {
103529
+ const metaObject = this.metaObjects[objectId];
103530
+ if (metaObject.children) {
103531
+ metaObject.children = [];
103490
103532
  }
103491
- createObjectsParams.push(filteredObject);
103492
103533
  }
103493
103534
 
103494
- // Create metaobjects in the creation list, add them to list of existing metaobjects
103495
-
103496
- for (let i = 0, len = createObjectsParams.length; i < len; i++) {
103497
- const createObject = createObjectsParams[i];
103498
- const type = createObject.type;
103499
- const objectId = options.globalizeObjectIds ? math.globalizeObjectId(modelId, createObject.id) : createObject.id;
103500
- const originalSystemId = createObject.id;
103501
- const name = createObject.name;
103502
- const propertySets = [];
103503
- if (createObject.propertySetIds && createObject.propertySetIds.length > 0) {
103504
- for (let j = 0, lenj = createObject.propertySetIds.length; j < lenj; j++) {
103505
- const propertySetId = createObject.propertySetIds[j];
103506
- const propertySet = metaModel.propertySets[propertySetId];
103507
- if (propertySet) {
103508
- propertySets.push(propertySet);
103509
- }
103510
- }
103511
- }
103512
- const parent = null;
103513
- const children = null;
103514
- const external = createObject.external;
103515
- const metaObject = new MetaObject(metaModel, objectId, originalSystemId, name, type, propertySets, parent, children, external);
103516
- metaObject._parentId = createObject.parent;
103517
- this.metaObjects[objectId] = metaObject;
103518
- (this.metaObjectsByType[type] || (this.metaObjectsByType[type] = {}))[objectId] = metaObject;
103519
- if (this._typeCounts[type] === undefined) {
103520
- this._typeCounts[type] = 1;
103521
- } else {
103522
- this._typeCounts[type]++;
103523
- }
103524
- existingObjects.push(metaObject);
103525
- if (createObject.parent === undefined || createObject.parent === null) ;
103526
- }
103527
-
103528
- // Ensure that metaobjects in the existing metaobject list are all attached to their parents,
103529
- // or registered as root metaobjects
103530
-
103531
- for (let i = 0, len = existingObjects.length; i < len; i++) {
103532
- const existingObject = existingObjects[i];
103533
- const objectId = options.globalizeObjectIds ? math.globalizeObjectId(modelId, existingObject.id) : existingObject.id;
103534
- if ((existingObject._parentId === undefined || existingObject._parentId === null) && !existingObject.parent) {
103535
- metaModel.rootMetaObject = existingObject; // Deprecated, and won't work for federated models
103536
- metaModel.rootMetaObjects[objectId] = existingObject;
103537
- this.rootMetaObjects[objectId] = existingObject;
103538
- } else if (existingObject._parentId) {
103539
- const parentId = options.globalizeObjectIds ? math.globalizeObjectId(modelId, existingObject._parentId) : existingObject._parentId;
103540
- existingObject._parentId = null;
103541
- let parentMetaObject = this.metaObjects[parentId];
103535
+ for (let objectId in this.metaObjects) {
103536
+ const metaObject = this.metaObjects[objectId];
103537
+ if (metaObject.parentId) {
103538
+ const parentMetaObject = this.metaObjects[metaObject.parentId];
103542
103539
  if (parentMetaObject) {
103543
- existingObject.parent = parentMetaObject;
103544
- parentMetaObject.children = parentMetaObject.children || [];
103545
- parentMetaObject.children.push(existingObject);
103540
+ metaObject.parent = parentMetaObject;
103541
+ (parentMetaObject.children || (parentMetaObject.children = [])).push(metaObject);
103546
103542
  }
103547
103543
  }
103548
103544
  }
103549
103545
 
103546
+ // Create MetaObjects-by-type lookup
103547
+
103548
+ this.metaObjectsByType = {};
103549
+ for (let objectId in this.metaObjects) {
103550
+ const metaObject = this.metaObjects[objectId];
103551
+ const type = metaObject.type;
103552
+ (this.metaObjectsByType[type] || (this.metaObjectsByType[type] = {}))[objectId] = metaObject;
103553
+ }
103554
+
103550
103555
  this.fire("metaModelCreated", modelId);
103556
+
103551
103557
  return metaModel;
103552
103558
  }
103553
103559
 
103560
+ _globalizeIDs(modelId, metaModelData, options) {
103561
+ const globalize = !!options.globalizeObjectIds;
103562
+ for (let i = 0, len = metaModelData.metaObjects.length; i < len; i++) {
103563
+ const metaObjectData = metaModelData.metaObjects[i];
103564
+
103565
+ // Globalize MetaObject IDs and parent IDs
103566
+
103567
+ metaObjectData.originalSystemId = metaObjectData.id;
103568
+ metaObjectData.originalParentSystemId = metaObjectData.parent;
103569
+ if (globalize) {
103570
+ metaObjectData.id = math.globalizeObjectId(modelId, metaObject.id);
103571
+ metaObjectData.parent = math.globalizeObjectId(modelId, metaObject.parent);
103572
+ }
103573
+
103574
+ // Globalize MetaObject property set IDs
103575
+
103576
+ const propertySetIds = metaObjectData.propertySetIds;
103577
+ if (propertySetIds) {
103578
+ const propertySetGlobalIds = [];
103579
+ for (let j = 0, lenj = propertySetIds.length; j < lenj; j++) {
103580
+ propertySetGlobalIds.push(math.globalizeObjectId(modelId, propertySetIds[j]));
103581
+ }
103582
+ metaObjectData.propertySetIds = propertySetGlobalIds;
103583
+ metaObjectData.originalSystemPropertySetIds = propertySetIds;
103584
+ }
103585
+ }
103586
+
103587
+ // Globalize global PropertySet IDs
103588
+
103589
+ for (let i = 0, len = metaModelData.propertySets.length; i < len; i++) {
103590
+ const propertySet = metaModelData.propertySets[i];
103591
+ propertySet.originalSystemId = propertySet.id;
103592
+ if (globalize) {
103593
+ propertySet.id = math.globalizeObjectId(modelId, propertySet.id);
103594
+ }
103595
+ }
103596
+ }
103597
+
103554
103598
  /**
103555
103599
  * Removes a {@link MetaModel} from this MetaScene.
103556
103600
  *
@@ -103559,43 +103603,86 @@ class MetaScene {
103559
103603
  * @param {String} id ID of the target {@link MetaModel}.
103560
103604
  */
103561
103605
  destroyMetaModel(id) {
103606
+
103562
103607
  const metaModel = this.metaModels[id];
103563
103608
  if (!metaModel) {
103564
103609
  return;
103565
103610
  }
103566
- this._removeMetaModel(metaModel);
103567
- this.fire("metaModelDestroyed", id);
103568
- }
103569
103611
 
103570
- _removeMetaModel(metaModel) {
103571
- const metaObjects = this.metaObjects;
103572
- const metaObjectsByType = this.metaObjectsByType;
103573
- let visit = (metaObject) => {
103574
- delete metaObjects[metaObject.id];
103575
- const types = metaObjectsByType[metaObject.type];
103576
- if (types && types[metaObject.id]) {
103577
- delete types[metaObject.id];
103578
- if (--this._typeCounts[metaObject.type] === 0) {
103579
- delete this._typeCounts[metaObject.type];
103580
- delete metaObjectsByType[metaObject.type];
103612
+ // Remove global PropertySets
103613
+
103614
+ for (let i = 0, len = metaModel.propertySets.length; i < len; i++) {
103615
+ const propertySet = metaModel.propertySets[i];
103616
+ if (propertySet.metaModels.length === 1) { // Property set owned by one model, delete
103617
+ delete this.propertySets[propertySet.id];
103618
+ } else {
103619
+ const newMetaModels = [];
103620
+ for (let j = 0, lenj = propertySet.metaModels.length; j < lenj; j++) {
103621
+ if (propertySet.metaModels[i].id !== id) {
103622
+ newMetaModels.push(propertySet.metaModels[i]);
103623
+ }
103581
103624
  }
103625
+ propertySet.metaModels = newMetaModels;
103582
103626
  }
103583
- const children = metaObject.children;
103584
- if (children) {
103585
- for (let i = 0, len = children.length; i < len; i++) {
103586
- const childMetaObject = children[i];
103587
- visit(childMetaObject);
103627
+ }
103628
+
103629
+ // Remove MetaObjects
103630
+
103631
+ for (let i = 0, len = metaModel.metaObjects.length; i < len; i++) {
103632
+ const metaObject = metaModel.metaObjects[i];
103633
+ metaObject.type;
103634
+ const id = metaObject.id;
103635
+ if (metaObject.metaModels.length === 1) { // MetaObject owned by one model, delete
103636
+ delete this.metaObjects[id];
103637
+ if (!metaObject.parent) {
103638
+ delete this.rootMetaObjects[id];
103639
+ }
103640
+ } else {
103641
+ const newMetaModels = [];
103642
+ const metaModelId = metaModel.id;
103643
+ for (let i = 0, len = metaObject.metaModels.length; i < len; i++) {
103644
+ if (metaObject.metaModels[i].id !== metaModelId) {
103645
+ newMetaModels.push(metaObject.metaModels[i]);
103646
+ }
103588
103647
  }
103648
+ metaObject.metaModels = newMetaModels;
103589
103649
  }
103590
- };
103591
- visit(metaModel.rootMetaObject);
103592
- for (let propertySetId in metaModel.propertySets) {
103593
- if (metaModel.propertySets.hasOwnProperty(propertySetId)) {
103594
- delete this.propertySets[propertySetId];
103650
+ }
103651
+
103652
+ // Re-link entire MetaObject parent/child hierarchy
103653
+
103654
+ for (let objectId in this.metaObjects) {
103655
+ const metaObject = this.metaObjects[objectId];
103656
+ if (metaObject.children) {
103657
+ metaObject.children = [];
103595
103658
  }
103596
103659
  }
103597
- delete this.rootMetaObjects[metaModel.rootMetaObject.id];
103598
- delete this.metaModels[metaModel.id];
103660
+
103661
+ this.metaObjectsByType = {};
103662
+
103663
+ for (let objectId in this.metaObjects) {
103664
+ const metaObject = this.metaObjects[objectId];
103665
+ const type = metaObject.type;
103666
+ if (metaObject.children) {
103667
+ metaObject.children = null;
103668
+ }
103669
+ (this.metaObjectsByType[type] || (this.metaObjectsByType[type] = {}))[objectId] = metaObject;
103670
+ }
103671
+
103672
+ for (let objectId in this.metaObjects) {
103673
+ const metaObject = this.metaObjects[objectId];
103674
+ if (metaObject.parentId) {
103675
+ const parentMetaObject = this.metaObjects[metaObject.parentId];
103676
+ if (parentMetaObject) {
103677
+ metaObject.parent = parentMetaObject;
103678
+ (parentMetaObject.children || (parentMetaObject.children = [])).push(metaObject);
103679
+ }
103680
+ }
103681
+ }
103682
+
103683
+ delete this.metaModels[id];
103684
+
103685
+ this.fire("metaModelDestroyed", id);
103599
103686
  }
103600
103687
 
103601
103688
  /**
@@ -103618,12 +103705,13 @@ class MetaScene {
103618
103705
  * @returns {String[]} Array of {@link MetaObject#id}s.
103619
103706
  */
103620
103707
  getObjectIDsInSubtree(id, includeTypes, excludeTypes) {
103708
+
103621
103709
  const list = [];
103622
103710
  const metaObject = this.metaObjects[id];
103623
103711
  const includeMask = (includeTypes && includeTypes.length > 0) ? arrayToMap(includeTypes) : null;
103624
103712
  const excludeMask = (excludeTypes && excludeTypes.length > 0) ? arrayToMap(excludeTypes) : null;
103625
103713
 
103626
- function visit(metaObject) {
103714
+ const visit = (metaObject) => {
103627
103715
  if (!metaObject) {
103628
103716
  return;
103629
103717
  }
@@ -103642,7 +103730,7 @@ class MetaScene {
103642
103730
  visit(children[i]);
103643
103731
  }
103644
103732
  }
103645
- }
103733
+ };
103646
103734
 
103647
103735
  visit(metaObject);
103648
103736
  return list;