From 6b52e17c488cbb32c8c7687038156be56db6c1f6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 4 Aug 2002 21:11:00 +0000 Subject: [PATCH] Fix to iv/vrml loader so that it correctly passes back the right ReadResult and checks the validity of the file extension being passed to the plugin. Removed main.cpp * .h moving all its functionality into readerwriter.cpp. --- VisualStudio/osgPlugins/iv/iv.dsp | 8 ----- src/osgPlugins/iv/Makefile | 1 - src/osgPlugins/iv/main.cpp | 56 ------------------------------ src/osgPlugins/iv/main.h | 22 ------------ src/osgPlugins/iv/osgvisitor.cpp | 16 ++++----- src/osgPlugins/iv/readerwriter.cpp | 44 +++++++++++++++++++++-- src/osgPlugins/iv/readerwriter.h | 7 ++-- 7 files changed, 52 insertions(+), 102 deletions(-) delete mode 100644 src/osgPlugins/iv/main.cpp delete mode 100644 src/osgPlugins/iv/main.h diff --git a/VisualStudio/osgPlugins/iv/iv.dsp b/VisualStudio/osgPlugins/iv/iv.dsp index 2092632cc..e9dc26f4a 100644 --- a/VisualStudio/osgPlugins/iv/iv.dsp +++ b/VisualStudio/osgPlugins/iv/iv.dsp @@ -93,10 +93,6 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File -SOURCE=..\..\..\src\osgPlugins\iv\main.cpp -# End Source File -# Begin Source File - SOURCE=..\..\..\src\osgPlugins\iv\nodecache.cpp # End Source File # Begin Source File @@ -169,10 +165,6 @@ SOURCE=..\..\..\src\osgPlugins\iv\ltstr.h # End Source File # Begin Source File -SOURCE=..\..\..\src\osgPlugins\iv\main.h -# End Source File -# Begin Source File - SOURCE=..\..\..\src\osgPlugins\iv\material.h # End Source File # Begin Source File diff --git a/src/osgPlugins/iv/Makefile b/src/osgPlugins/iv/Makefile index eaa17cb44..bd8d49f5f 100644 --- a/src/osgPlugins/iv/Makefile +++ b/src/osgPlugins/iv/Makefile @@ -2,7 +2,6 @@ TOPDIR = ../../.. include $(TOPDIR)/Make/makedefs CXXFILES =\ - main.cpp\ nodecache.cpp\ normals.cpp\ osgvisitor.cpp\ diff --git a/src/osgPlugins/iv/main.cpp b/src/osgPlugins/iv/main.cpp deleted file mode 100644 index 386a4b72e..000000000 --- a/src/osgPlugins/iv/main.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * osgDB::wrl - a VRML 1.0 loader for OpenSceneGraph - * Copyright (C) 2002 Ruben Lopez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef WIN32 -# pragma warning (disable:4786) -# pragma warning (disable:4541) -#endif -#include -#include -#include "mynode.h" -#include "osgvisitor.h" - -#include -#include - -extern int yyparse(); -extern int yydebug; -extern MyNode *getRoot(); -extern FILE *yyin; -int isatty(int) { return 0; } -extern void flush_scanner(); - -osg::Node *readVRMLNode(const char *file) { - yydebug=0; - yyin=fopen(file,"r"); - std::cout << "Parsing..." << std::endl; - if (yyparse()!=0) { - flush_scanner(); - return 0; - } - osg::ref_ptr n=getRoot(); - try { - std::cout << "Generating OSG tree..." << std::endl; - osg::ref_ptr visitante=new OSGVisitor(n.get()); - return visitante->getRoot(); - } catch (...) { - std::cerr << "VRML: error reading" << std::endl; - return 0; - } -} diff --git a/src/osgPlugins/iv/main.h b/src/osgPlugins/iv/main.h deleted file mode 100644 index bede0c6cd..000000000 --- a/src/osgPlugins/iv/main.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * osgDB::wrl - a VRML 1.0 loader for OpenSceneGraph - * Copyright (C) 2002 Ruben Lopez - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include - -osg::Node *readVRMLNode(const char *file); diff --git a/src/osgPlugins/iv/osgvisitor.cpp b/src/osgPlugins/iv/osgvisitor.cpp index 620fefcb9..7c7a0777b 100644 --- a/src/osgPlugins/iv/osgvisitor.cpp +++ b/src/osgPlugins/iv/osgvisitor.cpp @@ -17,10 +17,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifdef WIN32 -# pragma warning (disable:4786) -# pragma warning (disable:4541) -#endif +#include + #include #include "osgvisitor.h" #include "material.h" @@ -98,7 +96,7 @@ public: texture->setImage(osgDB::readImageFile(_texture)); texture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT); texture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT); - std::cout << "Loading texture " << _texture << std::endl; + osg::notify(osg::INFO) << "Loading texture " << _texture << std::endl; textures[_texture]=texture; } return textures[_texture].get(); @@ -128,7 +126,7 @@ OSGVisitor::OSGVisitor(MyNode *nodo) { total_vert=0; two_sided=false; nodo->accept(this); - std::cout << "Model of " << total_vert << " vertices" << std::endl; + osg::notify(osg::INFO) << "Model of " << total_vert << " vertices" << std::endl; } void OSGVisitor::applyMyNode(MyNode *) { @@ -228,7 +226,7 @@ void OSGVisitor::makeGeode(osg::Geode *geode, osg::Geometry *geometry, bool twoS if (!twoSided) { state->setAttributeAndModes(cull,osg::StateAttribute::ON); } else { - //std::cout << "Deactivating culling for this object" << std::endl; + //osg::notify(osg::INFO) << "Deactivating culling for this object" << std::endl; state->setAttributeAndModes(cull,osg::StateAttribute::OFF); osg::Transparency *transp=new osg::Transparency(); transp->setFunction(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); @@ -255,13 +253,13 @@ void OSGVisitor::makeGeode(osg::Geode *geode, osg::Geometry *geometry, bool twoS if (material_active) { AtrVec3List *diffuse=dynamic_cast(material_active->getAttribute("diffuseColor")); if (diffuse) { // Has per-vertex colors - std::cout << "Per vertex colors" << std::endl; + osg::notify(osg::INFO) << "Per vertex colors" << std::endl; VertexList *colors=diffuse->getList(); osg::Vec3Array *colors_osg=new osg::Vec3Array(); for (unsigned i=0;isize();i++) { colors_osg->push_back((*colors)[i]); } - std::cout << colors->size() << " colors" << std::endl; + osg::notify(osg::INFO) << colors->size() << " colors" << std::endl; geometry->setColorArray(colors_osg); geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX); } diff --git a/src/osgPlugins/iv/readerwriter.cpp b/src/osgPlugins/iv/readerwriter.cpp index 11f86aa8b..b6a491eec 100644 --- a/src/osgPlugins/iv/readerwriter.cpp +++ b/src/osgPlugins/iv/readerwriter.cpp @@ -22,11 +22,49 @@ # pragma warning (disable:4541) #endif #include "readerwriter.h" -#include "main.h" + +#include +#include + +#include + +#include "mynode.h" +#include "osgvisitor.h" + +extern int yyparse(); +extern int yydebug; +extern MyNode *getRoot(); +extern FILE *yyin; +int isatty(int) { return 0; } +extern void flush_scanner(); + osgDB::ReaderWriter::ReadResult VrmlReaderWriter::readNode(const std::string& fileName, - const osgDB::ReaderWriter::Options*) { - return readVRMLNode(fileName.c_str()); + const osgDB::ReaderWriter::Options*) +{ + std::string ext = osgDB::getFileExtension(fileName); + if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; + + yydebug=0; + yyin=fopen(fileName.c_str(),"r"); + osg::notify(osg::INFO) << "Parsing..." << std::endl; + if (yyparse()!=0) + { + flush_scanner(); + return ReadResult::FILE_NOT_HANDLED; + } + osg::ref_ptr n=getRoot(); + try + { + osg::notify(osg::INFO) << "Generating OSG tree..." << std::endl; + osg::ref_ptr visitante=new OSGVisitor(n.get()); + return visitante->getRoot(); + } + catch (...) + { + osg::notify(osg::INFO) << "VRML: error reading" << std::endl; + return ReadResult::ERROR_IN_READING_FILE; + } } osgDB::RegisterReaderWriterProxy g_readerWriter_VRML_Proxy; diff --git a/src/osgPlugins/iv/readerwriter.h b/src/osgPlugins/iv/readerwriter.h index a3158d87f..3a754f16a 100644 --- a/src/osgPlugins/iv/readerwriter.h +++ b/src/osgPlugins/iv/readerwriter.h @@ -30,9 +30,10 @@ class VrmlReaderWriter: public osgDB::ReaderWriter { public: VrmlReaderWriter() { } virtual const char* className() { return "VRML"; } - virtual bool acceptsExtension(const std::string& extension) { - return osgDB::equalCaseInsensitive(extension,"wrl") - || osgDB::equalCaseInsensitive(extension,"iv"); + virtual bool acceptsExtension(const std::string& extension) + { + return osgDB::equalCaseInsensitive(extension,"wrl") || + osgDB::equalCaseInsensitive(extension,"iv"); } virtual ReadResult readNode(const std::string& fileName,const osgDB::ReaderWriter::Options*); };