Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoSearchAction Class Reference

Searches for nodes in a scene graph. More...

#include <Inventor/actions/SoSearchAction.h>

+ Inheritance diagram for SoSearchAction:

Public Types

enum  LookFor {
  NODE = 0x01 ,
  TYPE = 0x02 ,
  NAME = 0x04
}
 Enum that defines the search criterion. More...
 
enum  Interest {
  FIRST ,
  LAST ,
  ALL
}
 Enum that defines which paths to return. More...
 
- Public Types inherited from SoAction
enum  DistribMode {
  LOCAL_ONLY ,
  CLUSTER_ONLY ,
  ALL
}
 This is used to define the way an action is distributed across a cluster. More...
 
enum  AppliedCode {
  NODE ,
  PATH ,
  PATH_LIST
}
 This enum is used to determine what the action is being applied to. More...
 
enum  PathCode {
  NO_PATH ,
  IN_PATH ,
  BELOW_PATH ,
  OFF_PATH
}
 This enum may be used during traversal of nodes to indicate where the node is with respect to the path being traversed. More...
 

Public Member Functions

virtual SoType getTypeId () const
 Returns the type identifier for this specific instance.
 
 SoSearchAction ()
 Constructor.
 
virtual void reset ()
 Resets options back to default values; clears list of returned paths.
 
