![]() |
http://www.sim.no http://www.coin3d.org |
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. More...
#include <Inventor/nodes/SoSelection.h>
Public Types | |
enum | Policy { SINGLE, TOGGLE, SHIFT } |
Public Member Functions | |
virtual SoType | getTypeId (void) const |
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 SoType | getClassTypeId (void) |
static void | initClass (void) |
Public Attributes | |
SoSFEnum | policy |
Protected Member Functions | |
virtual const SoFieldData * | getFieldData (void) const |
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) |
Static Protected Member Functions | |
static const SoFieldData ** | getFieldDataPtr (void) |
Protected Attributes | |
SoPathList | selectionList |
SoCallbackList * | selCBList |
SoCallbackList * | deselCBList |
SoCallbackList * | startCBList |
SoCallbackList * | finishCBList |
SoSelectionPickCB * | pickCBFunc |
void * | pickCBData |
SbBool | callPickCBOnlyIfSelectable |
SoCallbackList * | changeCBList |
SoPath * | mouseDownPickPath |
SbBool | pickMatching |
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\n", 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, "\nThis example program demonstrates the use of the SoSelection node type.\n" ); (void)fprintf( stdout, "\nQuick instructions:\n\n" ); (void)fprintf( stdout, " * pick with left mouse button\n" ); (void)fprintf( stdout, " * hold SHIFT to select multiple objects\n" ); (void)fprintf( stdout, " * hit ESC to toggle back and forth to view mode\n" ); (void)fprintf( stdout, "\n" ); } // ************************************************************************* 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 }
enum SoSelection::Policy |
Enum for different pick policies.
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().
SoType SoSelection::getClassTypeId | ( | void | ) | [static] |
This static method returns the SoType object associated with objects of this class.
Reimplemented from SoSeparator.
Reimplemented in SoExtSelection.
Referenced by SoLineHighlightRenderAction::apply(), and SoBoxHighlightRenderAction::apply().
SoType SoSelection::getTypeId | ( | void | ) | const [virtual] |
Returns the type identification of an object derived from a class inheriting SoBase. This is used for run-time type checking and "downward" casting.
Usage example:
void foo(SoNode * node) { if (node->getTypeId() == SoFile::getClassTypeId()) { SoFile * filenode = (SoFile *)node; // safe downward cast, knows the type } else if (node->getTypeId().isOfType(SoGroup::getClassTypeId())) { SoGroup * group = (SoGroup *)node; // safe downward cast, knows the type } }
For application programmers wanting to extend the library with new nodes, engines, nodekits, draggers or others: this method needs to be overridden in all subclasses. This is typically done as part of setting up the full type system for extension classes, which is usually accomplished by using the pre-defined macros available through for instance Inventor/nodes/SoSubNode.h (SO_NODE_INIT_CLASS and SO_NODE_CONSTRUCTOR for node classes), Inventor/engines/SoSubEngine.h (for engine classes) and so on.
For more information on writing Coin extensions, see the class documentation of the toplevel superclasses for the various class groups.
Reimplemented from SoSeparator.
Reimplemented in SoExtSelection.
Referenced by SoLineHighlightRenderAction::apply(), and SoBoxHighlightRenderAction::apply().
const SoFieldData ** SoSelection::getFieldDataPtr | ( | void | ) | [static, protected] |
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
Reimplemented from SoSeparator.
Reimplemented in SoExtSelection.
const SoFieldData * SoSelection::getFieldData | ( | void | ) | const [protected, virtual] |
Returns a pointer to the class-wide field data storage object for this instance. If no fields are present, returns NULL
.
Reimplemented from SoSeparator.
Reimplemented in SoExtSelection.
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 | ) | const |
Return TRUE if path is in the list of selected objects.
References findPath().
Referenced by isSelected().
SbBool SoSelection::isSelected | ( | SoNode * | node | ) | const |
Return 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 | ) | const |
Returns the number of selected objects.
References SbPList::getLength(), and selectionList.
Referenced by SoLineHighlightRenderAction::apply(), SoBoxHighlightRenderAction::apply(), deselectAll(), and performSingleSelection().
const SoPathList * SoSelection::getList | ( | void | ) | const |
Returns the list of selected objects.
References selectionList.
Referenced by SoLineHighlightRenderAction::apply(), and SoBoxHighlightRenderAction::apply().
SoPath * SoSelection::getPath | ( | const int | index | ) | const |
Returns the index'th selected objects.
References selectionList.
Referenced by performSingleSelection().
SoPath * SoSelection::operator[] | ( | const int | i | ) | const |
Operator 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.
References SoCallbackList::addCallback(), and selCBList.
void SoSelection::removeSelectionCallback | ( | SoSelectionPathCB * | f, | |
void * | userData = NULL | |||
) |
Removes one of the selection callbacks.
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.
References SoCallbackList::addCallback(), and deselCBList.
void SoSelection::removeDeselectionCallback | ( | SoSelectionPathCB * | f, | |
void * | userData = NULL | |||
) |
Removes one of the deselection callbacks.
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.
References SoCallbackList::addCallback(), and startCBList.
void SoSelection::removeStartCallback | ( | SoSelectionClassCB * | f, | |
void * | userData = NULL | |||
) |
Removes f from the list of start callbacks.
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.
References SoCallbackList::addCallback(), and finishCBList.
void SoSelection::removeFinishCallback | ( | SoSelectionClassCB * | f, | |
void * | userData = NULL | |||
) |
Removes f from the list og finish callbacks.
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:
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 | ) | const |
SbBool SoSelection::getPickMatching | ( | void | ) | const |
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 SoSFEnum::getValue(), 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().
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().
Field 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().
Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.
Generated on Mon Feb 23 16:33:58 2009 for Coin by Doxygen. 1.5.8