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