The file SoSubElement.h contains the macros for defining new element classes. The SO_ELEMENT_HEADER() macro declares type identifier and naming variables and methods that all element classes must support. The SO_ELEMENT_SOURCE() macro defines the static variables and methods declared in the SO_ELEMENT_HEADER() macro. Other macros useful in creating new element classes are mentioned in the following sections.
Creating a new element requires these steps:
Select a name for the new element class and determine what class it is derived from (see Section 5.2, “Deriving a Class from an Existing Element”).
Implement an initClass() method to initialize the type information (see Section 5.3, “The initClass() Method”).
Define an exitClass() method to clean up the type information. In the exitClass() routine of your class, use the macro SO_ELEMENT_EXIT_CLASS.
Implement a destructor. Elements don't have constructors (see Section 5.4, “Destructor”).
Implement an init() method (see Section 5.5, “The init() Method”).
Implement set() and get() methods to modify and access current values (see Section 5.6, “The set() and get() Methods”).
Implement a print() method for debugging purposes (see Section 5.7, “The print() Method”).
Depending on what your class is derived from and the nature of your element, you may need to implement the following methods:
a. matches() and copyMatchInfo() (see Section 5.8, “Additional Methods”).
b. push() and pop() (see Section 5.10, “Pushing and Popping Elements”).
c. setElt() (see Section 5.8, “Additional Methods”).