Salome HOME
updated copyright message
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
index d4075da7bd179e5289fcedecd50a140b57702815..b01e7c4e3d8fd5ae286664c6765f206f189eb1ef 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 #include "BLSURFPluginGUI_HypothesisCreator.h"
 #include "BLSURFPluginGUI_Dlg.h"
+#include "BLSURFPlugin_Hypothesis.hxx"
 
-#include "GeometryGUI.h"
+#include <GeometryGUI.h>
 
-#include <SMESHGUI_Utils.h>
-#include <SMESHGUI_HypothesesUtils.h>
 #include <SMESHGUI_Dialog.h>
-#include "SMESHGUI_SpinBox.h"
-#include "SMESH_NumberFilter.hxx"
+#include <SMESHGUI_HypothesesUtils.h>
+#include <SMESHGUI_IdValidator.h>
+#include <SMESHGUI_SpinBox.h>
+#include <SMESHGUI_Utils.h>
+#include <SMESH_Gen_i.hxx>
+#include <SMESH_NumberFilter.hxx>
+#include <StdMeshersGUI_SubShapeSelectorWdg.h>
 
-#include <SUIT_Session.h>
+#include <LightApp_SelectionMgr.h>
+#include <SALOME_ListIO.hxx>
 #include <SUIT_MessageBox.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+#include <SalomeApp_Application.h>
 #include <SalomeApp_Tools.h>
 
 #include <QApplication>
 #include <QCheckBox>
 #include <QComboBox>
 #include <QFrame>
-#include <QHBoxLayout>
-#include <QHeaderView>
 #include <QGridLayout>
 #include <QGroupBox>
+#include <QHBoxLayout>
+#include <QHeaderView>
 #include <QLabel>
 #include <QLineEdit>
 #include <QMenu>
+#include <QModelIndexList>
 #include <QObject>
 #include <QPushButton>
 #include <QRadioButton>
 #include <QSpinBox>
-#include <QTableWidget>
-#include <QTabWidget>
-#include <QVBoxLayout>
 #include <QSplitter>
-
-#include <QStandardItemModel>
 #include <QStandardItem>
+#include <QStandardItemModel>
+#include <QTabWidget>
+#include <QTableWidget>
 #include <QTreeWidget>
 #include <QTreeWidgetItem>
-#include <QModelIndexList>
-
-#include <LightApp_SelectionMgr.h>
-#include <SalomeApp_Application.h>
-#include <SALOME_ListIO.hxx>
-#include "SALOME_LifeCycleCORBA.hxx"
+#include <QVBoxLayout>
 
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Iterator.hxx>
-#include <SMESH_Gen_i.hxx>
-#include <boost/shared_ptr.hpp>
-#include <boost/algorithm/string.hpp>
-#include <structmember.h>
-#include <stdexcept>
-#include <algorithm>
+
+#include <structmember.h> // Python
 
 using namespace std;
 
@@ -86,8 +83,10 @@ enum {
   STD_TAB = 0,
   ADV_TAB,
   SMP_TAB,
-  ENF_TAB,
+  ENF_V_TAB,
+  ENF_M_TAB,
   PERIODICITY_TAB,
+  HYPERPATCH_TAB,
   SMP_NAME_COLUMN =0,
   SMP_SIZEMAP_COLUMN,
   SMP_ENTRY_COLUMN,
@@ -106,7 +105,11 @@ enum {
   ENF_VER_ENTRY_COLUMN,
   ENF_VER_GROUP_COLUMN,
   ENF_VER_NB_COLUMNS,
-// Periodicity
+
+  // Enforced 1D meshes
+  ENF_MESH_NB_COLUMNS = 2,
+
+  // Periodicity
   PERIODICITY_OBJ_SOURCE_COLUMN = 0,
   PERIODICITY_OBJ_TARGET_COLUMN,
   PERIODICITY_P1_SOURCE_COLUMN,
@@ -215,20 +218,19 @@ namespace {
   static PyMethodDef PyStdOut_methods[] = {
     {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
     PyDoc_STR("write(string) -> None")},
-    {NULL,    NULL}   /* sentinel */
+    {0, 0, 0, 0}   /* sentinel */
   };
 
   static PyMemberDef PyStdOut_memberlist[] = {
     {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
      (char*)"flag indicating that a space needs to be printed; used by print"},
-    {NULL} /* Sentinel */
+    {0, 0, 0, 0, 0} /* Sentinel */
   };
 
   static PyTypeObject PyStdOut_Type = {
     /* The ob_type field must be initialized in the module init function
      * to be portable to Windows without using C++. */
-    PyObject_HEAD_INIT(NULL)
-    0,                            /*ob_size*/
+    PyVarObject_HEAD_INIT(NULL, 0)
     "PyOut",                      /*tp_name*/
     sizeof(PyStdOut),             /*tp_basicsize*/
     0,                            /*tp_itemsize*/
@@ -270,6 +272,14 @@ namespace {
     0,                            /*tp_new*/
     0,                            /*tp_free*/
     0,                            /*tp_is_gc*/
+    0,                            /*tp_bases*/
+    0,                            /*tp_mro*/
+    0,                            /*tp_cache*/
+    0,                            /*tp_subclasses*/
+    0,                            /*tp_weaklist*/
+    0,                            /*tp_del*/
+    0,                            /*tp_version_tag*/
+    0,                            /*tp_finalize*/
   };
 
   PyObject * newPyStdOut( std::string& out )
@@ -298,7 +308,7 @@ EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
 }
 
 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
-                                              const QStyleOptionViewItem & option ,
+                                              const QStyleOptionViewItem & /*option*/ ,
                                               const QModelIndex & index ) const
 {
   QModelIndex father = index.parent();
@@ -477,9 +487,8 @@ BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool() const
 {
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-  if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
-    that->GeomToolSelected = new GeomSelectionTools(aStudy);
+  if (that->GeomToolSelected == NULL) {
+    that->GeomToolSelected = new GeomSelectionTools();
   }
   return that->GeomToolSelected;
 }
@@ -568,12 +577,6 @@ bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
       }
     }
   }
-  if ( !ok )
-  {
-    h->SetOptionValues( myOptions ); // restore values
-    h->SetPreCADOptionValues( myPreCADOptions ); // restore values
-    return ok;
-  }
 
   // SizeMap and attractors
   if ( ok )
@@ -594,7 +597,7 @@ bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
           try {
             e = entry.toStdString();
             s = that->mySMPMap[entry].toStdString();
-            h->SetSizeMapEntry( e.c_str(), s.c_str() );
+            //h->SetSizeMapEntry( e.c_str(), s.c_str() );
           }
           catch ( const SALOME::SALOME_Exception& ex )
           {
@@ -641,18 +644,70 @@ bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
       msg = tr("ZERO_VALUE_OF").arg( tr("BLSURF_CHORDAL_ERROR"));
   }
 
+  // #16954 EDF 19466 - localsize
+  // Warn the user if local size is less than Min Size
+  if ( ok &&
+       !myStdWidget->myMinSizeRel->isChecked() &&
+       !myStdWidget->myMinSize->text().isEmpty() )
+  {
+    const double minSize = myStdWidget->myMinSize->GetValue();
+    bool isValue;
+    for ( QMapIterator<QString,QString> i( mySMPMap ); i.hasNext() &&  ok ; )
+    {
+      i.next();
+      double size = i.value().toDouble( &isValue );
+      ok = ( !isValue || size >= minSize );
+    }
+    for ( QMapIterator<QString, TAttractorVec > i( myATTMap ); i.hasNext() &&  ok ; )
+    {
+      i.next();
+      const TAttractorVec& attVec = i.value();
+      for ( size_t i = 0; i < attVec.size(); ++i )
+        ok = ( attVec[i].IsToDelete()  || attVec[i].startSize >= minSize );
+    }
+    if ( !ok )
+      msg = tr( "TOO_SMALL_LOCAL_SIZE" );
+  }
+  // Warn the user if local size is more than User Size
+  if ( ok &&
+       !myStdWidget->myPhySizeRel->isChecked() &&
+       !myStdWidget->myPhySize->text().isEmpty() )
+  {
+    const double userSize = myStdWidget->myPhySize->GetValue();
+    bool isValue;
+    for ( QMapIterator<QString,QString> i( mySMPMap ); i.hasNext() &&  ok ; )
+    {
+      i.next();
+      double size = i.value().toDouble( &isValue );
+      ok = ( !isValue || size <= userSize );
+    }
+    for ( QMapIterator<QString, TAttractorVec > i( myATTMap ); i.hasNext() &&  ok ; )
+    {
+      i.next();
+      const TAttractorVec& attVec = i.value();
+      for ( size_t i = 0; i < attVec.size(); ++i )
+        ok = ( attVec[i].IsToDelete()  || attVec[i].startSize <= userSize );
+    }
+    if ( !ok )
+      msg = tr( "TOO_LARGE_LOCAL_SIZE" );
+  }
+
   // Enforced vertices
   // TODO
 
