1 // Created on: 1991-06-13
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.
18 #include <Expr_GeneralExpression.hxx>
19 #include <Expr_GeneralRelation.hxx>
20 #include <Expr_NamedUnknown.hxx>
21 #include <Expr_SystemRelation.hxx>
22 #include <Standard_DimensionMismatch.hxx>
23 #include <Standard_NoSuchObject.hxx>
24 #include <Standard_NumericError.hxx>
25 #include <Standard_OutOfRange.hxx>
26 #include <Standard_Type.hxx>
27 #include <TCollection_AsciiString.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(Expr_SystemRelation,Expr_GeneralRelation)
31 Expr_SystemRelation::Expr_SystemRelation (const Handle(Expr_GeneralRelation)& relation)
33 myRelations.Append(relation);
36 void Expr_SystemRelation::Add (const Handle(Expr_GeneralRelation)& relation)
38 myRelations.Append(relation);
41 void Expr_SystemRelation::Remove (const Handle(Expr_GeneralRelation)& relation)
43 Standard_Integer position = 0;
44 Standard_Boolean alreadyHere = Standard_False;
46 for (Standard_Integer i = 1; i <= myRelations.Length() && !alreadyHere; i++) {
47 if (myRelations.Value(i) == relation) {
48 alreadyHere = Standard_True;
54 throw Standard_NoSuchObject();
56 if (myRelations.Length() <= 1) {
57 throw Standard_DimensionMismatch();
59 myRelations.Remove(position);
62 Standard_Boolean Expr_SystemRelation::IsLinear () const
64 Standard_Integer len = myRelations.Length();
65 for (Standard_Integer i = 1; i<= len; i++) {
66 if (!myRelations(i)->IsLinear()) {
67 return Standard_False;
73 Standard_Boolean Expr_SystemRelation::Contains(const Handle(Expr_GeneralExpression)& exp) const
75 for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
76 if (myRelations(i)->Contains(exp)) {
80 return Standard_False;
83 void Expr_SystemRelation::Replace(const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
85 for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
86 myRelations(i)->Replace(var,with);
90 Standard_Integer Expr_SystemRelation::NbOfSubRelations () const
92 return myRelations.Length();
95 Handle(Expr_GeneralRelation) Expr_SystemRelation::SubRelation (const Standard_Integer index) const
97 return myRelations(index);
100 Standard_Boolean Expr_SystemRelation::IsSatisfied () const
102 Standard_Integer len = myRelations.Length();
103 for (Standard_Integer i = 1; i<= len; i++) {
104 if (!myRelations(i)->IsSatisfied()) {
105 return Standard_False;
108 return Standard_True;
112 Handle(Expr_GeneralRelation) Expr_SystemRelation::Simplified () const
114 Standard_Integer len = myRelations.Length();
115 Handle(Expr_GeneralRelation) rel;
116 rel = myRelations(1);
117 Handle(Expr_SystemRelation) result = new Expr_SystemRelation(rel->Simplified());
118 for (Standard_Integer i = 2; i<= len; i++) {
119 rel = myRelations(i);
120 rel = rel->Simplified();
128 void Expr_SystemRelation::Simplify ()
130 Standard_Integer len = myRelations.Length();
131 Handle(Expr_GeneralRelation) rel;
132 for (Standard_Integer i = 1; i<= len; i++) {
133 rel = myRelations(i);
138 Handle(Expr_GeneralRelation) Expr_SystemRelation::Copy () const
140 Handle(Expr_SystemRelation) cop = new Expr_SystemRelation(myRelations(1)->Copy());
141 Standard_Integer len = myRelations.Length();
142 for (Standard_Integer i = 2; i<= len; i++) {
143 cop->Add(myRelations(i)->Copy());
148 Standard_Integer Expr_SystemRelation::NbOfSingleRelations() const
150 Standard_Integer nbsing = 0;
151 Standard_Integer nbrel = myRelations.Length();
152 Handle(Expr_GeneralRelation) subrel;
153 for (Standard_Integer i = 1; i<= nbrel ; i++) {
154 subrel = myRelations(i);
155 nbsing = nbsing + subrel->NbOfSingleRelations();
160 TCollection_AsciiString Expr_SystemRelation::String() const
162 Standard_Integer nbrel = myRelations.Length();
163 Handle(Expr_GeneralRelation) subrel;
164 TCollection_AsciiString res;
165 for (Standard_Integer i = 1; i<= nbrel ; i++) {
166 res += myRelations(i)->String();
168 res += TCollection_AsciiString('\n');