Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

SoAction.h

00001 /**************************************************************************\
00002  *
00003  *  This file is part of the Coin 3D visualization library.
00004  *  Copyright (C) 1998-2002 by Systems in Motion. All rights reserved.
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public License
00008  *  version 2.1 as published by the Free Software Foundation. See the
00009  *  file LICENSE.LGPL at the root directory of the distribution for
00010  *  more details.
00011  *
00012  *  If you want to use Coin for applications not compatible with the
00013  *  LGPL, please contact SIM to acquire a Professional Edition license.
00014  *
00015  *  Systems in Motion, Prof Brochs gate 6, 7030 Trondheim, NORWAY
00016  *  http://www.sim.no support@sim.no Voice: +47 22114160 Fax: +47 22207097
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 // Include instead of using forward declarations to be compatible with
00029 // Open Inventor (and besides, all the other action class definitions
00030 // needs to know about these lists).
00031 #include <Inventor/lists/SoActionMethodList.h>
00032 #include <Inventor/lists/SoEnabledElementsList.h>
00033 
00034 // defined in Inventor/SbBasic.h
00035 #ifdef COIN_UNDEF_IN_PATH_HACK
00036 #include <sys/unistd.h>
00037 #undef IN_PATH
00038 // Avoid problem with HPUX 10.20 C library API headers, which defines IN_PATH
00039 // in <sys/unistd.h>.  That define destroys the SoAction::PathCode enum, and
00040 // the preprocessor is so broken that we can't store/restore the define for
00041 // the duration of this header file.
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   /* These two methods are not available in the original OIV API.  The
00132      reason they have been added is explained in SoSubAction.h for the
00133      SO_ACTION_HEADER macro. */
00134   static SoEnabledElementsList * getClassEnabledElements(void);
00135   static SoActionMethodList * getClassActionMethods(void);
00136 
00137 private:
00138   static SoType classTypeId;
00139   /* The enabledElements and methods variables are protected in the
00140      original OIV API. This is not such a good idea, see the comments
00141      in SoSubAction.h for SO_ACTION_HEADER. */
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 // inline methods
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

Generated at Tue Mar 5 03:31:11 2002 for Coin by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001