/
ModelSelectorState.ts
95 lines (78 loc) · 3.31 KB
/
ModelSelectorState.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*---------------------------------------------------------------------------------------------
* 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
*/
import { Id64, Id64Arg, Id64String, ObservableSet } from "@itwin/core-bentley";
import { ModelSelectorProps } from "@itwin/core-common";
import { ElementState } from "./EntityState";
import { IModelConnection } from "./IModelConnection";
/** 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
*/
export class ModelSelectorState extends ElementState {
public static override get className() { return "ModelSelector"; }
private readonly _models = new ObservableSet<string>();
/** The set of ModelIds of this ModelSelectorState */
public get models(): Set<string> {
return this._models;
}
public set models(models: Set<string>) {
this.models.clear();
for (const model of models)
this.models.add(model);
}
/** @internal */
public get observableModels(): ObservableSet<string> {
return this._models;
}
constructor(props: ModelSelectorProps, iModel: IModelConnection) {
super(props, iModel);
if (props.models)
props.models.forEach((model) => this.models.add(model));
}
/** The name of this ModelSelector */
public get name(): string { return this.code.value; }
public override toJSON(): ModelSelectorProps {
const val: any = 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
*/
public equalState(other: ModelSelectorState): boolean {
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 */
public addModels(arg: Id64Arg): void {
for (const id of Id64.iterable(arg))
this.models.add(id);
}
/** Drop one or more models from this ModelSelectorState */
public dropModels(arg: Id64Arg): void {
for (const id of Id64.iterable(arg))
this.models.delete(id);
}
/** Determine whether this ModelSelectorState includes the specified modelId value */
public has(id: string): boolean { return this.models.has(id); }
/** Determine whether this ModelSelectorState includes the specified modelId */
public containsModel(modelId: Id64String): boolean { return this.has(modelId.toString()); }
/** Make sure all models referenced by this ModelSelectorState are loaded. */
public async load(): Promise<void> {
return this.iModel.models.load(this.models);
}
}