Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / hmi / editTree.h
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef _EDITTREE_H_
20 #define _EDITTREE_H_
21
22 #include "guiObservers.hxx"
23
24 #include "wiedittree.h"
25 #include <qlistview.h>
26
27 #include <map>
28 #include <utility>
29
30 namespace YACS
31 {
32   namespace ENGINE
33   {
34     class Catalog;
35   }
36
37   namespace HMI
38   {
39
40     class ViewItem: public QListViewItem, public GuiObserver
41     {
42     public:
43       ViewItem(QListView *parent, QString label, Subject* subject);
44       ViewItem(ViewItem *parent, QString label, Subject* subject);
45       virtual ~ViewItem();
46       void setState(int state);
47       virtual void paintCell( QPainter *p, const QColorGroup &cg,
48                               int column, int width, int alignment );
49       virtual QListView *getParent();
50       virtual void select(bool isSelected);
51       virtual void update(GuiEvent event, int type, Subject* son);
52       virtual Subject* getSubject();
53     protected:
54       int _state;
55       QColor _cf;
56       Subject* _subject;
57       QListView *_parent;
58     };
59     
60     class editTree: public wiEditTree, public GuiObserver
61     {
62       Q_OBJECT
63         
64     public slots:
65       void printName();
66       void newNode(int key);
67       void newNode(YACS::ENGINE::Catalog* catalog,
68                    Subject* sub,
69                    std::pair<std::string,std::string> compoServ);
70       void newDataType(YACS::ENGINE::Catalog* catalog,
71                        Subject* sub,
72                        std::string typeName);
73       void newInputPort(int key);
74       void newOutputPort(int key);
75       void newDFInputPort();
76       void newDFOutputPort();
77       void newDSInputPort();
78       void newDSOutputPort();
79       void newDFInputPort(YACS::ENGINE::Catalog* catalog,
80                           Subject* sub,
81                           std::string typeName);
82       void newDFOutputPort(YACS::ENGINE::Catalog* catalog,
83                            Subject* sub,
84                            std::string typeName);
85       void newDSInputPort(YACS::ENGINE::Catalog* catalog,
86                           Subject* sub,
87                           std::string typeName);
88       void newDSOutputPort(YACS::ENGINE::Catalog* catalog,
89                            Subject* sub,
90                            std::string typeName);
91       void select();
92       void select(QListViewItem *it);
93       void destroy();
94       void addLink();
95       void editPortProperties();
96       void addComponent();
97       void associateServiceToComponent();
98       void addContainer();
99       void associateComponentToContainer();
100       void editContainerProperties();
101       void catalog(int cataType);
102       void setCatalog(int isproc);
103     public:
104       editTree(YACS::HMI::Subject *context,
105                 QWidget* parent = 0,
106                 const char* name = 0,
107                 WFlags fl = 0 );
108       virtual ~editTree();
109       virtual void update(GuiEvent event, int type, Subject* son);
110       void setNewRoot(YACS::HMI::Subject *root);
111       void addViewItemInMap(YACS::HMI::ViewItem* item, YACS::HMI::Subject* subject);
112       YACS::HMI::ViewItem* getViewItem(YACS::HMI::Subject* subject);
113       YACS::HMI::Subject* getSelectedSubject();
114     protected:
115       void contextMenuEvent ( QContextMenuEvent * );
116       void ComposedNodeContextMenu();
117       void NodeContextMenu();
118       void PortContextMenu();
119       void LinkContextMenu();
120       void ComponentContextMenu();
121       void ContainerContextMenu();
122       void resetTreeNode(QListView *lv);
123       QWidget* _parent;
124       Subject *_context;
125       Subject *_root;
126       QListViewItem *_previousSelected;
127       SubjectDataPort *_selectedSubjectOutPort;
128       SubjectNode *_selectedSubjectNode;
129       SubjectComponent *_selectedSubjectComponent;
130       SubjectServiceNode *_selectedSubjectService;
131       std::map<YACS::HMI::Subject*,YACS::HMI::ViewItem*> _viewItemsMap;
132       std::map<int, std::pair<YACS::ENGINE::Catalog*, std::string> > _catalogItemsMap;
133       int _keymap;
134     };
135     
136     class NodeViewItem: public ViewItem
137     {
138     public:
139       NodeViewItem(ViewItem *parent, QString label, Subject* subject);
140       virtual void update(GuiEvent event, int type, Subject* son);
141     protected:
142     };
143     
144     
145     class ComposedNodeViewItem: public ViewItem
146     {
147     public:
148       ComposedNodeViewItem(QListView *parent, QString label, Subject* subject);
149       ComposedNodeViewItem(ViewItem *parent, QString label, Subject* subject);
150       virtual void update(GuiEvent event, int type, Subject* son);
151     protected:
152     };
153     
154     class PortViewItem: public ViewItem
155     {
156     public:
157       PortViewItem(ViewItem *parent, QString label, Subject* subject);
158       virtual void update(GuiEvent event, int type, Subject* son);
159     protected:
160     };
161     
162     class LinkViewItem: public ViewItem
163     {
164     public:
165       LinkViewItem(ViewItem *parent, QString label, Subject* subject);
166       virtual void update(GuiEvent event, int type, Subject* son);
167     protected: 
168     };
169     
170     class ComponentViewItem: public ViewItem
171     {
172     public:
173       ComponentViewItem(ViewItem *parent, QString label, Subject* subject);
174       virtual void update(GuiEvent event, int type, Subject* son);
175     protected:
176     };
177     
178     class ContainerViewItem: public ViewItem
179     {
180     public:
181       ContainerViewItem(ViewItem *parent, QString label, Subject* subject);
182       virtual void update(GuiEvent event, int type, Subject* son);
183     protected:
184     };
185
186     class DataTypeViewItem: public ViewItem
187     {
188     public:
189       DataTypeViewItem(ViewItem *parent, QString label, Subject* subject);
190       virtual void update(GuiEvent event, int type, Subject* son);
191     protected:
192     };
193
194     class ReferenceViewItem: public ViewItem
195     {
196     public:
197       ReferenceViewItem(ViewItem *parent, QString label, Subject* subject);
198       virtual void update(GuiEvent event, int type, Subject* son);
199     protected:
200     };
201
202   }
203 }
204
205 #endif