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