Salome HOME
PR: synchro V7_main tag mergefrom_V6_main_28Feb13
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
index 6ba1d4a79299f4419541b16d8f4abfdddfe4c7b1..8081aec6994a7fc7434a3bc348862eb79a556db0 100755 (executable)
-//  SMESH SMESHGUI : GUI for SMESH component\r
-//\r
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
-// \r
-//  This library is free software; you can redistribute it and/or \r
-//  modify it under the terms of the GNU Lesser General Public \r
-//  License as published by the Free Software Foundation; either \r
-//  version 2.1 of the License. \r
-// \r
-//  This library is distributed in the hope that it will be useful, \r
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of \r
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU \r
-//  Lesser General Public License for more details. \r
-// \r
-//  You should have received a copy of the GNU Lesser General Public \r
-//  License along with this library; if not, write to the Free Software \r
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA \r
-// \r
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
-//\r
-//\r
-//\r
-//  File   : SMESHGUI_FilterDlg.h\r
-//  Author : Sergey LITONIN\r
-//  Module : SMESH\r
-\r
-\r
-#ifndef SMESHGUI_FilterDlg_H\r
-#define SMESHGUI_FilterDlg_H\r
-\r
-#include <qdialog.h>\r
-#include <qmap.h>\r
-#include <qvaluelist.h>\r
-#include <SALOME_Selection.h>\r
-\r
-#include <SALOMEconfig.h>\r
-#include CORBA_SERVER_HEADER(SMESH_Filter)\r
-#include CORBA_SERVER_HEADER(SMESH_Mesh)\r
-\r
-class QCloseEvent;\r
-class QWidgetStack;\r
-class QStringList;\r
-class QTableItem;\r
-class QFrame;\r
-class QEvent;\r
-class QPushButton;\r
-class QTable;\r
-class SALOME_Selection;\r
-class SMESHGUI;\r
-class QComboBox;\r
-class QButtonGroup;\r
-class QCheckBox;\r
-class QGroupBox;\r
-\r
-\r
-/*\r
-  Class       : SMESHGUI_FilterDlg\r
-  Description : Dialog to specify filters for VTK viewer\r
-*/\r
-\r
-class SMESHGUI_FilterDlg : public QDialog\r
-{ \r
-  Q_OBJECT\r
-\r
-  class Table;\r
-\r
-  // Edge criteria\r
-  enum { FreeBorders = 0, MultiBorders, Length }; \r
-\r
-  // Face criteria\r
-  enum { AspectRatio = 0, Warping, MinimumAngle, Taper, Skew, Area }; \r
-\r
-  // Comparision\r
-  enum { LessThan = 0, MoreThan, EqualTo };\r
-\r
-  // Logical operations\r
-  enum { LO_And = 0, LO_Or, LO_Undefined };\r
-\r
-  // Source elements to be selected\r
-  enum { Mesh, Selection, Dialog, None };\r
-\r
-  typedef QMap<int, Table*> TableMap;\r
-\r
-public:\r
-                            SMESHGUI_FilterDlg( QWidget*    parent, \r
-                                                const int   type,\r
-                                                const bool  theModal = true,\r
-                                                const char* name = 0 );\r
-  virtual                   ~SMESHGUI_FilterDlg();\r
-\r
-  void                      Init( const int type );\r
-\r
-  void                      SetSelection( SALOME_Selection* );\r
-  void                      SetMesh( SMESH::SMESH_Mesh_ptr );\r
-  void                      SetSourceWg( QWidget* );\r
-\r
-private slots:\r
-\r
-  void                      onAddBtn();\r
-  void                      onRemoveBtn();\r
-  void                      onClearBtn();\r
-  void                      onCriterionChanged( int, int );\r
-\r
-  void                      onOk();\r
-  bool                      onApply();\r
-  void                      onClose();\r
-  void                      onDeactivate();\r
-\r
-private:\r
-\r
-  void                      closeEvent( QCloseEvent* e );\r
-  void                      enterEvent ( QEvent * );\r
-\r
-  void                      updateBtnState();\r
-\r
-  // dialog creation\r
-  QFrame*                   createButtonFrame( QWidget*, const bool );\r
-  QFrame*                   createMainFrame( QWidget* );\r
-  Table*                    createTable( QWidget*, const int );\r
-  QButtonGroup*             createSourceGroup( QWidget* );\r
-  void                      addRow( Table*, const int );\r
-  QTableItem*               getCriterionItem( QTable*, const int );\r
-  QTableItem*               getCompareItem( QTable* );\r
-  QTableItem*               getNotItem( QTable* );\r
-  QTableItem*               getLogOpItem( QTable* );\r
-  const QStringList&        getCriteria( const int theType ) const;\r
-  const QStringList&        getCompare () const;\r
-  \r
-  // query\r
-  int                       getCurrType() const;\r
-  int                       getCriterion( const int theType, const int theRow ) const;\r
-\r
-  // execution\r
-  bool                      isValid() const;\r
-  SMESH::Predicate_ptr      createPredicate( const int theType );\r
-  void                      insertFilterInViewer( SMESH::Predicate_ptr thePred );\r
-  void                      selectInViewer( const int theType,\r
-                                            const QValueList<int>& theIds );\r
-  void                      filterSource( const int            theType,\r
-                                          SMESH::Predicate_ptr thePred,\r
-                                          QValueList<int>&     theResIds );\r
-  void                      filterSelectionSource( const int            theType,\r
-                                                   SMESH::Predicate_ptr thePred,\r
-                                                   QValueList<int>&     theResIds );\r
-  void                      getIdsFromWg( const QWidget*, QValueList<int>& ) const;\r
-  void                      setIdsToWg( QWidget*, const QValueList<int>& );\r
-  Selection_Mode            getSelMode( const int ) const;\r
-\r
-private:\r
-\r
-  // widgets\r
-  QFrame*                   myMainFrame;\r
-  QGroupBox*                myTableGrp;\r
-\r
-  TableMap                  myTables;\r
-  QPushButton*              myAddBtn;\r
-  QPushButton*              myRemoveBtn;\r
-  QPushButton*              myClearBtn;\r
-  QButtonGroup*             mySourceGrp;\r
-  QCheckBox*                mySetInViewer;\r
-\r
-  QPushButton*              myOkBtn;\r
-  QPushButton*              myApplyBtn;\r
-  QPushButton*              myCloseBtn;\r
-\r
-  // initial fields\r
-  int                       myType;\r
-  SMESHGUI*                 mySMESHGUI;\r
-  SALOME_Selection*         mySelection;\r
-  SMESH::SMESH_Mesh_ptr     myMesh;\r
-  QWidget*                  mySourceWg;\r
-};\r
-\r
-#endif\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+// SMESH SMESHGUI : GUI for SMESH component
+// File   : SMESHGUI_FilterDlg.h
+// Author : Sergey LITONIN, Open CASCADE S.A.S.
+//
+#ifndef SMESHGUI_FILTERDLG_H
+#define SMESHGUI_FILTERDLG_H
+
+// SMESH includes
+#include "SMESH_SMESHGUI.hxx"
+
+// Qt includes
+#include <QWidget>
+#include <QDialog>
+#include <QMap>
+#include <QList>
+
+// SALOME GUI includes
+#include <SALOME_DataMapOfIOMapOfInteger.hxx>
+#include <SVTK_Selection.h>
+
+// IDL includes
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(SMESH_Filter)
+#include CORBA_SERVER_HEADER(SMESH_Mesh)
+
+class QFrame;
+class QButtonGroup;
+class QCheckBox;
+class QGroupBox;
+class QPushButton;
+class QTableWidget;
+class QTableWidgetItem;
+class QStackedWidget;
+class LightApp_SelectionMgr;
+class SMESHGUI;
+class SMESHGUI_FilterLibraryDlg;
+class SVTK_Selector;
+
+/*!
+ *  Class       : SMESHGUI_FilterTable
+ *  Description : Frame containig 
+ *                  - Button group for switching entity type
+ *                  - Table for displaying filter criterions
+ *                  - Buttons for editing table
+ */
+
+class SMESHGUI_EXPORT SMESHGUI_FilterTable : public QWidget
+{
+  Q_OBJECT
+
+  class Table;
+  class ComboItem;
+  class IntSpinItem;
+  class DoubleSpinItem;
+  class CheckItem;
+  class AdditionalWidget;
+  class ComboDelegate;
+
+  typedef QMap<int, Table*> TableMap;
+
+public:  
+  SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const int );
+  SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const QList<int>& );
+  virtual ~SMESHGUI_FilterTable();
+
+  void                      Init( const QList<int>& );
+
+  QGroupBox*                GetTableGrp();
+
+  bool                      IsValid( const bool = true, const int = -1 ) const;
+  int                       GetType() const;
+  void                      SetType(const int);
+  void                      RestorePreviousEntityType();
+  int                       NumRows( const int = -1 ) const;
+  void                      Clear( const int = -1 );
+  void                      SetEditable( const bool );
+  void                      SetEnabled( const bool );
+  void                      SetLibsEnabled( const bool );
+  bool                      IsEditable() const;
+
+  int                       GetCriterionType( const int, const int = -1 ) const;
+
+  void                      GetCriterion( const int,
+                                          SMESH::Filter::Criterion&,
+                                          const int = -1 ) const;
+
+  void                      SetCriterion( const int,
+                                          const SMESH::Filter::Criterion&,
+                                          const int = -1 );
+
+  void                      AddCriterion( const SMESH::Filter::Criterion&,
+                                          const int = -1 );
+
+  void                      Copy( const SMESHGUI_FilterTable* );
+  void                      SetValidity( const bool );
+
+  bool                      CurrentCell( int&, int& ) const;
+  void                      SetThreshold( const int,
+                                          const QString&,
+                                          const int = -1 );
+
+  bool                      GetThreshold( const int,
+                                          QString&,
+                                          const int = -1 );
+
+  void                      SetID( const int,
+                                   const QString&,
+                                   const int = -1 ); 
+  
+  bool                      GetID( const int,
+                                   QString&,
+                                   const int = -1 );
+
+  void                      Update();
+
+signals:
+  void                      CopyFromClicked();
+  void                      AddToClicked();
+  void                      EntityTypeChanged( const int );
+  void                      NeedValidation();
+  void                      CriterionChanged( const int, const int );
+  void                      CurrentChanged( int, int );
+
+private slots:
+  void                      onAddBtn();
+  void                      onInsertBtn();
+  void                      onRemoveBtn();
+  void                      onClearBtn();
+  void                      onCopyFromBtn();
+  void                      onAddToBtn();
+  void                      onCriterionChanged( int, int );
+  void                      onEntityType( int );
+  void                      onCurrentChanged( int, int );
+
+private:
+  void                      addRow( Table*, const int, const bool = true );
+  QTableWidgetItem*         getCriterionItem( const int ) const;
+  QTableWidgetItem*         getCompareItem() const;
+  QTableWidgetItem*         getUnaryItem() const;
+  QTableWidgetItem*         getBinaryItem() const;
+  const QMap<int, QString>& getCriteria( const int ) const;
+  const QMap<int, QString>& getCompare() const;
+  Table*                    createTable( QWidget*, const int );
+  QWidget*                  createAdditionalFrame( QWidget* );
+  int                       getFirstSelectedRow() const;
+  void                      onCriterionChanged( const int, const int, const int );
+
+  void                      updateBtnState();
+  void                      removeAdditionalWidget( QTableWidget*, const int );
+  void                      updateAdditionalWidget();
+  const char*               getPrecision( const int );
+
+  const QMap<int, QString>& getSupportedTypes() const;
+
+private:
+  SMESHGUI*                 mySMESHGUI;
+
+  QGroupBox*                myTableGrp;
+  QWidget*                  mySwitchTableGrp;
+
+  TableMap                  myTables;
+  QPushButton*              myAddBtn;
+  QPushButton*              myInsertBtn;
+  QPushButton*              myRemoveBtn;
+  QPushButton*              myClearBtn;  
+  QPushButton*              myCopyFromBtn;  
+  QPushButton*              myAddToBtn;
+
+  QGroupBox*                myEntityTypeBox;
+  QButtonGroup*             myEntityTypeGrp;
+  int                       myEntityType;
+  int                       myIsValid;
+  bool                      myIsLocked;
+
+  SMESHGUI_FilterLibraryDlg* myLibDlg;
+
+  QStackedWidget*           myWgStack;
+
+  QMap<QTableWidgetItem*, AdditionalWidget*> myAddWidgets;
+};
+
+
+/*!
+ *  Class       : SMESHGUI_FilterDlg
+ *  Description : Dialog to specify filters for VTK viewer
+ */
+
+class SMESHGUI_FilterDlg : public QDialog
+{
+  Q_OBJECT
+
+  // Source elements to be selected
+  enum { Mesh, Selection, Dialog, None };
+
+  // Buttons
+  enum { BTN_OK, BTN_Apply, BTN_Close, BTN_Help };
+
+public:
+  SMESHGUI_FilterDlg( SMESHGUI*, const QList<int>& );
+  SMESHGUI_FilterDlg( SMESHGUI*, const int );
+  virtual ~SMESHGUI_FilterDlg();
+
+  void                      Init( const QList<int>&, const bool setInViewer=true );
+  void                      Init( const int, const bool setInViewer=true );
+
+  void                      SetSelection();
+  void                      SetMesh (SMESH::SMESH_Mesh_var);
+  void                      SetSourceWg( QWidget*, const bool initOnApply = true );
+
+  static SMESH::Filter::Criterion createCriterion();
+
+  SMESH::Filter_var         GetFilter() const;
+  void                      SetFilter(SMESH::Filter_var filter, int type);
+
+signals:
+
+  void                      Accepted();
+
+protected slots:
+  virtual void              reject();
+
+private slots:
+
+  void                      onOk();
+  bool                      onApply();
+  void                      onHelp();
+  void                      onDeactivate();
+  void                      onSelectionDone();
+  void                      onCriterionChanged( const int, const int );
+  void                      onCurrentChanged( int, int );
+
+private:
+
+  void                      construct( const QList<int>& ); 
+
+  void                      enterEvent( QEvent* );
+  void                      keyPressEvent( QKeyEvent* );
+
+  // dialog creation
+  QWidget*                  createButtonFrame( QWidget* );
+  QWidget*                  createMainFrame( QWidget* );
+  QWidget*                  createSourceGroup( QWidget* );
+  void                      updateMainButtons();
+
+  // execution
+  bool                      isValid() const;
+  bool                      createFilter( const int );
+  void                      insertFilterInViewer();
+  void                      selectInViewer( const int, const QList<int>& );
+  void                      filterSource( const int, QList<int>& );
+  void                      filterSelectionSource( const int, QList<int>& );
+  void                      getIdsFromWg( const QWidget*, QList<int>& ) const;
+  void                      setIdsToWg( QWidget*, const QList<int>& );
+  Selection_Mode            getSelMode( const int ) const;
+  void                      updateSelection();
+
+private:
+  // widgets
+  QWidget*                  myMainFrame;
+  QButtonGroup*             mySourceGrp;
+
+  QCheckBox*                mySetInViewer;
+
+  QMap<int, QPushButton*>   myButtons;
+  
+  SMESHGUI_FilterTable*     myTable;
+
+  // initial fields
+  QList<int>                myTypes;
+  SMESHGUI*                 mySMESHGUI;
+  LightApp_SelectionMgr*    mySelectionMgr;
+  SVTK_Selector*            mySelector;
+  SMESH::SMESH_Mesh_var     myMesh;
+  bool                      myInitSourceWgOnApply;
+  QWidget*                  mySourceWg;
+
+  SALOME_DataMapOfIOMapOfInteger myIObjects;
+  bool                           myIsSelectionChanged;
+  QMap< int, SMESH::Filter_var > myFilter;
+  QMap< int, bool >              myInsertState;
+  QMap< int, int  >              myApplyToState;
+
+  QString                   myHelpFileName;
+};
+
+#endif // SMESHGUI_FILTERDLG_H