Debian Codegraph @

apps/demos/SceneViewer/SvManipList.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,92 Silicon Graphics, Inc.
39 *
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 | Classes: SvManipList
47 |
48 | Author(s): David Mott
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/SbPList.h>
55 #include <Inventor/SoPath.h>
56 #include <Inventor/nodes/SoGroup.h>
57 #include <Inventor/manips/SoTransformManip.h>
58 #include "SvManipList.h"
59
60
61 typedef struct SvPathManipStuff {
62 SoPath *selectionPath;
63 SoTransformManip *manip;
64 SoPath *xfPath;
65 } SvPathManipStuff;
66
67 ////////////////////////////////////////////////////////////////////////
68 //
69 // Constructor
70 //
71 // Use: public
72 SvManipList::SvManipList()
73 //
74 ////////////////////////////////////////////////////////////////////////
75 {
76 list = new SbPList;
77 }
78
79 ////////////////////////////////////////////////////////////////////////
80 //
81 // Destructor
82 //
83 // Use: public
84 SvManipList::~SvManipList()
85 //
86 ////////////////////////////////////////////////////////////////////////
87 {
88 delete list;
89 }
90
91 ////////////////////////////////////////////////////////////////////////
92 //
93 // Use: public
94 int
95 SvManipList::getLength() const
96 //
97 ////////////////////////////////////////////////////////////////////////
98 {
99 return list->getLength();
100 }
101
102 ////////////////////////////////////////////////////////////////////////
103 //
104 // Append adds the selectionPath/manip/xfPath stuff to the list.
105 // This ref()'s both the paths and the manip.
106 //
107 // Use: public
108 void
109 SvManipList::append(SoPath *selectionP, SoTransformManip *m,
110 SoPath *xfP )
111 //
112 ////////////////////////////////////////////////////////////////////////
113 {
114 SvPathManipStuff *stuff = new SvPathManipStuff;
115
116 stuff->selectionPath = selectionP;
117 stuff->manip = m;
118 stuff->xfPath = xfP;
119 selectionP->ref();
120 m->ref();
121 xfP->ref();
122
123 list->append(stuff);
124 }
125
126 ////////////////////////////////////////////////////////////////////////
127 //
128 // Find locates the first selectionPath/manip/xfPath stuff whose
129 // selectionPath is p, and returns the index in the list of that stuff.
130 //
131 // Use: public
132 int
133 SvManipList::find(const SoPath *p) const
134 //
135 ////////////////////////////////////////////////////////////////////////
136 {
137 int which = -1;
138
139 for (int i = 0; (i < list->getLength()) && (which == -1); i++) {
140 SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[i];
141 if (*stuff->selectionPath == *p)
142 which = i;
143 }
144
145 return which;
146 }
147
148 ////////////////////////////////////////////////////////////////////////
149 //
150 // Find locates the first selectionPath/manip/xfPath stuff whose manip is m,
151 // and returns the index in the list of that stuff.
152 //
153 // Use: public
154 int
155 SvManipList::find(const SoTransformManip *m) const
156 //
157 ////////////////////////////////////////////////////////////////////////
158 {
159 int which = -1;
160
161 for (int i = 0; (i < list->getLength()) && (which == -1); i++) {
162 SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[i];
163 if (stuff->manip == m)
164 which = i;
165 }
166
167 return which;
168 }
169
170 ////////////////////////////////////////////////////////////////////////
171 //
172 // findByXfPath locates the first selectionPath/manip/xfPath stuff whose
173 // xfPath is p, and returns the index in the list of that stuff.
174 //
175 // Use: public
176 int
177 SvManipList::findByXfPath(const SoPath *p) const
178 //
179 ////////////////////////////////////////////////////////////////////////
180 {
181 int which = -1;
182
183 for (int i = 0; (i < list->getLength()) && (which == -1); i++) {
184 SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[i];
185 if (*stuff->xfPath == *p)
186 which = i;
187 }
188
189 return which;
190 }
191
192 ////////////////////////////////////////////////////////////////////////
193 //
194 // Remove removes the selectionPath/manip/xfPath stuff specified by
195 // which index from the list. This unref()'s both paths and the manip.
196 //
197 // Use: public
198 void
199 SvManipList::remove(int which)
200 //
201 ////////////////////////////////////////////////////////////////////////
202 {
203 SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
204
205 stuff->selectionPath->unref();
206 stuff->manip->unref();
207 stuff->xfPath->unref();
208
209 list->remove(which);
210 }
211
212 ////////////////////////////////////////////////////////////////////////
213 //
214 // This returns the selectionPath in the selectionPath/manip/xfPath stuff
215 // specified by which index.
216 //
217 // Use: public
218 SoPath *
219 SvManipList::getSelectionPath(int which) const
220 //
221 ////////////////////////////////////////////////////////////////////////
222 {
223 SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
224 return (stuff->selectionPath);
225 }
226
227 ////////////////////////////////////////////////////////////////////////
228 //
229 // This returns the manip in the selectionPath/manip/xfPath stuff
230 // specified by which index.
231 //
232 // Use: public
233 SoTransformManip *
234 SvManipList::getManip(int which) const
235 //
236 ////////////////////////////////////////////////////////////////////////
237 {
238 SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
239 return (stuff->manip);
240 }
241
242 ////////////////////////////////////////////////////////////////////////
243 //
244 // This returns the xfPath of the manip in the
245 // selectionPath/manip/xfPath stuff specified by which index.
246 //
247 // Use: public
248 SoPath *
249 SvManipList::getXfPath(int which) const
250 //
251 ////////////////////////////////////////////////////////////////////////
252 {
253 SvPathManipStuff *stuff = (SvPathManipStuff *) (*list)[which];
254 return (stuff->xfPath);
255 }