+  if ( !ok )
+  {
+    h->SetOptionValues( myOptions ); // restore values
+    h->SetPreCADOptionValues( myPreCADOptions ); // restore values
+  }
+
   return ok;
 }
 
 QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
 {
   QFrame* fr = new QFrame( 0 );
- // fr-> setMinimumSize(600,400);
   QVBoxLayout* lay = new QVBoxLayout( fr );
- // lay->setSizeConstraint(QLayout::SetDefaultConstraint);
   lay->setMargin( 5 );
   lay->setSpacing( 0 );
 
@@ -663,52 +718,50 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   lay->addWidget( myTabWidget );
 
   myName = 0;
-  
+
   // basic parameters
   myStdGroup = new QWidget();
   QGridLayout* aStdLayout = new QGridLayout( myStdGroup );
   aStdLayout->setSpacing( 6 );
   aStdLayout->setMargin( 11 );
-  
+
   if( isCreation() )
     myName = new QLineEdit( myStdGroup );
   myStdWidget = new BLSURFPluginGUI_StdWidget(myStdGroup);
-  
+  if ( !hasGeom() ) {
+    myStdWidget->myPhysicalMesh->removeItem( PhysicalLocalSize );
+  }
+
   int row = 0;
   if( isCreation() ) {
     aStdLayout->addWidget( new QLabel( tr( "SMESH_NAME" ), myStdGroup ),    0, 0, 1, 1 );
     aStdLayout->addWidget( myName,                                      row++, 1, 1, 3 );
   }
   aStdLayout->addWidget( myStdWidget,                                   row++, 0, 1, 4 );
-  
-  //int maxrow = row;
+
   row = 0;
   if( isCreation() )
     row = 1;
-//   row = max(row,maxrow)+1;
   aStdLayout->setRowStretch(row,1);
   aStdLayout->setColumnStretch(1,1);
-  //maxrow = row;
 
-  
+
   // advanced parameters
   myAdvGroup = new QWidget();
   QGridLayout* anAdvLayout = new QGridLayout( myAdvGroup );
   anAdvLayout->setSpacing( 6 );
-  anAdvLayout->setMargin( 11 );  
+  anAdvLayout->setMargin( 11 );
   myAdvWidget = new BLSURFPluginGUI_AdvWidget(myAdvGroup);
-  //myAdvWidget->addBtn->setMenu( new QMenu() );
   anAdvLayout->addWidget( myAdvWidget );
 
 
   // Size Maps parameters
 
-  mySmpGroup = new QWidget();
-//   mySmpGroup->setMinimumWidth(500);
+  mySmpGroup = new QWidget( dlg() );
 
   //Layout
   QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
-  
+
   // Table
   mySizeMapTable = new QTreeWidget( mySmpGroup );
   mySizeMapTable ->setMinimumWidth(200);
@@ -835,12 +888,8 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   smpTab->setCurrentIndex( SMP_STD_TAB ); 
 
   // Enforced vertices parameters
-  myEnfGroup = new QWidget();
+  myEnfGroup = new QWidget( dlg() );
   QGridLayout* anEnfLayout = new QGridLayout(myEnfGroup);
-//
-//   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced(myEnfGroup);
-//   anEnfLayout->addWidget(myEnforcedVertexWidget);
-//   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced();
 
   myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
   myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
@@ -858,18 +907,14 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-    myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
-#else
     myEnforcedTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
-#endif
     myEnforcedTreeWidget->resizeColumnToContents(column);
   }
   myEnforcedTreeWidget->hideColumn(ENF_VER_FACE_ENTRY_COLUMN);
   myEnforcedTreeWidget->hideColumn(ENF_VER_ENTRY_COLUMN);
   myEnforcedTreeWidget->setItemDelegate(new EnforcedTreeWidgetDelegate());
   
-// FACE AND VERTEX SELECTION
+  // FACE AND VERTEX SELECTION
   TColStd_MapOfInteger shapeTypes1, shapeTypes2;
   shapeTypes1.Add( TopAbs_FACE );
   shapeTypes1.Add( TopAbs_COMPOUND );
@@ -909,12 +954,9 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   QLabel* myInternalEnforcedVerticesAllFacesGroupLabel = new QLabel( tr( "BLSURF_ENF_VER_GROUP_LABEL" ), myEnfGroup );
   myInternalEnforcedVerticesAllFacesGroup = new QLineEdit(myEnfGroup);
 
-//   myGlobalGroupName = new QCheckBox(tr("BLSURF_ENF_VER_GROUPS"), myEnfGroup);
-//   myGlobalGroupName->setChecked(false);
-
   anEnfLayout->addWidget(myEnforcedTreeWidget,     0, 0, ENF_VER_NB_LINES, 1);
   QGridLayout* anEnfLayout2 = new QGridLayout(myEnfGroup);
-//  FACE AND VERTEX SELECTION
+  //  FACE AND VERTEX SELECTION
   //anEnfLayout2->addWidget(myEnfFaceWdg,             ENF_VER_FACE, 0, 1, 2);
   anEnfLayout2->addWidget(myEnfVertexWdg,           ENF_VER_VERTEX, 0, 1, 2);
   anEnfLayout2->addWidget(myXCoordLabel,            ENF_VER_X_COORD, 0, 1, 1);
@@ -925,21 +967,67 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   anEnfLayout2->addWidget(myZCoord,                 ENF_VER_Z_COORD, 1, 1, 1);
   anEnfLayout2->addWidget(myGroupNameLabel,         ENF_VER_GROUP, 0, 1, 1);
   anEnfLayout2->addWidget(myGroupName,              ENF_VER_GROUP, 1, 1, 1);
-//   anEnfLayout2->addWidget(myGlobalGroupName,        ENF_VER_GROUP_CHECK, 0, 1, 2);
-//   anEnfLayout2->setRowStretch(                      ENF_VER_SPACE, 1);
   anEnfLayout2->addWidget(addVertexButton,          ENF_VER_BTN, 0, 1, 1);
   anEnfLayout2->addWidget(removeVertexButton,       ENF_VER_BTN, 1, 1, 1);
   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFaces, ENF_VER_INTERNAL_ALL_FACES, 0, 1, 2);
   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroupLabel, ENF_VER_INTERNAL_ALL_FACES_GROUP, 0, 1, 1);
   anEnfLayout2->addWidget(myInternalEnforcedVerticesAllFacesGroup, ENF_VER_INTERNAL_ALL_FACES_GROUP, 1, 1, 1);
   anEnfLayout2->setRowStretch(ENF_VER_NB_LINES+1, 1);
-//   anEnfLayout2->addWidget(makeGroupsCheck,          ENF_VER_GROUP_CHECK, 0, 1, 2);
   anEnfLayout->addLayout(anEnfLayout2, 0,1,ENF_VER_NB_LINES+1,2);
-//   anEnfLayout->setRowStretch(1, 1);
+
+  // ---------------------------
+  // Enforced meshes parameters
+  // ---------------------------
+
+  myEnfMeshGroup = new QWidget();
+  QGridLayout* anEnfMeshLayout = new QGridLayout(myEnfMeshGroup);
+
+  myEnfMeshTableWdg = new QTableWidget(myEnfGroup);
+  //myEnfMeshTableWdg->setRowCount( 0 );
+  myEnfMeshTableWdg->setColumnCount( ENF_MESH_NB_COLUMNS );
+  myEnfMeshTableWdg->setSortingEnabled(true);
+  myEnfMeshTableWdg->verticalHeader()->hide();
+  myEnfMeshTableWdg->setHorizontalHeaderLabels( QStringList()
+                                                << tr( "ENF_NAME_COLUMN" )
+                                                << tr( "ENF_GROUP_COLUMN" ));
+  myEnfMeshTableWdg->horizontalHeader()->setStretchLastSection(true);
+  myEnfMeshTableWdg->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
+  myEnfMeshTableWdg->setAlternatingRowColors(true);
+  myEnfMeshTableWdg->setSelectionMode(QAbstractItemView::ExtendedSelection);
+  myEnfMeshTableWdg->setSelectionBehavior(QAbstractItemView::SelectItems);
+  myEnfMeshTableWdg->resizeColumnsToContents();
+  //myEnfMeshTableWdg->setItemDelegate(new EnforcedMeshTableWidgetDelegate());
+
+  myEnfMeshWdg = new StdMeshersGUI_ObjectReferenceParamWdg( SMESH::IDSOURCE_EDGE, myEnfMeshGroup, /*multiSel=*/false);
+  myEnfMeshWdg->SetDefaultText(tr("ENF_SELECT_MESH"), "QLineEdit { color: grey }");
+
+  myEnfMeshWdg->AvoidSimultaneousSelection(myEnfVertexWdg);
+  myEnfMeshWdg->AvoidSimultaneousSelection(myGeomSelWdg1);
+  myEnfMeshWdg->AvoidSimultaneousSelection(myGeomSelWdg2);
+  myEnfMeshWdg->AvoidSimultaneousSelection(myAttSelWdg);
+
+  QLabel* enforcedGroupNameLabel = new QLabel( tr( "ENF_GROUP_LABEL" ), myEnfMeshGroup );
+  myEnforcedGroupName = new QLineEdit(myEnfMeshGroup);
+
+  myAddEnfMeshButton    = new QPushButton(tr("ENF_ADD"),myEnfMeshGroup);
+  myRemoveEnfMeshButton = new QPushButton(tr("ENF_REMOVE"),myEnfMeshGroup);
+
+  QGridLayout* anEnfMeshLayout2 = new QGridLayout(myEnfMeshGroup);
+  anEnfMeshLayout2->addWidget(myEnfMeshWdg,             0, 0, 1, 2);
+  anEnfMeshLayout2->addWidget(enforcedGroupNameLabel,   1, 0, 1, 1);
+  anEnfMeshLayout2->addWidget(myEnforcedGroupName,      1, 1, 1, 1);
+  anEnfMeshLayout2->addWidget(myAddEnfMeshButton,       2, 0, 1, 2);
+  anEnfMeshLayout2->addWidget(myRemoveEnfMeshButton,    3, 0, 1, 2);
+  anEnfMeshLayout2->setRowStretch( 4, 1 );
+
+  anEnfMeshLayout->addWidget(myEnfMeshTableWdg, 0, 0, 5, 1);
+  anEnfMeshLayout->addLayout(anEnfMeshLayout2,  0, 1, 1, 1);
+  anEnfMeshLayout->setRowStretch( 2, 1 );
+
 
   // ---
   // Periodicity parameters
-  myPeriodicityGroup = new QWidget();
+  myPeriodicityGroup = new QWidget( dlg() );
   aPeriodicityLayout1 = new QGridLayout(myPeriodicityGroup);
 
   myPeriodicitySplitter = new QSplitter(myPeriodicityGroup);
@@ -977,13 +1065,9 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
   myPeriodicityTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
   
