0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / Expr / Expr_UnaryFunction.cxx
CommitLineData
b311480e 1// Created on: 1991-05-28
2// Created by: Arnaud BOUZY
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
0797d9d3 17#ifndef OCCT_DEBUG
7fd59977 18#define No_Standard_RangeError
19#define No_Standard_OutOfRange
20#endif
21
42cf5bc1 22
23#include <Expr.hxx>
7fd59977 24#include <Expr_Array1OfGeneralExpression.hxx>
42cf5bc1 25#include <Expr_Array1OfNamedUnknown.hxx>
7fd59977 26#include <Expr_FunctionDerivative.hxx>
42cf5bc1 27#include <Expr_GeneralExpression.hxx>
28#include <Expr_GeneralFunction.hxx>
29#include <Expr_InvalidFunction.hxx>
30#include <Expr_NamedUnknown.hxx>
42cf5bc1 31#include <Expr_Operators.hxx>
32#include <Expr_Product.hxx>
33#include <Expr_UnaryFunction.hxx>
42cf5bc1 34#include <Standard_Type.hxx>
35#include <TCollection_AsciiString.hxx>
7fd59977 36
92efcf78 37IMPLEMENT_STANDARD_RTTIEXT(Expr_UnaryFunction,Expr_UnaryExpression)
38
7fd59977 39Expr_UnaryFunction::Expr_UnaryFunction (const Handle(Expr_GeneralFunction)& func, const Handle(Expr_GeneralExpression)& exp)
40{
41 if (func->NbOfVariables() != 1) {
9775fa61 42 throw Expr_InvalidFunction();
7fd59977 43 }
44 myFunction = func;
45 CreateOperand(exp);
46}
47
48Handle(Expr_GeneralFunction) Expr_UnaryFunction::Function () const
49{
50 return myFunction;
51}
52
53Handle(Expr_GeneralExpression) Expr_UnaryFunction::ShallowSimplified () const
54{
55 Handle(Expr_GeneralExpression) op = Operand();
56 if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) {
57 Handle(Expr_NumericValue) nval = Handle(Expr_NumericValue)::DownCast(op);
58 TColStd_Array1OfReal tabval(1,1);
59 tabval(1) = nval->GetValue();
60 Expr_Array1OfNamedUnknown vars(1,1);
61 vars(1) = myFunction->Variable(1);
62 Standard_Real res = myFunction->Evaluate(vars,tabval);
63 return new Expr_NumericValue(res);
64 }
65 Handle(Expr_UnaryFunction) me = this;
66 return me;
67}
68
69Handle(Expr_GeneralExpression) Expr_UnaryFunction::Copy () const
70{
71 return new Expr_UnaryFunction(myFunction,Expr::CopyShare(Operand()));
72}
73
74Standard_Boolean Expr_UnaryFunction::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const
75{
76 if (!Other->IsKind(STANDARD_TYPE(Expr_UnaryFunction))) {
77 return Standard_False;
78 }
79 Handle(Expr_UnaryFunction) fother = Handle(Expr_UnaryFunction)::DownCast(Other);
80 Handle(Expr_GeneralExpression) otherexp = fother->Operand();
81 if (otherexp->IsIdentical(Operand())) {
82 if (myFunction->IsIdentical(fother->Function())) {
83 return Standard_True;
84 }
85 }
86 return Standard_False;
87}
88
89Standard_Boolean Expr_UnaryFunction::IsLinear () const
90{
91 if (!ContainsUnknowns()) {
92 return Standard_True;
93 }
94 if (!Operand()->IsLinear()) {
95 return Standard_False;
96 }
97 return myFunction->IsLinearOnVariable(1);
98}
99
100Handle(Expr_GeneralExpression) Expr_UnaryFunction::Derivative (const Handle(Expr_NamedUnknown)& X) const
101{
102 Handle(Expr_NamedUnknown) myvar = myFunction->Variable(1);
103 Handle(Expr_GeneralExpression) myop = Operand();
104 Handle(Expr_GeneralExpression) myexpder = myop->Derivative(X);
105 Handle(Expr_GeneralFunction) myfuncder = myFunction->Derivative(myvar);
106 Handle(Expr_UnaryFunction) firstpart = new Expr_UnaryFunction(myfuncder,Expr::CopyShare(myop));
107 Handle(Expr_Product) resu = firstpart->ShallowSimplified() * myexpder;
108 return resu->ShallowSimplified();
109}
110
111Standard_Real Expr_UnaryFunction::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const
112{
113 Expr_Array1OfNamedUnknown varsfunc(1,1);
114 varsfunc(1) = myFunction->Variable(1);
115 TColStd_Array1OfReal valsfunc(1,1);
116 valsfunc(1) = Operand()->Evaluate(vars,vals);
117 return myFunction->Evaluate(varsfunc,valsfunc);
118}
119
120TCollection_AsciiString Expr_UnaryFunction::String() const
121{
122 TCollection_AsciiString res = myFunction->GetStringName();
123 res += "(";
124 res += Operand()->String();
8c2d3314 125 res += ")";
7fd59977 126 return res;
127}