Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.cxx
index 49d6ff7958aef493981cf9e0bbc59d007e455ea7..db1157c1def671fdb90df45d46b81581c3ade246 100755 (executable)
@@ -17,7 +17,7 @@
 //  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 
 #include "SUIT_Desktop.h"
 #include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
 
-#include "SalomeApp_Application.h"
+#include "LightApp_Application.h"
 #include "SalomeApp_Tools.h"
 #include "SalomeApp_Study.h"
 
@@ -428,7 +430,7 @@ QString SMESHGUI_FilterTable::Table::text (int row, int col) const
 // Purpose : Constructor
 //=======================================================================
 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
-                                           QWidget* parent,
+                                            QWidget* parent,
                                             const int type)
 : QFrame(parent),
   myIsLocked( false ),
@@ -443,7 +445,7 @@ SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
 // Purpose : Constructor
 //=======================================================================
 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
-                                           QWidget* parent,
+                                            QWidget* parent,
                                             const QValueList<int>& types)
 : QFrame(parent),
   myIsLocked( false ),
@@ -674,7 +676,8 @@ bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType)
          aCriterion == FT_BelongToGeom ||
          aCriterion == FT_BelongToPlane ||
          aCriterion == FT_BelongToCylinder ||
-        aCriterion == FT_LyingOnGeom) {
+         aCriterion == FT_BelongToGenSurface ||
+         aCriterion == FT_LyingOnGeom) {
       if (aTable->text(i, 2).isEmpty()) {
         if (theMess)
           QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
@@ -784,13 +787,18 @@ void SMESHGUI_FilterTable::GetCriterion (const int                 theRow,
        aCriterionType != FT_BelongToGeom &&
        aCriterionType != FT_BelongToPlane &&
        aCriterionType != FT_BelongToCylinder &&
+       aCriterionType != FT_BelongToGenSurface &&
        aCriterionType != FT_LyingOnGeom)
   {
     theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->GetValue();
     theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
   }
   else
-    theCriterion.ThresholdStr = aTable->text(theRow, 2).latin1();
+    {
+      theCriterion.ThresholdStr = aTable->text(theRow, 2).latin1();
+      if ( aCriterionType != FT_RangeOfIds )
+       theCriterion.ThresholdID = aTable->text( theRow, 5 ).latin1();
+    }
 
   QTableItem* anItem = aTable->item(theRow, 0);
   if (myAddWidgets.contains(anItem))
@@ -827,17 +835,26 @@ void SMESHGUI_FilterTable::SetCriterion (const int                       theRow,
     aTable->SetEditable(false, theRow, 4);
 
   if (theCriterion.Type != FT_RangeOfIds &&
-       theCriterion.Type != FT_BelongToGeom &&
-       theCriterion.Type != FT_BelongToPlane &&
-       theCriterion.Type != FT_BelongToCylinder &&
-       theCriterion.Type != FT_LyingOnGeom)
+      theCriterion.Type != FT_BelongToGeom &&
+      theCriterion.Type != FT_BelongToPlane &&
+      theCriterion.Type != FT_BelongToCylinder &&
+      theCriterion.Type != FT_BelongToGenSurface &&
+      theCriterion.Type != FT_LyingOnGeom &&
+      theCriterion.Type != FT_FreeBorders &&
+      theCriterion.Type != FT_FreeEdges &&
+      theCriterion.Type != FT_BadOrientedVolume)
     aTable->setText(theRow, 2, QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
   else
-    aTable->setText(theRow, 2, QString(theCriterion.ThresholdStr));
+    {
+      aTable->setText(theRow, 2, QString(theCriterion.ThresholdStr));
+      if ( theCriterion.Type != FT_RangeOfIds )
+       aTable->setText( theRow, 5, QString( theCriterion.ThresholdID ) );
+    }
 
   if (theCriterion.Compare == FT_EqualTo ||
        theCriterion.Type    == FT_BelongToPlane ||
-       theCriterion.Type    == FT_BelongToCylinder)
+       theCriterion.Type    == FT_BelongToCylinder ||
+       theCriterion.Type    == FT_BelongToGenSurface)
   {
     QTableItem* anItem = aTable->item(theRow, 0);
     if (!myAddWidgets.contains(anItem))
@@ -950,7 +967,7 @@ void SMESHGUI_FilterTable::onRemoveBtn()
     if (aTable->isRowSelected(i))
     {
       aRows.resize(aRows.size() + 1);
-      aRows[ aRows.size() - 1 ] = i;
+      aRows[ (int)(aRows.size() - 1) ] = i;
       removeAdditionalWidget(aTable, i);
     }
   }
@@ -984,7 +1001,7 @@ void SMESHGUI_FilterTable::updateAdditionalWidget()
                   GetCriterionType(aRow) != FT_LyingOnGeom &&
                   GetCriterionType(aRow) != FT_RangeOfIds &&
                   GetCriterionType(aRow) != FT_FreeEdges &&
-                 GetCriterionType(aRow) != FT_BadOrientedVolume;
+                  GetCriterionType(aRow) != FT_BadOrientedVolume;
   if (!myAddWidgets.contains(anItem))
   {
     myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
@@ -1065,10 +1082,11 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
     aTable->SetEditable(false, row, 2);
   }
   else if (aCriterionType == SMESH::FT_RangeOfIds ||
-            aCriterionType == SMESH::FT_BelongToGeom ||
-            aCriterionType == SMESH::FT_BelongToPlane ||
-            aCriterionType == SMESH::FT_BelongToCylinder ||
-           aCriterionType == SMESH::FT_LyingOnGeom)
+           aCriterionType == SMESH::FT_BelongToGeom ||
+           aCriterionType == SMESH::FT_BelongToPlane ||
+           aCriterionType == SMESH::FT_BelongToCylinder ||
+           aCriterionType == SMESH::FT_BelongToGenSurface ||
+           aCriterionType == SMESH::FT_LyingOnGeom)
   {
     QMap<int, QString> aMap;
     aMap[ FT_EqualTo ] = tr("EQUAL_TO");
@@ -1262,6 +1280,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_BelongToGeom     ] = tr("BELONG_TO_GEOM");
       aCriteria[ SMESH::FT_BelongToPlane    ] = tr("BELONG_TO_PLANE");
       aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+      aCriteria[ SMESH::FT_BelongToGenSurface]= tr("BELONG_TO_GENSURFACE");
       aCriteria[ SMESH::FT_LyingOnGeom      ] = tr("LYING_ON_GEOM");
     }
     return aCriteria;
