Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txshmeshcolumn.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TXshMeshColumn, "meshColumn")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
TFrameId qstringToFrameId(QString str) {
Shinya Kitaoka 120a6e
  if (str.isEmpty() || str == "-1")
Shinya Kitaoka 120a6e
    return TFrameId::EMPTY_FRAME;
Shinya Kitaoka 120a6e
  else if (str == "-" || str == "-2")
Shinya Kitaoka 120a6e
    return TFrameId::NO_FRAME;
Shinya Kitaoka 120a6e
shun-iwasawa ef0f8b
  QString regExpStr = QString("^%1$").arg(TFilePath::fidRegExpStr());
shun-iwasawa ef0f8b
  QRegExp rx(regExpStr);
shun-iwasawa ef0f8b
  int pos = rx.indexIn(str);
shun-iwasawa ef0f8b
  if (pos < 0) return TFrameId();
shun-iwasawa ef0f8b
  if (rx.cap(2).isEmpty())
shun-iwasawa ef0f8b
    return TFrameId(rx.cap(1).toInt());
shun-iwasawa ef0f8b
  else
shun-iwasawa ef0f8b
    return TFrameId(rx.cap(1).toInt(), rx.cap(2));
Toshihiro Shimizu 890ddd
}
shun-iwasawa ef0f8b
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
//    TXshMeshColumn  implementation
Toshihiro Shimizu 890ddd
//*******************************************************************************
Toshihiro Shimizu 890ddd
manongjohn 057de6
TXshMeshColumn::TXshMeshColumn() : TXshCellColumn(), m_iconVisible(false) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn *TXshMeshColumn::clone() const {
Shinya Kitaoka 120a6e
  TXshMeshColumn *column = new TXshMeshColumn();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  column->setStatusWord(getStatusWord());
manongjohn 09549b
  column->setOpacity(getOpacity());
Shinya Kitaoka 120a6e
  column->m_cells = m_cells;
Shinya Kitaoka 120a6e
  column->m_first = m_first;
manongjohn 09549b
  column->setColorTag(getColorTag());
manongjohn 09549b
  column->setFilterColorId(getFilterColorId());
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return column;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXshMeshColumn::canSetCell(const TXshCell &cell) const {
Shinya Kitaoka 120a6e
  TXshSimpleLevel *sl = cell.getSimpleLevel();
Shinya Kitaoka 120a6e
  return cell.isEmpty() || (sl && sl->getType() == MESH_XSHLEVEL);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshMeshColumn::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.child("status") << getStatusWord();
Shinya Kitaoka 120a6e
  if (getOpacity() < 255) os.child("camerastand_opacity") << (int)getOpacity();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int r0, r1;
Shinya Kitaoka 120a6e
  if (getRange(r0, r1)) {
Shinya Kitaoka 120a6e
    os.openChild("cells");
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      for (int r = r0; r <= r1; ++r) {
Shinya Kitaoka 120a6e
        TXshCell cell = getCell(r);
Shinya Kitaoka 120a6e
        if (cell.isEmpty()) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        TFrameId fid = cell.m_frameId;
Shinya Kitaoka 120a6e
        int n = 1, inc = 0, dr = fid.getNumber();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // If fid has no letter save more than one cell and its increment -
Shinya Kitaoka 120a6e
        // otherwise save just one cell
shun-iwasawa ef0f8b
        if (r < r1 && fid.getLetter().isEmpty()) {
Shinya Kitaoka 120a6e
          TXshCell cell2 = getCell(r + 1);
Shinya Kitaoka 120a6e
          TFrameId fid2  = cell2.m_frameId;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          if (cell2.m_level.getPointer() == cell.m_level.getPointer() &&
shun-iwasawa ef0f8b
              fid2.getLetter().isEmpty()) {
Shinya Kitaoka 120a6e
            inc = cell2.m_frameId.getNumber() - dr;
Shinya Kitaoka 120a6e
            for (++n;; ++n) {
Shinya Kitaoka 120a6e
              if (r + n > r1) break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
              cell2         = getCell(r + n);
Shinya Kitaoka 120a6e
              TFrameId fid2 = cell2.m_frameId;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
              if (cell2.m_level.getPointer() != cell.m_level.getPointer() ||
shun-iwasawa ef0f8b
                  !fid2.getLetter().isEmpty())
Shinya Kitaoka 120a6e
                break;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
              if (fid2.getNumber() != dr + n * inc) break;
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        os.child("cell") << r << n << cell.m_level.getPointer() << fid.expand()
Shinya Kitaoka 120a6e
                         << inc;
Shinya Kitaoka 120a6e
        r += n - 1;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
shun-iwasawa f84c65
  // cell marks
shun-iwasawa f84c65
  saveCellMarks(os);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshMeshColumn::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.openChild(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "status") {
Shinya Kitaoka 120a6e
      int status;
Shinya Kitaoka 120a6e
      is >> status;
Shinya Kitaoka 120a6e
      setStatusWord(status);
Shinya Kitaoka 120a6e
      if (status & eCamstandTransparent43) {
Shinya Kitaoka 120a6e
        setOpacity(128);
Shinya Kitaoka 120a6e
        status = status & ~eCamstandTransparent43;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      is.closeChild();
Shinya Kitaoka 120a6e
    } else if (tagName == "camerastand_opacity") {
Shinya Kitaoka 120a6e
      int opacity;
Shinya Kitaoka 120a6e
      is >> opacity;
Shinya Kitaoka 120a6e
      setOpacity((UCHAR)opacity);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      is.closeChild();
Shinya Kitaoka 120a6e
    } else if (tagName == "cells") {
Shinya Kitaoka 120a6e
      while (is.openChild(tagName)) {
Shinya Kitaoka 120a6e
        if (tagName == "cell") {
Shinya Kitaoka 120a6e
          TPersist *p = 0;
shun-iwasawa ef0f8b
          std::string str;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          int row = 1, rowCount = 1, increment = 0;
Shinya Kitaoka 120a6e
          TFilePath path;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          is >> row >> rowCount >> p >> str >> increment;
Shinya Kitaoka 120a6e
shun-iwasawa ef0f8b
          TFrameId fid = qstringToFrameId(QString::fromStdString(str));
shun-iwasawa ef0f8b
          assert((fid.getLetter().isEmpty() && rowCount >= 0) ||
shun-iwasawa ef0f8b
                 (!fid.getLetter().isEmpty() && rowCount == 1));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          TXshLevel *xshLevel = dynamic_cast<txshlevel *="">(p);</txshlevel>
Shinya Kitaoka 120a6e
          if (xshLevel) {
Shinya Kitaoka 120a6e
            int fidNumber = fid.getNumber();
Shinya Kitaoka 120a6e
            for (int i = 0; i < rowCount; ++i) {
Shinya Kitaoka 120a6e
              TXshCell cell(xshLevel, fid);
Shinya Kitaoka 120a6e
              setCell(row++, cell);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
              // rowCount>1 => fid has not letter.
Shinya Kitaoka 120a6e
              fidNumber += increment;
Shinya Kitaoka 120a6e
              fid = TFrameId(fidNumber);
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          is.closeChild();
Shinya Kitaoka 120a6e
        } else
Shinya Kitaoka 120a6e
          is.skipCurrentTag();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      is.closeChild();
shun-iwasawa f84c65
    } else if (loadCellMarks(tagName, is)) {
shun-iwasawa f84c65
      is.closeChild();
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      is.skipCurrentTag();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}