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

# SoAction.h

    00001 #ifndef COIN_SOACTION_H
    00002 #define COIN_SOACTION_H
    00003
    00004 /**************************************************************************\
    00005  *
    00006  *  This file is part of the Coin 3D visualization library.
    00007  *  Copyright (C) 1998-2003 by Systems in Motion.  All rights reserved.
    00008  *
    00009  *  This library is free software; you can redistribute it and/or
    00010  *  modify it under the terms of the GNU General Public License
    00011  *  ("GPL") version 2 as published by the Free Software Foundation.
    00012  *  See the file LICENSE.GPL at the root directory of this source
    00013  *  distribution for additional information about the GNU GPL.
    00014  *
    00015  *  For using Coin with software that can not be combined with the GNU
    00016  *  GPL, and for taking advantage of the additional benefits of our
    00017  *  support services, please contact Systems in Motion about acquiring
    00018  *  a Coin Professional Edition License.
    00019  *
    00020  *  See <URL:http://www.coin3d.org> for  more information.
    00021  *
    00022  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
    00023  *  <URL:http://www.sim.no>.
    00024  *
    00025 \**************************************************************************/
    00026
    00027 #include <Inventor/SbBasic.h>
    00028 #include <Inventor/SoType.h>
    00029 #include <Inventor/misc/SoTempPath.h>
    00030
    00031 // Include instead of using forward declarations to be compatible with
    00032 // Open Inventor (and besides, all the other action class definitions
    00033 // needs to know about these lists).
    00034 #include <Inventor/lists/SoActionMethodList.h>
    00035 #include <Inventor/lists/SoEnabledElementsList.h>
    00036
    00037 // defined in Inventor/SbBasic.h
    00038 #ifdef COIN_UNDEF_IN_PATH_HACK
    00039 #include <sys/unistd.h>
    00040 #undef IN_PATH
    00041 // Avoid problem with HPUX 10.20 C library API headers, which defines IN_PATH
    00042 // in <sys/unistd.h>.  That define destroys the SoAction::PathCode enum, and
    00043 // the preprocessor is so broken that we can't store/restore the define for
    00044 // the duration of this header file.
    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   /* These two methods are not available in the original OIV API.  The
    00135      reason they have been added is explained in SoSubAction.h for the
    00136      SO_ACTION_HEADER macro. */
    00137   static SoEnabledElementsList * getClassEnabledElements(void);
    00138   static SoActionMethodList * getClassActionMethods(void);
    00139
    00140 private:
    00141   static SoType classTypeId;
    00142   /* The enabledElements and methods variables are protected in the
    00143      original OIV API. This is not such a good idea, see the comments
    00144      in SoSubAction.h for SO_ACTION_HEADER. */
    00145   static SoEnabledElementsList * enabledElements;
    00146   static SoActionMethodList * methods;
    00147
    00148   SoTempPath currentpath;
    00149   PathCode currentpathcode;
    00150
    00151   SoActionP * pimpl;
    00152 };
    00153
    00154 // inline methods
    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