Salome HOME
bos #20256: [CEA 18523] Porting SMESH to int 64 bits
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
index 886b17408f1021b9143532267dbf17708038df9a..c21e967796705f85f3224dc62ef2649e9be1f9b1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D
 //
 // 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_ListIteratorOfListIO.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;
 
 enum {
   STD_TAB = 0,
@@ -88,12 +85,17 @@ enum {
   SMP_TAB,
   ENF_TAB,
   PERIODICITY_TAB,
+  HYPERPATCH_TAB,
   SMP_NAME_COLUMN =0,
   SMP_SIZEMAP_COLUMN,
   SMP_ENTRY_COLUMN,
 //  SMP_DIST_COLUMN,
   SMP_NB_COLUMNS,
-// Enforced vertices array columns
+
+  // Adv tables
+  TBL_MESHING = 0, TBL_PRECAD, TBL_CUSTOM,
+
+  // Enforced vertices array columns
   ENF_VER_NAME_COLUMN = 0,
   ENF_VER_FACE_ENTRY_COLUMN,
   ENF_VER_X_COLUMN,
@@ -159,7 +161,7 @@ enum {
 // Enforced vertices inputs
 enum {
   ENF_VER_FACE = 0,
-  ENF_VER_VERTEX,
+  ENF_VER_VERTEX = 0,
   ENF_VER_X_COORD,
   ENF_VER_Y_COORD,
   ENF_VER_Z_COORD,
@@ -181,102 +183,109 @@ enum {
  Begin initialization Python structures and objects
 ***************************************************/
 
-typedef struct {
-  PyObject_HEAD
-  int softspace;
-  std::string *out;
-  } PyStdOut;
-
-static void
-PyStdOut_dealloc(PyStdOut *self)
-{
-  PyObject_Del(self);
-}
-
-static PyObject *
-PyStdOut_write(PyStdOut *self, PyObject *args)
-{
-  char *c;
-  int l;
-  if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
-    return NULL;
-
-  //std::cerr << c ;
-  *(self->out)=*(self->out)+c;
+namespace {
+  typedef struct {
+    PyObject_HEAD
+    int softspace;
+    std::string *out;
+    } PyStdOut;
 
-  Py_INCREF(Py_None);
-  return Py_None;
-}
-
-static PyMethodDef PyStdOut_methods[] = { 
-  {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
-  PyDoc_STR("write(string) -> None")},
-  {NULL,    NULL}   /* 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 */
-};
-
-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*/
-  "PyOut",                      /*tp_name*/
-  sizeof(PyStdOut),             /*tp_basicsize*/
-  0,                            /*tp_itemsize*/
-  /* methods */
-  (destructor)PyStdOut_dealloc, /*tp_dealloc*/
-  0,                            /*tp_print*/
-  0,                            /*tp_getattr*/
-  0,                            /*tp_setattr*/
-  0,                            /*tp_compare*/
-  0,                            /*tp_repr*/
-  0,                            /*tp_as_number*/
-  0,                            /*tp_as_sequence*/
-  0,                            /*tp_as_mapping*/
-  0,                            /*tp_hash*/
-  0,                            /*tp_call*/
-  0,                            /*tp_str*/
-  PyObject_GenericGetAttr,      /*tp_getattro*/
-  /* softspace is writable:  we must supply tp_setattro */
-  PyObject_GenericSetAttr,      /* tp_setattro */
-  0,                            /*tp_as_buffer*/
-  Py_TPFLAGS_DEFAULT,           /*tp_flags*/
-  0,                            /*tp_doc*/
-  0,                            /*tp_traverse*/
-  0,                            /*tp_clear*/
-  0,                            /*tp_richcompare*/
-  0,                            /*tp_weaklistoffset*/
-  0,                            /*tp_iter*/
-  0,                            /*tp_iternext*/
-  PyStdOut_methods,             /*tp_methods*/
-  PyStdOut_memberlist,          /*tp_members*/
-  0,                            /*tp_getset*/
-  0,                            /*tp_base*/
-  0,                            /*tp_dict*/
-  0,                            /*tp_descr_get*/
-  0,                            /*tp_descr_set*/
-  0,                            /*tp_dictoffset*/
-  0,                            /*tp_init*/
-  0,                            /*tp_alloc*/
-  0,                            /*tp_new*/
-  0,                            /*tp_free*/
-  0,                            /*tp_is_gc*/
-};
+  static void
+  PyStdOut_dealloc(PyStdOut *self)
+  {
+    PyObject_Del(self);
+  }
 
-PyObject * newPyStdOut( std::string& out )
-{
-  PyStdOut *self;
-  self = PyObject_New(PyStdOut, &PyStdOut_Type);
-  if (self == NULL)
-    return NULL;
-  self->softspace = 0;
-  self->out=&out;
-  return (PyObject*)self;
+  static PyObject *
+  PyStdOut_write(PyStdOut *self, PyObject *args)
+  {
+    char *c;
+    int l;
+    if (!PyArg_ParseTuple(args, "t#:write",&c, &l))
+      return NULL;
+
+    *(self->out)=*(self->out)+c;
+
+    Py_INCREF(Py_None);
+    return Py_None;
+  }
+
+  static PyMethodDef PyStdOut_methods[] = {
+    {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
+    PyDoc_STR("write(string) -> None")},
+    {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"},
+    {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++. */
+    PyVarObject_HEAD_INIT(NULL, 0)
+    "PyOut",                      /*tp_name*/
+    sizeof(PyStdOut),             /*tp_basicsize*/
+    0,                            /*tp_itemsize*/
+    /* methods */
+    (destructor)PyStdOut_dealloc, /*tp_dealloc*/
+    0,                            /*tp_print*/
+    0,                            /*tp_getattr*/
+    0,                            /*tp_setattr*/
+    0,                            /*tp_compare*/
+    0,                            /*tp_repr*/
+    0,                            /*tp_as_number*/
+    0,                            /*tp_as_sequence*/
+    0,                            /*tp_as_mapping*/
+    0,                            /*tp_hash*/
+    0,                            /*tp_call*/
+    0,                            /*tp_str*/
+    PyObject_GenericGetAttr,      /*tp_getattro*/
+    /* softspace is writable:  we must supply tp_setattro */
+    PyObject_GenericSetAttr,      /* tp_setattro */
+    0,                            /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT,           /*tp_flags*/
+    0,                            /*tp_doc*/
+    0,                            /*tp_traverse*/
+    0,                            /*tp_clear*/
+    0,                            /*tp_richcompare*/
+    0,                            /*tp_weaklistoffset*/
+    0,                            /*tp_iter*/
+    0,                            /*tp_iternext*/
+    PyStdOut_methods,             /*tp_methods*/
+    PyStdOut_memberlist,          /*tp_members*/
+    0,                            /*tp_getset*/
+    0,                            /*tp_base*/
+    0,                            /*tp_dict*/
+    0,                            /*tp_descr_get*/
+    0,                            /*tp_descr_set*/
+    0,                            /*tp_dictoffset*/
+    0,                            /*tp_init*/
+    0,                            /*tp_alloc*/
+    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 )
+  {
+    PyStdOut* self = PyObject_New(PyStdOut, &PyStdOut_Type);
+    if (self) {
+      self->softspace = 0;
+      self->out=&out;
+    }
+    return (PyObject*)self;
+  }
 }
 
 /*************************************************
@@ -294,7 +303,7 @@ EnforcedTreeWidgetDelegate::EnforcedTreeWidgetDelegate(QObject *parent)
 }
 
 QWidget *EnforcedTreeWidgetDelegate::createEditor(QWidget *parent,
-                                              const QStyleOptionViewItem & option ,
+                                              const QStyleOptionViewItem & /*option*/ ,
                                               const QModelIndex & index ) const
 {
   QModelIndex father = index.parent();
@@ -439,7 +448,6 @@ bool EnforcedTreeWidgetDelegate::vertexExists(QAbstractItemModel *model,
 BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator( const QString& theHypType )
   : SMESHGUI_GenericHypothesisCreator( theHypType )
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::BLSURFPluginGUI_HypothesisCreator");
   this->mySMPMap.clear();
 
   GeomToolSelected = NULL;
@@ -471,12 +479,11 @@ BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
 /**
  * \brief {Get or create the geom selection tool for active study}
  * */
-GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool()
+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;
 }
@@ -514,7 +521,6 @@ void BLSURFPluginGUI_HypothesisCreator::avoidSimultaneousSelection(ListOfWidgets
 
 bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::checkParams");
   bool ok = true;
 
   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
@@ -525,32 +531,47 @@ bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
     myAdvWidget->myOptionTable->setFocus();
     QApplication::instance()->processEvents();
 
-    int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
-    for ( ; row < nbRows; ++row )
+    QString name, value;
+    bool isDefault;
+    int iTbl = 0, nbTbl = myAdvWidget->myOptionTable->topLevelItemCount();
+    for ( ; iTbl < nbTbl; ++iTbl )
     {
-      QString name  = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
-      QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
-      if ( !value.isEmpty() ) {
+      QTreeWidgetItem* table = myAdvWidget->myOptionTable->topLevelItem( iTbl );
+      int nbRows = table->childCount();
+      for ( int iRow = 0; iRow < nbRows; ++iRow )
+      {
+        QTreeWidgetItem* row = table->child( iRow );
+        myAdvWidget->GetOptionAndValue( row, name, value, isDefault );
+
+        if ( name.simplified().isEmpty() )
+          continue; // invalid custom option
+
+        if ( isDefault ) // not selected option
+          value.clear();
+
         try {
-          QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().trimmed();
-          if (optionType == "PRECAD")
-            h->SetPreCADOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
-          else if (optionType == "BLSURF")
+          switch ( iTbl )
+          {
+          case TBL_MESHING:
             h->SetOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
+            break;
+          case TBL_PRECAD:
+            h->SetPreCADOptionValue( name.toLatin1().constData(), value.toLatin1().constData() );
+            break;
+          case TBL_CUSTOM:
+            h->AddOption( name.toLatin1().constData(), value.toLatin1().constData() );
+            break;
+          }
         }
         catch ( const SALOME::SALOME_Exception& ex )
         {
           msg = ex.details.text.in();
           ok = false;
+          break;
         }
       }
     }
   }
-  if ( !ok )
-  {
-    h->SetOptionValues( myOptions ); // restore values
-    h->SetPreCADOptionValues( myPreCADOptions ); // restore values
-  }
 
   // SizeMap and attractors
   if ( ok )
@@ -565,20 +586,13 @@ bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
     {
       QString entry   = mySizeMapTable->topLevelItem( row )->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
       QString sizeMap = mySizeMapTable->topLevelItem( row )->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
-      MESSAGE("entry ="<<entry.toStdString())
       if ( !sizeMap.isEmpty() ) {
         if (that->sizeMapValidationFromRow(row))
         {
           try {
-            MESSAGE("entry ="<<entry.toStdString())
-            MESSAGE("sizeMap ="<<sizeMap.toStdString())
-            
             e = entry.toStdString();
             s = that->mySMPMap[entry].toStdString();
-            MESSAGE("row = "<<row)
-            MESSAGE("e = "<<e)
-            MESSAGE("s = "<<s)
-            h->SetSizeMapEntry( e.c_str(), s.c_str() );
+            //h->SetSizeMapEntry( e.c_str(), s.c_str() );
           }
           catch ( const SALOME::SALOME_Exception& ex )
           {
@@ -625,20 +639,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()
 {
-  MESSAGE("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 );
 
@@ -659,6 +723,9 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   if( isCreation() )
     myName = new QLineEdit( myStdGroup );
   myStdWidget = new BLSURFPluginGUI_StdWidget(myStdGroup);
+  if ( !hasGeom() ) {
+    myStdWidget->myPhysicalMesh->removeItem( PhysicalLocalSize );
+  }
   
   int row = 0;
   if( isCreation() ) {
@@ -667,14 +734,11 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   }
   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
@@ -683,14 +747,12 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   anAdvLayout->setSpacing( 6 );
   anAdvLayout->setMargin( 11 );  
   myAdvWidget = new BLSURFPluginGUI_AdvWidget(myAdvGroup);
-  myAdvWidget->addBtn->setMenu( new QMenu() );
-  anAdvLayout->addWidget( myAdvWidget);
+  anAdvLayout->addWidget( myAdvWidget );
 
 
   // Size Maps parameters
 
-  mySmpGroup = new QWidget();
-//   mySmpGroup->setMinimumWidth(500);
+  mySmpGroup = new QWidget( dlg() );
 
   //Layout
   QGridLayout* anSmpLayout = new QGridLayout(mySmpGroup);
@@ -732,7 +794,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   // Standard size map tab
   mySmpStdGroup = new QWidget();
   QGridLayout* anSmpStdLayout = new QGridLayout(mySmpStdGroup);
-  myGeomSelWdg1 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter1, 0, /*multiSel=*/false,/*stretch=*/false);
+  myGeomSelWdg1 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter1, 0, /*multiSel=*/false);
   myGeomSelWdg1->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
   mySmpSizeSpin = new SMESHGUI_SpinBox(mySmpStdGroup);
   mySmpSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
@@ -741,7 +803,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   // Attractor tab
   myAttractorGroup = new QWidget();
   QGridLayout* anAttLayout = new QGridLayout(myAttractorGroup);
-  myGeomSelWdg2 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter3, 0, /*multiSel=*/false,/*stretch=*/false);
+  myGeomSelWdg2 = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter3, 0, /*multiSel=*/false);
   myGeomSelWdg2->SetDefaultText(tr("BLS_SEL_FACE"), "QLineEdit { color: grey }");
   myGeomSelWdg2->AvoidSimultaneousSelection(myGeomSelWdg1);
   myAttractorCheck = new QCheckBox(tr("BLSURF_ATTRACTOR"),myAttractorGroup);
@@ -749,7 +811,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   QFrame* attLine  = new QFrame(myAttractorGroup);
   attLine->setFrameShape(QFrame::HLine);
   attLine->setFrameShadow(QFrame::Sunken);
-  myAttSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter2, myAttractorGroup, /*multiSel=*/false,/*stretch=*/false);
+  myAttSelWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myFilter2, myAttractorGroup, /*multiSel=*/false);
   myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }"); 
   myAttSizeSpin = new SMESHGUI_SpinBox(myAttractorGroup);
   myAttSizeSpin->RangeStepAndValidator(0., COORD_MAX, 1.0, "length_precision");
@@ -821,13 +883,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);
-//   MESSAGE("Creating DlgBlSurfHyp_Enforced widget instance");
-//   myEnforcedVertexWidget = new DlgBlSurfHyp_Enforced();
 
   myEnforcedTreeWidget = new QTreeWidget(myEnfGroup);
   myEnforcedTreeWidget->setColumnCount( ENF_VER_NB_COLUMNS );
@@ -845,29 +902,29 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
-    myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
+    myEnforcedTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
     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 );
   shapeTypes2.Add( TopAbs_VERTEX );
   shapeTypes2.Add( TopAbs_COMPOUND );
 
-  SMESH_NumberFilter* faceFilter = new SMESH_NumberFilter("GEOM", TopAbs_FACE, 0, shapeTypes1);
-  myEnfFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( faceFilter, 0, /*multiSel=*/true, /*stretch=*/false);
-  myEnfFaceWdg->SetDefaultText(tr("BLS_SEL_FACES"), "QLineEdit { color: grey }");
+  // SMESH_NumberFilter* faceFilter = new SMESH_NumberFilter("GEOM", TopAbs_FACE, 0, shapeTypes1);
+  // myEnfFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( faceFilter, 0, /*multiSel=*/true);
+  // myEnfFaceWdg->SetDefaultText(tr("BLS_SEL_FACES"), "QLineEdit { color: grey }");
 
   SMESH_NumberFilter* vertexFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, shapeTypes2);
-  myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true, /*stretch=*/false);
+  myEnfVertexWdg = new StdMeshersGUI_ObjectReferenceParamWdg( vertexFilter, 0, /*multiSel=*/true);
   myEnfVertexWdg->SetDefaultText(tr("BLS_SEL_VERTICES"), "QLineEdit { color: grey }");
 
-  myEnfVertexWdg->AvoidSimultaneousSelection(myEnfFaceWdg);
+  //myEnfVertexWdg->AvoidSimultaneousSelection(myEnfFaceWdg);
 
   QLabel* myXCoordLabel = new QLabel( tr( "BLSURF_ENF_VER_X_LABEL" ), myEnfGroup );
   myXCoord = new SMESHGUI_SpinBox(myEnfGroup);
@@ -892,13 +949,10 @@ 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
-  anEnfLayout2->addWidget(myEnfFaceWdg,             ENF_VER_FACE, 0, 1, 2);
+  //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);
   anEnfLayout2->addWidget(myXCoord,                 ENF_VER_X_COORD, 1, 1, 1);
@@ -908,21 +962,17 @@ 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);
 
   // ---
   // Periodicity parameters
-  myPeriodicityGroup = new QWidget();
+  myPeriodicityGroup = new QWidget( dlg() );
   aPeriodicityLayout1 = new QGridLayout(myPeriodicityGroup);
 
   myPeriodicitySplitter = new QSplitter(myPeriodicityGroup);
@@ -961,8 +1011,8 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
   
   int periodicityVisibleColumns = 2;
-  for (size_t column = 0; column < periodicityVisibleColumns; ++column) {
-      myPeriodicityTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
+  for (int column = 0; column < periodicityVisibleColumns; ++column) {
+      myPeriodicityTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
       myPeriodicityTreeWidget->resizeColumnToContents(column);
   }
   myPeriodicityTreeWidget->header()->setStretchLastSection(true);
@@ -1000,11 +1050,11 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityMainSourceLabel, 1, 0, 1, 1);
 
   SMESH_NumberFilter* myPeriodicitySourceFaceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, shapeTypesFace);
-  myPeriodicitySourceFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicitySourceFaceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicitySourceFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicitySourceFaceFilter, 0, /*multiSel=*/false);
 //  myPeriodicitySourceFaceWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_FACE"), "QLineEdit { color: grey }");
   myPeriodicityGroupBox1Layout->addWidget(myPeriodicitySourceFaceWdg, 1, 1, 1, 1);
 
