Salome HOME
Porting to OCCT 7.8.0
[modules/smesh.git] / src / StdMeshers / StdMeshers_NumberOfSegments.cxx
index c63861614d5dc0df39415aac5735d38ad79e861d..338f3ca525d34934e70aea6d54927f694ee2634a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2021  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
@@ -109,9 +109,9 @@ StdMeshers_NumberOfSegments::BuildDistributionTab( const vector<double>& tab,
  */
 //=============================================================================
 
-void StdMeshers_NumberOfSegments::SetNumberOfSegments(int segmentsNumber)
+void StdMeshers_NumberOfSegments::SetNumberOfSegments(smIdType segmentsNumber)
 {
-  int oldNumberOfSegments = _numberOfSegments;
+  smIdType oldNumberOfSegments = _numberOfSegments;
   if (segmentsNumber <= 0)
     throw SALOME_Exception(LOCALIZED("number of segments must be positive"));
   _numberOfSegments = segmentsNumber;
@@ -126,7 +126,7 @@ void StdMeshers_NumberOfSegments::SetNumberOfSegments(int segmentsNumber)
  */
 //=============================================================================
 
-int StdMeshers_NumberOfSegments::GetNumberOfSegments() const
+smIdType StdMeshers_NumberOfSegments::GetNumberOfSegments() const
 {
   return _numberOfSegments;
 }
@@ -139,7 +139,7 @@ int StdMeshers_NumberOfSegments::GetNumberOfSegments() const
 
 void StdMeshers_NumberOfSegments::SetDistrType(DistrType typ)
 {
-  if (typ < DT_Regular || typ > DT_ExprFunc)
+  if (!IsValidDistrType(typ))
     throw SALOME_Exception(LOCALIZED("distribution type is out of range"));
 
   if (typ != _distrType)
@@ -166,6 +166,18 @@ StdMeshers_NumberOfSegments::DistrType StdMeshers_NumberOfSegments::GetDistrType
  */
 //================================================================================
 
+bool StdMeshers_NumberOfSegments::IsValidDistrType(int distrType) const
+{
+  // DistrType is sequential, so we can just check against its first and last values 
+  return distrType >= DT_Regular && distrType <= DT_BetaLaw;
+}
+
+//================================================================================
+/*!
+ * 
+ */
+//================================================================================
+
 void StdMeshers_NumberOfSegments::SetScaleFactor(double scaleFactor)
 {
   if (scaleFactor < PRECISION)
@@ -198,6 +210,43 @@ double StdMeshers_NumberOfSegments::GetScaleFactor() const
   return _scaleFactor;
 }
 
+//================================================================================
+/*!
+ * 
+ */
+//================================================================================
+
+void StdMeshers_NumberOfSegments::SetBeta(double beta)
+{
+  if (_distrType != DT_BetaLaw)
+    throw SALOME_Exception(LOCALIZED("not a Beta Law distribution"));
+
+  const double diff = fabs(fabs(_beta) - fabs(beta));
+  if (diff <= PRECISION)
+  {
+    // Check for a special case where we have values with
+    // equal base but opposite signs like -1.01 and 1.01
+    if (std::signbit(_beta) == std::signbit(beta))
+      return;
+  }
+
+  _beta = beta;
+  NotifySubMeshesHypothesisModification();
+}
+
+//================================================================================
+/*!
+ *
+ */
+//================================================================================
+
+double StdMeshers_NumberOfSegments::GetBeta() const
+{
+  if (_distrType != DT_BetaLaw)
+    throw SALOME_Exception(LOCALIZED("not a Beta Law distribution"));
+  return _beta;
+}
+
 //================================================================================
 /*!
  *
@@ -477,7 +526,7 @@ int StdMeshers_NumberOfSegments::ConversionMode() const
 
 ostream & StdMeshers_NumberOfSegments::SaveTo(ostream & save)
 {
-  int listSize = _edgeIDs.size();
+  size_t listSize = _edgeIDs.size();
   save << _numberOfSegments << " " << (int)_distrType;
   switch (_distrType)
   {
@@ -492,6 +541,9 @@ ostream & StdMeshers_NumberOfSegments::SaveTo(ostream & save)
   case DT_ExprFunc:
     save << " " << _func;
     break;
+  case DT_BetaLaw:
+    save << " " << _beta;
+    break;
   case DT_Regular:
   default:
     break;
@@ -502,7 +554,7 @@ ostream & StdMeshers_NumberOfSegments::SaveTo(ostream & save)
 
   if ( _distrType != DT_Regular && listSize > 0 ) {
     save << " " << listSize;
-    for ( int i = 0; i < listSize; i++ )
+    for ( size_t i = 0; i < listSize; i++ )
       save << " " << _edgeIDs[i];
     save << " " << _objEntry;
   }
@@ -542,7 +594,7 @@ istream & StdMeshers_NumberOfSegments::LoadFrom(istream & load)
   // supposing that this hypothesis was written in the new format
   if (isOK)
   {
-    if (a < DT_Regular || a > DT_ExprFunc)
+    if (!IsValidDistrType(a))
       _distrType = DT_Regular;
     else
       _distrType = (DistrType) a;
@@ -607,6 +659,22 @@ istream & StdMeshers_NumberOfSegments::LoadFrom(istream & load)
       }
     }
     break;
+
+  case DT_BetaLaw:
+    {
+      isOK = static_cast<bool>(load >> b);
+      if (isOK)
+        _beta = b;
+      else
+      {
+        load.clear(ios::badbit | load.rdstate());
+        // this can mean, that the hypothesis is stored in old format
+        _distrType = DT_Regular;
+        _scaleFactor = scale_factor;
+      }
+    }
+    break;
+
   case DT_Regular:
   default:
     break;