Debian Codegraph @

lib/database/src/so/upgraders/SoV1CustomNode.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.1.1.1 $
44 |
45 | Classes:
46 | SoV1CustomNode
47 |
48 | Author(s) : Gavin Bell
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/misc/upgraders/SoV1CustomNode.h>
55 #include <Inventor/errors/SoDebugError.h>
56 #include <Inventor/nodes/SoInfo.h>
57
58 SO_NODE_SOURCE(SoV1CustomNode);
59
60 ////////////////////////////////////////////////////////////////////////
61 //
62 // Description:
63 // Constructor
64 //
65 // Use: public
66
67 SoV1CustomNode::SoV1CustomNode()
68 //
69 ////////////////////////////////////////////////////////////////////////
70 {
71 SO_NODE_CONSTRUCTOR(SoV1CustomNode);
72
73 SO_NODE_ADD_FIELD(className, (""));
74 SO_NODE_ADD_FIELD(fields, (""));
75 SO_NODE_ADD_FIELD(customData, (""));
76 }
77
78 ////////////////////////////////////////////////////////////////////////
79 //
80 // Description:
81 // Destructor
82 //
83 // Use: private
84
85 SoV1CustomNode::~SoV1CustomNode()
86 //
87 ////////////////////////////////////////////////////////////////////////
88 {
89 }
90
91 ////////////////////////////////////////////////////////////////////////
92 //
93 // Description:
94 // Create a version 2.0 SoCustomNode.
95 //
96 // Use: private
97
98 SbBool
99 SoV1CustomNode::upgrade(SoInput *in, const SbName &refName,
100 SoBase *&result)
101 //
102 ////////////////////////////////////////////////////////////////////////
103 {
104 // First, read in fields:
105 const SoFieldData *fieldData = getFieldData();
106 SbBool notBuiltIn; // Not used
107 if (! fieldData->read(in, this, FALSE, notBuiltIn))
108 return FALSE;
109
110 // Custom nodes must use one of the 'real' classes (stored in the
111 // className field) to do the conversion, so search from
112 // most-derived to least-derived to find an appropriate converter
113 // and call convert() on it. If there is no upgrader for any
114 // subclasses, spit out an error and return NULL.
115
116 SoV1CustomNode *upgrader = NULL;
117 int i;
118
119 for (i = className.getNum()-1; i >= 0 && upgrader == NULL; i--) {
120 upgrader = (SoV1CustomNode *)
121 SoUpgrader::getUpgrader(className[i], 1.0);
122 }
123 if (upgrader == NULL) {
124 // Not found, warning, and return a group with an Info node:
125 #ifdef DEBUG
126 SoDebugError::postWarning("SoV1CustomNode::upgrade",
127 "No upgrader found for class %s\n",
128 className[className.getNum()-1].getString());
129 #endif
130 SoGroup *g = SO_UPGRADER_CREATE_NEW(SoGroup);
131 result = g;
132
133 // Add to dictionary
134 if (! (!refName))
135 in->addReference(refName, result);
136
137 // Add an Info node so the group can be found later:
138 SoInfo *info = SO_UPGRADER_CREATE_NEW(SoInfo);
139 SbString infoString("Group converted from CustomNode class ");
140 infoString += className[className.getNum()-1].getString();
141 info->string = infoString;
142 g->addChild(info);
143
144 readChildren(in);
145 for (int i = 0; i < getNumChildren(); i++)
146 g->addChild(getChild(i));
147
148 return TRUE;
149 }
150
151 upgrader->ref();
152
153 // Copy fields into upgrader:
154 upgrader->className.setValues(0, className.getNum(),
155 className.getValues(0));
156 upgrader->fields.setValues(0, fields.getNum(),
157 fields.getValues(0));
158 upgrader->customData.setValues(0, customData.getNum(),
159 customData.getValues(0));
160
161 result = upgrader->createNewNode();
162
163 // Add to dictionary
164 if (! (!refName))
165 in->addReference(refName, result);
166
167 // Read children into upgrader:
168 upgrader->readChildren(in);
169
170 // Set fields
171 for (i = 0; i < fields.getNum(); i++) {
172 upgrader->set(fields[i].getString(), in);
173 }
174
175 // Now, let each subclass have a chance to interpret its custom
176 // data:
177 for (i = 0; i < className.getNum(); i++) {
178 SoV1CustomNode *base = (SoV1CustomNode *)
179 SoUpgrader::getUpgrader(className[i], 1.0);
180 if (base) {
181 base->ref();
182 base->interpretCustomData(upgrader, i);
183 base->unref();
184 }
185 }
186
187 upgrader->setUpNewNode((SoNode *)result);
188
189 upgrader->unref();
190
191 return TRUE;
192 }
193
194 ////////////////////////////////////////////////////////////////////////
195 //
196 // Description:
197 // Create the V2.0 node to replace this node
198 //
199 // Use: public
200
201 SoNode *
202 SoV1CustomNode::createNewNode()
203 //
204 ////////////////////////////////////////////////////////////////////////
205 {
206 SoDebugError::post("SoV1CustomNode::createNewNode",
207 "Subclasses must implement createNewNode!");
208 return NULL;
209 }
210
211 ////////////////////////////////////////////////////////////////////////
212 //
213 // Description:
214 // This method is called to let subclass instances do whatever they
215 // have to do based on the info in the customData field value with
216 // the given index after the given instance has been read. This
217 // default does nothing.
218 //
219 // Use: public
220
221 void
222 SoV1CustomNode::interpretCustomData(SoV1CustomNode *, int ) const
223 //
224 ////////////////////////////////////////////////////////////////////////
225 {
226 }
227
228 ////////////////////////////////////////////////////////////////////////
229 //
230 // Description:
231 // Virtual method to setUp the new node. Default does nothing.
232 //
233 // Use: public
234
235 void
236 SoV1CustomNode::setUpNewNode(SoNode *)
237 //
238 ////////////////////////////////////////////////////////////////////////
239 {
240 }
241