SoSearchAction SoSearchAction SoSearchAction searches through the scene graph for paths to specific nodes, types of nodes, or nodes with a given name. First, you initialize the action. Then, you specify the node, node type, or name to search for (or a combination of these elements). If you specify a node type, you can also specify whether to search for an exact type match, or to search for subclasses of the specified type as well.
First, specify what you are searching for, whether you want to find all matches, and how to traverse the scene graph.
If you want to search for a particular node (by pointer), use the setNode() method. For example, you might use setNode() to search for a particular light-source node so that you can attach an editor to it.
Rather than searching for a specific node, you may want to search for a type of node (see Chapter 3, Nodes and Groups). When searching for a node type, you then have the choice of searching for all nodes of a particular type, or for derivations of the given type (the default). The syntax for setType() is as follows:
Use the setName() method to specify the name of the node to search for. (See Chapter 3, Nodes and Groups for more information on naming.)
SoSearchAction SoSearchAction SoSearchAction is applied in the same manner as any other action.
To obtain the results of the search, use one of the following methods:
returns the found path (if interest is FIRST or LAST) | |
getPaths() | returns the found path list (if interest is ALL) |
See the Open Inventor C++ Reference Manual for a complete description of all methods available for SoSearchAction SoSearchAction SoSearchAction .
The following example searches a scene graph for any node derived from SoLight SoLight SoLight . If it does not find one, it creates and adds an SoDirectionalLight SoDirectionalLight SoDirectionalLight . This example searches for only the first match by calling setInterest- (SoSearchAction::FIRST).
SoSearchAction mySearchAction;
// Look for first existing light derived from class SoLight
mySearchAction.setType(SoLight::getClassTypeId());
mySearchAction.setInterest(SoSearchAction::FIRST);
mySearchAction.apply(root);
if (mySearchAction.getPath() == NULL) { // No lights found
// Add a default directional light to the scene
SoDirectionalLight *myLight = new SoDirectionalLight;
root->insertChild(myLight, 0);
}
SoSearchAction mySearchAction = new SoSearchAction();
// Look for first existing light derived from class SoLight
mySearchAction.SetType(Type.GetType("SoLight"));
mySearchAction.SetInterest(SoSearchAction.Interests.FIRST);
mySearchAction.Apply(root);
if (mySearchAction.GetPath() == null) // No lights found
{
// Add a default directional light to the scene
SoDirectionalLight myLight = new SoDirectionalLight();
root.InsertChild(myLight, 0);
}
SoSearchAction mySearchAction = new SoSearchAction();
// Look for first existing light derived from class SoLight
mySearchAction.setNodeClass(SoLight.class);
mySearchAction.setInterest(SoSearchAction.Interests.FIRST);
mySearchAction.apply(root);
if (mySearchAction.getPath() == null) // No lights found
{
// Add a default directional light to the scene
SoDirectionalLight myLight = new SoDirectionalLight();
root.insertChild(myLight, 0);
}