Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoElement.h
Go to the documentation of this file.
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-2019 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_ELEMENT
51#define _SO_ELEMENT
52
53#include <Inventor/SbPImpl.h>
54#include <Inventor/SoType.h>
58#include <assert.h>
59
60class SoNotList;
61
62
63#ifndef HIDDEN_FROM_DOC
64//Max expected key, smaller than full range to optimize use in bitset
65#define SO_ELEMENT_MAX_KEY 512
66#endif
67
68SO_PIMPL_PUBLIC_DECLARATION(SoGLCacheList)
69
70
103
104 public:
105
110 virtual void push(SoState *state);
111
116 virtual void pop(SoState *state, const SoElement *prevTopElement);
117
121 virtual void print(FILE *fp) const;
122
127
131 virtual SoType getTypeId() const { return typeId; }
132
133private:
134
140 virtual void commonInit();
141
146 virtual void init(SoState *state);
147
153 virtual SbBool matches(const SoElement* elt) const = 0;
154
159 virtual SoElement* copyMatchInfo() const = 0;
160
164 SoElement* getNextInStack() const { return nextInStack; }
165
166 private:
167 typedef uint16_t SoElementKeyType;
168 // Create a new key
169 static SoElementKeyType createElementKey();
170
174 virtual SoElementKeyType getElementKey() const
175 {
176 return badElementKey();
177 }
178
182 static SoElementKeyType badElementKey();
183
184 // Initialize ALL Inventor element classes
185 static void initElements();
186 static void exitElements();
187
189 inline bool isTrackingSetterGetterNodes() const
190 {
191 return m_trackSetterGetterNodes;
192 }
193
194 virtual int getClassStackIndexInternal() const = 0;
195
196 // Initializes the SoElement class
197 static void initClass();
198 static void exitClass();
199
200 // get max element key value
201 static int maxElementKey() { return s_nextElementKey; }
202
203 // Returns the number of stack indices allocated
204 static int getNumStackIndices();
205
206 // Returns the id for the element with the given stack index
207 static SoType getIdFromStackIndex(int stackIndex);
208
209 // Returns the stack index for an element instance
210 inline int getStackIndex() const { return stackIndex; }
211
212 // Sets stackIndex in instance
213 void setStackIndex(int index) { stackIndex = index; }
214
215 // Sets stuff in an element instance
216 void setDepth(int dpth) { depth = dpth; }
217 void setNext(SoElement *nxt) { next = nxt; }
218 void setNextInStack(SoElement *nxt) { nextInStack = nxt; }
219 void setNextFree(SoElement *nxt) { nextFree = nxt; }
220
221 // Returns stuff from element instance
222 int getDepth() const { return depth; }
223 SoElement* getNext() const { return next; }
224
225 static const SoElement* getStackElement(SoState *state, const SoType& type, int stackIndex);
226
234 static const SoElement* getConstElement(SoState *state, const SoType& type, int stackIndex);
235
240 template<typename T>
241 static const T* getConstElement(SoState *state)
242 {
243 return static_cast<const T*>(getConstElement(state, T::getClassTypeId(), T::getClassStackIndex()));
244 }
245
246 // Sets/Gets the pop priority.
247 // Higher priority will be popped first.
248 void setPopPriority(unsigned short priority) {m_popPriority = priority ;}
249 unsigned short getPopPriority() const { return m_popPriority ; }
250
251 // Destructor
252 virtual ~SoElement();
253
254 // This is called when a referenced SoBase (path, field, node, whatever) is
255 // deleted. All subclasses must implement this to do the right
256 // thing in case of reference to any SoBase object.
257 virtual void dyingReference() {} ;
258
264 inline SoType getInstanceTypeId() const
265 {
266 // if this assert is triggered it means that SO_SUB_ELEMENT macro
267 // are not use/defined correctly: setTypeId(classTypeId) has not
268 // been called in element constructor (see constructor code above)
269 assert(typeId!=SoType::badType());
270 return typeId;
271 }
272
273#if 1 SoDEPRECATED
280 static const SoElement* getConstElement(SoState *state, int stackIndex);
281SoDEPRECATED
283 static const SoElement* getStackElement(SoState *state, int stackIndex);
284
285#endif
287 private:
289 SoElement();
290
296 template<typename T>
297 static T* getElement(SoState *state)
298 {
299 return static_cast<T*>(getElement(state, T::getClassTypeId(), T::getClassStackIndex()));
300 }
301
306 static SoElement* getElement(SoState *state, const SoType& type, int stackIndex);
307
308 // Does whatever is necessary in state to capture this element for
309 // caching purposes. Should be called by subclasses whenever
310 // any value in the element is accessed.
311 void capture(SoState *state) const
312 {
313 if ( state->isCacheOpen() )
314 captureThis(state);
315 }
316
317 // Really captures this element, once it has been determined that
318 // a cache is open to capture it
319 virtual void captureThis(SoState *state) const;
320
321 // Sets typeId in instance
322 void setTypeId(SoType id) { typeId = id; }
323
324
325 // Returns next free element in a specific element stack
326 SoElement* getNextFree() const { return nextFree; }
327
328 inline void setPopped(SbBool flag) { m_popped = (flag == TRUE); }
329 inline SbBool isPopped() const { return m_popped ; }
330
335 static int getClassStackIndex();
336
342#if 1 SoDEPRECATED
345 static SoElement* getElement(SoState *state, int stackIndex);
346
347#endif
349 SoINTERNAL private:
350 // Creates and returns a new stack index
351 // used internally whille registering an element in the database
352 static int createStackIndex(const SoType& id);
353
355 inline void trackSetterGetterNodes(bool flag)
356 {
357 m_trackSetterGetterNodes = flag;
358 }
359
360 private:
365 SoElement* insertAtDepth(SoElement* elt, int depth);
366
367 SoElement* replaceElement(SoState* state, SoElement* oldElt, SoElement* newElt);
368
369 void updateNextInStackAndFree(SoElement* oldElt, SoElement* newElt);
370
371 // nextInStack and nextFree are the pointers in a doubly-linked
372 // list for each stack in the state. nextInStack points toward
373 // the bottom of the stack and nextFree points toward the top of
374 // the stack. Once a stack has been fully allocated, pushing
375 // becomes simply following the nextFree pointer and popping
376 // becomes following the nextInStack pointer.
377
378 SoElement *nextInStack; // Next element of same type on stack
379 SoElement *nextFree; // Next free element
380 SoElement *next; // Next element in all-element
381
382 static int classStackIndex; // Stack index for SoElement class
383
384 // Stack index stuff
385 static int nextStackIndex; // Next stack index to allocate
386
387 static SoTypeList *stackToType; // Correlates stack index to type id
388 int stackIndex; // Stack index for instance
389 int depth; // Stack depth of element
390
391 // Type identifier stuff
392 static SoType classTypeId; // Type identifier for SoElement class
393 SoType typeId; // Type identifier for instance
394
395 // Other per-instance stuff
396 // stack
397 unsigned short m_popPriority ; // Stores the pop priority.
398 bool m_popped ; // Indicates if the element has been popped.
399
404 bool m_trackSetterGetterNodes;
405
406 friend class SoState;
407 friend class SoCache;
408 friend class SoBoundingBoxCache;
409 friend class inventor::impl::SoGLCacheListImpl;
410 friend class SoGLViewingMatrixElement;
411
412 //Insure increment of key while initing element class
413 static SoElementKeyType s_nextElementKey;
414};
415
416#endif /* _SO_ELEMENT */
417
418
#define SoEXTENDER_Documented
#define SoINTERNAL
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
static int getClassStackIndex()
Returns the stack id for this element.
SO_PIMPL_PUBLIC_DECLARATION(SoFileDataAdapter)
static void init()
Abstract base class for all state elements.
Definition SoElement.h:102
virtual void print(FILE *fp) const
Prints element (for debugging).
static SoType getClassTypeId()
Returns type identifier for SoElement class.
virtual SoType getTypeId() const
Returns type identifier for element instance.
Definition SoElement.h:131
virtual void pop(SoState *state, const SoElement *prevTopElement)
Pops element.
virtual void push(SoState *state)
Pushes element.
Traversal state.
Definition SoState.h:74
Stores runtime type information.
Definition SoType.h:98
static SoType badType()
Returns an always-illegal type.
Definition SoType.h:124
Maintains a list of SoTypes.
Definition SoTypeList.h:72
Base class for object storing runtime type information.
int SbBool
Boolean type.
Definition SbBase.h:87