5.2. Deriving a Class from an Existing Element

Elements are used for storing information in the Inventor traversal state. Writing a new element goes hand-in-hand with writing a new node, since nodes set and get element values. As explained in Chapter 1, elements provide the mechanism for caching in Inventor. They also provide the pushing and popping facility used by separators. Later sections in this chapter supply details on both topics.

Before an element class can be used, it must be initialized using one of the macros provided (see Section 5.12, “Creating a New Element”). The element must also be enabled in the method list of each action for which it is required. (Nodes and actions enable the elements in an action's state.)

As shown in Figure 5.1, “ Element Class Tree (Part 1 of 2), most elements are derived from one of four abstract base classes: SoFloatElement SoFloatElement SoFloatElement , SoLongElement ,SoReplacedElement SoReplacedElement SoReplacedElement , or SoAccumulatedElement SoAccumulatedElement SoAccumulatedElement . Most elements fall into the SoReplacedElement SoReplacedElement SoReplacedElement category. The diffuse-color and specular-color elements are examples of elements that fall into this category, because their value replaces the previous value (and it is not a simple floating-point or integer value). A few elements, such as transformations and profiles, accumulate values.

Element Class Tree (Part 1 of 2)

Figure 5.1.  Element Class Tree (Part 1 of 2)

Element Class Tree (Part 2 of 2)

Figure 5.2.  Element Class Tree (Part 2 of 2)

In addition, some elements have a derived element class that is used to cause the side effects required for OpenGL. An example is SoDrawStyleElement SoDrawStyleElement SoDrawStyleElement , from which SoGLDrawStyleElement SoGLDrawStyleElement SoGLDrawStyleElement is derived. Section 5.10, “Special Behavior for Derived Elements” discusses the use of these element class pairs.

The first question to ask when creating a new element class is: What class can I derive my new element from? The answer depends partly on the kind of information stored in the element. If it can be stored as a single floating-point value (such as complexity or font size), derive your new class from SoFloatElement SoFloatElement SoFloatElement . If it can be stored as an integer (such as drawing style, an enumerated value), derive your new class from SoLongElement. You will probably be able to inherit many of the base class methods in these cases.

If your new element contains other types of values, you may be able to derive it from SoReplacedElement SoReplacedElement SoReplacedElement . If the current value of the element accumulates with previous values, you can derive it from SoAccumulated- Element. Later sections in this chapter describe in detail how these classes differ from each other.