Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfxset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tstream.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
TFxSet::TFxSet()
Toshihiro Shimizu 890ddd
//: m_xsheetFx(0)
Shinya Kitaoka 120a6e
{}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
TFxSet::~TFxSet() {
Shinya Kitaoka 120a6e
  // delete m_xsheetFx;
Shinya Kitaoka 120a6e
  clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFxSet::addFx(TFx *fx) {
Shinya Kitaoka 120a6e
  std::set<tfx *="">::iterator it = m_fxs.find(fx);</tfx>
Shinya Kitaoka 120a6e
  if (it == m_fxs.end()) {
Shinya Kitaoka 120a6e
    fx->addRef();
Shinya Kitaoka 120a6e
    m_fxs.insert(fx);
Shinya Kitaoka 120a6e
    fx->setNewIdentifier();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFxSet::getFxs(std::set<tfx *=""> &fxs) {</tfx>
Shinya Kitaoka 120a6e
  fxs.insert(m_fxs.begin(), m_fxs.end());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFxSet::saveData(TOStream &os, int occupiedColumnCount) {
Shinya Kitaoka 120a6e
  std::set<tfx *="">::iterator it;</tfx>
Shinya Kitaoka 120a6e
  for (it = m_fxs.begin(); it != m_fxs.end(); ++it) {
Shinya Kitaoka 120a6e
    TRasterFx *rasterFx = dynamic_cast<trasterfx *="">(*it);</trasterfx>
Shinya Kitaoka 120a6e
    if (rasterFx) {
Shinya Kitaoka 120a6e
      TColumnFx *columnFx = dynamic_cast<tcolumnfx *="">(rasterFx);</tcolumnfx>
Shinya Kitaoka 120a6e
      if (columnFx && (columnFx->getColumnIndex() == -1 ||
Shinya Kitaoka 120a6e
                       columnFx->getColumnIndex() >= occupiedColumnCount))
Shinya Kitaoka 120a6e
        continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    os.openChild("fxnode");
Shinya Kitaoka 120a6e
    os << (*it);
Shinya Kitaoka 120a6e
    os.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int TFxSet::getFxCount() const { return m_fxs.size(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
bool TFxSet::removeFx(TFx *fx) {
Shinya Kitaoka 120a6e
  std::set<tfx *="">::iterator it = m_fxs.find(fx);</tfx>
Shinya Kitaoka 120a6e
  if (it != m_fxs.end()) {
Shinya Kitaoka 120a6e
    TFx *fx = *it;
Shinya Kitaoka 120a6e
    fx->release();
Shinya Kitaoka 120a6e
    m_fxs.erase(fx);
Shinya Kitaoka 120a6e
    return true;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFx *TFxSet::getFx(int index) const {
Shinya Kitaoka 120a6e
  assert(0 <= index && index < getFxCount());
Shinya Kitaoka 120a6e
  std::set<tfx *="">::const_iterator it = m_fxs.begin();</tfx>
Shinya Kitaoka 120a6e
  std::advance(it, index);
Shinya Kitaoka 120a6e
  return *it;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFx *TFxSet::getFx(const std::string &id) const {
Shinya Kitaoka 120a6e
  std::set<tfx *="">::const_iterator it;</tfx>
Shinya Kitaoka 120a6e
  for (it = m_fxs.begin(); it != m_fxs.end(); ++it) {
Shinya Kitaoka 120a6e
    //     TFx *fx = *it;
Shinya Kitaoka 120a6e
    // if (fx->getId() == id)
Shinya Kitaoka 120a6e
    //  return fx;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFxSet::clear() {
Shinya Kitaoka 120a6e
  std::set<tfx *="">::iterator it;</tfx>
Shinya Kitaoka 120a6e
  for (it = m_fxs.begin(); it != m_fxs.end(); ++it) {
Shinya Kitaoka 120a6e
    TFx *fx = *it;
Shinya Kitaoka 120a6e
    fx->release();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_fxs.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TFxSet::loadData(TIStream &is) {
Shinya Kitaoka 120a6e
  clear();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::string tagName;
Shinya Kitaoka 120a6e
  while (is.openChild(tagName)) {
Shinya Kitaoka 120a6e
    if (tagName == "fxnode") {
Shinya Kitaoka 120a6e
      TPersist *p = 0;
Shinya Kitaoka 120a6e
      is >> p;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // NOTE: In current implementation p is sharedly owned by is - it's
Shinya Kitaoka 120a6e
      // automatically
Shinya Kitaoka 120a6e
      //       released upon stream destruction if the below assignment fails
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (TFx *fx = dynamic_cast<tfx *="">(p)) {</tfx>
Shinya Kitaoka 120a6e
        addFx(fx);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      throw TException("TFxSet, unknown tag: " + tagName);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    is.closeChild();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Campbell Barton b3bd84
static TFx *getActualFx(TFx *fx) {
Shinya Kitaoka 120a6e
  // Zerary fxs and zerary COLUMN fxs are separate, and fx port connections
Shinya Kitaoka 120a6e
  // are stored in the actual zerary fx.
Shinya Kitaoka 120a6e
  // It's sad - couldn't we do something about it?
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TZeraryColumnFx *zeraryColumnFx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
  return zeraryColumnFx ? zeraryColumnFx->getZeraryFx() : fx;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TFx *searchFx(const std::map<tfx *="" *,="" tfx=""> &table, TFx *fx) {</tfx>
Shinya Kitaoka 120a6e
  std::map<tfx *="" *,="" tfx="">::const_iterator it = table.find(fx);</tfx>
Shinya Kitaoka 120a6e
  return it == table.end() ? 0 : it->second;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void updateFxLinks(const std::map<tfx *="" *,="" tfx=""> &table) {</tfx>
Shinya Kitaoka 120a6e
  // The input table is made of (original, cloned) couples.
Shinya Kitaoka 120a6e
  // The purpose of this function is that of replicating the hierarchycal
Shinya Kitaoka 120a6e
  // structure from the first fxs to the seconds.
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  std::map<tfx *="" *,="" tfx="">::const_iterator it;</tfx>
Shinya Kitaoka 120a6e
  for (it = table.begin(); it != table.end(); ++it) {
Shinya Kitaoka 120a6e
    TFx *fx = getActualFx(it->first), *fx2 = getActualFx(it->second);
Shinya Kitaoka 120a6e
    if (!fx || !fx2) continue;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    for (int i = 0; i < fx->getInputPortCount(); ++i) {
Shinya Kitaoka 120a6e
      TFx *inputFx  = fx->getInputPort(i)->getFx();
Shinya Kitaoka 120a6e
      TFx *inputFx2 = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (inputFx) {
Shinya Kitaoka 120a6e
        inputFx2 = searchFx(table, inputFx);
Shinya Kitaoka 120a6e
        inputFx  = getActualFx(inputFx);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        // Normally, the above should be enough. However, it seems that
Shinya Kitaoka 120a6e
        // the possibility of the input table being 'incomplete' must be dealt
Shinya Kitaoka 120a6e
        // with
Shinya Kitaoka 120a6e
        // (why is it not asserted >_< !)
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
        while (inputFx && !inputFx2 && (inputFx->getInputPortCount() > 0)) {
Shinya Kitaoka 120a6e
          // So, well... this block tries to delve deeper in the hierarchy
Shinya Kitaoka 120a6e
          // until a suitable mapped children is found... Yeah, sure...
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          TFxPort *port = inputFx->getInputPort(0);
Shinya Kitaoka 120a6e
          inputFx       = port->getFx();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          inputFx2 = searchFx(table, inputFx);
Shinya Kitaoka 120a6e
          inputFx  = getActualFx(inputFx);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (inputFx2) fx2->getInputPort(i)->setFx(inputFx2);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}