Salome HOME
Porting to OCCT 7.8.0
[modules/smesh.git] / src / StdMeshers / StdMeshers_NumberOfSegments.cxx
index 16fb3224d1d4e51a242f82e066c3c06527a9116c..338f3ca525d34934e70aea6d54927f694ee2634a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2022  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
@@ -139,7 +139,7 @@ smIdType 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;
+}
+
 //================================================================================
 /*!
  *
@@ -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;
@@ -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;