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
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
TFrameId qstringToFrameId(QString str)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (str.isEmpty() || str == "-1")
Toshihiro Shimizu 890ddd
		return TFrameId::EMPTY_FRAME;
Toshihiro Shimizu 890ddd
	else if (str == "-" || str == "-2")
Toshihiro Shimizu 890ddd
		return TFrameId::NO_FRAME;
Toshihiro Shimizu 890ddd
	TFrameId fid;
Toshihiro Shimizu 890ddd
	int s = 0;
Toshihiro Shimizu 890ddd
	QString number;
Toshihiro Shimizu 890ddd
	char letter(0);
Toshihiro Shimizu 890ddd
	for (s = 0; s < str.size(); s++) {
Toshihiro Shimizu 890ddd
		QChar c = str.at(s);
Toshihiro Shimizu 890ddd
		if (c.isNumber())
Toshihiro Shimizu 890ddd
			number.append(c);
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050500
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			letter = c.toLatin1();
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			letter = c.toAscii();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	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()
Toshihiro Shimizu 890ddd
	: m_fx(new TLevelColumnFx())
Toshihiro Shimizu 890ddd
	  //, m_iconId("")
Toshihiro Shimizu 890ddd
	  ,
Toshihiro Shimizu 890ddd
	  m_iconVisible(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//updateIcon();
Toshihiro Shimizu 890ddd
	m_fx->addRef();
Toshihiro Shimizu 890ddd
	m_fx->setColumn(this);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshLevelColumn::~TXshLevelColumn()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_fx->setColumn(0);
Toshihiro Shimizu 890ddd
	m_fx->release();
Toshihiro Shimizu 890ddd
	m_fx = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshColumn::ColumnType TXshLevelColumn::getColumnType() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return eLevelType;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool TXshLevelColumn::canSetCell(const TXshCell &cell) const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (cell.isEmpty())
Toshihiro Shimizu 890ddd
		return true;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TXshSimpleLevel *sl = cell.getSimpleLevel();
Toshihiro Shimizu 890ddd
	if (sl)
Toshihiro Shimizu 890ddd
		return (sl->getType() & LEVELCOLUMN_XSHLEVEL);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return cell.getChildLevel();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TLevelColumnFx *TXshLevelColumn::getLevelColumnFx() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_fx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFx *TXshLevelColumn::getFx() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_fx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TXshColumn *TXshLevelColumn::clone() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TXshLevelColumn *column = new TXshLevelColumn;
Toshihiro Shimizu 890ddd
	column->setStatusWord(getStatusWord());
Toshihiro Shimizu 890ddd
	column->setOpacity(getOpacity());
Toshihiro Shimizu 890ddd
	column->m_cells = m_cells;
Toshihiro Shimizu 890ddd
	column->m_first = m_first;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//column->updateIcon();
Toshihiro Shimizu 890ddd
	return column;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshLevelColumn::loadData(TIStream &is)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	string tagName;
Toshihiro Shimizu 890ddd
	while (is.openChild(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
			if (status & eCamstandTransparent43) {
Toshihiro Shimizu 890ddd
				setOpacity(128);
Toshihiro Shimizu 890ddd
				status = status & ~eCamstandTransparent43;
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else if (tagName == "camerastand_opacity") {
Toshihiro Shimizu 890ddd
			int opacity;
Toshihiro Shimizu 890ddd
			is >> opacity;
Toshihiro Shimizu 890ddd
			setOpacity((UCHAR)opacity);
Toshihiro Shimizu 890ddd
		} else if (tagName == "cells") {
Toshihiro Shimizu 890ddd
			while (is.openChild(tagName)) {
Toshihiro Shimizu 890ddd
				if (tagName == "cell") {
Toshihiro Shimizu 890ddd
					TPersist *p = 0;
Toshihiro Shimizu 890ddd
					QString str;
Toshihiro Shimizu 890ddd
					int row = 1, rowCount = 1, increment = 0;
Toshihiro Shimizu 890ddd
					TFilePath path;
Toshihiro Shimizu 890ddd
					is >> row >> rowCount >> p >> str >> increment;
Toshihiro Shimizu 890ddd
					TFrameId fid = qstringToFrameId(str);
Toshihiro Shimizu 890ddd
					assert((fid.getLetter() == 0 && rowCount >= 0) || (fid.getLetter() != 0 && rowCount == 1));
Toshihiro Shimizu 890ddd
					TXshLevel *xshLevel = dynamic_cast<txshlevel *="">(p);</txshlevel>
Toshihiro Shimizu 890ddd
					if (xshLevel) {
Toshihiro Shimizu 890ddd
						int fidNumber = fid.getNumber();
Toshihiro Shimizu 890ddd
						for (int i = 0; i < rowCount; i++) {
Toshihiro Shimizu 890ddd
							TXshCell cell(xshLevel, fid);
Toshihiro Shimizu 890ddd
							setCell(row++, cell);
Toshihiro Shimizu 890ddd
							//rowCount>1 => fid has not letter.
Toshihiro Shimizu 890ddd
							fidNumber += increment;
Toshihiro Shimizu 890ddd
							fid = TFrameId(fidNumber);
Toshihiro Shimizu 890ddd
						}
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				} else
Toshihiro Shimizu 890ddd
					throw TException("TXshLevelColumn, unknown tag(2): " + tagName);
Toshihiro Shimizu 890ddd
				is.closeChild();
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else if (tagName == "fx") {
Toshihiro Shimizu 890ddd
			TPersist *p = 0;
Toshihiro Shimizu 890ddd
			is >> p;
Toshihiro Shimizu 890ddd
			if (TLevelColumnFx *lcf = dynamic_cast<tlevelcolumnfx *="">(p)) {</tlevelcolumnfx>
Toshihiro Shimizu 890ddd
				lcf->addRef();
Toshihiro Shimizu 890ddd
				if (m_fx)
Toshihiro Shimizu 890ddd
					m_fx->release();
Toshihiro Shimizu 890ddd
				m_fx = lcf;
Toshihiro Shimizu 890ddd
				lcf->setColumn(this);
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
		} else if (tagName == "fxnodes") // per compatibilita' con 1.x e precedenti
Toshihiro Shimizu 890ddd
		{
Toshihiro Shimizu 890ddd
			TFxSet fxSet;
Toshihiro Shimizu 890ddd
			fxSet.loadData(is);
Toshihiro Shimizu 890ddd
		} else {
Toshihiro Shimizu 890ddd
			throw TException("TXshLevelColumn, unknown tag: " + tagName);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		is.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TXshLevelColumn::saveData(TOStream &os)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	os.child("status") << getStatusWord();
Toshihiro Shimizu 890ddd
	if (getOpacity() < 255)
Toshihiro Shimizu 890ddd
		os.child("camerastand_opacity") << (int)getOpacity();
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
			TFrameId fid = cell.m_frameId;
Toshihiro Shimizu 890ddd
			int n = 1, inc = 0, dr = fid.getNumber();
Toshihiro Shimizu 890ddd
			//If fid has not letter save more than one cell and its incrementation; otherwise save one cell.
Toshihiro Shimizu 890ddd
			if (r < r1 && fid.getLetter() == 0) {
Toshihiro Shimizu 890ddd
				TXshCell cell2 = getCell(r + 1);
Toshihiro Shimizu 890ddd
				TFrameId fid2 = cell2.m_frameId;
Toshihiro Shimizu 890ddd
				if (cell2.m_level.getPointer() == cell.m_level.getPointer() && fid2.getLetter() == 0) {
Toshihiro Shimizu 890ddd
					inc = cell2.m_frameId.getNumber() - dr;
Toshihiro Shimizu 890ddd
					n++;
Toshihiro Shimizu 890ddd
					for (;;) {
Toshihiro Shimizu 890ddd
						if (r + n > r1)
Toshihiro Shimizu 890ddd
							break;
Toshihiro Shimizu 890ddd
						cell2 = getCell(r + n);
Toshihiro Shimizu 890ddd
						TFrameId fid2 = cell2.m_frameId;
Toshihiro Shimizu 890ddd
						if (cell2.m_level.getPointer() != cell.m_level.getPointer() || fid2.getLetter() != 0)
Toshihiro Shimizu 890ddd
							break;
Toshihiro Shimizu 890ddd
						if (fid2.getNumber() != dr + n * inc)
Toshihiro Shimizu 890ddd
							break;
Toshihiro Shimizu 890ddd
						n++;
Toshihiro Shimizu 890ddd
					}
Toshihiro Shimizu 890ddd
				}
Toshihiro Shimizu 890ddd
			}
Toshihiro Shimizu 890ddd
			os.child("cell") << r << n << cell.m_level.getPointer() << fid.expand() << inc;
Toshihiro Shimizu 890ddd
			r += n - 1;
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
		os.closeChild();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	os.child("fx") << m_fx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
PERSIST_IDENTIFIER(TXshLevelColumn, "levelColumn")