0023024: Update headers of OCCT files
[occt.git] / src / BRepAlgo / BRepAlgo_AsDes.cxx
CommitLineData
b311480e 1// Created on: 1995-10-26
2// Created by: Yves FRICAUD
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <BRepAlgo_AsDes.ixx>
24#include <TopTools_ListIteratorOfListOfShape.hxx>
25
26//=======================================================================
27//function : BRepAlgo_AsDes
28//purpose :
29//=======================================================================
30
31BRepAlgo_AsDes::BRepAlgo_AsDes()
32{
33}
34
35
36//=======================================================================
37//function : Add
38//purpose :
39//=======================================================================
40
41void BRepAlgo_AsDes::Add(const TopoDS_Shape& S, const TopoDS_Shape& SS)
42{
43 if (!down.IsBound(S)) {
44 TopTools_ListOfShape L;
45 down.Bind(S,L);
46 }
47 down(S).Append(SS);
48
49 if (!up.IsBound(SS)) {
50 TopTools_ListOfShape L;
51 up.Bind(SS,L);
52 }
53 up(SS).Append(S);
54}
55
56
57//=======================================================================
58//function : Add
59//purpose :
60//=======================================================================
61
62void BRepAlgo_AsDes::Add(const TopoDS_Shape& S, const TopTools_ListOfShape& SS)
63{
64 TopTools_ListIteratorOfListOfShape it(SS);
65 for ( ; it.More(); it.Next()) {
66 Add(S,it.Value());
67 }
68}
69
70//=======================================================================
71//function : Clear
72//purpose :
73//=======================================================================
74
75void BRepAlgo_AsDes::Clear()
76{
77 up .Clear();
78 down.Clear();
79}
80
81
82//=======================================================================
83//function : HasAscendant
84//purpose :
85//=======================================================================
86
87Standard_Boolean BRepAlgo_AsDes::HasAscendant(const TopoDS_Shape& S)
88const
89{
90 return up.IsBound(S);
91}
92
93//=======================================================================
94//function : HasDescendant
95//purpose :
96//=======================================================================
97
98Standard_Boolean BRepAlgo_AsDes::HasDescendant(const TopoDS_Shape& S)
99const
100{
101 return down.IsBound(S);
102}
103
104//=======================================================================
105//function : Ascendant
106//purpose :
107//=======================================================================
108
109const TopTools_ListOfShape& BRepAlgo_AsDes::Ascendant(const TopoDS_Shape& S) const
110{
111 if (up.IsBound(S))
112 return up(S);
113 static TopTools_ListOfShape empty;
114 return empty;
115}
116
117
118//=======================================================================
119//function : Descendant
120//purpose :
121//=======================================================================
122
123const TopTools_ListOfShape& BRepAlgo_AsDes::Descendant(const TopoDS_Shape& S) const
124{
125 if (down.IsBound(S))
126 return down(S);
127 static TopTools_ListOfShape empty;
128 return empty;
129}
130
131//=======================================================================
132//function : ChangeDescendant
133//purpose :
134//=======================================================================
135
136TopTools_ListOfShape& BRepAlgo_AsDes::ChangeDescendant(const TopoDS_Shape& S)
137{
138 if (down.IsBound(S))
139 return down.ChangeFind(S);
140 static TopTools_ListOfShape empty;
141 return empty;
142}
143
144//=======================================================================
145//function : ReplaceInList
146//purpose :
147//=======================================================================
148
149static void ReplaceInList(const TopoDS_Shape& OldS,
150 const TopoDS_Shape& NewS,
151 TopTools_ListOfShape& L)
152{
153 TopTools_ListIteratorOfListOfShape it(L);
154
155 while(it.More()) {
156 if (it.Value().IsSame(OldS)) {
157 TopAbs_Orientation O = it.Value().Orientation();
158 L.InsertBefore(NewS.Oriented(O),it);
159 L.Remove(it);
160 }
161 else it.Next();
162 }
163}
164//=======================================================================
165//function : RemoveInList
166//purpose :
167//=======================================================================
168
169static void RemoveInList(const TopoDS_Shape& S,
170 TopTools_ListOfShape& L)
171{
172 TopTools_ListIteratorOfListOfShape it(L);
173 while(it.More()) {
174 if (it.Value().IsSame(S)) {
175 L.Remove(it);
176 break;
177 }
178 it.Next();
179 }
180}
181
182//=======================================================================
183//function : HasCommonDescendant
184//purpose :
185//=======================================================================
186
187Standard_Boolean BRepAlgo_AsDes::HasCommonDescendant(const TopoDS_Shape& S1,
188 const TopoDS_Shape& S2,
189 TopTools_ListOfShape& LC)
190const
191{
192 LC.Clear();
193 if (HasDescendant (S1) && HasDescendant (S2)) {
194 TopTools_ListIteratorOfListOfShape it1(Descendant(S1));
195 for (; it1.More(); it1.Next()) {
196 const TopoDS_Shape& DS1 = it1.Value();
197 TopTools_ListIteratorOfListOfShape it2(Ascendant(DS1));
198 for (; it2.More(); it2.Next()) {
199 const TopoDS_Shape& ADS1 = it2.Value();
200 if (ADS1.IsSame(S2)) {
201 LC.Append(DS1);
202 }
203 }
204 }
205 }
206 return (!LC.IsEmpty());
207}
208
209//=======================================================================
210//function : BackReplace
211//purpose :
212//=======================================================================
213
214void BRepAlgo_AsDes::BackReplace(const TopoDS_Shape& OldS,
215 const TopoDS_Shape& NewS,
216 const TopTools_ListOfShape& L,
217 const Standard_Boolean InUp)
218{
219 TopTools_ListIteratorOfListOfShape it(L);
220 for ( ; it.More(); it.Next()) {
221 const TopoDS_Shape& S = it.Value();
222 if (InUp) {
223 if (up.IsBound(S)) {
224 ReplaceInList(OldS,NewS,up.ChangeFind(S));
225 }
226 }
227 else {
228 if (down.IsBound(S)) {
229 ReplaceInList(OldS,NewS,down.ChangeFind(S));
230 }
231 }
232 }
233}
234
235//=======================================================================
236//function : Replace
237//purpose :
238//=======================================================================
239
240void BRepAlgo_AsDes::Replace(const TopoDS_Shape& OldS,
241 const TopoDS_Shape& NewS)
242{
243 Standard_Boolean InUp;
244
245 if (up.IsBound(OldS)) {
246 InUp = Standard_False;
247 BackReplace (OldS,NewS,up(OldS),InUp);
248 if (up.IsBound(NewS)) {
249 up(NewS).Append(up(OldS));
250 }
251 else {
252 up.Bind(NewS,up(OldS));
253 }
254 up.UnBind(OldS);
255 }
256
257 if (down.IsBound(OldS)) {
258 InUp = Standard_True;
259 BackReplace(OldS,NewS,down (OldS),InUp);
260 if (down.IsBound(NewS)) {
261 down(NewS).Append(down(OldS));
262 }
263 else {
264 down.Bind(NewS,down(OldS));
265 }
266 down.UnBind(OldS);
267 }
268}
269
270//=======================================================================
271//function : Remove
272//purpose :
273//=======================================================================
274
275void BRepAlgo_AsDes::Remove(const TopoDS_Shape& SS)
276{
277 if (down.IsBound(SS)) {
278 Standard_ConstructionError::Raise(" BRepAlgo_AsDes::Remove");
279 }
280 if (!up.IsBound(SS)) {
281 Standard_ConstructionError::Raise(" BRepAlgo_AsDes::Remove");
282 }
283 TopTools_ListIteratorOfListOfShape it(up(SS));
284 for (; it.More(); it.Next()) {
285 RemoveInList(SS,down.ChangeFind((it.Value())));
286 }
287 up.UnBind(SS);
288}