Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txshzeraryfxcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxdag.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshzeraryfxlevel.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// TXshZeraryFxColumn
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshZeraryFxColumn::TXshZeraryFxColumn(int frameCount)
Shinya Kitaoka 120a6e
    : m_zeraryColumnFx(new TZeraryColumnFx())
Shinya Kitaoka 120a6e
    , m_zeraryFxLevel(new TXshZeraryFxLevel()) {
Shinya Kitaoka 120a6e
  m_zeraryColumnFx->addRef();
Shinya Kitaoka 120a6e
  m_zeraryColumnFx->setColumn(this);
Shinya Kitaoka 120a6e
  m_zeraryFxLevel->addRef();
Shinya Kitaoka 120a6e
  m_zeraryFxLevel->setColumn(this);
Shinya Kitaoka 120a6e
  for (int i = 0; i < frameCount; i++)
Shinya Kitaoka 120a6e
    setCell(i, TXshCell(m_zeraryFxLevel, TFrameId(1)));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshZeraryFxColumn::TXshZeraryFxColumn(const TXshZeraryFxColumn &src)
Shinya Kitaoka 120a6e
    : m_zeraryColumnFx(new TZeraryColumnFx())
Shinya Kitaoka 120a6e
    , m_zeraryFxLevel(new TXshZeraryFxLevel()) {
Shinya Kitaoka 120a6e
  m_zeraryColumnFx->addRef();
Shinya Kitaoka 120a6e
  m_zeraryColumnFx->setColumn(this);
Shinya Kitaoka 120a6e
  m_zeraryFxLevel->addRef();
Shinya Kitaoka 120a6e
  m_zeraryFxLevel->setColumn(this);
Shinya Kitaoka 120a6e
  m_first = src.m_first;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < (int)src.m_cells.size(); i++)
Shinya Kitaoka 120a6e
    m_cells.push_back(TXshCell(m_zeraryFxLevel, src.m_cells[i].getFrameId()));
Shinya Kitaoka 120a6e
  assert((int)src.m_cells.size() == (int)m_cells.size());
Shinya Kitaoka 120a6e
  TFx *fx = src.getZeraryColumnFx()->getZeraryFx();
Shinya Kitaoka 120a6e
  if (fx) {
Shinya Kitaoka 120a6e
    std::wstring fxName = fx->getName();
Shinya Kitaoka 120a6e
    fx                  = fx->clone(false);
Shinya Kitaoka 120a6e
    fx->setName(fxName);
Shinya Kitaoka 120a6e
    m_zeraryColumnFx->setZeraryFx(fx);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshZeraryFxColumn::~TXshZeraryFxColumn() {
Shinya Kitaoka 120a6e
  m_zeraryColumnFx->setColumn(0);
Shinya Kitaoka 120a6e
  m_zeraryColumnFx->release();
Shinya Kitaoka 120a6e
  m_zeraryFxLevel->release();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn::ColumnType TXshZeraryFxColumn::getColumnType() const {
Shinya Kitaoka 120a6e
  return eZeraryFxType;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXshZeraryFxColumn::canSetCell(const TXshCell &cell) const {
Shinya Kitaoka 120a6e
  return cell.isEmpty() || cell.m_level->getZeraryFxLevel() != 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn *TXshZeraryFxColumn::clone() const {
Shinya Kitaoka 120a6e
  return new TXshZeraryFxColumn(*this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFx *TXshZeraryFxColumn::getFx() const { return m_zeraryColumnFx; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXshZeraryFxColumn::setCell(int row, const TXshCell &cell) {
Shinya Kitaoka 120a6e
  if (cell.isEmpty()) return false;
Shinya Kitaoka 120a6e
  TXshCell newCell = cell;
Shinya Kitaoka 120a6e
  // Sto settando delle celle in una colonna nuova, devo settare anche
Shinya Kitaoka 120a6e
  // l'effetto.
Shinya Kitaoka 120a6e
  if (isEmpty() && getZeraryColumnFx()->getZeraryFx() == 0) {
Shinya Kitaoka 120a6e
    newCell                      = TXshCell(m_zeraryFxLevel, cell.getFrameId());
Shinya Kitaoka 120a6e
    TXshZeraryFxLevel *fxLevel   = cell.m_level->getZeraryFxLevel();
Shinya Kitaoka 120a6e
    TXshZeraryFxColumn *fxColumn = fxLevel->getColumn();
Shinya Kitaoka 120a6e
    m_zeraryColumnFx->setZeraryFx(fxColumn->getZeraryColumnFx()->getZeraryFx());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return TXshCellColumn::setCell(row, newCell);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXshZeraryFxColumn::setCells(int row, int rowCount,
Shinya Kitaoka 120a6e
                                  const TXshCell cells[]) {
Shinya Kitaoka 120a6e
  std::vector<txshcell> newCells;</txshcell>
Shinya Kitaoka 120a6e
  bool isEmptyColumn = isEmpty() && getZeraryColumnFx()->getZeraryFx() == 0;
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < rowCount; i++) {
Shinya Kitaoka 120a6e
    if (isEmptyColumn)
Shinya Kitaoka 120a6e
      newCells.push_back(TXshCell(m_zeraryFxLevel, cells[i].getFrameId()));
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      newCells.push_back(cells[i]);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  // Sto settando delle celle in una colonna nuova, devo settare anche
Shinya Kitaoka 120a6e
  // l'effetto.
Shinya Kitaoka 120a6e
  if (isEmptyColumn) {
Shinya Kitaoka 120a6e
    i = 0;
Shinya Kitaoka 120a6e
    while (i < rowCount && cells[i].isEmpty()) i++;
Shinya Kitaoka 120a6e
    if (i >= rowCount) return false;
Shinya Kitaoka 120a6e
    TXshZeraryFxLevel *fxLevel =
Shinya Kitaoka 120a6e
        dynamic_cast<txshzeraryfxlevel *="">(cells[i].m_level.getPointer());</txshzeraryfxlevel>
Shinya Kitaoka 120a6e
    TXshZeraryFxColumn *fxColumn = fxLevel->getColumn();
Shinya Kitaoka 120a6e
    m_zeraryColumnFx->setZeraryFx(fxColumn->getZeraryColumnFx()->getZeraryFx());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return TXshCellColumn::setCells(row, rowCount, &newCells[0]);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshZeraryFxColumn::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  TPersist *p = 0;
Shinya Kitaoka 120a6e
  is >> p;
Shinya Kitaoka 120a6e
  if (!p) return;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TZeraryColumnFx *fx = dynamic_cast<tzerarycolumnfx *="">(p);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
  fx->addRef();
Shinya Kitaoka 120a6e
  if (m_zeraryColumnFx) {
Shinya Kitaoka 120a6e
    m_zeraryColumnFx->setColumn(0);
Shinya Kitaoka 120a6e
    m_zeraryColumnFx->release();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_zeraryColumnFx = fx;
Shinya Kitaoka 120a6e
  m_zeraryColumnFx->setColumn(this);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int r0, r1;
Shinya Kitaoka 120a6e
  bool touched = false;
Shinya Kitaoka 120a6e
  const TXshCell cell(m_zeraryFxLevel, TFrameId(1));
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.matchTag(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
    } else if (tagName == "cells") {
Shinya Kitaoka 120a6e
      while (is.matchTag(tagName)) {
Shinya Kitaoka 120a6e
        if (tagName == "cell") {
Shinya Kitaoka 120a6e
          if (!touched) {
Shinya Kitaoka 120a6e
            touched = true;
Shinya Kitaoka 120a6e
            if (getRange(r0, r1)) removeCells(r0, r1 - r0 + 1);
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
          int r, n;
Shinya Kitaoka 120a6e
          is >> r >> n;
Shinya Kitaoka 120a6e
          for (int i = 0; i < n; i++) setCell(r++, cell);
Shinya Kitaoka 120a6e
        } else
Shinya Kitaoka 120a6e
          throw TException("expected <cell>");</cell>
Shinya Kitaoka 120a6e
        is.closeChild();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      throw TException("expected <status> or <cells>");</cells></status>
Shinya Kitaoka 120a6e
    is.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshZeraryFxColumn::saveData(TOStream &os) {
Shinya Kitaoka 120a6e
  os << m_zeraryColumnFx;
Shinya Kitaoka 120a6e
  os.child("status") << getStatusWord();
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
      int n = 1;
Shinya Kitaoka 120a6e
      while (r + n <= r1 && !getCell(r + n).isEmpty()) n++;
Shinya Kitaoka 120a6e
      os.child("cell") << r << n;
Shinya Kitaoka 120a6e
      r += n - 1;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TXshZeraryFxColumn, "zeraryFxColumn")