-  size_t periodicityVisibleColumns = 2;
-  for (size_t column = 0; column < periodicityVisibleColumns; ++column) {
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-      myPeriodicityTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
-#else
+  int periodicityVisibleColumns = 2;
+  for (int column = 0; column < periodicityVisibleColumns; ++column) {
       myPeriodicityTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
-#endif
       myPeriodicityTreeWidget->resizeColumnToContents(column);
   }
   myPeriodicityTreeWidget->header()->setStretchLastSection(true);
@@ -1128,65 +1212,122 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicitySelectionWidgets.append(myPeriodicityP3TargetWdg);
   avoidSimultaneousSelection(myPeriodicitySelectionWidgets);
 
+  // HyperPatch parameters
+
+  QWidget*      hpGroup = new QWidget();
+  QGridLayout* hpLayout = new QGridLayout(hpGroup);
+
+  myHyPatchTable = new QTableWidget( hpGroup );
+  myHyPatchTable->setColumnCount(1);
+  myHyPatchTable->setHorizontalHeaderLabels( QStringList() << tr("BLSURF_HYPATCH_TBL_HEADER") );
+  myHyPatchTable->setAlternatingRowColors(true);
+  myHyPatchTable->horizontalHeader()->setSectionResizeMode( 0, QHeaderView::Stretch );
+
+
+  QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
+  myHyPatchFaceSelBtn  = new QPushButton( iconSelect, tr("BLSURF_HYPATCH_SEL_FACE"), hpGroup );
+  myHyPatchGroupSelBtn = new QPushButton( iconSelect, tr("BLSURF_HYPATCH_SEL_GROUP"), hpGroup );
+  myHyPatchFaceSelBtn->setCheckable( true );
+  myHyPatchGroupSelBtn->setCheckable( true );
+
+  myHyPatchFaceSelector = new StdMeshersGUI_SubShapeSelectorWdg( hpGroup, TopAbs_FACE, /*toShowList=*/false );
+
+  QLabel* hpTagsLbl = new QLabel( tr("BLSURF_TAGS"), hpGroup );
+  myHyPatchTagsLE   = new QLineEdit( hpGroup );
+  myHyPatchTagsLE->setValidator( new SMESHGUI_IdValidator( hpGroup ));
+
+  QPushButton* hpAddBtn = new QPushButton( tr("BLSURF_SM_ADD"), hpGroup );
+  QPushButton* hpRemBtn = new QPushButton( tr("BLSURF_SM_REMOVE"), hpGroup );
+
+  hpLayout->addWidget( myHyPatchTable,        0, 0, 5, 1 );
+  hpLayout->addWidget( myHyPatchFaceSelBtn,   0, 1, 1, 2 );
+  hpLayout->addWidget( myHyPatchGroupSelBtn,  0, 3, 1, 2 );
+  hpLayout->addWidget( hpTagsLbl,             1, 1, 1, 1 );
+  hpLayout->addWidget( myHyPatchTagsLE,       1, 2, 1, 3 );
+  hpLayout->addWidget( hpAddBtn,              2, 1, 1, 2 );
+  hpLayout->addWidget( hpRemBtn,              2, 3, 1, 2 );
+  hpLayout->addWidget( myHyPatchFaceSelector, 3, 1, 1, 4 );
+
+
+
   // ---
   myTabWidget->insertTab( STD_TAB, myStdGroup, tr( "SMESH_ARGUMENTS" ) );
   myTabWidget->insertTab( ADV_TAB, myAdvGroup, tr( "BLSURF_ADV_ARGS" ) );
-  myTabWidget->insertTab( SMP_TAB, mySmpGroup, tr( "LOCAL_SIZE" ) );
-  myTabWidget->insertTab( ENF_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
-  myTabWidget->insertTab( PERIODICITY_TAB, myPeriodicityGroup, tr( "BLSURF_PERIODICITY" ) );
-
+  if ( hasGeom() ) {
+    myTabWidget->insertTab( SMP_TAB, mySmpGroup, tr( "LOCAL_SIZE" ) );
+    myTabWidget->insertTab( ENF_V_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
+    myTabWidget->insertTab( ENF_M_TAB, myEnfMeshGroup, tr( "ENF_MESH" ) );
+    myTabWidget->insertTab( PERIODICITY_TAB, myPeriodicityGroup, tr( "BLSURF_PERIODICITY" ) );
+    myTabWidget->insertTab( HYPERPATCH_TAB, hpGroup, tr( "BLSURF_HYPERPATCH_TAB" ));
+  }
+  else
+  {
+    mySmpGroup->hide();
+    myEnfGroup->hide();
+    myEnfMeshGroup->hide();
+    myPeriodicityGroup->hide();
+    hpGroup->hide();
+  }
   myTabWidget->setCurrentIndex( STD_TAB );
 
-  connect( myAdvWidget->addBtn, SIGNAL( clicked() ),           this, SLOT( onAddOption() ) );
-  connect( myStdWidget->myAllowQuadrangles, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChange() ));
+  connect( myAdvWidget->addBtn, SIGNAL( clicked() ),                           SLOT( onAddOption() ) );
 
   // Size Maps
-  connect( addMapButton,        SIGNAL( clicked()),                    this,         SLOT( onAddMap() ) );
-  connect( removeMapButton,     SIGNAL( clicked()),                    this,         SLOT( onRemoveMap() ) );
-  connect( modifyMapButton,     SIGNAL( clicked()),                    this,         SLOT( onModifyMap() ) );
-//   connect( mySizeMapTable,      SIGNAL( cellChanged ( int, int  )),    this,         SLOT( onSetSizeMap(int,int ) ) );
-  connect( mySizeMapTable,      SIGNAL( itemClicked (QTreeWidgetItem *, int)),this,  SLOT( onSmpItemClicked(QTreeWidgetItem *, int) ) );
-  connect( myGeomSelWdg2,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
-  connect( myGeomSelWdg1,       SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
-  connect( myAttSelWdg,         SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
-//   connect( myAttractorGroup,    SIGNAL( clicked(bool) ),               this,         SLOT( onAttractorGroupClicked(bool) ) );
-  connect( mySizeMapTable,      SIGNAL( itemChanged (QTreeWidgetItem *, int)),this,  SLOT( onSetSizeMap(QTreeWidgetItem *, int) ) );
-  connect( myAttractorCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onAttractorClicked( int ) ) );
-  connect( myConstSizeCheck,    SIGNAL( stateChanged ( int )),         this,         SLOT( onConstSizeClicked( int ) ) );
-  connect( smpTab,              SIGNAL( currentChanged ( int )),       this,         SLOT( onTabChanged( int ) ) );
-  connect( myTabWidget,         SIGNAL( currentChanged ( int )),       this,         SLOT( onTabChanged( int ) ) );
+  connect( addMapButton,        SIGNAL( clicked()),                            SLOT( onAddMap() ) );
+  connect( removeMapButton,     SIGNAL( clicked()),                            SLOT( onRemoveMap() ) );
+  connect( modifyMapButton,     SIGNAL( clicked()),                            SLOT( onModifyMap() ) );
+  connect( mySizeMapTable,      SIGNAL( itemClicked (QTreeWidgetItem *, int)), SLOT( onSmpItemClicked(QTreeWidgetItem *, int) ) );
+  connect( myGeomSelWdg2,       SIGNAL( contentModified() ),                   SLOT( onMapGeomContentModified() ) );
+  connect( myGeomSelWdg1,       SIGNAL( contentModified() ),                   SLOT( onMapGeomContentModified() ) );
+  connect( myAttSelWdg,         SIGNAL( contentModified() ),                   SLOT( onMapGeomContentModified() ) );
+  connect( mySizeMapTable,      SIGNAL( itemChanged (QTreeWidgetItem *, int)), SLOT( onSetSizeMap(QTreeWidgetItem *, int) ) );
+  connect( myAttractorCheck,    SIGNAL( stateChanged ( int )),                 SLOT( onAttractorClicked( int ) ) );
+  connect( myConstSizeCheck,    SIGNAL( stateChanged ( int )),                 SLOT( onConstSizeClicked( int ) ) );
+  connect( smpTab,              SIGNAL( currentChanged ( int )),               SLOT( onTabChanged( int ) ) );
+  connect( myTabWidget,         SIGNAL( currentChanged ( int )),               SLOT( onTabChanged( int ) ) );
 
   // Enforced vertices
-  connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)), this,  SLOT( synchronizeCoords() ) );
-  connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this,  SLOT( updateEnforcedVertexValues(QTreeWidgetItem *, int) ) );
-//   connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)), this,  SLOT( update(QTreeWidgetItem *, int) ) );
-  connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ),      this,         SLOT( synchronizeCoords() ) );
-  connect( addVertexButton,     SIGNAL( clicked()),                    this,         SLOT( onAddEnforcedVertices() ) );
-  connect( removeVertexButton,  SIGNAL( clicked()),                    this,         SLOT( onRemoveEnforcedVertex() ) );
-  connect( myEnfVertexWdg,      SIGNAL( contentModified()),            this,         SLOT( onSelectEnforcedVertex() ) );
-  connect( myInternalEnforcedVerticesAllFaces, SIGNAL( stateChanged ( int )), this,  SLOT( onInternalVerticesClicked( int ) ) );
-//   connect( myEnfVertexWdg,     SIGNAL( selectionActivated()),         this,         SLOT( onVertexSelectionActivated() ) );
-//   connect( myEnfFaceWdg,       SIGNAL( selectionActivated()),         this,         SLOT( onFaceSelectionActivated() ) );
+  connect( myEnforcedTreeWidget,SIGNAL( itemClicked(QTreeWidgetItem *, int)),  SLOT( synchronizeCoords() ) );
+  connect( myEnforcedTreeWidget,SIGNAL( itemChanged(QTreeWidgetItem *, int)),  SLOT( updateEnforcedVertexValues(QTreeWidgetItem *, int) ) );
+  connect( myEnforcedTreeWidget,SIGNAL( itemSelectionChanged() ),              SLOT( synchronizeCoords() ) );
+  connect( addVertexButton,     SIGNAL( clicked()),                            SLOT( onAddEnforcedVertices() ) );
+  connect( removeVertexButton,  SIGNAL( clicked()),                            SLOT( onRemoveEnforcedVertex() ) );
+  connect( myEnfVertexWdg,      SIGNAL( contentModified()),                    SLOT( onSelectEnforcedVertex() ) );
+  connect( myInternalEnforcedVerticesAllFaces, SIGNAL( stateChanged ( int )),  SLOT( onInternalVerticesClicked( int ) ) );
+
+  // Enforced mesh
+  connect( myAddEnfMeshButton,    SIGNAL( clicked()),              SLOT( onAddEnforcedMesh()));
+  connect( myRemoveEnfMeshButton, SIGNAL( clicked()),              SLOT( onRemoveEnforcedMesh()));
+  connect( myEnfMeshWdg,          SIGNAL( contentModified()),      SLOT( onEnforcedMeshSelected()));
+  connect( myEnfMeshTableWdg,     SIGNAL( itemSelectionChanged()), SLOT( onEnfMeshTableSelected()));
+
 
   // Periodicity
