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
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.
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.
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.
23 #include <BRepAlgo_Image.ixx>
25 #include <Standard_ConstructionError.hxx>
26 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <TopTools_MapOfShape.hxx>
28 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
29 #include <TopExp_Explorer.hxx>
31 //=======================================================================
32 //function : BRepAlgo_Image
34 //=======================================================================
36 BRepAlgo_Image::BRepAlgo_Image()
41 //=======================================================================
44 //=======================================================================
46 void BRepAlgo_Image::SetRoot(const TopoDS_Shape& S)
51 //=======================================================================
54 //=======================================================================
56 void BRepAlgo_Image::Bind(const TopoDS_Shape& OldS,
57 const TopoDS_Shape& NewS)
59 if (down.IsBound(OldS)) {
60 Standard_ConstructionError::Raise(" BRepAlgo_Image::Bind");
63 TopTools_ListOfShape L;
65 down(OldS).Append(NewS);
70 //=======================================================================
73 //=======================================================================
75 void BRepAlgo_Image::Bind(const TopoDS_Shape& OldS,
76 const TopTools_ListOfShape& L)
79 Standard_ConstructionError::Raise(" BRepAlgo_Image::Bind");
82 TopTools_ListIteratorOfListOfShape it(L);
83 for (; it.More(); it.Next()) {
85 Bind(OldS, it.Value());
87 Add (OldS, it.Value());
91 //=======================================================================
94 //=======================================================================
96 void BRepAlgo_Image::Clear()
103 //=======================================================================
106 //=======================================================================
108 void BRepAlgo_Image::Add(const TopoDS_Shape& OldS, const TopoDS_Shape& NewS)
110 if (!HasImage(OldS)) {
111 Standard_ConstructionError::Raise(" BRepAlgo_Image::Add");
113 down(OldS).Append(NewS);
117 //=======================================================================
120 //=======================================================================
122 void BRepAlgo_Image::Add(const TopoDS_Shape& OldS,
123 const TopTools_ListOfShape& L)
125 TopTools_ListIteratorOfListOfShape it(L);
126 for (; it.More(); it.Next()) {
127 Add(OldS,it.Value());
132 //=======================================================================
135 //=======================================================================
137 void BRepAlgo_Image::Remove(const TopoDS_Shape& S)
139 if (!up.IsBound(S)) {
140 Standard_ConstructionError::Raise(" BRepAlgo_Image::Remove");
142 const TopoDS_Shape& OldS = up(S);
143 TopTools_ListOfShape& L = down(OldS);
144 TopTools_ListIteratorOfListOfShape it(L);
146 if (it.Value().IsSame(S)) {
152 if (L.IsEmpty()) down.UnBind(OldS);
157 //=======================================================================
158 //function : TopTools_ListOfShape&
160 //=======================================================================
162 const TopTools_ListOfShape& BRepAlgo_Image::Roots() const
167 //=======================================================================
170 //=======================================================================
172 Standard_Boolean BRepAlgo_Image::IsImage(const TopoDS_Shape& S) const
174 return up.IsBound(S);
177 //=======================================================================
178 //function : ImageFrom
180 //=======================================================================
182 const TopoDS_Shape& BRepAlgo_Image::ImageFrom(const TopoDS_Shape& S) const
184 if (!up.IsBound(S)) {
185 Standard_ConstructionError::Raise(" BRepAlgo_Image::ImageFrom");
190 //=======================================================================
191 //function : FirstImageFrom
193 //=======================================================================
195 const TopoDS_Shape& BRepAlgo_Image::Root(const TopoDS_Shape& S)
198 if (!up.IsBound(S)) {
199 Standard_ConstructionError::Raise(" BRepAlgo_Image::FirstImageFrom");
202 TopoDS_Shape S1 = up(S);
208 while ( up.IsBound(S1)) {
211 if ( S1.IsSame(S2)) break;
216 //=======================================================================
217 //function : HasImage
219 //=======================================================================
221 Standard_Boolean BRepAlgo_Image::HasImage(const TopoDS_Shape& S) const
223 return down.IsBound(S);
226 //=======================================================================
227 //function : TopTools_ListOfShape&
229 //=======================================================================
231 const TopTools_ListOfShape& BRepAlgo_Image::Image(const TopoDS_Shape& S) const
234 static TopTools_ListOfShape L;
242 //=======================================================================
243 //function : TopTools_ListOfShape&
245 //=======================================================================
246 void BRepAlgo_Image::LastImage(const TopoDS_Shape& S,
247 TopTools_ListOfShape& L) const
249 if (!down.IsBound(S)) {
253 TopTools_ListIteratorOfListOfShape it(down(S));
254 for (; it.More(); it.Next()) {
255 if (it.Value().IsSame(S)) {
259 LastImage(it.Value(),L);
266 //=======================================================================
269 //=======================================================================
271 void BRepAlgo_Image::Compact()
273 TopTools_DataMapOfShapeListOfShape M;
274 TopTools_ListIteratorOfListOfShape it(roots);
275 for (; it.More(); it.Next()) {
276 const TopoDS_Shape& S = it.Value();
277 TopTools_ListOfShape LI;
278 if (HasImage(S)) LastImage(S,LI);
283 for (it.Initialize(roots); it.More(); it.Next()) {
284 if (M.IsBound(it.Value())) {
285 Bind(it.Value(), M(it.Value()));
290 //=======================================================================
293 //=======================================================================
295 void BRepAlgo_Image::Filter(const TopoDS_Shape& S,
296 const TopAbs_ShapeEnum T)
299 TopExp_Explorer exp(S,T) ;
300 TopTools_MapOfShape M;
301 for (; exp.More(); exp.Next()) {M.Add(exp.Current());}
302 Standard_Boolean Change = Standard_True;
304 Change = Standard_False;
305 TopTools_DataMapIteratorOfDataMapOfShapeShape mit(up);
306 for (; mit.More(); mit.Next()) {
307 const TopoDS_Shape& S = mit.Key();
308 if (S.ShapeType() == T && !M.Contains(S)) {
310 Change = Standard_True;