0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / Expr / Expr_SystemRelation.cxx
CommitLineData
b311480e 1// Created on: 1991-06-13
2// Created by: Arnaud BOUZY
3// Copyright (c) 1991-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
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>
7fd59977 23#include <Standard_NoSuchObject.hxx>
42cf5bc1 24#include <Standard_NumericError.hxx>
7fd59977 25#include <Standard_OutOfRange.hxx>
42cf5bc1 26#include <Standard_Type.hxx>
27#include <TCollection_AsciiString.hxx>
7fd59977 28
92efcf78 29IMPLEMENT_STANDARD_RTTIEXT(Expr_SystemRelation,Expr_GeneralRelation)
30
7fd59977 31Expr_SystemRelation::Expr_SystemRelation (const Handle(Expr_GeneralRelation)& relation)
32{
33 myRelations.Append(relation);
34}
35
36void Expr_SystemRelation::Add (const Handle(Expr_GeneralRelation)& relation)
37{
38 myRelations.Append(relation);
39}
40
41void Expr_SystemRelation::Remove (const Handle(Expr_GeneralRelation)& relation)
42{
43 Standard_Integer position = 0;
44 Standard_Boolean alreadyHere = Standard_False;
45
46 for (Standard_Integer i = 1; i <= myRelations.Length() && !alreadyHere; i++) {
47 if (myRelations.Value(i) == relation) {
48 alreadyHere = Standard_True;
49 position = i;
50 }
51 }
52
53 if (alreadyHere) {
9775fa61 54 throw Standard_NoSuchObject();
7fd59977 55 }
56 if (myRelations.Length() <= 1) {
9775fa61 57 throw Standard_DimensionMismatch();
7fd59977 58 }
59 myRelations.Remove(position);
60}
61
62Standard_Boolean Expr_SystemRelation::IsLinear () const
63{
64 Standard_Integer len = myRelations.Length();
65 for (Standard_Integer i = 1; i<= len; i++) {
66 if (!myRelations(i)->IsLinear()) {
67 return Standard_False;
68 }
69 }
70 return Standard_True;
71}
72
73Standard_Boolean Expr_SystemRelation::Contains(const Handle(Expr_GeneralExpression)& exp) const
74{
75 for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
76 if (myRelations(i)->Contains(exp)) {
77 return Standard_True;
78 }
79 }
80 return Standard_False;
81}
82
83void Expr_SystemRelation::Replace(const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
84{
85 for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
86 myRelations(i)->Replace(var,with);
87 }
88}
89
90Standard_Integer Expr_SystemRelation::NbOfSubRelations () const
91{
92 return myRelations.Length();
93}
94
95Handle(Expr_GeneralRelation) Expr_SystemRelation::SubRelation (const Standard_Integer index) const
96{
97 return myRelations(index);
98}
99
100Standard_Boolean Expr_SystemRelation::IsSatisfied () const
101{
102 Standard_Integer len = myRelations.Length();
103 for (Standard_Integer i = 1; i<= len; i++) {
104 if (!myRelations(i)->IsSatisfied()) {
105 return Standard_False;
106 }
107 }
108 return Standard_True;
109}
110
111
112Handle(Expr_GeneralRelation) Expr_SystemRelation::Simplified () const
113{
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();
121 result->Add(rel);
122 }
123 return result;
124}
125
126
127
128void Expr_SystemRelation::Simplify ()
129{
130 Standard_Integer len = myRelations.Length();
131 Handle(Expr_GeneralRelation) rel;
132 for (Standard_Integer i = 1; i<= len; i++) {
133 rel = myRelations(i);
134 rel->Simplify();
135 }
136}
137
138Handle(Expr_GeneralRelation) Expr_SystemRelation::Copy () const
139{
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());
144 }
145 return cop;
146}
147
148Standard_Integer Expr_SystemRelation::NbOfSingleRelations() const
149{
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();
156 }
157 return nbsing;
158}
159
160TCollection_AsciiString Expr_SystemRelation::String() const
161{
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();
167 if (i != nbrel) {
168 res += TCollection_AsciiString('\n');
169 }
170 }
171 return res;
172}