Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoSelection Class Reference

Manages a list of selected objects. More...

#include <Inventor/nodes/SoSelection.h>

+ Inheritance diagram for SoSelection:

Public Types

enum  Policy {
  SINGLE ,
  TOGGLE ,
  SHIFT ,
  DISABLE
}
 
typedef void SoSelectionPathCB(void *userData, SoPath *path)
 
typedef void SoSelectionClassCB(void *userData, SoSelection *sel)
 
typedef SoPathSoSelectionPickCB(void *userData, const SoPickedPoint *pick)
 
- Public Types inherited from SoSeparator
enum  CacheEnabled {
  OFF ,
  ON ,
  AUTO
}
 Possible values for caching. More...
 
enum  FastEditing {
  DISABLE = 0x01 ,
  KEEP_ZBUFFER = 0x02 ,
  CLEAR_ZBUFFER = 0x03
}
 Fast editing policy enumeration values. More...
 

Public Member Functions

virtual SoType getTypeId () const
 Returns the type identifier for this specific instance.
 
 SoSelection ()
 Creates a selection node with the default settings.
 
 SoSelection (int nChildren)
 Constructor that specifies the approximate number of children.
 
void select (const SoPath *path)
 Selects the passed path by adding it to the selection list.
 
void select (SoNode *node)
 Selects the passed node by creating a path to it, and adding the path to the selection list by calling select(path) .
 
void deselect (const SoPath *path)
 Deselects the passed path by removing it from the selection list.
 
void deselect (int which)
 Deselects a path by removing it from the selection list.
 
void deselect (SoNode *node)
 Deselects the passed node by creating a path to it, and removing the node from the selection list by calling deselect(path) .
 
void toggle (const SoPath *path)
 Toggles the selection status of the passed path - if the path is in the selection list, it is removed; if not in the list, it is added.
 
void toggle (SoNode *node)
 Toggles the selection status of the passed node by creating a path to it, then calling toggle(path) .
 
SbBool isSelected (const SoPath *path) const
 Returns TRUE if the passed path is selected, that is, if it is in the selection list.
 
SbBool isSelected (SoNode *node) const
 Returns TRUE if the passed node is selected by creating a path to it, then calling isSelected().
 
SbBool isSelected (const SoNode *node) const
 Returns TRUE if the passed node is selected by creating a path to it, then calling isSelected().
 
void deselectAll ()
 Deselects all paths in the selection list, that is, clear the list.
 
int getNumSelected () const
 Returns the number of paths in the selection list.
 
const SoPathListgetList () const
 Returns the list of selected paths.
 
SoPathgetPath (int index) const
 Returns the ith path in the selection list.
 
SoPathoperator[] (int i) const
 Returns the ith path in the selection list.
 
void setPickRadius (float radiusInPixels)
 Sets the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking.
 
float getPickRadius () const
 Returns the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking.
 
void addSelectionCallback (SoSelectionPathCB *f, void *userData=NULL)
 Adds selection callback.
 
void removeSelectionCallback (SoSelectionPathCB *f, void *userData=NULL)
 Removes selection callback.
 
void addDeselectionCallback (SoSelectionPathCB *f, void *userData=NULL)
 Adds deselection callback.
 
void removeDeselectionCallback (SoSelectionPathCB *f, void *userData=NULL)
 Removes deselection callback.
 
void addStartCallback (SoSelectionClassCB *f, void *userData=NULL)
 Adds start callback.
 
void removeStartCallback (SoSelectionClassCB *f, void *userData=NULL)
 Removes start callback.
 
void addFinishCallback (SoSelectionClassCB *f, void *userData=NULL)
 Adds finish callback.
 
void removeFinishCallback (SoSelectionClassCB *f, void *userData=NULL)
 Removes finish callback.
 
void setPickFilterCallback (SoSelectionPickCB *f, void *userData=NULL, SbBool callOnlyIfSelectable=TRUE)
 The pick filter callback is invoked when a pick has occurred and the selection node is about to change the selection list.
 
