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 SoEXTENDER_Documented class SoState {
00075
00076 public:
00081 SoState(SoAction *action, const SoTypeList &enabledElements);
00082
00084 ~SoState();
00085
00087 inline SoAction* getAction() const
00088 { return m_action; }
00089
00094 template<typename T>
00095 inline T* getElement()
00096 {
00097 return static_cast<T*>(getElement(T::getClassTypeId(), T::getClassStackIndex()));
00098 }
00099
00105 SoElement* getElement(const SoType& type, const int stackIndex);
00106
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
00159 class PushPop
00160 {
00161 public:
00162 PushPop(SoState* state) : m_state(state) { m_state->push(); }
00163 ~PushPop() { m_state->pop(); }
00164 private:
00165 SoState* m_state;
00166 };
00167
00168
00170 inline SbBool isElementEnabled(const SoType& type, const int stackIndex, SbBool checkType = TRUE) const
00171 {
00172 if ( !s_checkStateElementsType )
00173 return isElementEnabled(stackIndex);
00174 return isElementEnabledChecked(type,stackIndex,checkType);
00175 }
00176
00177
00178 inline SbBool isElementEnabled(const int stackIndex) const
00179 {
00180 if (m_stack && (stackIndex < m_numStacks))
00181 return (m_stack[stackIndex] != NULL);
00182 else
00183 return FALSE;
00184 }
00185
00186
00187 inline int getDepth() const
00188 { return m_depth; }
00189
00190
00191
00192
00193 inline void setCacheOpen(const SbBool flag)
00194 { m_cacheOpen = flag; }
00195
00196 inline SbBool isCacheOpen() const
00197 { return m_cacheOpen; }
00198
00203 inline bool trackDependencies(bool flag)
00204 {
00205 bool oldValue = m_trackElementsDependencies;
00206 m_trackElementsDependencies = flag;
00207 return oldValue;
00208 }
00209
00211 bool isTrackingDependencies() const;
00212
00219 template<typename T>
00220 inline T* getElementNoPush() const
00221 {
00222 return static_cast<T*>(getElementNoPush(T::getClassTypeId(), T::getClassStackIndex()));
00223 }
00224
00231 inline SoElement* getElementNoPush(SoType type, const int stackIndex) const
00232 {
00233 return const_cast<SoElement*>(getConstElement(type, stackIndex, true));
00234 }
00235
00236
00237
00238
00239
00240 void popElement(const int classStackIndex) ;
00241
00246 inline const SoElement* getConstElement(const SoType& type, const int stackIndex, bool checkType) const
00247 {
00248
00249
00250
00251 const SoElement* elt = stackIndex < m_numStacks ? m_stack[stackIndex] : NULL;
00252 if ( elt == NULL )
00253 {
00254 enableMissingElement(type, stackIndex, checkType);
00255 return m_stack[stackIndex];
00256 }
00257
00258 return elt;
00259 }
00260
00261 inline const SoElement* getTopElement() const { return m_topElement; }
00262
00266 void insertElement( SoElement* );
00267
00268 #if 1 SoDEPRECATED
00271 SoElement* getElementNoPush(const int stackIndex) const;
00272
00273 #endif
00275 private:
00276
00282 void enableSendToGL(bool enable);
00283
00289 bool isSendToGLEnabled() const;
00290
00291 private:
00292
00294 SbBool isElementEnabledChecked(const SoType& type, const int stackIndex, SbBool checkType = TRUE) const;
00295
00297 SoType getBestElementType(const SoType& type) const;
00298
00300 void createDepth0Element(int stackIndex);
00301
00303 void displayStack(const char *funcStr);
00304
00306 void checkStateConsistency(const char *funcStr);
00307
00309 void enableMissingElement(const SoType& type, int stackIndex, bool checkType) const;
00310
00311 SoAction *m_action;
00312 int m_depth;
00313 SoElement **m_stack;
00314 int m_numStacks;
00315 SoElement * m_topElement;
00316
00317 SbBool m_cacheOpen;
00318 bool m_enableSendToGL;
00319 bool m_trackElementsDependencies;
00320
00322 bool m_actionNeedDependencies;
00323
00325 bool m_usingGLAction;
00326
00328 static int s_checkStateConsistency;
00329 static int s_displayStateElements;
00330 static int s_checkStateElementsType;
00331 static bool s_printStateDepth;
00332 static FILE* s_stateDepthFile;
00333 };
00334
00335 #endif
00336
00337
00338