-//  myPeriodicitySourceEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+//  myPeriodicitySourceEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false);
 //  myPeriodicitySourceEdgeWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_EDGE"), "QLineEdit { color: grey }");
 //  myPeriodicitySourceEdgeWdg->hide();
 //  myPeriodicityGroupBox1Layout->addWidget(myPeriodicitySourceEdgeWdg, 1, 1, 1, 1);
@@ -1013,11 +1063,11 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityMainTargetLabel, 1, 2, 1, 1);
 
   SMESH_NumberFilter* myPeriodicityTargetFaceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 0, shapeTypesFace);
-  myPeriodicityTargetFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityTargetFaceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicityTargetFaceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityTargetFaceFilter, 0, /*multiSel=*/false);
 //  myPeriodicityTargetFaceWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_FACE"), "QLineEdit { color: grey }");
   myPeriodicityGroupBox1Layout->addWidget(myPeriodicityTargetFaceWdg, 1, 3, 1, 1);
 
-//  myPeriodicityTargetEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+//  myPeriodicityTargetEdgeWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityEdgeFilter, 0, /*multiSel=*/false);
 //  myPeriodicityTargetEdgeWdg->SetDefaultText(tr("BLSURF_PERIODICITY_SELECT_EDGE"), "QLineEdit { color: grey }");
 //  myPeriodicityTargetEdgeWdg->hide();
 //  myPeriodicityGroupBox1Layout->addWidget(myPeriodicityTargetEdgeWdg, 1, 3, 1, 1);
@@ -1041,7 +1091,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
 
 
   SMESH_NumberFilter* myPeriodicityP1SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
-  myPeriodicityP1SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1SourceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicityP1SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1SourceFilter, 0, /*multiSel=*/false);
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1SourceWdg, 1, 1, 1, 1);
 
   // P2
@@ -1049,7 +1099,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2SourceLabel, 2, 0, 1, 1);
 
   SMESH_NumberFilter* myPeriodicityP2SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
-  myPeriodicityP2SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2SourceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicityP2SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2SourceFilter, 0, /*multiSel=*/false);
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2SourceWdg, 2, 1, 1, 1);
 
   // P3
@@ -1057,7 +1107,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3SourceLabel, 3, 0, 1, 1);
 
   SMESH_NumberFilter* myPeriodicityP3SourceFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
-  myPeriodicityP3SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3SourceFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicityP3SourceWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3SourceFilter, 0, /*multiSel=*/false);
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3SourceWdg, 3, 1, 1, 1);
 
   // P1
@@ -1065,7 +1115,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1TargetLabel, 1, 2, 1, 1);
 
   SMESH_NumberFilter* myPeriodicityP1TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
-  myPeriodicityP1TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1TargetFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicityP1TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP1TargetFilter, 0, /*multiSel=*/false);
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP1TargetWdg, 1, 3, 1, 1);
 
   // P2
@@ -1073,7 +1123,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2TargetLabel, 2, 2, 1, 1);
 
   SMESH_NumberFilter* myPeriodicityP2TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
-  myPeriodicityP2TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2TargetFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicityP2TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP2TargetFilter, 0, /*multiSel=*/false);
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP2TargetWdg, 2, 3, 1, 1);
 
   // P3
@@ -1081,7 +1131,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3TargetLabel, 3, 2, 1, 1);
 
   SMESH_NumberFilter* myPeriodicityP3TargetFilter = new SMESH_NumberFilter("GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX);
-  myPeriodicityP3TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3TargetFilter, 0, /*multiSel=*/false, /*stretch=*/false);
+  myPeriodicityP3TargetWdg = new StdMeshersGUI_ObjectReferenceParamWdg( myPeriodicityP3TargetFilter, 0, /*multiSel=*/false);
   myPeriodicityGroupBox2Layout->addWidget(myPeriodicityP3TargetWdg, 3, 3, 1, 1);
 
   myPeriodicityVerticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
@@ -1107,44 +1157,86 @@ 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_TAB, myEnfGroup, tr( "BLSURF_ENF_VER" ) );
+    myTabWidget->insertTab( PERIODICITY_TAB, myPeriodicityGroup, tr( "BLSURF_PERIODICITY" ) );
+    myTabWidget->insertTab( HYPERPATCH_TAB, hpGroup, tr( "BLSURF_HYPERPATCH_TAB" ));
+  }
+  else
+  {
+    mySmpGroup->hide();
+    myEnfGroup->hide();
+    myPeriodicityGroup->hide();
+    hpGroup->hide();
+  }
   myTabWidget->setCurrentIndex( STD_TAB );
 
-  connect( myAdvWidget->addBtn->menu(), SIGNAL( aboutToShow() ),         this, SLOT( onAddOption() ) );
-  connect( myAdvWidget->addBtn->menu(), SIGNAL( triggered( QAction* ) ), this, SLOT( onOptionChosenInPopup( QAction* ) ) );
-  connect( myAdvWidget->rmBtn,          SIGNAL( clicked()),              this, SLOT( onDeleteOption() ) );
+  connect( myAdvWidget->addBtn, SIGNAL( clicked() ),           this, 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( myAttractorGroup,    SIGNAL( clicked(bool) ),               this,         SLOT( onAttractorGroupClicked(bool) ) );
+  connect( myAttSelWdg,         SIGNAL( contentModified() ),           this,         SLOT( onMapGeomContentModified() ) );
   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( onSmpTabChanged( int ) ) );
+  connect( smpTab,              SIGNAL( currentChanged ( int )),       this,         SLOT( onTabChanged( int ) ) );
+  connect( myTabWidget,         SIGNAL( currentChanged ( int )),       this,         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() ) );
 
   // Periodicity
   connect( myPeriodicityAddButton,     SIGNAL( clicked()),                    this,   SLOT( onAddPeriodicity() ) );
@@ -1154,17 +1246,24 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
 
   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 ()),                 this,   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)
 // {
@@ -1177,9 +1276,14 @@ This method stop the selection of the widgets StdMeshersGUI_ObjectReferenceParam
 //   }
 // }
 
