Debian Codegraph @

lib/database/src/so/elements/SoAccumulatedElement.c++

raw
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 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.2 $
44 |
45 | Classes:
46 | SoAccumulatedElement
47 |
48 | Author(s) : Paul S. Strauss
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/errors/SoDebugError.h>
55 #include <Inventor/elements/SoAccumulatedElement.h>
56 #include <Inventor/nodes/SoNode.h>
57
58 // Can't use normal SO_ELEMENT_ABSTRACT_SOURCE method because we need
59 // to set flag in constructor.
60 SO__ELEMENT_ABSTRACT_VARS(SoAccumulatedElement);
61
62 ////////////////////////////////////////////////////////////////////////
63 //
64 // Description:
65 // Constructor
66 //
67 // Use: protected
68
69 SoAccumulatedElement::SoAccumulatedElement()
70 //
71 ////////////////////////////////////////////////////////////////////////
72 {
73 accumulatesWithParentFlag = TRUE;
74 }
75
76 ////////////////////////////////////////////////////////////////////////
77 //
78 // Description:
79 // Destructor.
80 //
81 // Use: private
82
83 SoAccumulatedElement::~SoAccumulatedElement()
84 //
85 ////////////////////////////////////////////////////////////////////////
86 {
87 }
88
89 ////////////////////////////////////////////////////////////////////////
90 //
91 // Description:
92 // Overrides this method to return TRUE if the all of the node-id's
93 // of the two elements match.
94 //
95 // Use: public
96
97 SbBool
98 SoAccumulatedElement::matches(const SoElement *elt) const
99 //
100 ////////////////////////////////////////////////////////////////////////
101 {
102 const SoAccumulatedElement *accElt = (const SoAccumulatedElement *) elt;
103 int i;
104
105 if (accElt->nodeIds.getLength() != nodeIds.getLength())
106 return FALSE;
107
108 for (i = 0; i < nodeIds.getLength(); i++)
109 if (nodeIds[i] != accElt->nodeIds[i])
110 return FALSE;
111
112 return TRUE;
113 }
114
115 ////////////////////////////////////////////////////////////////////////
116 //
117 // Description:
118 // Clears out the list of node id's
119 //
120 // Use: protected
121
122 void
123 SoAccumulatedElement::clearNodeIds()
124 //
125 ////////////////////////////////////////////////////////////////////////
126 {
127 nodeIds.truncate(0);
128 accumulatesWithParentFlag = FALSE;
129 }
130
131
132 ////////////////////////////////////////////////////////////////////////
133 //
134 // Description:
135 // Adds the id of the given node to the current list. Keeps the
136 // list sorted by increasing node-id.
137 //
138 // Use: protected
139
140 void
141 SoAccumulatedElement::addNodeId(const SoNode *node)
142 //
143 ////////////////////////////////////////////////////////////////////////
144 {
145 #ifdef DEBUG
146 if (node == NULL) {
147 SoDebugError::post("SoAccumulatedElement::addNodeId",
148 "NULL node pointer passed");
149 return;
150 }
151 #endif /* DEBUG */
152
153 int i;
154 unsigned long id = (unsigned long)node->getNodeId();
155
156 // Search through list for correct place for id
157 for (i = 0; i < nodeIds.getLength(); i++)
158 if (id <= (unsigned long) nodeIds[i])
159 break;
160
161 // Otherwise, i will contain the index where the new element belongs
162 if (i >= nodeIds.getLength())
163 nodeIds.append((void *) id);
164
165 // Insert it in the list if it is not already there:
166 else {
167 if (id != (unsigned long) nodeIds[i])
168 nodeIds.insert((void *) id, i);
169 }
170 }
171
172 ////////////////////////////////////////////////////////////////////////
173 //
174 // Description:
175 // Sets the node id list to JUST the id of the given node.
176 //
177 // Use: protected
178
179 void
180 SoAccumulatedElement::setNodeId(const SoNode *node)
181 //
182 ////////////////////////////////////////////////////////////////////////
183 {
184 #ifdef DEBUG
185 if (node == NULL) {
186 SoDebugError::post("SoAccumulatedElement::setNodeId",
187 "NULL node pointer passed");
188 return;
189 }
190 #endif /* DEBUG */
191
192 nodeIds.truncate(0);
193 nodeIds.append((void *) (unsigned long) node->getNodeId());
194
195 accumulatesWithParentFlag = FALSE;
196 }
197
198 ////////////////////////////////////////////////////////////////////////
199 //
200 // Description:
201 // Create a copy of this instance suitable for calling matches()
202 // on.
203 //
204 // Use: protected
205
206 SoElement *
207 SoAccumulatedElement::copyMatchInfo() const
208 //
209 ////////////////////////////////////////////////////////////////////////
210 {
211 SoAccumulatedElement *result =
212 (SoAccumulatedElement *)getTypeId().createInstance();
213
214 result->nodeIds = nodeIds;
215
216 return result;
217 }
218
219 ////////////////////////////////////////////////////////////////////////
220 //
221 // Description:
222 // "Captures" this element for caching purposes. When
223 // accumulating, all the elements up to the last reset (when the
224 // nodeId list was cleared) must be captured in the cache.
225 //
226 // Use: virtual, protected
227
228 void
229 SoAccumulatedElement::captureThis(SoState *state) const
230 //
231 ////////////////////////////////////////////////////////////////////////
232 {
233 SoElement::captureThis(state); // Capture this...
234
235 if (accumulatesWithParentFlag) {
236 SoAccumulatedElement *parent =
237 (SoAccumulatedElement *)getNextInStack();
238 if (parent)
239 parent->captureThis(state);
240 }
241 }
242
243 ////////////////////////////////////////////////////////////////////////
244 //
245 // Description:
246 // Prints element for debugging.
247 //
248 // Use: public
249 //
250 ////////////////////////////////////////////////////////////////////////
251
252 #ifdef DEBUG
253 void
254 SoAccumulatedElement::print(FILE *fp) const
255 {
256 SoElement::print(fp);
257
258 fprintf(fp, "NodeIds: [ ");
259 for (int i = 0; i < nodeIds.getLength(); i++) {
260 fprintf(fp, "%p, ", nodeIds[i]);
261 }
262 fprintf(fp, "]\n");
263 }
264 #else /* DEBUG */
265 void
266 SoAccumulatedElement::print(FILE *) const
267 {
268 }
269 #endif /* DEBUG */