4.1. Overview

The file SoSubAction.h contains the macros for defining new action classes. The SO_ACTION_HEADER() macro declares type identifier and naming variables and methods that all action classes must support. The SO_ACTION_SOURCE() macro defines the static variables and methods declared in the SO_ACTION_HEADER() macro.

Creating a new action requires these steps:

  1. Select a name for the new action class and determine what class it is derived from.

  2. Define an initClass() method to initialize the runtime type information for the class (see Section 4.2, “Initializing the Action Class”).

    a. Enable elements in the state that are used by nodes when the action is applied to them (see the section called “Enabling Elements in the State”).

    b. Register a static method for each node class that supports this action (see the section called “Registering Static Methods”).

    c. Define an exitClass() method to clean up the type information. In the exitClass() routine of your class, use the macro SO_ACTION_EXIT_CLASS.

  3. Write the constructor for the action (see Section 4.3, “Defining the Constructor”).

  4. Write the destructor for the action (see Section 4.4, “Defining the Destructor”).

  5. If necessary, override the beginTraversal() method to implement a different traversal behavior or to perform special initialization before traversal. The apply() methods all call beginTraversal() (see Section 4.5, “Traversal Behavior”).

  6. Implement the methods that you registered in step 2b of this list (see Section 4.6, “Implementing Static Methods”).

[Tip]

An easy way to create a new action is to derive it from the callback action. The callback action provides generic traversal of the scene graph and enables all standard elements. Note that deriving a new action class requires more work than simply registering callback functions with the callback action. In many cases, this latter approach will suffice.