diff --git a/src/osgPlugins/osg/AsciiStreamOperator.h b/src/osgPlugins/osg/AsciiStreamOperator.h index 091d497ae..9fca5768b 100644 --- a/src/osgPlugins/osg/AsciiStreamOperator.h +++ b/src/osgPlugins/osg/AsciiStreamOperator.h @@ -7,8 +7,12 @@ class AsciiOutputIterator : public osgDB::OutputIterator { public: - AsciiOutputIterator( std::ostream* ostream ) - : _readyForIndent(false), _indent(0) { _out = ostream; } + AsciiOutputIterator( std::ostream* ostream, int precision ) + : _readyForIndent(false), _indent(0) + { + _out = ostream; + if (precision>0) _out->precision(precision); + } virtual ~AsciiOutputIterator() {} diff --git a/src/osgPlugins/osg/ReaderWriterOSG2.cpp b/src/osgPlugins/osg/ReaderWriterOSG2.cpp index 41eb55cc8..9f20d07f3 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG2.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG2.cpp @@ -71,15 +71,29 @@ InputIterator* readInputIterator( std::istream& fin, const Options* options ) OutputIterator* writeOutputIterator( std::ostream& fout, const Options* options ) { + // Read precision parameter, for text & XML formats + int precision(-1); + if ( options ) { + std::istringstream iss(options->getOptionString()); + std::string opt; + while (iss >> opt) + { + if(opt=="PRECISION" || opt=="precision") + { + iss >> precision; + } + } + } + if ( options && options->getOptionString().find("Ascii")!=std::string::npos ) { fout << std::string("#Ascii") << ' '; - return new AsciiOutputIterator(&fout); + return new AsciiOutputIterator(&fout, precision); } else if ( options && options->getOptionString().find("XML")!=std::string::npos ) { fout << std::string("") << std::endl; - return new XmlOutputIterator(&fout); + return new XmlOutputIterator(&fout, precision); } else { diff --git a/src/osgPlugins/osg/XmlStreamOperator.h b/src/osgPlugins/osg/XmlStreamOperator.h index c85d0a767..16fc4fe41 100644 --- a/src/osgPlugins/osg/XmlStreamOperator.h +++ b/src/osgPlugins/osg/XmlStreamOperator.h @@ -19,10 +19,11 @@ public: TEXT_LINE // A text line, e.g. recording array elements }; - XmlOutputIterator( std::ostream* ostream ) + XmlOutputIterator( std::ostream* ostream, int precision ) : _readLineType(FIRST_LINE), _prevReadLineType(FIRST_LINE), _hasSubProperty(false) { _out = ostream; + if (precision>0) _sstream.precision(precision); _root = new osgDB::XmlNode; _root->type = osgDB::XmlNode::GROUP; }