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