diff --git a/src/conversion/vtk/output/foamVtkOutput.C b/src/conversion/vtk/output/foamVtkOutput.C index 4ece681a85..fc2d298841 100644 --- a/src/conversion/vtk/output/foamVtkOutput.C +++ b/src/conversion/vtk/output/foamVtkOutput.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -62,14 +62,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile vtmFile .xmlHeader() - .openTag("VTKFile") - ( "type", content ) - ( "version", "1.0" ) - ( "byte_order", foamVtkFormatter::byteOrder ) - ( "header_type", foamVtkFormatter::headerType ) - .closeTag(); - - vtmFile.tag(content); + .beginVTKFile(content, "1.0"); forAll(files, i) { @@ -80,7 +73,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile .closeTag(true); } - vtmFile.endTag(content).endTag("VTKFile"); + vtmFile.endTag(content).endVTKFile(); return files.size(); } diff --git a/src/conversion/vtk/output/foamVtkOutput.H b/src/conversion/vtk/output/foamVtkOutput.H index ad7964bfff..f0897d6675 100644 --- a/src/conversion/vtk/output/foamVtkOutput.H +++ b/src/conversion/vtk/output/foamVtkOutput.H @@ -58,6 +58,12 @@ class foamVtkOutput public: + // Public typedefs + + //- Use UInt64 for header data + typedef foamVtkFormatter::headerType headerType; + + // Forward declarations class legacy; diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.C b/src/fileFormats/vtk/format/foamVtkFormatter.C index 2bc607a78a..5b9fded769 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkFormatter.C @@ -23,16 +23,6 @@ License \*---------------------------------------------------------------------------*/ #include "foamVtkFormatter.H" -#include "foamVtkPTraits.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -const char* const Foam::foamVtkFormatter::byteOrder - = Foam::foamVtkPTraits::typeName; - -const char* const Foam::foamVtkFormatter::headerType = - Foam::foamVtkPTraits::typeName; - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -145,16 +135,6 @@ Foam::foamVtkFormatter::closeTag(const bool isEmpty) } -Foam::foamVtkFormatter& -Foam::foamVtkFormatter::tag(const word& tag) -{ - openTag(tag); - closeTag(); - - return *this; -} - - Foam::foamVtkFormatter& Foam::foamVtkFormatter::endTag(const word& tag) { @@ -186,6 +166,53 @@ Foam::foamVtkFormatter::endTag(const word& tag) } +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::tag(const word& tag) +{ + openTag(tag); + closeTag(); + + return *this; +} + + +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::beginVTKFile +( + const word& contentType, + const word& contentVersion, + const bool leaveOpen +) +{ + openTag("VTKFile"); + xmlAttr("type", contentType); + xmlAttr("version", contentVersion); + xmlAttr("byte_order", foamVtkPTraits::typeName); + xmlAttr("header_type", foamVtkPTraits::typeName); + closeTag(); + + openTag(contentType); + if (!leaveOpen) + { + closeTag(); + } + + return *this; +} + + +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::beginAppendedData() +{ + openTag("AppendedData"); + xmlAttr("encoding", encoding()); + closeTag(); + os_ << '_'; + + return *this; +} + + Foam::foamVtkFormatter& Foam::foamVtkFormatter::xmlAttr ( @@ -258,55 +285,35 @@ Foam::foamVtkFormatter::xmlAttr // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const std::string& v -) +Foam::foamVtkFormatter::operator()(const word& k, const std::string& v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const int32_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const int32_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const int64_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const int64_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const uint64_t v -) +Foam::foamVtkFormatter::operator()(const word& k, const uint64_t v) { return xmlAttr(k, v); } Foam::foamVtkFormatter& -Foam::foamVtkFormatter::operator() -( - const word& k, - const scalar v -) +Foam::foamVtkFormatter::operator()(const word& k, const scalar v) { return xmlAttr(k, v); } diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 5ab0776d60..9e37f2c625 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -89,13 +89,10 @@ protected: public: - // Static Data + // Public typedefs - //- VTK name for the 'byte_order' attribute - static const char* const byteOrder; - - //- VTK name for the 'header_type' attribute (UInt64) - static const char* const headerType; + //- Use UInt64 for header data + typedef uint64_t headerType; //- Destructor @@ -161,6 +158,20 @@ public: //- Write XML tag without any attributes. Combines openTag/closeTag. foamVtkFormatter& tag(const word& tag); + //- Add a "VTKFile" XML tag for contentType, followed by a tag for + // the contentType itself. Optionally leave the contentType tag + // open for adding additional attributes. + foamVtkFormatter& beginVTKFile + ( + const word& contentType, + const word& contentVersion, + const bool leaveOpen = false + ); + + //- Add a "AppendedData" XML tag with the current encoding and output + // the requisite '_' prefix. + foamVtkFormatter& beginAppendedData(); + //- Open "DataArray" XML tag template @@ -174,11 +185,25 @@ public: //- End "DataArray" XML tag - foamVtkFormatter& endDataArray() + inline foamVtkFormatter& endDataArray() { return endTag("DataArray"); } + //- End "AppendedData" XML tag + inline foamVtkFormatter& endAppendedData() + { + flush(); // flush any pending encoded content + os_ << '\n'; // clear separation from content. + return endTag("AppendedData"); + } + + //- End "VTKFile" XML tag + inline foamVtkFormatter& endVTKFile() + { + return endTag("VTKFile"); + } + //- Write XML attribute foamVtkFormatter& xmlAttr