Salome HOME
Updated copyright comment
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
index b32b2d2deeb29b2e28774fe93afc0513e4b36fc0..773db4dd20249b1b921abee1cbeec2b95228edb8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 #include "BLSURFPlugin_Hypothesis.hxx"
 #include "BLSURFPlugin_Attractor.hxx"
-#include "SMESH_Gen_i.hxx"
+
+#include <SMESHDS_Group.hxx>
+#include <SMESHDS_Mesh.hxx>
+#include <SMESH_BoostTxtArchive.hxx>
+#include <SMESH_Gen_i.hxx>
+#include <SMESH_Group.hxx>
+#include <SMESH_TryCatch.hxx>
+
+#include <Basics_Utils.hxx>
 #include <utilities.h>
-#include <cstring>
-#include <iostream>
-#include <sstream>
 
 // cascade include
-#include "ShapeAnalysis.hxx"
+#include <ShapeAnalysis.hxx>
 
 // CORBA includes
 #include CORBA_CLIENT_HEADER(SALOMEDS)
 #include CORBA_CLIENT_HEADER(GEOM_Gen)
 
+#include <meshgems/meshgems.h>
+#define MESHGEMS_VERSION_HEX (MESHGEMS_VERSION_MAJOR << 16 | MESHGEMS_VERSION_MINOR << 8 | MESHGEMS_VERSION_PATCH)
+
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/serialization/set.hpp>
+#include <boost/serialization/vector.hpp>
+#include <boost/serialization/string.hpp>
+
 namespace
 {
   struct GET_DEFAULT // struct used to get default value from GetOptionValue()
@@ -49,8 +62,8 @@ namespace
 }
 
 //=============================================================================
-BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen) :
-  SMESH_Hypothesis(hypId, studyId, gen), 
+BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, SMESH_Gen * gen, bool hasgeom) :
+  SMESH_Hypothesis(hypId, gen),
   _physicalMesh(GetDefaultPhysicalMesh()),
   _geometricMesh(GetDefaultGeometricMesh()),
   _phySize(GetDefaultPhySize()),
@@ -63,9 +76,9 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _gradation(GetDefaultGradation()),
   _useVolumeGradation(GetDefaultUseVolumeGradation()),
   _volumeGradation(GetDefaultVolumeGradation()),
-  _quadAllowed(GetDefaultQuadAllowed()),
+  _elementType(GetDefaultElementType()),
   _angleMesh(GetDefaultAngleMesh()),
-  _chordalError(GetDefaultChordalError()), 
+  _chordalError(GetDefaultChordalError()),
   _anisotropic(GetDefaultAnisotropic()),
   _anisotropicRatio(GetDefaultAnisotropicRatio()),
   _removeTinyEdges(GetDefaultRemoveTinyEdges()),
@@ -80,8 +93,13 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _quadraticMesh(GetDefaultQuadraticMesh()),
   _verb(GetDefaultVerbosity()),
   _topology(GetDefaultTopology()),
+  _useSurfaceProximity(GetDefaultUseSurfaceProximity()),
+  _nbSurfaceProximityLayers(GetDefaultNbSurfaceProximityLayers()),
+  _surfaceProximityRatio(GetDefaultSurfaceProximityRatio()),
+  _useVolumeProximity(GetDefaultUseVolumeProximity()),
+  _nbVolumeProximityLayers(GetDefaultNbVolumeProximityLayers()),
+  _volumeProximityRatio(GetDefaultVolumeProximityRatio()),
   _preCADMergeEdges(GetDefaultPreCADMergeEdges()),
-  _preCADRemoveTinyUVEdges(GetDefaultPreCADRemoveTinyUVEdges()),
   _preCADRemoveDuplicateCADFaces(GetDefaultPreCADRemoveDuplicateCADFaces()),
   _preCADProcess3DTopology(GetDefaultPreCADProcess3DTopology()),
   _preCADDiscardInput(GetDefaultPreCADDiscardInput()),
@@ -100,39 +118,41 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()),
   _GMFFileName(GetDefaultGMFFile())
 {
-  _name = GetHypType();
+  _name = GetHypType(hasgeom);
   _param_algo_dim = 2;
-  
-//   _GMFFileMode = false; // GMF ascii mode
 
   // Advanced options with their defaults according to MG User Manual
 
-  const char* boolOptionNames[] = {         "enforce_cad_edge_sizes",                   // default = 0
-                                            // "correct_surface_intersections",            // default = 1
-                                            // "create_tag_on_collision",                  // default = 1
-                                            "jacobian_rectification_respect_geometry",  // default = 1
-                                            "rectify_jacobian",                         // default = 1
-                                            "respect_geometry",                         // default = 1
-                                            // "optimise_tiny_edges",                      // default = 0
-                                            // "remove_duplicate_cad_faces",               // default = 1
-                                            "tiny_edge_avoid_surface_intersections",    // default = 1
-                                            // "tiny_edge_respect_geometry",               // default = 0
-                                            "" // mark of end
-      };
+  const char* boolOptionNames[] = {
+#if MESHGEMS_VERSION_HEX < 0x020A00
+    "enforce_cad_edge_sizes",                   // default = 0 // Deprecated since MeshGems 2.10
+#endif
+    "jacobian_rectification_respect_geometry",  // default = 1
+    "rectify_jacobian",                         // default = 1
+    "respect_geometry",                         // default = 1
+    "tiny_edge_avoid_surface_intersections",    // default = 1
+    "debug",                                    // default = 0
+    "allow_patch_independent",                   // false
+    "" // mark of end
+  };
 
-  const char* intOptionNames[] = {          "max_number_of_points_per_patch",           // default = 100000
-                                            "" // mark of end
-      };
+  const char* intOptionNames[] = {
+#if MESHGEMS_VERSION_HEX < 0x020A00
+    "max_number_of_points_per_patch",           // default = 100000 // Deprecated since MeshGems 2.10
+#endif
+    "max_number_of_threads",                    // default = 4
+    "" // mark of end
+  };
   const char* doubleOptionNames[] = {       // "surface_intersections_processing_max_cost",// default = 15
                                             // "periodic_tolerance",                       // default = diag/100
                                             // "volume_gradation",
                                             // "tiny_edge_optimisation_length",            // default = diag * 1e-6
-                                            "" // mark of end
-      };
+    "" // mark of end
+  };
   const char* charOptionNames[] = {         // "required_entities",                        // default = "respect"
                                             // "tags",                                     // default = "respect"
-                                            "" // mark of end
-      };
+    "" // mark of end
+  };
 
   // PreCAD advanced options
   const char* preCADboolOptionNames[] = {   "closed_geometry",                          // default = 0
@@ -140,9 +160,12 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
                                             "merge_edges",                              // default =  = 1
                                             "remove_duplicate_cad_faces",               // default = 1
                                             // "create_tag_on_collision",                  // default = 1
-                                            "debug",                                    // default = 0 
                                             "process_3d_topology",                      // default = 1
                                             // "remove_tiny_edges",                        // default = 0
+                                            // remove_tiny_uv_edges option is not documented
+                                            // but it is useful that the user can change it to disable all preprocessing options
+                                            "remove_tiny_uv_edges",                        // default = 1
+                                            "compute_ridges",                             // true
                                             "" // mark of end
       };
   const char* preCADintOptionNames[] = {    // "manifold_geometry",                        // default = 0
@@ -165,7 +188,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
     _option2value[boolOptionNames[i++]].clear();
   }
   i = 0;
-  while (preCADboolOptionNames[i][0])
+  while (preCADboolOptionNames[i][0] && hasgeom)
   {
     _boolOptions.insert( preCADboolOptionNames[i] );
     _preCADoption2value[preCADboolOptionNames[i++]].clear();
@@ -175,7 +198,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
     _option2value[intOptionNames[i++]].clear();
   
   i = 0;
-  while (preCADintOptionNames[i][0])
+  while (preCADintOptionNames[i][0] && hasgeom)
     _preCADoption2value[preCADintOptionNames[i++]].clear();
 
   i = 0;
@@ -184,7 +207,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
     _option2value[doubleOptionNames[i++]].clear();
   }
   i = 0;
-  while (preCADdoubleOptionNames[i][0]) {
+  while (preCADdoubleOptionNames[i][0] && hasgeom) {
     _preCADdoubleOptions.insert(preCADdoubleOptionNames[i]);
     _preCADoption2value[preCADdoubleOptionNames[i++]].clear();
   }
@@ -194,29 +217,49 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
     _option2value[charOptionNames[i++]].clear();
   }
   i = 0;
-  while (preCADcharOptionNames[i][0]) {
+  while (preCADcharOptionNames[i][0] && hasgeom) {
     _preCADcharOptions.insert(preCADcharOptionNames[i]);
     _preCADoption2value[preCADcharOptionNames[i++]].clear();
   }
 
   // default values to be used while MG meshing
 
-  _defaultOptionValues["enforce_cad_edge_sizes"                 ] = "no";
+#if MESHGEMS_VERSION_HEX < 0x020A00
+  _defaultOptionValues["enforce_cad_edge_sizes"                 ] = "no";  // Deprecated since MeshGems 2.10
+#endif
   _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
-  _defaultOptionValues["max_number_of_points_per_patch"         ] = "0";
+#if MESHGEMS_VERSION_HEX < 0x020A00
+  _defaultOptionValues["max_number_of_points_per_patch"         ] = "0";   // Deprecated since MeshGems 2.10
+#endif
+  _defaultOptionValues["max_number_of_threads"                  ] = "4";
   _defaultOptionValues["rectify_jacobian"                       ] = "yes";
   _defaultOptionValues["respect_geometry"                       ] = "yes";
   _defaultOptionValues["tiny_edge_avoid_surface_intersections"  ] = "yes";
-  _defaultOptionValues["process_3d_topology"                    ] = "no";
-  _defaultOptionValues["closed_geometry"                        ] = "no";
+  //_defaultOptionValues["use_deprecated_patch_mesher"          ] = "no";
   _defaultOptionValues["debug"                                  ] = "no";
-  _defaultOptionValues["discard_input_topology"                 ] = "no";
-  _defaultOptionValues["merge_edges"                            ] = "no";
-  _defaultOptionValues["periodic_tolerance"                     ] = "1e-5*D";
-  _defaultOptionValues["remove_duplicate_cad_faces"             ] = "no";
-  _defaultOptionValues["required_entities"                      ] = "respect";
-  _defaultOptionValues["sewing_tolerance"                       ] = "5e-4*D";
-  _defaultOptionValues["tags"                                   ] = "respect";
+  _defaultOptionValues["allow_patch_independent"                ] = "no";
+  if ( hasgeom )
+  {
+    _defaultOptionValues["closed_geometry"                        ] = "no";
+    _defaultOptionValues["discard_input_topology"                 ] = "no";
+    _defaultOptionValues["merge_edges"                            ] = "no";
+    _defaultOptionValues["periodic_tolerance"                     ] = "1e-5*D";
+    _defaultOptionValues["process_3d_topology"                    ] = "no";
+    _defaultOptionValues["remove_duplicate_cad_faces"             ] = "no";
+    _defaultOptionValues["remove_tiny_uv_edges"                   ] = "no";
+    _defaultOptionValues["required_entities"                      ] = "respect";
+    _defaultOptionValues["sewing_tolerance"                       ] = "5e-4*D";
+    _defaultOptionValues["tags"                                   ] = "respect";
+    _defaultOptionValues["compute_ridges"                         ] = "yes";
+  }
+
+  if ( MESHGEMS_VERSION_HEX < 0x020906 )
+  {
+    std::string missingOption = "allow_patch_independent";
+    _defaultOptionValues.erase( missingOption );
+    _boolOptions.erase( missingOption );
+    _option2value.erase( missingOption );
+  }
 
 #ifdef _DEBUG_
   // check validity of option names of _defaultOptionValues
@@ -225,44 +268,34 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
     ASSERT( _option2value.count( n2v->first ) || _preCADoption2value.count( n2v->first ));
   ASSERT( _option2value.size() + _preCADoption2value.size() == _defaultOptionValues.size() );
 #endif
-      
-  _sizeMap.clear();
-  _attractors.clear();
-  _faceEntryEnfVertexListMap.clear();
-  _enfVertexList.clear();
-  _faceEntryCoordsListMap.clear();
-  _coordsEnfVertexMap.clear();
-  _faceEntryEnfVertexEntryListMap.clear();
-  _enfVertexEntryEnfVertexMap.clear();
-  _groupNameNodeIDMap.clear();
 
-  /* TODO GROUPS
-   _groupNameEnfVertexListMap.clear();
-   _enfVertexGroupNameMap.clear();
-   */
 }
 
 TopoDS_Shape BLSURFPlugin_Hypothesis::entryToShape(std::string entry)
 {
-  MESSAGE("BLSURFPlugin_Hypothesis::entryToShape "<<entry );
   GEOM::GEOM_Object_var aGeomObj;
-  SMESH_Gen_i* smeshGen_i = SMESH_Gen_i::GetSMESHGen();
-  SALOMEDS::Study_ptr myStudy = smeshGen_i->GetCurrentStudy();
   
   TopoDS_Shape S = TopoDS_Shape();
-  SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() );
+  SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( entry.c_str() );
   if (!aSObj->_is_nil() ) {
     CORBA::Object_var obj = aSObj->GetObject();
     aGeomObj = GEOM::GEOM_Object::_narrow(obj);
     aSObj->UnRegister();
   }
   if ( !aGeomObj->_is_nil() )
