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.
17 #include <BRepAlgo_Image.ixx>
19 #include <Standard_ConstructionError.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
21 #include <TopTools_MapOfShape.hxx>
22 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
23 #include <TopExp_Explorer.hxx>
25 //=======================================================================
26 //function : BRepAlgo_Image
28 //=======================================================================
30 BRepAlgo_Image::BRepAlgo_Image()
35 //=======================================================================
38 //=======================================================================
40 void BRepAlgo_Image::SetRoot(const TopoDS_Shape& S)
45 //=======================================================================
48 //=======================================================================
50 void BRepAlgo_Image::Bind(const TopoDS_Shape& OldS,
51 const TopoDS_Shape& NewS)
53 if (down.IsBound(OldS)) {
54 Standard_ConstructionError::Raise(" BRepAlgo_Image::Bind");
57 TopTools_ListOfShape L;
59 down(OldS).Append(NewS);
64 //=======================================================================
67 //=======================================================================
69 void BRepAlgo_Image::Bind(const TopoDS_Shape& OldS,
70 const TopTools_ListOfShape& L)
73 Standard_ConstructionError::Raise(" BRepAlgo_Image::Bind");
76 TopTools_ListIteratorOfListOfShape it(L);
77 for (; it.More(); it.Next()) {
79 Bind(OldS, it.Value());
81 Add (OldS, it.Value());
85 //=======================================================================
88 //=======================================================================
90 void BRepAlgo_Image::Clear()
97 //=======================================================================
100 //=======================================================================
102 void BRepAlgo_Image::Add(const TopoDS_Shape& OldS, const TopoDS_Shape& NewS)
104 if (!HasImage(OldS)) {
105 Standard_ConstructionError::Raise(" BRepAlgo_Image::Add");
107 down(OldS).Append(NewS);
111 //=======================================================================
114 //=======================================================================
116 void BRepAlgo_Image::Add(const TopoDS_Shape& OldS,
117 const TopTools_ListOfShape& L)
119 TopTools_ListIteratorOfListOfShape it(L);
120 for (; it.More(); it.Next()) {
121 Add(OldS,it.Value());
126 //=======================================================================
129 //=======================================================================
131 void BRepAlgo_Image::Remove(const TopoDS_Shape& S)
133 if (!up.IsBound(S)) {
134 Standard_ConstructionError::Raise(" BRepAlgo_Image::Remove");
136 const TopoDS_Shape& OldS = up(S);
137 TopTools_ListOfShape& L = down(OldS);
138 TopTools_ListIteratorOfListOfShape it(L);
140 if (it.Value().IsSame(S)) {
146 if (L.IsEmpty()) down.UnBind(OldS);
151 //=======================================================================
152 //function : TopTools_ListOfShape&
154 //=======================================================================
156 const TopTools_ListOfShape& BRepAlgo_Image::Roots() const
161 //=======================================================================
164 //=======================================================================
166 Standard_Boolean BRepAlgo_Image::IsImage(const TopoDS_Shape& S) const
168 return up.IsBound(S);
171 //=======================================================================
172 //function : ImageFrom
174 //=======================================================================
176 const TopoDS_Shape& BRepAlgo_Image::ImageFrom(const TopoDS_Shape& S) const
178 if (!up.IsBound(S)) {
179 Standard_ConstructionError::Raise(" BRepAlgo_Image::ImageFrom");
184 //=======================================================================
185 //function : FirstImageFrom
187 //=======================================================================
189 const TopoDS_Shape& BRepAlgo_Image::Root(const TopoDS_Shape& S)
192 if (!up.IsBound(S)) {
193 Standard_ConstructionError::Raise(" BRepAlgo_Image::FirstImageFrom");
196 TopoDS_Shape S1 = up(S);
202 while ( up.IsBound(S1)) {
205 if ( S1.IsSame(S2)) break;
210 //=======================================================================
211 //function : HasImage
213 //=======================================================================
215 Standard_Boolean BRepAlgo_Image::HasImage(const TopoDS_Shape& S) const
217 return down.IsBound(S);
220 //=======================================================================
221 //function : TopTools_ListOfShape&
223 //=======================================================================
225 const TopTools_ListOfShape& BRepAlgo_Image::Image(const TopoDS_Shape& S) const
228 static TopTools_ListOfShape L;
236 //=======================================================================
237 //function : TopTools_ListOfShape&
239 //=======================================================================
240 void BRepAlgo_Image::LastImage(const TopoDS_Shape& S,
241 TopTools_ListOfShape& L) const
243 if (!down.IsBound(S)) {
247 TopTools_ListIteratorOfListOfShape it(down(S));
248 for (; it.More(); it.Next()) {
249 if (it.Value().IsSame(S)) {
253 LastImage(it.Value(),L);
260 //=======================================================================
263 //=======================================================================
265 void BRepAlgo_Image::Compact()
267 TopTools_DataMapOfShapeListOfShape M;
268 TopTools_ListIteratorOfListOfShape it(roots);
269 for (; it.More(); it.Next()) {
270 const TopoDS_Shape& S = it.Value();
271 TopTools_ListOfShape LI;
272 if (HasImage(S)) LastImage(S,LI);
277 for (it.Initialize(roots); it.More(); it.Next()) {
278 if (M.IsBound(it.Value())) {
279 Bind(it.Value(), M(it.Value()));
284 //=======================================================================
287 //=======================================================================
289 void BRepAlgo_Image::Filter(const TopoDS_Shape& S,
290 const TopAbs_ShapeEnum T)
293 TopExp_Explorer exp(S,T) ;
294 TopTools_MapOfShape M;
295 for (; exp.More(); exp.Next()) {M.Add(exp.Current());}
296 Standard_Boolean Change = Standard_True;
298 Change = Standard_False;
299 TopTools_DataMapIteratorOfDataMapOfShapeShape mit(up);
300 for (; mit.More(); mit.Next()) {
301 const TopoDS_Shape& S = mit.Key();
302 if (S.ShapeType() == T && !M.Contains(S)) {
304 Change = Standard_True;