Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://coin3d.github.io
https://www.kongsberg.com/en/kogt/
SoWriteAction Class Reference

The SoWriteAction class writes a scene graph to file. More...

#include <Inventor/actions/SoWriteAction.h>

Inheritance diagram for SoWriteAction:
SoAction

Public Member Functions

virtual SoType getTypeId (void) const
 
 SoWriteAction (void)
 
 SoWriteAction (SoOutput *out)
 
virtual ~SoWriteAction (void)
 
SoOutputgetOutput (void) const
 
void continueToApply (SoNode *node)
 
void continueToApply (SoPath *path)
 
- Public Member Functions inherited from SoAction
virtual ~SoAction (void)
 
virtual SbBool isOfType (SoType type) const
 
virtual void apply (SoNode *root)
 
virtual void apply (SoPath *path)
 
virtual void apply (const SoPathList &pathlist, SbBool obeysrules=FALSE)
 
void apply (SoAction *beingApplied)
 
virtual void invalidateState (void)
 
AppliedCode getWhatAppliedTo (void) const
 
SoNodegetNodeAppliedTo (void) const
 
SoPathgetPathAppliedTo (void) const
 
const SoPathListgetPathListAppliedTo (void) const
 
const SoPathListgetOriginalPathListAppliedTo (void) const
 
SbBool isLastPathListAppliedTo (void) const
 
PathCode getPathCode (int &numindices, const int *&indices)
 
void traverse (SoNode *const node)
 
SbBool hasTerminated (void) const
 
const SoPathgetCurPath (void)
 
SoStategetState (void) const
 
PathCode getCurPathCode (void) const
 
virtual SoNodegetCurPathTail (void)
 
void usePathCode (int &numindices, const int *&indices)
 
void pushCurPath (const int childindex, SoNode *node=NULL)
 
void popCurPath (const PathCode prevpathcode)
 
void pushCurPath (void)
 
void popPushCurPath (const int childindex, SoNode *node=NULL)
 
void popCurPath (void)
 
void switchToPathTraversal (SoPath *path)
 
void switchToNodeTraversal (SoNode *node)
 

Static Public Member Functions

static SoType getClassTypeId (void)
 
static void addMethod (const SoType type, SoActionMethod method)
 
static void enableElement (const SoType type, const int stackindex)
 
static void initClass (void)
 
- Static Public Member Functions inherited from SoAction
static void initClass (void)
 
static void initClasses (void)
 
static SoType getClassTypeId (void)
 
static void nullAction (SoAction *action, SoNode *node)
 

Protected Member Functions

virtual const SoEnabledElementsListgetEnabledElements (void) const
 
virtual void beginTraversal (SoNode *node)
 
virtual SbBool shouldCompactPathLists (void) const
 
- Protected Member Functions inherited from SoAction
 SoAction (void)
 
virtual void endTraversal (SoNode *node)
 
void setTerminated (const SbBool flag)
 
virtual SbBool shouldCompactPathList (void) const
 

Static Protected Member Functions

static SoEnabledElementsListgetClassEnabledElements (void)
 
static SoActionMethodListgetClassActionMethods (void)
 
- Static Protected Member Functions inherited from SoAction
static SoEnabledElementsListgetClassEnabledElements (void)
 
static SoActionMethodListgetClassActionMethods (void)
 

Additional Inherited Members

- Public Types inherited from SoAction
enum  AppliedCode { NODE = 0, PATH = 1, PATH_LIST = 2 }
 
enum  PathCode { NO_PATH = 0, IN_PATH = 1, BELOW_PATH = 2, OFF_PATH = 3 }
 
- Protected Attributes inherited from SoAction
SoStatestate
 
SoActionMethodListtraversalMethods
 

Detailed Description

The SoWriteAction class writes a scene graph to file.

When applied to a scene, this action writes its contents to the stream contained within an SoOutput instance. This can be a file, a memory buffer or a system file handle like stdout, for instance.