-/** 
+void BLSURFPluginGUI_HypothesisCreator::onStateChange()
+{
+  myStdWidget->onPhysicalMeshChanged();
+}
+
+/**
  * This method resets the content of the X, Y, Z widgets;
-**/
+ **/
 void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
 {
   myXCoord->setCleared(true);
@@ -1188,15 +1292,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) {
-//   MESSAGE("BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues");
+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);
@@ -1233,8 +1337,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)
   {
@@ -1243,8 +1348,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;
       
@@ -1264,7 +1368,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) {
@@ -1291,7 +1396,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;
@@ -1309,62 +1415,45 @@ QTreeWidgetItem* BLSURFPluginGUI_HypothesisCreator::addEnforcedFace(std::string
 }
 
 /** BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(entry, shapeName, x, y, z)
-This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
+    This method adds an enforced vertex (x,y,z) to shapeName in the tree widget.
 */
-void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(QTreeWidgetItem* theItem, double x, double y, double z, 
-                                                          std::string vertexName, std::string geomEntry, std::string groupName) {
-
-  std::string theFaceName = theItem->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
-//   MESSAGE("theItemName is " << theItem->text(ENF_VER_NAME_COLUMN).toStdString());
+void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(double x, double y, double z,
+                                                          std::string vertexName,
+                                                          std::string geomEntry,
+                                                          std::string groupName)
+{
   bool okToCreate = true;
 
-  const int nbVert = theItem->childCount();
-//   MESSAGE("Number of child rows: " << nbVert);
-  if (nbVert >0) {
-    double childValueX,childValueY,childValueZ;
-    QString childEntry, childGroupName;
-    QTreeWidgetItem* child;
-    for (int row = 0;row<nbVert;row++) {
-      child = theItem->child(row);
-      childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
-      childEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
-      childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
-      childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
-      childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
-      if (((childValueX == x) && (childValueY == y) && (childValueZ == z)) || ( (childEntry.toStdString() != "") && (childEntry.toStdString() == geomEntry))) {
-        // update group name
-        if (childGroupName.toStdString() != groupName) {
-          MESSAGE("Group is updated from \"" << childGroupName.toStdString() << "\" to \"" << groupName << "\"");
-          child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
-        }
-        okToCreate = false;
-        break;
-      } // if
-    } // for
-  } // if
+  const int nbVert = myEnforcedTreeWidget->topLevelItemCount();
+  for (int row = 0; row < nbVert; row++ )
+  {
+    QTreeWidgetItem* child = myEnforcedTreeWidget->topLevelItem( row );
+    QString childGroupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString();
+    QString childEntry     = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString();
+    double childX          = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
+    double childY          = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
+    double childZ          = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
+    if (((childEntry.isEmpty()) && (childX == x) && (childY == y) && (childZ == z)) ||
+        ( !childEntry.isEmpty() && childEntry == geomEntry.c_str() ))
+    {
+      // update group name
+      if ( childGroupName != groupName.c_str() ) {
+        child->setData(ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
+      }
+      okToCreate = false;
+      break;
+    } // if
+  } // for
   if (!okToCreate) {
-    if (geomEntry.empty()) {
-      MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z << " already exist: dont create again");
-    }
-    else {
-      MESSAGE("In " << theFaceName << " vertex with entry " << geomEntry << " already exist: dont create again");
-    }
     return;
   }
-    
-  if (geomEntry.empty()) {
-    MESSAGE("In " << theFaceName << " vertex with coords " << x << ", " << y << ", " << z<< " is created");
-  }
-  else {
-    MESSAGE("In " << theFaceName << " vertex with geom entry " << geomEntry << " is created");
-  }
 
-  QTreeWidgetItem *vertexItem = new QTreeWidgetItem( theItem);
+  QTreeWidgetItem *vertexItem = new QTreeWidgetItem( myEnforcedTreeWidget );
   vertexItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
   QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
   QSize iconSize = iconSelect.size()*0.7;
-  
-  int vertexIndex=myEnforcedTreeWidget->indexOfTopLevelItem(theItem);
+
+  int vertexIndex=nbVert;
   QString myVertexName;
   int indexRef = -1;
   while(indexRef != vertexIndex) {
@@ -1375,7 +1464,7 @@ void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(QTreeWidgetItem* theIt
       myVertexName = QString(vertexName.c_str());
 
     for (int row = 0;row<nbVert;row++) {
-      QString name = theItem->child(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
+      QString name = myEnforcedTreeWidget->topLevelItem(row)->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString();
       if (myVertexName == name) {
         vertexIndex++;
         break;
@@ -1395,59 +1484,38 @@ void BLSURFPluginGUI_HypothesisCreator::addEnforcedVertex(QTreeWidgetItem* theIt
   if (groupName != "")
     vertexItem->setData( ENF_VER_GROUP_COLUMN, Qt::EditRole, QVariant(groupName.c_str()));
 
-  QString toolTip = QString(theFaceName.c_str())+QString(": ")+myVertexName;
+  QString toolTip = myVertexName;
   if (geomEntry.empty()) {
-    toolTip += QString(" (%1, ").arg(x);
-    toolTip += QString("%1, ").arg(y);
-    toolTip += QString("%1)").arg(z);
+    toolTip += QString(" (%1, %2, %3").arg(x).arg(y).arg(z);
   }
   if (groupName != "")
     toolTip += QString(" [%1]").arg(groupName.c_str());
   
   vertexItem->setToolTip(ENF_VER_NAME_COLUMN,toolTip);
-  theItem->setExpanded(true);
   myEnforcedTreeWidget->setCurrentItem(vertexItem,ENF_VER_NAME_COLUMN);
 }
 
 /** BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
 This method is called when a item is added into the enforced vertices tree widget
 */
-void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
-//   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
-
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-
-  that->getGeomSelectionTool()->selectionMgr()->clearFilters();
-  myEnfFaceWdg->deactivateSelection();
+void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
+{
+  getGeomSelectionTool()->selectionMgr()->clearFilters();
   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 < selEnfFace ; 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)
     {
@@ -1457,37 +1525,36 @@ void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices() {
       z = myZCoord->GetValue();
       if (selEnfVertex == 1) {
         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >();
-        addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
+        addEnforcedVertex(x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
       }
       else
-        addEnforcedVertex(faceItem, x, y, z, "", "", groupName);
+        addEnforcedVertex(x, y, z, "", "", groupName);
     }
     else
     {
       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) {
           measureOp->PointCoordinates (myEnfVertex, x, y, z);
           if ( measureOp->IsDone() )
-            addEnforcedVertex(faceItem, x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
+            addEnforcedVertex(x, y, z, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
         } else if (myEnfVertex->GetShapeType() == GEOM::COMPOUND) {
-            addEnforcedVertex(faceItem, 0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
+            addEnforcedVertex(0, 0, 0, myEnfVertex->GetName(),myEnfVertex->GetStudyEntry(), groupName);
         }
       }
     }
   }
 
-  myEnfFaceWdg->SetObject(GEOM::GEOM_Object::_nil());
   myEnfVertexWdg->SetObject(GEOM::GEOM_Object::_nil());
   
   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
@@ -1502,8 +1569,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() {
-//   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
+void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
+{
   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
   QList<QTreeWidgetItem *> selectedVertices;
   QSet<QTreeWidgetItem *> selectedEntries;
@@ -1524,10 +1591,10 @@ void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
 
   foreach(item,selectedVertices) {
     QTreeWidgetItem* parent = item->parent();
-//     MESSAGE("From geometry "<< parent->text(ENF_VER_NAME_COLUMN).toStdString()<<" remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
-    parent->removeChild(item);
+    if ( parent )
+      parent->removeChild(item);
     delete item;
-    if (parent->childCount() == 0) {
+    if ( parent && parent->childCount() == 0) {
       if (selectedEntries.contains(parent))
         selectedEntries.remove(parent);
       delete parent;
@@ -1535,7 +1602,6 @@ void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex() {
   }
 
   foreach(item,selectedEntries) {
-//     MESSAGE("Remove " << item->text(ENF_VER_NAME_COLUMN).toStdString());
     delete item;
   }
 
@@ -1551,9 +1617,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() {
-//   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices");
-
+void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
+{
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
@@ -1566,8 +1631,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;
@@ -1575,12 +1640,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)
         {
@@ -1601,7 +1666,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 );
@@ -1633,13 +1698,12 @@ 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() {
-//   MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex");
+void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
+{
   QList<QTreeWidgetItem *> selectedItems = myPeriodicityTreeWidget->selectedItems();
   QTreeWidgetItem* item;
 
   foreach(item,selectedItems) {
-     MESSAGE("Remove " << item->text(0).toStdString());
     delete item;
   }
 
@@ -1653,7 +1717,7 @@ void BLSURFPluginGUI_HypothesisCreator::onPeriodicityByVerticesChecked(bool chec
 {
   if (! checked)
     {
-      for (size_t k=2; k<myPeriodicitySelectionWidgets.size(); k++)
+      for (int k=2; k<myPeriodicitySelectionWidgets.size(); k++)
         {
           StdMeshersGUI_ObjectReferenceParamWdg * w1 = ( StdMeshersGUI_ObjectReferenceParamWdg* ) ( myPeriodicitySelectionWidgets[k] );
           w1->deactivateSelection();
@@ -1669,7 +1733,6 @@ This method enable the proper shape selection widget to Face or Edge shapes
 //{
 //  if (myPeriodicityOnFaceRadioButton->isChecked())
 //    {
-//      MESSAGE("Show Face");
 //      myPeriodicitySourceEdgeWdg->hide();
 //      myPeriodicityTargetEdgeWdg->hide();
 //      myPeriodicitySourceFaceWdg->show();
@@ -1677,7 +1740,6 @@ This method enable the proper shape selection widget to Face or Edge shapes
 //    }
 //  else
 //    {
-//      MESSAGE("Show Edge");
 //      myPeriodicitySourceFaceWdg->hide();
 //      myPeriodicityTargetFaceWdg->hide();
 //      myPeriodicitySourceEdgeWdg->show();
@@ -1685,11 +1747,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++)
     {
@@ -1725,7 +1787,7 @@ void BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   ListOfWidgets::const_iterator anIt = myPeriodicitySelectionWidgets.begin();
-  size_t k=0;
+  int k=0;
   // find wich selection widget is activated
   for (; anIt != myPeriodicitySelectionWidgets.end(); anIt++, k++)
     {
@@ -1747,11 +1809,10 @@ 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
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::retrieveParams");
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   BlsurfHypothesisData data;
@@ -1779,12 +1840,41 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
   else
     myStdWidget->myMaxSize->SetValue( data.myMaxSize );
   myStdWidget->myMaxSizeRel->setChecked( data.myMaxSizeRel );
-  if (data.myGradation <= 0)
+  myStdWidget->myUseGradation->setChecked( data.myUseGradation );
+  if (data.myGradation <= 0 || !data.myUseGradation )
     myStdWidget->myGradation->setText("");
   else
     myStdWidget->myGradation->SetValue( data.myGradation );
-  myStdWidget->myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
-  
+  myStdWidget->myUseVolumeGradation->setChecked( data.myUseVolumeGradation );
+  if (data.myVolumeGradation <= 0 || !data.myUseVolumeGradation )
+    myStdWidget->myVolumeGradation->setText("");
+  else
+    myStdWidget->myVolumeGradation->SetValue( data.myVolumeGradation );
+
+  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
@@ -1803,6 +1893,16 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
     myStdWidget->myTinyEdgeLength->setText("");
   else
     myStdWidget->myTinyEdgeLength->SetValue( data.myTinyEdgeLength );
+  myStdWidget->myOptimiseTinyEdges->setChecked( data.myOptimiseTinyEdges );
+  if (data.myTinyEdgeOptimisLength <= 0)
+    myStdWidget->myTinyEdgeOptimisLength->setText("");
+  else
+    myStdWidget->myTinyEdgeOptimisLength->SetValue( data.myTinyEdgeOptimisLength );
+  myStdWidget->myCorrectSurfaceIntersection->setChecked( data.myCorrectSurfaceIntersection );
+  if (data.myCorrectSurfaceIntersectionMaxCost <= 0)
+    myStdWidget->myCorrectSurfaceIntersectionMaxCost->setText("");
+  else
+    myStdWidget->myCorrectSurfaceIntersectionMaxCost->SetValue( data.myCorrectSurfaceIntersectionMaxCost );
   myStdWidget->myForceBadElementRemoval->setChecked( data.myForceBadElementRemoval );
   if (data.myBadElementAspectRatio <= 0)
     myStdWidget->myBadElementAspectRatio->setText("");
@@ -1814,111 +1914,74 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
   myStdWidget->resizeWidgets();  
   
   myAdvWidget->myVerbosity->setValue( data.myVerbosity );
-  myAdvWidget->myPreCADGroupBox->setChecked(data.myTopology == PreCAD);
-  myAdvWidget->myPreCADMergeEdges->setChecked( data.myPreCADMergeEdges );
-  myAdvWidget->myPreCADProcess3DTopology->setChecked( data.myPreCADProcess3DTopology );
-  myAdvWidget->myPreCADDiscardInput->setChecked( data.myPreCADDiscardInput );
 
   if ( myOptions.operator->() ) {
-//     MESSAGE("retrieveParams():myOptions->length() = " << myOptions->length());
-    for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
-      QString option = that->myOptions[i].in();
-      QStringList name_value = option.split( ":", QString::KeepEmptyParts );
-      if ( name_value.count() > 1 ) {
-        QString idStr = QString("%1").arg( i );
-        int row = myAdvWidget->myOptionTable->rowCount();
-        myAdvWidget->myOptionTable->setRowCount( row+1 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "BLSURF" ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
-                                                                                Qt::ItemIsEditable   |
-                                                                                Qt::ItemIsEnabled );
-      }
-    }
+    for ( int i = 0, nb = myOptions->length(); i < nb; ++i )
+      myAdvWidget->AddOption( TBL_MESHING, that->myOptions[i].in() );
   }
   if ( myPreCADOptions.operator->() ) {
-//     MESSAGE("retrieveParams():myPreCADOptions->length() = " << myPreCADOptions->length());
-    for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
-      QString option = that->myPreCADOptions[i].in();
-      QStringList name_value = option.split( ":", QString::KeepEmptyParts );
-      if ( name_value.count() > 1 ) {
-        QString idStr = QString("%1").arg( i );
-        int row = myAdvWidget->myOptionTable->rowCount();
-        myAdvWidget->myOptionTable->setRowCount( row+1 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( "PRECAD" ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( name_value[0] ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
-        myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( name_value[1] ) );
-        myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
-                                                                                Qt::ItemIsEditable   |
-                                                                                Qt::ItemIsEnabled );
-      }
-    }
+    for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i )
+      myAdvWidget->AddOption( TBL_PRECAD, that->myPreCADOptions[i].in() );
+  }
+  if ( myCustomOptions.operator->() ) {
+    for ( int i = 0, nb = myCustomOptions->length(); i < nb; ++i )
+      myAdvWidget->AddOption( TBL_CUSTOM, that->myCustomOptions[i].in() );
   }
   myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
   myAdvWidget->myGMFFileName->setText(QString(data.myGMFFileName.c_str()));
 //   myGMFFileMode->setChecked(data.myGMFFileMode);
   
   // Sizemaps
-  MESSAGE("retrieveParams():that->mySMPMap.size() = " << that->mySMPMap.size());
   QMapIterator<QString, QString> i(that->mySMPMap);
   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
   while (i.hasNext()) {
     i.next();
     const QString entry = i.key();
     const QString sizeMap = i.value();
-    string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString()); 
-    int row = mySizeMapTable->topLevelItemCount();
+    string shapeName = myGeomToolSelected->getNameFromEntry(entry.toStdString());
+    //int row = mySizeMapTable->topLevelItemCount();
     QTreeWidgetItem* item = new QTreeWidgetItem();
-    mySizeMapTable->addTopLevelItem( item ); 
+    mySizeMapTable->addTopLevelItem( item );
     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
     item->setData(SMP_ENTRY_COLUMN,Qt::DisplayRole, QVariant(entry) );
     item->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString(shapeName) ) );
-    if (that->myATTMap.contains(entry)){
-      const QString attEntry = that->myATTMap[entry];
-      std::string attName = myGeomToolSelected->getNameFromEntry(attEntry.toStdString());
-      QTreeWidgetItem* child = new QTreeWidgetItem();
-      item->addChild( child );
-      item->setExpanded(true);
-      child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap  ) );
-      child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attEntry  ) );
-      child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString( attName ) ) );
-   
-      if (that->myAttDistMap[entry] >  std::numeric_limits<double>::epsilon()){
-        item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Attractor" )  ) ); 
-      }
-      else{
-        item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( QString::fromStdString("Constant Size" )  ) );
+    if (that->myATTMap.contains(entry)) {
+      TAttractorVec & attVec = that->myATTMap[entry];
+      for ( size_t i = 0; i < attVec.size(); ++i )
+      {
+        std::string attName = myGeomToolSelected->getNameFromEntry( attVec[i].attEntry );
+        QTreeWidgetItem* child = new QTreeWidgetItem();
+        item->addChild( child );
+        item->setExpanded(true);
+        child->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( attVec[i].startSize  ));
+        child->setData(SMP_ENTRY_COLUMN, Qt::DisplayRole, QVariant( attVec[i].attEntry.c_str() ));
+        child->setData(SMP_NAME_COLUMN, Qt::DisplayRole, QVariant( attName.c_str() ));
+
+        if ( attVec[i].infDist >  std::numeric_limits<double>::epsilon()){
+          item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Attractor" ));
+        }
+        else{
+          item->setData(SMP_SIZEMAP_COLUMN, Qt::DisplayRole, QVariant( "Constant Size" ));
+        }
       }
     }
     else
     {
       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant( sizeMap ) );
-    } 
+    }
   }
   mySizeMapTable->resizeColumnToContents( SMP_ENTRY_COLUMN );
   mySizeMapTable->resizeColumnToContents( SMP_NAME_COLUMN );
   mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
 
   // Enforced vertices
-  MESSAGE("retrieveParams(): data.entryCoordsListMap.size() = " << data.faceEntryEnfVertexListMap.size());
   TFaceEntryEnfVertexListMap::const_iterator evmIt = data.faceEntryEnfVertexListMap.begin();
 
   for ( ; evmIt != data.faceEntryEnfVertexListMap.end() ; ++evmIt) {
     TEntry entry = (*evmIt).first;
     std::string shapeName = myGeomToolSelected->getNameFromEntry(entry);
-    MESSAGE("Face entry: " << entry);
-    MESSAGE("Face name: " << shapeName);
-    
-    QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
+
+    //QTreeWidgetItem* faceItem = that->addEnforcedFace(entry, shapeName);
 
     TEnfVertexList evs = (*evmIt).second;
 
@@ -1926,17 +1989,16 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
     TEnfVertex *enfVertex;
     for ( ; evsIt != evs.end() ; ++evsIt) {
       enfVertex = (*evsIt);
-      MESSAGE("Name: " << enfVertex->name);
-      double x, y, z = 0;
+      double x = 0, y = 0, z = 0;
       if (enfVertex->coords.size()) {
         x = enfVertex->coords[0];
         y = enfVertex->coords[1];
         z = enfVertex->coords[2];
       }
-      that->addEnforcedVertex(faceItem, x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
+      that->addEnforcedVertex(x, y, z, enfVertex->name, enfVertex->geomEntry, enfVertex->grpName);
     }
   }
-  
+
   for (int column = 0; column < myEnforcedTreeWidget->columnCount(); ++column)
     myEnforcedTreeWidget->resizeColumnToContents(column);
 
@@ -1945,28 +2007,35 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
   myInternalEnforcedVerticesAllFacesGroup->setEnabled(data.myInternalEnforcedVerticesAllFaces);
 
   // Periodicity
-  MESSAGE("retrieveParams(): 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();
 }
 
 /** BLSURFPluginGUI_HypothesisCreator::storeParams()
@@ -1974,7 +2043,6 @@ This method updates the hypothesis data with the GUI widgets content.
 */
 QString BLSURFPluginGUI_HypothesisCreator::storeParams() const
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParams");
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   BlsurfHypothesisData data;
@@ -1989,7 +2057,6 @@ Updates the hypothesis data from hypothesis values.
 */
 bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData& h_data ) const
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo");
   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis() );
 
@@ -2006,8 +2073,11 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   h_data.myMinSizeRel             = h->IsMinSizeRel();
   h_data.myMaxSize                = maxSize > 0 ? maxSize : -1.0;
   h_data.myMaxSizeRel             = h->IsMaxSizeRel();
+  h_data.myUseGradation           = h->GetUseGradation();
   h_data.myGradation              = h->GetGradation();
-  h_data.myAllowQuadrangles       = h->GetQuadAllowed();
+  h_data.myUseVolumeGradation     = h->GetUseVolumeGradation();
+  h_data.myVolumeGradation        = h->GetVolumeGradation();
+  h_data.myElementType            = h->GetElementType();
   double angle                    = h->GetAngleMesh();
   h_data.myAngleMesh              = angle > 0 ? angle : -1.0;
   double chordalError             = h->GetChordalError();
@@ -2018,44 +2088,53 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   h_data.myRemoveTinyEdges        = h->GetRemoveTinyEdges();
   double myTinyEdgeLength         = h->GetTinyEdgeLength();
   h_data.myTinyEdgeLength         = myTinyEdgeLength > 0 ? myTinyEdgeLength : -1.0;
+  h_data.myOptimiseTinyEdges      = h->GetOptimiseTinyEdges();
+  double myTinyEdgeOptimisLength  = h->GetTinyEdgeOptimisationLength();
+  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.myForceBadElementRemoval = h->GetBadElementRemoval();
   double myBadElementAspectRatio  = h->GetBadElementAspectRatio();
   h_data.myBadElementAspectRatio  = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
   h_data.myOptimizeMesh           = h->GetOptimizeMesh();
   h_data.myQuadraticMesh          = h->GetQuadraticMesh();
   h_data.myVerbosity              = h->GetVerbosity();
-  h_data.myTopology               = (int) h->GetTopology();
-  h_data.myPreCADMergeEdges       = h->GetPreCADMergeEdges();
-  h_data.myPreCADProcess3DTopology  = h->GetPreCADProcess3DTopology();
-  h_data.myPreCADDiscardInput     = h->GetPreCADDiscardInput();
-
+  //h_data.myTopology               = (int) h->GetTopology();
+  //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();
+  that->myOptions       = h->GetOptionValues();
   that->myPreCADOptions = h->GetPreCADOptionValues();
-  
+  that->myCustomOptions = h->GetAdvancedOptionValues();
+
   h_data.myGMFFileName = h->GetGMFFile();
 //   h_data.myGMFFileMode = h->GetGMFFileMode();
 
   that->mySMPMap.clear();
   that->myATTMap.clear();
-  that->myAttDistMap.clear();
-  that->myDistMap.clear();
+  // that->myAttDistMap.clear();
+  // that->myDistMap.clear();
 
   // classic size maps
   BLSURFPlugin::string_array_var mySizeMaps = h->GetSizeMapEntries();
-//   MESSAGE("mySizeMaps->length() = " << mySizeMaps->length());
   QString fullSizeMaps;
   QStringList fullSizeMapList;
   GeomSelectionTools* myGeomToolSelected = that->getGeomSelectionTool();
-  for ( int i = 0;i<mySizeMaps->length(); ++i ) {
+  for ( CORBA::ULong i = 0;i<mySizeMaps->length(); ++i ) {
     fullSizeMaps =  mySizeMaps[i].in();
-//     MESSAGE("fullSizeMaps: " << fullSizeMaps.toStdString());
     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
     if ( fullSizeMapList.count() > 1 ) {
       string fullSizeMap = fullSizeMapList[1].toStdString();
-      int pos = fullSizeMap.find("return")+7;
-//       MESSAGE("pos:" << pos);
+      size_t pos = fullSizeMap.find("return")+7;
       QString sizeMap;
       try {
         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
@@ -2064,16 +2143,13 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
         continue;
       }
       that->mySMPMap[fullSizeMapList[0]] = sizeMap;
-//       MESSAGE("mySMPMap[" << fullSizeMapList[0].toStdString() << "] = " << sizeMap.toStdString());
       that->mySMPShapeTypeMap[fullSizeMapList[0]] = myGeomToolSelected->entryToShapeType(fullSizeMapList[0].toStdString());
-//       MESSAGE("mySMPShapeTypeMap[" << fullSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullSizeMapList[0]]);
     }
   }
 
   // custom size maps
 /*
   BLSURFPlugin::string_array_var myCustomSizeMaps = h->GetCustomSizeMapEntries();
-  MESSAGE("myCustomSizeMaps->length() = " << myCustomSizeMaps->length());
 
   for ( int i = 0;i<myCustomSizeMaps->length(); ++i ) {
     QString fullCustomSizeMaps =  myCustomSizeMaps[i].in();
@@ -2081,43 +2157,33 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
     if ( fullCustomSizeMapList.count() > 1 ) {
       that->mySMPMap[fullCustomSizeMapList[0]] = fullCustomSizeMapList[1];
       that->mySMPShapeTypeMap[fullCustomSizeMapList[0]] = GeomToolSelected->entryToShapeType(fullCustomSizeMapList[0].toStdString());
-      MESSAGE("mySMPMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << fullCustomSizeMapList[1].toStdString());
-      MESSAGE("mySMPShapeTypeMap[" << fullCustomSizeMapList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[fullCustomSizeMapList[0]]);
     }
   }
 */
   // attractor
   BLSURFPlugin::string_array_var allMyAttractors = h->GetAttractorEntries();
-//   MESSAGE("myAttractors->length() = " << allMyAttractors->length());
 
-  for ( int i = 0;i<allMyAttractors->length(); ++i ) {
+  for ( CORBA::ULong i = 0;i<allMyAttractors->length(); ++i ) {
     QString myAttractors =  allMyAttractors[i].in();
     QStringList myAttractorList = myAttractors.split( "|", QString::KeepEmptyParts );
     if ( myAttractorList.count() > 1 ) {
       that->mySMPMap[myAttractorList[0]] = myAttractorList[1];
       that->mySMPShapeTypeMap[myAttractorList[0]] = myGeomToolSelected->entryToShapeType(myAttractorList[0].toStdString());
-//       MESSAGE("mySMPMap[" << myAttractorList[0].toStdString() << "] = " << myAttractorList[1].toStdString());
-//       MESSAGE("mySMPShapeTypeMap[" << myAttractorList[0].toStdString() << "] = " << that->mySMPShapeTypeMap[myAttractorList[0]]);
     }
   }
   
   // attractor new version
-  MESSAGE("readParamsFromHypo, Attractors")
   BLSURFPlugin::TAttParamsMap_var allMyAttractorParams = h->GetAttractorParams();
-  for ( int i = 0;i<allMyAttractorParams->length(); ++i ) {
+  for ( CORBA::ULong i = 0;i<allMyAttractorParams->length(); ++i ) {
     BLSURFPlugin::TAttractorParams myAttractorParams =  allMyAttractorParams[i];
     QString faceEntry = myAttractorParams.faceEntry.in();
     QString attEntry  = myAttractorParams.attEntry.in();
-    MESSAGE("attEntry = "<<attEntry.toStdString())
-    double  startSize = myAttractorParams.startSize;
-    double  endSize   = myAttractorParams.endSize;
-    double  infDist   = myAttractorParams.infDist;
-    double  constDist = myAttractorParams.constDist;
-    that->mySMPMap[faceEntry] = QString::number( startSize, 'g',  6 ); // TODO utiliser les préférences ici (cf. sketcher)
+    that->mySMPMap[faceEntry] = QString::number( myAttractorParams.startSize, 'g',  6 ); // TODO utiliser les préférences ici (cf. sketcher)
     that->mySMPShapeTypeMap[faceEntry] = myGeomToolSelected->entryToShapeType(faceEntry.toStdString());
-    that->myATTMap[faceEntry] = attEntry;
-    that->myAttDistMap[faceEntry] = infDist;
-    that->myDistMap[faceEntry] = constDist;
+    that->myATTMap[faceEntry].push_back( TAttractor( myAttractorParams.attEntry.in(),
+                                                     myAttractorParams.startSize,
+                                                     myAttractorParams.infDist,
+                                                     myAttractorParams.constDist ));
   }
   
   // Enforced vertices
@@ -2128,23 +2194,19 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   */
 
   BLSURFPlugin::TFaceEntryEnfVertexListMap_var faceEntryEnfVertexListMap = h->GetAllEnforcedVerticesByFace();
-  MESSAGE("faceEntryEnfVertexListMap->length() = " << faceEntryEnfVertexListMap->length());
 
-  for ( int i = 0;i<faceEntryEnfVertexListMap->length(); ++i ) {
-    std::string entry =  faceEntryEnfVertexListMap[i].faceEntry.in();
-//     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList.in();
+  for ( CORBA::ULong i = 0;i<faceEntryEnfVertexListMap->length(); ++i )
+  {
+    std::string entry = faceEntryEnfVertexListMap[i].faceEntry.in();
     BLSURFPlugin::TEnfVertexList vertexList = faceEntryEnfVertexListMap[i].enfVertexList;
-//     BLSURFPlugin::TEnfVertexList_var vertexList = h->GetEnforcedVerticesEntry(entry.c_str());
 
-//     TEnfVertexList& enfVertexList = h_data.faceEntryEnfVertexListMap[entry];
-
-    for (int j=0 ; j<vertexList.length(); ++j) {
+    for (CORBA::ULong j=0 ; j<vertexList.length(); ++j)
+    {
       TEnfVertex *enfVertex = new TEnfVertex();
-      
-      enfVertex->name = CORBA::string_dup(vertexList[j].name.in());
-      enfVertex->geomEntry = CORBA::string_dup(vertexList[j].geomEntry.in());
-      enfVertex->grpName = CORBA::string_dup(vertexList[j].grpName.in());
-      for (int k=0 ; k< vertexList[j].coords.length();k++)
+      enfVertex->name      = vertexList[j].name.in();
+      enfVertex->geomEntry = vertexList[j].geomEntry.in();
+      enfVertex->grpName   = vertexList[j].grpName.in();
+      for (CORBA::ULong k=0 ; k< vertexList[j].coords.length();k++)
         enfVertex->coords.push_back(vertexList[j].coords[k]);
 
       h_data.faceEntryEnfVertexListMap[entry].insert(enfVertex);
@@ -2166,7 +2228,6 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   h_data.myInternalEnforcedVerticesAllFacesGroup = h->GetInternalEnforcedVertexAllFacesGroup();
 
   // Periodicity
-  MESSAGE("readParamsFromHypo, Periodicity")
 
   h_data.preCadPeriodicityVector.clear();
 
@@ -2175,6 +2236,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;
 }
 
@@ -2182,7 +2276,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();
@@ -2195,14 +2289,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)
@@ -2219,7 +2315,6 @@ Saves the hypothesis data to hypothesis values.
 */
 bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesisData& h_data ) const
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo");
   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( hypothesis() );
 
@@ -2257,27 +2352,50 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
       else
         h->SetMaxSize( h_data.myMaxSize <= 0 ? -1 : h_data.myMaxSize );
     }
+    if ( h->GetUseGradation() !=  h_data.myUseGradation )
+      h->SetUseGradation( h_data.myUseGradation );
     if ( h->GetGradation() !=  h_data.myGradation )
       h->SetGradation( h_data.myGradation <= 0 ? -1 : h_data.myGradation );
-    if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
-      h->SetQuadAllowed( h_data.myAllowQuadrangles );
-    
+    if ( h->GetUseVolumeGradation() !=  h_data.myUseVolumeGradation )
+      h->SetUseVolumeGradation( h_data.myUseVolumeGradation );
+    if ( h->GetVolumeGradation() !=  h_data.myVolumeGradation )
+      h->SetVolumeGradation( h_data.myVolumeGradation <= 0 ? -1 : h_data.myVolumeGradation );
+
+    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 ) )
+      h->SetTinyEdgeOptimisationLength( h_data.myTinyEdgeOptimisLength <= 0 ? -1 :h_data.myTinyEdgeOptimisLength );
+    if ( h->GetCorrectSurfaceIntersection() != h_data.myCorrectSurfaceIntersection )
+      h->SetCorrectSurfaceIntersection( h_data.myCorrectSurfaceIntersection );
+    if ( h_data.myCorrectSurfaceIntersection && ( h->GetCorrectSurfaceIntersectionMaxCost() != h_data.myCorrectSurfaceIntersectionMaxCost ) )
+      h->SetCorrectSurfaceIntersectionMaxCost( h_data.myCorrectSurfaceIntersectionMaxCost <= 0 ? -1 :h_data.myCorrectSurfaceIntersectionMaxCost );
     
     if ( h->GetBadElementRemoval() != h_data.myForceBadElementRemoval )
       h->SetBadElementRemoval( h_data.myForceBadElementRemoval );
@@ -2288,25 +2406,26 @@ 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 );
-    if ( h->GetTopology() != h_data.myTopology )
-      h->SetTopology( (int) h_data.myTopology );
-    if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
-      h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
-    if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
-      h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
-    if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
-      h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
-
-    h->SetOptionValues( myOptions ); // is set in checkParams()
-    h->SetPreCADOptionValues( myPreCADOptions ); // is set in checkParams()
-    
+      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 )
+    //   h->SetPreCADMergeEdges( h_data.myPreCADMergeEdges );
+    // if ( h->GetPreCADProcess3DTopology() != h_data.myPreCADProcess3DTopology )
+    //   h->SetPreCADProcess3DTopology( h_data.myPreCADProcess3DTopology );
+    // if ( h->GetPreCADDiscardInput() != h_data.myPreCADDiscardInput )
+    //   h->SetPreCADDiscardInput( h_data.myPreCADDiscardInput );
+
+    // 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;
@@ -2317,26 +2436,30 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
       const QString sizeMap = i.value();
 
       if (sizeMap == "__TO_DELETE__") {
-        MESSAGE("Delete entry " << entry.toStdString() << " from engine");
         h->UnsetEntry(entry.toLatin1().constData());
       }
       else if (sizeMap.startsWith("ATTRACTOR")) {
-//         MESSAGE("SetAttractorEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
         h->SetAttractorEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData());
       }
       else if (sizeMap.startsWith("def")) {
-//         MESSAGE("SetCustomSizeMapEntry(" << entry.toStdString() << ")= " << sizeMap.toStdString());
-//        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
+        //        h->SetCustomSizeMapEntry( entry.toLatin1().constData(), sizeMap.toLatin1().constData() );
       }
       else {
-        if (!myATTMap[entry].isEmpty()){
-          QString att_entry = myATTMap[entry];
-          double infDist = myAttDistMap[entry];
-          double constDist = myDistMap[entry];
-          double phySize = h->GetPhySize();
-          QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-          h->SetClassAttractorEntry( entry.toLatin1().constData(), att_entry.toLatin1().constData(), sizeMap.toDouble() , phySize, infDist, constDist ); 
-          QApplication::restoreOverrideCursor();
+        if (!myATTMap[entry].empty()){
+          const TAttractorVec& attVec = myATTMap[entry];
+          for ( size_t i = 0; i < attVec.size(); ++i )
+          {
+            if ( attVec[i].IsToDelete() )
+              h->UnsetAttractorEntry( entry.toLatin1().constData(),
+                                      attVec[i].attEntry.c_str() );
+            else
+              h->SetClassAttractorEntry( entry.toLatin1().constData(),
+                                         attVec[i].attEntry.c_str(),
+                                         attVec[i].startSize,
+                                         h->GetPhySize(),
+                                         attVec[i].infDist,
+                                         attVec[i].constDist );
+          }
         }
         else {
           QString fullSizeMap;
@@ -2347,24 +2470,23 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
             fullSizeMap = QString("def f(t): return ") + sizeMap;
           else if (that->mySMPShapeTypeMap[entry] == TopAbs_VERTEX)
             fullSizeMap = QString("def f(): return ") + sizeMap;
-          MESSAGE("SetSizeMapEntry("<<entry.toStdString()<<") = " <<fullSizeMap.toStdString());
           h->SetSizeMapEntry( entry.toLatin1().constData(), fullSizeMap.toLatin1().constData() );
         }
       }
     }
 
     // Enforced vertices
-    bool ret;
+    //bool ret;
     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;
@@ -2374,7 +2496,6 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
     {
       faceEntry = evmIt->first;
       evs = evmIt->second;
-      MESSAGE("Number of enforced vertices for face entry " << faceEntry << ": " << evs.size());
       evsIt = evs.begin();
       for ( ; evsIt != evs.end() ; ++evsIt)
       {
@@ -2384,7 +2505,8 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
           y = (*evsIt)->coords[1];
           z = (*evsIt)->coords[2];
         }
-        ret = h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
+        //ret =
+        h->SetEnforcedVertexEntry( faceEntry.c_str(), x, y, z, (*evsIt)->name.c_str(), (*evsIt)->geomEntry.c_str(), (*evsIt)->grpName.c_str());
       } // for
     } // for
 
@@ -2395,72 +2517,91 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
 
     // Periodicity
     if ( h->GetPreCadFacesPeriodicityVector()->length() > 0 || h->GetPreCadEdgesPeriodicityVector()->length() > 0 )
-          h->ClearPreCadPeriodicityVectors();
+      h->ClearPreCadPeriodicityVectors();
 
-    MESSAGE("h_data.preCadPeriodicityVector.size(): " << h_data.preCadPeriodicityVector.size());
     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());
-          }
-
-        if (onFace)
-          h->AddPreCadFacesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
-        else
-          h->AddPreCadEdgesPeriodicityEntry(source.c_str(), target.c_str(), sourceVertices, targetVertices);
+      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());
       }
 
-    MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo end periodicity");
+      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 );
 
 
   } // 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;
