1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSGDB_OUTPUT
15#define OSGDB_OUTPUT 1
16
17#include <osg/Object>
18
19#include <osgDB/ReaderWriter>
20#include <osgDB/fstream>
21
22#include <string>
23#include <map>
24
25namespace osgDB {
26
27/** deprecated. */
28class OSGDB_EXPORT Output : public osgDB::ofstream
29{
30    public:
31
32        Output();
33        Output(const char* name);
34
35        virtual ~Output();
36
37
38        void setOptions(const Options* options);
39        const Options* getOptions() const { return _options.get(); }
40
41        void setWriteOutDefaultValues(bool flag) { _writeOutDefaultValues = flag; }
42        bool getWriteOutDefaultValues() const { return _writeOutDefaultValues; }
43
44        void open(const char *name);
45
46        // comment out temporarily to avoid compilation problems, RO Jan 2002.
47        // void open(const char *name,int mode);
48
49        Output& indent();
50
51        /** wrap a string with "" quotes and use \" for any internal quotes.*/
52        std::string wrapString(const char* str);
53
54        /** wrap a string with "" quotes and use \" for any internal quotes.*/
55        std::string wrapString(const std::string& str);
56
57        inline void setIndentStep(int step) { _indentStep = step; }
58        inline int getIndentStep() const { return _indentStep; }
59
60        inline void setIndent(int indent)  { _indent = indent; }
61        inline int getIndent() const { return _indent; }
62
63        inline void setNumIndicesPerLine(int num) { _numIndicesPerLine = num; }
64        inline int getNumIndicesPerLine() const { return _numIndicesPerLine; }
65
66        void moveIn();
67        void moveOut();
68
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);
74
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);
78
79        enum PathNameHint
80        {
81            AS_IS,
82            FULL_PATH,
83            RELATIVE_PATH,
84            FILENAME_ONLY
85        };
86
87        inline void setPathNameHint(const PathNameHint pnh) { _pathNameHint = pnh; }
88        inline PathNameHint getPathNameHint() const { return _pathNameHint; }
89
90        virtual std::string getFileNameForOutput(const std::string& filename) const;
91        const std::string& getFileName() const { return _filename; }
92
93        // Set and get if export texture files during write
94        void setOutputTextureFiles(bool flag) { _outputTextureFiles = flag; }
95        bool getOutputTextureFiles() const { return _outputTextureFiles; }
96
97        // support code for OutputTextureFiles
98        virtual std::string getTextureFileNameForOutput();
99
100        void setOutputShaderFiles(bool flag) { _outputShaderFiles = flag; }
101        bool getOutputShaderFiles() const { return _outputShaderFiles; }
102
103        virtual std::string getShaderFileNameForOutput();
104
105        void setExternalFileWritten(const std::string& filename, bool hasBeenWritten=true);
106        bool getExternalFileWritten(const std::string& filename) const;
107
108    protected:
109
110
111        virtual void init();
112
113        osg::ref_ptr<const Options> _options;
114
115        int _indent;
116        int _indentStep;
117
118        int _numIndicesPerLine;
119
120        typedef std::map<const osg::Object*,std::string> UniqueIDToLabelMapping;
121        UniqueIDToLabelMapping _objectToUniqueIDMap;
122
123        std::string _filename;
124
125        PathNameHint _pathNameHint;
126
127        bool _outputTextureFiles;
128        unsigned int _textureFileNameNumber;
129
130        bool _outputShaderFiles;
131        unsigned int _shaderFileNameNumber;
132
133        bool _writeOutDefaultValues;
134
135        typedef std::map<std::string, bool> ExternalFileWrittenMap;
136        ExternalFileWrittenMap _externalFileWritten;
137};
138
139}
140
141#endif                                            // __SG_OUTPUT_H
142