From 4a0e9a6ad20e0b75426b00126e1d51e4e29c4b72 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 23 Feb 2009 09:54:25 +0000 Subject: [PATCH] From Ralf Habacker & Robert Osfield, fixed handling of file name string of the form"PG:host=localhost user=postgres dbname=osm tables=public.planet_osm_line". The patch also routes gdal debug and error message to the related osg::notify debug port - this is usefull for debugging ogr plugin. --- src/osgPlugins/ogr/ReaderWriterOGR.cpp | 27 +++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/osgPlugins/ogr/ReaderWriterOGR.cpp b/src/osgPlugins/ogr/ReaderWriterOGR.cpp index 8e9b01a84..0fb9084a0 100644 --- a/src/osgPlugins/ogr/ReaderWriterOGR.cpp +++ b/src/osgPlugins/ogr/ReaderWriterOGR.cpp @@ -38,6 +38,17 @@ #define SERIALIZER() OpenThreads::ScopedLock lock(_serializerMutex) +void CPL_STDCALL CPLOSGErrorHandler( CPLErr eErrClass, int nError, + const char * pszErrorMsg ) +{ + if( eErrClass == CE_Debug ) + osg::notify(osg::DEBUG_INFO) << pszErrorMsg << std::endl; + else if( eErrClass == CE_Warning ) + osg::notify(osg::WARN) << nError << " " << pszErrorMsg << std::endl; + else + osg::notify(osg::FATAL) << nError << " " << pszErrorMsg << std::endl; +} + static osg::Material* createDefaultMaterial() { osg::Vec4 color; @@ -86,19 +97,29 @@ public: supportsExtension("ogr","OGR file reader"); supportsOption("useRandomColorByFeature", "Assign a random color to each feature."); supportsOption("addGroupPerFeature", "Places each feature in a seperate group."); + oldHandler = CPLSetErrorHandler(CPLOSGErrorHandler); } + + virtual ~ReaderWriterOGR() + { + CPLSetErrorHandler(oldHandler); + } + virtual const char* className() const { return "OGR file reader"; } virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const { + osg::notify(osg::NOTICE)<<"OGR::readNode("< lock(_serializerMutex); + return readFile(osgDB::getNameLessExtension(file), options); } OpenThreads::ScopedLock lock(_serializerMutex); std::string fileName = osgDB::findDataFile( file, options ); - if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; + if (fileName.empty()) return readFile(file, options); // ReadResult::FILE_NOT_FOUND; return readFile(fileName, options); } @@ -418,7 +439,7 @@ public: } mutable OpenThreads::ReentrantMutex _serializerMutex; - + CPLErrorHandler oldHandler; }; // now register with Registry to instantiate the above