@itwin/core-frontend
Version:
iTwin.js frontend components
81 lines • 3.32 kB
JavaScript
"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Views
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ModelSelectorState = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const EntityState_1 = require("./EntityState");
/** The state of a [ModelSelector]($backend). It holds a set of ids of GeometricModels for a [[SpatialViewState]].
* It defines the set of [[ModelState]]s drawn within the view as a set of IDs.
* @public
* @extensions
*/
class ModelSelectorState extends EntityState_1.ElementState {
static get className() { return "ModelSelector"; }
_models = new core_bentley_1.ObservableSet();
/** The set of ModelIds of this ModelSelectorState */
get models() {
return this._models;
}
set models(models) {
this.models.clear();
for (const model of models)
this.models.add(model);
}
/** @internal */
get observableModels() {
return this._models;
}
constructor(props, iModel) {
super(props, iModel);
if (props.models)
props.models.forEach((model) => this.models.add(model));
}
/** The name of this ModelSelector */
get name() { return this.code.value; }
toJSON() {
const val = super.toJSON();
val.models = [];
this.models.forEach((model) => val.models.push(model));
return val;
}
/** Determine if this model selector is logically equivalent to the specified model selector. Two model selectors are logically equivalent is
* they have the same name and Id and contain the same set of models.
* @param other The model selector to which to compare.
* @returns true if the model selectors are logically equivalent.
* @public
*/
equalState(other) {
if (this.models.size !== other.models.size || this.id !== other.id || this.name !== other.name)
return false;
for (const model of this.models)
if (!other.models.has(model))
return false;
return true;
}
/** Add one or more models to this ModelSelectorState */
addModels(arg) {
for (const id of core_bentley_1.Id64.iterable(arg))
this.models.add(id);
}
/** Drop one or more models from this ModelSelectorState */
dropModels(arg) {
for (const id of core_bentley_1.Id64.iterable(arg))
this.models.delete(id);
}
/** Determine whether this ModelSelectorState includes the specified modelId value */
has(id) { return this.models.has(id); }
/** Determine whether this ModelSelectorState includes the specified modelId */
containsModel(modelId) { return this.has(modelId.toString()); }
/** Make sure all models referenced by this ModelSelectorState are loaded. */
async load() {
return this.iModel.models.load(this.models);
}
}
exports.ModelSelectorState = ModelSelectorState;
//# sourceMappingURL=ModelSelectorState.js.map