Salome HOME
Fix "Conditional jump or move depends on uninitialised value" valgrind error
[plugins/ghs3dplugin.git] / src / GHS3DPlugin / GHS3DPlugin_Hypothesis.cxx
index 437233c1c948f069469e9c7862b80895f57bfc83..5f1ee5dc357d42255922b9e48a02b70500b1b6c2 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2004-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2004-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 //=============================================================================
 //
 #include "GHS3DPlugin_Hypothesis.hxx"
-#include <SMESH_ProxyMesh.hxx>
-#include <SMESH_Group.hxx>
-#include <StdMeshers_QuadToTriaAdaptor.hxx>
+
+#include <SMESHDS_Mesh.hxx>
 
 #include <TCollection_AsciiString.hxx>
 
-#ifdef WNT
+#ifdef WIN32
 #include <process.h>
 #define getpid _getpid
 #endif
 
+using namespace std;
+
 //=======================================================================
 //function : GHS3DPlugin_Hypothesis
 //=======================================================================
 
 GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen)
   : SMESH_Hypothesis(hypId, studyId, gen),
-  myToMeshHoles(DefaultMeshHoles()),
-  myMaximumMemory(-1),
-  myInitialMemory(-1),
-  myOptimizationLevel(DefaultOptimizationLevel()),
-  myWorkingDirectory(DefaultWorkingDirectory()),
-  myKeepFiles(DefaultKeepFiles()),
-  myVerboseLevel(DefaultVerboseLevel()),
-  myToCreateNewNodes(DefaultToCreateNewNodes()),
-  myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
-  myToUseFemCorrection(DefaultToUseFEMCorrection()),
-  myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
-  myGradation(DefaultGradation()),
-  _enfVertexList(DefaultGHS3DEnforcedVertexList()),
-  _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()),
-  _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()),
-  _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()),
-  _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()),
-  _enfMeshList(DefaultGHS3DEnforcedMeshList()),
-  _entryEnfMeshMap(DefaultEntryGHS3DEnforcedMeshListMap()),
-  _enfNodes(TIDSortedNodeGroupMap()),
-  _enfEdges(TIDSortedElemGroupMap()),
-  _enfTriangles(TIDSortedElemGroupMap()),
-  _nodeIDToSizeMap(DefaultID2SizeMap()),
-  _groupsToRemove(DefaultGroupsToRemove())
-{
-  _name = "GHS3D_Parameters";
+    myToMeshHoles(DefaultMeshHoles()),
+    myToMakeGroupsOfDomains(DefaultToMakeGroupsOfDomains()),
+    myMaximumMemory(-1),
+    myInitialMemory(-1),
+    myOptimizationLevel(DefaultOptimizationLevel()),
+    myKeepFiles(DefaultKeepFiles()),
+    myWorkingDirectory(DefaultWorkingDirectory()),
+    myVerboseLevel(DefaultVerboseLevel()),
+    myToCreateNewNodes(DefaultToCreateNewNodes()),
+    myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()),
+    myToUseFemCorrection(DefaultToUseFEMCorrection()),
+    myToRemoveCentralPoint(DefaultToRemoveCentralPoint()),
+    myLogInStandardOutput(DefaultStandardOutputLog()),
+    myRemoveLogOnSuccess( DefaultRemoveLogOnSuccess() ),
+    myGradation(DefaultGradation()),
+    _enfVertexList(DefaultGHS3DEnforcedVertexList()),
+    _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()),
+    _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()),
+    _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()),
+    _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()),
+    _enfMeshList(DefaultGHS3DEnforcedMeshList()),
+    _entryEnfMeshMap(DefaultEntryGHS3DEnforcedMeshListMap()),
+    _enfNodes(TIDSortedNodeGroupMap()),
+    _enfEdges(TIDSortedElemGroupMap()),
+    _enfTriangles(TIDSortedElemGroupMap()),
+    _nodeIDToSizeMap(DefaultID2SizeMap()),
+    _groupsToRemove(DefaultGroupsToRemove())
+{
+  _name = GetHypType();
   _param_algo_dim = 3;
 }
 
