Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/actions/SoAction.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.1.1.1 $
00045  |
00046  |   Description:
00047  |      Defines the SoAction class and related classes.
00048  |
00049  |   Author(s)          : Paul S. Strauss, Gavin Bell
00050  |
00051  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00052  _______________________________________________________________________
00053  */
00054 
00055 #ifndef  _SO_ACTION_
00056 #define  _SO_ACTION_
00057 
00058 #include <Inventor/system/SbSystem.h>
00059 #include <Inventor/misc/SoBasic.h>
00060 #include <Inventor/misc/SoTempPath.h>
00061 #include <Inventor/SoPath.h>
00062 
00064 class SoAction;
00065 class SoCompactPathList;
00066 class SoNode;
00067 class SoState;
00068 class SoLightPath;
00069 
00070 typedef void    (*SoActionMethod)(SoAction *, SoNode *);
00071 
00072 
00080 
00081 SoINTERNAL class INVENTOR_API SoActionMethodList : public SbPList {
00082 
00083   public:
00085     SoActionMethodList(SoActionMethodList *parentList);
00086 
00090     SoActionMethod &    operator [](int i) const
00091         { return ((SoActionMethod &)((*(const SbPList *)this)[i])); }
00092 
00094     void                addMethod(SoType nodeType, SoActionMethod method);
00095     
00098     void                setUp();
00099 
00100   private:
00101     SoActionMethod      parentMethod(SoType);   
00102     SoActionMethodList  *parent;
00103     int                 numValidTypes;   
00104 
00105 
00107     static void         dummyAction(SoAction *, SoNode *);
00108 
00109 };
00110 
00120 
00121 SoINTERNAL class INVENTOR_API SoEnabledElementsList {
00122 
00123   public:
00125     SoEnabledElementsList(SoEnabledElementsList *parentList);
00126 
00129     const SoTypeList &  getElements() const;
00130 
00132     void                enable(SoType elementType, int stackIndex);
00133 
00136     void                merge(const SoEnabledElementsList &list);
00137 
00140     static int          getCounter()            { return counter; }
00141 
00142   private:
00146     static int          counter;
00147 
00150     int                 setUpCounter;
00151 
00154     SoTypeList          elements;
00155 
00158     SoEnabledElementsList       *parent;
00159 };
00160 
00161 
00164 
00177 
00178 
00179 class INVENTOR_API SoAction {
00180 
00181   public:
00182 
00184     virtual ~SoAction();
00185 
00187     static SoType       getClassTypeId()
00188                             { return classTypeId; }
00189 
00191     virtual SoType      getTypeId() const = 0;
00192 
00200     SbBool              isOfType(SoType type) const;
00201 
00202     
00204     virtual void        apply(SoNode *node);
00205 
00207     virtual void        apply(SoPath *path);
00208 
00221     virtual void        apply(const SoPathList &pathList,
00222                               SbBool obeysRules = FALSE);
00223 
00227     virtual void        invalidateState();
00228     
00229   SoEXTENDER public:
00230 
00232     static void         nullAction(SoAction *, SoNode *);
00233 
00235     enum AppliedCode {
00236         NODE,                   
00237         PATH,                   
00238         PATH_LIST               
00239     };
00240 
00243     enum PathCode {
00244         NO_PATH,                
00245         IN_PATH,                
00246         BELOW_PATH,             
00247         OFF_PATH                
00248     };
00249 
00251     AppliedCode         getWhatAppliedTo() const   { return appliedTo.code; }
00252 
00256     SoNode *            getNodeAppliedTo() const  { return appliedTo.node; }
00257     SoPath *            getPathAppliedTo() const  { return appliedTo.path; }
00262     const SoPathList *  getPathListAppliedTo() const
00263         { return appliedTo.pathList; }
00264     const SoPathList *  getOriginalPathListAppliedTo() const
00265         { return appliedTo.origPathList; }
00266     SbBool              isLastPathListAppliedTo() const
00267         { return appliedTo.isLastPathList; }
00268 
00275     PathCode    getPathCode(int &numIndices, const int *&indices)
00276         {   if (appliedTo.curPathCode == IN_PATH) {
00277                 usePathCode(numIndices, indices);
00278             }
00279             return appliedTo.curPathCode;
00280         }
00281 
00282 
00284     void                traverse(SoNode *node);
00285 
00287     SbBool              hasTerminated() const   { return terminated; }
00288 
00292     const SoPath *      getCurPath();
00293 
00295     SoState *           getState() const        { return state; }
00296 
00297   SoINTERNAL public:
00298     static void         initClass();
00299 
00301     static void         initClasses();
00302 
00310     PathCode            getCurPathCode() const { return appliedTo.curPathCode;}
00311     void                pushCurPath(int childIndex);
00312     void                popCurPath(PathCode prevPathCode);
00314     virtual SoNode *    getCurPathTail();                       
00315 
00317     void                usePathCode(int &numIndices, const int *&indices);
00318 
00319 
00320 
00323     void                pushCurPath()
00324                         { curPath.append(-1); }
00325     void                popPushCurPath(int childIndex)
00326                         { curPath.setTail(childIndex);}
00327     void                popCurPath()
00328                         { curPath.pop(); }
00329 
00330   protected:
00332     SoAction();
00333 
00335     virtual const SoEnabledElementsList & getEnabledElements() const;
00336 
00340     virtual void        beginTraversal(SoNode *node);
00341 
00344     void                setTerminated(SbBool flag)      { terminated = flag; }
00345 
00354     virtual SbBool      shouldCompactPathLists() const;
00355 
00356   SoINTERNAL protected:    
00357     SoState             *state;         
00358 
00361     SoActionMethodList  *traversalMethods;
00362 
00364     static SoEnabledElementsList *enabledElements;
00365 
00367     static SoActionMethodList *methods;
00368 
00369   private:
00370     static SoType       classTypeId;            
00371 
00375     struct AppliedTo {
00376         AppliedCode             code;
00377         SoNode                  *node;          
00378         SoPath                  *path;          
00379         const SoPathList        *pathList;      
00380         const SoPathList        *origPathList;
00381         SoCompactPathList       *compactPathList;
00382         int                     isLastPathList;
00383         PathCode                curPathCode;
00384     }                   appliedTo;
00385 
00388     SbBool              isBeingApplied;
00389 
00392     SoLightPath         curPath;
00393 
00396     SoTempPath  *       tempPath;
00397  
00398 
00401     int                 enabledElementsCounter;
00402 
00404     SbBool              terminated;
00405 
00408     int                 index;
00409 
00411     void                setUpState();
00412 
00414     void                cleanUp();
00415 
00417     void                splitPathList(const SoPathList &sortedList,
00418                                       const SoPathList &origPathList);
00419 
00421     void                apply(const SoPathList &sortedList,
00422                               const SoPathList &origPathList,
00423                               SbBool isLastPathList);
00424 
00425 friend class SoDB;
00426 };
00427 
00435 
00436 #define SO_ENABLE(actionClass, elementClass)                            \
00437         actionClass::enableElement(elementClass::getClassTypeId(),      \
00438                                    elementClass::getClassStackIndex())
00439 
00442 
00443 #endif /* _SO_ACTION_ */