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 void apply(SoAction * beingApplied);
00086 virtual void invalidateState(void);
00087
00088 static void nullAction(SoAction * action, SoNode * node);
00089
00090 AppliedCode getWhatAppliedTo(void) const;
00091 SoNode * getNodeAppliedTo(void) const;
00092 SoPath * getPathAppliedTo(void) const;
00093 const SoPathList * getPathListAppliedTo(void) const;
00094 const SoPathList * getOriginalPathListAppliedTo(void) const;
00095
00096 SbBool isLastPathListAppliedTo(void) const;
00097
00098 PathCode getPathCode(int & numindices, const int * & indices);
00099
00100 void traverse(SoNode * const node);
00101 SbBool hasTerminated(void) const;
00102
00103 const SoPath * getCurPath(void);
00104 SoState * getState(void) const;
00105
00106 PathCode getCurPathCode(void) const;
00107 virtual SoNode * getCurPathTail(void);
00108 void usePathCode(int & numindices, const int * & indices);
00109
00110 void pushCurPath(const int childindex, SoNode * node = NULL);
00111 void popCurPath(const PathCode prevpathcode);
00112 void pushCurPath(void);
00113
00114 void popPushCurPath(const int childindex, SoNode * node = NULL);
00115 void popCurPath(void);
00116
00117 public:
00118 void switchToPathTraversal(SoPath * path);
00119 void switchToNodeTraversal(SoNode * node);
00120
00121
00122 protected:
00123 SoAction(void);
00124
00125 virtual void beginTraversal(SoNode * node);
00126 virtual void endTraversal(SoNode * node);
00127 void setTerminated(const SbBool flag);
00128
00129 virtual const SoEnabledElementsList & getEnabledElements(void) const;
00130 virtual SbBool shouldCompactPathList(void) const;
00131
00132 SoState * state;
00133 SoActionMethodList * traversalMethods;
00134
00135
00136
00137
00138 static SoEnabledElementsList * getClassEnabledElements(void);
00139 static SoActionMethodList * getClassActionMethods(void);
00140
00141 private:
00142 static SoType classTypeId;
00143
00144
00145
00146 static SoEnabledElementsList * enabledElements;
00147 static SoActionMethodList * methods;
00148
00149 SoTempPath currentpath;
00150 PathCode currentpathcode;
00151
00152 SoActionP * pimpl;
00153 };
00154
00155
00156
00157 inline SoAction::PathCode
00158 SoAction::getCurPathCode(void) const
00159 {
00160 return this->currentpathcode;
00161 }
00162
00163 inline void
00164 SoAction::popCurPath(const PathCode prevpathcode)
00165 {
00166 this->currentpath.pop();
00167 this->currentpathcode = prevpathcode;
00168 }
00169
00170 #endif // !COIN_SOACTION_H