Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGVRMLNodeFactory.inl

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 
00042 #include <OSGConfig.h>
00043 #include <OSGLog.h>
00044 
00045 #include <OSGFieldFactory.h>
00046 #include <OSGTransform.h>
00047 
00048 #include <iostream>
00049 
00050 //#define OSG_DEBUG_VRML
00051 
00052 #ifndef OSG_DO_DOC
00053 #    ifdef OSG_DEBUG_VRML
00054 #        define OSG_VRML_ARG(ARG) ARG
00055 #    else
00056 #        define OSG_VRML_ARG(ARG)
00057 #    endif
00058 #else
00059 #    define OSG_VRML_ARG(ARG) ARG
00060 #endif
00061 
00062 
00063 OSG_BEGIN_NAMESPACE
00064 
00068 /*-------------------------------------------------------------------------*/
00069 /*                            Constructors                                 */
00070 
00071 template <class BaseT> inline
00072 VRMLNodeFactory<BaseT>::VRMLNodeFactory(void) :
00073     Inherited(),
00074 
00075     _pCurrentNodeDesc(NULL),
00076     _mNodeDescHash   (),
00077 
00078     _bInFieldProto   (false),
00079 
00080     _bIgnoreProto    (false)
00081 {
00082 }
00083 
00084 /*-------------------------------------------------------------------------*/
00085 /*                             Destructor                                  */
00086 
00087 template <class BaseT> inline
00088 VRMLNodeFactory<BaseT>::~VRMLNodeFactory(void)
00089 {
00090 }
00091 
00092 /*-------------------------------------------------------------------------*/
00093 /*                            Skel Replacements                            */
00094 
00095 template <class BaseT> inline
00096 void VRMLNodeFactory<BaseT>::beginProto(
00097     const Char8 *szProtoname)
00098 {
00099 #ifdef OSG_DEBUG_VRML
00100     indentLog(VRMLNodeDesc::getIndent(), PINFO);
00101     PINFO << "Begin Proto " << szProtoname << std::endl;
00102 #endif
00103 
00104     Char8 *szName = NULL;
00105 
00106     NodeNameDescHash::iterator mNodeDescIt =
00107         _mNodeDescHash.find(szProtoname);
00108 
00109     if(mNodeDescIt == _mNodeDescHash.end())
00110     {
00111         if(stringcasecmp("IndexedFaceSet", szProtoname) == 0)
00112         {
00113             stringDup(szProtoname, szName);
00114 
00115             _pCurrentNodeDesc = new VRMLGeometryDesc(true);
00116 
00117             _pCurrentNodeDesc->init(szProtoname);
00118 
00119             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00120         }
00121         else if(stringcasecmp("IndexedLineSet", szProtoname) == 0)
00122         {
00123             stringDup(szProtoname, szName);
00124 
00125             _pCurrentNodeDesc = new VRMLGeometryDesc(false);
00126 
00127             _pCurrentNodeDesc->init(szProtoname);
00128 
00129             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00130         }
00131         else if(stringcasecmp("PointSet", szProtoname) == 0)
00132         {
00133             stringDup(szProtoname, szName);
00134 
00135             _pCurrentNodeDesc = new VRMLGeometryPointSetDesc();
00136 
00137             _pCurrentNodeDesc->init(szProtoname);
00138 
00139             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00140         }
00141         else if(stringcasecmp("Shape", szProtoname) == 0)
00142         {
00143             stringDup(szProtoname, szName);
00144 
00145             _pCurrentNodeDesc = new VRMLShapeDesc;
00146 
00147             _pCurrentNodeDesc->init(szProtoname);
00148 
00149             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00150         }
00151         else if(stringcasecmp("Coordinate", szProtoname) == 0)
00152         {
00153             stringDup(szProtoname, szName);
00154 
00155             _pCurrentNodeDesc = new VRMLGeometryPartDesc("point",
00156                                                          "positions",
00157                                                          "GeoPositions3f");
00158 
00159             _pCurrentNodeDesc->init(szProtoname);
00160 
00161             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00162         }
00163         else if(stringcasecmp("Normal", szProtoname) == 0)
00164         {
00165             stringDup(szProtoname, szName);
00166 
00167             _pCurrentNodeDesc = new VRMLGeometryPartDesc("vector",
00168                                                          "normals",
00169                                                          "GeoNormals3f");
00170 
00171             _pCurrentNodeDesc->init(szProtoname);
00172 
00173             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00174         }
00175         else if(stringcasecmp("Color", szProtoname) == 0)
00176         {
00177             stringDup(szProtoname, szName);
00178 
00179             _pCurrentNodeDesc = new VRMLGeometryPartDesc("color",
00180                                                          "colors",
00181                                                          "GeoColors3f");
00182 
00183             _pCurrentNodeDesc->init(szProtoname);
00184 
00185             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00186         }
00187         else if(stringcasecmp("TextureCoordinate", szProtoname) == 0)
00188         {
00189             stringDup(szProtoname, szName);
00190 
00191             _pCurrentNodeDesc = new VRMLGeometryPartDesc("point",
00192                                                          "TexCoords",
00193                                                          "GeoTexCoords2f");
00194 
00195             _pCurrentNodeDesc->init(szProtoname);
00196 
00197             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00198         }
00199         else if(stringcasecmp("Appearance", szProtoname) == 0)
00200         {
00201             stringDup(szProtoname, szName);
00202 
00203             _pCurrentNodeDesc = new VRMLAppearanceDesc();
00204 
00205             _pCurrentNodeDesc->init(szProtoname);
00206 
00207             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00208         }
00209         else if(stringcasecmp("Material", szProtoname) == 0)
00210         {
00211             stringDup(szProtoname, szName);
00212 
00213             _pCurrentNodeDesc = new VRMLMaterialDesc();
00214 
00215             _pCurrentNodeDesc->init(szProtoname);
00216 
00217             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00218         }
00219         else if(stringcasecmp("Box", szProtoname) == 0)
00220         {
00221             stringDup(szProtoname, szName);
00222 
00223             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Box");
00224 
00225             _pCurrentNodeDesc->init(szProtoname);
00226 
00227             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00228         }
00229         else if(stringcasecmp("Cone", szProtoname) == 0)
00230         {
00231             stringDup(szProtoname, szName);
00232 
00233             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Cone");
00234 
00235             _pCurrentNodeDesc->init(szProtoname);
00236 
00237             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00238         }
00239         else if(stringcasecmp("Cylinder", szProtoname) == 0)
00240         {
00241             stringDup(szProtoname, szName);
00242 
00243             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Cylinder");
00244 
00245             _pCurrentNodeDesc->init(szProtoname);
00246 
00247             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00248         }
00249         else if(stringcasecmp("Sphere", szProtoname) == 0)
00250         {
00251             stringDup(szProtoname, szName);
00252 
00253             _pCurrentNodeDesc = new VRMLGeometryObjectDesc("Sphere");
00254 
00255             _pCurrentNodeDesc->init(szProtoname);
00256 
00257             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00258         }
00259         else if(stringcasecmp("TextureTransform", szProtoname) == 0)
00260         {
00261             stringDup(szProtoname, szName);
00262 
00263             _pCurrentNodeDesc = new VRMLTextureTransformDesc();
00264 
00265             _pCurrentNodeDesc->init(szProtoname);
00266 
00267             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00268         }
00269         else if(stringcasecmp("ImageTexture", szProtoname) == 0)
00270         {
00271             stringDup(szProtoname, szName);
00272 
00273             _pCurrentNodeDesc = new VRMLImageTextureDesc();
00274 
00275             _pCurrentNodeDesc->init(szProtoname);
00276 
00277             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00278         }
00279         else if(stringcasecmp("PixelTexture", szProtoname) == 0)
00280         {
00281             stringDup(szProtoname, szName);
00282 
00283             _pCurrentNodeDesc = new VRMLPixelTextureDesc();
00284 
00285             _pCurrentNodeDesc->init(szProtoname);
00286 
00287             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00288         }
00289         else if(stringcasecmp("LOD", szProtoname) == 0)
00290         {
00291             stringDup(szProtoname, szName);
00292 
00293             _pCurrentNodeDesc = new VRMLLODDesc();
00294 
00295             _pCurrentNodeDesc->init(szProtoname);
00296 
00297             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00298         }
00299         else if(stringcasecmp("Switch", szProtoname) == 0)
00300         {
00301             stringDup(szProtoname, szName);
00302 
00303             _pCurrentNodeDesc = new VRMLSwitchDesc();
00304 
00305             _pCurrentNodeDesc->init(szProtoname);
00306 
00307             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00308         }
00309         else if(stringcasecmp("Group", szProtoname) == 0)
00310         {
00311             stringDup(szProtoname, szName);
00312 
00313             _pCurrentNodeDesc = new VRMLGroupDesc();
00314 
00315             _pCurrentNodeDesc->init(szProtoname);
00316 
00317             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00318         }
00319         else if(stringcasecmp("Inline", szProtoname) == 0)
00320         {
00321             stringDup(szProtoname, szName);
00322 
00323             _pCurrentNodeDesc = new VRMLInlineDesc();
00324 
00325             _pCurrentNodeDesc->init(szProtoname);
00326 
00327             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00328         }
00329         else if(stringcasecmp("Viewpoint", szProtoname) == 0)
00330         {
00331             stringDup(szProtoname, szName);
00332 
00333             _pCurrentNodeDesc = new VRMLViewpointDesc();
00334 
00335             _pCurrentNodeDesc->init(szProtoname);
00336 
00337             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00338         }
00339         else if(stringcasecmp("Extrusion", szProtoname) == 0)
00340         {
00341             stringDup(szProtoname, szName);
00342 
00343             _pCurrentNodeDesc = new VRMLExtrusionDesc();
00344 
00345             _pCurrentNodeDesc->init(szProtoname);
00346 
00347             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00348         }
00349         else
00350         {
00351             stringDup(szProtoname, szName);
00352 
00353             _pCurrentNodeDesc = new VRMLNodeDesc;
00354 
00355             _pCurrentNodeDesc->init(szProtoname);
00356 
00357             _mNodeDescHash[szName] = _pCurrentNodeDesc;
00358         }
00359 
00360     }
00361     else
00362     {
00363 #ifdef OSG_DEBUG_VRML
00364         indentLog(VRMLNodeDesc::getIndent(), PINFO);
00365         PINFO << "Could not add second proto named "
00366               << szProtoname
00367               << std::endl;
00368 #endif
00369 
00370         _bIgnoreProto = true;
00371     }
00372 
00373     VRMLNodeDesc::incIndent();
00374 }
00375 
00376 template <class BaseT> inline
00377 void VRMLNodeFactory<BaseT>::endProto  (void)
00378 {
00379     if(_pCurrentNodeDesc != NULL)
00380         _pCurrentNodeDesc->endProtoInterface();
00381 
00382 #ifdef OSG_DEBUG_VRML
00383     VRMLNodeDesc::decIndent();
00384 #endif
00385 
00386     _bIgnoreProto = false;
00387 }
00388 
00389 template <class BaseT> inline
00390 void VRMLNodeFactory<BaseT>::beginEventInDecl(
00391     const Char8  *OSG_VRML_ARG(szEventType),
00392     const UInt32,
00393     const Char8  *OSG_VRML_ARG(szEventName))
00394 {
00395     if(_bIgnoreProto == true)
00396         return;
00397 
00398 #ifdef OSG_DEBUG_VRML
00399     indentLog(VRMLNodeDesc::getIndent(), PINFO);
00400     PINFO << "AddEventIn " << szEventType << " " << szEventName << std::endl;
00401 #endif
00402 }
00403 
00404 template <class BaseT> inline
00405 void VRMLNodeFactory<BaseT>::beginEventOutDecl(
00406     const Char8  *OSG_VRML_ARG(szEventType),
00407     const UInt32,
00408     const Char8  *OSG_VRML_ARG(szEventName))
00409 {
00410     if(_bIgnoreProto == true)
00411         return;
00412 
00413 #ifdef OSG_DEBUG_VRML
00414     indentLog(VRMLNodeDesc::getIndent(), PINFO);
00415     PINFO << "AddEventOut " << szEventType << " " << szEventName << std::endl;
00416 #endif
00417 }
00418 
00419 template <class BaseT> inline
00420 void VRMLNodeFactory<BaseT>::beginFieldDecl(
00421     const Char8  *szFieldType,
00422     const UInt32  uiFieldTypeId,
00423     const Char8  *szFieldName)
00424 {
00425     bool rc;
00426 
00427     if(_bIgnoreProto == true)
00428         return;
00429 
00430     if(_pCurrentNodeDesc != NULL)
00431     {
00432         rc = _pCurrentNodeDesc->prototypeAddField(
00433             szFieldType,
00434             Self::mapIntExtFieldType(szFieldName, uiFieldTypeId),
00435             szFieldName);
00436 
00437         if(rc == true)
00438         {
00439             _bInFieldProto = true;
00440         }
00441     }
00442 }
00443 
00444 template <class BaseT> inline
00445 void VRMLNodeFactory<BaseT>::endFieldDecl(void)
00446 {
00447     _bInFieldProto = false;
00448 }
00449 
00450 template <class BaseT> inline
00451 void VRMLNodeFactory<BaseT>::beginExposedFieldDecl(
00452     const Char8  *szFieldType,
00453     const UInt32  uiFieldTypeId,
00454     const Char8  *szFieldName)
00455 {
00456     beginFieldDecl(szFieldType, uiFieldTypeId, szFieldName);
00457 }
00458 
00459 template <class BaseT> inline
00460 void VRMLNodeFactory<BaseT>::endExposedFieldDecl(void)
00461 {
00462     endFieldDecl();
00463 }
00464 
00465 #if 0
00466 template <class BaseT> inline
00467 OSG::NodePtr VRMLNodeFactory<BaseT>::getNode(const Char8 *szNodename)
00468 {
00469     OSG::NodePtr              returnValue = OSG::NullNode;
00470     OSG::FieldContainerPtr    pTmp;
00471     NodeProtoMap::iterator gIt;
00472 
00473     if(szNodename == NULL)
00474         return returnValue;
00475 
00476     gIt = _mNodeProtos.find(IDStringLink(szNodename));
00477 
00478     if(gIt != _mNodeProtos.end())
00479     {
00480         pTmp = (*gIt).second->clone();
00481 
00482         if(pTmp != OSG::NullFC)
00483             returnValue = pTmp.dcast<OSG::NodePtr>();
00484     }
00485 
00486     return returnValue;
00487 }
00488 #endif
00489 
00490 template <class BaseT> inline
00491 void VRMLNodeFactory<BaseT>::addFieldValue(const Char8 *szFieldVal)
00492 {
00493     if(_bInFieldProto == true)
00494     {
00495 #ifdef OSG_DEBUG_VRML
00496         indentLog(VRMLNodeDesc::getIndent(), PINFO);
00497 
00498         PINFO << "Add proto field value : " << szFieldVal << std::endl;
00499 #endif
00500     }
00501 
00502     if(_pCurrentNodeDesc != NULL)
00503     {
00504         _pCurrentNodeDesc->prototypeAddFieldValue(szFieldVal);
00505     }
00506 }
00507 
00508 /*-------------------------------------------------------------------------*/
00509 /*                                Dump                                     */
00510 
00511 template <class BaseT> inline
00512 void VRMLNodeFactory<BaseT>::dumpTable(void)
00513 {
00514     NodeNameDescHash::iterator  mNodeDescIt = _mNodeDescHash.begin();
00515 
00516     while(mNodeDescIt != _mNodeDescHash.end())
00517     {
00518 //        fprintf(stderr, "NodeDesc : %s\n", mNodeDescIt->first);
00519 
00520         mNodeDescIt->second->dump(mNodeDescIt->first);
00521 
00522         mNodeDescIt++;
00523     }
00524 }
00525 
00526 /*-------------------------------------------------------------------------*/
00527 /*                               Helper                                    */
00528 
00529 template <class BaseT> inline
00530 VRMLNodeDesc *VRMLNodeFactory<BaseT>::findNodeDesc(const Char8 *szNodeTypename)
00531 {
00532     VRMLNodeDesc *returnValue = NULL;
00533 
00534     NodeNameDescHash::iterator mNodeDescIt =
00535         _mNodeDescHash.find(szNodeTypename);
00536 
00537     if(mNodeDescIt != _mNodeDescHash.end())
00538     {
00539 #ifdef OSG_DEBUG_VRML
00540         indentLog(VRMLNodeDesc::getIndent(), PINFO);
00541         PINFO << "Found Node "
00542               << mNodeDescIt->first << " ("
00543               << szNodeTypename     << ")" << std::endl;
00544 #endif
00545 
00546         returnValue = mNodeDescIt->second;
00547     }
00548 
00549     return returnValue;
00550 }
00551 
00552 template <class BaseT> inline
00553 void VRMLNodeFactory<BaseT>::addNodeDesc(const Char8        *szNodeTypename,
00554                                                VRMLNodeDesc *pDesc)
00555 {
00556     Char8 *szName = NULL;
00557 
00558     if(szNodeTypename == NULL || pDesc == NULL)
00559         return;
00560 
00561     stringDup(szNodeTypename, szName);
00562 
00563     _mNodeDescHash[szName] = pDesc;
00564 
00565     _pCurrentNodeDesc = pDesc;
00566 }
00567 
00568 template <class BaseT> inline
00569 void VRMLNodeFactory<BaseT>::preStandardProtos (void)
00570 {
00571 }
00572 
00573 template <class BaseT> inline
00574 void VRMLNodeFactory<BaseT>::postStandardProtos(void)
00575 {
00576     VRMLNodeDesc         *pNodeDesc         = NULL;
00577     VRMLShapeDesc        *pShapeDesc        = NULL;
00578     VRMLAppearanceDesc   *pAppearanceDesc   = NULL;
00579     VRMLMaterialDesc     *pMaterialDesc     = NULL;
00580 
00581     pNodeDesc = findNodeDesc("Shape");
00582 
00583     if(pNodeDesc != NULL)
00584     {
00585         pShapeDesc = dynamic_cast<VRMLShapeDesc *>(pNodeDesc);
00586     }
00587 
00588     pNodeDesc = findNodeDesc("Appearance");
00589 
00590     if(pNodeDesc != NULL)
00591     {
00592         pAppearanceDesc = dynamic_cast<VRMLAppearanceDesc *>(pNodeDesc);
00593     }
00594 
00595     pNodeDesc = findNodeDesc("Material");
00596 
00597     if(pNodeDesc != NULL)
00598     {
00599         pMaterialDesc = dynamic_cast<VRMLMaterialDesc *>(pNodeDesc);
00600     }
00601 
00602     if(pShapeDesc != NULL)
00603     {
00604         pShapeDesc->setMaterialDesc(pMaterialDesc);
00605     }
00606 
00607     if(pAppearanceDesc != NULL)
00608     {
00609         pAppearanceDesc->setMaterialDesc(pMaterialDesc);
00610     }
00611 }
00612 
00613 OSG_END_NAMESPACE
00614 
00615 #define OSGVRNLNODEFACTORY_INLINE_CVSID "@(#)$Id: $"

Generated on Thu Aug 25 04:12:07 2005 for OpenSG by  doxygen 1.4.3