1 // Created on: 1995-10-26
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRepAlgo_AsDes.hxx>
19 #include <Standard_ConstructionError.hxx>
20 #include <Standard_Type.hxx>
21 #include <TopoDS_Shape.hxx>
22 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 #include <TopTools_MapOfOrientedShape.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(BRepAlgo_AsDes,Standard_Transient)
27 //=======================================================================
28 //function : BRepAlgo_AsDes
30 //=======================================================================
31 BRepAlgo_AsDes::BRepAlgo_AsDes()
36 //=======================================================================
39 //=======================================================================
41 void BRepAlgo_AsDes::Add(const TopoDS_Shape& S, const TopoDS_Shape& SS)
43 if (!down.IsBound(S)) {
44 TopTools_ListOfShape L;
49 if (!up.IsBound(SS)) {
50 TopTools_ListOfShape L;
57 //=======================================================================
60 //=======================================================================
62 void BRepAlgo_AsDes::Add(const TopoDS_Shape& S, const TopTools_ListOfShape& SS)
64 TopTools_ListIteratorOfListOfShape it(SS);
65 for ( ; it.More(); it.Next()) {
70 //=======================================================================
73 //=======================================================================
75 void BRepAlgo_AsDes::Clear()
82 //=======================================================================
83 //function : HasAscendant
85 //=======================================================================
87 Standard_Boolean BRepAlgo_AsDes::HasAscendant(const TopoDS_Shape& S)
93 //=======================================================================
94 //function : HasDescendant
96 //=======================================================================
98 Standard_Boolean BRepAlgo_AsDes::HasDescendant(const TopoDS_Shape& S)
101 return down.IsBound(S);
104 //=======================================================================
105 //function : Ascendant
107 //=======================================================================
109 const TopTools_ListOfShape& BRepAlgo_AsDes::Ascendant(const TopoDS_Shape& S) const
113 static TopTools_ListOfShape empty;
118 //=======================================================================
119 //function : Descendant
121 //=======================================================================
123 const TopTools_ListOfShape& BRepAlgo_AsDes::Descendant(const TopoDS_Shape& S) const
127 static TopTools_ListOfShape empty;
131 //=======================================================================
132 //function : ChangeDescendant
134 //=======================================================================
136 TopTools_ListOfShape& BRepAlgo_AsDes::ChangeDescendant(const TopoDS_Shape& S)
139 return down.ChangeFind(S);
140 static TopTools_ListOfShape empty;
144 //=======================================================================
145 //function : ReplaceInList
147 //=======================================================================
149 static void ReplaceInList(const TopoDS_Shape& OldS,
150 const TopoDS_Shape& NewS,
151 TopTools_ListOfShape& L)
153 TopTools_MapOfOrientedShape aMS;
154 TopTools_ListIteratorOfListOfShape it(L);
155 for (; it.More(); it.Next()) {
160 if (it.Value().IsSame(OldS)) {
161 TopAbs_Orientation O = it.Value().Orientation();
162 if (aMS.Add(NewS.Oriented(O))) {
163 L.InsertBefore(NewS.Oriented(O),it);
170 //=======================================================================
171 //function : RemoveInList
173 //=======================================================================
175 static void RemoveInList(const TopoDS_Shape& S,
176 TopTools_ListOfShape& L)
178 TopTools_ListIteratorOfListOfShape it(L);
180 if (it.Value().IsSame(S)) {
188 //=======================================================================
189 //function : HasCommonDescendant
191 //=======================================================================
193 Standard_Boolean BRepAlgo_AsDes::HasCommonDescendant(const TopoDS_Shape& S1,
194 const TopoDS_Shape& S2,
195 TopTools_ListOfShape& LC)
199 if (HasDescendant (S1) && HasDescendant (S2)) {
200 TopTools_ListIteratorOfListOfShape it1(Descendant(S1));
201 for (; it1.More(); it1.Next()) {
202 const TopoDS_Shape& DS1 = it1.Value();
203 TopTools_ListIteratorOfListOfShape it2(Ascendant(DS1));
204 for (; it2.More(); it2.Next()) {
205 const TopoDS_Shape& ADS1 = it2.Value();
206 if (ADS1.IsSame(S2)) {
212 return (!LC.IsEmpty());
215 //=======================================================================
216 //function : BackReplace
218 //=======================================================================
220 void BRepAlgo_AsDes::BackReplace(const TopoDS_Shape& OldS,
221 const TopoDS_Shape& NewS,
222 const TopTools_ListOfShape& L,
223 const Standard_Boolean InUp)
225 TopTools_ListIteratorOfListOfShape it(L);
226 for ( ; it.More(); it.Next()) {
227 const TopoDS_Shape& S = it.Value();
230 ReplaceInList(OldS,NewS,up.ChangeFind(S));
234 if (down.IsBound(S)) {
235 ReplaceInList(OldS,NewS,down.ChangeFind(S));
241 //=======================================================================
244 //=======================================================================
245 void BRepAlgo_AsDes::Replace(const TopoDS_Shape& OldS,
246 const TopoDS_Shape& NewS)
248 for (Standard_Integer i = 0; i < 2; ++i) {
249 TopTools_DataMapOfShapeListOfShape& aMap = !i ? up : down;
250 TopTools_ListOfShape* pLSOld = aMap.ChangeSeek(OldS);
255 Standard_Boolean InUp = !i ? Standard_False : Standard_True;
256 BackReplace(OldS, NewS, *pLSOld, InUp);
258 TopTools_ListOfShape* pLSNew = aMap.ChangeSeek(NewS);
261 TopTools_MapOfOrientedShape aMS;
262 TopTools_ListIteratorOfListOfShape aIt(*pLSOld);
263 for (; aIt.More(); ) {
264 if (!aMS.Add(aIt.Value())) {
271 aMap.Bind(NewS, *pLSOld);
275 TopTools_MapOfOrientedShape aMS;
276 TopTools_ListIteratorOfListOfShape aIt(*pLSNew);
277 for (; aIt.More(); aIt.Next()) {
278 aMS.Add(aIt.Value());
281 aIt.Initialize(*pLSOld);
282 for (; aIt.More(); aIt.Next()) {
283 const TopoDS_Shape& aS = aIt.Value();
294 //=======================================================================
297 //=======================================================================
299 void BRepAlgo_AsDes::Remove(const TopoDS_Shape& SS)
301 if (down.IsBound(SS)) {
302 throw Standard_ConstructionError(" BRepAlgo_AsDes::Remove");
304 if (!up.IsBound(SS)) {
305 throw Standard_ConstructionError(" BRepAlgo_AsDes::Remove");
307 TopTools_ListIteratorOfListOfShape it(up(SS));
308 for (; it.More(); it.Next()) {
309 RemoveInList(SS,down.ChangeFind((it.Value())));