Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
Implementing Static Methods

Creating a Node provides important background material on implementing static methods and on doAction(). If you are creating a new node class, the static methods are typically included in the new node class. If you are creating a new action class, the static methods are included in the new action class. In the end, the new class (whether node or action) registers these static methods with the action class.

First, for SoNode, you will usually want to register the nullAction() method (defined on SoAction). This method will be used for any node classes that do not have a specific method registered for them.

For the node classes that actually do something for your action, you need to implement a static method. You'll probably choose one of two approaches:

  • Implement a new method for the class to handle the method in its unique way.
  • Implement a simple method that calls the doAction() method for that class if you want it to perform the action in its typical manner (for example, group nodes traverse their children in a specified order, property nodes affect elements in the state, and so on). In our example class, the GetVolumeAction registers the nullAction() method for SoNode. This method, defined on SoAction, will be inherited by nodes that do not implement their own GetVolumeAction:
SO_ACTION_ADD_METHOD( SoNode, nullAction );

GetVolumeAction implements specific methods for the SoCube and SoSphere classes. For purposes of example, only the cube and sphere classes implement the GetVolumeAction. If you were actually creating and using such an action, you would probably want to be able to obtain the volume of any shape.

For GetVolumeAction, the group and relevant property classes (such as the coordinate, transformation, and complexity classes) all call doAction(), since they perform their “typical” action behavior:

void
GetVolumeAction::callDoAction( SoAction* action, SoNode* node )
{
node->doAction( action );
}