@@ -89,19 +93,52 @@ void GHS3DPlugin_Hypothesis::SetToMeshHoles(bool toMesh)
 bool GHS3DPlugin_Hypothesis::GetToMeshHoles(bool checkFreeOption) const
 {
   if (checkFreeOption && !myTextOption.empty()) {
-    if ( myTextOption.find("-c 0"))
+    if ( myTextOption.find("--components all"))
       return true;
-    if ( myTextOption.find("-c 1"))
+    if ( myTextOption.find("--components outside_components"))
       return false;
   }
   return myToMeshHoles;
 }
 
+//=======================================================================
+//function : SetToMakeGroupsOfDomains
+//=======================================================================
+
+void GHS3DPlugin_Hypothesis::SetToMakeGroupsOfDomains(bool toMakeGroups)
+{
+  if ( myToMakeGroupsOfDomains != toMakeGroups ) {
+    myToMakeGroupsOfDomains = toMakeGroups;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : GetToMakeGroupsOfDomains
+//=======================================================================
+
+bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains() const
+{
+  return myToMakeGroupsOfDomains;
+}
+
+//=======================================================================
+//function : GetToMakeGroupsOfDomains
+//=======================================================================
+
+bool GHS3DPlugin_Hypothesis::GetToMakeGroupsOfDomains(const GHS3DPlugin_Hypothesis* hyp)
+{
+  bool res;
+  if ( hyp ) res = /*hyp->GetToMeshHoles(true) &&*/ hyp->GetToMakeGroupsOfDomains();
+  else       res = /*DefaultMeshHoles()        &&*/ DefaultToMakeGroupsOfDomains();
+  return res;
+}
+
 //=======================================================================
 //function : SetMaximumMemory
 //=======================================================================
 
-void GHS3DPlugin_Hypothesis::SetMaximumMemory(short MB)
+void GHS3DPlugin_Hypothesis::SetMaximumMemory(float MB)
 {
   if ( myMaximumMemory != MB ) {
     myMaximumMemory = MB;
@@ -114,7 +151,7 @@ void GHS3DPlugin_Hypothesis::SetMaximumMemory(short MB)
 //           * automatic memory adjustment mode. Default is zero
 //=======================================================================
 
-short GHS3DPlugin_Hypothesis::GetMaximumMemory() const
+float GHS3DPlugin_Hypothesis::GetMaximumMemory() const
 {
   return myMaximumMemory;
 }
@@ -123,7 +160,7 @@ short GHS3DPlugin_Hypothesis::GetMaximumMemory() const
 //function : SetInitialMemory
 //=======================================================================
 
-void GHS3DPlugin_Hypothesis::SetInitialMemory(short MB)
+void GHS3DPlugin_Hypothesis::SetInitialMemory(float MB)
 {
   if ( myInitialMemory != MB ) {
     myInitialMemory = MB;
@@ -135,7 +172,7 @@ void GHS3DPlugin_Hypothesis::SetInitialMemory(short MB)
 //function : GetInitialMemory
 //=======================================================================
 
-short GHS3DPlugin_Hypothesis::GetInitialMemory() const
+float GHS3DPlugin_Hypothesis::GetInitialMemory() const
 {
   return myInitialMemory;
 }
@@ -309,10 +346,10 @@ bool GHS3DPlugin_Hypothesis::GetToRemoveCentralPoint() const
 }
 
 //=======================================================================
-//function : SetTextOption
+//function : SetAdvancedOption
 //=======================================================================
 
-void GHS3DPlugin_Hypothesis::SetTextOption(const std::string& option)
+void GHS3DPlugin_Hypothesis::SetAdvancedOption(const std::string& option)
 {
   if ( myTextOption != option ) {
     myTextOption = option;
@@ -321,10 +358,10 @@ void GHS3DPlugin_Hypothesis::SetTextOption(const std::string& option)
 }
 
 //=======================================================================
-//function : GetTextOption
+//function : GetAdvancedOption
 //=======================================================================
 
-std::string GHS3DPlugin_Hypothesis::GetTextOption() const
+std::string GHS3DPlugin_Hypothesis::GetAdvancedOption() const
 {
   return myTextOption;
 }
@@ -350,12 +387,58 @@ double GHS3DPlugin_Hypothesis::GetGradation() const
   return myGradation;
 }
 
+//=======================================================================
+//function : SetStandardOutputLog
+//=======================================================================
+
+void GHS3DPlugin_Hypothesis::SetStandardOutputLog(bool logInStandardOutput)
+{
+  if ( myLogInStandardOutput != logInStandardOutput ) {
+    myLogInStandardOutput = logInStandardOutput;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : GetStandardOutputLog
+//=======================================================================
+
+bool GHS3DPlugin_Hypothesis::GetStandardOutputLog() const
+{
+  return myLogInStandardOutput;
+}
+
+//=======================================================================
+//function : SetRemoveLogOnSuccess
+//=======================================================================
+
+void GHS3DPlugin_Hypothesis::SetRemoveLogOnSuccess(bool removeLogOnSuccess)
+{
+  if ( myRemoveLogOnSuccess != removeLogOnSuccess ) {
+    myRemoveLogOnSuccess = removeLogOnSuccess;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : GetRemoveLogOnSuccess
+//=======================================================================
+
+bool GHS3DPlugin_Hypothesis::GetRemoveLogOnSuccess() const
+{
+  return myRemoveLogOnSuccess;
+}
+
 //=======================================================================
 //function : SetEnforcedVertex
 //=======================================================================
 
-bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName,
-                                               double size, double x, double y, double z, bool isCompound)
+bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName,
+                                               std::string theEntry,
+                                               std::string theGroupName,
+                                               double      size,
+                                               double x, double y, double z,
+                                               bool        isCompound)
 {
   MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex(\""<< theName << "\", \""<< theEntry << "\", \"" << theGroupName << "\", "
                                                       << size << ", " << x << ", " << y << ", " << z  << ", "<< isCompound << ")");
@@ -476,7 +559,7 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SME
   MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedGroup");
   TIDSortedElemSet theElemSet;
     if ( theIDs->length() == 0 ){MESSAGE("The source group is empty");}
-    for (int i=0; i < theIDs->length(); i++) {
+    for ( CORBA::ULong i=0; i < theIDs->length(); i++) {
       CORBA::Long ind = theIDs[i];
       if (elementType == SMESH::NODE)
       {
@@ -756,36 +839,42 @@ bool GHS3DPlugin_Hypothesis::DefaultMeshHoles()
   return false; // PAL19680
 }
 
+//=======================================================================
+//function : DefaultToMakeGroupsOfDomains
+//=======================================================================
+
+bool GHS3DPlugin_Hypothesis::DefaultToMakeGroupsOfDomains()
+{
+  return false; // issue 0022172
+}
+
 //=======================================================================
 //function : DefaultMaximumMemory
 //=======================================================================
 
-#ifndef WIN32
-#include <sys/sysinfo.h>
-#else
+#if defined(WIN32)
 #include <windows.h>
+#elif !defined(__APPLE__)
+#include <sys/sysinfo.h>
 #endif
 
-short  GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
+float GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
 {
-#ifndef WIN32
-  struct sysinfo si;
-  int err = sysinfo( &si );
-  if ( err == 0 ) {
-    int ramMB = si.totalram * si.mem_unit / 1024 / 1024;
-    return (int) ( 0.7 * ramMB );
-  }
-#else
+#if defined(WIN32)
   // See http://msdn.microsoft.com/en-us/library/aa366589.aspx
   MEMORYSTATUSEX statex;
   statex.dwLength = sizeof (statex);
-  int err = GlobalMemoryStatusEx (&statex);
+  long err = GlobalMemoryStatusEx (&statex);
   if (err != 0) {
-    int totMB = 
-      statex.ullTotalPhys / 1024 / 1024 +
-      statex.ullTotalPageFile / 1024 / 1024 +
-      statex.ullTotalVirtual / 1024 / 1024;
-    return (int) ( 0.7 * totMB );
+    double totMB = (double)statex.ullAvailPhys / 1024. / 1024.;
+    return (float)( 0.7 * totMB );
+  }
+#elif !defined(__APPLE__)
+  struct sysinfo si;
+  long err = sysinfo( &si );
+  if ( err == 0 ) {
+    long ramMB = si.totalram * si.mem_unit / 1024 / 1024;
+    return ( 0.7 * ramMB );
   }
 #endif
   return 1024;
@@ -795,7 +884,7 @@ short  GHS3DPlugin_Hypothesis::DefaultMaximumMemory()
 //function : DefaultInitialMemory
 //=======================================================================
 
-short  GHS3DPlugin_Hypothesis::DefaultInitialMemory()
+float GHS3DPlugin_Hypothesis::DefaultInitialMemory()
 {
   return DefaultMaximumMemory();
 }
@@ -804,7 +893,7 @@ short  GHS3DPlugin_Hypothesis::DefaultInitialMemory()
 //function : DefaultOptimizationLevel
 //=======================================================================
 
-short  GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
+short GHS3DPlugin_Hypothesis::DefaultOptimizationLevel()
 {
   return Medium;
 }
@@ -840,6 +929,16 @@ bool   GHS3DPlugin_Hypothesis::DefaultKeepFiles()
   return false;
 }
 
+//=======================================================================
+//function : DefaultRemoveLogOnSuccess
+//=======================================================================
+
+bool   GHS3DPlugin_Hypothesis::DefaultRemoveLogOnSuccess()
+{
+  return false;
+}
+
+
 //=======================================================================
 //function : DefaultVerboseLevel
 //=======================================================================
@@ -894,6 +993,15 @@ double GHS3DPlugin_Hypothesis::DefaultGradation()
   return 1.05;
 }
 
+//=======================================================================
+//function : DefaultStandardOutputLog
+//=======================================================================
+
+bool GHS3DPlugin_Hypothesis::DefaultStandardOutputLog()
+{
+  return false;
+}
+
 // //=======================================================================
 // //function : DefaultID2SizeMap
 // //=======================================================================
@@ -922,6 +1030,7 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
   save << (int)myToUseFemCorrection           << " ";
   save << (int)myToRemoveCentralPoint         << " ";
   save << myGradation                         << " ";
+  save << myToMakeGroupsOfDomains             << " ";
   if (!myTextOption.empty()) {
     save << "__OPTIONS_BEGIN__ ";
     save << myTextOption                      << " ";
@@ -953,7 +1062,7 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save)
       }
       if (enfVertex->coords.size()) {
         save << " " << "__BEGIN_COORDS__";
-        for (int i=0;i<enfVertex->coords.size();i++)
+        for ( size_t i = 0; i < enfVertex->coords.size(); i++ )
           save << " " << enfVertex->coords[i];
         save << " " << "__END_COORDS__";
       }
@@ -1009,31 +1118,31 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
   int i;
   double d;
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> i);
   if (isOK)
     myToMeshHoles = i;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> d);
   if (isOK)
-    myMaximumMemory = i;
+    myMaximumMemory = d;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> d);
   if (isOK)
-    myInitialMemory = i;
+    myInitialMemory = d;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> i);
   if (isOK)
     myOptimizationLevel = i;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> myWorkingDirectory);
+  isOK = static_cast<bool>(load >> myWorkingDirectory);
   if (isOK) {
     if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty
       myKeepFiles = false;
@@ -1048,44 +1157,44 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
     load.clear(ios::badbit | load.rdstate());
 
   if ( !myWorkingDirectory.empty() ) {
-    isOK = (load >> i);
+    isOK = static_cast<bool>(load >> i);
     if (isOK)
       myKeepFiles = i;
     else
       load.clear(ios::badbit | load.rdstate());
   }
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> i);
   if (isOK)
     myVerboseLevel = (short) i;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> i);
   if (isOK)
     myToCreateNewNodes = (bool) i;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> i);
   if (isOK)
     myToUseBoundaryRecoveryVersion = (bool) i;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> i);
   if (isOK)
     myToUseFemCorrection = (bool) i;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> i);