-//   }
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo end");
+  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
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets");
   h_data.myName                  = myName ? myName->text() : "";
   h_data.myPhysicalMesh          = myStdWidget->myPhysicalMesh->currentIndex();
   h_data.myGeometricMesh         = myStdWidget->myGeometricMesh->currentIndex();
@@ -2470,23 +2611,36 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   h_data.myMinSizeRel            = myStdWidget->myMinSizeRel->isChecked();
   h_data.myMaxSize               = myStdWidget->myMaxSize->text().isEmpty() ? -1.0 : myStdWidget->myMaxSize->GetValue();
   h_data.myMaxSizeRel            = myStdWidget->myMaxSizeRel->isChecked();
-  h_data.myGradation             = myStdWidget->myGradation->text().isEmpty() ? -1.0 : myStdWidget->myGradation->GetValue();
-  h_data.myAllowQuadrangles      = myStdWidget->myAllowQuadrangles->isChecked();
+  h_data.myUseGradation          = myStdWidget->myUseGradation->isChecked() && !myStdWidget->myGradation->text().isEmpty();
+  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.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();
   h_data.myAnisotropicRatio      = myStdWidget->myAnisotropicRatio->text().isEmpty() ? -1.0 : myStdWidget->myAnisotropicRatio->GetValue();
   h_data.myRemoveTinyEdges       = myStdWidget->myRemoveTinyEdges->isChecked();
   h_data.myTinyEdgeLength        = myStdWidget->myTinyEdgeLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeLength->GetValue();
