Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/txshpalettecolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshcell.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshPaletteColumn::TXshPaletteColumn()
Shinya Kitaoka 120a6e
    : TXshCellColumn(), m_fx(new TPaletteColumnFx()) {
Shinya Kitaoka 120a6e
  m_fx->addRef();
Shinya Kitaoka 120a6e
  m_fx->setColumn(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshPaletteColumn::~TXshPaletteColumn() {
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
Shinya Kitaoka 120a6e
TXshColumn::ColumnType TXshPaletteColumn::getColumnType() const {
Shinya Kitaoka 120a6e
  return ePaletteType;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXshColumn *TXshPaletteColumn::clone() const {
Shinya Kitaoka 120a6e
  TXshPaletteColumn *column = new TXshPaletteColumn();
Shinya Kitaoka 120a6e
  column->setStatusWord(getStatusWord());
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
Shinya Kitaoka 120a6e
TFx *TXshPaletteColumn::getFx() const { return m_fx; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshPaletteColumn::setFx(TFx *fx) {
Shinya Kitaoka 120a6e
  TPaletteColumnFx *pfx = dynamic_cast<tpalettecolumnfx *="">(fx);</tpalettecolumnfx>
Shinya Kitaoka 120a6e
  assert(pfx);
Shinya Kitaoka 120a6e
  assert(m_fx);
Shinya Kitaoka 120a6e
  if (m_fx == pfx) return;
Shinya Kitaoka 120a6e
  pfx->addRef();
Shinya Kitaoka 120a6e
  m_fx->release();
Shinya Kitaoka 120a6e
  m_fx = pfx;
Shinya Kitaoka 120a6e
  pfx->setColumn(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool TXshPaletteColumn::canSetCell(const TXshCell &cell) const {
Shinya Kitaoka 120a6e
  return cell.isEmpty() || cell.m_level->getPaletteLevel() != 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TXshPaletteColumn::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.openChild(tagName)) {
Shinya Kitaoka 120a6e
    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
          int row = 1, rowCount = 1, drawing = 1, increment = 0;
Shinya Kitaoka 120a6e
          is >> row >> rowCount >> p >> drawing >> increment;
Shinya Kitaoka 120a6e
          TXshLevel *xshLevel = dynamic_cast<txshlevel *="">(p);</txshlevel>
Shinya Kitaoka 120a6e
          if (xshLevel) {
Shinya Kitaoka 120a6e
            for (int i = 0; i < rowCount; i++) {
Shinya Kitaoka 120a6e
              TXshCell cell(xshLevel, drawing);
Shinya Kitaoka 120a6e
              setCell(row++, cell);
Shinya Kitaoka 120a6e
              drawing += increment;
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        } else
Shinya Kitaoka 120a6e
          throw TException("TXshPaletteColumn, 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 (TFx *fx = dynamic_cast<tfx *="">(p)) setFx(fx);</tfx>
shun-iwasawa f84c65
    } else if (loadCellMarks(tagName, is)) {
shun-iwasawa f84c65
      // do nothing
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
}
Shinya Kitaoka 120a6e
void TXshPaletteColumn::saveData(TOStream &os) {
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, inc = 0, dr = cell.m_frameId.getNumber();
Shinya Kitaoka 120a6e
      if (r < r1) {
Shinya Kitaoka 120a6e
        TXshCell cell2 = getCell(r + 1);
Shinya Kitaoka 120a6e
        if (cell2.m_level.getPointer() == cell.m_level.getPointer()) {
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
            if (cell2.m_level.getPointer() != cell.m_level.getPointer()) break;
Shinya Kitaoka 120a6e
            if (cell2.m_frameId.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() << dr << 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;
shun-iwasawa f84c65
shun-iwasawa f84c65
  // cell marks
shun-iwasawa f84c65
  saveCellMarks(os);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TXshPaletteColumn, "paletteColumn")