+  isOK = static_cast<bool>(load >> i);
   if (isOK)
     myToRemoveCentralPoint = (bool) i;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> d);
+  isOK = static_cast<bool>(load >> d);
   if (isOK)
     myGradation = d;
   else
@@ -1095,7 +1204,13 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
   bool hasOptions = false;
   bool hasEnforcedVertices = false;
   bool hasEnforcedMeshes = false;
-  isOK = (load >> separator);
+  isOK = static_cast<bool>(load >> separator);
+
+  if ( isOK && ( separator == "0" || separator == "1" ))
+  {
+    myToMakeGroupsOfDomains = ( separator == "1" );
+    isOK = static_cast<bool>(load >> separator);
+  }
 
   if (isOK) {
     if (separator == "__OPTIONS_BEGIN__")
@@ -1109,7 +1224,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
   if (hasOptions) {
     std::string txt;
     while (isOK) {
-      isOK = (load >> txt);
+      isOK = static_cast<bool>(load >> txt);
       if (isOK) {
         if (txt == "__OPTIONS_END__") {
           if (!myTextOption.empty()) {
@@ -1126,7 +1241,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
   }
 
   if (hasOptions) {
-    isOK = (load >> separator);
+    isOK = static_cast<bool>(load >> separator);
     if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__")
       hasEnforcedVertices = true;
     if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
@@ -1138,14 +1253,16 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
     double size, coords[3];
     bool isCompound;
     bool hasCoords = false;
-    isOK = (load >> txt);  // __BEGIN_VERTEX__
+    isOK = static_cast<bool>(load >> txt);  // __BEGIN_VERTEX__
     while (isOK) {
-      if (txt == "__ENFORCED_VERTICES_END__")
-        isOK = false;
-
+      if (txt == "__ENFORCED_VERTICES_END__") {
+        //isOK = false;
+        break;
+      }
+      
       TGHS3DEnforcedVertex *enfVertex = new TGHS3DEnforcedVertex();
       while (isOK) {
-        isOK = (load >> txt);
+        isOK = static_cast<bool>(load >> txt);
         if (txt == "__END_VERTEX__") {
           enfVertex->name = name;
           enfVertex->geomEntry = entry;
@@ -1171,7 +1288,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
 
         if (txt == "__BEGIN_NAME__") {  // __BEGIN_NAME__
           while (isOK && (txt != "__END_NAME__")) {
-            isOK = (load >> txt);
+            isOK = static_cast<bool>(load >> txt);
             if (txt != "__END_NAME__") {
               if (!name.empty())
                 name += " ";
@@ -1182,9 +1299,9 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
         }
 
         if (txt == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
-          isOK = (load >> entry);
-          isOK = (load >> isCompound);
-          isOK = (load >> txt); // __END_ENTRY__
+          isOK = static_cast<bool>(load >> entry);
+          isOK = static_cast<bool>(load >> isCompound);
+          isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
           if (txt != "__END_ENTRY__")
             throw std::exception();
           MESSAGE("entry: " << entry);
@@ -1192,7 +1309,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
 
         if (txt == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
           while (isOK && (txt != "__END_GROUP__")) {
-            isOK = (load >> txt);
+            isOK = static_cast<bool>(load >> txt);
             if (txt != "__END_GROUP__") {
               if (!groupName.empty())
                 groupName += " ";
@@ -1204,28 +1321,28 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
 
         if (txt == "__BEGIN_COORDS__") {  // __BEGIN_COORDS__
           hasCoords = true;
-          isOK = (load >> coords[0] >> coords[1] >> coords[2]);
-          isOK = (load >> txt); // __END_COORDS__
+          isOK = static_cast<bool>(load >> coords[0] >> coords[1] >> coords[2]);
+          isOK = static_cast<bool>(load >> txt); // __END_COORDS__
           if (txt != "__END_COORDS__")
             throw std::exception();
           MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]);
         }
 
         if (txt == "__BEGIN_SIZE__") {  // __BEGIN_ENTRY__
-          isOK = (load >> size);
-          isOK = (load >> txt); // __END_ENTRY__
+          isOK = static_cast<bool>(load >> size);
+          isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
           if (txt != "__END_SIZE__") {
             throw std::exception();
           }
           MESSAGE("size: " << size);
         }
       }
-      isOK = (load >> txt);  // __BEGIN_VERTEX__
+      isOK = static_cast<bool>(load >> txt);  // __BEGIN_VERTEX__
     }
   }
 
   if (hasEnforcedVertices) {
-    isOK = (load >> separator);
+    isOK = static_cast<bool>(load >> separator);
     if (isOK && separator == "__ENFORCED_MESHES_BEGIN__")
       hasEnforcedMeshes = true;
   }
@@ -1233,7 +1350,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
   if (hasEnforcedMeshes) {
     std::string txt, name, entry, groupName;
     int elementType = -1, persistID = -1;
-    isOK = (load >> txt);  // __BEGIN_ENF_MESH__
+    isOK = static_cast<bool>(load >> txt);  // __BEGIN_ENF_MESH__
     while (isOK) {
       //                if (isOK) {
       if (txt == "__ENFORCED_MESHES_END__")
@@ -1241,7 +1358,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
 
       TGHS3DEnforcedMesh *enfMesh = new TGHS3DEnforcedMesh();
       while (isOK) {
-        isOK = (load >> txt);
+        isOK = static_cast<bool>(load >> txt);
         if (txt == "__END_ENF_MESH__") {
           enfMesh->name = name;
           enfMesh->entry = entry;
@@ -1250,7 +1367,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
           enfMesh->persistID = persistID;
 
           _enfMeshList.insert(enfMesh);
-          std::cout << "Restoring of enforced mesh " <<name  << " done" << std::endl;
+          //std::cout << "Restoring of enforced mesh " <<name  << " done" << std::endl;
 
           name.clear();
           entry.clear();
@@ -1262,7 +1379,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
 
         if (txt == "__BEGIN_NAME__") {  // __BEGIN_NAME__
           while (isOK && (txt != "__END_NAME__")) {
-            isOK = (load >> txt);
+            isOK = static_cast<bool>(load >> txt);
             if (txt != "__END_NAME__") {
               if (!name.empty())
                 name += " ";
@@ -1273,16 +1390,16 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
         }
 
         if (txt == "__BEGIN_ENTRY__") {  // __BEGIN_ENTRY__
-          isOK = (load >> entry);
-          isOK = (load >> txt); // __END_ENTRY__
+          isOK = static_cast<bool>(load >> entry);
+          isOK = static_cast<bool>(load >> txt); // __END_ENTRY__
           if (txt != "__END_ENTRY__")
             throw std::exception();
           MESSAGE("entry: " << entry);
         }
 
         if (txt == "__BEGIN_ELEM_TYPE__") {  // __BEGIN_ELEM_TYPE__
-          isOK = (load >> elementType);
-          isOK = (load >> txt); // __END_ELEM_TYPE__
+          isOK = static_cast<bool>(load >> elementType);
+          isOK = static_cast<bool>(load >> txt); // __END_ELEM_TYPE__
           if (txt != "__END_ELEM_TYPE__")
             throw std::exception();
           MESSAGE("elementType: " << elementType);
@@ -1290,7 +1407,7 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
 
         if (txt == "__BEGIN_GROUP__") {  // __BEGIN_GROUP__
           while (isOK && (txt != "__END_GROUP__")) {
-            isOK = (load >> txt);
+            isOK = static_cast<bool>(load >> txt);
             if (txt != "__END_GROUP__") {
               if (!groupName.empty())
                 groupName += " ";
@@ -1301,13 +1418,13 @@ std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load)
         } // if
 
         if (txt == "__PERSIST_ID__") {
-          isOK = (load >> persistID);
+          isOK = static_cast<bool>(load >> persistID);
           MESSAGE("persistID: " << persistID);
         }
-        std::cout << "isOK: " << isOK << std::endl;
+        //std::cout << "isOK: " << isOK << std::endl;
       } // while
       //                } // if
-      isOK = (load >> txt);  // __BEGIN_ENF_MESH__
+      isOK = static_cast<bool>(load >> txt);  // __BEGIN_ENF_MESH__
     } // while
   } // if
 
@@ -1326,37 +1443,38 @@ bool GHS3DPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* ,const TopoDS
 
 //================================================================================
 /*!
- * \brief Return false
+ * \brief Sets myToMakeGroupsOfDomains depending on whether theMesh is on shape or not
  */
 //================================================================================
 
-bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
+bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
                                                      const SMESH_Mesh* /*theMesh*/)
 {
-  return false;
+  myToMakeGroupsOfDomains = ( !dflts._shape || dflts._shape->IsNull() );
+  return true;
 }
 
 //================================================================================
 /*!
- * \brief Return command to run ghs3d mesher excluding file prefix (-f)
+ * \brief Return command to run MG-Tetra mesher excluding file prefix (-f)
  */
 //================================================================================
 
 std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp,
-                                                 const bool         hasShapeToMesh)
+                                                 const bool                    hasShapeToMesh,
+                                                 const bool                    forExecutable)
 {
-  TCollection_AsciiString cmd;
-  cmd = "mg-tetra.exe";
+  std::string cmd = GetExeName();
   // check if any option is overridden by hyp->myTextOption
-  bool m   = hyp ? ( hyp->myTextOption.find("-m")  == std::string::npos ) : true;
-  bool M   = hyp ? ( hyp->myTextOption.find("-M")  == std::string::npos ) : true;
-  bool c   = hyp ? ( hyp->myTextOption.find("-c")  == std::string::npos ) : true;
-  bool o   = hyp ? ( hyp->myTextOption.find("-o")  == std::string::npos ) : true;
-  bool p0  = hyp ? ( hyp->myTextOption.find("-p0") == std::string::npos ) : true;
+  bool max_memory   = hyp ? ( hyp->myTextOption.find("--max_memory")  == std::string::npos ) : true;
+  bool auto_memory   = hyp ? ( hyp->myTextOption.find("--automatic_memory")  == std::string::npos ) : true;
+  bool comp   = hyp ? ( hyp->myTextOption.find("--components")  == std::string::npos ) : true;
+  bool optim_level   = hyp ? ( hyp->myTextOption.find("--optimisation_level")  == std::string::npos ) : true;
+  bool no_int_points  = hyp ? ( hyp->myTextOption.find("--no_internal_points") == std::string::npos ) : true;
   bool C   = hyp ? ( hyp->myTextOption.find("-C")  == std::string::npos ) : true;
-  bool v   = hyp ? ( hyp->myTextOption.find("-v")  == std::string::npos ) : true;
+  bool verbose   = hyp ? ( hyp->myTextOption.find("--verbose")  == std::string::npos ) : true;
   bool fem = hyp ? ( hyp->myTextOption.find("-FEM")== std::string::npos ) : true;
-  bool rem = hyp ? ( hyp->myTextOption.find("-no_initial_central_point")== std::string::npos ) : true;
+  bool rem = hyp ? ( hyp->myTextOption.find("--no_initial_central_point")== std::string::npos ) : true;
   bool gra = hyp ? ( hyp->myTextOption.find("-Dcpropa")== std::string::npos ) : true;
 
   // if use boundary recovery version, few options are allowed
@@ -1364,59 +1482,57 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h
   if ( !useBndRecovery && hyp )
     useBndRecovery = hyp->myToUseBoundaryRecoveryVersion;
 
-  // ghs3d needs to know amount of memory it may use (MB).
-  // Default memory is defined at ghs3d installation but it may be not enough,
+  // MG-Tetra needs to know amount of memory it may use (MB).
+  // Default memory is defined at MG-Tetra installation but it may be not enough,
   // so allow to use about all available memory
-  if ( m ) {
-    short aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
-    cmd += " -m ";
-    if ( aMaximumMemory < 0 )
-      cmd += DefaultMaximumMemory();
-    else
-      cmd += aMaximumMemory;
+  if ( max_memory ) {
+    float aMaximumMemory = hyp ? hyp->myMaximumMemory : -1;
+    cmd += " --max_memory ";
+    if ( aMaximumMemory < 0 ) cmd += SMESH_Comment( DefaultMaximumMemory() );
+    else                      cmd += SMESH_Comment( aMaximumMemory );
   }
-  if ( M && !useBndRecovery ) {
-    short aInitialMemory = hyp ? hyp->myInitialMemory : -1;
-    cmd += " -M ";
-    if ( aInitialMemory > 0 )
-      cmd += aInitialMemory;
-    else
-      cmd += "100";
+  if ( auto_memory && !useBndRecovery ) {
+    float aInitialMemory = hyp ? hyp->myInitialMemory : -1;
+    cmd += " --automatic_memory ";
+    if ( aInitialMemory > 0 ) cmd += SMESH_Comment( aInitialMemory );
+    else                      cmd += "100";
   }
   // component to mesh
-  // 0 , all components to be meshed
-  // 1 , only the main ( outermost ) component to be meshed
-  if ( c && !useBndRecovery ) {
-    // We always run GHS3D with "to mesh holes'==TRUE (see PAL19680)
+  if ( comp && !useBndRecovery ) {
+    // We always run MG-Tetra with "to mesh holes'==TRUE (see PAL19680)
     if ( hasShapeToMesh )
-      cmd += " -c 0";
+      cmd += " --components all";
     else {
       bool aToMeshHoles = hyp ? hyp->myToMeshHoles : DefaultMeshHoles();
-      if ( aToMeshHoles )
-        cmd += " -c 0";
-      else
-        cmd += " -c 1";
+      if ( aToMeshHoles ) cmd += " --components all";
+      else                cmd += " --components outside_components";
     }
   }
+  const bool toCreateNewNodes = ( no_int_points && ( !hyp || hyp->myToCreateNewNodes ));
 
   // optimization level
-  if ( o && hyp && !useBndRecovery ) {
+  if ( !toCreateNewNodes ) {
+    cmd += " --optimisation_level none"; // issue 22608
+  }
+  else if ( optim_level && hyp && !useBndRecovery ) {
     if ( hyp->myOptimizationLevel >= 0 && hyp->myOptimizationLevel < 5 ) {
       const char* level[] = { "none" , "light" , "standard" , "standard+" , "strong" };
-      cmd += " -o ";
+      cmd += " --optimisation_level ";
       cmd += level[ hyp->myOptimizationLevel ];
     }
   }
 
   // to create internal nodes
-  if ( p0 && hyp && !hyp->myToCreateNewNodes ) {
-    cmd += " -p0";
+  if ( no_int_points && !toCreateNewNodes ) {
+    if ( forExecutable )
+      cmd += " --no_internal_points";
+    else
+      cmd += " --internalpoints no";
   }
 
   // verbose mode
-  if ( v && hyp ) {
-    cmd += " -v ";
-    cmd += hyp->myVerboseLevel;
+  if ( verbose && hyp ) {
+    cmd += " --verbose " + SMESH_Comment( hyp->myVerboseLevel );
   }
 
   // boundary recovery version
@@ -1431,26 +1547,30 @@ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* h
 
   // to remove initial central point.
   if ( rem && hyp && hyp->myToRemoveCentralPoint) {
-    cmd += " -no_initial_central_point";
+    if ( forExecutable )
+      cmd += " --no_initial_central_point";
+    else
+      cmd += " --centralpoint no";
   }
 
   // options as text
   if ( hyp && !hyp->myTextOption.empty() ) {
-    cmd += " ";
-    cmd += (char*) hyp->myTextOption.c_str();
+    cmd += " " + hyp->myTextOption;
   }
 
   // to define volumic gradation.
-  if ( gra && hyp) {
-    cmd += " -Dcpropa=";
-    cmd += hyp->myGradation;
+  if ( gra && hyp ) {
+    if ( forExecutable )
+      cmd += " -Dcpropa=" + SMESH_Comment( hyp->myGradation );
+    else
+      cmd += " --gradation " + SMESH_Comment( hyp->myGradation );
   }
 
-#ifdef WNT
+#ifdef WIN32
   cmd += " < NUL";
 #endif
 
-  return cmd.ToCString();
+  return cmd;
 }
 
 //================================================================================
@@ -1478,6 +1598,16 @@ std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hy
   return aGenericName.ToCString();
 }
 
+//================================================================================
+/*
+ * Return the name of executable
+ */
+//================================================================================
+
+std::string GHS3DPlugin_Hypothesis::GetExeName()
+{
+  return "mg-tetra.exe";
+}
 
 //================================================================================
 /*!