+  h_data.myOptimiseTinyEdges     = myStdWidget->myOptimiseTinyEdges->isChecked();
+  h_data.myTinyEdgeOptimisLength = myStdWidget->myTinyEdgeOptimisLength->text().isEmpty() ? -1.0 : myStdWidget->myTinyEdgeOptimisLength->GetValue();
+  h_data.myCorrectSurfaceIntersection = myStdWidget->myCorrectSurfaceIntersection->isChecked();
+  h_data.myCorrectSurfaceIntersectionMaxCost = myStdWidget->myCorrectSurfaceIntersectionMaxCost->text().isEmpty() ? -1.0 : myStdWidget->myCorrectSurfaceIntersectionMaxCost->GetValue();
   h_data.myForceBadElementRemoval= myStdWidget->myForceBadElementRemoval->isChecked();
   h_data.myBadElementAspectRatio = myStdWidget->myBadElementAspectRatio->text().isEmpty() ? -1.0 : myStdWidget->myBadElementAspectRatio->GetValue();
   h_data.myOptimizeMesh          = myStdWidget->myOptimizeMesh->isChecked();
   h_data.myQuadraticMesh         = myStdWidget->myQuadraticMesh->isChecked();
   h_data.myVerbosity             = myAdvWidget->myVerbosity->value();
