Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/fxschematicscene.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzQt includes
manongjohn d6e3cc
#include "toonzqt/fxtypes.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxschematicnode.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/fxselection.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/schematicgroupeditor.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/swatchviewer.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/tselectionhandle.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzLib includes
Toshihiro Shimizu 890ddd
#include "toonz/txsheet.h"
Toshihiro Shimizu 890ddd
#include "toonz/toonzscene.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfxset.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxdag.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshlevelcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnfx.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshpalettecolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/txshzeraryfxcolumn.h"
Toshihiro Shimizu 890ddd
#include "toonz/fxcommand.h"
Toshihiro Shimizu 890ddd
#include "toonz/txsheethandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tfxhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tscenehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tcolumnhandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tframehandle.h"
Toshihiro Shimizu 890ddd
#include "toonz/tobjecthandle.h"
manongjohn d6e3cc
#include "toonz/childstack.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tmacrofx.h"
Toshihiro Shimizu 890ddd
#include "fxdata.h"
Toshihiro Shimizu 890ddd
#include "tpassivecachemanager.h"
Toshihiro Shimizu 890ddd
#include "tfxattributes.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tconst.h"
manongjohn d6e3cc
#include "tenv.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qmenu></qmenu>
Toshihiro Shimizu 890ddd
#include <qapplication></qapplication>
Toshihiro Shimizu 890ddd
#include <qgraphicsscenecontextmenuevent></qgraphicsscenecontextmenuevent>
Toshihiro Shimizu 890ddd
manongjohn d6e3cc
TEnv::IntVar IconifyFxSchematicNodes("IconifyFxSchematicNodes", 0);
manongjohn d6e3cc
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class MatchesFx {
Shinya Kitaoka 120a6e
  TFxP m_fx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  MatchesFx(const TFxP &fx) : m_fx(fx) {}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool operator()(const TFxP &fx) {
Shinya Kitaoka 120a6e
    TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(fx.getPointer());</tzerarycolumnfx>
Shinya Kitaoka 120a6e
    return (m_fx.getPointer() == fx.getPointer()) ||
Shinya Kitaoka 120a6e
           (zfx && m_fx.getPointer() == zfx->getZeraryFx());
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void keepSubgroup(QMap<int, *="" qlist<schematicnode="">> &editedGroup) {</int,>
Shinya Kitaoka 120a6e
  QMap<int, *="" qlist<schematicnode="">>::iterator it;</int,>
Shinya Kitaoka 120a6e
  for (it = editedGroup.begin(); it != editedGroup.end(); it++) {
Shinya Kitaoka 120a6e
    QList<schematicnode *=""> groupedNodes = it.value();</schematicnode>
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    for (i = 0; i < groupedNodes.size(); i++) {
Shinya Kitaoka 120a6e
      FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(groupedNodes[i]);</fxschematicnode>
Shinya Kitaoka 120a6e
      if (!node) continue;
Shinya Kitaoka 120a6e
      TFx *fx = node->getFx();
Shinya Kitaoka 120a6e
      assert(fx);
Shinya Kitaoka 120a6e
      QMap<int, *="" qlist<schematicnode="">>::iterator it2;</int,>
Shinya Kitaoka 120a6e
      for (it2 = editedGroup.begin(); it2 != editedGroup.end(); it2++) {
Shinya Kitaoka 120a6e
        if (fx->getAttributes()->isContainedInGroup(it2.key()) &&
Shinya Kitaoka 120a6e
            !editedGroup[it2.key()].contains(node))
Shinya Kitaoka 120a6e
          editedGroup[it2.key()].append(node);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//! Find the input and the output fx contained in \b visitedFxs.
Shinya Kitaoka 120a6e
//! \b visitedFxs must be a connected fx selection. In \b outputFx is put the
Shinya Kitaoka 120a6e
//! root of the connected fx selection.
Toshihiro Shimizu 890ddd
//! In \b inputFx is put a leaf of the connected fx selection.
Shinya Kitaoka 120a6e
void findBoundariesFxs(TFx *&inputFx, TFx *&outputFx,
Shinya Kitaoka 120a6e
                       QMap<tfx *,="" bool=""> &visitedFxs, TFx *currentFx = 0) {</tfx>
Shinya Kitaoka 120a6e
  if (visitedFxs.isEmpty()) return;
Shinya Kitaoka 120a6e
  if (!currentFx) currentFx = visitedFxs.begin().key();
Shinya Kitaoka 120a6e
  int inputPortCount        = currentFx->getInputPortCount();
Shinya Kitaoka 120a6e
  int outputConnectionCount = currentFx->getOutputConnectionCount();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (inputPortCount > 0 && !visitedFxs[currentFx]) {
Shinya Kitaoka 120a6e
    visitedFxs[currentFx] = true;
Shinya Kitaoka 120a6e
    TFxPort *fxPort       = currentFx->getInputPort(0);
Shinya Kitaoka 120a6e
    TFx *fx               = fxPort->getFx();
Shinya Kitaoka 120a6e
    if (fx && visitedFxs.count(fx) == 1) {
Shinya Kitaoka 120a6e
      if (!visitedFxs[fx]) findBoundariesFxs(inputFx, outputFx, visitedFxs, fx);
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      inputFx = currentFx;
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    inputFx = currentFx;
Shinya Kitaoka 120a6e
  if (!outputFx) {
Shinya Kitaoka 120a6e
    if (outputConnectionCount > 0) {
Shinya Kitaoka 120a6e
      TFx *fx = currentFx->getOutputConnection(0)->getOwnerFx();
Shinya Kitaoka 120a6e
      if (fx && visitedFxs.count(fx) == 1) {
Shinya Kitaoka 120a6e
        if (!visitedFxs[fx])
Shinya Kitaoka 120a6e
          findBoundariesFxs(inputFx, outputFx, visitedFxs, fx);
Shinya Kitaoka 120a6e
      } else
Shinya Kitaoka 120a6e
        outputFx = currentFx;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      outputFx = currentFx;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool canDisconnectSelection(FxSelection *selection) {
Shinya Kitaoka 120a6e
  QList<tfxp> selectedFx = selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < selectedFx.size(); i++)  // .....
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    TFx *fx = selectedFx[i].getPointer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TLevelColumnFx *lcFx  = dynamic_cast<tlevelcolumnfx *="">(fx);</tlevelcolumnfx>
Shinya Kitaoka 120a6e
    TPaletteColumnFx *pfx = dynamic_cast<tpalettecolumnfx *="">(fx);</tpalettecolumnfx>
Shinya Kitaoka 120a6e
    TXsheetFx *xfx        = dynamic_cast<txsheetfx *="">(fx);</txsheetfx>
Shinya Kitaoka 120a6e
    TOutputFx *ofx        = dynamic_cast<toutputfx *="">(fx);</toutputfx>
Shinya Kitaoka 120a6e
    TZeraryColumnFx *zfx  = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    return (!lcFx && !pfx && !xfx && !ofx &&
Shinya Kitaoka 120a6e
            (!zfx || zfx->getInputPortCount() > 0));  // !!!!!
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return false;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
QList<tfxp> getRoots(const QList<tfxp> &fxs, TFxSet *terminals) {</tfxp></tfxp>
Shinya Kitaoka 120a6e
  QList<tfxp> roots;</tfxp>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < fxs.size(); i++) {
Shinya Kitaoka 120a6e
    TFx *fx = fxs[i].getPointer();
Shinya Kitaoka 120a6e
    int j;
Shinya Kitaoka 120a6e
    bool isRoot = true;
Shinya Kitaoka 120a6e
    for (j = 0; j < fx->getOutputConnectionCount(); j++) {
Shinya Kitaoka 120a6e
      TFx *outFx = fx->getOutputConnection(j)->getOwnerFx();
Shinya Kitaoka 120a6e
      if (outFx &&
Shinya Kitaoka 120a6e
          std::find_if(fxs.begin(), fxs.end(), MatchesFx(outFx)) != fxs.end() &&
Shinya Kitaoka 120a6e
          !terminals->containsFx(fx))
Shinya Kitaoka 120a6e
        isRoot = false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (isRoot) roots.append(fx);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return roots;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
manongjohn adae7d
bool resizingNodes = false;
manongjohn adae7d
bool updatingScene = false;
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// FxSchematicScene::SupportLinks
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::addBridgeLink(SchematicLink *link) {
Shinya Kitaoka 120a6e
  if (link && !m_bridges.contains(link)) m_bridges.push_back(link);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::addOutputLink(SchematicLink *link) {
Shinya Kitaoka 120a6e
  if (link && !m_outputs.contains(link)) m_outputs.push_back(link);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::addInputLink(SchematicLink *link) {
Shinya Kitaoka 120a6e
  if (link && !m_inputs.contains(link)) m_inputs.push_back(link);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::hideBridgeLinks() {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_bridges.size(); i++) m_bridges[i]->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::hideInputLinks() {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_inputs.size(); i++) m_inputs[i]->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::hideOutputLinks() {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_outputs.size(); i++) m_outputs[i]->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::showBridgeLinks() {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_bridges.size(); i++) m_bridges[i]->show();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::showInputLinks() {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_inputs.size(); i++) m_inputs[i]->show();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::showOutputLinks() {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_outputs.size(); i++) m_outputs[i]->show();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::removeBridgeLinks(bool deleteLink) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_bridges.size(); i++) {
Shinya Kitaoka 120a6e
    SchematicLink *link = m_bridges[i];
Shinya Kitaoka 120a6e
    m_bridges.removeAt(i);
Shinya Kitaoka 120a6e
    if (deleteLink) {
Shinya Kitaoka 120a6e
      link->getStartPort()->removeLink(link);
Shinya Kitaoka 120a6e
      link->getEndPort()->removeLink(link);
Shinya Kitaoka 120a6e
      delete link;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::removeInputLinks(bool deleteLink) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_inputs.size(); i++) {
Shinya Kitaoka 120a6e
    SchematicLink *link = m_inputs[i];
Shinya Kitaoka 120a6e
    m_inputs.removeAt(i);
Shinya Kitaoka 120a6e
    if (deleteLink) {
Shinya Kitaoka 120a6e
      link->getStartPort()->removeLink(link);
Shinya Kitaoka 120a6e
      link->getEndPort()->removeLink(link);
Shinya Kitaoka 120a6e
      delete link;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::removeOutputLinks(bool deleteLink) {
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < m_outputs.size(); i++) {
Shinya Kitaoka 120a6e
    SchematicLink *link = m_outputs[i];
Shinya Kitaoka 120a6e
    m_outputs.removeAt(i);
Shinya Kitaoka 120a6e
    if (deleteLink) {
Shinya Kitaoka 120a6e
      link->getStartPort()->removeLink(link);
Shinya Kitaoka 120a6e
      link->getEndPort()->removeLink(link);
Shinya Kitaoka 120a6e
      delete link;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::SupportLinks::clearAll() {
Shinya Kitaoka 120a6e
  m_bridges.clear();
Shinya Kitaoka 120a6e
  m_inputs.clear();
Shinya Kitaoka 120a6e
  m_outputs.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int FxSchematicScene::SupportLinks::size() {
Shinya Kitaoka 120a6e
  return m_bridges.size() + m_inputs.size() + m_outputs.size();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// FxSchematicScene
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FxSchematicScene::FxSchematicScene(QWidget *parent)
Shinya Kitaoka 120a6e
    : SchematicScene(parent)
Shinya Kitaoka 120a6e
    , m_firstPoint(sceneRect().center())
Shinya Kitaoka 120a6e
    , m_xshHandle(0)
Shinya Kitaoka 120a6e
    , m_fxHandle(0)
Shinya Kitaoka 120a6e
    , m_addFxContextMenu()
Shinya Kitaoka 120a6e
    , m_disconnectionLinks()
Shinya Kitaoka 120a6e
    , m_connectionLinks()
Shinya Kitaoka 120a6e
    , m_isConnected(false)
Shinya Kitaoka 120a6e
    , m_linkUnlinkSimulation(false)
Shinya Kitaoka 120a6e
    , m_altPressed(false)
Shinya Kitaoka 120a6e
    , m_lastPos(0, 0)
Shinya Kitaoka 120a6e
    , m_currentFxNode(0)
Shinya Kitaoka 120a6e
    , m_gridDimension(eSmall)
manongjohn d6e3cc
    , m_isNormalIconView(!IconifyFxSchematicNodes)
manongjohn d6e3cc
    , m_viewer() {
manongjohn d6e3cc
  m_viewer = (SchematicViewer *)parent;
manongjohn d6e3cc
Shinya Kitaoka 120a6e
  m_selection = new FxSelection();
Shinya Kitaoka 120a6e
  m_selection->setFxSchematicScene(this);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  connect(m_selection, SIGNAL(doCollapse(const QList<tfxp> &)), this,</tfxp>
Shinya Kitaoka 120a6e
          SLOT(onCollapse(const QList<tfxp> &)));</tfxp>
Shinya Kitaoka 120a6e
  connect(m_selection, SIGNAL(doExplodeChild(const QList<tfxp> &)), this,</tfxp>
Shinya Kitaoka 120a6e
          SIGNAL(doExplodeChild(const QList<tfxp> &)));</tfxp>
Shinya Kitaoka 120a6e
  connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_addFxContextMenu.setSelection(m_selection);
Shinya Kitaoka 120a6e
  m_highlightedLinks.clear();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FxSchematicScene::~FxSchematicScene() {
Shinya Kitaoka 120a6e
  if (m_selection) delete m_selection;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::setApplication(TApplication *app) {
Shinya Kitaoka 120a6e
  m_app = app;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_xshHandle    = app->getCurrentXsheet();
Shinya Kitaoka 120a6e
  m_fxHandle     = app->getCurrentFx();
Shinya Kitaoka 120a6e
  m_frameHandle  = app->getCurrentFrame();
Shinya Kitaoka 120a6e
  m_columnHandle = app->getCurrentColumn();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (m_fxHandle)
Shinya Kitaoka 120a6e
    connect(m_fxHandle, SIGNAL(fxSwitched()), this,
Shinya Kitaoka 120a6e
            SLOT(onCurrentFxSwitched()));
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_addFxContextMenu.setApplication(app);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_selection->setXsheetHandle(m_xshHandle);
Shinya Kitaoka 120a6e
  m_selection->setFxHandle(m_fxHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::updateScene() {
manongjohn adae7d
  if (updatingScene) return;
manongjohn adae7d
  updatingScene = true;
manongjohn d6e3cc
  if (!views().empty()) m_disconnectionLinks.clearAll();
Shinya Kitaoka 120a6e
  m_connectionLinks.clearAll();
Shinya Kitaoka 120a6e
  m_selectionOldPos.clear();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  clearSelection();
Shinya Kitaoka 120a6e
  clearAllItems();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_table.clear();
Shinya Kitaoka 120a6e
  m_groupedTable.clear();
Shinya Kitaoka 120a6e
  m_groupEditorTable.clear();
Shinya Kitaoka 120a6e
  m_macroEditorTable.clear();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_currentFxNode = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // GroupId->Fx
Shinya Kitaoka 120a6e
  QMap<int, qlist<tfxp="">> groupedFxs;</int,>
Shinya Kitaoka 120a6e
  QMap<int, *="" qlist<schematicnode="">> editedGroup;</int,>
Shinya Kitaoka 120a6e
  QMap<tmacrofx *="" *,="" qlist<schematicnode="">> editedMacro;</tmacrofx>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TXsheet *xsh    = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
  m_gridDimension = xsh->getFxDag()->getDagGridDimension();
Shinya Kitaoka 120a6e
  TFxSet *fxSet   = xsh->getFxDag()->getInternalFxs();
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FxDag *fxDag = xsh->getFxDag();
Shinya Kitaoka 120a6e
  // Add XSheetFX node
Shinya Kitaoka 120a6e
  addFxSchematicNode(fxDag->getXsheetFx());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Add outputFx nodes
Shinya Kitaoka 120a6e
  int k;
Shinya Kitaoka 120a6e
  for (k = 0; k < fxDag->getOutputFxCount(); k++) {
Shinya Kitaoka 120a6e
    TOutputFx *fx = fxDag->getOutputFx(k);
Shinya Kitaoka 120a6e
    if (fx->getAttributes()->isGrouped() &&
Shinya Kitaoka 120a6e
        !fx->getAttributes()->isGroupEditing()) {
Shinya Kitaoka 120a6e
      groupedFxs[fx->getAttributes()->getGroupId()].push_back(fx);
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    SchematicNode *node = addFxSchematicNode(fx);
Shinya Kitaoka 120a6e
    if (fx->getAttributes()->isGrouped())
Shinya Kitaoka 120a6e
      editedGroup[fx->getAttributes()->getEditingGroupId()].append(node);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Add columnFx and zeraryFx nodes
Shinya Kitaoka 120a6e
  for (i = 0; i < xsh->getColumnCount(); i++) {
Shinya Kitaoka 120a6e
    TXshColumn *column = xsh->getColumn(i);
Shinya Kitaoka 120a6e
    TFx *fx            = 0;
Shinya Kitaoka 120a6e
    if (TXshLevelColumn *lc = column->getLevelColumn())
Shinya Kitaoka 120a6e
      fx = lc->getLevelColumnFx();
Shinya Kitaoka 120a6e
    else if (TXshPaletteColumn *pc = dynamic_cast<txshpalettecolumn *="">(column))</txshpalettecolumn>
Shinya Kitaoka 120a6e
      fx = pc->getPaletteColumnFx();
Shinya Kitaoka 120a6e
    else if (TXshZeraryFxColumn *zc =
Shinya Kitaoka 120a6e
                 dynamic_cast<txshzeraryfxcolumn *="">(column))</txshzeraryfxcolumn>
Shinya Kitaoka 120a6e
      fx = zc->getZeraryColumnFx();
Shinya Kitaoka 120a6e
    if (!fx) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (fx->getAttributes()->isGrouped() &&
Shinya Kitaoka 120a6e
        !fx->getAttributes()->isGroupEditing()) {
Shinya Kitaoka 120a6e
      groupedFxs[fx->getAttributes()->getGroupId()].push_back(fx);
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (column->isEmpty() && fx && fx->getOutputConnectionCount() == 0)
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    SchematicNode *node = addFxSchematicNode(fx);
Shinya Kitaoka 120a6e
    if (fx->getAttributes()->isGrouped())
Shinya Kitaoka 120a6e
      editedGroup[fx->getAttributes()->getEditingGroupId()].append(node);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Add normalFx
Shinya Kitaoka 120a6e
  for (i = 0; i < fxSet->getFxCount(); i++) {
Shinya Kitaoka 120a6e
    TFx *fx         = fxSet->getFx(i);
Shinya Kitaoka 120a6e
    TMacroFx *macro = dynamic_cast<tmacrofx *="">(fx);</tmacrofx>
Shinya Kitaoka 120a6e
    if (fx->getAttributes()->isGrouped() &&
Shinya Kitaoka 120a6e
        !fx->getAttributes()->isGroupEditing()) {
Shinya Kitaoka 120a6e
      groupedFxs[fx->getAttributes()->getGroupId()].push_back(fx);
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    } else if (macro && macro->isEditing()) {
Shinya Kitaoka 120a6e
      std::vector<tfxp> fxs = macro->getFxs();</tfxp>
Shinya Kitaoka 120a6e
      int j;
Shinya Kitaoka 120a6e
      for (j = 0; j < (int)fxs.size(); j++) {
Shinya Kitaoka 120a6e
        SchematicNode *node = addFxSchematicNode(fxs[j].getPointer());
Shinya Kitaoka 120a6e
        editedMacro[macro].append(node);
Shinya Kitaoka 120a6e
        if (fxs[j]->getAttributes()->isGrouped() &&
Shinya Kitaoka 120a6e
            macro->getAttributes()->isGroupEditing())
Shinya Kitaoka 120a6e
          editedGroup[fx->getAttributes()->getEditingGroupId()].append(node);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    SchematicNode *node = addFxSchematicNode(fx);
Shinya Kitaoka 120a6e
    if (fx->getAttributes()->isGrouped())
Shinya Kitaoka 120a6e
      editedGroup[fx->getAttributes()->getEditingGroupId()].append(node);
manongjohn f37f4a
    // If adding an unedited macro and nodes are not yet set, let's position the
manongjohn f37f4a
    // internal nodes now
manongjohn f37f4a
    if (macro) {
manongjohn f37f4a
      double minY           = macro->getAttributes()->getDagNodePos().y;
manongjohn f37f4a
      double maxX           = macro->getAttributes()->getDagNodePos().x;
manongjohn f37f4a
      double y              = minY;
manongjohn f37f4a
      double x              = maxX;
manongjohn f37f4a
      std::vector<tfxp> fxs = macro->getFxs();</tfxp>
manongjohn f37f4a
      for (int j = 0; j < (int)fxs.size(); j++) {
manongjohn f37f4a
        TFx *macroFx = fxs[j].getPointer();
manongjohn f37f4a
        if (macroFx && !m_placedFxs.contains(macroFx)) {
manongjohn f37f4a
          placeNodeAndParents(macroFx, x, maxX, minY);
manongjohn f37f4a
          y -= (m_gridDimension == eLarge ? 100 : 50);
manongjohn f37f4a
          minY = std::min(y, minY);
manongjohn f37f4a
        }
manongjohn f37f4a
      }
manongjohn f37f4a
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // grouped node
Shinya Kitaoka 120a6e
  QMap<int, qlist<tfxp="">>::const_iterator it;</int,>
Shinya Kitaoka 120a6e
  for (it = groupedFxs.begin(); it != groupedFxs.end(); it++) {
Shinya Kitaoka 120a6e
    FxSchematicNode *node = addGroupedFxSchematicNode(it.key(), it.value());
Shinya Kitaoka 120a6e
    TFx *fx               = node->getFx();
Shinya Kitaoka 120a6e
    assert(fx);
Shinya Kitaoka 120a6e
    int editingGroupId = fx->getAttributes()->getEditingGroupId();
Shinya Kitaoka 120a6e
    if (editingGroupId != -1) editedGroup[editingGroupId].append(node);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  keepSubgroup(editedGroup);
Shinya Kitaoka 120a6e
  updateEditedGroups(editedGroup);
Shinya Kitaoka 120a6e
  updateEditedMacros(editedMacro);
Shinya Kitaoka 120a6e
  updateLink();
Shinya Kitaoka 120a6e
  m_nodesToPlace.clear();
manongjohn adae7d
  updatingScene = false;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::updateEditedGroups(
Shinya Kitaoka 120a6e
    const QMap<int, *="" qlist<schematicnode="">> &editedGroup) {</int,>
Shinya Kitaoka 120a6e
  QMap<int, *="" qlist<schematicnode="">>::const_iterator it;</int,>
Shinya Kitaoka 120a6e
  for (it = editedGroup.begin(); it != editedGroup.end(); it++) {
Shinya Kitaoka 120a6e
    int zValue = 2;
Shinya Kitaoka 120a6e
    QMap<int, *="" qlist<schematicnode="">>::const_iterator it2 = editedGroup.begin();</int,>
Shinya Kitaoka 120a6e
    while (it2 != editedGroup.end()) {
Shinya Kitaoka 120a6e
      FxSchematicNode *placedFxNode =
Shinya Kitaoka 120a6e
          dynamic_cast<fxschematicnode *="">(it2.value()[0]);</fxschematicnode>
Shinya Kitaoka 120a6e
      FxSchematicNode *fxNode = dynamic_cast<fxschematicnode *="">(it.value()[0]);</fxschematicnode>
Shinya Kitaoka 120a6e
      if (!placedFxNode || !fxNode) {
Shinya Kitaoka 120a6e
        it2++;
Shinya Kitaoka 120a6e
        continue;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      int placedGroupedId =
Shinya Kitaoka 120a6e
          placedFxNode->getFx()->getAttributes()->getEditingGroupId();
Shinya Kitaoka 120a6e
      if (fxNode->getFx()->getAttributes()->isContainedInGroup(
Shinya Kitaoka 120a6e
              placedGroupedId) &&
Shinya Kitaoka 120a6e
          fxNode->getFx()->getAttributes()->getEditingGroupId() != it2.key())
Shinya Kitaoka 120a6e
        zValue += 2;
Shinya Kitaoka 120a6e
      it2++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    FxSchematicGroupEditor *node =
Shinya Kitaoka 120a6e
        addEditedGroupedFxSchematicNode(it.key(), it.value());
Shinya Kitaoka 120a6e
    node->setZValue(zValue);
Shinya Kitaoka 120a6e
    node->setGroupedNodeZValue(zValue + 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::updateEditedMacros(
Shinya Kitaoka 120a6e
    const QMap<tmacrofx *="" *,="" qlist<schematicnode="">> &editedMacro) {</tmacrofx>
Shinya Kitaoka 120a6e
  QMap<tmacrofx *="" *,="" qlist<schematicnode="">>::const_iterator it;</tmacrofx>
Shinya Kitaoka 120a6e
  for (it = editedMacro.begin(); it != editedMacro.end(); it++) {
Shinya Kitaoka 120a6e
    TMacroFx *macro = it.key();
Shinya Kitaoka 120a6e
    int zValue      = 2;
Shinya Kitaoka 120a6e
    if (macro->getAttributes()->isGrouped()) {
Shinya Kitaoka 120a6e
      FxSchematicGroupEditor *containingGroup =
Shinya Kitaoka 120a6e
          m_groupEditorTable[macro->getAttributes()->getEditingGroupId()];
Shinya Kitaoka 120a6e
      assert(containingGroup);
Shinya Kitaoka 120a6e
      zValue = containingGroup->zValue() + 2;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    FxSchematicMacroEditor *node =
Shinya Kitaoka 120a6e
        addEditedMacroFxSchematicNode(it.key(), it.value());
Shinya Kitaoka 120a6e
    node->setZValue(zValue);
Shinya Kitaoka 120a6e
    node->setGroupedNodeZValue(zValue + 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
FxSchematicNode *FxSchematicScene::addFxSchematicNode(TFx *fx) {
Shinya Kitaoka 120a6e
  FxSchematicNode *node = createFxSchematicNode(fx);
Shinya Kitaoka 120a6e
  if (!node) return 0;
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(sceneChanged()), this, SLOT(onSceneChanged()));
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(xsheetChanged()), this, SLOT(onXsheetChanged()));
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(switchCurrentFx(TFx *)), this,
Shinya Kitaoka 120a6e
          SLOT(onSwitchCurrentFx(TFx *)));
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(currentColumnChanged(int)), this,
Shinya Kitaoka 120a6e
          SLOT(onCurrentColumnChanged(int)));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(fxNodeDoubleClicked()), this,
Shinya Kitaoka 120a6e
          SLOT(onFxNodeDoubleClicked()));
manongjohn adae7d
manongjohn adae7d
  connect(node, SIGNAL(nodeChangedSize()), this, SLOT(onNodeChangedSize()));
manongjohn adae7d
Shinya Kitaoka 120a6e
  if (fx->getAttributes()->getDagNodePos() == TConst::nowhere) {
Shinya Kitaoka 120a6e
    node->resize(m_gridDimension == 0);
Shinya Kitaoka 120a6e
    placeNode(node);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    updatePosition(node, fx->getAttributes()->getDagNodePos());
Shinya Kitaoka 120a6e
  m_table[fx] = node;
Shinya Kitaoka 120a6e
  return node;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
FxSchematicNode *FxSchematicScene::addGroupedFxSchematicNode(
Shinya Kitaoka 120a6e
    int groupId, const QList<tfxp> &groupedFxs) {</tfxp>
Shinya Kitaoka 120a6e
  TFxSet *terminals = getXsheet()->getFxDag()->getTerminalFxs();
Shinya Kitaoka 120a6e
  QList<tfxp> roots = getRoots(groupedFxs, terminals);</tfxp>
Shinya Kitaoka 120a6e
  if (roots.isEmpty()) return 0;
Shinya Kitaoka 120a6e
  std::wstring name = roots[0]->getAttributes()->getGroupName(false);
Shinya Kitaoka 120a6e
  FxGroupNode *node = new FxGroupNode(this, groupedFxs, roots, groupId, name);
Shinya Kitaoka 120a6e
  if (!node) return 0;
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(sceneChanged()), this, SLOT(onSceneChanged()));
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(xsheetChanged()), this, SLOT(onXsheetChanged()));
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(switchCurrentFx(TFx *)), this,
Shinya Kitaoka 120a6e
          SLOT(onSwitchCurrentFx(TFx *)));
Shinya Kitaoka 120a6e
  connect(node, SIGNAL(currentColumnChanged(int)), this,
Shinya Kitaoka 120a6e
          SLOT(onCurrentColumnChanged(int)));
manongjohn b13816
  connect(node, SIGNAL(fxNodeDoubleClicked()), this,
manongjohn b13816
          SLOT(onFxNodeDoubleClicked()));
Shinya Kitaoka 120a6e
  m_groupedTable[groupId] = node;
Shinya Kitaoka 120a6e
  return node;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
FxSchematicGroupEditor *FxSchematicScene::addEditedGroupedFxSchematicNode(
Shinya Kitaoka 120a6e
    int groupId, const QList<schematicnode *=""> &groupedFxs) {</schematicnode>
Shinya Kitaoka 120a6e
  FxSchematicGroupEditor *editorGroup =
Shinya Kitaoka 120a6e
      new FxSchematicGroupEditor(groupId, groupedFxs, this);
Shinya Kitaoka 120a6e
  m_groupEditorTable[groupId] = editorGroup;
Shinya Kitaoka 120a6e
  return editorGroup;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
FxSchematicMacroEditor *FxSchematicScene::addEditedMacroFxSchematicNode(
Shinya Kitaoka 120a6e
    TMacroFx *macro, const QList<schematicnode *=""> &groupedFxs) {</schematicnode>
Shinya Kitaoka 120a6e
  FxSchematicMacroEditor *editorMacro =
Shinya Kitaoka 120a6e
      new FxSchematicMacroEditor(macro, groupedFxs, this);
Shinya Kitaoka 120a6e
  m_macroEditorTable[macro] = editorMacro;
Shinya Kitaoka 120a6e
  return editorMacro;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::updatePosition(FxSchematicNode *node,
Shinya Kitaoka 120a6e
                                      const TPointD &pos) {
Shinya Kitaoka 120a6e
  node->setPos(QPointF(pos.x, pos.y));
Shinya Kitaoka 120a6e
  node->getFx()->getAttributes()->setDagNodePos(pos);
Shinya Kitaoka 120a6e
  QVector<schematicnode *=""> placedNodes = getPlacedNode(node);</schematicnode>
Shinya Kitaoka 120a6e
  int step                             = m_gridDimension == eLarge ? 100 : 50;
Shinya Kitaoka 120a6e
  TPointD offset(0, -step);
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < placedNodes.size(); i++) {
Shinya Kitaoka 120a6e
    FxSchematicNode *placedNode =
Shinya Kitaoka 120a6e
        dynamic_cast<fxschematicnode *="">(placedNodes[i]);</fxschematicnode>
Shinya Kitaoka 120a6e
    assert(placedNode);
Shinya Kitaoka 120a6e
    TPointD newPos =
Shinya Kitaoka 120a6e
        placedNode->getFx()->getAttributes()->getDagNodePos() + offset;
Shinya Kitaoka 120a6e
    updatePosition(placedNode, newPos);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! create node depends on the fx type
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
FxSchematicNode *FxSchematicScene::createFxSchematicNode(TFx *fx) {
Shinya Kitaoka 120a6e
  if (TLevelColumnFx *lcFx = dynamic_cast<tlevelcolumnfx *="">(fx))</tlevelcolumnfx>
Shinya Kitaoka 120a6e
    return new FxSchematicColumnNode(this, lcFx);
Shinya Kitaoka 120a6e
  else if (TPaletteColumnFx *pfx = dynamic_cast<tpalettecolumnfx *="">(fx))</tpalettecolumnfx>
Shinya Kitaoka 120a6e
    return new FxSchematicPaletteNode(this, pfx);
Shinya Kitaoka 120a6e
  else if (TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(fx))</tzerarycolumnfx>
Shinya Kitaoka 120a6e
    return new FxSchematicZeraryNode(this, zfx);
Shinya Kitaoka 120a6e
  else if (TXsheetFx *xfx = dynamic_cast<txsheetfx *="">(fx))</txsheetfx>
Shinya Kitaoka 120a6e
    return new FxSchematicXSheetNode(this, xfx);
Shinya Kitaoka 120a6e
  else if (TOutputFx *ofx = dynamic_cast<toutputfx *="">(fx))</toutputfx>
Shinya Kitaoka 120a6e
    return new FxSchematicOutputNode(this, ofx);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return new FxSchematicNormalFxNode(this, fx);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! place nodes of which positions are not specified manually
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void FxSchematicScene::placeNode(FxSchematicNode *node) {
Shinya Kitaoka 120a6e
  if (!node) return;
Shinya Kitaoka 120a6e
  int step        = m_gridDimension == eLarge ? 100 : 50;
Shinya Kitaoka 120a6e
  FxDag *fxDag    = m_xshHandle->getXsheet()->getFxDag();
Shinya Kitaoka 120a6e
  QRectF nodeRect = node->boundingRect();
Shinya Kitaoka 120a6e
  if (node->isA(eOutpuFx)) {
Shinya Kitaoka 120a6e
    // I'm placing an output node
Shinya Kitaoka 120a6e
    TFx *xsheetFx        = fxDag->getXsheetFx();
Shinya Kitaoka 120a6e
    TFxPort *outPort     = xsheetFx->getOutputConnection(0);
Shinya Kitaoka 120a6e
    TFx *connectedOutput = outPort ? outPort->getOwnerFx() : 0;
Shinya Kitaoka 120a6e
    if (connectedOutput && connectedOutput == node->getFx()) {
Shinya Kitaoka 120a6e
      // The output node is connected to the xsheet node
Shinya Kitaoka 120a6e
      TPointD pos = xsheetFx->getAttributes()->getDagNodePos();
Shinya Kitaoka 120a6e
      if (pos != TConst::nowhere)
Shinya Kitaoka 120a6e
        nodeRect.translate(pos.x + 120, pos.y);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        nodeRect.translate(sceneRect().center());
Shinya Kitaoka 120a6e
      while (!isAnEmptyZone(nodeRect)) nodeRect.translate(0, step);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      // The output node is not connected to the xsheet node
Shinya Kitaoka 120a6e
      TFx *fx       = node->getFx();
Shinya Kitaoka 120a6e
      TFxPort *port = fx->getInputPort(0);
Shinya Kitaoka 120a6e
      TFx *inputFx  = port->getFx();
Shinya Kitaoka 120a6e
      if (inputFx) {
Shinya Kitaoka 120a6e
        // The output node is connected to another node
Shinya Kitaoka 120a6e
        TPointD pos = inputFx->getAttributes()->getDagNodePos();
Shinya Kitaoka 120a6e
        if (pos != TConst::nowhere)
Shinya Kitaoka 120a6e
          nodeRect.translate(pos.x + 120, pos.y);
Shinya Kitaoka 120a6e
        else {
Shinya Kitaoka 120a6e
          m_nodesToPlace[inputFx].append(node);
Shinya Kitaoka 120a6e
          return;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        // The output node is not connected
Shinya Kitaoka 120a6e
        QPointF pos = sceneRect().center();
Shinya Kitaoka 120a6e
        nodeRect.translate(pos);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    while (!isAnEmptyZone(nodeRect)) nodeRect.translate(0, step);
Shinya Kitaoka 120a6e
    QPointF newPos = nodeRect.topLeft();
Shinya Kitaoka 120a6e
    node->getFx()->getAttributes()->setDagNodePos(
Shinya Kitaoka 120a6e
        TPointD(newPos.x(), newPos.y()));
Shinya Kitaoka 120a6e
    node->setPos(newPos);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (node->isA(eXSheetFx)) {
Shinya Kitaoka 120a6e
    // I'm placing the xsheet node
Shinya Kitaoka 120a6e
    TFxSet *terminalFxs = fxDag->getTerminalFxs();
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    double maxX = m_firstPoint.x();
Shinya Kitaoka 120a6e
    for (i = 0; i < terminalFxs->getFxCount(); i++) {
Shinya Kitaoka 120a6e
      TFx *terminalFx = terminalFxs->getFx(i);
Shinya Kitaoka 120a6e
      if (terminalFx->getAttributes()->getDagNodePos() == TConst::nowhere)
Shinya Kitaoka 120a6e
        continue;
Shinya Kitaoka 120a6e
      maxX = std::max(maxX, terminalFx->getAttributes()->getDagNodePos().x);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    TPointD oldPos = node->getFx()->getAttributes()->getDagNodePos();
Shinya Kitaoka 120a6e
    QPointF pos;
Shinya Kitaoka 120a6e
    if (oldPos == TConst::nowhere)
Shinya Kitaoka 120a6e
      pos = QPointF(maxX + 120, m_firstPoint.y());
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      pos = QPointF(maxX + 120 > oldPos.x ? maxX + 120 : oldPos.x, oldPos.y);
Shinya Kitaoka 120a6e
    node->getFx()->getAttributes()->setDagNodePos(TPointD(pos.x(), pos.y()));
Shinya Kitaoka 120a6e
    node->setPos(pos);
Shinya Kitaoka 120a6e
    return;
manongjohn f37f4a
  } else if (node->isA(eMacroFx)) {
manongjohn f37f4a
    double minX = TConst::nowhere.x, minY = TConst::nowhere.y, maxY;
manongjohn f37f4a
    QPointF pos;
manongjohn f37f4a
    TMacroFx *macroFx     = dynamic_cast<tmacrofx *="">(node->getFx());</tmacrofx>
manongjohn f37f4a
    std::vector<tfxp> fxs = macroFx->getFxs();</tfxp>
manongjohn f37f4a
    int k;
manongjohn f37f4a
    for (k = 0; k < (int)fxs.size(); k++) {
manongjohn f37f4a
      TFx *fx = fxs[k].getPointer();
manongjohn f37f4a
      if (fx->getAttributes()->getDagNodePos() == TConst::nowhere) continue;
manongjohn f37f4a
      if (QPointF(minX, minY) ==
manongjohn f37f4a
          QPointF(TConst::nowhere.x, TConst::nowhere.y)) {
manongjohn f37f4a
        minX = fx->getAttributes()->getDagNodePos().x;
manongjohn f37f4a
        minY = maxY = fx->getAttributes()->getDagNodePos().y;
manongjohn f37f4a
        continue;
manongjohn f37f4a
      }
manongjohn f37f4a
      minX = std::min(fx->getAttributes()->getDagNodePos().x, minX);
manongjohn f37f4a
      minY = std::min(fx->getAttributes()->getDagNodePos().y, minY);
manongjohn f37f4a
      maxY = std::max(fx->getAttributes()->getDagNodePos().y, maxY);
manongjohn f37f4a
    }
manongjohn f37f4a
    if (QPointF(minX, minY) == QPointF(TConst::nowhere.x, TConst::nowhere.y)) {
manongjohn f37f4a
      pos = sceneRect().center();
manongjohn f37f4a
      nodeRect.moveTopLeft(pos);
manongjohn f37f4a
      while (!isAnEmptyZone(nodeRect)) nodeRect.translate(0, -step);
manongjohn f37f4a
      pos = nodeRect.topLeft();
manongjohn f37f4a
    } else {
manongjohn f37f4a
      pos.setX(minX);
manongjohn f37f4a
      pos.setY((maxY + minY) / 2);
manongjohn f37f4a
    }
manongjohn f37f4a
    node->getFx()->getAttributes()->setDagNodePos(TPointD(pos.x(), pos.y()));
manongjohn f37f4a
    node->setPos(QPointF(pos));
manongjohn f37f4a
    if (m_nodesToPlace.contains(node->getFx())) {
manongjohn f37f4a
      QList<fxschematicnode *=""> nodes = m_nodesToPlace[node->getFx()];</fxschematicnode>
manongjohn f37f4a
      int i;
manongjohn f37f4a
      for (i = 0; i < nodes.size(); i++) placeNode(nodes[i]);
manongjohn f37f4a
    }
manongjohn f37f4a
    return;
manongjohn f37f4a
  } else if (node->isA(eNormalFx) || node->isA(eNormalLayerBlendingFx) ||
manongjohn f37f4a
             node->isA(eNormalMatteFx) || node->isA(eNormalImageAdjustFx)) {
Shinya Kitaoka 120a6e
    // I'm placing an effect or a macro
Shinya Kitaoka 120a6e
    TFx *inputFx = node->getFx()->getInputPort(0)->getFx();
Shinya Kitaoka 120a6e
    QPointF pos;
Shinya Kitaoka 120a6e
    if (inputFx) {
Shinya Kitaoka 120a6e
      if (inputFx->getAttributes()->getDagNodePos() != TConst::nowhere) {
Shinya Kitaoka 120a6e
        TPointD dagPos =
Shinya Kitaoka 120a6e
            inputFx->getAttributes()->getDagNodePos() + TPointD(150, 0);
Shinya Kitaoka 120a6e
        pos = QPointF(dagPos.x, dagPos.y);
Shinya Kitaoka 120a6e
        nodeRect.moveTopLeft(pos);
Shinya Kitaoka 120a6e
        while (!isAnEmptyZone(nodeRect)) nodeRect.translate(0, -step);
Shinya Kitaoka 120a6e
        pos = nodeRect.topLeft();
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        m_nodesToPlace[inputFx].append(node);
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      pos = sceneRect().center();
Shinya Kitaoka 120a6e
      nodeRect.moveTopLeft(pos);
Shinya Kitaoka 120a6e
      while (!isAnEmptyZone(nodeRect)) nodeRect.translate(0, -step);
Shinya Kitaoka 120a6e
      pos = nodeRect.topLeft();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    node->getFx()->getAttributes()->setDagNodePos(TPointD(pos.x(), pos.y()));
Shinya Kitaoka 120a6e
    node->setPos(QPointF(pos));
Shinya Kitaoka 120a6e
    if (m_nodesToPlace.contains(node->getFx())) {
Shinya Kitaoka 120a6e
      QList<fxschematicnode *=""> nodes = m_nodesToPlace[node->getFx()];</fxschematicnode>
Shinya Kitaoka 120a6e
      int i;
Shinya Kitaoka 120a6e
      for (i = 0; i < nodes.size(); i++) placeNode(nodes[i]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else if (node->isA(eZeraryFx) || node->isA(eColumnFx) ||
Shinya Kitaoka 120a6e
             node->isA(eGroupedFx)) {
Shinya Kitaoka 120a6e
    // I'm placing a column
Shinya Kitaoka 120a6e
    nodeRect.translate(m_firstPoint);
Shinya Kitaoka 120a6e
    nodeRect.translate(10, 10);
Shinya Kitaoka 120a6e
    while (!isAnEmptyZone(nodeRect)) nodeRect.translate(0, -step);
Shinya Kitaoka 120a6e
    QPointF newPos = nodeRect.topLeft();
Shinya Kitaoka 120a6e
    node->getFx()->getAttributes()->setDagNodePos(
Shinya Kitaoka 120a6e
        TPointD(newPos.x(), newPos.y()));
Shinya Kitaoka 120a6e
    node->setPos(QPointF(newPos));
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::updateLink() {
Shinya Kitaoka 120a6e
  TXsheet *xsh = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Iterate the fxs table
Shinya Kitaoka 120a6e
  QMap<tfx *="" *,="" fxschematicnode="">::iterator it;</tfx>
Shinya Kitaoka 120a6e
  for (it = m_table.begin(); it != m_table.end(); ++it) {
Shinya Kitaoka 120a6e
    FxSchematicNode *node = it.value();
Shinya Kitaoka 120a6e
    if (!node) continue;  // Should be asserted? Is it legal?
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TFx *fx           = it.key();
Shinya Kitaoka 120a6e
    TFx *inputPortsFx = fx;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (TZeraryColumnFx *fx2 = dynamic_cast<tzerarycolumnfx *="">(fx)) {</tzerarycolumnfx>
Shinya Kitaoka 120a6e
      inputPortsFx = fx2->getZeraryFx();
Shinya Kitaoka 120a6e
      if (!inputPortsFx)
Shinya Kitaoka 120a6e
        return;  // Should really never happen. Should be asserted...
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int i = 0; i != inputPortsFx->getInputPortCount(); ++i) {
Shinya Kitaoka 120a6e
      TFxPort *port = inputPortsFx->getInputPort(i);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (TFx *linkedFx = port->getFx()) {
Shinya Kitaoka 120a6e
        if (!linkedFx->getAttributes()->isGrouped() ||
Shinya Kitaoka 120a6e
            linkedFx->getAttributes()->isGroupEditing()) {
Shinya Kitaoka 120a6e
          // Not in a group / open group case
Shinya Kitaoka 120a6e
          assert(m_table.contains(linkedFx));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          if (m_table.contains(linkedFx)) {
Shinya Kitaoka 120a6e
            FxSchematicNode *linkedNode = m_table[linkedFx];
Shinya Kitaoka 120a6e
            SchematicPort *p0           = linkedNode->getOutputPort();
Shinya Kitaoka 120a6e
            SchematicPort *p1           = node->getInputPort(i);
Shinya Kitaoka 120a6e
            if (p0 && p1) p0->makeLink(p1);
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          assert(
Shinya Kitaoka 120a6e
              m_groupedTable.contains(linkedFx->getAttributes()->getGroupId()));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
          if (m_groupedTable.contains(
Shinya Kitaoka 120a6e
                  linkedFx->getAttributes()->getGroupId())) {
Shinya Kitaoka 120a6e
            FxSchematicNode *linkedNode =
Shinya Kitaoka 120a6e
                m_groupedTable[linkedFx->getAttributes()->getGroupId()];
Shinya Kitaoka 120a6e
            SchematicPort *p0 = linkedNode->getOutputPort();
Shinya Kitaoka 120a6e
            SchematicPort *p1 = node->getInputPort(i);
Shinya Kitaoka 120a6e
            if (p0 && p1) p0->makeLink(p1);
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (xsh->getFxDag()->getTerminalFxs()->containsFx(fx)) {
Shinya Kitaoka 120a6e
      SchematicPort *p0 = node->getOutputPort();
Shinya Kitaoka 120a6e
      SchematicPort *p1 =
Shinya Kitaoka 120a6e
          m_table[xsh->getFxDag()->getXsheetFx()]->getInputPort(0);
Shinya Kitaoka 120a6e
      p0->makeLink(p1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  QMap<int, *="" fxgroupnode="">::iterator it2;</int,>
Shinya Kitaoka 120a6e
  for (it2 = m_groupedTable.begin(); it2 != m_groupedTable.end(); it2++) {
Shinya Kitaoka 120a6e
    FxGroupNode *node = it2.value();
Shinya Kitaoka 120a6e
    if (!node) continue;
Shinya Kitaoka 120a6e
    int i, fxCount = node->getFxCount();
Shinya Kitaoka 120a6e
    bool xsheetConnected = false;
Shinya Kitaoka 120a6e
    for (i = 0; i < fxCount; i++) {
Shinya Kitaoka 120a6e
      TFx *fx = node->getFx(i);
Shinya Kitaoka 120a6e
      if (xsh->getFxDag()->getTerminalFxs()->containsFx(fx) &&
Shinya Kitaoka 120a6e
          !xsheetConnected) {
Shinya Kitaoka 120a6e
        SchematicPort *p0 = node->getOutputPort();
Shinya Kitaoka 120a6e
        SchematicPort *p1 =
Shinya Kitaoka 120a6e
            m_table[xsh->getFxDag()->getXsheetFx()]->getInputPort(0);
Shinya Kitaoka 120a6e
        p0->makeLink(p1);
Shinya Kitaoka 120a6e
        xsheetConnected = true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
      if (zfx) fx          = zfx->getZeraryFx();
Shinya Kitaoka 120a6e
      if (fx) {
Shinya Kitaoka 120a6e
        int j;
Shinya Kitaoka 120a6e
        for (j = 0; j < fx->getInputPortCount(); j++) {
Shinya Kitaoka 120a6e
          TFx *linkedFx = fx->getInputPort(j)->getFx();
Shinya Kitaoka 120a6e
          if (!linkedFx) continue;
Shinya Kitaoka 120a6e
          if (!linkedFx->getAttributes()->isGrouped() ||
Shinya Kitaoka 120a6e
              linkedFx->getAttributes()->isGroupEditing()) {
Shinya Kitaoka 120a6e
            assert(m_table.contains(linkedFx));
Shinya Kitaoka 120a6e
            if (m_table.contains(linkedFx)) {
Shinya Kitaoka 120a6e
              FxSchematicNode *linkedNode = m_table[linkedFx];
Shinya Kitaoka 120a6e
              SchematicPort *p0           = linkedNode->getOutputPort();
Shinya Kitaoka 120a6e
              SchematicPort *p1           = node->getInputPort(0);
Shinya Kitaoka 120a6e
              if (p0 && p1) p0->makeLink(p1);
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          } else {
Shinya Kitaoka 120a6e
            int linkedGroupId = linkedFx->getAttributes()->getGroupId();
Shinya Kitaoka 120a6e
            assert(m_groupedTable.contains(linkedGroupId));
Shinya Kitaoka 120a6e
            if (m_groupedTable.contains(linkedGroupId)) {
Shinya Kitaoka 120a6e
              FxGroupNode *linkedNode = m_groupedTable[linkedGroupId];
Shinya Kitaoka 120a6e
              if (linkedNode == node) continue;
Shinya Kitaoka 120a6e
              SchematicPort *p0 = linkedNode->getOutputPort();
Shinya Kitaoka 120a6e
              SchematicPort *p1 = node->getInputPort(0);
Shinya Kitaoka 120a6e
              if (p0 && p1 && !p0->isLinkedTo(p1)) p0->makeLink(p1);
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // to solve an edit macro problem: create a dummy link
Shinya Kitaoka 120a6e
  QMap<tmacrofx *="" *,="" fxschematicmacroeditor="">::iterator it3;</tmacrofx>
Shinya Kitaoka 120a6e
  for (it3 = m_macroEditorTable.begin(); it3 != m_macroEditorTable.end();
Shinya Kitaoka 120a6e
       it3++) {
Shinya Kitaoka 120a6e
    TMacroFx *macro = it3.key();
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    FxSchematicNode *root = m_table[macro->getRoot()];
Shinya Kitaoka 120a6e
    SchematicPort *p0     = root->getOutputPort();
Shinya Kitaoka 120a6e
    for (i = 0; i < macro->getOutputConnectionCount(); i++) {
Shinya Kitaoka 120a6e
      TFxPort *outConnection = macro->getOutputConnection(i);
Shinya Kitaoka 120a6e
      TFx *outFx             = outConnection->getOwnerFx();
Shinya Kitaoka 120a6e
      TMacroFx *outMacroFx   = dynamic_cast<tmacrofx *="">(outFx);</tmacrofx>
Shinya Kitaoka 120a6e
      if (outMacroFx && outMacroFx->isEditing()) {
Shinya Kitaoka 120a6e
        std::vector<tfxp> fxs = outMacroFx->getFxs();</tfxp>
Shinya Kitaoka 120a6e
        int k;
Shinya Kitaoka 120a6e
        for (k = 0; k < (int)fxs.size(); k++) {
Shinya Kitaoka 120a6e
          TFx *fx = fxs[k].getPointer();
Shinya Kitaoka 120a6e
          int j;
Shinya Kitaoka 120a6e
          for (j = 0; j < fx->getInputPortCount(); j++)
Shinya Kitaoka 120a6e
            if (outConnection == fx->getInputPort(j)) {
Shinya Kitaoka 120a6e
              outFx = fx;
Shinya Kitaoka 120a6e
              break;
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          if (outFx != outMacroFx) break;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      int j;
Shinya Kitaoka 120a6e
      for (j = 0; j < outFx->getInputPortCount(); j++)
Shinya Kitaoka 120a6e
        if (outFx->getInputPort(j)->getFx() == macro) {
Shinya Kitaoka 120a6e
          SchematicPort *p1 = m_table[outFx]->getInputPort(j);
Shinya Kitaoka 120a6e
          p0->makeLink(p1);
Shinya Kitaoka 120a6e
          break;
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (xsh->getFxDag()->getTerminalFxs()->containsFx(macro)) {
Shinya Kitaoka 120a6e
      assert(root);
Shinya Kitaoka 120a6e
      if (!root) continue;
Shinya Kitaoka 120a6e
      SchematicPort *p1 =
Shinya Kitaoka 120a6e
          m_table[xsh->getFxDag()->getXsheetFx()]->getInputPort(0);
Shinya Kitaoka 120a6e
      p0->makeLink(p1);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateDuplcatedNodesLink();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) {
Shinya Kitaoka 120a6e
  QPointF scenePos                = cme->scenePos();
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> itemList = items(scenePos);</qgraphicsitem>
Shinya Kitaoka 120a6e
  if (!itemList.isEmpty()) {
Shinya Kitaoka 120a6e
    SchematicScene::contextMenuEvent(cme);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QMenu menu(views()[0]);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (cme->modifiers() & Qt::ControlModifier) {
Shinya Kitaoka 120a6e
    menu.addAction(m_addFxContextMenu.getAgainCommand(AddFxContextMenu::Add));
Shinya Kitaoka 120a6e
    if (!menu.actions().isEmpty()) {
Shinya Kitaoka 120a6e
      menu.exec(cme->screenPos());
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QAction *addOutputFx =
Shinya Kitaoka 120a6e
      CommandManager::instance()->getAction("MI_NewOutputFx");
shun_iwasawa 4a5f42
  QAction *copy  = CommandManager::instance()->getAction("MI_Copy");
shun_iwasawa 4a5f42
  QAction *cut   = CommandManager::instance()->getAction("MI_Cut");
shun_iwasawa 4a5f42
  QAction *paste = CommandManager::instance()->getAction("MI_Paste");
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_addFxContextMenu.setCurrentCursorScenePos(cme->scenePos());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  menu.addMenu(m_addFxContextMenu.getAddMenu());
Shinya Kitaoka 120a6e
  if (addOutputFx) menu.addAction(addOutputFx);
manongjohn d6e3cc
manongjohn d6e3cc
  // Close sub xsheet and move to parent sheet
manongjohn d6e3cc
  ToonzScene *scene      = getXsheet()->getScene();
manongjohn d6e3cc
  ChildStack *childStack = scene->getChildStack();
manongjohn d6e3cc
  if (childStack && childStack->getAncestorCount() > 0) {
manongjohn d6e3cc
    menu.addSeparator();
manongjohn d6e3cc
    menu.addAction(CommandManager::instance()->getAction("MI_CloseChild"));
manongjohn d6e3cc
  }
manongjohn d6e3cc
Shinya Kitaoka 120a6e
  menu.addSeparator();
Shinya Kitaoka 120a6e
  menu.addAction(copy);
Shinya Kitaoka 120a6e
  menu.addAction(cut);
Shinya Kitaoka 120a6e
  menu.addAction(paste);
Shinya Kitaoka 120a6e
  m_selection->setPastePosition(TPointD(scenePos.x(), scenePos.y()));
Shinya Kitaoka 120a6e
  menu.exec(cme->screenPos());
Shinya Kitaoka 120a6e
  m_selection->setPastePosition(TConst::nowhere);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
QPointF FxSchematicScene::nearestPoint(const QPointF &point) {
Shinya Kitaoka 120a6e
  QRectF rect(0, 0, 0.1, 0.1);
Shinya Kitaoka 120a6e
  rect.moveCenter(point);
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> itemList = items(rect);</qgraphicsitem>
Shinya Kitaoka 120a6e
  while (itemList.isEmpty()) {
Shinya Kitaoka 120a6e
    rect.adjust(-0.1, -0.1, 0.1, 0.1);
Shinya Kitaoka 120a6e
    itemList = items(rect);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
  FIXME: QTransform() のデフォルトは Qt4.8 の itemAt() と比べて equivant
Shinya Kitaoka 120a6e
  だろうか?
Shinya Kitaoka 120a6e
*/
Shinya Kitaoka 120a6e
  QGraphicsItem *item = itemAt(rect.bottomLeft(), QTransform());
Shinya Kitaoka 120a6e
  if (item) return rect.bottomLeft();
Shinya Kitaoka 120a6e
  item = itemAt(rect.bottomRight(), QTransform());
Shinya Kitaoka 120a6e
  if (item) return rect.bottomRight();
Shinya Kitaoka 120a6e
  item = itemAt(rect.topLeft(), QTransform());
Shinya Kitaoka 120a6e
  if (item) return rect.topLeft();
Shinya Kitaoka 120a6e
  item = itemAt(rect.topRight(), QTransform());
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  QGraphicsItem *item = itemAt(rect.bottomLeft());
Shinya Kitaoka 120a6e
  if (item) return rect.bottomLeft();
Shinya Kitaoka 120a6e
  item = itemAt(rect.bottomRight());
Shinya Kitaoka 120a6e
  if (item) return rect.bottomRight();
Shinya Kitaoka 120a6e
  item = itemAt(rect.topLeft());
Shinya Kitaoka 120a6e
  if (item) return rect.topLeft();
manongjohn d6e3cc
  item = itemAt(rect.topRight());
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  if (item) return rect.topRight();
Shinya Kitaoka 120a6e
  return QPointF();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
FxSchematicNode *FxSchematicScene::getFxNodeFromPosition(const QPointF &pos) {
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> pickedItems = items(pos);</qgraphicsitem>
Shinya Kitaoka 120a6e
  for (int i = 0; i < pickedItems.size(); i++) {
Shinya Kitaoka 120a6e
    FxSchematicNode *fxNode =
Shinya Kitaoka 120a6e
        dynamic_cast<fxschematicnode *="">(pickedItems.at(i));</fxschematicnode>
Shinya Kitaoka 120a6e
    if (fxNode) return fxNode;
Shinya Kitaoka 120a6e
    FxSchematicPort *fxPort =
Shinya Kitaoka 120a6e
        dynamic_cast<fxschematicport *="">(pickedItems.at(i));</fxschematicport>
Shinya Kitaoka 120a6e
    if (fxPort) return fxPort->getDock()->getNode();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return 0;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::updateDuplcatedNodesLink() {
Shinya Kitaoka 120a6e
  QMap<tfx *="" *,="" fxschematicnode="">::iterator it;</tfx>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // fx2node contains only duplicated nodes
Shinya Kitaoka 120a6e
  // and zerary duplicated node s
Shinya Kitaoka 120a6e
  QMap<tfx *="" *,="" fxschematicnode=""> fx2node;</tfx>
Shinya Kitaoka 120a6e
  for (it = m_table.begin(); it != m_table.end(); ++it) {
Shinya Kitaoka 120a6e
    TFx *fx               = it.key();
Shinya Kitaoka 120a6e
    FxSchematicNode *node = it.value();
Shinya Kitaoka 120a6e
    if (TZeraryColumnFx *zcfx = dynamic_cast<tzerarycolumnfx *="">(fx)) {</tzerarycolumnfx>
Shinya Kitaoka 120a6e
      fx = zcfx->getZeraryFx();
Shinya Kitaoka 120a6e
      if (!fx) return;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    assert(fx2node.count(fx) == 0);
Shinya Kitaoka 120a6e
    if (fx->getLinkedFx() == fx) continue;
Shinya Kitaoka 120a6e
    fx2node[fx] = node;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // trovo i link
Shinya Kitaoka 120a6e
  std::set<tfx *=""> visited;</tfx>
Shinya Kitaoka 120a6e
  for (it = fx2node.begin(); it != fx2node.end(); ++it) {
Shinya Kitaoka 120a6e
    TFx *fx               = it.key();
Shinya Kitaoka 120a6e
    FxSchematicNode *node = it.value();
Shinya Kitaoka 120a6e
    assert(fx->getLinkedFx() != fx);
Shinya Kitaoka 120a6e
    if (visited.count(fx) > 0) continue;
Shinya Kitaoka 120a6e
    visited.insert(fx);
Shinya Kitaoka 120a6e
    FxSchematicNode *lastNode = node;
Shinya Kitaoka 120a6e
    assert(lastNode);
Shinya Kitaoka 120a6e
    FxSchematicPort *lastPort = lastNode->getLinkPort();
Shinya Kitaoka 120a6e
    assert(lastPort);
Shinya Kitaoka 120a6e
    for (fx = fx->getLinkedFx(); fx != it.key(); fx = fx->getLinkedFx()) {
Shinya Kitaoka 120a6e
      assert(visited.count(fx) == 0);
Shinya Kitaoka 120a6e
      if (visited.count(fx) > 0) break;
Shinya Kitaoka 120a6e
      visited.insert(fx);
Shinya Kitaoka 120a6e
      QMap<tfx *="" *,="" fxschematicnode="">::iterator h;</tfx>
Shinya Kitaoka 120a6e
      h = fx2node.find(fx);
Shinya Kitaoka 120a6e
      if (h == fx2node.end()) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      assert(h != fx2node.end());
Shinya Kitaoka 120a6e
      FxSchematicNode *node = h.value();
Shinya Kitaoka 120a6e
      assert(node);
Shinya Kitaoka 120a6e
      FxSchematicPort *port = node->getLinkPort();
Shinya Kitaoka 120a6e
      assert(port);
Shinya Kitaoka 120a6e
      if (port && lastPort) port->makeLink(lastPort);
Shinya Kitaoka 120a6e
      lastNode = node;
Shinya Kitaoka 120a6e
      lastPort = port;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
QGraphicsItem *FxSchematicScene::getCurrentNode() {
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> allItems = items();</qgraphicsitem>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (auto const item : allItems) {
Shinya Kitaoka 120a6e
    FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(item);</fxschematicnode>
Shinya Kitaoka 120a6e
    if (node && node->getFx() == m_fxHandle->getFx()) return node;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return 0;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::onSelectionSwitched(TSelection *oldSel,
Shinya Kitaoka 120a6e
                                           TSelection *newSel) {
Shinya Kitaoka 120a6e
  if (m_selection == oldSel && m_selection != newSel) clearSelection();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::onSelectionChanged() {
Shinya Kitaoka 120a6e
  m_selection->selectNone();
Shinya Kitaoka 120a6e
  int i, size = m_highlightedLinks.size();
Shinya Kitaoka 120a6e
  for (i = 0; i < size; i++) {
Shinya Kitaoka 120a6e
    SchematicLink *link = m_highlightedLinks[i];
Shinya Kitaoka 120a6e
    link->setHighlighted(false);
Shinya Kitaoka 120a6e
    link->update();
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_highlightedLinks.clear();
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> slcItems = selectedItems();</qgraphicsitem>
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *="">::iterator it;</qgraphicsitem>
Shinya Kitaoka 120a6e
  for (it = slcItems.begin(); it != slcItems.end(); it++) {
Shinya Kitaoka 120a6e
    FxSchematicNode *node = dynamic_cast<fxschematicnode *="">(*it);</fxschematicnode>
Shinya Kitaoka 120a6e
    if (node) {
Shinya Kitaoka 120a6e
      if (!node->isA(eGroupedFx)) {
Shinya Kitaoka 120a6e
        if (node->isA(eXSheetFx)) continue;
Shinya Kitaoka 120a6e
        m_selection->select(node->getFx());
Shinya Kitaoka 120a6e
        if (node->isA(eColumnFx)) {
Shinya Kitaoka 120a6e
          FxSchematicColumnNode *columnNode =
Shinya Kitaoka 120a6e
              dynamic_cast<fxschematiccolumnnode *="">(node);</fxschematiccolumnnode>
Shinya Kitaoka 120a6e
          if (columnNode)
Shinya Kitaoka 120a6e
            m_selection->select(columnNode->getColumnIndex());
Shinya Kitaoka 120a6e
          else {
Shinya Kitaoka 120a6e
            FxSchematicPaletteNode *paletteNode =
Shinya Kitaoka 120a6e
                dynamic_cast<fxschematicpalettenode *="">(node);</fxschematicpalettenode>
Shinya Kitaoka 120a6e
            if (paletteNode) m_selection->select(paletteNode->getColumnIndex());
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        FxGroupNode *groupNode = dynamic_cast<fxgroupnode *="">(node);</fxgroupnode>
Shinya Kitaoka 120a6e
        assert(groupNode);
Shinya Kitaoka 120a6e
        QList<tfxp> fxs = groupNode->getGroupedFxs();</tfxp>
Shinya Kitaoka 120a6e
        for (i = 0; i < fxs.size(); i++) {
Shinya Kitaoka 120a6e
          m_selection->select(fxs[i].getPointer());
Shinya Kitaoka 120a6e
          TLevelColumnFx *colFx =
Shinya Kitaoka 120a6e
              dynamic_cast<tlevelcolumnfx *="">(fxs[i].getPointer());</tlevelcolumnfx>
Shinya Kitaoka 120a6e
          if (colFx) {
Shinya Kitaoka 120a6e
            if (TXshLevelColumn *column = colFx->getColumn()) {
Shinya Kitaoka 120a6e
              int colIndex = column->getIndex();
Shinya Kitaoka 120a6e
              m_selection->select(colIndex);
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
      highlightLinks(node, true);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    SchematicLink *link = dynamic_cast<schematiclink *="">(*it);</schematiclink>
Shinya Kitaoka 120a6e
    if (link) m_selection->select(link);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_selection->makeCurrent();
Shinya Kitaoka 120a6e
  TSelectionHandle *selHandle = TSelectionHandle::getCurrent();
Shinya Kitaoka 120a6e
  selHandle->notifySelectionChanged();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::reorderScene() {
Shinya Kitaoka 120a6e
  int step = m_gridDimension == eLarge ? 100 : 50;
Shinya Kitaoka 120a6e
  m_placedFxs.clear();
Shinya Kitaoka 120a6e
  QPointF sceneCenter = sceneRect().center();
Shinya Kitaoka 120a6e
  double minY         = sceneCenter.y();
Shinya Kitaoka 120a6e
  double maxX         = sceneCenter.x();
Shinya Kitaoka 120a6e
  double y            = minY;
Shinya Kitaoka 120a6e
  double x            = maxX;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TXsheet *xsh = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
  int i        = 0;
manongjohn f37f4a
manongjohn f37f4a
  FxDag *fxDag  = xsh->getFxDag();
manongjohn f37f4a
  TFxSet *fxSet = fxDag->getInternalFxs();
manongjohn f37f4a
manongjohn f37f4a
  //  Let's reset every position to nowhere first
manongjohn f37f4a
  fxDag->getXsheetFx()->getAttributes()->setDagNodePos(TConst::nowhere);
manongjohn f37f4a
manongjohn f37f4a
  for (i = 0; i < fxDag->getOutputFxCount(); i++) {
manongjohn f37f4a
    TOutputFx *fx = fxDag->getOutputFx(i);
manongjohn f37f4a
    if (!fx) continue;
manongjohn f37f4a
    fx->getAttributes()->setDagNodePos(TConst::nowhere);
manongjohn f37f4a
  }
manongjohn f37f4a
manongjohn f37f4a
  for (i = 0; i < xsh->getColumnCount(); i++) {
manongjohn f37f4a
    TXshColumn *column = xsh->getColumn(i);
manongjohn f37f4a
    TFx *fx            = column->getFx();
manongjohn f37f4a
    if (!fx) continue;
manongjohn f37f4a
    fx->getAttributes()->setDagNodePos(TConst::nowhere);
manongjohn f37f4a
  }
manongjohn f37f4a
manongjohn f37f4a
  for (i = 0; i < fxSet->getFxCount(); i++) {
manongjohn f37f4a
    TFx *fx = fxSet->getFx(i);
manongjohn f37f4a
    fx->getAttributes()->setDagNodePos(TConst::nowhere);
manongjohn f37f4a
    TMacroFx *macro = dynamic_cast<tmacrofx *="">(fx);</tmacrofx>
manongjohn f37f4a
    if (macro && macro->isEditing()) {
manongjohn f37f4a
      std::vector<tfxp> fxs = macro->getFxs();</tfxp>
manongjohn f37f4a
      int j;
manongjohn f37f4a
      for (j = 0; j < (int)fxs.size(); j++) {
manongjohn f37f4a
        fxs[j]->getAttributes()->setDagNodePos(TConst::nowhere);
manongjohn f37f4a
      }
manongjohn f37f4a
    }
manongjohn f37f4a
  }
manongjohn f37f4a
manongjohn f37f4a
  // Let's start placing them now
Shinya Kitaoka 120a6e
  for (i = 0; i < xsh->getColumnCount(); i++) {
Shinya Kitaoka 120a6e
    TXshColumn *column = xsh->getColumn(i);
Shinya Kitaoka 120a6e
    TFx *fx            = column->getFx();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (column->isEmpty() || !fx) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
    if (zfx && (zfx->getZeraryFx()->getInputPortCount() > 0)) {
Shinya Kitaoka 120a6e
      TFxPort *port = zfx->getZeraryFx()->getInputPort(0);
Shinya Kitaoka 120a6e
      if (port && port->getFx()) continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (zfx && m_placedFxs.contains(zfx->getZeraryFx())) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    x = sceneCenter.x();
Shinya Kitaoka 120a6e
    placeNodeAndParents(fx, x, maxX, minY);
Shinya Kitaoka 120a6e
    y -= step;
Shinya Kitaoka 120a6e
    minY = std::min(y, minY);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // remove retrolink
Shinya Kitaoka 120a6e
  for (i = 0; i < xsh->getColumnCount(); i++) {
Shinya Kitaoka 120a6e
    TXshColumn *column = xsh->getColumn(i);
Shinya Kitaoka 120a6e
    TFx *fx            = column->getFx();
Shinya Kitaoka 120a6e
    if (column->isEmpty() || !fx) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
    if (zfx && m_placedFxs.contains(zfx->getZeraryFx())) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (zfx && (zfx->getZeraryFx()->getInputPortCount() > 0)) {
Shinya Kitaoka 120a6e
      TFxPort *port = zfx->getZeraryFx()->getInputPort(0);
Shinya Kitaoka 120a6e
      if (port && port->getFx()) continue;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    for (int j = 0; j < fx->getOutputConnectionCount(); j++) {
Shinya Kitaoka 120a6e
      TFx *outFx = fx->getOutputConnection(j)->getOwnerFx();
Shinya Kitaoka 120a6e
      removeRetroLinks(outFx, maxX);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double middleY = (sceneCenter.y() + minY + step) * 0.5;
Shinya Kitaoka 120a6e
  placeNodeAndParents(xsh->getFxDag()->getXsheetFx(), maxX, maxX, middleY);
manongjohn f37f4a
  y -= step;
manongjohn f37f4a
  minY = std::min(y, minY);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (i = 0; i < fxSet->getFxCount(); i++) {
Shinya Kitaoka 120a6e
    TFx *fx = fxSet->getFx(i);
Shinya Kitaoka 120a6e
    if (m_placedFxs.contains(fx)) continue;
Shinya Kitaoka 120a6e
manongjohn f37f4a
    placeNodeAndParents(fx, (sceneCenter.x() + 120), maxX, minY);
manongjohn f37f4a
    y -= step;
manongjohn f37f4a
    minY = std::min(y, minY);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateScene();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::removeRetroLinks(TFx *fx, double &maxX) {
Shinya Kitaoka 120a6e
  if (!fx) return;
Shinya Kitaoka 120a6e
  for (int i = 0; i < fx->getInputPortCount(); i++) {
Shinya Kitaoka 120a6e
    TFx *inFx = fx->getInputPort(i)->getFx();
Shinya Kitaoka 120a6e
    if (!inFx) continue;
Shinya Kitaoka 120a6e
    TPointD inFxPos = inFx->getAttributes()->getDagNodePos();
Shinya Kitaoka 120a6e
    TPointD fxPos   = fx->getAttributes()->getDagNodePos();
manongjohn f37f4a
    if (inFxPos != TConst::nowhere && fxPos != TConst::nowhere &&
manongjohn f37f4a
        fxPos.x <= inFxPos.x) {
Shinya Kitaoka 120a6e
      while (fxPos.x <= inFxPos.x) fxPos.x += 150;
Shinya Kitaoka 120a6e
      maxX = std::max(fxPos.x + 150, maxX);
Shinya Kitaoka 120a6e
      fx->getAttributes()->setDagNodePos(fxPos);
Shinya Kitaoka 120a6e
      for (int j = 0; j < fx->getOutputConnectionCount(); j++) {
Shinya Kitaoka 120a6e
        TFx *outFx = fx->getOutputConnection(j)->getOwnerFx();
Shinya Kitaoka 120a6e
        removeRetroLinks(outFx, maxX);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::placeNodeAndParents(TFx *fx, double x, double &maxX,
Shinya Kitaoka 120a6e
                                           double &minY) {
Shinya Kitaoka 120a6e
  int step = m_gridDimension == eLarge ? 100 : 50;
Shinya Kitaoka 120a6e
  if (!fx) return;
Shinya Kitaoka 120a6e
  m_placedFxs.append(fx);
Shinya Kitaoka 120a6e
  if (fx->getFxType() == "STD_particlesFx" ||
Shinya Kitaoka 120a6e
      fx->getFxType() == "STD_Iwa_ParticlesFx") {
Shinya Kitaoka 120a6e
    TXsheet *xsh = m_xshHandle->getXsheet();
Shinya Kitaoka 120a6e
    int i        = 0;
Shinya Kitaoka 120a6e
    for (i = 0; i < xsh->getColumnCount(); i++) {
Shinya Kitaoka 120a6e
      TFx *columnFx        = xsh->getColumn(i)->getFx();
Shinya Kitaoka 120a6e
      TZeraryColumnFx *zfx = dynamic_cast<tzerarycolumnfx *="">(columnFx);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
      if (zfx && zfx->getZeraryFx() == fx) {
Shinya Kitaoka 120a6e
        fx = zfx;
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
manongjohn f37f4a
  double y        = minY;
manongjohn f37f4a
  TMacroFx *macro = dynamic_cast<tmacrofx *="">(fx);</tmacrofx>
manongjohn f37f4a
  if (macro) {
manongjohn f37f4a
    int tmpY              = y;
manongjohn f37f4a
    std::vector<tfxp> fxs = macro->getFxs();</tfxp>
manongjohn f37f4a
    for (int j = 0; j < (int)fxs.size(); j++) {
manongjohn f37f4a
      TFx *macroFx = fxs[j].getPointer();
manongjohn f37f4a
      if (macroFx && !m_placedFxs.contains(macroFx)) {
manongjohn f37f4a
        placeNodeAndParents(macroFx, x, maxX, minY);
manongjohn f37f4a
        y -= step;
manongjohn f37f4a
        minY = std::min(y, minY);
manongjohn f37f4a
      }
manongjohn f37f4a
    }
manongjohn f37f4a
    tmpY = (minY + tmpY + step) * 0.5;
manongjohn f37f4a
    fx->getAttributes()->setDagNodePos(TPointD(x, tmpY));
manongjohn f37f4a
  } else
manongjohn f37f4a
    fx->getAttributes()->setDagNodePos(TPointD(x, y));
Shinya Kitaoka 120a6e
  if (fx->getOutputConnectionCount() == 0) minY -= step;
Shinya Kitaoka 120a6e
  x += 120;
Shinya Kitaoka 120a6e
  maxX = std::max(maxX, x);
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < fx->getOutputConnectionCount(); i++) {
Shinya Kitaoka 120a6e
    TFx *outputFx = fx->getOutputConnection(i)->getOwnerFx();
Shinya Kitaoka 120a6e
    // controllo se e' una porta sorgente
Shinya Kitaoka 120a6e
    TFxPort *port = outputFx->getInputPort(0);
Shinya Kitaoka 120a6e
    if (port && port->getFx() != fx) continue;
Shinya Kitaoka 120a6e
    if (!m_placedFxs.contains(outputFx) ||
Shinya Kitaoka 120a6e
        outputFx->getAttributes()->getDagNodePos().x < x) {
Shinya Kitaoka 120a6e
      placeNodeAndParents(outputFx, x, maxX, minY);
Shinya Kitaoka 120a6e
      y -= step;
Shinya Kitaoka 120a6e
      minY = std::min(y, minY);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onDisconnectFromXSheet() {
Shinya Kitaoka 120a6e
  std::list<tfxp, std::allocator<tfxp="">> list =</tfxp,>
Shinya Kitaoka 120a6e
      m_selection->getFxs().toStdList();
Shinya Kitaoka 120a6e
  TFxCommand::disconnectNodesFromXsheet(list, m_xshHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onConnectToXSheet() {
Shinya Kitaoka 120a6e
  std::list<tfxp, std::allocator<tfxp="">> list =</tfxp,>
Shinya Kitaoka 120a6e
      m_selection->getFxs().toStdList();
Shinya Kitaoka 120a6e
  TFxCommand::connectNodesToXsheet(list, m_xshHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onDeleteFx() {
Shinya Kitaoka 120a6e
  std::list<tfxp, std::allocator<tfxp="">> fxList =</tfxp,>
Shinya Kitaoka 120a6e
      m_selection->getFxs().toStdList();
Shinya Kitaoka 120a6e
  std::list<tfxcommand::link> linkList = m_selection->getLinks().toStdList();</tfxcommand::link>
Shinya Kitaoka 120a6e
  std::list<int> columnIndexList = m_selection->getColumnIndexes().toStdList();</int>
Shinya Kitaoka 120a6e
  TFxCommand::deleteSelection(fxList, linkList, columnIndexList, m_xshHandle,
Shinya Kitaoka 120a6e
                              m_fxHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onDuplicateFx() {
Shinya Kitaoka 120a6e
  QList<tfxp> fxs = m_selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
  if (fxs.empty()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int i, size = fxs.size();
Shinya Kitaoka 120a6e
  for (i = 0; i != size; ++i)
Shinya Kitaoka 120a6e
    TFxCommand::duplicateFx(fxs[i].getPointer(), m_xshHandle, m_fxHandle);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onUnlinkFx() {
Shinya Kitaoka 120a6e
  QList<tfxp> fxs = m_selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
  if (fxs.empty()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int i, size = fxs.size();
Shinya Kitaoka 120a6e
  for (i = 0; i != size; ++i)
Shinya Kitaoka 120a6e
    TFxCommand::unlinkFx(fxs[i].getPointer(), m_fxHandle, m_xshHandle);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onMacroFx() {
Shinya Kitaoka 120a6e
  TFxCommand::makeMacroFx(m_selection->getFxs().toVector().toStdVector(),
Shinya Kitaoka 120a6e
                          m_app);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onExplodeMacroFx() {
Shinya Kitaoka 120a6e
  if (TMacroFx *macroFx = dynamic_cast<tmacrofx *="">(m_fxHandle->getFx()))</tmacrofx>
Shinya Kitaoka 120a6e
    TFxCommand::explodeMacroFx(macroFx, m_app);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onOpenMacroFx() {
Shinya Kitaoka 120a6e
  if (TMacroFx *macroFx = dynamic_cast<tmacrofx *="">(m_fxHandle->getFx())) {</tmacrofx>
Shinya Kitaoka 120a6e
    macroFx->editMacro(true);
Shinya Kitaoka 120a6e
    updateScene();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onSavePresetFx() {
Shinya Kitaoka 120a6e
  CommandManager::instance()->getAction("MI_SavePreset")->trigger();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onRemoveOutput() {
Shinya Kitaoka 120a6e
  TFxCommand::removeOutputFx(m_fxHandle->getFx(), m_xshHandle, m_fxHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onActivateOutput() {
Shinya Kitaoka 120a6e
  TFxCommand::makeOutputFxCurrent(m_fxHandle->getFx(), m_xshHandle);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onPreview() { emit showPreview(m_fxHandle->getFx()); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onCacheFx() { setEnableCache(true); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onUncacheFx() { setEnableCache(false); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::setEnableCache(bool toggle) {
Shinya Kitaoka 120a6e
  QList<tfxp> selectedFxs = m_selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < selectedFxs.size(); i++) {
Shinya Kitaoka 120a6e
    TFx *fx               = selectedFxs[i].getPointer();
Shinya Kitaoka 120a6e
    TZeraryColumnFx *zcfx = dynamic_cast<tzerarycolumnfx *="">(fx);</tzerarycolumnfx>
Shinya Kitaoka 120a6e
    if (zcfx) fx          = zcfx->getZeraryFx();
Shinya Kitaoka 120a6e
    TFxAttributes *attr   = fx->getAttributes();
Shinya Kitaoka 120a6e
    if (!attr->isGrouped() || attr->isGroupEditing())
Shinya Kitaoka 120a6e
      if (toggle)
Shinya Kitaoka 120a6e
        TPassiveCacheManager::instance()->enableCache(fx);
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        TPassiveCacheManager::instance()->disableCache(fx);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      QMap<int, *="" fxgroupnode="">::iterator it;</int,>
Shinya Kitaoka 120a6e
      for (it = m_groupedTable.begin(); it != m_groupedTable.end(); it++) {
Shinya Kitaoka 120a6e
        FxGroupNode *group = it.value();
Shinya Kitaoka 120a6e
        QList<tfxp> roots  = group->getRootFxs();</tfxp>
Shinya Kitaoka 120a6e
        int j;
Shinya Kitaoka 120a6e
        for (j = 0; j < roots.size(); j++)
Shinya Kitaoka 120a6e
          if (fx == roots[j].getPointer())
Shinya Kitaoka 120a6e
            if (toggle)
Shinya Kitaoka 120a6e
              TPassiveCacheManager::instance()->enableCache(fx);
Shinya Kitaoka 120a6e
            else
Shinya Kitaoka 120a6e
              TPassiveCacheManager::instance()->disableCache(fx);
Shinya Kitaoka 120a6e
        group->update();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onCollapse(const QList<tfxp> &fxs) {</tfxp>
Shinya Kitaoka 120a6e
  emit doCollapse(fxs);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TXsheet *FxSchematicScene::getXsheet() { return m_xshHandle->getXsheet(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onXsheetChanged() { m_xshHandle->notifyXsheetChanged(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onSceneChanged() {
Shinya Kitaoka 120a6e
  m_app->getCurrentScene()->notifySceneChanged();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onSwitchCurrentFx(TFx *fx) {
Shinya Kitaoka 120a6e
  if (m_fxHandle->getFx() == fx) return;
Shinya Kitaoka 120a6e
  if (fx) {
Shinya Kitaoka 120a6e
    // Forbid update of the swatch upon column switch. This could generate
Shinya Kitaoka 120a6e
    // a further useless render...
Shinya Kitaoka 120a6e
    SwatchViewer::suspendRendering(true, false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    int columnIndex = fx->getReferenceColumnIndex();
Shinya Kitaoka 120a6e
    if (columnIndex >= 0) {
Shinya Kitaoka 120a6e
      m_columnHandle->setColumnIndex(columnIndex);
Shinya Kitaoka 120a6e
      m_app->getCurrentObject()->setObjectId(
Shinya Kitaoka 120a6e
          TStageObjectId::ColumnId(columnIndex));
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    SwatchViewer::suspendRendering(false);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_fxHandle->setFx(fx, false);  // Setting the fx updates the swatch
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    emit editObject();
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_fxHandle->setFx(0, false);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onFxNodeDoubleClicked() {
Shinya Kitaoka 120a6e
  // emitting fxSettingsShouldBeSwitched
Shinya Kitaoka 120a6e
  m_fxHandle->onFxNodeDoubleClicked();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onCurrentFxSwitched() {
Shinya Kitaoka 120a6e
  if (m_currentFxNode) m_currentFxNode->setIsCurrentFxLinked(false, 0);
Shinya Kitaoka 120a6e
  if (m_table.contains(m_fxHandle->getFx())) {
Shinya Kitaoka 120a6e
    m_currentFxNode = m_table[m_fxHandle->getFx()];
Shinya Kitaoka 120a6e
    m_currentFxNode->setIsCurrentFxLinked(true, 0);
Shinya Kitaoka 120a6e
  } else
Shinya Kitaoka 120a6e
    m_currentFxNode = 0;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onCurrentColumnChanged(int index) {
Shinya Kitaoka 120a6e
  m_app->getCurrentColumn()->setColumnIndex(index);
Shinya Kitaoka 120a6e
  m_app->getCurrentObject()->setObjectId(TStageObjectId::ColumnId(index));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
manongjohn d6e3cc
void FxSchematicScene::onIconifyNodesToggled(bool iconified) {
manongjohn d6e3cc
  m_isNormalIconView      = !iconified;
manongjohn d6e3cc
  IconifyFxSchematicNodes = (iconified) ? 1 : 0;
manongjohn d6e3cc
  updateScene();
manongjohn d6e3cc
}
manongjohn d6e3cc
manongjohn d6e3cc
//------------------------------------------------------------------
manongjohn d6e3cc
Shinya Kitaoka 120a6e
TFx *FxSchematicScene::getCurrentFx() { return m_fxHandle->getFx(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::mousePressEvent(QGraphicsSceneMouseEvent *me) {
Shinya Kitaoka 120a6e
  QList<qgraphicsitem *=""> items = selectedItems();</qgraphicsitem>
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
  QGraphicsItem *item = itemAt(me->scenePos(), QTransform());
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  QGraphicsItem *item     = itemAt(me->scenePos());
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  FxSchematicPort *port = dynamic_cast<fxschematicport *="">(item);</fxschematicport>
Shinya Kitaoka 120a6e
  FxSchematicLink *link = dynamic_cast<fxschematiclink *="">(item);</fxschematiclink>
Shinya Kitaoka 120a6e
  SchematicScene::mousePressEvent(me);
Shinya Kitaoka 120a6e
  onSelectionChanged();
Shinya Kitaoka 120a6e
  if (me->button() == Qt::MidButton) {
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    for (i = 0; i < items.size(); i++) items[i]->setSelected(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
  m_selection may not be updated here, so I use QGraphicsScene::selectedItems()
Shinya Kitaoka 120a6e
  instead of m_selection->isEmpty() to check whether any node is selected or
Shinya Kitaoka 120a6e
  not.
Shinya Kitaoka 120a6e
  */
Shinya Kitaoka 120a6e
  if (selectedItems().isEmpty()) {
Shinya Kitaoka 120a6e
    if (me->button() != Qt::MidButton && !item) m_fxHandle->setFx(0, false);
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  m_isConnected = false;
Shinya Kitaoka 120a6e
  if (!canDisconnectSelection(m_selection)) return;
Shinya Kitaoka 120a6e
  m_selectionOldPos.clear();
Shinya Kitaoka 120a6e
  QList<tfxp> selectedFxs = m_selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < selectedFxs.size(); i++) {
Shinya Kitaoka 120a6e
    TFxP selectedFx = selectedFxs[i];
Shinya Kitaoka 120a6e
    TPointD pos     = selectedFx->getAttributes()->getDagNodePos();
Shinya Kitaoka 120a6e
    m_selectionOldPos.append(QPair<tfxp, tpointd="">(selectedFx, pos));</tfxp,>
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  FxsData fxsData;
Shinya Kitaoka 120a6e
  fxsData.setFxs(m_selection->getFxs(), m_selection->getLinks(),
Shinya Kitaoka 120a6e
                 m_selection->getColumnIndexes(), m_xshHandle->getXsheet());
shun-iwasawa 8e8baa
  // m_isConnected indicates that the all selected nodes are connected
Shinya Kitaoka 120a6e
  if (fxsData.isConnected() && me->button() == Qt::LeftButton && !port && !link)
Shinya Kitaoka 120a6e
    m_isConnected = true;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::mouseMoveEvent(QGraphicsSceneMouseEvent *me) {
Shinya Kitaoka 120a6e
  SchematicScene::mouseMoveEvent(me);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_lastPos = me->scenePos();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool leftButton = (QApplication::mouseButtons() == Qt::LeftButton);
Shinya Kitaoka 120a6e
  bool altButton  = (QApplication::keyboardModifiers() == Qt::AltModifier);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (leftButton && m_isConnected && altButton) {
Shinya Kitaoka 120a6e
    m_linkUnlinkSimulation = true;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    simulateDisconnectSelection(true);
Shinya Kitaoka 120a6e
    m_connectionLinks.showBridgeLinks();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
    SchematicLink *link =
Shinya Kitaoka 120a6e
        dynamic_cast<schematiclink *="">(itemAt(m_lastPos, QTransform()));</schematiclink>
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    SchematicLink *link   = dynamic_cast<schematiclink *="">(itemAt(m_lastPos));</schematiclink>
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    if (link && (link->getEndPort() && link->getStartPort())) {
Shinya Kitaoka 120a6e
      TFxCommand::Link fxLink = m_selection->getBoundingFxs(link);
Shinya Kitaoka 120a6e
      if (fxLink == TFxCommand::Link()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TFx *inputFx  = fxLink.m_inputFx.getPointer();
Shinya Kitaoka 120a6e
      TFx *outputFx = fxLink.m_outputFx.getPointer();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      TFxSet *internalFxs = getXsheet()->getFxDag()->getInternalFxs();
Shinya Kitaoka 120a6e
      if (!internalFxs->containsFx(inputFx) &&
Shinya Kitaoka 120a6e
          !dynamic_cast<tcolumnfx *="">(inputFx) &&</tcolumnfx>
Shinya Kitaoka 120a6e
          !dynamic_cast<txsheetfx *="">(inputFx) &&</txsheetfx>
Shinya Kitaoka 120a6e
          !dynamic_cast<toutputfx *="">(inputFx))</toutputfx>
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      if (!internalFxs->containsFx(outputFx) &&
Shinya Kitaoka 120a6e
          !dynamic_cast<tcolumnfx *="">(outputFx) &&</tcolumnfx>
Shinya Kitaoka 120a6e
          !dynamic_cast<txsheetfx *="">(outputFx) &&</txsheetfx>
Shinya Kitaoka 120a6e
          !dynamic_cast<toutputfx *="">(outputFx))</toutputfx>
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
    }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
    m_connectionLinks.hideBridgeLinks();
Shinya Kitaoka 120a6e
    simulateInsertSelection(link, altButton && !!link);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *me) {
Shinya Kitaoka 120a6e
  SchematicScene::mouseReleaseEvent(me);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_linkUnlinkSimulation = false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if ((m_disconnectionLinks.size() == 0) && (m_connectionLinks.size() == 0))
Shinya Kitaoka 120a6e
    return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUndoManager::manager()->beginBlock();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  bool altButton = QApplication::keyboardModifiers() == Qt::AltModifier;
Shinya Kitaoka 120a6e
  if (altButton && m_isConnected) {
Shinya Kitaoka 120a6e
    if (m_connectionLinks.size() > 0) {
Shinya Kitaoka 120a6e
      const QList<schematiclink *=""> &bridgeLinks =</schematiclink>
Shinya Kitaoka 120a6e
          m_connectionLinks.getBridgeLinks();
Shinya Kitaoka 120a6e
      assert(bridgeLinks.size() <= 1);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      SchematicLink *link = bridgeLinks[0];
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      if (link) {
Shinya Kitaoka 120a6e
        FxSchematicNode *outputNode =
Shinya Kitaoka 120a6e
            dynamic_cast<fxschematicnode *="">(link->getEndPort()->getNode());</fxschematicnode>
Shinya Kitaoka 120a6e
        FxSchematicNode *inputNode =
Shinya Kitaoka 120a6e
            dynamic_cast<fxschematicnode *="">(link->getStartPort()->getNode());</fxschematicnode>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
        if (inputNode && outputNode) {
Shinya Kitaoka 120a6e
          SchematicPort *port = link->getStartPort();
Shinya Kitaoka 120a6e
          if (port->getType() == 200 || port->getType() == 204)
Shinya Kitaoka 120a6e
            port = link->getOtherPort(port);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
          int i;
Shinya Kitaoka 120a6e
          for (i = 0; i < outputNode->getInputPortCount(); i++)
Shinya Kitaoka 120a6e
            if (port == outputNode->getInputPort(i)) break;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
          TFxCommand::Link fxLink;
Shinya Kitaoka 120a6e
          fxLink.m_outputFx                               = outputNode->getFx();
Shinya Kitaoka 120a6e
          fxLink.m_inputFx                                = inputNode->getFx();
Shinya Kitaoka 120a6e
          if (!outputNode->isA(eXSheetFx)) fxLink.m_index = i;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
          TFxCommand::connectFxs(fxLink, m_selection->getFxs().toStdList(),
Shinya Kitaoka 120a6e
                                 m_xshHandle, m_selectionOldPos);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else if (m_disconnectionLinks.size() > 0) {
Shinya Kitaoka 120a6e
      QList<tfxp> fxs = m_selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
      TFxCommand::disconnectFxs(fxs.toStdList(), m_xshHandle,
Shinya Kitaoka 120a6e
                                m_selectionOldPos);
Shinya Kitaoka 120a6e
      m_selectionOldPos.clear();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUndoManager::manager()->endBlock();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_isConnected = false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool FxSchematicScene::event(QEvent *e) {
Shinya Kitaoka 120a6e
  bool ret        = SchematicScene::event(e);
Shinya Kitaoka 120a6e
  bool altPressed = QApplication::keyboardModifiers() == Qt::AltModifier;
shun-iwasawa 8e8baa
  if (m_altPressed != altPressed) {
shun-iwasawa 8e8baa
    // When Alt key is pressed, put the link lines on top of other items
shun-iwasawa 8e8baa
    // in order to enable to pick them up with itemAt() function.
shun-iwasawa 8e8baa
    double z                          = (altPressed) ? 5.0 : 0.0;
shun-iwasawa 8e8baa
    QList<qgraphicsitem *=""> sceneItems = items();</qgraphicsitem>
shun-iwasawa 8e8baa
    for (int i = 0; i < sceneItems.size(); i++) {
shun-iwasawa 8e8baa
      SchematicLink *link = dynamic_cast<schematiclink *="">(sceneItems.at(i));</schematiclink>
shun-iwasawa 8e8baa
      if (link) link->setZValue(z);
shun-iwasawa 8e8baa
    }
shun-iwasawa 8e8baa
shun-iwasawa 8e8baa
    if (m_linkUnlinkSimulation) onAltModifierChanged(altPressed);
shun-iwasawa 8e8baa
    m_altPressed = altPressed;
shun-iwasawa 8e8baa
  }
Shinya Kitaoka 120a6e
  return ret;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onInsertPaste() {
Shinya Kitaoka 120a6e
  if (!m_selection->insertPasteSelection())
Shinya Kitaoka 120a6e
    DVGui::error(
Shinya Kitaoka 120a6e
        tr("Cannot Paste Insert a selection of unconnected FX nodes.\nSelect "
Shinya Kitaoka 120a6e
           "FX nodes and related links before copying or cutting the selection "
Shinya Kitaoka 120a6e
           "you want to paste."));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onAddPaste() {
Shinya Kitaoka 120a6e
  if (!m_selection->addPasteSelection())
Shinya Kitaoka 120a6e
    DVGui::error(
Shinya Kitaoka 120a6e
        tr("Cannot Paste Add a selection of unconnected FX nodes.\nSelect FX "
Shinya Kitaoka 120a6e
           "nodes and related links before copying or cutting the selection "
Shinya Kitaoka 120a6e
           "you want to paste."));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onReplacePaste() {
Shinya Kitaoka 120a6e
  if (!m_selection->replacePasteSelection())
Shinya Kitaoka 120a6e
    DVGui::error(
Shinya Kitaoka 120a6e
        tr("Cannot Paste Replace a selection of unconnected FX nodes.\nSelect "
Shinya Kitaoka 120a6e
           "FX nodes and related links before copying or cutting the selection "
Shinya Kitaoka 120a6e
           "you want to paste."));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FxSchematicScene::onAltModifierChanged(bool altPressed) {
Shinya Kitaoka 120a6e
  if (altPressed) {
Shinya Kitaoka 120a6e
    if (m_disconnectionLinks.size() == 0 && m_linkUnlinkSimulation)
Shinya Kitaoka 120a6e
      simulateDisconnectSelection(altPressed);
Shinya Kitaoka 120a6e
    if (m_connectionLinks.size() == 0 && m_linkUnlinkSimulation) {
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
      SchematicLink *link =
Shinya Kitaoka 120a6e
          dynamic_cast<schematiclink *="">(itemAt(m_lastPos, QTransform()));</schematiclink>
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
      SchematicLink *link = dynamic_cast<schematiclink *="">(itemAt(m_lastPos));</schematiclink>
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
      if (link && (!link->getEndPort() || !link->getStartPort())) return;
Shinya Kitaoka 120a6e
      simulateInsertSelection(link, altPressed && !!link);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (m_disconnectionLinks.size() > 0 && m_linkUnlinkSimulation)
Shinya Kitaoka 120a6e
      simulateDisconnectSelection(altPressed);
Shinya Kitaoka 120a6e
    if (m_connectionLinks.size() > 0 && m_linkUnlinkSimulation) {
Shinya Kitaoka 120a6e
      m_connectionLinks.showBridgeLinks();
shun-iwasawa 8e8baa
      simulateInsertSelection(0, false);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::onEditGroup() {
Shinya Kitaoka 120a6e
  if (m_selection->isEmpty()) return;
Shinya Kitaoka 120a6e
  QList<tfxp> fxs = m_selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < fxs.size(); i++) {
Shinya Kitaoka 120a6e
    if (fxs[i]->getAttributes()->isGrouped() &&
Shinya Kitaoka 120a6e
        !fxs[i]->getAttributes()->isGroupEditing()) {
Shinya Kitaoka 120a6e
      fxs[i]->getAttributes()->editGroup();
Shinya Kitaoka 120a6e
      TMacroFx *macro = dynamic_cast<tmacrofx *="">(fxs[i].getPointer());</tmacrofx>
Shinya Kitaoka 120a6e
      if (macro) {
Shinya Kitaoka 120a6e
        std::vector<tfxp> macroFxs = macro->getFxs();</tfxp>
Shinya Kitaoka 120a6e
        int j;
Shinya Kitaoka 120a6e
        for (j = 0; j < (int)macroFxs.size(); j++)
Shinya Kitaoka 120a6e
          macroFxs[j]->getAttributes()->editGroup();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateScene();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::highlightLinks(FxSchematicNode *node, bool value) {
Shinya Kitaoka 120a6e
  int i, portCount = node->getInputPortCount();
Shinya Kitaoka 120a6e
  // SchematicLink* ghostLink = m_supportLinks.getDisconnectionLink(eGhost);
Shinya Kitaoka 120a6e
  for (i = 0; i < portCount; i++) {
Shinya Kitaoka 120a6e
    FxSchematicPort *port = node->getInputPort(i);
Shinya Kitaoka 120a6e
    int j, linkCount = port->getLinkCount();
Shinya Kitaoka 120a6e
    for (j = 0; j < linkCount; j++) {
Shinya Kitaoka 120a6e
      SchematicLink *link = port->getLink(j);
Shinya Kitaoka 120a6e
      if (!link) continue;
Shinya Kitaoka 120a6e
      if (m_disconnectionLinks.isABridgeLink(link)) continue;
Shinya Kitaoka 120a6e
      link->setHighlighted(value);
Shinya Kitaoka 120a6e
      link->update();
Shinya Kitaoka 120a6e
      m_highlightedLinks.push_back(link);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FxSchematicPort *port = node->getOutputPort();
Shinya Kitaoka 120a6e
  if (port) {
Shinya Kitaoka 120a6e
    int linkCount = port->getLinkCount();
Shinya Kitaoka 120a6e
    for (i = 0; i < linkCount; i++) {
Shinya Kitaoka 120a6e
      SchematicLink *link = port->getLink(i);
Shinya Kitaoka 120a6e
      if (!link) continue;
Shinya Kitaoka 120a6e
      if (m_disconnectionLinks.isABridgeLink(link)) continue;
Shinya Kitaoka 120a6e
      link->setHighlighted(value);
Shinya Kitaoka 120a6e
      link->update();
Shinya Kitaoka 120a6e
      m_highlightedLinks.push_back(link);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  port = node->getLinkPort();
Shinya Kitaoka 120a6e
  if (port) {
Shinya Kitaoka 120a6e
    SchematicLink *link = port->getLink(0);
Shinya Kitaoka 120a6e
    if (link && !m_disconnectionLinks.isABridgeLink(link)) {
Shinya Kitaoka 120a6e
      link->setHighlighted(value);
Shinya Kitaoka 120a6e
      link->update();
Shinya Kitaoka 120a6e
      m_highlightedLinks.push_back(link);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::simulateDisconnectSelection(bool disconnect) {
shun-iwasawa 8e8baa
  if (disconnect) {
shun-iwasawa 8e8baa
    if (m_selection->isEmpty()) return;
shun-iwasawa 8e8baa
    QList<tfxp> selectedFxs = m_selection->getFxs();</tfxp>
shun-iwasawa 8e8baa
    if (selectedFxs.isEmpty()) return;
shun-iwasawa 8e8baa
    QMap<tfx *,="" bool=""> visitedFxs;</tfx>
shun-iwasawa 8e8baa
    int i;
shun-iwasawa 8e8baa
    for (i                                    = 0; i < selectedFxs.size(); i++)
shun-iwasawa 8e8baa
      visitedFxs[selectedFxs[i].getPointer()] = false;
shun-iwasawa 8e8baa
shun-iwasawa 8e8baa
    TFx *inputFx = 0, *outputFx = 0;
shun-iwasawa 8e8baa
    findBoundariesFxs(inputFx, outputFx, visitedFxs);
shun-iwasawa 8e8baa
    FxSchematicNode *inputNode  = m_table[inputFx];
shun-iwasawa 8e8baa
    FxSchematicNode *outputNode = m_table[outputFx];
shun-iwasawa 8e8baa
    assert(inputNode && outputNode);
shun-iwasawa 8e8baa
shun-iwasawa 8e8baa
    FxSchematicPort *inputPort = 0, *outputPort = 0;
shun-iwasawa 8e8baa
    SchematicPort *otherInputPort = 0;
shun-iwasawa 8e8baa
    QList<schematicport *=""> otherOutputPorts;</schematicport>
shun-iwasawa 8e8baa
    if (inputNode->getInputPortCount() > 0) {
shun-iwasawa 8e8baa
      inputPort = inputNode->getInputPort(0);
shun-iwasawa 8e8baa
      if (inputPort) {
shun-iwasawa 8e8baa
        SchematicLink *inputLink = inputPort->getLink(0);
shun-iwasawa 8e8baa
        if (inputLink && !m_connectionLinks.isAnInputLink(inputLink)) {
shun-iwasawa 8e8baa
          if (!m_disconnectionLinks.isAnInputLink(inputLink))
shun-iwasawa 8e8baa
            m_disconnectionLinks.addInputLink(inputLink);
shun-iwasawa 8e8baa
          otherInputPort = inputLink->getOtherPort(inputPort);
shun-iwasawa 8e8baa
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
shun-iwasawa 8e8baa
    outputPort = outputNode->getOutputPort();
shun-iwasawa 8e8baa
    if (outputPort) {
shun-iwasawa 8e8baa
      for (i = 0; i < outputPort->getLinkCount(); i++) {
shun-iwasawa 8e8baa
        SchematicLink *outputLink = outputPort->getLink(i);
shun-iwasawa 8e8baa
        if (outputLink && !m_connectionLinks.isAnOutputLink(outputLink)) {
shun-iwasawa 8e8baa
          if (!m_disconnectionLinks.isAnOutputLink(outputLink))
shun-iwasawa 8e8baa
            m_disconnectionLinks.addOutputLink(outputLink);
shun-iwasawa 8e8baa
          otherOutputPorts.push_back(outputLink->getOtherPort(outputPort));
shun-iwasawa 8e8baa
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    m_disconnectionLinks.hideInputLinks();
Shinya Kitaoka 120a6e
    m_disconnectionLinks.hideOutputLinks();
shun-iwasawa 8e8baa
shun-iwasawa 8e8baa
    if (otherInputPort) {
shun-iwasawa 8e8baa
      for (i = 0; i < otherOutputPorts.size(); i++)
shun-iwasawa 8e8baa
        m_disconnectionLinks.addBridgeLink(
shun-iwasawa 8e8baa
            otherOutputPorts[i]->makeLink(otherInputPort));
shun-iwasawa 8e8baa
    }
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_disconnectionLinks.showInputLinks();
Shinya Kitaoka 120a6e
    m_disconnectionLinks.showOutputLinks();
Shinya Kitaoka 120a6e
    m_disconnectionLinks.removeInputLinks();
Shinya Kitaoka 120a6e
    m_disconnectionLinks.removeOutputLinks();
shun-iwasawa 8e8baa
    m_disconnectionLinks.removeBridgeLinks(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::simulateInsertSelection(SchematicLink *link,
Shinya Kitaoka 120a6e
                                               bool connect) {
shun-iwasawa 8e8baa
  if (!link || !connect) {
Shinya Kitaoka 120a6e
    m_connectionLinks.showBridgeLinks();
Shinya Kitaoka 120a6e
    m_connectionLinks.hideInputLinks();
Shinya Kitaoka 120a6e
    m_connectionLinks.hideOutputLinks();
Shinya Kitaoka 120a6e
    m_connectionLinks.removeBridgeLinks();
Shinya Kitaoka 120a6e
    m_connectionLinks.removeInputLinks(true);
Shinya Kitaoka 120a6e
    m_connectionLinks.removeOutputLinks(true);
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    if (m_disconnectionLinks.isABridgeLink(link) || m_selection->isEmpty())
Shinya Kitaoka 120a6e
      return;
Shinya Kitaoka 120a6e
shun-iwasawa 8e8baa
    m_connectionLinks.addBridgeLink(link);
shun-iwasawa 8e8baa
    m_connectionLinks.hideBridgeLinks();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    SchematicPort *inputPort = 0, *outputPort = 0;
Shinya Kitaoka 120a6e
    if (link) {
Shinya Kitaoka 120a6e
      if (link->getStartPort()->getType() == eFxInputPort) {
Shinya Kitaoka 120a6e
        inputPort  = link->getStartPort();
Shinya Kitaoka 120a6e
        outputPort = link->getEndPort();
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        inputPort  = link->getEndPort();
Shinya Kitaoka 120a6e
        outputPort = link->getStartPort();
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QMap<tfx *,="" bool=""> visitedFxs;</tfx>
Shinya Kitaoka 120a6e
    QList<tfxp> selectedFxs = m_selection->getFxs();</tfxp>
Shinya Kitaoka 120a6e
    if (selectedFxs.isEmpty()) return;
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    for (i                                    = 0; i < selectedFxs.size(); i++)
Shinya Kitaoka 120a6e
      visitedFxs[selectedFxs[i].getPointer()] = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    TFx *inputFx = 0, *outputFx = 0;
Shinya Kitaoka 120a6e
    findBoundariesFxs(inputFx, outputFx, visitedFxs);
Shinya Kitaoka 120a6e
    FxSchematicNode *inputNode  = m_table[inputFx];
Shinya Kitaoka 120a6e
    FxSchematicNode *outputNode = m_table[outputFx];
Shinya Kitaoka 120a6e
    assert(inputNode && outputNode);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (inputNode->getInputPortCount() > 0) {
Shinya Kitaoka 120a6e
      SchematicPort *inputNodePort = inputNode->getInputPort(0);
Shinya Kitaoka 120a6e
      if (inputNodePort && outputPort)
Shinya Kitaoka 120a6e
        m_connectionLinks.addInputLink(inputNodePort->makeLink(outputPort));
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    SchematicPort *outputNodePort = outputNode->getOutputPort();
Shinya Kitaoka 120a6e
    if (outputNodePort && inputPort)
Shinya Kitaoka 120a6e
      m_connectionLinks.addOutputLink(inputPort->makeLink(outputNodePort));
Shinya Kitaoka 120a6e
shun-iwasawa 8e8baa
    m_connectionLinks.showInputLinks();
shun-iwasawa 8e8baa
    m_connectionLinks.showOutputLinks();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------
Toshihiro Shimizu 890ddd
/*! in order to select nods after pasting the copied fx nodes from FxSelection
Toshihiro Shimizu 890ddd
*/
Shinya Kitaoka 120a6e
void FxSchematicScene::selectNodes(QList<tfxp> &fxs) {</tfxp>
Shinya Kitaoka 120a6e
  clearSelection();
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)fxs.size(); i++) {
Shinya Kitaoka 120a6e
    TFx *tempFx = fxs[i].getPointer();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QMap<tfx *="" *,="" fxschematicnode="">::iterator it;</tfx>
Shinya Kitaoka 120a6e
    it = m_table.find(tempFx);
Shinya Kitaoka 120a6e
    if (it == m_table.end()) continue;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    it.value()->setSelected(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  update();
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::updateNestedGroupEditors(FxSchematicNode *node,
Shinya Kitaoka 120a6e
                                                const QPointF &newPos) {
Shinya Kitaoka 120a6e
  if (!node) return;
Shinya Kitaoka 120a6e
  QStack<int> groupIdStack = node->getFx()->getAttributes()->getGroupIdStack();</int>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  QRectF rect;
Shinya Kitaoka 120a6e
  for (i = 0; i < groupIdStack.size(); i++) {
Shinya Kitaoka 120a6e
    if (m_groupEditorTable.contains(groupIdStack[i])) {
Shinya Kitaoka 120a6e
      QRectF app = m_groupEditorTable[groupIdStack[i]]->sceneBoundingRect();
Shinya Kitaoka 120a6e
      if (rect.isEmpty())
Shinya Kitaoka 120a6e
        rect = app;
Shinya Kitaoka 120a6e
      else
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
        rect = rect.united(app);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
        rect              = rect.unite(app);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  QMap<tmacrofx *="" *,="" fxschematicmacroeditor="">::iterator it;</tmacrofx>
Shinya Kitaoka 120a6e
  for (it = m_macroEditorTable.begin(); it != m_macroEditorTable.end(); it++) {
Shinya Kitaoka 120a6e
    if (it.value()->contains(node)) {
Shinya Kitaoka 120a6e
      QRectF app = it.value()->sceneBoundingRect();
Shinya Kitaoka 120a6e
      if (rect.isEmpty())
Shinya Kitaoka 120a6e
        rect = app;
Shinya Kitaoka 120a6e
      else
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
        rect = rect.united(app);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
        rect              = rect.unite(app);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  node->setPos(newPos);
Shinya Kitaoka 120a6e
  for (i = 0; i < groupIdStack.size(); i++) {
Shinya Kitaoka 120a6e
    if (!m_groupEditorTable.contains(groupIdStack[i])) continue;
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
    rect =
Shinya Kitaoka 120a6e
        rect.united(m_groupEditorTable[groupIdStack[i]]->sceneBoundingRect());
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
    rect                  = rect.unite(m_groupEditorTable[groupIdStack[i]]->sceneBoundingRect());
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
    QRectF app = m_groupEditorTable[groupIdStack[i]]->boundingSceneRect();
Shinya Kitaoka 120a6e
    if (m_groupEditorTable[groupIdStack[i]]->scenePos() != app.topLeft())
Shinya Kitaoka 120a6e
      m_groupEditorTable[groupIdStack[i]]->setPos(app.topLeft());
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  for (it = m_macroEditorTable.begin(); it != m_macroEditorTable.end(); it++) {
Shinya Kitaoka 120a6e
    FxSchematicMacroEditor *editor = it.value();
Shinya Kitaoka 120a6e
    if (editor->contains(node)) {
Shinya Kitaoka 120a6e
      QRectF app = editor->sceneBoundingRect();
Toshihiro Shimizu 890ddd
#if QT_VERSION >= 0x050000
Shinya Kitaoka 120a6e
      rect = rect.united(app);
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
      rect                = rect.unite(app);
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
      app = editor->boundingSceneRect();
Shinya Kitaoka 120a6e
      if (editor->scenePos() != app.topLeft()) editor->setPos(app.topLeft());
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  update(rect);
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::closeInnerMacroEditor(int groupId) {
Shinya Kitaoka 120a6e
  assert(m_groupEditorTable.contains(groupId));
Shinya Kitaoka 120a6e
  QMap<tmacrofx *="" *,="" fxschematicmacroeditor="">::iterator it;</tmacrofx>
Shinya Kitaoka 120a6e
  for (it = m_macroEditorTable.begin(); it != m_macroEditorTable.end(); it++) {
Shinya Kitaoka 120a6e
    TMacroFx *macro = it.key();
Shinya Kitaoka 120a6e
    assert(macro);
Shinya Kitaoka 120a6e
    if (macro->getAttributes()->isContainedInGroup(groupId)) {
Shinya Kitaoka 120a6e
      macro->editMacro(false);
Shinya Kitaoka 120a6e
      macro->getAttributes()->closeEditingGroup(groupId);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::resizeNodes(bool maximizedNode) {
manongjohn adae7d
  resizingNodes = true;
manongjohn adae7d
Shinya Kitaoka 120a6e
  // resize nodes
Shinya Kitaoka 120a6e
  m_gridDimension = maximizedNode ? eLarge : eSmall;
Shinya Kitaoka 120a6e
  m_xshHandle->getXsheet()->getFxDag()->setDagGridDimension(m_gridDimension);
Shinya Kitaoka 120a6e
  QMap<tfx *="" *,="" fxschematicnode="">::iterator it1;</tfx>
Shinya Kitaoka 120a6e
  for (it1 = m_table.begin(); it1 != m_table.end(); it1++) {
Shinya Kitaoka 120a6e
    if (!it1.value()) continue;
Shinya Kitaoka 120a6e
    it1.value()->resize(maximizedNode);
Shinya Kitaoka 120a6e
    TFx *fx = it1.value()->getFx();
Shinya Kitaoka 120a6e
    updatePositionOnResize(fx, maximizedNode);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  QMap<int, *="" fxgroupnode="">::iterator it2;</int,>
Shinya Kitaoka 120a6e
  for (it2 = m_groupedTable.begin(); it2 != m_groupedTable.end(); it2++) {
Shinya Kitaoka 120a6e
    if (!it2.value()) continue;
Shinya Kitaoka 120a6e
    it2.value()->resize(maximizedNode);
Shinya Kitaoka 120a6e
    QList<tfxp> groupedFxs = it2.value()->getGroupedFxs();</tfxp>
Shinya Kitaoka 120a6e
    for (int i = 0; i < groupedFxs.size(); i++)
Shinya Kitaoka 120a6e
      updatePositionOnResize(groupedFxs[i].getPointer(), maximizedNode);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QMap<tmacrofx *="" *,="" fxschematicmacroeditor="">::iterator it3;</tmacrofx>
Shinya Kitaoka 120a6e
  for (it3 = m_macroEditorTable.begin(); it3 != m_macroEditorTable.end();
Shinya Kitaoka 120a6e
       it3++) {
Shinya Kitaoka 120a6e
    if (!it3.value()) continue;
Shinya Kitaoka 120a6e
    it3.value()->resizeNodes(maximizedNode);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  updateScene();
manongjohn adae7d
manongjohn adae7d
  resizingNodes = false;
Shinya Kitaoka 120a6e
}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
//------------------------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
void FxSchematicScene::updatePositionOnResize(TFx *fx, bool maximizedNode) {
Shinya Kitaoka 120a6e
  TPointD oldPos = fx->getAttributes()->getDagNodePos();
manongjohn f37f4a
  if (oldPos == TConst::nowhere) return;
Shinya Kitaoka 120a6e
  double oldPosY = oldPos.y - 25000;
Shinya Kitaoka 120a6e
  double newPosY = maximizedNode ? oldPosY * 2 : oldPosY * 0.5;
Shinya Kitaoka 120a6e
  fx->getAttributes()->setDagNodePos(TPointD(oldPos.x, newPosY + 25000));
Toshihiro Shimizu 890ddd
}
manongjohn adae7d
manongjohn adae7d
//------------------------------------------------------------------
manongjohn adae7d
manongjohn adae7d
void FxSchematicScene::onNodeChangedSize() {
manongjohn adae7d
  if (resizingNodes) return;
manongjohn adae7d
  updateScene();
manongjohn adae7d
}