fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / WRL / OSGVRMLFile.cpp
blob054326efe31b348f06b4f8aefbf6d6fff9c77388
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 // AMZ disabled for now.
41 #include <cstdlib>
42 #include <cstdio>
44 #include "OSGConfig.h"
46 #include <iostream>
48 #include "OSGVRMLFile.h"
50 #include "OSGFieldType.h"
51 #include "OSGMathMFields.h"
52 #include "OSGMathSFields.h"
53 #include "OSGVecMFields.h"
54 #include "OSGVecSFields.h"
57 #include "OSGAction.h"
58 #include "OSGMaterial.h"
59 #include "OSGMaterialGroup.h"
60 #include "OSGNameAttachment.h"
62 #include "OSGGroup.h"
64 #include "OSGBlendChunk.h"
65 #include "OSGTextureObjChunk.h"
66 #include "OSGTextureEnvChunk.h"
67 #include "OSGFieldConnector.h"
70 #include "OSGSceneFileHandler.h"
72 //#define OSG_DEBUG_VRML
74 OSG_BEGIN_NAMESPACE
76 /*! \class OSG::VRMLFile
79 /*! \var OSG::VRMLFile::PushNames
80 Option to push the name attachments for entities that can not have a
81 NameAttachment in OpenSG to their respective parent.
83 This is currently only implemented for MaterialChunks and only sets the
84 name on the containing ChunkMaterial if that does not have a name of its
85 own.
88 OSG::Time startTime = 0.;
89 OSG::Time useTime = 0.;
90 OSG::Time findTime = 0.;
92 /*-------------------------------------------------------------------------*/
93 /* Constructors */
95 VRMLFile::VRMLFile(void) :
96 Inherited(),
98 _pSceneRootNode (NULL),
100 _pCurrNodeHelper(NULL),
101 _sNodeHelpers (),
103 _pCurrentFC (NULL ),
104 _pCurrentFieldFC (NULL ),
105 _pCurrentField ( ),
106 _pCurrentFieldDesc(NULL ),
108 _fcStack (),
109 _fStack (),
110 _fdStack (),
112 _nameFCMap ()
114 Self::setReferenceHeader("#VRML V2.0 ");
116 initIntExtFieldTypeMapper();
117 initExtIntFieldTypeMapper();
120 /*-------------------------------------------------------------------------*/
121 /* Destructor */
123 VRMLFile::~VRMLFile(void)
127 /*-------------------------------------------------------------------------*/
128 /* Skel Replacements */
130 NodeTransitPtr VRMLFile::scanStream(std::istream &iStream)
132 startTime = getSystemTime();
134 _pSceneRootNode = NULL;
135 _pCurrentFC = NULL;
137 _nameFCMap.clear();
139 #ifdef OSG_DEBUG_VRML
140 VRMLNodeHelper::resetIndent();
141 #endif
143 if(iStream)
145 Inherited::scanStream(iStream);
148 SceneFileHandler::the()->updateReadProgress(100);
150 NodeTransitPtr returnValue(_pSceneRootNode);
152 _pSceneRootNode = NULL;
153 _pCurrentFC = NULL;
155 FINFO(("Full Time : %lf | Use Time %lf\n",
156 getSystemTime() - startTime,
157 useTime));
159 return returnValue;
162 bool VRMLFile::checkHeader(void)
164 return true;
167 void VRMLFile::handleError(void *pSelf, const Char8 *szErrorText)
169 Inherited::handleError(pSelf, szErrorText);
170 // on an error we destroy the incomplete scene.
172 #if 0
173 if(_pSceneRootNode != NULL)
175 _pSceneRootNode = NULL;
177 #endif
180 void VRMLFile::beginNode(const Char8 *szNodeTypename,
181 const Char8 *szNodename,
182 const BitVector bvLocalFlags )
184 SceneFileHandler::the()->updateReadProgress();
186 FieldContainerUnrecPtr pNewNode;
188 #ifdef OSG_DEBUG_VRML
189 indentLog(VRMLNodeHelper::getIndent(), PINFO);
190 PINFO << "Begin Node " << szNodeTypename << std::endl;
192 VRMLNodeHelper::incIndent();
193 #endif
195 VRMLNodeHelper *pOldHelper = _pCurrNodeHelper;
197 _pCurrNodeHelper = findNodeHelper(szNodeTypename);
199 _sNodeHelpers.push(_pCurrNodeHelper);
201 if(_pCurrNodeHelper == NULL)
203 std::string szTmp = "Unknow node type '#";
205 szTmp += szNodeTypename;
206 szTmp += "#";
208 Inherited::handleError(this, szTmp.c_str());
210 return;
213 _pCurrNodeHelper->reset();
215 pNewNode = _pCurrNodeHelper->beginNode( szNodeTypename,
216 szNodename,
217 _pCurrentFC);
220 if(szNodename != NULL)
222 if(pNewNode != NULL)
224 std::string szKey = szNodename;
226 AttachmentContainer *pAttC =
227 dynamic_pointer_cast<AttachmentContainer>(pNewNode);
229 if(pAttC != NULL)
231 setName(pAttC, szKey);
234 // amz - I removed the map checks that's more spec conform.
235 // From the spec:
236 // If multiple nodes are given the same name,
237 // each USE statement refers to the closest node with the given
238 // name preceding it
239 // in either the VRML file or prototype definition.
241 //NameContainerMap::iterator mIt = _nameFCMap.find(szKey);
242 //if(mIt == _nameFCMap.end())
244 _nameFCMap[szKey] = pNewNode;
246 // else
247 // {
248 // PWARNING << "Did not add fieldContainer with name "
249 // << szKey
250 // << " a second time"
251 // << std::endl;
252 // }
257 if(pOldHelper != NULL)
259 pOldHelper->setContainerFieldValue( pNewNode,
260 _pCurrentFieldDesc,
261 _pCurrentFieldFC );
264 _pCurrentFC = pNewNode;
266 _fcStack.push(_pCurrentFC);
268 if(_fcStack.size() == 1)
270 Node *pNode = dynamic_cast<Node *>(_pCurrentFC.get());
272 if(pNode != NULL)
274 if(_pSceneRootNode == NULL)
276 _pSceneRootNode = Node::create();
278 _pSceneRootNode->setCore(Group::create());
281 _pSceneRootNode->addChild(pNode);
286 void VRMLFile::endNode(void)
288 SceneFileHandler::the()->updateReadProgress();
290 if(_pCurrNodeHelper == NULL)
292 #ifdef OSG_DEBUG_VRML
293 VRMLNodeHelper::decIndent();
295 indentLog(VRMLNodeHelper::getIndent(), PINFO);
296 PINFO << "End Node " << std::endl;
297 #endif
299 _sNodeHelpers.pop();
301 if(_sNodeHelpers.size() != 0)
303 _pCurrNodeHelper = _sNodeHelpers.top();
305 else
307 _pCurrNodeHelper = NULL;
310 return;
313 _pCurrNodeHelper->endNode(_pCurrentFC);
315 _sNodeHelpers.pop();
317 if(_sNodeHelpers.size() != 0)
319 _pCurrNodeHelper = _sNodeHelpers.top();
321 else
323 _pCurrNodeHelper = NULL;
326 if(_pCurrentFC != NULL)
328 if(_pCurrentFC->getType().isNode() == true)
330 Node *pNode = dynamic_cast<Node *>(_pCurrentFC.get());
332 if(pNode->getCore() == NULL)
334 pNode->setCore(Group::create());
339 _fcStack.pop();
341 if(_fcStack.size() != 0)
343 _pCurrentFC = _fcStack.top();
345 else
347 _pCurrentFC = NULL;
350 if(_pCurrentFieldDesc != NULL)
352 _pCurrentFieldFC = _pCurrentFC;
354 #ifdef OSG_DEBUG_VRML
355 VRMLNodeHelper::decIndent();
357 indentLog(VRMLNodeHelper::getIndent(), PINFO);
358 PINFO << "End Node " << std::endl;
359 #endif
362 void VRMLFile::beginScript(const Char8 *szNodename)
364 beginNode("Script", szNodename, TypeTraits<BitVector>::BitsClear);
367 void VRMLFile::endScript(void)
369 endNode();
372 void VRMLFile::beginField(const Char8 *szFieldname,
373 const UInt32 OSG_VRML_ARG(uiFieldTypeId))
375 if(szFieldname == NULL)
376 return;
378 #ifdef OSG_DEBUG_VRML
379 indentLog(VRMLNodeHelper::getIndent(), PINFO);
380 PINFO << "VRMLFile::beginField : looking for "
381 << szFieldname
382 << " ("
383 << uiFieldTypeId
384 << " | "
385 << _pCurrentField
386 << " | "
387 << _pCurrentFieldDesc
388 << ") "
389 << ScanParseSkel::OSGmfNode
390 << std::endl;
392 VRMLNodeHelper::incIndent();
393 #endif
395 _fStack .push(_pCurrentField );
396 _fdStack.push(_pCurrentFieldDesc);
399 void VRMLFile::endField(void)
401 _fStack.pop();
403 if(_fStack.size() != 0)
405 _pCurrentField = _fStack.top();
407 else
409 _pCurrentField.reset();
413 _fdStack.pop();
415 if(_fdStack.size() != 0)
417 _pCurrentFieldDesc = _fdStack.top();
419 else
421 _pCurrentFieldDesc = NULL;
424 #ifdef OSG_DEBUG_VRML
425 VRMLNodeHelper::decIndent();
427 indentLog(VRMLNodeHelper::getIndent(), PINFO);
428 PINFO << "VRMLFile::endField " << std::endl;
429 #endif
433 void VRMLFile::addFieldValue(const Char8 *szFieldVal)
435 if(_pCurrNodeHelper != NULL)
437 _pCurrNodeHelper->addFieldValue(_pCurrentField,
438 _pCurrentFieldDesc,
439 szFieldVal);
443 void VRMLFile::addImageValue(Image *pImage)
445 if(_pCurrNodeHelper != NULL)
447 _pCurrNodeHelper->addImageValue(_pCurrentField,
448 _pCurrentFieldDesc,
449 pImage );
453 void VRMLFile::beginProto(const Char8 *szProtoname)
455 Inherited::beginProto(szProtoname);
457 _pCurrNodeHelper = Inherited::_pCurrentHelper;
460 void VRMLFile::endProtoInterface(void)
462 Inherited::endProtoInterface();
465 void VRMLFile::endProto(void)
467 Inherited::endProto();
469 if(_sNodeHelpers.size() != 0)
471 _pCurrNodeHelper = _sNodeHelpers.top();
476 void VRMLFile::beginFieldDecl(const Char8 *szFieldType,
477 const UInt32 uiFieldTypeId,
478 const Char8 *szFieldName)
480 Inherited::beginFieldDecl(szFieldType, uiFieldTypeId, szFieldName);
482 getFieldType(szFieldName);
484 beginField(szFieldName, uiFieldTypeId);
487 void VRMLFile::endFieldDecl(void)
489 Inherited::endFieldDecl();
491 endField();
495 UInt32 VRMLFile::getFieldType(const Char8 *szFieldname)
497 UInt32 returnValue = 0;
499 if(_pCurrNodeHelper == NULL)
500 return returnValue;
502 if(szFieldname == NULL)
503 return returnValue;
505 _pCurrentFieldFC = NULL;
506 _pCurrentField.reset();
507 _pCurrentFieldDesc = NULL;
509 _pCurrNodeHelper->getFieldAndDesc(_pCurrentFC,
510 szFieldname,
511 _pCurrentFieldFC,
512 _pCurrentField,
513 _pCurrentFieldDesc);
515 if(_pCurrentFieldDesc != NULL)
516 returnValue = _pCurrentFieldDesc->getFieldType().getId();
518 #ifdef OSG_DEBUG_VRML
519 indentLog(VRMLNodeHelper::getIndent(), PINFO);
520 PINFO << "VRMLFile::getFieldType : Got Field and type "
521 << returnValue << " "
522 << _pCurrentField << " "
523 << _pCurrentFieldDesc << " ";
525 if(_pCurrentFieldDesc != NULL)
526 PINFO << _pCurrentFieldDesc->getFieldType().getName() << std::endl;
527 else
528 PINFO << std::endl;
529 #endif
531 return returnValue;
534 void VRMLFile::use(const Char8 *szName)
536 SceneFileHandler::the()->updateReadProgress();
537 Time beginUse = getSystemTime();
539 FieldContainerUnrecPtr pUsedFC;
541 // try to find a container with the given name attachment
543 #ifdef OSG_DEBUG_VRML
544 indentLog(VRMLNodeHelper::getIndent(), PINFO);
545 PINFO << "VRMLFile::use : looking for "
546 << szName
547 << std::endl;
549 VRMLNodeHelper::incIndent();
550 #endif
552 pUsedFC = findReference(szName);
554 if(pUsedFC == NULL)
556 PWARNING << "No fieldContainer with name found to use"
557 << szName
558 << std::endl;
560 else
562 // assign nodepointer to current sf|mf field
564 if(_pCurrNodeHelper != NULL)
566 if(pUsedFC->getType().isNode())
568 Node *pRootNode = dynamic_pointer_cast<Node>(pUsedFC);
570 pUsedFC = cloneTree(pRootNode);
573 _pCurrNodeHelper->setContainerFieldValue( pUsedFC,
574 _pCurrentFieldDesc,
575 _pCurrentFieldFC );
579 #ifdef OSG_DEBUG_VRML
580 VRMLNodeHelper::decIndent();
581 #endif
583 useTime += (getSystemTime() - beginUse);
586 void VRMLFile::addRoute(const Char8 *szOutNodename,
587 const Char8 *szOutFieldname,
588 const Char8 *szInNodename,
589 const Char8 *szInFieldname )
591 if(szOutNodename == NULL || szOutFieldname == NULL ||
592 szInNodename == NULL || szInFieldname == NULL )
594 FWARNING(("addRoute missing params\n"));
597 FieldContainer *pSrcNode = findReference(szOutNodename);
598 FieldContainer *pDstNode = findReference(szInNodename);
600 AttachmentContainer *pSrc = dynamic_cast<AttachmentContainer *>(pSrcNode);
601 AttachmentContainer *pDst = dynamic_cast<AttachmentContainer *>(pDstNode);
603 if(pSrc == NULL)
605 FWARNING(("Unknow src node %s\n", szOutNodename));
606 return;
609 if(pDstNode == NULL)
611 FWARNING(("Unknow dst node %s\n", szInNodename));
612 return;
615 VRMLGenericAtt *pSrcAtt = dynamic_cast<VRMLGenericAtt *>(
616 pSrc->findAttachment(VRMLGenericAtt::getClassType()));
618 VRMLGenericAtt *pDstAtt = NULL;
620 if(pDst != NULL)
622 pDstAtt = dynamic_cast<VRMLGenericAtt *>(
623 pDst->findAttachment(VRMLGenericAtt::getClassType()));
626 if(pSrcAtt == NULL)
628 Node *pNode = dynamic_cast<Node *>(pSrc);
630 if(pNode != NULL && pNode->getCore() != NULL)
632 pSrcAtt = dynamic_cast<VRMLGenericAtt *>(
633 pNode->getCore()->findAttachment(
634 VRMLGenericAtt::getClassType()));
638 if(pDstAtt == NULL)
640 Node *pNode = dynamic_cast<Node *>(pDst);
642 if(pNode != NULL && pNode->getCore() != NULL)
644 pDstAtt = dynamic_cast<VRMLGenericAtt *>(
645 pNode->getCore()->findAttachment(
646 VRMLGenericAtt::getClassType()));
651 std::string szOutFName = szOutFieldname;
652 std::string szInFName = szInFieldname;
655 std::string::size_type uiPos = szOutFName.rfind(std::string("_changed"));
658 if(uiPos != std::string::npos)
660 szOutFName.erase(uiPos, std::string::npos);
663 uiPos = szInFName.find(std::string("set_"));
665 if(uiPos != std::string::npos)
667 szInFName.erase(uiPos, uiPos + 4);
671 if(pSrcAtt != NULL)
673 VRMLNodeHelper *pHelper = findNodeHelper(
674 pSrcAtt->getVrmlNodeTypename().c_str());
676 if(pHelper != NULL)
678 pHelper->mapFieldname(pSrcAtt->getVrmlNodeTypename(), szOutFName);
682 if(pSrcAtt != NULL)
684 VRMLNodeHelper *pHelper = findNodeHelper(
685 pDstAtt->getVrmlNodeTypename().c_str());
687 if(pHelper != NULL)
689 pHelper->mapFieldname(pDstAtt->getVrmlNodeTypename(), szInFName);
693 addConnection(pSrc, szOutFName.c_str(),
694 pDstNode, szInFName .c_str());
697 /*-------------------------------------------------------------------------*/
698 /* Helper */
700 void VRMLFile::scanStandardPrototypes(const Char8 *szFilename)
702 #ifdef OSG_DEBUG_VRML
703 VRMLNodeHelper::resetIndent();
704 #endif
706 preStandardProtos();
707 scanFile(szFilename);
708 postStandardProtos();
711 #if 0
712 static Action::ResultE modifyMaterial(Node * const node)
714 MaterialGroup *mg = dynamic_cast<MaterialGroup *>(node->getCore());
716 if(mg == NULL)
717 return Action::Continue;
719 ChunkMaterial *cmat = dynamic_cast<ChunkMaterial *>(mg->getMaterial());
721 if(cmat == NULL)
722 return Action::Continue;
724 TextureObjChunk *texc =
725 dynamic_cast<TextureObjChunk *>(
726 cmat->find(TextureObjChunk::getClassType()));
728 if(texc == NULL)
729 return Action::Continue;
731 MaterialChunk *matc =
732 dynamic_cast<MaterialChunk *>(
733 cmat->find(MaterialChunk::getClassType()));
735 TextureEnvChunkUnrecPtr texe =
736 dynamic_cast<TextureEnvChunk *>(
737 cmat->find(TextureEnvChunk::getClassType()));
739 if(texe == NULL)
741 texe = TextureEnvChunk::create();
742 cmat->addChunk(texe);
745 if(matc == NULL)
747 // no material chunk so we use the replace mode.
748 texe->setEnvMode(GL_REPLACE);
749 return Action::Continue;
752 if(matc != NULL)
754 Image *img = texc->getImage();
756 texe->setEnvMode(GL_MODULATE);
758 if(img != NULL && img->getBpp() > 2)
760 // for color textures the texture replaces only the diffuse part.
761 matc->setDiffuse(Color4f(1.0f, 1.0f, 1.0f, 1.0f));
765 // check for textures with alpha
766 if(!matc->isTransparent() &&
767 img != NULL &&
768 img->getBpp() == 4 )
770 BlendChunkUnrecPtr blendc =
771 dynamic_cast<BlendChunk *>(
772 cmat->find(BlendChunk::getClassType()));
774 if(blendc == NULL)
776 blendc = OSG::BlendChunk::create();
778 blendc->setSrcFactor (GL_SRC_ALPHA);
779 blendc->setDestFactor(GL_ONE_MINUS_SRC_ALPHA);
781 cmat->addChunk(blendc);
786 return Action::Continue;
788 #endif
790 /*-------------------------------------------------------------------------*/
791 /* Member */
793 void VRMLFile::initIntExtFieldTypeMapper(void)
795 Self::setIntExtMapping(SFBool::getClassType().getId(),
796 ScanParseSkel::OSGsfBool);
798 Self::setIntExtMapping(SFColor3f::getClassType().getId(),
799 ScanParseSkel::OSGsfColor);
801 Self::setIntExtMapping(SFReal32::getClassType().getId(),
802 ScanParseSkel::OSGsfFloat);
804 Self::setIntExtMapping(SFUnrecImagePtr::getClassType().getId(),
805 ScanParseSkel::OSGsfImage);
807 Self::setIntExtMapping(SFInt32::getClassType().getId(),
808 ScanParseSkel::OSGsfInt32);
810 Self::setIntExtMapping(SFGLenum::getClassType().getId(),
811 ScanParseSkel::OSGsfString);
814 Self::setIntExtMapping(SFQuaternion::getClassType().getId(),
815 ScanParseSkel::OSGsfRotation);
817 Self::setIntExtMapping(SFString::getClassType().getId(),
818 ScanParseSkel::OSGsfString);
820 Self::setIntExtMapping(SFTime::getClassType().getId(),
821 ScanParseSkel::OSGsfTime);
823 Self::setIntExtMapping(SFVec2f::getClassType().getId(),
824 ScanParseSkel::OSGsfVec2f);
826 Self::setIntExtMapping(SFVec2s::getClassType().getId(),
827 ScanParseSkel::OSGsfVec2i);
829 Self::setIntExtMapping(SFVec3f::getClassType().getId(),
830 ScanParseSkel::OSGsfVec3f);
834 Self::setIntExtMapping(MFColor3f::getClassType().getId(),
835 ScanParseSkel::OSGmfColor);
837 Self::setIntExtMapping(MFReal32::getClassType().getId(),
838 ScanParseSkel::OSGmfFloat);
840 Self::setIntExtMapping(MFInt32::getClassType().getId(),
841 ScanParseSkel::OSGmfInt32);
843 Self::setIntExtMapping(MFGLenum::getClassType().getId(),
844 ScanParseSkel::OSGmfString);
846 Self::setIntExtMapping(MFQuaternion::getClassType().getId(),
847 ScanParseSkel::OSGmfRotation);
849 Self::setIntExtMapping(MFString::getClassType().getId(),
850 ScanParseSkel::OSGmfString);
852 Self::setIntExtMapping(MFTime::getClassType().getId(),
853 ScanParseSkel::OSGmfTime);
855 Self::setIntExtMapping(MFVec3f::getClassType().getId(),
856 ScanParseSkel::OSGmfVec3f);
858 Self::setIntExtMapping(MFVec2f::getClassType().getId(),
859 ScanParseSkel::OSGmfVec2f);
862 Self::setIntExtMapping(SFUnrecFieldContainerPtr::getClassType().getId(),
863 ScanParseSkel::OSGsfNode);
865 Self::setIntExtMapping(MFUnrecFieldContainerPtr::getClassType().getId(),
866 ScanParseSkel::OSGmfNode);
868 Self::setIntExtMapping(SFUnrecNodePtr::getClassType().getId(),
869 ScanParseSkel::OSGsfNode);
871 Self::setIntExtMapping(MFUnrecChildNodePtr::getClassType().getId(),
872 ScanParseSkel::OSGmfNode);
874 /* To Base Type Mappings */
876 Self::setIntExtMapping(SFUInt8::getClassType().getId(),
877 ScanParseSkel::OSGsfInt32);
879 Self::setIntExtMapping(MFUInt8::getClassType().getId(),
880 ScanParseSkel::OSGmfInt32);
882 Self::setIntExtMapping(SFUInt32::getClassType().getId(),
883 ScanParseSkel::OSGsfInt32);
885 Self::setIntExtMapping(MFUInt32::getClassType().getId(),
886 ScanParseSkel::OSGmfInt32);
888 /* To Node Mappings */
890 Self::setIntExtMapping(SFUnrecNodeCorePtr::getClassType().getId(),
891 ScanParseSkel::OSGsfNode);
893 Self::setIntExtMapping(SFUnrecMaterialPtr::getClassType().getId(),
894 ScanParseSkel::OSGsfNode);
896 // AMZ
897 #if 0
898 Self::setIntExtMapping(SFGeoPTypesPtr::getClassType().getId(),
899 ScanParseSkel::OSGsfNode);
901 Self::setIntExtMapping(SFGeoIndicesPtr::getClassType().getId(),
902 ScanParseSkel::OSGsfNode);
904 Self::setIntExtMapping(SFGeoPLengthsPtr::getClassType().getId(),
905 ScanParseSkel::OSGsfNode);
907 Self::setIntExtMapping(SFGeoColorsPtr::getClassType().getId(),
908 ScanParseSkel::OSGsfNode);
910 Self::setIntExtMapping(SFGeoPositionsPtr::getClassType().getId(),
911 ScanParseSkel::OSGsfNode);
913 Self::setIntExtMapping(SFGeoNormalsPtr::getClassType().getId(),
914 ScanParseSkel::OSGsfNode);
916 Self::setIntExtMapping(SFGeoTexCoordsPtr::getClassType().getId(),
917 ScanParseSkel::OSGsfNode);
918 #endif
919 Self::setIntExtMapping(MFUnrecStateChunkPtr::getClassType().getId(),
920 ScanParseSkel::OSGmfNode);
922 //SFAttachmentMap
923 Self::setIntExtMapping(SFAttachmentPtrMap::getClassType().getId(),
924 ScanParseSkel::OSGmfNode);
926 /* extended types */
928 Self::setIntExtMapping(SFMatrix::getClassType().getId(),
929 ScanParseSkel::OSGsfMatrix);
931 Self::setIntExtMapping(SFPnt3f::getClassType().getId(),
932 ScanParseSkel::OSGsfPnt3f);
934 Self::setIntExtMapping(MFPnt3f::getClassType().getId(),
935 ScanParseSkel::OSGmfPnt3f);
939 void VRMLFile::initExtIntFieldTypeMapper(void)
941 Self::setExtIntMapping(ScanParseSkel::OSGsfBool,
942 SFBool::getClassType().getId());
944 Self::setExtIntMapping(ScanParseSkel::OSGsfColor,
945 SFColor3f::getClassType().getId());
947 Self::setExtIntMapping(ScanParseSkel::OSGsfFloat,
948 SFReal32::getClassType().getId());
951 Self::setExtIntMapping(SFImage::getClassType().getId(),
952 ScanParseSkel::OSGsfInt32);
955 Self::setExtIntMapping(ScanParseSkel::OSGsfImage,
956 SFUnrecImagePtr::getClassType().getId());
958 Self::setExtIntMapping(ScanParseSkel::OSGsfInt32,
959 SFInt32::getClassType().getId());
962 Self::setExtIntMapping(ScanParseSkel::OSGsfRotation,
963 SFQuaternion::getClassType().getId());
965 Self::setExtIntMapping(ScanParseSkel::OSGsfString,
966 SFString::getClassType().getId());
968 Self::setExtIntMapping(ScanParseSkel::OSGsfTime,
969 SFTime::getClassType().getId());
971 Self::setExtIntMapping(ScanParseSkel::OSGsfVec2f,
972 SFVec2f::getClassType().getId());
974 Self::setExtIntMapping(ScanParseSkel::OSGsfVec2i,
975 SFVec2s::getClassType().getId());
977 Self::setExtIntMapping(ScanParseSkel::OSGsfVec3f,
978 SFVec3f::getClassType().getId());
982 Self::setExtIntMapping(ScanParseSkel::OSGmfColor,
983 MFColor3f::getClassType().getId());
985 Self::setExtIntMapping(ScanParseSkel::OSGmfFloat,
986 MFReal32::getClassType().getId());
988 Self::setExtIntMapping(ScanParseSkel::OSGmfInt32,
989 MFInt32::getClassType().getId());
991 Self::setExtIntMapping(ScanParseSkel::OSGmfRotation,
992 MFQuaternion::getClassType().getId());
994 Self::setExtIntMapping(ScanParseSkel::OSGmfString,
995 MFString::getClassType().getId());
997 Self::setExtIntMapping(ScanParseSkel::OSGmfTime,
998 MFTime::getClassType().getId());
1001 Self::setExtIntMapping(ScanParseSkel::OSGmfVec3f,
1002 MFVec3f::getClassType().getId());
1004 Self::setExtIntMapping(ScanParseSkel::OSGmfVec2f,
1005 MFVec2f::getClassType().getId());
1008 Self::setExtIntMapping(ScanParseSkel::OSGsfNode,
1009 SFUnrecFieldContainerPtr::getClassType().getId());
1011 Self::setExtIntMapping(ScanParseSkel::OSGmfNode,
1012 MFUnrecFieldContainerPtr::getClassType().getId());
1015 /* extended types */
1017 Self::setExtIntMapping(ScanParseSkel::OSGsfMatrix,
1018 SFMatrix::getClassType().getId());
1020 Self::setExtIntMapping(ScanParseSkel::OSGsfPnt3f,
1021 SFPnt3f::getClassType().getId());
1023 Self::setExtIntMapping(ScanParseSkel::OSGmfPnt3f,
1024 MFPnt3f::getClassType().getId());
1027 /* remove this, if there is a general methode to find containers */
1028 FieldContainer *VRMLFile::findFCByName(const Char8 *szName,
1029 Node *pNode)
1031 MFUnrecNodePtr::const_iterator i;
1033 FieldContainer *pFC = NULL;
1035 #if 0
1036 Name *pNodename = NULL;
1037 NodeCore *pCore = NULL;
1038 // check if name matches nodename
1040 pNodename =
1041 dynamic_cast<NamePtr>(
1042 pNode->findAttachment(Name::getClassType().getGroupId()));
1044 if(pNodename != NullFC)
1046 if(strcmp(szName, pNodename->getFieldPtr()->getValue().c_str())==0)
1047 return pNode;
1049 // check if name matches corename
1051 pCore = pNode->getCore();
1053 if(pCore != NullFC)
1055 pNodename = dynamic_cast<NamePtr>(
1056 pCore->findAttachment(Name::getClassType().getGroupId()));
1058 if(pNodename != NullFC)
1060 if(strcmp(szName, pNodename->getFieldPtr()->getValue().c_str())==0)
1061 return pCore;
1065 // matching for children
1066 for(i = pNode->getMFChildren()->begin();
1067 i != pNode->getMFChildren()->end();
1068 i++)
1070 pFC = findFCByName(szName, *i);
1072 if(pFC != NullFC)
1074 return pFC;
1077 #endif
1079 return pFC;
1082 FieldContainer *VRMLFile::findReference(const Char8 *szName)
1084 // search reference in this file
1085 FieldContainer *returnValue = NULL;
1087 std::string szKey = szName;
1089 NameContainerMap::iterator mIt = _nameFCMap.find(szKey);
1091 if(mIt != _nameFCMap.end())
1093 returnValue = mIt->second;
1095 else
1097 returnValue = findFCByName(szName, _pSceneRootNode);
1100 return returnValue;
1104 #include "OSGVRMLProtos.inl"
1106 OSG_END_NAMESPACE