Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SoSearchAction Class Reference

The SoSearchAction class provides methods for searching through scene graphs. More...

#include <Inventor/actions/SoSearchAction.h>

Inheritance diagram for SoSearchAction:
SoAction

Public Types

enum  Interest { FIRST , LAST , ALL }
 
enum  LookFor { NODE = 1 , TYPE = 2 , NAME = 4 }
 
- Public Types inherited from SoAction
enum  AppliedCode { NODE = 0 , PATH = 1 , PATH_LIST = 2 }
 
enum  PathCode { NO_PATH = 0 , IN_PATH = 1 , BELOW_PATH = 2 , OFF_PATH = 3 }
 

Public Member Functions

 SoSearchAction (void)
 
virtual ~SoSearchAction (void)
 
void addPath (SoPath *const path)
 
int getFind (void) const
 
Interest getInterest (void) const
 
SbName getName (void) const
 
SoNodegetNode (void) const
 
SoPathgetPath (void) const
 
SoPathListgetPaths (void)
 
SoType getType (SbBool &chkderived) const
 
virtual SoType getTypeId (void) const
 
SbBool isFound (void) const
 
SbBool isSearchingAll (void) const
 
void reset (void)
 
void setFind (const int what)
 
void setFound (void)
 
void setInterest (const Interest interest)
 
void setName (const SbName name)
 
void setNode (SoNode *const node)
 
void setSearchingAll (const SbBool searchall)
 
void setType (const SoType type, const SbBool chkderived=TRUE)
 
- Public Member Functions inherited from SoAction
virtual ~SoAction (void)
 
virtual void apply (const SoPathList &pathlist, SbBool obeysrules=FALSE)
 
void apply (SoAction *beingApplied)
 
virtual void apply (SoNode *root)
 
virtual void apply (SoPath *path)
 
const SoPathgetCurPath (void)
 
PathCode getCurPathCode (void) const
 
virtual SoNodegetCurPathTail (void)
 
SoNodegetNodeAppliedTo (void) const
 
const SoPathListgetOriginalPathListAppliedTo (void) const
 
SoPathgetPathAppliedTo (void) const
 
PathCode getPathCode (int &numindices, const int *&indices)
 
const SoPathListgetPathListAppliedTo (void) const
 
SoStategetState (void) const
 
AppliedCode getWhatAppliedTo (void) const
 
SbBool hasTerminated (void) const
 
virtual void invalidateState (void)
 
SbBool isLastPathListAppliedTo (void) const
 
virtual SbBool isOfType (SoType type) const
 
void popCurPath (const PathCode prevpathcode)
 
void popCurPath (void)
 
void popPushCurPath (const int childindex, SoNode *node=NULL)
 
void pushCurPath (const int childindex, SoNode *node=NULL)
 
void pushCurPath (void)
 
void switchToNodeTraversal (SoNode *node)
 
void switchToPathTraversal (SoPath *path)
 
void traverse (SoNode *const node)
 
void usePathCode (int &numindices, const int *&indices)
 

Static Public Member Functions

static void addMethod (const SoType type, SoActionMethod method)
 
static void enableElement (const SoType type, const int stackindex)
 
static SoType getClassTypeId (void)
 
static void initClass (void)
 
- Static Public Member Functions inherited from SoAction
static SoType getClassTypeId (void)
 
static void initClass (void)
 
static void initClasses (void)
 
static void nullAction (SoAction *action, SoNode *node)
 

Static Public Attributes

static SbBool duringSearchAll = FALSE
 

Protected Member Functions

virtual void beginTraversal (SoNode *node)
 
virtual const SoEnabledElementsListgetEnabledElements (void) const
 
- Protected Member Functions inherited from SoAction
 SoAction (void)
 
virtual void endTraversal (SoNode *node)
 
void setTerminated (const SbBool flag)
 
virtual SbBool shouldCompactPathList (void) const
 

Static Protected Member Functions

static SoActionMethodListgetClassActionMethods (void)
 
static SoEnabledElementsListgetClassEnabledElements (void)
 
- Static Protected Member Functions inherited from SoAction
static SoActionMethodListgetClassActionMethods (void)
 
static SoEnabledElementsListgetClassEnabledElements (void)
 

Additional Inherited Members

- Protected Attributes inherited from SoAction
SoStatestate
 
SoActionMethodListtraversalMethods
 

Detailed Description

The SoSearchAction class provides methods for searching through scene graphs.

Nodes can be searched for by pointer, type, and name, or a combination of those criteria. Types can be interpreted as exact types, or the type can match nodes derived from it. Every single node can be searched, or normal traversal rules can be followed when searching (this is especially important to note with regard to switch nodes).