All information considered part of the scene graph should be written out, including not only nodes, but also the nodes' field values, global fields (at least those with connections inside the scene the action is applied to), engines in the scene, paths, etc.

The scene is written in the Open Inventor file format. Files in this format can be parsed into their scene graph structures by using the SoDB::readAll() method (SoDB also contains a few other import methods you can use).

Here's a complete, standalone usage example which shows how to write a scene graph to a memory buffer:

#include <Inventor/SoDB.h>
#include <Inventor/actions/SoWriteAction.h>
#include <Inventor/nodes/SoCone.h>
#include <Inventor/nodes/SoSeparator.h>
static char * buffer;
static size_t buffer_size = 0;
static void *
buffer_realloc(void * bufptr, size_t size)
{
buffer = (char *)realloc(bufptr, size);
buffer_size = size;
return buffer;
}
static SbString
buffer_writeaction(SoNode * root)
{
SoOutput out;
buffer = (char *)malloc(1024);
buffer_size = 1024;
out.setBuffer(buffer, buffer_size, buffer_realloc);
SoWriteAction wa(&out);
wa.apply(root);
SbString s(buffer);
free(buffer);
return s;
}
int
main(int argc, char ** argv)
{
SoSeparator * root = new SoSeparator;
root->ref();
root->addChild(new SoCone);
SbString s = buffer_writeaction(root);
(void)fprintf(stdout, "%s\n", s.getString());
root->unref();
return 0;
}
See also
SoOutput

Constructor & Destructor Documentation

◆ SoWriteAction() [1/2]

SoWriteAction::SoWriteAction ( void  )

Default constructor. Output will be written to stdout in ASCII format.

◆ SoWriteAction() [2/2]

SoWriteAction::SoWriteAction ( SoOutput out)

Constructor. Output will be written via the out object.

◆ ~SoWriteAction()

SoWriteAction::~SoWriteAction ( void  )
virtual

Destructor.

Member Function Documentation

◆ getTypeId()

SoType SoWriteAction::getTypeId ( void  ) const
virtual

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:

void bar(SoAction * action)
{
if (action->getTypeId() == SoGLRenderAction::getClassTypeId()) {
// safe downward cast, know the type
SoGLRenderAction * glrender = (SoGLRenderAction *)action;
}
return; // ignore if not render action
}

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.

Implements SoAction.

◆ addMethod()

void SoWriteAction::addMethod ( const SoType  type,
SoActionMethod  method 
)
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ enableElement()

void SoWriteAction::enableElement ( const SoType  type,
const int  stackindex 
)
static

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

◆ getEnabledElements()

const SoEnabledElementsList & SoWriteAction::getEnabledElements ( void  ) const
protectedvirtual

Returns a list of the elements used by action instances of this class upon traversal operations.

Reimplemented from SoAction.

◆ getOutput()

SoOutput * SoWriteAction::getOutput ( void  ) const

Returns a pointer to the SoOutput object we're using when writing the scene graph.

◆ continueToApply() [1/2]

void SoWriteAction::continueToApply ( SoNode node)

Applies the write method to the subgraph starting at node with the current SoOutput instance, without resetting any of the internal state of the action instance.

This should normally be for internal use only.

◆ continueToApply() [2/2]

void SoWriteAction::continueToApply ( SoPath path)

Applies the write method to path with the current SoOutput instance, without resetting any of the internal state of the action instance.

This should normally be for internal use only.

◆ beginTraversal()

void SoWriteAction::beginTraversal ( SoNode node)
protectedvirtual

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

◆ shouldCompactPathLists()

SbBool SoWriteAction::shouldCompactPathLists ( void  ) const
protectedvirtual

This API member is considered internal to the library, as it is not likely to be of interest to the application programmer.

Compact path lists are not implemented in Coin (yet), but if they are, SoWriteAction should return FALSE here – it would only be extra overhead for the SoWriteAction to have path lists compacted before traversal.

Seems like a silly optimization to me, though.. :^/ 20000306 mortene.


The documentation for this class was generated from the following files: