Coin
4.0.3
Coin3D core library
|
The SoAction class is the base class for all traversal actions. More...
#include <Inventor/actions/SoAction.h>
Public Types | |
enum | AppliedCode { NODE = 0 , PATH = 1 , PATH_LIST = 2 } |
enum | PathCode { NO_PATH = 0 , IN_PATH = 1 , BELOW_PATH = 2 , OFF_PATH = 3 } |
Static Public Member Functions | |
static SoType | getClassTypeId (void) |
static void | initClass (void) |
static void | initClasses (void) |
static void | nullAction (SoAction *action, SoNode *node) |
Protected Member Functions | |
SoAction (void) | |
virtual void | beginTraversal (SoNode *node) |
virtual void | endTraversal (SoNode *node) |
virtual const SoEnabledElementsList & | getEnabledElements (void) const |
void | setTerminated (const SbBool flag) |
virtual SbBool | shouldCompactPathList (void) const |
Static Protected Member Functions | |
static SoActionMethodList * | getClassActionMethods (void) |
static SoEnabledElementsList * | getClassEnabledElements (void) |
Protected Attributes | |
SoState * | state |
SoActionMethodList * | traversalMethods |
The SoAction class is the base class for all traversal actions.
Applying actions is the basic mechanism in Coin for executing various operations on scene graphs or paths within scene graphs, including search operations, rendering, interaction through picking, etc.
The basic operation is to instantiate an action, set it up with miscellaneous parameters if necessary, then call its apply() method on the root node of the scene graph (or subgraph of a scene graph). The action then traverses the scene graph from the root node, depth-first and left-to-right, applying its specific processing at the nodes where it is applicable.
(The SoAction and its derived classes in Coin is an implementation of the design pattern commonly known as the "Visitor" pattern.)
Here's a simple example that shows how to use the SoWriteAction to dump a scene graph in the Inventor format to a file:
After traversal, some action types have stored information about the (sub-)scene graph that was traversed, which you can then inquire about through methods like SoGetBoundingBoxAction::getBoundingBox(), SoRayPickAction::getPickedPoint(), SoGetPrimitiveCountAction::getTriangleCount(), etc.
See the various built-in actions for further information (i.e. the subclasses of this class), or look at the example code applications of the Coin library to see how actions are generally used.
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, as well 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 source code of the built-in classes in Coin should also prove very helpful.
The following example shows the basic outline on how to set up your own extension action class:
Enumerated values for what the action was applied to.
Enumerated values for how the action is applied to a scene graph.
|
virtual |
Destructor, free resources.
|
protected |
Default constructor, does all necessary top level initialization.
|
virtual |
Applies action to the graphs defined by pathlist. If obeysrules is set to TRUE
, pathlist must obey the following four conditions (which is the case for path lists returned from search actions for non-group nodes and path lists returned from picking actions):
All paths must start at the same head node. All paths must be sorted in traversal order. The paths must be unique. No path can continue through the end point of another path.
Reimplemented in SoBoxHighlightRenderAction, SoLineHighlightRenderAction, SoReorganizeAction, SoSimplifyAction, SoToVRML2Action, SoToVRMLAction, SoVectorizeAction, and SoIntersectionDetectionAction.
Applies the action to the scene graph rooted at root.
Note that you should not apply an action to a node with a zero reference count. The behavior in that case is undefined.
Reimplemented in SoBoxHighlightRenderAction, SoLineHighlightRenderAction, SoToVRML2Action, SoToVRMLAction, SoVectorizeAction, SoIntersectionDetectionAction, SoReorganizeAction, and SoSimplifyAction.
Applies the action to the parts of the graph defined by path.
Note that an SoPath will also contain all nodes that may influence e.g. geometry nodes in the path. So for instance applying an SoGLRenderAction on an SoPath will render that path as expected in the view, where geometry will get its materials, textures, and other appearance settings correctly.
If the path ends in an SoGroup node, the action will also traverse the tail node's children.
Reimplemented in SoBoxHighlightRenderAction, SoLineHighlightRenderAction, SoReorganizeAction, SoSimplifyAction, SoToVRML2Action, SoToVRMLAction, SoVectorizeAction, and SoIntersectionDetectionAction.
This virtual method is called from SoAction::apply(), and is the entry point for the actual scene graph traversal.
It can be overridden to initialize the action at traversal start, for specific initializations in the action subclasses inheriting SoAction.
Default method just calls traverse(), which any overridden implementation of the method must do too (or call SoAction::beginTraversal()) to trigger the scene graph traversal.
Reimplemented in SoAudioRenderAction, SoCallbackAction, SoGetBoundingBoxAction, SoGetMatrixAction, SoGetPrimitiveCountAction, SoGlobalSimplifyAction, SoGLRenderAction, SoHandleEventAction, SoPickAction, SoRayPickAction, SoReorganizeAction, SoSearchAction, SoShapeSimplifyAction, SoSimplifyAction, SoToVRML2Action, SoToVRMLAction, and SoWriteAction.
This virtual method can be overridden to execute code after the scene graph traversal. Default method does nothing.
Reimplemented in SoGLRenderAction.
|
staticprotected |
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
This method not available in the original OIV API, see SoSubAction.h for explanation.
|
staticprotected |
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
This method not available in the original OIV API, see SoSubAction.h for explanation.
Returns the runtime type object associated with instances of this class.
Returns a pointer to the path generated during traversal, from the root of the traversed graph to the current node.
|
inline |
Returns the current traversal path code.
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
Reimplemented in SoCallbackAction.
|
protectedvirtual |
Returns a list of the elements used by action instances of this class upon traversal operations.
Reimplemented in SoAudioRenderAction, SoBoxHighlightRenderAction, SoCallbackAction, SoGetBoundingBoxAction, SoGetMatrixAction, SoGetPrimitiveCountAction, SoGlobalSimplifyAction, SoGLRenderAction, SoHandleEventAction, SoLineHighlightRenderAction, SoPickAction, SoRayPickAction, SoReorganizeAction, SoSearchAction, SoShapeSimplifyAction, SoSimplifyAction, SoToVRML2Action, SoToVRMLAction, SoWriteAction, SoVectorizeAction, SoVectorizePSAction, and SoIntersectionDetectionAction.
Returns a pointer to the node the action is being applied to.
If action is not being applied to a node (but a path or a path list), the method returns NULL
.
const SoPathList * SoAction::getOriginalPathListAppliedTo | ( | void | ) | const |
Returns a pointer to the original path list the action is being applied to.
If the action is not being applied to a path list (but a node or a path), the method returns NULL
.
Returns the pointer to the path the action is being applied to. The path is managed by the action instance and should not be destroyed or modified by the caller.
If action is not being applied to a path (but a node or a path list), the method returns NULL
.
SoAction::PathCode SoAction::getPathCode | ( | int & | numindices, |
const int *& | indices ) |
Returns a code that indicates where the current node lies with respect to the path(s) the action is being applied to. The arguments indices and numindices are only set if the method returns IN_PATH
.
const SoPathList * SoAction::getPathListAppliedTo | ( | void | ) | const |
Returns the pointer to the path list the action is currently being applied to. The path list is managed by the action instance and should not be destroyed or modified by the caller.
If action is not being applied to a path list (but a node or a path), the method returns NULL
.
The returned path list pointer need not be equal to the list apply() was called with, as the action may have reorganized the path list for efficiency reasons.
Returns a pointer to the state of the action instance. The state contains the current set of elements used during traversal.
Returns the type identification of an action derived from a class inheriting SoAction. This is used for runtime type checking and "downward" casting.
Usage example:
For application programmers wanting to extend the library with new actions: this method needs to be overridden in all subclasses. This is typically done as part of setting up the full type system for extension classes, which is usually accomplished by using the predefined macros available through Inventor/nodes/SoSubAction.h: SO_ACTION_SOURCE, SO_ACTION_INIT_CLASS and SO_ACTION_CONSTRUCTOR.
For more information on writing Coin extensions, see the SoAction class documentation.
Returns the actual type id of an object derived from a class inheriting SoAction. Needs to be overridden in all subclasses.
Implemented in SoAudioRenderAction, SoBoxHighlightRenderAction, SoCallbackAction, SoGetBoundingBoxAction, SoGetMatrixAction, SoGetPrimitiveCountAction, SoGlobalSimplifyAction, SoGLRenderAction, SoHandleEventAction, SoLineHighlightRenderAction, SoPickAction, SoRayPickAction, SoReorganizeAction, SoSearchAction, SoShapeSimplifyAction, SoSimplifyAction, SoToVRML2Action, SoToVRMLAction, SoWriteAction, SoVectorizeAction, SoVectorizePSAction, and SoIntersectionDetectionAction.
SoAction::AppliedCode SoAction::getWhatAppliedTo | ( | void | ) | const |
Returns a code indicating what (node, path, or path list) the action instance is being applied to.
SbBool SoAction::hasTerminated | ( | void | ) | const |
Returns TRUE
if the action was prematurely terminated.
Note that the termination flag will be FALSE
if the action simply completed its run over the scene graph in the "ordinary" fashion, i.e. was not explicitly aborted from any of the nodes in the graph.
Initializes the runtime type system for this class, and sets up the enabled elements and action method list.
Initialize all the SoAction subclasses. Automatically called from SoAction::initClass().
Invalidates the state, forcing it to be recreated at the next apply() invocation.
Reimplemented in SoGLRenderAction.
SbBool SoAction::isLastPathListAppliedTo | ( | void | ) | const |
This method is not supported in Coin. It should probably have been private in OIV.
|
virtual |
Returns TRUE
if the type of this object is either of the same type or a subclass of type.
This method is used for filling up the lookup tables with void methods.
Pops the current path, and sets the path code to prevpathcode.
This method is very internal. Do not use unless you know what you're doing.
Pops of the last child in the current path. Use this if you know the path code hasn't changed since the current path was pushed.
This method is very internal. Do not use unless you know what you're doing.
Get ready to traverse the childindex'th child. Use this method if you know the path code will not change as a result of this.
This method is very internal. Do not use unless you know what you're doing.
Get ready to traverse the childindex'th child. Use this method if the path code might change as a result of this.
This method is very internal. Do not use unless you know what you're doing.
Pushes a NULL node onto the current path. Use this before traversing all children when you know that the path code will not change while traversing children.
This method is very internal. Do not use unless you know what you're doing.
Set the termination flag.
Typically set to TRUE from nodes upon special conditions being met during scene graph traversal – like the correct node being found when doing SoSearchAction traversal or when grabbing the event from an SoHandleEventAction.
|
protectedvirtual |
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
Store our state, traverse the subgraph rooted at the given node, restore our state and continue traversal.
Store our state, traverse the given path, restore our state and continue traversal.
Traverses a scene graph rooted at node, invoking the action methods of the nodes in the graph.
This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.
|
protected |
Pointer to the traversal state instance of the action.
|
protected |
Stores the list of "nodetype to actionmethod" mappings for the particular action instance.