@itwin/measure-tools-react
Version:
Frontend framework and tools for measurements
95 lines • 5.45 kB
TypeScript
import { BeUiEvent } from "@itwin/core-bentley";
import type { GeometryStreamProps } from "@itwin/core-common";
import type { BeButtonEvent, DecorateContext, HitDetail, IModelConnection, ScreenViewport, ToolAssistanceInstruction } from "@itwin/core-frontend";
import { EventHandled, OutputMessagePriority, PrimitiveTool } from "@itwin/core-frontend";
import type { Feature } from "./FeatureTracking.js";
import type { Measurement } from "./Measurement.js";
import type { MeasurementToolModel } from "./MeasurementToolModel.js";
import { SheetMeasurementsHelper } from "./SheetMeasurementHelper.js";
/** Interface for any interactive tool that creates measurements. */
export interface MeasurementTool {
/** Gets a read-only list of measurements active in the tool. Note: By convention all measurements can be found in the [[MeasurementManager]] so it is unnecessary to query the current measurement
* tool if interested in querying all measurements.
*/
readonly measurements: ReadonlyArray<Measurement>;
/** Gets the current measurement the user is placing. */
readonly dynamicMeasurement: Measurement | undefined;
/** Persists the measurements that are active in the tool. Ownership of the measurements transfer to the measurement manager. If the tool does not persist, the
* measurements it has created are deleted from the [[MeasurementManager]].
* @returns true if measurements were persisted, false otherwise.
*/
persistMeasurements(): boolean;
/** Clears any active measurements in the [[MeasurementManager]] that the tool owns.
* @param viewType Optionally clear measurements based on the type of viewport they're drawn in.
*/
clearMeasurements(viewType?: string): void;
}
/** Namespace for functions relating to the MeasurementTool interface. */
export declare namespace MeasurementTool {
/** Event for when a tool creates a new measurement. */
const onNewMeasurement: BeUiEvent<Measurement>;
/** Event when the tool's dynamic measurement has changed. */
const onDynamicMeasurementChanged: BeUiEvent<Measurement>;
/** Gets the active measurement tool, if it exists.
* @returns the measurement tool, or undefined if the current tool is not one.
*/
function getActiveMeasurementTool(): MeasurementTool | undefined;
}
/**
* Helper class to hold the selection state during the operation of a tool. Call saveSelection on install and restoreSelection on cleanup.
*/
export declare class SelectionHolder {
private _imodel?;
private _selectedIds;
constructor();
saveSelection(imodel: IModelConnection, clearSelectionAfter: boolean): void;
restoreSelection(): void;
}
/** Useful base class for tools */
export declare abstract class PrimitiveToolBase extends PrimitiveTool {
protected get feature(): Feature | undefined;
onPostInstall(): Promise<void>;
protected showMessage(priority: OutputMessagePriority, briefMessage: string | HTMLElement, detailedMessage?: string | HTMLElement): void;
protected showException(err: Error): Promise<void>;
protected createMouseUndoInstruction(textOverride?: string): ToolAssistanceInstruction;
protected createMouseRedoInstruction(textOverride?: string): ToolAssistanceInstruction;
decorateSuspended(context: DecorateContext): void;
}
/** Useful base class for measurement tools which maintains a tool model that a subclass will instantiate as well as save the current selection/restore on exit.
* Generally a measurement tool model contains all the logic to create and manage measurements dynamically, while the tool is responsible
* for sending input events to the model.
*/
export declare abstract class MeasurementToolBase<T extends Measurement, ToolModel extends MeasurementToolModel<T>> extends PrimitiveToolBase implements MeasurementTool {
private _toolModel;
private _selectionHolder;
protected _allowedViewportCallback: (vp: ScreenViewport) => boolean;
protected _enableSheetMeasurements: boolean;
get measurements(): ReadonlyArray<Measurement>;
get dynamicMeasurement(): Measurement | undefined;
protected get toolModel(): ToolModel;
protected get selectionHolder(): SelectionHolder;
protected get saveRestoreSelection(): boolean;
protected get allowedDrawingTypes(): SheetMeasurementsHelper.DrawingType[];
constructor(allowedViewportCallback?: (vp: ScreenViewport) => boolean);
requireWriteableTarget(): boolean;
isValidLocation(ev: BeButtonEvent, _isButtonEvent: boolean): boolean;
onPostInstall(): Promise<void>;
onCleanup(): Promise<void>;
onReinitialize(): Promise<void>;
onUndoPreviousStep(): Promise<boolean>;
onRedoPreviousStep(): Promise<boolean>;
onResetButtonDown(_ev: BeButtonEvent): Promise<EventHandled>;
onKeyTransition(wentDown: boolean, keyEvent: KeyboardEvent): Promise<EventHandled>;
testDecorationHit(id: string): boolean;
getDecorationGeometry(hit: HitDetail): GeometryStreamProps | undefined;
getToolTip(hit: HitDetail): Promise<HTMLElement | string>;
decorate(context: DecorateContext): void;
onUnsuspend(): Promise<void>;
persistMeasurements(): boolean;
clearMeasurements(viewportType?: string): void;
protected updateAccuSnap(): void;
protected updateToolAssistance(): void;
protected abstract createToolModel(): ToolModel;
protected setupEvents(): void;
}
//# sourceMappingURL=MeasurementTool.d.ts.map