When using more than one of the setNode(), setType() and setName() calls, note that the action will search for node(s) with an "AND" combination of the given search criteria.

One of the most common pitfalls when using the SoSearchAction class is to call the function isFound() after doing a search. It does not return what you would expect it to return if you haven't read the documentation for that function.

Be aware that if you do search operations on an SoSearchAction created on the stack, you can get some unfortunate side effects if you're not careful. Since SoSearchAction keeps a list of the path(s) found in the latest search, the nodes in these paths will be unref'ed when the SoSearchAction stack instance is destructed at the end of your function. If the root of your scene graph then has ref-count zero (it is often useful to do a unrefNoDelete() before returning a node from a function to leave the referencing to the caller), the root node will be destructed! It might be better to create a heap instance of the search action in those cases, since you'll then be able to destruct the search action before calling unrefNoDelete(). Another solution would be to call reset() before calling unrefNoDelete() on your object, since reset() truncates the path list.

See the documentation of SoTexture2 for a full usage example of SoSearchAction.

Member Enumeration Documentation

◆ Interest

Values used when specifying what node(s) we are interested in: the first one found, the last one or all of them.

Enumerator
FIRST 

Return the path to the first node found.

LAST 

Return the path to the last node found.

ALL 

Return paths to all nodes found.

◆ LookFor

Specify the search criterion. This can be a bitwise combination of the available values.

Enumerator
NODE 

Search for a node by pointer.

TYPE 

Search for a node by type.

NAME 

Search for a node by name.

Constructor & Destructor Documentation

◆ SoSearchAction()

SoSearchAction::SoSearchAction ( void )

Initializes internal settings with default values. With the default settings, the SoSearchAction will ignore all nodes.

◆ ~SoSearchAction()

SoSearchAction::~SoSearchAction ( void )
virtual

Destructor.

Member Function Documentation

◆ addMethod()

void SoSearchAction::addMethod ( const SoType type,
SoActionMethod method )
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ addPath()

void SoSearchAction::addPath ( SoPath *const pathptr)

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Sets the path, or adds the path to the path list, depending on the interest configuration. The path is not copied, so it cannot be modified after being added without side effects.

◆ beginTraversal()

void SoSearchAction::beginTraversal ( SoNode * node)
protectedvirtual

This virtual method is called from SoAction::apply(), and is the entry point for the actual scene graph traversal.

It can be overridden to initialize the action at traversal start, for specific initializations in the action subclasses inheriting SoAction.

Default method just calls traverse(), which any overridden implementation of the method must do too (or call SoAction::beginTraversal()) to trigger the scene graph traversal.

Reimplemented from SoAction.

◆ enableElement()

void SoSearchAction::enableElement ( const SoType type,
const int stackindex )
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ getClassActionMethods()

SoActionMethodList * SoSearchAction::getClassActionMethods ( void )
staticprotected

Returns list of action methods for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.

◆ getClassEnabledElements()

SoEnabledElementsList * SoSearchAction::getClassEnabledElements ( void )
staticprotected

Returns list of enabled elements for this class. The enabledElements and methods variables are protected in the original OIV API. This is not such a good idea, since exposed static class member variables is a major grievance with regard to Win32 DLLs. This function is an extension for Coin, and it is not available in the original SGI Open Inventor v2.1 API.

◆ getClassTypeId()

SoType SoSearchAction::getClassTypeId ( void )
static

This static method returns the SoType object associated with objects of this class.

◆ getEnabledElements()

const SoEnabledElementsList & SoSearchAction::getEnabledElements ( void ) const
protectedvirtual

Returns list of enabled elements.

Reimplemented from SoAction.

◆ getFind()

int SoSearchAction::getFind ( void ) const

Returns the search configuration of the action instance.

◆ getInterest()

SoSearchAction::Interest SoSearchAction::getInterest ( void ) const

Returns whether only the first, the last, or all the searching matches will be saved.

◆ getName()

SbName SoSearchAction::getName ( void ) const

Returns the name the SoSearchAction instance is configured to search for.

◆ getNode()

SoNode * SoSearchAction::getNode ( void ) const

Returns the node the SoSearchAction instance is configured to search for.

Note that this method does not return what was found when you applied the action - it only returns what was specifically set by the user with setNode(). What the action found is returned by getPath() and getPaths().

◆ getPath()

SoPath * SoSearchAction::getPath ( void ) const

Returns the path to the node of interest that matched the search criterions. If no match was found, NULL is returned.

Note that if ALL matches are of interest, the result of a search action must be fetched through SoSearchAction::getPaths().

