2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-10-04 23:12:57 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
#ifndef OSGDB_OUTPUT
|
|
|
|
#define OSGDB_OUTPUT 1
|
|
|
|
|
|
|
|
#include <osg/Object>
|
|
|
|
|
2005-09-19 22:07:44 +08:00
|
|
|
#include <osgDB/ReaderWriter>
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace osgDB {
|
|
|
|
|
|
|
|
/** ofstream wrapper class for adding support for indenting.
|
|
|
|
Used in output of .osg ASCII files to improve their readability.*/
|
2001-12-15 05:49:04 +08:00
|
|
|
class OSGDB_EXPORT Output : public std::ofstream
|
2001-09-20 05:08:56 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Output();
|
|
|
|
Output(const char* name);
|
|
|
|
|
|
|
|
virtual ~Output();
|
|
|
|
|
2005-09-19 22:07:44 +08:00
|
|
|
|
|
|
|
void setOptions(const ReaderWriter::Options* options) { _options = options; }
|
|
|
|
const ReaderWriter::Options* getOptions() const { return _options.get(); }
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
void open(const char *name);
|
2002-01-21 00:24:54 +08:00
|
|
|
|
|
|
|
// comment out temporarily to avoid compilation problems, RO Jan 2002.
|
|
|
|
// void open(const char *name,int mode);
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
Output& indent();
|
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
/** wrap a string with "" quotes and use \" for any internal quotes.*/
|
|
|
|
std::string wrapString(const std::string& str);
|
2002-10-28 20:55:19 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void setIndentStep(int step) { _indentStep = step; }
|
2002-09-02 20:31:35 +08:00
|
|
|
inline int getIndentStep() const { return _indentStep; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
inline void setIndent(int indent) { _indent = indent; }
|
2002-09-02 20:31:35 +08:00
|
|
|
inline int getIndent() const { return _indent; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
inline void setNumIndicesPerLine(int num) { _numIndicesPerLine = num; }
|
2002-09-02 20:31:35 +08:00
|
|
|
inline int getNumIndicesPerLine() const { return _numIndicesPerLine; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
void moveIn();
|
|
|
|
void moveOut();
|
|
|
|
|
|
|
|
virtual bool writeObject(const osg::Object& obj);
|
2007-05-09 18:01:15 +08:00
|
|
|
virtual void writeBeginObject(const std::string& name);
|
|
|
|
virtual void writeEndObject();
|
|
|
|
virtual void writeUseID(const std::string& id);
|
|
|
|
virtual void writeUniqueID(const std::string& id);
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
bool getUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
|
|
|
|
bool createUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
|
|
|
|
bool registerUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
|
|
|
|
|
|
|
|
enum PathNameHint
|
|
|
|
{
|
|
|
|
AS_IS,
|
|
|
|
FULL_PATH,
|
|
|
|
RELATIVE_PATH,
|
|
|
|
FILENAME_ONLY
|
|
|
|
};
|
|
|
|
|
|
|
|
inline void setPathNameHint(const PathNameHint pnh) { _pathNameHint = pnh; }
|
2003-05-17 16:36:25 +08:00
|
|
|
inline PathNameHint getPathNameHint() const { return _pathNameHint; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2003-05-17 16:36:25 +08:00
|
|
|
virtual std::string getFileNameForOutput(const std::string& filename) const;
|
2004-11-15 05:08:10 +08:00
|
|
|
const std::string& getFileName() const { return _filename; }
|
2001-09-20 05:08:56 +08:00
|
|
|
|
2005-10-27 04:30:15 +08:00
|
|
|
void setOutputTextureFiles(bool flag) { _outputTextureFiles = flag; }
|
2005-09-19 22:07:44 +08:00
|
|
|
bool getOutputTextureFiles() const { return _outputTextureFiles; }
|
|
|
|
|
|
|
|
virtual std::string getTextureFileNameForOutput();
|
2003-01-08 22:32:13 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
|
|
virtual void init();
|
|
|
|
|
2005-09-19 22:07:44 +08:00
|
|
|
osg::ref_ptr<const ReaderWriter::Options> _options;
|
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
int _indent;
|
|
|
|
int _indentStep;
|
|
|
|
|
|
|
|
int _numIndicesPerLine;
|
|
|
|
|
|
|
|
typedef std::map<const osg::Object*,std::string> UniqueIDToLabelMapping;
|
|
|
|
UniqueIDToLabelMapping _objectToUniqueIDMap;
|
|
|
|
|
|
|
|
std::string _filename;
|
|
|
|
|
|
|
|
PathNameHint _pathNameHint;
|
2005-09-19 22:07:44 +08:00
|
|
|
bool _outputTextureFiles;
|
|
|
|
unsigned int _textureFileNameNumber;
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-09-20 05:08:56 +08:00
|
|
|
|
|
|
|
#endif // __SG_OUTPUT_H
|