1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
40 //#define OSG_DEBUG_VRML
43 # ifdef OSG_DEBUG_VRML
44 # define OSG_VRML_ARG(ARG) ARG
46 # define OSG_VRML_ARG(ARG)
49 # define OSG_VRML_ARG(ARG) ARG
55 /*! \class OSG::VRMLPrototypeHandler
58 /*-------------------------------------------------------------------------*/
61 template <class BaseT> inline
62 VRMLNodePrototypeHandler<BaseT>::VRMLNodePrototypeHandler(void) :
65 _pCurrentHelper (NULL),
70 /*-------------------------------------------------------------------------*/
73 template <class BaseT> inline
74 VRMLNodePrototypeHandler<BaseT>::~VRMLNodePrototypeHandler(void)
76 typename NameHelperMap::iterator mNodeHelperIt = _mNodeHelperHash.begin();
77 typename NameHelperMap::iterator mNodeHelperEnd = _mNodeHelperHash.end ();
79 while(mNodeHelperIt != mNodeHelperEnd)
81 delete (mNodeHelperIt)->second;
87 /*-------------------------------------------------------------------------*/
88 /* Skel Replacements */
90 template <class BaseT> inline
91 void VRMLNodePrototypeHandler<BaseT>::beginProto(const Char8 *szProtoname)
94 indentLog(VRMLNodeHelper::getIndent(), PINFO);
95 PINFO << "Begin Proto " << szProtoname << std::endl;
100 typename NameHelperMap::iterator mNodeHelperIt =
101 _mNodeHelperHash.find(szProtoname);
103 if(mNodeHelperIt == _mNodeHelperHash.end())
105 VRMLNodeHelper *pNewHelper =
106 VRMLNodeHelperFactory::the()->createHelper(szProtoname);
108 if(pNewHelper == NULL)
110 szName.assign(szProtoname);
112 _pCurrentHelper = VRMLDefaultHelper::create();
114 _pCurrentHelper->init(szProtoname);
116 _mNodeHelperHash[szName] = _pCurrentHelper;
120 szName.assign(szProtoname);
122 _pCurrentHelper = pNewHelper;
124 _pCurrentHelper->init(szProtoname);
126 _mNodeHelperHash[szName] = _pCurrentHelper;
131 fprintf(stderr, "Helper already present for %s\n", szProtoname);
135 Char8 *szName = NULL;
136 if(mNodeDescIt == _mNodeDescHash.end())
138 else if(osgStringCaseCmp("PointSet", szProtoname) == 0)
140 osgStringDup(szProtoname, szName);
142 _pCurrentNodeDesc = new VRMLGeometryPointSetDesc();
144 _pCurrentNodeDesc->init(szProtoname);
146 _mNodeDescHash[szName] = _pCurrentNodeDesc;
148 else if(osgStringCaseCmp("Appearance", szProtoname) == 0)
150 osgStringDup(szProtoname, szName);
152 _pCurrentNodeDesc = new VRMLAppearanceDesc();
154 _pCurrentNodeDesc->init(szProtoname);
156 _mNodeDescHash[szName] = _pCurrentNodeDesc;
158 else if(osgStringCaseCmp("Box", szProtoname) == 0)
160 osgStringDup(szProtoname, szName);
162 _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Box");
164 _pCurrentNodeDesc->init(szProtoname);
166 _mNodeDescHash[szName] = _pCurrentNodeDesc;
168 else if(osgStringCaseCmp("Cone", szProtoname) == 0)
170 osgStringDup(szProtoname, szName);
172 _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Cone");
174 _pCurrentNodeDesc->init(szProtoname);
176 _mNodeDescHash[szName] = _pCurrentNodeDesc;
178 else if(osgStringCaseCmp("Cylinder", szProtoname) == 0)
180 osgStringDup(szProtoname, szName);
182 _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Cylinder");
184 _pCurrentNodeDesc->init(szProtoname);
186 _mNodeDescHash[szName] = _pCurrentNodeDesc;
188 else if(osgStringCaseCmp("Sphere", szProtoname) == 0)
190 osgStringDup(szProtoname, szName);
192 _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Sphere");
194 _pCurrentNodeDesc->init(szProtoname);
196 _mNodeDescHash[szName] = _pCurrentNodeDesc;
198 else if(osgStringCaseCmp("TextureTransform", szProtoname) == 0)
200 osgStringDup(szProtoname, szName);
202 _pCurrentNodeDesc = new VRMLTextureTransformDesc();
204 _pCurrentNodeDesc->init(szProtoname);
206 _mNodeDescHash[szName] = _pCurrentNodeDesc;
208 else if(osgStringCaseCmp("ImageTexture", szProtoname) == 0)
210 osgStringDup(szProtoname, szName);
212 _pCurrentNodeDesc = new VRMLImageTextureDesc();
214 _pCurrentNodeDesc->init(szProtoname);
216 _mNodeDescHash[szName] = _pCurrentNodeDesc;
218 else if(osgStringCaseCmp("PixelTexture", szProtoname) == 0)
220 osgStringDup(szProtoname, szName);
222 _pCurrentNodeDesc = new VRMLPixelTextureDesc();
224 _pCurrentNodeDesc->init(szProtoname);
226 _mNodeDescHash[szName] = _pCurrentNodeDesc;
228 else if(osgStringCaseCmp("LOD", szProtoname) == 0)
230 osgStringDup(szProtoname, szName);
232 _pCurrentNodeDesc = new VRMLLODDesc();
234 _pCurrentNodeDesc->init(szProtoname);
236 _mNodeDescHash[szName] = _pCurrentNodeDesc;
238 else if(osgStringCaseCmp("Switch", szProtoname) == 0)
240 osgStringDup(szProtoname, szName);
242 _pCurrentNodeDesc = new VRMLSwitchDesc();
244 _pCurrentNodeDesc->init(szProtoname);
246 _mNodeDescHash[szName] = _pCurrentNodeDesc;
248 else if(osgStringCaseCmp("Group", szProtoname) == 0)
250 osgStringDup(szProtoname, szName);
252 _pCurrentNodeDesc = new VRMLGroupDesc();
254 _pCurrentNodeDesc->init(szProtoname);
256 _mNodeDescHash[szName] = _pCurrentNodeDesc;
258 else if(osgStringCaseCmp("Inline", szProtoname) == 0)
260 osgStringDup(szProtoname, szName);
262 _pCurrentNodeDesc = new VRMLInlineDesc();
264 _pCurrentNodeDesc->init(szProtoname);
266 _mNodeDescHash[szName] = _pCurrentNodeDesc;
268 else if(osgStringCaseCmp("Viewpoint", szProtoname) == 0)
270 osgStringDup(szProtoname, szName);
272 _pCurrentNodeDesc = new VRMLViewpointDesc();
274 _pCurrentNodeDesc->init(szProtoname);
276 _mNodeDescHash[szName] = _pCurrentNodeDesc;
278 else if(osgStringCaseCmp("Extrusion", szProtoname) == 0)
280 osgStringDup(szProtoname, szName);
282 _pCurrentNodeDesc = new VRMLExtrusionDesc();
284 _pCurrentNodeDesc->init(szProtoname);
286 _mNodeDescHash[szName] = _pCurrentNodeDesc;
290 osgStringDup(szProtoname, szName);
292 _pCurrentNodeDesc = new VRMLNodeDesc;
294 _pCurrentNodeDesc->init(szProtoname);
296 _mNodeDescHash[szName] = _pCurrentNodeDesc;
302 #ifdef OSG_DEBUG_VRML
303 indentLog(VRMLNodeDesc::getIndent(), PINFO);
304 PINFO << "Could not add second proto named "
312 VRMLNodeHelper::incIndent();
313 VRMLNodeHelper::incIndent();
316 template <class BaseT> inline
317 void VRMLNodePrototypeHandler<BaseT>::endProtoInterface(void)
319 if(_pCurrentHelper != NULL)
320 _pCurrentHelper->endProtoInterface();
322 #ifdef OSG_DEBUG_VRML
323 VRMLNodeHelper::decIndent();
327 template <class BaseT> inline
328 void VRMLNodePrototypeHandler<BaseT>::endProto(void)
330 #ifdef OSG_DEBUG_VRML
331 VRMLNodeHelper::decIndent();
335 template <class BaseT> inline
336 void VRMLNodePrototypeHandler<BaseT>::beginEventInDecl(
337 const Char8 *OSG_VRML_ARG(szEventType),
339 const Char8 *OSG_VRML_ARG(szEventName))
341 #ifdef OSG_DEBUG_VRML
342 indentLog(VRMLNodeHelper::getIndent(), PINFO);
343 PINFO << "AddEventIn " << szEventType << " " << szEventName << std::endl;
347 template <class BaseT> inline
348 void VRMLNodePrototypeHandler<BaseT>::beginEventOutDecl(
349 const Char8 *OSG_VRML_ARG(szEventType),
351 const Char8 *OSG_VRML_ARG(szEventName))
353 #ifdef OSG_DEBUG_VRML
354 indentLog(VRMLNodeHelper::getIndent(), PINFO);
355 PINFO << "AddEventOut " << szEventType << " " << szEventName << std::endl;
359 template <class BaseT> inline
360 void VRMLNodePrototypeHandler<BaseT>::beginFieldDecl(
361 const Char8 *szFieldType,
362 const UInt32 uiFieldTypeId,
363 const Char8 *szFieldName)
365 #ifdef OSG_DEBUG_VRML
366 indentLog(VRMLNodeHelper::getIndent(), PINFO);
369 << " " << uiFieldTypeId
370 << " " << szFieldName
374 if(_pCurrentHelper != NULL)
376 _pCurrentHelper->prototypeAddField(
378 Self::mapIntExtFieldType(szFieldName, uiFieldTypeId),
383 template <class BaseT> inline
384 void VRMLNodePrototypeHandler<BaseT>::endFieldDecl(void)
388 template <class BaseT> inline
389 void VRMLNodePrototypeHandler<BaseT>::beginExposedFieldDecl(
390 const Char8 *szFieldType,
391 const UInt32 uiFieldTypeId,
392 const Char8 *szFieldName)
394 beginFieldDecl(szFieldType, uiFieldTypeId, szFieldName);
397 template <class BaseT> inline
398 void VRMLNodePrototypeHandler<BaseT>::endExposedFieldDecl(void)
404 /*-------------------------------------------------------------------------*/
408 /*-------------------------------------------------------------------------*/
411 template <class BaseT> inline
412 VRMLNodeHelper *VRMLNodePrototypeHandler<BaseT>::findNodeHelper(
413 const Char8 *szNodeTypename)
415 VRMLNodeHelper *returnValue = NULL;
417 typename NameHelperMap::iterator mNodeHelperIt =
418 _mNodeHelperHash.find(szNodeTypename);
420 if(mNodeHelperIt != _mNodeHelperHash.end())
422 #ifdef OSG_DEBUG_VRML
423 indentLog(VRMLNodeHelper::getIndent(), PINFO);
424 PINFO << "Found Node "
425 << mNodeHelperIt->first << " ("
426 << szNodeTypename << ")" << std::endl;
429 returnValue = mNodeHelperIt->second;
436 template <class BaseT> inline
437 void VRMLNodePrototypeHandler<BaseT>::preStandardProtos (void)
441 template <class BaseT> inline
442 void VRMLNodePrototypeHandler<BaseT>::postStandardProtos(void)
444 VRMLNodeHelper *pNodeHelper = NULL;
445 VRMLShapeHelper *pShapeHelper = NULL;
446 VRMLAppearanceHelper *pAppearanceHelper = NULL;
447 VRMLMaterialHelper *pMaterialHelper = NULL;
449 pNodeHelper = findNodeHelper("Shape");
451 if(pNodeHelper != NULL)
453 pShapeHelper = dynamic_cast<VRMLShapeHelper *>(pNodeHelper);
456 pNodeHelper = findNodeHelper("Appearance");
458 if(pNodeHelper != NULL)
460 pAppearanceHelper = dynamic_cast<VRMLAppearanceHelper *>(pNodeHelper);
463 pNodeHelper = findNodeHelper("Material");
465 if(pNodeHelper != NULL)
467 pMaterialHelper = dynamic_cast<VRMLMaterialHelper *>(pNodeHelper);
470 if(pShapeHelper != NULL)
472 pShapeHelper->setMaterialHelper(pMaterialHelper);
475 if(pAppearanceHelper != NULL)
477 pAppearanceHelper->setMaterialHelper(pMaterialHelper);