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

OSGVRMLSceneFileType.cpp

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 <fstream>
00043 
00044 #include "OSGConfig.h"
00045 
00046 #include "OSGVRMLSceneFileType.h"
00047 #include "OSGVRMLWriteAction.h"
00048 
00049 OSG_USING_NAMESPACE
00050 
00055 const Char8 *VRMLSceneFileType::_suffixA[] =  { "wrl" };
00056 
00057 VRMLSceneFileType VRMLSceneFileType::_the(_suffixA,
00058                                           sizeof(_suffixA),
00059                                           false,
00060                                           10,
00061                                           OSG_READ_SUPPORTED | 
00062                                           OSG_WRITE_SUPPORTED);
00063 
00064 VRMLFile *VRMLSceneFileType::_pVRMLLoader = NULL;
00065 
00066 /*-------------------------------------------------------------------------*/
00067 /*                                The                                      */
00068 
00069 VRMLSceneFileType &VRMLSceneFileType::the(void)
00070 {
00071     return _the;
00072 }
00073 
00074 
00075 /*-------------------------------------------------------------------------*/
00076 /*                             Destructor                                  */
00077 
00078 VRMLSceneFileType::~VRMLSceneFileType(void)
00079 {
00080 }
00081 
00082 /*-------------------------------------------------------------------------*/
00083 /*                                Get                                      */
00084 
00085 const Char8 *VRMLSceneFileType::getName(void) const
00086 {
00087     return "VRML GEOMETRY";
00088 }
00089 
00090 /*-------------------------------------------------------------------------*/
00091 /*                               Read                                      */
00092 
00093 NodePtr VRMLSceneFileType::read(std::istream &is, const Char8 *) const
00094 {
00095     if(_pVRMLLoader == NULL)
00096     {
00097         _pVRMLLoader = new VRMLFile();
00098 
00099 //        _pVRMLLoader->scanStandardPrototypes("std.wrl", 0);
00100         _pVRMLLoader->createStandardPrototypes();
00101     }
00102 
00103     _pVRMLLoader->scanStream(is);
00104 
00105     return  _pVRMLLoader->getRoot();
00106 }
00107 
00108 /*-------------------------------------------------------------------------*/
00109 /*                               Write                                     */
00110 
00111 bool VRMLSceneFileType::write(const NodePtr &node, std::ostream &os,
00112                               const Char8 *fileNameOrExtension) const
00113 {
00114     // This is a hack but should be safer.
00115     std::ofstream *osf = dynamic_cast<std::ofstream *>(&os);
00116     if(osf != NULL)
00117         osf->close();
00118     
00119     VRMLWriteAction *pWriter = VRMLWriteAction::create();
00120 
00121     pWriter->open(fileNameOrExtension);
00122 
00123     pWriter->write(node);
00124 
00125     pWriter->close();
00126 
00127     return true;
00128 }
00129 
00130 /*-------------------------------------------------------------------------*/
00131 /*                            Constructors                                 */
00132 
00133 VRMLSceneFileType::VRMLSceneFileType(const Char8  *suffixArray[],
00134                                            UInt16  suffixByteCount,
00135                                            bool    override,
00136                                            UInt32  overridePriority,
00137                                            UInt32  flags) :
00138     Inherited(suffixArray,
00139               suffixByteCount,
00140               override,
00141               overridePriority,
00142               flags)
00143 {
00144 }
00145 
00146 
00147 /*-------------------------------------------------------------------------*/
00148 /*                              cvs id's                                   */
00149 
00150 #ifdef __sgi
00151 #pragma set woff 1174
00152 #endif
00153 
00154 #ifdef OSG_LINUX_ICC
00155 #pragma warning( disable : 177 )
00156 #endif
00157 
00158 namespace
00159 {
00160     static Char8 cvsid_cpp[] = "@(#)$Id: $";
00161     static Char8 cvsid_hpp[] = OSGVRMLSCENEFILETYPE_HEADER_CVSID;
00162 }
00163 

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