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