SoSelection.3coin2

Langue: en

Version: 373611 (fedora - 01/12/10)

Section: 3 (Bibliothèques de fonctions)

Sommaire

NAME

SoSelection -

The SoSelection class manages a list of selected nodes.

Inserting an SoSelection node in your scene graph enables you to let the user 'pick' with the left mousebutton to select/deselect objects below the SoSelection node.

SYNOPSIS


#include <Inventor/nodes/SoSelection.h>

Inherits SoSeparator.

Inherited by SoExtSelection.

Public Types


enum Policy { SINGLE, TOGGLE, SHIFT }

Public Member Functions


SoSelection (void)

SoSelection (const int nChildren)

void select (const SoPath *path)

void select (SoNode *node)

void deselect (const SoPath *path)

void deselect (const int which)

void deselect (SoNode *node)

void toggle (const SoPath *path)

void toggle (SoNode *node)

SbBool isSelected (const SoPath *path) const

SbBool isSelected (SoNode *node) const

void deselectAll (void)

int getNumSelected (void) const

const SoPathList * getList (void) const

SoPath * getPath (const int index) const

SoPath * operator[] (const int i) const

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

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

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

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

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

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

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

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

void setPickFilterCallback (SoSelectionPickCB *f, void *userData=NULL, const SbBool callOnlyIfSelectable=1)

void setPickMatching (const SbBool pickMatching)

SbBool isPickMatching (void) const

SbBool getPickMatching (void) const

void addChangeCallback (SoSelectionClassCB *f, void *userData=NULL)

void removeChangeCallback (SoSelectionClassCB *f, void *userData=NULL)

Static Public Member Functions


static void initClass (void)

Public Attributes


SoSFEnum policy

Protected Member Functions


virtual ~SoSelection ()

void invokeSelectionPolicy (SoPath *path, SbBool shiftDown)

void performSingleSelection (SoPath *path)

void performToggleSelection (SoPath *path)

SoPath * copyFromThis (const SoPath *path) const

void addPath (SoPath *path)

void removePath (const int which)

int findPath (const SoPath *path) const

virtual void handleEvent (SoHandleEventAction *action)

Protected Attributes


SoPathList selectionList

SoCallbackList * selCBList

SoCallbackList * deselCBList

SoCallbackList * startCBList

SoCallbackList * finishCBList

SoSelectionPickCB * pickCBFunc

void * pickCBData

SbBool callPickCBOnlyIfSelectable

SoCallbackList * changeCBList

SoPath * mouseDownPickPath

SbBool pickMatching

Detailed Description

The SoSelection class manages a list of selected nodes.

Inserting an SoSelection node in your scene graph enables you to let the user 'pick' with the left mousebutton to select/deselect objects below the SoSelection node.

Using an SoBoxHighlightRenderAction or an SoLineHighlightRenderAction to render scenegraphs containing SoSelection nodes provides a convenient way of providing visual feedback about the selections to the application user.

Beware that one common faulty assumption which is made about the node is that the scene will automatically be re-rendered whenever the user pick objects. This is not the case, the application programmer must himself schedule a redraw. A straightforward way to accomplish this is to SoNode::touch() the SoSelection node in the selection / deselection callback.

