Debian Codegraph @

lib/nodekits/src/upgraders/SoV1AppearKit.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 | SoV1AppearanceKit
47 |
48 | Author(s) : Paul Isaacs and Thad Beier
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/SoDB.h>
55 #include <Inventor/misc/upgraders/SoV1AppearanceKit.h>
56 #include <Inventor/nodes/SoLightModel.h>
57 #include <Inventor/nodes/SoEnvironment.h>
58 #include <Inventor/nodes/SoDrawStyle.h>
59 #include <Inventor/nodes/SoMaterial.h>
60 #include <Inventor/nodes/SoComplexity.h>
61 #include <Inventor/nodes/SoTexture2.h>
62 #include <Inventor/nodes/SoTexture2Transform.h>
63 #include <Inventor/nodes/SoFont.h>
64 #include <Inventor/nodekits/SoAppearanceKit.h>
65 #include <Inventor/errors/SoDebugError.h>
66
67
68 // Define the required type id and name inquiry methods
69 SO_NODE_SOURCE(SoV1AppearanceKit);
70
71 // Define the required catalog inquiry methods
72 SO_V1_SUBKIT_CATALOG_VARS(SoV1AppearanceKit);
73 SO_V1_SUBKIT_CATALOG_METHODS(SoV1AppearanceKit);
74
75 SoNodeList *SoV1AppearanceKit::kitsWithUnusedTextureXfs = NULL;
76 SoNodeList *SoV1AppearanceKit::unusedTextureXfs = NULL;
77
78 ////////////////////////////////////////////////////////////////////////
79 //
80 // Description:
81 // Constructor
82 //
83 // Use: public
84
85 SoV1AppearanceKit::SoV1AppearanceKit()
86 //
87 ////////////////////////////////////////////////////////////////////////
88 {
89 SO_NODE_CONSTRUCTOR(SoV1AppearanceKit);
90
91 if(SO_NODE_IS_FIRST_INSTANCE() ) {
92 // Initialize children catalog and add entries to it
93 // These are the macros you use to make a catalog.
94 // Use ...INHERIT_CATALOG once, and put it first.
95 // Then, use combinations of ...ADD_CATALOG_ENTRY
96 // and ...ADD_CATALOG_LIST_ENTRY. See SoSubKit.h for more info
97 // on syntax of these macros.
98 SO_V1_SUBKIT_INHERIT_CATALOG(SoV1AppearanceKit, SoV1BaseKit );
99 SO_V1_SUBKIT_ADD_CATALOG_ENTRY("lightModel", SoLightModel, "this", "",TRUE );
100 SO_V1_SUBKIT_ADD_CATALOG_ENTRY("environment", SoEnvironment,"this", "",TRUE );
101 SO_V1_SUBKIT_ADD_CATALOG_ENTRY("drawStyle", SoDrawStyle, "this", "",TRUE );
102 SO_V1_SUBKIT_ADD_CATALOG_ENTRY("material", SoMaterial, "this", "",TRUE );
103 SO_V1_SUBKIT_ADD_CATALOG_ENTRY("complexity", SoComplexity, "this", "",TRUE );
104 SO_V1_SUBKIT_ADD_CATALOG_LIST_ENTRY("texture2List", SoGroup,
105 "this", "", SoTexture2, TRUE );
106 // NOTE: This differs from the AppearanceKit in V1.0 and V2.0
107 // This is because a texture node can get converted into
108 // a group containing both a texture and texture2Transform by
109 // the SoV1Texture2 upon readin. We don't want to throw it away.
110 // Instead, we hold it as a group and extract the texture during
111 // SoV1AppearanceKit::dealWithUpgradedPart().
112 SO_V1_SUBKIT_ADD_LIST_ITEM_TYPE("texture2List", SoGroup );
113
114 SO_V1_SUBKIT_ADD_CATALOG_ENTRY("font", SoFont, "this", "",TRUE );
115
116 }
117
118 // Create the static variables:
119 if ( kitsWithUnusedTextureXfs == NULL)
120 kitsWithUnusedTextureXfs = new SoNodeList;
121 if ( unusedTextureXfs == NULL )
122 unusedTextureXfs = new SoNodeList;
123
124
125
126 createNodekitPartsList();
127 }
128
129 ////////////////////////////////////////////////////////////////////////
130 //
131 // Description:
132 // Destructor (necessary since inline destructor is too complex)
133 //
134 // Use: public
135
136 SoV1AppearanceKit::~SoV1AppearanceKit()
137 //
138 ////////////////////////////////////////////////////////////////////////
139 {
140 }
141
142 SoNode *
143 SoV1AppearanceKit::createNewNode()
144 {
145 return new SoAppearanceKit;
146 }
147
148 ////////////////////////////////////////////////////////////////////////
149 //
150 // Description:
151 // A virtual function that allows classes to treat parts that fail the
152 // tests of 'tryToSetPartInNewNode'
153 //
154 // If tryToSetPartInNewNode fails, then this routine is called.
155 // It will fail if the part read from file was called "texture2List"
156 // This part has been changed to a single noded part, "texture2"
157 // We will use just the first child of the list and set it as the "texture2"
158 //
159 // Use: public
160 //
161 SbBool
162 SoV1AppearanceKit::dealWithUpgradedPart( SoBaseKit *newNode, SoNode *newPart,
163 const SbName &newPartName )
164 //
165 ////////////////////////////////////////////////////////////////////////
166 {
167 // First, try to let base class handle it...
168 if ( SoV1BaseKit::dealWithUpgradedPart( newNode, newPart, newPartName ) )
169 return TRUE;
170
171 // If the part name is "texture2List", get the first element
172 // and set it in the new kit as "texture2"
173 if ( newPartName == "texture2List" ) {
174 if ( !newPart->isOfType( SoGroup::getClassTypeId() ))
175 return FALSE;
176
177 SoGroup *listGrp = (SoGroup *) newPart;
178 if (listGrp->getNumChildren() > 0 ) {
179 SoNode *myNode = listGrp->getChild(0);
180 SoTexture2 *myTexture2 = NULL;
181 if ( !myNode->isOfType( SoTexture2::getClassTypeId() )) {
182 // The texture2 upgrader returns a group with an SoTexture2
183 // as a child in some cases. If so, replace it with just
184 // the texture and use that texture,
185 // otherwise just return.
186 if ( myNode->isOfType( SoGroup::getClassTypeId() ) ) {
187 SoGroup *tex2UpgdGrp = (SoGroup *) myNode;
188 tex2UpgdGrp->ref();
189 for (int i = 0; i < tex2UpgdGrp->getNumChildren(); i++ ) {
190 SoNode *theKid = tex2UpgdGrp->getChild(i);
191 if (theKid->isOfType(SoTexture2::getClassTypeId())) {
192
193 // Use the texture child.
194 myTexture2 = (SoTexture2 *) theKid;
195
196 // Replace the texture child for its parent group:
197 listGrp->replaceChild( tex2UpgdGrp, myTexture2 );
198
199 SoDebugError::postWarning("SoV1AppearanceKit::dealWithUpgradedPart",
200 "the input file contained a texture2 with transform fields in it. Since the new SoTexture2 does not contain these fields they may be lost");
201
202 }
203 if (theKid->isOfType(SoTexture2Transform::getClassTypeId())) {
204 // Save the values of newNode and theKid
205 // in case a parent
206 // nodekit wants to get at it later.
207 // This is necessary because AppearanceKit is not
208 // capable of storing the info for texture transform
209 kitsWithUnusedTextureXfs->append(newNode);
210 unusedTextureXfs->append(theKid);
211 }
212 }
213 tex2UpgdGrp->unref();
214 }
215 if (myTexture2 == NULL)
216 return FALSE;
217 }
218 else {
219 myTexture2 = (SoTexture2 *) myNode;
220 }
221 SoDebugError::postWarning("SoV1AppearanceKit::dealWithUpgradedPart",
222 "the input file contained a texture2List part. The new kits have only a texture2 part. Setting texture2 to be the first child in texture2List");
223 newNode->setPart("texture2", myTexture2 );
224 }
225 return TRUE;
226 }
227
228 return FALSE; // don't know how to do anything yet...
229 }
230
231 ////////////////////////////////////////////////////////////////////////
232 //
233 // Use: static, INTERNAL public
234 //
235 SoNodeList *
236 SoV1AppearanceKit::getKitsWithUnusedTextureXfs()
237 //
238 ////////////////////////////////////////////////////////////////////////
239 {
240 return kitsWithUnusedTextureXfs;
241 }
242
243 ////////////////////////////////////////////////////////////////////////
244 //
245 // Use: static, INTERNAL public
246 //
247 SoNodeList *
248 SoV1AppearanceKit::getUnusedTextureXfs()
249 //
250 ////////////////////////////////////////////////////////////////////////
251 {
252 return unusedTextureXfs;
253 }