virtual void clearApplyResult ()
 When applied, an action may reference nodes or create objects (e.g.
 
void setFind (int what)
 Sets what to look for; what is a bitmask of LookFor enum values.
 
int getFind ()
 Returns what to look for.
 
SoNodegetNode () const
 Returns the node to search for.
 
void setNode (SoNode *n)
 Sets the node to search for.
 
SoType getType (SbBool &derivedIsOk) const
 Returns the node type to search for.
 
void setType (SoType t, SbBool derivedIsOk=TRUE)
 Sets the node type to search for.
 
const SbNamegetName () const
 Returns the name of the node to search for.
 
void setName (const SbName &n)
 Sets the name of the node to search for.
 
Interest getInterest () const
 Returns which paths to return.
 
void setInterest (Interest i)
 Sets which paths to return.
 
SbBool isSearchingAll () const
 Returns FALSE if searching uses regular traversal, TRUE if it traverses every single node.
 
void setSearchingAll (SbBool flag)
 Sets whether searching uses regular traversal or whether it traverses every single node.
 
SoPathgetPath () const
 Returns resulting path, or NULL if no path was found.
 
SoPathListgetPaths ()
 Returns resulting path list.
 
- Public Member Functions inherited from SoAction
virtual ~SoAction ()
 Destructor.
 
virtual void apply (SoNode *node)
 Initiates an action on the graph defined by a node.
 
virtual void apply (SoPath *path)
 Initiates an action on the graph defined by a path.
 
virtual void apply (const SoPathList &pathList, SbBool obeysRules=FALSE)
 Initiates an action on the graph defined by a list of paths.
 
virtual void invalidateState ()
 Invalidates the current traversal state in the action, forcing it to be recreated when the action is next applied.
 
void stopActionInBranch ()
 This function stops the action in the current Scene Graph branch.
 
SbBool getContinueActionInBranchFlag () const
 This function indicates if the action must stop in the current branch.
 
void resetContinueActionInBranchFlag ()
 This function resets the continue action flag.
 
void useAlternateRep (const SbBool enable)
 Tell the action to use alternate representations during traversal when available.
 
SbBool isUsingAlternateRep () const
 Returns TRUE if current action is using alternate representations.
 
void setSceneManager (SoSceneManager *mgr)
 Set the scene manager associated with this action (if any ).
 
SoSceneManagergetSceneManager () const
 Return the SoSceneManager associated with this action.
 
virtual void forwardTraversal (SoNode *node)
 Traverse a node that is not part of the current scenegraph.
 
virtual void forwardTraversal (SoPath *path)
 Traverse a path that is not part of the current scenegraph.
 
DistribMode getDistribMode () const
 Returns the distribution mode of this action across a cluster (ScaleViz-Cluster only).
 
AppliedCode getWhatAppliedTo () const
 Returns code indicating what action is being applied to.
 
SoNodegetNodeAppliedTo () const
 Returns the node the action is being applied to.
 
SoPathgetPathAppliedTo () const
 Returns the path the action is being applied to.
 
const SoPathListgetPathListAppliedTo () const
 Returns the path list the action is being applied to.
 
const SoPathListgetOriginalPathListAppliedTo () const
 Returns the original path list the action is being applied to.
 
SbBool isLastPathListAppliedTo () const
 Returns TRUE if the current list is the last one from the original.
 
PathCode getPathCode (int &numIndices, const int *&indices)
 Returns path code based on where current node (the node at the end of the current path) lies with respect to the path(s) the action is being applied to.
 
PathCode getPathCodeMI (int &numIndices, const int *&indices, const int *&instanceIndices)
 Extender API: available to programmers who wish to extend the toolkit
 
void traverse (SoNode *node)
 Does traversal of a graph rooted by a node.
 
SbBool hasTerminated () const
 Returns TRUE if the traversal has reached a termination condition.
 
const SoPathgetCurPath ()
 Returns the path accumulated during traversal, i.e., the chain of nodes from the root of the traversed graph to the current node being traversed.
 
SoStategetState () const
 Gets the state from the action.
 
virtual void setUpState ()
 Creates state if it is NULL or it is no longer valid because new elements have been enabled since it was created.
 
void setPipeId (int id)
 Sets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration.
 
int getPipeId () const
 Gets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration.
 
bool isBeingApplied ()
 Returns TRUE if this action is currently being applied.
 
virtual bool preDelayedTraversal ()
 Method called by SoMultiPassManager before delayed pass traversals.
 
virtual void postDelayedTraversal ()
 Method called by SoMultiPassManager after delayed pass traversals.
 
- 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 SoAction
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 
static void nullAction (SoAction *, SoNode *)
 Null action method that can be stored in lookup table when desired.
 
- Static Public Member Functions inherited from SoTypedObject
static SoType getClassTypeId ()
 Returns the type identifier for this class.
 

Detailed Description

Searches for nodes in a scene graph.

This class is used to search scene graphs for specific nodes, nodes of a specific type, nodes with a specific name, or any combination of these. It can search for just the first or last node satisfying the criteria or for all such nodes. The action returns a path (SoPath) to each node found. The searched for node is the "tail" of each path.

Note that the search criteria are cumulative. For example, if you do a search by name (setName()), then reuse the same SoSearchAction object to do a search by type (setType()), the action will actually search for a node that satisfies both criteria. To avoid this problem, call reset() before reusing the action object.

By default SoSearchAction only searches nodes that are actually traversed. For example it would not search all the children of an SoSwitch node unless the whichChild field is set to SO_SWITCH_ALL. To search all nodes in the scene graph (except nodekits - see next paragraph) call setSearchingAll(TRUE).

Nodekits:

  • By default SoSearchAction will not search inside nodekits even when setSearchingAll is true. This is because nodekits try to keep their children hidden. To allow searching inside nodekits call the static method SoBaseKit::setSearchingChildren(TRUE).
  • A common problem is that when the searched for node is found inside a nodekit, the SoPath method getTail() does not return the found node. This is also because nodekits try to keep their children hidden. To avoid this problem cast the returned SoPath to SoFullPath.

Hidden references:

SoSearchAction creates one or more SoPath objects when applied to the scene graph. An SoPath object calls ref() on each node in the path. This reference will prevent the node from being destroyed for as long as the SoPath object exists. These SoPath objects are stored internally in the action and exist until the action object itself is destroyed or reset.

Efficiency:

SoSearchAction is convenient for finding one or many nodes in the scene graph. However it may be an inefficient solution for finding a large number of nodes because it uses CPU time and memory to create an SoPath for every node found. If you expect to find many nodes, especially if you just need the node object and not a path, then you should consider using SoCallbackAction instead.
For example, if you want to count all the shape nodes in the scene graph, you could use an SoSearchAction similar to the second example below. The number of shapes would conveniently be the number of paths created by the action, but you wouldn't actually make any use of the path information. Using SoCallbackAction would be a little more work, because you have to implement a counter in a callback method. But it would be much more efficient because the action simply calls your callback when each shape node is visited during the traversal.

EXAMPLE

SEE ALSO

SoPath, SoBaseKit, SoSearchPathAction, SoSearchStepAction

Definition at line 241 of file SoSearchAction.h.

Member Enumeration Documentation

◆ Interest

Enum that defines which paths to return.

Enumerator
FIRST 

Return only the first path found (default)

LAST 

Return only the last path found.

ALL 

Return all paths found.

Definition at line 264 of file SoSearchAction.h.

◆ LookFor

Enum that defines the search criterion.

Enumerator
NODE 

Search for a particular node instance.

TYPE 

Search for a particular type of node.

NAME 

Search for a node with a particular name.

Definition at line 248 of file SoSearchAction.h.

Constructor & Destructor Documentation

◆ SoSearchAction()

SoSearchAction::SoSearchAction ( )

Constructor.

Member Function Documentation

◆ clearApplyResult()

virtual void SoSearchAction::clearApplyResult ( )
virtual

When applied, an action may reference nodes or create objects (e.g.

SoPath) that reference nodes. This is especially true for SoSearchAction and SoRayPickAction. These references will prevent the nodes from being destroyed and so may appear to be a "memory leak".

All references are cleared when the action is destroyed or re-applied. However it may be useful to clear them explicitly to remove references to nodes.

See also reset()

Reimplemented from SoAction.

◆ getClassTypeId()

static SoType SoSearchAction::getClassTypeId ( )
static

Returns the type identifier for this class.


◆ getFind()

int SoSearchAction::getFind ( )
inline

Returns what to look for.

Definition at line 313 of file SoSearchAction.h.

◆ getInterest()

Interest SoSearchAction::getInterest ( ) const
inline

Returns which paths to return.

Definition at line 354 of file SoSearchAction.h.

◆ getName()

const SbName & SoSearchAction::getName ( ) const
inline

Returns the name of the node to search for.

Definition at line 344 of file SoSearchAction.h.

◆ getNode()

SoNode * SoSearchAction::getNode ( ) const
inline

Returns the node to search for.

Definition at line 318 of file SoSearchAction.h.

◆ getPath()

SoPath * SoSearchAction::getPath ( ) const
inline

Returns resulting path, or NULL if no path was found.

This should be used if the interest is FIRST or LAST.

Definition at line 380 of file SoSearchAction.h.

◆ getPaths()

SoPathList & SoSearchAction::getPaths ( )
inline

Returns resulting path list.

This should be used if the interest is ALL.

Definition at line 385 of file SoSearchAction.h.

◆ getType()

SoType SoSearchAction::getType ( SbBool derivedIsOk) const
inline

Returns the node type to search for.

Definition at line 331 of file SoSearchAction.h.

◆ getTypeId()

virtual SoType SoSearchAction::getTypeId ( ) const
virtual

Returns the type identifier for this specific instance.

Implements SoTypedObject.

Reimplemented in SoSearchPathAction, and SoSearchStepAction.

◆ isSearchingAll()

SbBool SoSearchAction::isSearchingAll ( ) const
inline

Returns FALSE if searching uses regular traversal, TRUE if it traverses every single node.

Default is FALSE.

Definition at line 365 of file SoSearchAction.h.

◆ reset()

virtual void SoSearchAction::reset ( )
virtual

Resets options back to default values; clears list of returned paths.

This can be used to apply the action again with a different set of search criteria. See also clearApplyResult().

Reimplemented in SoSearchPathAction.

◆ setFind()

void SoSearchAction::setFind ( int  what)
inline

Sets what to look for; what is a bitmask of LookFor enum values.

Default is no flags at all. Note that setting a node, type, and/or name to search for activates the relevant flag, so you may never need to call this method directly.

Definition at line 308 of file SoSearchAction.h.

◆ setInterest()

void SoSearchAction::setInterest ( Interest  i)
inline

Sets which paths to return.

Default is FIRST.

Definition at line 359 of file SoSearchAction.h.

◆ setName()

void SoSearchAction::setName ( const SbName n)

Sets the name of the node to search for.

◆ setNode()

void SoSearchAction::setNode ( SoNode n)

Sets the node to search for.

◆ setSearchingAll()

void SoSearchAction::setSearchingAll ( SbBool  flag)
inline

Sets whether searching uses regular traversal or whether it traverses every single node.

For example, if this flag is FALSE, an SoSwitch node will traverse only the child or children it would normally traverse for an action. If the flag is TRUE, the switch would always traverse all of its children. The default is FALSE.

Definition at line 374 of file SoSearchAction.h.

◆ setType()

void SoSearchAction::setType ( SoType  t,
SbBool  derivedIsOk = TRUE 
)

Sets the node type to search for.

If derivedIsOk is TRUE, a node that is of a type that is derived from t will pass this search criterion.


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