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
Shinya Kitaoka 120a6e
  TFrameId fid;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QString number;
Shinya Kitaoka 120a6e
  char letter(0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int s, strSize = str.size();
Shinya Kitaoka 120a6e
  for (s = 0; s < strSize; ++s) {
Shinya Kitaoka 120a6e
    QChar c = str.at(s);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (c.isNumber())
Shinya Kitaoka 120a6e
      number.append(c);
Shinya Kitaoka 120a6e
    else
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Shinya Kitaoka 120a6e
      letter = c.toLatin1();
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
      letter = c.toAscii();
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return TFrameId(number.toInt(), letter);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
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
Shinya Kitaoka 120a6e
        if (r < r1 && fid.getLetter() == 0) {
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() &&
Shinya Kitaoka 120a6e
              fid2.getLetter() == 0) {
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() ||
Shinya Kitaoka 120a6e
                  fid2.getLetter() != 0)
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
  }
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;
Shinya Kitaoka 120a6e
          QString 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
Shinya Kitaoka 120a6e
          TFrameId fid = qstringToFrameId(str);
Shinya Kitaoka 120a6e
          assert((fid.getLetter() == 0 && rowCount >= 0) ||
Shinya Kitaoka 120a6e
                 (fid.getLetter() != 0 && 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();
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      is.skipCurrentTag();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}