void setPickMatching (SbBool pickTwice)
 SoSelection will pick once on mouse down and once on mouse up, and make sure the picks match before changing the selection list.
 
SbBool isPickMatching () const
 Returns pick matching flag.
 
- Public Member Functions inherited from SoSeparator
 SoSeparator ()
 Creates a separator node with default settings.
 
 SoSeparator (int nChildren)
 Constructor that takes approximate number of children.
 
- Public Member Functions inherited from SoGroup
 SoGroup ()
 Creates an empty group node.
 
 SoGroup (int nChildren)
 Constructor that takes approximate number of children.
 
virtual void addChild (SoNode *child)
 Adds a child as last one in group.
 
virtual void insertChild (SoNode *child, int newChildIndex)
 Adds a child so that it becomes the one with the given index.
 
virtual SoNodegetChild (int index) const
 Returns pointer the child node with the given index.
 
virtual int findChild (const SoNode *child) const
 Finds index of given child within group.
 
virtual int getNumChildren () const
 Returns number of children.
 
virtual void removeChild (int index)
 Removes child with given index from group.
 
virtual void removeChild (SoNode *child)
 Removes first instance of given child from group.
 
virtual void removeAllChildren ()
 Removes all children from group.
 
virtual void replaceChild (int index, SoNode *newChild)
 Replaces child with given index with new child.
 
virtual void replaceChild (SoNode *oldChild, SoNode *newChild)
 Replaces first instance of given child with new child.
 
- Public Member Functions inherited from SoNode
virtual void setOverride (const SbBool state)
 Turns the override flag on or off.
 
virtual SbBool isOverride () const
 Returns the state of the override flag.
 
virtual SoNodecopy (SbBool copyConnections=FALSE) const
 Creates and returns an exact copy of the node.
 
virtual void touch ()
 Marks an instance as modified, simulating a change to it.
 
- Public Member Functions inherited from SoFieldContainer
void setToDefaults ()
 Sets all fields in this object to their default values.
 
SbBool hasDefaultValues () const
 Returns TRUE if all of the object's fields have their default values.
 
SbBool fieldsAreEqual (const SoFieldContainer *fc) const
 Returns TRUE if this object's fields are exactly equal to fc's fields.
 
void copyFieldValues (const SoFieldContainer *fc, SbBool copyConnections=FALSE)
 Copies the contents of fc's fields into this object's fields.
 
SoNONUNICODE SbBool set (const char *fieldDataString)
 Sets one or more fields in this object to the values specified in the given string, which should be a string in the Open Inventor file format.
 
SbBool set (const SbString &fieldDataString)
 Sets one or more fields in this object to the values specified in the given string, which should be a string in the Open Inventor file format.
 
void get (SbString &fieldDataString)
 Returns the values of the fields of this object in the Open Inventor ASCII file format in the given string.
 
virtual int getFields (SoFieldList &list) const
 Appends references to all of this object's fields to resultList, and returns the number of fields appended.
 
virtual int getAllFields (SoFieldList &list) const
 Returns a list of fields, including the eventIn's and eventOut's.
 
virtual SoFieldgetField (const SbName &fieldName) const
 Returns a the field of this object whose name is fieldName.
 
virtual SoFieldgetEventIn (const SbName &fieldName) const
 Returns a the eventIn with the given name.
 
virtual SoFieldgetEventOut (const SbName &fieldName) const
 Returns the eventOut with the given name.
 
SbBool getFieldName (const SoField *field, SbName &fieldName) const
 Returns the name of the given field in the fieldName argument.
 
SbBool enableNotify (SbBool flag)
 Notification at this Field Container is enabled (if flag == TRUE) or disabled (if flag == FALSE).
 
SbBool isNotifyEnabled () const
 Notification is the process of telling interested objects that this object has changed.
 
virtual void setUserData (void *data)
 Sets application data.
 
void * getUserData (void) const
 Gets user application data.
 
- Public Member Functions inherited from SoBase
virtual SbName getName () const
 Returns the name of an instance.
 
