Open Inventor Reference
SoAction.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37
38/*
39 * Copyright (C) 1990,91 Silicon Graphics, Inc.
40 *
41 _______________________________________________________________________
42 ______________ S I L I C O N G R A P H I C S I N C . ____________
43 |
44 | $Revision: 1.1.1.1 $
45 |
46 | Description:
47 | Defines the SoAction class and related classes.
48 |
49 | Author(s) : Paul S. Strauss, Gavin Bell
50 |
51 ______________ S I L I C O N G R A P H I C S I N C . ____________
52 _______________________________________________________________________
53 */
54
55#ifndef _SO_ACTION_
56#define _SO_ACTION_
57
61#include <Inventor/SoPath.h>
62
64class SoAction;
66class SoNode;
67class SoState;
69
70typedef void (*SoActionMethod)(SoAction *, SoNode *);
71
72
80
82
83 public:
86
91 { return ((SoActionMethod &)((*(const SbPList *)this)[i])); }
92
94 void addMethod(SoType nodeType, SoActionMethod method);
95
98 void setUp();
99
100 private:
101 SoActionMethod parentMethod(SoType);
102 SoActionMethodList *parent;
103 int numValidTypes;
105
107 static void dummyAction(SoAction *, SoNode *);
108
109};
110
120
122
123 public:
126
129 const SoTypeList & getElements() const;
130
132 void enable(SoType elementType, int stackIndex);
133
136 void merge(const SoEnabledElementsList &list);
137
140 static int getCounter() { return counter; }
141
142 private:
146 static int counter;
147
150 int setUpCounter;
151
154 SoTypeList elements;
155
158 SoEnabledElementsList *parent;
159};
160
161
164
178
180
181 public:
182
184 virtual ~SoAction();
185
188 { return classTypeId; }
189
191 virtual SoType getTypeId() const = 0;
192
200 bool isOfType(SoType type) const;
201
202
204 virtual void apply(SoNode *node);
205
207 virtual void apply(SoPath *path);
208
221 virtual void apply(const SoPathList &pathList,
222 bool obeysRules = FALSE);
223
227 virtual void invalidateState();
228
229 SoEXTENDER public:
230
232 static void nullAction(SoAction *, SoNode *);
233
238 PATH_LIST
239 };
240
243 enum PathCode {
247 OFF_PATH
248 };
249
251 AppliedCode getWhatAppliedTo() const { return appliedTo.code; }
252
256 SoNode * getNodeAppliedTo() const { return appliedTo.node; }
257 SoPath * getPathAppliedTo() const { return appliedTo.path; }
263 { return appliedTo.pathList; }
265 { return appliedTo.origPathList; }
267 { return appliedTo.isLastPathList; }
268
275 PathCode getPathCode(int &numIndices, const int *&indices)
276 { if (appliedTo.curPathCode == IN_PATH) {
277 usePathCode(numIndices, indices);
278 }
279 return appliedTo.curPathCode;
280 }
281
282
284 void traverse(SoNode *node);
285
287 bool hasTerminated() const { return terminated; }
288
293
295 SoState * getState() const { return state; }
296
297 SoINTERNAL public:
298 static void initClass();
299
301 static void initClasses();
302
310 PathCode getCurPathCode() const { return appliedTo.curPathCode;}
311 void pushCurPath(int childIndex);
312 void popCurPath(PathCode prevPathCode);
314 virtual SoNode * getCurPathTail();
315
317 void usePathCode(int &numIndices, const int *&indices);
318
319
320
324 { curPath.append(-1); }
325 void popPushCurPath(int childIndex)
326 { curPath.setTail(childIndex);}
328 { curPath.pop(); }
329
332 const SoLightweightPath& getCurrentLightweightPath() const { return curPath; }
333
337 void setCurrentLightweightPath(const SoLightweightPath& path) { curPath = path; }
338
339 protected:
342
345
349 virtual void beginTraversal(SoNode *node);
350
353 void setTerminated(bool flag) { terminated = flag; }
354
363 virtual bool shouldCompactPathLists() const;
364
365 SoINTERNAL protected:
367
371
374
377
378 private:
379 static SoType classTypeId;
380
384 struct AppliedTo {
385 AppliedCode code;
386 SoNode *node;
387 SoPath *path;
388 const SoPathList *pathList;
389 const SoPathList *origPathList;
390 SoCompactPathList *compactPathList;
391 bool isLastPathList;
392 PathCode curPathCode;
393 } appliedTo;
394
397 bool isBeingApplied;
398
401 SoLightweightPath curPath;
402
405 SoTempPath * tempPath;
406
407
410 int enabledElementsCounter;
411
413 bool terminated;
414
417 int index;
418
420 void setUpState();
421
423 void cleanUp();
424
426 void splitPathList(const SoPathList &sortedList,
427 const SoPathList &origPathList);
428
430 void apply(const SoPathList &sortedList,
431 const SoPathList &origPathList,
432 bool isLastPathList);
433
434friend class SoDB;
435};
436
444
445#define SO_ENABLE(actionClass, elementClass) \
446 actionClass::enableElement(elementClass::getClassTypeId(), \
447 elementClass::getClassStackIndex())
448
451
452#endif /* _SO_ACTION_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition SbBasic.h:154
#define FALSE
Definition SbBasic.h:79
#define SoINTERNAL
Definition SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition SbSystem.h:77
void(* SoActionMethod)(SoAction *, SoNode *)
Definition SoAction.h:70
List of generic (void *) pointers.
Definition SbPList.h:78
void *& operator[](int i) const
Returns pointer with given index.
Definition SbPList.h:123
Internal class.
Definition SoAction.h:81
void setUp()
This MUST be called before using the list.
void addMethod(SoType nodeType, SoActionMethod method)
Add a method to the appropriate place in the list.
SoActionMethodList(SoActionMethodList *parentList)
Constructor. Pass in list from parent action.
Abstract base class for all actions.
Definition SoAction.h:179
bool hasTerminated() const
Returns TRUE if the traversal has reached a termination condition.
Definition SoAction.h:287
PathCode
This enum may be used during traversal of nodes to indicate where the node is with respect to the pat...
Definition SoAction.h:243
@ NO_PATH
Not traversing a path.
Definition SoAction.h:244
@ IN_PATH
In middle of path chain (not tail node)
Definition SoAction.h:245
@ BELOW_PATH
Tail node of path or below tail node.
Definition SoAction.h:246
bool isLastPathListAppliedTo() const
Definition SoAction.h:266
void setTerminated(bool flag)
Allows subclass instance to indicate that traversal has reached a termination condition.
Definition SoAction.h:353
AppliedCode getWhatAppliedTo() const
Returns code indicating what action is being applied to.
Definition SoAction.h:251
AppliedCode
This enum is used to determine what the action is being applied to.
Definition SoAction.h:235
@ NODE
Applied to graph rooted by a node.
Definition SoAction.h:236
@ PATH
Applied to graph defined by a path.
Definition SoAction.h:237
bool isOfType(SoType type) const
Returns TRUE if this instance is of the type specified in type or is derived from that type.
const SoPath * getCurPath()
Returns a pointer to the path accumulated during traversal, i.e., the chain of nodes from the root of...
SoNode * getNodeAppliedTo() const
These returns a pointer to the node, path, or path list the action is being applied to.
Definition SoAction.h:256
void pushCurPath()
Optimized versions of push/pop when we know path codes won't change:
Definition SoAction.h:323
SoState * getState() const
Get the state from the action.
Definition SoAction.h:295
static SoActionMethodList * methods
... and the methods
Definition SoAction.h:376
virtual void apply(SoNode *node)
virtual void beginTraversal(SoNode *node)
Begins traversal of an action at the given node.
const SoPathList * getOriginalPathListAppliedTo() const
Definition SoAction.h:264
virtual const SoEnabledElementsList & getEnabledElements() const
Returns the list of enabled elements for a given action subclass.
virtual void invalidateState()
Invalidates the current traversal state in the action, forcing it to be recreated when the action is ...
SoState * state
Traversal state.
Definition SoAction.h:366
void setCurrentLightweightPath(const SoLightweightPath &path)
Sets the current "light" path.
Definition SoAction.h:337
static void initClass()
virtual ~SoAction()
Destructor.
virtual void apply(const SoPathList &pathList, bool obeysRules=FALSE)
Initiates an action on the graph defined either by a node, path, or list of paths.
PathCode getPathCode(int &numIndices, const int *&indices)
Returns path code based on where current node (the node at the end of the current path) lies with res...
Definition SoAction.h:275
virtual bool shouldCompactPathLists() const
This method is used when applying an action to an SoPathList.
PathCode getCurPathCode() const
These methods maintain the current path accumulated so far during traversal.
Definition SoAction.h:310
void pushCurPath(int childIndex)
static SoType getClassTypeId()
Returns the type identifier for this class.
Definition SoAction.h:187
void popCurPath()
Definition SoAction.h:327
virtual SoType getTypeId() const =0
Returns the type identifier for a specific instance.
SoAction()
Constructor.
SoPath * getPathAppliedTo() const
Definition SoAction.h:257
void traverse(SoNode *node)
Does traversal of a graph rooted by a node.
void usePathCode(int &numIndices, const int *&indices)
called by inline getPathCode:
const SoLightweightPath & getCurrentLightweightPath() const
Returns the current "light" path.
Definition SoAction.h:332
virtual SoNode * getCurPathTail()
This is virtual, so that SoCallbackAction can use current node.
static SoEnabledElementsList * enabledElements
Holds list of enabled elements for the SoAction class.
Definition SoAction.h:373
static void nullAction(SoAction *, SoNode *)
Null action method that can be stored in lookup table when desired.
static void initClasses()
Initialize ALL Inventor action classes.
void popPushCurPath(int childIndex)
Definition SoAction.h:325
void popCurPath(PathCode prevPathCode)
virtual void apply(SoPath *path)
const SoPathList * getPathListAppliedTo() const
A single path list may be split into several, one for each different head node.
Definition SoAction.h:262
SoActionMethodList * traversalMethods
The list of what to do when.
Definition SoAction.h:370
This class represents a list of paths (like an SoPathList) in a more compact form.
Scene graph database class.
Definition SoDB.h:115
Internal class.
Definition SoAction.h:121
void merge(const SoEnabledElementsList &list)
Enables all elements from the given list that are not already enabled in this one.
static int getCounter()
Returns the current setting of the global counter used to determine when lists are out of date.
Definition SoAction.h:140
SoEnabledElementsList(SoEnabledElementsList *parentList)
Constructor.
const SoTypeList & getElements() const
Returns list of elements.
void enable(SoType elementType, int stackIndex)
Adds an element to the list if it's not already in it.
A SoLightweightPath is a light-weight version of an SoTempPath, intended to be used just to keep trac...
Definition SoPath.h:350
Abstract base class for all database nodes.
Definition SoNode.h:103
Maintains a list of pointers to paths.
Definition SoLists.h:212
Path that points to a list of hierarchical nodes.
Definition SoPath.h:109
An SoState collects and holds state while traversing a scene graph.
Definition SoState.h:82
This class is internal to Inventor.
Definition SoTempPath.h:74
Maintains a list of SoTypes.
Definition SoLists.h:295
SoType has no virtual functions to keep it small...
Definition SoType.h:103