UNPKG

@itwin/measure-tools-react

Version:
165 lines 10 kB
import { BeUiEvent } from "@itwin/core-bentley"; import type { GeometryStreamProps } from "@itwin/core-common"; import type { BeButtonEvent, DecorateContext, Decorator, HitDetail, ScreenViewport, Viewport } from "@itwin/core-frontend"; import { EventHandled } from "@itwin/core-frontend"; import type { Measurement } from "./Measurement.js"; import { MeasurementPickContext } from "./Measurement.js"; /** Handler for overriding what is returned for the tooltip of a measurement. */ export type MeasurementToolTipHandler = (measurement: Measurement, pickContext: MeasurementPickContext) => Promise<HTMLElement | string>; /** Handler for overriding what is returned for pick-able geometry of a measurement. */ export type MeasurementGeometryHandler = (measurement: Measurement, pickContext: MeasurementPickContext) => GeometryStreamProps | undefined; /** Handler ofr overriding to determine if a measurement has been picked or not. */ export type MeasurementHitHandler = (measurement: Measurement, pickContext: MeasurementPickContext) => boolean; /** Button event details */ export interface MeasurementButtonEvent { measurement: Measurement; pickContext: MeasurementPickContext; } /** * Singleton manager which maintains a list of all active measurements once they are created by a measurement tool. The manager facilitates drawing and picking of measurements * to the appropriate viewport. */ export declare class MeasurementManager implements Decorator { private static _instance?; private _measurements; private _dropDecoratorCallback?; private _dropQuantityFormatterListeners?; private _dropGlobalOriginChangedCallback?; private _iModelIdForGlobalOrigin?; private _overrideToolTipHandler?; private _overrideGeometryHandler?; private _overrideHitHandler?; /** Event that is invoked when a measurement has responded to a button event. */ readonly onMeasurementButtonEvent: BeUiEvent<MeasurementButtonEvent>; /** Event that is invoked when a measurement is added. */ readonly onMeasurementsAdded: BeUiEvent<Measurement[]>; /** Event that is invoked when a measurement is dropped or cleared. */ readonly onMeasurementsRemoved: BeUiEvent<Measurement[]>; /** Gets the manager instance. */ static get instance(): MeasurementManager; /** Gets a readonly array of measurements the manager owns. This does not include any transient measurements an active tool is displaying. */ get measurements(): ReadonlyArray<Measurement>; /** Gets or sets an override tooltip handler. If defined, this overrides what is returned in getDecorationToolTip. */ get overrideToolTipHandler(): MeasurementToolTipHandler | undefined; set overrideToolTipHandler(handler: MeasurementToolTipHandler | undefined); /** Gets or sets an override geometry handler. If defined, this overrides what is returned in getDecorationGeometry. */ get overrideGeometryHandler(): MeasurementGeometryHandler | undefined; set overrideGeometryHandler(handler: MeasurementGeometryHandler | undefined); /** Gets or sets an override hit handler. If defined, this overrides the logic in testDecorationHit. */ get overrideHitHandler(): MeasurementHitHandler | undefined; set overrideHitHandler(handler: MeasurementHitHandler | undefined); /** Adds one or more measurements to the manager. * @param measurement one or more measurements to add. */ addMeasurement(measurement: Measurement | Measurement[]): void; /** * Iterates over all measurements owned by the manager. * @param callback Callback to invoke for each measurement, return true to keep iterating or false to early out. */ forAllMeasurements(callback: (measurement: Measurement) => boolean): void; /** * Queries measurements that can be drawn in a given view type. * @param viewType view type to find measurements for. Can be any [[WellKnownViewType]] or an app-defined one. * @returns an array of measurements that are valid for the view type or an empty array if none were found. */ getMeasurementsForViewType(viewType: string): Measurement[]; /** * Queries measurements that can be drawn in a given viewport. * @param vp Viewport to find measurements for. * @returns an array of measurements that are valid for the viewport or an empty array if none were found. */ getMeasurementsForViewport(vp: Viewport): Measurement[]; /** Queries measurements that belong to the group, and optionally subgroup. * @param groupId ID of the group * @param subgroupId Optional ID of the subgroup * @returns an array of measurements that belong to the specified group. */ getMeasurementsForGroup(groupId: string, subgroupId?: string): Measurement[]; /** Queries measurements based on a user-defined predicate. * @param callback Defines the criteria for what the measurement needs to satisfy to be returned. * @returns an array of measurements that satisfy the predicate. */ getMeasurementsForPredicate(callback: (measurement: Measurement) => boolean): Measurement[]; /** Removes one or more measurements from the manager. * @param measurement one or more measurements to remove. * @returns true if the measurements were dropped, false if none were found. */ dropMeasurement(measurement: Measurement | Measurement[]): boolean; /** * Removes any measurements from the manager based on the view type. * @param viewType view type to find measurements for. Can be any [[WellKnownViewType]] or an app-defined one. * @returns an array of measurements that were dropped, or empty if none were. */ dropMeasurementsForViewType(viewType: string): Measurement[]; /** Removes any measurements from the manager for a given viewport. * @param vp Viewport to find measurements to drop for. * @returns an array of measurements that were dropped, or empty if none were. */ dropMeasurementForViewport(vp: Viewport): Measurement[]; /** Removes one or more measurements that belong to the given group. * @param groupId ID of the group. * @param subgroupId Optional ID of the subgroup. * @returns an array of measurements removed from the decorator. */ dropMeasurementsForGroup(groupId: string, subgroupId?: string): Measurement[]; /** Removes one or more measurements that satisfy the predicate. * @param callback Defines the criteria for whether or not the measurement should be removed. * @returns an array of measurements removed from the decorator. */ dropMeasurementsForPredicate(callback: (measurement: Measurement) => boolean): Measurement[]; /** Clears measurements from the manager. * @param clearLocked true if locked measurements should be cleared as well as non-locked, false to not clear locked measurements. */ clear(clearLocked?: boolean): void; /** Tests if the pick ID belongs to any measurement. * @param id pick ID used by graphics the measurement generates for drawing. * @returns true if the measurement has been picked, false otherwise. */ testDecorationHit(id: string): boolean; /** Get a geometry stream representing the pickable geometry of any measurement currently picked. Usually this is simplier geometry than what is drawn. * @param hit Current picking context. * @returns a geometry stream of pickable data or undefined. */ getDecorationGeometry(hit: HitDetail): GeometryStreamProps | undefined; /** Get a tooltip for any measurement currently picked. * @param hit Current picking context. * @returns a tooltip HTML element or string. */ getDecorationToolTip(hit: HitDetail): Promise<HTMLElement | string>; /** Handles button events on any measurements that have been picked. * @param hit Current picking context. * @param ev Current button event. * @returns enum whether the event has been handled or not. */ onDecorationButtonEvent(hit: HitDetail, ev: BeButtonEvent): Promise<EventHandled>; /** * Notifies the event handler the measurement has responded to a button event. * @param measurement Measurement that responded to the event. * @param pickContext Current pick context. */ notifyMeasurementButtonEvent(measurement: Measurement, pickContext: MeasurementPickContext): void; /** Draws all valid measurements to a given viewport. Measurements that do not have the correct viewport type are not drawn to the viewport. * @param context Decorate context for drawing to a viewport. */ decorate(context: DecorateContext): void; /** Draws all measurements that have cached graphics to a given viewport. Measurements that do not have the correct viewport type are not drawn to the viewport. * @param context Decorate context for drawing to a viewport. */ decorateCached(context: DecorateContext): void; private tryAddGlobalOriginChangedListener; /** Invalidates decorations in all views, including any cached graphics measurements may be using. */ invalidateDecorationsAllViews(): void; /** Invalidates decorations in a specified viewport. If undefined then all viewports are invalidated. This includes any cached graphics measurements may be using. * @param vp Viewport to invalidate decorations, if undefined all viewports. */ invalidateDecorations(vp?: ScreenViewport): void; /** Adds the decorator singleton to the view manager's list of active decorators. The decorator will participate in drawing and picking operations. */ startDecorator(): void; /** Removes the decorator singleton from the view manager's list of active decorators. The decorator will still manage measurements, but will not * participate in drawing or picking operations. */ stopDecorator(): void; onActiveUnitSystemChanged(): void; onFormatsChanged(): Promise<void>; } //# sourceMappingURL=MeasurementManager.d.ts.map