Coin Logo http://www.sim.no
http://www.coin3d.org

SoAction.h
1 #ifndef COIN_SOACTION_H
2 #define COIN_SOACTION_H
3 
4 /**************************************************************************\
5  *
6  * This file is part of the Coin 3D visualization library.
7  * Copyright (C) 1998-2007 by Systems in Motion. All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.GPL at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using Coin with software that can not be combined with the GNU
16  * GPL, and for taking advantage of the additional benefits of our
17  * support services, please contact Systems in Motion about acquiring
18  * a Coin Professional Edition License.
19  *
20  * See http://www.coin3d.org/ for more information.
21  *
22  * Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
23  * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24  *
25 \**************************************************************************/
26 
27 #include <Inventor/SbBasic.h>
28 #include <Inventor/SoType.h>
29 #include <Inventor/misc/SoTempPath.h>
30 
31 // Include instead of using forward declarations to be compatible with
32 // Open Inventor (and besides, all the other action class definitions
33 // needs to know about these lists).
34 #include <Inventor/lists/SoActionMethodList.h>
35 #include <Inventor/lists/SoEnabledElementsList.h>
36 
37 // defined in Inventor/SbBasic.h
38 #ifdef COIN_UNDEF_IN_PATH_HACK
39 #include <sys/unistd.h>
40 #undef IN_PATH
41 // Avoid problem with HPUX 10.20 C library API headers, which defines IN_PATH
42 // in <sys/unistd.h>. That define destroys the SoAction::PathCode enum, and
43 // the preprocessor is so broken that we can't store/restore the define for
44 // the duration of this header file.
45 #endif
46 
47 
52 #define SO_ENABLE(action, element) \
53  do { \
54  assert(!element::getClassTypeId().isBad()); \
55  action::enableElement(element::getClassTypeId(), \
56  element::getClassStackIndex()); \
57  } while (0)
58 
59 
61 class SoNode;
62 class SoPath;
63 class SoPathList;
64 class SoState;
65 class SoActionP;
66 
67 class COIN_DLL_API SoAction {
68 public:
69  enum AppliedCode { NODE = 0, PATH = 1, PATH_LIST = 2 };
70  enum PathCode { NO_PATH = 0, IN_PATH = 1, BELOW_PATH = 2, OFF_PATH = 3 };
71 
72  virtual ~SoAction();
73 
74  static void initClass(void);
75  static void initClasses(void);
76 
77  static SoType getClassTypeId(void);
78  virtual SoType getTypeId(void) const = 0;
79  virtual SbBool isOfType(SoType type) const;
80 
81 
82  virtual void apply(SoNode * root);
83  virtual void apply(SoPath * path);
84  virtual void apply(const SoPathList & pathlist, SbBool obeysrules = FALSE);
85  void apply(SoAction * beingApplied);
86  virtual void invalidateState(void);
87 
88  static void nullAction(SoAction * action, SoNode * node);
89 
90  AppliedCode getWhatAppliedTo(void) const;
91  SoNode * getNodeAppliedTo(void) const;
92  SoPath * getPathAppliedTo(void) const;
93  const SoPathList * getPathListAppliedTo(void) const;
94  const SoPathList * getOriginalPathListAppliedTo(void) const;
95 
96  SbBool isLastPathListAppliedTo(void) const;
97 
98  PathCode getPathCode(int & numindices, const int * & indices);
99 
100  void traverse(SoNode * const node);
101  SbBool hasTerminated(void) const;
102 
103  const SoPath * getCurPath(void);
104  SoState * getState(void) const;
105 
106  PathCode getCurPathCode(void) const;
107  virtual SoNode * getCurPathTail(void);
108  void usePathCode(int & numindices, const int * & indices);
109 
110  void pushCurPath(const int childindex, SoNode * node = NULL);
111  void popCurPath(const PathCode prevpathcode);
112  void pushCurPath(void);
113 
114  void popPushCurPath(const int childindex, SoNode * node = NULL);
115  void popCurPath(void);
116 
117 public:
118  void switchToPathTraversal(SoPath * path);
119  void switchToNodeTraversal(SoNode * node);
120 
121 
122 protected:
123  SoAction(void);
124 
125  virtual void beginTraversal(SoNode * node);
126  virtual void endTraversal(SoNode * node);
127  void setTerminated(const SbBool flag);
128 
129  virtual const SoEnabledElementsList & getEnabledElements(void) const;
130  virtual SbBool shouldCompactPathList(void) const;
131 
134 
135  /* These two methods are not available in the original OIV API. The
136  reason they have been added is explained in SoSubAction.h for the
137  SO_ACTION_HEADER macro. */
138  static SoEnabledElementsList * getClassEnabledElements(void);
139  static SoActionMethodList * getClassActionMethods(void);
140 
141 private:
142  static SoType classTypeId;
143  /* The enabledElements and methods variables are protected in the
144  original OIV API. This is not such a good idea, see the comments
145  in SoSubAction.h for SO_ACTION_HEADER. */
146 
147  static void atexit_cleanup(void);
148  static SoEnabledElementsList * enabledElements;
149  static SoActionMethodList * methods;
150  SoTempPath currentpath;
151  PathCode currentpathcode;
152 
153  SoActionP * pimpl;
154 };
155 
156 // inline methods
157 
158 inline SoAction::PathCode
160 {
161  return this->currentpathcode;
162 }
163 
164 inline void
165 SoAction::popCurPath(const PathCode prevpathcode)
166 {
167  this->currentpath.pop();
168  this->currentpathcode = prevpathcode;
169 }
170 
171 #endif // !COIN_SOACTION_H
SoAction::getNodeAppliedTo
SoNode * getNodeAppliedTo(void) const
Definition: SoAction.cpp:817
SoAction::initClasses
static void initClasses(void)
Definition: SoAction.cpp:424
SbPList::getLength
int getLength(void) const
Definition: SbPList.h:94
SoType::badType
static SoType badType(void)
Definition: SoType.cpp:664
SoState
The SoState class manages the Coin scenegraph traversal state data.
Definition: SoState.h:35
SoAction::usePathCode
void usePathCode(int &numindices, const int *&indices)
Definition: SoAction.cpp:1062
SoAction::hasTerminated
SbBool hasTerminated(void) const
Definition: SoAction.cpp:1018
SbList::getArrayPtr
const Type * getArrayPtr(const int start=0) const
Definition: SbList.h:168
SoAction::apply
virtual void apply(SoNode *root)
Definition: SoAction.cpp:476
SoAction::getClassEnabledElements
static SoEnabledElementsList * getClassEnabledElements(void)
Definition: SoAction.cpp:1176
SoBaseList::truncate
void truncate(const int length)
Definition: SoBaseList.cpp:156
SoAction::getClassActionMethods
static SoActionMethodList * getClassActionMethods(void)
Definition: SoAction.cpp:1188
SbList::truncate
void truncate(const int length, const int dofit=0)
Definition: SbList.h:149
SoAction::getEnabledElements
virtual const SoEnabledElementsList & getEnabledElements(void) const
Definition: SoAction.cpp:1164
SoAction::beginTraversal
virtual void beginTraversal(SoNode *node)
Definition: SoAction.cpp:1208
SoBase::getName
virtual SbName getName(void) const
Definition: SoBase.cpp:730
SoAction::getCurPath
const SoPath * getCurPath(void)
Definition: SoAction.cpp:1044
SoDebugError::postWarning
static void postWarning(const char *const source, const char *const format,...)
Definition: SoDebugError.cpp:324
SoAction
The SoAction class is the base class for all traversal actions.
Definition: SoAction.h:67
SoAction::SoAction
SoAction(void)
Definition: SoAction.cpp:357
SoPathList
The SoPathList class is a container for pointers to SoPath objects.
Definition: SoPathList.h:31
SbList::append
void append(const Type item)
Definition: SbList.h:98
SoAction::getClassTypeId
static SoType getClassTypeId(void)
Definition: SoAction.cpp:452
SoPath::containsPath
SbBool containsPath(const SoPath *const path) const
Definition: SoPath.cpp:611
SoAction::popPushCurPath
void popPushCurPath(const int childindex, SoNode *node=NULL)
Definition: SoAction.cpp:1132
SoAction::getPathAppliedTo
SoPath * getPathAppliedTo(void) const
Definition: SoAction.cpp:831
SoAction::popCurPath
void popCurPath(void)
Definition: SoAction.cpp:1152
SoAction::traversalMethods
SoActionMethodList * traversalMethods
Definition: SoAction.h:133
SoType::isDerivedFrom
SbBool isDerivedFrom(const SoType type) const
Definition: SoType.cpp:687
SoEnabledElementsList::enable
void enable(const SoType elementtype, const int stackindex)
Definition: SoEnabledElementsList.cpp:124
SoEnabledElementsList
The SoEnabledElementsList class is a container for type info for element types that are enabled in ac...
Definition: SoEnabledElementsList.h:29
SoPathList::append
void append(SoPath *const path)
Definition: SoPathList.cpp:88
SoPath
The SoPath class is a container class for traversal path descriptions.
Definition: SoPath.h:43
SoBase::getRefCount
int32_t getRefCount(void) const
Definition: SoBase.cpp:686
SoType
The SoType class is the basis for the run-time type system in Coin.
Definition: SoType.h:50
SoPath::getLength
int getLength(void) const
Definition: SoPath.cpp:473
SoEnabledElementsList::getCounter
static int getCounter(void)
Definition: SoEnabledElementsList.cpp:158
SbList
The SbList class is a template container class for lists.
Definition: SoType.h:46
SbName::getString
const char * getString(void) const
Definition: SbName.cpp:278
SoActionMethodList
The SoActionMethodList class contains function pointers for action methods.
Definition: SoActionMethodList.h:35
SbList::getLength
int getLength(void) const
Definition: SbList.h:145
SoAction::AppliedCode
AppliedCode
Definition: SoAction.h:69
SoAction::pushCurPath
void pushCurPath(void)
Definition: SoAction.cpp:1119
SoPathList::sort
void sort(void)
Definition: SoPathList.cpp:161
SoAction::getPathCode
PathCode getPathCode(int &numindices, const int *&indices)
Definition: SoAction.cpp:890
SoAction::getState
SoState * getState(void) const
Definition: SoAction.cpp:1028
SoAction::switchToNodeTraversal
void switchToNodeTraversal(SoNode *node)
Definition: SoAction.cpp:1279
SoDB::readlock
static void readlock(void)
Definition: SoDB.cpp:1828
SoBase::ref
void ref(void) const
Definition: SoBase.cpp:574
SoAction::~SoAction
virtual ~SoAction()
Definition: SoAction.cpp:375
SoAction::getWhatAppliedTo
AppliedCode getWhatAppliedTo(void) const
Definition: SoAction.cpp:805
SoAction::getPathListAppliedTo
const SoPathList * getPathListAppliedTo(void) const
Definition: SoAction.cpp:851
SoAction::getCurPathCode
PathCode getCurPathCode(void) const
Definition: SoAction.h:159
SoBase::getTypeId
virtual SoType getTypeId(void) const =0
SoAction::switchToPathTraversal
void switchToPathTraversal(SoPath *path)
Definition: SoAction.cpp:1252
SoType::createType
static const SoType createType(const SoType parent, const SbName name, const instantiationMethod method=(instantiationMethod) NULL, const uint16_t data=0)
Definition: SoType.cpp:256
SoAction::invalidateState
virtual void invalidateState(void)
Definition: SoAction.cpp:783
SoAction::isLastPathListAppliedTo
SbBool isLastPathListAppliedTo(void) const
Definition: SoAction.cpp:877
SoAction::initClass
static void initClass(void)
Definition: SoAction.cpp:392
SoPath::getIndex
int getIndex(const int index) const
Definition: SoPath.cpp:436
SoAction::getOriginalPathListAppliedTo
const SoPathList * getOriginalPathListAppliedTo(void) const
Definition: SoAction.cpp:866
SoAction::shouldCompactPathList
virtual SbBool shouldCompactPathList(void) const
Definition: SoAction.cpp:1242
SoPath::getNode
SoNode * getNode(const int index) const
Definition: SoPath.cpp:402
SoAction::endTraversal
virtual void endTraversal(SoNode *node)
Definition: SoAction.cpp:1218
SoNode
The SoNode class is the base class for nodes used in scene graphs.
Definition: SoNode.h:47
SoAction::PathCode
PathCode
Definition: SoAction.h:70
SoAction::nullAction
static void nullAction(SoAction *action, SoNode *node)
Definition: SoAction.cpp:796
SoActionMethodList::setUp
void setUp(void)
Definition: SoActionMethodList.cpp:131
SoAction::traverse
void traverse(SoNode *const node)
Definition: SoAction.cpp:902
SoAction::getCurPathTail
virtual SoNode * getCurPathTail(void)
Definition: SoAction.cpp:1053
SoAction::getTypeId
virtual SoType getTypeId(void) const =0
SoBase::unrefNoDelete
void unrefNoDelete(void) const
Definition: SoBase.cpp:665
SoNode::getActionMethodIndex
static int getActionMethodIndex(const SoType type)
Definition: SoNode.cpp:445
SoDB::readunlock
static void readunlock(void)
Definition: SoDB.cpp:1843
SoPathList::uniquify
void uniquify(void)
Definition: SoPathList.cpp:175
SoAction::setTerminated
void setTerminated(const SbBool flag)
Definition: SoAction.cpp:1233
SoAction::state
SoState * state
Definition: SoAction.h:132
SoAction::isOfType
virtual SbBool isOfType(SoType type) const
Definition: SoAction.cpp:462

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Wed Jul 24 2019 for Coin by Doxygen. 1.8.17