0024129: Eliminate remaining compiler warnings in MSVC++ 2008 32 bit with warning...
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_FaceBuilder.cxx
1 // Created on: 1996-01-05
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1996-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 <TopOpeBRepBuild_FaceBuilder.ixx>
23
24 #include <gp_Pnt.hxx>
25 #include <gp_Pnt2d.hxx>
26 #include <TopAbs_Orientation.hxx>
27 #include <TopoDS.hxx>
28 #include <TopoDS_Compound.hxx>
29 #include <TopoDS_Face.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopOpeBRepDS_BuildTool.hxx>
33 #include <BRep_Tool.hxx>
34 #include <BRep_Builder.hxx>
35 //#include <BRepAdaptor_Curve2d.hxx>
36 #include <TopExp.hxx>
37 #include <TopTools_Array1OfShape.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_IndexedMapOfOrientedShape.hxx>
40 #include <TopTools_IndexedDataMapOfShapeShape.hxx>
41 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42 #include <TopTools_DataMapOfShapeListOfShape.hxx>
43 #include <TopTools_DataMapOfShapeListOfShape.hxx>
44 #include <TopOpeBRepBuild_WireEdgeClassifier.hxx>
45 #include <TopOpeBRepBuild_Loop.hxx>
46 #include <TopOpeBRepBuild_BlockBuilder.hxx>
47 #include <TopOpeBRepBuild_LoopSet.hxx>
48 #include <Standard_ProgramError.hxx>
49 #include <Precision.hxx>
50 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <TopTools_DataMapOfShapeInteger.hxx>
52 #include <TopOpeBRepBuild_define.hxx>
53
54 #undef RM_HANGING
55 // MSV: RM_HANGING behaviour: when state of wire is UNCLOSEDW we do not
56 // remove the whole wire but remove the chains of hanging edges. This would
57 // produce a good result in some cases. But :-( it gives regressions on grid
58 // tests (1cto 021 W4,X4). Therefore I leaved this code not active.
59 #ifdef RM_HANGING
60 #include <TColStd_ListIteratorOfListOfInteger.hxx>
61 #endif
62
63 #ifdef DEB
64 extern Standard_Boolean TopOpeBRepBuild_GettracePURGE();
65 extern Standard_Boolean TopOpeBRepDS_GettraceSTRANGE();
66 #include <TopOpeBRepDS_DSX.hxx>
67 void debifb() {}
68 #endif
69
70 #ifdef DRAW
71 #include <TopOpeBRepTool_DRAW.hxx>
72 #endif
73
74 //=======================================================================
75 //function : TopOpeBRepBuild_FaceBuilder
76 //purpose  : 
77 //=======================================================================
78 TopOpeBRepBuild_FaceBuilder::TopOpeBRepBuild_FaceBuilder()
79 {
80 }
81
82 //=======================================================================
83 //function : TopOpeBRepBuild_FaceBuilder
84 //purpose  : 
85 //=======================================================================
86 TopOpeBRepBuild_FaceBuilder::TopOpeBRepBuild_FaceBuilder(TopOpeBRepBuild_WireEdgeSet& WES,const TopoDS_Shape& F,const Standard_Boolean ForceClass)
87 {
88   InitFaceBuilder(WES,F,ForceClass);
89 }
90
91 //=======================================================================
92 //function : InitFaceBuilder
93 //purpose  : 
94 //=======================================================================
95 void TopOpeBRepBuild_FaceBuilder::InitFaceBuilder(TopOpeBRepBuild_WireEdgeSet& WES,const TopoDS_Shape& F,const Standard_Boolean ForceClass) 
96 {
97   myFace = TopoDS::Face(F);
98 #ifdef DEB
99   Standard_Boolean deb = TopOpeBRepDS_GettraceSPSX(myFace);
100   if (deb) debifb();
101 #endif
102   MakeLoops(WES);
103   TopOpeBRepBuild_BlockBuilder& BB = myBlockBuilder;
104   TopOpeBRepBuild_WireEdgeClassifier WEC(F,BB);
105   TopOpeBRepBuild_LoopSet& LS = myLoopSet;
106   myFaceAreaBuilder.InitFaceAreaBuilder(LS,WEC,ForceClass);
107 }
108
109 //---------------------------------------------------------------
110 void FUN_DetectVerticesOn1Edge(const TopoDS_Shape& W,TopTools_IndexedDataMapOfShapeShape& mapVon1E)
111 {
112   // Fills the map <mapVon1edge>,with vertices of <W> of 3d connexity 1.
113   TopTools_IndexedDataMapOfShapeListOfShape mapVedges;
114   TopExp::MapShapesAndAncestors(W,TopAbs_VERTEX,TopAbs_EDGE,mapVedges);
115   Standard_Integer nV = mapVedges.Extent();
116
117   for (Standard_Integer i = 1;i <= nV;i++) {
118     const TopoDS_Shape& V = mapVedges.FindKey(i);
119     if (V.Orientation() == TopAbs_INTERNAL) continue;
120
121     const TopTools_ListOfShape& loE = mapVedges.FindFromIndex(i);
122     if (loE.Extent() < 2) {
123       // Keeping INTERNAL or EXTERNAL edges
124       const TopoDS_Shape& E = loE.First();
125       TopAbs_Orientation oriE = E.Orientation();
126       if ((oriE == TopAbs_INTERNAL) || (oriE == TopAbs_EXTERNAL)) continue;
127       mapVon1E.Add(V,E);
128     }
129   }
130
131
132 #define ISUNKNOWN -1
133 #define ISVERTEX  0
134 #define GCLOSEDW  1
135 #define UNCLOSEDW 2
136 #define CLOSEDW   10
137 Standard_Integer FUN_AnalyzemapVon1E(const TopTools_IndexedDataMapOfShapeShape& mapVon1E,
138                         TopTools_IndexedDataMapOfShapeShape& mapVV)
139 {
140 #ifdef DRAW
141   Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE();
142   if (trc) cout<<endl<<"* DetectUnclosedWire :"<<endl;
143 #endif
144
145   Standard_Integer res = ISUNKNOWN;
146
147   Standard_Integer nV = mapVon1E.Extent();
148   if      (nV == 0) {
149     res = CLOSEDW;
150   }
151   else if (nV == 1) {
152     const TopoDS_Shape& E = mapVon1E.FindFromIndex(1);
153     Standard_Boolean Eclosed = E.Closed();
154     Standard_Boolean dgE = BRep_Tool::Degenerated(TopoDS::Edge(E));
155     if      (dgE)     res = ISVERTEX;
156     else if (Eclosed) res = CLOSEDW;
157     else              res = UNCLOSEDW;
158   } 
159   else {
160     // Finding among all vertices,couple of vertices falling on same
161     // geometry.
162     // Filling up map <mapVV>,with (vi,vj),vi and vj are on same point.
163     Standard_Real tol = Precision::Confusion();
164     for (Standard_Integer i = 1;i <= nV;i++) {
165       const TopoDS_Vertex& vi = TopoDS::Vertex(mapVon1E.FindKey(i));
166       gp_Pnt pi = BRep_Tool::Pnt(vi);
167       for (Standard_Integer j = i+1;j <= nV;j++) {
168         const TopoDS_Vertex& vj = TopoDS::Vertex(mapVon1E.FindKey(j));
169         gp_Pnt pj = BRep_Tool::Pnt(vj);
170         Standard_Boolean same = pi.IsEqual(pj,tol);
171         if (same) {
172           mapVV.Add(vi,vj);
173           mapVV.Add(vj,vi);
174           break;
175         }
176       } // j
177     } // i
178     Standard_Integer nVV = mapVV.Extent();
179 #ifdef RM_HANGING
180     // MSV Oct 4, 2001: consider GCLOSEDW even if not all vertices from mapVon1E
181     //                  hit into mapVV; reason is the left vertices may start
182     //                  useless chains of hanging edges that can be removed to
183     //                  achieve a closed wire.
184     if (nVV > 0)   res = GCLOSEDW;
185 #else
186     if (nVV == nV) res = GCLOSEDW;
187 #endif
188     else           res = UNCLOSEDW;
189   }
190   return res;
191 } // FUN_AnalyzemapVon1E
192
193 #ifdef DRAW
194 void FUN_AnalyzemapVon1EDRAW(const Standard_Integer res,
195                              const TopTools_IndexedDataMapOfShapeShape& mapVon1E,
196                              const TopTools_IndexedDataMapOfShapeShape& mapVV,
197                              const TopoDS_Shape& W,const Standard_Integer iiwi,
198                              TopTools_IndexedDataMapOfShapeShape& mapVon1EdgeDRAW,
199                              TopTools_IndexedDataMapOfShapeShape& mapVVsameGDRAW)
200 {
201   Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE();
202   if (!trc) return;
203   cout<<"wire "<<iiwi;
204   if      (res == ISVERTEX) {
205     cout<<" is vertex"<<endl;
206   }
207   else if (res == CLOSEDW) {
208     cout<<" is closed"<<endl;
209   }
210   else if (res == GCLOSEDW) {
211     cout<<" is Gclosed :"<<endl;
212     TCollection_AsciiString aa("w_");FUN_tool_draw(aa,W,iiwi);
213     Standard_Integer i ;
214     for ( i = 1;i <= mapVV.Extent();i++) {
215       Standard_Integer iV = mapVVsameGDRAW.Add(mapVV.FindKey(i),mapVV.FindFromIndex(i));
216       cout<<" on vve_"<<iV; aa = "vve_";
217       FUN_tool_draw(aa,mapVVsameGDRAW.FindKey(iV),iV);
218     }
219     for (i = 1;i <= mapVon1E.Extent();i++) {
220       Standard_Integer iE = mapVon1EdgeDRAW.Add(mapVon1E.FindKey(i),mapVon1E.FindFromIndex(i));
221       cout<<" on eed_"<<iE; aa = "eed_";
222       FUN_tool_draw(aa,mapVon1EdgeDRAW.FindFromIndex(iE),iE);
223     }
224     cout<<endl;
225   }
226   else if (res == UNCLOSEDW) {
227     cout<<" is unclosed "<<endl;
228     TCollection_AsciiString aa("w_");FUN_tool_draw(aa,W,iiwi);
229   }
230   cout<<endl;
231 } // FUN_AnalyzemapVon1EDRAW
232 #endif
233
234 //=======================================================================
235 //function : DetectUnclosedWire
236 //purpose  : 
237 //=======================================================================
238 void TopOpeBRepBuild_FaceBuilder::DetectUnclosedWire(TopTools_IndexedDataMapOfShapeShape& mapVVsameG,
239                               TopTools_IndexedDataMapOfShapeShape& mapVon1Edge)
240 {
241   // wire unclosed : has vertices of connexity == 1
242   // exception : a wire of one closed edge with only one vertex describing
243   //             a face or a degenerated edge.
244
245   mapVVsameG.Clear();
246   mapVon1Edge.Clear();
247
248   // During the wire processing,
249   // * IF THE WIRE IS G-CLOSED,we fill up the maps :
250   //  - <mapVVsameG> with vertices falling on same geometry
251   //  - <mapVon1Edge> with (key = vertex,item = edge),
252   //    the vertex is connected to only one unclosed,undegenerated edge.
253   // * Else,if it is unclosed,we delete it (or it`s hanging edges).
254
255 #ifdef DRAW
256   TopTools_IndexedDataMapOfShapeShape mapVon1EdgeDRAW,mapVVsameGDRAW;
257   Standard_Boolean trc = TopOpeBRepBuild_GettracePURGE();
258   if (trc) cout<<endl<<"* DetectUnclosedWire :"<<endl<<endl;
259 #endif
260
261   Standard_Integer iiwi = 0; // DEB
262
263   InitFace();
264   for (;MoreFace();NextFace()) {
265    InitWire();
266     for (;MoreWire();NextWire()) { 
267       iiwi++;
268       Standard_Boolean isold = IsOldWire();
269 #ifdef DRAW
270       if ( trc && isold ) cout<<"wire "<<iiwi<<" is old wire => closed"<<endl;
271 #endif
272       if (isold) continue;
273       
274       TopoDS_Compound cmp;BRep_Builder BB;BB.MakeCompound(cmp);
275       InitEdge();
276       for(;MoreEdge();NextEdge()) AddEdgeWire(Edge(),cmp);
277       TopoDS_Shape W = cmp;
278
279       // <mapVon1E> binds vertices of connexity 1 attached to one non-closed,non-degenerated edge.
280       TopTools_IndexedDataMapOfShapeShape mapVon1E;
281       FUN_DetectVerticesOn1Edge(W,mapVon1E);
282
283       TopTools_IndexedDataMapOfShapeShape mapVV;
284       Standard_Integer res = FUN_AnalyzemapVon1E(mapVon1E,mapVV);
285 #ifdef DRAW
286       FUN_AnalyzemapVon1EDRAW(res,mapVon1E,mapVV,W,iiwi,mapVon1EdgeDRAW,mapVVsameGDRAW);
287 #endif
288
289       if      (res == ISVERTEX) {
290         continue;
291       }
292       else if (res == CLOSEDW) {
293         continue;
294       }
295       else if (res == GCLOSEDW) {
296         Standard_Integer i;
297         for (i = 1;i <= mapVV.Extent();i++) {
298           mapVVsameG.Add(mapVV.FindKey(i),mapVV.FindFromIndex(i));
299         }
300         for (i = 1;i <= mapVon1E.Extent();i++) {
301            mapVon1Edge.Add(mapVon1E.FindKey(i),mapVon1E.FindFromIndex(i));
302         }
303       }
304       else if (res == UNCLOSEDW) {
305 #ifdef RM_HANGING
306         // MSV Oct 4, 2001: remove hanging edges
307         TopTools_IndexedDataMapOfShapeListOfShape mapVE;
308         TopExp::MapShapesAndAncestors (W, TopAbs_VERTEX, TopAbs_EDGE, mapVE);
309         Standard_Integer nV = mapVon1E.Extent();
310         for (Standard_Integer i = 1; i <= nV; i++)
311         {
312           TopoDS_Vertex V = TopoDS::Vertex (mapVon1E.FindKey(i));
313           if (mapVV.Contains(V)) continue;  // V is in same geometry pair
314           while (1)
315           {
316             const TopTools_ListOfShape &LE = mapVE.FindFromKey(V);
317
318             // get not yet processed edge, count the number of such edges
319             Standard_Integer nEdges = 0;
320             TopoDS_Edge Edge;
321             TColStd_ListOfInteger LOI;
322             TopTools_ListIteratorOfListOfShape itE (LE);
323             for (; itE.More() && nEdges <= 1; itE.Next())
324             {
325               const TopoDS_Edge &E = TopoDS::Edge (itE.Value());
326               Standard_Integer I = myBlockBuilder.Element(E);
327               if (!E.Closed() && myBlockBuilder.ElementIsValid(I))
328               {
329                 TopoDS_Vertex Vf,Vl;
330                 TopExp::Vertices (E, Vf, Vl);
331                 LOI.Append(I);
332                 // consider not small edges only
333                 if (!Vf.IsSame(Vl))
334                 {
335                   Edge = E;
336                   nEdges++;
337                 }
338               }
339             }
340             if (nEdges != 1) break;  // stop this chain
341
342             // remove edges from Block Builder
343             TColStd_ListIteratorOfListOfInteger itLOI (LOI);
344             for (; itLOI.More(); itLOI.Next())
345               myBlockBuilder.SetValid (itLOI.Value(), Standard_False);
346
347             // get other vertex
348             TopoDS_Vertex aV1, aV2, otherV;
349             TopExp::Vertices (Edge, aV1, aV2);
350             if (aV1.IsSame (V))
351               otherV = aV2;
352             else if (aV2.IsSame (V))
353               otherV = aV1;
354             if (otherV.IsNull()) break;
355             V = otherV;
356           }
357         }
358 #else
359         TopExp_Explorer ex;
360         for (ex.Init(W,TopAbs_EDGE);ex.More();ex.Next()) {
361 //      for (TopExp_Explorer ex(W,TopAbs_EDGE);ex.More();ex.Next()) {
362           Standard_Integer I = myBlockBuilder.Element(ex.Current());
363           myBlockBuilder.SetValid(I,Standard_False);
364         }
365 #endif
366       }
367     } // MoreWire
368   } // MoreFace
369 } // DetectUnclosedWire
370
371 //=======================================================================
372 //function : CorrectGclosedWire
373 //purpose  :
374 //=======================================================================
375 void TopOpeBRepBuild_FaceBuilder::CorrectGclosedWire(const TopTools_IndexedDataMapOfShapeShape& mapVVref,
376                                const TopTools_IndexedDataMapOfShapeShape& mapVon1Edge)
377 {
378   // prequesitory : edges described by <mapVon1Edge> are not closed,not degenerated
379 #ifdef DEB
380   Standard_Boolean trc = TopOpeBRepDS_GettraceSTRANGE();
381   if (TopOpeBRepBuild_GettracePURGE()) {
382     cout<<endl<<"* CorrectGclosedWire :"<<endl<<endl;
383     trc = Standard_True;
384   }
385 #endif
386   
387   Standard_Integer nVV = mapVVref.Extent();
388   for (Standard_Integer i = 1;i <= nVV;i++) {
389     const TopoDS_Vertex& V = TopoDS::Vertex(mapVVref.FindKey(i));
390     const TopoDS_Vertex& Vref = TopoDS::Vertex(mapVVref.FindFromIndex(i));
391     
392     if (V.IsSame(Vref)) continue;
393
394     TopoDS_Edge E = TopoDS::Edge(mapVon1Edge.FindFromKey(V));
395     Standard_Real paronE = BRep_Tool::Parameter(V,E);
396     
397     BRep_Builder BB;E.Free(Standard_True);
398     BB.Remove(E,V);
399     TopoDS_Shape aLocalShape = Vref.Oriented(V.Orientation());
400     TopoDS_Vertex newVref = TopoDS::Vertex(aLocalShape);
401 //    TopoDS_Vertex newVref = TopoDS::Vertex(Vref.Oriented(V.Orientation()));
402     BB.Add(E,newVref);
403 #ifdef DEB
404     Standard_Integer iV = i,iVref = mapVVref.FindIndex(Vref),iE = mapVon1Edge.FindIndex(V);
405     if (trc) cout << " replacing V "<<iV<<" with V "<<iVref<<" on edge "<<iE<<endl;
406 #endif
407     TopOpeBRepDS_BuildTool BT;
408     BT.Parameter(E,newVref,paronE);
409   }
410 }
411
412 //=======================================================================
413 //function : DetectPseudoInternalEdge
414 //purpose  :
415 //=======================================================================
416 void TopOpeBRepBuild_FaceBuilder::DetectPseudoInternalEdge(TopTools_IndexedMapOfShape& MapE)
417 {
418   TopoDS_Compound cmp;BRep_Builder BB;BB.MakeCompound(cmp);
419   InitFace();
420   for (;MoreFace();NextFace()) {
421     InitWire();
422     for (;MoreWire();NextWire()) {
423       Standard_Boolean isold = IsOldWire(); if (isold) continue;
424       InitEdge();
425       for(;MoreEdge();NextEdge()) AddEdgeWire(Edge(),cmp);
426     } // MoreWire
427   } // MoreFace
428
429   TopTools_IndexedDataMapOfShapeListOfShape mapVOE;
430   TopExp::MapShapesAndAncestors(cmp,TopAbs_VERTEX,TopAbs_EDGE,mapVOE);
431   Standard_Integer nv = mapVOE.Extent();
432
433   MapE.Clear();
434   for (Standard_Integer i = 1; i <= nv; i++) {
435     const TopTools_ListOfShape& le = mapVOE.FindFromIndex(i);
436     Standard_Integer ne = le.Extent();
437     if (ne == 2) {
438       TopTools_ListIteratorOfListOfShape ile(le); const TopoDS_Shape& e1 = ile.Value();
439       ile.Next();        const TopoDS_Shape& e2 = ile.Value();
440       Standard_Boolean same = e1.IsSame(e2);
441       TopAbs_Orientation o1 = e1.Orientation();
442       TopAbs_Orientation o2 = e2.Orientation();
443       Standard_Boolean o1co2 = (o1 == TopAbs::Complement(o2));
444
445       if ( same && o1co2 ) {
446         MapE.Add(e1);
447
448         Standard_Integer ie1 = myBlockBuilder.Element(e1);
449         myBlockBuilder.SetValid(ie1,Standard_False);
450
451         Standard_Integer ie2 = myBlockBuilder.Element(e2);
452         myBlockBuilder.SetValid(ie2,Standard_False);
453       }
454     }
455   }
456
457 }
458
459 //=======================================================================
460 //function : Face
461 //purpose  : 
462 //=======================================================================
463 const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::Face() const 
464 {
465   return myFace;
466 }
467
468 //=======================================================================
469 //function : InitFace
470 //purpose  : 
471 //=======================================================================
472 Standard_Integer TopOpeBRepBuild_FaceBuilder::InitFace()
473 {
474   Standard_Integer n = myFaceAreaBuilder.InitArea();
475   return n;
476 }
477
478 //=======================================================================
479 //function : MoreFace
480 //purpose  : 
481 //=======================================================================
482 Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreFace() const
483 {
484   Standard_Boolean b = myFaceAreaBuilder.MoreArea();
485   return b;
486 }
487
488 //=======================================================================
489 //function : NextFace
490 //purpose  : 
491 //=======================================================================
492 void TopOpeBRepBuild_FaceBuilder::NextFace()
493 {
494   myFaceAreaBuilder.NextArea();
495 }
496
497 //=======================================================================
498 //function : InitWire
499 //purpose  : 
500 //=======================================================================
501 Standard_Integer TopOpeBRepBuild_FaceBuilder::InitWire()
502 {
503   Standard_Integer n = myFaceAreaBuilder.InitLoop();
504   return n;
505 }
506
507 //=======================================================================
508 //function : MoreWire
509 //purpose  : 
510 //=======================================================================
511 Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreWire() const
512 {
513   Standard_Boolean b = myFaceAreaBuilder.MoreLoop();
514   return b;
515 }
516
517 //=======================================================================
518 //function : NextWire
519 //purpose  : 
520 //=======================================================================
521 void TopOpeBRepBuild_FaceBuilder::NextWire()
522 {
523   myFaceAreaBuilder.NextLoop();
524 }
525
526 //=======================================================================
527 //function : IsOldWire
528 //purpose  : 
529 //=======================================================================
530 Standard_Boolean TopOpeBRepBuild_FaceBuilder::IsOldWire() const
531 {
532   const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop();
533   Standard_Boolean b = L->IsShape();
534   return b;
535 }
536
537 //=======================================================================
538 //function : OldWire
539 //purpose  : 
540 //=======================================================================
541 const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::OldWire() const
542 {
543   const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop();
544   const TopoDS_Shape& B = L->Shape();
545   return B;
546 }
547
548 //=======================================================================
549 //function : FindNextValidElement
550 //purpose  : 
551 //=======================================================================
552 void TopOpeBRepBuild_FaceBuilder::FindNextValidElement()
553 {
554   // prerequisites : myBlockIterator.Initialize
555   myFaceAreaBuilder.Loop();
556   Standard_Boolean found = Standard_False;
557
558   while ( myBlockIterator.More()) {
559     const Standard_Integer i = myBlockIterator.Value();
560     found = myBlockBuilder.ElementIsValid(i);
561     if (found) break;
562     else myBlockIterator.Next();
563   }
564 }
565
566 //=======================================================================
567 //function : InitEdge
568 //purpose  : 
569 //=======================================================================
570 Standard_Integer TopOpeBRepBuild_FaceBuilder::InitEdge()
571 {
572   const Handle(TopOpeBRepBuild_Loop)& L = myFaceAreaBuilder.Loop();
573   if ( L->IsShape() )
574     Standard_DomainError::Raise("TopOpeBRepBuild_FaceBuilder:InitEdge");
575   else {
576     myBlockIterator = L->BlockIterator();
577     myBlockIterator.Initialize();
578     FindNextValidElement();
579   }
580   Standard_Integer n = myBlockIterator.Extent();
581   return n;
582 }
583
584 //=======================================================================
585 //function : MoreEdge
586 //purpose  : 
587 //=======================================================================
588 Standard_Boolean TopOpeBRepBuild_FaceBuilder::MoreEdge() const
589 {
590   Standard_Boolean b = myBlockIterator.More();
591   return b;
592 }
593
594 //=======================================================================
595 //function : NextEdge
596 //purpose  : 
597 //=======================================================================
598 void TopOpeBRepBuild_FaceBuilder::NextEdge()
599 {
600   myBlockIterator.Next();
601   FindNextValidElement();
602 }
603
604 //=======================================================================
605 //function : Edge
606 //purpose  : 
607 //=======================================================================
608 const TopoDS_Shape& TopOpeBRepBuild_FaceBuilder::Edge() const
609 {
610   if (!myBlockIterator.More()) Standard_Failure::Raise("OutOfRange");
611
612   const Standard_Integer i = myBlockIterator.Value();
613   Standard_Boolean isvalid = myBlockBuilder.ElementIsValid(i);
614   if (!isvalid) Standard_Failure::Raise("Edge not Valid");
615
616   const TopoDS_Shape& E = myBlockBuilder.Element(i);
617   return E;
618 }
619
620 //=======================================================================
621 //function : EdgeConnexity
622 //purpose  : 
623 //=======================================================================
624 Standard_Integer TopOpeBRepBuild_FaceBuilder::EdgeConnexity(const TopoDS_Shape& /*E*/) const
625 {
626 #ifdef DEB
627   Standard_ProgramError::Raise("FaceBuilder::EdgeConnexity management disactivated");
628 #endif
629   return 0;
630 //  Standard_Boolean inmosi = myMOSI.IsBound(E);
631 //  Standard_Integer nmosi = (inmosi) ? myMOSI.Find(E) : 0;
632 //  return nmosi;
633 }
634
635 //=======================================================================
636 //function : AddEdgeWire
637 //purpose  : 
638 //=======================================================================
639 Standard_Integer TopOpeBRepBuild_FaceBuilder::AddEdgeWire(const TopoDS_Shape& E,TopoDS_Shape& W) const
640 {
641   Standard_Integer nadd = 0;
642   BRep_Builder BB;
643   BB.Add(W,E);nadd++;
644 //  Standard_Integer nmosi = EdgeConnexity(E);
645 //  Standard_Boolean addEC = (nmosi == 1);
646 //  if (addEC) {
647 //    TopAbs_Orientation oe = E.Orientation();
648 //    TopAbs_Orientation oc = TopAbs::Complement(oe);
649 //    TopoDS_Shape EC = E.Oriented(oc);
650 //    BB.Add(W,EC);nadd++;
651 //  }
652   return nadd;
653 }
654
655 //=======================================================================
656 //function : MakeLoops
657 //purpose  : 
658 //=======================================================================
659 void TopOpeBRepBuild_FaceBuilder::MakeLoops(TopOpeBRepBuild_ShapeSet& SS)
660 {
661   TopOpeBRepBuild_BlockBuilder& BB = myBlockBuilder;
662   TopOpeBRepBuild_ListOfLoop& LL = myLoopSet.ChangeListOfLoop();
663
664   // Build blocks on elements of SS
665   BB.MakeBlock(SS);
666
667   // make list of loop (LL) of the LoopSet
668   // - on shapes of the ShapeSet (SS)
669   // - on blocks of the BlockBuilder (BB)
670
671   // Add shapes of SS as shape loops
672   LL.Clear();
673   for(SS.InitShapes();SS.MoreShapes();SS.NextShape()) {
674     const TopoDS_Shape& S = SS.Shape();
675     Handle(TopOpeBRepBuild_Loop) ShapeLoop = new TopOpeBRepBuild_Loop(S);
676     LL.Append(ShapeLoop);
677   }
678   
679   // Add blocks of BB as block loops
680   for (BB.InitBlock();BB.MoreBlock();BB.NextBlock()) {
681     TopOpeBRepBuild_BlockIterator BI = BB.BlockIterator();
682     Handle(TopOpeBRepBuild_Loop) BlockLoop = new TopOpeBRepBuild_Loop(BI);
683     LL.Append(BlockLoop);
684   }
685
686 }