43 bool Foam::vtk::vtmWriter::vtmEntry::good()
const
47 type_ == vtmEntry::BEGIN_BLOCK
48 || type_ == vtmEntry::END_BLOCK
49 || (type_ == vtmEntry::DATA && file_.size())
56 if (type_ == vtmEntry::BEGIN_BLOCK)
58 format.openTag(vtk::fileTag::BLOCK);
61 format.xmlAttr(
"name", name_);
67 else if (type_ == vtmEntry::END_BLOCK)
72 else if (type_ == vtmEntry::DATA && file_.size())
74 format.openTag(vtk::fileTag::DATA_SET);
78 format.xmlAttr(
"name", name_);
81 format.xmlAttr(
"file", file_);
93 bool Foam::vtk::vtmWriter::pruneEmpty()
95 const label nEntries = entries_.size();
99 for (label src=0; src < nEntries; ++src)
101 if (entries_[src].good())
105 entries_[dst] = std::move(entries_[src]);
111 const bool changed = (dst != nEntries);
118 bool Foam::vtk::vtmWriter::pruneEmptyBlocks()
122 const label nEntries = entries_.size();
126 bool changed =
false;
128 for (label i=0; i < nEntries; ++i)
130 vtmEntry&
e = entries_[i];
132 if (
e.isType(vtmEntry::BEGIN_BLOCK))
134 for (label j=i+1; j < nEntries; ++j)
136 if (entries_[j].
isType(vtmEntry::END_BLOCK))
144 else if (!entries_[j].
isType(vtmEntry::NONE))
171 bool Foam::vtk::vtmWriter::collapseBlocks()
173 bool collapsed =
false;
175 const label nEntries = entries_.size();
177 for (label i=0; i < nEntries-2; ++i)
179 vtmEntry&
b = entries_[i];
180 vtmEntry& d = entries_[i+1];
181 vtmEntry&
e = entries_[i+2];
185 b.isType(vtmEntry::BEGIN_BLOCK)
186 &&
e.isType(vtmEntry::END_BLOCK)
187 && d.isType(vtmEntry::DATA)
188 && (d.name_.empty() || d.name_ ==
b.name_)
191 d.name_ = std::move(
b.name_);
213 for (vtmEntry&
e : entries_)
215 if (
e.isType(vtmEntry::BEGIN_BLOCK))
219 else if (
e.isType(vtmEntry::END_BLOCK))
226 entries_.resize(nEntries);
230 else if (
e.isType(vtmEntry::DATA))
245 entries_.append(vtmEntry::endblock());
266 for (
const vtmEntry&
e : entries_)
279 os <<
"{ \"name\" : " <<
e.name_
280 <<
", \"file\" : " <<
e.file_ <<
" }" <<
nl;
283 case vtmEntry::BEGIN_BLOCK:
286 os.beginBlock(
e.name_);
289 case vtmEntry::END_BLOCK:
299 for (label i=0; i < depth; ++i)
306 os <<
"# Had " << depth <<
" unclosed blocks" <<
nl;
310 os <<
"# Had " << (-depth) <<
" too many end blocks" <<
nl;
347 for (
const auto&
e : entries_)
349 if (
e.isType(vtmEntry::DATA) &&
e.name_.size())
363 for (
const auto&
e : entries_)
365 if (
e.isType(vtmEntry::DATA) &&
e.file_.size())
377 timeValue_ = timeValue;
384 timeValue_ = t.
value();
391 entries_.append(vtmEntry::block(blockName));
392 blocks_.append(blockName);
394 return blocks_.size();
400 label nblock = blocks_.size();
404 const word curr(blocks_.remove());
407 if (!blockName.empty() && blockName != curr)
410 <<
"expecting to end block '" << blockName
411 <<
"' but found '" << curr <<
"' instead"
415 entries_.append(vtmEntry::endblock());
418 return blocks_.size();
459 entries_.append(vtmEntry::entry(
name, file));
478 entries_.append(vtmEntry::entry(
name, file));
498 const word& blockName,
511 for (
const vtmEntry&
e : other.entries_)
535 case vtmEntry::BEGIN_BLOCK:
541 case vtmEntry::END_BLOCK:
558 entries_.append(vtmEntry::endblock());
561 entries_.append(vtmEntry::endblock());
563 if (!hasTime_ && other.hasTime_)
566 timeValue_ = other.timeValue_;
573 const word& blockName,
593 os_.open(file +
"." + ext());
620 for (
const vtmEntry&
e : entries_)
633 case vtmEntry::BEGIN_BLOCK:
638 case vtmEntry::END_BLOCK:
672 .writeTimeValue(timeValue_)