00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 #ifndef  _SO_STATE_
00050 #define  _SO_STATE_
00051 
00052 #include <Inventor/SoLists.h>
00053 
00054 class SoAction;
00055 class SoElement;
00056 
00074 
00075 class  SoState {
00076 
00077 public:
00082   SoState(SoAction *action, const SoTypeList &enabledElements);
00083 
00085   ~SoState();
00086 
00088   inline SoAction* getAction() const
00089   { return m_action; }
00090 
00095   template<typename T>
00096   inline T* getElement()
00097   {
00098     return static_cast<T*>(getElement(T::getClassTypeId(), T::getClassStackIndex()));
00099   }
00100 
00106   SoElement* getElement(const SoType& type, const int stackIndex);
00107 
00111   template<typename T>
00112   inline const T* getConstElement() const
00113   {
00114     return static_cast<const T*>(getConstElement(T::getClassTypeId(), T::getClassStackIndex(), true));
00115   }
00116 
00121   inline const SoElement* getConstElement(const SoType& type, const int stackIndex) const
00122   {
00123     return getConstElement(type, stackIndex, false);
00124   }
00125 
00132   void push();
00133 
00135   void pop();
00136 
00138   void print(FILE *fp);
00139 
00140 #if 1             SoDEPRECATED
00147   SoElement* getElement(const int stackIndex);SoDEPRECATED
00152   const SoElement* getConstElement(const int stackIndex) const;
00153 
00154 #endif 
00156  private:
00157 
00158   inline SbBool isElementEnabled(const SoType& type, const int stackIndex, SbBool checkType = TRUE) const
00159   {
00160     if ( !s_checkStateElementsType )
00161       return isElementEnabled(stackIndex);
00162     return isElementEnabledChecked(type,stackIndex,checkType);
00163   }
00164 
00165   
00166   inline SbBool isElementEnabled(const int stackIndex) const
00167   {
00168     if (m_stack && (stackIndex < m_numStacks))
00169       return (m_stack[stackIndex] != NULL);
00170     else
00171       return FALSE;
00172   }
00173 
00174   
00175   inline int getDepth() const
00176   { return m_depth; }
00177 
00178   
00179   
00180   
00181   inline void setCacheOpen(const SbBool flag)
00182   { m_cacheOpen = flag; }
00183 
00184   inline SbBool isCacheOpen() const
00185   { return m_cacheOpen; }
00186 
00193   template<typename T>
00194   inline T* getElementNoPush() const
00195   {
00196     return static_cast<T*>(getElementNoPush(T::getClassTypeId(), T::getClassStackIndex()));
00197   }
00198 
00205   inline SoElement* getElementNoPush(SoType type, const int stackIndex) const
00206   {
00207     return const_cast<SoElement*>(getConstElement(type, stackIndex, true));
00208   }
00209 
00210   
00211   
00212   
00213   
00214   void popElement(const int classStackIndex) ;
00215 
00220   inline const SoElement* getConstElement(const SoType& type, const int stackIndex, bool checkType) const
00221   {
00222     if ( !m_stack )
00223       return NULL;
00224     enableMissingElement(type, stackIndex, checkType);
00225     return m_stack[stackIndex];
00226   }
00227 
00228   inline const SoElement* getTopElement() const { return m_topElement; }
00229 
00233   void insertElement( SoElement* );
00234 
00235 #if 1             SoDEPRECATED
00238   SoElement* getElementNoPush(const int stackIndex) const;
00239 
00240 #endif 
00242 private:
00243 
00249   void enableSendToGL(bool enable);
00250 
00256   bool isSendToGLEnabled() const;
00257 
00258 private:
00259 
00261   SbBool isElementEnabledChecked(const SoType& type, const int stackIndex, SbBool checkType = TRUE) const;
00262 
00264   SoType getBestElementType(const SoType& type) const;
00265 
00267   void createDepth0Element(int stackIndex);
00268 
00270   void displayStack();
00271 
00273   void checkStateConsistency();
00274 
00276   void enableMissingElement(const SoType& type, int stackIndex, bool checkType) const;
00277 
00278   SoAction            *m_action;        
00279   int                 m_depth;          
00280   SoElement           **m_stack;        
00281   int                 m_numStacks;      
00282   SoElement *         m_topElement;     
00283 
00284   SbBool              m_cacheOpen;      
00285   bool                m_enableSendToGL; 
00287   bool m_usingGLAction;
00288 
00290   static int s_checkStateConsistency;
00291   static int s_displayStateElements;
00292   static int s_checkStateElementsType;
00293   static bool s_printStateDepth;
00294   static FILE* s_stateDepthFile;
00295 };
00296 
00297 #endif  
00298 
00299 
00300