-    S = smeshGen_i->GeomObjectToShape( aGeomObj.in() );
+    S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() );
   return S;
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
+std::string BLSURFPlugin_Hypothesis::GetMeshGemsVersion()
+{
+  return MESHGEMS_VERSION_LONG;
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh)
+{
   if (thePhysicalMesh != _physicalMesh) {
     _physicalMesh = thePhysicalMesh;
     NotifySubMeshesHypothesisModification();
@@ -270,7 +303,8 @@ void BLSURFPlugin_Hypothesis::SetPhysicalMesh(PhysicalMesh thePhysicalMesh) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
+void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh)
+{
   if (theGeometricMesh != _geometricMesh) {
     _geometricMesh = theGeometricMesh;
 //     switch (_geometricMesh) {
@@ -285,12 +319,12 @@ void BLSURFPlugin_Hypothesis::SetGeometricMesh(GeometricMesh theGeometricMesh) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
+void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative)
+{
   if ((theVal != _phySize) || (isRelative != _phySizeRel)) {
     _phySizeRel = isRelative;
     if (theVal == 0) {
       _phySize = GetMaxSize();
-      MESSAGE("Warning: nul physical size is not allowed");
     }
     else
       _phySize = theVal;
@@ -299,7 +333,8 @@ void BLSURFPlugin_Hypothesis::SetPhySize(double theVal, bool isRelative) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
+void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative)
+{
   if ((theMinSize != _minSize) || (isRelative != _minSizeRel)) {
     _minSizeRel = isRelative;
     _minSize = theMinSize;
@@ -308,7 +343,8 @@ void BLSURFPlugin_Hypothesis::SetMinSize(double theMinSize, bool isRelative) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
+void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative)
+{
   if ((theMaxSize != _maxSize) || (isRelative != _maxSizeRel)) {
     _maxSizeRel = isRelative;
     _maxSize = theMaxSize;
@@ -317,7 +353,8 @@ void BLSURFPlugin_Hypothesis::SetMaxSize(double theMaxSize, bool isRelative) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal)
+{
   if (theVal != _useGradation) {
     _useGradation = theVal;
     NotifySubMeshesHypothesisModification();
@@ -325,7 +362,8 @@ void BLSURFPlugin_Hypothesis::SetUseGradation(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
+void BLSURFPlugin_Hypothesis::SetGradation(double theVal)
+{
   _useGradation = ( theVal > 0 );
   if (theVal != _gradation) {
     _gradation = theVal;
@@ -334,7 +372,8 @@ void BLSURFPlugin_Hypothesis::SetGradation(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal)
+{
   if (theVal != _useVolumeGradation) {
     _useVolumeGradation = theVal;
     NotifySubMeshesHypothesisModification();
@@ -342,7 +381,8 @@ void BLSURFPlugin_Hypothesis::SetUseVolumeGradation(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
+void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal)
+{
   _useVolumeGradation = ( theVal > 0 );
   if (theVal != _volumeGradation) {
     _volumeGradation = theVal;
@@ -351,15 +391,17 @@ void BLSURFPlugin_Hypothesis::SetVolumeGradation(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetQuadAllowed(bool theVal) {
-  if (theVal != _quadAllowed) {
-    _quadAllowed = theVal;
+void BLSURFPlugin_Hypothesis::SetElementType(ElementType theElementType)
+{
+  if (theElementType != _elementType) {
+    _elementType = theElementType;
     NotifySubMeshesHypothesisModification();
   }
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
+void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal)
+{
   if (theVal != _angleMesh) {
     _angleMesh = theVal;
     NotifySubMeshesHypothesisModification();
@@ -367,7 +409,8 @@ void BLSURFPlugin_Hypothesis::SetAngleMesh(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
+void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance)
+{
   if (theDistance != _chordalError) {
     _chordalError = theDistance;
     NotifySubMeshesHypothesisModification();
@@ -375,7 +418,8 @@ void BLSURFPlugin_Hypothesis::SetChordalError(double theDistance) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal)
+{
   if (theVal != _anisotropic) {
     _anisotropic = theVal;
     NotifySubMeshesHypothesisModification();
@@ -383,7 +427,8 @@ void BLSURFPlugin_Hypothesis::SetAnisotropic(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
+void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal)
+{
   if (theVal != _anisotropicRatio) {
     _anisotropicRatio = theVal;
     NotifySubMeshesHypothesisModification();
@@ -391,7 +436,8 @@ void BLSURFPlugin_Hypothesis::SetAnisotropicRatio(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal)
+{
   if (theVal != _removeTinyEdges) {
     _removeTinyEdges = theVal;
     NotifySubMeshesHypothesisModification();
@@ -399,7 +445,8 @@ void BLSURFPlugin_Hypothesis::SetRemoveTinyEdges(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
+void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal)
+{
   if (theVal != _tinyEdgeLength) {
     _tinyEdgeLength = theVal;
     NotifySubMeshesHypothesisModification();
@@ -407,7 +454,8 @@ void BLSURFPlugin_Hypothesis::SetTinyEdgeLength(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal)
+{
   if (theVal != _optimiseTinyEdges) {
     _optimiseTinyEdges = theVal;
     NotifySubMeshesHypothesisModification();
@@ -415,7 +463,8 @@ void BLSURFPlugin_Hypothesis::SetOptimiseTinyEdges(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
+void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal)
+{
   if (theVal != _tinyEdgeOptimisationLength) {
     _tinyEdgeOptimisationLength = theVal;
     NotifySubMeshesHypothesisModification();
@@ -423,7 +472,8 @@ void BLSURFPlugin_Hypothesis::SetTinyEdgeOptimisationLength(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal)
+{
   if (theVal != _correctSurfaceIntersec) {
     _correctSurfaceIntersec = theVal;
     NotifySubMeshesHypothesisModification();
@@ -431,7 +481,8 @@ void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersection(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal) {
+void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal)
+{
   if (theVal != _corrSurfaceIntersCost) {
     _corrSurfaceIntersCost = theVal;
     NotifySubMeshesHypothesisModification();
@@ -439,7 +490,8 @@ void BLSURFPlugin_Hypothesis::SetCorrectSurfaceIntersectionMaxCost(double theVal
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal)
+{
   if (theVal != _badElementRemoval) {
     _badElementRemoval = theVal;
     NotifySubMeshesHypothesisModification();
@@ -447,7 +499,8 @@ void BLSURFPlugin_Hypothesis::SetBadElementRemoval(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
+void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal)
+{
   if (theVal != _badElementAspectRatio) {
     _badElementAspectRatio = theVal;
     NotifySubMeshesHypothesisModification();
@@ -455,7 +508,8 @@ void BLSURFPlugin_Hypothesis::SetBadElementAspectRatio(double theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal)
+{
   if (theVal != _optimizeMesh) {
     _optimizeMesh = theVal;
     NotifySubMeshesHypothesisModification();
@@ -463,7 +517,8 @@ void BLSURFPlugin_Hypothesis::SetOptimizeMesh(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
+void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal)
+{
   if (theVal != _quadraticMesh) {
     _quadraticMesh = theVal;
     NotifySubMeshesHypothesisModification();
@@ -471,13 +526,74 @@ void BLSURFPlugin_Hypothesis::SetQuadraticMesh(bool theVal) {
 }
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology) {
+void BLSURFPlugin_Hypothesis::SetTopology(Topology theTopology)
+{
   if (theTopology != _topology) {
     _topology = theTopology;
     NotifySubMeshesHypothesisModification();
   }
 }
 
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetUseSurfaceProximity( bool toUse )
+{
+  if ( _useSurfaceProximity != toUse )
+  {
+    _useSurfaceProximity = toUse;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetNbSurfaceProximityLayers( int nbLayers )
+{
+  if ( _nbSurfaceProximityLayers != nbLayers )
+  {
+    _nbSurfaceProximityLayers = nbLayers;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetSurfaceProximityRatio( double ratio )
+{
+  if ( _surfaceProximityRatio != ratio )
+  {
+    _surfaceProximityRatio = ratio;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetUseVolumeProximity( bool toUse )
+{
+  if ( _useVolumeProximity != toUse )
+  {
+    _useVolumeProximity = toUse;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetNbVolumeProximityLayers( int nbLayers )
+{
+  if ( _nbVolumeProximityLayers != nbLayers )
+  {
+    _nbVolumeProximityLayers = nbLayers;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetVolumeProximityRatio( double ratio )
+{
+  if ( _volumeProximityRatio != ratio )
+  {
+    _volumeProximityRatio = ratio;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
 //=============================================================================
 void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
   if (theVal != _verb) {
@@ -489,16 +605,26 @@ void BLSURFPlugin_Hypothesis::SetVerbosity(int theVal) {
 //=============================================================================
 void BLSURFPlugin_Hypothesis::SetEnforceCadEdgesSize( bool toEnforce )
 {
+#if MESHGEMS_VERSION_HEX < 0x020A00
+  // Deprecated since MeshGems 2.10
   if ( GetEnforceCadEdgesSize() != toEnforce )
   {
     SetOptionValue( "enforce_cad_edge_sizes", toEnforce ? "yes" : "no" );
     NotifySubMeshesHypothesisModification();
   }
+#else
+  (void)toEnforce; // maybe unused
+#endif
 }
 //=============================================================================
 bool BLSURFPlugin_Hypothesis::GetEnforceCadEdgesSize()
 {
+#if MESHGEMS_VERSION_HEX < 0x020A00
+  // Deprecated since MeshGems 2.10
   return ToBool( GetOptionValue( "enforce_cad_edge_sizes" ), GET_DEFAULT() );
+#else
+  return false;
+#endif
 }
 //=============================================================================
 
@@ -532,9 +658,25 @@ bool BLSURFPlugin_Hypothesis::GetJacobianRectification()
 }
 //=============================================================================
 
+void BLSURFPlugin_Hypothesis::SetUseDeprecatedPatchMesher( bool /*useDeprecatedPatchMesher*/ )
+{
+  // if ( GetUseDeprecatedPatchMesher() != useDeprecatedPatchMesher )
+  // {
+  //   SetOptionValue( "use_deprecated_patch_mesher", useDeprecatedPatchMesher ? "yes" : "no" );
+  //   NotifySubMeshesHypothesisModification();
+  // }
+}
+//=============================================================================
+bool BLSURFPlugin_Hypothesis::GetUseDeprecatedPatchMesher()
+{
+  return false;//ToBool( GetOptionValue("use_deprecated_patch_mesher", GET_DEFAULT()));
+}
+//=============================================================================
+
 void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
-  throw (std::invalid_argument)
 {
+#if MESHGEMS_VERSION_HEX < 0x020A00
+  // Deprecated since MeshGems 2.10
   if ( nb < 0 )
     throw std::invalid_argument( SMESH_Comment("Invalid number of points: ") << nb );
 
@@ -543,11 +685,37 @@ void BLSURFPlugin_Hypothesis::SetMaxNumberOfPointsPerPatch( int nb )
     SetOptionValue("max_number_of_points_per_patch", SMESH_Comment( nb ));
     NotifySubMeshesHypothesisModification();
   }
+#else
+  (void)nb; // maybe unused
+#endif
 }
 //=============================================================================
 int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
 {
+#if MESHGEMS_VERSION_HEX < 0x020A00
+  // Deprecated since MeshGems 2.10
   return ToInt( GetOptionValue("max_number_of_points_per_patch", GET_DEFAULT()));
+#else
+  return 0;
+#endif
+}
+//=============================================================================
+
+void BLSURFPlugin_Hypothesis::SetMaxNumberOfThreads( int nb )
+{
+  if ( nb < 0 )
+    throw std::invalid_argument( SMESH_Comment("Invalid number of threads: ") << nb );
+
+  if ( GetMaxNumberOfThreads() != nb )
+  {
+    SetOptionValue("max_number_of_threads", SMESH_Comment( nb ));
+    NotifySubMeshesHypothesisModification();
+  }
+}
+//=============================================================================
+int BLSURFPlugin_Hypothesis::GetMaxNumberOfThreads()
+{
+  return ToInt( GetOptionValue("max_number_of_threads", GET_DEFAULT()));
 }
 //=============================================================================
 
@@ -612,7 +780,6 @@ bool BLSURFPlugin_Hypothesis::GetDebug()
 //=============================================================================
 
 void BLSURFPlugin_Hypothesis::SetPeriodicTolerance( CORBA::Double tol )
-  throw (std::invalid_argument)
 {
   if ( tol <= 0 )
     throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
@@ -630,7 +797,6 @@ double BLSURFPlugin_Hypothesis::GetPeriodicTolerance()
 //=============================================================================
 
 void BLSURFPlugin_Hypothesis::SetRequiredEntities( const std::string& howToTreat )
-  throw (std::invalid_argument)
 {
   if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear"  )
     throw std::invalid_argument
@@ -650,7 +816,6 @@ std::string BLSURFPlugin_Hypothesis::GetRequiredEntities()
 //=============================================================================
 
 void BLSURFPlugin_Hypothesis::SetSewingTolerance( CORBA::Double tol )
-  throw (std::invalid_argument)
 {
   if ( tol <= 0 )
     throw std::invalid_argument( SMESH_Comment("Invalid tolerance: ") << tol );
@@ -668,7 +833,6 @@ CORBA::Double BLSURFPlugin_Hypothesis::GetSewingTolerance()
 //=============================================================================
 
 void BLSURFPlugin_Hypothesis::SetTags( const std::string& howToTreat )
-  throw (std::invalid_argument)
 {
   if ( howToTreat != "respect" && howToTreat != "ignore" && howToTreat != "clear"  )
     throw std::invalid_argument
@@ -685,21 +849,198 @@ std::string BLSURFPlugin_Hypothesis::GetTags()
 {
   return GetPreCADOptionValue("tags", GET_DEFAULT());
 }
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchList& hpl, bool notifyMesh)
+{
+  if ( hpl != _hyperPatchList )
+  {
+    // join patches sharing tags
+    _hyperPatchList.clear();
+    for ( size_t i = 0; i < hpl.size(); ++i )
+    {
+      const THyperPatchTags& tags = hpl[i];
+      if ( tags.size() < 2 ) continue;
+
+      std::set<int> iPatches;
+      if ( !_hyperPatchList.empty() )
+      {
+        THyperPatchTags::iterator t = tags.begin();
+        for ( ; t != tags.end(); ++t )
+        {
+          int iPatch = -1;
+          GetHyperPatchTag( *t, this, &iPatch );
+          if ( iPatch >= 0 )
+            iPatches.insert( iPatch );
+        }
+      }
+
+      if ( iPatches.empty() )
+      {
+        _hyperPatchList.push_back( tags );
+      }
+      else
+      {
+        std::set<int>::iterator iPatch = iPatches.begin();
+        THyperPatchTags&     mainPatch = _hyperPatchList[ *iPatch ];
+        mainPatch.insert( tags.begin(), tags.end() );
+
+        for ( ++iPatch; iPatch != iPatches.end(); ++iPatch )
+        {
+          mainPatch.insert( _hyperPatchList[ *iPatch ].begin(), _hyperPatchList[ *iPatch ].end() );
+          _hyperPatchList[ *iPatch ].clear();
+        }
+        if ( iPatches.size() > 1 )
+          for ( int j = (int) _hyperPatchList.size()-1; j > 0; --j )
+            if ( _hyperPatchList[j].empty() )
+              _hyperPatchList.erase( _hyperPatchList.begin() + j );
+      }
+    }
+    if ( notifyMesh )
+      NotifySubMeshesHypothesisModification();
+  }
+}
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
+void BLSURFPlugin_Hypothesis::SetHyperPatches(const THyperPatchEntriesList& hpel)
 {
-  if (theVal != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
-    _preCADMergeEdges = theVal;
-    SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
+  if ( hpel != _hyperPatchEntriesList )
+  {
+    _hyperPatchEntriesList = hpel;
+    _hyperPatchList.clear();
+
     NotifySubMeshesHypothesisModification();
   }
 }
+//================================================================================
+/*!
+ * \brief Set _hyperPatchList by _hyperPatchEntriesList
+ */
+//================================================================================
+
+void BLSURFPlugin_Hypothesis::
+SetHyperPatchIDsByEntry( const TopoDS_Shape&                          mainShape,
+                         const std::map< std::string, TopoDS_Shape >& entryToShape)
+{
+  _hyperPatchList.clear();
+  if ( _hyperPatchEntriesList.empty() || mainShape.IsNull() )
+    return;
+
+  _hyperPatchList.resize( _hyperPatchEntriesList.size() );
+
+  TopTools_IndexedMapOfShape shapeMap;
+  TopExp::MapShapes( mainShape, shapeMap );
+
+  for ( size_t i = 0; i < _hyperPatchEntriesList.size(); ++i )
+  {
+    THyperPatchTags &            idsList = _hyperPatchList       [ i ];
+    const THyperPatchEntries & entryList = _hyperPatchEntriesList[ i ];
+    for ( const std::string & entry : entryList )
+    {
+      auto e2sIt = entryToShape.find( entry );
+      if ( e2sIt != entryToShape.end() )
+      {
+        for ( TopExp_Explorer fExp( e2sIt->second, TopAbs_FACE ); fExp.More(); fExp.Next() )
+        {
+          int id = shapeMap.FindIndex( fExp.Current() );
+          if ( id > 0 )
+            idsList.insert( id );
+        }
+      }
+    }
+  }
+  THyperPatchList hpl;
+  hpl.swap( _hyperPatchList );
+  SetHyperPatches( hpl, /*notifyMesh=*/false );
+}
+
+//=============================================================================
+/*!
+ * \brief Return a tag of a face taking into account the hyper-patches. Optionally
+ *        return an index of a patch including the face
+ */
+//================================================================================
+
+int BLSURFPlugin_Hypothesis::GetHyperPatchTag( const int                      faceTag,
+                                               const BLSURFPlugin_Hypothesis* hyp,
+                                               int*                           iPatch)
+{
+  if ( hyp )
+  {
+    const THyperPatchList& hpl = hyp->_hyperPatchList;
+    for ( size_t i = 0; i < hpl.size(); ++i )
+      if ( hpl[i].count( faceTag ))
+      {
+        if ( iPatch ) *iPatch = (int) i;
+        return *( hpl[i].begin() );
+      }
+  }
+  return faceTag;
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::SetEnforcedMeshes( std::vector< EnforcedMesh > & enforcedMeshes )
+{
+  if ( _enforcedMeshes != enforcedMeshes )
+  {
+    _enforcedMeshes.swap( enforcedMeshes );
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//================================================================================
+/*!
+ * \brief Return elements of 1D enforced mesh. Result can be NULL
+ */
+//================================================================================
+
+SMDS_ElemIteratorPtr
+BLSURFPlugin_Hypothesis::GetEnforcedSegments( const EnforcedMesh& enfMesh,
+                                              SMESH_Mesh* &       mesh ) const
+{
+  SMDS_ElemIteratorPtr it;
+  if (( mesh = SMESH_Hypothesis::GetMeshByPersistentID( enfMesh._meshID )))
+  {
+    mesh->Load();
+    if ( mesh->NbEdges() == 0 )
+      GetGen()->Compute( *mesh, mesh->GetShapeToMesh(), /*flags=*/0 );
+
+    switch( enfMesh._type )
+    {
+    case ENFORCED_MESH:
+      it = mesh->GetMeshDS()->elementsIterator( SMDSAbs_Edge );
+      break;
+
+    case ENFORCED_GROUP:
+      if ( SMESH_Group* grp = mesh->GetGroup( enfMesh._subID ))
+      {
+        if ( grp->GetGroupDS()->GetType() == SMDSAbs_Edge )
+          it = grp->GetGroupDS()->GetElements();
+      }
+      break;
+
+    case ENFORCED_SUBMESH:
+      if ( SMESH_subMesh* sm = mesh->GetSubMeshContaining( enfMesh._subID ))
+        if ( SMESHDS_SubMesh * smDS = sm->GetSubMeshDS() )
+        {
+          it = smDS->GetElements();
+          if ( it->more() && it->next()->GetType() != SMDSAbs_Edge )
+            it = SMDS_ElemIteratorPtr();
+          else
+            it = smDS->GetElements();
+        }
+      break;
+    }
+  }
+  return it;
+}
+
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetPreCADRemoveTinyUVEdges(bool theVal)
+void BLSURFPlugin_Hypothesis::SetPreCADMergeEdges(bool theVal)
 {
-  if (theVal != _preCADRemoveTinyUVEdges) {
-    _preCADRemoveTinyUVEdges = theVal;
+  if (theVal != ToBool( GetPreCADOptionValue("merge_edges", GET_DEFAULT()))) {
+    _preCADMergeEdges = theVal;
+    SetPreCADOptionValue("merge_edges", theVal ? "yes" : "no" );
     NotifySubMeshesHypothesisModification();
   }
 }
@@ -738,7 +1079,7 @@ void BLSURFPlugin_Hypothesis::SetPreCADDiscardInput(bool theVal)
 // Return true if any PreCAD option is activated
 bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hyp)
 {
-  if ( !hyp )
+  if ( !hyp || hyp->_name == GetHypType(/*hasgeom=*/false))
   {
     return false;
   }
@@ -749,7 +1090,14 @@ bool BLSURFPlugin_Hypothesis::HasPreCADOptions(const BLSURFPlugin_Hypothesis* hy
            ToBool( hyp->GetPreCADOptionValue("remove_duplicate_cad_faces", &orDefault )) ||
            ToBool( hyp->GetPreCADOptionValue("process_3d_topology"       , &orDefault )) ||
            ToBool( hyp->GetPreCADOption     ("manifold_geometry")        , &isOk       ) ||
-           hyp->GetPreCADOptionValue("sewing_tolerance") != "5e-4*D" );
+           hyp->GetPreCADOptionValue("sewing_tolerance", &orDefault ) != "5e-4*D"        ||
+           !hyp->_preCadFacesPeriodicityVector.empty()                                   ||
+           !hyp->_preCadEdgesPeriodicityVector.empty()                                   ||
+           !hyp->_facesPeriodicityVector.empty()                                         ||
+           !hyp->_edgesPeriodicityVector.empty()                                         ||
+           !hyp->_verticesPeriodicityVector.empty()                                      ||
+           !hyp->GetHyperPatches().empty()                                               ||
+           hyp->GetTopology() != FromCAD );
 }
 
 //=============================================================================
@@ -763,8 +1111,7 @@ void BLSURFPlugin_Hypothesis::SetGMFFile(const std::string& theFileName)
 
 //=============================================================================
 void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, const std::string& optionValue)
-  throw (std::invalid_argument) {
-
+{
   TOptionValues::iterator op_val = _option2value.find(optionName);
   if (op_val == _option2value.end())
   {
@@ -781,7 +1128,7 @@ void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, cons
     // strip white spaces
     while (ptr[0] == ' ')
       ptr++;
-    int i = strlen(ptr);
+    size_t i = strlen(ptr);
     while (i != 0 && ptr[i - 1] == ' ')
       i--;
     // check value type
@@ -820,8 +1167,7 @@ void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, cons
 
 //=============================================================================
 void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName, const std::string& optionValue)
-  throw (std::invalid_argument) {
-
+{
   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
   if (op_val == _preCADoption2value.end()) {
     op_val = _option2value.find(optionName);
@@ -836,7 +1182,7 @@ void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName
     // strip white spaces
     while (ptr[0] == ' ')
       ptr++;
-    int i = strlen(ptr);
+    size_t i = strlen(ptr);
     while (i != 0 && ptr[i - 1] == ' ')
       i--;
     // check value type
@@ -880,7 +1226,6 @@ void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName
 //=============================================================================
 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName,
                                                     bool*              isDefault) const
-  throw (std::invalid_argument)
 {
   TOptionValues::const_iterator op_val = _option2value.find(optionName);
   if (op_val == _option2value.end())
@@ -911,7 +1256,6 @@ std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionNam
 //=============================================================================
 std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& optionName,
                                                           bool*              isDefault) const
-  throw (std::invalid_argument)
 {
   TOptionValues::const_iterator op_val = _preCADoption2value.find(optionName);
   if (op_val == _preCADoption2value.end())
@@ -933,7 +1277,7 @@ std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& opt
   if ( val.empty() && isDefault )
   {
     op_val = _defaultOptionValues.find( optionName );
-    if (op_val != _option2value.end())
+    if (op_val != _defaultOptionValues.end())
       val = op_val->second;
   }
   return val;
@@ -1222,7 +1566,6 @@ void BLSURFPlugin_Hypothesis::ClearEntry(const std::string& entry,
            ++it_clAt;
        }
        while ( it_clAt != _classAttractors.end() );
-       MESSAGE("_classAttractors.size() = "<<_classAttractors.size())
        NotifySubMeshesHypothesisModification();
      }
      else
@@ -1249,7 +1592,6 @@ void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
 //                                                        bool toEnforceInternalVertices,
 //                                                        TEnfGroupName theGroupName) {
 
-//  MESSAGE("BLSURFPlugin_Hypothesis::SetInternalEnforcedVertex("<< theFaceEntry << ", "
 //      << toEnforceInternalVertices << ", " << theGroupName << ")");
   
 //  TFaceEntryInternalVerticesList::iterator it = _faceEntryInternalVerticesList.find(theFaceEntry);
@@ -1272,15 +1614,14 @@ void BLSURFPlugin_Hypothesis::ClearSizeMaps() {
 //=======================================================================
 //function : SetEnforcedVertex
 //=======================================================================
-bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry,
-                                                TEnfGroupName theGroupName, double x, double y, double z) {
-
-  MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex("<< theFaceEntry << ", "
-      << x << ", " << y << ", " << z << ", " << theVertexName << ", " << theVertexEntry << ", " << theGroupName << ")");
-
+bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry        theFaceEntry,
+                                                TEnfName      theVertexName,
+                                                TEntry        theVertexEntry,
+                                                TEnfGroupName theGroupName,
+                                                double x, double y, double z)
+{
   SetPhysicalMesh(PhysicalLocalSize);
 
-  //  TEnfVertexList::iterator it;
   bool toNotify = false;
   bool toCreate = true;
 
@@ -1297,27 +1638,23 @@ bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName th
   newEnfVertex->grpName = theGroupName;
   newEnfVertex->faceEntries.clear();
   newEnfVertex->faceEntries.insert(theFaceEntry);
-  
-  
+
+
   // update _enfVertexList
   TEnfVertexList::iterator it = _enfVertexList.find(newEnfVertex);
   if (it != _enfVertexList.end()) {
     toCreate = false;
     oldEnVertex = (*it);
-    MESSAGE("Enforced Vertex was found => Update");
     if (oldEnVertex->name != theVertexName) {
-      MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theVertexName << "\"");
       oldEnVertex->name = theVertexName;
       toNotify = true;
     }
     if (oldEnVertex->grpName != theGroupName) {
-      MESSAGE("Update group name from \"" << oldEnVertex->grpName << "\" to \"" << theGroupName << "\"");
       oldEnVertex->grpName = theGroupName;
       toNotify = true;
     }
     TEntryList::iterator it_faceEntries = oldEnVertex->faceEntries.find(theFaceEntry);
     if (it_faceEntries == oldEnVertex->faceEntries.end()) {
-      MESSAGE("Update face list by adding \"" << theFaceEntry << "\"");
       oldEnVertex->faceEntries.insert(theFaceEntry);
       _faceEntryEnfVertexListMap[theFaceEntry].insert(oldEnVertex);
       toNotify = true;
@@ -1340,34 +1677,46 @@ bool BLSURFPlugin_Hypothesis::SetEnforcedVertex(TEntry theFaceEntry, TEnfName th
 //   //////// CREATE ////////////
   if (toCreate) {
     toNotify = true;
-    MESSAGE("Creating new enforced vertex");
-    _faceEntryEnfVertexListMap[theFaceEntry].insert(newEnfVertex);
-    _enfVertexList.insert(newEnfVertex);
-    if (theVertexEntry == "") {
-      _faceEntryCoordsListMap[theFaceEntry].insert(newEnfVertex->coords);
-      _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
-    }
-    else {
-      _faceEntryEnfVertexEntryListMap[theFaceEntry].insert(newEnfVertex->geomEntry);
-      _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
-    }
+    AddEnforcedVertex( theFaceEntry, newEnfVertex );
+  }
+  else {
+    delete newEnfVertex;
   }
 
   if (toNotify)
     NotifySubMeshesHypothesisModification();
 
-  MESSAGE("BLSURFPlugin_Hypothesis::SetEnforcedVertex END");
   return toNotify;
 }
 
+//=======================================================================
+//function : AddEnforcedVertex
+//=======================================================================
+
+void BLSURFPlugin_Hypothesis::AddEnforcedVertex( const TEntry& faceEntry,
+                                                 TEnfVertex *  newEnfVertex )
+{
+  if ( newEnfVertex )
+  {
+    _faceEntryEnfVertexListMap[faceEntry].insert(newEnfVertex);
+    _enfVertexList.insert(newEnfVertex);
+    if ( newEnfVertex->geomEntry.empty() ) {
+      _faceEntryCoordsListMap[faceEntry].insert(newEnfVertex->coords);
+      _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex;
+    }
+    else {
+      _faceEntryEnfVertexEntryListMap[faceEntry].insert(newEnfVertex->geomEntry);
+      _enfVertexEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex;
+    }
+  }
+}
 
 //=======================================================================
 //function : GetEnforcedVertices
 //=======================================================================
 
 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexList(const TEntry& theFaceEntry)
-    throw (std::invalid_argument) {
-
+{
   if (_faceEntryEnfVertexListMap.count(theFaceEntry) > 0)
     return _faceEntryEnfVertexListMap[theFaceEntry];
   else
@@ -1382,9 +1731,8 @@ BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetEnfVertexLis
 //function : GetEnfVertexCoordsList
 //=======================================================================
 
-BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(
-    const TEntry& theFaceEntry) throw (std::invalid_argument) {
-
+BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVertexCoordsList(const TEntry& theFaceEntry)
+{
   if (_faceEntryCoordsListMap.count(theFaceEntry) > 0)
     return _faceEntryCoordsListMap[theFaceEntry];
 
@@ -1398,8 +1746,7 @@ BLSURFPlugin_Hypothesis::TEnfVertexCoordsList BLSURFPlugin_Hypothesis::GetEnfVer
 //=======================================================================
 
 BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryList(const TEntry& theFaceEntry)
-    throw (std::invalid_argument) {
-
+{
   if (_faceEntryEnfVertexEntryListMap.count(theFaceEntry) > 0)
     return _faceEntryEnfVertexEntryListMap[theFaceEntry];
 
@@ -1413,8 +1760,7 @@ BLSURFPlugin_Hypothesis::TEntryList BLSURFPlugin_Hypothesis::GetEnfVertexEntryLi
 //=======================================================================
 
 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfVertexCoords coords)
-    throw (std::invalid_argument) {
-
+{
   if (_coordsEnfVertexMap.count(coords) > 0)
     return _coordsEnfVertexMap[coords];
 
@@ -1428,8 +1774,7 @@ BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(TEnfV
 //=======================================================================
 
 BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const TEntry& theEnfVertexEntry)
-    throw (std::invalid_argument) {
-
+{
   if (_enfVertexEntryEnfVertexMap.count(theEnfVertexEntry) > 0)
     return _enfVertexEntryEnfVertexMap[theEnfVertexEntry];
 
@@ -1454,9 +1799,10 @@ BLSURFPlugin_Hypothesis::TEnfVertex* BLSURFPlugin_Hypothesis::GetEnfVertex(const
 //function : ClearEnforcedVertex
 //=======================================================================
 
-bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, double x, double y, double z,
-    const TEntry& theVertexEntry) throw (std::invalid_argument) {
-
+bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry,
+                                                  double x, double y, double z,
+                                                  const TEntry& theVertexEntry)
+{
   bool toNotify = false;
   std::ostringstream msg;
   TEnfVertex *oldEnfVertex;
@@ -1470,7 +1816,6 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, do
   TEnfVertexEntryEnfVertexMap::iterator it_enfVertexEntry = _enfVertexEntryEnfVertexMap.find(theVertexEntry);
   if (it_enfVertexEntry != _enfVertexEntryEnfVertexMap.end()) {
     // Success
-    MESSAGE("Found enforced vertex with geom entry " << theVertexEntry);
     oldEnfVertex = it_enfVertexEntry->second;
 
     _enfVertexEntryEnfVertexMap.erase(it_enfVertexEntry);
@@ -1492,7 +1837,6 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, do
     TCoordsEnfVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords);
     if (it_coords_enf != _coordsEnfVertexMap.end()) {
       // Success
-      MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z);
       oldEnfVertex = it_coords_enf->second;
 
       _coordsEnfVertexMap.erase(it_coords_enf);
@@ -1515,8 +1859,6 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, do
     }
   }
 
-  MESSAGE("Remove enf vertex from _enfVertexList");
-
   // update _enfVertexList
   TEnfVertexList::iterator it = _enfVertexList.find(oldEnfVertex);
   if (it != _enfVertexList.end()) {
@@ -1525,7 +1867,6 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, do
       _enfVertexList.erase(it);
       toNotify = true;
     }
-    MESSAGE("Done");
   }
 
   // update _faceEntryEnfVertexListMap
@@ -1533,9 +1874,7 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, do
   currentEnfVertexList.erase(oldEnfVertex);
 
   if (currentEnfVertexList.size() == 0) {
-    MESSAGE("Remove _faceEntryEnfVertexListMap[" << theFaceEntry <<"]");
     _faceEntryEnfVertexListMap.erase(theFaceEntry);
-    MESSAGE("Done");
   }
 
   if (toNotify)
@@ -1548,8 +1887,8 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertex(const TEntry& theFaceEntry, do
 //function : ClearEnforcedVertices
 //=======================================================================
 
-bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry) throw (std::invalid_argument) {
-
+bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry)
+{
   bool toNotify = false;
   TEnfVertex *oldEnfVertex;
 
@@ -1570,7 +1909,6 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry)
           _enfVertexList.erase(it);
           toNotify = true;
         }
-        MESSAGE("Done");
       }
     }
     _faceEntryCoordsListMap.erase(it_entry_coords);
@@ -1594,7 +1932,6 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry)
           _enfVertexList.erase(it);
           toNotify = true;
         }
-        MESSAGE("Done");
       }
     }
     _faceEntryEnfVertexEntryListMap.erase(it_entry_entry);
@@ -1613,18 +1950,25 @@ bool BLSURFPlugin_Hypothesis::ClearEnforcedVertices(const TEntry& theFaceEntry)
 //=======================================================================
 //function : ClearAllEnforcedVertices
 //=======================================================================
-void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
+void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices()
+{
   _faceEntryEnfVertexListMap.clear();
-  _enfVertexList.clear();
   _faceEntryCoordsListMap.clear();
   _coordsEnfVertexMap.clear();
   _faceEntryEnfVertexEntryListMap.clear();
   _enfVertexEntryEnfVertexMap.clear();
+  
+  TEnfVertexList::iterator it_enfVertex = _enfVertexList.begin();
+  for ( ; it_enfVertex != _enfVertexList.end(); ++it_enfVertex )
+    delete *it_enfVertex;
+  _enfVertexList.clear();
+
 //  Enable internal enforced vertices on specific face if requested by user
 //  _faceEntryInternalVerticesList.clear();
   NotifySubMeshesHypothesisModification();
 }
 
+
 //================================================================================
 /*!
  * \brief Return the enforced vertices
@@ -1633,7 +1977,8 @@ void BLSURFPlugin_Hypothesis::ClearAllEnforcedVertices() {
 
 
 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexListMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByFace(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetAllEnforcedVerticesByFace() : GetDefaultFaceEntryEnfVertexListMap();
 }
 
@@ -1654,31 +1999,36 @@ BLSURFPlugin_Hypothesis::TEnfGroupName BLSURFPlugin_Hypothesis::GetInternalEnfor
 }
 
 BLSURFPlugin_Hypothesis::TEnfVertexList BLSURFPlugin_Hypothesis::GetAllEnforcedVertices(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetAllEnforcedVertices() : GetDefaultEnfVertexList();
 }
 
 BLSURFPlugin_Hypothesis::TFaceEntryCoordsListMap BLSURFPlugin_Hypothesis::GetAllCoordsByFace(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetAllCoordsByFace() : GetDefaultFaceEntryCoordsListMap();
 }
 
 BLSURFPlugin_Hypothesis::TCoordsEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByCoords(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetAllEnforcedVerticesByCoords() : GetDefaultCoordsEnfVertexMap();
 }
 
 BLSURFPlugin_Hypothesis::TFaceEntryEnfVertexEntryListMap BLSURFPlugin_Hypothesis::GetAllEnfVertexEntriesByFace(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetAllEnfVertexEntriesByFace() : GetDefaultFaceEntryEnfVertexEntryListMap();
 }
 
 BLSURFPlugin_Hypothesis::TEnfVertexEntryEnfVertexMap BLSURFPlugin_Hypothesis::GetAllEnforcedVerticesByEnfVertexEntry(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetAllEnforcedVerticesByEnfVertexEntry() : GetDefaultEnfVertexEntryEnfVertexMap();
 }
 
-std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName) throw (std::invalid_argument)
+std::set<smIdType> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGroupName)
 {
   TGroupNameNodeIDMap::const_iterator it = _groupNameNodeIDMap.find(theGroupName);
   if (it != _groupNameNodeIDMap.end()) {
@@ -1689,16 +2039,16 @@ std::set<int> BLSURFPlugin_Hypothesis::GetEnfVertexNodeIDs(TEnfGroupName theGrou
   throw std::invalid_argument(msg.str());
 }
 
-void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID)
+void BLSURFPlugin_Hypothesis::AddEnfVertexNodeID(TEnfGroupName theGroupName,smIdType theNodeID)
 {
   _groupNameNodeIDMap[theGroupName].insert(theNodeID);
 }
 
-void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,int theNodeID) throw (std::invalid_argument)
+void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,smIdType theNodeID)
 {
   TGroupNameNodeIDMap::iterator it = _groupNameNodeIDMap.find(theGroupName);
   if (it != _groupNameNodeIDMap.end()) {
-    std::set<int>::iterator IDit = it->second.find(theNodeID);
+    std::set<smIdType>::iterator IDit = it->second.find(theNodeID);
     if (IDit != it->second.end())
       it->second.erase(IDit);
     std::ostringstream msg;
@@ -1712,7 +2062,8 @@ void BLSURFPlugin_Hypothesis::RemoveEnfVertexNodeID(TEnfGroupName theGroupName,i
 
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices) {
+void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceInternalVertices)
+{
   if (toEnforceInternalVertices != _enforcedInternalVerticesAllFaces) {
     _enforcedInternalVerticesAllFaces = toEnforceInternalVertices;
     if (toEnforceInternalVertices)
@@ -1723,7 +2074,8 @@ void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFaces(bool toEnforceIn
 
 
 //=============================================================================
-void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName) {
+void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugin_Hypothesis::TEnfGroupName theGroupName)
+{
   if (std::string(theGroupName) != std::string(_enforcedInternalVerticesAllFacesGroup)) {
     _enforcedInternalVerticesAllFacesGroup = theGroupName;
     NotifySubMeshesHypothesisModification();
@@ -1732,38 +2084,44 @@ void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugi
 
 //=============================================================================
 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector();
 }
 
 //=============================================================================
 BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector();
 }
 
 //=============================================================================
 BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector(
-    const BLSURFPlugin_Hypothesis* hyp) {
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector();
 }
 
 //=============================================================================
 BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector(
-    const BLSURFPlugin_Hypothesis* hyp){
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector();
 }
 
 //=============================================================================
 BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector(
-    const BLSURFPlugin_Hypothesis* hyp){
+    const BLSURFPlugin_Hypothesis* hyp)
+{
   return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector();
 }
 
 //=======================================================================
 //function : ClearAllEnforcedVertices
 //=======================================================================
-void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
+void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors()
+{
   _preCadFacesPeriodicityVector.clear();
   _preCadEdgesPeriodicityVector.clear();
   NotifySubMeshesHypothesisModification();
@@ -1773,7 +2131,8 @@ void BLSURFPlugin_Hypothesis::ClearPreCadPeriodicityVectors() {
 //function : AddPreCadFacesPeriodicity
 //=======================================================================
 void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TEntry theFace2Entry,
-    std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
+                                                        std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries)
+{
 
   TPreCadPeriodicity preCadFacesPeriodicity;
   preCadFacesPeriodicity.shape1Entry = theFace1Entry;
@@ -1790,8 +2149,8 @@ void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry theFace1Entry, TE
 //function : AddPreCadEdgesPeriodicity
 //=======================================================================
 void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TEntry theEdge2Entry,
-    std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries) {
-
+    std::vector<std::string> &theSourceVerticesEntries, std::vector<std::string> &theTargetVerticesEntries)
+{
   TPreCadPeriodicity preCadEdgesPeriodicity;
   preCadEdgesPeriodicity.shape1Entry = theEdge1Entry;
   preCadEdgesPeriodicity.shape2Entry = theEdge2Entry;
@@ -1804,44 +2163,45 @@ void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry theEdge1Entry, TE
 }
 
 //=============================================================================
-std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
-   // We must keep at least the same number of arguments when increasing the SALOME version
-   // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
-   // parameter can be written several times to keep the old global number of parameters.
+std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save)
+{
+  // We must keep at least the same number of arguments when increasing the SALOME version
+  // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
+  // parameter can be written several times to keep the old global number of parameters.
+
+  // Treat old options which are now in the advanced options
+  TOptionValues::iterator op_val;
+  int _decimesh = -1;
+  int _preCADRemoveNanoEdges = -1;
+  double _preCADEpsNano = -1.0;
+  op_val = _option2value.find("respect_geometry");
+  if (op_val != _option2value.end()) {
+    std::string value = op_val->second;
+    if (!value.empty())
+      _decimesh = value.compare("1") == 0 ? 1 : 0;
+  }
+  op_val = _preCADoption2value.find("remove_tiny_edges");
+  if (op_val != _preCADoption2value.end()) {
+    std::string value = op_val->second;
+    if (!value.empty())
+      _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
+  }
+  op_val = _preCADoption2value.find("tiny_edge_length");
+  if (op_val != _preCADoption2value.end()) {
+    std::string value = op_val->second;
+    if (!value.empty())
+      _preCADEpsNano = strtod(value.c_str(), NULL);
+  }
 
-   // Treat old options which are now in the advanced options
-   TOptionValues::iterator op_val;
-   int _decimesh = -1;
-   int _preCADRemoveNanoEdges = -1;
-   double _preCADEpsNano = -1.0;
-   op_val = _option2value.find("respect_geometry");
-   if (op_val != _option2value.end()) {
-     std::string value = op_val->second;
-     if (!value.empty())
-       _decimesh = value.compare("1") == 0 ? 1 : 0;
-   }
-   op_val = _preCADoption2value.find("remove_tiny_edges");
-   if (op_val != _preCADoption2value.end()) {
-     std::string value = op_val->second;
-     if (!value.empty())
-       _preCADRemoveNanoEdges = value.compare("1") == 0 ? 1 : 0;
-   }
-   op_val = _preCADoption2value.find("tiny_edge_length");
-   if (op_val != _preCADoption2value.end()) {
-     std::string value = op_val->second;
-     if (!value.empty())
-       _preCADEpsNano = strtod(value.c_str(), NULL);
-   }
-   
   save << " " << (int) _topology << " " << (int) _physicalMesh << " " << (int) _geometricMesh << " " << _phySize << " "
-      << _angleMesh << " " << _gradation << " " << (int) _quadAllowed << " " << _decimesh;
+       << _angleMesh << " " << _gradation << " " << (int) _elementType << " " << _decimesh;
   save << " " << _minSize << " " << _maxSize << " " << _angleMesh << " " << _minSize << " " << _maxSize << " " << _verb;
   save << " " << (int) _preCADMergeEdges << " " << _preCADRemoveNanoEdges << " " << (int) _preCADDiscardInput << " " << _preCADEpsNano ;
   save << " " << (int) _enforcedInternalVerticesAllFaces;
   save << " " << (int) _phySizeRel << " " << (int) _minSizeRel << " " << (int) _maxSizeRel << " " << _chordalError ;
   save << " " << (int) _anisotropic << " " << _anisotropicRatio << " " << (int) _removeTinyEdges << " " << _tinyEdgeLength ;
   save << " " << (int) _badElementRemoval << " " << _badElementAspectRatio << " " << (int) _optimizeMesh << " " << (int) _quadraticMesh ;
-  save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces << " " << (int) _preCADRemoveTinyUVEdges;
+  save << " " << (int) _preCADProcess3DTopology << " " << (int) _preCADRemoveDuplicateCADFaces;
   save << " " << (int)_optimiseTinyEdges << " " << _tinyEdgeOptimisationLength;
   save << " " << (int)_correctSurfaceIntersec << " " << _corrSurfaceIntersCost;
   save << " " << (int)_useGradation << " " << (int)_useVolumeGradation << " " << _volumeGradation;
@@ -1914,7 +2274,6 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
     }
     save << " " << "__NEW_ATTRACTORS_END__";
     test << " " << "__NEW_ATTRACTORS_END__";
-    MESSAGE(" Attractor hypothesis saved as "<<test.str())
   }
 
   TEnfVertexList::const_iterator it_enf = _enfVertexList.begin();
@@ -1951,7 +2310,10 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
         save << " " << "__BEGIN_FACELIST__";
       }
       for (; faceEntriesIt != enfVertex->faceEntries.end(); ++faceEntriesIt)
-        save << " " << (*faceEntriesIt);
+        if ( faceEntriesIt->empty() )
+          save << " _no_face_";
+        else
+          save << " " << (*faceEntriesIt);
       if (hasFaces)
         save << " " << "__END_FACELIST__";
       save << " " << "__END_VERTEX__";
@@ -1968,14 +2330,44 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
   SaveEdgesPeriodicity(save);
   SaveVerticesPeriodicity(save);
 
+  // HYPER-PATCHES
+  save << " " << _hyperPatchList.size() << " ";
+  for ( size_t i = 0; i < _hyperPatchList.size(); ++i )
+  {
+    THyperPatchTags& patch = _hyperPatchList[i];
+    save << patch.size() << " ";
+    THyperPatchTags::iterator tag = patch.begin();
+    for ( ; tag != patch.end(); ++tag )
+      save << *tag << " ";
+  }
+
+  // New options in 2.9.6 (issue #17784)
+  save << " " << _useSurfaceProximity;
+  save << " " << _nbSurfaceProximityLayers;
+  save << " " << _surfaceProximityRatio;
+  save << " " << _useVolumeProximity;
+  save << " " << _nbVolumeProximityLayers;
+  save << " " << _volumeProximityRatio;
+
+  // hyper-patches as entries
+  std::ostringstream hpStream;
+  boost::archive::text_oarchive( hpStream ) << _hyperPatchEntriesList;
+  std::string hpString = hpStream.str();
+  SMESHDS_Hypothesis::SaveStringToStream( save, hpString );
+
+  // Enforced meshes
+  std::ostringstream enfMStream;
+  boost::archive::text_oarchive( enfMStream ) << _enforcedMeshes;
+  std::string enfMString = enfMStream.str();
+  SMESHDS_Hypothesis::SaveStringToStream( save, enfMString );
+
   return save;
 }
 
-void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
-
+void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save)
+{
   TFacesPeriodicityVector::const_iterator it_faces_periodicity = _facesPeriodicityVector.begin();
   if (it_faces_periodicity != _facesPeriodicityVector.end()) {
-    MESSAGE("__FACES_PERIODICITY_BEGIN__");
     save << " " << "__FACES_PERIODICITY_BEGIN__";
     for (; it_faces_periodicity != _facesPeriodicityVector.end(); ++it_faces_periodicity) {
       TFacesPeriodicity periodicity_i = (*it_faces_periodicity);
@@ -1989,16 +2381,14 @@ void BLSURFPlugin_Hypothesis::SaveFacesPeriodicity(std::ostream & save){
       save << " " << "__END_PERIODICITY_DESCRIPTION__";
     }
     save << " " << "__FACES_PERIODICITY_END__";
-    MESSAGE("__FACES_PERIODICITY_END__");
   }
 }
 
-void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
-
+void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save)
+{
   TEdgesPeriodicityVector::const_iterator it_edges_periodicity = _edgesPeriodicityVector.begin();
   if (it_edges_periodicity != _edgesPeriodicityVector.end()) {
     save << " " << "__EDGES_PERIODICITY_BEGIN__";
-    MESSAGE("__EDGES_PERIODICITY_BEGIN__");
     for (; it_edges_periodicity != _edgesPeriodicityVector.end(); ++it_edges_periodicity) {
       TEdgePeriodicity periodicity_i = (*it_edges_periodicity);
       save << " " << "__BEGIN_PERIODICITY_DESCRIPTION__";
@@ -2024,15 +2414,13 @@ void BLSURFPlugin_Hypothesis::SaveEdgesPeriodicity(std::ostream & save){
       save << " " << "__END_PERIODICITY_DESCRIPTION__";
     }
     save << " " << "__EDGES_PERIODICITY_END__";
-    MESSAGE("__EDGES_PERIODICITY_END__");
   }
 }
 
-void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
-
+void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save)
+{
   TVerticesPeriodicityVector::const_iterator it_vertices_periodicity = _verticesPeriodicityVector.begin();
   if (it_vertices_periodicity != _verticesPeriodicityVector.end()) {
-    MESSAGE("__VERTICES_PERIODICITY_BEGIN__");
     save << " " << "__VERTICES_PERIODICITY_BEGIN__";
     for (; it_vertices_periodicity != _verticesPeriodicityVector.end(); ++it_vertices_periodicity) {
       TVertexPeriodicity periodicity_i = (*it_vertices_periodicity);
@@ -2052,11 +2440,11 @@ void BLSURFPlugin_Hypothesis::SaveVerticesPeriodicity(std::ostream & save){
       save << " " << "__END_PERIODICITY_DESCRIPTION__";
     }
     save << " " << "__VERTICES_PERIODICITY_END__";
-    MESSAGE("__VERTICES_PERIODICITY_END__");
   }
 }
 
-void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType) {
+void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const char* shapeType)
+{
   TPreCadPeriodicityVector precad_periodicity;
   if ( shapeType  &&  strcmp( shapeType, "FACES" ) == 0 )
     precad_periodicity = _preCadFacesPeriodicityVector;
@@ -2109,7 +2497,8 @@ void BLSURFPlugin_Hypothesis::SavePreCADPeriodicity(std::ostream & save, const c
 }
 
 //=============================================================================
-std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
+std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load)
+{
   bool isOK = true;
   int i;
   double val;
@@ -2153,7 +2542,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
 
   isOK = static_cast<bool>(load >> i);
   if (isOK)
-    _quadAllowed = (bool) i;
+    _elementType = (ElementType) i;
   else
     load.clear(std::ios::badbit | load.rdstate());
 
@@ -2265,13 +2654,13 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
   bool hasVerticesPeriodicity = false;
 
   isOK = static_cast<bool>(load >> option_or_sm);
-  if (isOK)
-    if ( (option_or_sm == "1")||(option_or_sm == "0") ) {
+  if (isOK) {
+    if (( option_or_sm == "1" ) || ( option_or_sm == "0" )) {
       i = atoi(option_or_sm.c_str());
       hasCADSurfOptions = true;
       _phySizeRel = (bool) i;
     }
-    if (option_or_sm == "__OPTIONS_BEGIN__")
+    else if (option_or_sm == "__OPTIONS_BEGIN__")
       hasOptions = true;
     else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
       hasCustomOptions = true;
@@ -2295,6 +2684,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
       hasEdgesPeriodicity = true;
     else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
       hasVerticesPeriodicity = true;
+  }
 
   if (isOK && hasCADSurfOptions) {
     isOK = static_cast<bool>(load >> i);
@@ -2377,12 +2767,6 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
       else
         load.clear(std::ios::badbit | load.rdstate());
 
-      isOK = static_cast<bool>(load >> i);
-      if (isOK)
-        _preCADRemoveTinyUVEdges = (bool) i;
-      else
-        load.clear(std::ios::badbit | load.rdstate());
-
       isOK = static_cast<bool>(load >> i);
       if (isOK)
         _optimiseTinyEdges = (bool) i;
@@ -2466,17 +2850,23 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
         break;
       isOK = static_cast<bool>(load >> optValue);
     }
-    if (isOK) {
+    // read the value of the advanced option
+    // unless this option is no more used
+    if (isOK
+#if MESHGEMS_VERSION_HEX >= 0x020A00
+        && optName != "enforce_cad_edge_sizes" && optName != "max_number_of_points_per_patch"
+#endif
+        ) {
       std::string & value = _option2value[optName];
       value = optValue;
-      int len = value.size();
+      int len = (int) value.size();
       // continue reading until "%#" encountered
       while (value[len - 1] != '#' || value[len - 2] != '%') {
         isOK = static_cast<bool>(load >> optValue);
         if (isOK) {
           value += " ";
           value += optValue;
-          len = value.size();
+          len = (int) value.size();
         } else {
           break;
         }
@@ -2523,14 +2913,14 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     }
     if (isOK) {
       std::string& value = optValue;
-      int len = value.size();
+      int len = (int) value.size();
       // continue reading until "%#" encountered
       while (value[len - 1] != '#' || value[len - 2] != '%') {
         isOK = static_cast<bool>(load >> optValue);
         if (isOK) {
           value += " ";
           value += optValue;
-          len = value.size();
+          len = (int) value.size();
         } else {
           break;
         }
@@ -2577,14 +2967,14 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     if (isOK) {
       std::string & value = _preCADoption2value[optName];
       value = optValue;
-      int len = value.size();
+      int len = (int) value.size();
       // continue reading until "%#" encountered
       while (value[len - 1] != '#' || value[len - 2] != '%') {
         isOK = static_cast<bool>(load >> optValue);
         if (isOK) {
           value += " ";
           value += optValue;
-          len = value.size();
+          len = (int) value.size();
         } else {
           break;
         }
@@ -2629,14 +3019,14 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     if (isOK) {
       std::string & value2 = _sizeMap[smEntry];
       value2 = smValue;
-      int len2 = value2.size();
+      int len2 = (int) value2.size();
       // continue reading until "%#" encountered
       while (value2[len2 - 1] != '#' || value2[len2 - 2] != '%') {
         isOK = static_cast<bool>(load >> smValue);
         if (isOK) {
           value2 += " ";
           value2 += smValue;
-          len2 = value2.size();
+          len2 = (int) value2.size();
         } else {
           break;
         }
@@ -2647,10 +3037,10 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
 
   if (hasSizeMap) {
     isOK = static_cast<bool>(load >> option_or_sm);
-    if (isOK)
+    if (isOK) {
       if (option_or_sm == "__ATTRACTORS_BEGIN__")
         hasAttractor = true;
-      if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
+      else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
         hasNewAttractor = true;
       else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
         hasEnforcedVertex = true;
@@ -2664,6 +3054,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
         hasEdgesPeriodicity = true;
       else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
         hasVerticesPeriodicity = true;
+    }
   }
 
   std::string atEntry, atValue;
@@ -2677,14 +3068,14 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     if (isOK) {
       std::string & value3 = _attractors[atEntry];
       value3 = atValue;
-      int len3 = value3.size();
+      int len3 = (int) value3.size();
       // continue reading until "%#" encountered
       while (value3[len3 - 1] != '#' || value3[len3 - 2] != '%') {
         isOK = static_cast<bool>(load >> atValue);
         if (isOK) {
           value3 += " ";
           value3 += atValue;
-          len3 = value3.size();
+          len3 = (int) value3.size();
         } else {
           break;
         }
@@ -2725,11 +3116,10 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
         break;
       isOK = static_cast<bool>(load >> newAtShapeEntry);
       if (!isOK)
-    break;
+        break;
       isOK = static_cast<bool>(load >> attParams[0]>>attParams[1]>>attParams[2]>>attParams[3]); //>>step);
     }
     if (isOK) {
-      MESSAGE(" LOADING ATTRACTOR HYPOTHESIS ")
       const TopoDS_Shape attractorShape = BLSURFPlugin_Hypothesis::entryToShape(newAtShapeEntry);
       const TopoDS_Face faceShape = TopoDS::Face(BLSURFPlugin_Hypothesis::entryToShape(newAtFaceEntry));
       BLSURFPlugin_Attractor* attractor = new BLSURFPlugin_Attractor(faceShape, attractorShape, newAtShapeEntry);//, step);
@@ -2764,17 +3154,17 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
 // __ENFORCED_VERTICES_BEGIN__ 
 // __BEGIN_VERTEX__  => no name, no entry
 // __BEGIN_GROUP__ mon groupe __END_GROUP__
-// __BEGIN_COORDS__ 10 10 10 __END_COORDS__ 
-// __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__ 
-// __END_VERTEX__ 
+// __BEGIN_COORDS__ 10 10 10 __END_COORDS__
+// __BEGIN_FACELIST__ 0:1:1:1:1 __END_FACELIST__
+// __END_VERTEX__
 // __BEGIN_VERTEX__ => no coords
-// __BEGIN_NAME__ mes points __END_NAME__ 
+// __BEGIN_NAME__ mes points __END_NAME__
 // __BEGIN_ENTRY__ 0:1:1:4 __END_ENTRY__
 // __BEGIN_GROUP__ mon groupe __END_GROUP__
 // __BEGIN_FACELIST__ 0:1:1:1:3 __END_FACELIST__
-// __END_VERTEX__ 
+// __END_VERTEX__
 // __ENFORCED_VERTICES_END__
-// 
+//
 
   std::string enfSeparator;
   std::string enfName;
@@ -2783,29 +3173,28 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
   TEntryList enfFaceEntryList;
   double enfCoords[3];
   bool hasCoords = false;
-  
+
   _faceEntryEnfVertexListMap.clear();
   _enfVertexList.clear();
   _faceEntryCoordsListMap.clear();
   _coordsEnfVertexMap.clear();
   _faceEntryEnfVertexEntryListMap.clear();
   _enfVertexEntryEnfVertexMap.clear();
-  
-  
-  while (isOK && hasEnforcedVertex) {
+
+
+  while (isOK && hasEnforcedVertex)
+  {
     isOK = static_cast<bool>(load >> enfSeparator); // __BEGIN_VERTEX__
     TEnfVertex *enfVertex = new TEnfVertex();
-//     MESSAGE("enfSeparator: " <<enfSeparator);
     if (enfSeparator == "__ENFORCED_VERTICES_END__")
       break; // __ENFORCED_VERTICES_END__
     if (enfSeparator != "__BEGIN_VERTEX__")
       throw std::exception();
-    
+
     while (isOK) {
       isOK = static_cast<bool>(load >> enfSeparator);
-      MESSAGE("enfSeparator: " <<enfSeparator);
       if (enfSeparator == "__END_VERTEX__") {
-        
+
         enfVertex->name = enfName;
         enfVertex->geomEntry = enfGeomEntry;
         enfVertex->grpName = enfGroup;
@@ -2813,9 +3202,9 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
         if (hasCoords)
           enfVertex->coords.assign(enfCoords,enfCoords+3);
         enfVertex->faceEntries = enfFaceEntryList;
-        
+
         _enfVertexList.insert(enfVertex);
-        
+
         if (enfVertex->coords.size()) {
           _coordsEnfVertexMap[enfVertex->coords] = enfVertex;
           for (TEntryList::const_iterator it = enfVertex->faceEntries.begin() ; it != enfVertex->faceEntries.end(); ++it) {
@@ -2830,7 +3219,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
             _faceEntryEnfVertexListMap[(*it)].insert(enfVertex);
           }
         }
-        
+
         enfName.clear();
         enfGeomEntry.clear();
         enfGroup.clear();
@@ -2838,7 +3227,7 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
         hasCoords = false;
         break; // __END_VERTEX__
       }
-        
+
       if (enfSeparator == "__BEGIN_NAME__") {  // __BEGIN_NAME__
         while (isOK && (enfSeparator != "__END_NAME__")) {
           isOK = static_cast<bool>(load >> enfSeparator);
@@ -2848,17 +3237,15 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
             enfName += enfSeparator;
           }
         }
-        MESSAGE("enfName: " <<enfName);
       }
-        
+
       if (enfSeparator == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
         isOK = static_cast<bool>(load >> enfGeomEntry);
         isOK = static_cast<bool>(load >> enfSeparator); // __END_ENTRY__
         if (enfSeparator != "__END_ENTRY__")
           throw std::exception();
-        MESSAGE("enfGeomEntry: " <<enfGeomEntry);
       }
-        
+
       if (enfSeparator == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
         while (isOK && (enfSeparator != "__END_GROUP__")) {
           isOK = static_cast<bool>(load >> enfSeparator);
@@ -2868,33 +3255,47 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
             enfGroup += enfSeparator;
           }
         }
-        MESSAGE("enfGroup: " <<enfGroup);
       }
-        
+
       if (enfSeparator == "__BEGIN_COORDS__") {  // __BEGIN_COORDS__
         hasCoords = true;
         isOK = static_cast<bool>(load >> enfCoords[0] >> enfCoords[1] >> enfCoords[2]);
         isOK = static_cast<bool>(load >> enfSeparator); // __END_COORDS__
         if (enfSeparator != "__END_COORDS__")
           throw std::exception();
-        MESSAGE("enfCoords: " << enfCoords[0] <<","<< enfCoords[1] <<","<< enfCoords[2]);
-      } 
-        
+      }
+
       if (enfSeparator == "__BEGIN_FACELIST__") {  // __BEGIN_FACELIST__
         while (isOK && (enfSeparator != "__END_FACELIST__")) {
           isOK = static_cast<bool>(load >> enfSeparator);
           if (enfSeparator != "__END_FACELIST__") {
             enfFaceEntryList.insert(enfSeparator);
-            MESSAGE(enfSeparator << " was inserted into enfFaceEntryList");
           }
         }
-      } 
+      }
+    }
+  }
+
+  if ( hasEnforcedVertex ) {
+    isOK = static_cast<bool>(load >> option_or_sm);
+    if (isOK) {
+      if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
+        hasPreCADFacesPeriodicity = true;
+      else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
+        hasPreCADEdgesPeriodicity = true;
+      else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
+        hasFacesPeriodicity = true;
+      else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
+        hasEdgesPeriodicity = true;
+      else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
+        hasVerticesPeriodicity = true;
     }
   }
 
   // PERIODICITY
 
-  if (hasPreCADFacesPeriodicity){
+  if (hasPreCADFacesPeriodicity)
+  {
     LoadPreCADPeriodicity(load, "FACES");
 
     isOK = static_cast<bool>(load >> option_or_sm);
@@ -2910,7 +3311,8 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     }
   }
 
-  if (hasPreCADEdgesPeriodicity){
+  if (hasPreCADEdgesPeriodicity)
+  {
     LoadPreCADPeriodicity(load, "EDGES");
 
     isOK = static_cast<bool>(load >> option_or_sm);
@@ -2924,8 +3326,9 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     }
   }
 
-  if (hasFacesPeriodicity){
-      LoadFacesPeriodicity(load);
+  if (hasFacesPeriodicity)
+  {
+    LoadFacesPeriodicity(load);
 
     isOK = static_cast<bool>(load >> option_or_sm);
     if (isOK) {
@@ -2936,8 +3339,9 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     }
   }
 
-  if (hasEdgesPeriodicity){
-      LoadEdgesPeriodicity(load);
+  if (hasEdgesPeriodicity)
+  {
+    LoadEdgesPeriodicity(load);
 
     isOK = static_cast<bool>(load >> option_or_sm);
     if (isOK)
@@ -2946,13 +3350,94 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
   }
 
   if (hasVerticesPeriodicity)
-      LoadVerticesPeriodicity(load);
+    LoadVerticesPeriodicity(load);
+
+  // HYPER-PATCHES
+  if ( !option_or_sm.empty() && option_or_sm[0] == '_' )
+    isOK = static_cast<bool>(load >> option_or_sm);
+  if ( isOK && !option_or_sm.empty() )
+  {
+    int nbPatches = atoi( option_or_sm.c_str() );
+    if ( nbPatches >= 0 )
+    {
+      _hyperPatchList.resize( nbPatches );
+      for ( int iP = 0; iP < nbPatches && isOK; ++iP )
+      {
+        isOK = static_cast<bool>(load >> i) && i >= 2;
+        if ( !isOK ) break;
+        int nbTags = i;
+        for ( int iT = 0; iT < nbTags; ++iT )
+        {
+          if (( isOK = static_cast<bool>(load >> i)))
+            _hyperPatchList[ iP ].insert( i );
+          else
+            break;
+        }
+      }
+      if ( !isOK ) // remove invalid patches
+      {
+        for ( i = nbPatches - 1; i >= 0; i-- )
+          if ( _hyperPatchList[i].size() < 2 )
+            _hyperPatchList.resize( i );
+      }
+    }
+  }
+
+  // New options in 2.9.6 (issue #17784)
+  if ( static_cast<bool>( load >> _useSurfaceProximity ))
+  {
+    load >> _nbSurfaceProximityLayers;
+    load >> _surfaceProximityRatio;
+    load >> _useVolumeProximity;
+    load >> _nbVolumeProximityLayers;
+    isOK = static_cast<bool>( load >> _volumeProximityRatio );
+  }
+
+  // hyper-patches as entries (issue bos #20543)
+  std::string buffer;
+  if ( SMESHDS_Hypothesis::LoadStringFromStream( load, buffer ))
+  {
+    SMESH_TRY;
+    SMESHUtils::BoostTxtArchive( buffer ) >> _hyperPatchEntriesList;
+    SMESH_CATCH( SMESH::printErrorInDebugMode );
+  }
+
+  // Enforced meshes (issue bos $16292)
+  buffer.clear();
+  if ( SMESHDS_Hypothesis::LoadStringFromStream( load, buffer ))
+  {
+    SMESH_TRY;
+    SMESHUtils::BoostTxtArchive( buffer ) >> _enforcedMeshes;
+    SMESH_CATCH( SMESH::printErrorInDebugMode );
+  }
 
   return load;
 }
 
-void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
+namespace boost {
+  namespace serialization {
+
+    //=======================================================================
+    //function : serialize
+    //purpose  : serialize EnforcedMesh
+    //=======================================================================
+
+    template<class Archive>
+    void serialize(Archive & ar, BLSURFPlugin_Hypothesis::EnforcedMesh & enfM,
+                   const unsigned int /*version*/)
+    {
+      ar & enfM._meshID;
+      ar & enfM._subID;
+      ar & enfM._type;
+      ar & enfM._groupName;
+    }
 
+  } // namespace serialization
+} // namespace boost
+
+
+void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load)
+{
   bool isOK = true;
 
   std::string periodicitySeparator;
@@ -2963,18 +3448,15 @@ void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
 
   while (isOK) {
     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
-    MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
     TFacesPeriodicity *periodicity_i = new TFacesPeriodicity();
     if (periodicitySeparator == "__FACES_PERIODICITY_END__")
       break; // __FACES_PERIODICITY_END__
     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
-      MESSAGE("//" << periodicitySeparator << "//");
       throw std::exception();
     }
 
     while (isOK) {
       isOK = static_cast<bool>(load >> periodicitySeparator);
-      MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
 
         periodicity_i->first = shape1Entry;
@@ -2990,7 +3472,6 @@ void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
         if (periodicitySeparator != "__END_ENTRY1__")
           throw std::exception();
-        MESSAGE("shape1Entry: " <<shape1Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
@@ -2998,15 +3479,14 @@ void BLSURFPlugin_Hypothesis::LoadFacesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
         if (periodicitySeparator != "__END_ENTRY2__")
           throw std::exception();
-        MESSAGE("shape2Entry: " <<shape2Entry);
       }
     }
   }
 }
 
 
-void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
-
+void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load)
+{
   bool isOK = true;
 
   std::string periodicitySeparator;
@@ -3020,18 +3500,15 @@ void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
 
   while (isOK) {
     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
-    MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
     TEdgePeriodicity *periodicity_i = new TEdgePeriodicity();
     if (periodicitySeparator == "__EDGES_PERIODICITY_END__")
       break; // __EDGES_PERIODICITY_END__
     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
-      MESSAGE("//" << periodicitySeparator << "//");
       throw std::exception();
     }
 
     while (isOK) {
       isOK = static_cast<bool>(load >> periodicitySeparator);
-      MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
 
         periodicity_i->theFace1Entry = theFace1Entry;
@@ -3047,13 +3524,10 @@ void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
 
       if (periodicitySeparator == "__BEGIN_FACE1__") {  // __BEGIN_FACE1__
         isOK = static_cast<bool>(load >> theFace1Entry);
-        MESSAGE("//" << theFace1Entry << "//");
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE1__
         if (periodicitySeparator != "__END_FACE1__"){
-          MESSAGE("//" << periodicitySeparator << "//");
           throw std::exception();
         }
-        MESSAGE("theFace1Entry: " <<theFace1Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_EDGE1__") {  // __BEGIN_EDGE1__
@@ -3061,7 +3535,6 @@ void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
         if (periodicitySeparator != "__END_EDGE1__")
           throw std::exception();
-        MESSAGE("theEdge1Entry: " <<theEdge1Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_FACE2__") {  // __BEGIN_FACE2__
@@ -3069,7 +3542,6 @@ void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_FACE2__
         if (periodicitySeparator != "__END_FACE2__")
           throw std::exception();
-        MESSAGE("theFace2Entry: " <<theFace2Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
@@ -3077,7 +3549,6 @@ void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
         if (periodicitySeparator != "__END_EDGE2__")
           throw std::exception();
-        MESSAGE("theEdge2Entry: " <<theEdge2Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_EDGE_ORIENTATION__") {  // __BEGIN_EDGE_ORIENTATION__
@@ -3085,14 +3556,13 @@ void BLSURFPlugin_Hypothesis::LoadEdgesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE_ORIENTATION__
         if (periodicitySeparator != "__END_EDGE_ORIENTATION__")
           throw std::exception();
-        MESSAGE("edge_orientation: " <<edge_orientation);
       }
     }
   }
 }
 
-void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
-
+void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load)
+{
   bool isOK = true;
 
   std::string periodicitySeparator;
@@ -3105,18 +3575,15 @@ void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
 
   while (isOK) {
     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
-    MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
     TVertexPeriodicity *periodicity_i = new TVertexPeriodicity();
     if (periodicitySeparator == "__VERTICES_PERIODICITY_END__")
       break; // __VERTICES_PERIODICITY_END__
     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
-      MESSAGE("//" << periodicitySeparator << "//");
       throw std::exception();
     }
 
     while (isOK) {
       isOK = static_cast<bool>(load >> periodicitySeparator);
-      MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
 
         periodicity_i->theEdge1Entry = theEdge1Entry;
@@ -3134,7 +3601,6 @@ void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE1__
         if (periodicitySeparator != "__END_EDGE1__")
           throw std::exception();
-        MESSAGE("theEdge1Entry: " <<theEdge1Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_VERTEX1__") {  // __BEGIN_VERTEX1__
@@ -3142,7 +3608,6 @@ void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX1__
         if (periodicitySeparator != "__END_VERTEX1__")
           throw std::exception();
-        MESSAGE("theVertex1Entry: " <<theVertex1Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_EDGE2__") {  // __BEGIN_EDGE2__
@@ -3150,7 +3615,6 @@ void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_EDGE2__
         if (periodicitySeparator != "__END_EDGE2__")
           throw std::exception();
-        MESSAGE("theEdge2Entry: " <<theEdge2Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_VERTEX2__") {  // __BEGIN_VERTEX2__
@@ -3158,14 +3622,13 @@ void BLSURFPlugin_Hypothesis::LoadVerticesPeriodicity(std::istream & load){
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_VERTEX2__
         if (periodicitySeparator != "__END_VERTEX2__")
           throw std::exception();
-        MESSAGE("theVertex2Entry: " <<theVertex2Entry);
       }
     }
   }
 }
 
-void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType) {
-
+void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const char* shapeType)
+{
   bool isOK = true;
 
   std::string periodicitySeparator;
@@ -3185,35 +3648,27 @@ void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const c
 
   while (isOK) {
     isOK = static_cast<bool>(load >> periodicitySeparator); // __BEGIN_PERIODICITY_DESCRIPTION__
-    MESSAGE("periodicitySeparator 1: " <<periodicitySeparator);
     TPreCadPeriodicity *periodicity_i = new TPreCadPeriodicity();
-//     MESSAGE("periodicitySeparator: " <<periodicitySeparator);
     std::string endSeparator = "__PRECAD_" + std::string(shapeType) + "_PERIODICITY_END__";
     if (periodicitySeparator == endSeparator)
       break; // __PRECAD_FACES_PERIODICITY_END__
     if (periodicitySeparator != "__BEGIN_PERIODICITY_DESCRIPTION__"){
-      MESSAGE("//" << endSeparator << "//");
-      MESSAGE("//" << periodicitySeparator << "//");
       throw std::exception();
     }
 
     while (isOK) {
       isOK = static_cast<bool>(load >> periodicitySeparator);
-      MESSAGE("periodicitySeparator 2: " <<periodicitySeparator);
       if (periodicitySeparator == "__END_PERIODICITY_DESCRIPTION__") {
 
         periodicity_i->shape1Entry = shape1Entry;
         periodicity_i->shape2Entry = shape2Entry;
 
-        MESSAGE("theSourceVerticesEntries.size(): " << theSourceVerticesEntries.size());
-        MESSAGE("theTargetVerticesEntries.size(): " << theTargetVerticesEntries.size());
-
         if (hasSourceVertices)
           periodicity_i->theSourceVerticesEntries = theSourceVerticesEntries;
         if (hasTargetVertices)
           periodicity_i->theTargetVerticesEntries = theTargetVerticesEntries;
 
-        if ( shapeType  &&  strcmp( shapeType, "FACES" ))
+        if ( shapeType  &&  strcmp( shapeType, "FACES" ) == 0 )
           _preCadFacesPeriodicityVector.push_back(*periodicity_i);
         else
           _preCadEdgesPeriodicityVector.push_back(*periodicity_i);
@@ -3230,7 +3685,6 @@ void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const c
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY1__
         if (periodicitySeparator != "__END_ENTRY1__")
           throw std::exception();
-        MESSAGE("shape1Entry: " <<shape1Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_ENTRY2__") {  // __BEGIN_ENTRY2__
@@ -3238,7 +3692,6 @@ void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const c
         isOK = static_cast<bool>(load >> periodicitySeparator); // __END_ENTRY2__
         if (periodicitySeparator != "__END_ENTRY2__")
           throw std::exception();
-        MESSAGE("shape2Entry: " <<shape2Entry);
       }
 
       if (periodicitySeparator == "__BEGIN_SOURCE_VERTICES_LIST__") {  // __BEGIN_SOURCE_VERTICES_LIST__
@@ -3247,7 +3700,6 @@ void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const c
           isOK = static_cast<bool>(load >> periodicitySeparator);
           if (periodicitySeparator != "__END_SOURCE_VERTICES_LIST__") {
             theSourceVerticesEntries.push_back(periodicitySeparator);
-            MESSAGE("theSourceVerticesEntries: " <<periodicitySeparator);
           }
         }
       }
@@ -3258,7 +3710,6 @@ void BLSURFPlugin_Hypothesis::LoadPreCADPeriodicity(std::istream & load, const c
           isOK = static_cast<bool>(load >> periodicitySeparator);
           if (periodicitySeparator != "__END_TARGET_VERTICES_LIST__") {
             theTargetVerticesEntries.push_back(periodicitySeparator);
-            MESSAGE("theTargetVerticesEntries: " <<periodicitySeparator);
           }
         }
       }
@@ -3282,7 +3733,8 @@ std::istream & operator >>(std::istream & load, BLSURFPlugin_Hypothesis & hyp) {
  */
 //================================================================================
 
-bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, const TopoDS_Shape& theShape) {
+bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/, const TopoDS_Shape& /*theShape*/)
+{
   return false;
 }
 
@@ -3292,7 +3744,8 @@ bool BLSURFPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh, con
  */
 //================================================================================
 
-double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation) {
+double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegmentation)
+{
   if (bbSegmentation != 0 && diagonal != 0)
     return diagonal / bbSegmentation ;
   return 10;
@@ -3304,7 +3757,8 @@ double BLSURFPlugin_Hypothesis::GetDefaultPhySize(double diagonal, double bbSegm
  */
 //================================================================================
 
-double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
+double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal)
+{
   if (diagonal != 0)
     return diagonal / 1000.0 ;
   return undefinedDouble();
@@ -3316,7 +3770,8 @@ double BLSURFPlugin_Hypothesis::GetDefaultMinSize(double diagonal) {
  */
 //================================================================================
 
-double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
+double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal)
+{
   if (diagonal != 0)
     return diagonal / 5.0 ;
   return undefinedDouble();
@@ -3328,7 +3783,8 @@ double BLSURFPlugin_Hypothesis::GetDefaultMaxSize(double diagonal) {
  */
 //================================================================================
 
-double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
+double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal)
+{
   if (diagonal != 0)
     return diagonal;
   return undefinedDouble();
@@ -3340,7 +3796,8 @@ double BLSURFPlugin_Hypothesis::GetDefaultChordalError(double diagonal) {
  */
 //================================================================================
 
-double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
+double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal)
+{
   if (diagonal != 0)
     return diagonal * 1e-6 ;
   return undefinedDouble();
@@ -3352,7 +3809,8 @@ double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeLength(double diagonal) {
  */
 //================================================================================
 
-double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal) {
+double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diagonal)
+{
   if (diagonal != 0)
     return diagonal * 1e-6 ;
   return undefinedDouble();
@@ -3365,14 +3823,29 @@ double BLSURFPlugin_Hypothesis::GetDefaultTinyEdgeOptimisationLength(double diag
  */
 //=============================================================================
 
-bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, const SMESH_Mesh* theMesh) {
-  double diagonal = dflts._elemLength*_gen->GetBoundaryBoxSegmentation();
-  _phySize = GetDefaultPhySize(diagonal, _gen->GetBoundaryBoxSegmentation());
-  _minSize = GetDefaultMinSize(diagonal);
-  _maxSize = GetDefaultMaxSize(diagonal);
+bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
+                                                      const SMESH_Mesh* /*theMesh*/)
+{
+  _phySize = GetDefaultPhySize(dflts._diagonal, _gen->GetBoundaryBoxSegmentation());
+  _minSize = GetDefaultMinSize(dflts._diagonal);
+  _maxSize = GetDefaultMaxSize(dflts._diagonal);
   _chordalError = 0.5 * _phySize; //GetDefaultChordalError(diagonal); IMP 0023307
-  _tinyEdgeLength = GetDefaultTinyEdgeLength(diagonal);
-  _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(diagonal);
+
+  if ( dflts._way == SMESH_Hypothesis::BY_AVERAGE_LENGTH )
+  {
+    _phySize      = dflts._elemLength;
+    _minSize      = dflts._elemLength / 100.;
+    _maxSize      = dflts._elemLength * 2.;
+    _chordalError = dflts._elemLength / 2.;
+    _elementType  = dflts._quadDominated ? QuadrangleDominant : Triangles;
+    _physicalMesh = PhysicalLocalSize; // to activate _enforcedInternalVerticesAllFaces
+    _enforcedInternalVerticesAllFaces = true;
+  }
+  else
+  {
+    _tinyEdgeLength = GetDefaultTinyEdgeLength(dflts._diagonal);
+    _tinyEdgeOptimisationLength = GetDefaultTinyEdgeOptimisationLength(dflts._diagonal);
+  }
 
   return true;
 }
@@ -3384,13 +3857,12 @@ bool BLSURFPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts, co
 //================================================================================
 
 bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
-  throw (std::invalid_argument)
 {
   std::string s = str;
   if ( isOk ) *isOk = true;
 
   for ( size_t i = 0; i <= s.size(); ++i )
-    s[i] = tolower( s[i] );
+    s[i] = (char) tolower( s[i] );
 
   if ( s == "1" || s == "true" || s == "active" || s == "yes" )
     return true;
@@ -3414,10 +3886,12 @@ bool BLSURFPlugin_Hypothesis::ToBool(const std::string& str, bool* isOk )
 //================================================================================
 
 double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
-  throw (std::invalid_argument)
 {
   if ( str.empty() ) throw std::invalid_argument("Empty value provided");
 
+  // Forces "C" locale to be set as LC_NUMERIC
+  Kernel_Utils::Localizer loc;
+
   char * endPtr;
   double val = strtod(&str[0], &endPtr);
   bool ok = (&str[0] != endPtr);
@@ -3439,7 +3913,6 @@ double BLSURFPlugin_Hypothesis::ToDbl(const std::string& str, bool* isOk )
 //================================================================================
 
 int BLSURFPlugin_Hypothesis::ToInt(const std::string& str, bool* isOk )
-  throw (std::invalid_argument)
 {
   if ( str.empty() ) throw std::invalid_argument("Empty value provided");