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 | |
42cf5bc1 |
17 | |
7fd59977 |
18 | #include <Expr.hxx> |
42cf5bc1 |
19 | #include <Expr_GeneralExpression.hxx> |
20 | #include <Expr_NamedUnknown.hxx> |
21 | #include <Expr_NotEvaluable.hxx> |
22 | #include <Expr_NumericValue.hxx> |
23 | #include <Expr_Sign.hxx> |
24 | #include <Standard_NumericError.hxx> |
25 | #include <Standard_Type.hxx> |
26 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
27 | |
92efcf78 |
28 | IMPLEMENT_STANDARD_RTTIEXT(Expr_Sign,Expr_UnaryExpression) |
29 | |
7fd59977 |
30 | Expr_Sign::Expr_Sign (const Handle(Expr_GeneralExpression)& exp) |
31 | { |
32 | CreateOperand(exp); |
33 | } |
34 | |
35 | Handle(Expr_GeneralExpression) Expr_Sign::ShallowSimplified () const |
36 | { |
37 | Handle(Expr_GeneralExpression) op = Operand(); |
38 | if (op->IsKind(STANDARD_TYPE(Expr_NumericValue))) { |
39 | Handle(Expr_NumericValue) valop = Handle(Expr_NumericValue)::DownCast(op); |
40 | return new Expr_NumericValue(Expr::Sign(valop->GetValue())); |
41 | } |
42 | Handle(Expr_Sign) me = this; |
43 | return me; |
44 | } |
45 | |
46 | Handle(Expr_GeneralExpression) Expr_Sign::Copy () const |
47 | { |
48 | return new Expr_Sign(Expr::CopyShare(Operand())); |
49 | } |
50 | |
51 | Standard_Boolean Expr_Sign::IsIdentical (const Handle(Expr_GeneralExpression)& Other) const |
52 | { |
53 | if (!Other->IsKind(STANDARD_TYPE(Expr_Sign))) { |
54 | return Standard_False; |
55 | } |
56 | Handle(Expr_GeneralExpression) op = Operand(); |
57 | return op->IsIdentical(Other->SubExpression(1)); |
58 | } |
59 | |
60 | Standard_Boolean Expr_Sign::IsLinear () const |
61 | { |
62 | return !ContainsUnknowns(); |
63 | } |
64 | |
65 | Handle(Expr_GeneralExpression) Expr_Sign::Derivative (const Handle(Expr_NamedUnknown)& ) const |
66 | { |
67 | return new Expr_NumericValue(0.0); |
68 | } |
69 | |
70 | Standard_Real Expr_Sign::Evaluate(const Expr_Array1OfNamedUnknown& vars, const TColStd_Array1OfReal& vals) const |
71 | { |
72 | Standard_Real res = Operand()->Evaluate(vars,vals); |
73 | return Expr::Sign(res); |
74 | } |
75 | |
76 | TCollection_AsciiString Expr_Sign::String() const |
77 | { |
78 | TCollection_AsciiString str("Sign("); |
79 | str += Operand()->String(); |
80 | str += ")"; |
81 | return str; |
82 | } |