A 'skeleton' for basic use of SoSelection nodes is given below:

   extern SoSeparator * make_scenegraph( void );
   static SoSelection * selection = NULL;
 
   // Callback function triggered for selection / deselection.
   void made_selection( void * userdata, SoPath * path )
   {
     (void)fprintf( stdout, '%sselected %s,
                    userdata == (void *)1L ? '' : 'de',
                    path->getTail()->getTypeId().getName().getString() );
 
     selection->touch(); // to redraw
   }
 
   // *************************************************************************
 
   // Print a quick instructions notice on stdout.
   void show_instructions( void )
   {
     (void)fprintf( stdout, 'his example program demonstrates the use of the SoSelection node type. );
     (void)fprintf( stdout, 'uick instructions:n' );
     (void)fprintf( stdout, '  * pick with left mouse button );
     (void)fprintf( stdout, '  * hold SHIFT to select multiple objects );
     (void)fprintf( stdout, '  * hit ESC to toggle back and forth to view mode );
     (void)fprintf( stdout, ' );
   }
 
   // *************************************************************************
 
   int main( int argc, char ** argv )
   {
     QWidget * window = SoQt::init( argv[0] );
     show_instructions();
 
     selection = new SoSelection;
     selection->policy = SoSelection::SHIFT;
     selection->ref();
 
     selection->addChild( make_scenegraph() );
     selection->addSelectionCallback( made_selection, (void *)1L );
     selection->addDeselectionCallback( made_selection, (void *)0L );
 
     SoQtExaminerViewer * examinerviewer = new SoQtExaminerViewer( window );
     examinerviewer->setSceneGraph( selection );
     examinerviewer->setGLRenderAction( new SoBoxHighlightRenderAction );
     examinerviewer->setViewing( FALSE );
     examinerviewer->show();
 
     SoQt::show( window );
     SoQt::mainLoop();
 
     delete examinerviewer;
     selection->unref();
 
     return 0;
   }
 

This node is not initialized in SoDB::init(), since it is part of the interaction kit 'add-on'. Before using this node, you should therefore call SoInteraction::init(). If you're using one of the standard GUI-toolkits (SoXt / SoQt / SoWin) SoInteraction::init() will be called for you from the So[Xt|Qt|Win]init() method and you don't have to worry about it.

With regard to using multiple SoSelection nodes at the same time in the same scene graph: this is possible, but it is not straightforward. The standard viewers provided by SoQt, SoWin, et al, will only snoop on one SoSelection node (part of the the legacy API from SGI's InventorXt), so selection changes on the others doesn't trigger redraws. You don't necessarily see what's happening in other words. You'll have to hook up manually and trigger redraws yourself.

Also be aware that when having multiple SoSelection nodes in the scene graph active at the same time, the SoHandleEventAction traversals that you intend for selection-change on one SoSelection node will also affect all the other SoSelection nodes in the scene -- usually delesecting everything below them since you will be clicking outside the selectable objects. You'll therefore also have to manually override that behaviour, if you want selection change on one SoSelection node to not affect the others.

FILE FORMAT/DEFAULTS:

     Selection {
         renderCaching AUTO
         boundingBoxCaching AUTO
         renderCulling AUTO
         pickCulling AUTO
         policy SHIFT
     }
 
 


 

Member Enumeration Documentation

enum SoSelection::PolicyEnum for different pick policies.

Enumerator:

SINGLE
Only one object can be selected at any time. When the user picks a new object, the previous selection will be unselected. If the user picks on nothing, the current selection will be unselected.

Note that if a new selection matches one already present in the selection list, neither a deselect nor a select notification callback will be made about that selection path.

TOGGLE
Picking an object toggles its selection state.
SHIFT
Same as SINGLE, but when shift key is pressed the selection policy will be changed to TOGGLE.

Constructor & Destructor Documentation

SoSelection::SoSelection (void)Default constructor.

SoSelection::SoSelection (const int nChildren)Constructor.

The argument should be the approximate number of children which is expected to be inserted below this node. The number need not be exact, as it is only used as a hint for better memory resource allocation.

SoSelection::~SoSelection () [protected, virtual]Destructor.

References changeCBList, deselCBList, finishCBList, mouseDownPickPath, selCBList, startCBList, and SoBase::unref().

Member Function Documentation

void SoSelection::initClass (void) [static]Sets up initialization for data common to all instances of this class, like submitting necessary information to the Coin type system.

Reimplemented from SoSeparator.

Reimplemented in SoExtSelection.

Referenced by SoInteraction::init().

void SoSelection::select (const SoPath * path)Adds path to the list of selected objects.

References addPath(), copyFromThis(), findPath(), SoBase::ref(), and SoBase::unrefNoDelete().

Referenced by performSingleSelection(), performToggleSelection(), and toggle().

void SoSelection::select (SoNode * node)Adds node to the list of selected objects. The scene graph below the Selection node will be searched, and the path to node will be added if found.

References addPath(), findPath(), and SoBase::unref().

void SoSelection::deselect (const SoPath * path)Remove path from the list of selected objects.

References findPath(), and removePath().

Referenced by deselect().

void SoSelection::deselect (const int which)Remove objects which from the list of selected objects.

References removePath().

void SoSelection::deselect (SoNode * node)Remove node from the list of selected objects. The scene graph below the Selection node will be searched, and the path to node will be removed if found.

References deselect(), and SoBase::unref().

void SoSelection::toggle (const SoPath * path)If path is not already selected, add path to the list of selected objects. Otherwise remove path from the list of selected objects.

References findPath(), removePath(), and select().

Referenced by invokeSelectionPolicy(), and toggle().

void SoSelection::toggle (SoNode * node)If node is not already selected, add path to the list of selected objects. Otherwise remove node from the list of selected objects.

References toggle(), and SoBase::unref().

SbBool SoSelection::isSelected (const SoPath * path) constReturn TRUE if path is in the list of selected objects.

References findPath().

Referenced by isSelected().

SbBool SoSelection::isSelected (SoNode * node) constReturn TRUE if the path to node is in the list of selected objects.

References isSelected(), and SoBase::unref().

void SoSelection::deselectAll (void)Clears the selection list.

References getNumSelected(), and removePath().

int SoSelection::getNumSelected (void) constReturns the number of selected objects.

References SbPList::getLength(), and selectionList.

Referenced by SoLineHighlightRenderAction::apply(), SoBoxHighlightRenderAction::apply(), deselectAll(), and performSingleSelection().

const SoPathList * SoSelection::getList (void) constReturns the list of selected objects.

References selectionList.

Referenced by SoLineHighlightRenderAction::apply(), and SoBoxHighlightRenderAction::apply().

SoPath * SoSelection::getPath (const int index) constReturns the index'th selected objects.

References selectionList.

Referenced by performSingleSelection().

SoPath * SoSelection::operator[] (const int i) constOperator for accessing selected objects.

References selectionList.

void SoSelection::addSelectionCallback (SoSelectionPathCB * f, void * userData = NULL)Adds a callback which will be called every time an object is selected.

See also:

removeSelectionCallback()

References SoCallbackList::addCallback(), and selCBList.

void SoSelection::removeSelectionCallback (SoSelectionPathCB * f, void * userData = NULL)Removes one of the selection callbacks.

See also:

addSelectionCallback()

References SoCallbackList::removeCallback(), and selCBList.

void SoSelection::addDeselectionCallback (SoSelectionPathCB * f, void * userData = NULL)Adds a callback which will be called every time an object is deselected.

See also:

removeDeselectionCallback()

References SoCallbackList::addCallback(), and deselCBList.

void SoSelection::removeDeselectionCallback (SoSelectionPathCB * f, void * userData = NULL)Removes one of the deselection callbacks.

See also:

addDeselctionCallback()

References deselCBList, and SoCallbackList::removeCallback().

void SoSelection::addStartCallback (SoSelectionClassCB * f, void * userData = NULL)Adds a callback which will be invoked when the user start an interactive change to the list of selected objects.

This callback is useful for storing the old selection list for undo/redo functionality.

See also:

addFinishCallback()

References SoCallbackList::addCallback(), and startCBList.

void SoSelection::removeStartCallback (SoSelectionClassCB * f, void * userData = NULL)Removes f from the list of start callbacks.

See also:

addStartCallback()

References SoCallbackList::removeCallback(), and startCBList.

void SoSelection::addFinishCallback (SoSelectionClassCB * f, void * userData = NULL)Adds a callback which will be invoked when the user has finished an interactive change to the list of selected objects.

See also:

addStartCallback()

References SoCallbackList::addCallback(), and finishCBList.

void SoSelection::removeFinishCallback (SoSelectionClassCB * f, void * userData = NULL)Removes f from the list og finish callbacks.

See also:

addFinishCallback()

References finishCBList, and SoCallbackList::removeCallback().

void SoSelection::setPickFilterCallback (SoSelectionPickCB * f, void * userData = NULL, const SbBool callOnlyIfSelectable = 1)Sets the pick filter callback. This callback will be called when a path is about to be added to or removed from the list of selected objects. The callback function should return a replacement path that should be used instead of the picked path. The returned path will be ref'ed, copied, and then unref'ed again by the SoSelection node.

If no callback is set (the default), the picked path will be used for selecting/deselecting.

Possible return values from the callback:

*
NULL: simulate that nothing was picked. This will clear the selection for the SINGLE policy. The handle event action will be halted.
*
A path: the path will be selected/deselected. The handle event action will be halted.
*
A path containing only the Selection node: as NULL, but action will not be halted.
*
An empty path or a path not containing the Selection node: the pick will be ignored.

if callOnlyIfSelectable is TRUE, the callback will only be called if the Selection node is in the picked path.

References callPickCBOnlyIfSelectable, pickCBData, and pickCBFunc.

void SoSelection::setPickMatching (const SbBool pickmatchflag)When pickmatchflag is TRUE (the default), the mouse button release pick must match the mouse button press pick before object is selected/deselected.

This flag should normally not be of interest to application programmers.

References pickMatching.

SbBool SoSelection::isPickMatching (void) constReturns TRUE if pick matching is enabled.

See also:

setPickMatching()

References pickMatching.

SbBool SoSelection::getPickMatching (void) constReturns TRUE if pick matching is enabled.

See also:

setPickMatching()

References pickMatching.

void SoSelection::addChangeCallback (SoSelectionClassCB * f, void * userData = NULL)This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Used by render area to receive notification when the selection list changes.

References SoCallbackList::addCallback(), and changeCBList.

void SoSelection::removeChangeCallback (SoSelectionClassCB * f, void * userData = NULL)This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Used by render area to receive notification when the selection list changes.

References changeCBList, and SoCallbackList::removeCallback().

void SoSelection::invokeSelectionPolicy (SoPath * path, SbBool shiftdown) [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

References performSingleSelection(), performToggleSelection(), policy, SHIFT, TOGGLE, and toggle().

Referenced by handleEvent().

void SoSelection::performSingleSelection (SoPath * path) [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

References copyFromThis(), getNumSelected(), getPath(), SoBase::ref(), removePath(), select(), and SoBase::unref().

Referenced by invokeSelectionPolicy().

void SoSelection::performToggleSelection (SoPath * path) [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

References SoPath::findNode(), findPath(), removePath(), and select().

Referenced by invokeSelectionPolicy().

SoPath * SoSelection::copyFromThis (const SoPath * path) const [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

References SoPath::copy(), SoPath::findNode(), SoBase::ref(), and SoBase::unrefNoDelete().

Referenced by findPath(), performSingleSelection(), and select().

void SoSelection::addPath (SoPath * path) [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

References SoPathList::append(), changeCBList, SoCallbackList::invokeCallbacks(), selCBList, and selectionList.

Referenced by select().

void SoSelection::removePath (const int which) [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

References changeCBList, deselCBList, SoCallbackList::invokeCallbacks(), SoBase::ref(), SoBaseList::remove(), selectionList, and SoBase::unref().

Referenced by deselect(), deselectAll(), performSingleSelection(), performToggleSelection(), and toggle().

int SoSelection::findPath (const SoPath * path) const [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

References copyFromThis(), SoPathList::findPath(), SoPath::getHead(), SoBase::ref(), selectionList, and SoBase::unref().

Referenced by deselect(), isSelected(), performToggleSelection(), select(), and toggle().

void SoSelection::handleEvent (SoHandleEventAction * action) [protected, virtual]Action method for SoHandleEventAction.

Inspects the event data from action, and processes it if it is something which this node should react to.

Nodes influencing relevant state variables for how event handling is done also overrides this method.

Reimplemented from SoSeparator.

Reimplemented in SoExtSelection.

References callPickCBOnlyIfSelectable, SoPath::findNode(), finishCBList, SoHandleEventAction::getEvent(), SoPickedPoint::getPath(), SoHandleEventAction::getPickedPoint(), SoSeparator::handleEvent(), SoCallbackList::invokeCallbacks(), invokeSelectionPolicy(), SoHandleEventAction::isHandled(), mouseDownPickPath, pickCBData, pickCBFunc, SoBase::ref(), SoHandleEventAction::setHandled(), startCBList, and SoBase::unref().

Referenced by SoExtSelection::handleEvent().

Member Data Documentation

SoSFEnum SoSelection::policyField for selection policy. Default value is SHIFT.

Referenced by invokeSelectionPolicy().

SoPathList SoSelection::selectionList [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by addPath(), findPath(), getList(), getNumSelected(), getPath(), operator[](), and removePath().

SoCallbackList * SoSelection::selCBList [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by addPath(), addSelectionCallback(), removeSelectionCallback(), and ~SoSelection().

SoCallbackList * SoSelection::deselCBList [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by addDeselectionCallback(), removeDeselectionCallback(), removePath(), and ~SoSelection().

SoCallbackList * SoSelection::startCBList [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by addStartCallback(), handleEvent(), removeStartCallback(), and ~SoSelection().

SoCallbackList * SoSelection::finishCBList [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by addFinishCallback(), handleEvent(), removeFinishCallback(), and ~SoSelection().

SoSelectionPickCB * SoSelection::pickCBFunc [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by handleEvent(), and setPickFilterCallback().

void * SoSelection::pickCBData [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by handleEvent(), and setPickFilterCallback().

SbBool SoSelection::callPickCBOnlyIfSelectable [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by handleEvent(), and setPickFilterCallback().

SoCallbackList * SoSelection::changeCBList [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by addChangeCallback(), addPath(), removeChangeCallback(), removePath(), and ~SoSelection().

SoPath * SoSelection::mouseDownPickPath [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by handleEvent(), and ~SoSelection().

SbBool SoSelection::pickMatching [protected]This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Referenced by getPickMatching(), isPickMatching(), and setPickMatching().

Author

Generated automatically by Doxygen for Coin from the source code.