UNPKG

@itwin/core-frontend

Version:
274 lines • 16.3 kB
/** @packageDocumentation * @module Views */ import { BeEvent, BentleyStatus, BeTimePoint, BeUiEvent, Id64Arg } from "@itwin/core-bentley"; import { GeometryStreamProps } from "@itwin/core-common"; import { HitDetail } from "./HitDetail"; import { IModelConnection } from "./IModelConnection"; import { BeButtonEvent, EventHandled } from "./tools/Tool"; import { ScreenViewport, ViewportDecorator } from "./Viewport"; /** Interface for drawing [decoration graphics]($docs/learning/frontend/ViewDecorations.md) into, or on top of, the active [[ScreenViewport]]s managed by [[ViewManager]]. * Decorators generate [[Decorations]]. * @public * @extensions */ export interface Decorator extends ViewportDecorator { /** If the [[decorate]] method created pickable graphics, return true if the supplied Id is from this Decorator. * @param id The Id of the currently selected pickable graphics. * @returns true if 'id' belongs to this Decorator */ testDecorationHit?(id: string): boolean; /** If the [[decorate]] method created pickable graphics using a persistent element id instead of a transient id, * return true if the Decorator wants the opportunity to override the default persistent element behavior for * the supplied [[HitDetail]]. * - Replace or augment the element's tooltip by implementing [[getDecorationToolTip]]. * - Override the element's snap geometry by implementing [[getDecorationGeometry]]. * - Handle button events as decorator events by implementing [[onDecorationButtonEvent]]. * @param hit The HitDetail of the currently selected persistent element or pickable graphics using a persistent element id. * @returns true if this Decorator wants to override the default persistent element behavior. */ overrideElementHit?(hit: HitDetail): boolean; /** If [[testDecorationHit]] or [[overrideElementHit]] returned true, implement this method to return the tooltip message for this Decorator. * @param hit The HitDetail about the decoration that was picked. * @returns A promise with the HTMLElement or string (that may contain HTML) with the tooltip message. */ getDecorationToolTip?(hit: HitDetail): Promise<HTMLElement | string>; /** If [[testDecorationHit]] or [[overrideElementHit]] returned true, implement this method to handle a button event for this Decorator. * @param hit The HitDetail about the decoration that was picked. * @param ev The BeButtonEvent that identified this decoration. * @returns A Promise that resolves to Yes if event completely handled by decoration and event should not be processed by the calling tool. */ onDecorationButtonEvent?(hit: HitDetail, ev: BeButtonEvent): Promise<EventHandled>; /** If [[testDecorationHit]] or [[overrideElementHit]] returned true, implement this method to return the snappable geometry for this Decorator. Geometry that changes with every cursor motion isn't valid for snapping. * An example would be an InteractiveTool for placing a linestring. It might wish to allow snapping to accepted segments, the segment from the last accepted point to the current cursor position would not be included * as snappable geometry and would just be displayed in dynamics. * @param hit The HitDetail about the decoration that was picked. * @returns GeometryStreamProps containing world coordinate snappable geometry for this decoration. */ getDecorationGeometry?(hit: HitDetail): GeometryStreamProps | undefined; } /** Argument for [[ViewManager.onSelectedViewportChanged]] * @public * @extensions */ export interface SelectedViewportChangedArgs { current?: ScreenViewport; previous?: ScreenViewport; } /** An object that can contribute customizations to the tooltip displayed when mousing over an element or other entity in a [[Viewport]]. * @see [[ViewManager.addToolTipProvider]] to register a tooltip provider. * @public */ export interface ToolTipProvider { /** Augment or replace the tooltip for the specified HitDetail. * @note To cooperate with other tooltip providers, prefer to *append* information to the input tooltip instead of replacing it entirely. */ augmentToolTip(hit: HitDetail, tooltip: Promise<HTMLElement | string>): Promise<HTMLElement | string>; } /** The ViewManager holds the list of opened views, plus the *selected view*. It also provides notifications of view open/close and suspend/resume. * Applications must call [[addViewport]] when new Viewports that should be associated with user events are created. * * A single ViewManager is created when [[IModelApp.startup]] is called. It can be accessed via the static member [[IModelApp.viewManager]]. * * The ViewManager controls the render loop, which causes the contents of each registered [[Viewport]] to update on the screen. * @public * @extensions */ export declare class ViewManager implements Iterable<ScreenViewport> { inDynamicsMode: boolean; cursor: string; private readonly _viewports; readonly decorators: Decorator[]; private _selectedView?; private _invalidateScenes; private _skipSceneCreation; private _doIdleWork; private _idleWorkTimer?; /** @internal */ readonly toolTipProviders: ToolTipProvider[]; private _beginIdleWork; /** @internal */ onInitialized(): void; /** @internal */ onShutDown(): void; /** Returns true if the specified viewport is currently being managed by this ViewManager. * @see [[addViewport]] to enable management of a viewport and [[dropViewport]] to disable it. */ hasViewport(viewport: ScreenViewport): boolean; /** Called after the selected view changes. * @param old Previously selected viewport. * @param current Currently selected viewport. */ readonly onSelectedViewportChanged: BeUiEvent<SelectedViewportChangedArgs>; /** Called after a view is opened. This can happen when the iModel is first opened or when a user opens a new view. */ readonly onViewOpen: BeUiEvent<ScreenViewport>; /** Called after a view is closed. This can happen when the iModel is closed or when a user closes an open view. */ readonly onViewClose: BeUiEvent<ScreenViewport>; /** Called after a view is suspended. This happens when the application is minimized or, on a tablet, when the application * is moved to the background. */ readonly onViewSuspend: BeUiEvent<ScreenViewport>; /** Called after a suspended view is resumed. This can happen when a minimized application is restored * or, on a tablet, when the application is moved to the foreground. */ readonly onViewResume: BeUiEvent<ScreenViewport>; /** Called at the beginning of each tick of the render loop, before any viewports have been updated. * The render loop is typically invoked by a requestAnimationFrame() callback. It will not be invoked if the ViewManager is tracking no viewports. * @note Due to the frequency of this event, avoid performing expensive work inside event listeners. * @see [[ViewManager.onFinishRender]] */ readonly onBeginRender: BeEvent<() => void>; /** Called at the end of each tick of the render loop, after all viewports have been updated. * The render loop is typically invoked by a requestAnimationFrame() callback. It will not be invoked if the ViewManager is tracking no viewports. * @note Due to the frequency of this event, avoid performing expensive work inside event listeners. * @see [[ViewManager.onBeginRender]] */ readonly onFinishRender: BeEvent<() => void>; /** @internal */ endDynamicsMode(): void; /** @internal */ beginDynamicsMode(): void; /** @internal */ get doesHostHaveFocus(): boolean; /** Set the selected [[Viewport]] to undefined. */ clearSelectedView(): void; /** Sets the selected [[Viewport]]. */ setSelectedView(vp: ScreenViewport | undefined): Promise<BentleyStatus>; /** @internal */ notifySelectedViewportChanged(previous: ScreenViewport | undefined, current: ScreenViewport | undefined): void; /** The "selected view" is the default for certain operations. */ get selectedView(): ScreenViewport | undefined; /** Get the first opened view. */ getFirstOpenView(): ScreenViewport | undefined; /** Check if only a single viewport is being used. If so, render directly on-screen using its WebGL canvas. Otherwise, render each view offscreen. */ private updateRenderToScreen; /** Add a new Viewport to the list of opened views and create an EventController for it. * @param newVp the Viewport to add * @returns SUCCESS if vp was successfully added, ERROR if it was already present. * @note raises onViewOpen event with newVp. */ addViewport(newVp: ScreenViewport): BentleyStatus; /** Remove a Viewport from the list of opened views, and optionally dispose of it. * Typically a Viewport is dropped when it is no longer of any use to the application, in which case it should also be * disposed of as it may hold significant GPU resources. * However in some cases a Viewport may be temporarily dropped to suspend rendering; and subsequently re-added to * resume rendering - for example, when the Viewport is temporarily hidden by other UI elements. * In the latter case it is up to the caller to ensure the Viewport is properly disposed of when it is no longer needed. * Attempting to invoke any function on a Viewport after it has been disposed is an error. * @param vp the Viewport to remove. * @param disposeOfViewport Whether or not to dispose of the Viewport. Defaults to true. * @return SUCCESS if vp was successfully removed, ERROR if it was not present. * @note raises onViewClose event with vp. */ dropViewport(vp: ScreenViewport, disposeOfViewport?: boolean): BentleyStatus; /** Iterate over the viewports registered with the view manager. */ [Symbol.iterator](): Iterator<ScreenViewport>; /** Instruct each registered [[Viewport]] that the cached [[Decorations]] for the specified `decorator` should be discarded and recreated on the next frame. * @see [[Viewport.invalidateCachedDecorations]] to invalidate the cached decorations for a single viewport. */ invalidateCachedDecorationsAllViews(decorator: ViewportDecorator): void; /** Force each registered [[Viewport]] to regenerate its [[Decorations]] on the next frame. */ invalidateDecorationsAllViews(): void; /** Force each registered [[Viewport]] to regenerate its [[FeatureSymbology.Overrides]] on the next frame. * This is rarely needed - viewports keep track of their own states to detect when the overrides need to be recreated. */ invalidateSymbologyOverridesAllViews(): void; /** @internal */ onSelectionSetChanged(_iModel: IModelConnection): void; /** @internal */ invalidateViewportScenes(): void; /** @internal */ validateViewportScenes(): void; /** Requests that [[Viewport.createScene]] be invoked for every viewport on the next frame. * This is rarely useful - viewports keep track of their own states to detect when the scene needs to be recreated. */ invalidateScenes(): void; /** @internal */ get sceneInvalidated(): boolean; /** Invoked by ToolAdmin event loop. * @internal */ renderLoop(): void; /** Purge TileTrees that haven't been drawn since the specified time point and are not currently in use by any ScreenViewport. * Intended strictly for debugging purposes - TileAdmin takes care of properly purging. * @internal */ purgeTileTrees(olderThan: BeTimePoint): void; /** Compute the tooltip for a persistent element. * This method calls the backend method [Element.getToolTipMessage]($backend), and replaces all instances of `${localizeTag}` with localized string from IModelApp.i18n. */ getElementToolTip(hit: HitDetail): Promise<HTMLElement | string>; /** Register a new [[ToolTipProvider]] to customize the locate tooltip. * @param provider The new tooltip provider to add. * @throws Error if `provider` is already registered. * @returns a function that may be called to remove this provider (in lieu of calling [[dropToolTipProvider]].) */ addToolTipProvider(provider: ToolTipProvider): () => void; /** Drop (remove) a [[ToolTipProvider]] so it is no longer active. * @param provider The tooltip provider to drop. * @note Does nothing if provider is not currently active. */ dropToolTipProvider(provider: ToolTipProvider): void; /** Add a new [[Decorator]] to display decorations into the active views. * @param decorator The new decorator to add. * @throws Error if decorator is already active. * @returns a function that may be called to remove this decorator (in lieu of calling [[dropDecorator]].) * @see [[dropDecorator]] */ addDecorator(decorator: Decorator): () => void; /** Drop (remove) a [[Decorator]] so it is no longer active. * @param decorator The Decorator to drop. * @returns true if the decorator was found and removed; false if the decorator was not found. */ dropDecorator(decorator: Decorator): boolean; /** Get the tooltip for a pickable decoration. * @internal */ getDecorationToolTip(hit: HitDetail): Promise<HTMLElement | string>; /** Allow a pickable decoration to handle a button event that identified it for the SelectTool. * @internal */ onDecorationButtonEvent(hit: HitDetail, ev: BeButtonEvent): Promise<EventHandled>; /** Allow a pickable decoration to be snapped to by AccuSnap or TentativePoint. * @internal */ getDecorationGeometry(hit: HitDetail): GeometryStreamProps | undefined; /** Allow a pickable decoration created using a persistent element id to augment or replace the the persistent element's tooltip. * @internal */ overrideElementToolTip(hit: HitDetail): Promise<HTMLElement | string>; /** Allow a pickable decoration created using a persistent element id to handle a button event that identified it for the SelectTool. * @internal */ overrideElementButtonEvent(hit: HitDetail, ev: BeButtonEvent): Promise<EventHandled>; /** Allow a pickable decoration created using a persistent element id to control whether snapping uses the persistent element's geometry. * @internal */ overrideElementGeometry(hit: HitDetail): GeometryStreamProps | undefined; get crossHairCursor(): string; get dynamicsCursor(): string; get grabCursor(): string; get grabbingCursor(): string; get walkCursor(): string; get rotateCursor(): string; get lookCursor(): string; get zoomCursor(): string; /** Change the cursor shown in all Viewports. * @param cursor The new cursor to display. If undefined, the default cursor is used. */ setViewCursor(cursor?: string): void; /** Intended strictly as a temporary solution for interactive editing applications, until official support for such apps is implemented. * Call this after editing one or more models, passing in the Ids of those models, to cause new tiles to be generated reflecting the changes. * Pass undefined if you are unsure which models changed (this is less efficient as it discards all tiles for all viewed models in all viewports). * @internal */ refreshForModifiedModels(modelIds: Id64Arg | undefined): void; /** Sets the number of [MSAA]($docs/learning/display/MSAA.md) samples for all currently- and subsequently-opened [[ScreenViewport]]s. * @param numSamples The number of samples as a power of two. Values of 1 or less indicates anti-aliasing should be disabled. Non-power-of-two values are rounded * down to the nearest power of two. The maximum number of samples supported depends upon the client's graphics hardware capabilities. Higher values produce * a higher-quality image but also may also reduce framerate. * @see [[Viewport.antialiasSamples]] to adjust the number of samples for a specific viewport. */ setAntialiasingAllViews(numSamples: number): void; } //# sourceMappingURL=ViewManager.d.ts.map