0022904: Clean up sccsid variables
[occt.git] / src / Expr / Expr_SystemRelation.cxx
1 // Copyright:   Matra-Datavision 1991
2 // File:        Expr_SystemRelation.cxx
3 // Created:     Thu Jun 13 14:01:02 1991
4 // Author:      Arnaud BOUZY
5 //              <adn>
6
7 #include <Expr_SystemRelation.ixx>
8 #include <Standard_NoSuchObject.hxx>
9 #include <Standard_OutOfRange.hxx>
10 #include <Standard_DimensionMismatch.hxx>
11
12 Expr_SystemRelation::Expr_SystemRelation (const Handle(Expr_GeneralRelation)& relation)
13 {
14   myRelations.Append(relation);
15 }
16
17 void Expr_SystemRelation::Add (const Handle(Expr_GeneralRelation)& relation)
18 {
19   myRelations.Append(relation);
20 }
21
22 void Expr_SystemRelation::Remove (const Handle(Expr_GeneralRelation)& relation)
23 {
24   Standard_Integer position    = 0;
25   Standard_Boolean alreadyHere = Standard_False;
26
27   for (Standard_Integer i = 1; i <=  myRelations.Length() && !alreadyHere; i++) {
28     if (myRelations.Value(i) == relation) {
29       alreadyHere = Standard_True;
30       position    = i;
31     }
32   }
33
34   if (alreadyHere) {
35     Standard_NoSuchObject::Raise();
36   }
37   if (myRelations.Length() <= 1) {
38     Standard_DimensionMismatch::Raise();
39   }
40   myRelations.Remove(position);
41 }
42
43 Standard_Boolean Expr_SystemRelation::IsLinear () const
44 {
45   Standard_Integer len = myRelations.Length();
46   for (Standard_Integer i = 1; i<= len; i++) {
47     if (!myRelations(i)->IsLinear()) {
48       return Standard_False;
49     }
50   }
51   return Standard_True;
52 }
53
54 Standard_Boolean Expr_SystemRelation::Contains(const Handle(Expr_GeneralExpression)& exp) const
55 {
56   for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
57     if (myRelations(i)->Contains(exp)) {
58       return Standard_True;
59     }
60   }
61   return Standard_False;
62 }
63
64 void Expr_SystemRelation::Replace(const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
65 {
66   for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
67     myRelations(i)->Replace(var,with);
68   }
69 }
70
71 Standard_Integer Expr_SystemRelation::NbOfSubRelations () const
72 {
73   return myRelations.Length();
74 }
75
76 Handle(Expr_GeneralRelation) Expr_SystemRelation::SubRelation (const Standard_Integer index) const
77 {
78   return myRelations(index);
79 }
80
81 Standard_Boolean Expr_SystemRelation::IsSatisfied () const
82 {
83   Standard_Integer len = myRelations.Length();
84   for (Standard_Integer i = 1; i<= len; i++) {
85     if (!myRelations(i)->IsSatisfied()) {
86       return Standard_False;
87     }
88   }
89   return Standard_True;
90 }
91
92
93 Handle(Expr_GeneralRelation) Expr_SystemRelation::Simplified () const
94 {
95   Standard_Integer len = myRelations.Length();
96   Handle(Expr_GeneralRelation) rel;
97   rel = myRelations(1);
98   Handle(Expr_SystemRelation) result = new Expr_SystemRelation(rel->Simplified());
99   for (Standard_Integer i = 2; i<= len; i++) {
100     rel = myRelations(i);
101     rel = rel->Simplified();
102     result->Add(rel);
103   }
104   return result;
105 }
106   
107
108   
109 void Expr_SystemRelation::Simplify ()
110 {
111   Standard_Integer len = myRelations.Length();
112   Handle(Expr_GeneralRelation) rel;
113   for (Standard_Integer i = 1; i<= len; i++) {
114     rel = myRelations(i);
115     rel->Simplify();
116   }
117 }
118
119 Handle(Expr_GeneralRelation) Expr_SystemRelation::Copy () const
120 {
121   Handle(Expr_SystemRelation) cop = new Expr_SystemRelation(myRelations(1)->Copy());
122   Standard_Integer len = myRelations.Length();
123   for (Standard_Integer i = 2; i<= len; i++) {
124     cop->Add(myRelations(i)->Copy());
125   }
126   return cop;
127 }
128
129 Standard_Integer Expr_SystemRelation::NbOfSingleRelations() const
130 {
131   Standard_Integer nbsing = 0;
132   Standard_Integer nbrel = myRelations.Length();
133   Handle(Expr_GeneralRelation) subrel;
134   for (Standard_Integer i = 1; i<= nbrel ; i++) {
135     subrel = myRelations(i);
136     nbsing = nbsing + subrel->NbOfSingleRelations();
137   }
138   return nbsing;
139 }
140
141 TCollection_AsciiString Expr_SystemRelation::String() const
142 {
143   Standard_Integer nbrel = myRelations.Length();
144   Handle(Expr_GeneralRelation) subrel;
145   TCollection_AsciiString res;
146   for (Standard_Integer i = 1; i<= nbrel ; i++) {
147     res += myRelations(i)->String();
148     if (i != nbrel) {
149       res += TCollection_AsciiString('\n');
150     }
151   }
152   return res;
153 }