X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FStdMeshers%2FStdMeshers_NumberOfSegments.cxx;h=338f3ca525d34934e70aea6d54927f694ee2634a;hb=0eea513c934f0925f9b9ec6cc56892feafc04c0d;hp=cbc94485d45dcd276bb36a26ad9371cb92da51c1;hpb=120207d740662965e1ca6dfe8325d1e7edad0e73;p=modules%2Fsmesh.git diff --git a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx index cbc94485d..338f3ca52 100644 --- a/src/StdMeshers/StdMeshers_NumberOfSegments.cxx +++ b/src/StdMeshers/StdMeshers_NumberOfSegments.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2023 CEA, EDF, 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(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;