Salome HOME
ac6cd16ab2a780caff52386260fa194a35dd12a3
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_ManagePortsDlg.h
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SUPERVGUI_ManagePortsDlg.h
23 //  Author : Alexander SLADKOV
24 //  Module : SUPERV
25
26 #ifndef SUPERVGUI_ManagePortsDlg_H
27 #define SUPERVGUI_ManagePortsDlg_H
28
29 #include "SUPERVGUI.h"
30
31 #include <qdialog.h>
32 #include <qlistbox.h>
33 #include <qstringlist.h>
34 #include <qlineedit.h>
35 #include <qcombobox.h>
36 #include <qpair.h>
37
38 class SUPERVGUI_CanvasNode;
39
40 /** 
41  * Simple redefinition of ListBoxItem for storing ports name and type without having to parce it
42  */
43 class PortListItem : QListBoxText {
44 public:
45   PortListItem ( QListBox* lb, const QString& name, const QString& type )
46   : QListBoxText( lb/*, QString( "%1 (%2)" ).arg( name ).arg( type )*/ ),
47     PortName( name ),
48     PortType( type ) {}
49   QString PortName;
50   QString PortType;
51   virtual QString text() const { return QString( "%1 (%2)" ).arg( PortName ).arg( PortType ); }
52 };
53
54 /**
55  * The dialog class
56  */
57 class SUPERVGUI_ManagePortsDlg: public QDialog {
58   
59   Q_OBJECT
60
61 public:
62   SUPERVGUI_ManagePortsDlg( SUPERVGUI_CanvasNode* theNode );
63   virtual ~SUPERVGUI_ManagePortsDlg();
64
65 protected slots:
66   void accept();
67   void reject();
68
69   void addInput()     { addPort( myInList ); }    
70   void addOutput()    { addPort( myOutList );}
71   void removeInput()  { removePort( myInList ); }
72   void removeOutput() { removePort( myOutList );}
73   void upInput()      { moveUp( myInList ); }
74   void upOutput()     { moveUp( myOutList );}
75   void downInput()    { moveDown( myInList ); }
76   void downOutput()   { moveDown( myOutList );}
77
78   void nameChanged( const QString& name );
79   void typeChanged( const QString& type );
80   void itemChanged( QListBoxItem * item );
81   void itemDeselect(QListBoxItem* item, const QPoint& point); // mkr: PAL12448
82
83 protected:
84   virtual void showEvent( QShowEvent* theEvent );
85   void addPort( QListBox* );
86   void removePort( QListBox* );
87   void moveUp( QListBox* );
88   void moveDown( QListBox* );
89   void moveItem( QListBox* theLB, const int from, const int to );
90   // mkr : PAL8060
91   void createLinkEngine( SUPERV::Port_ptr thePort, 
92                          QValueList< QPair< QString,QString > >& theOwnList, 
93                          QValueList< QPair< QString,QString > >& theCorrespList );
94   
95 private:
96   void init();
97   void init( const SUPERVGUI_CanvasNode* theNode );
98
99   SUPERVGUI_CanvasNode*         myNode;
100
101   QLineEdit*                    myNameEdt;
102   QComboBox*                    myTypeCombo;
103   QListBox*                     myInList;
104   QListBox*                     myOutList;
105   QListBoxItem*                 myLastItem;
106 };
107
108 /*!
109  * Port parameters dialog definition (taken from SUPERVGUI_Node.h without change)
110  */
111 class SUPERVGUI_PortParamsDlg: public QDialog {
112   Q_OBJECT
113     
114  public:
115   SUPERVGUI_PortParamsDlg(const QStringList& thePortsNames);
116   ~SUPERVGUI_PortParamsDlg() {};
117
118   QString getName() { return myNameTxt->text(); }
119   QString getType() { return myTypeTxt->currentText(); }
120
121  public slots:
122   void clickOnOk();
123     
124    
125  private:
126   QLineEdit* myNameTxt;
127   QComboBox* myTypeTxt;
128   QStringList myPortsNames;
129 };
130
131
132 #endif