Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoAction.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** Modified by : Gavin Bell (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2023 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51#ifndef _SO_ACTION_
52#define _SO_ACTION_
53
54#include <Inventor/SoLists.h>
55#include <Inventor/SoTypedObject.h>
56#include <Inventor/SoPath.h>
57#include <Inventor/STL/cassert>
58#include <SoDeprecationRules.h>
59#include <Inventor/misc/SoTempPath.h>
60#include <Inventor/misc/SoCompactPathList.h>
61
62class SoEnabledElementsList;
63class SoActionMethodList;
64class SoSceneManager;
65class SoMultiPassManager;
66class SoTraversalPass;
67class SoActionImpl;
68
69#ifdef _WIN32
70#pragma warning(push)
71#pragma warning(disable:4251)
72#endif
73
132class SoAction: public SoTypedObject {
133
134 public:
138 virtual ~SoAction();
139
144
153 virtual void apply(SoNode *node);
154
163 virtual void apply(SoPath *path);
164
177 virtual void apply(const SoPathList &pathList,
178 SbBool obeysRules = FALSE);
179
189 virtual void clearApplyResult() {};
190
196 virtual void invalidateState();
197
205 { m_continueInBranchFlag = FALSE; }
206
213 { return m_continueInBranchFlag; }
214
219 { m_continueInBranchFlag = TRUE; }
220
228 void useAlternateRep(const SbBool enable);
229
235
243 { m_sceneManager = mgr; }
244
249 { return m_sceneManager; }
250
271 virtual void forwardTraversal( SoNode* node );
272
277 virtual void forwardTraversal( SoPath* path );
278
279 // SoEXTENDER section: the following methods are dedicated to extend the toolkit only
280 public:
281
294
301 { return m_distribMode; }
302
307 static void nullAction(SoAction *, SoNode *);
308
321
337
342 AppliedCode getWhatAppliedTo() const { return appliedTo.code; }
343
349 SoNode * getNodeAppliedTo() const { return appliedTo.node.ptr(); }
350
356 SoPath * getPathAppliedTo() const { return appliedTo.path.ptr(); }
357
367 { return appliedTo.pathList; }
368
378 { return appliedTo.origPathList; }
379
388 { return appliedTo.isLastPathList; }
389
402 PathCode getPathCode(int &numIndices, const int *&indices)
403 { if (appliedTo.curPathCode == IN_PATH) {
404 usePathCode(numIndices, indices);
405 }
406 return appliedTo.curPathCode;
407 }
408
412 PathCode getPathCodeMI(int &numIndices, const int *&indices, const int *&instanceIndices)
413 {
414 if (appliedTo.curPathCode == IN_PATH) {
415 usePathCodeMI(numIndices, indices, instanceIndices);
416 }
417 return appliedTo.curPathCode;
418 }
419
424 void traverse(SoNode *node);
425
430 SbBool hasTerminated() const { return terminated; }
431
439
447 { return m_state; }
448
449 // Changed to virtual so that derived actions that need to do
450 // things to the state such as the GLRenderAction. This action
451 // needs to change the value of whatChanged to ALL if the state has
452 // been recreated because the number of elements has changed.
453
461 virtual void setUpState();
462
468 virtual const SoEnabledElementsList & getEnabledElements() const;
469
475 void setPipeId( int id )
476 { m_pipeId = id; }
477
483 int getPipeId() const
484 { return m_pipeId; }
485
490 bool isBeingApplied() { return m_isBeingApplied; }
491
499 virtual bool preDelayedTraversal()
500 { return true; }
501
509 virtual void postDelayedTraversal()
510 {}
511
512 private:
513 static void initClass();
514 static void exitClass();
515
516 // Initialize ALL Inventor action classes
517 static void initClasses();
518 static void exitClasses();
519
521 virtual bool isEnabledElement( const SoType& ) const;
522
523 // These methods maintain the current path accumulated so far
524 // during traversal. The action needs to know whether this path is
525 // a subset of the path being applied to; it saves this info in
526 // the onPath variable. Before a node is pushed onto the current
527 // path, call getOnPath() to determine the current setting. The
528 // value of this flag should be passed in to popCurPath() so the
529 // onPath variable can be restored.
530 PathCode getCurPathCode() const { return appliedTo.curPathCode;}
531 // lastFound is an inout parameter that contains the last indices found in the compactPathList
532 // for the current separator. When iterating over children of a separator it
533 // should be set to 0 on first call then the returned result has to be reused until the last
534 // call for the separator.
535 void pushCurPath(int childIndex, int &lastFound);
536 // lastFound is an inout parameter that contains the last indices found in the compactPathList
537 // for the current separator. When iterating over children of a separator it
538 // should be set to 0 on first call then the returned result has to be reused until the last
539 // call for the separator.
540 void pushCurPathMI(int childIndex, int &lastFound, int instanceIndex);
541 void popCurPath(PathCode prevPathCode);
542 // This is virtual, so that SoCallbackAction can use current node.
543 virtual SoNode * getCurPathTail();
544
545 // ask if action is currently forward traversed
546 bool isForwardTraversing() const { return appliedTo.isForwardTraversing; }
547
548 // get the public node if action is forward traversed
549 SoNode* getForwardTraversalCaller() const { return appliedTo.forwardTraversalCaller.ptr(); }
550
551 // called by inline getPathCode:
552 void usePathCode(int &numIndices, const int *&indices);
553 // called by inline getPathCode:
554 void usePathCodeMI(int &numIndices, const int *&indices, const int *&instanceIndices);
555
556 // Optimized versions of push/pop when we know path codes won't
557 // change:
558 void pushCurPath()
559 { curPath.append(-1); }
560 void popPushCurPath(int childIndex)
561 { curPath.setTail(childIndex);}
562 // generalization for multi-instancing
563 void popPushCurPathMI(int childIndex, int instanceIndex)
564 { curPath.setTail(childIndex, instanceIndex);}
565 void popCurPath()
566 { curPath.pop(); }
567
568 // Returns true if the state has been reset since action traversal startup
569 // ie. setupState recreated the state because of some new elements enabled.
570 SbBool hasChangedState() const
571 { return m_hasStateChanged; }
572#if 1 SoDEPRECATED
577 virtual void switchToNodeTraversal( SoNode* node );
578SoDEPRECATED
583 void switchToPathTraversal( SoPath* path )
584 {
585 forwardTraversal( path );
586 }
587#endif
590 DistribMode getDistribMode() { return m_distribMode; }
591
592
593 // Enter critical section for this action
594 inline void lock()
595 { m_criticalSection->lock(); }
596
597 // Exit critical section for this action
598 inline void unlock()
599 { m_criticalSection->unlock(); }
600
601
609 inline bool isAbortable() const
610 { return m_isAbortable; }
611
615 inline void setAbortable(bool flag)
616 { m_isAbortable = flag; }
617
622 bool shouldAbort() const;
623
636 void abort();
637
641 bool isAborted() const;
642
643 private:
644 // Constructor
645 SoAction();
646
647 // WARNING : Copy constructor should never be called.
648 // WARNING : Implemented here only to add a debug message to derived class.
649 SoAction(const SoAction&);
650
651 // Begins traversal of an action at the given node. The default
652 // method just calls traverse(node). This is virtual to allow
653 // subclasses to do extra work before or after traversing the node.
654 virtual void beginTraversal(SoNode *node);
655
656 // Ends traversal of an action at the given node. By default
657 // nothing is gone
658 virtual void endTraversal(SoNode *) { ; }
659
660 // Allows subclass instance to indicate that traversal has reached
661 // a termination condition
662 void setTerminated(SbBool flag) { terminated = flag; }
663
664 // This method is used when applying an action to an SoPathList.
665 // It returns TRUE if the action should create a compact version
666 // of the path list before applying itself to it. The default
667 // method returns TRUE, since the compact version is more
668 // efficient. Some actions may choose to return FALSE; for
669 // example, the SoWriteAction applies itself to each path
670 // separately, so it doesn't need the extra overhead of compacting
671 // the list.
672 virtual SbBool shouldCompactPathLists() const;
673
678 void setDistribMode(DistribMode mode )
679 { m_distribMode = mode; }
680
681SoINTERNAL private:
682
683 // Holds list of enabled elements for the SoAction class
684 static SoEnabledElementsList *enabledElements;
685
686 // ... and the methods
687 static SoActionMethodList *methods;
688
689 SoLightPath* getCurLightPath()
690 { return &curPath; }
691
692 private:
693
694 virtual SoActionMethodList* getActionMethods();
695 SbBool getUseAlternateRep() const
696 { return m_useAlternatRep; }
697
698 SbBool isForcedUseAlternateRep() const
699 { return m_forceUseAlternateRep; }
700
701 SoMultiPassManager* getMultiPassManager() const
702 { return m_multiPassManager; }
703
704 bool isApplyingDelayed() const;
705
706 SoActionImpl* getImpl() { return m_impl; }
707
708 private:
709 // Current Traversal state
710 SoState* m_state;
711
712 // Type identifier
713 static SoType classTypeId;
714 static bool s_defaultAlternateRepUsage;
715
716 // Critical section use in multi-thread to protect the action state
717 SbThreadMutex* m_criticalSection;
718
719 // This indicates if we must stop this action in the current Scene Graph branch
720 SbBool m_continueInBranchFlag;
721
722 // This is the current path through the graph the action is being applied to
723 SoLightPath curPath;
724
725 SbBool m_hasStateChanged;
726
727 // Current Distribution mode (ScaleViz Cluster)
728 DistribMode m_distribMode;
729
730 // This structure holds the necessary information about what the
731 // action is being applied to. It allows this information to be
732 // saved and restored when necessary.
733 struct AppliedTo {
734 AppliedCode code;
735 SoRef<SoNode> node; // If code is NODE
736 SoRef<SoPath> path; // If code is PATH
737 const SoPathList *pathList; // If code is PATH_LIST
738 const SoPathList *origPathList;
739 SoRef<SoCompactPathList> compactPathList;
740 int isLastPathList;
741 PathCode curPathCode;
742 bool isForwardTraversing; // true if the action is inside a forward traversal
743 SoRef<SoNode> forwardTraversalCaller; // node that call forwardTraversal, if any.
744
745 // Default Constructor
746 AppliedTo();
747 } appliedTo;
748
749 // This is set to TRUE while the action is being applied, so we
750 // can tell if the action is being applied recursively.
751 bool m_isBeingApplied;
752
753 // Indicate if we should ask for alternate representation or not
754 // default is FALSE.
755 SbBool m_useAlternatRep;
756
757 // Indicate if we force for using alternate representation or not
758 // default is FALSE.
759 SbBool m_forceUseAlternateRep;
760
761 // This holds the current path (nodes and childindices) whenever
762 // action->getCurPath is called:
763 SoRef<SoTempPath> tempPath;
764
765
766 // Holds enabled-elements counter when state is created; used to
767 // determine whether list of enabled elements is up to date.
768 int enabledElementsCounter;
769
770 // This is TRUE if the action has reached a termination condition
771 SbBool terminated;
772
773 // Stores next index in path being applied to so a pointer to it
774 // can be returned
775 int index;
776
777
778 // Cleans up after an action is done
779 void cleanUp();
780
781 // Splits a sorted path list based on head nodes, then applies to each
782 void splitPathList(const SoPathList &sortedList,
783 const SoPathList &origPathList);
784
785 // Applies action to sorted path list
786 void apply(const SoPathList &sortedList,
787 const SoPathList &origPathList,
788 SbBool isLastPathList);
789
790 int m_pipeId; // this render action pipe id
791
792 SoSceneManager* m_sceneManager;
793
794 SoMultiPassManager* m_multiPassManager;
795
796 bool m_isAbortable;
797
798 SoActionImpl* m_impl;
799
800 friend class SoDB;
801 friend class SoMultiPassElement;
802};
803
804#ifndef HIDDEN_FROM_DOC
806//
807// Classes can use this macro to enable a specific element class
808// within a specific action class. E.g.:
809//
810// SO_ENABLE(SoGetBoundingBoxAction, SoModelMatrixElement);
811//
812
813#define SO_ENABLE(actionClass, elementClass) \
814 if ( elementClass::getClassTypeId().isBad() ) \
815 elementClass::initClass(); \
816 actionClass::enableElement(elementClass::getClassTypeId(), \
817 elementClass::getClassStackIndex())
818
819//
821
822#include <Inventor/lists/SoActionMethodList.h>
823#include <Inventor/lists/SoEnabledElementsList.h>
824
825#endif // HIDDEN_FROM_DOC
826
827#ifdef _WIN32
828#pragma warning(pop)
829#endif
830
831#endif /* _SO_ACTION_ */
832
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
int lock()
Locks the current thread on this mutex.
int unlock()
Relinquishes ownership of this mutex.
Abstract base class for all actions.
Definition SoAction.h:132
virtual void setUpState()
Creates state if it is NULL or it is no longer valid because new elements have been enabled since it ...
PathCode
This enum may be used during traversal of nodes to indicate where the node is with respect to the pat...
Definition SoAction.h:327
@ NO_PATH
Not traversing a path.
Definition SoAction.h:329
@ IN_PATH
In middle of path chain (not tail node)
Definition SoAction.h:331
@ OFF_PATH
None of the above (Probably to the left)
Definition SoAction.h:335
@ BELOW_PATH
Tail node of path or below tail node.
Definition SoAction.h:333
AppliedCode getWhatAppliedTo() const
Returns code indicating what action is being applied to.
Definition SoAction.h:342
void setSceneManager(SoSceneManager *mgr)
Set the scene manager associated with this action (if any ).
Definition SoAction.h:242
SbBool getContinueActionInBranchFlag() const
This function indicates if the action must stop in the current branch.
Definition SoAction.h:212
AppliedCode
This enum is used to determine what the action is being applied to.
Definition SoAction.h:313
@ NODE
Applied to graph rooted by a node.
Definition SoAction.h:315
@ PATH
Applied to graph defined by a path.
Definition SoAction.h:317
@ PATH_LIST
Applied to graphs defined by list of paths.
Definition SoAction.h:319
virtual void clearApplyResult()
When applied, an action may reference nodes or create objects (e.g.
Definition SoAction.h:189
const SoPath * getCurPath()
Returns the path accumulated during traversal, i.e., the chain of nodes from the root of the traverse...
virtual bool preDelayedTraversal()
Method called by SoMultiPassManager before delayed pass traversals.
Definition SoAction.h:499
SoNode * getNodeAppliedTo() const
Returns the node the action is being applied to.
Definition SoAction.h:349
SoState * getState() const
Gets the state from the action.
Definition SoAction.h:446
virtual void apply(SoNode *node)
Initiates an action on the graph defined by a node.
SoSceneManager * getSceneManager() const
Return the SoSceneManager associated with this action.
Definition SoAction.h:248
PathCode getPathCodeMI(int &numIndices, const int *&indices, const int *&instanceIndices)
Extender API: available to programmers who wish to extend the toolkit
Definition SoAction.h:412
friend class SoMultiPassElement
Definition SoAction.h:801
const SoPathList * getOriginalPathListAppliedTo() const
Returns the original path list the action is being applied to.
Definition SoAction.h:377
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 ...
DistribMode getDistribMode() const
Returns the distribution mode of this action across a cluster (ScaleViz-Cluster only).
Definition SoAction.h:300
virtual ~SoAction()
Destructor.
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:402
void setPipeId(int id)
Sets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Mu...
Definition SoAction.h:475
void useAlternateRep(const SbBool enable)
Tell the action to use alternate representations during traversal when available.
virtual void apply(const SoPathList &pathList, SbBool obeysRules=FALSE)
Initiates an action on the graph defined by a list of paths.
int getPipeId() const
Gets pipe identifier in the range [1..N] associated to this render action while running a ScaleViz Mu...
Definition SoAction.h:483
virtual void postDelayedTraversal()
Method called by SoMultiPassManager after delayed pass traversals.
Definition SoAction.h:509
void stopActionInBranch()
This function stops the action in the current Scene Graph branch.
Definition SoAction.h:204
static SoType getClassTypeId()
Returns the type identifier for this class.
DistribMode
This is used to define the way an action is distributed across a cluster.
Definition SoAction.h:286
@ ALL
Both application and cluster apply the action.
Definition SoAction.h:292
@ CLUSTER_ONLY
Action is only applied by OIRU of the cluster.
Definition SoAction.h:290
@ LOCAL_ONLY
Action is only applied by the application.
Definition SoAction.h:288
virtual void forwardTraversal(SoNode *node)
Traverse a node that is not part of the current scenegraph.
SbBool isLastPathListAppliedTo() const
Returns TRUE if the current list is the last one from the original.
Definition SoAction.h:387
SoPath * getPathAppliedTo() const
Returns the path the action is being applied to.
Definition SoAction.h:356
void traverse(SoNode *node)
Does traversal of a graph rooted by a node.
void resetContinueActionInBranchFlag()
This function resets the continue action flag.
Definition SoAction.h:218
static void nullAction(SoAction *, SoNode *)
Null action method that can be stored in lookup table when desired.
bool isBeingApplied()
Returns TRUE if this action is currently being applied.
Definition SoAction.h:490
SbBool isUsingAlternateRep() const
Returns TRUE if current action is using alternate representations.
SbBool hasTerminated() const
Returns TRUE if the traversal has reached a termination condition.
Definition SoAction.h:430
virtual void apply(SoPath *path)
Initiates an action on the graph defined by a path.
virtual void forwardTraversal(SoPath *path)
Traverse a path that is not part of the current scenegraph.
const SoPathList * getPathListAppliedTo() const
Returns the path list the action is being applied to.
Definition SoAction.h:366
Scene graph database class.
Definition SoDB.h:222
Abstract base class for all database nodes.
Definition SoNode.h:145
Path that points to a list of hierarchical nodes.
Definition SoPath.h:187
Maintains a list of pointers to paths.
Definition SoPathList.h:81
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
Manages scene graph rendering and event handling.
Traversal state.
Definition SoState.h:74
Stores runtime type information.
Definition SoType.h:98
Base class for object storing runtime type information.
int SbBool
Boolean type.
Definition SbBase.h:87