0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[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>
42cf5bc1 19#include <Expr_NamedUnknown.hxx>
20#include <Expr_SystemRelation.hxx>
21#include <Standard_DimensionMismatch.hxx>
7fd59977 22#include <Standard_NoSuchObject.hxx>
42cf5bc1 23#include <Standard_Type.hxx>
24#include <TCollection_AsciiString.hxx>
7fd59977 25
92efcf78 26IMPLEMENT_STANDARD_RTTIEXT(Expr_SystemRelation,Expr_GeneralRelation)
27
7fd59977 28Expr_SystemRelation::Expr_SystemRelation (const Handle(Expr_GeneralRelation)& relation)
29{
30 myRelations.Append(relation);
31}
32
33void Expr_SystemRelation::Add (const Handle(Expr_GeneralRelation)& relation)
34{
35 myRelations.Append(relation);
36}
37
38void Expr_SystemRelation::Remove (const Handle(Expr_GeneralRelation)& relation)
39{
40 Standard_Integer position = 0;
41 Standard_Boolean alreadyHere = Standard_False;
42
43 for (Standard_Integer i = 1; i <= myRelations.Length() && !alreadyHere; i++) {
44 if (myRelations.Value(i) == relation) {
45 alreadyHere = Standard_True;
46 position = i;
47 }
48 }
49
50 if (alreadyHere) {
9775fa61 51 throw Standard_NoSuchObject();
7fd59977 52 }
53 if (myRelations.Length() <= 1) {
9775fa61 54 throw Standard_DimensionMismatch();
7fd59977 55 }
56 myRelations.Remove(position);
57}
58
59Standard_Boolean Expr_SystemRelation::IsLinear () const
60{
61 Standard_Integer len = myRelations.Length();
62 for (Standard_Integer i = 1; i<= len; i++) {
63 if (!myRelations(i)->IsLinear()) {
64 return Standard_False;
65 }
66 }
67 return Standard_True;
68}
69
70Standard_Boolean Expr_SystemRelation::Contains(const Handle(Expr_GeneralExpression)& exp) const
71{
72 for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
73 if (myRelations(i)->Contains(exp)) {
74 return Standard_True;
75 }
76 }
77 return Standard_False;
78}
79
80void Expr_SystemRelation::Replace(const Handle(Expr_NamedUnknown)& var, const Handle(Expr_GeneralExpression)& with)
81{
82 for (Standard_Integer i=1; i<= myRelations.Length(); i++) {
83 myRelations(i)->Replace(var,with);
84 }
85}
86
87Standard_Integer Expr_SystemRelation::NbOfSubRelations () const
88{
89 return myRelations.Length();
90}
91
92Handle(Expr_GeneralRelation) Expr_SystemRelation::SubRelation (const Standard_Integer index) const
93{
94 return myRelations(index);
95}
96
97Standard_Boolean Expr_SystemRelation::IsSatisfied () const
98{
99 Standard_Integer len = myRelations.Length();
100 for (Standard_Integer i = 1; i<= len; i++) {
101 if (!myRelations(i)->IsSatisfied()) {
102 return Standard_False;
103 }
104 }
105 return Standard_True;
106}
107
108
109Handle(Expr_GeneralRelation) Expr_SystemRelation::Simplified () const
110{
111 Standard_Integer len = myRelations.Length();
112 Handle(Expr_GeneralRelation) rel;
113 rel = myRelations(1);
114 Handle(Expr_SystemRelation) result = new Expr_SystemRelation(rel->Simplified());
115 for (Standard_Integer i = 2; i<= len; i++) {
116 rel = myRelations(i);
117 rel = rel->Simplified();
118 result->Add(rel);
119 }
120 return result;
121}
122
123
124
125void Expr_SystemRelation::Simplify ()
126{
127 Standard_Integer len = myRelations.Length();
128 Handle(Expr_GeneralRelation) rel;
129 for (Standard_Integer i = 1; i<= len; i++) {
130 rel = myRelations(i);
131 rel->Simplify();
132 }
133}
134
135Handle(Expr_GeneralRelation) Expr_SystemRelation::Copy () const
136{
137 Handle(Expr_SystemRelation) cop = new Expr_SystemRelation(myRelations(1)->Copy());
138 Standard_Integer len = myRelations.Length();
139 for (Standard_Integer i = 2; i<= len; i++) {
140 cop->Add(myRelations(i)->Copy());
141 }
142 return cop;
143}
144
145Standard_Integer Expr_SystemRelation::NbOfSingleRelations() const
146{
147 Standard_Integer nbsing = 0;
148 Standard_Integer nbrel = myRelations.Length();
149 Handle(Expr_GeneralRelation) subrel;
150 for (Standard_Integer i = 1; i<= nbrel ; i++) {
151 subrel = myRelations(i);
152 nbsing = nbsing + subrel->NbOfSingleRelations();
153 }
154 return nbsing;
155}
156
157TCollection_AsciiString Expr_SystemRelation::String() const
158{
159 Standard_Integer nbrel = myRelations.Length();
160 Handle(Expr_GeneralRelation) subrel;
161 TCollection_AsciiString res;
162 for (Standard_Integer i = 1; i<= nbrel ; i++) {
163 res += myRelations(i)->String();
164 if (i != nbrel) {
165 res += TCollection_AsciiString('\n');
166 }
167 }
168 return res;
169}