]> Creatis software - cpPlugins.git/blob - lib/cpBaseQtApplication/Pipeline/Port.h
...
[cpPlugins.git] / lib / cpBaseQtApplication / Pipeline / Port.h
1 #ifndef __cpBaseQtApplication__Pipeline__Port__h__\r
2 #define __cpBaseQtApplication__Pipeline__Port__h__\r
3 \r
4 #include <cpBaseQtApplication_Export.h>\r
5 #include <QGraphicsPathItem>\r
6 \r
7 namespace cpBaseQtApplication\r
8 {\r
9   namespace Pipeline\r
10   {\r
11     class Block;\r
12     class Connection;\r
13 \r
14     /**\r
15      */\r
16     class cpBaseQtApplication_EXPORT Port\r
17       : public QObject,\r
18         public QGraphicsPathItem\r
19     {\r
20       Q_OBJECT;\r
21     public:\r
22       typedef Port Self;\r
23       typedef QGraphicsPathItem Superclass;\r
24 \r
25       enum { Type = QGraphicsItem::UserType + 1 };\r
26 \r
27     public:\r
28       Port( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
29       virtual ~Port( );\r
30 \r
31       void setBlock( Block* b );\r
32       inline Block* block( ) const\r
33         { return( this->m_Block ); }\r
34 \r
35       virtual void setName( const QString& n );\r
36       virtual void setExtendedName( const QString& n );\r
37       inline QString name( ) const\r
38         { return( this->m_Label->toPlainText( ) ); }\r
39       inline QString extendedName( ) const\r
40         { return( this->m_ExtendedLabel->toPlainText( ) ); }\r
41 \r
42       inline int radius( ) const\r
43         { return( this->m_Radius ); }\r
44 \r
45       inline bool isExtended( ) const\r
46         { return( this->m_IsExtended ); }\r
47       virtual void setExtend( bool extend );\r
48 \r
49       virtual bool isConnected( Port* other ) = 0;\r
50       inline int type( ) const\r
51         { return( this->Type ); }\r
52 \r
53       virtual void paint(\r
54         QPainter* painter,\r
55         const QStyleOptionGraphicsItem* option,\r
56         QWidget* widget\r
57         );\r
58 \r
59     protected:\r
60       virtual void _updateLabels( ) { }\r
61 \r
62     protected:\r
63       Block* m_Block;\r
64 \r
65       int  m_Radius;\r
66       int  m_Margin;\r
67       bool m_IsExtended;\r
68 \r
69       QGraphicsTextItem* m_Label;\r
70       QGraphicsTextItem* m_ExtendedLabel;\r
71     };\r
72 \r
73     /**\r
74      */\r
75     class cpBaseQtApplication_EXPORT NamePort\r
76       : public Port\r
77     {\r
78       Q_OBJECT;\r
79     public:\r
80       typedef NamePort Self;\r
81       typedef Port     Superclass;\r
82 \r
83       enum { Type = Superclass::Type + 1 };\r
84 \r
85     public:\r
86       NamePort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
87       virtual ~NamePort( );\r
88 \r
89       virtual bool isConnected( Port* other );\r
90       inline int type( ) const\r
91         { return( this->Type ); }\r
92 \r
93     protected:\r
94       virtual void _updateLabels( );\r
95     };\r
96 \r
97     /**\r
98      */\r
99     class cpBaseQtApplication_EXPORT InfoPort\r
100       : public Port\r
101     {\r
102       Q_OBJECT;\r
103     public:\r
104       typedef InfoPort Self;\r
105       typedef Port     Superclass;\r
106 \r
107       enum { Type = Superclass::Type + 2 };\r
108 \r
109     public:\r
110       InfoPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
111       virtual ~InfoPort( );\r
112 \r
113       virtual bool isConnected( Port* other );\r
114       inline int type( ) const\r
115         { return( this->Type ); }\r
116 \r
117     protected:\r
118       virtual void _updateLabels( );\r
119     };\r
120 \r
121     /**\r
122      */\r
123     class cpBaseQtApplication_EXPORT InputPort\r
124       : public Port\r
125     {\r
126       Q_OBJECT;\r
127     public:\r
128       typedef InputPort Self;\r
129       typedef Port      Superclass;\r
130 \r
131       enum { Type = Superclass::Type + 3 };\r
132 \r
133     public:\r
134       InputPort(\r
135         QGraphicsItem* parent,\r
136         bool multiple,\r
137         QGraphicsScene* scene = NULL\r
138         );\r
139       virtual ~InputPort( );\r
140 \r
141       virtual void setExtend( bool extend );\r
142 \r
143       virtual bool isConnected( Port* other );\r
144       inline int type( ) const\r
145         { return( this->Type ); }\r
146 \r
147       void setConnection( Connection* c );\r
148       void removeConnection( Connection* c );\r
149       inline unsigned int numberOfConnections( ) const\r
150         { return( this->m_Connection.size( ) ); }\r
151       inline Connection* connection( unsigned int i )\r
152         { return( this->m_Connection[ i ] ); }\r
153       inline const Connection* connection( unsigned int i ) const\r
154         { return( this->m_Connection[ i ] ); }\r
155       inline bool hasConnection( ) const\r
156         { return( this->m_Connection.size( ) > 0 ); }\r
157       inline bool isMultiple( ) const\r
158         { return( this->m_IsMultiple ); }\r
159 \r
160     protected:\r
161       QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
162       virtual void _updateLabels( );\r
163 \r
164     protected:\r
165       std::vector< Connection* > m_Connection;\r
166       bool m_IsMultiple;\r
167     };\r
168 \r
169     /**\r
170      */\r
171     class cpBaseQtApplication_EXPORT OutputPort\r
172       : public Port\r
173     {\r
174       Q_OBJECT;\r
175     public:\r
176       typedef OutputPort Self;\r
177       typedef Port       Superclass;\r
178 \r
179       enum { Type = Superclass::Type + 4 };\r
180 \r
181     public:\r
182       OutputPort( QGraphicsItem* parent = NULL, QGraphicsScene* scene = NULL );\r
183       virtual ~OutputPort( );\r
184 \r
185       void removeConnection( Connection* c );\r
186       virtual void setExtend( bool extend );\r
187 \r
188       virtual bool isConnected( Port* other );\r
189       inline int type( ) const\r
190         { return( this->Type ); }\r
191 \r
192       inline std::vector< Connection* >& connections( )\r
193         { return( this->m_Connections ); }\r
194       inline const std::vector< Connection* >& connections( ) const\r
195         { return( this->m_Connections ); }\r
196 \r
197     signals:\r
198     void viewData( const std::string& name, bool show );\r
199 \r
200     protected:\r
201       QVariant itemChange( GraphicsItemChange change, const QVariant& value );\r
202       virtual void _updateLabels( );\r
203 \r
204       virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* evt );\r
205 \r
206     protected:\r
207       std::vector< Connection* > m_Connections;\r
208     };\r
209 \r
210   } // ecapseman\r
211 \r
212 } // ecapseman\r
213 \r
214 #endif // __cpBaseQtApplication__Pipeline__Port__h__\r
215 \r
216 // eof - $RCSfile$\r