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 Deriving a Class from an Existing Element).
- Implement an initClass() method to initialize the type information (see 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 Destructor).
- Implement an init() method (see The init() Method).
- Implement set() and get() methods to modify and access current values (see The set() and get() Methods).
- Implement a print() method for debugging purposes (see 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 Additional Methods).
b. push() and pop() (see Pushing and Popping Elements).
c. setElt() (see Additional Methods).