Further steps towards reading coniguration files.

This commit is contained in:
Robert Osfield
2007-09-21 13:30:33 +00:00
parent 609315caa5
commit ece7b57df2
10 changed files with 219 additions and 8 deletions

View File

@@ -23,9 +23,66 @@ class OSGReaderWriter : public ReaderWriter
return equalCaseInsensitive(extension,"osg");
}
virtual ReadResult readObject(const std::string& fileName, const Options* opt) const { return readNode(fileName, opt); }
virtual ReadResult readObject(const std::string& file, const Options* opt) const
{
std::string ext = osgDB::getLowerCaseFileExtension(file);
if (equalCaseInsensitive(ext,"osgs"))
{
std::istringstream fin(osgDB::getNameLessExtension(file));
if (fin) return readNode(fin,opt);
return ReadResult::ERROR_IN_READING_FILE;
}
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
virtual ReadResult readObject(std::istream& fin, const Options* opt) const { return readNode(fin, opt); }
std::string fileName = osgDB::findDataFile( file, opt );
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
// code for setting up the database path so that internally referenced file are searched for on relative paths.
osg::ref_ptr<Options> local_opt = opt ? static_cast<Options*>(opt->clone(osg::CopyOp::SHALLOW_COPY)) : new Options;
local_opt->setDatabasePath(osgDB::getFilePath(fileName));
std::ifstream fin(fileName.c_str());
if (fin)
{
return readObject(fin, local_opt.get());
}
return 0L;
}
virtual ReadResult readObject(std::istream& fin, const Options* options) const
{
fin.imbue(std::locale::classic());
Input fr;
fr.attach(&fin);
fr.setOptions(options);
typedef std::vector<osg::Object*> ObjectList;
ObjectList objectList;
// load all nodes in file, placing them in a group.
while(!fr.eof())
{
Object *object = fr.readObject();
if (object) objectList.push_back(object);
else fr.advanceOverCurrentFieldOrBlock();
}
if (objectList.empty())
{
return ReadResult("No data loaded");
}
else if (objectList.size()==1)
{
return objectList.front();
}
else
{
return objectList.front();
}
}
virtual ReadResult readNode(const std::string& file, const Options* opt) const
{

View File

@@ -1,6 +1,8 @@
SET(TARGET_SRC
View.cpp
Viewer.cpp
CompositeViewer.cpp
ReaderWriterOsgViewer.cpp
)
SET(TARGET_ADDED_LIBRARIES osgViewer )

View File

@@ -0,0 +1,40 @@
#include <osgViewer/CompositeViewer>
#include <iostream>
#include <string>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool CompositeViewer_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool CompositeViewer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy CompositeViewer_Proxy
(
new osgViewer::CompositeViewer,
"CompositeViewer",
"Object CompositeViewer",
CompositeViewer_readLocalData,
CompositeViewer_writeLocalData
);
bool CompositeViewer_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgViewer::CompositeViewer& compositeViewer = static_cast<osgViewer::CompositeViewer&>(obj);
bool iteratorAdvanced = false;
osg::notify(osg::NOTICE)<<"CompositeViewer_readLocalData"<<std::endl;
return iteratorAdvanced;
}
bool CompositeViewer_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgViewer::CompositeViewer& compositeViewer = static_cast<const osgViewer::CompositeViewer&>(obj);
osg::notify(osg::NOTICE)<<"CompositeViewer_writeLocalData"<<std::endl;
return true;
}

View File

@@ -29,7 +29,7 @@ public:
virtual bool acceptsExtension(const std::string& extension) const
{
return osgDB::equalCaseInsensitive( extension, "osgViewer" ) || osgDB::equalCaseInsensitive( extension, "view" ) ;
return osgDB::equalCaseInsensitive( extension, "osgviewer" ) || osgDB::equalCaseInsensitive( extension, "view" ) ;
}

View File

@@ -60,6 +60,8 @@ bool View_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgViewer::View& view = static_cast<const osgViewer::View&>(obj);
osg::notify(osg::NOTICE)<<"View_writeLocalData"<<std::endl;
if (view.getCamera())
{
fw.writeObject(*view.getCamera());

View File

@@ -0,0 +1,36 @@
#include <osgViewer/Viewer>
#include <iostream>
#include <string>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool Viewer_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool Viewer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Viewer_Proxy
(
new osgViewer::Viewer,
"Viewer",
"Object Viewer View",
Viewer_readLocalData,
Viewer_writeLocalData
);
bool Viewer_readLocalData(osg::Object &obj, osgDB::Input &fr)
{
osgViewer::Viewer& viewer = static_cast<osgViewer::Viewer&>(obj);
bool iteratorAdvanced = false;
return iteratorAdvanced;
}
bool Viewer_writeLocalData(const osg::Object &obj, osgDB::Output &fw)
{
const osgViewer::Viewer& viewer = static_cast<const osgViewer::Viewer&>(obj);
return true;
}