virtual void setName (const SbName &name)
 Sets the name of an instance.
 
void setSynchronizable (const bool b)
 Sets this to be a ScaleViz synchronizable object.
 
bool isSynchronizable () const
 Gets the ScaleViz synchronizable state of this object.
 
- Public Member Functions inherited from SoRefCounter
void ref () const
 Adds a reference to an instance.
 
void unref () const
 Removes a reference from an instance.
 
void unrefNoDelete () const
 unrefNoDelete() should be called when it is desired to decrement the reference count, but not delete the instance if this brings the reference count to zero.
 
int getRefCount () const
 Returns current reference count.
 
void lock () const
 lock this instance.
 
void unlock () const
 unlock this instance.
 
- Public Member Functions inherited from SoTypedObject
SbBool isOfType (const SoType &type) const
 Returns TRUE if this object is of the type specified in type or is derived from that type.
 
template<typename TypedObjectClass >
SbBool isOfType () const
 Returns TRUE if this object is of the type of class TypedObjectClass or is derived from that class.
 

Static Public Member Functions

static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
- Static Public Member Functions inherited from SoSeparator
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
- Static Public Member Functions inherited from SoGroup
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
- Static Public Member Functions inherited from SoNode
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
static SoNodegetByName (const SbName &name)
 A node's name can be set using SoBase::setName().
 
static int getByName (const SbName &name, SoNodeList &list)
 A node's name can be set using SoBase::setName().
 
- Static Public Member Functions inherited from SoFieldContainer
static SoType getClassTypeId ()
 Returns the type of this class.
 
- Static Public Member Functions inherited from SoBase
static SoType getClassTypeId ()
 Returns type identifier for this class.
 
- Static Public Member Functions inherited from SoTypedObject
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 

Public Attributes

SoSFEnum policy
 Selection policy that is followed in response to user interaction.
 
- Public Attributes inherited from SoSeparator
SoSFEnum boundingBoxCaching
 Whether to cache during bounding box traversal.
 
SoSFEnum renderCulling
 Whether to cull during rendering traversal.
 
SoSFEnum pickCulling
 Whether to cull during picking traversal.
 
SoSFEnum fastEditing
 Specifies the fast edit mode of the separator node.
 
SoSFInt32 renderUnitId
 Used during the ScaleViz depth compositing process, this field specifies which render unit (OIRU) will render the sub scene graph below this separator.
 
SoDEPRECATED SoSFEnum renderCaching
 Whether to cache during rendering traversal.
 
- Public Attributes inherited from SoGroup
SoSFBool boundingBoxIgnoring
 Whether to ignore this node during bounding box traversal.
 

Additional Inherited Members

Detailed Description

Manages a list of selected objects.

SoSelection defines a node which can be inserted into a scene graph and will generate and manage a selection list from picks on any node in the subgraph below it. Nodes are selected based on a current selection policy. Callbacks report back to the application when a path has been selected or deselected. The selection list can also be managed programmatically.

SoSelection is convenient when the application just needs to know the path (SoPath) to the objects that were selected (or deselected). SoSelection automatically does picking (applies an SoRayPickAction), but it does not provide information about the picked point or pick details. For that see SoRayPickAction, SoEventCallback and SoDetail. SoSelection does picking based on a single coordinate (the cursor position). The SoExtSelection node can do selection based on a lasso or rectangle drawn on the screen.

The selection callbacks are invoked every time an object is selected, whether from user interaction or from a method call. The callbacks are invoked after the object has been added to the selection list.

When handling events, by default SoSelection makes sure that the mouse release event was over the same object as the mouse press event before changing the list of selected objects. This allows users to mouse down on an object, change their mind and move the cursor off the object, then release the mouse button without altering the selection. See the setPickMatching method.

The selection can be highlighted automatically by replacing the render area's render action with one of the specialized highlighting render actions, for example SoHaloHighlightRenderAction. See the code example below. The application can also create a custom highlight action. See the chapter "Creating a Selection Highlight Style" in the Inventor Toolmaker Volume 1.