-  connect( myPeriodicityAddButton,     SIGNAL( clicked()),                    this,   SLOT( onAddPeriodicity() ) );
-  connect( myPeriodicityRemoveButton,  SIGNAL( clicked()),                    this,   SLOT( onRemovePeriodicity() ) );
-  connect( myPeriodicityTreeWidget,    SIGNAL( itemClicked(QTreeWidgetItem*, int)), this, SLOT( onPeriodicityTreeClicked(QTreeWidgetItem *, int) ) );
-  connect( myPeriodicityGroupBox2,     SIGNAL(toggled(bool)),                 this,   SLOT(onPeriodicityByVerticesChecked(bool)));
+  connect( myPeriodicityAddButton,     SIGNAL( clicked()),                     SLOT( onAddPeriodicity() ) );
+  connect( myPeriodicityRemoveButton,  SIGNAL( clicked()),                     SLOT( onRemovePeriodicity() ) );
+  connect( myPeriodicityTreeWidget,    SIGNAL( itemClicked(QTreeWidgetItem*, int)), SLOT( onPeriodicityTreeClicked(QTreeWidgetItem *, int) ) );
+  connect( myPeriodicityGroupBox2,     SIGNAL(toggled(bool)),                  SLOT(onPeriodicityByVerticesChecked(bool)));
 
   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++)
-    {
-      StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
-      connect( w1,     SIGNAL(contentModified ()),                 this,   SLOT(onPeriodicityContentModified()));
+  {
+    StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
+    connect( w1, SIGNAL( contentModified ()), SLOT( onPeriodicityContentModified() ));
+
+  }
+
+  // HyperPatch
+  connect( myHyPatchFaceSelBtn,   SIGNAL( toggled(bool) ),   SLOT( onHyPatchFaceSelection(bool) ));
+  connect( myHyPatchGroupSelBtn,  SIGNAL( toggled(bool) ),   SLOT( onHyPatchGroupSelection(bool) ));
+  connect( myHyPatchFaceSelector, SIGNAL( shapeSelected() ), SLOT( onHyPatchSelectionChanged()));
+  connect( hpAddBtn,              SIGNAL( clicked() ),       SLOT( onHyPatchAdd()));
+  connect( hpRemBtn,              SIGNAL( clicked() ),       SLOT( onHyPatchRemove()));
 
-    }
-//  connect( myPeriodicitySourceFaceWdg,     SIGNAL(contentModified()),    this,   SLOT(onPeriodicityContentModified()));
   return fr;
 }
 
 /** BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget*, QWidget*)
-This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParamWdg
+    This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParamWdg
 */
 // void BLSURFPluginGUI_HypothesisCreator::deactivateSelection(QWidget* old, QWidget* now)
 // {
@@ -1215,14 +1356,15 @@ void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
   myXCoord->setText("");
   myYCoord->setText("");
   myZCoord->setText("");
-//   myGroupName->setText("");
+  //   myGroupName->setText("");
 }
 
 /** BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(item, column)
-This method updates the tooltip of a modified item. The QLineEdit widgets content
-is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
+    This method updates the tooltip of a modified item. The QLineEdit widgets content
+    is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
 */
-void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int column) {
+void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int /*column*/)
+{
   QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
   QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
@@ -1259,8 +1401,9 @@ void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetIt
   }
 }
 
