2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
|
|
|
|
#include "toonz/txshzeraryfxcolumn.h"
|
|
|
|
#include "toonz/tcolumnfx.h"
|
|
|
|
#include "toonz/toonzscene.h"
|
|
|
|
#include "toonz/txshcell.h"
|
|
|
|
#include "toonz/txsheet.h"
|
|
|
|
#include "toonz/fxdag.h"
|
|
|
|
#include "toonz/txshzeraryfxlevel.h"
|
2022-01-08 02:02:24 +13:00
|
|
|
#include "toonz/preferences.h"
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#include "tstream.h"
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
// TXshZeraryFxColumn
|
|
|
|
|
|
|
|
TXshZeraryFxColumn::TXshZeraryFxColumn(int frameCount)
|
2016-06-15 18:43:10 +12:00
|
|
|
: m_zeraryColumnFx(new TZeraryColumnFx())
|
2020-09-01 09:44:23 +12:00
|
|
|
, m_zeraryFxLevel(new TXshZeraryFxLevel())
|
|
|
|
, m_iconVisible(false) {
|
2016-06-15 18:43:10 +12:00
|
|
|
m_zeraryColumnFx->addRef();
|
|
|
|
m_zeraryColumnFx->setColumn(this);
|
|
|
|
m_zeraryFxLevel->addRef();
|
|
|
|
m_zeraryFxLevel->setColumn(this);
|
2022-01-08 02:02:24 +13:00
|
|
|
if (frameCount <= 0) return;
|
2016-06-15 18:43:10 +12:00
|
|
|
for (int i = 0; i < frameCount; i++)
|
|
|
|
setCell(i, TXshCell(m_zeraryFxLevel, TFrameId(1)));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TXshZeraryFxColumn::TXshZeraryFxColumn(const TXshZeraryFxColumn &src)
|
2016-06-15 18:43:10 +12:00
|
|
|
: m_zeraryColumnFx(new TZeraryColumnFx())
|
2021-12-03 18:59:53 +13:00
|
|
|
, m_zeraryFxLevel(new TXshZeraryFxLevel())
|
|
|
|
, m_iconVisible(false) {
|
2016-06-15 18:43:10 +12:00
|
|
|
m_zeraryColumnFx->addRef();
|
|
|
|
m_zeraryColumnFx->setColumn(this);
|
|
|
|
m_zeraryFxLevel->addRef();
|
|
|
|
m_zeraryFxLevel->setColumn(this);
|
|
|
|
m_first = src.m_first;
|
|
|
|
int i;
|
2022-01-08 02:02:24 +13:00
|
|
|
for (i = 0; i < (int)src.m_cells.size(); i++) {
|
|
|
|
if (Preferences::instance()->isImplicitHoldEnabled() &&
|
|
|
|
src.m_cells[i].getFrameId().isEmptyFrame())
|
|
|
|
m_cells.push_back(TXshCell(0, src.m_cells[i].getFrameId()));
|
|
|
|
else
|
|
|
|
m_cells.push_back(TXshCell(m_zeraryFxLevel, src.m_cells[i].getFrameId()));
|
|
|
|
}
|
2016-06-15 18:43:10 +12:00
|
|
|
assert((int)src.m_cells.size() == (int)m_cells.size());
|
|
|
|
TFx *fx = src.getZeraryColumnFx()->getZeraryFx();
|
|
|
|
if (fx) {
|
|
|
|
std::wstring fxName = fx->getName();
|
|
|
|
fx = fx->clone(false);
|
|
|
|
fx->setName(fxName);
|
|
|
|
m_zeraryColumnFx->setZeraryFx(fx);
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TXshZeraryFxColumn::~TXshZeraryFxColumn() {
|
|
|
|
m_zeraryColumnFx->setColumn(0);
|
|
|
|
m_zeraryColumnFx->release();
|
|
|
|
m_zeraryFxLevel->release();
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TXshColumn::ColumnType TXshZeraryFxColumn::getColumnType() const {
|
|
|
|
return eZeraryFxType;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool TXshZeraryFxColumn::canSetCell(const TXshCell &cell) const {
|
|
|
|
return cell.isEmpty() || cell.m_level->getZeraryFxLevel() != 0;
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TXshColumn *TXshZeraryFxColumn::clone() const {
|
|
|
|
return new TXshZeraryFxColumn(*this);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
TFx *TXshZeraryFxColumn::getFx() const { return m_zeraryColumnFx; }
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool TXshZeraryFxColumn::setCell(int row, const TXshCell &cell) {
|
|
|
|
if (cell.isEmpty()) return false;
|
|
|
|
TXshCell newCell = cell;
|
|
|
|
// Sto settando delle celle in una colonna nuova, devo settare anche
|
|
|
|
// l'effetto.
|
|
|
|
if (isEmpty() && getZeraryColumnFx()->getZeraryFx() == 0) {
|
|
|
|
newCell = TXshCell(m_zeraryFxLevel, cell.getFrameId());
|
|
|
|
TXshZeraryFxLevel *fxLevel = cell.m_level->getZeraryFxLevel();
|
|
|
|
TXshZeraryFxColumn *fxColumn = fxLevel->getColumn();
|
|
|
|
m_zeraryColumnFx->setZeraryFx(fxColumn->getZeraryColumnFx()->getZeraryFx());
|
|
|
|
}
|
|
|
|
|
|
|
|
return TXshCellColumn::setCell(row, newCell);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
bool TXshZeraryFxColumn::setCells(int row, int rowCount,
|
|
|
|
const TXshCell cells[]) {
|
|
|
|
std::vector<TXshCell> newCells;
|
|
|
|
bool isEmptyColumn = isEmpty() && getZeraryColumnFx()->getZeraryFx() == 0;
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < rowCount; i++) {
|
2022-01-08 02:02:24 +13:00
|
|
|
if (isEmptyColumn) {
|
|
|
|
if (Preferences::instance()->isImplicitHoldEnabled() &&
|
|
|
|
cells[i].getFrameId().isEmptyFrame())
|
|
|
|
newCells.push_back(TXshCell(0, cells[i].getFrameId()));
|
|
|
|
else
|
|
|
|
newCells.push_back(TXshCell(m_zeraryFxLevel, cells[i].getFrameId()));
|
|
|
|
} else
|
2016-06-15 18:43:10 +12:00
|
|
|
newCells.push_back(cells[i]);
|
|
|
|
}
|
|
|
|
// Sto settando delle celle in una colonna nuova, devo settare anche
|
|
|
|
// l'effetto.
|
|
|
|
if (isEmptyColumn) {
|
|
|
|
i = 0;
|
|
|
|
while (i < rowCount && cells[i].isEmpty()) i++;
|
|
|
|
if (i >= rowCount) return false;
|
|
|
|
TXshZeraryFxLevel *fxLevel =
|
|
|
|
dynamic_cast<TXshZeraryFxLevel *>(cells[i].m_level.getPointer());
|
|
|
|
TXshZeraryFxColumn *fxColumn = fxLevel->getColumn();
|
|
|
|
m_zeraryColumnFx->setZeraryFx(fxColumn->getZeraryColumnFx()->getZeraryFx());
|
|
|
|
}
|
|
|
|
return TXshCellColumn::setCells(row, rowCount, &newCells[0]);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshZeraryFxColumn::loadData(TIStream &is) {
|
|
|
|
TPersist *p = 0;
|
|
|
|
is >> p;
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
TZeraryColumnFx *fx = dynamic_cast<TZeraryColumnFx *>(p);
|
|
|
|
fx->addRef();
|
|
|
|
if (m_zeraryColumnFx) {
|
|
|
|
m_zeraryColumnFx->setColumn(0);
|
|
|
|
m_zeraryColumnFx->release();
|
|
|
|
}
|
|
|
|
m_zeraryColumnFx = fx;
|
|
|
|
m_zeraryColumnFx->setColumn(this);
|
|
|
|
|
|
|
|
int r0, r1;
|
|
|
|
bool touched = false;
|
2021-12-22 16:25:56 +13:00
|
|
|
TXshCell cell(m_zeraryFxLevel, TFrameId(1));
|
2016-06-15 18:43:10 +12:00
|
|
|
std::string tagName;
|
|
|
|
while (is.matchTag(tagName)) {
|
|
|
|
if (tagName == "status") {
|
|
|
|
int status;
|
|
|
|
is >> status;
|
|
|
|
setStatusWord(status);
|
|
|
|
} else if (tagName == "cells") {
|
|
|
|
while (is.matchTag(tagName)) {
|
|
|
|
if (tagName == "cell") {
|
|
|
|
if (!touched) {
|
|
|
|
touched = true;
|
|
|
|
if (getRange(r0, r1)) removeCells(r0, r1 - r0 + 1);
|
|
|
|
}
|
|
|
|
int r, n;
|
|
|
|
is >> r >> n;
|
2021-12-22 16:25:56 +13:00
|
|
|
if (is.getTagAttribute("stopframe") == "yes")
|
|
|
|
cell.m_frameId = TFrameId::STOP_FRAME;
|
|
|
|
else
|
|
|
|
cell.m_frameId = 1;
|
2016-06-15 18:43:10 +12:00
|
|
|
for (int i = 0; i < n; i++) setCell(r++, cell);
|
|
|
|
} else
|
|
|
|
throw TException("expected <cell>");
|
|
|
|
is.closeChild();
|
|
|
|
}
|
2021-11-22 22:49:42 +13:00
|
|
|
} else if (loadCellMarks(tagName, is)) {
|
|
|
|
// do nothing
|
2016-06-15 18:43:10 +12:00
|
|
|
} else
|
|
|
|
throw TException("expected <status> or <cells>");
|
|
|
|
is.closeChild();
|
|
|
|
}
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
void TXshZeraryFxColumn::saveData(TOStream &os) {
|
|
|
|
os << m_zeraryColumnFx;
|
|
|
|
os.child("status") << getStatusWord();
|
|
|
|
int r0, r1;
|
|
|
|
if (getRange(r0, r1)) {
|
|
|
|
os.openChild("cells");
|
|
|
|
for (int r = r0; r <= r1; r++) {
|
2022-01-29 03:05:21 +13:00
|
|
|
TXshCell cell = getCell(r, false);
|
2016-06-15 18:43:10 +12:00
|
|
|
if (cell.isEmpty()) continue;
|
2021-12-22 16:25:56 +13:00
|
|
|
int fnum = cell.m_frameId.getNumber();
|
|
|
|
if (fnum > 1) fnum = 1; // Should always be 1 unless it's stopframe
|
|
|
|
int n = 1;
|
|
|
|
|
|
|
|
if (r < r1) {
|
2022-01-29 03:05:21 +13:00
|
|
|
TXshCell cell2 = getCell(r + 1, false);
|
2021-12-22 16:25:56 +13:00
|
|
|
if (!cell2.isEmpty()) {
|
|
|
|
int fnum2 = cell2.m_frameId.getNumber();
|
|
|
|
if (fnum2 > 1) fnum2 = 1; // Should always be 1 unless it's stopframe
|
|
|
|
if (fnum == fnum2) {
|
|
|
|
n++;
|
|
|
|
for (;;) {
|
|
|
|
if (r + n > r1) break;
|
2022-01-29 03:05:21 +13:00
|
|
|
cell2 = getCell(r + n, false);
|
2021-12-22 16:25:56 +13:00
|
|
|
if (cell2.isEmpty()) break;
|
|
|
|
fnum2 = cell2.m_frameId.getNumber();
|
|
|
|
if (fnum2 > 1)
|
|
|
|
fnum2 = 1; // Should always be 1 unless it's stopframe
|
|
|
|
if (fnum != fnum2) break;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::map<std::string, std::string> attr;
|
|
|
|
if (cell.m_frameId.isStopFrame()) attr["stopframe"] = "yes";
|
|
|
|
os.openChild("cell", attr);
|
|
|
|
os << r << n;
|
|
|
|
os.closeChild();
|
2016-06-15 18:43:10 +12:00
|
|
|
r += n - 1;
|
|
|
|
}
|
|
|
|
os.closeChild();
|
|
|
|
}
|
2021-11-22 22:49:42 +13:00
|
|
|
// cell marks
|
|
|
|
saveCellMarks(os);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
PERSIST_IDENTIFIER(TXshZeraryFxColumn, "zeraryFxColumn")
|