Salome HOME
0023299: [CEA] Finalize multi-study removal
[plugins/netgenplugin.git] / src / NETGENPlugin / NETGENPlugin_Hypothesis.cxx
index 75100b5ea4a11f21ee3ccd2bfce920b6a33b7e8d..5ec88e3e4b944e08709d5823b7d318d634f66a85 100644 (file)
@@ -1,31 +1,36 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  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.
+// 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, 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
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  NETGENPlugin : C++ implementation
 // File      : NETGENPlugin_Hypothesis.cxx
 // Author    : Michael Sazonov (OCN)
 // Date      : 28/03/2006
 // Project   : SALOME
 //
-#include <NETGENPlugin_Hypothesis.hxx>
+#include "NETGENPlugin_Hypothesis.hxx"
+
+#include "NETGENPlugin_Mesher.hxx"
+#include "SMESH_Mesh.hxx"
+
 #include <utilities.h>
 
 using namespace std;
@@ -35,19 +40,25 @@ using namespace std;
  *  
  */
 //=============================================================================
-NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, int studyId,
+NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId,
                                                   SMESH_Gen * gen)
-  : SMESH_Hypothesis(hypId, studyId, gen),
-    _maxSize       (GetDefaultMaxSize()),
-    _growthRate    (GetDefaultGrowthRate()),
-    _nbSegPerEdge  (GetDefaultNbSegPerEdge()),
-    _nbSegPerRadius(GetDefaultNbSegPerRadius()),
-    _fineness      (GetDefaultFineness()),
-    _secondOrder   (GetDefaultSecondOrder()),
-    _optimize      (GetDefaultOptimize())
+  : SMESH_Hypothesis(hypId, 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())
 {
   _name = "NETGEN_Parameters";
   _param_algo_dim = 3;
+  _localSize.clear();
 }
 
 //=============================================================================
@@ -64,6 +75,20 @@ void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
   }
 }
 
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
+{
+  if (theSize != _minSize)
+  {
+    _minSize = theSize;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
 //=============================================================================
 /*!
  *  
@@ -188,6 +213,131 @@ void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
  *  
  */
 //=============================================================================
+void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
+{
+  if(_localSize[entry] != localSize)
+  {
+    _localSize[entry] = localSize;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
+{
+  TLocalSize::iterator it  = _localSize.find( entry );
+  if ( it != _localSize.end() )
+    return it->second;
+  else
+    return -1.0;
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
+{
+  _localSize.erase(entry);
+  NotifySubMeshesHypothesisModification();
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName)
+{
+  if ( fileName != _meshSizeFile )
+  {
+    _meshSizeFile = fileName;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
+{
+  if (theVal != _quadAllowed)
+  {
+    _quadAllowed = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+bool NETGENPlugin_Hypothesis::GetDefaultQuadAllowed()
+{
+  return false;
+}
+
+//=============================================================================
+/*!
+ *  
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
+{
+  if (theVal != _surfaceCurvature)
+  {
+    _surfaceCurvature = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature()
+{
+  return true;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
+{
+  if (theVal != _fuseEdges)
+  {
+    _fuseEdges = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool NETGENPlugin_Hypothesis::GetDefaultFuseEdges()
+{
+  return true; // false; -- for SALOME_TESTS/Grids/smesh/3D_mesh_NETGEN_05/F6
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
 {
   save << _maxSize << " " << _fineness;
@@ -197,6 +347,22 @@ ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
 
   save << " " << (int)_secondOrder << " " << (int)_optimize;
 
+  TLocalSize::iterator it_sm  = _localSize.begin();
+  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 << " " << "__LOCALSIZE_END__";
+  }
+  save << " " << _minSize;
+  save << " " << _quadAllowed;
+  save << " " << _surfaceCurvature;
+  save << " " << _fuseEdges;
+
+  save << " " << _meshSizeFile.size() << " " << _meshSizeFile;
+
   return save;
 }
 
@@ -211,13 +377,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
@@ -225,36 +391,91 @@ 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
     load.clear(ios::badbit | load.rdstate());
+
+  std::string option_or_sm;
+  bool hasLocalSize = false;
+
+  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 = static_cast<bool>(load >> smEntry);
+    if (isOK) {
+      if (smEntry == "__LOCALSIZE_END__")
+        break;
+      isOK = static_cast<bool>(load >> smValue);
+    }
+    if (isOK) {
+      std::istringstream tmp(smValue);
+      double val;
+      tmp >> val;
+      _localSize[ smEntry ] = val;
+    }
+  }
+
+  if ( !hasLocalSize && !option_or_sm.empty() )
+    _minSize = atof( option_or_sm.c_str() );
+  else
+    load >> _minSize;
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _quadAllowed = (bool) is;
+  else
+    _quadAllowed = GetDefaultQuadAllowed();
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _surfaceCurvature = (bool) is;
+  else
+    _surfaceCurvature = GetDefaultSurfaceCurvature();
+
+  isOK = static_cast<bool>( load >> is );
+  if ( isOK )
+    _fuseEdges = (bool) is;
+  else
+    _fuseEdges = GetDefaultFuseEdges();
+
+  isOK = static_cast<bool>( load >> is >> std::ws ); // size of meshSizeFile
+  if ( isOK && is > 0 )
+  {
+    _meshSizeFile.resize( is );
+    load.get( &_meshSizeFile[0], is+1 );
+  }
+
   return load;
 }
 
@@ -301,10 +522,16 @@ bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   theMesh,
 //================================================================================
 
 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  dflts,
-                                                      const SMESH_Mesh* /*theMesh*/)
+                                                      const SMESH_Mesh* theMesh)
 {
   _nbSegPerEdge = dflts._nbSegments;
   _maxSize      = dflts._elemLength;
+
+  if ( dflts._shape && !dflts._shape->IsNull() )
+    _minSize    = NETGENPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
+  else if ( theMesh && theMesh->HasShapeToMesh() )
+    _minSize    = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
+
   return _nbSegPerEdge && _maxSize > 0;
 }