@itwin/core-frontend
Version:
iTwin.js frontend components
389 lines • 18.1 kB
TypeScript
/** @packageDocumentation
* @module Tools
*/
import { BeEvent, Id64Arg, Id64String } from "@itwin/core-bentley";
import { ClipPlane, ClipShape, ClipVector, ConvexClipPlaneSet, GeometryQuery, Matrix3d, Point3d, Range1d, Range3d, Ray3d, Transform, Vector3d } from "@itwin/core-geometry";
import { ColorDef, LinePixels } from "@itwin/core-common";
import { DialogItem, DialogPropertySyncItem, PropertyDescription } from "@itwin/appui-abstract";
import { ContextRotationId } from "../AccuDraw";
import { HitDetail } from "../HitDetail";
import { GraphicBuilder } from "../render/GraphicBuilder";
import { DecorateContext } from "../ViewContext";
import { ScreenViewport, Viewport } from "../Viewport";
import { EditManipulator } from "./EditManipulator";
import { PrimitiveTool } from "./PrimitiveTool";
import { BeButtonEvent, EventHandled } from "./Tool";
/** An object that can react to a view's clip being changed by tools or modify handles.
* @public
* @extensions
*/
export interface ViewClipEventHandler {
/** Add newly created clip geometry to selection set and show modify controls. */
selectOnCreate(): boolean;
/** Stop displaying clip geometry when clip is removed from the selection set. */
clearOnDeselect(): boolean;
/** Called by tools that set or replace the existing view clip with a new clip. */
onNewClip(viewport: Viewport): void;
/** Called by tools that add a single plane to the view clip. When there is more than one plane, the new plane is always last. */
onNewClipPlane(viewport: Viewport): void;
/** Called by tools after modifying the view clip. */
onModifyClip(viewport: Viewport): void;
/** Called when the view clip is cleared from the view. */
onClearClip(viewport: Viewport): void;
/** Called when user right clicks on clip geometry or clip modify handle. Return true if event handled. */
onRightClick(hit: HitDetail, ev: BeButtonEvent): boolean;
}
/** @internal Options to control display for ViewClipTool.drawClip */
export interface DrawClipOptions {
/** Color to use for clip edges, uses white adjusted for background color if not specified. */
color?: ColorDef;
/** Color to use for clip plane fill, uses transparent cyan adjusted for background color if not specified. */
fill?: ColorDef;
/** Width for visible clip edges, uses 3 if not specified. */
visibleWidth?: number;
/** Width for hidden clip edges, uses 1 if not specified. */
hiddenWidth?: number;
/** Style for hidden clip edges, uses LinePixels.Code2 if not specified. */
hiddenStyle?: LinePixels;
/** Whether to draw filled clip planes. */
fillClipPlanes?: boolean;
/** Whether clip represents a single section plane with additional planes for xy and back clipping. Fill will only apply to the primary plane. */
hasPrimaryPlane?: boolean;
/** Unique id to allow clip edges to be pickable. */
id?: string;
}
/** A tool to define a clip volume for a view
* @public @extensions
*/
export declare class ViewClipTool extends PrimitiveTool {
protected _clipEventHandler?: ViewClipEventHandler | undefined;
constructor(_clipEventHandler?: ViewClipEventHandler | undefined);
/** @internal */
protected static _orientationName: string;
/** @internal */
protected static enumAsOrientationMessage(str: string): string;
/** @internal */
protected static _getEnumAsOrientationDescription: () => PropertyDescription;
/** @internal */
requireWriteableTarget(): boolean;
/** @internal */
isCompatibleViewport(vp: Viewport | undefined, isSelectedViewChange: boolean): boolean;
/** @internal */
onPostInstall(): Promise<void>;
/** @internal */
onUnsuspend(): Promise<void>;
/** @internal */
onRestartTool(): Promise<void>;
/** @internal */
protected showPrompt(): void;
/** @internal */
protected setupAndPromptForNextAction(): void;
/** @internal */
onResetButtonUp(_ev: BeButtonEvent): Promise<EventHandled>;
/** @internal */
static getPlaneInwardNormal(orientation: ContextRotationId, viewport: Viewport): Vector3d | undefined;
static enableClipVolume(viewport: Viewport): boolean;
static setViewClip(viewport: Viewport, clip?: ClipVector): boolean;
static doClipToConvexClipPlaneSet(viewport: Viewport, planes: ConvexClipPlaneSet): boolean;
static doClipToPlane(viewport: Viewport, origin: Point3d, normal: Vector3d, clearExistingPlanes: boolean): boolean;
static doClipToShape(viewport: Viewport, xyPoints: Point3d[], transform?: Transform, zLow?: number, zHigh?: number): boolean;
static doClipToRange(viewport: Viewport, range: Range3d, transform?: Transform): boolean;
static doClipClear(viewport: Viewport): boolean;
/** @internal */
static getClipRayTransformed(origin: Point3d, direction: Vector3d, transform?: Transform): Ray3d;
/** @internal */
static getOffsetValueTransformed(offset: number, transform?: Transform): number;
/** @internal */
static addClipPlanesLoops(builder: GraphicBuilder, loops: GeometryQuery[], outline: boolean): void;
/** @internal */
private static addClipShape;
/** @internal */
static drawClip(context: DecorateContext, clip: ClipVector, viewExtents?: Range3d, options?: DrawClipOptions): void;
private static isHilited;
private static isFlashed;
static drawClipShape(context: DecorateContext, shape: ClipShape, extents: Range1d, color: ColorDef, weight: number, id?: string): void;
/** @internal */
static getClipShapePoints(shape: ClipShape, z: number): Point3d[];
/** @internal */
static getClipShapeExtents(shape: ClipShape, viewRange: Range3d): Range1d;
/** @internal */
static isSingleClipShape(clip: ClipVector): ClipShape | undefined;
static drawClipPlanesLoops(context: DecorateContext, loops: GeometryQuery[], color: ColorDef, weight: number, dashed?: boolean, fill?: ColorDef, id?: string): void;
/** @internal */
static isSingleConvexClipPlaneSet(clip: ClipVector): ConvexClipPlaneSet | undefined;
/** @internal */
static isSingleClipPlane(clip: ClipVector): ClipPlane | undefined;
static areClipsEqual(clipA: ClipVector, clipB: ClipVector): boolean;
static hasClip(viewport: Viewport): boolean;
}
/** A tool to remove a clip volume for a view
* @public @extensions
*/
export declare class ViewClipClearTool extends ViewClipTool {
static toolId: string;
static iconSpec: string;
/** @internal */
isCompatibleViewport(vp: Viewport | undefined, isSelectedViewChange: boolean): boolean;
/** @internal */
protected showPrompt(): void;
protected doClipClear(viewport: Viewport): Promise<boolean>;
/** @internal */
onPostInstall(): Promise<void>;
/** @internal */
onDataButtonDown(_ev: BeButtonEvent): Promise<EventHandled>;
}
/** A tool to define a clip volume for a view by specifying a plane
* @public
*/
export declare class ViewClipByPlaneTool extends ViewClipTool {
protected _clearExistingPlanes: boolean;
static toolId: string;
static iconSpec: string;
/** @internal */
private _orientationValue;
constructor(clipEventHandler?: ViewClipEventHandler, _clearExistingPlanes?: boolean);
/** @internal */
get orientation(): ContextRotationId;
set orientation(option: ContextRotationId);
/** @internal */
supplyToolSettingsProperties(): DialogItem[] | undefined;
/** @internal */
applyToolSettingPropertyChange(updatedValue: DialogPropertySyncItem): Promise<boolean>;
/** @internal */
protected showPrompt(): void;
/** @internal */
protected setupAndPromptForNextAction(): void;
/** @internal */
onDataButtonDown(ev: BeButtonEvent): Promise<EventHandled>;
}
/** A tool to define a clip volume for a view by specifying a shape
* @public
*/
export declare class ViewClipByShapeTool extends ViewClipTool {
static toolId: string;
static iconSpec: string;
/** @internal */
private _orientationValue;
/** @internal */
protected readonly _points: Point3d[];
/** @internal */
protected _matrix?: Matrix3d;
/** @internal */
protected _zLow?: number;
/** @internal */
protected _zHigh?: number;
/** @internal */
get orientation(): ContextRotationId;
set orientation(option: ContextRotationId);
/** @internal */
supplyToolSettingsProperties(): DialogItem[] | undefined;
/** @internal */
applyToolSettingPropertyChange(updatedValue: DialogPropertySyncItem): Promise<boolean>;
/** @internal */
protected showPrompt(): void;
/** @internal */
protected setupAndPromptForNextAction(): void;
protected getClipPoints(ev: BeButtonEvent): Point3d[];
/** @internal */
isValidLocation(ev: BeButtonEvent, isButtonEvent: boolean): boolean;
/** @internal */
decorate(context: DecorateContext): void;
/** @internal */
onMouseMotion(ev: BeButtonEvent): Promise<void>;
/** @internal */
onDataButtonDown(ev: BeButtonEvent): Promise<EventHandled>;
/** @internal */
onUndoPreviousStep(): Promise<boolean>;
}
/** A tool to define a clip volume for a view by specifying range corners
* @public
*/
export declare class ViewClipByRangeTool extends ViewClipTool {
static toolId: string;
static iconSpec: string;
/** @internal */
protected _corner?: Point3d;
/** @internal */
protected showPrompt(): void;
/** @internal */
protected setupAndPromptForNextAction(): void;
protected getClipRange(range: Range3d, transform: Transform, ev: BeButtonEvent): boolean;
/** @internal */
decorate(context: DecorateContext): void;
/** @internal */
onMouseMotion(ev: BeButtonEvent): Promise<void>;
/** @internal */
onDataButtonDown(ev: BeButtonEvent): Promise<EventHandled>;
/** @internal */
onUndoPreviousStep(): Promise<boolean>;
}
/** A tool to define a clip volume for a view using the element aligned box or axis aligned box.
* @public
*/
export declare class ViewClipByElementTool extends ViewClipTool {
protected _alwaysUseRange: boolean;
static toolId: string;
static iconSpec: string;
constructor(clipEventHandler?: ViewClipEventHandler, _alwaysUseRange?: boolean);
/** @internal */
protected showPrompt(): void;
/** @internal */
onPostInstall(): Promise<void>;
/** @internal */
doClipToSelectedElements(viewport: Viewport): Promise<boolean>;
protected doClipToElements(viewport: Viewport, ids: Id64Arg, alwaysUseRange?: boolean, modelId?: Id64String): Promise<boolean>;
/** @internal */
onDataButtonDown(ev: BeButtonEvent): Promise<EventHandled>;
}
/** @internal Interactive tool base class to modify a view's clip */
export declare abstract class ViewClipModifyTool extends EditManipulator.HandleTool {
protected _anchorIndex: number;
protected _ids: string[];
protected _controls: ViewClipControlArrow[];
protected _clipView: Viewport;
protected _clip: ClipVector;
protected _viewRange: Range3d;
protected _restoreClip: boolean;
protected _currentDistance: number;
private readonly _clipStyle;
constructor(manipulator: EditManipulator.HandleProvider, clip: ClipVector, vp: Viewport, hitId: string, ids: string[], controls: ViewClipControlArrow[]);
protected get wantAccuSnap(): boolean;
protected init(): void;
protected abstract updateViewClip(ev: BeButtonEvent, isAccept: boolean): boolean;
protected abstract drawViewClip(context: DecorateContext): void;
protected getOffsetValue(ev: BeButtonEvent, transformFromClip?: Transform): number | undefined;
protected drawAnchorOffset(context: DecorateContext, color: ColorDef, weight: number, transformFromClip?: Transform): void;
decorate(context: DecorateContext): void;
onMouseMotion(ev: BeButtonEvent): Promise<void>;
protected accept(ev: BeButtonEvent): boolean;
onCleanup(): Promise<void>;
}
/** @internal Interactive tool to modify a view's clip defined by a ClipShape */
export declare class ViewClipShapeModifyTool extends ViewClipModifyTool {
protected updateViewClip(ev: BeButtonEvent, _isAccept: boolean): boolean;
protected drawViewClip(context: DecorateContext): void;
}
/** @internal Interactive tool to modify a view's clip defined by a ConvexClipPlaneSet */
export declare class ViewClipPlanesModifyTool extends ViewClipModifyTool {
protected updateViewClip(ev: BeButtonEvent, _isAccept: boolean): boolean;
protected drawViewClip(context: DecorateContext): void;
}
/** @internal Modify handle data to modify a view's clip */
export declare class ViewClipControlArrow {
origin: Point3d;
direction: Vector3d;
sizeInches: number;
fill?: ColorDef;
outline?: ColorDef;
name?: string;
floatingOrigin?: Point3d;
constructor(origin: Point3d, direction: Vector3d, sizeInches: number, fill?: ColorDef, outline?: ColorDef, name?: string);
}
/** A pickable decoration managed by ViewClipDecorationProvider used to visualize a view's clip and present modification handles.
* This class is public to facilitate customization of view clip events by type or selected controls.
* @see [[ViewClipDecorationProvider]]
* @public
* @extensions
*/
export declare class ViewClipDecoration extends EditManipulator.HandleProvider {
protected _clipView: ScreenViewport;
protected _clipEventHandler?: ViewClipEventHandler | undefined;
private static _decorator?;
/** @internal */
protected _clip?: ClipVector;
/** @internal */
protected _clipId?: string;
/** @internal */
protected _clipShape?: ClipShape;
/** @internal */
protected _clipShapeExtents?: Range1d;
/** @internal */
protected _clipPlanes?: ConvexClipPlaneSet;
/** @internal */
protected _clipPlanesLoops?: GeometryQuery[];
/** @internal */
protected _clipPlanesLoopsNoncontributing?: GeometryQuery[];
/** @internal */
protected _controlIds: string[];
/** @internal */
protected _controls: ViewClipControlArrow[];
/** @internal */
protected _suspendDecorator: boolean;
/** @internal */
protected _removeViewCloseListener?: () => void;
constructor(_clipView: ScreenViewport, _clipEventHandler?: ViewClipEventHandler | undefined);
get clipId(): string | undefined;
get clipShape(): ClipShape | undefined;
get clipPlaneSet(): ConvexClipPlaneSet | undefined;
getControlIndex(id: string): number;
protected stop(): void;
onViewClose(vp: ScreenViewport): void;
private getClipData;
private ensureNumControls;
private createClipShapeControls;
private getLoopCentroidAreaNormal;
private createClipPlanesControls;
protected createControls(): Promise<boolean>;
protected clearControls(): void;
protected modifyControls(hit: HitDetail, _ev: BeButtonEvent): Promise<boolean>;
doClipPlaneNegate(index: number): boolean;
doClipPlaneClear(index: number): boolean;
private getClipShapeFaceLoops;
private getMatchingLoop;
private getLoopPreferredX;
doClipPlaneOrientView(index: number): boolean;
private getWorldUpPlane;
private isAlignedToWorldUpPlane;
isClipShapeAlignedWithWorldUp(extents?: Range1d): boolean;
doClipShapeSetZExtents(extents: Range1d): boolean;
protected onRightClick(hit: HitDetail, ev: BeButtonEvent): Promise<EventHandled>;
protected onTouchTap(hit: HitDetail, ev: BeButtonEvent): Promise<EventHandled>;
onManipulatorEvent(eventType: EditManipulator.EventType): void;
testDecorationHit(id: string): boolean;
getDecorationToolTip(hit: HitDetail): Promise<HTMLElement | string>;
protected updateDecorationListener(_add: boolean): void;
decorate(context: DecorateContext): void;
static get(vp: ScreenViewport): ViewClipDecoration | undefined;
static create(vp: ScreenViewport, clipEventHandler?: ViewClipEventHandler): string | undefined;
static clear(): void;
static toggle(vp: ScreenViewport, clipEventHandler?: ViewClipEventHandler): Promise<string | undefined>;
}
/** Event types for ViewClipDecorationProvider.onActiveClipChanged \
* @public
* @extensions
*/
export declare enum ClipEventType {
New = 0,
NewPlane = 1,
Modify = 2,
Clear = 3
}
/** An implementation of ViewClipEventHandler that responds to new clips by presenting clip modification handles
* @public @extensions
*/
export declare class ViewClipDecorationProvider implements ViewClipEventHandler {
private static _provider?;
selectDecorationOnCreate: boolean;
clearDecorationOnDeselect: boolean;
/** Called when the active clip for a view is changed */
readonly onActiveClipChanged: BeEvent<(viewport: Viewport, eventType: ClipEventType, provider: ViewClipDecorationProvider) => void>;
/** Called on a right click over the clip geometry or clip modify handle. ViewClipDecoration provides methods for the following possible menu actions:
* For ClipPlanes (undefined !== clipPlaneSet): Flip (doClipPlaneNegate), Clear (doClipPlaneClear), and Orient View (doClipPlaneOrientView)
* For ClipShapes (undefined === clipPlaneSet): Orient View (doClipPlaneOrientView) and input fields to set world zLow/zHigh (doClipShapeSetZExtents provided isClipShapeAlignedWithWorldUp returns true)
*/
readonly onActiveClipRightClick: BeEvent<(hit: HitDetail, ev: BeButtonEvent, provider: ViewClipDecorationProvider) => void>;
selectOnCreate(): boolean;
clearOnDeselect(): boolean;
onNewClip(viewport: ScreenViewport): void;
onNewClipPlane(viewport: ScreenViewport): void;
onModifyClip(viewport: ScreenViewport): void;
onClearClip(viewport: ScreenViewport): void;
onRightClick(hit: HitDetail, ev: BeButtonEvent): boolean;
showDecoration(vp: ScreenViewport): void;
hideDecoration(): void;
toggleDecoration(vp: ScreenViewport): Promise<string | undefined>;
isDecorationActive(vp: ScreenViewport): boolean;
static create(): ViewClipDecorationProvider;
static clear(): void;
}
//# sourceMappingURL=ClipViewTool.d.ts.map