SoSearchAction Class |
Searches for nodes in a scene graph.
Namespace: OIV.Inventor.Actions
The SoSearchAction type exposes the following members.
Name | Description | |
---|---|---|
![]() | SoSearchAction | Constructor. |
Name | Description | |
---|---|---|
![]() | AddPath | |
![]() | Apply(SoNode) | Initiates an action on the graph defined by a node. |
![]() | Apply(SoPath) | Initiates an action on the graph defined by a path. |
![]() | Apply(SoPathList) | Calls Apply(pathList, false). (Inherited from SoAction.) |
![]() | Apply(SoPathList, Boolean) | Initiates an action on the graph defined by a list of paths. |
![]() | ClearApplyResult | When applied, an action may reference nodes or create objects (e.g. |
![]() ![]() | EnableElement | |
![]() | EnableElements | (Overrides SoActionEnableElements.) |
![]() | Equals | (Inherited from Object.) |
![]() | ForwardTraversal | Traverse a node that is not part of the current scenegraph. |
![]() | GetContinueActionInBranchFlag | This function indicates if the action must stop in the current branch. |
![]() | GetCurPath | (Inherited from SoAction.) |
![]() | GetFind | Returns what to look for. |
![]() | GetHashCode |
Overrides GetHashCode().
(Inherited from SoNetBase.) |
![]() | GetInterest | Returns which paths to return. |
![]() | GetName | Returns the name of the node to search for. |
![]() | GetNode | Returns the node to search for. |
![]() | GetNodeAppliedTo | (Inherited from SoAction.) |
![]() | GetOriginalPathListAppliedTo | (Inherited from SoAction.) |
![]() | GetPath | Returns resulting path, or NULL if no path was found. |
![]() | GetPathAppliedTo | (Inherited from SoAction.) |
![]() | GetPathCode(SbNativeArrayInt32) | 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. |
![]() | GetPathCode(SbNativeInt32Array) | Obsolete. 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. |
![]() | GetPathListAppliedTo | (Inherited from SoAction.) |
![]() | GetPaths | Returns resulting path list. |
![]() | GetPipeId | Gets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration. |
![]() | GetSceneManager | Return the SoSceneManager associated with this action. |
![]() | GetState | (Inherited from SoAction.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetType(Boolean) | Returns the node type to search for. |
![]() | GetWhatAppliedTo | (Inherited from SoAction.) |
![]() | HasTerminated | (Inherited from SoAction.) |
![]() | InvalidateState | Invalidates the current traversal state in the action, forcing it to be recreated when the action is next applied. |
![]() | IsBeingApplied | Returns true if this action is currently being applied. |
![]() | IsFound | |
![]() | IsLastPathListAppliedTo | (Inherited from SoAction.) |
![]() | IsSearchingAll | Returns false if searching uses regular traversal, true if it traverses every single node. |
![]() | IsUsingAlternateRep | Returns true if current action is using alternate representations. |
![]() | PostDelayedTraversal | Method called by SoMultiPassManager after delayed pass traversals. |
![]() | PreDelayedTraversal | Method called by SoMultiPassManager before delayed pass traversals. |
![]() | Reset | Resets options back to default values; clears list of returned paths. |
![]() | ResetContinueActionInBranchFlag | This function resets the continue action flag. |
![]() | SetFind | Sets what to look for; what is a bitmask of LookFor enum values. |
![]() | SetFound | |
![]() | SetInterest | Sets which paths to return. |
![]() | SetName | Sets the name of the node to search for. |
![]() | SetNode | Sets the node to search for. |
![]() | SetPipeId | Sets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Multipipe configuration. |
![]() | SetSceneManager | Set the scene manager associated with this action (if any ). |
![]() | SetSearchingAll | Sets whether searching uses regular traversal or whether it traverses every single node. |
![]() | SetType(Type) | Calls SetType(t, true). |
![]() | SetType(Type, Boolean) | Sets the node type to search for. |
![]() | SetUpState | (Inherited from SoAction.) |
![]() | StopActionInBranch | This function stops the action in the current Scene Graph branch. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | Traverse | (Inherited from SoAction.) |
![]() | UseAlternateRep | Tell the action to use alternate representations during traversal when available. |
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. The SoPath object references each node in the path. This reference will prevent the node and its associated memory from being reclaimed 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 reclaimed 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 delegate method. But it would be much more efficient because the action simply calls your delegatewhen each shape node is visited during the traversal.
Example 1: Given an instance of a node, create a path to the location of that node in the scene graph:
SoSearchAction sa = new SoSearchAction(); sa.SetNode( coneNode ); sa.SetSearchingAll( true ); // Optional: Search all nodes SoBaseKit.SetSearchingChildren( true ); // Optional: Search inside nodekits sa.Apply( root ); SoFullPath path = (SoFullPath)sa.GetPath(); if (path) { SoNode node = path.GetTail(); }
Example 2: Find all the SoFont nodes in the scene graph:
SoSearchAction sa = new SoSearchAction(); sa.SetType( typeof(SoFont) ); sa.SetInterest( SoSearchAction.Interests.ALL ); // Find ALL instances sa.SetSearchingAll( true ); // Optional: Search all nodes SoBaseKit.SetSearchingChildren( true ); // Optional: Search inside nodekits sa.Apply( rootNode ); SoPathList pathList = sa.GetPaths(); // Get list of paths foreach (SoFullPath path in pathList) { SoFont fontNode = (SoFont)path.GetTail(); . . . }