Salome HOME
bos #20256: [CEA 18523] Porting SMESH to int 64 bits
[plugins/blsurfplugin.git] / src / GUI / BLSURFPluginGUI_HypothesisCreator.cxx
index 94ba8e72e4b64316a58756f2d7c43f6726156ab9..c21e967796705f85f3224dc62ef2649e9be1f9b1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  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
@@ -213,20 +213,19 @@ namespace {
   static PyMethodDef PyStdOut_methods[] = {
     {"write",  (PyCFunction)PyStdOut_write,  METH_VARARGS,
     PyDoc_STR("write(string) -> None")},
-    {NULL,    NULL}   /* sentinel */
+    {0, 0, 0, 0}   /* sentinel */
   };
 
   static PyMemberDef PyStdOut_memberlist[] = {
     {(char*)"softspace", T_INT,  offsetof(PyStdOut, softspace), 0,
      (char*)"flag indicating that a space needs to be printed; used by print"},
-    {NULL} /* Sentinel */
+    {0, 0, 0, 0, 0} /* Sentinel */
   };
 
   static PyTypeObject PyStdOut_Type = {
     /* The ob_type field must be initialized in the module init function
      * to be portable to Windows without using C++. */
-    PyObject_HEAD_INIT(NULL)
-    0,                            /*ob_size*/
+    PyVarObject_HEAD_INIT(NULL, 0)
     "PyOut",                      /*tp_name*/
     sizeof(PyStdOut),             /*tp_basicsize*/
     0,                            /*tp_itemsize*/
@@ -268,6 +267,14 @@ namespace {
     0,                            /*tp_new*/
     0,                            /*tp_free*/
     0,                            /*tp_is_gc*/
+    0,                            /*tp_bases*/
+    0,                            /*tp_mro*/
+    0,                            /*tp_cache*/
+    0,                            /*tp_subclasses*/
+    0,                            /*tp_weaklist*/
+    0,                            /*tp_del*/
+    0,                            /*tp_version_tag*/
+    0,                            /*tp_finalize*/
   };
 
   PyObject * newPyStdOut( std::string& out )
@@ -296,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();
@@ -475,9 +482,8 @@ BLSURFPluginGUI_HypothesisCreator::~BLSURFPluginGUI_HypothesisCreator()
 GeomSelectionTools* BLSURFPluginGUI_HypothesisCreator::getGeomSelectionTool() const
 {
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-  if (that->GeomToolSelected == NULL || that->GeomToolSelected->getMyStudy() != aStudy) {
-    that->GeomToolSelected = new GeomSelectionTools(aStudy);
+  if (that->GeomToolSelected == NULL) {
+    that->GeomToolSelected = new GeomSelectionTools();
   }
   return that->GeomToolSelected;
 }
@@ -566,12 +572,6 @@ bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
       }
     }
   }
-  if ( !ok )
-  {
-    h->SetOptionValues( myOptions ); // restore values
-    h->SetPreCADOptionValues( myPreCADOptions ); // restore values
-    return ok;
-  }
 
   // SizeMap and attractors
   if ( ok )
@@ -592,7 +592,7 @@ bool BLSURFPluginGUI_HypothesisCreator::checkParams(QString& msg) const
           try {
             e = entry.toStdString();
             s = that->mySMPMap[entry].toStdString();
-            h->SetSizeMapEntry( e.c_str(), s.c_str() );
+            //h->SetSizeMapEntry( e.c_str(), s.c_str() );
           }
           catch ( const SALOME::SALOME_Exception& ex )
           {
@@ -639,9 +639,63 @@ 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;
 }
 
@@ -848,11 +902,7 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myEnforcedTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
   myEnforcedTreeWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
   for (int column = 0; column < ENF_VER_NB_COLUMNS; ++column) {
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-    myEnforcedTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
-#else
     myEnforcedTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
-#endif
     myEnforcedTreeWidget->resizeColumnToContents(column);
   }
   myEnforcedTreeWidget->hideColumn(ENF_VER_FACE_ENTRY_COLUMN);
@@ -960,13 +1010,9 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myPeriodicityTreeWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
   myPeriodicityTreeWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
   
