0023024: Update headers of OCCT files
[occt.git] / src / BOP / BOP_ShapeSet.cxx
1 // Created on: 1993-06-17
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1993-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
21
22 #include <BOP_ShapeSet.ixx>
23
24 #include <Standard_ProgramError.hxx>
25
26 #include <TopExp_Explorer.hxx>
27
28 #include <TopAbs.hxx>
29
30
31 //=======================================================================
32 //function : BOP_ShapeSet::BOP_ShapeSet
33 //purpose  : 
34 //=======================================================================
35 BOP_ShapeSet::BOP_ShapeSet(const TopAbs_ShapeEnum SubShapeType)
36
37   mySubShapeType(SubShapeType)
38 {
39   switch (SubShapeType) {
40   case  TopAbs_EDGE:
41     myShapeType = TopAbs_FACE;
42     break;
43   case TopAbs_VERTEX:
44     myShapeType = TopAbs_EDGE;
45     break;
46   default:
47     Standard_ProgramError::Raise("ShapeSet : bad ShapeType");
48     break;
49   }
50 }
51 //=======================================================================
52 //function : Delete
53 //purpose  : 
54 //=======================================================================
55   void BOP_ShapeSet::Delete()
56 {}
57
58 //=======================================================================
59 //function : ClearContents
60 //purpose  : 
61 //=======================================================================
62   void BOP_ShapeSet::ClearContents()
63 {
64   myStartShapes.Clear();
65   mySubShapeMap.Clear();
66   myShapes.Clear();
67   myCurrentShapeNeighbours.Clear();
68 }
69
70 //=======================================================================
71 //function : AddShape
72 //purpose  : 
73 //=======================================================================
74   void BOP_ShapeSet::AddShape(const TopoDS_Shape& S)
75 {
76   ProcessAddShape(S);
77 }
78
79 //=======================================================================
80 //function : AddStartElement
81 //purpose  : 
82 //=======================================================================
83   void BOP_ShapeSet::AddStartElement(const TopoDS_Shape& S)
84 {
85   ProcessAddStartElement(S);
86 }
87
88 //=======================================================================
89 //function : AddElement
90 //purpose  : 
91 //=======================================================================
92   void BOP_ShapeSet::AddElement(const TopoDS_Shape& S)
93 {
94   ProcessAddElement(S);
95 }
96
97 //=======================================================================
98 //function : ProcessAddShape
99 //purpose  : 
100 //=======================================================================
101   void BOP_ShapeSet::ProcessAddShape(const TopoDS_Shape& S)
102 {
103   myShapes.Append(S);
104 }
105
106 //=======================================================================
107 //function : ProcessAddStartElement
108 //purpose  : 
109 //=======================================================================
110   void BOP_ShapeSet::ProcessAddStartElement(const TopoDS_Shape& S)
111 {
112   TopTools_ListIteratorOfListOfShape anIt(myStartShapes);
113   for (; anIt.More(); anIt.Next()) {
114     const TopoDS_Shape& aSInner=anIt.Value();
115     if (aSInner==S) {
116       return;
117     }
118   }
119   myStartShapes.Append(S);
120   ProcessAddElement(S);
121 }
122
123 //=======================================================================
124 //function : ProcessAddElement
125 //purpose  : 
126 //=======================================================================
127   void BOP_ShapeSet::ProcessAddElement(const TopoDS_Shape& S)
128 {
129   Standard_Boolean b;
130   TopTools_ListOfShape  Lemp;
131   
132   TopExp_Explorer Ex(S, mySubShapeType);
133   for (; Ex.More(); Ex.Next()) {
134     const TopoDS_Shape& subshape = Ex.Current();
135     b = ( ! mySubShapeMap.Contains(subshape) );
136     if ( b ) {
137       mySubShapeMap.Add(subshape, Lemp);
138     }
139     mySubShapeMap.ChangeFromKey(subshape).Append(S);
140   }
141 }
142
143 //=======================================================================
144 //function : StartElements
145 //purpose  : 
146 //=======================================================================
147   const TopTools_ListOfShape& BOP_ShapeSet::StartElements()const 
148 {
149   return myStartShapes;
150 }
151
152 //=======================================================================
153 //function : InitShapes
154 //purpose  : 
155 //=======================================================================
156   void  BOP_ShapeSet::InitShapes()
157 {
158   myShapesIter.Initialize(myShapes);
159 }
160
161 //=======================================================================
162 //function : MoreShapes
163 //purpose  : 
164 //=======================================================================
165   Standard_Boolean  BOP_ShapeSet::MoreShapes()const 
166 {
167   Standard_Boolean b = myShapesIter.More();
168   return b;
169 }
170
171 //=======================================================================
172 //function : NextShape
173 //purpose  : 
174 //=======================================================================
175   void  BOP_ShapeSet::NextShape()
176 {
177   myShapesIter.Next();
178 }
179
180 //=======================================================================
181 //function : Shape
182 //purpose  : 
183 //=======================================================================
184   const TopoDS_Shape&  BOP_ShapeSet::Shape()const 
185 {
186   const TopoDS_Shape& S = myShapesIter.Value();
187   return S;
188 }
189
190 //=======================================================================
191 //function : InitStartElements
192 //purpose  : 
193 //=======================================================================
194   void  BOP_ShapeSet::InitStartElements()
195 {
196   myStartShapesIter.Initialize(myStartShapes);
197 }
198
199 //=======================================================================
200 //function : MoreStartElements
201 //purpose  : 
202 //=======================================================================
203   Standard_Boolean  BOP_ShapeSet::MoreStartElements()const 
204 {
205   Standard_Boolean b = myStartShapesIter.More();
206   return b;
207 }
208
209 //=======================================================================
210 //function : NextStartElement
211 //purpose  : 
212 //=======================================================================
213   void  BOP_ShapeSet::NextStartElement()
214 {
215   myStartShapesIter.Next();
216 }
217
218 //=======================================================================
219 //function : StartElement
220 //purpose  : 
221 //=======================================================================
222   const TopoDS_Shape& BOP_ShapeSet::StartElement()const 
223 {
224   const TopoDS_Shape& S = myStartShapesIter.Value();
225   return S;
226 }
227
228 //=======================================================================
229 //function : InitNeighbours
230 //purpose  : 
231 //=======================================================================
232   void  BOP_ShapeSet::InitNeighbours(const TopoDS_Shape& S)
233 {
234   mySubShapeExplorer.Init(S, mySubShapeType);
235   myCurrentShape = S;
236   FindNeighbours();
237 }
238
239 //=======================================================================
240 //function : MoreNeighbours
241 //purpose  : 
242 //=======================================================================
243   Standard_Boolean BOP_ShapeSet::MoreNeighbours()
244 {
245   Standard_Boolean b = myIncidentShapesIter.More();
246   return b;
247 }
248
249 //=======================================================================
250 //function : NextNeighbour
251 //purpose  : 
252 //=======================================================================
253   void BOP_ShapeSet::NextNeighbour()
254 {
255   Standard_Boolean noisimore, ssemore;
256  
257   myIncidentShapesIter.Next();
258   noisimore = ! myIncidentShapesIter.More();
259   if ( noisimore ) {
260     ssemore = mySubShapeExplorer.More();
261     if ( ssemore ) {
262       mySubShapeExplorer.Next();
263       FindNeighbours();
264     }
265   }
266 }
267
268 //=======================================================================
269 //function : Neighbour
270 //purpose  : 
271 //=======================================================================
272   const TopoDS_Shape&  BOP_ShapeSet::Neighbour()const 
273 {
274   const TopoDS_Shape& S = myIncidentShapesIter.Value();
275   return S;
276 }
277
278 //=======================================================================
279 //function : ChangeStartShapes
280 //purpose  : 
281 //=======================================================================
282   TopTools_ListOfShape& BOP_ShapeSet::ChangeStartShapes()
283 {
284   return myStartShapes;
285 }
286
287 //=======================================================================
288 //function : FindNeighbours
289 //purpose  : 
290 //=======================================================================
291   void BOP_ShapeSet::FindNeighbours()
292 {
293   while (mySubShapeExplorer.More()) {
294      // l = list of edges neighbour of edge myCurrentShape trough
295     // the vertex mySubShapeExplorer.Current(), which is a vertex of the
296     // edge myCurrentShape.
297     const TopoDS_Shape& V = mySubShapeExplorer.Current();
298     const TopTools_ListOfShape & l = MakeNeighboursList(myCurrentShape,V);
299     // myIncidentShapesIter iterates on the neighbour edges of the edge
300     // given as InitNeighbours() argument (this edge has been stored 
301     // in the field myCurrentShape).
302     myIncidentShapesIter.Initialize(l);
303     if (myIncidentShapesIter.More()) {
304       break;
305     }    
306     else {
307       mySubShapeExplorer.Next();
308     }
309   }
310 }
311
312 //=======================================================================
313 //function : MakeNeighboursList
314 //purpose  : 
315 //=======================================================================
316   const TopTools_ListOfShape & BOP_ShapeSet::MakeNeighboursList(const TopoDS_Shape& ,//Earg, 
317                                                                 const TopoDS_Shape& Varg)
318 {
319   const TopTools_ListOfShape& l = mySubShapeMap.FindFromKey(Varg);
320   return l;
321 }
322
323 //=======================================================================
324 //function : MaxNumberSubShape
325 //purpose  : 
326 //=======================================================================
327   Standard_Integer BOP_ShapeSet::MaxNumberSubShape(const TopoDS_Shape& Shape)
328 {
329   Standard_Integer i, m = 0;
330  
331   TopExp_Explorer SE(Shape, mySubShapeType);
332
333   while(SE.More()) {
334     const TopoDS_Shape& SubShape = SE.Current();
335     if(!mySubShapeMap.Contains(SubShape)) {
336       SE.Next();
337       continue;
338     }
339     
340     const TopTools_ListOfShape& l = mySubShapeMap.FindFromKey(SubShape);
341     i=l.Extent();
342     m = Max(m, i);
343     SE.Next();
344   }
345   return m;
346 }
347
348