# 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   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   /* These two methods are not available in the original OIV API.  The
    00136      reason they have been added is explained in SoSubAction.h for the
    00137      SO_ACTION_HEADER macro. */
    00138   static SoEnabledElementsList * getClassEnabledElements(void);
    00139   static SoActionMethodList * getClassActionMethods(void);
    00140
    00141 private:
    00142   static SoType classTypeId;
    00143   /* The enabledElements and methods variables are protected in the
    00144      original OIV API. This is not such a good idea, see the comments
    00145      in SoSubAction.h for SO_ACTION_HEADER. */
    00146   static SoEnabledElementsList * enabledElements;
    00147   static SoActionMethodList * methods;
    00148
    00149   SoTempPath currentpath;
    00150   PathCode currentpathcode;
    00151
    00152   SoActionP * pimpl;
    00153 };
    00154
    00155 // inline methods
    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