2001-09-20 05:08:56 +08:00
|
|
|
#include <osgDB/Output>
|
|
|
|
#include <osgDB/Registry>
|
|
|
|
#include <osgDB/FileNameUtils>
|
|
|
|
|
|
|
|
#include <osg/Notify>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2001-12-15 07:18:28 +08:00
|
|
|
using namespace std;
|
2001-09-20 05:08:56 +08:00
|
|
|
using namespace osgDB;
|
|
|
|
|
|
|
|
Output::Output()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Output::Output(const char* name) : ofstream(name)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
_filename = name;
|
|
|
|
}
|
|
|
|
|
2001-12-15 07:18:28 +08:00
|
|
|
Output::Output(const Output&) : ofstream() {}
|
|
|
|
|
|
|
|
Output& Output::operator = (const Output&) { return *this; }
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
Output::~Output()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Output::init()
|
|
|
|
{
|
|
|
|
_indent = 0;
|
|
|
|
_indentStep = 2;
|
|
|
|
_numIndicesPerLine = 10;
|
|
|
|
_pathNameHint = AS_IS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Output::open(const char *name)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
ofstream::open(name);
|
|
|
|
_filename = name;
|
|
|
|
}
|
|
|
|
|
2002-01-21 00:24:54 +08:00
|
|
|
// Comment out to avoid compile errors under new compilers, the int mode
|
|
|
|
// is now a replaced by a class to wrap the mode.
|
|
|
|
// This method is not used right now to hopefully nobody will miss it...
|
|
|
|
// Jan 2002.
|
|
|
|
// void Output::open(const char *name,int mode)
|
|
|
|
// {
|
|
|
|
// init();
|
|
|
|
// ofstream::open(name,mode);
|
|
|
|
// _filename = name;
|
|
|
|
// }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
Output& Output::indent()
|
|
|
|
{
|
|
|
|
for(int i=0;i<_indent;++i) *this<<' ';
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Output::moveIn()
|
|
|
|
{
|
|
|
|
_indent += _indentStep;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Output::moveOut()
|
|
|
|
{
|
|
|
|
_indent -= _indentStep;
|
|
|
|
if (_indent<0) _indent=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Output::writeObject(const osg::Object& obj)
|
|
|
|
{
|
|
|
|
return Registry::instance()->writeObject(obj,*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Output::getUniqueIDForObject(const osg::Object* obj,std::string& uniqueID)
|
|
|
|
{
|
|
|
|
UniqueIDToLabelMapping::iterator fitr = _objectToUniqueIDMap.find(obj);
|
|
|
|
if (fitr != _objectToUniqueIDMap.end())
|
|
|
|
{
|
|
|
|
uniqueID = (*fitr).second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Output::createUniqueIDForObject(const osg::Object* obj,std::string& uniqueID)
|
|
|
|
{
|
|
|
|
char str[256];
|
2002-07-14 05:17:40 +08:00
|
|
|
sprintf(str,"%s_%i",obj->className(),(unsigned int)_objectToUniqueIDMap.size());
|
2001-09-20 05:08:56 +08:00
|
|
|
uniqueID = str;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Output::registerUniqueIDForObject(const osg::Object* obj,std::string& uniqueID)
|
|
|
|
{
|
|
|
|
_objectToUniqueIDMap[obj] = uniqueID;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string Output::getFileNameForOutput(const std::string& filename) const
|
|
|
|
{
|
|
|
|
switch(_pathNameHint)
|
|
|
|
{
|
|
|
|
case(FULL_PATH):
|
|
|
|
{
|
|
|
|
// need to think about how best to implement this first...
|
2001-12-15 07:18:28 +08:00
|
|
|
osg::notify(osg::WARN)<<"Warning: Output::getFileNameForOutput() does not support FULL_PATH yet."<< std::endl;
|
2001-09-20 05:08:56 +08:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
case(RELATIVE_PATH):
|
|
|
|
{
|
|
|
|
// need to think about how best to implement this as well...
|
2001-12-15 07:18:28 +08:00
|
|
|
osg::notify(osg::WARN)<<"Warning: Output::getFileNameForOutput() does not support RELATIVE_PATH yet."<< std::endl;
|
2001-09-20 05:08:56 +08:00
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
case(FILENAME_ONLY):
|
|
|
|
// this one is straight forward.
|
|
|
|
return getSimpleFileName(filename);
|
|
|
|
case(AS_IS):
|
|
|
|
default:
|
|
|
|
// and this one is even more trivial.
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
}
|