2.2. Initializing the Node Class

As discussed in Chapter 1, the initClass() method sets up the type identifier and file format name information for the class. The initialization macro for nodes, SO_NODE_INIT_CLASS(), does most of the work for you. One additional task for you as the node writer is to enable each of the elements in the state for each action the node supports. The following subsections provide additional information about enabling elements in the state.

Enabling Elements in the State

In the initClass() method, use the SO_ENABLE() macro (defined in SoAction.h) to enable the elements required by your node in the state. To use a simple example, SoDrawStyle SoDrawStyle SoDrawStyle enables these elements in the SoGLRenderAction SoGLRenderAction SoGLRenderAction :

SO_ENABLE(SoGLRenderAction, SoGLDrawStyleElement);
SO_ENABLE(SoGLRenderAction, SoGLLinePatternElement);
SO_ENABLE(SoGLRenderAction, SoGLLineWidthElement);
SO_ENABLE(SoGLRenderAction, SoGLPointSizeElement);

SoDrawStyle SoDrawStyle SoDrawStyle also implements the SoCallbackAction SoCallbackAction SoCallbackAction . It enables these elements in the SoCallbackAction SoCallbackAction SoCallbackAction :

SO_ENABLE(SoCallbackAction, SoDrawStyleElement);
SO_ENABLE(SoCallbackAction, SoLinePatternElement);
SO_ENABLE(SoCallbackAction, SoLineWidthElement);
SO_ENABLE(SoCallbackAction, SoPointSizeElement);

If you know that the element is already enabled by another node or action, you can skip this step. (See Table 1-1.)

Now that these elements have been enabled, their values can be set and inquired. (The debugging version of Inventor generates an error if you try to access or set an element that has not been enabled.)

Inheritance within the Element Stack

The previous example using SoDrawStyle SoDrawStyle SoDrawStyle elements brings up another feature of the element stack: Some elements have corresponding GL versions that are derived from them. The SoGL version of an element typically sends its value to OpenGL when it is set. As you might guess, SoGLDrawStyleElement SoGLDrawStyleElement SoGLDrawStyleElement is derived from SoDrawStyleElement SoDrawStyleElement SoDrawStyleElement , and SoGLLinePatternElement SoGLLinePatternElement SoGLLinePatternElement is derived from SoLinePatternElement SoLinePatternElement SoLinePatternElement . The parent element class and its derived class share the same stack index.

If you try to enable two classes that share a stack index (for example, SoGLDrawStyleElement SoGLDrawStyleElement SoGLDrawStyleElement and SoDrawStyleElement SoDrawStyleElement SoDrawStyleElement ), only the more derived class is actually enabled (in this case, SoGLDrawStyleElement SoGLDrawStyleElement SoGLDrawStyleElement ). However, you can always use the base class static method to set or get the value for either the parent or the derived class. (You cannot, however, enable only the parent version and then try to treat it as the derived GL version.)