Output 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifndef OSGDB_OUTPUT
  14. #define OSGDB_OUTPUT 1
  15. #include <osg/Object>
  16. #include <osgDB/ReaderWriter>
  17. #include <osgDB/fstream>
  18. #include <string>
  19. #include <map>
  20. namespace osgDB {
  21. /** deprecated. */
  22. class OSGDB_EXPORT Output : public osgDB::ofstream
  23. {
  24. public:
  25. Output();
  26. Output(const char* name);
  27. virtual ~Output();
  28. void setOptions(const Options* options);
  29. const Options* getOptions() const { return _options.get(); }
  30. void setWriteOutDefaultValues(bool flag) { _writeOutDefaultValues = flag; }
  31. bool getWriteOutDefaultValues() const { return _writeOutDefaultValues; }
  32. void open(const char *name);
  33. // comment out temporarily to avoid compilation problems, RO Jan 2002.
  34. // void open(const char *name,int mode);
  35. Output& indent();
  36. /** wrap a string with "" quotes and use \" for any internal quotes.*/
  37. std::string wrapString(const char* str);
  38. /** wrap a string with "" quotes and use \" for any internal quotes.*/
  39. std::string wrapString(const std::string& str);
  40. inline void setIndentStep(int step) { _indentStep = step; }
  41. inline int getIndentStep() const { return _indentStep; }
  42. inline void setIndent(int indent) { _indent = indent; }
  43. inline int getIndent() const { return _indent; }
  44. inline void setNumIndicesPerLine(int num) { _numIndicesPerLine = num; }
  45. inline int getNumIndicesPerLine() const { return _numIndicesPerLine; }
  46. void moveIn();
  47. void moveOut();
  48. virtual bool writeObject(const osg::Object& obj);
  49. virtual void writeBeginObject(const std::string& name);
  50. virtual void writeEndObject();
  51. virtual void writeUseID(const std::string& id);
  52. virtual void writeUniqueID(const std::string& id);
  53. bool getUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
  54. bool createUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
  55. bool registerUniqueIDForObject(const osg::Object* obj,std::string& uniqueID);
  56. enum PathNameHint
  57. {
  58. AS_IS,
  59. FULL_PATH,
  60. RELATIVE_PATH,
  61. FILENAME_ONLY
  62. };
  63. inline void setPathNameHint(const PathNameHint pnh) { _pathNameHint = pnh; }
  64. inline PathNameHint getPathNameHint() const { return _pathNameHint; }
  65. virtual std::string getFileNameForOutput(const std::string& filename) const;
  66. const std::string& getFileName() const { return _filename; }
  67. // Set and get if export texture files during write
  68. void setOutputTextureFiles(bool flag) { _outputTextureFiles = flag; }
  69. bool getOutputTextureFiles() const { return _outputTextureFiles; }
  70. // support code for OutputTextureFiles
  71. virtual std::string getTextureFileNameForOutput();
  72. void setOutputShaderFiles(bool flag) { _outputShaderFiles = flag; }
  73. bool getOutputShaderFiles() const { return _outputShaderFiles; }
  74. virtual std::string getShaderFileNameForOutput();
  75. void setExternalFileWritten(const std::string& filename, bool hasBeenWritten=true);
  76. bool getExternalFileWritten(const std::string& filename) const;
  77. protected:
  78. virtual void init();
  79. osg::ref_ptr<const Options> _options;
  80. int _indent;
  81. int _indentStep;
  82. int _numIndicesPerLine;
  83. typedef std::map<const osg::Object*,std::string> UniqueIDToLabelMapping;
  84. UniqueIDToLabelMapping _objectToUniqueIDMap;
  85. std::string _filename;
  86. PathNameHint _pathNameHint;
  87. bool _outputTextureFiles;
  88. unsigned int _textureFileNameNumber;
  89. bool _outputShaderFiles;
  90. unsigned int _shaderFileNameNumber;
  91. bool _writeOutDefaultValues;
  92. typedef std::map<std::string, bool> ExternalFileWrittenMap;
  93. ExternalFileWrittenMap _externalFileWritten;
  94. };
  95. }
  96. #endif // __SG_OUTPUT_H