SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NetworkEditor.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2012 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9  License for the specific language governing rights and limitations under
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 #ifndef INTERFACE_APPLICATION_NETWORKEDITOR_H
30 #define INTERFACE_APPLICATION_NETWORKEDITOR_H
31 
32 #include <boost/shared_ptr.hpp>
33 #include <QGraphicsView>
34 #include <map>
40 
41 class QMenu;
42 class QToolBar;
43 class QAction;
44 class QGraphicsScene;
45 class DialogErrorControl;
46 Q_DECLARE_METATYPE (std::string)
47 
48 namespace SCIRun {
49 
50  namespace Dataflow { namespace Engine { class NetworkEditorController; struct DisableDynamicPortSwitch; }}
51 
52 namespace Gui {
53 
55  {
56  public:
58  virtual QString text() const = 0;
59  virtual bool isModule() const = 0;
60  };
61 
62  //almost just want to pass a boost::function for this one.
64  {
65  public:
67  virtual NotePosition position() const = 0;
68  };
69 
70  class ModuleEventProxy : public QObject
71  {
72  Q_OBJECT
73  public:
75  void trackModule(SCIRun::Dataflow::Networks::ModuleHandle module);
76 Q_SIGNALS:
77  void moduleExecuteStart(const std::string& id);
78  void moduleExecuteEnd(const std::string& id);
79  };
80 
81  class ModuleProxyWidget;
82 
84  {
85  public:
86  explicit ZLevelManager(QGraphicsScene* scene);
87  int max() const { return maxZ_; }
88  void bringToFront();
89  void sendToBack();
90  private:
91  void setZValue(int z);
92  ModuleProxyWidget* selectedModuleProxy() const;
93  QGraphicsScene* scene_;
94  int minZ_;
95  int maxZ_;
96  enum { INITIAL_Z = 1000 };
97  };
98 
99  class ConnectionLine;
100  class ModuleWidget;
101  class NetworkEditorControllerGuiProxy;
102  class DialogErrorControl;
103 
104  class NetworkEditor : public QGraphicsView,
107  public SCIRun::Dataflow::Engine::NetworkIOInterface<SCIRun::Dataflow::Networks::NetworkFileHandle>,
109  {
110  Q_OBJECT
111 
112  public:
113  explicit NetworkEditor(boost::shared_ptr<CurrentModuleSelection> moduleSelectionGetter, boost::shared_ptr<DefaultNotePositionGetter> dnpg,
114  boost::shared_ptr<DialogErrorControl> dialogErrorControl, QWidget* parent = 0);
115  ~NetworkEditor();
116  QList<QAction*> getModuleSpecificActions() const;
117  void setNetworkEditorController(boost::shared_ptr<NetworkEditorControllerGuiProxy> controller);
118  boost::shared_ptr<NetworkEditorControllerGuiProxy> getNetworkEditorController() const;
120 
122  void loadNetwork(const SCIRun::Dataflow::Networks::NetworkFileHandle& file);
123 
124  virtual SCIRun::Dataflow::Networks::ModulePositionsHandle dumpModulePositions() const;
125  virtual void moveModules(const SCIRun::Dataflow::Networks::ModulePositions& modulePositions);
126 
127  size_t numModules() const;
128 
129  boost::shared_ptr<ModuleEventProxy> moduleEventProxy() { return moduleEventProxy_; }
130  virtual int errorCode() const;
131 
132  void disableInputWidgets();
133  void enableInputWidgets();
134 
135  //TODO: this class is getting too big and messy, schedule refactoring
136  void setRegressionTestDataDir(const QString& dir);
137 
138  void setBackground(const QBrush& brush);
139  QBrush background() const;
140 
141  int connectionPipelineType() const;
142 
143  QPixmap sceneGrab();
144 
145  boost::shared_ptr<Dataflow::Engine::DisableDynamicPortSwitch> createDynamicPortDisabler();
146 
147  protected:
148  virtual void dropEvent(QDropEvent* event) override;
149  virtual void dragEnterEvent(QDragEnterEvent* event) override;
150  virtual void dragMoveEvent(QDragMoveEvent* event) override;
151  virtual void mouseMoveEvent(QMouseEvent *event) override;
152  virtual void mouseReleaseEvent(QMouseEvent *event) override;
153 
154  public Q_SLOTS:
155  void addModuleWidget(const std::string& name, SCIRun::Dataflow::Networks::ModuleHandle module);
157  void duplicateModule(const SCIRun::Dataflow::Networks::ModuleHandle& module);
158  void connectNewModule(const SCIRun::Dataflow::Networks::ModuleHandle& moduleToConnectTo, const SCIRun::Dataflow::Networks::PortDescriptionInterface* portToConnect, const std::string& newModuleName);
159  void executeAll();
160  void removeModuleWidget(const SCIRun::Dataflow::Networks::ModuleId& id);
161  virtual void clear();
162  void setConnectionPipelineType(int type);
163  void addModuleViaDoubleClickedTreeItem();
164  void selectAll();
165  void del();
166 
167  Q_SIGNALS:
168  void addConnection(const SCIRun::Dataflow::Networks::ConnectionDescription&);
169  void connectionDeleted(const SCIRun::Dataflow::Networks::ConnectionId& id);
170  void modified();
171  void networkExecuted();
172  void networkExecutionFinished();
173  void networkEditorMouseButtonPressed();
174  void moduleMoved(const SCIRun::Dataflow::Networks::ModuleId& id, double newX, double newY);
175  void defaultNotePositionChanged(NotePosition position);
176  void sceneChanged(const QList<QRectF>& region);
177  private Q_SLOTS:
178  void cut();
179  void copy();
180  void paste();
181  void bringToFront();
182  void sendToBack();
183  void properties();
184  void updateActions();
185 
186  private:
187  typedef QPair<ModuleWidget*, ModuleWidget*> ModulePair;
188  void createActions();
189  //void createMenus();
190  //void createToolBars();
191  void setZValue(int z);
192  void setupModuleWidget(ModuleWidget* node);
193  ModuleWidget* selectedModule() const;
194  ConnectionLine* selectedLink() const;
195  ModulePair selectedModulePair() const;
196  void addNewModuleAtPosition(const QPoint& position);
197  ConnectionLine* getSingleConnectionSelected();
198  void unselectConnectionGroup();
199  //QToolBar* editToolBar_;
200  //QAction* cutAction_;
201  //QAction* copyAction_;
202  //QAction* pasteAction_;
203  QAction* deleteAction_;
204  QAction* sendToBackAction_;
205  QAction* propertiesAction_;
206  //QAction* executeAction_;
207 
208  QGraphicsScene* scene_;
209 
210  QPointF lastModulePosition_;
211  QPoint defaultModulePosition_;
212  boost::shared_ptr<DialogErrorControl> dialogErrorControl_;
213  boost::shared_ptr<CurrentModuleSelection> moduleSelectionGetter_;
214  boost::shared_ptr<NetworkEditorControllerGuiProxy> controller_;
215  boost::shared_ptr<DefaultNotePositionGetter> defaultNotePositionGetter_;
216  boost::shared_ptr<ModuleEventProxy> moduleEventProxy_;
217  boost::shared_ptr<ZLevelManager> zLevelManager_;
218  };
219 }
220 }
221 
222 #endif
Definition: ConnectionId.h:67
Definition: ModulePositionGetter.h:49
boost::shared_ptr< NetworkFile > NetworkFileHandle
Definition: NetworkFwd.h:86
boost::shared_ptr< ModuleEventProxy > moduleEventProxy()
Definition: NetworkEditor.h:129
NotePosition
Definition: Note.h:47
string dir
Definition: eab.py:5
Definition: ModulePositionGetter.h:43
Definition: ModuleProxyWidget.h:42
boost::shared_ptr< ModulePositions > ModulePositionsHandle
Definition: NetworkFwd.h:85
Definition: ExecutableObject.h:45
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Definition: ModuleDescription.h:77
Definition: NetworkEditor.h:104
Definition: NetworkEditor.h:70
Definition: ModuleWidget.h:58
Definition: Connection.h:60
Definition: NetworkEditor.h:54
Definition: NetworkEditor.h:83
int max() const
Definition: NetworkEditor.h:87
virtual ~CurrentModuleSelection()
Definition: NetworkEditor.h:57
boost::shared_ptr< ModuleInterface > ModuleHandle
Definition: NetworkFwd.h:74
virtual ~DefaultNotePositionGetter()
Definition: NetworkEditor.h:66
tuple file
Definition: eab.py:7
Definition: ControllerInterfaces.h:42
Definition: NetworkEditor.h:63
Definition: NetworkInterface.h:48