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.

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( C++ | Java | .NET ) enables these elements in the SoGLRenderAction( C++ | Java | .NET ):


C++
SO_ENABLE(SoGLRenderAction, SoDrawStyleElement);
SO_ENABLE(SoGLRenderAction, SoLinePatternElement);
SO_ENABLE(SoGLRenderAction, SoLineWidthElement);
SO_ENABLE(SoGLRenderAction, SoPointSizeElement);

SoDrawStyle( C++ | Java | .NET ) also implements the SoCallbackAction( C++ | Java | .NET ). It enables these elements in the SoCallbackAction( C++ | Java | .NET ):


C++
SO_ENABLE(SoCallbackAction, SoDrawStyleElement);
SO_ENABLE(SoCallbackAction, SoLinePatternElement);
SO_ENABLE(SoCallbackAction, SoLineWidthElement);
SO_ENABLE(SoCallbackAction, SoPointSizeElement);
[Tip]

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.)