Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / gui / YACSGui_TreeViewItem.h
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #ifndef YACSGui_TreeViewItem_HeaderFile
22 #define YACSGui_TreeViewItem_HeaderFile
23
24 #include <qlistview.h>
25
26 #include <Port.hxx>
27 #include <ElementaryNode.hxx>
28 #include <ServiceNode.hxx>
29 #include <Proc.hxx>
30 #include <TypeCode.hxx>
31 #include <SalomeContainer.hxx>
32 #include <ComponentInstance.hxx>
33 #include <guiObservers.hxx>
34
35 /* ================ items for tree view in edition mode ================ */
36
37 class YACSGui_Executor;
38
39 /*!
40  * YACS tree view item
41  */
42 class YACSGui_ViewItem : public QListViewItem, public YACS::HMI::GuiObserver
43 {
44 public:
45   YACSGui_ViewItem( QListView* theParent, 
46                     QListViewItem* theAfter );
47   YACSGui_ViewItem( QListViewItem* theParent, 
48                     QListViewItem* theAfter );
49   
50   virtual void select(bool isSelected);
51   //virtual void update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
52
53   // axiluary methods for blocking reaction inside select() method
54   bool blockSelection( const bool toBlock );
55   bool selectionBlocked() const;
56
57   virtual void update( const bool theIsRecursive = false ) {}
58
59 protected:
60   void removeNodeItem( YACS::HMI::Subject* theSNode );
61   void removeLinkItem( YACS::HMI::Subject* theSLink );
62
63 protected:
64   bool myBlockSelect;
65 };
66
67 /*!
68  * YACS label tree view item
69  */
70 class YACSGui_LabelViewItem : public YACSGui_ViewItem
71 {
72 public:
73   YACSGui_LabelViewItem( QListView* theParent, 
74                          QListViewItem* theAfter, 
75                          const QString theName );
76   YACSGui_LabelViewItem( QListViewItem* theParent, 
77                          QListViewItem* theAfter, 
78                          const QString theName );
79
80   virtual void select( bool isSelected );
81   
82   QString name() const;
83   QPixmap icon() const;
84
85   virtual void update( const bool theIsRecursive = false );
86   
87 protected:
88   QString myName;
89 };
90
91 /*!
92  * YACS reference tree view item
93  */
94 class YACSGui_ReferenceViewItem : public YACSGui_ViewItem
95 {
96 public:
97   typedef enum { Text, HighlightedText, Highlight } ColorRole;
98
99   YACSGui_ReferenceViewItem( QListView* theParent, 
100                              QListViewItem* theAfter,
101                              YACS::HMI::SubjectReference* theSReference );
102   YACSGui_ReferenceViewItem( QListViewItem* theParent, 
103                              QListViewItem* theAfter,
104                              YACS::HMI::SubjectReference* theSReference );
105   virtual ~YACSGui_ReferenceViewItem();
106   
107   virtual void select(bool isSelected);
108   virtual void update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
109
110   QString name() const;
111   QPixmap icon() const;
112   QColor  color( const ColorRole = Text ) const;
113   
114   YACS::ENGINE::Node* getNode() const;
115   YACS::HMI::SubjectReference* getSReference() const { return mySReference; }
116
117   virtual void paintCell( QPainter* p, const QColorGroup& cg, int c, int w, int align );
118
119   virtual void update( const bool theIsRecursive = false );
120     
121 private:
122   YACS::HMI::SubjectReference* mySReference;
123 };
124
125 /*!
126  * YACS tree view item for port
127  */
128 class YACSGui_PortViewItem : public YACSGui_ViewItem
129 {
130 public:
131   YACSGui_PortViewItem( QListView* theParent, 
132                         QListViewItem* theAfter,
133                         YACS::HMI::SubjectDataPort* theSPort );
134   YACSGui_PortViewItem( QListViewItem* theParent, 
135                         QListViewItem* theAfter,
136                         YACS::HMI::SubjectDataPort* theSPort );
137   virtual ~YACSGui_PortViewItem();
138
139   QString name() const;
140   QPixmap icon() const;
141
142   YACS::ENGINE::DataPort* getPort() const;
143   YACS::HMI::SubjectDataPort* getSPort() const { return mySPort; }
144
145   virtual void update( const bool theIsRecursive = false );
146     
147 private:
148   YACS::HMI::SubjectDataPort* mySPort;
149 };
150
151 /*!
152  * YACS tree view item for node
153  */
154 class YACSGui_NodeViewItem : public YACSGui_ViewItem
155 {
156 public:
157   typedef enum { Text, HighlightedText, Highlight } ColorRole;
158
159   YACSGui_NodeViewItem( QListView* theParent, 
160                         QListViewItem* theAfter,
161                         YACS::HMI::SubjectNode* theSNode );
162   YACSGui_NodeViewItem( QListViewItem* theParent, 
163                         QListViewItem* theAfter,
164                         YACS::HMI::SubjectNode* theSNode );
165   virtual ~YACSGui_NodeViewItem();
166   
167   virtual void update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
168
169   QString name() const;
170   QPixmap icon() const;
171
172   static QPixmap icon( YACS::ENGINE::Node* );
173   
174   YACS::ENGINE::Node* getNode() const;
175   YACS::HMI::SubjectNode* getSNode() const { return mySNode; }
176
177   virtual void update( const bool theIsRecursive = false );
178
179 private:
180   void renamePortItem( YACS::HMI::Subject* theSPort );
181   void addPortItem( YACS::HMI::Subject* theSPort );
182   void removePortItem( YACS::HMI::Subject* theSPort );
183   void addNodeItem( YACS::HMI::Subject* theSNode );
184   void moveUpPortItem( YACS::HMI::Subject* theSPort );
185   void moveDownPortItem( YACS::HMI::Subject* theSPort );
186   bool isPublished( YACS::ENGINE::Port* thePort );
187
188   void addReferenceItem( YACS::HMI::Subject* theSRef );
189   void removeReferenceItem( YACS::HMI::Subject* theSRef );
190
191   void addLinkItem( YACS::HMI::Subject* theSLink );
192
193   YACS::HMI::SubjectNode* mySNode;
194 };
195
196 /*!
197  * YACS tree view item for data link
198  */
199 class YACSGui_LinkViewItem : public YACSGui_ViewItem
200 {
201 public:
202   YACSGui_LinkViewItem( QListView* theParent, 
203                         QListViewItem* theAfter,
204                         YACS::HMI::SubjectLink* theSLink );
205   YACSGui_LinkViewItem( QListViewItem* theParent, 
206                         QListViewItem* theAfter,
207                         YACS::HMI::SubjectLink* theSLink );
208   virtual ~YACSGui_LinkViewItem();
209   
210   QString name() const;
211   QPixmap icon() const;
212
213   YACS::HMI::SubjectLink* getSLink() const { return mySLink; }
214
215   virtual void update( const bool theIsRecursive = false );
216     
217 private:
218   YACS::HMI::SubjectLink* mySLink;
219 };
220
221 /*!
222  * YACS tree view item for control link
223  */
224 class YACSGui_ControlLinkViewItem : public YACSGui_ViewItem
225 {
226 public:
227   YACSGui_ControlLinkViewItem( QListView* theParent, 
228                                QListViewItem* theAfter,
229                                YACS::HMI::SubjectControlLink* theSLink );
230   YACSGui_ControlLinkViewItem( QListViewItem* theParent, 
231                                QListViewItem* theAfter,
232                                YACS::HMI::SubjectControlLink* theSLink );
233   virtual ~YACSGui_ControlLinkViewItem();
234   
235   QString name() const;
236   QPixmap icon() const;
237
238   YACS::HMI::SubjectControlLink* getSLink() const { return mySLink; }
239
240   virtual void update( const bool theIsRecursive = false );
241     
242 private:
243   YACS::HMI::SubjectControlLink* mySLink;
244 };
245
246 /*!
247  * YACS tree view item for schema
248  */
249 class YACSGui_SchemaViewItem : public YACSGui_ViewItem
250 {
251 public:
252   YACSGui_SchemaViewItem( QListView* theParent, 
253                           QListViewItem* theAfter, 
254                           YACS::HMI::SubjectProc* theSProc );
255   YACSGui_SchemaViewItem( QListViewItem* theParent,
256                           QListViewItem* theAfter,
257                           YACS::HMI::SubjectProc* theSProc );
258   virtual ~YACSGui_SchemaViewItem();
259   
260   virtual void update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
261   
262   QPixmap icon() const;
263   
264   YACS::ENGINE::Proc* getProc() const;
265   YACS::HMI::SubjectProc* getSProc() const { return mySProc; }
266
267   virtual void update( const bool theIsRecursive = false,
268                        YACS::HMI::Subject* theSon = 0,
269                        YACSGui_NodeViewItem* theBlocItem = 0 );
270
271   YACSGui_LabelViewItem* buildDataTypesTree();
272
273 private:
274   void addNodeItem( YACS::HMI::Subject* theSNode );
275   void addContainerItem( YACS::HMI::Subject* theSContainer );
276   void removeContainerItem( YACS::HMI::Subject* theSContainer );
277   void removeComponentItem( YACS::HMI::Subject* theSComponent );
278   void addDataTypeItem( YACS::HMI::Subject* theSDataType );
279   void removeDataTypeItem( YACS::HMI::Subject* theSDataType );
280
281   void addLinkItem( YACS::HMI::Subject* theSLink );
282   
283   YACS::HMI::SubjectProc* mySProc;
284
285   std::map< YACS::ENGINE::DynType, QListViewItem* > myRootDataTypeItems;
286
287 };
288
289 class YACSGui_ComponentViewItem;
290 /*!
291  * YACS tree view item for container
292  */
293 class YACSGui_ContainerViewItem : public YACSGui_ViewItem
294 {
295 public:
296   YACSGui_ContainerViewItem(  QListView* theParent, 
297                               QListViewItem* theAfter,
298                               YACS::HMI::SubjectContainer* theSContainer = 0 );
299   YACSGui_ContainerViewItem(  QListViewItem* theParent, 
300                               QListViewItem* theAfter,
301                               YACS::HMI::SubjectContainer* theSContainer = 0 );
302   virtual ~YACSGui_ContainerViewItem();
303
304   virtual void update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
305
306   QString name() const;
307   QPixmap icon() const;  
308   
309   YACS::ENGINE::Container* getContainer() const;
310   YACS::HMI::SubjectContainer* getSContainer() const { return mySContainer; }
311
312   virtual void update( YACSGui_ComponentViewItem* theComponent = 0 );
313   
314   void addComponentItem( YACS::HMI::Subject* theSComponent );
315   
316 private:
317   void removeComponentItem( YACS::HMI::Subject* theSComponent );
318
319   YACS::HMI::SubjectContainer* mySContainer;
320 };
321
322 /*!
323  * YACS tree view item for component
324  */
325 class YACSGui_ComponentViewItem : public YACSGui_ViewItem
326 {
327 public:
328   YACSGui_ComponentViewItem( QListView* theParent, 
329                              QListViewItem* theAfter,
330                              YACS::HMI::SubjectComponent* theSComponent = 0 );
331   YACSGui_ComponentViewItem( QListViewItem* theParent, 
332                              QListViewItem* theAfter,
333                              YACS::HMI::SubjectComponent* theSComponent = 0 );
334
335   virtual ~YACSGui_ComponentViewItem();
336
337   virtual void update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
338   
339   QString name() const;
340   QString instanceName() const;
341   QPixmap icon() const;
342   
343   YACS::ENGINE::ComponentInstance* getComponent() const;
344   YACS::HMI::SubjectComponent* getSComponent() const { return mySComponent; }
345
346   virtual void update( const bool theMove = false );
347   virtual void move( YACS::HMI::Subject* theSReference );
348     
349 private:
350   YACS::HMI::SubjectComponent* mySComponent;
351 };
352
353 /*!
354  * YACS tree view item for data type
355  */
356 class YACSGui_DataTypeItem : public YACSGui_ViewItem
357 {
358 public:
359   //typedef enum { Text, HighlightedText, Highlight } ColorRole;
360
361   YACSGui_DataTypeItem( QListView* theParent, 
362                         QListViewItem* theAfter,
363                         YACS::HMI::SubjectDataType* theSDataType );
364   YACSGui_DataTypeItem( QListViewItem* theParent, 
365                         QListViewItem* theAfter,
366                         YACS::HMI::SubjectDataType* theSDataType );
367   virtual ~YACSGui_DataTypeItem();
368   
369   virtual void update(YACS::HMI::GuiEvent event, int type, YACS::HMI::Subject* son);
370
371   QString name() const;
372   static QPixmap icon();
373   
374   YACS::HMI::SubjectDataType* getSDataType() const { return mySDataType; }
375
376   virtual void update( const bool theIsRecursive = false );
377
378 private:
379   YACS::HMI::SubjectDataType* mySDataType;
380 };
381
382 /* ================ items for tree view in run mode ================ */
383
384
385 class YACSGui_ComposedNodeViewItem: public YACSGui_ViewItem
386 {
387  public:
388   YACSGui_ComposedNodeViewItem(QListView *parent,
389                                QString label,
390                                YACS::ENGINE::ComposedNode *node = 0);
391   YACSGui_ComposedNodeViewItem(QListViewItem *parent,
392                                QString label,
393                                YACS::ENGINE::ComposedNode *node = 0);
394   virtual ~YACSGui_ComposedNodeViewItem();
395
396   void setState(int state);
397   void setStatus(int status);
398   virtual void paintCell( QPainter *p, const QColorGroup &cg,
399                           int column, int width, int alignment );
400   QColor statusBgColor() const;
401   YACS::ENGINE::ComposedNode* getNode() {return _node;};
402
403   QPixmap icon() const;
404
405   void update( const bool theIsRecursive = false );
406
407   YACS::HMI::Subject* getSubject() const;
408   void popup(YACSGui_Executor* anExecutor,const QPoint & point);
409
410  protected:
411   int _state;
412   QColor _cf;
413   YACS::ENGINE::ComposedNode *_node;
414 };
415
416 class YACSGui_ElementaryNodeViewItem: public QCheckListItem,
417                                       public YACS::HMI::GuiObserver
418 {
419  public:
420   YACSGui_ElementaryNodeViewItem(QListView *parent,
421                                  const QString &text,
422                                  Type tt = RadioButtonController,
423                                  YACS::ENGINE::ElementaryNode *node = 0);
424   YACSGui_ElementaryNodeViewItem(QListViewItem *parent,
425                                  const QString &text,
426                                  Type tt = RadioButtonController,
427                                  YACS::ENGINE::ElementaryNode *node = 0);
428   virtual ~YACSGui_ElementaryNodeViewItem();
429   
430   void setState(int state); 
431   virtual void paintCell( QPainter *p, const QColorGroup &cg,
432                           int column, int width, int alignment );
433   YACS::ENGINE::ElementaryNode* getNode() {return _node;};
434
435   virtual void select(bool isSelected);
436
437   void update( const bool theIsRecursive = false );
438
439   // axiluary methods for blocking reaction inside select() method
440   bool blockSelection( const bool toBlock );
441   bool selectionBlocked() const;
442
443   YACS::HMI::Subject* getSubject() const;
444   void popup(YACSGui_Executor* anExecutor,const QPoint & point);
445   
446  protected:
447   int _state;
448   QColor _cf;
449   YACS::ENGINE::ElementaryNode *_node;
450
451   bool myBlockSelect;
452 };
453
454 #endif