1 // Created on: 1991-06-26
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
19 #include <Expr_FunctionDerivative.hxx>
20 #include <Expr_GeneralFunction.hxx>
21 #include <Expr_NamedFunction.hxx>
22 #include <Expr_NamedUnknown.hxx>
23 #include <Expr_NumericValue.hxx>
24 #include <Standard_OutOfRange.hxx>
25 #include <Standard_Type.hxx>
26 #include <TCollection_AsciiString.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(Expr_NamedFunction,Expr_GeneralFunction)
30 Expr_NamedFunction::Expr_NamedFunction (const TCollection_AsciiString& name, const Handle(Expr_GeneralExpression)& exp, const Expr_Array1OfNamedUnknown& vars) :
31 myVariables(vars.Lower(),vars.Upper())
38 void Expr_NamedFunction::SetName(const TCollection_AsciiString& newname)
43 TCollection_AsciiString Expr_NamedFunction::GetName () const
48 Standard_Integer Expr_NamedFunction::NbOfVariables () const
50 return myVariables.Length();
53 Handle(Expr_NamedUnknown) Expr_NamedFunction::Variable (const Standard_Integer index) const
55 return myVariables(index);
58 Standard_Real Expr_NamedFunction::Evaluate (const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& values) const
60 if (vars.Length() != values.Length()) {
61 throw Standard_OutOfRange();
63 return myExp->Evaluate(vars,values);
67 Handle(Expr_GeneralFunction) Expr_NamedFunction::Copy () const
69 return new Expr_NamedFunction(myName,Expr::CopyShare(Expression()),myVariables);
72 Handle(Expr_GeneralFunction) Expr_NamedFunction::Derivative(const Handle(Expr_NamedUnknown)& var) const
74 Handle(Expr_NamedFunction) me = this;
75 return new Expr_FunctionDerivative(me,var,1);
78 Handle(Expr_GeneralFunction) Expr_NamedFunction::Derivative(const Handle(Expr_NamedUnknown)& var, const Standard_Integer deg) const
80 Handle(Expr_NamedFunction) me = this;
81 return new Expr_FunctionDerivative(me,var,deg);
84 Standard_Boolean Expr_NamedFunction::IsIdentical (const Handle(Expr_GeneralFunction)& func) const
86 if (!func->IsKind(STANDARD_TYPE(Expr_NamedFunction))) {
87 return Standard_False;
89 if (myName != Handle(Expr_NamedFunction)::DownCast(func)->GetName()) {
90 return Standard_False;
92 Standard_Integer nbvars = NbOfVariables();
93 if (nbvars != func->NbOfVariables()) {
94 return Standard_False;
96 Handle(Expr_NamedUnknown) thisvar;
97 for (Standard_Integer i =1; i<=nbvars; i++) {
98 thisvar = Variable(i);
99 if (!thisvar->IsIdentical(func->Variable(i))) {
100 return Standard_False;
103 if (!Expression()->IsIdentical(Handle(Expr_NamedFunction)::DownCast(func)->Expression())) {
104 return Standard_False;
106 return Standard_True;
109 Standard_Boolean Expr_NamedFunction::IsLinearOnVariable(const Standard_Integer) const
111 // bad implementation, should be improved
112 return myExp->IsLinear();
115 TCollection_AsciiString Expr_NamedFunction::GetStringName() const
120 Handle(Expr_GeneralExpression) Expr_NamedFunction::Expression() const
125 void Expr_NamedFunction::SetExpression(const Handle(Expr_GeneralExpression)& anexp)