It is possible to use multiple SoSelection nodes in a scene graph, but there are a few things to keep in mind:

  • If two selection nodes could potentially select the same geometry, the geometry will be selected by the selection node lowest in the scene graph (the closest ancestor of the geometry).
  • The automatic viewer redraw on selection change (renderArea's redrawOnSelectionChange method) feature currently only works for a single selection node. You can work around this by calling renderArea's scheduleRedraw() method in a selection callback .
  • The box and line highlighting render actions currently search for the first selection node in the scene graph and only highlight geometry selected by that selection node. You can work around this by creating a custom highlight action.

Instancing:
When instance nodes of a SoMultipleInstance or a SoMultipleCopy group
are selected, the application can get the instance identifier using the SoPath method getInstanceIndex().

Hidden references:

SoSelection creates an SoPath when an object is added to the selection list. The SoPath calls ref() on each node in the path, including the SoSelection node. This reference will prevent those nodes, including the SoSelection, from being destroyed for as long as the SoPath exists. The SoPath exists until the object is deselected or the selection list is cleared. In general, the deselectAll() method should be called when the SoSelection is no longer needed.

EXAMPLE

FILE FORMAT/DEFAULT

    Selection {
    boundingBoxCaching AUTO
    renderCulling AUTO
    pickCulling AUTO
    policy SHIFT
    fastEditing DISABLE
    }

SEE ALSO

SoEventCallback, SoWinRenderArea, SoBoxHighlightRenderAction, SoHaloHighlightRenderAction, SoColorHighlightRenderAction, SoLineHighlightRenderAction, SoHighlightRenderAction, SoLineHighlightRenderAction

Definition at line 309 of file SoSelection.h.

Member Typedef Documentation

◆ SoSelectionClassCB

typedef void SoSelectionClassCB(void *userData, SoSelection *sel)

Definition at line 84 of file SoSelection.h.

◆ SoSelectionPathCB

typedef void SoSelectionPathCB(void *userData, SoPath *path)

Definition at line 78 of file SoSelection.h.

◆ SoSelectionPickCB

typedef SoPath * SoSelectionPickCB(void *userData, const SoPickedPoint *pick)

Definition at line 90 of file SoSelection.h.

Member Enumeration Documentation

◆ Policy

Enumerator
SINGLE 

Picking an object object clears current selection, then selects object.

Picking on nothing clears current selection. Only one object may be selected at a time.

TOGGLE 

Picking an object toggles its selection status.

Picking on nothing does nothing. Multiple objects may be selected.

SHIFT 

When shift key is down, selection policy is TOGGLE.

When shift key is up, selection policy is SINGLE. Multiple objects may be selected.

DISABLE 

Disable selection (behave like a normal SoSeparator).

Definition at line 329 of file SoSelection.h.

Constructor & Destructor Documentation

◆ SoSelection() [1/2]

SoSelection::SoSelection ( )

Creates a selection node with the default settings.

◆ SoSelection() [2/2]

SoSelection::SoSelection ( int  nChildren)

Constructor that specifies the approximate number of children.

Member Function Documentation

◆ addDeselectionCallback()

void SoSelection::addDeselectionCallback ( SoSelectionPathCB f,
void *  userData = NULL 
)

Adds deselection callback.

The deselection callbacks are invoked every time an object is deselected, whether it be from user interaction or from method call. This is invoked after the object has been removed from the selection list.

◆ addFinishCallback()

void SoSelection::addFinishCallback ( SoSelectionClassCB f,
void *  userData = NULL 
)

Adds finish callback.

The finish callbacks are invoked when the user has finished interactively changing the selection list (by picking objects). This was preceded by an invocation of each start callback, and invocations of the select and/or deselect callbacks. The finish callbacks are not called when the selection list is changed programmatically.

◆ addSelectionCallback()

void SoSelection::addSelectionCallback ( SoSelectionPathCB f,
void *  userData = NULL 
)

Adds selection callback.

The selection callbacks are invoked every time an object is selected, whether it be from user interaction or from method call. The callbacks are invoked after the object has been added to the selection list.

◆ addStartCallback()

void SoSelection::addStartCallback ( SoSelectionClassCB f,
void *  userData = NULL 
)

Adds start callback.

The start callbacks are invoked when the user has initiated an interactive change to the selection list (by picking objects). This will be followed by invocations of the select and/or deselect callbacks, finally followed by each finish callback. A start callback can be used, for instance, to save the current selection for later restoration (e.g. undo/redo). The start callbacks are not called when the selection list is changed programmatically.

◆ deselect() [1/3]

void SoSelection::deselect ( const SoPath path)

Deselects the passed path by removing it from the selection list.

◆ deselect() [2/3]

void SoSelection::deselect ( int  which)

Deselects a path by removing it from the selection list.

The argument which specifies which path in the list to be removed.

◆ deselect() [3/3]

void SoSelection::deselect ( SoNode node)

Deselects the passed node by creating a path to it, and removing the node from the selection list by calling deselect(path) .

If there is more than one instance of node beneath the selection node, the created path will be the first instance found.

◆ deselectAll()

void SoSelection::deselectAll ( )

Deselects all paths in the selection list, that is, clear the list.

◆ getClassTypeId()

static SoType SoSelection::getClassTypeId ( )
static

Returns the type identifier for this class.


◆ getList()

const SoPathList * SoSelection::getList ( ) const

Returns the list of selected paths.

◆ getNumSelected()

int SoSelection::getNumSelected ( ) const

Returns the number of paths in the selection list.

◆ getPath()

SoPath * SoSelection::getPath ( int  index) const

Returns the ith path in the selection list.

◆ getPickRadius()

float SoSelection::getPickRadius ( ) const

Returns the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking.

◆ getTypeId()

virtual SoType SoSelection::getTypeId ( ) const
virtual

Returns the type identifier for this specific instance.

Reimplemented from SoSeparator.

Reimplemented in SoExtSelection.

◆ isPickMatching()

SbBool SoSelection::isPickMatching ( ) const

Returns pick matching flag.

◆ isSelected() [1/3]

SbBool SoSelection::isSelected ( const SoNode node) const

Returns TRUE if the passed node is selected by creating a path to it, then calling isSelected().

If there is more than one instance of node beneath the selection node, the created path will be the first instance found.

◆ isSelected() [2/3]

SbBool SoSelection::isSelected ( const SoPath path) const

Returns TRUE if the passed path is selected, that is, if it is in the selection list.

◆ isSelected() [3/3]

SbBool SoSelection::isSelected ( SoNode node) const

Returns TRUE if the passed node is selected by creating a path to it, then calling isSelected().

If there is more than one instance of node beneath the selection node, the created path will be the first instance found.

◆ operator[]()

SoPath * SoSelection::operator[] ( int  i) const
inline

Returns the ith path in the selection list.

Definition at line 452 of file SoSelection.h.

◆ removeDeselectionCallback()

void SoSelection::removeDeselectionCallback ( SoSelectionPathCB f,
void *  userData = NULL 
)

Removes deselection callback.

The deselection callbacks are invoked every time an object is deselected, whether it be from user interaction or from method call. This is invoked after the object has been removed from the selection list.

◆ removeFinishCallback()

void SoSelection::removeFinishCallback ( SoSelectionClassCB f,
void *  userData = NULL 
)

Removes finish callback.

The finish callbacks are invoked when the user has finished interactively changing the selection list (by picking objects). This was preceded by an invocation of each start callback, and invocations of the select and/or deselect callbacks. The finish callbacks are not called when the selection list is changed programmatically.

◆ removeSelectionCallback()

void SoSelection::removeSelectionCallback ( SoSelectionPathCB f,
void *  userData = NULL 
)

Removes selection callback.

The selection callbacks are invoked every time an object is selected, whether it be from user interaction or from method call. The callbacks are invoked after the object has been added to the selection list.

◆ removeStartCallback()

void SoSelection::removeStartCallback ( SoSelectionClassCB f,
void *  userData = NULL 
)

Removes start callback.

The start callbacks are invoked when the user has initiated an interactive change to the selection list (by picking objects). This will be followed by invocations of the select and/or deselect callbacks, finally followed by each finish callback. A start callback can be used, for instance, to save the current selection for later restoration (e.g. undo/redo). The start callbacks are not called when the selection list is changed programmatically.

◆ select() [1/2]

void SoSelection::select ( const SoPath path)

Selects the passed path by adding it to the selection list.

The selection node must lie in the path. The path is copied and truncated such that the selection node is the head of the path. If the selection node does not lie in the path, the selection list remains unchanged. This method ignores the current selection policy.

◆ select() [2/2]

void SoSelection::select ( SoNode node)

Selects the passed node by creating a path to it, and adding the path to the selection list by calling select(path) .

If there is more than one instance of node beneath the selection node, the created path will be the first instance found.

◆ setPickFilterCallback()

void SoSelection::setPickFilterCallback ( SoSelectionPickCB f,
void *  userData = NULL,
SbBool  callOnlyIfSelectable = TRUE 
)

The pick filter callback is invoked when a pick has occurred and the selection node is about to change the selection list.

The callback function returns the path that the selection node should use when selecting and deselecting. If no pick callback is registered (the default), the selection node will use the path returned by SoPickedPoint::getPath() on the picked point associated with the event being processed. The returned path should not be ref'd - selection will ref() and unref() it. (See SoPath::unrefNoDelete().)

Note that a picked object may or may not be a child of the selection node. A selection node will only select paths that pass through it. Possible return values from the callback:

[a] NULL - selection behaves as if nothing was picked (i.e. for SINGLE and SHIFT policies, this clears the selection list). Handle event action traversal halts.

[b] Path - this path will be selected/deselected according to the selection policy (it must lie under the selection node). Handle event action traversal halts.

[c] Path containing only the selection node - apply the selection policy as if nothing was picked. Handle event action traversal continues.

[d] Path not passing through the selection node - selection ignores this pick event and no change is made to the selection list. Handle event action traversal continues.

A simple way to tell selection to ignore the pick is to return an SoPath with no nodes in it. (i.e. return new SoPath; ) Selection will always ref the path returned by the callback, make a copy of the path, then unref the path.

The callOnlyIfSelectable argument, when set to TRUE, means the pick callback function will only be invoked on picks which pass through the selection node. When FALSE, all picks will be passed to the callback whether they pass through the selection or not.

◆ setPickMatching()

void SoSelection::setPickMatching ( SbBool  pickTwice)

SoSelection will pick once on mouse down and once on mouse up, and make sure the picks match before changing the selection list.

This allows the user to pick down on an object, change their mind and drag off the object, release the mouse button and not affect the selection. Pass TRUE to enable this behavior. Pass FALSE to disable this, meaning whatever is picked on a mouse release is added to/removed from the selection list. Default is pick-matching on.

◆ setPickRadius()

void SoSelection::setPickRadius ( float  radiusInPixels)

Sets the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking.

Ray picking is performed when getPickedPoint() is called. The pick radius set here is only used when testing the ray against lines and points.

◆ toggle() [1/2]

void SoSelection::toggle ( const SoPath path)

Toggles the selection status of the passed path - if the path is in the selection list, it is removed; if not in the list, it is added.

◆ toggle() [2/2]

void SoSelection::toggle ( SoNode node)

Toggles the selection status of the passed node by creating a path to it, then calling toggle(path) .

If there is more than one instance of node beneath the selection node, the created path will be the first instance found.

Member Data Documentation

◆ policy

SoSFEnum SoSelection::policy

Selection policy that is followed in response to user interaction.

Use enum Policy. Default is SHIFT.

Definition at line 361 of file SoSelection.h.


The documentation for this class was generated from the following file: