SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Port.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_PORTWIDGET_H
30 #define INTERFACE_APPLICATION_PORTWIDGET_H
31 
32 #include <boost/shared_ptr.hpp>
33 #include <boost/tuple/tuple.hpp>
34 #include <boost/tuple/tuple_comparison.hpp>
35 #include <QGraphicsWidget>
36 #include <QPushButton>
37 #include <QColor>
38 #include <set>
42 
43 class QGraphicsScene;
44 
45 namespace SCIRun {
46 namespace Gui {
47 
48 class ConnectionLine;
49 class PositionProvider;
50 class ConnectionInProgress;
51 class ConnectionFactory;
52 class ClosestPortFinder;
53 class PortActionsMenu;
54 
56 {
57  Q_OBJECT
58 public:
59  PortWidget(const QString& name, const QColor& color, const std::string& datatype, const SCIRun::Dataflow::Networks::ModuleId& moduleId, const SCIRun::Dataflow::Networks::PortId& portId, size_t index, bool isInput, bool isDynamic,
60  boost::shared_ptr<ConnectionFactory> connectionFactory,
61  boost::shared_ptr<ClosestPortFinder> closestPortFinder, QWidget* parent = 0);
62  virtual ~PortWidget();
63 
64  QString name() const { return name_; }
65  QColor color() const { return color_; }
66  virtual bool isInput() const { return isInput_; }
67  virtual bool isDynamic() const { return isDynamic_; }
68  bool isConnected() const { return isConnected_; }
69  void setConnected(bool connected) { isConnected_ = connected; }
70 
71  virtual size_t nconnections() const;
72  virtual std::string get_typename() const;
73  virtual std::string get_portname() const;
75  virtual size_t getIndex() const;
76  void setIndex(size_t i);
77 
78  virtual SCIRun::Dataflow::Networks::PortId id() const;
79 
80  void toggleLight();
81  void turn_on_light();
82  void turn_off_light();
83  bool isLightOn() const { return lightOn_; }
84 
85  QSize sizeHint() const;
86 
89 
90  void trackConnections();
91  void deleteConnections();
92 
93  QPointF position() const;
94 
95  bool sharesParentModule(const PortWidget& other) const;
96  bool isFullInputPort() const;
97 
98  void doMousePress(Qt::MouseButton button, const QPointF& pos);
99  void doMouseMove(Qt::MouseButtons buttons, const QPointF& pos);
100  void doMouseRelease(Qt::MouseButton button, const QPointF& pos);
101 
102  static const int WIDTH = 11;
103 
104 protected:
105  virtual void moveEvent(QMoveEvent * event);
106 
107 public Q_SLOTS:
110  void portCachingChanged(bool checked);
111  void connectNewModule();
112 Q_SIGNALS:
115  void connectNewModule(const SCIRun::Dataflow::Networks::PortDescriptionInterface* portToConnect, const std::string& newModuleName);
116  void portMoved();
117 protected:
118  void mousePressEvent(QMouseEvent* event);
119  void mouseReleaseEvent(QMouseEvent* event);
120  void mouseMoveEvent(QMouseEvent* event);
121  void paintEvent(QPaintEvent* event);
122 private:
123  void performDrag(const QPointF& endPos);
124  void makeConnection(const QPointF& pos);
125  void tryConnectPort(const QPointF& pos, PortWidget* port);
126  bool matches(const SCIRun::Dataflow::Networks::ConnectionDescription& cd) const;
127 
128  const QString name_;
129  const SCIRun::Dataflow::Networks::ModuleId moduleId_;
131  size_t index_;
132  const QColor color_;
133  const std::string typename_;
134  const bool isInput_;
135  const bool isDynamic_;
136  bool isConnected_;
137  bool lightOn_;
138  QPointF startPos_;
139  ConnectionInProgress* currentConnection_;
141  std::set<ConnectionLine*> connections_;
142  boost::shared_ptr<ConnectionFactory> connectionFactory_;
143  boost::shared_ptr<ClosestPortFinder> closestPortFinder_;
144  PortActionsMenu* menu_;
145  //TODO
146  typedef std::map<std::string, std::map<bool, std::map<SCIRun::Dataflow::Networks::PortId, PortWidget*>>> PortWidgetMap;
147  static PortWidgetMap portWidgetMap_;
148 };
149 
151 {
152 public:
153  InputPortWidget(const QString& name, const QColor& color, const std::string& datatype, const SCIRun::Dataflow::Networks::ModuleId& moduleId,
154  const SCIRun::Dataflow::Networks::PortId& portId, size_t index, bool isDynamic,
155  boost::shared_ptr<ConnectionFactory> connectionFactory,
156  boost::shared_ptr<ClosestPortFinder> closestPortFinder,
157  QWidget* parent = 0);
158 };
159 
161 {
162 public:
163  OutputPortWidget(const QString& name, const QColor& color, const std::string& datatype, const SCIRun::Dataflow::Networks::ModuleId& moduleId,
164  const SCIRun::Dataflow::Networks::PortId& portId, size_t index, bool isDynamic,
165  boost::shared_ptr<ConnectionFactory> connectionFactory,
166  boost::shared_ptr<ClosestPortFinder> closestPortFinder,
167  QWidget* parent = 0);
168 };
169 
170 }
171 }
172 
173 #endif
Definition: Port.h:55
virtual void moveEvent(QMoveEvent *event)
Definition: Port.cc:310
virtual std::string get_portname() const
Definition: Port.cc:387
void turn_on_light()
Definition: Port.cc:170
Definition: ConnectionId.h:67
void mouseMoveEvent(QMouseEvent *event)
Definition: Port.cc:200
void setConnected(bool connected)
Definition: Port.h:69
bool isFullInputPort() const
Definition: Port.cc:327
void toggleLight()
Definition: Port.cc:160
virtual ~PortWidget()
Definition: Port.cc:147
void trackConnections()
Definition: Port.cc:362
void removeConnection(ConnectionLine *c)
Definition: Port.cc:347
void requestConnection(const SCIRun::Dataflow::Networks::PortDescriptionInterface *from, const SCIRun::Dataflow::Networks::PortDescriptionInterface *to)
Definition: PositionProvider.h:49
OutputPortWidget(const QString &name, const QColor &color, const std::string &datatype, const SCIRun::Dataflow::Networks::ModuleId &moduleId, const SCIRun::Dataflow::Networks::PortId &portId, size_t index, bool isDynamic, boost::shared_ptr< ConnectionFactory > connectionFactory, boost::shared_ptr< ClosestPortFinder > closestPortFinder, QWidget *parent=0)
Definition: Port.cc:420
void mouseReleaseEvent(QMouseEvent *event)
Definition: Port.cc:215
bool isConnected() const
Definition: Port.h:68
Definition: Connection.h:100
void portCachingChanged(bool checked)
Definition: Port.cc:398
virtual SCIRun::Dataflow::Networks::PortId id() const
Definition: Port.cc:225
void turn_off_light()
Definition: Port.cc:165
InputPortWidget(const QString &name, const QColor &color, const std::string &datatype, const SCIRun::Dataflow::Networks::ModuleId &moduleId, const SCIRun::Dataflow::Networks::PortId &portId, size_t index, bool isDynamic, boost::shared_ptr< ConnectionFactory > connectionFactory, boost::shared_ptr< ClosestPortFinder > closestPortFinder, QWidget *parent=0)
Definition: Port.cc:411
void connectionDeleted(const SCIRun::Dataflow::Networks::ConnectionId &id)
virtual std::string get_typename() const
Definition: Port.cc:382
Definition: Port.h:150
void MakeTheConnection(const SCIRun::Dataflow::Networks::ConnectionDescription &cd)
Definition: Port.cc:296
void cancelConnectionsInProgress()
Definition: Port.cc:254
Definition: ModuleDescription.h:77
bool sharesParentModule(const PortWidget &other) const
Definition: Port.cc:322
virtual Dataflow::Networks::ModuleId getUnderlyingModuleId() const
Definition: Port.cc:392
virtual size_t getIndex() const
Definition: Port.cc:220
void paintEvent(QPaintEvent *event)
Definition: Port.cc:175
Definition: Port.cc:91
virtual bool isDynamic() const
Definition: Port.h:67
QColor color() const
Definition: Port.h:65
void doMousePress(Qt::MouseButton button, const QPointF &pos)
Definition: Port.cc:190
QSize sizeHint() const
Definition: Port.cc:152
Definition: Connection.h:60
void deleteConnections()
Definition: Port.cc:354
static const int WIDTH
Definition: Port.h:102
void doMouseMove(Qt::MouseButtons buttons, const QPointF &pos)
Definition: Port.cc:205
virtual size_t nconnections() const
Definition: Port.cc:377
Definition: Port.h:160
void addConnection(ConnectionLine *c)
Definition: Port.cc:341
void doMouseRelease(Qt::MouseButton button, const QPointF &pos)
Definition: Port.cc:260
bool isLightOn() const
Definition: Port.h:83
void setIndex(size_t i)
Definition: Port.cc:230
QString name() const
Definition: Port.h:64
Definition: ModuleDescription.h:45
void mousePressEvent(QMouseEvent *event)
Definition: Port.cc:185
PortWidget(const QString &name, const QColor &color, const std::string &datatype, const SCIRun::Dataflow::Networks::ModuleId &moduleId, const SCIRun::Dataflow::Networks::PortId &portId, size_t index, bool isInput, bool isDynamic, boost::shared_ptr< ConnectionFactory > connectionFactory, boost::shared_ptr< ClosestPortFinder > closestPortFinder, QWidget *parent=0)
Definition: Port.cc:127
QPointF position() const
Definition: Port.cc:368
void connectNewModule()
Definition: Port.cc:404
virtual bool isInput() const
Definition: Port.h:66