+ Handle( Expr_NamedUnknown ) sub = Handle( Expr_NamedUnknown )::DownCast( expr );
+ if( !sub.IsNull() )
+ return sub->GetName()=="t";
+
+ bool res = true;
+ for( int i=1, n=expr->NbSubExpressions(); i<=n && res; i++ )
+ {
+ Handle( Expr_GeneralExpression ) sub = expr->SubExpression( i );
+ Handle( Expr_NamedUnknown ) name = Handle( Expr_NamedUnknown )::DownCast( sub );
+ if( !name.IsNull() )
+ {
+ if( name->GetName()!="t" )
+ res = false;
+ }
+ else
+ res = isCorrectArg( sub );
+ }
+ return res;
+}
+
+//================================================================================
+/*! this function parses the expression 'str' in order to check if syntax is correct
+ * ( result in 'syntax' ) and if only 't' is unknown variable in expression ( result in 'args' )
+ */
+//================================================================================
+bool process( const TCollection_AsciiString& str, int convMode,
+ bool& syntax, bool& args,
+ bool& non_neg, bool& non_zero,
+ bool& singulars, double& sing_point )
+{
+ // Set "C" numeric locale to save numbers correctly
+ std::string aCurLocale = setlocale(LC_NUMERIC, 0);
+ setlocale(LC_NUMERIC, "C");
+
+ bool parsed_ok = true;
+ Handle( ExprIntrp_GenExp ) myExpr;
+ try {
+#ifdef NO_CAS_CATCH
+ OCC_CATCH_SIGNALS;
+#endif
+ myExpr = ExprIntrp_GenExp::Create();
+ myExpr->Process( str.ToCString() );
+ } catch(Standard_Failure) {
+ Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+ parsed_ok = false;
+ }
+
+ syntax = false;
+ args = false;
+ if( parsed_ok && myExpr->IsDone() )
+ {
+ syntax = true;
+ args = isCorrectArg( myExpr->Expression() );
+ }
+
+ bool res = parsed_ok && syntax && args;
+ if( !res )
+ myExpr.Nullify();
+
+ non_neg = true;
+ singulars = false;
+ non_zero = false;
+
+ if( res )
+ {
+ FunctionExpr f( str.ToCString(), convMode );
+ const int max = 500;
+ for( int i=0; i<=max; i++ )
+ {
+ double t = double(i)/double(max), val;
+ if( !f.value( t, val ) )
+ {
+ sing_point = t;
+ singulars = true;
+ break;
+ }
+ if( val<0 )
+ {
+ non_neg = false;
+ break;
+ }
+ if( val>PRECISION )
+ non_zero = true;
+ }
+ }
+
+ // Return previous locale
+ setlocale(LC_NUMERIC, aCurLocale.data());
+
+ return res && non_neg && non_zero && ( !singulars );
+}
+
+//================================================================================
+/*!
+ *
+ */
+//================================================================================
+
+void StdMeshers_NumberOfSegments::SetExpressionFunction(const char* expr)
+ throw(SALOME_Exception)
+{
+ if (_distrType != DT_ExprFunc)
+ _distrType = DT_ExprFunc;
+ //throw SALOME_Exception(LOCALIZED("not an expression function distribution"));
+
+ // remove white spaces
+ TCollection_AsciiString str((Standard_CString)expr);
+ str.RemoveAll(' ');
+ str.RemoveAll('\t');
+ str.RemoveAll('\r');
+ str.RemoveAll('\n');
+
+ bool syntax, args, non_neg, singulars, non_zero;
+ double sing_point;
+ bool res = process( str, _convMode, syntax, args, non_neg, non_zero, singulars, sing_point );
+ if( !res )
+ {
+ if( !syntax )
+ throw SALOME_Exception(LOCALIZED("invalid expression syntax"));
+ if( !args )
+ throw SALOME_Exception(LOCALIZED("only 't' may be used as function argument"));
+ if( !non_neg )
+ throw SALOME_Exception(LOCALIZED("only non-negative function can be used as density"));
+ if( singulars )
+ {
+ char buf[1024];
+ sprintf( buf, "Function has singular point in %.3f", sing_point );
+ throw SALOME_Exception( buf );
+ }
+ if( !non_zero )
+ throw SALOME_Exception(LOCALIZED("f(t)=0 cannot be used as density"));
+
+ return;
+ }
+
+ string func = expr;
+ if( _func != func )
+ {
+ _func = func;
+ NotifySubMeshesHypothesisModification();
+ }
+}
+
+//================================================================================
+/*!
+ *
+ */
+//================================================================================
+
+const char* StdMeshers_NumberOfSegments::GetExpressionFunction() const
+ throw(SALOME_Exception)
+{
+ if (_distrType != DT_ExprFunc)
+ throw SALOME_Exception(LOCALIZED("not an expression function distribution"));
+ return _func.c_str();
+}
+
+//================================================================================
+/*!
+ *
+ */
+//================================================================================
+
+void StdMeshers_NumberOfSegments::SetConversionMode( int conv )
+ throw(SALOME_Exception)
+{
+// if (_distrType != DT_TabFunc && _distrType != DT_ExprFunc)
+// throw SALOME_Exception(LOCALIZED("not a functional distribution"));
+
+ if( conv != _convMode )
+ {
+ _convMode = conv;
+ NotifySubMeshesHypothesisModification();
+ }
+}
+
+//================================================================================
+/*!
+ *
+ */
+//================================================================================
+
+int StdMeshers_NumberOfSegments::ConversionMode() const
+ throw(SALOME_Exception)
+{
+// if (_distrType != DT_TabFunc && _distrType != DT_ExprFunc)
+// throw SALOME_Exception(LOCALIZED("not a functional distribution"));
+ return _convMode;