Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshsimplelevel.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfxset.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshleveltypes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
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
  TFrameId fid;
Shinya Kitaoka 120a6e
  int s = 0;
Shinya Kitaoka 120a6e
  QString number;
Shinya Kitaoka 120a6e
  char letter(0);
Shinya Kitaoka 120a6e
  for (s = 0; s < str.size(); s++) {
Shinya Kitaoka 120a6e
    QChar c = str.at(s);
Shinya Kitaoka 120a6e
    if (c.isNumber()) number.append(c);
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      letter = c.toLatin1();
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      letter = c.toAscii();
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return TFrameId(number.toInt(), letter);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TXshLevelColumn
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshLevelColumn::TXshLevelColumn()
Shinya Kitaoka 120a6e
    : m_fx(new TLevelColumnFx())
Shinya Kitaoka 120a6e
    //, m_iconId("")
Shinya Kitaoka 120a6e
    , m_iconVisible(false) {
Shinya Kitaoka 120a6e
  // updateIcon();
Shinya Kitaoka 120a6e
  m_fx->addRef();
Shinya Kitaoka 120a6e
  m_fx->setColumn(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshLevelColumn::~TXshLevelColumn() {
Shinya Kitaoka 120a6e
  m_fx->setColumn(0);
Shinya Kitaoka 120a6e
  m_fx->release();
Shinya Kitaoka 120a6e
  m_fx = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn::ColumnType TXshLevelColumn::getColumnType() const {
Shinya Kitaoka 120a6e
  return eLevelType;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXshLevelColumn::canSetCell(const TXshCell &cell) const {
Shinya Kitaoka 120a6e
  if (cell.isEmpty()) return true;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TXshSimpleLevel *sl = cell.getSimpleLevel();
Shinya Kitaoka 120a6e
  if (sl) return (sl->getType() & LEVELCOLUMN_XSHLEVEL);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return cell.getChildLevel();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TLevelColumnFx *TXshLevelColumn::getLevelColumnFx() const { return m_fx; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFx *TXshLevelColumn::getFx() const { return m_fx; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn *TXshLevelColumn::clone() const {
Shinya Kitaoka 120a6e
  TXshLevelColumn *column = new TXshLevelColumn;
Shinya Kitaoka 120a6e
  column->setStatusWord(getStatusWord());
Shinya Kitaoka 120a6e
  column->setOpacity(getOpacity());
Shinya Kitaoka 120a6e
  column->m_cells = m_cells;
Shinya Kitaoka 120a6e
  column->m_first = m_first;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // column->updateIcon();
Shinya Kitaoka 120a6e
  return column;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshLevelColumn::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
    } else if (tagName == "camerastand_opacity") {
Shinya Kitaoka 120a6e
      int opacity;
Shinya Kitaoka 120a6e
      is >> opacity;
Shinya Kitaoka 120a6e
      setOpacity((UCHAR)opacity);
shun_iwasawa a3cdd8
    } else if (tagName == "filter_color_id") {
shun_iwasawa a3cdd8
      int id;
shun_iwasawa a3cdd8
      is >> id;
shun_iwasawa 2c0f50
      setFilterColorId((TXshColumn::FilterColor)id);
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
          int row = 1, rowCount = 1, increment = 0;
Shinya Kitaoka 120a6e
          TFilePath path;
Shinya Kitaoka 120a6e
          is >> row >> rowCount >> p >> str >> increment;
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
          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
              // 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
        } else
Shinya Kitaoka 120a6e
          throw TException("TXshLevelColumn, unknown tag(2): " + tagName);
Shinya Kitaoka 120a6e
        is.closeChild();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (tagName == "fx") {
Shinya Kitaoka 120a6e
      TPersist *p = 0;
Shinya Kitaoka 120a6e
      is >> p;
Shinya Kitaoka 120a6e
      if (TLevelColumnFx *lcf = dynamic_cast<tlevelcolumnfx *="">(p)) {</tlevelcolumnfx>
Shinya Kitaoka 120a6e
        lcf->addRef();
Shinya Kitaoka 120a6e
        if (m_fx) m_fx->release();
Shinya Kitaoka 120a6e
        m_fx = lcf;
Shinya Kitaoka 120a6e
        lcf->setColumn(this);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (tagName == "fxnodes")  // per compatibilita' con 1.x e precedenti
Shinya Kitaoka 120a6e
    {
Shinya Kitaoka 120a6e
      TFxSet fxSet;
Shinya Kitaoka 120a6e
      fxSet.loadData(is);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      throw TException("TXshLevelColumn, unknown tag: " + tagName);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    is.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshLevelColumn::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os.child("status") << getStatusWord();
Shinya Kitaoka 120a6e
  if (getOpacity() < 255) os.child("camerastand_opacity") << (int)getOpacity();
shun_iwasawa a3cdd8
  if (getFilterColorId() != 0)
shun_iwasawa a3cdd8
    os.child("filter_color_id") << (int)getFilterColorId();
Shinya Kitaoka 120a6e
  int r0, r1;
Shinya Kitaoka 120a6e
  if (getRange(r0, r1)) {
Shinya Kitaoka 120a6e
    os.openChild("cells");
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
      TFrameId fid = cell.m_frameId;
Shinya Kitaoka 120a6e
      int n = 1, inc = 0, dr = fid.getNumber();
Shinya Kitaoka 120a6e
      // If fid has not letter save more than one cell and its incrementation;
Shinya Kitaoka 120a6e
      // otherwise save 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
        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
          n++;
Shinya Kitaoka 120a6e
          for (;;) {
Shinya Kitaoka 120a6e
            if (r + n > r1) break;
Shinya Kitaoka 120a6e
            cell2         = getCell(r + n);
Shinya Kitaoka 120a6e
            TFrameId fid2 = cell2.m_frameId;
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
            if (fid2.getNumber() != dr + n * inc) break;
Shinya Kitaoka 120a6e
            n++;
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
    os.closeChild();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  os.child("fx") << m_fx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TXshLevelColumn, "levelColumn")