There is one frequently asked question about the paths that are returned from either this method or the getPaths() method below: "why am I not getting the complete path as expected?"

Well, then you probably have to cast the path to a SoFullPath, since certain nodes (nodekits, many VRML97 nodes) have hidden children. SoPath::getTail() will return the first node that has hidden children, or the tail if none of the nodes have hidden children. SoFullPath::getTail() will always return the actual tail. Just do like this:

SoFullPath * path = (SoFullPath *) searchaction->getPath();
The SbList class is a template container class for lists.
Definition SbList.h:70
The SoFullPath class allows examination of hidden children in paths.
Definition SoFullPath.h:38
SoNode * getTail(void) const
Definition SoFullPath.cpp:84
The SoVRMLCoordinate class is used to define 3D coordinates for shapes.
Definition SoVRMLCoordinate.h:43

◆ getPaths()

SoPathList & SoSearchAction::getPaths ( void )

Returns a path list of all nodes that matched the search criterions.

Note that if interest were only FIRST or LAST, SoSearchAction::getPath() should be used instead of this method.

See also
getPath()

◆ getType()

SoType SoSearchAction::getType ( SbBool & chkderivedref) const

Returns the node type which is searched for, and whether derived classes of that type also returns a match.

◆ getTypeId()

SoType SoSearchAction::getTypeId ( void ) const
virtual

Returns the type identification of an object derived from a class inheriting SoAction. This is used for runtime type checking and "downward" casting.

Implements SoAction.

◆ initClass()

void SoSearchAction::initClass ( void )
static

Initializes the runtime type system for this class, and sets up the enabled elements and action method list.

◆ isFound()

SbBool SoSearchAction::isFound ( void ) const

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Returns whether the search action was terminated.

Note that this value does not reflect whether the node(s) that was searched for was found or not. Use the result of getPath() / getPaths() if that is what you really are looking for.

◆ isSearchingAll()

SbBool SoSearchAction::isSearchingAll ( void ) const

Returns the traversal method configuration of the action.

◆ reset()

void SoSearchAction::reset ( void )

Resets all the SoSearchAction internals back to their default values.

◆ setFind()

void SoSearchAction::setFind ( const int what)

Configures what to search for in the scene graph. what is a bitmask of LookFor flags.

Default find configuration is to ignore all nodes, but the setFind() configuration is updated automatically when any one of SoSearchAction::setNode(), SoSearchAction::setType() or SoSearchAction::setName() is called.

◆ setFound()

void SoSearchAction::setFound ( void )

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Marks the SoSearchAction instance as terminated.

◆ setInterest()

void SoSearchAction::setInterest ( const Interest interestarg)

Configures whether only the first, the last, or all the searching matches are of interest. Default configuration is FIRST.

◆ setName()

void SoSearchAction::setName ( const SbName namearg)

Configures the SoSearchAction instance to search for nodes with the given name.

The action will be configured to set the search "interest" to LookFor NAME, so there is no need to call SoSearchAction::setFind().

See also
SoNode::getByName()

◆ setNode()

void SoSearchAction::setNode ( SoNode *const nodeptr)

Sets the node pointer to search for.

The action will be configured to set the search "interest" to LookFor NODE, so there is no need to call SoSearchAction::setFind().

◆ setSearchingAll()

void SoSearchAction::setSearchingAll ( const SbBool searchallarg)

Specifies whether normal graph traversal should be done (searchall is FALSE, which is the default setting), or if every single node should be searched (searchall is TRUE).

If the searchall flag is TRUE, even nodes considered "hidden" by other actions are searched (like for instance the disabled children of SoSwitch nodes).

SoBaseKit::setSearchingChildren() must be used to search for nodes under node kits.

◆ setType()

void SoSearchAction::setType ( const SoType typearg,
const SbBool chkderivedarg = TRUE )

Configures the SoSearchAction instance to search for nodes of the given type, and nodes of classes derived from the given type if chkderived is TRUE.

The action will be configured to set the search "interest" to LookFor TYPE, so there is no need to call SoSearchAction::setFind().

Member Data Documentation

◆ duringSearchAll

SbBool SoSearchAction::duringSearchAll = FALSE
static

Obsoleted global flag, only present for compatibility reasons with old SGI / TGS Inventor application code.

It's set to TRUE when an SoSearchAction traversal with SoSearchAction::isSearchingAll() equal to TRUE is started, and is reset to FALSE again after traversal has finished.

(The flag is used by SGI / TGS Inventor in SoSwitch::affectsState() to know when SoSwitch::whichChild should behave as SoSwitch::SO_SWITCH_ALL. We have a better solution for this problem in Coin.)


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