Added better handling of writeNode operations that arn't successful.
This commit is contained in:
parent
ac9a28051f
commit
530e9e08d4
@ -630,11 +630,20 @@ int main( int argc, char **argv )
|
||||
std::cout<<"Warning: compressing texture only supported when outputing to .ive"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
if (osgDB::writeNodeFile(*root,fileNameOut))
|
||||
|
||||
osgDB::ReaderWriter::WriteResult result = osgDB::Registry::instance()->writeNode(*root,fileNameOut);
|
||||
if (result.success())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Data written to '"<<fileNameOut<<"'."<< std::endl;
|
||||
}
|
||||
else if (result.message().empty())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Warning: file write to '"<<fileNameOut<<"' no supported."<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<result.message()<< std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -164,6 +164,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
osg::Node* takeNode();
|
||||
osgDB::Archive* takeArchive();
|
||||
|
||||
std::string& message() { return _message; }
|
||||
const std::string& message() const { return _message; }
|
||||
|
||||
ReadStatus status() const { return _status; }
|
||||
@ -197,6 +198,7 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
||||
WriteResult(const WriteResult& rr):_status(rr._status),_message(rr._message) {}
|
||||
WriteResult& operator = (const WriteResult& rr) { if (this==&rr) return *this; _status=rr._status; _message=rr._message; return *this; }
|
||||
|
||||
std::string& message() { return _message; }
|
||||
const std::string& message() const { return _message; }
|
||||
|
||||
WriteStatus status() const { return _status; }
|
||||
|
@ -96,10 +96,12 @@ class OSGDB_EXPORT Registry : public osg::Referenced
|
||||
/** create the platform specific library name associated with nodekit library name.*/
|
||||
std::string createLibraryNameForNodeKit(const std::string& name);
|
||||
|
||||
/** find the library in the SG_LIBRARY_PATH and load it.*/
|
||||
/** find the library in the OSG_LIBRARY_PATH and load it.*/
|
||||
bool loadLibrary(const std::string& fileName);
|
||||
|
||||
/** close the attached library with specified name.*/
|
||||
bool closeLibrary(const std::string& fileName);
|
||||
|
||||
/** close all libraries.*/
|
||||
void closeAllLibraries();
|
||||
|
||||
|
@ -1519,6 +1519,16 @@ ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,
|
||||
return ReaderWriter::WriteResult("Warning: Could not find plugin to write objects to file \""+fileName+"\".");
|
||||
}
|
||||
|
||||
if (results.front().message().empty())
|
||||
{
|
||||
switch(results.front().status())
|
||||
{
|
||||
case(ReaderWriter::WriteResult::FILE_NOT_HANDLED): results.front().message() = "Warning: Write to \""+fileName+"\" not supported."; break;
|
||||
case(ReaderWriter::WriteResult::ERROR_IN_WRITING_FILE): results.front().message() = "Warning: Error in writing to \""+fileName+"\"."; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return results.front();
|
||||
}
|
||||
|
||||
@ -1545,6 +1555,8 @@ ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,
|
||||
else results.push_back(rr);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
|
||||
// now look for a plug-in to save the file.
|
||||
std::string libraryName = createLibraryNameForFile(fileName);
|
||||
if (loadLibrary(libraryName))
|
||||
@ -1562,6 +1574,16 @@ ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,
|
||||
return ReaderWriter::WriteResult("Warning: Could not find plugin to write image to file \""+fileName+"\".");
|
||||
}
|
||||
|
||||
if (results.front().message().empty())
|
||||
{
|
||||
switch(results.front().status())
|
||||
{
|
||||
case(ReaderWriter::WriteResult::FILE_NOT_HANDLED): results.front().message() = "Warning: Write to \""+fileName+"\" not supported."; break;
|
||||
case(ReaderWriter::WriteResult::ERROR_IN_WRITING_FILE): results.front().message() = "Warning: Error in writing to \""+fileName+"\"."; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return results.front();
|
||||
}
|
||||
|
||||
@ -1587,6 +1609,8 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF
|
||||
else results.push_back(rr);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
|
||||
// now look for a plug-in to save the file.
|
||||
std::string libraryName = createLibraryNameForFile(fileName);
|
||||
if (loadLibrary(libraryName))
|
||||
@ -1603,6 +1627,16 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF
|
||||
{
|
||||
return ReaderWriter::WriteResult("Warning: Could not find plugin to write HeightField to file \""+fileName+"\".");
|
||||
}
|
||||
|
||||
if (results.front().message().empty())
|
||||
{
|
||||
switch(results.front().status())
|
||||
{
|
||||
case(ReaderWriter::WriteResult::FILE_NOT_HANDLED): results.front().message() = "Warning: Write to \""+fileName+"\" not supported."; break;
|
||||
case(ReaderWriter::WriteResult::ERROR_IN_WRITING_FILE): results.front().message() = "Warning: Error in writing to \""+fileName+"\"."; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return results.front();
|
||||
}
|
||||
@ -1629,13 +1663,18 @@ ReaderWriter::WriteResult Registry::writeNodeImplementation(const Node& node,con
|
||||
else results.push_back(rr);
|
||||
}
|
||||
|
||||
results.clear();
|
||||
|
||||
// now look for a plug-in to save the file.
|
||||
std::string libraryName = createLibraryNameForFile(fileName);
|
||||
|
||||
|
||||
if (loadLibrary(libraryName))
|
||||
{
|
||||
for(;itr.valid();++itr)
|
||||
{
|
||||
ReaderWriter::WriteResult rr = itr->writeNode(node,fileName,_options.get());
|
||||
|
||||
if (rr.success()) return rr;
|
||||
else results.push_back(rr);
|
||||
}
|
||||
@ -1646,6 +1685,16 @@ ReaderWriter::WriteResult Registry::writeNodeImplementation(const Node& node,con
|
||||
return ReaderWriter::WriteResult("Warning: Could not find plugin to write nodes to file \""+fileName+"\".");
|
||||
}
|
||||
|
||||
if (results.front().message().empty())
|
||||
{
|
||||
switch(results.front().status())
|
||||
{
|
||||
case(ReaderWriter::WriteResult::FILE_NOT_HANDLED): results.front().message() = "Warning: Write to \""+fileName+"\" not supported."; break;
|
||||
case(ReaderWriter::WriteResult::ERROR_IN_WRITING_FILE): results.front().message() = "Warning: Error in writing to \""+fileName+"\"."; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return results.front();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user