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