00001 #ifndef COIN_SOACTION_H
00002 #define COIN_SOACTION_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <Inventor/SbBasic.h>
00028 #include <Inventor/SoType.h>
00029 #include <Inventor/misc/SoTempPath.h>
00030
00031
00032
00033
00034 #include <Inventor/lists/SoActionMethodList.h>
00035 #include <Inventor/lists/SoEnabledElementsList.h>
00036
00037
00038 #ifdef COIN_UNDEF_IN_PATH_HACK
00039 #include <sys/unistd.h>
00040 #undef IN_PATH
00041
00042
00043
00044
00045 #endif
00046
00047
00052 #define SO_ENABLE(action, element) \
00053 do { \
00054 assert(!element::getClassTypeId().isBad()); \
00055 action::enableElement(element::getClassTypeId(), \
00056 element::getClassStackIndex()); \
00057 } while (0)
00058
00059
00060 class SoEnabledElementsList;
00061 class SoNode;
00062 class SoPath;
00063 class SoPathList;
00064 class SoState;
00065 class SoActionP;
00066
00067 class COIN_DLL_API SoAction {
00068 public:
00069 enum AppliedCode { NODE = 0, PATH = 1, PATH_LIST = 2 };
00070 enum PathCode { NO_PATH = 0, IN_PATH = 1, BELOW_PATH = 2, OFF_PATH = 3 };
00071
00072 virtual ~SoAction();
00073
00074 static void initClass(void);
00075 static void initClasses(void);
00076
00077 static SoType getClassTypeId(void);
00078 virtual SoType getTypeId(void) const = 0;
00079 virtual SbBool isOfType(SoType type) const;
00080
00081
00082 virtual void apply(SoNode * root);
00083 virtual void apply(SoPath * path);
00084 virtual void apply(const SoPathList & pathlist, SbBool obeysrules = FALSE);
00085 virtual void invalidateState(void);
00086
00087 static void nullAction(SoAction * action, SoNode * node);
00088
00089 AppliedCode getWhatAppliedTo(void) const;
00090 SoNode * getNodeAppliedTo(void) const;
00091 SoPath * getPathAppliedTo(void) const;
00092 const SoPathList * getPathListAppliedTo(void) const;
00093 const SoPathList * getOriginalPathListAppliedTo(void) const;
00094
00095 SbBool isLastPathListAppliedTo(void) const;
00096
00097 PathCode getPathCode(int & numindices, const int * & indices);
00098
00099 void traverse(SoNode * const node);
00100 SbBool hasTerminated(void) const;
00101
00102 const SoPath * getCurPath(void);
00103 SoState * getState(void) const;
00104
00105 PathCode getCurPathCode(void) const;
00106 virtual SoNode * getCurPathTail(void);
00107 void usePathCode(int & numindices, const int * & indices);
00108
00109 void pushCurPath(const int childindex, SoNode * node = NULL);
00110 void popCurPath(const PathCode prevpathcode);
00111 void pushCurPath(void);
00112
00113 void popPushCurPath(const int childindex, SoNode * node = NULL);
00114 void popCurPath(void);
00115
00116 public:
00117 void switchToPathTraversal(SoPath * path);
00118 void switchToNodeTraversal(SoNode * node);
00119
00120
00121 protected:
00122 SoAction(void);
00123
00124 virtual void beginTraversal(SoNode * node);
00125 virtual void endTraversal(SoNode * node);
00126 void setTerminated(const SbBool flag);
00127
00128 virtual const SoEnabledElementsList & getEnabledElements(void) const;
00129 virtual SbBool shouldCompactPathList(void) const;
00130
00131 SoState * state;
00132 SoActionMethodList * traversalMethods;
00133
00134
00135
00136
00137 static SoEnabledElementsList * getClassEnabledElements(void);
00138 static SoActionMethodList * getClassActionMethods(void);
00139
00140 private:
00141 static SoType classTypeId;
00142
00143
00144
00145 static SoEnabledElementsList * enabledElements;
00146 static SoActionMethodList * methods;
00147
00148 SoTempPath currentpath;
00149 PathCode currentpathcode;
00150
00151 SoActionP * pimpl;
00152 };
00153
00154
00155
00156 inline SoAction::PathCode
00157 SoAction::getCurPathCode(void) const
00158 {
00159 return this->currentpathcode;
00160 }
00161
00162 inline void
00163 SoAction::popCurPath(const PathCode prevpathcode)
00164 {
00165 this->currentpath.pop();
00166 this->currentpathcode = prevpathcode;
00167 }
00168
00169 #endif // !COIN_SOACTION_H