Salome HOME
Merge remote-tracking branch 'origin/master' into V8_5_BR
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterLibraryDlg.cxx
index 0a2ec7b6663e1d82fd262458c05ca6ad2b280eae..2972d8cda38fadd75a7ef840350523c3e19806ac 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
@@ -6,7 +6,7 @@
 // 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.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -30,6 +30,9 @@
 #include "SMESHGUI.h"
 #include "SMESHGUI_FilterUtils.h"
 #include "SMESHGUI_FilterDlg.h"
+#include "SMESHGUI_VTKUtils.h"
+
+#include <GEOMBase.h>
 
 // SALOME GUI includes
 #include <SUIT_Session.h>
@@ -37,8 +40,9 @@
 #include <SUIT_FileDlg.h>
 #include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
-
 #include <LightApp_Application.h>
+#include <LightApp_SelectionMgr.h>
+#include <SALOME_ListIO.hxx>
 
 // Qt includes
 #include <QApplication>
@@ -149,7 +153,7 @@ void SMESHGUI_FilterLibraryDlg::construct (const QList<int>& theTypes,
 
   aDlgLay->setStretchFactor(myMainFrame, 1);
 
-  myHelpFileName = "selection_filter_library_page.html";
+  myHelpFileName = "selection_filter_library.html";
   
   Init(myTypes, myMode);
 }
@@ -233,13 +237,16 @@ QWidget* SMESHGUI_FilterLibraryDlg::createMainFrame (QWidget* theParent)
   connect(myDeleteBtn, SIGNAL(clicked()), this, SLOT(onDeleteBtnPressed()));
 
   connect(myName, SIGNAL(textChanged(const QString&)),
-           this, SLOT(onFilterNameChanged(const QString&)));
+          this, SLOT(onFilterNameChanged(const QString&)));
 
   connect(myTable, SIGNAL(EntityTypeChanged(const int)),
-           this, SLOT(onEntityTypeChanged(const int)));
+          this, SLOT(onEntityTypeChanged(const int)));
 
   connect(myTable, SIGNAL(NeedValidation()), this, SLOT(onNeedValidation()));
 
+  LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( mySMESHGUI );
+  connect( selMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
+
   return aMainFrame;
 }
 
@@ -466,8 +473,11 @@ bool SMESHGUI_FilterLibraryDlg::onApply()
 //=======================================================================
 void SMESHGUI_FilterLibraryDlg::onOk()
 {
-  if (onApply())
-    reject();
+  if (onApply()) {
+    disconnect( mySMESHGUI, 0, this, 0);
+    mySMESHGUI->ResetState();
+    accept();
+  }
 }
 
 //=======================================================================
@@ -507,7 +517,7 @@ void SMESHGUI_FilterLibraryDlg::onHelp()
 
 //=======================================================================
 // name    : SMESHGUI_FilterLibraryDlg::onDeactivate
-// Purpose : SLOT called when dialog must be deativated
+// Purpose : SLOT called when dialog must be deactivated
 //=======================================================================
 void SMESHGUI_FilterLibraryDlg::onDeactivate()
 {
@@ -592,7 +602,7 @@ QStringList SMESHGUI_FilterLibraryDlg::prepareFilters() const
 
 //================================================================
 // Function : onBrowse
-// Purpose  : SLOT. Display "Open file" dialog for chosing library name
+// Purpose  : SLOT. Display "Open file" dialog for choosing library name
 //================================================================
 void SMESHGUI_FilterLibraryDlg::onBrowse()
 {
@@ -601,7 +611,7 @@ void SMESHGUI_FilterLibraryDlg::onBrowse()
 
   //aDlg->setMode(myMode == COPY_FROM ? QFileDialogP::ExistingFile : QFileDialogP::AnyFile);
   aDlg->setFileMode(myMode == COPY_FROM ? QFileDialog::ExistingFile : QFileDialog::AnyFile);
-  aDlg->setFilters(prepareFilters());
+  aDlg->setNameFilters(prepareFilters());
   aDlg->selectFile(getFileName());
 
   QPushButton* anOkBtn = (QPushButton*)aDlg->findChild<QPushButton*>("OK");
@@ -619,8 +629,8 @@ void SMESHGUI_FilterLibraryDlg::onBrowse()
   if (QFileInfo(fName).suffix().isEmpty())
     fName = autoExtension(fName);
 
-  fName = QDir::convertSeparators(fName);
-  QString prev = QDir::convertSeparators(getFileName());
+  fName = QDir::toNativeSeparators(fName);
+  QString prev = QDir::toNativeSeparators(getFileName());
 
   if (prev == fName)
     return;
@@ -746,7 +756,7 @@ bool SMESHGUI_FilterLibraryDlg::isPermissionValid(const bool theIsExistingOnly)
   if (QFileInfo(fName).suffix().isEmpty())
     fName = autoExtension(fName);
 
-  fName = QDir::convertSeparators(fName);
+  fName = QDir::toNativeSeparators(fName);
 
   if (QFileInfo(fName).exists()) {
     isWritable = QFileInfo(fName).isWritable();
@@ -1176,6 +1186,77 @@ void SMESHGUI_FilterLibraryDlg::onNeedValidation()
   }
 }
 
+
+//=======================================================================
+// name    : SMESHGUI_FilterLibraryDlg::onSelectionDone
+// Purpose : SLOT called when selection changed.
+//           If current cell corresponds to the threshold value of
+//           BelongToGeom criterion name of selected object is set in this cell
+//=======================================================================
+
+void SMESHGUI_FilterLibraryDlg::onSelectionDone()
+{
+  SALOME_ListIO aList;
+  if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
+    aSel->selectedObjects( aList );
+
+  int aRow, aCol;
+  if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol))
+    return;
+
+  const int type = myTable->GetCriterionType(aRow);
+  QList<int> types;
+  types << SMESH::FT_BelongToGeom      << SMESH::FT_BelongToPlane 
+        << SMESH::FT_BelongToCylinder  << SMESH::FT_BelongToGenSurface
+        << SMESH::FT_LyingOnGeom       << SMESH::FT_CoplanarFaces
+        << SMESH::FT_ConnectedElements << SMESH::FT_BelongToMeshGroup;
+  if ( !types.contains( type ))
+    return;
+
+  Handle(SALOME_InteractiveObject) anIO = aList.First();
+  switch ( type )
+  {
+  case SMESH::FT_CoplanarFaces: // get ID of a selected mesh face
+    {
+      QString aString;
+      int nbElems = SMESH::GetNameOfSelectedElements(SMESH::GetSelector(), anIO, aString);
+      if (nbElems == 1)
+        myTable->SetThreshold(aRow, aString);
+      break;
+    }
+  case SMESH::FT_ConnectedElements: // get either VERTEX or a node ID
+    {
+      GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
+      if (!anObj->_is_nil())
+      {
+        myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+        myTable->SetID       (aRow, anIO->getEntry());
+      }
+      else
+      {
+        QString aString;
+        int nbElems = SMESH::GetNameOfSelectedElements(SMESH::GetSelector(), anIO, aString);
+        if (nbElems == 1)
+          myTable->SetThreshold(aRow, aString);
+      }
+      break;
+    }
+  case SMESH::FT_BelongToMeshGroup: // get a group name and IOR
+    {
+      myTable->SetThreshold(aRow, anIO->getName() );
+    }
+  default: // get a GEOM object
+    {
+      GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
+      if (!anObj->_is_nil())
+      {
+        myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+        myTable->SetID       (aRow, anIO->getEntry());
+      }
+    }
+  }
+}
+
 //=================================================================================
 // function : keyPressEvent()
 // purpose  :