Test for 0022778: Bug in BRepMesh
[occt.git] / src / Expr / Expr_UnaryExpression.cxx
1 // Created on: 1991-04-15
2 // Created by: Arnaud BOUZY
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #include <Expr_UnaryExpression.ixx>
23 #include <Expr_NamedUnknown.hxx>
24 #include <Expr_InvalidOperand.hxx>
25 #include <Standard_OutOfRange.hxx>
26
27 void Expr_UnaryExpression::SetOperand (const Handle(Expr_GeneralExpression)& exp)
28 {
29   Handle(Expr_UnaryExpression) me = this;
30   if (exp == me) {
31     Expr_InvalidOperand::Raise();
32   }
33   if (exp->Contains(me)) {
34     Expr_InvalidOperand::Raise();
35   }
36   myOperand = exp;
37 }
38
39 void Expr_UnaryExpression::CreateOperand (const Handle(Expr_GeneralExpression)& exp)
40 {
41   myOperand = exp;
42 }
43
44 Standard_Integer Expr_UnaryExpression::NbSubExpressions () const
45 {
46   return 1;
47 }
48
49 const Handle(Expr_GeneralExpression)& Expr_UnaryExpression::SubExpression (const Standard_Integer I) const
50 {
51   if (I != 1) {
52     Standard_OutOfRange::Raise();
53   }
54   return myOperand;
55 }
56
57 Standard_Boolean Expr_UnaryExpression::ContainsUnknowns () const
58 {
59   if (!myOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) {
60     return myOperand->ContainsUnknowns();
61   }
62   return Standard_True;
63 }
64
65 Standard_Boolean Expr_UnaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const
66 {
67   if (myOperand != exp) {
68     return myOperand->Contains(exp);
69   }
70   return Standard_True;
71 }
72
73 void Expr_UnaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
74 {
75   if (myOperand == var) {
76     SetOperand(with);
77   }
78   else {
79     if (myOperand->Contains(var)) {
80       myOperand->Replace(var,with);
81     }
82   }
83 }
84
85
86 Handle(Expr_GeneralExpression) Expr_UnaryExpression::Simplified() const
87 {
88   Handle(Expr_UnaryExpression) cop = Handle(Expr_UnaryExpression)::DownCast(Copy());
89   Handle(Expr_GeneralExpression) op = cop->Operand();
90   cop->SetOperand(op->Simplified());
91   return cop->ShallowSimplified();
92 }
93