Back to index

salome-smesh  6.5.0
SMESHGUI_FilterDlg.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_FilterDlg.h
00025 // Author : Sergey LITONIN, Open CASCADE S.A.S.
00026 //
00027 #ifndef SMESHGUI_FILTERDLG_H
00028 #define SMESHGUI_FILTERDLG_H
00029 
00030 // SMESH includes
00031 #include "SMESH_SMESHGUI.hxx"
00032 
00033 // Qt includes
00034 #include <QWidget>
00035 #include <QDialog>
00036 #include <QMap>
00037 #include <QList>
00038 
00039 // SALOME GUI includes
00040 #include <SALOME_DataMapOfIOMapOfInteger.hxx>
00041 #include <SVTK_Selection.h>
00042 
00043 // IDL includes
00044 #include <SALOMEconfig.h>
00045 #include CORBA_SERVER_HEADER(SMESH_Filter)
00046 #include CORBA_SERVER_HEADER(SMESH_Mesh)
00047 
00048 class QFrame;
00049 class QButtonGroup;
00050 class QCheckBox;
00051 class QGroupBox;
00052 class QPushButton;
00053 class QTableWidget;
00054 class QTableWidgetItem;
00055 class QStackedWidget;
00056 class LightApp_SelectionMgr;
00057 class SMESHGUI;
00058 class SMESHGUI_FilterLibraryDlg;
00059 class SVTK_Selector;
00060 
00069 class SMESHGUI_EXPORT SMESHGUI_FilterTable : public QWidget
00070 {
00071   Q_OBJECT
00072 
00073   class Table;
00074   class ComboItem;
00075   class IntSpinItem;
00076   class DoubleSpinItem;
00077   class CheckItem;
00078   class AdditionalWidget;
00079   class ComboDelegate;
00080 
00081   typedef QMap<int, Table*> TableMap;
00082 
00083 public:  
00084   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const int );
00085   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const QList<int>& );
00086   virtual ~SMESHGUI_FilterTable();
00087 
00088   void                      Init( const QList<int>& );
00089 
00090   QGroupBox*                GetTableGrp();
00091 
00092   bool                      IsValid( const bool = true, const int = -1 ) const;
00093   int                       GetType() const;
00094   void                      SetType(const int);
00095   void                      RestorePreviousEntityType();
00096   int                       NumRows( const int = -1 ) const;
00097   void                      Clear( const int = -1 );
00098   void                      SetEditable( const bool );
00099   void                      SetEnabled( const bool );
00100   void                      SetLibsEnabled( const bool );
00101   bool                      IsEditable() const;
00102 
00103   int                       GetCriterionType( const int, const int = -1 ) const;
00104 
00105   void                      GetCriterion( const int,
00106                                           SMESH::Filter::Criterion&,
00107                                           const int = -1 ) const;
00108 
00109   void                      SetCriterion( const int,
00110                                           const SMESH::Filter::Criterion&,
00111                                           const int = -1 );
00112 
00113   void                      AddCriterion( const SMESH::Filter::Criterion&,
00114                                           const int = -1 );
00115 
00116   void                      Copy( const SMESHGUI_FilterTable* );
00117   void                      SetValidity( const bool );
00118 
00119   bool                      CurrentCell( int&, int& ) const;
00120   void                      SetThreshold( const int,
00121                                           const QString&,
00122                                           const int = -1 );
00123 
00124   bool                      GetThreshold( const int,
00125                                           QString&,
00126                                           const int = -1 );
00127 
00128   void                      SetID( const int,
00129                                    const QString&,
00130                                    const int = -1 ); 
00131   
00132   bool                      GetID( const int,
00133                                    QString&,
00134                                    const int = -1 );
00135 
00136   void                      Update();
00137 
00138 signals:
00139   void                      CopyFromClicked();
00140   void                      AddToClicked();
00141   void                      EntityTypeChanged( const int );
00142   void                      NeedValidation();
00143   void                      CriterionChanged( const int, const int );
00144   void                      CurrentChanged( int, int );
00145 
00146 private slots:
00147   void                      onAddBtn();
00148   void                      onInsertBtn();
00149   void                      onRemoveBtn();
00150   void                      onClearBtn();
00151   void                      onCopyFromBtn();
00152   void                      onAddToBtn();
00153   void                      onCriterionChanged( int, int );
00154   void                      onEntityType( int );
00155   void                      onCurrentChanged( int, int );
00156 
00157 private:
00158   void                      addRow( Table*, const int, const bool = true );
00159   QTableWidgetItem*         getCriterionItem( const int ) const;
00160   QTableWidgetItem*         getCompareItem() const;
00161   QTableWidgetItem*         getUnaryItem() const;
00162   QTableWidgetItem*         getBinaryItem() const;
00163   const QMap<int, QString>& getCriteria( const int ) const;
00164   const QMap<int, QString>& getCompare() const;
00165   Table*                    createTable( QWidget*, const int );
00166   QWidget*                  createAdditionalFrame( QWidget* );
00167   int                       getFirstSelectedRow() const;
00168   void                      onCriterionChanged( const int, const int, const int );
00169 
00170   void                      updateBtnState();
00171   void                      removeAdditionalWidget( QTableWidget*, const int );
00172   void                      updateAdditionalWidget();
00173   const char*               getPrecision( const int );
00174 
00175   const QMap<int, QString>& getSupportedTypes() const;
00176 
00177 private:
00178   SMESHGUI*                 mySMESHGUI;
00179 
00180   QGroupBox*                myTableGrp;
00181   QWidget*                  mySwitchTableGrp;
00182 
00183   TableMap                  myTables;
00184   QPushButton*              myAddBtn;
00185   QPushButton*              myInsertBtn;
00186   QPushButton*              myRemoveBtn;
00187   QPushButton*              myClearBtn;  
00188   QPushButton*              myCopyFromBtn;  
00189   QPushButton*              myAddToBtn;
00190 
00191   QGroupBox*                myEntityTypeBox;
00192   QButtonGroup*             myEntityTypeGrp;
00193   int                       myEntityType;
00194   int                       myIsValid;
00195   bool                      myIsLocked;
00196 
00197   SMESHGUI_FilterLibraryDlg* myLibDlg;
00198 
00199   QStackedWidget*           myWgStack;
00200 
00201   QMap<QTableWidgetItem*, AdditionalWidget*> myAddWidgets;
00202 };
00203 
00204 
00210 class SMESHGUI_FilterDlg : public QDialog
00211 {
00212   Q_OBJECT
00213 
00214   // Source elements to be selected
00215   enum { Mesh, Selection, Dialog, None };
00216 
00217   // Buttons
00218   enum { BTN_OK, BTN_Apply, BTN_Close, BTN_Help };
00219 
00220 public:
00221   SMESHGUI_FilterDlg( SMESHGUI*, const QList<int>& );
00222   SMESHGUI_FilterDlg( SMESHGUI*, const int );
00223   virtual ~SMESHGUI_FilterDlg();
00224 
00225   void                      Init( const QList<int>& );
00226   void                      Init( const int );
00227 
00228   void                      SetSelection();
00229   void                      SetMesh (SMESH::SMESH_Mesh_var);
00230   void                      SetSourceWg( QWidget*, const bool initOnApply = true );
00231 
00232   static SMESH::Filter::Criterion createCriterion();
00233 
00234   SMESH::Filter_var         GetFilter() const;
00235   void                      SetFilter(SMESH::Filter_var filter, int type);
00236 
00237 signals:
00238 
00239   void                      Accepted();
00240 
00241 private slots:
00242 
00243   void                      onOk();
00244   bool                      onApply();
00245   void                      onClose();
00246   void                      onHelp();
00247   void                      onDeactivate();
00248   void                      onSelectionDone();
00249   void                      onCriterionChanged( const int, const int );
00250   void                      onCurrentChanged( int, int );
00251 
00252 private:
00253 
00254   void                      construct( const QList<int>& ); 
00255 
00256   void                      closeEvent( QCloseEvent* );
00257   void                      enterEvent( QEvent* );
00258   void                      keyPressEvent( QKeyEvent* );
00259 
00260   // dialog creation
00261   QWidget*                  createButtonFrame( QWidget* );
00262   QWidget*                  createMainFrame( QWidget* );
00263   QWidget*                  createSourceGroup( QWidget* );
00264   void                      updateMainButtons();
00265 
00266   // execution
00267   bool                      isValid() const;
00268   bool                      createFilter( const int );
00269   void                      insertFilterInViewer();
00270   void                      selectInViewer( const int, const QList<int>& );
00271   void                      filterSource( const int, QList<int>& );
00272   void                      filterSelectionSource( const int, QList<int>& );
00273   void                      getIdsFromWg( const QWidget*, QList<int>& ) const;
00274   void                      setIdsToWg( QWidget*, const QList<int>& );
00275   Selection_Mode            getSelMode( const int ) const;
00276   void                      updateSelection();
00277 
00278 private:
00279   // widgets
00280   QWidget*                  myMainFrame;
00281   QButtonGroup*             mySourceGrp;
00282 
00283   QCheckBox*                mySetInViewer;
00284 
00285   QMap<int, QPushButton*>   myButtons;
00286   
00287   SMESHGUI_FilterTable*     myTable;
00288 
00289   // initial fields
00290   QList<int>                myTypes;
00291   SMESHGUI*                 mySMESHGUI;
00292   LightApp_SelectionMgr*    mySelectionMgr;
00293   SVTK_Selector*            mySelector;
00294   SMESH::SMESH_Mesh_var     myMesh;
00295   bool                      myInitSourceWgOnApply;
00296   QWidget*                  mySourceWg;
00297 
00298   SALOME_DataMapOfIOMapOfInteger myIObjects;
00299   bool                           myIsSelectionChanged;
00300   QMap< int, SMESH::Filter_var > myFilter;
00301   QMap< int, bool >              myInsertState;
00302   QMap< int, int  >              myApplyToState;
00303 
00304   QString                   myHelpFileName;
00305 };
00306 
00307 #endif // SMESHGUI_FILTERDLG_H