-  h_data.myTopology              = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
-  h_data.myPreCADMergeEdges      = myAdvWidget->myPreCADMergeEdges->isChecked();
-  h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
-  h_data.myPreCADDiscardInput    = myAdvWidget->myPreCADDiscardInput->isChecked();
+  //h_data.myTopology              = myAdvWidget->myPreCADGroupBox->isChecked() ? PreCAD : FromCAD;
+  //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 ) + "; ";
@@ -2498,7 +2652,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") + "; ";
@@ -2513,46 +2667,22 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   guiHyp += tr("BLSURF_ELEMENT_ORDER") + " = " + QString(h_data.myQuadraticMesh ? "yes" : "no") + "; ";
   
   
-  guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
-  guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
-  guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
-  guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
-
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-  int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
-  for ( ; row < nbRows; ++row )
-  {
-    int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
-    std::string optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text().toStdString();
-    if ( id >= 0 && ( ( optionType == "BLSURF" && id < myOptions->length() ) || ( optionType == "PRECAD" && id < myPreCADOptions->length() ) ) )
-    {
-      QString name  = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text();
-      QString value = myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->text().trimmed();
-      if ( value.isNull() )
-        value = "";
-      if (optionType == "PRECAD")
-        that->myPreCADOptions[ id ] = ( name + ":" + value).toLatin1().constData();
-      else
-        that->myOptions[ id ] = ( name + ":" + value).toLatin1().constData();
-
-      if ( value != "" ) {
-        if (optionType == "PRECAD")
-          guiHyp += "PRECAD_";
-        guiHyp += name + " = " + value + "; ";
-      }
-    }
-  }
-  
+  // guiHyp += tr("BLSURF_TOPOLOGY") + " = " + QString::number( h_data.myTopology ) + "; ";
+  // guiHyp += tr("BLSURF_PRECAD_MERGE_EDGES") + " = " + QString(h_data.myPreCADMergeEdges ? "yes" : "no") + "; ";
+  // guiHyp += tr("BLSURF_PRECAD_REMOVE_NANO_EDGES") + " = " + QString(h_data.myPreCADProcess3DTopology ? "yes" : "no") + "; ";
+  // guiHyp += tr("BLSURF_PRECAD_DISCARD_INPUT") + " = " + QString(h_data.myPreCADDiscardInput ? "yes" : "no") + "; ";
   h_data.myGMFFileName = myAdvWidget->myGMFFileName->text().toStdString();
 //   h_data.myGMFFileMode = myGMFFileMode->isChecked();
 
   // SizeMap
-  row = 0, nbRows = mySizeMapTable->topLevelItemCount();
+  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
+  int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
   for ( ; row < nbRows; ++row )
   {
-      QString entry   = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
-      if ( that->mySMPMap.contains(entry) )
-        guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
+    QString entry   = mySizeMapTable->topLevelItem(row)->data(SMP_ENTRY_COLUMN ,Qt::EditRole).toString();
+    if ( that->mySMPMap.contains(entry) )
+      guiHyp += "SetSizeMapEntry(" + entry + ", " + that->mySMPMap[entry] + "); ";
   }
 
   // Enforced vertices
@@ -2560,54 +2690,42 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   h_data.faceEntryEnfVertexListMap.clear();
 
   int nbEnforcedShapes = myEnforcedTreeWidget->topLevelItemCount();
