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 | Obsolete.
Returns the list of enabled elements for a given action subclass.
(Inherited from SoAction.) | |
Equals | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
ForwardTraversal(SoNode) | Traverse a node that is not part of the current scenegraph. | |
ForwardTraversal(SoPath) | Traverse a path that is not part of the current scenegraph. | |
GetContinueActionInBranchFlag | This function indicates if the action must stop in the current branch. | |
GetCurPath | 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. | |
GetDistribMode | Returns the distribution mode of this action across a cluster (ScaleViz-Cluster only). | |
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 | Returns the node the action is being applied to. | |
GetOriginalPathListAppliedTo | Returns the original path list the action is being applied to. | |
GetPath | Returns resulting path, or NULL if no path was found. | |
GetPathAppliedTo | Returns the path the action is being applied to. | |
GetPathCode | 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 | Returns the path list the action is being applied to. | |
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 OIV.Inventor.SoSceneManager associated with this action. | |
GetState | Gets the state from the action. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
GetType(Boolean) | Returns the node type to search for. | |
GetWhatAppliedTo | Returns code indicating what action is being applied to. | |
HasTerminated | Returns true if the traversal has reached a termination condition. | |
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 | Returns true if the current list is the last one from the original. | |
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 | Creates state if it is NULL or it is no longer valid because new elements have been enabled since it was created. | |
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 | Does traversal of a graph rooted by a node. | |
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 (OIV.Inventor.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 (OIV.Inventor.Actions.SoSearchAction.SetName(System.String)), then reuse the same OIV.Inventor.Actions.SoSearchAction object to do a search by type (OIV.Inventor.Actions.SoSearchAction.SetType(System.Type, System.Boolean)), the action will actually search for a node that satisfies both criteria. To avoid this problem, call OIV.Inventor.Actions.SoSearchAction.Reset() before reusing the action object.
By default OIV.Inventor.Actions.SoSearchAction only searches nodes that are actually traversed. For example it would not search all the children of an OIV.Inventor.Nodes.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 OIV.Inventor.Actions.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 OIV.Inventor.SoPath method getTail() does not return the found node. This is also because nodekits try to keep their children hidden. To avoid this problem use FullPath.GetTail() instead.
Hidden references:
OIV.Inventor.Actions.SoSearchAction creates one or more OIV.Inventor.SoPath objects when applied to the scene graph. The OIV.Inventor.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 OIV.Inventor.SoPath object exists. These OIV.Inventor.SoPath objects are stored internally in the action and exist until the action object itself is reclaimed or reset.
Efficiency:OIV.Inventor.Actions.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 OIV.Inventor.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 OIV.Inventor.Actions.SoCallbackAction instead.
For example, if you want to count all the shape nodes in the scene graph, you could use an OIV.Inventor.Actions.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 OIV.Inventor.Actions.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 ); SoPath path = sa.GetPath(); if (path != null) { SoNode node = path.FullPath.GetTail(); }
Example 2: Find all the OIV.Inventor.Nodes.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 (SoPath path in pathList) { SoFont fontNode = (SoFont)path.FullPath.GetTail(); . . . }