b311480e |
1 | // Created on: 1995-10-26 |
2 | // Created by: Yves FRICAUD |
3 | // Copyright (c) 1995-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 | |
17 | #include <BRepAlgo_AsDes.ixx> |
18 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
19 | |
20 | //======================================================================= |
21 | //function : BRepAlgo_AsDes |
22 | //purpose : |
23 | //======================================================================= |
24 | |
25 | BRepAlgo_AsDes::BRepAlgo_AsDes() |
26 | { |
27 | } |
28 | |
29 | |
30 | //======================================================================= |
31 | //function : Add |
32 | //purpose : |
33 | //======================================================================= |
34 | |
35 | void BRepAlgo_AsDes::Add(const TopoDS_Shape& S, const TopoDS_Shape& SS) |
36 | { |
37 | if (!down.IsBound(S)) { |
38 | TopTools_ListOfShape L; |
39 | down.Bind(S,L); |
40 | } |
41 | down(S).Append(SS); |
42 | |
43 | if (!up.IsBound(SS)) { |
44 | TopTools_ListOfShape L; |
45 | up.Bind(SS,L); |
46 | } |
47 | up(SS).Append(S); |
48 | } |
49 | |
50 | |
51 | //======================================================================= |
52 | //function : Add |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | void BRepAlgo_AsDes::Add(const TopoDS_Shape& S, const TopTools_ListOfShape& SS) |
57 | { |
58 | TopTools_ListIteratorOfListOfShape it(SS); |
59 | for ( ; it.More(); it.Next()) { |
60 | Add(S,it.Value()); |
61 | } |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : Clear |
66 | //purpose : |
67 | //======================================================================= |
68 | |
69 | void BRepAlgo_AsDes::Clear() |
70 | { |
71 | up .Clear(); |
72 | down.Clear(); |
73 | } |
74 | |
75 | |
76 | //======================================================================= |
77 | //function : HasAscendant |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | Standard_Boolean BRepAlgo_AsDes::HasAscendant(const TopoDS_Shape& S) |
82 | const |
83 | { |
84 | return up.IsBound(S); |
85 | } |
86 | |
87 | //======================================================================= |
88 | //function : HasDescendant |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | Standard_Boolean BRepAlgo_AsDes::HasDescendant(const TopoDS_Shape& S) |
93 | const |
94 | { |
95 | return down.IsBound(S); |
96 | } |
97 | |
98 | //======================================================================= |
99 | //function : Ascendant |
100 | //purpose : |
101 | //======================================================================= |
102 | |
103 | const TopTools_ListOfShape& BRepAlgo_AsDes::Ascendant(const TopoDS_Shape& S) const |
104 | { |
105 | if (up.IsBound(S)) |
106 | return up(S); |
107 | static TopTools_ListOfShape empty; |
108 | return empty; |
109 | } |
110 | |
111 | |
112 | //======================================================================= |
113 | //function : Descendant |
114 | //purpose : |
115 | //======================================================================= |
116 | |
117 | const TopTools_ListOfShape& BRepAlgo_AsDes::Descendant(const TopoDS_Shape& S) const |
118 | { |
119 | if (down.IsBound(S)) |
120 | return down(S); |
121 | static TopTools_ListOfShape empty; |
122 | return empty; |
123 | } |
124 | |
125 | //======================================================================= |
126 | //function : ChangeDescendant |
127 | //purpose : |
128 | //======================================================================= |
129 | |
130 | TopTools_ListOfShape& BRepAlgo_AsDes::ChangeDescendant(const TopoDS_Shape& S) |
131 | { |
132 | if (down.IsBound(S)) |
133 | return down.ChangeFind(S); |
134 | static TopTools_ListOfShape empty; |
135 | return empty; |
136 | } |
137 | |
138 | //======================================================================= |
139 | //function : ReplaceInList |
140 | //purpose : |
141 | //======================================================================= |
142 | |
143 | static void ReplaceInList(const TopoDS_Shape& OldS, |
144 | const TopoDS_Shape& NewS, |
145 | TopTools_ListOfShape& L) |
146 | { |
147 | TopTools_ListIteratorOfListOfShape it(L); |
148 | |
149 | while(it.More()) { |
150 | if (it.Value().IsSame(OldS)) { |
151 | TopAbs_Orientation O = it.Value().Orientation(); |
152 | L.InsertBefore(NewS.Oriented(O),it); |
153 | L.Remove(it); |
154 | } |
155 | else it.Next(); |
156 | } |
157 | } |
158 | //======================================================================= |
159 | //function : RemoveInList |
160 | //purpose : |
161 | //======================================================================= |
162 | |
163 | static void RemoveInList(const TopoDS_Shape& S, |
164 | TopTools_ListOfShape& L) |
165 | { |
166 | TopTools_ListIteratorOfListOfShape it(L); |
167 | while(it.More()) { |
168 | if (it.Value().IsSame(S)) { |
169 | L.Remove(it); |
170 | break; |
171 | } |
172 | it.Next(); |
173 | } |
174 | } |
175 | |
176 | //======================================================================= |
177 | //function : HasCommonDescendant |
178 | //purpose : |
179 | //======================================================================= |
180 | |
181 | Standard_Boolean BRepAlgo_AsDes::HasCommonDescendant(const TopoDS_Shape& S1, |
182 | const TopoDS_Shape& S2, |
183 | TopTools_ListOfShape& LC) |
184 | const |
185 | { |
186 | LC.Clear(); |
187 | if (HasDescendant (S1) && HasDescendant (S2)) { |
188 | TopTools_ListIteratorOfListOfShape it1(Descendant(S1)); |
189 | for (; it1.More(); it1.Next()) { |
190 | const TopoDS_Shape& DS1 = it1.Value(); |
191 | TopTools_ListIteratorOfListOfShape it2(Ascendant(DS1)); |
192 | for (; it2.More(); it2.Next()) { |
193 | const TopoDS_Shape& ADS1 = it2.Value(); |
194 | if (ADS1.IsSame(S2)) { |
195 | LC.Append(DS1); |
196 | } |
197 | } |
198 | } |
199 | } |
200 | return (!LC.IsEmpty()); |
201 | } |
202 | |
203 | //======================================================================= |
204 | //function : BackReplace |
205 | //purpose : |
206 | //======================================================================= |
207 | |
208 | void BRepAlgo_AsDes::BackReplace(const TopoDS_Shape& OldS, |
209 | const TopoDS_Shape& NewS, |
210 | const TopTools_ListOfShape& L, |
211 | const Standard_Boolean InUp) |
212 | { |
213 | TopTools_ListIteratorOfListOfShape it(L); |
214 | for ( ; it.More(); it.Next()) { |
215 | const TopoDS_Shape& S = it.Value(); |
216 | if (InUp) { |
217 | if (up.IsBound(S)) { |
218 | ReplaceInList(OldS,NewS,up.ChangeFind(S)); |
219 | } |
220 | } |
221 | else { |
222 | if (down.IsBound(S)) { |
223 | ReplaceInList(OldS,NewS,down.ChangeFind(S)); |
224 | } |
225 | } |
226 | } |
227 | } |
228 | |
229 | //======================================================================= |
230 | //function : Replace |
231 | //purpose : |
232 | //======================================================================= |
233 | |
234 | void BRepAlgo_AsDes::Replace(const TopoDS_Shape& OldS, |
235 | const TopoDS_Shape& NewS) |
236 | { |
237 | Standard_Boolean InUp; |
238 | |
239 | if (up.IsBound(OldS)) { |
240 | InUp = Standard_False; |
241 | BackReplace (OldS,NewS,up(OldS),InUp); |
242 | if (up.IsBound(NewS)) { |
243 | up(NewS).Append(up(OldS)); |
244 | } |
245 | else { |
246 | up.Bind(NewS,up(OldS)); |
247 | } |
248 | up.UnBind(OldS); |
249 | } |
250 | |
251 | if (down.IsBound(OldS)) { |
252 | InUp = Standard_True; |
253 | BackReplace(OldS,NewS,down (OldS),InUp); |
254 | if (down.IsBound(NewS)) { |
255 | down(NewS).Append(down(OldS)); |
256 | } |
257 | else { |
258 | down.Bind(NewS,down(OldS)); |
259 | } |
260 | down.UnBind(OldS); |
261 | } |
262 | } |
263 | |
264 | //======================================================================= |
265 | //function : Remove |
266 | //purpose : |
267 | //======================================================================= |
268 | |
269 | void BRepAlgo_AsDes::Remove(const TopoDS_Shape& SS) |
270 | { |
271 | if (down.IsBound(SS)) { |
272 | Standard_ConstructionError::Raise(" BRepAlgo_AsDes::Remove"); |
273 | } |
274 | if (!up.IsBound(SS)) { |
275 | Standard_ConstructionError::Raise(" BRepAlgo_AsDes::Remove"); |
276 | } |
277 | TopTools_ListIteratorOfListOfShape it(up(SS)); |
278 | for (; it.More(); it.Next()) { |
279 | RemoveInList(SS,down.ChangeFind((it.Value()))); |
280 | } |
281 | up.UnBind(SS); |
282 | } |