summaryrefslogtreecommitdiff
path: root/src/Expr/Expr_SystemRelation.cxx
blob: 34bef2fab01d8853141a9a046ce818404218d5f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//static const char* sccsid = "@(#)Expr_SystemRelation.cxx	3.2 95/01/10"; // Do not delete this line. Used by sccs.
// Copyright: 	Matra-Datavision 1991
// File:	Expr_SystemRelation.cxx
// Created:	Thu Jun 13 14:01:02 1991
// Author:	Arnaud BOUZY
//		<adn>

#include <Expr_SystemRelation.ixx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_OutOfRange.hxx>
#include <Standard_DimensionMismatch.hxx>

Expr_SystemRelation::Expr_SystemRelation (const Handle(Expr_GeneralRelation)& relation)
{
  myRelations.Append(relation);
}

void Expr_SystemRelation::Add (const Handle(Expr_GeneralRelation)& relation)
{
  myRelations.Append(relation);
}

void Expr_SystemRelation::Remove (const Handle(Expr_GeneralRelation)& relation)
{
  Standard_Integer position    = 0;
  Standard_Boolean alreadyHere = Standard_False;

  for (Standard_Integer i = 1; i <=  myRelations.Length() && !alreadyHere; i++) {
    if (myRelations.Value(i) == relation) {
      alreadyHere = Standard_True;
      position    = i;
    }
  }

  if (alreadyHere) {
    Standard_NoSuchObject::Raise();
  }
  if (myRelations.Length() <= 1) {
    Standard_DimensionMismatch::Raise();
  }
  myRelations.Remove(position);
}

Standard_Boolean Expr_SystemRelation::IsLinear () const
{
  Standard_Integer len = myRelations.Length();
  for (Standard_Integer i = 1; i<= len; i++) {
    if (!myRelations(i)->IsLinear()) {
      return Standard_False;
    }
  }
  return Standard_True;
}

Standard_Boolean Expr_SystemRelation::Contains(const Handle(Expr_GeneralExpression)& exp) const
{
  for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
    if (myRelations(i)->Contains(exp)) {
      return Standard_True;
    }
  }
  return Standard_False;
}

void Expr_SystemRelation::Replace(const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
{
  for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
    myRelations(i)->Replace(var,with);
  }
}

Standard_Integer Expr_SystemRelation::NbOfSubRelations () const
{
  return myRelations.Length();
}

Handle(Expr_GeneralRelation) Expr_SystemRelation::SubRelation (const Standard_Integer index) const
{
  return myRelations(index);
}

Standard_Boolean Expr_SystemRelation::IsSatisfied () const
{
  Standard_Integer len = myRelations.Length();
  for (Standard_Integer i = 1; i<= len; i++) {
    if (!myRelations(i)->IsSatisfied()) {
      return Standard_False;
    }
  }
  return Standard_True;
}


Handle(Expr_GeneralRelation) Expr_SystemRelation::Simplified () const
{
  Standard_Integer len = myRelations.Length();
  Handle(Expr_GeneralRelation) rel;
  rel = myRelations(1);
  Handle(Expr_SystemRelation) result = new Expr_SystemRelation(rel->Simplified());
  for (Standard_Integer i = 2; i<= len; i++) {
    rel = myRelations(i);
    rel = rel->Simplified();
    result->Add(rel);
  }
  return result;
}
  

  
void Expr_SystemRelation::Simplify ()
{
  Standard_Integer len = myRelations.Length();
  Handle(Expr_GeneralRelation) rel;
  for (Standard_Integer i = 1; i<= len; i++) {
    rel = myRelations(i);
    rel->Simplify();
  }
}

Handle(Expr_GeneralRelation) Expr_SystemRelation::Copy () const
{
  Handle(Expr_SystemRelation) cop = new Expr_SystemRelation(myRelations(1)->Copy());
  Standard_Integer len = myRelations.Length();
  for (Standard_Integer i = 2; i<= len; i++) {
    cop->Add(myRelations(i)->Copy());
  }
  return cop;
}

Standard_Integer Expr_SystemRelation::NbOfSingleRelations() const
{
  Standard_Integer nbsing = 0;
  Standard_Integer nbrel = myRelations.Length();
  Handle(Expr_GeneralRelation) subrel;
  for (Standard_Integer i = 1; i<= nbrel ; i++) {
    subrel = myRelations(i);
    nbsing = nbsing + subrel->NbOfSingleRelations();
  }
  return nbsing;
}

TCollection_AsciiString Expr_SystemRelation::String() const
{
  Standard_Integer nbrel = myRelations.Length();
  Handle(Expr_GeneralRelation) subrel;
  TCollection_AsciiString res;
  for (Standard_Integer i = 1; i<= nbrel ; i++) {
    res += myRelations(i)->String();
    if (i != nbrel) {
      res += TCollection_AsciiString('\n');
    }
  }
  return res;
}