Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef FXSCHEMATIC_H
Toshihiro Shimizu 890ddd
#define FXSCHEMATIC_H
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/addfxcontextmenu.h"
Toshihiro Shimizu 890ddd
#include "schematicviewer.h"
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
#include <qmap></qmap>
Toshihiro Shimizu 890ddd
#include <tfx.h></tfx.h>
Toshihiro Shimizu 890ddd
#include <set></set>
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
// forward declaration
Toshihiro Shimizu 890ddd
class FxSchematicNode;
Toshihiro Shimizu 890ddd
class TFxHandle;
Toshihiro Shimizu 890ddd
class FxSelection;
Toshihiro Shimizu 890ddd
class FxSchematicNode;
Toshihiro Shimizu 890ddd
class TXsheet;
Toshihiro Shimizu 890ddd
class TSceneHandle;
Toshihiro Shimizu 890ddd
class QMenu;
Toshihiro Shimizu 890ddd
class SchematicLink;
Toshihiro Shimizu 890ddd
class FxGroupNode;
Toshihiro Shimizu 890ddd
class FxSchematicGroupEditor;
Toshihiro Shimizu 890ddd
class FxSchematicMacroEditor;
Toshihiro Shimizu 890ddd
class TMacroFx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
// FXSchematic
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//==================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class FxSchematicScene final : public SchematicScene {
Shinya Kitaoka 120a6e
  Q_OBJECT
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  class SupportLinks {
Shinya Kitaoka 120a6e
    QList<schematiclink *=""> m_bridges;</schematiclink>
Shinya Kitaoka 120a6e
    QList<schematiclink *=""> m_inputs;</schematiclink>
Shinya Kitaoka 120a6e
    QList<schematiclink *=""> m_outputs;</schematiclink>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  public:
Shinya Kitaoka 120a6e
    SupportLinks() {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void addBridgeLink(SchematicLink *link);
Shinya Kitaoka 120a6e
    void addInputLink(SchematicLink *link);
Shinya Kitaoka 120a6e
    void addOutputLink(SchematicLink *link);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    QList<schematiclink *=""> getBridgeLinks() { return m_bridges; }</schematiclink>
Shinya Kitaoka 120a6e
    QList<schematiclink *=""> getInputLinks() { return m_inputs; }</schematiclink>
Shinya Kitaoka 120a6e
    QList<schematiclink *=""> getOutputLinks() { return m_outputs; }</schematiclink>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void hideBridgeLinks();
Shinya Kitaoka 120a6e
    void hideInputLinks();
Shinya Kitaoka 120a6e
    void hideOutputLinks();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void showBridgeLinks();
Shinya Kitaoka 120a6e
    void showInputLinks();
Shinya Kitaoka 120a6e
    void showOutputLinks();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void removeBridgeLinks(bool deleteLink = false);
Shinya Kitaoka 120a6e
    void removeInputLinks(bool deleteLink = false);
Shinya Kitaoka 120a6e
    void removeOutputLinks(bool deleteLink = false);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    bool isABridgeLink(SchematicLink *link) { return m_bridges.contains(link); }
Shinya Kitaoka 120a6e
    bool isAnInputLink(SchematicLink *link) { return m_inputs.contains(link); }
Shinya Kitaoka 120a6e
    bool isAnOutputLink(SchematicLink *link) {
Shinya Kitaoka 120a6e
      return m_outputs.contains(link);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    void clearAll();
Shinya Kitaoka 120a6e
    int size();
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //----------------------------------------------------
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TApplication *m_app;
Shinya Kitaoka 120a6e
  TXsheetHandle *m_xshHandle;
Shinya Kitaoka 120a6e
  TFxHandle *m_fxHandle;
Shinya Kitaoka 120a6e
  TFrameHandle *m_frameHandle;
Shinya Kitaoka 120a6e
  TColumnHandle *m_columnHandle;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPointF m_firstPoint;
Shinya Kitaoka 120a6e
  QMap<tfx *="" *,="" fxschematicnode=""> m_table;</tfx>
Shinya Kitaoka 120a6e
  QMap<int, *="" fxgroupnode=""> m_groupedTable;</int,>
Shinya Kitaoka 120a6e
  QMap<int, *="" fxschematicgroupeditor=""> m_groupEditorTable;</int,>
Shinya Kitaoka 120a6e
  QMap<tmacrofx *="" *,="" fxschematicmacroeditor=""> m_macroEditorTable;</tmacrofx>
Shinya Kitaoka 120a6e
  FxSelection *m_selection;
Shinya Kitaoka 120a6e
  AddFxContextMenu m_addFxContextMenu;
Shinya Kitaoka 120a6e
  SupportLinks m_disconnectionLinks, m_connectionLinks;
Shinya Kitaoka 120a6e
  bool m_isConnected;
Shinya Kitaoka 120a6e
  bool m_linkUnlinkSimulation;
Shinya Kitaoka 120a6e
  bool m_altPressed;
Shinya Kitaoka 120a6e
  QPointF m_lastPos;
Shinya Kitaoka 120a6e
  QList<qpair<tfxp, tpointd="">> m_selectionOldPos;</qpair<tfxp,>
Shinya Kitaoka 120a6e
  QList<tfx *=""> m_placedFxs;</tfx>
Shinya Kitaoka 120a6e
  FxSchematicNode *m_currentFxNode;
Shinya Kitaoka 120a6e
  int m_gridDimension;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool m_isLargeScaled;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QMap<tfx *="" *,="" qlist<fxschematicnode="">> m_nodesToPlace;</tfx>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  FxSchematicScene(QWidget *parent);
Shinya Kitaoka 120a6e
  ~FxSchematicScene();
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void updateScene() override;
Shinya Kitaoka 473e70
  QGraphicsItem *getCurrentNode() override;
Shinya Kitaoka 473e70
  void reorderScene() override;
Shinya Kitaoka 120a6e
  TXsheet *getXsheet();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void setApplication(TApplication *app);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TApplication *getApplication() const { return m_app; }
Shinya Kitaoka 120a6e
  TXsheetHandle *getXsheetHandle() const { return m_xshHandle; }
Shinya Kitaoka 120a6e
  TFxHandle *getFxHandle() const { return m_fxHandle; }
Shinya Kitaoka 120a6e
  TFrameHandle *getFrameHandle() const { return m_frameHandle; }
Shinya Kitaoka 120a6e
  TColumnHandle *getColumnHandle() const { return m_columnHandle; }
Shinya Kitaoka 120a6e
  TFx *getCurrentFx();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QMenu *getInsertFxMenu() { return m_addFxContextMenu.getInsertMenu(); }
Shinya Kitaoka 120a6e
  QMenu *getAddFxMenu() { return m_addFxContextMenu.getAddMenu(); }
Shinya Kitaoka 120a6e
  QMenu *getReplaceFxMenu() { return m_addFxContextMenu.getReplaceMenu(); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QAction *getAgainAction(int commands) {
Shinya Kitaoka 120a6e
    return m_addFxContextMenu.getAgainCommand(commands);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  FxSelection *getFxSelection() const { return m_selection; }
Shinya Kitaoka 120a6e
  //! Disconnects or connects selected item from the rest of the graph.
Shinya Kitaoka 120a6e
  //! Selection must be a connected subgraph. If \b disconnect is true, the
Shinya Kitaoka 120a6e
  //! selection is disconnected; connected otherwise.
Shinya Kitaoka 120a6e
  void simulateDisconnectSelection(bool disconnect);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //! Updates all Group Editors containing fx.
Shinya Kitaoka 120a6e
  //! Each fx is only in one group, but each gruop can contains othe group. All
Shinya Kitaoka 120a6e
  //! nested Groups must be updated.
Shinya Kitaoka 120a6e
  void updateNestedGroupEditors(FxSchematicNode *node, const QPointF &newPos);
Shinya Kitaoka 120a6e
  void closeInnerMacroEditor(int groupId);
Shinya Kitaoka 120a6e
  void resizeNodes(bool maximizedNode);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void initCursorScenePos() {
Shinya Kitaoka 120a6e
    m_addFxContextMenu.setCurrentCursorScenePos(QPointF(0, 0));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void selectNodes(QList<tfxp> &fxs);</tfxp>
Shinya Kitaoka 120a6e
  bool isLargeScaled() { return m_isLargeScaled; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Shinya Kitaoka 473e70
  void contextMenuEvent(QGraphicsSceneContextMenuEvent *cme) override;
Shinya Kitaoka 473e70
  void mousePressEvent(QGraphicsSceneMouseEvent *me) override;
Shinya Kitaoka 473e70
  void mouseMoveEvent(QGraphicsSceneMouseEvent *me) override;
Shinya Kitaoka 473e70
  void mouseReleaseEvent(QGraphicsSceneMouseEvent *me) override;
Shinya Kitaoka 473e70
  bool event(QEvent *e) override;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  FxSchematicNode *addFxSchematicNode(TFx *fx);
Shinya Kitaoka 120a6e
  FxSchematicNode *addGroupedFxSchematicNode(int groupId,
Shinya Kitaoka 120a6e
                                             const QList<tfxp> &groupedFxs);</tfxp>
Shinya Kitaoka 120a6e
  FxSchematicGroupEditor *addEditedGroupedFxSchematicNode(
Shinya Kitaoka 120a6e
      int groupId, const QList<schematicnode *=""> &groupedFxs);</schematicnode>
Shinya Kitaoka 120a6e
  FxSchematicMacroEditor *addEditedMacroFxSchematicNode(
Shinya Kitaoka 120a6e
      TMacroFx *macro, const QList<schematicnode *=""> &groupedFxs);</schematicnode>
Shinya Kitaoka 120a6e
  FxSchematicNode *createFxSchematicNode(TFx *fx);
Shinya Kitaoka 120a6e
  void placeNode(FxSchematicNode *node);
Shinya Kitaoka 120a6e
  void updateLink();
Shinya Kitaoka 120a6e
  void updateDuplcatedNodesLink();
Shinya Kitaoka 120a6e
  void updateEditedGroups(const QMap<int, *="" qlist<schematicnode="">> &editedGroup);</int,>
Shinya Kitaoka 120a6e
  void updateEditedMacros(
Shinya Kitaoka 120a6e
      const QMap<tmacrofx *="" *,="" qlist<schematicnode="">> &editedMacro);</tmacrofx>
Shinya Kitaoka 120a6e
  FxSchematicNode *getFxNodeFromPosition(const QPointF &pos);
Shinya Kitaoka 120a6e
  void placeNodeAndParents(TFx *fx, double x, double &maxX, double &maxY);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  QPointF nearestPoint(const QPointF &point);
Shinya Kitaoka 120a6e
  void highlightLinks(FxSchematicNode *node, bool value);
Shinya Kitaoka 120a6e
  void updatePosition(FxSchematicNode *node, const TPointD &pos);
Shinya Kitaoka 120a6e
  void simulateInsertSelection(SchematicLink *link, bool connect);
Shinya Kitaoka 120a6e
  void updatePositionOnResize(TFx *fx, bool maximizedNode);
Shinya Kitaoka 120a6e
  void removeRetroLinks(TFx *fx, double &maxX);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
signals:
Shinya Kitaoka 120a6e
  void showPreview(TFxP);
Shinya Kitaoka 120a6e
  void cacheFx(TFxP);
Shinya Kitaoka 120a6e
  void doCollapse(const QList<tfxp> &);</tfxp>
Shinya Kitaoka 120a6e
  void doExplodeChild(const QList<tfxp> &);</tfxp>
Shinya Kitaoka 120a6e
  void editObject();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected slots:
Shinya Kitaoka 473e70
  void onSelectionSwitched(TSelection *oldSel, TSelection *newSel) override;
Shinya Kitaoka 120a6e
  void onSelectionChanged();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // void onOutputFxAdded();
Shinya Kitaoka 120a6e
  void onDisconnectFromXSheet();
Shinya Kitaoka 120a6e
  void onConnectToXSheet();
Shinya Kitaoka 120a6e
  void onDeleteFx();
Shinya Kitaoka 120a6e
  void onDuplicateFx();
Shinya Kitaoka 120a6e
  void onUnlinkFx();
Shinya Kitaoka 120a6e
  void onMacroFx();
Shinya Kitaoka 120a6e
  void onExplodeMacroFx();
Shinya Kitaoka 120a6e
  void onOpenMacroFx();
Shinya Kitaoka 120a6e
  void onSavePresetFx();
Shinya Kitaoka 120a6e
  void onRemoveOutput();
Shinya Kitaoka 120a6e
  void onActivateOutput();
Shinya Kitaoka 120a6e
  void onPreview();
Shinya Kitaoka 120a6e
  void onCacheFx();
Shinya Kitaoka 120a6e
  void onUncacheFx();
Shinya Kitaoka 120a6e
  void onCollapse(const QList<tfxp> &);</tfxp>
Shinya Kitaoka 120a6e
  void onOpenSubxsheet();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onXsheetChanged();
Shinya Kitaoka 120a6e
  void onSceneChanged();
Shinya Kitaoka 120a6e
  void onSwitchCurrentFx(TFx *);
Shinya Kitaoka 120a6e
  void onCurrentFxSwitched();
Shinya Kitaoka 120a6e
  void onCurrentColumnChanged(int);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onFxNodeDoubleClicked();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void onInsertPaste();
Shinya Kitaoka 120a6e
  void onAddPaste();
Shinya Kitaoka 120a6e
  void onReplacePaste();
Shinya Kitaoka 120a6e
  void onAltModifierChanged(bool);
Shinya Kitaoka 120a6e
  void onEditGroup();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  void setEnableCache(bool toggle);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  // not implemented
Shinya Kitaoka 120a6e
  FxSchematicScene(const FxSchematicScene &);
Shinya Kitaoka 120a6e
  const FxSchematicScene &operator=(const FxSchematicScene &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // FXSCHEMATIC_H