iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Port.H
Go to the documentation of this file.
1 /*! @file
2  @author Unknown
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 #ifndef SRC_APPS_NRTDESIGNER_PORT_H
35 #define SRC_APPS_NRTDESIGNER_PORT_H
36 
37 #include "Common.H"
39 
41 NRT_BEGIN_UNCHECKED_INCLUDES
42 #include <QGraphicsItem>
43 NRT_END_UNCHECKED_INCLUDES
44 
45 class ModuleRepBase;
46 class PortList;
47 class ConnectionRequest;
48 
49 class Port : public QGraphicsObject
50 {
51 
52  Q_OBJECT
53 
54  public:
55  enum PortType { ModulePoster=1, ModuleSubscriber=2, ModuleChecker=3,
56  BorderPosterInner=4, BorderSubscriberInner=5, BorderCheckerInner=6,
57  BorderPosterOuter=7, BorderSubscriberOuter=8, BorderCheckerOuter=9 };
58 
59  //! Construct a module-port
60  /*! A port's parent must always be a PortList */
61  Port(QString const & moduleUID, nrt::blackboard::ModulePortSummary const & portSummary,
62  PortType type_, PortList * parent);
63 
64  //! Construct a connector-port
65  /*! A port's parent must always be a PortList. */
66  Port(QString const & connectorUID, nrt::blackboard::ConnectorSummary const & connSummary,
67  PortType type_, PortList * parent);
68 
69  //! Destructor
70  /*! Automatically removes from the NetworkCanvas scene */
71  virtual ~Port();
72 
73  //! Draw this port
74  void paint(QPainter * painter, QStyleOptionGraphicsItem const * option, QWidget * widget);
75 
76  //! Get this port's bounding rectangle
77  QRectF boundingRect() const;
78 
79  //! This port's message type
80  QString const messageType;
81 
82  //! This port's return type
83  QString const returnType;
84 
85  //! This port's message color
86  QColor const messageColor;
87 
88  //! This port's return message color
89  QColor const returnColor;
90 
91  //! Name of this port
92  QString const name;
93 
94  //! Description of the port
95  QString const description;
96 
97  //! This port's type
98  PortType const type;
99 
100  //! The module or connector uid for that port
101  QString const owneruid;
102 
103  //! The display name for tooltip or other display purposes
104  /*! For module ports, this is the portname. For connector ports, this is the connector instance name. */
105  QString const displayname;
106 
107  //! Get this port's topic
108  QString topic() const;
109 
110  //! Get this port's topicFilter
111  QString topicFilter() const;
112 
113  //! The size of a port when drawn on the canvas
114  static QSize const portSize;
115 
116  //! Update this Port's info using a new ModulePortSummary
117  void updateSummary(nrt::blackboard::ModulePortSummary const & portSummary);
118 
119  //! Update this Port's info using a new ConnectorSummary
120  void updateSummary(nrt::blackboard::ConnectorSummary const & connSummary);
121 
122  //! Create a new connection request that starts at this PortRepBase
123  ConnectionRequest * startConnectionRequest();
124 
125  protected:
126  //! Emit a portSelectedSignal() when we are selected
127  void mousePressEvent(QGraphicsSceneMouseEvent * event);
128 
129  signals:
130  //! Let the NetworkCanvas know that we have been clicked so it can start a ConnectionRequest
131  void portSelectedSignal(Port * p);
132 
133  //! Let any connections know that we have moved
134  void portMovedSignal(QPointF pos);
135 
136  public slots:
137  //! Triggered whenever our parent Module is moved so that we can recalculate all of our bound connection lines
138  void moduleMovedSlot(ModuleRepBase * module);
139 
140  //! Triggered when a key is pressed (e.g., backspace) while we are selected
141  void keyPressedSlot(QKeyEvent * event);
142 
143  private:
144  QRectF itsRect;
145  QString itsTopic;
146  bool itsSplittable;
147  bool itsIsSplit;
148 
149  // The following are only used for Connector ports
150  QString itsTopicFilter;
151  QString itsUID;
152 
153  // The following are used only for Module ports
154  QString itsOwnerUID;
155 
156  ModuleRepBase *itsParentModule;
157 
158  bool itsHighlight;
159 
160 };
161 
162 #endif // SRC_APPS_NRTDESIGNER_PORT_H
163