UNPKG

@itwin/core-frontend

Version:
250 lines • 12.6 kB
/** @packageDocumentation * @module SelectionSet */ import { BeEvent, Id64, Id64Arg, Id64String } from "@itwin/core-bentley"; import { IModelConnection } from "./IModelConnection"; /** Identifies the type of changes made to the [[SelectionSet]] to produce a [[SelectionSetEvent]]. * @public * @extensions */ export declare enum SelectionSetEventType { /** Ids have been added to the set. */ Add = 0, /** Ids have been removed from the set. */ Remove = 1, /** Some ids have been added to the set and others have been removed. */ Replace = 2, /** All ids have been removed from the set. */ Clear = 3 } /** Passed to [[SelectionSet.onChanged]] event listeners when ids are added to the selection set. * @public * @extensions */ export interface SelectAddEvent { type: SelectionSetEventType.Add; /** * The Ids of the elements added to the set. * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use the [[additions]] attribute instead. */ added: Id64Arg; /** A collection of geometric element, model and subcategory ids that have been added to selection set. */ additions: SelectableIds; /** The affected SelectionSet. */ set: SelectionSet; } /** Passed to [[SelectionSet.onChanged]] event listeners when ids are removed from the selection set. * @public * @extensions */ export interface SelectRemoveEvent { /** The type of operation that produced this event. */ type: SelectionSetEventType.Remove | SelectionSetEventType.Clear; /** * The element Ids removed from the set. * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use the [[removals]] attribute instead. */ removed: Id64Arg; /** A collection of geometric element, model and subcategory ids that have been removed from selection set. */ removals: SelectableIds; /** The affected SelectionSet. */ set: SelectionSet; } /** Passed to [[SelectionSet.onChanged]] event listeners when ids are simultaneously added to and removed from the selection set. * @public * @extensions */ export interface SelectReplaceEvent { type: SelectionSetEventType.Replace; /** * The element Ids added to the set. * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use the [[additions]] attribute instead. */ added: Id64Arg; /** A collection of geometric element, model and subcategory ids that have been added to selection set. */ additions: SelectableIds; /** * The element Ids removed from the set. * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use the [[removals]] attribute instead. */ removed: Id64Arg; /** A collection of geometric element, model and subcategory ids that have been removed from selection set. */ removals: SelectableIds; /** The affected SelectionSet. */ set: SelectionSet; } /** Payload sent to [[SelectionSet.onChanged]] event listeners to describe how the contents of the set have changed. * The `type` property of the event serves as a type assertion. For example, the following code will output the added and/or removed Ids: * ```ts * processSelectionSetEvent(ev: SelectionSetEvent): void { * if (SelectionSetEventType.Add === ev.type || SelectionSetEventType.Replace === ev.type) * console.log("Added " + (ev.additions.elements?.size ?? 0) + " elements"); * * if (SelectionSetEventType.Add !== ev.type) * console.log("Removed " + (ev.removals.elements?.size ?? 0) + " elements"); * } * ``` * @public * @extensions */ export type SelectionSetEvent = SelectAddEvent | SelectRemoveEvent | SelectReplaceEvent; /** Describes how the sets of hilited models and subcategories in a [[HiliteSet]] interact. * - "union" indicates a [Feature]($common) will be hilited if either its model **or** its subcategory is present in the HiliteSet. * - "intersection" indicates a [Feature]($common) will be hilited only if both its model **and** its subcategory are present in the HiliteSet. * * @see [[HiliteSet.modelSubCategoryMode]] to change the mode for a HiliteSet. * @public */ export type ModelSubCategoryHiliteMode = "union" | "intersection"; /** A set of *hilited* elements for an [[IModelConnection]], by element id. * Hilited elements are displayed with a customizable hilite effect within a [[Viewport]]. * The set exposes 3 types of elements in 3 separate collections: [GeometricElement]($backend), [GeometricModel]($backend), and [SubCategory]($backend). * The [[models]] and [[subcategories]] can be hilited independently or as an intersection of the two sets, as specified by [[modelSubCategoryMode]]. * * Technically, the hilite effect is applied to [Feature]($common)s, not [Element]($backend)s. An element's geometry stream can contain multiple * features belonging to different subcategories. * * Because Javascript lacks efficient support for 64-bit integers, the Ids are stored as pairs of 32-bit integers via [Id64.Uint32Set]($bentley). * * @note Typically, elements are hilited by virtue of their presence in the IModelConnection's [[SelectionSet]]. The HiliteSet allows additional * elements to be displayed with the hilite effect without adding them to the [[SelectionSet]]. If you add elements to the HiliteSet directly, you * are also responsible for removing them as appropriate. * @see [[IModelConnection.hilited]] for the HiliteSet associated with an iModel. * @see [Hilite.Settings]($common) for customization of the hilite effect. * @public * @extensions */ export declare class HiliteSet { #private; iModel: IModelConnection; /** The set of hilited elements. */ readonly elements: Id64.Uint32Set; /** The set of hilited subcategories. * @see [[modelSubCategoryMode]] to control how this set interacts with the set of hilited [[models]]. * @see [[IModelConnection.Categories]] to obtain the set of subcategories associated with one or more [Category]($backend)'s. */ readonly subcategories: Id64.Uint32Set; /** The set of hilited [[GeometricModelState]]s. * @see [[modelSubCategoryMode]] to control how this set interacts with the set of hilited [[subcategories]]. */ readonly models: Id64.Uint32Set; /** Controls how the sets of hilited [[models]] and [[subcategories]] interact with one another. * By default they are treated as a union: a [Feature]($common) is hilited if either its model **or** its subcategory is hilited. * This can be changed to an intersection such that a [Feature]($common) is hilited only if both its model **and** subcategory are hilited. * @note The sets of hilited models and subcategories are independent of the set of hilited [[elements]] - an element whose Id is present in * [[elements]] is always hilited regardless of its model or subcategories. */ get modelSubCategoryMode(): ModelSubCategoryHiliteMode; set modelSubCategoryMode(mode: ModelSubCategoryHiliteMode); /** Event raised just before changing the value of [[modelSubCategoryMode]]. */ readonly onModelSubCategoryModeChanged: BeEvent<(newMode: ModelSubCategoryHiliteMode) => void>; /** Construct a HiliteSet * @param iModel The iModel containing the entities to be hilited. * @param syncWithSelectionSet If true, the hilite set contents will be synchronized with those in the `iModel`'s [[SelectionSet]]. */ constructor(iModel: IModelConnection, syncWithSelectionSet?: boolean); /** Control whether the hilite set will be synchronized with the contents of the [[SelectionSet]]. * By default they are synchronized. Applications that override this take responsibility for managing the set of hilited entities. * When turning synchronization off, the contents of the HiliteSet will remain unchanged. * When turning synchronization on, the current contents of the HiliteSet will be preserved, and the contents of the selection set will be added to them. */ get wantSyncWithSelectionSet(): boolean; set wantSyncWithSelectionSet(want: boolean); /** Adds a collection of geometric element, model and subcategory ids to this hilite set. */ add(additions: SelectableIds): void; /** Removes a collection of geometric element, model and subcategory ids from this hilite set. */ remove(removals: SelectableIds): void; /** Replaces ids currently in the hilite set with the given collection. */ replace(ids: SelectableIds): void; /** Remove all elements from the hilited set. */ clear(): void; /** Returns true if nothing is hilited. */ get isEmpty(): boolean; /** Toggle the hilited state of one or more elements. * @param arg the ID(s) of the elements whose state is to be toggled. * @param onOff True to add the elements to the hilited set, false to remove them. * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use [[add]], [[remove]], [[replace]] instead. */ setHilite(arg: Id64Arg, onOff: boolean): void; } /** A set of *currently selected* geometric elements, models and subcategories for an `IModelConnection`. * Generally, selected elements are displayed with a customizable hilite effect within a [[Viewport]], see [[HiliteSet]]. * @see [Hilite.Settings]($common) for customization of the hilite effect. * @public * @extensions */ export declare class SelectionSet { #private; iModel: IModelConnection; /** The IDs of the selected elements. * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]]. */ get elements(): Set<Id64String>; /** The IDs of the selected models. * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]]. */ get models(): Set<Id64String>; /** The IDs of the selected subcategories. * @note Do not modify this set directly. Instead, use methods like [[SelectionSet.add]]. */ get subcategories(): Set<Id64String>; /** Get the active selection as a collection of geometric element, model and subcategory ids. * @note Do not modify the sets in returned collection directly. Instead, use methods like [[SelectionSet.add]]. */ get active(): { [P in keyof SelectableIds]-?: Set<Id64String>; }; /** Called whenever ids are added or removed from this `SelectionSet` */ readonly onChanged: BeEvent<(ev: SelectionSetEvent) => void>; constructor(iModel: IModelConnection); /** Get the number of entries in this selection set. */ get size(): number; /** Check whether there are any ids in this selection set. */ get isActive(): boolean; /** Return true if elemId is in this `SelectionSet`. * @see [[isSelected]] * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `SelectionSet.elements.has(elemId)` instead. */ has(elemId?: string): boolean; /** Query whether an Id is in the selection set. * @see [[has]] * @deprecated in 5.0 - will not be removed until after 2026-06-13. Use `SelectionSet.elements.has(elemId)` instead. */ isSelected(elemId?: Id64String): boolean; /** Clear current selection set. * @note raises the [[onChanged]] event with [[SelectionSetEventType.Clear]]. */ emptyAll(): void; /** * Add one or more Ids to the current selection set. * @param elem The set of Ids to add. * @returns true if any elements were added. */ add(adds: Id64Arg | SelectableIds): boolean; /** * Remove one or more Ids from the current selection set. * @param elem The set of Ids to remove. * @returns true if any elements were removed. */ remove(removes: Id64Arg | SelectableIds): boolean; /** * Add one set of Ids, and remove another set of Ids. Any Ids that are in both sets are removed. * @returns True if any Ids were either added or removed. */ addAndRemove(adds: Id64Arg | SelectableIds, removes: Id64Arg | SelectableIds): boolean; /** Invert the state of a set of Ids in the `SelectionSet` */ invert(ids: Id64Arg | SelectableIds): boolean; /** Change selection set to be the supplied set of Ids. */ replace(ids: Id64Arg | SelectableIds): boolean; } /** * A collection of geometric element, model and subcategory ids that can be added to * a [[SelectionSet]] or [[HiliteSet]]. * @public */ export interface SelectableIds { elements?: Id64Arg; models?: Id64Arg; subcategories?: Id64Arg; } //# sourceMappingURL=SelectionSet.d.ts.map