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