Salome HOME
fix bug 12361. In SetName(): there may be no study
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.cxx
index 95f8ed3039d5e3e72b2157a38ba6a641790c1e4f..d04574b23a51a831d6459007d3a18bc7a38f1241 100755 (executable)
 
 #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"
 
@@ -790,7 +792,11 @@ void SMESHGUI_FilterTable::GetCriterion (const int                 theRow,
     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))
@@ -833,7 +839,11 @@ void SMESHGUI_FilterTable::SetCriterion (const int                       theRow,
        theCriterion.Type != FT_LyingOnGeom)
     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 ||
@@ -1352,7 +1362,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();
 
@@ -1383,11 +1393,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();
@@ -1589,6 +1603,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
@@ -1652,6 +1697,8 @@ void SMESHGUI_FilterDlg::construct (const QValueList<int>& theTypes)
 
   aDlgLay->setStretchFactor(myMainFrame, 1);
 
+  myHelpFileName = "selection_filter_library.htm";
+
   Init(myTypes);
 }
 
@@ -1747,11 +1794,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();
 
@@ -1812,11 +1861,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();
 
@@ -1900,6 +1945,23 @@ 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 {
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
+                          QObject::tr("BUT_OK"));
+  }
+}
+
 //=======================================================================
 // name    : SMESHGUI_FilterDlg::onDeactivate
 // Purpose : SLOT called when dialog must be deativated
@@ -2217,17 +2279,17 @@ 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);
+      SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
     } else {
       Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
       aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
-      SMESH::SetFilter(aFilter, aStyle);
+      SMESH::SetFilter(aFilter, aSelector);
     }
   }
 }
@@ -2425,6 +2487,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;
@@ -2452,7 +2515,10 @@ void SMESHGUI_FilterDlg::onSelectionDone()
   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));
+    }
 }
 
 //=======================================================================