Salome HOME
Revert "Merge branch 'yan/parallel_mesh2'"
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_Hypothesis.cxx
index 300c4cd3d2d7a40ce4776cfbbfab6a05bab216e2..28c9c6e87cee225d9056d64c79df44cd6cce7350 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -37,33 +37,40 @@ using namespace std;
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
-NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, int studyId,
-                                                  SMESH_Gen * gen)
-  : SMESH_Hypothesis(hypId, studyId, gen),
-    _maxSize         (GetDefaultMaxSize()),
-    _minSize         (0),
-    _growthRate      (GetDefaultGrowthRate()),
-    _nbSegPerEdge    (GetDefaultNbSegPerEdge()),
-    _nbSegPerRadius  (GetDefaultNbSegPerRadius()),
-    _fineness        (GetDefaultFineness()),
-    _secondOrder     (GetDefaultSecondOrder()),
-    _optimize        (GetDefaultOptimize()),
-    _localSize       (GetDefaultLocalSize()),
-    _quadAllowed     (GetDefaultQuadAllowed()),
-    _surfaceCurvature(GetDefaultSurfaceCurvature()),
-    _fuseEdges       (GetDefaultFuseEdges())
+NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, SMESH_Gen * gen)
+
+  : SMESH_Hypothesis(hypId, gen),
+    _fineness           (GetDefaultFineness()),
+    _secondOrder        (GetDefaultSecondOrder()),
+    _quadAllowed        (GetDefaultQuadAllowed()),
+    _maxSize            (GetDefaultMaxSize()),
+    _minSize            (0),
+    _growthRate         (GetDefaultGrowthRate()),
+    _nbSegPerRadius     (GetDefaultNbSegPerRadius()),
+    _nbSegPerEdge       (GetDefaultNbSegPerEdge()),
+    _chordalErrorEnabled(GetDefaultChordalError() > 0),
+    _chordalError       (GetDefaultChordalError() ),
+    _optimize           (GetDefaultOptimize()),
+    _nbSurfOptSteps     (GetDefaultNbSurfOptSteps()),
+    _nbVolOptSteps      (GetDefaultNbVolOptSteps()),
+    _elemSizeWeight     (GetDefaultElemSizeWeight()),
+    _worstElemMeasure   (GetDefaultWorstElemMeasure()),
+    _surfaceCurvature   (GetDefaultSurfaceCurvature()),
+    _useDelauney        (GetDefaultUseDelauney()),
+    _checkOverlapping   (GetDefaultCheckOverlapping()),
+    _checkChartBoundary (GetDefaultCheckChartBoundary()),
+    _fuseEdges          (GetDefaultFuseEdges())
 {
   _name = "NETGEN_Parameters";
   _param_algo_dim = 3;
-  _localSize.clear();
 }
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
@@ -208,6 +215,34 @@ void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
   }
 }
 
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::SetChordalErrorEnabled(bool theVal)
+{
+  if (theVal != _chordalErrorEnabled)
+  {
+    _chordalErrorEnabled = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::SetChordalError(double theVal)
+{
+  if (theVal != _chordalError)
+  {
+    _chordalError = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
 //=============================================================================
 /*!
  *  
@@ -252,11 +287,11 @@ void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
  *  
  */
 //=============================================================================
-void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
+void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName)
 {
-  if (theVal != _quadAllowed)
+  if ( fileName != _meshSizeFile )
   {
-    _quadAllowed = theVal;
+    _meshSizeFile = fileName;
     NotifySubMeshesHypothesisModification();
   }
 }
@@ -266,9 +301,13 @@ void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
  *  
  */
 //=============================================================================
-bool NETGENPlugin_Hypothesis::GetDefaultQuadAllowed()
+void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
 {
-  return false;
+  if (theVal != _quadAllowed)
+  {
+    _quadAllowed = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
 }
 
 //=============================================================================
@@ -285,16 +324,6 @@ void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
   }
 }
 
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-bool NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature()
-{
-  return true;
-}
-
 //=============================================================================
 /*!
  *
@@ -309,14 +338,102 @@ void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
   }
 }
 
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-bool NETGENPlugin_Hypothesis::GetDefaultFuseEdges()
+//=======================================================================
+//function : SetNbSurfOptSteps
+//purpose  : 
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetNbSurfOptSteps( int theVal )
 {
-  return true; // false; -- for SALOME_TESTS/Grids/smesh/3D_mesh_NETGEN_05/F6
+  if (theVal != _nbSurfOptSteps)
+  {
+    _nbSurfOptSteps = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetNbVolOptSteps
+//purpose  : 
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetNbVolOptSteps( int theVal )
+{
+  if (theVal != _nbVolOptSteps)
+  {
+    _nbVolOptSteps = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetElemSizeWeight
+//purpose  : 
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetElemSizeWeight( double theVal )
+{
+  if (theVal != _elemSizeWeight)
+  {
+    _elemSizeWeight = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetWorstElemMeasure
+//purpose  : 
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetWorstElemMeasure( int theVal )
+{
+  if (theVal != _worstElemMeasure)
+  {
+    _worstElemMeasure = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetUseDelauney
+//purpose  : 
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetUseDelauney( bool theVal )
+{
+  if (theVal != _useDelauney )
+  {
+    _useDelauney = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetCheckOverlapping
+//purpose  : 
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetCheckOverlapping( bool theVal )
+{
+  if (theVal != _checkOverlapping )
+  {
+    _checkOverlapping = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetCheckChartBoundary
+//purpose  : 
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetCheckChartBoundary( bool theVal )
+{
+  if (theVal != _checkChartBoundary)
+  {
+    _checkChartBoundary = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
 }
 
 //=============================================================================
@@ -337,8 +454,8 @@ ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
   if (it_sm != _localSize.end()) {
     save << " " << "__LOCALSIZE_BEGIN__";
     for ( ; it_sm != _localSize.end(); ++it_sm ) {
-        save << " " << it_sm->first
-             << " " << it_sm->second << "%#"; // "%#" is a mark of value end
+      save << " " << it_sm->first
+           << " " << it_sm->second << "%#"; // "%#" is a mark of value end
     }
     save << " " << "__LOCALSIZE_END__";
   }
@@ -347,6 +464,22 @@ ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
   save << " " << _surfaceCurvature;
   save << " " << _fuseEdges;
 
+  save << " " << _meshSizeFile.size() << " " << _meshSizeFile;
+
+  save << " " << ( _chordalErrorEnabled ? _chordalError : 0. );
+
+
+  // added for option set completion
+
+  save << " " << _nbSurfOptSteps;
+  save << " " << _nbVolOptSteps;
+  save << " " << _elemSizeWeight;
+  save << " " << _worstElemMeasure;
+
+  save << " " << _useDelauney;
+  save << " " << _checkOverlapping;
+  save << " " << _checkChartBoundary;
+
   return save;
 }
 
@@ -361,13 +494,13 @@ istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
   int is;
   double val;
 
-  isOK = (load >> val);
+  isOK = static_cast<bool>(load >> val);
   if (isOK)
     _maxSize = val;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> is);
+  isOK = static_cast<bool>(load >> is);
   if (isOK)
     SetFineness((Fineness) is);
   else
@@ -375,32 +508,32 @@ istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
 
   if (_fineness == UserDefined)
   {
-    isOK = (load >> val);
+    isOK = static_cast<bool>(load >> val);
     if (isOK)
       _growthRate = val;
     else
       load.clear(ios::badbit | load.rdstate());
 
-    isOK = (load >> val);
+    isOK = static_cast<bool>(load >> val);
     if (isOK)
       _nbSegPerEdge = val;
     else
       load.clear(ios::badbit | load.rdstate());
 
-    isOK = (load >> val);
+    isOK = static_cast<bool>(load >> val);
     if (isOK)
       _nbSegPerRadius = val;
     else
       load.clear(ios::badbit | load.rdstate());
   }
 
-  isOK = (load >> is);
+  isOK = static_cast<bool>(load >> is);
   if (isOK)
     _secondOrder = (bool) is;
   else
     load.clear(ios::badbit | load.rdstate());
 
-  isOK = (load >> is);
+  isOK = static_cast<bool>(load >> is);
   if (isOK)
     _optimize = (bool) is;
   else
@@ -409,18 +542,18 @@ istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
   std::string option_or_sm;
   bool hasLocalSize = false;
 
-  isOK = (load >> option_or_sm);
+  isOK = static_cast<bool>(load >> option_or_sm);
   if (isOK)
     if (option_or_sm == "__LOCALSIZE_BEGIN__")
       hasLocalSize = true;
 
   std::string smEntry, smValue;
   while (isOK && hasLocalSize) {
-    isOK = (load >> smEntry);
+    isOK = static_cast<bool>(load >> smEntry);
     if (isOK) {
       if (smEntry == "__LOCALSIZE_END__")
         break;
-      isOK = (load >> smValue);
+      isOK = static_cast<bool>(load >> smValue);
     }
     if (isOK) {
       std::istringstream tmp(smValue);
@@ -432,42 +565,74 @@ istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
 
   if ( !hasLocalSize && !option_or_sm.empty() )
     _minSize = atof( option_or_sm.c_str() );
+  else
+    load >> _minSize;
 
-  isOK = ( load >> _quadAllowed );
-  if ( !isOK )
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _quadAllowed = (bool) is;
+  else
     _quadAllowed = GetDefaultQuadAllowed();
 
-  isOK = ( load >> _surfaceCurvature );
-  if ( !isOK )
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _surfaceCurvature = (bool) is;
+  else
     _surfaceCurvature = GetDefaultSurfaceCurvature();
 
-  isOK = ( load >> _fuseEdges );
-  if ( !isOK )
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _fuseEdges = (bool) is;
+  else
     _fuseEdges = GetDefaultFuseEdges();
 
-  return load;
-}
+  isOK = static_cast<bool>( load >> is >> std::ws ); // size of meshSizeFile
+  if ( isOK && is > 0 )
+  {
+    _meshSizeFile.resize( is );
+    load.get( &_meshSizeFile[0], is+1 );
+  }
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
-{
-  return hyp.SaveTo( save );
-}
+  isOK = static_cast<bool>(load >> val);
+  if (isOK)
+    _chordalError = val;
+  else
+    load.clear(ios::badbit | load.rdstate());
+  _chordalErrorEnabled = ( _chordalError > 0 );
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
-{
-  return hyp.LoadFrom( load );
-}
 
+  // added for option set completion
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _nbSurfOptSteps = is;
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _nbVolOptSteps = is;
+
+  isOK = static_cast<bool>( load >> val );
+  if ( isOK )
+    _elemSizeWeight =  val;
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _worstElemMeasure = is;
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _useDelauney = (bool) is;
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _checkOverlapping = (bool) is;
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _checkChartBoundary = (bool) is;
+
+  return load;
+}
 
 //================================================================================
 /*!
@@ -477,8 +642,8 @@ istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
  * \retval bool - always false
  */
 //================================================================================
-bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
-                                                  const TopoDS_Shape& theShape)
+bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   /*theMesh*/,
+                                                  const TopoDS_Shape& /*theShape*/)
 {
   return false;
 }
@@ -501,75 +666,14 @@ bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
   else if ( theMesh && theMesh->HasShapeToMesh() )
     _minSize    = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
 
-  return _nbSegPerEdge && _maxSize > 0;
-}
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
-{
-  return 1000;
-}
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
-{
-  return Moderate;
-}
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
-{
-  return 0.3;
-}
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
-{
-  return 1;
-}
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
-{
-  return 2;
-}
-
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
-{
-  return false;
-}
+  if ( dflts._way == SMESH_Hypothesis::BY_AVERAGE_LENGTH )
+  {
+    _minSize      = dflts._elemLength / 100.;
+    _nbSegPerEdge = 1;
+    _chordalError = dflts._elemLength / 2.;
+    _chordalErrorEnabled = true;
+    _quadAllowed  = dflts._quadDominated;
+  }
 
-//=============================================================================
-/*!
- *  
- */
-//=============================================================================
-bool NETGENPlugin_Hypothesis::GetDefaultOptimize()
-{
-  return true;
+  return _nbSegPerEdge && _maxSize > 0;
 }