UNPKG

@itwin/measure-tools-react

Version:
187 lines 9.87 kB
import type { Viewport, ViewState } from "@itwin/core-frontend"; import type { MeasurementViewTargetProps } from "./MeasurementProps.js"; /** Base class for view type classifiers. This returns either a well-known type or an app-defined one that measurements use identify what viewports they are compatible with (e.g. to draw in). */ export declare abstract class MeasurementViewTypeClassifier { /** Gets the type name of the viewport this corresponds to. */ readonly typeName: string; /** Gets whether this viewport type is a spatial view. */ readonly isSpatial: boolean; /** Gets whether this viewport type is a drawing view. */ readonly isDrawing: boolean; /** * Constructs a new MeasurementViewClassifier * @param typeName Name of the view that is used to identify it. * @param isSpatial If the view type is within the AnySpatial hierarchy. * @param isDrawing If the view type is within the AnyDrawing hierarchy. */ constructor(typeName: string, isSpatial: boolean, isDrawing: boolean); /** Classify a viewport. * @param vp Viewport to classify. * @returns True if the viewport corresponds to the class name of this classifier, false if not. */ classifyViewport(vp: Viewport): boolean; /** Classify a view state. * @param vs Viewstate to classify. * @returns True if the viewstate corresponds to the class name of this classifier, false if not. */ abstract classifyView(vs: ViewState): boolean; } /** Generic measurement view classifier that classifies an incoming viewstate by it's class name. */ export declare class ClassNameMeasurementViewTypeClassifier extends MeasurementViewTypeClassifier { readonly className: string; /** * Constructs a new ClassNameMeasurementViewClassifier * @param typeName Name of the view that is used to identify it. * @param isSpatial If the view type is within the AnySpatial hierarchy. * @param isDrawing If the view type is within the AnyDrawing hierarchy. * @param viewClassname The target's viewstate's classname. */ constructor(typeName: string, isSpatial: boolean, isDrawing: boolean, viewClassname: string); /** Classify a view state. * @param vs Viewstate to classify. * @returns True if the viewstate corresponds to the class name of this classifier, false if not. */ classifyView(vs: ViewState): boolean; } /** * Defines what type of viewports the measurement "targets". Each viewport can be classified based on its view state (or some other app-specific context) * and have a type name associated with it, which is used to determine what viewports the measurement will decorate at draw time. A target can include some viewports * and exclude others. In the majority of cases, a measurement will just target one type of viewport but complicated cases are possible, for example if a measurement * can draw different representations of itself in different viewports. */ export declare class MeasurementViewTarget { private static readonly _classifiers; /** list of standard/default view type classifiers * Apps can override this by registering their own classifier against the same name. * Registered classifiers have a higher priority than the default ones. */ private static readonly _defaultClassifiers; private _included; private _excluded; private _viewIds; /** Gets all the view classifiers, with registered classifiers before default classifiers. */ static get classifiers(): MeasurementViewTypeClassifier[]; /** Gets the "primary" view type which is the first included view type. If there is none, then the default is "any". The majority of cases * there will be a single view type, but more complex measurements may have more complicated cases where certain view type should be excluded. */ get primary(): string; /** Gets the view types that a measurement will draw in. */ get included(): ReadonlySet<string>; /** Gets the view types that a measurement will not draw in. */ get excluded(): ReadonlySet<string>; /** Gets the viewIds that the measurement will draw in */ get viewIds(): ReadonlySet<string>; /** * Constructs a new MeasurementViewTarget. * @param included Optional, one or more view type names where the view is valid. If none, then "Any" is the default type meaning any viewport can be valid. * @param excluded Optional, one or more view type names where the view is not valid. * @param viewIds Optional, one or more view ids where the measurement should display. If none, will not consider for display */ constructor(included?: string | string[], excluded?: string | string[], viewIds?: string | string[]); addViewIds(viewIds: string | string[]): void; /** * Adds one or more view types to the include list. * @param type View types. */ include(type: string | string[]): void; /** * Adds one or more view types to the exclude list. * @param type View types. */ exclude(type: string | string[]): void; /** * Adds one or more view types to either the include or exclude list. * @param type View types. * @param isIncluded True if add to the include list, false to the exclude list. */ add(type: string | string[], isIncluded?: boolean): void; /** * Replaces the include or exclude sets with the specified view types. * @param type View types. * @param isIncluded True if to replace the include list, false to replace the exclude list. */ replace(type: string | string[], isIncluded?: boolean): void; /** Clears both include and exclude lists. */ clear(): void; /** Creates a deep copy of the view type object. */ clone(): MeasurementViewTarget; /** Tests if this view target is equal to the other one. Equality means they both have the same number and types of views in their include/exclude sets. */ equals(other: MeasurementViewTarget): boolean; /** * Copies the view classes from the other view type object (completely overwrites). * @param other view type object. */ copyFrom(other: MeasurementViewTarget): void; /** * Cpies the view classes from the other view type object (preserves existing data if possible). * @param other view type object. */ merge(other: MeasurementViewTarget): void; /** * Removes one or more view types from both the include or exclude lists. * @param type View types. */ remove(type: string | string[]): void; /** * Checks if the target is compatible with the specified type, meaning the type is part of the include list and not excluded. If the specified type is of the "Any" special cases, * then included types may be part of that hierarchy if their classifiers are Spatial/Drawing types, so this would return true in that case. * @param type type to check compatibility. Can be the "Any" special cases (e.g. if targets Sheet and you request AnyDrawing, this will return true). */ isOfViewType(type: string): boolean; /** * Checks if the specified viewport is compatible with this view type. * @param vp Viewport to check * @returns true if the viewport is compatible (e.g. can draw in it). */ isViewportCompatible(vp: Viewport): boolean; /** * Invalidates decorations in all appropiate viewports that are compatible with this view type. */ invalidateViewportDecorations(): void; /** * Creates a plain old JSON object with the include/exclude lists. If it is an object with empty arrays, then it allows for "Any" viewport to be compatible. */ toJSON(): MeasurementViewTargetProps; /** * Loads JSON data into the object instance, overwriting previous data. * @param props Props that contain include/exclude lists. */ loadFromJSON(props: MeasurementViewTargetProps): void; /** * Creates a new view type based on incoming props. * @param props Props that contain include/exclude lists. * @returns constructed view type. */ static fromJSON(props: MeasurementViewTargetProps): MeasurementViewTarget; /** * Invalidate decorations for all viewports that are of the specified type. * @param viewType Type of view, can be any WellKnownViewType or app-defined name. */ static invalidateDecorationsForViewType(viewType: string): void; /** * Classifies a viewport. This will never return the special cases of "Any", "AnySpatial", "AnyDrawing", but concrete view type names. * @param vp Viewport to classify. * @returns a type name for the view, either a WellKnown view type or an app-defined one. */ static classifyViewport(vp: Viewport): string; /** * Adds an app-specific view classifier. This overrides any current classifiers that correspond to it's type name. * @param classifier Classifier to add. * @returns A function to drop the classifier * @remarks Multiple classifiers can be registered with the same typeName */ static registerClassifier(classifier: MeasurementViewTypeClassifier): VoidFunction; /** * Removes an app-specific view classifier. * @param classifier Classifier to drop. */ static dropClassifier(classifier: MeasurementViewTypeClassifier): boolean; /** * Finds the first associated view type classifier for the type name. * @param typeName Type name to find the classifier associated. * @returns the associated classifier or undefined if it does not exist. */ static findFirstClassifierForType(typeName: string, includeDefaults?: boolean): MeasurementViewTypeClassifier | undefined; isValidViewId(viewId: string): boolean; } //# sourceMappingURL=MeasurementViewTarget.d.ts.map