-  size_t periodicityVisibleColumns = 2;
-  for (size_t column = 0; column < periodicityVisibleColumns; ++column) {
-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
-      myPeriodicityTreeWidget->header()->setResizeMode(column,QHeaderView::Interactive);
-#else
+  int periodicityVisibleColumns = 2;
+  for (int column = 0; column < periodicityVisibleColumns; ++column) {
       myPeriodicityTreeWidget->header()->setSectionResizeMode(column,QHeaderView::Interactive);
-#endif
       myPeriodicityTreeWidget->resizeColumnToContents(column);
   }
   myPeriodicityTreeWidget->header()->setStretchLastSection(true);
@@ -1168,7 +1214,6 @@ QFrame* BLSURFPluginGUI_HypothesisCreator::buildFrame()
   myTabWidget->setCurrentIndex( STD_TAB );
 
   connect( myAdvWidget->addBtn, SIGNAL( clicked() ),           this, SLOT( onAddOption() ) );
-  connect( myStdWidget->myAllowQuadrangles, SIGNAL( stateChanged( int ) ), this, SLOT( onStateChange() ));
 
   // Size Maps
   connect( addMapButton,        SIGNAL( clicked()),                    this,         SLOT( onAddMap() ) );
@@ -1254,7 +1299,8 @@ void BLSURFPluginGUI_HypothesisCreator::clearEnforcedVertexWidgets()
     This method updates the tooltip of a modified item. The QLineEdit widgets content
     is synchronized with the coordinates of the enforced vertex clicked in the tree widget.
 */
-void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int column) {
+void BLSURFPluginGUI_HypothesisCreator::updateEnforcedVertexValues(QTreeWidgetItem* item, int /*column*/)
+{
   QVariant vertexName = item->data(ENF_VER_NAME_COLUMN, Qt::EditRole);
   QVariant x = item->data(ENF_VER_X_COLUMN, Qt::EditRole);
   QVariant y = item->data(ENF_VER_Y_COLUMN, Qt::EditRole);
@@ -1291,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)
   {
@@ -1301,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;
       
@@ -1322,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) {
@@ -1349,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;
@@ -1452,8 +1500,6 @@ This method is called when a item is added into the enforced vertices tree widge
 */
 void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
 {
-  BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
-
   getGeomSelectionTool()->selectionMgr()->clearFilters();
   myEnfVertexWdg->deactivateSelection();
 
@@ -1461,7 +1507,7 @@ void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
     myEnforcedTreeWidget->resizeColumnToContents(column);
 
   // Vertex selection
-  int selEnfVertex = myEnfVertexWdg->NbObjects();
+  size_t selEnfVertex = myEnfVertexWdg->NbObjects();
   bool coordsEmpty = (myXCoord->text().isEmpty()) || (myYCoord->text().isEmpty()) || (myZCoord->text().isEmpty());
 
   if ((selEnfVertex == 0) && coordsEmpty)
@@ -1489,13 +1535,13 @@ void BLSURFPluginGUI_HypothesisCreator::onAddEnforcedVertices()
       if ( CORBA::is_nil(getGeomEngine()))
         return;
 
-      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations( that->getGeomSelectionTool()->getMyStudy()->StudyId() );
+      GEOM::GEOM_IMeasureOperations_var measureOp = getGeomEngine()->GetIMeasureOperations();
       if (CORBA::is_nil(measureOp))
         return;
 
       CORBA::Double x,y,z;
       x = y = z = 0.;
-      for (int j = 0 ; j < selEnfVertex ; j++)
+      for (size_t j = 0 ; j < selEnfVertex ; j++)
       {
         myEnfVertex = myEnfVertexWdg->GetObject< GEOM::GEOM_Object >(j);
         if (myEnfVertex->GetShapeType() == GEOM::VERTEX) {
@@ -1523,7 +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() {
+void BLSURFPluginGUI_HypothesisCreator::onRemoveEnforcedVertex()
+{
   QList<QTreeWidgetItem *> selectedItems = myEnforcedTreeWidget->selectedItems();
   QList<QTreeWidgetItem *> selectedVertices;
   QSet<QTreeWidgetItem *> selectedEntries;
@@ -1570,8 +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() {
-
+void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity()
+{
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
 
   that->getGeomSelectionTool()->selectionMgr()->clearFilters();
@@ -1584,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;
@@ -1593,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)
         {
@@ -1619,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 );
@@ -1651,7 +1698,8 @@ void BLSURFPluginGUI_HypothesisCreator::onAddPeriodicity() {
 /** BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
 This method is called when a item is removed from the periodicity tree widget
 */
-void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity() {
+void BLSURFPluginGUI_HypothesisCreator::onRemovePeriodicity()
+{
   QList<QTreeWidgetItem *> selectedItems = myPeriodicityTreeWidget->selectedItems();
   QTreeWidgetItem* item;
 
@@ -1699,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++)
     {
@@ -1761,7 +1809,7 @@ void BLSURFPluginGUI_HypothesisCreator::onPeriodicityContentModified()
 
 
 /** BLSURFPluginGUI_HypothesisCreator::retrieveParams()
-This method updates the GUI widgets with the hypothesis data
+    This method updates the GUI widgets with the hypothesis data
 */
 void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
 {
@@ -1802,8 +1850,31 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
     myStdWidget->myVolumeGradation->setText("");
   else
     myStdWidget->myVolumeGradation->SetValue( data.myVolumeGradation );
-  myStdWidget->myAllowQuadrangles->setChecked( data.myAllowQuadrangles );
-  
+
+  foreach (QAbstractButton* button, myStdWidget->myButtonGroupElementType->buttons()) {
+    if (myStdWidget->myButtonGroupElementType->id(button) == data.myElementType) {
+      button->setChecked(true);
+      break;
+    }
+  }
+
+  myStdWidget->myUseSurfaceProximity->setChecked( data.myUseSurfaceProximity );
+  myStdWidget->myNbSurfaceProximityLayers->setValue( data.myNbSurfaceProximityLayers );
+  myStdWidget->mySurfaceProximityRatio->SetValue( data.mySurfaceProximityRatio );
+  myStdWidget->myUseVolumeProximity->setChecked( data.myUseVolumeProximity );
+  myStdWidget->myNbVolumeProximityLayers->setValue( data.myNbVolumeProximityLayers );
+  myStdWidget->myVolumeProximityRatio->SetValue( data.myVolumeProximityRatio );
+  if ( !data.myUseSurfaceProximity )
+  {
+    //myStdWidget->myNbSurfaceProximityLayers->setText("");
+    myStdWidget->mySurfaceProximityRatio->setText("");
+  }
+  if ( !data.myUseVolumeProximity )
+  {
+    //myStdWidget->myNbVolumeProximityLayers->setText("");
+    myStdWidget->myVolumeProximityRatio->setText("");
+  }
+
   if (data.myAngleMesh < 0)
     myStdWidget->myAngleMesh->setText("");
   else
@@ -1948,15 +2019,19 @@ void BLSURFPluginGUI_HypothesisCreator::retrieveParams() const
     {
       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() );
+      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 )
-    that->addHyPatchToTable( data.hyperpatches[i] );
-
+  {
+    if ( i < data.hyperEntries.size() )
+      patchEntries = data.hyperEntries[i];
+    that->addHyPatchToTable( data.hyperpatches[i], patchEntries );
+  }
   // update widgets
   that->myStdWidget->onPhysicalMeshChanged();
   that->myStdWidget->onGeometricMeshChanged();
@@ -2002,7 +2077,7 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   h_data.myGradation              = h->GetGradation();
   h_data.myUseVolumeGradation     = h->GetUseVolumeGradation();
   h_data.myVolumeGradation        = h->GetVolumeGradation();
-  h_data.myAllowQuadrangles       = h->GetQuadAllowed();
+  h_data.myElementType            = h->GetElementType();
   double angle                    = h->GetAngleMesh();
   h_data.myAngleMesh              = angle > 0 ? angle : -1.0;
   double chordalError             = h->GetChordalError();
@@ -2018,7 +2093,7 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   h_data.myTinyEdgeOptimisLength  = myTinyEdgeOptimisLength > 0 ? myTinyEdgeOptimisLength : -1.0;
   h_data.myCorrectSurfaceIntersection = h->GetCorrectSurfaceIntersection();
   double corrSurfaceIntersMaxCost = h->GetCorrectSurfaceIntersectionMaxCost();
-  h_data.myCorrectSurfaceIntersectionMaxCost  = corrSurfaceIntersMaxCost > 0 ? corrSurfaceIntersMaxCost : -1.0;
+  h_data.myCorrectSurfaceIntersectionMaxCost = corrSurfaceIntersMaxCost > 0 ? corrSurfaceIntersMaxCost : -1.0;
   h_data.myForceBadElementRemoval = h->GetBadElementRemoval();
   double myBadElementAspectRatio  = h->GetBadElementAspectRatio();
   h_data.myBadElementAspectRatio  = myBadElementAspectRatio > 0 ? myBadElementAspectRatio : -1.0;
@@ -2029,7 +2104,12 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
   //h_data.myPreCADMergeEdges       = h->GetPreCADMergeEdges();
   // h_data.myPreCADProcess3DTopology  = h->GetPreCADProcess3DTopology();
   // h_data.myPreCADDiscardInput     = h->GetPreCADDiscardInput();
-
+  h_data.myUseSurfaceProximity      = h->GetSurfaceProximity        ();
+  h_data.myNbSurfaceProximityLayers = h->GetNbSurfaceProximityLayers();
+  h_data.mySurfaceProximityRatio    = h->GetSurfaceProximityRatio   ();
+  h_data.myUseVolumeProximity       = h->GetVolumeProximity         ();
+  h_data.myNbVolumeProximityLayers  = h->GetNbVolumeProximityLayers ();
+  h_data.myVolumeProximityRatio     = h->GetVolumeProximityRatio    ();
 
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
   that->myOptions       = h->GetOptionValues();
@@ -2054,7 +2134,7 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
     fullSizeMapList = fullSizeMaps.split( "|", QString::KeepEmptyParts );
     if ( fullSizeMapList.count() > 1 ) {
       string fullSizeMap = fullSizeMapList[1].toStdString();
-      int pos = fullSizeMap.find("return")+7;
+      size_t pos = fullSizeMap.find("return")+7;
       QString sizeMap;
       try {
         sizeMap = QString::fromStdString(fullSizeMap.substr(pos, fullSizeMap.size()-pos));
@@ -2159,8 +2239,14 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
 
   // Hyper Patches
 
+  GEOM::GEOM_Object_var geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getMainShapeEntry() );
+  if ( geom->_is_nil() )
+    geom = myHyPatchFaceSelector->GetGeomObjectByEntry( getShapeEntry() );
+
   h_data.hyperpatches.clear();
-  BLSURFPlugin::THyperPatchList_var patchList = h->GetHyperPatches();
+  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;
@@ -2169,7 +2255,19 @@ bool BLSURFPluginGUI_HypothesisCreator::readParamsFromHypo( BlsurfHypothesisData
       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;
 }
@@ -2178,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();
@@ -2191,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)
@@ -2261,26 +2361,33 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
     if ( h->GetVolumeGradation() !=  h_data.myVolumeGradation )
       h->SetVolumeGradation( h_data.myVolumeGradation <= 0 ? -1 : h_data.myVolumeGradation );
 
-    if ( h->GetQuadAllowed() != h_data.myAllowQuadrangles )
-      h->SetQuadAllowed( h_data.myAllowQuadrangles );
-    
+    h->SetSurfaceProximity        ((CORBA::Short) h_data.myUseSurfaceProximity      );
+    h->SetNbSurfaceProximityLayers((CORBA::Short) h_data.myNbSurfaceProximityLayers );
+    h->SetSurfaceProximityRatio   ( h_data.mySurfaceProximityRatio    );
+    h->SetVolumeProximity         ((CORBA::Short) h_data.myUseVolumeProximity       );
+    h->SetNbVolumeProximityLayers ((CORBA::Short) h_data.myNbVolumeProximityLayers  );
+    h->SetVolumeProximityRatio    ( h_data.myVolumeProximityRatio     );
+
+    if ( h->GetElementType() != h_data.myElementType )
+      h->SetElementType( h_data.myElementType );
+
     if ( (int) h_data.myGeometricMesh != DefaultGeom ) {
       if ( h->GetAngleMesh() != h_data.myAngleMesh )
         h->SetAngleMesh( h_data.myAngleMesh <= 0 ? -1 :h_data.myAngleMesh );
       if ( h->GetChordalError() != h_data.myChordalError )
         h->SetChordalError( h_data.myChordalError <= 0 ? -1 :h_data.myChordalError );
     }
-    
+
     if ( h->GetAnisotropic() != h_data.myAnisotropic )
       h->SetAnisotropic( h_data.myAnisotropic );
     if ( h_data.myAnisotropic && ( h->GetAnisotropicRatio() != h_data.myAnisotropicRatio ) )
       h->SetAnisotropicRatio( h_data.myAnisotropicRatio <= 0 ? -1 :h_data.myAnisotropicRatio );
-    
+
     if ( h->GetRemoveTinyEdges() != h_data.myRemoveTinyEdges )
       h->SetRemoveTinyEdges( h_data.myRemoveTinyEdges );
     if ( h_data.myRemoveTinyEdges && ( h->GetTinyEdgeLength() != h_data.myTinyEdgeLength ) )
       h->SetTinyEdgeLength( h_data.myTinyEdgeLength <= 0 ? -1 :h_data.myTinyEdgeLength );
-    
+
     if ( h->GetOptimiseTinyEdges() != h_data.myOptimiseTinyEdges )
       h->SetOptimiseTinyEdges( h_data.myOptimiseTinyEdges );
     if ( h_data.myOptimiseTinyEdges && ( h->GetTinyEdgeOptimisationLength() != h_data.myTinyEdgeOptimisLength ) )
@@ -2302,7 +2409,7 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
       h->SetQuadraticMesh( h_data.myQuadraticMesh );
 
     if ( h->GetVerbosity() != h_data.myVerbosity )
-      h->SetVerbosity( h_data.myVerbosity );
+      h->SetVerbosity((CORBA::Short) h_data.myVerbosity );
     // if ( h->GetTopology() != h_data.myTopology )
     //   h->SetTopology( (int) h_data.myTopology );
     // if ( h->GetPreCADMergeEdges() != h_data.myPreCADMergeEdges )
@@ -2452,8 +2559,10 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
     }
 
     // Hyper-patches
-    BLSURFPlugin::THyperPatchList_var hpl = new BLSURFPlugin::THyperPatchList();
-    hpl->length( h_data.hyperpatches.size() );
+    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 )
     {
@@ -2462,9 +2571,22 @@ bool BLSURFPluginGUI_HypothesisCreator::storeParamsToHypo( const BlsurfHypothesi
       patch.length( tags.size() );
 
       for ( int j = 0; j < tags.size(); ++j )
-        patch[ j ] = tags[ j ].toDouble();
+        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() );
+      }
     }
-    h->SetHyperPatches( hpl );
+    if ( h_data.hyperEntries.size() == h_data.hyperpatches.size() )
+      h->SetHyperPatchEntries( hpel );
+    else
+      h->SetHyperPatches( hpl );
 
 
   } // try
@@ -2493,7 +2615,7 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   h_data.myGradation             = h_data.myUseGradation ? myStdWidget->myGradation->GetValue() : -1.0;
   h_data.myUseVolumeGradation    = myStdWidget->myUseVolumeGradation->isChecked() && !myStdWidget->myVolumeGradation->text().isEmpty();
   h_data.myVolumeGradation       = h_data.myUseVolumeGradation ? myStdWidget->myVolumeGradation->GetValue() : -1. ;
-  h_data.myAllowQuadrangles      = myStdWidget->myAllowQuadrangles->isChecked();
+  h_data.myElementType           = myStdWidget->myButtonGroupElementType->checkedId();
   h_data.myAngleMesh             = myStdWidget->myAngleMesh->text().isEmpty() ? -1.0 : myStdWidget->myAngleMesh->GetValue();
   h_data.myChordalError          = myStdWidget->myChordalError->text().isEmpty() ? -1.0 : myStdWidget->myChordalError->GetValue();
   h_data.myAnisotropic           = myStdWidget->myAnisotropic->isChecked();
@@ -2513,6 +2635,12 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
   //h_data.myPreCADMergeEdges      = myAdvWidget->myPreCADMergeEdges->isChecked();
   //h_data.myPreCADProcess3DTopology = myAdvWidget->myPreCADProcess3DTopology->isChecked();
   //h_data.myPreCADDiscardInput    = myAdvWidget->myPreCADDiscardInput->isChecked();
+  h_data.myUseSurfaceProximity      = myStdWidget->myUseSurfaceProximity     ->isChecked();
+  h_data.myNbSurfaceProximityLayers = myStdWidget->myNbSurfaceProximityLayers->value();
+  h_data.mySurfaceProximityRatio    = myStdWidget->mySurfaceProximityRatio   ->value();
+  h_data.myUseVolumeProximity       = myStdWidget->myUseVolumeProximity      ->isChecked();
+  h_data.myNbVolumeProximityLayers  = myStdWidget->myNbVolumeProximityLayers ->value();
+  h_data.myVolumeProximityRatio     = myStdWidget->myVolumeProximityRatio    ->value();
 
   QString guiHyp;
   guiHyp += tr("BLSURF_PHY_MESH") + " = " + QString::number( h_data.myPhysicalMesh ) + "; ";
@@ -2524,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") + "; ";
@@ -2623,8 +2751,16 @@ QString BLSURFPluginGUI_HypothesisCreator::readParamsFromWidgets( BlsurfHypothes
 
   // Hyper-patches
   h_data.hyperpatches.clear();
+  h_data.hyperEntries.clear();
   for ( int row = 0; row < myHyPatchTable->rowCount(); ++row )
-    h_data.hyperpatches.append( myHyPatchTable->item( row, 0 )->text() );
+  {
+    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;
 }
@@ -2634,7 +2770,7 @@ void BLSURFPluginGUI_HypothesisCreator::onAddOption()
   myAdvWidget->AddOption( TBL_CUSTOM, NULL );
 }
 
-void BLSURFPluginGUI_HypothesisCreator::onChangeOptionName( int row, int column )
+void BLSURFPluginGUI_HypothesisCreator::onChangeOptionName( int /*row*/, int /*column*/ )
 {
   // if ( column != OPTION_NAME_COLUMN )
   //   return;
@@ -2679,7 +2815,7 @@ void BLSURFPluginGUI_HypothesisCreator::onMapGeomContentModified()
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item, int col)
-{ 
+{
   BLSURFPluginGUI_HypothesisCreator* that = (BLSURFPluginGUI_HypothesisCreator*)this;
   if (col == SMP_SIZEMAP_COLUMN) {
     QString entry   = item->data( SMP_ENTRY_COLUMN, Qt::EditRole ).toString();
@@ -2703,7 +2839,7 @@ void BLSURFPluginGUI_HypothesisCreator::onSmpItemClicked(QTreeWidgetItem * item,
       const TAttractorVec& attVec = myATTMap[entry];
       if ( !attVec.empty() )
       {
-        int iAtt = 0;
+        size_t iAtt = 0;
         if ( !childEntry.isEmpty() )
           for ( size_t i = 0; i < attVec.size(); ++i )
             if ( childEntry == attVec[i].attEntry.c_str() )
@@ -2766,7 +2902,6 @@ void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
       myHyPatchFaceSelBtn->toggle();
     if ( myHyPatchGroupSelBtn->isChecked() )
       myHyPatchGroupSelBtn->toggle();
-    return;
   }
   else if ( sender() == smpTab )
   {
@@ -2783,6 +2918,22 @@ void BLSURFPluginGUI_HypothesisCreator::onTabChanged(int tab)
     myAttractorCheck->setChecked(false);
     myConstSizeCheck->setChecked(false);
   }
+
+  if ( tab == SMP_TAB ) // [#16954] limit local size by Min and User Size
+  {
+    double minSize = 0, maxSize = COORD_MAX;
+
+    if ( !myStdWidget->myMinSizeRel->isChecked() &&
+         !myStdWidget->myMinSize->text().isEmpty() )
+      minSize = myStdWidget->myMinSize->GetValue();
+
+    if ( !myStdWidget->myPhySizeRel->isChecked() &&
+         !myStdWidget->myPhySize->text().isEmpty() )
+      maxSize = myStdWidget->myPhySize->GetValue();
+
+    mySmpSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
+    myAttSizeSpin->RangeStepAndValidator(minSize, maxSize, 1.0, "length_precision");
+  }
 }
 
 void BLSURFPluginGUI_HypothesisCreator::onAttractorClicked(int state)
@@ -3362,7 +3513,23 @@ void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd()
   QStringList tagList = myHyPatchTagsLE->text().split(" ",  QString::SkipEmptyParts);
   if ( tagList.size() > 1 )
   {
-    addHyPatchToTable( myHyPatchTagsLE->text() );
+    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("");
   }
 }
@@ -3373,12 +3540,17 @@ void BLSURFPluginGUI_HypothesisCreator::onHyPatchAdd()
  */
 //================================================================================
 
-void BLSURFPluginGUI_HypothesisCreator::addHyPatchToTable(const QString& tags)
+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 );
@@ -3438,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();