Skip to content

Commit

Permalink
doc(viewer): rewrite/rearrange viewer reference
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasRichel committed Nov 22, 2023
1 parent 43fce33 commit 39f5a8a
Show file tree
Hide file tree
Showing 10 changed files with 899 additions and 479 deletions.
7 changes: 5 additions & 2 deletions src/.vuepress/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ function getViewerSidebar() {
title: "Reference",
children: [
"reference/makeBIMDataViewer",
"reference/native_plugins",
"reference/mount",
"reference/$viewer",
"reference/hubs",
"reference/state",
"reference/global_context",
"reference/local_context",
"reference/context_menu",
"reference/native_plugins",
"reference/viewer_plugins",
"reference/global_components",
"reference/hubs",
],
},
"release_notes",
Expand Down
11 changes: 11 additions & 0 deletions src/api/external_libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ npm install @bimdata/bimdata-api-client --save

- Repository: [https://github.com/bimdata/javascript-api-client](https://github.com/bimdata/javascript-api-client)

## Typescript

- Install via NPM:
```bash
npm install @bimdata/typescript-fetch-api-client --save
```

- URL: [https://www.npmjs.com/package/@bimdata/typescript-fetch-api-client](https://www.npmjs.com/package/@bimdata/typescript-fetch-api-client)

- Repository: [https://github.com/bimdata/typescript-fetch-api-client-generator](https://github.com/bimdata/typescript-fetch-api-client-generator)

## Python

- URL: [https://pypi.org/project/bimdata-api-client/](https://pypi.org/project/bimdata-api-client/)
Expand Down
359 changes: 205 additions & 154 deletions src/viewer/reference/$viewer.md

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions src/viewer/reference/global_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Global Context

Here is the full `GlobalContext` interface:

```typescript
interface GlobalContext {
hub: EventHandler<GlobalContextEvents & LocalContextEvents>;

readonly plugins: Map<string, PluginInstance[]>;
readonly activeLocalContext?: LocalContext;
readonly localContexts: LocalContext[];
getLocalContexts(window: string): LocalContext[];
getViewers(): ModelViewerInstance[];

registerShortcut(shortcut: Shortcut, context: GlobalContext | LocalContext): boolean;
unregisterShortcut(name: string, context: GlobalContext | LocalContext): boolean;

readonly loading: boolean;
loadingProcessStart(): void;
loadingProcessEnd(): void;
setSpinner(spinner: any): void;

modals: {
pushModal(component: any, props?: any, options?: any): void;
clearModal(): void;
};
}
```

## Events

The table below describe global context specific events:

| Name | Payload | Description |
| :-------------- | :----------------------- | :---------- |
| `window-open` | the opened window object | Sent when a [window](/viewer/customize_the_ui.html#window) is selected on the window selector. |
| `window-close` | the closed window object | Sent when a [window](/viewer/customize_the_ui.html#window) is closed. |

Additionally a set of [local context events](/viewer/reference/local_context.html#events-emitted-on-both-global-local-contexts)
are also emitted on global context.
2 changes: 1 addition & 1 deletion src/viewer/reference/hubs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tags: ["event", "events"]
---

# Hubs
# Event Hubs

A Hub is an event manager. It allows to register event handler and to trigger events.

Expand Down
166 changes: 166 additions & 0 deletions src/viewer/reference/local_context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Local Context

The `$viewer.localContext` object is used as an interface between a plugin and its containing window.

Here is the full `LocalContext` interface:

```typescript
interface LocalContext {
hub: EventHandler<LocalContextEvents>;

id: number;
readonly el: Element;
readonly x: number;
readonly y: number;
readonly width: number;
readonly height: number;
resolution: number;

// Local state
readonly multiModel: boolean;
readonly modelTypes?: string[];
readonly loadedModels: StateModel[];
readonly loadedModelIds: number[];
readonly loadingModelIds: number[];
readonly currentStorey: StateStorey | null;
loadModels(ids: number[]): Promise<boolean>;
unloadModels(ids: number[]): boolean;
toggleModel(id: number): Promise<boolean>;
selectStorey(storey: StateStorey): void;
showPlan(plan: StatePlan): void;
hidePlan(plan: StatePlan): void;
togglePlanVisibility(plan: StatePlan): void;
togglePlanEdition(plan: StatePlan): void;
createPlan(model: StateModel, storey: StateStorey, document: ApiDocument, positioning: StatePositionning): Promise<StatePlan>;
updatePlan(plan: StatePlan, positioning: StatePositionning): Promise<StatePlan>;
deletePlan(plan: StatePlan): Promise<void>;

// Viewer Interface
readonly viewer: ModelViewerInstance | null;
readonly annotationMode: boolean;
getViewpoint: (options?: any) => any | Promise<any>;
setViewpoint: (viewpoint: any, options?: any) => void | Promise<void>;
startAnnotationMode: (callback: Function) => void;
stopAnnotationMode: () => void;
fitView: (options?: any) => void;
showUI: (options?: any) => void;
hideUI: (options?: { exceptions: string[] }) => Promise<void>;

// Context Window
readonly window: Window;
loadWindow(windowName: string): void;

// Plugins
readonly plugins: Map<string, PluginInstance>;

// Shortcuts
registerShortcut(shortcut: Shortcut): boolean;
unregisterShortcut(name: string): boolean;

// Loading
readonly loading: boolean;
loadingProcessStart(): void;
loadingProcessEnd(): void;

// Modals
readonly modals: {
pushModal(component: Object, props?: Object, options?: Object): void;
clearModal(): void;
};
}
```

## Local State

The [global state](./state.md) allows to manage a set of shared data that is not tied to a specific context.

To manage models, storeys and plans for a given context you can use the `localContext` object.

| Name | Description |
| :--------------------------------- | :--------------------------------------------------------------------- |
| **properties** | |
| `loadedModels` | List of currently loaded models |
| `loadedModelIds` | List of currently loaded model ids |
| `loadingModelIds` | List of model ids that are currently loading |
| `currentStorey` | Storey that is currently active |
| **methods** | |
| `loadModels(ids: number[])` | Load the given models in this context |
| `unloadModels(ids: number[])` | Unload the given models from this context |
| `toggleModel(id: number)` | *Load* (resp. *unload*) model if it is *not unloaded* (resp. *loaded*) |
| `selectStorey(storey: Storey)` | Set storey as the current storey |
| `showPlan(plan: Plan)` | Show plan |
| `hidePlan(plan: Plan)` | Hide plan |
| `togglePlanVisibility(plan: Plan)` | Toggle plan visibility |
| `togglePlanEdition(plan: Plan)` | Toggle plan edition mode |

The properties described above are reactive and can be watched by Vue to trigger effects:

```javascript
watch(
() => $viewer.localContext.loadedModels
models => {
console.log("Currently loaded models: ", models);
}
);
```

## Viewer Interface

For [viewer windows](./viewer_plugins.md) the `localContext` provide an API to interact with the local model viewer.
It is a set of methods that are independent on the type of viewer (`IFC`, `DWG`, `Plan`, ...).
If the current context is not a viewer window, an error is thrown when these methods are called.

| Name | Description |
| :-------------------------------------------- | :---------------------------------------------------------------------------------- |
| **properties** | |
| `viewer` | Model viewer instance of this context, `null` if the context is not a viewer window |
| `annotationMode` | `true` if annotation mode is activated, `false` otherwise |
| **methods** | |
| `getViewpoint(options?: any)` | (*async*) Get the current model viewer viewpoint |
| `setViewpoint(viewpoint: any, options?: any)` | (*async*) Set model viewer viewpoint |
| `startAnnotationMode(callback: Function)` | Activate annotation mode |
| `stopAnnotationMode()` | Deactivate annotation mode |
| `fitView(options?: any)` | Apply a "fit view" command to the model viewer |
| `showUI(options?: any)` | Makes all UI elements of the context visible (such as plugins and model selector) |
| `hideUI(options?: { exceptions: string[] })` | (*async*) Hide all UI elements of the context (some exceptions can be specified) |

## Events

### Local Context specific events

| Name | Payload | Description |
| :-------------------------- | :------------------------------------------- | :---------- |
| `alert` | `{ type: string, message: string }` | A plugin in this context raised an alert to be displayed |
| `context-resize` | `{ width: number, height: number }` | The context window has been resized |
| `models-loaded` | `{ models: Model[] }` | One or more models have been loaded in this context |
| `models-unloaded` | `{ models: Model[] }` | One or more models have been unloaded from this context |
| `models-loading` | `{ ids: number[] }` | One or more models are loading in this context |
| `storey-selected` | `{ storey: Storey }` | The current active storey has changed |
| `plan-shown` | `{ plan: Plan }` | A storey plan is now visible |
| `plan-hidden` | `{ plan: Plan }` | A storey plan has been hidden |
| `plan-editing` | `{ plan: Plan }` | A storey plan edition mode has been toggle |
| `plan-created` | `{ plan: Plan }` | A storey plan has been created |
| `plan-updated` | `{ plan: Plan }` | A storey plan has been updated |
| `plan-deleted` | `{ plan: Plan }` | A storey plan has been deleted |
| `pdf-page-changed` | `{ model: Model, page: any }` | The current PDF page changed |

### Events emitted on both Global & Local contexts

| Name | Payload | Description |
| :-------------------------- | :------------------------------------------- | :---------- |
| `plugin-created` | `{ name: string, plugin: PluginInstance }` | A plugin has been added to this context |
| `plugin-destroyed` | `{ name: string, plugin: PluginInstance }` | A plugin has been removed from this context |
| `plugin-menu-open` | `{ name: string, plugin: PluginInstance }` | A menu plugin has been opened |
| `plugin-menu-close` | `{ name: string, plugin: PluginInstance }` | A menu plugin has been closed |
| `3d-model-loaded` | `{ model: Model, plugin: ViewerIfc3D }` | An IFC model has been loaded in an IFC 3D viewer |
| `3d-model-unloaded` | `{ model: Model, plugin: ViewerIfc3D }` | An IFC model has been unloaded from an IFC 3D viewer |
| `2d-model-loaded` | `{ model: Model, plugin: ViewerIfc2D }` | An IFC model has been loaded in an IFC 2D viewer |
| `2d-model-unloaded` | `{ model: Model, plugin: ViewerIfc2D }` | An IFC model has been unloaded from an IFC 2D viewer |
| `dwg-model-loaded` | `{ model: Model, plugin: ViewerDwg }` | A DWG model has been loaded |
| `dwg-model-unloaded` | `{ model: Model, plugin: ViewerDwg }` | A DWG model has been unloaded |
| `dxf-model-loaded` | `{ model: Model, plugin: ViewerDwg }` | A DXF model has been loaded |
| `dxf-model-unloaded` | `{ model: Model, plugin: ViewerDwg }` | A DXF model has been unloaded |
| `plan-model-loaded` | `{ model: Model, plugin: ViewerPlan }` | A Plan/Meta-Building model has been loaded |
| `plan-model-unloaded` | `{ model: Model, plugin: ViewerPlan }` | A Plan/Meta-Building model has been unloaded |
| `pointcloud-model-loaded` | `{ model: Model, plugin: ViewerPointCloud }` | A Point Cloud model has been loaded |
| `pointcloud-model-unloaded` | `{ model: Model, plugin: ViewerPointCloud }` | A Point Cloud model has been unloaded |
Loading

0 comments on commit 39f5a8a

Please sign in to comment.