![]() |
http://www.sim.no http://www.coin3d.org |
SoElement is the abstract base class for all elements.Elements are part of the design for scenegraph traversal in Coin. More...
#include <Inventor/elements/SoElement.h>
Public Member Functions | |
const SoType | getTypeId (void) const |
int | getStackIndex (void) const |
virtual void | init (SoState *state) |
virtual void | push (SoState *state) |
virtual void | pop (SoState *state, const SoElement *prevTopElement) |
virtual SbBool | matches (const SoElement *element) const =0 |
virtual SoElement * | copyMatchInfo (void) const =0 |
void | setDepth (const int depth) |
int | getDepth (void) const |
virtual void | print (FILE *file=stdout) const |
virtual | ~SoElement () |
Static Public Member Functions | |
static void | initClass (void) |
static SoType | getClassTypeId (void) |
static int | getClassStackIndex (void) |
static void | initElements (void) |
static int | getNumStackIndices (void) |
static SoType | getIdFromStackIndex (const int stackIndex) |
Protected Member Functions | |
SoElement (void) | |
void | capture (SoState *const state) const |
virtual void | captureThis (SoState *state) const |
void | setTypeId (const SoType typeId) |
void | setStackIndex (const int index) |
SoElement * | getNextInStack (void) const |
SoElement * | getNextFree (void) const |
Static Protected Member Functions | |
static SoElement * | getElement (SoState *const state, const int stackIndex) |
static const SoElement * | getConstElement (SoState *const state, const int stackIndex) |
static int | createStackIndex (const SoType id) |
Protected Attributes | |
SoType | typeId |
int | stackIndex |
int | depth |
Static Protected Attributes | |
static int | classStackIndex |
static SoTypeList * | stackToType |
Friends | |
class | SoState |
SoElement is the abstract base class for all elements.
Elements are part of the design for scenegraph traversal in Coin.
It works like this: any traversal action instantiates and keeps a single SoState instance during traversal. The SoState instance uses SoElement objects as "memory units" to keep track of the current state for any feature of the scenegraph nodes.
As an example, consider the SoPointSize node: when the SoPointSize node is traversed by for instance a SoGLRenderAction, it will itself push a SoPointSizeElement onto the SoGLRenderAction's SoState stack. Later, when a SoPointSet node occurs in the scenegraph, it will request the current pointsize value from the SoState by reading off the value of it's SoPointSizeElement.
SoSeparator nodes will push and pop elements on and off the state stack, so anything that changes state below a SoSeparator node will not influence anything above the SoSeparator.
For more information on the theoretical underpinnings of this traversal design, you should consider reading available literature on the so-called "Visitor pattern". We recommend "Design Patterns", by Gamma, Helm, Johnson, Vlissides (aka the "Gang Of Four"). This book actually uses the Inventor API traversal mechanism as the case study for explaining the Visitor pattern.
For extending the Coin library with your own classes, we strongly recommend that you make yourself acquainted with the excellent «The Inventor Toolmaker» book (ISBN 0-201-62493-1), which describes the tasks involved in detail. This book was written by the original SGI Inventor designers and explains many of the underlying design ideas, aswell as having lots of hands-on examples on how to extend the Coin toolkit in ways that are true to the fundamental design ideas. («The Inventor Toolmaker» is also available at SGI's online library, at no cost. See Download The Inventor Toolmaker.) Reading the sourcecode of the built-in classes in Coin should also provide very helpful.
The following is a complete example on how to extend Coin with your own traversal elements. First, the class declaration of the new element (ie the header include file):
The implementation of the element:
And a small, stand-alone test application putting the new element to use:
|
virtual |
The destructor.
|
protected |
The constructor. To create element instances, use SoType::createInstance() for the elements type identifier..
|
static |
Initialize relevant common data for all instances, like the type system.
References SoType::badType(), classStackIndex, SoType::createType(), initElements(), and stackToType.
Referenced by SoDB::init().
|
static |
This static method returns the class type.
|
static |
This static method returns the state stack index for the class.
References classStackIndex.
const SoType SoElement::getTypeId | ( | void | ) | const |
Returns the type identification of an object derived from a class inheriting SoElement. This is used for run-time type checking and "downward" casting.
For a more thorough explanation of the run-time type identification functionality, see the documentation of SoBase::getTypeId().
References typeId.
Referenced by SoFloatElement::copyMatchInfo(), SoReplacedElement::copyMatchInfo(), SoInt32Element::copyMatchInfo(), SoAccumulatedElement::copyMatchInfo(), SoOverrideElement::copyMatchInfo(), SoState::getElement(), SoFloatElement::matches(), SoInt32Element::matches(), SoFloatElement::print(), SoInt32Element::print(), SoReplacedElement::print(), SoState::print(), and print().
int SoElement::getStackIndex | ( | void | ) | const |
Returns the stack index for an element instance.
References stackIndex.
Referenced by SoState::SoState().
|
virtual |
This function initializes the element type in the given SoState. It is called for the first element of each enabled element type in SoState objects.
Reimplemented in SoOverrideElement, SoAccumulatedElement, SoGLColorIndexElement, SoGLPointSizeElement, SoInt32Element, SoReplacedElement, SoListenerPositionElement, SoListenerOrientationElement, SoListenerDopplerElement, SoFloatElement, SoGLLineWidthElement, SoLineWidthElement, SoPointSizeElement, and SoListenerGainElement.
Referenced by SoFloatElement::init(), SoReplacedElement::init(), SoInt32Element::init(), SoAccumulatedElement::init(), SoOverrideElement::init(), and SoState::SoState().
|
virtual |
This method is called every time a new element is required in one of the stacks. This happens when a writable element is requested, using SoState::getElement() or indirectly SoElement::getElement(), and the depth of the current element is less than the state depth.
Override this method if your element needs to copy data from the previous top of stack. The push() method is called on the new element, and the previous element can be found using SoElement::getNextInStack().
Reimplemented in SoOverrideElement, SoAccumulatedElement, SoGLPointSizeElement, and SoGLLineWidthElement.
Referenced by SoState::getElement(), SoAccumulatedElement::push(), and SoOverrideElement::push().
This method is callled when the state is popped, and the depth of the element is bigger than the current state depth. pop() is called on the new top of stack, and a pointer to the previous top of stack is passed in prevTopElement.
Override this method if you need to copy some state information from the previous top of stack.
Reimplemented in SoGLPointSizeElement, and SoGLLineWidthElement.
Referenced by SoState::pop().
|
pure virtual |
This function returns TRUE
is the element matches another element (of the same class), with respect to cache validity.
If the application programmer's extension element has a matches() function, it should also have a copyMatchInfo() function.
Implemented in SoOverrideElement, SoInt32Element, SoFloatElement, SoReplacedElement, and SoAccumulatedElement.
|
pure virtual |
This function creates a copy of the element that contains enough information to enable the matches() function to work.
Used to help with scenegraph traversal caching operations.
Implemented in SoOverrideElement, SoAccumulatedElement, SoInt32Element, SoReplacedElement, and SoFloatElement.
|
static |
This function initializes all the built-in Coin element classes.
References SoListenerPositionElement::initClass(), SoListenerDopplerElement::initClass(), SoListenerOrientationElement::initClass(), and SoOverrideElement::initClass().
Referenced by initClass().
|
static |
Returns the number of allocated element stack index slots.
References SbPList::getLength().
Referenced by SoState::SoState().
|
static |
Returns the SoType identifier for the element class with element state stack index stackIndex.
References stackIndex.
void SoElement::setDepth | ( | const int | deptharg | ) |
Sets the depth value of the element instance in the state stack.
References depth.
Referenced by SoState::getElement(), and SoState::SoState().
int SoElement::getDepth | ( | void | ) | const |
Returns the state stack depth value of the element instance.
References depth.
Referenced by SoState::getElement().
|
virtual |
This function is for printing element information, and is used mostly for debugging purposes.
Reimplemented in SoOverrideElement, SoListenerDopplerElement, SoReplacedElement, SoListenerPositionElement, SoListenerOrientationElement, SoInt32Element, and SoFloatElement.
References SoType::getName(), SbName::getString(), and getTypeId().
|
inlinestaticprotected |
This method returns the top instance (in the state stack) of the element class with stack index stackIndex.
The retuned instance is writable. To make this instance, some lazy evaluation may have to be perfomed, so use getConstElement() instead if the instance shouldn't be modified.
If no instance is available and can not be made, NULL
is returned.
References SoState::getElement().
Referenced by SoReplacedElement::getElement(), SoInt32Element::print(), SoListenerOrientationElement::set(), SoListenerPositionElement::set(), SoFloatElement::set(), SoListenerDopplerElement::setDopplerFactor(), and SoListenerDopplerElement::setDopplerVelocity().
|
inlinestaticprotected |
This method returns a reference to the top element of the class with stack index stackIndex. The returned element is non-mutable.
(Don't try to be clever and cast away the constness – if the returned instance is modified, strange, hard to find and generally wonderful bugs will most likely start to happen.)
If no instance can be returned, NULL
is returned.
References capture(), and SoState::getConstElement().
Referenced by SoListenerOrientationElement::get(), SoListenerPositionElement::get(), SoFloatElement::get(), SoInt32Element::get(), SoListenerDopplerElement::getDopplerFactor(), SoListenerDopplerElement::getDopplerVelocity(), SoListenerOrientationElement::isSetByListener(), and SoListenerPositionElement::isSetByListener().
|
inlineprotected |
This function does whatever is necessary in the state for caching purposes. If should be called by subclasses of SoElement whenever any value in the element is accessed.
References SoState::isCacheOpen().
Referenced by getConstElement(), SoGLLineWidthElement::push(), and SoGLPointSizeElement::push().
|
protectedvirtual |
Adds the element to the cache.
Reimplemented in SoAccumulatedElement.
Referenced by SoAccumulatedElement::captureThis().
|
protected |
|
protected |
Sets the stack index in an instance. Used in constructors of derived elements.
References stackIndex.
|
staticprotected |
Returns the value of a new available stack index.
References SoTypeList::append(), SoType::canCreateInstance(), and SbPList::getLength().
|
protected |
Returns the next element down in the stack. Should be used in push() to get the previous element.
This method has a slightly misleading name, but we didn't change it to stay compatible with the original SGI Inventor API.
Referenced by SoAccumulatedElement::captureThis(), SoGLLineWidthElement::push(), SoGLPointSizeElement::push(), and SoOverrideElement::push().
|
protected |
Returns the next free element, ie the next element up in the stack.
|
staticprotected |
This is the static state stack index for the class.
Referenced by getClassStackIndex(), and initClass().
|
protected |
The element's unique SoType type identification.
Referenced by getTypeId(), and setTypeId().
|
protected |
The index in the state stack for this particular element instance.
Referenced by getIdFromStackIndex(), getStackIndex(), and setStackIndex().
|
staticprotected |
Provides mapping from state stack indices to element types.
Referenced by initClass().
|
protected |
The depth of the element instance in the state stack.
Referenced by getDepth(), and setDepth().
Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.
Generated on Fri Feb 17 2017 for Coin by Doxygen. 1.8.13