ModelManager
Class in @bimworks/viewercommon.
API catalogue · @bimworks/viewercommon · Class
class ModelManagerA ModelManager keeps track of the models that have been loaded. A ModelManager is required when using the Viewer2d or Viewer3d. Most application will only need one ModelManager, but if you have an application where you want to show different models in different viewers, you might need more. The ModelManager keeps track of:
- Which @bimworks/jssdk!Qid (object) belongs the which model
- A mapping from (IFC) type to @bimworks/jssdk!Qid
Members#
| Member | Kind | Description |
|---|---|---|
| constructor | Method | |
| addListener | Method | Registers a listener for loaded, unloaded and swapped models |
| addModels | Method | Add one or more models. The returned Promise will resolve after all connected components have performed the addModels call. |
| addVisibilityListener | Method | Registers a listener for models shown or hidden as a whole (showModels, hideModels) |
| getAllQids | Method | |
| getAllQidsNotOfTypes | Method | |
| getBuildingStoreyQid | Method | |
| getBuildingStoreyQids | Method | |
| getBuildingStoreys | Method | |
| getDefaultVisibleQids | Method | |
| getModel | Method | Get some information about a model, the model must already have been loaded |
| getNumberOfObjects | Method | |
| getObjectInfo | Method | |
| getObjectQidsForBuildingStoreyQids | Method | |
| getType | Method | |
| getTypeQids | Method | Get all the @bimworks/jssdk!Qid s of the objects of the given (IFC) type |
| getTypesSet | Method | |
| getVersion | Method | |
| getVersions | Method | |
| getVersionsAsArray | Method | |
| getVersionUuidsArray | Method | |
| hasObject | Method | |
| hasVersion | Method | |
| hasVidOid | Method | hasObject for a version and oid, without making a Qid (members of a large group) |
| hideModels | Method | Hide the given models (must already be loaded) |
| inverseOf | Method | Return the inverse of a set of @bimworks/jssdk!Qid, so all the other loaded objects |
| isOfType | Method | |
| isRoofSlab | Method | Whether the object is a slab with predefined type ROOF, among the loaded models |
| isVersionUuidLoaded | Method | |
| prioritizeOver | Method | Puts one viewer ahead of another. The ModelManager hands new models to its viewers one at a time, in the order they were created; after this call high gets… |
| removeListener | Method | |
| removeModels | Method | Remove one or more models. The returned Promise will resolve after all connected components have performed the removeModels call. |
| removeObjectStateManager | Method | Lets go of an ObjectStateManager made on this ModelManager (its constructor registers it). Until then every model loaded later fills its sets: call it when t… |
| removeVisibilityListener | Method | |
| setClient | Method | The client to load model data with, for a manager constructed before the client existed |
| setModels | Method | Replace the existing set of loaded models, by the given set of models. This method will potentially unload models. The returned Promise will resolve after al… |
| showModels | Method | Show the given models (must already be loaded) |
| size | Method | |
| swapVersion | Method | Replaces a loaded version by its successor (after a commit), keeping the object state of the objects that still exist. Falls back to unloading both and loadi… |
| whenSettled | Method | Resolves once no addModels, removeModels, setModels or swapVersion call is in flight, one task after the last one ended. A removal followed by an addModels w… |
constructor#
constructor(client?: BimWorksClient<Client | null | undefined>, settings?: ModelManagerSettings)Parameters#
| Name | Type | Description |
|---|---|---|
client |
BimWorksClient<Client | null | undefined> |
The @bimworks/jssdk!BimWorksClient to use for communication with the BIM.works Repository |
settings |
ModelManagerSettings | See ModelManagerSettings |
addListener#
addListener(listener: ModelListener, triggerForAllLoadedModels?: boolean): void | Promise<unknown>Registers a listener for loaded, unloaded and swapped models
Parameters#
| Name | Type | Description |
|---|---|---|
listener |
ModelListener | |
triggerForAllLoadedModels |
boolean |
true: call listener.addModels with the models loaded already (the listener must have addModels then); what addModels returns is returned, a resolved Promise otherwise |
addModels#
Add one or more models. The returned Promise will resolve after all connected components have performed the addModels call.
Parameters#
| Name | Type | Description |
|---|---|---|
versions |
Iterable<Version> |
Exceptions#
- When a version lacks im_metadata (summary object, or geometry still processing). Use the complete Version as returned by @bimworks/jssdk!BimWorksClient.getNodeVersion.
While a connected Viewer3d is in offline mode, the object data of an IFC model is read from the viewer's offline store instead of the server, and a model that was not prepared for offline use rejects with ModelNotAvailableOfflineError before any server call.
addVisibilityListener#
addVisibilityListener(target: ModelVisibilityListener): voidRegisters a listener for models shown or hidden as a whole (showModels, hideModels)
Parameters#
| Name | Type | Description |
|---|---|---|
target |
ModelVisibilityListener |
getAllQids#
Returns#
All the known @bimworks/jssdk!Qid
getAllQidsNotOfTypes#
Parameters#
| Name | Type | Description |
|---|---|---|
types |
(string)[] |
Returns#
All loaded objects except those of the given types
getBuildingStoreyQid#
Parameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid |
Returns#
Get the Qid of the BuildingStorey of the given object (by Qid) or null if the object does not have a building storey
getBuildingStoreyQids#
Parameters#
| Name | Type | Description |
|---|---|---|
buildingStoreyQid |
Qid |
Returns#
The objects on a building storey. The returned object should not be changed.
getBuildingStoreys#
Returns#
The building storeys of the loaded models. The returned object should not be changed.
getDefaultVisibleQids#
Parameters#
| Name | Type | Description |
|---|---|---|
versionUuids |
(string)[] |
Returns#
The objects of the versions (default: all loaded) a viewer shows when they load: no spaces, zones, openings or building and storey boxes. A new set.
getModel#
Get some information about a model, the model must already have been loaded
Parameters#
| Name | Type | Description |
|---|---|---|
versionUuid |
Qid | The UUID of the Version |
getNumberOfObjects#
public getNumberOfObjects(): numberReturns#
The number of objects that are currently loaded
getObjectInfo#
getObjectInfo(qid: Qid): ObjectInfo | undefinedParameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid |
Returns#
What the ModelManager knows about a loaded object, undefined for an unknown one. The returned object should not be changed.
getObjectQidsForBuildingStoreyQids#
public getObjectQidsForBuildingStoreyQids(buildingStoreyQids: Iterable<Qid>, includeOpenings: boolean): QidSetParameters#
| Name | Type | Description |
|---|---|---|
buildingStoreyQids |
Iterable<Qid> |
|
includeOpenings |
boolean |
Returns#
A Set of Qid of the objects that belong to the given building storeys
getType#
Parameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid |
Returns#
The IFC type of a loaded object
getTypeQids#
Get all the @bimworks/jssdk!Qid s of the objects of the given (IFC) type
Parameters#
| Name | Type | Description |
|---|---|---|
type |
string |
getTypesSet#
getTypesSet(): Set<string>Returns#
The IFC types of the loaded objects
getVersion#
Parameters#
| Name | Type | Description |
|---|---|---|
versionUuid |
string |
Returns#
The loaded @bimworks/jssdk!Version with this uuid, undefined when it is not loaded (or still loading)
getVersions#
Returns#
A Set<@bimworks/jssdk!Version with all the currently loaded models
getVersionsAsArray#
Returns#
An Array<@bimworks/jssdk!Version with all the currently loaded models
getVersionUuidsArray#
public getVersionUuidsArray(): (string)[]Returns#
An Array<@bimworks/jssdk!Vid with the @bimworks/jssdk!Vid of the currently loaded IFC models (no point clouds, drawings or glTF: what a query or a storey listing can be asked for)
hasObject#
Parameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid |
hasVersion#
hasVersion(versionUuid: string): booleanParameters#
| Name | Type | Description |
|---|---|---|
versionUuid |
string |
hasVidOid#
hasVidOid(vid: string, oid: number): booleanhasObject for a version and oid, without making a Qid (members of a large group)
Parameters#
| Name | Type | Description |
|---|---|---|
vid |
string |
|
oid |
number |
hideModels#
public hideModels(versionUuids: (string)[]): Promise<void>Hide the given models (must already be loaded)
Parameters#
| Name | Type | Description |
|---|---|---|
versionUuids |
(string)[] |
inverseOf#
Return the inverse of a set of @bimworks/jssdk!Qid, so all the other loaded objects
Parameters#
| Name | Type | Description |
|---|---|---|
qids |
{ has: (qid: Qid) => boolean } |
Anything with a has(qid), typically a @bimworks/jssdk!QidSet |
Returns#
A new QidSet with the Qid of every loaded object that qids does not contain
isOfType#
Parameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid | |
types |
(string)[] |
Returns#
Whether the object is of one of the types
isRoofSlab#
Whether the object is a slab with predefined type ROOF, among the loaded models
Parameters#
| Name | Type | Description |
|---|---|---|
qid |
Qid |
isVersionUuidLoaded#
public isVersionUuidLoaded(versionUuid: string): booleanParameters#
| Name | Type | Description |
|---|---|---|
versionUuid |
string |
Returns#
Whether the given Version (by UUID) has been loaded
prioritizeOver#
prioritizeOver(high: ModelListener, low: ModelListener): voidPuts one viewer ahead of another. The ModelManager hands new models to its viewers one at a time, in the
order they were created; after this call high gets them before low, so the view in front loads first.
Does nothing when either viewer is not attached to this ModelManager, or high is already first.
Parameters#
| Name | Type | Description |
|---|---|---|
high |
ModelListener | The viewer (Viewer3d or Viewer2d) that should load first |
low |
ModelListener | The viewer that should wait for it |
removeListener#
removeListener(listener: ModelListener): voidParameters#
| Name | Type | Description |
|---|---|---|
listener |
ModelListener |
removeModels#
Remove one or more models. The returned Promise will resolve after all connected components have performed the removeModels call.
Parameters#
| Name | Type | Description |
|---|---|---|
versions |
Iterable<Version> |
removeObjectStateManager#
removeObjectStateManager(objectStateManager: ObjectStateManager): voidLets go of an ObjectStateManager made on this ModelManager (its constructor registers it). Until then every model loaded later fills its sets: call it when the viewer the ObjectStateManager was made for goes
Parameters#
| Name | Type | Description |
|---|---|---|
objectStateManager |
ObjectStateManager |
removeVisibilityListener#
removeVisibilityListener(target: ModelVisibilityListener): voidParameters#
| Name | Type | Description |
|---|---|---|
target |
ModelVisibilityListener |
setClient#
public setClient(client: BimWorksClient): voidThe client to load model data with, for a manager constructed before the client existed
Parameters#
| Name | Type | Description |
|---|---|---|
client |
BimWorksClient |
setModels#
Replace the existing set of loaded models, by the given set of models. This method will potentially unload models. The returned Promise will resolve after all connected components have performed the setModels call.
Parameters#
| Name | Type | Description |
|---|---|---|
versions |
Iterable<Version> |
showModels#
public showModels(versionUuids: (string)[]): Promise<void>Show the given models (must already be loaded)
Parameters#
| Name | Type | Description |
|---|---|---|
versionUuids |
(string)[] |
size#
size(): numberReturns#
The number of loaded models
swapVersion#
swapVersion(oldVersion: Version, newVersion: Version, deletedOids?: Iterable<number, any, any> | null, changed?: ChangedGeometry | null): Promise<void>Replaces a loaded version by its successor (after a commit), keeping the object state of the objects that still exist. Falls back to unloading both and loading the new one when the swap cannot be done in place.
Parameters#
| Name | Type | Description |
|---|---|---|
oldVersion |
Version | |
newVersion |
Version | |
deletedOids |
Iterable<number, any, any> | null |
|
changed |
ChangedGeometry | null |
Set when the commit changed the geometry of some objects and the new version has them in a geometry overlay of its own: the viewers load those objects in place of the ones they show, and nothing is unloaded. Without it the two versions must have the same geometry |
whenSettled#
public whenSettled(): Promise<void>Resolves once no addModels, removeModels, setModels or swapVersion call is in flight, one task after the
last one ended. A removal followed by an addModels when it resolves (a version replaced by another) is
one change: ModelManager.getVersions then holds what the change left, not the empty set between.