Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SoPath.h
1 #ifndef COIN_SOPATH_H
2 #define COIN_SOPATH_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/misc/SoBase.h>
37 #include <Inventor/lists/SbList.h>
38 #include <Inventor/lists/SoNodeList.h>
39 
40 #ifndef COIN_INTERNAL
41 // For SGI / TGS Open Inventor compile-time compatibility.
42 #include <Inventor/SoLists.h>
43 #endif // !COIN_INTERNAL
44 
45 
46 class SoWriteAction;
47 class SoNotList;
48 class SoInput;
49 class SoPathList;
50 
51 
52 class COIN_DLL_API SoPath : public SoBase {
53  typedef SoBase inherited;
54 
55 public:
56  static void initClass(void);
57 
58  SoPath(const int approxlength = 4);
59  SoPath(SoNode * const head);
60  SoPath(const SoPath & rhs);
61 
62  SoPath & operator=(const SoPath & rhs);
63 
64  static SoType getClassTypeId(void);
65  virtual SoType getTypeId(void) const;
66 
67  void setHead(SoNode * const head);
68  SoNode * getHead(void) const;
69  void append(const int childindex);
70  void append(SoNode * const node);
71  void append(const SoPath * const frompath);
72  void push(const int childindex);
73  void pop(void);
74  SoNode * getTail(void) const;
75  SoNode * getNode(const int index) const;
76  SoNode * getNodeFromTail(const int index) const;
77  int getIndex(const int index) const;
78  int getIndexFromTail(const int index) const;
79  int getLength(void) const;
80  void truncate(const int length);
81 
82  int findFork(const SoPath * const path) const;
83  int findNode(const SoNode * const node) const;
84 
85  SbBool containsNode(const SoNode * const node) const;
86  SbBool containsPath(const SoPath * const path) const;
87  SoPath * copy(const int startfromnodeindex = 0, int numnodes = 0) const;
88  friend COIN_DLL_API SbBool operator==(const SoPath & lhs, const SoPath & rhs);
89  friend COIN_DLL_API SbBool operator!=(const SoPath & lhs, const SoPath & rhs);
90 
91  static SoPath * getByName(const SbName name);
92  static int getByName(const SbName name, SoPathList & l);
93 
94  void insertIndex(SoNode * const parent, const int newindex);
95  void removeIndex(SoNode * const parent, const int oldindex);
96  void replaceIndex(SoNode * const parent, const int index,
97  SoNode * const newchild);
98  SbBool isRelevantNotification(SoNotList * const l) const;
99 
100  virtual void write(SoWriteAction * action);
101 
102 protected:
103  virtual ~SoPath();
104  void auditPath(const SbBool flag);
105 
106 private:
107  static void cleanupClass(void);
108  static void * createInstance(void);
109  void append(SoNode * const node, const int index);
110  int getFullLength(void) const;
111  void truncate(const int length, const SbBool donotify);
112  virtual SbBool readInstance(SoInput * in, unsigned short flags);
113  void setFirstHidden(void);
114 
115  SoNodeList nodes;
116  SbList<int> indices;
117  SbBool isauditing;
118  int firsthidden;
119  SbBool firsthiddendirty;
120  static SoType classTypeId;
121 
122  friend class SoFullPath;
123  friend class SoNodeKitPath;
124  friend class SoAction;
125  friend class SoTempPath;
126 };
127 
129 
130 inline int
131 SoPath::getFullLength(void) const
132 {
133  return this->nodes.getLength();
134 }
135 
136 inline void
137 SoPath::push(const int childindex)
138 {
139  this->append(childindex);
140 }
141 
142 inline void
144 {
145  this->truncate(this->getFullLength() - 1);
146 }
147 
149 
150 
151 #ifndef COIN_INTERNAL
152 // For SGI / TGS Open Inventor compile-time compatibility.
153 #include <Inventor/SoFullPath.h>
154 #include <Inventor/misc/SoLightPath.h>
155 #endif // COIN_INTERNAL
156 
157 #endif // !COIN_SOPATH_H
The SoBase class is the top-level superclass for a number of class-hierarchies.
Definition: SoBase.h:45
The SoPathList class is a container for pointers to SoPath objects.
Definition: SoPathList.h:40
virtual SoType getTypeId(void) const =0
Returns the type identification of an object derived from a class inheriting SoBase. This is used for run-time type checking and "downward" casting.
void push(const int childindex)
Definition: SoPath.h:137
The SoNodeKitPath class is a path that contains only nodekit nodes.
Definition: SoNodeKitPath.h:42
The SoNode class is the base class for nodes used in scene graphs.
Definition: SoNode.h:56
The SoFullPath class allows examination of hidden children in paths.
Definition: SoFullPath.h:38
The SoPath class is a container class for traversal path descriptions.
Definition: SoPath.h:52
The SoAction class is the base class for all traversal actions.
Definition: SoAction.h:77
The SoTempPath class is used to store temporary paths.
Definition: SoTempPath.h:38
virtual SbBool readInstance(SoInput *input, unsigned short flags)=0
static void initClass(void)
Sets up initialization for data common to all instances of this class, like submitting necessary info...
Definition: SoBase.cpp:348
void append(const int childindex)
Definition: SoPath.cpp:211
The SoNodeList class is a container for pointers to SoNode objects.
Definition: SoNodeList.h:40
The SoWriteAction class writes a scene graph to file.
Definition: SoWriteAction.h:42
The SoInput class is an abstraction of file import functionality.
Definition: SoInput.h:61
static SoType getClassTypeId(void)
This static method returns the SoType object associated with objects of this class.
Definition: SoBase.cpp:632
void pop(void)
Definition: SoPath.h:143
The SoNotList class is a list of SoNotRec notification records.
Definition: SoNotification.h:43
The SoType class is the basis for the run-time type system in Coin.
Definition: SoType.h:59
int getLength(void) const
Definition: lists/SbPList.h:103
The SbName class stores strings by reference.
Definition: SbName.h:40
void truncate(const int length)
Definition: SoPath.cpp:528