Salome HOME
Update of CheckDone
[modules/smesh.git] / src / StdMeshers / StdMeshers_CartesianParameters3D.cxx
index 60b9532d414aa6fe433e8295de49960f9cd47a9a..66256788b7cc1727776f2bccf32f8f2e3c92d129 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // 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
@@ -61,11 +61,15 @@ using namespace std;
 //=======================================================================
 
 StdMeshers_CartesianParameters3D::StdMeshers_CartesianParameters3D(int         hypId,
-                                                                   int         studyId,
                                                                    SMESH_Gen * gen)
-  : SMESH_Hypothesis(hypId, studyId, gen),
+  : SMESH_Hypothesis(hypId, gen),
     _sizeThreshold( 4.0 ), // default according to the customer specification
-    _toAddEdges( false )
+    _toAddEdges( false ),
+    _toConsiderInternalFaces( false ),
+    _toUseThresholdForInternalFaces( false ),
+    _toCreateFaces( false ),
+    _toUseQuanta(false),
+    _quanta(0.01)
 {
   _name = "CartesianParameters3D"; // used by "Cartesian_3D"
   _param_algo_dim = 3; // 3D
@@ -131,7 +135,6 @@ namespace
   void checkGridSpacing(std::vector<std::string>& spaceFunctions,
                         std::vector<double>&      internalPoints,
                         const std::string&        axis)
-    throw ( SALOME_Exception )
   {
     if ( spaceFunctions.empty() )
       throw SALOME_Exception(SMESH_Comment("Empty space function for ") << axis );
@@ -168,7 +171,6 @@ namespace
 //=======================================================================
 
 void StdMeshers_CartesianParameters3D::SetGrid(std::vector<double>& coords, int axis)
-  throw ( SALOME_Exception )
 {
   checkAxis( axis );
 
@@ -196,7 +198,6 @@ void StdMeshers_CartesianParameters3D::SetGrid(std::vector<double>& coords, int
 void StdMeshers_CartesianParameters3D::SetGridSpacing(std::vector<string>& xSpaceFuns,
                                                       std::vector<double>& xInternalPoints,
                                                       const int            axis)
-  throw ( SALOME_Exception )
 {
   checkAxis( axis );
 
@@ -240,6 +241,7 @@ bool StdMeshers_CartesianParameters3D::GetFixedPoint(double p[3]) const
   if ( Precision::IsInfinite( _fixedPoint[0] ))
     return false;
   std::copy( &_fixedPoint[0], &_fixedPoint[0]+3, &p[0] );
+  return true;
 }
 
 
@@ -249,7 +251,6 @@ bool StdMeshers_CartesianParameters3D::GetFixedPoint(double p[3]) const
 //=======================================================================
 
 void StdMeshers_CartesianParameters3D::SetSizeThreshold(const double threshold)
-  throw ( SALOME_Exception )
 {
   if ( threshold <= 1.0 )
     throw SALOME_Exception(LOCALIZED("threshold must be > 1.0"));
@@ -269,7 +270,6 @@ void StdMeshers_CartesianParameters3D::SetSizeThreshold(const double threshold)
 void StdMeshers_CartesianParameters3D::GetGridSpacing(std::vector<std::string>& spaceFunctions,
                                                       std::vector<double>&      internalPoints,
                                                       const int                 axis) const
-  throw ( SALOME_Exception )
 {
   if ( !IsGridBySpacing(axis) )
     throw SALOME_Exception(LOCALIZED("The grid is defined by coordinates and not by spacing"));
@@ -283,7 +283,6 @@ void StdMeshers_CartesianParameters3D::GetGridSpacing(std::vector<std::string>&
 //=======================================================================
 
 bool StdMeshers_CartesianParameters3D::IsGridBySpacing(const int axis) const
-  throw ( SALOME_Exception )
 {
   checkAxis(axis);
   return !_spaceFunctions[axis].empty();
@@ -302,7 +301,6 @@ void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double    x0,
                                                           vector<double>& coords,
                                                           const string&   axis,
                                                           const double*   xForced )
-  throw ( SALOME_Exception )
 {
   checkGridSpacing( theSpaceFuns, thePoints, axis );
 
@@ -329,19 +327,19 @@ void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double    x0,
   coords.clear();
   for ( size_t i = 0; i < spaceFuns.size(); ++i )
   {
-    FunctionExpr fun( spaceFuns[i].c_str(), /*convMode=*/-1 );
+    StdMeshers::FunctionExpr fun( spaceFuns[i].c_str(), /*convMode=*/-1 );
 
     const double p0 = x0 * ( 1. - points[i])   + x1 * points[i];
     const double p1 = x0 * ( 1. - points[i+1]) + x1 * points[i+1];
     const double length = p1 - p0;
 
-    const size_t nbSections = 1000;
+    const int    nbSections = 1000;
     const double sectionLen = ( p1 - p0 ) / nbSections;
     vector< double > nbSegments( nbSections + 1 );
     nbSegments[ 0 ] = 0.;
 
     double t, spacing = 0;
-    for ( size_t i = 1; i <= nbSections; ++i )
+    for ( int i = 1; i <= nbSections; ++i )
     {
       t = double( i ) / nbSections;
       if ( !fun.value( t, spacing ) || spacing < std::numeric_limits<double>::min() )
@@ -354,11 +352,11 @@ void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double    x0,
 
     if ( coords.empty() ) coords.push_back( p0 );
 
-    for ( size_t iCell = 1, i = 1; i <= nbSections; ++i )
+    for ( int iCell = 1, j = 1; j <= nbSections; ++j )
     {
-      if ( nbSegments[i]*corr >= iCell )
+      if ( nbSegments[j]*corr >= iCell )
       {
-        t = (i - ( nbSegments[i] - iCell/corr )/( nbSegments[i] - nbSegments[i-1] )) / nbSections;
+        t = (j - ( nbSegments[j] - iCell/corr )/( nbSegments[j] - nbSegments[j-1] )) / nbSections;
         coords.push_back( p0 + t * length );
         ++iCell;
       }
@@ -371,7 +369,7 @@ void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double    x0,
   // correct coords if a forced point is too close to a neighbor node
   if ( forced )
   {
-    int iF = 0;
+    size_t iF = 0;
     double minLen = ( x1 - x0 );
     for ( size_t i = 1; i < coords.size(); ++i )
     {
@@ -383,9 +381,9 @@ void StdMeshers_CartesianParameters3D::ComputeCoordinates(const double    x0,
     const double tol = minLen * 1e-3;
     int iRem = -1;
     if (( iF > 1 ) && ( coords[iF] - coords[iF-1] < tol ))
-      iRem = iF-1;
+      iRem = (int) iF-1;
     else if (( iF < coords.size()-2 ) && ( coords[iF+1] - coords[iF] < tol ))
-      iRem = iF+1;
+      iRem = (int) iF+1;
     if ( iRem > 0 )
       coords.erase( coords.begin() + iRem );
   }
@@ -401,7 +399,6 @@ void StdMeshers_CartesianParameters3D::GetCoordinates(std::vector<double>& xNode
                                                       std::vector<double>& yNodes,
                                                       std::vector<double>& zNodes,
                                                       const Bnd_Box&       bndBox) const
-  throw ( SALOME_Exception )
 {
   double x0,y0,z0, x1,y1,z1;
   if ( IsGridBySpacing(0) || IsGridBySpacing(1) || IsGridBySpacing(2))
@@ -522,9 +519,8 @@ ComputeOptimalAxesDirs(const TopoDS_Shape& shape,
   const TCooTriple*           norm1 = 0;
   double                      sumArea = 0;
   vector< const TCooTriple* > norms;
-  for ( int iF = 1; norm2a != areasByNormal.end(); ++norm2a, ++iF )
+  for ( size_t iF = 1; norm2a != areasByNormal.end(); ++norm2a, ++iF )
   {
-
     if ( !norm1 || !sameDir( *norm1, norm2a->first ))
     {
       if ( !norms.empty() )
@@ -653,7 +649,6 @@ ComputeOptimalAxesDirs(const TopoDS_Shape& shape,
 //=======================================================================
 
 void StdMeshers_CartesianParameters3D::SetAxisDirs(const double* the9DirComps)
-  throw ( SALOME_Exception )
 {
   gp_Vec x( the9DirComps[0],
             the9DirComps[1],
@@ -695,7 +690,6 @@ void StdMeshers_CartesianParameters3D::SetAxisDirs(const double* the9DirComps)
 //=======================================================================
 
 void StdMeshers_CartesianParameters3D::GetGrid(std::vector<double>& coords, int axis) const
-  throw ( SALOME_Exception )
 {
   if ( IsGridBySpacing(axis) )
     throw SALOME_Exception(LOCALIZED("The grid is defined by spacing and not by coordinates"));
@@ -740,6 +734,79 @@ bool StdMeshers_CartesianParameters3D::GetToAddEdges() const
   return _toAddEdges;
 }
 
+//=======================================================================
+//function : SetToConsiderInternalFaces
+//purpose  : Enables treatment of geom faces either shared by solids or internal
+//=======================================================================
+
+void StdMeshers_CartesianParameters3D::SetToConsiderInternalFaces(bool toTreat)
+{
+  if ( _toConsiderInternalFaces != toTreat )
+  {
+    _toConsiderInternalFaces = toTreat;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetToUseThresholdForInternalFaces
+//purpose  : Enables applying size threshold to grid cells cut by internal geom faces.
+//=======================================================================
+
+void StdMeshers_CartesianParameters3D::SetToUseThresholdForInternalFaces(bool toUse)
+{
+  if ( _toUseThresholdForInternalFaces != toUse )
+  {
+    _toUseThresholdForInternalFaces = toUse;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetToCreateFaces
+//purpose  : Enables creation of mesh faces.
+//=======================================================================
+
+void StdMeshers_CartesianParameters3D::SetToCreateFaces(bool toCreate)
+{
+  if ( _toCreateFaces != toCreate )
+  {
+    _toCreateFaces = toCreate;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetToUseQuanta
+//purpose  : Enables use of quanta
+//=======================================================================
+
+void StdMeshers_CartesianParameters3D::SetToUseQuanta(bool toUseQuanta)
+{
+  if ( _toUseQuanta != toUseQuanta )
+  {
+    _toUseQuanta = toUseQuanta;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
+//=======================================================================
+//function : SetQuanta
+//purpose  : Set size quanta value
+//=======================================================================
+
+void StdMeshers_CartesianParameters3D::SetQuanta(const double quanta)
+{
+  if ( quanta < 1e-6 || quanta > 1.0 )
+    throw SALOME_Exception(LOCALIZED("Quanta must be in the range [0.01,1] "));
+
+  bool changed = (_quanta != quanta); 
+  _quanta = quanta;
+  
+  if ( changed )
+    NotifySubMeshesHypothesisModification();
+}
+
 //=======================================================================
 //function : IsDefined
 //purpose  : Return true if parameters are well defined
@@ -787,63 +854,78 @@ std::ostream & StdMeshers_CartesianParameters3D::SaveTo(std::ostream & save)
   for ( int i = 0; i < 3; ++i )
     save << _fixedPoint[i] << " ";
 
+  save << " " << _toConsiderInternalFaces
+       << " " << _toUseThresholdForInternalFaces
+       << " " << _toCreateFaces
+       << " " << _toUseQuanta
+       << " " << _quanta;
+
   return save;
 }
 
 //=======================================================================
 //function : LoadFrom
-//purpose  : resore my parameters from a stream
+//purpose  : restore my parameters from a stream
 //=======================================================================
 
 std::istream & StdMeshers_CartesianParameters3D::LoadFrom(std::istream & load)
 {
   bool ok;
 
-  ok = ( load >> _sizeThreshold );
+  ok = static_cast<bool>( load >> _sizeThreshold );
   for ( int ax = 0; ax < 3; ++ax )
   {
     if (ok)
     {
       size_t i = 0;
-      ok = (load >> i  );
+      ok = static_cast<bool>(load >> i  );
       if ( i > 0 && ok )
       {
         _coords[ax].resize( i );
         for ( i = 0; i < _coords[ax].size() && ok; ++i )
-          ok = (load >> _coords[ax][i]  );
+          ok = static_cast<bool>(load >> _coords[ax][i]  );
       }
     }
     if (ok)
     {
       size_t i = 0;
-      ok = (load >> i  );
+      ok = static_cast<bool>(load >> i  );
       if ( i > 0 && ok )
       {
         _internalPoints[ax].resize( i );
         for ( i = 0; i < _internalPoints[ax].size() && ok; ++i )
-          ok = (load >> _internalPoints[ax][i]  );
+          ok = static_cast<bool>(load >> _internalPoints[ax][i]  );
       }
     }
     if (ok)
     {
       size_t i = 0;
-      ok = (load >> i  );
+      ok = static_cast<bool>(load >> i  );
       if ( i > 0 && ok )
       {
         _spaceFunctions[ax].resize( i );
         for ( i = 0; i < _spaceFunctions[ax].size() && ok; ++i )
-          ok = (load >> _spaceFunctions[ax][i]  );
+          ok = static_cast<bool>(load >> _spaceFunctions[ax][i]  );
       }
     }
   }
 
-  ok = ( load >> _toAddEdges );
+  ok = static_cast<bool>( load >> _toAddEdges );
 
   for ( int i = 0; i < 9 && ok; ++i )
-    ok = ( load >> _axisDirs[i]);
+    ok = static_cast<bool>( load >> _axisDirs[i]);
 
   for ( int i = 0; i < 3 && ok ; ++i )
-    ok = ( load >> _fixedPoint[i]);
+    ok = static_cast<bool>( load >> _fixedPoint[i]);
+
+  if ( load >> _toConsiderInternalFaces )
+  {
+    load >> _toUseThresholdForInternalFaces;
+    load >> _toCreateFaces;
+  }
+
+  if ( load >> _toUseQuanta )
+    load >> _quanta;
 
   return load;
 }