-  int nbEnforcedVertices = 0;
-  std::string groupName = "";
-//   MESSAGE("Nb of enforced shapes: " << nbEnforcedShapes);
-  for (int i=0 ; i<nbEnforcedShapes ; i++) {
-    QTreeWidgetItem* shapeItem = myEnforcedTreeWidget->topLevelItem(i);
-    if (shapeItem) {
-      std::string faceEntry = shapeItem->data(ENF_VER_FACE_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
-      nbEnforcedVertices = shapeItem->childCount();
-      if (nbEnforcedVertices >0) {
-        double childValueX,childValueY,childValueZ;
-        std::string childName, vertexEntry;
-        QTreeWidgetItem* child;
-        TEnfVertexList evs;
-        evs.clear();
-        for (row = 0;row<nbEnforcedVertices;row++) {
-          child = shapeItem->child(row);
-          childName   = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
-          childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
-          childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
-          childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
-          vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
-//           if (myGlobalGroupName->isChecked())
-//             groupName = myGlobalGroupName->text().toStdString();
-//           else
-            groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
-
-          TEnfVertex *enfVertex = new TEnfVertex();
-          enfVertex->name = childName;
-          if (vertexEntry.empty()) {
-            enfVertex->coords.push_back(childValueX);
-            enfVertex->coords.push_back(childValueY);
-            enfVertex->coords.push_back(childValueZ);
-          }
-          else
-            enfVertex->geomEntry = vertexEntry;
-          enfVertex->grpName = groupName;
-//           TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
-//           if (it == h_data.enfVertexList.end())
-          h_data.enfVertexList.insert(enfVertex);
-          evs.insert(enfVertex);
-          /* TODO GROUPS
-          if (groupName != "")
-            h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
-          */
-        }
-        h_data.faceEntryEnfVertexListMap[faceEntry] = evs;
-      }
+  std::string groupName = "", faceEntry = "";
+  for (int i=0 ; i<nbEnforcedShapes ; i++)
+  {
+    double childValueX,childValueY,childValueZ;
+    std::string childName, vertexEntry;
+    QTreeWidgetItem* child;
+
+    child = myEnforcedTreeWidget->topLevelItem(i);
+    childName   = child->data(ENF_VER_NAME_COLUMN,Qt::EditRole).toString().toStdString();
+    childValueX = child->data(ENF_VER_X_COLUMN,Qt::EditRole).toDouble();
+    childValueY = child->data(ENF_VER_Y_COLUMN,Qt::EditRole).toDouble();
+    childValueZ = child->data(ENF_VER_Z_COLUMN,Qt::EditRole).toDouble();
+    vertexEntry = child->data(ENF_VER_ENTRY_COLUMN,Qt::EditRole).toString().toStdString();
+    //           if (myGlobalGroupName->isChecked())
+    //             groupName = myGlobalGroupName->text().toStdString();
+    //           else
+    groupName = child->data(ENF_VER_GROUP_COLUMN,Qt::EditRole).toString().toStdString();
+
+    TEnfVertex *enfVertex = new TEnfVertex();
+    enfVertex->name = childName;
+    if (vertexEntry.empty()) {
+      enfVertex->coords.push_back(childValueX);
+      enfVertex->coords.push_back(childValueY);
+      enfVertex->coords.push_back(childValueZ);
     }
+    else
+      enfVertex->geomEntry = vertexEntry;
+    enfVertex->grpName = groupName;
+    //           TEnfVertexList::iterator it = h_data.enfVertexList.find(enfVertex);
+    //           if (it == h_data.enfVertexList.end())
+    h_data.enfVertexList.insert(enfVertex);
+    /* TODO GROUPS
+       if (groupName != "")
+       h_data.groupNameEnfVertexListMap[groupName].insert(vertex);
+    */
+    h_data.faceEntryEnfVertexListMap[faceEntry].insert( enfVertex );
   }
 
   h_data.myInternalEnforcedVerticesAllFaces      = myInternalEnforcedVerticesAllFaces->isChecked();
@@ -2617,15 +2735,13 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   h_data.preCadPeriodicityVector.clear();
   // For each tree item, store each value. Shapes are stored as entries.
   int nbPeriodicityDescriptions = myPeriodicityTreeWidget->topLevelItemCount();
-  for (size_t i=0 ; i<nbPeriodicityDescriptions ; i++) {
+  for (int i=0 ; i<nbPeriodicityDescriptions ; i++) {
     QTreeWidgetItem* item = myPeriodicityTreeWidget->topLevelItem(i);
     TPreCadPeriodicity periodicity_i;
     if (item) {
-        for (size_t k=0; k<myPeriodicityTreeWidget->columnCount(); ++k)
+        for (int k=0; k<myPeriodicityTreeWidget->columnCount(); ++k)
           {
-            MESSAGE(k);
             std::string entry = item->data(k, Qt::UserRole).toString().toStdString();
-            MESSAGE(entry);
             periodicity_i.push_back(entry);
           }
         h_data.preCadPeriodicityVector.push_back(periodicity_i);
@@ -2633,104 +2749,32 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
     guiHyp += "PERIODICITY = yes; ";
   }
 
-  MESSAGE("guiHyp : " << guiHyp.toLatin1().data());
+  // 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;
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onAddOption()
 {
-  QMenu* menu = (QMenu*)sender();
-  // fill popup with option names
-  menu->clear();
-  QString name_value, name;
-  if ( myOptions.operator->() ) {
-    QMenu* blsurfMenu = menu->addMenu(tr("OPTION_MENU_BLSURF"));
-    for ( int i = 0, nb = myOptions->length(); i < nb; ++i ) {
-      name_value = myOptions[i].in();
-      name = name_value.split( ":", QString::KeepEmptyParts )[0];
-      blsurfMenu->addAction( name );
-    }
-  }
-  if ( myPreCADOptions.operator->() ) {
-    QMenu* preCADmenu = menu->addMenu(tr("OPTION_MENU_PRECAD"));
-    for ( int i = 0, nb = myPreCADOptions->length(); i < nb; ++i ) {
-      name_value = myPreCADOptions[i].in();
-      name = name_value.split( ":", QString::KeepEmptyParts )[0];
-      preCADmenu->addAction( name );
-    }
-  }
+  myAdvWidget->AddOption( TBL_CUSTOM, NULL );
 }
 
-void BLSURFPluginGUI_HypothesisCreator::onOptionChosenInPopup( QAction* a )
-{
-  myAdvWidget->myOptionTable->setFocus();
-  QMenu* menu = (QMenu*)( a->parent() );
-
-  int idx = menu->actions().indexOf( a );
-  QString idStr = QString("%1").arg( idx );
-  QString option, optionType;
-  if (menu->title() == tr("OPTION_MENU_BLSURF")) {
-    option = myOptions[idx].in();
-    optionType = "BLSURF";
-  }
-  else if (menu->title() == tr("OPTION_MENU_PRECAD")) {
-    option = myPreCADOptions[idx].in();
-    optionType = "PRECAD";
-  }
-  QString optionName = option.split( ":", QString::KeepEmptyParts )[0];
-
-  // look for a row with optionName
-  int row = 0, nbRows = myAdvWidget->myOptionTable->rowCount();
-  for ( ; row < nbRows; ++row )
-    if ( myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text() == idStr )
-      if ( myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text() == optionType )
-        break;
-  // add a row if not found
-  if ( row == nbRows ) {
-    myAdvWidget->myOptionTable->setRowCount( row+1 );
-    myAdvWidget->myOptionTable->setItem( row, OPTION_ID_COLUMN, new QTableWidgetItem( idStr ) );
-    myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->setFlags( 0 );
-    myAdvWidget->myOptionTable->setItem( row, OPTION_TYPE_COLUMN, new QTableWidgetItem( optionType ) );
-    myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->setFlags( 0 );
-    myAdvWidget->myOptionTable->setItem( row, OPTION_NAME_COLUMN, new QTableWidgetItem( optionName ) );
-    myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->setFlags( 0 );
-    myAdvWidget->myOptionTable->setItem( row, OPTION_VALUE_COLUMN, new QTableWidgetItem( "" ) );
-    myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setFlags( Qt::ItemIsSelectable |
-                                                                            Qt::ItemIsEditable   |
-                                                                            Qt::ItemIsEnabled );
-    myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
-  }
-  myAdvWidget->myOptionTable->clearSelection();
-  myAdvWidget->myOptionTable->scrollToItem( myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
-  //myAdvWidget->myOptionTable->item( row, OPTION_VALUE_COLUMN )->setSelected( true );
-  myAdvWidget->myOptionTable->setCurrentCell( row, OPTION_VALUE_COLUMN );
-  //myAdvWidget->myOptionTable->openPersistentEditor( myOptionTable->item( row, OPTION_VALUE_COLUMN ) );
-}
-
-void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
+void BLSURFPluginGUI_HypothesisCreator::onChangeOptionName( int /*row*/, int /*column*/ )
 {
-  // clear option values and remember selected row
-  QList<int> selectedRows;
-  QList<QTableWidgetItem*> selected = myAdvWidget->myOptionTable->selectedItems();
-  QTableWidgetItem* item;
-  foreach( item, selected ) {
-    int row = item->row();
-    if ( !selectedRows.contains( row ) ) {
-      selectedRows.append( row );
-      int id = myAdvWidget->myOptionTable->item( row, OPTION_ID_COLUMN )->text().toInt();
-      QString optionType = myAdvWidget->myOptionTable->item( row, OPTION_TYPE_COLUMN )->text();
-      if ( id >= 0 )
-        if (optionType == "BLSURF" && id < myOptions->length() )
-          myOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
-        else if (optionType == "PRECAD" && id < myPreCADOptions->length() )
-          myPreCADOptions[ id ] = myAdvWidget->myOptionTable->item( row, OPTION_NAME_COLUMN )->text().toLatin1().constData();
-    }
-  }
-  qSort( selectedRows );
-  QListIterator<int> it( selectedRows );
-  it.toBack();
-  while ( it.hasPrevious() )
-    myAdvWidget->myOptionTable->removeRow( it.previous() );
+  // if ( column != OPTION_NAME_COLUMN )
+  //   return;
+  // myAdvWidget->myOptionTable->resizeColumnToContents( OPTION_NAME_COLUMN );
 }
 
 // **********************
@@ -2739,86 +2783,157 @@ void BLSURFPluginGUI_HypothesisCreator::onDeleteOption()
 
 void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
 {
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-  
-  if ( myGeomSelWdg2->IsObjectSelected() ){ 
+  if ( myGeomSelWdg2->IsObjectSelected() ){
     mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
   }
   else if ( myGeomSelWdg1->IsObjectSelected() ){
     mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
   }
-  std::string entry = (string) mySMapObject->GetStudyEntry();
-  QString qEntry = QString::fromStdString(entry);
-  if (that->mySMPMap.contains(qEntry) && that->mySMPMap[qEntry] != "__TO_DELETE__" ) {  
-    addMapButton->setEnabled(false);
-    modifyMapButton->setEnabled(true);
-  }
-  else{
-    addMapButton->setEnabled(true);
-    modifyMapButton->setEnabled(false);
+  else {
+    mySMapObject = GEOM::GEOM_Object::_nil();
+  }
+  bool dataAvailable = !mySMapObject->_is_nil();
+  QString qEntry;
+  if ( dataAvailable )
+    qEntry = SMESH::toQStr( mySMapObject->GetStudyEntry() );
+
+  bool mapExists = ( mySMPMap.contains(qEntry) && mySMPMap[qEntry] != "__TO_DELETE__" );
+  if (( mapExists && myGeomSelWdg2->IsObjectSelected() )  &&
+      ( dataAvailable = myAttSelWdg->isEnabled() )        &&
+      ( dataAvailable = myAttSelWdg->IsObjectSelected() ) &&
+      ( myATTMap.contains( qEntry )))
+  {
+    mapExists = false;
+    QString attEntry = myAttSelWdg->GetValue();
+    const TAttractorVec& attVec = myATTMap[ qEntry ];
+    for ( size_t i = 0; i < attVec.size() && !mapExists; ++i )
+      mapExists = ( attEntry == attVec[i].attEntry.c_str() );
   }
-      
-} 
+
+  addMapButton->setEnabled( !mapExists && dataAvailable );
+  modifyMapButton->setEnabled( mapExists && dataAvailable );
+}
 
 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
-{ 
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked("<<col<<")")
+{
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-  if (col == SMP_SIZEMAP_COLUMN){
+  if (col == SMP_SIZEMAP_COLUMN) {
     QString entry   = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
+    QString childEntry;
     if (!mySMPMap.contains(entry))
-      return;
+    {
+      if ( QTreeWidgetItem* parent = item->parent() )
+      {
+        childEntry = entry;
+        item = parent;
+        entry = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
+      }
+      if (!mySMPMap.contains(entry))
+        return;
+    }
     QString sizeMap = item->data( SMP_SIZEMAP_COLUMN, Qt::EditRole ).toString();
-    CORBA::Object_var obj = entryToObject(entry); 
-    if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")){  // ADVANCED MAPS
+    CORBA::Object_var obj = entryToObject(entry);
+    if (sizeMap.startsWith("Attractor") || sizeMap.startsWith("Constant")) {  // ADVANCED MAPS
       smpTab->setCurrentIndex(ATT_TAB);         // Change Tab
-      double phySize = that->mySMPMap[entry].toDouble();  // Retrieve values of the selected item in the current tab widgets
-      double infDist = that->myAttDistMap[entry];
-      double constDist = that->myDistMap[entry];
-      QString attEntry = that->myATTMap[entry];
-      CORBA::Object_var attObj = entryToObject(attEntry);
-      myAttSizeSpin->setValue(phySize);
-      if (sizeMap.startsWith("Attractor")){     
-        myAttDistSpin->setValue(infDist);
-        myAttractorCheck->setChecked(true);
-      }
-      else {
-        myAttractorCheck->setChecked(false);
-      }
-      if (sizeMap.startsWith("Constant") || constDist > std::numeric_limits<double>::epsilon()){
-        myAttDistSpin2->setValue(constDist);
-        myConstSizeCheck->setChecked(true);
-      }
-      else{
-        myConstSizeCheck->setChecked(false);
+      // Retrieve values of the selected item in the current tab widgets
+      const TAttractorVec& attVec = myATTMap[entry];
+      if ( !attVec.empty() )
+      {
+        size_t iAtt = 0;
+        if ( !childEntry.isEmpty() )
+          for ( size_t i = 0; i < attVec.size(); ++i )
+            if ( childEntry == attVec[i].attEntry.c_str() )
+            {
+              iAtt = i;
+              break;
+            }
+        double phySize   = attVec[iAtt].startSize;
+        double infDist   = attVec[iAtt].infDist;
+        double constDist = attVec[iAtt].constDist;
+        QString attEntry = attVec[iAtt].attEntry.c_str();
+        CORBA::Object_var attObj = entryToObject(attEntry);
+        myAttSizeSpin->setValue(phySize);
+        if ( infDist > std::numeric_limits<double>::epsilon() /*sizeMap.startsWith("Attractor")*/){
+          myAttDistSpin->setValue(infDist);
+          myAttractorCheck->setChecked(true);
+        }
+        else {
+          myAttractorCheck->setChecked(false);
+        }
+        if (/*sizeMap.startsWith("Constant") || */constDist > std::numeric_limits<double>::epsilon()){
+          myAttDistSpin2->setValue(constDist);
+          myConstSizeCheck->setChecked(true);
+        }
+        else{
+          myConstSizeCheck->setChecked(false);
+        }
+        myGeomSelWdg2->SetObject(obj);
+        myAttSelWdg->SetObject(attObj);
       }
-      myGeomSelWdg2->SetObject(obj); 
-      myAttSelWdg->SetObject(attObj);
     }
     else {                                                                   // CLASSIC MAPS
       smpTab->setCurrentIndex(SMP_STD_TAB);  // Change Tab
       myGeomSelWdg1->SetObject(obj);         // Retrieve values of the selected item in the current tab widgets
       if (!sizeMap.startsWith("def")){
-        mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble()); 
+        mySmpSizeSpin->setValue(that->mySMPMap[entry].toDouble());
       }
-    }  
-  } 
+    }
+  }
 }
 
-void BLSURFPluginGUI_HypothesisCreator::onSmpTabChanged(int tab)
+void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
 {
-  myAttDistSpin->setValue(0.);           // Reinitialize widgets 
-  myAttSizeSpin->setValue(0.);
-  myAttDistSpin2->setValue(0.);
-  mySmpSizeSpin->setValue(0.); 
-  myGeomSelWdg1->deactivateSelection();
-  myGeomSelWdg2->deactivateSelection();
-  myAttSelWdg->deactivateSelection();
-  myGeomSelWdg1->SetObject(CORBA::Object::_nil());
-  myGeomSelWdg2->SetObject(CORBA::Object::_nil());
-  myAttSelWdg->SetObject(CORBA::Object::_nil());
-  myAttractorCheck->setChecked(false);
-  myConstSizeCheck->setChecked(false);
+  getGeomSelectionTool()->selectionMgr()->clearFilters();
+  if ( sender() == myTabWidget )
+  {
+    myGeomSelWdg1             ->deactivateSelection();
+    myGeomSelWdg2             ->deactivateSelection();
+    myAttSelWdg               ->deactivateSelection();
+    myEnfVertexWdg            ->deactivateSelection();
+    myPeriodicitySourceFaceWdg->deactivateSelection();
+    myPeriodicityTargetFaceWdg->deactivateSelection();
+    myPeriodicityP1SourceWdg  ->deactivateSelection();
+    myPeriodicityP2SourceWdg  ->deactivateSelection();
+    myPeriodicityP3SourceWdg  ->deactivateSelection();
+    myPeriodicityP1TargetWdg  ->deactivateSelection();
+    myPeriodicityP2TargetWdg  ->deactivateSelection();
+    myPeriodicityP3TargetWdg  ->deactivateSelection();
+    if ( myHyPatchFaceSelBtn->isChecked() )
+      myHyPatchFaceSelBtn->toggle();
+    if ( myHyPatchGroupSelBtn->isChecked() )
+      myHyPatchGroupSelBtn->toggle();
+  }
+  else if ( sender() == smpTab )
+  {
+    myAttDistSpin->setValue(0.);           // Reinitialize widgets
+    myAttSizeSpin->setValue(0.);
+    myAttDistSpin2->setValue(0.);
+    mySmpSizeSpin->setValue(0.);
+    myGeomSelWdg1->deactivateSelection();
+    myGeomSelWdg2->deactivateSelection();
+    myAttSelWdg->deactivateSelection();
+    myGeomSelWdg1->SetObject(CORBA::Object::_nil());
+    myGeomSelWdg2->SetObject(CORBA::Object::_nil());
+    myAttSelWdg->SetObject(CORBA::Object::_nil());
+    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");
+  }
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
@@ -2847,7 +2962,8 @@ void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
     else if (!myAttSelWdg->IsObjectSelected()){           // Only constant size selected
       myAttSelWdg->SetDefaultText(tr("BLS_SEL_SHAPE"), "QLineEdit { color: grey }");
     }
-  }   
+  }
+  onMapGeomContentModified();
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
@@ -2878,11 +2994,11 @@ void BLSURFPluginGUI_HypothesisCreator::onConstSizeClicked(int state)
     myAttSelWdg->SetDefaultText(tr("BLS_SEL_ATTRACTOR"), "QLineEdit { color: grey }");
     }
   }   
+  onMapGeomContentModified();
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::onRemoveMap()");
   QList<int> selectedRows;
   QList<QTreeWidgetItem*> selected = mySizeMapTable->selectedItems();
   QTreeWidgetItem* item;
@@ -2894,16 +3010,34 @@ void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
   while ( it.hasPrevious() ) {
       item = it.previous();
       QString entry = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
+      QString parentEntry;
+      if ( QTreeWidgetItem* parent = item->parent() )
+        parentEntry = parent->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
       if (that->mySMPMap.contains(entry))
+      {
         that->mySMPMap[entry] = "__TO_DELETE__";
+        if ( myATTMap.contains( entry ))
+        {
+          TAttractorVec& attVec = myATTMap[entry];
+          for ( size_t i = 0; i < attVec.size(); ++i )
+            attVec[i].SetToDelete();
+        }          
+      }
+      else if ( mySMPMap.contains( parentEntry ) && myATTMap.contains( parentEntry ))
+      {
+        TAttractorVec& attVec = myATTMap[parentEntry];
+        for ( size_t i = 0; i < attVec.size(); ++i )
+        {
+          if ( entry == attVec[i].attEntry.c_str() )
+            attVec[i].SetToDelete();
+        }
+      }
       if (that->mySMPShapeTypeMap.contains(entry))
         that->mySMPShapeTypeMap.remove(entry);
-      if (that->myATTMap.contains(entry))
-        that->myATTMap.remove(entry);
-      if (that->myDistMap.contains(entry))
-        that->myDistMap.remove(entry);
-      if (that->myAttDistMap.contains(entry))
-        that->myAttDistMap.remove(entry);
+      // if (that->myDistMap.contains(entry))
+      //   that->myDistMap.remove(entry);
+      // if (that->myAttDistMap.contains(entry))
+      //   that->myAttDistMap.remove(entry);
       delete item;
   }
   mySizeMapTable->resizeColumnToContents(SMP_NAME_COLUMN);
@@ -2912,15 +3046,11 @@ void BLSURFPluginGUI_HypothesisCreator::onRemoveMap()
 
 void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int col)
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::onSetSizeMap("<< col << ")");
-  MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
   if (col == SMP_SIZEMAP_COLUMN) {
     BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
     QString entry   = item->data(SMP_ENTRY_COLUMN, Qt::EditRole).toString();
     QString sizeMap = item->data(SMP_SIZEMAP_COLUMN, Qt::EditRole).toString();
-    MESSAGE("entry: " << entry.toStdString() << ", sizeMap: " << sizeMap.toStdString());
     if (! that->mySMPShapeTypeMap.contains(entry))
-      MESSAGE("no such entry in mySMPShapeTypeMap")
       return;
     if (that->mySMPMap.contains(entry))
       if (that->mySMPMap[entry] == sizeMap 
@@ -2933,7 +3063,6 @@ void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int
       sizeMapValidationFromEntry(entry); 
     }
     else {
-      MESSAGE("Size map empty: reverse to precedent value" );
       item->setData(SMP_SIZEMAP_COLUMN, Qt::EditRole, QVariant(that->mySMPMap[entry]) );
     }
     mySizeMapTable->resizeColumnToContents(SMP_SIZEMAP_COLUMN);
@@ -2943,8 +3072,8 @@ void BLSURFPluginGUI_HypothesisCreator::onSetSizeMap(QTreeWidgetItem* item, int
 void BLSURFPluginGUI_HypothesisCreator::onAddMap()
 {
   bool res = false;
-  if ( smpTab->currentIndex() == ATT_TAB ){    
-    if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){ 
+  if ( smpTab->currentIndex() == ATT_TAB ){
+    if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){
       mySMapObject = myGeomSelWdg2->GetObject< GEOM::GEOM_Object >(0);
       myAttObject = myAttSelWdg->GetObject< GEOM::GEOM_Object >(0);
       res = insertAttractor(mySMapObject, myAttObject);
@@ -2953,8 +3082,8 @@ void BLSURFPluginGUI_HypothesisCreator::onAddMap()
   if (smpTab->currentIndex() == SMP_STD_TAB  ){
     if ( myGeomSelWdg1->IsObjectSelected() ){
       mySMapObject = myGeomSelWdg1->GetObject< GEOM::GEOM_Object >(0);
-      res = insertElement(mySMapObject);  
-    }  
+      res = insertElement(mySMapObject);
+    }
   }
   if ( !res ) {
     // Local size should be more than 0
@@ -2962,8 +3091,7 @@ void BLSURFPluginGUI_HypothesisCreator::onAddMap()
     SUIT_MessageBox::critical( dlg(),"Error" , msg );
     return;
   }
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;  
-  that->getGeomSelectionTool()->selectionMgr()->clearFilters();
+  getGeomSelectionTool()->selectionMgr()->clearFilters();
   myAttDistSpin->setValue(0.);
   myAttSizeSpin->setValue(0.);
   myAttDistSpin2->setValue(0.);
@@ -2980,7 +3108,6 @@ void BLSURFPluginGUI_HypothesisCreator::onAddMap()
 
 void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::onModifyMap()");
   bool res = false;
   if ( smpTab->currentIndex() == ATT_TAB ){    
     if ( myGeomSelWdg2->IsObjectSelected() && myAttSelWdg->IsObjectSelected() ){ 
@@ -3001,8 +3128,7 @@ void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
     SUIT_MessageBox::critical( dlg(),"Error" , msg );
     return;
   }
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;  
-  that->getGeomSelectionTool()->selectionMgr()->clearFilters();
+  getGeomSelectionTool()->selectionMgr()->clearFilters();
   myAttDistSpin->setValue(0.);
   myAttSizeSpin->setValue(0.);
   myAttDistSpin2->setValue(0.);
@@ -3019,16 +3145,14 @@ void BLSURFPluginGUI_HypothesisCreator::onModifyMap()
 
 bool BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anObject, bool modify)
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertElement()");
-  BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
-    BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
+  // BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
+  //   BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
 
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   TopAbs_ShapeEnum shapeType;
   string entry, shapeName;
   entry = (string) anObject->GetStudyEntry();
-  MESSAGE("entry = "<<entry);
   shapeName = anObject->GetName();
   shapeType = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( anObject ).ShapeType();
   // Group management : the type of entities in the group is stored in the SMPShapeTypeMap
@@ -3066,14 +3190,13 @@ bool BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anOb
   else{
     if (that->mySMPMap.contains(shapeEntry)) {  
       if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
-  //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
         return false;
       }
     }
     mySizeMapTable->addTopLevelItem(item);
   }
   that->mySMPMap[shapeEntry] = sizeMap;
-  that->myDistMap[shapeEntry] = 0. ;
+  //that->myDistMap[shapeEntry] = 0. ;
   that->mySMPShapeTypeMap[shapeEntry] = shapeType;
   item->setFlags( Qt::ItemIsSelectable |Qt::ItemIsEditable   |Qt::ItemIsEnabled );
   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
@@ -3093,12 +3216,9 @@ bool BLSURFPluginGUI_HypothesisCreator::insertElement(GEOM::GEOM_Object_var anOb
 
 bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aFace, GEOM::GEOM_Object_var anAttractor, bool modify)
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::insertAttractor()");
   BLSURFPlugin::BLSURFPlugin_Hypothesis_var h =
     BLSURFPlugin::BLSURFPlugin_Hypothesis::_narrow( initParamsHypothesis());
 
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-
   TopAbs_ShapeEnum shapeType;
   string entry, attEntry, faceName, attName;
   entry = (string) aFace->GetStudyEntry();
@@ -3135,29 +3255,55 @@ bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aF
   QString constDistString = QString::fromStdString(oss3.str());
   
   QTreeWidgetItem* item; 
-  QTreeWidgetItem* child; 
-  if (modify){
+  QTreeWidgetItem* child = 0;
+  TAttractor attParams( attEntry.c_str(), phySize, infDist, constDist );
+  if (modify) {
     int rowToChange = findRowFromEntry(shapeEntry);
     item = mySizeMapTable->topLevelItem( rowToChange );
-    child = item->child( 0 );
+    
+    for ( int i = 0, nb = item->childCount(); i < nb; ++i )
+      if (( child = item->child( i )))
+        if ( qAttEntry == child->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString() )
+          break;
+    TAttractorVec & attVec = myATTMap[shapeEntry];
+    for ( size_t i = 0; i < attVec.size(); ++i )
+      if ( attVec[i].attEntry == attEntry )
+      {
+        attVec[i] = attParams;
+        break;
+      }
   }
   else{
-    if (that->mySMPMap.contains(shapeEntry)) {  
-      if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
-    //             MESSAGE("Size map for shape with name(entry): "<< shapeName << "(" << entry << ")");
-        return false;
-      }
+    // if (that->mySMPMap.contains(shapeEntry)) {  
+    //   if (that->mySMPMap[shapeEntry] != "__TO_DELETE__") {
+    //     return false;
+    //   }
+    // }
+    int rowToChange = findRowFromEntry(shapeEntry);
+    if ( rowToChange < mySizeMapTable->topLevelItemCount() )
+    {
+      item = mySizeMapTable->topLevelItem( rowToChange );
+    }
+    else {
+      item = new QTreeWidgetItem();
+      mySizeMapTable->addTopLevelItem(item);
     }
-    item = new QTreeWidgetItem();
     child = new QTreeWidgetItem();
-    mySizeMapTable->addTopLevelItem(item);
     item->addChild(child);
+    bool exists = false;
+    TAttractorVec & attVec = myATTMap[shapeEntry];
+    for ( size_t i = 0; i < attVec.size(); ++i )
+      if ( attVec[i].attEntry == attEntry )
+      {
+        attVec[i] = attParams;
+        exists = true;
+        break;
+      }
+    if ( !exists )
+      myATTMap[shapeEntry].push_back( attParams );
   }
-  that->mySMPMap.insert(shapeEntry,sizeMap);
-  that->myATTMap.insert(shapeEntry,qAttEntry);
-  that->myAttDistMap.insert(shapeEntry,infDist);
-  that->myDistMap.insert(shapeEntry,constDist);
-  that->mySMPShapeTypeMap.insert(shapeEntry,shapeType);
+  mySMPMap.insert(shapeEntry,sizeMap);
+  mySMPShapeTypeMap.insert(shapeEntry,shapeType);
   item->setExpanded(true); 
   item->setData(SMP_ENTRY_COLUMN, Qt::EditRole, QVariant(shapeEntry) );
   item->setData(SMP_NAME_COLUMN, Qt::EditRole, QVariant(QString::fromStdString(faceName)) );
@@ -3181,13 +3327,11 @@ bool BLSURFPluginGUI_HypothesisCreator::insertAttractor(GEOM::GEOM_Object_var aF
     myStdWidget->myPhysicalMesh->setCurrentIndex( PhysicalLocalSize );
     myStdWidget->onPhysicalMeshChanged();
   }
-  MESSAGE("mySMPMap.size() = "<<mySMPMap.size());
   return true;
 }
 
 bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()");
   int row = 0, nbRows = mySizeMapTable->topLevelItemCount();
   for ( ; row < nbRows; ++row )
     if (! sizeMapValidationFromRow(row))
@@ -3197,7 +3341,6 @@ bool BLSURFPluginGUI_HypothesisCreator::sizeMapsValidation()
 
 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool displayError)
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(), row = "<<myRow);
   QString myEntry   = mySizeMapTable->topLevelItem( myRow )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
   bool res = sizeMapValidationFromEntry(myEntry,displayError);
   mySizeMapTable->setFocus();
@@ -3206,28 +3349,22 @@ bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromRow(int myRow, bool
 
 bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEntry, bool displayError)
 {
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry()");
-  MESSAGE("myEntry = "<<myEntry.toStdString())
 
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   if (! that->mySMPMap.contains(myEntry)) {
-//     MESSAGE("Geometry with entry "<<myEntry.toStdString()<<" was not found.");
     return false;
   }
   if (! that->mySMPShapeTypeMap.contains(myEntry)) {
-//     MESSAGE("Shape type with entry "<<myEntry.toStdString()<<" was not found.");
     return false;
   }
 
   string expr;
 
   if (that->mySMPMap[myEntry].startsWith("def")) {
-//     MESSAGE("custom function" );
     expr = that->mySMPMap[myEntry].toStdString();
   }
   else if (that->mySMPMap[myEntry].startsWith("ATTRACTOR")) {
-//     MESSAGE("Attractor" );
     if ((that->mySMPMap[myEntry].count(QRegExp("^ATTRACTOR\\((?:(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+);){5}(True|False)(?:;(-?0(\\.\\d*)*|-?[1-9]+\\d*(\\.\\d*)*|-?\\.(\\d)+))?\\)$")) != 1)) {
 
       if (displayError)
@@ -3258,17 +3395,17 @@ bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEnt
   PyGILState_STATE gstate;
   gstate = PyGILState_Ensure();
 
-  PyObject * obj = NULL;
-  PyObject* new_stderr = NULL;
   string  err_description="";
-  obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
+  PyObject* obj= PyRun_String(expr.c_str(), Py_file_input, main_dict, NULL);
   if (obj == NULL){
     fflush(stderr);
     err_description="";
-    new_stderr=newPyStdOut(err_description);
+    PyObject* new_stderr = newPyStdOut(err_description);
+    PyObject* old_stderr = PySys_GetObject((char*)"stderr");
+    Py_INCREF(old_stderr);
     PySys_SetObject((char*)"stderr", new_stderr);
     PyErr_Print();
-    PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
+    PySys_SetObject((char*)"stderr", old_stderr);
     Py_DECREF(new_stderr);
     if (displayError)
       SUIT_MessageBox::warning( dlg(),"Definition of Python Function : Error" ,err_description.c_str() );
@@ -3277,15 +3414,16 @@ bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEnt
   }
   Py_DECREF(obj);
 
-  PyObject * func = NULL;
-  func = PyObject_GetAttrString(main_mod, "f");
+  PyObject* func = PyObject_GetAttrString(main_mod, "f");
   if ( func == NULL){
     fflush(stderr);
     err_description="";
-    new_stderr=newPyStdOut(err_description);
+    PyObject* new_stderr = newPyStdOut(err_description);
+    PyObject* old_stderr = PySys_GetObject((char*)"stderr");
+    Py_INCREF(old_stderr);
     PySys_SetObject((char*)"stderr", new_stderr);
     PyErr_Print();
-    PySys_SetObject((char*)"stderr", PySys_GetObject((char*)"__stderr__"));
+    PySys_SetObject((char*)"stderr", old_stderr);
     Py_DECREF(new_stderr);
     if (displayError)
       SUIT_MessageBox::warning( dlg(),"Python Error" ,err_description.c_str() );
@@ -3295,11 +3433,151 @@ bool BLSURFPluginGUI_HypothesisCreator::sizeMapValidationFromEntry(QString myEnt
 
   PyGILState_Release(gstate);
 
-//   MESSAGE("SizeMap expression "<<expr<<" is valid");
 
   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();
+  }
+}
+
+bool BLSURFPluginGUI_HypothesisCreator::hasGeom() const
+{
+  return hypType() == BLSURFPlugin_Hypothesis::GetHypType(true);
+}
+
 QString BLSURFPluginGUI_HypothesisCreator::caption() const
 {
   return tr( "BLSURF_TITLE" );
@@ -3332,10 +3610,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();
@@ -3344,15 +3620,14 @@ CORBA::Object_var BLSURFPluginGUI_HypothesisCreator::entryToObject(QString entry
 }
 
 int BLSURFPluginGUI_HypothesisCreator::findRowFromEntry(QString entry){
-  QString entryForChecking;
   int endRow = mySizeMapTable->topLevelItemCount()-1;
   int row = 0;
-  entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
-  while (entry != entryForChecking && row <= endRow){
-    row++;
-    entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
+  for ( ; row <= endRow; ++row )
+  {
+    QString entryForChecking = mySizeMapTable->topLevelItem( row )->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
+    if (entry == entryForChecking )
+      break;
   }
-  MESSAGE("BLSURFPluginGUI_HypothesisCreator::findRowFromEntry; row = "<<row<<" , endRow ="<<endRow)
   return row;
 }