1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
19#include <osgDB/ReaderWriter>
20#include <osgDB/fstream>
28class OSGDB_EXPORT Output : public osgDB::ofstream
33 Output(const char* name);
38 void setOptions(const Options* options);
39 const Options* getOptions() const { return _options.get(); }
41 void setWriteOutDefaultValues(bool flag) { _writeOutDefaultValues = flag; }
42 bool getWriteOutDefaultValues() const { return _writeOutDefaultValues; }
44 void open(const char *name);
46 // comment out temporarily to avoid compilation problems, RO Jan 2002.
47 // void open(const char *name,int mode);
51 /** wrap a string with "" quotes and use \" for any internal quotes.*/
52 std::string wrapString(const char* str);
54 /** wrap a string with "" quotes and use \" for any internal quotes.*/
55 std::string wrapString(const std::string& str);
57 inline void setIndentStep(int step) { _indentStep = step; }
58 inline int getIndentStep() const { return _indentStep; }
60 inline void setIndent(int indent) { _indent = indent; }
61 inline int getIndent() const { return _indent; }
63 inline void setNumIndicesPerLine(int num) { _numIndicesPerLine = num; }
64 inline int getNumIndicesPerLine() const { return _numIndicesPerLine; }
69 virtual bool writeObject(const osg::Object& obj);
70 virtual void writeBeginObject(const std::string& name);
71 virtual void writeEndObject();
72 virtual void writeUseID(const std::string& id);
73 virtual void writeUniqueID(const std::string& id);
75 bool getUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
76 bool createUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
77 bool registerUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
87 inline void setPathNameHint(const PathNameHint pnh) { _pathNameHint = pnh; }
88 inline PathNameHint getPathNameHint() const { return _pathNameHint; }
90 virtual std::string getFileNameForOutput(const std::string& filename) const;
91 const std::string& getFileName() const { return _filename; }
93 // Set and get if export texture files during write
94 void setOutputTextureFiles(bool flag) { _outputTextureFiles = flag; }
95 bool getOutputTextureFiles() const { return _outputTextureFiles; }
97 // support code for OutputTextureFiles
98 virtual std::string getTextureFileNameForOutput();
100 void setOutputShaderFiles(bool flag) { _outputShaderFiles = flag; }
101 bool getOutputShaderFiles() const { return _outputShaderFiles; }
103 virtual std::string getShaderFileNameForOutput();
105 void setExternalFileWritten(const std::string& filename, bool hasBeenWritten=true);
106 bool getExternalFileWritten(const std::string& filename) const;
113 osg::ref_ptr<const Options> _options;
118 int _numIndicesPerLine;
120 typedef std::map<const osg::Object*,std::string> UniqueIDToLabelMapping;
121 UniqueIDToLabelMapping _objectToUniqueIDMap;
123 std::string _filename;
125 PathNameHint _pathNameHint;
127 bool _outputTextureFiles;
128 unsigned int _textureFileNameNumber;
130 bool _outputShaderFiles;
131 unsigned int _shaderFileNameNumber;
133 bool _writeOutDefaultValues;
135 typedef std::map<std::string, bool> ExternalFileWrittenMap;
136 ExternalFileWrittenMap _externalFileWritten;
141#endif // __SG_OUTPUT_H