Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoState.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2018 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49#ifndef _SO_STATE_
50#define _SO_STATE_
51
52#include <Inventor/SoLists.h>
53
54class SoAction;
55class SoElement;
56
74SoEXTENDER_Documented class SoState {
75
76public:
81 SoState(SoAction *action, const SoTypeList &enabledElements);
82
85
87 inline SoAction* getAction() const
88 { return m_action; }
89
94 template<typename T>
95 inline T* getElement()
96 {
97 return static_cast<T*>(getElement(T::getClassTypeId(), T::getClassStackIndex()));
98 }
99
105 SoElement* getElement(const SoType& type, const int stackIndex);
106
111 template<typename T>
112 inline const T* getConstElement() const
113 {
114 return static_cast<const T*>(getConstElement(T::getClassTypeId(), T::getClassStackIndex(), true));
115 }
116
121 inline const SoElement* getConstElement(const SoType& type, const int stackIndex) const
122 {
123 return getConstElement(type, stackIndex, false);
124 }
125
132 void push();
133
135 void pop();
136
138 void print(FILE *fp);
139
140#if 1 SoDEPRECATED
147 SoElement* getElement(const int stackIndex);SoDEPRECATED
152 const SoElement* getConstElement(const int stackIndex) const;
153
154#endif
156 private:
157
159 class PushPop
160 {
161 public:
162 PushPop(SoState* state) : m_state(state) { m_state->push(); }
163 ~PushPop() { m_state->pop(); }
164 private:
165 SoState* m_state;
166 };
167
168
170 inline SbBool isElementEnabled(const SoType& type, const int stackIndex, SbBool checkType = TRUE) const
171 {
172 if ( !s_checkStateElementsType )
173 return isElementEnabled(stackIndex);
174 return isElementEnabledChecked(type,stackIndex,checkType);
175 }
176
177 // Returns TRUE if element with given stack index is enabled in state
178 inline SbBool isElementEnabled(const int stackIndex) const
179 {
180 if (m_stack && (stackIndex < m_numStacks))
181 return (m_stack[stackIndex] != NULL);
182 else
183 return FALSE;
184 }
185
186 // Returns current depth of state
187 inline int getDepth() const
188 { return m_depth; }
189
190 // Sets/returns flag that indicates whether a cache is open. This
191 // flag lets us optimize element capturing; we don't need to try
192 // to capture elements if the flag is FALSE.
193 inline void setCacheOpen(const SbBool flag)
194 { m_cacheOpen = flag; }
195
196 inline SbBool isCacheOpen() const
197 { return m_cacheOpen; }
198
203 inline bool trackDependencies(bool flag)
204 {
205 bool oldValue = m_trackElementsDependencies;
206 m_trackElementsDependencies = flag;
207 return oldValue;
208 }
209
211 bool isTrackingDependencies() const;
212
219 template<typename T>
220 inline T* getElementNoPush() const
221 {
222 return static_cast<T*>(getElementNoPush(T::getClassTypeId(), T::getClassStackIndex()));
223 }
224
231 inline SoElement* getElementNoPush(SoType type, const int stackIndex) const
232 {
233 return const_cast<SoElement*>(getConstElement(type, stackIndex, true));
234 }
235
236 // Internal-only.
237 // Pops from the an element corresponding to classStackIndex.
238 // Only the side effect of popping is done (ie. the element is not
239 // removed from the stack).
240 void popElement(const int classStackIndex) ;
241
246 inline const SoElement* getConstElement(const SoType& type, const int stackIndex, bool checkType) const
247 {
248 //This method must be fast, it is called very often so avoid
249 //testing for m_stask, it can't be NULL (set at contructor and deleted
250 //in destructor only)
251 const SoElement* elt = stackIndex < m_numStacks ? m_stack[stackIndex] : NULL;
252 if ( elt == NULL )
253 {
254 enableMissingElement(type, stackIndex, checkType);
255 return m_stack[stackIndex];
256 }
257
258 return elt;
259 }
260
261 inline const SoElement* getTopElement() const { return m_topElement; }
262
266 void insertElement( SoElement* );
267
268#if 1 SoDEPRECATED
271 SoElement* getElementNoPush(const int stackIndex) const;
272
273#endif
275private:
276
282 void enableSendToGL(bool enable);
283
289 bool isSendToGLEnabled() const;
290
291private:
292
294 SbBool isElementEnabledChecked(const SoType& type, const int stackIndex, SbBool checkType = TRUE) const;
295
297 SoType getBestElementType(const SoType& type) const;
298
300 void createDepth0Element(int stackIndex);
301
303 void displayStack(const char *funcStr);
304
306 void checkStateConsistency(const char *funcStr);
307
309 void enableMissingElement(const SoType& type, int stackIndex, bool checkType) const;
310
311 SoAction *m_action; // Action instance state is in
312 int m_depth; // Current depth
313 SoElement **m_stack; // Array of element stacks
314 int m_numStacks; // Number of stacks in array
315 SoElement * m_topElement; // First element in threaded stack
316
317 SbBool m_cacheOpen; // TRUE if a cache is open
318 bool m_enableSendToGL; // send to OpenGL activation flag
319 bool m_trackElementsDependencies;
320
322 bool m_actionNeedDependencies;
323
325 bool m_usingGLAction;
326
328 static int s_checkStateConsistency;
329 static int s_displayStateElements;
330 static int s_checkStateElementsType;
331 static bool s_printStateDepth;
332 static FILE* s_stateDepthFile;
333};
334
335#endif /* _SO_STATE_ */
336
337
Abstract base class for all actions.
Definition SoAction.h:132
Abstract base class for all state elements.
Definition SoElement.h:102
Traversal state.
Definition SoState.h:74
T * getElement()
Returns a writable instance of the element on the top of the stack with the given type.
Definition SoState.h:95
void push()
Pushes (saves) the current state until a pop() restores it.
SoDEPRECATED SoElement * getElement(const int stackIndex)
Returns a writable instance of the element on the top of the stack with the given stack index.
SoAction * getAction() const
Returns the action instance the state is part of.
Definition SoState.h:87
const T * getConstElement() const
Returns the top (read-only) instance of the given element.
Definition SoState.h:112
void print(FILE *fp)
Prints state to file (for debugging)
~SoState()
Destructor.
SoState(SoAction *action, const SoTypeList &enabledElements)
Constructor.
void pop()
Pops the state, restoring the state to just before the last push().
SoDEPRECATED const SoElement * getConstElement(const int stackIndex) const
Returns the top (read-only) instance of the given element stack.
SoElement * getElement(const SoType &type, const int stackIndex)
Returns a writable instance of the element on the top of the stack with the given index and type.
const SoElement * getConstElement(const SoType &type, const int stackIndex) const
Returns the top (read-only) instance of the given element stack.
Definition SoState.h:121
Stores runtime type information.
Definition SoType.h:98
Maintains a list of SoTypes.
Definition SoTypeList.h:72
int SbBool
Boolean type.
Definition SbBase.h:87