Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tfxattributes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshzeraryfxcolumn.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "fxdata.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
//    Local namespace  stuff
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void linkFxs(const QMap<tfx *="" *,="" tfx=""> &clonedFxs, const QList<link> &selectedLinks)</tfx>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < selectedLinks.size(); i++) {
Toshihiro Shimizu 890ddd
		TFx *outFx = selectedLinks[i].m_outputFx.getPointer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TZeraryColumnFx *zerayFx = dynamic_cast<tzerarycolumnfx *="">(outFx);</tzerarycolumnfx>
Toshihiro Shimizu 890ddd
		if (zerayFx)
Toshihiro Shimizu 890ddd
			outFx = zerayFx->getZeraryFx();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFx *inFx = selectedLinks[i].m_inputFx.getPointer();
Toshihiro Shimizu 890ddd
		zerayFx = dynamic_cast<tzerarycolumnfx *="">(inFx);</tzerarycolumnfx>
Toshihiro Shimizu 890ddd
		if (zerayFx)
Toshihiro Shimizu 890ddd
			inFx = zerayFx->getZeraryFx();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		if (!clonedFxs.contains(outFx) || !clonedFxs.contains(inFx))
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFx *clonedOutFx = clonedFxs[outFx];
Toshihiro Shimizu 890ddd
		TFx *clonedInFx = clonedFxs[inFx];
Toshihiro Shimizu 890ddd
		assert(clonedOutFx && clonedInFx);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		clonedOutFx->getInputPort(selectedLinks[i].m_index)->setFx(clonedInFx);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void linkFxs(const QMap<tfx *="" *,="" tfx=""> &clonedFxs)</tfx>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QMap<tfx *="" *,="" tfx="">::const_iterator it;</tfx>
Toshihiro Shimizu 890ddd
	for (it = clonedFxs.begin(); it != clonedFxs.end(); it++) {
Toshihiro Shimizu 890ddd
		TFx *fx = it.key();
Toshihiro Shimizu 890ddd
		int j, portCount = fx->getInputPortCount();
Toshihiro Shimizu 890ddd
		for (j = 0; j < portCount; j++) {
Toshihiro Shimizu 890ddd
			TFx *inputFx = fx->getInputPort(j)->getFx();
Toshihiro Shimizu 890ddd
			if (!clonedFxs.contains(inputFx))
Toshihiro Shimizu 890ddd
				continue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
			TFx *clonedFx = clonedFxs[fx];
Toshihiro Shimizu 890ddd
			TFx *inputClonedFx = clonedFxs[inputFx];
Toshihiro Shimizu 890ddd
			assert(clonedFx && inputClonedFx);
Toshihiro Shimizu 890ddd
			clonedFx->getInputPort(j)->setFx(inputClonedFx);
Toshihiro Shimizu 890ddd
		}
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool canCopyFx(TFx *fx)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TLevelColumnFx *lcFx = dynamic_cast<tlevelcolumnfx *="">(fx);</tlevelcolumnfx>
Toshihiro Shimizu 890ddd
	TPaletteColumnFx *pfx = dynamic_cast<tpalettecolumnfx *="">(fx);</tpalettecolumnfx>
Toshihiro Shimizu 890ddd
	TXsheetFx *xfx = dynamic_cast<txsheetfx *="">(fx);</txsheetfx>
Toshihiro Shimizu 890ddd
	TOutputFx *ofx = dynamic_cast<toutputfx *="">(fx);</toutputfx>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return (!lcFx && !pfx && !xfx && !ofx);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
//    FxsData  implementation
Toshihiro Shimizu 890ddd
//******************************************************************
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxsData::FxsData()
Toshihiro Shimizu 890ddd
	: m_connected(false)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxsData::setFxs(const QList<tfxp> &selectedFxs,</tfxp>
Toshihiro Shimizu 890ddd
					 const QList<link> &selectedLinks,
Toshihiro Shimizu 890ddd
					 const QList<int> &columnIndexes,</int>
Toshihiro Shimizu 890ddd
					 TXsheet *xsh)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//fx->clonedFx
Toshihiro Shimizu 890ddd
	QMap<tfx *="" *,="" tfx=""> clonedFxs;</tfx>
Toshihiro Shimizu 890ddd
	for (int i = 0; i < selectedFxs.size(); i++) {
Toshihiro Shimizu 890ddd
		TFx *fx = selectedFxs[i].getPointer();
Toshihiro Shimizu 890ddd
		if (!canCopyFx(fx))
Toshihiro Shimizu 890ddd
			continue;
Toshihiro Shimizu 890ddd
		TZeraryColumnFx *zerayFx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Toshihiro Shimizu 890ddd
		if (zerayFx)
Toshihiro Shimizu 890ddd
			fx = zerayFx->getZeraryFx();
Toshihiro Shimizu 890ddd
		TFx *clonedFx = fx->clone(false);
Toshihiro Shimizu 890ddd
		TPointD pos;
Toshihiro Shimizu 890ddd
		if (zerayFx)
Toshihiro Shimizu 890ddd
			pos = zerayFx->getAttributes()->getDagNodePos();
Toshihiro Shimizu 890ddd
		else
Toshihiro Shimizu 890ddd
			pos = fx->getAttributes()->getDagNodePos();
Toshihiro Shimizu 890ddd
		clonedFx->getAttributes()->setDagNodePos(pos);
Toshihiro Shimizu 890ddd
		m_fxs.append(clonedFx);
Toshihiro Shimizu 890ddd
		if (zerayFx)
Toshihiro Shimizu 890ddd
			m_zeraryFxColumnSize[clonedFx] = zerayFx->getColumn()->getRowCount();
Toshihiro Shimizu 890ddd
		m_visitedFxs[clonedFx] = false;
Toshihiro Shimizu 890ddd
		clonedFxs[fx] = clonedFx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFx *linkedFx = fx->getLinkedFx();
Toshihiro Shimizu 890ddd
		if (linkedFx && clonedFxs.contains(linkedFx))
Toshihiro Shimizu 890ddd
			clonedFx->linkParams(clonedFxs[linkedFx]);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QList<int>::const_iterator it;</int>
Toshihiro Shimizu 890ddd
	for (it = columnIndexes.begin(); it != columnIndexes.end(); it++) {
Toshihiro Shimizu 890ddd
		TXshColumn *col = xsh->getColumn(*it);
Toshihiro Shimizu 890ddd
		TXshColumn *newCol = col->clone();
Toshihiro Shimizu 890ddd
		newCol->getFx()->getAttributes()->setDagNodePos(col->getFx()->getAttributes()->getDagNodePos());
Toshihiro Shimizu 890ddd
		m_columns.append(newCol);
Toshihiro Shimizu 890ddd
		clonedFxs[col->getFx()] = newCol->getFx();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	linkFxs(clonedFxs, selectedLinks);
Toshihiro Shimizu 890ddd
	checkConnectivity();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxsData::getFxs(QList<tfxp> &fxs, QMap<tfx *,="" int=""> &zeraryFxColumnSize, QList<txshcolumnp> &columns) const</txshcolumnp></tfx></tfxp>
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QMap<tfx *="" *,="" tfx=""> clonedFxs;</tfx>
Toshihiro Shimizu 890ddd
	for (int i = 0; i < m_fxs.size(); i++) {
Toshihiro Shimizu 890ddd
		TFx *clonedFx = m_fxs[i]->clone(false);
Toshihiro Shimizu 890ddd
		TPointD pos = m_fxs[i]->getAttributes()->getDagNodePos();
Toshihiro Shimizu 890ddd
		clonedFx->getAttributes()->setDagNodePos(pos);
Toshihiro Shimizu 890ddd
		clonedFx->getAttributes()->removeFromAllGroup();
Toshihiro Shimizu 890ddd
		fxs.append(clonedFx);
Toshihiro Shimizu 890ddd
		if (m_fxs[i]->isZerary())
Toshihiro Shimizu 890ddd
			zeraryFxColumnSize[clonedFx] = m_zeraryFxColumnSize[m_fxs[i].getPointer()];
Toshihiro Shimizu 890ddd
		clonedFxs[m_fxs[i].getPointer()] = clonedFx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TFx *linkedFx = m_fxs[i]->getLinkedFx();
Toshihiro Shimizu 890ddd
		if (linkedFx && clonedFxs.contains(linkedFx))
Toshihiro Shimizu 890ddd
			clonedFx->linkParams(clonedFxs[linkedFx]);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QList<txshcolumnp>::const_iterator it;</txshcolumnp>
Toshihiro Shimizu 890ddd
	for (it = m_columns.begin(); it != m_columns.end(); it++) {
Toshihiro Shimizu 890ddd
		TXshColumn *col = it->getPointer();
Toshihiro Shimizu 890ddd
		TXshColumn *newCol = col->clone();
Toshihiro Shimizu 890ddd
		newCol->getFx()->getAttributes()->setDagNodePos(col->getFx()->getAttributes()->getDagNodePos());
Toshihiro Shimizu 890ddd
		columns.append(newCol);
Toshihiro Shimizu 890ddd
		clonedFxs[col->getFx()] = newCol->getFx();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	linkFxs(clonedFxs);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxsData *FxsData::clone() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FxsData *data = new FxsData;
Toshihiro Shimizu 890ddd
	getFxs(data->m_fxs, data->m_zeraryFxColumnSize, data->m_columns);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return data;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxsData::checkConnectivity()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_fxs.isEmpty())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	visitFx(m_fxs.at(0).getPointer());
Toshihiro Shimizu 890ddd
	m_connected = true;
Toshihiro Shimizu 890ddd
	QMap<tfx *,="" bool="">::const_iterator it;</tfx>
Toshihiro Shimizu 890ddd
	for (it = m_visitedFxs.begin(); it != m_visitedFxs.end(); it++)
Toshihiro Shimizu 890ddd
		m_connected = m_connected && it.value();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FxsData::visitFx(TFx *fx)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_visitedFxs.value(fx))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_visitedFxs[fx] = true;
Toshihiro Shimizu 890ddd
	int i;
Toshihiro Shimizu 890ddd
	for (i = 0; i < fx->getInputPortCount(); i++) {
Toshihiro Shimizu 890ddd
		TFx *inputFx = fx->getInputPort(i)->getFx();
Toshihiro Shimizu 890ddd
		if (m_visitedFxs.contains(inputFx) && areLinked(fx, inputFx))
Toshihiro Shimizu 890ddd
			visitFx(inputFx);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	for (i = 0; i < fx->getOutputConnectionCount(); i++) {
Toshihiro Shimizu 890ddd
		TFx *outputFx = fx->getOutputConnection(i)->getOwnerFx();
Toshihiro Shimizu 890ddd
		if (m_visitedFxs.contains(outputFx) && areLinked(outputFx, fx))
Toshihiro Shimizu 890ddd
			visitFx(outputFx);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool FxsData::areLinked(TFx *outFx, TFx *inFx)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	for (int i = 0; i < outFx->getInputPortCount(); i++) {
Toshihiro Shimizu 890ddd
		TFx *inputFx = outFx->getInputPort(i)->getFx();
Toshihiro Shimizu 890ddd
		if (inFx == inputFx)
Toshihiro Shimizu 890ddd
			return true;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	return false;
Toshihiro Shimizu 890ddd
}