diff --git a/include/osgDB/ReaderWriter b/include/osgDB/ReaderWriter index 8e9a39e19..60a2753da 100644 --- a/include/osgDB/ReaderWriter +++ b/include/osgDB/ReaderWriter @@ -122,7 +122,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object CacheHintOptions getObjectCacheHint() const { return _objectCacheHint; } /** Sets a plugindata value PluginData with a string */ - void setPluginData(const std::string& s, void* v) { _pluginData[s] = v; } + void setPluginData(const std::string& s, void* v) const { _pluginData[s] = v; } /** Get a value from the PluginData */ void* getPluginData(const std::string& s) { return _pluginData[s]; } @@ -135,7 +135,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object } /** Remove a value from the PluginData */ - void removePluginData(const std::string& s) { _pluginData.erase(s); } + void removePluginData(const std::string& s) const { _pluginData.erase(s); } protected: @@ -146,7 +146,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object CacheHintOptions _objectCacheHint; typedef std::map PluginDataMap; - PluginDataMap _pluginData; + mutable PluginDataMap _pluginData; }; diff --git a/src/osgPlugins/dae/ReaderWriterDAE.cpp b/src/osgPlugins/dae/ReaderWriterDAE.cpp index 1dd4e132b..947a30cf3 100644 --- a/src/osgPlugins/dae/ReaderWriterDAE.cpp +++ b/src/osgPlugins/dae/ReaderWriterDAE.cpp @@ -11,6 +11,7 @@ */ #include +#include #include #include @@ -72,7 +73,13 @@ ReaderWriterDAE::readNode(const std::string& fname, const osgDB::ReaderWriter::Options* options) const { SERIALIZER(); - + + DAE* daeptr = 0L; + + if ( options ) { + daeptr = (DAE*) options->getPluginData("DAE"); + } + std::string ext( osgDB::getLowerCaseFileExtension(fname) ); if( ! acceptsExtension(ext) ) return ReadResult::FILE_NOT_HANDLED; @@ -81,10 +88,14 @@ ReaderWriterDAE::readNode(const std::string& fname, osg::notify(osg::INFO) << "ReaderWriterDAE( \"" << fileName << "\" )" << std::endl; - if (_dae == NULL) - _dae = new DAE(); + + if (daeptr == NULL) { + if (_dae == NULL) + _dae = new DAE(); + daeptr = _dae; + } - osgdae::daeReader daeReader(_dae); + osgdae::daeReader daeReader(daeptr) ; std::string fileURI( osgDB::convertFileNameToUnixStyle(fileName) ); if ( ! daeReader.convert( fileURI ) ) { @@ -92,6 +103,17 @@ ReaderWriterDAE::readNode(const std::string& fname, return ReadResult::ERROR_IN_READING_FILE; } + if ( options ) { + // return DAE* used + options->setPluginData("DAE", daeptr); + // and filename document was stored as in database, does not have to be + // the same as fname + options->setPluginData("DAE-DocumentFileName", ( fileURI[1] == ':' ? + (void*) new std::auto_ptr(new std::string('/'+fileURI)) : + (void*) new std::auto_ptr(new std::string(fileURI)) ) + ); + } + osg::Node* rootNode( daeReader.getRootNode() ); return rootNode; } @@ -104,9 +126,15 @@ ReaderWriterDAE::writeNode( const osg::Node& node, { SERIALIZER(); + DAE* daeptr = 0L; + std::string ext( osgDB::getLowerCaseFileExtension(fname) ); if( ! acceptsExtension(ext) ) return WriteResult::FILE_NOT_HANDLED; + if ( options ) { + daeptr = (DAE*) options->getPluginData("DAE"); + } + // Process options bool usePolygon(false); if( options ) @@ -129,10 +157,13 @@ ReaderWriterDAE::writeNode( const osg::Node& node, } } - if (_dae == NULL) - _dae = new DAE(); + if (daeptr == NULL) { + if (_dae == NULL) + _dae = new DAE(); + daeptr = _dae; + } - osgdae::daeWriter daeWriter(_dae, fname, usePolygon ); + osgdae::daeWriter daeWriter(daeptr, fname, usePolygon ); daeWriter.setRootNode( node ); const_cast(&node)->accept( daeWriter ); @@ -145,6 +176,17 @@ ReaderWriterDAE::writeNode( const osg::Node& node, } } + if ( options ) { + // return DAE* used + options->setPluginData("DAE", daeptr); + + // saving filename so read and write work the same way, + // this could be skipped since write does not currently modify the + // filename which load might do (under windows for example) + options->setPluginData("DAE-DocumentFileName", (void*) new + std::auto_ptr(new std::string(fname))); + } + return retVal; } diff --git a/src/osgPlugins/dae/daeReader.h b/src/osgPlugins/dae/daeReader.h index e98515a8d..d8a73670d 100644 --- a/src/osgPlugins/dae/daeReader.h +++ b/src/osgPlugins/dae/daeReader.h @@ -176,7 +176,7 @@ protected: AuthoringTool m_AuthoringTool; }; -}; +} #endif diff --git a/src/osgPlugins/dae/daeWriter.h b/src/osgPlugins/dae/daeWriter.h index a10892437..9e64219a5 100644 --- a/src/osgPlugins/dae/daeWriter.h +++ b/src/osgPlugins/dae/daeWriter.h @@ -242,7 +242,7 @@ private: //members std::string uniquify( const std::string &name ); }; -}; +} #endif diff --git a/src/osgWrappers/osgDB/ReaderWriter.cpp b/src/osgWrappers/osgDB/ReaderWriter.cpp index 6170d8d68..d9f935e41 100644 --- a/src/osgWrappers/osgDB/ReaderWriter.cpp +++ b/src/osgWrappers/osgDB/ReaderWriter.cpp @@ -251,6 +251,26 @@ BEGIN_OBJECT_REFLECTOR(osgDB::ReaderWriter::Options) __CacheHintOptions__getObjectCacheHint, "Get whether the Registry::ObjectCache should be used by default. ", ""); + I_Method2(void, setPluginData, IN, const std::string &, s, IN, void *, v, + Properties::NON_VIRTUAL, + __void__setPluginData__C5_std_string_R1__void_P1, + "Sets a plugindata value PluginData with a string. ", + ""); + I_Method1(void *, getPluginData, IN, const std::string &, s, + Properties::NON_VIRTUAL, + __void_P1__getPluginData__C5_std_string_R1, + "Get a value from the PluginData. ", + ""); + I_Method1(const void *, getPluginData, IN, const std::string &, s, + Properties::NON_VIRTUAL, + __C5_void_P1__getPluginData__C5_std_string_R1, + "Get a value from the PluginData. ", + ""); + I_Method1(void, removePluginData, IN, const std::string &, s, + Properties::NON_VIRTUAL, + __void__removePluginData__C5_std_string_R1, + "Remove a value from the PluginData. ", + ""); I_SimpleProperty(const std::string &, DatabasePath, 0, __void__setDatabasePath__C5_std_string_R1); @@ -263,6 +283,10 @@ BEGIN_OBJECT_REFLECTOR(osgDB::ReaderWriter::Options) I_SimpleProperty(const std::string &, OptionString, __C5_std_string_R1__getOptionString, __void__setOptionString__C5_std_string_R1); + I_IndexedProperty(void *, PluginData, + __void_P1__getPluginData__C5_std_string_R1, + __void__setPluginData__C5_std_string_R1__void_P1, + 0); END_REFLECTOR BEGIN_ENUM_REFLECTOR(osgDB::ReaderWriter::ReadResult::ReadStatus)