0022904: Clean up sccsid variables
[occt.git] / src / Expr / Expr_UnaryFunction.cxx
1 // Copyright:   Matra-Datavision 1991
2 // File:        Expr_UnaryFunction.cxx
3 // Created:     Tue May 28 14:40:33 1991
4 // Author:      Arnaud BOUZY
5 //              <adn>
6
7 #ifndef DEB
8 #define No_Standard_RangeError
9 #define No_Standard_OutOfRange
10 #endif
11
12 #include <Expr_UnaryFunction.ixx>
13 #include <Expr_InvalidFunction.hxx>
14 #include <Expr_Array1OfNamedUnknown.hxx>
15 #include <Expr_Array1OfGeneralExpression.hxx>
16 #include <Expr_FunctionDerivative.hxx>
17 #include <Expr_Product.hxx>
18 #include <Expr_Operators.hxx>
19 #include <Expr.hxx>
20
21 Expr_UnaryFunction::Expr_UnaryFunction (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_GeneralExpression)& exp)
22 {
23   if (func->NbOfVariables() != 1) {
24     Expr_InvalidFunction::Raise();
25   }
26   myFunction = func;
27   CreateOperand(exp);
28 }
29
30 Handle(Expr_GeneralFunction) Expr_UnaryFunction::Function () const
31 {
32   return myFunction;
33 }
34
35 Handle(Expr_GeneralExpression) Expr_UnaryFunction::ShallowSimplified () const
36 {
37   Handle(Expr_GeneralExpression) op = Operand();
38   if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
39     Handle(Expr_NumericValue) nval = Handle(Expr_NumericValue)::DownCast(op);
40     TColStd_Array1OfReal tabval(1,1);
41     tabval(1) = nval->GetValue();
42     Expr_Array1OfNamedUnknown vars(1,1);
43     vars(1) = myFunction->Variable(1);
44     Standard_Real res = myFunction->Evaluate(vars,tabval);
45     return new Expr_NumericValue(res);
46   }
47   Handle(Expr_UnaryFunction) me = this;
48   return me;
49 }
50
51 Handle(Expr_GeneralExpression) Expr_UnaryFunction::Copy () const
52 {
53   return new Expr_UnaryFunction(myFunction,Expr::CopyShare(Operand()));
54 }
55
56 Standard_Boolean Expr_UnaryFunction::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
57 {
58   if (!Other->IsKind(STANDARD_TYPE(Expr_UnaryFunction))) {
59     return Standard_False;
60   }
61   Handle(Expr_UnaryFunction) fother = Handle(Expr_UnaryFunction)::DownCast(Other);
62   Handle(Expr_GeneralExpression) otherexp = fother->Operand();
63   if (otherexp->IsIdentical(Operand())) {
64     if (myFunction->IsIdentical(fother->Function())) {
65       return Standard_True;
66     }
67   }
68   return Standard_False;
69 }
70
71 Standard_Boolean Expr_UnaryFunction::IsLinear () const
72 {
73   if (!ContainsUnknowns()) {
74     return Standard_True;
75   }
76   if (!Operand()->IsLinear()) {
77     return Standard_False;
78   }
79   return myFunction->IsLinearOnVariable(1);
80 }
81
82 Handle(Expr_GeneralExpression) Expr_UnaryFunction::Derivative (const Handle(Expr_NamedUnknown)& X) const
83 {
84   Handle(Expr_NamedUnknown) myvar = myFunction->Variable(1);
85   Handle(Expr_GeneralExpression) myop = Operand();
86   Handle(Expr_GeneralExpression) myexpder = myop->Derivative(X);
87   Handle(Expr_GeneralFunction) myfuncder = myFunction->Derivative(myvar);
88   Handle(Expr_UnaryFunction) firstpart = new Expr_UnaryFunction(myfuncder,Expr::CopyShare(myop));
89   Handle(Expr_Product) resu = firstpart->ShallowSimplified() * myexpder;
90   return resu->ShallowSimplified();
91 }
92
93 Standard_Real Expr_UnaryFunction::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
94 {
95   Expr_Array1OfNamedUnknown varsfunc(1,1);
96   varsfunc(1) = myFunction->Variable(1);
97   TColStd_Array1OfReal valsfunc(1,1);
98   valsfunc(1) = Operand()->Evaluate(vars,vals);
99   return myFunction->Evaluate(varsfunc,valsfunc);
100 }
101
102 TCollection_AsciiString Expr_UnaryFunction::String() const
103 {
104   TCollection_AsciiString res = myFunction->GetStringName();
105   res += "(";
106   res += Operand()->String();
107   res += ")";;
108   return res;
109 }