Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterLibraryDlg.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_FilterLibraryDlg.h
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
25 //
26 #ifndef SMESHGUI_FILTERLIBRARYDLG_H
27 #define SMESHGUI_FILTERLIBRARYDLG_H
28
29 // SMESH includes
30 #include "SMESH_SMESHGUI.hxx"
31
32 // Qt includes
33 #include <QDialog>
34 #include <QList>
35 #include <QMap>
36
37 // IDL includes
38 #include <SALOMEconfig.h>
39 #include CORBA_SERVER_HEADER(SMESH_Filter)
40
41 class QListWidget;
42 class QListWidgetItem;
43 class QLineEdit;
44 class QPushButton;
45 class SMESHGUI;
46 class SMESHGUI_FilterTable;
47
48 /*
49   Class       : SMESHGUI_FilterLibraryDlg
50   Description : Dialog to specify filters for VTK viewer
51 */
52
53 class SMESHGUI_EXPORT SMESHGUI_FilterLibraryDlg : public QDialog
54
55   Q_OBJECT
56   
57   // Buttons
58   enum { BTN_OK, BTN_Cancel, BTN_Apply, BTN_Close, BTN_Help };
59
60   class Dialog;
61   
62 public:
63   
64   // Mode
65   enum { ADD_TO, COPY_FROM, EDIT };
66     
67 public:
68   SMESHGUI_FilterLibraryDlg( SMESHGUI*, QWidget*, const QList<int>&, const int );
69   SMESHGUI_FilterLibraryDlg( SMESHGUI*, QWidget*, const int, const int );
70   virtual ~SMESHGUI_FilterLibraryDlg();
71                             
72   void                        Init( const QList<int>&, const int );
73   void                        Init( const int, const int );
74   
75   const SMESHGUI_FilterTable* GetTable() const;
76   void                        SetTable( const SMESHGUI_FilterTable* );
77
78 private:
79   void                        closeEvent( QCloseEvent* );
80   void                        enterEvent( QEvent* );            
81   void                        keyPressEvent( QKeyEvent* );
82   
83 private slots:
84   void                        onOk();
85   bool                        onApply();
86   void                        onClose();
87   void                        onHelp();
88
89   void                        onDeactivate();
90   
91   void                        onBrowse();
92   void                        onReturnPressed();
93   void                        onFilterChanged();
94   void                        onAddBtnPressed();
95   void                        onDeleteBtnPressed();
96   void                        onFilterNameChanged( const QString& );
97   void                        onEntityTypeChanged( const int );
98   void                        onNeedValidation();
99
100 private:
101   void                        construct( const QList<int>&, const int ); 
102   QWidget*                    createButtonFrame( QWidget* );
103   QWidget*                    createMainFrame( QWidget* );
104   bool                        isValid( const bool = true ) const;
105   bool                        isNameValid( const bool = true ) const;
106   SMESH::Filter_ptr           createFilter( const int = -1 );
107   QStringList                 prepareFilters() const;
108   QString                     autoExtension( const QString& ) const;
109   bool                        setSelected( const QString& );
110   int                         getIndex( const QString& ) const;
111   void                        updateControlsVisibility();
112   void                        updateMainButtons();
113   void                        enableMainButtons();
114   void                        processNewLibrary();
115   QString                     getFileName() const;
116   void                        setFileName( const QString&, const bool = true );
117   QStringList                 filterWildCards( const QString& ) const;
118   QString&                    getDefaultLibraryName() const;
119   QString                     getDefaultFilterName() const;
120   void                        addFilterToLib( const QString& );
121   void                        updateList();
122   bool                        isPermissionValid( const bool );
123
124 private:
125
126   QWidget*                    myMainFrame;
127   QMap<int, QPushButton*>     myButtons;
128   SMESHGUI_FilterTable*       myTable;
129   QLineEdit*                  myFileName;
130   QPushButton*                myOpenBtn;
131   QListWidget*                myListBox;
132   QPushButton*                myAddBtn;
133   QPushButton*                myDeleteBtn;
134   QWidget*                    myNameGrp;
135   QLineEdit*                  myName;
136   SMESHGUI*                   mySMESHGUI;
137
138   QList<int>                  myTypes;
139   int                         myMode;
140       
141   SMESH::FilterLibrary_var    myLibrary;
142   QString                     myCurrFilterName;
143   int                         myCurrFilter;
144
145   QString                     myHelpFileName;
146 };
147
148 #endif // SMESHGUI_FILTERLIBRARYDLG_H