Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
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 Key Concepts, 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 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 Element Class Tree (Part 1 of 2) , most elements are derived from one of four abstract base classes: SoFloatElement, SoLongElement,SoReplacedElement, or SoAccumulatedElement. Most elements fall into the 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)

Element Class Tree (Part 2 of 2)

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