-void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
-  int nbSelEnfVertex = myEnfVertexWdg->NbObjects();
+void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex()
+{
+  size_t nbSelEnfVertex = myEnfVertexWdg->NbObjects();
   clearEnforcedVertexWidgets();
   if (nbSelEnfVertex == 1)
   {
@@ -1269,8 +1412,7 @@ void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
 
     myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(nbSelEnfVertex-1);
     if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
-      BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
+      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
       if (CORBA::is_nil(measureOp))
         return;
       
@@ -1290,7 +1432,8 @@ void BLSURFPluginGUI_HypothesisCreator::onSelectEnforcedVertex() {
 This method synchronizes the QLineEdit/SMESHGUI_SpinBox widgets content with the coordinates
 of the enforced vertex clicked in the tree widget.
 */
-void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
+void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords()
+{
   clearEnforcedVertexWidgets();
   QList<QTreeWidgetItem *> items = myEnforcedTreeWidget->selectedItems();
   if (! items.isEmpty() && items.size() == 1) {
@@ -1317,7 +1460,8 @@ void BLSURFPluginGUI_HypothesisCreator::synchronizeCoords() {
 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(entry, shapeName, useInternalVertices)
 This method adds a face containing enforced vertices in the tree widget.
 */
-QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName) {
+QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string theFaceEntry, std::string theFaceName)
+{
   // Find theFaceEntry item
   QList<QTreeWidgetItem* > theItemList = myEnforcedTreeWidget->findItems(QString(theFaceEntry.c_str()),Qt::MatchExactly,ENF_VER_FACE_ENTRY_COLUMN);
   QTreeWidgetItem* theItem;
@@ -1418,42 +1562,24 @@ void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, do
 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
 This method is called when a item is added into the enforced vertices tree widget
 */
-void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
-
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-
+void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
+{
   getGeomSelectionTool()->selectionMgr()->clearFilters();
-  //myEnfFaceWdg->deactivateSelection();
   myEnfVertexWdg->deactivateSelection();
 
   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
     myEnforcedTreeWidget->resizeColumnToContents(column);
 
   // Vertex selection
-  //int selEnfFace   = myEnfFaceWdg->NbObjects();
-  int selEnfVertex = myEnfVertexWdg->NbObjects();
+  size_t selEnfVertex = myEnfVertexWdg->NbObjects();
   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
 
-  // if (selEnfFace == 0)
-  //   return;
-
   if ((selEnfVertex == 0) && coordsEmpty)
     return;
 
   string entry, shapeName;
-
-  //for (int i = 0 ; i < selEnfVertex + !coordsEmpty; i++)
   {
-    //myEnfFace = myEnfFaceWdg->GetObject< GEOM::GEOM_Object >(i);
-    //entry = myEnfFace->GetStudyEntry();
-    //shapeName = myEnfFace->GetName();
-    
-    //QTreeWidgetItem * faceItem = addEnforcedFace(entry, shapeName);
-    
-    std::string groupName = myGroupName->text().toStdString();
-
-    if (boost::trim_copy(groupName).empty())
-      groupName = "";
+    std::string groupName = myGroupName->text().simplified().toStdString();
 
     if (selEnfVertex <= 1)
     {
@@ -1473,13 +1599,13 @@ void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
       if ( CORBA::is_nil(getGeomEngine()))
         return;
 
-      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
+      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
       if (CORBA::is_nil(measureOp))
         return;
 
       CORBA::Double x,y,z;
       x = y = z = 0.;
-      for (int j = 0 ; j < selEnfVertex ; j++)
+      for (size_t j = 0 ; j < selEnfVertex ; j++)
       {
         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
         if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
@@ -1493,7 +1619,6 @@ void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
     }
   }
 
-  //myEnfFaceWdg->SetObject(GEOM::GEOM_Object::_nil());
   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
   
   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
@@ -1508,7 +1633,8 @@ void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
 /** BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
 This method is called when a item is removed from the enforced vertices tree widget
 */
-void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
+void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
+{
   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
   QList<QTreeWidgetItem *> selectedVertices;
   QSet<QTreeWidgetItem *> selectedEntries;
@@ -1555,8 +1681,8 @@ void BLSURFPluginGUI_HypothesisCreator::onInternalVerticesClicked(int state)
 /** BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
 This method is called when a item is added into the periodicity table widget
 */
-void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
-
+void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
+{
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
@@ -1569,8 +1695,8 @@ void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
 
 
   // Source-Target selection
-  int selSource = myPeriodicitySourceFaceWdg->NbObjects();
-  int selTarget = myPeriodicityTargetFaceWdg->NbObjects();
+  size_t selSource = myPeriodicitySourceFaceWdg->NbObjects();
+  size_t selTarget = myPeriodicityTargetFaceWdg->NbObjects();
 
   if (selSource == 0 || selTarget == 0)
     return;
@@ -1578,12 +1704,12 @@ void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
   // Vertices selection
   if (myPeriodicityGroupBox2->isChecked())
     {
-      int P1Ssel = myPeriodicityP1SourceWdg->NbObjects();
-      int P2Ssel = myPeriodicityP2SourceWdg->NbObjects();
-      int P3Ssel = myPeriodicityP3SourceWdg->NbObjects();
-      int P1Tsel = myPeriodicityP1TargetWdg->NbObjects();
-      //int P2Tsel = myPeriodicityP2TargetWdg->NbObjects();
-      int P3Tsel = myPeriodicityP3TargetWdg->NbObjects();
+      size_t P1Ssel = myPeriodicityP1SourceWdg->NbObjects();
+      size_t P2Ssel = myPeriodicityP2SourceWdg->NbObjects();
+      size_t P3Ssel = myPeriodicityP3SourceWdg->NbObjects();
+      size_t P1Tsel = myPeriodicityP1TargetWdg->NbObjects();
+      //size_t P2Tsel = myPeriodicityP2TargetWdg->NbObjects();
+      size_t P3Tsel = myPeriodicityP3TargetWdg->NbObjects();
 
       if (P1Ssel!=1 || P2Ssel!=1 || P3Ssel!=1 || P1Tsel!=1 || P3Tsel!=1 || P3Tsel!=1)
         {
@@ -1604,7 +1730,7 @@ void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
   item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
 
 
-  size_t k=0;
+  int k=0;
   for (anIt = myPeriodicitySelectionWidgets.begin(); anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
     {
       StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( *anIt );
@@ -1636,7 +1762,8 @@ void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
 /** BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
 This method is called when a item is removed from the periodicity tree widget
 */
-void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity() {
+void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
+{
   QList<QTreeWidgetItem *> selectedItems = myPeriodicityTreeWidget->selectedItems();
   QTreeWidgetItem* item;
 
@@ -1684,11 +1811,11 @@ This method enable the proper shape selection widget to Face or Edge shapes
 //    }
 //}
 
-void BLSURFPluginGUI_HypothesisCreator::onPeriodicityTreeClicked(QTreeWidgetItem* item, int row)
+void BLSURFPluginGUI_HypothesisCreator::onPeriodicityTreeClicked(QTreeWidgetItem* item, int /*row*/)
 {
   QString shapeName, shapeEntry;
   CORBA::Object_var shape;
-  size_t k=0;
+  int k=0;
   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
     {
@@ -1746,7 +1873,7 @@ void BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
 
 
 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
-This method updates the GUI widgets with the hypothesis data
+    This method updates the GUI widgets with the hypothesis data
 */
 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
 {
@@ -1787,8 +1914,31 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
     myStdWidget->myVolumeGradation->setText("");
   else
     myStdWidget->myVolumeGradation->SetValue( data.myVolumeGradation );
-  myStdWidget->myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
-  
+
+  foreach (QAbstractButton* button, myStdWidget->myButtonGroupElementType->buttons()) {
+    if (myStdWidget->myButtonGroupElementType->id(button) == data.myElementType) {
+      button->setChecked(true);
+      break;
+    }
+  }
+
+  myStdWidget->myUseSurfaceProximity->setChecked( data.myUseSurfaceProximity );
+  myStdWidget->myNbSurfaceProximityLayers->setValue( data.myNbSurfaceProximityLayers );
+  myStdWidget->mySurfaceProximityRatio->SetValue( data.mySurfaceProximityRatio );
+  myStdWidget->myUseVolumeProximity->setChecked( data.myUseVolumeProximity );
+  myStdWidget->myNbVolumeProximityLayers->setValue( data.myNbVolumeProximityLayers );
+  myStdWidget->myVolumeProximityRatio->SetValue( data.myVolumeProximityRatio );
+  if ( !data.myUseSurfaceProximity )
+  {
+    //myStdWidget->myNbSurfaceProximityLayers->setText("");
+    myStdWidget->mySurfaceProximityRatio->setText("");
+  }
+  if ( !data.myUseVolumeProximity )
+  {
+    //myStdWidget->myNbVolumeProximityLayers->setText("");
+    myStdWidget->myVolumeProximityRatio->setText("");
+  }
+
   if (data.myAngleMesh < 0)
     myStdWidget->myAngleMesh->setText("");
   else
@@ -1882,7 +2032,7 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
     else
     {
       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
-    } 
+    }
   }
   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
@@ -1894,7 +2044,7 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
   for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
     TEntry entry = (*evmIt).first;
     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
-    
+
     //QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
 
     TEnfVertexList evs = (*evmIt).second;
@@ -1912,7 +2062,7 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
       that->addEnforcedVertex(x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
     }
   }
-  
+
   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
     myEnforcedTreeWidget->resizeColumnToContents(column);
 
@@ -1922,27 +2072,47 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
 
   // Periodicity
 
-
   // Add an item in the tree widget for each association
   for (size_t i=0 ; i<data.preCadPeriodicityVector.size() ; i++)
+  {
+    QTreeWidgetItem* item = new QTreeWidgetItem();
+    myPeriodicityTreeWidget->addTopLevelItem(item);
+    item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
+    TPreCadPeriodicity periodicity_i = data.preCadPeriodicityVector[i];
+    for (size_t k=0; k<periodicity_i.size(); k++)
     {
-      QTreeWidgetItem* item = new QTreeWidgetItem();
-      myPeriodicityTreeWidget->addTopLevelItem(item);
-      item->setFlags( Qt::ItemIsSelectable   |Qt::ItemIsEnabled );
-      TPreCadPeriodicity periodicity_i = data.preCadPeriodicityVector[i];
-      for (size_t k=0; k<periodicity_i.size(); k++)
-        {
-          string shapeEntry = periodicity_i[k];
-          string shapeName = myGeomToolSelected->getNameFromEntry(shapeEntry);
-          item->setData(k, Qt::EditRole, shapeName.c_str() );
-          item->setData(k, Qt::UserRole, shapeEntry.c_str() );
-        }
+      string shapeEntry = periodicity_i[k];
+      string shapeName = myGeomToolSelected->getNameFromEntry(shapeEntry);
+      item->setData((int) k, Qt::EditRole, shapeName.c_str() );
+      item->setData((int) k, Qt::UserRole, shapeEntry.c_str() );
     }
+  }
 
+  // Hyper patches
+
+  QString patchEntries;
+  for ( int i = 0; i < data.hyperpatches.size(); ++i )
+  {
+    if ( i < data.hyperEntries.size() )
+      patchEntries = data.hyperEntries[i];
+    that->addHyPatchToTable( data.hyperpatches[i], patchEntries );
+  }
   // update widgets
   that->myStdWidget->onPhysicalMeshChanged();
   that->myStdWidget->onGeometricMeshChanged();
   that->onStateChange();
+
+  // Enforced mesh
+
+  BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
+    BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
+
+  BLSURFPlugin::EnforcedMeshesList_var enfMeshes = h->GetEnforcedMeshes();
+  for ( CORBA::ULong i = 0; i < enfMeshes->length(); ++i )
+  {
+    BLSURFPlugin::MG_EnforcedMesh1D & enfMesh = enfMeshes[i];
+    that->addEnforcedMesh( enfMesh.mesh.in(), enfMesh.groupName.in() );
+  }
 }
 
 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
@@ -1984,7 +2154,7 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   h_data.myGradation              = h->GetGradation();
   h_data.myUseVolumeGradation     = h->GetUseVolumeGradation();
   h_data.myVolumeGradation        = h->GetVolumeGradation();
-  h_data.myAllowQuadrangles       = h->GetQuadAllowed();
+  h_data.myElementType            = h->GetElementType();
   double angle                    = h->GetAngleMesh();
   h_data.myAngleMesh              = angle > 0 ? angle : -1.0;
   double chordalError             = h->GetChordalError();
@@ -2000,7 +2170,7 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   h_data.myTinyEdgeOptimisLength  = myTinyEdgeOptimisLength > 0 ? myTinyEdgeOptimisLength : -1.0;
   h_data.myCorrectSurfaceIntersection = h->GetCorrectSurfaceIntersection();
   double corrSurfaceIntersMaxCost = h->GetCorrectSurfaceIntersectionMaxCost();
-  h_data.myCorrectSurfaceIntersectionMaxCost  = corrSurfaceIntersMaxCost > 0 ? corrSurfaceIntersMaxCost : -1.0;
+  h_data.myCorrectSurfaceIntersectionMaxCost = corrSurfaceIntersMaxCost > 0 ? corrSurfaceIntersMaxCost : -1.0;
   h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
   double myBadElementAspectRatio  = h->GetBadElementAspectRatio();
   h_data.myBadElementAspectRatio  = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
@@ -2011,7 +2181,12 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   //h_data.myPreCADMergeEdges       = h->GetPreCADMergeEdges();
   // h_data.myPreCADProcess3DTopology  = h->GetPreCADProcess3DTopology();
   // h_data.myPreCADDiscardInput     = h->GetPreCADDiscardInput();
-
+  h_data.myUseSurfaceProximity      = h->GetSurfaceProximity        ();
+  h_data.myNbSurfaceProximityLayers = h->GetNbSurfaceProximityLayers();
+  h_data.mySurfaceProximityRatio    = h->GetSurfaceProximityRatio   ();
+  h_data.myUseVolumeProximity       = h->GetVolumeProximity         ();
+  h_data.myNbVolumeProximityLayers  = h->GetNbVolumeProximityLayers ();
+  h_data.myVolumeProximityRatio     = h->GetVolumeProximityRatio    ();
 
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
   that->myOptions       = h->GetOptionValues();
@@ -2036,7 +2211,7 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
     if ( fullSizeMapList.count() > 1 ) {
       string fullSizeMap = fullSizeMapList[1].toStdString();
-      int pos = fullSizeMap.find("return")+7;
+      size_t pos = fullSizeMap.find("return")+7;
       QString sizeMap;
       try {
         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
@@ -2138,6 +2313,39 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
 
   BLSURFPlugin::TPeriodicityList_var preCadEdgePeriodicityVector = h->GetPreCadEdgesPeriodicityVector();
   AddPreCadSequenceToVector(h_data, preCadEdgePeriodicityVector, false);
+
+  // Hyper Patches
+
+  GEOM::GEOM_Object_var geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getMainShapeEntry() );
+  if ( geom->_is_nil() )
+    geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getShapeEntry() );
+
+  h_data.hyperpatches.clear();
+  h_data.hyperEntries.clear();
+  BLSURFPlugin::THyperPatchList_var               patchList = h->GetHyperPatches( geom );
+  BLSURFPlugin::THyperPatchEntriesList_var patchEntriesList = h->GetHyperPatchShapes();
+  for ( CORBA::ULong i = 0; i < patchList->length(); ++i )
+  {
+    QString tags;
+    BLSURFPlugin::THyperPatch& patch = patchList[i];
+    for ( CORBA::ULong j = 0; j < patch.length(); ++j )
+      tags += QString::number( patch[j] ) + " ";
+    if ( !tags.isEmpty() )
+      h_data.hyperpatches.append( tags );
+
+    if ( patchEntriesList->length() == patchList->length() )
+    {
+      QString entries;
+      BLSURFPlugin::THyperPatchEntries& patchEntries = patchEntriesList[i];
+      for ( CORBA::ULong j = 0; j < patchEntries.length(); ++j )
+        entries += patchEntries[j].in() + QString(" ");
+      if ( !entries.isEmpty() )
+        h_data.hyperEntries.append( entries );
+    }
+  }
+  if ( h_data.hyperpatches.size() != h_data.hyperEntries.size() )
+    h_data.hyperEntries.clear();
+
   return true;
 }
 
@@ -2145,7 +2353,7 @@ void BLSURFPluginGUI_HypothesisCreator::AddPreCadSequenceToVector(BlsurfHypothes
     BLSURFPlugin::TPeriodicityList_var preCadFacePeriodicityVector, bool onFace) const
 {
 
-  for (size_t i=0; i<preCadFacePeriodicityVector->length(); i++ )
+  for (CORBA::ULong i=0; i<preCadFacePeriodicityVector->length(); i++ )
     {
       TPreCadPeriodicity periodicity_i(PERIODICITY_NB_COLUMN);
       periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN] = preCadFacePeriodicityVector[i].shape1Entry.in();
@@ -2158,14 +2366,16 @@ void BLSURFPluginGUI_HypothesisCreator::AddPreCadSequenceToVector(BlsurfHypothes
         {
           periodicity_i[PERIODICITY_P1_SOURCE_COLUMN] = sourceVertices[0].in();
           periodicity_i[PERIODICITY_P2_SOURCE_COLUMN] = sourceVertices[1].in();
-          periodicity_i[PERIODICITY_P3_SOURCE_COLUMN] = sourceVertices[2].in();
+          if ( onFace )
+            periodicity_i[PERIODICITY_P3_SOURCE_COLUMN] = sourceVertices[2].in();
         }
 
       if (targetVertices.length()!=0)
         {
           periodicity_i[PERIODICITY_P1_TARGET_COLUMN] = targetVertices[0].in();
           periodicity_i[PERIODICITY_P2_TARGET_COLUMN] = targetVertices[1].in();
-          periodicity_i[PERIODICITY_P3_TARGET_COLUMN] = targetVertices[2].in();
+          if ( onFace )
+            periodicity_i[PERIODICITY_P3_TARGET_COLUMN] = targetVertices[2].in();
         }
 
       if (onFace)
@@ -2228,26 +2438,33 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
     if ( h->GetVolumeGradation() !=  h_data.myVolumeGradation )
       h->SetVolumeGradation( h_data.myVolumeGradation <= 0 ? -1 : h_data.myVolumeGradation );
 
-    if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
-      h->SetQuadAllowed( h_data.myAllowQuadrangles );
-    
+    h->SetSurfaceProximity        ((CORBA::Short) h_data.myUseSurfaceProximity      );
+    h->SetNbSurfaceProximityLayers((CORBA::Short) h_data.myNbSurfaceProximityLayers );
+    h->SetSurfaceProximityRatio   ( h_data.mySurfaceProximityRatio    );
+    h->SetVolumeProximity         ((CORBA::Short) h_data.myUseVolumeProximity       );
+    h->SetNbVolumeProximityLayers ((CORBA::Short) h_data.myNbVolumeProximityLayers  );
+    h->SetVolumeProximityRatio    ( h_data.myVolumeProximityRatio     );
+
+    if ( h->GetElementType() != h_data.myElementType )
+      h->SetElementType( h_data.myElementType );
+
     if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
       if ( h->GetAngleMesh() != h_data.myAngleMesh )
         h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
       if ( h->GetChordalError() != h_data.myChordalError )
         h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
     }
-    
+
     if ( h->GetAnisotropic() != h_data.myAnisotropic )
       h->SetAnisotropic( h_data.myAnisotropic );
     if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
       h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
-    
+
     if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
       h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
     if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
       h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
-    
+
     if ( h->GetOptimiseTinyEdges() != h_data.myOptimiseTinyEdges )
       h->SetOptimiseTinyEdges( h_data.myOptimiseTinyEdges );
     if ( h_data.myOptimiseTinyEdges && ( h->GetTinyEdgeOptimisationLength() != h_data.myTinyEdgeOptimisLength ) )
@@ -2266,10 +2483,10 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
       h->SetOptimizeMesh( h_data.myOptimizeMesh );    
     
     if ( h->GetQuadraticMesh() != h_data.myQuadraticMesh )
-      h->SetQuadraticMesh( h_data.myQuadraticMesh );    
+      h->SetQuadraticMesh( h_data.myQuadraticMesh );
 
     if ( h->GetVerbosity() != h_data.myVerbosity )
-      h->SetVerbosity( h_data.myVerbosity );
+      h->SetVerbosity((CORBA::Short) h_data.myVerbosity );
     // if ( h->GetTopology() != h_data.myTopology )
     //   h->SetTopology( (int) h_data.myTopology );
     // if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
@@ -2282,10 +2499,10 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
     // options are set in checkParams()
     //h->SetOptionValues( myOptions ); // is set in readParamsFromWidgets()
     //h->SetPreCADOptionValues( myPreCADOptions ); // is set in readParamsFromWidgets()
-    
+
     if ( h->GetGMFFile() != h_data.myGMFFileName )
-//       || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
-//       h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
+      //       || ( h->GetGMFFileMode() != h_data.myGMFFileMode ) )
+      //       h->SetGMFFile( h_data.myGMFFileName.c_str(), h_data.myGMFFileMode );
       h->SetGMFFile( h_data.myGMFFileName.c_str());
 
     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
@@ -2302,7 +2519,7 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
       }
       else if (sizeMap.startsWith("def")) {
-//        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
+        //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
       }
       else {
         if (!myATTMap[entry].empty()){
@@ -2340,13 +2557,13 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
     double x, y, z = 0;
     std::string enfName;
     /* TODO GROUPS
-    std::string groupName = "";
+       std::string groupName = "";
     */
 
     TFaceEntryEnfVertexListMap::const_iterator evmIt = h_data.faceEntryEnfVertexListMap.begin();
     // 1. Clear all enforced vertices in hypothesis
     // 2. Add new enforced vertex according to h_data
-    
+
     if ( h->GetAllEnforcedVertices()->length() > 0 )
       h->ClearAllEnforcedVertices();
     TEnfName faceEntry;
@@ -2377,65 +2594,113 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
 
     // Periodicity
     if ( h->GetPreCadFacesPeriodicityVector()->length() > 0 || h->GetPreCadEdgesPeriodicityVector()->length() > 0 )
-          h->ClearPreCadPeriodicityVectors();
+      h->ClearPreCadPeriodicityVectors();
 
     TPreCadPeriodicityVector::const_iterator pIt = h_data.preCadPeriodicityVector.begin();
     for ( ; pIt != h_data.preCadPeriodicityVector.end() ; ++pIt)
+    {
+      TPreCadPeriodicity periodicity_i = *pIt;
+      TEntry source = periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN];
+      TEntry target = periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN];
+      TEntry p1Source = periodicity_i[PERIODICITY_P1_SOURCE_COLUMN];
+      TEntry p2Source = periodicity_i[PERIODICITY_P2_SOURCE_COLUMN];
+      TEntry p3Source = periodicity_i[PERIODICITY_P3_SOURCE_COLUMN];
+      TEntry p1Target = periodicity_i[PERIODICITY_P1_TARGET_COLUMN];
+      TEntry p2Target = periodicity_i[PERIODICITY_P2_TARGET_COLUMN];
+      TEntry p3Target = periodicity_i[PERIODICITY_P3_TARGET_COLUMN];
+      bool onFace = (periodicity_i[PERIODICITY_SHAPE_TYPE]=="1") ? true : false;
+
+      BLSURFPlugin::TEntryList_var sourceVertices = new BLSURFPlugin::TEntryList();
+      if (! p1Source.empty())
       {
-        TPreCadPeriodicity periodicity_i = *pIt;
-        TEntry source = periodicity_i[PERIODICITY_OBJ_SOURCE_COLUMN];
-        TEntry target = periodicity_i[PERIODICITY_OBJ_TARGET_COLUMN];
-        TEntry p1Source = periodicity_i[PERIODICITY_P1_SOURCE_COLUMN];
-        TEntry p2Source = periodicity_i[PERIODICITY_P2_SOURCE_COLUMN];
-        TEntry p3Source = periodicity_i[PERIODICITY_P3_SOURCE_COLUMN];
-        TEntry p1Target = periodicity_i[PERIODICITY_P1_TARGET_COLUMN];
-        TEntry p2Target = periodicity_i[PERIODICITY_P2_TARGET_COLUMN];
-        TEntry p3Target = periodicity_i[PERIODICITY_P3_TARGET_COLUMN];
-        bool onFace = (periodicity_i[PERIODICITY_SHAPE_TYPE]=="1") ? true : false;
-
-        BLSURFPlugin::TEntryList_var sourceVertices = new BLSURFPlugin::TEntryList();
-        if (! p1Source.empty())
-          {
-            sourceVertices->length(3);
-            sourceVertices[0]=CORBA::string_dup(p1Source.c_str());
-            sourceVertices[1]=CORBA::string_dup(p2Source.c_str());
-            sourceVertices[2]=CORBA::string_dup(p3Source.c_str());
-          }
+        sourceVertices->length(3);
+        sourceVertices[0]=CORBA::string_dup(p1Source.c_str());
+        sourceVertices[1]=CORBA::string_dup(p2Source.c_str());
+        sourceVertices[2]=CORBA::string_dup(p3Source.c_str());
+      }
 
 
-        BLSURFPlugin::TEntryList_var targetVertices = new BLSURFPlugin::TEntryList();
-        if (! p1Target.empty())
-          {
-            targetVertices->length(3);
-            targetVertices[0]=CORBA::string_dup(p1Target.c_str());
-            targetVertices[1]=CORBA::string_dup(p2Target.c_str());
-            targetVertices[2]=CORBA::string_dup(p3Target.c_str());
-          }
+      BLSURFPlugin::TEntryList_var targetVertices = new BLSURFPlugin::TEntryList();
+      if (! p1Target.empty())
+      {
+        targetVertices->length(3);
+        targetVertices[0]=CORBA::string_dup(p1Target.c_str());
+        targetVertices[1]=CORBA::string_dup(p2Target.c_str());
+        targetVertices[2]=CORBA::string_dup(p3Target.c_str());
+      }
 
-        if (onFace)
-          h->AddPreCadFacesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
-        else
-          h->AddPreCadEdgesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
+      if (onFace)
+        h->AddPreCadFacesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
+      else
+        h->AddPreCadEdgesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
+    }
+
+    // Hyper-patches
+    BLSURFPlugin::THyperPatchList_var         hpl = new BLSURFPlugin::THyperPatchList();
+    BLSURFPlugin::THyperPatchEntriesList_var hpel = new BLSURFPlugin::THyperPatchEntriesList();
+    hpl ->length( h_data.hyperpatches.size() );
+    hpel->length( h_data.hyperEntries.size() );
+
+    for ( int i = 0; i < h_data.hyperpatches.size(); ++i )
+    {
+      QStringList tags = h_data.hyperpatches[i].split(" ",  QString::SkipEmptyParts);
+      BLSURFPlugin::THyperPatch& patch = hpl[ i ];
+      patch.length( tags.size() );
+
+      for ( int j = 0; j < tags.size(); ++j )
+        patch[ j ] = tags[ j ].toInt();
+
+      if ( i < h_data.hyperEntries.size() )
+      {
+        QStringList entries = h_data.hyperEntries[i].split(" ",  QString::SkipEmptyParts);
+        BLSURFPlugin::THyperPatchEntries& pe = hpel[ i ];
+        pe.length( entries.size() );
+
+        for ( int j = 0; j < entries.size(); ++j )
+          pe[ j ] = CORBA::string_dup( entries[ j ].toStdString().c_str() );
       }
+    }
+    if ( h_data.hyperEntries.size() == h_data.hyperpatches.size() )
+      h->SetHyperPatchEntries( hpel );
+    else
+      h->SetHyperPatches( hpl );
+
 
+    // Enforced meshes
+    BLSURFPlugin::EnforcedMeshesList_var enfMeshesList = new BLSURFPlugin::EnforcedMeshesList();
+    enfMeshesList->length( myEnfMeshTableWdg->rowCount() );
+
+    int nbMeshes = 0;
+    for ( int row = 0, nbRow = myEnfMeshTableWdg->rowCount(); row < nbRow; ++row )
+    {
+      QTableWidgetItem *  meshCell = myEnfMeshTableWdg->item( row, 0 );
+      QString                entry = meshCell->data( Qt::UserRole ).toString();
+      QTableWidgetItem * groupCell = myEnfMeshTableWdg->item( row, 1 );
+      QString            groupName = groupCell->text();
+
+      SMESH::SMESH_IDSource_var mesh = SMESH::EntryToInterface< SMESH::SMESH_IDSource >( entry );
+      if ( !mesh->_is_nil() )
+      {
+        enfMeshesList[ nbMeshes ].mesh = SMESH::SMESH_IDSource::_duplicate( mesh );
+        enfMeshesList[ nbMeshes ].groupName = CORBA::string_dup( groupName.toStdString().c_str() );
+        ++nbMeshes;
+      }
+    }
+    enfMeshesList->length( nbMeshes );
+
+    h->SetEnforcedMeshes( enfMeshesList );
 
 
   } // try
-  catch(const std::exception& ex) {
-    std::cout << "Exception: " << ex.what() << std::endl;
-    throw ex;
-  }
-//   catch(const SALOME::SALOME_Exception& ex)
-//   {
-//     throw ex;
-// //     SalomeApp_Tools::QtCatchCorbaException(ex);
-// //     ok = false;
-//   }
+  catch(...) {
+    ok = false;
+  }
+
   return ok;
 }
 
 /** BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets(h_data)
-Stores the widgets content to the hypothesis data.
+    Stores the widgets content to the hypothesis data.
 */
 QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothesisData& h_data ) const
 {
@@ -2452,7 +2717,7 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   h_data.myGradation             = h_data.myUseGradation ? myStdWidget->myGradation->GetValue() : -1.0;
   h_data.myUseVolumeGradation    = myStdWidget->myUseVolumeGradation->isChecked() && !myStdWidget->myVolumeGradation->text().isEmpty();
   h_data.myVolumeGradation       = h_data.myUseVolumeGradation ? myStdWidget->myVolumeGradation->GetValue() : -1. ;
-  h_data.myAllowQuadrangles      = myStdWidget->myAllowQuadrangles->isChecked();
+  h_data.myElementType           = myStdWidget->myButtonGroupElementType->checkedId();
   h_data.myAngleMesh             = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
   h_data.myChordalError          = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
   h_data.myAnisotropic           = myStdWidget->myAnisotropic->isChecked();
@@ -2472,6 +2737,12 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   //h_data.myPreCADMergeEdges      = myAdvWidget->myPreCADMergeEdges->isChecked();
   //h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
   //h_data.myPreCADDiscardInput    = myAdvWidget->myPreCADDiscardInput->isChecked();
+  h_data.myUseSurfaceProximity      = myStdWidget->myUseSurfaceProximity     ->isChecked();
+  h_data.myNbSurfaceProximityLayers = myStdWidget->myNbSurfaceProximityLayers->value();
+  h_data.mySurfaceProximityRatio    = myStdWidget->mySurfaceProximityRatio   ->value();
+  h_data.myUseVolumeProximity       = myStdWidget->myUseVolumeProximity      ->isChecked();
+  h_data.myNbVolumeProximityLayers  = myStdWidget->myNbVolumeProximityLayers ->value();
+  h_data.myVolumeProximityRatio     = myStdWidget->myVolumeProximityRatio    ->value();
 
   QString guiHyp;
   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
@@ -2483,7 +2754,7 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   guiHyp += tr("BLSURF_MAXSIZE") + " = "+ QString::number( h_data.myMaxSize ) + "; ";
   guiHyp += tr("BLSURF_MAXSIZE") + " " + tr("BLSURF_SIZE_REL") + " = " + QString(h_data.myMaxSizeRel ? "yes" : "no") + "; ";
   guiHyp += tr("BLSURF_GRADATION") + " = " + QString::number( h_data.myGradation ) + "; ";
-  guiHyp += tr("BLSURF_ALLOW_QUADRANGLES") + " = " + QString(h_data.myAllowQuadrangles ? "yes" : "no") + "; ";
+  guiHyp += tr("BLSURF_ELEMENT_TYPE") + " = " + QString::number(h_data.myElementType) + "; ";
   guiHyp += tr("BLSURF_ANGLE_MESH") + " = " + QString::number( h_data.myAngleMesh ) + "; ";
   guiHyp += tr("BLSURF_CHORDAL_ERROR") + " = " + QString::number( h_data.myChordalError ) + "; ";
   guiHyp += tr("BLSURF_ANISOTROPIC") + " = " + QString(h_data.myAnisotropic ? "yes" : "no") + "; ";
@@ -2580,6 +2851,19 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
     guiHyp += "PERIODICITY = yes; ";
   }
 
+  // Hyper-patches
+  h_data.hyperpatches.clear();
+  h_data.hyperEntries.clear();
+  for ( int row = 0; row < myHyPatchTable->rowCount(); ++row )
+  {
+    QTableWidgetItem* cell = myHyPatchTable->item( row, 0 );
+    h_data.hyperpatches.append( cell->text() );
+    if ( cell->data( Qt::UserRole ).isValid() )
+      h_data.hyperEntries.append( cell->data( Qt::UserRole ).toString() );
+  }
+  if ( h_data.hyperpatches.size() != h_data.hyperEntries.size() )
+    h_data.hyperEntries.clear();
+
   return guiHyp;
 }
 
@@ -2588,7 +2872,7 @@ void BLSURFPluginGUI_HypothesisCreator::onAddOption()
   myAdvWidget->AddOption( TBL_CUSTOM, NULL );
 }
 
-void BLSURFPluginGUI_HypothesisCreator::onChangeOptionName( int row, int column )
+void BLSURFPluginGUI_HypothesisCreator::onChangeOptionName( int /*row*/, int /*column*/ )
 {
   // if ( column != OPTION_NAME_COLUMN )
   //   return;
@@ -2633,7 +2917,7 @@ void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
-{ 
+{
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
   if (col == SMP_SIZEMAP_COLUMN) {
     QString entry   = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
@@ -2657,7 +2941,7 @@ void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item,
       const TAttractorVec& attVec = myATTMap[entry];
       if ( !attVec.empty() )
       {
-        int iAtt = 0;
+        size_t iAtt = 0;
         if ( !childEntry.isEmpty() )
           for ( size_t i = 0; i < attVec.size(); ++i )
             if ( childEntry == attVec[i].attEntry.c_str() )
@@ -2707,7 +2991,6 @@ void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
     myGeomSelWdg1             ->deactivateSelection();
     myGeomSelWdg2             ->deactivateSelection();
     myAttSelWdg               ->deactivateSelection();
-    //myEnfFaceWdg              ->deactivateSelection();
     myEnfVertexWdg            ->deactivateSelection();
     myPeriodicitySourceFaceWdg->deactivateSelection();
     myPeriodicityTargetFaceWdg->deactivateSelection();
@@ -2717,7 +3000,11 @@ void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
     myPeriodicityP1TargetWdg  ->deactivateSelection();
     myPeriodicityP2TargetWdg  ->deactivateSelection();
     myPeriodicityP3TargetWdg  ->deactivateSelection();
-    return;
+    myEnfMeshWdg              ->deactivateSelection();
+    if ( myHyPatchFaceSelBtn->isChecked() )
+      myHyPatchFaceSelBtn->toggle();
+    if ( myHyPatchGroupSelBtn->isChecked() )
+      myHyPatchGroupSelBtn->toggle();
   }
   else if ( sender() == smpTab )
   {
@@ -2734,6 +3021,31 @@ void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
     myAttractorCheck->setChecked(false);
     myConstSizeCheck->setChecked(false);
   }
+
+  if ( tab == SMP_TAB ) // [#16954] limit local size by Min and User Size
+  {
+    double minSize = 0, maxSize = COORD_MAX;
+
+    if ( !myStdWidget->myMinSizeRel->isChecked() &&
+         !myStdWidget->myMinSize->text().isEmpty() )
+      minSize = myStdWidget->myMinSize->GetValue();
+
+    if ( !myStdWidget->myPhySizeRel->isChecked() &&
+         !myStdWidget->myPhySize->text().isEmpty() )
+      maxSize = myStdWidget->myPhySize->GetValue();
+
+    mySmpSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
+    myAttSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
+  }
+
+  if ( tab == ENF_M_TAB )
+  {
+    myEnfMeshWdg->activateSelection();
+    onEnforcedMeshSelected(); // update buttons
+    onEnfMeshTableSelected();
+    if ( myEnforcedGroupName->text().isEmpty() )
+      myEnforcedGroupName->setText("Group 1D");
+  }
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
@@ -3237,6 +3549,294 @@ bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEnt
   return true;
 }
 
+//================================================================================
+/*!
+ * \brief SLOT: Activate selection of faces in the Viewer
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchFaceSelection(bool on)
+{
+  if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
+  {
+    QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
+    QString aSubEntry  = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+    myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
+  }
+  myHyPatchFaceSelector->setVisible( on );  // show its buttons
+  myHyPatchFaceSelector->ShowPreview( on ); // show faces in the Viewer
+  // treat selection or not
+  myHyPatchFaceSelector->ActivateSelection( on || myHyPatchGroupSelBtn->isChecked() );
+
+  if ( on )
+    myHyPatchGroupSelBtn->setChecked( false );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: Deactivate selection of faces in the Viewer
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchGroupSelection(bool on)
+{
+  if ( on && myHyPatchFaceSelector->GetMainShape().IsNull() )
+  {
+    QString aMainEntry = SMESHGUI_GenericHypothesisCreator::getMainShapeEntry();
+    QString aSubEntry  = SMESHGUI_GenericHypothesisCreator::getShapeEntry();
+    myHyPatchFaceSelector->SetGeomShapeEntry( aSubEntry, aMainEntry );
+  }
+  if ( !myHyPatchFaceSelBtn->isChecked() )
+  {
+    myHyPatchFaceSelector->setVisible( false ); // show its buttons
+    myHyPatchFaceSelector->ShowPreview( false ); // show faces in the Viewer
+  }
+  // treat selection or not
+  myHyPatchFaceSelector->ActivateSelection( on || myHyPatchFaceSelBtn->isChecked() );
+
+  if ( on )
+    myHyPatchFaceSelBtn->setChecked( false );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: show IDs of selected faces in Tags LineEdit
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchSelectionChanged()
+{
+  QString tagString;
+  const QList<int>& tags = myHyPatchFaceSelector->GetSelectedIDs();
+  for ( int i = 0; i < tags.size(); ++i )
+    tagString += QString::number( tags[i] ) + " ";
+
+  myHyPatchTagsLE->setText( tagString );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: Add the Tags to the HyperPatch table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd()
+{
+  QStringList tagList = myHyPatchTagsLE->text().split(" ",  QString::SkipEmptyParts);
+  if ( tagList.size() > 1 )
+  {
+    LightApp_SelectionMgr* selMrg = SMESHGUI::GetSMESHGUI()->selectionMgr();
+    SALOME_ListIO aList;
+    selMrg->selectedObjects( aList );
+    QString entries;
+    for ( SALOME_ListIteratorOfListIO anIt( aList ); anIt.More(); anIt.Next() )
+    {
+      Handle(SALOME_InteractiveObject) io = anIt.Value();
+      GEOM::GEOM_Object_var go = myHyPatchFaceSelector->GetGeomObjectByEntry( io->getEntry() );
+      if ( !CORBA::is_nil( go ))
+        entries += io->getEntry() + QString(" ");
+      else
+      {
+        entries.clear();
+        break;
+      }
+    }
+    addHyPatchToTable( myHyPatchTagsLE->text(), entries );
+    myHyPatchTagsLE->setText("");
+  }
+}
+
+//================================================================================
+/*!
+ * \brief Add a row to myHyPatchTable
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::addHyPatchToTable(const QString& tags,
+                                                          const QString& entries)
+{
+  if ( tags.isEmpty() ) return;
+
+  QTableWidgetItem* cell = new QTableWidgetItem( tags );
+  cell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
+  if ( entries.isEmpty() )
+    cell->setData( Qt::UserRole, QVariant() );
+  else
+    cell->setData( Qt::UserRole, entries );
+
+  int row = myHyPatchTable->rowCount();
+  myHyPatchTable->insertRow( row );
+  myHyPatchTable->setItem( row, 0, cell );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT: remove selected rows from the HyperPatch table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onHyPatchRemove()
+{
+  QList<QTableWidgetItem *> items = myHyPatchTable->selectedItems();
+  while ( !items.isEmpty() )
+  {
+    myHyPatchTable->removeRow( items[0]->row() );
+    items = myHyPatchTable->selectedItems();
+  }
+}
+
+//================================================================================
+/*!
+ * \brief Add a new row in Enforced mesh table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::addEnforcedMesh( SMESH::SMESH_IDSource_ptr mesh,
+                                                         const QString&            groupName  )
+{
+  _PTR(SObject) sobj = SMESH::FindSObject( mesh );
+  if ( !sobj )
+    return;
+
+  QString meshEntry = sobj->GetID().c_str();
+  QString meshName  = sobj->GetName().c_str();
+
+  QTableWidgetItem* meshCell = new QTableWidgetItem( meshName );
+  meshCell->setData( Qt::UserRole, meshEntry );
+  meshCell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
+
+  QTableWidgetItem* groupCell = new QTableWidgetItem( groupName );
+  groupCell->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable );
+
+  int row = myEnfMeshTableWdg->rowCount();
+  myEnfMeshTableWdg->insertRow( row );
+  myEnfMeshTableWdg->setItem( row, 0, meshCell );
+  myEnfMeshTableWdg->setItem( row, 1, groupCell );
+
+  myEnfMeshTableWdg->resizeColumnToContents( 0 );
+  myEnfMeshTableWdg->resizeColumnToContents( 1 );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when [Add] is clicked in Enforced mesh tab.
+ *        Add an item to the enforced meshes table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedMesh()
+{
+  if ( myEnfMeshWdg->NbObjects() != 1 )
+    return;
+
+  SMESH::SMESH_IDSource_var mesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >();
+  QString              groupName = myEnforcedGroupName->text().simplified();
+
+  addEnforcedMesh( mesh, groupName );
+
+  selectionMgr()->clearSelected();
+  myEnfMeshWdg->SetObject( SMESH::SMESH_IDSource::_nil() );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when [Remove] is clicked in Enforced mesh tab.
+ *        Remove a selected mesh from the enforced meshes table
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedMesh()
+{
+  QList<int> selectedRows;
+  QList<QTableWidgetItem *> selectedItems = myEnfMeshTableWdg->selectedItems();
+  QTableWidgetItem* item;
+  int row;
+  foreach( item, selectedItems )
+  {
+    row = item->row();
+    if (!selectedRows.contains( row ) )
+      selectedRows.append(row);
+  }
+
+  qSort( selectedRows );
+  QListIterator<int> it( selectedRows );
+  it.toBack();
+  while ( it.hasPrevious() ) {
+    row = it.previous();
+    myEnfMeshTableWdg->removeRow(row );
+  }
+
+  myEnfMeshTableWdg->selectionModel()->clearSelection();
+
+  onEnforcedMeshSelected(); // to activate [Add] if possible
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when mesh selection changes. Enable/disable [Add] button
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onEnforcedMeshSelected()
+{
+  bool enable = ( myEnfMeshWdg->NbObjects() == 1 );
+  if ( enable )
+  {
+    // check if a selected mesh contains segments
+    SMESH::SMESH_IDSource_var mesh = myEnfMeshWdg->GetObject< SMESH::SMESH_IDSource >();
+    if (( enable = !mesh->_is_nil() ))
+    {
+      SMESH::array_of_ElementType_var types = mesh->GetTypes();
+      if (( enable = ( types->length() > 0 )))
+      {
+        enable = false;
+        for ( CORBA::ULong i = 0; i < types->length() &&  !enable; ++i )
+          enable = ( types[ i ] = SMESH::EDGE );
+      }
+    }
+
+    // check if this mesh is already in the table
+    if ( enable )
+    {
+      _PTR(SObject) sobj = SMESH::FindSObject( mesh );
+      if (( enable = bool( sobj )))
+      {
+        QString meshEntry = sobj->GetID().c_str();
+        for ( int row = 0, nbRow = myEnfMeshTableWdg->rowCount(); row < nbRow &&  enable; ++row )
+        {
+          QTableWidgetItem * cell = myEnfMeshTableWdg->item( row, 0 );
+          enable = ( meshEntry != cell->data( Qt::UserRole ).toString() );
+        }
+      }
+    }
+  }
+  myAddEnfMeshButton->setEnabled( enable );
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when selection changes in the table. Enable/disable [Remove] button
+ */
+//================================================================================
+
+void BLSURFPluginGUI_HypothesisCreator::onEnfMeshTableSelected()
+{
+  bool enable = !myEnfMeshTableWdg->selectedItems().empty();
+
+  myRemoveEnfMeshButton->setEnabled( enable );
+}
+
+//================================================================================
+/*!
+ * \brief Return false if algorithm is a re-mesher
+ */
+//================================================================================
+
+bool BLSURFPluginGUI_HypothesisCreator::hasGeom() const
+{
+  return hypType() == BLSURFPlugin_Hypothesis::GetHypType(true);
+}
+
 QString BLSURFPluginGUI_HypothesisCreator::caption() const
 {
   return tr( "BLSURF_TITLE" );
@@ -3269,10 +3869,8 @@ LightApp_SelectionMgr* BLSURFPluginGUI_HypothesisCreator::selectionMgr()
 
 CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry)
 {
-  SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
-  SALOMEDS::Study_var myStudy = smeshGen_i->GetCurrentStudy();
   CORBA::Object_var obj;
-  SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.toStdString().c_str() );
+  SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( entry.toStdString().c_str() );
   if (!aSObj->_is_nil()) {
     obj = aSObj->GetObject();
     aSObj->UnRegister();