Reference·JavaScript · @bimworks/viewercommonJavaScript

ModelManager

Class in @bimworks/viewercommon.

API catalogue · @bimworks/viewercommon · Class

TypeScript#
class ModelManager

A 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:

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#

TypeScript#
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#

TypeScript#
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#

TypeScript#
public addModels(versions: Iterable<Version>): Promise<void>

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#

TypeScript#
addVisibilityListener(target: ModelVisibilityListener): void

Registers a listener for models shown or hidden as a whole (showModels, hideModels)

Parameters#

Name Type Description
target ModelVisibilityListener

getAllQids#

TypeScript#
public getAllQids(): QidSet

Returns#

All the known @bimworks/jssdk!Qid

getAllQidsNotOfTypes#

TypeScript#
getAllQidsNotOfTypes(...types: (string)[]): QidSet

Parameters#

Name Type Description
types (string)[]

Returns#

All loaded objects except those of the given types

getBuildingStoreyQid#

TypeScript#
public getBuildingStoreyQid(qid: Qid): Qid | null

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#

TypeScript#
getBuildingStoreyQids(buildingStoreyQid: Qid): QidSet | undefined

Parameters#

Name Type Description
buildingStoreyQid Qid

Returns#

The objects on a building storey. The returned object should not be changed.

getBuildingStoreys#

TypeScript#
getBuildingStoreys(): QidMap<unknown>

Returns#

The building storeys of the loaded models. The returned object should not be changed.

getDefaultVisibleQids#

TypeScript#
getDefaultVisibleQids(versionUuids?: (string)[]): QidSet

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#

TypeScript#
public getModel(versionUuid: Qid): Model

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#

TypeScript#
public getNumberOfObjects(): number

Returns#

The number of objects that are currently loaded

getObjectInfo#

TypeScript#
getObjectInfo(qid: Qid): ObjectInfo | undefined

Parameters#

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#

TypeScript#
public getObjectQidsForBuildingStoreyQids(buildingStoreyQids: Iterable<Qid>, includeOpenings: boolean): QidSet

Parameters#

Name Type Description
buildingStoreyQids Iterable<Qid>
includeOpenings boolean

Returns#

A Set of Qid of the objects that belong to the given building storeys

getType#

TypeScript#
getType(qid: Qid): string | undefined

Parameters#

Name Type Description
qid Qid

Returns#

The IFC type of a loaded object

getTypeQids#

TypeScript#
public getTypeQids(type: string): QidSet

Get all the @bimworks/jssdk!Qid s of the objects of the given (IFC) type

Parameters#

Name Type Description
type string

getTypesSet#

TypeScript#
getTypesSet(): Set<string>

Returns#

The IFC types of the loaded objects

getVersion#

TypeScript#
public getVersion(versionUuid: string): Version | undefined

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#

TypeScript#
public getVersions(): Set<Version>

Returns#

A Set<@bimworks/jssdk!Version with all the currently loaded models

getVersionsAsArray#

TypeScript#
public getVersionsAsArray(): (Version)[]

Returns#

An Array<@bimworks/jssdk!Version with all the currently loaded models

getVersionUuidsArray#

TypeScript#
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#

TypeScript#
hasObject(qid: Qid): boolean

Parameters#

Name Type Description
qid Qid

hasVersion#

TypeScript#
hasVersion(versionUuid: string): boolean

Parameters#

Name Type Description
versionUuid string

hasVidOid#

TypeScript#
hasVidOid(vid: string, oid: number): boolean

hasObject for a version and oid, without making a Qid (members of a large group)

Parameters#

Name Type Description
vid string
oid number

hideModels#

TypeScript#
public hideModels(versionUuids: (string)[]): Promise<void>

Hide the given models (must already be loaded)

Parameters#

Name Type Description
versionUuids (string)[]

inverseOf#

TypeScript#
public inverseOf(qids: { has: (qid: Qid) => boolean }): QidSet

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#

TypeScript#
isOfType(qid: Qid, ...types: (string)[]): boolean

Parameters#

Name Type Description
qid Qid
types (string)[]

Returns#

Whether the object is of one of the types

isRoofSlab#

TypeScript#
isRoofSlab(qid: Qid): boolean

Whether the object is a slab with predefined type ROOF, among the loaded models

Parameters#

Name Type Description
qid Qid

isVersionUuidLoaded#

TypeScript#
public isVersionUuidLoaded(versionUuid: string): boolean

Parameters#

Name Type Description
versionUuid string

Returns#

Whether the given Version (by UUID) has been loaded

prioritizeOver#

TypeScript#
prioritizeOver(high: ModelListener, low: ModelListener): void

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 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#

TypeScript#
removeListener(listener: ModelListener): void

Parameters#

Name Type Description
listener ModelListener

removeModels#

TypeScript#
public removeModels(versions: Iterable<Version>): Promise<void>

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#

TypeScript#
removeObjectStateManager(objectStateManager: ObjectStateManager): void

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 the viewer the ObjectStateManager was made for goes

Parameters#

Name Type Description
objectStateManager ObjectStateManager

removeVisibilityListener#

TypeScript#
removeVisibilityListener(target: ModelVisibilityListener): void

Parameters#

Name Type Description
target ModelVisibilityListener

setClient#

TypeScript#
public setClient(client: BimWorksClient): void

The client to load model data with, for a manager constructed before the client existed

Parameters#

Name Type Description
client BimWorksClient

setModels#

TypeScript#
public setModels(versions: Iterable<Version>): Promise<void>

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#

TypeScript#
public showModels(versionUuids: (string)[]): Promise<void>

Show the given models (must already be loaded)

Parameters#

Name Type Description
versionUuids (string)[]

size#

TypeScript#
size(): number

Returns#

The number of loaded models

swapVersion#

TypeScript#
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#

TypeScript#
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.