b311480e |
1 | // Created on: 1991-04-12 |
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 | |
7fd59977 |
21 | |
22 | #include <Expr_BinaryExpression.ixx> |
23 | #include <Expr_NamedUnknown.hxx> |
24 | #include <Expr_InvalidOperand.hxx> |
25 | #include <Standard_OutOfRange.hxx> |
26 | |
27 | |
28 | void Expr_BinaryExpression::SetFirstOperand (const Handle(Expr_GeneralExpression)& exp) |
29 | { |
30 | Handle(Expr_BinaryExpression) me; |
31 | me = this; |
32 | if (exp == me) { |
33 | Expr_InvalidOperand::Raise(); |
34 | } |
35 | if (exp->Contains(me)) { |
36 | Expr_InvalidOperand::Raise(); |
37 | } |
38 | myFirstOperand = exp; |
39 | } |
40 | |
41 | void Expr_BinaryExpression::SetSecondOperand (const Handle(Expr_GeneralExpression)& exp) |
42 | { |
43 | Handle(Expr_BinaryExpression) me; |
44 | me = this; |
45 | if (exp == me) { |
46 | Expr_InvalidOperand::Raise(); |
47 | } |
48 | if (exp->Contains(me)) { |
49 | Expr_InvalidOperand::Raise(); |
50 | } |
51 | mySecondOperand = exp; |
52 | } |
53 | |
54 | void Expr_BinaryExpression::CreateFirstOperand (const Handle(Expr_GeneralExpression)& exp) |
55 | { |
56 | myFirstOperand = exp; |
57 | } |
58 | |
59 | void Expr_BinaryExpression::CreateSecondOperand (const Handle(Expr_GeneralExpression)& exp) |
60 | { |
61 | mySecondOperand = exp; |
62 | } |
63 | |
64 | Standard_Integer Expr_BinaryExpression::NbSubExpressions () const |
65 | { |
66 | return 2; |
67 | } |
68 | |
69 | const Handle(Expr_GeneralExpression)& Expr_BinaryExpression::SubExpression (const Standard_Integer I) const |
70 | { |
71 | if (I == 1) { |
72 | return myFirstOperand; |
73 | } |
74 | else { |
75 | if (I == 2) { |
76 | return mySecondOperand; |
77 | } |
78 | else { |
79 | Standard_OutOfRange::Raise(); |
80 | } |
81 | } |
82 | #if defined (WNT) || !defined (DEB) |
83 | return *( ( Handle_Expr_GeneralExpression* )NULL ); |
84 | #endif // WNT || !DEB |
85 | } |
86 | |
87 | Standard_Boolean Expr_BinaryExpression::ContainsUnknowns () const |
88 | { |
89 | if (myFirstOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) { |
90 | return Standard_True; |
91 | } |
92 | if (mySecondOperand->IsKind(STANDARD_TYPE(Expr_NamedUnknown))) { |
93 | return Standard_True; |
94 | } |
95 | if (myFirstOperand->ContainsUnknowns()) { |
96 | return Standard_True; |
97 | } |
98 | if (mySecondOperand->ContainsUnknowns()) { |
99 | return Standard_True; |
100 | } |
101 | return Standard_False; |
102 | } |
103 | |
104 | Standard_Boolean Expr_BinaryExpression::Contains (const Handle(Expr_GeneralExpression)& exp) const |
105 | { |
106 | if (myFirstOperand == exp) { |
107 | return Standard_True; |
108 | } |
109 | if (mySecondOperand == exp) { |
110 | return Standard_True; |
111 | } |
112 | if (myFirstOperand->Contains(exp)) { |
113 | return Standard_True; |
114 | } |
115 | if (mySecondOperand->Contains(exp)) { |
116 | return Standard_True; |
117 | } |
118 | return Standard_False; |
119 | } |
120 | |
121 | void Expr_BinaryExpression::Replace (const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with) |
122 | { |
123 | if (myFirstOperand == var) { |
124 | SetFirstOperand(with); |
125 | } |
126 | else { |
127 | if (myFirstOperand->Contains(var)) { |
128 | myFirstOperand->Replace(var,with); |
129 | } |
130 | } |
131 | if (mySecondOperand == var) { |
132 | SetSecondOperand(with); |
133 | } |
134 | else { |
135 | if (mySecondOperand->Contains(var)) { |
136 | mySecondOperand->Replace(var,with); |
137 | } |
138 | } |
139 | } |
140 | |
141 | |
142 | Handle(Expr_GeneralExpression) Expr_BinaryExpression::Simplified() const |
143 | { |
144 | Handle(Expr_BinaryExpression) cop = Handle(Expr_BinaryExpression)::DownCast(Copy()); |
145 | Handle(Expr_GeneralExpression) op1 = cop->FirstOperand(); |
146 | Handle(Expr_GeneralExpression) op2 = cop->SecondOperand(); |
147 | cop->SetFirstOperand(op1->Simplified()); |
148 | cop->SetSecondOperand(op2->Simplified()); |
149 | return cop->ShallowSimplified(); |
150 | } |