@@ -1278,6 +1297,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_BelongToGeom     ] = tr("BELONG_TO_GEOM");
       aCriteria[ SMESH::FT_BelongToPlane    ] = tr("BELONG_TO_PLANE");
       aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+      aCriteria[ SMESH::FT_BelongToGenSurface]= tr("BELONG_TO_GENSURFACE");
       aCriteria[ SMESH::FT_LyingOnGeom      ] = tr("LYING_ON_GEOM");
     }
     return aCriteria;
@@ -1298,6 +1318,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_BelongToGeom     ] = tr("BELONG_TO_GEOM");
       aCriteria[ SMESH::FT_BelongToPlane    ] = tr("BELONG_TO_PLANE");
       aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+      aCriteria[ SMESH::FT_BelongToGenSurface]= tr("BELONG_TO_GENSURFACE");
       aCriteria[ SMESH::FT_LyingOnGeom      ] = tr("LYING_ON_GEOM");
       aCriteria[ SMESH::FT_Length2D         ] = tr("LENGTH2D");
       aCriteria[ SMESH::FT_MultiConnection2D] = tr("MULTI2D_BORDERS");
@@ -1314,6 +1335,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
       aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
       aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
+      aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
     }
     return aCriteria;
   }
@@ -1351,7 +1373,7 @@ SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget*  thePar
                                                                 const int theType)
 {
   // create table
-  Table* aTable= new Table(0, 5, theParent);
+  Table* aTable= new Table(0, 6, theParent);
 
   QHeader* aHeaders = aTable->horizontalHeader();
 
@@ -1382,11 +1404,15 @@ SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget*  thePar
   aHeaders->setLabel(2, tr("THRESHOLD_VALUE"));
   aHeaders->setLabel(3, tr("UNARY"));
   aHeaders->setLabel(4, tr("BINARY") + "  ");
+  aHeaders->setLabel( 5, tr( "ID" ) );
 
   // set geometry of the table
   for (int i = 0; i <= 4; i++)
     aTable->adjustColumn(i);
 
+  // set the ID column invisible
+  aTable->hideColumn( 5 );
+
   aTable->updateGeometry();
   QSize aSize = aTable->sizeHint();
   int aWidth = aSize.width();
@@ -1588,6 +1614,37 @@ bool SMESHGUI_FilterTable::GetThreshold (const int      theRow,
    return false;
 }
 
+//=======================================================================
+// name    : SMESHGUI_FilterTable::SetID
+// Purpose : Set text and internal value in cell of ID value 
+//=======================================================================
+void SMESHGUI_FilterTable::SetID( const int      theRow,
+                                         const QString& theText,
+                                         const int      theEntityType )
+{
+  Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
+  aTable->setText( theRow, 5, theText );
+}
+
+//=======================================================================
+// name    : SMESHGUI_FilterTable::GetID
+// Purpose : Get text and internal value from cell of ID value
+//=======================================================================
+bool SMESHGUI_FilterTable::GetID( const int      theRow,
+                                 QString&       theText,
+                                 const int      theEntityType )
+{
+  Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
+  QTableItem* anItem = aTable->item( theRow, 5 );
+  if ( anItem != 0 )
+    {
+      theText = anItem->text();
+      return true;    
+    }
+  else
+    return false;
+} 
+
 /*
   Class       : SMESHGUI_FilterDlg
   Description : Dialog to specify filters for VTK viewer
@@ -1608,7 +1665,7 @@ SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI*              theModule,
 {
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     mySelector = aViewWindow->GetSelector();
-  
+
   construct(theTypes);
 }
 
@@ -1651,6 +1708,8 @@ void SMESHGUI_FilterDlg::construct (const QValueList<int>& theTypes)
 
   aDlgLay->setStretchFactor(myMainFrame, 1);
 
+  myHelpFileName = "selection_filter_library_page.html";
+
   Init(myTypes);
 }
 
@@ -1746,11 +1805,13 @@ QFrame* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
 
   myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
   myButtons[ BTN_Close  ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
+  myButtons[ BTN_Help  ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
 
   connect(myButtons[ BTN_OK     ], SIGNAL(clicked()), SLOT(onOk()));
   connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose()));
   connect(myButtons[ BTN_Close  ], SIGNAL(clicked()), SLOT(onClose()));
   connect(myButtons[ BTN_Apply  ], SIGNAL(clicked()), SLOT(onApply()));
+  connect(myButtons[ BTN_Help   ], SIGNAL(clicked()), SLOT(onHelp()));
 
   updateMainButtons();
 
@@ -1811,11 +1872,7 @@ void SMESHGUI_FilterDlg::Init (const QValueList<int>& theTypes)
 
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
-
-  int x, y;
-  mySMESHGUI->DefineDlgPosition(this, x, y);
-  this->move(x, y);
-
+  
   updateMainButtons();
   updateSelection();
 
@@ -1887,7 +1944,7 @@ void SMESHGUI_FilterDlg::onClose()
 
       mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
-       aViewWindow->highlight( anIter.Key(), true, true );
+        aViewWindow->highlight( anIter.Key(), true, true );
     }
     mySelectionMgr->setSelectedObjects(aList, false);
   }
@@ -1899,6 +1956,29 @@ void SMESHGUI_FilterDlg::onClose()
   return;
 }
 
+//=================================================================================
+// function : onHelp()
+// purpose  :
+//=================================================================================
+void SMESHGUI_FilterDlg::onHelp()
+{
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) 
+    app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
+  else {
+               QString platform;
+#ifdef WIN32
+               platform = "winapplication";
+#else
+               platform = "application";
+#endif
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
+                          QObject::tr("BUT_OK"));
+  }
+}
+
 //=======================================================================
 // name    : SMESHGUI_FilterDlg::onDeactivate
 // Purpose : SLOT called when dialog must be deativated
@@ -2038,9 +2118,10 @@ bool SMESHGUI_FilterDlg::isValid() const
   {
     int aType = myTable->GetCriterionType(i);
     if (aType == FT_BelongToGeom ||
-         aType == FT_BelongToPlane ||
-         aType == FT_BelongToCylinder ||
-        aType == FT_LyingOnGeom) {
+        aType == FT_BelongToPlane ||
+        aType == FT_BelongToCylinder ||
+        aType == FT_BelongToGenSurface ||
+        aType == FT_LyingOnGeom) {
       QString aName;
       myTable->GetThreshold(i, aName);
 
@@ -2052,7 +2133,9 @@ bool SMESHGUI_FilterDlg::isValid() const
         return false;
       }
 
-      if (aType == FT_BelongToCylinder || aType == FT_BelongToPlane) {
+      if (aType == FT_BelongToCylinder ||
+          aType == FT_BelongToPlane    ||
+          aType == FT_BelongToGenSurface ) {
         CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
         //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
@@ -2216,17 +2299,19 @@ bool SMESHGUI_FilterDlg::createFilter (const int theType)
 //=======================================================================
 void SMESHGUI_FilterDlg::insertFilterInViewer()
 {
-  if (SVTK_InteractorStyle* aStyle = SMESH::GetInteractorStyle()) {
+  if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
     SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
 
     if (myFilter[ myTable->GetType() ]->_is_nil() ||
          myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
          !mySetInViewer->isChecked()) {
-      SMESH::RemoveFilter(getFilterId(anEntType), aStyle);
-    } else {
+      SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
+    }
+    else {
       Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
       aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
-      SMESH::SetFilter(aFilter, aStyle);
+      SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
+      SMESH::SetFilter(aFilter, aSelector);
     }
   }
 }
@@ -2424,6 +2509,7 @@ SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
   aCriterion.UnaryOp       = FT_Undefined;
   aCriterion.BinaryOp      = FT_Undefined;
   aCriterion.ThresholdStr  = "";
+  aCriterion.ThresholdID   = "";
   aCriterion.TypeOfElement = SMESH::ALL;
 
   return aCriterion;
@@ -2445,13 +2531,18 @@ void SMESHGUI_FilterDlg::onSelectionDone()
       myTable->GetCriterionType(aRow) != FT_BelongToGeom &&
       myTable->GetCriterionType(aRow) != FT_BelongToPlane &&
       myTable->GetCriterionType(aRow) != FT_BelongToCylinder &&
+      myTable->GetCriterionType(aRow) != FT_BelongToGenSurface &&
       myTable->GetCriterionType(aRow) != FT_LyingOnGeom)
     return;
 
   Handle(SALOME_InteractiveObject) anIO = aList.First();
   GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
   if (!anObj->_is_nil())
-    myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+    {
+      myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+      //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
+      myTable->SetID(aRow, anIO->getEntry());
+    }
 }
 
 //=======================================================================
@@ -2494,12 +2585,14 @@ void SMESHGUI_FilterDlg::updateSelection()
   int aRow, aCol;
 
   if (myTable->CurrentCell(aRow, aCol) &&
-       (myTable->GetCriterionType(aRow) == FT_BelongToGeom ||
-         myTable->GetCriterionType(aRow) == FT_BelongToPlane ||
-         myTable->GetCriterionType(aRow) == FT_BelongToCylinder ||
-        myTable->GetCriterionType(aRow) == FT_LyingOnGeom)) {
+      (myTable->GetCriterionType(aRow) == FT_BelongToGeom ||
+       myTable->GetCriterionType(aRow) == FT_BelongToPlane ||
+       myTable->GetCriterionType(aRow) == FT_BelongToCylinder ||
+       myTable->GetCriterionType(aRow) == FT_BelongToGenSurface ||
+       myTable->GetCriterionType(aRow) == FT_LyingOnGeom)) {
 
     if (myTable->GetCriterionType(aRow) == FT_BelongToGeom ||
+        myTable->GetCriterionType(aRow) == FT_BelongToGenSurface ||
         myTable->GetCriterionType(aRow) == FT_LyingOnGeom) {
 
       mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
@@ -2518,3 +2611,21 @@ void SMESHGUI_FilterDlg::updateSelection()
     }
   }
 }
+
+//=================================================================================
+// function : keyPressEvent()
+// purpose  :
+//=================================================================================
+void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
+{
+  QDialog::keyPressEvent( e );
+  if ( e->isAccepted() )
+    return;
+
+  if ( e->key() == Key_F1 )
+    {
+      e->accept();
+      onHelp();
+    }
+}
+