0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepFill / BRepFill_TrimShellCorner.cxx
CommitLineData
b311480e 1// Created on: 2003-10-21
2// Created by: Mikhail KLOKOV
973c2be1 3// Copyright (c) 2003-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <BOPAlgo_BOP.hxx>
18#include <BOPAlgo_PaveFiller.hxx>
19#include <BOPCol_DataMapOfShapeListOfShape.hxx>
20#include <BOPCol_ListOfShape.hxx>
21#include <BOPDS_DS.hxx>
7fd59977 22#include <BRep_Builder.hxx>
23#include <BRep_Tool.hxx>
42cf5bc1 24#include <BRepAlgoAPI_Section.hxx>
25#include <BRepFill_TrimShellCorner.hxx>
7fd59977 26#include <BRepLib_MakeEdge.hxx>
42cf5bc1 27#include <BRepLib_MakeWire.hxx>
7fd59977 28#include <BRepTools_ReShape.hxx>
42cf5bc1 29#include <gce_MakeLin.hxx>
30#include <GCPnts_UniformAbscissa.hxx>
31#include <Geom2d_Curve.hxx>
32#include <Geom_Curve.hxx>
33#include <GeomLib.hxx>
34#include <gp_Ax2.hxx>
35#include <gp_Pln.hxx>
36#include <gp_Pnt2d.hxx>
7fd59977 37#include <IntTools_BeanFaceIntersector.hxx>
1e143abb 38#include <IntTools_Context.hxx>
7fd59977 39#include <IntTools_Range.hxx>
42cf5bc1 40#include <IntTools_Tools.hxx>
41#include <TColgp_Array1OfDir.hxx>
42#include <TColgp_Array1OfPnt.hxx>
43#include <TColgp_Array2OfPnt.hxx>
44#include <TColgp_SequenceOfPnt.hxx>
45#include <TColStd_Array1OfBoolean.hxx>
46#include <TColStd_ListIteratorOfListOfInteger.hxx>
47#include <TColStd_ListOfInteger.hxx>
7fd59977 48#include <TopExp.hxx>
49#include <TopExp_Explorer.hxx>
42cf5bc1 50#include <TopLoc_Location.hxx>
51#include <TopoDS.hxx>
52#include <TopoDS_Compound.hxx>
53#include <TopoDS_Face.hxx>
54#include <TopoDS_Iterator.hxx>
55#include <TopoDS_Shape.hxx>
56#include <TopoDS_Shell.hxx>
57#include <TopoDS_Wire.hxx>
7fd59977 58#include <TopTools_Array1OfListOfShape.hxx>
4e57c75e 59#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
42cf5bc1 60#include <TopTools_DataMapOfShapeListOfShape.hxx>
61#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
62#include <TopTools_ListIteratorOfListOfShape.hxx>
63#include <TopTools_ListOfShape.hxx>
64#include <TopTools_MapOfShape.hxx>
7fd59977 65#include <TopTools_SequenceOfShape.hxx>
4e57c75e 66
4e57c75e 67static Standard_Boolean FindCommonVertex(const BOPDS_PDS& theDS,
68 const Standard_Integer theEIndex1,
69 const Standard_Integer theEIndex2,
70 TopoDS_Vertex& theCommonVertex,
71 Standard_Real& theParamOnE1,
72 Standard_Real& theParamOnE2);
7fd59977 73
74static Standard_Boolean MakeFacesNonSec(const Standard_Integer theIndex,
4e57c75e 75 const Handle(TopTools_HArray2OfShape)& theUEdges,
76 const Handle(TopTools_HArray2OfShape)& theBounds,
77 const BOPDS_PDS& theDS,
78 const Standard_Integer theFaceIndex1,
79 const Standard_Integer theFaceIndex2,
80 TopTools_DataMapOfShapeListOfShape& theHistMap);
7fd59977 81
82static Standard_Boolean MakeFacesSec(const Standard_Integer theIndex,
4e57c75e 83 const Handle(TopTools_HArray2OfShape)& theUEdges,
84 const Handle(TopTools_HArray2OfShape)& theBounds,
85 const BOPDS_PDS& theDS,
86 const Standard_Integer theFaceIndex1,
87 const Standard_Integer theFaceIndex2,
88 const Standard_Integer theSSInterfIndex,
89 const gp_Ax2& AxeOfBisPlane,
90 TopTools_DataMapOfShapeListOfShape& theHistMap);
7fd59977 91
92static Standard_Boolean SplitUEdges(const Handle(TopTools_HArray2OfShape)& theUEdges,
4e57c75e 93 const BOPDS_PDS& theDS,
94 TopTools_DataMapOfShapeListOfShape& theHistMap);
7fd59977 95
96static void FindFreeVertices(const TopoDS_Shape& theShape,
4e57c75e 97 const TopTools_MapOfShape& theVerticesToAvoid,
98 TopTools_ListOfShape& theListOfVertex);
7fd59977 99
100static Standard_Boolean CheckAndOrientEdges(const TopTools_ListOfShape& theOrderedList,
4e57c75e 101 const gp_Pnt2d& theFirstPoint,
102 const gp_Pnt2d& theLastPoint,
103 const TopoDS_Face& theFace,
104 TopTools_ListOfShape& theOrientedList);
7fd59977 105
106static Standard_Boolean FillGap(const TopoDS_Vertex& theFirstVertex,
4e57c75e 107 const TopoDS_Vertex& theLastVertex,
108 const gp_Pnt2d& theFirstPoint,
109 const gp_Pnt2d& theLastPoint,
110 const TopoDS_Face& theFace,
111 const TopoDS_Compound& theSectionEdges,
112 TopTools_ListOfShape& theOrderedList);
7fd59977 113
114static Standard_Boolean FindNextEdge(const TopoDS_Vertex& theFirstVertex,
4e57c75e 115 const TopoDS_Vertex& theLastVertex,
116 const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
117 const TopTools_MapOfShape& theMapToAvoid,
118 TopTools_ListOfShape& theOrderedList);
7fd59977 119
120static Standard_Boolean FindVertex(const TopoDS_Edge& theEdge,
4e57c75e 121 const Standard_Integer theRank,
122 const BOPDS_PDS& theDS,
123 const TopTools_DataMapOfShapeListOfShape& theHistMap,
124 TopoDS_Vertex& theVertex,
125 BOPDS_Pave& thePave);
7fd59977 126
127static Standard_Boolean FindNextVertex(const Standard_Integer theEdgeIndex,
4e57c75e 128 const BOPDS_Pave& thePrevPave,
129 const BOPDS_PDS& theDS,
130 TopoDS_Vertex& theNextVertex,
131 BOPDS_Pave& thePave);
7fd59977 132
4e57c75e 133static Standard_Boolean GetPave(const Standard_Integer theEdgeIndex,
134 const Standard_Boolean isFirst,
135 const BOPDS_PDS& theDS,
136 BOPDS_Pave& thePave);
7fd59977 137
138static Standard_Boolean FindFromUEdge(const TopoDS_Edge& theUE1Old,
4e57c75e 139 const TopoDS_Edge& theUE2Old,
140 const TopoDS_Edge& theUE1New,
141 const TopoDS_Edge& theUE2New,
142 const TopoDS_Face& theFace,
143 const TopoDS_Compound& theSecEdges,
144 const Standard_Integer theRank,
145 const TopoDS_Edge& theBoundEdge,
146 const Standard_Integer theBoundEdgeIndex,
147 const BOPDS_PDS& theDS,
148 const TopTools_DataMapOfShapeListOfShape& theHistMap,
149 TopoDS_Compound& theSecEdgesNew,
150 TopTools_ListOfShape& theListOfWireEdges,
151 BOPDS_Pave& theFoundPave,
152 Standard_Boolean& isOnUEdge);
153
154static Standard_Boolean FindFromVEdge(const BOPDS_Pave& thePrevPave,
155 const Standard_Boolean& isOnUEdge,
156 const TopoDS_Edge& theUE1Old,
157 const TopoDS_Edge& theUE2Old,
158 const TopoDS_Face& theFace,
159 const TopoDS_Compound& theSecEdges,
160 const Standard_Integer theRank,
161 const TopoDS_Edge& theBoundEdge,
162 const Standard_Integer theBoundEdgeIndex,
163 const BOPDS_PDS& theDS,
164 const TopTools_DataMapOfShapeListOfShape& theHistMap,
165 TopTools_ListOfShape& theListOfWireEdges,
166 Standard_Boolean& isSectionFound);
7fd59977 167
168static void RemoveEdges(const TopoDS_Compound& theSourceComp,
4e57c75e 169 const TopTools_ListOfShape& theListToRemove,
170 TopoDS_Compound& theResultComp);
7fd59977 171
4e57c75e 172static Standard_Boolean FilterSectionEdges(const BOPDS_VectorOfCurve& theBCurves,
173 const TopoDS_Face& theSecPlane,
174 const BOPDS_PDS& theDS,
175 TopoDS_Compound& theResult);
7fd59977 176
177static Standard_Boolean GetUEdges(const Standard_Integer theIndex,
4e57c75e 178 const Standard_Integer theRank,
179 const Handle(TopTools_HArray2OfShape)& theUEdges,
180 const TopoDS_Edge& theBoundEdge,
181 const TopoDS_Face& theFace,
182 TopoDS_Edge& theFirstUEdge,
183 TopoDS_Edge& theSecondUEdge);
7fd59977 184
185static Standard_Real ComputeAveragePlaneAndMaxDeviation(const TopoDS_Shape& aWire,
4e57c75e 186 gp_Pln& thePlane,
187 Standard_Boolean& IsSingular);
7fd59977 188
189static Standard_Boolean ChooseSection(const TopoDS_Shape& Comp,
4e57c75e 190 const gp_Ax2& bis,
191 TopoDS_Shape& resWire,
192 gp_Pln& resPlane,
193 Standard_Boolean& IsSingular);
7fd59977 194
7fd59977 195// ===========================================================================================
196// function: Constructor
197// purpose:
198// ===========================================================================================
199BRepFill_TrimShellCorner::BRepFill_TrimShellCorner(const Handle(TopTools_HArray2OfShape)& theFaces,
4e57c75e 200 const gp_Ax2& theAxeOfBisPlane,
201 const TopoDS_Face& theSecPlane) :
7fd59977 202myAxeOfBisPlane(theAxeOfBisPlane),
203myDone(Standard_False),
204myHasSection(Standard_False)
205{
206 myFaces = new TopTools_HArray2OfShape(theFaces->LowerRow(), theFaces->UpperRow(),
4e57c75e 207 theFaces->LowerCol(), theFaces->UpperCol());
7fd59977 208 myFaces->ChangeArray2() = theFaces->Array2();
209 mySecPln = theSecPlane;
210}
211
212// ===========================================================================================
213// function: Constructor
214// purpose:
215// ===========================================================================================
216BRepFill_TrimShellCorner::BRepFill_TrimShellCorner(const Handle(TopTools_HArray2OfShape)& theFaces,
4e57c75e 217 const gp_Ax2& theAxeOfBisPlane,
218 const TopoDS_Wire& theSpine,
219 const TopoDS_Face& theSecPlane):
7fd59977 220myAxeOfBisPlane(theAxeOfBisPlane),
221myDone(Standard_False),
222myHasSection(Standard_False)
223{
224 myFaces = new TopTools_HArray2OfShape(theFaces->LowerRow(), theFaces->UpperRow(),
4e57c75e 225 theFaces->LowerCol(), theFaces->UpperCol());
7fd59977 226 myFaces->ChangeArray2() = theFaces->Array2();
227 mySpine = theSpine;
228 mySecPln = theSecPlane;
229}
230
231// ===========================================================================================
232// function: SetSpine
233// purpose:
234// ===========================================================================================
235void BRepFill_TrimShellCorner::SetSpine(const TopoDS_Wire& theSpine)
236{
237 mySpine = theSpine;
238}
239
240// ===========================================================================================
241// function: AddBounds
242// purpose:
243// ===========================================================================================
244void BRepFill_TrimShellCorner::AddBounds(const Handle(TopTools_HArray2OfShape)& theBounds)
245{
246 myBounds = new TopTools_HArray2OfShape(theBounds->LowerRow(), theBounds->UpperRow(),
4e57c75e 247 theBounds->LowerCol(), theBounds->UpperCol());
7fd59977 248 myBounds->ChangeArray2() = theBounds->Array2();
249}
250
251// ===========================================================================================
252// function: AddUEdges
253// purpose:
254// ===========================================================================================
255void BRepFill_TrimShellCorner::AddUEdges(const Handle(TopTools_HArray2OfShape)& theUEdges)
256{
257 myUEdges = new TopTools_HArray2OfShape(theUEdges->LowerRow(), theUEdges->UpperRow(),
4e57c75e 258 theUEdges->LowerCol(), theUEdges->UpperCol());
7fd59977 259 myUEdges->ChangeArray2() = theUEdges->Array2();
260}
261
262// ===========================================================================================
263// function: Perform
264// purpose:
265// ===========================================================================================
266void BRepFill_TrimShellCorner::Perform()
267{
4e57c75e 268 Standard_Integer anIndex1, anIndex2, nF1, nF2, i, j, aNbP, aNbC;
269 Standard_Boolean bhassec;
270
7fd59977 271 myDone = Standard_False;
272 myHistMap.Clear();
273
274 if(myFaces->RowLength() != 2)
275 return;
276 Standard_Integer ii = 0, jj = 0;
277 BRep_Builder aBB;
278
279 for(jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
280 TopoDS_Shell aShell;
281 aBB.MakeShell(aShell);
282
283 for(ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
284 aBB.Add(aShell, myFaces->Value(ii, jj));
285 }
ab860031 286 aShell.Closed (BRep_Tool::IsClosed (aShell));
7fd59977 287
288 if(jj == myFaces->LowerCol()) {
289 myShape1 = aShell;
290 }
291 else {
292 myShape2 = aShell;
293 }
294 }
4e57c75e 295
296 BOPAlgo_PaveFiller aPF;
297 BOPCol_ListOfShape aLS;
298 aLS.Append(myShape1);
299 aLS.Append(myShape2);
300 aPF.SetArguments(aLS);
301 //
302 aPF.Perform();
303 if (aPF.ErrorStatus()) {
7fd59977 304 return;
305 }
4e57c75e 306 //
307 const BOPDS_PDS& theDS = aPF.PDS();
308 //
309 BOPDS_VectorOfInterfFF& aFFs = theDS->InterfFF();
7fd59977 310 Standard_Integer aNbFFs = aFFs.Extent();
311
4e57c75e 312 if(!SplitUEdges(myUEdges, theDS, myHistMap)) {
7fd59977 313 return;
314 }
315
316 for(ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
317 TopoDS_Shape aF1 = myFaces->Value(ii, myFaces->LowerCol());
318 TopoDS_Shape aF2 = myFaces->Value(ii, myFaces->UpperCol());
4e57c75e 319 //
320 anIndex1 = theDS->Index(aF1);
321 anIndex2 = theDS->Index(aF2);
322
323 if((anIndex1 == -1) || (anIndex2 == -1))
7fd59977 324 continue;
4e57c75e 325
326 for (i=0; i < aNbFFs; ++i) {
327 BOPDS_InterfFF& aFFi = aFFs(i);
328 aFFi.Indices(nF1, nF2);
329 //
330 BOPDS_VectorOfPoint& aVP=aFFi.ChangePoints();
331 aNbP=aVP.Extent();
332 BOPDS_VectorOfCurve& aVC=aFFi.ChangeCurves();
333 aNbC=aVC.Extent();
334 if (!aNbP && !aNbC) {
335 if (!theDS->HasInterfSubShapes(nF1, nF2)) {
336 continue;
337 }
338 }
7fd59977 339 //
7fd59977 340 if((nF1 == anIndex1) && (nF2 == anIndex2)) {
4e57c75e 341 const BOPDS_VectorOfCurve& aVC = aFFi.Curves();
342 bhassec = Standard_False;
343 //
344 for (j = 0; j < aNbC; ++j) {
345 const BOPDS_Curve& aBCurve = aVC(j);
346 const BOPDS_ListOfPaveBlock& aSectEdges = aBCurve.PaveBlocks();
347 //
348 if (aSectEdges.Extent()) {
349 bhassec = Standard_True;
350 break;
351 }
352 }
353
354 if(!bhassec) {
355 if(!MakeFacesNonSec(ii, myUEdges, myBounds, theDS, anIndex1, anIndex2, myHistMap)) {
356 myHistMap.Clear();
357 return;
358 }
359 }
360 else {
361 if(!MakeFacesSec(ii, myUEdges, myBounds, theDS, anIndex1, anIndex2,
362 i, myAxeOfBisPlane, myHistMap)) {
363 myHistMap.Clear();
364 return;
365 }
366 }
367 break;
7fd59977 368 }
369 }
370 }
371 myDone = Standard_True;
372}
373
374// ===========================================================================================
375// function: IsDone
376// purpose:
377// ===========================================================================================
378Standard_Boolean BRepFill_TrimShellCorner::IsDone() const
379{
380 return myDone;
381}
382
383// ===========================================================================================
384// function: HasSection
385// purpose:
386// ===========================================================================================
387Standard_Boolean BRepFill_TrimShellCorner::HasSection() const
388{
389 return myHasSection;
390}
391
392// ===========================================================================================
393// function: Modified
394// purpose:
395// ===========================================================================================
396void BRepFill_TrimShellCorner::Modified(const TopoDS_Shape& theShape,
4e57c75e 397 TopTools_ListOfShape& theModified)
7fd59977 398{
399 theModified.Clear();
400
401 if(myHistMap.IsBound(theShape)) {
402 theModified = myHistMap.Find(theShape);
403 }
404}
405
406// ----------------------------------------------------------------------------------------------------
407// static function: MakeFacesNonSec
408// purpose:
409// ----------------------------------------------------------------------------------------------------
410Standard_Boolean MakeFacesNonSec(const Standard_Integer theIndex,
4e57c75e 411 const Handle(TopTools_HArray2OfShape)& theUEdges,
412 const Handle(TopTools_HArray2OfShape)& theBounds,
413 const BOPDS_PDS& theDS,
414 const Standard_Integer theFaceIndex1,
415 const Standard_Integer theFaceIndex2,
416 TopTools_DataMapOfShapeListOfShape& theHistMap)
7fd59977 417{
7fd59977 418 Standard_Boolean bHasNewEdge = Standard_False;
419 TopoDS_Edge aNewEdge;
7fd59977 420
421 BRep_Builder aBB;
422 const TopoDS_Shape& aE1 = theBounds->Value(theIndex, 1);
423 const TopoDS_Shape& aE2 = theBounds->Value(theIndex, 2);
424
425 // search common vertex between bounds. begin
426 TopoDS_Vertex aCommonVertex;
4e57c75e 427 Standard_Integer anIndex1 = theDS->Index(aE1);
428 Standard_Integer anIndex2 = theDS->Index(aE2);
7fd59977 429 Standard_Real apar1 = 0., apar2 = 0.;
430
431 Standard_Boolean bvertexfound =
4e57c75e 432 FindCommonVertex(theDS, anIndex1, anIndex2, aCommonVertex, apar1, apar2);
7fd59977 433 // search common vertex between bounds. end
434
435 Handle(BRepTools_ReShape) aSubstitutor = new BRepTools_ReShape();
436
437 // search common vertices between uedges. begin
438 TopTools_ListOfShape aCommonVertices;
439 Standard_Boolean acommonflag = 0; // 0 - no, 1 - first pair, 2 - second pair, 3 - both
440 Standard_Integer ueit = 0, eindex = 0;
441
442 for(ueit = 1, eindex = theIndex; ueit <= 2; ueit++, eindex++) {
443 const TopoDS_Shape& aShape1 = theUEdges->Value(eindex, theUEdges->LowerCol());
444 const TopoDS_Shape& aShape2 = theUEdges->Value(eindex, theUEdges->UpperCol());
445 TopoDS_Edge aUE1 = TopoDS::Edge(aShape1);
446 TopoDS_Edge aUE2 = TopoDS::Edge(aShape2);
447
448 if(theHistMap.IsBound(aShape1)) {
449 const TopTools_ListOfShape& lst = theHistMap.Find(aShape1);
450
451 if(!lst.IsEmpty())
4e57c75e 452 aUE1 = TopoDS::Edge(lst.First());
7fd59977 453 }
454
455 if(theHistMap.IsBound(aShape2)) {
456 const TopTools_ListOfShape& lst = theHistMap.Find(aShape2);
457
458 if(!lst.IsEmpty())
4e57c75e 459 aUE2 = TopoDS::Edge(lst.First());
7fd59977 460 }
461
462 if(!aShape1.IsSame(aUE1))
463 aSubstitutor->Replace(aShape1.Oriented(TopAbs_FORWARD), aUE1.Oriented(TopAbs_FORWARD));
464
465 if(!aShape2.IsSame(aUE2))
466 aSubstitutor->Replace(aShape2.Oriented(TopAbs_FORWARD), aUE2.Oriented(TopAbs_FORWARD));
467
468 TopoDS_Vertex V1 = TopExp::LastVertex(aUE1);
469 TopoDS_Vertex V2 = TopExp::FirstVertex(aUE2);
470
471 if(V1.IsSame(V2)) {
472 acommonflag = (acommonflag == 0) ? ueit : 3;
473 aCommonVertices.Append(V1);
474 }
475 }
476 // search common vertices between uedges. end
477
478 if(bvertexfound) {
479 if(aCommonVertices.Extent() != 1)
480 return Standard_False;
481
482 if(acommonflag == 1)
483 aNewEdge = BRepLib_MakeEdge(TopoDS::Vertex(aCommonVertices.First()), aCommonVertex);
484 else
485 aNewEdge = BRepLib_MakeEdge(aCommonVertex, TopoDS::Vertex(aCommonVertices.First()));
486
487 bHasNewEdge = Standard_True;
488 }
489
490 if(aCommonVertices.Extent() == 2) {
491 aNewEdge = BRepLib_MakeEdge(TopoDS::Vertex(aCommonVertices.First()),
4e57c75e 492 TopoDS::Vertex(aCommonVertices.Last()));
7fd59977 493 bHasNewEdge = Standard_True;
494 }
495 Standard_Integer fit = 0;
496
497 for(fit = 1; fit <= 2; fit++) {
498 TopoDS_Compound aComp;
499 TopTools_MapOfShape aMapV;
500 aBB.MakeCompound(aComp);
501
502 for(ueit = 1, eindex = theIndex; ueit <= 2; ueit++, eindex++) {
503 const TopoDS_Shape& aShape = theUEdges->Value(eindex, theUEdges->LowerCol() + fit - 1);
504 TopoDS_Shape aUE = aShape;
505
506 if(theHistMap.IsBound(aShape)) {
4e57c75e 507 const TopTools_ListOfShape& lst = theHistMap.Find(aShape);
7fd59977 508
4e57c75e 509 if(!lst.IsEmpty())
510 aUE = TopoDS::Edge(lst.First());
7fd59977 511 }
512 const TopoDS_Shape& aV = (fit == 1) ? TopExp::FirstVertex(TopoDS::Edge(aUE)) : TopExp::LastVertex(TopoDS::Edge(aUE));
513 aMapV.Add(aV);
514 aBB.Add(aComp, aUE);
515 }
516 if(bHasNewEdge) {
517 aBB.Add(aComp, aNewEdge);
518 }
519 TopTools_ListOfShape alonevertices;
520 FindFreeVertices(aComp, aMapV, alonevertices);
521
522 if(!alonevertices.IsEmpty() && (alonevertices.Extent() != 2))
523 return Standard_False;
524
525 Standard_Integer aFaceIndex = (fit == 1) ? theFaceIndex1 : theFaceIndex2;
4e57c75e 526 TopoDS_Shape aFace = theDS->Shape(aFaceIndex);
7fd59977 527 TopAbs_Orientation aFaceOri = aFace.Orientation();
7fd59977 528 aFace.Orientation(TopAbs_FORWARD);
529
530 TopExp_Explorer anExpE(aFace, TopAbs_EDGE);
7fd59977 531
532 if(bHasNewEdge) {
533 aNewEdge.Orientation(TopAbs_FORWARD);
534 }
535
536 TopTools_ListOfShape aOrderedList;
537
538 if(!alonevertices.IsEmpty()) {
539 Standard_Integer anEIndex = (fit == 1) ? anIndex1 : anIndex2;
7fd59977 540 Standard_Boolean bfound1 = Standard_False;
541 Standard_Boolean bfound2 = Standard_False;
542 Standard_Real aparam1 = 0., aparam2 = 0.;
543
4e57c75e 544 BOPDS_ListOfPave aLP;
545 theDS->Paves(anEIndex, aLP);
546 BOPDS_ListIteratorOfListOfPave aIt;
547 aIt.Initialize(aLP);
548 for ( ; aIt.More(); aIt.Next()) {
549 const BOPDS_Pave& aPave = aIt.Value();
550 TopoDS_Shape aV = theDS->Shape(aPave.Index());
551
552 if(aV.IsSame(alonevertices.First())) {
553 if(!bfound1) {
554 aparam1 = aPave.Parameter();
555 bfound1 = Standard_True;
556 }
557 }
558
559 if(aV.IsSame(alonevertices.Last())) {
560 if(!bfound2) {
561 aparam2 = aPave.Parameter();
562 bfound2 = Standard_True;
563 }
564 }
7fd59977 565 }
566
567 if(bfound1 && bfound2) {
4e57c75e 568 TopoDS_Edge aNewBoundE;
569
570 if(fit == 1) {
571 aNewBoundE = TopoDS::Edge(aE1.EmptyCopied());
572 }
573 else {
574 aNewBoundE = TopoDS::Edge(aE2.EmptyCopied());
575 }
576 TopoDS_Vertex aV1, aV2;
577
578 if(aparam1 < aparam2) {
579 aV1 = TopoDS::Vertex(alonevertices.First());
580 aV2 = TopoDS::Vertex(alonevertices.Last());
581 }
582 else {
583 aV1 = TopoDS::Vertex(alonevertices.Last());
584 aV2 = TopoDS::Vertex(alonevertices.First());
585 Standard_Real tmp = aparam1;
586 aparam1 = aparam2;
587 aparam2 = tmp;
588 }
589 aV1.Orientation(TopAbs_FORWARD);
590 aV2.Orientation(TopAbs_REVERSED);
591 aBB.Add(aNewBoundE, aV1);
592 aBB.Add(aNewBoundE, aV2);
593 aBB.Range(aNewBoundE, aparam1, aparam2);
594 aNewBoundE.Orientation(TopAbs_FORWARD);
595
596 aOrderedList.Append(aNewBoundE);
597
598 if(bHasNewEdge) {
599 TopExp_Explorer anExpV(aNewEdge, TopAbs_VERTEX);
600 Standard_Boolean bfoundv = Standard_False;
601
602 for(; !bfoundv && anExpV.More(); anExpV.Next()) {
603 if(aV2.IsSame(anExpV.Current()))
604 bfoundv = Standard_True;
605 }
606
607 if(bfoundv)
608 aOrderedList.Append(aNewEdge);
609 else
610 aOrderedList.Prepend(aNewEdge);
611 }
7fd59977 612 }
613 else {
4e57c75e 614 return Standard_False;
7fd59977 615 }
616 }
617 else {
618 if(bHasNewEdge) {
4e57c75e 619 aOrderedList.Append(aNewEdge);
7fd59977 620 }
621 }
622
623 if(!aOrderedList.IsEmpty()) {
624 TopoDS_Wire aW;
625 aBB.MakeWire(aW);
626 TopTools_ListIteratorOfListOfShape anItE(aOrderedList);
627
628 for(; anItE.More(); anItE.Next()) {
4e57c75e 629 aBB.Add(aW, anItE.Value());
7fd59977 630 }
631 if(fit == 1)
4e57c75e 632 aSubstitutor->Replace(aE1.Oriented(TopAbs_FORWARD), aW);
7fd59977 633 else
4e57c75e 634 aSubstitutor->Replace(aE2.Oriented(TopAbs_FORWARD), aW);
7fd59977 635 }
636
637 aSubstitutor->Apply(aFace);
638 TopoDS_Shape aNewFace = aSubstitutor->Value(aFace);
639 aNewFace.Orientation(aFaceOri);
640 TopTools_ListOfShape atmpList;
641 atmpList.Append(aNewFace);
642 theHistMap.Bind(aFace, atmpList);
643
644 anExpE.Init(aFace, TopAbs_EDGE);
645
646 for(; anExpE.More(); anExpE.Next()) {
647 TopoDS_Shape aNewValue = aSubstitutor->Value(anExpE.Current());
648
649 if(aNewValue.IsNull() || aNewValue.IsSame(anExpE.Current()))
4e57c75e 650 continue;
7fd59977 651
652 if(theHistMap.IsBound(anExpE.Current()))
4e57c75e 653 continue;
7fd59977 654 TopTools_ListOfShape aListOfNewEdge;
655 TopExp_Explorer anExpE2(aNewValue, TopAbs_EDGE);
656
657 for(; anExpE2.More(); anExpE2.Next()) {
4e57c75e 658 aListOfNewEdge.Append(anExpE2.Current());
7fd59977 659 }
660 theHistMap.Bind(anExpE.Current(), aListOfNewEdge);
661 }
662 }
663
664 return Standard_True;
665}
666
667// ----------------------------------------------------------------------------------------------------
668// static function: MakeFacesSec
669// purpose:
670// ----------------------------------------------------------------------------------------------------
671Standard_Boolean MakeFacesSec(const Standard_Integer theIndex,
4e57c75e 672 const Handle(TopTools_HArray2OfShape)& theUEdges,
673 const Handle(TopTools_HArray2OfShape)& theBounds,
674 const BOPDS_PDS& theDS,
675 const Standard_Integer theFaceIndex1,
676 const Standard_Integer theFaceIndex2,
677 const Standard_Integer theSSInterfIndex,
678 const gp_Ax2& AxeOfBisPlane,
679 TopTools_DataMapOfShapeListOfShape& theHistMap)
7fd59977 680{
4e57c75e 681 const BOPDS_VectorOfInterfFF& aFFs = theDS->InterfFF();
682 const BOPDS_InterfFF& aFFi = aFFs(theSSInterfIndex);
683 const BOPDS_VectorOfCurve& aBCurves = aFFi.Curves();
684
7fd59977 685 TopoDS_Compound aSecEdges;
7fd59977 686 TopoDS_Face aSecPlane;
687
4e57c75e 688 if(!FilterSectionEdges(aBCurves, aSecPlane, theDS, aSecEdges))
7fd59977 689 return Standard_False;
690
691 TopoDS_Shape SecWire;
692 gp_Pln SecPlane;
693 Standard_Boolean IsSingular;
694 Standard_Boolean WireFound = ChooseSection( aSecEdges, AxeOfBisPlane, SecWire, SecPlane, IsSingular );
695
696 if(WireFound) {
697 //aSecEdges = SecWire;
698 TopoDS_Compound aComp;
699 BRep_Builder BB;
700 BB.MakeCompound(aComp);
701 TopExp_Explorer explo( SecWire, TopAbs_EDGE );
702
703 for (; explo.More(); explo.Next())
704 BB.Add( aComp, explo.Current() );
705 aSecEdges = aComp;
706 }
707
708 TopTools_ListOfShape aCommonVertices;
709// Standard_Boolean acommonflag = 0; // 0 - no, 1 - first pair, 2 - second pair, 3 - both
710 Standard_Integer fit = 0; //, ueit = 0, eindex = 0, i = 0;
711 Handle(BRepTools_ReShape) aSubstitutor = new BRepTools_ReShape();
712
4e57c75e 713 for(fit = 0; fit < 2; fit++) {
714 Standard_Integer aFaceIndex = (fit == 0) ? theFaceIndex1 : theFaceIndex2;
715 TopoDS_Face aFace = TopoDS::Face(theDS->Shape(aFaceIndex));
7fd59977 716 TopAbs_Orientation aFaceOri = aFace.Orientation();
717 TopoDS_Face aFaceF = aFace;
718 aFaceF.Orientation(TopAbs_FORWARD);
4e57c75e 719 TopoDS_Edge aBoundEdge = TopoDS::Edge(theBounds->Value(theIndex, theBounds->LowerCol() +fit));
720 Standard_Integer aBoundEdgeIndex = theDS->Index(aBoundEdge);
7fd59977 721 TopoDS_Edge aUE1;
722 TopoDS_Edge aUE2;
723
724 if(!GetUEdges(theIndex, fit, theUEdges, aBoundEdge, aFaceF, aUE1, aUE2))
725 return Standard_False;
726
727 TopoDS_Edge aUE1old = aUE1;
728 TopoDS_Edge aUE2old = aUE2;
729
730 if(theHistMap.IsBound(aUE1)) {
731 const TopTools_ListOfShape& lst = theHistMap.Find(aUE1);
732
733 if(!lst.IsEmpty()) {
4e57c75e 734 const TopoDS_Shape& anEdge = lst.First().Oriented(aUE1.Orientation());
7fd59977 735
4e57c75e 736 if(!aUE1.IsSame(anEdge))
737 aSubstitutor->Replace(aUE1.Oriented(TopAbs_FORWARD), anEdge.Oriented(TopAbs_FORWARD));
738 aUE1 = TopoDS::Edge(anEdge);
7fd59977 739 }
740 }
741
742 if(theHistMap.IsBound(aUE2)) {
743 const TopTools_ListOfShape& lst = theHistMap.Find(aUE2);
744
745 if(!lst.IsEmpty()) {
4e57c75e 746 const TopoDS_Shape& anEdge = lst.First().Oriented(aUE2.Orientation());
7fd59977 747
4e57c75e 748 if(!aUE2.IsSame(anEdge))
749 aSubstitutor->Replace(aUE2.Oriented(TopAbs_FORWARD), anEdge.Oriented(TopAbs_FORWARD));
750 aUE2 = TopoDS::Edge(anEdge);
7fd59977 751 }
752 }
753 TopoDS_Vertex aPrevVertex, aNextVertex;
754 TopoDS_Compound aCompOfSecEdges = aSecEdges;
755 TopTools_ListOfShape aListOfWireEdges;
756 BRep_Builder aBB;
4e57c75e 757 BOPDS_Pave aPave1;
7fd59977 758 Standard_Boolean isPave1OnUEdge = Standard_True;
759
760 if(FindFromUEdge(aUE1old, aUE2old, aUE1, aUE2, aFace, aSecEdges, fit, aBoundEdge, aBoundEdgeIndex,
4e57c75e 761 theDS, theHistMap, aCompOfSecEdges, aListOfWireEdges, aPave1, isPave1OnUEdge)) {
7fd59977 762 TopTools_ListOfShape aSecondListOfEdges;
763 Standard_Boolean bisSectionFound = Standard_False;
764
765 if(!FindFromVEdge(aPave1, isPave1OnUEdge, aUE1old, aUE2old, aFace, aCompOfSecEdges, fit, aBoundEdge,
4e57c75e 766 aBoundEdgeIndex, theDS, theHistMap, aSecondListOfEdges, bisSectionFound)) {
767 return Standard_False;
7fd59977 768 }
769
770 if(!bisSectionFound && aListOfWireEdges.IsEmpty()) {
4e57c75e 771 return Standard_False;
7fd59977 772 }
773 aListOfWireEdges.Append(aSecondListOfEdges);
774 }
775 else {
776 return Standard_False;
777 }
778
779 if(!aListOfWireEdges.IsEmpty()) {
780 TopoDS_Wire aW;
781 aBB.MakeWire(aW);
782 TopTools_ListIteratorOfListOfShape aEIt(aListOfWireEdges);
783
784 for(; aEIt.More(); aEIt.Next()) {
4e57c75e 785 if(!aBoundEdge.IsSame(aEIt.Value()))
786 aBB.Add(aW, aEIt.Value());
7fd59977 787 }
788 aSubstitutor->Replace(aBoundEdge.Oriented(TopAbs_FORWARD), aW);
789 }
790
791 aSubstitutor->Apply(aFace);
792 TopoDS_Shape aNewFace = aSubstitutor->Value(aFace);
793 aNewFace.Orientation(aFaceOri);
794 TopTools_ListOfShape atmpList;
795 atmpList.Append(aNewFace);
796 theHistMap.Bind(aFace, atmpList);
797
798 TopExp_Explorer anExpE(aFace, TopAbs_EDGE);
799
800 for(; anExpE.More(); anExpE.Next()) {
801 TopoDS_Shape aNewValue = aSubstitutor->Value(anExpE.Current());
802
803 if(aNewValue.IsNull() || aNewValue.IsSame(anExpE.Current()))
4e57c75e 804 continue;
7fd59977 805
806 if(theHistMap.IsBound(anExpE.Current()))
4e57c75e 807 continue;
7fd59977 808 TopTools_ListOfShape aListOfNewEdge;
809 TopExp_Explorer anExpE2(aNewValue, TopAbs_EDGE);
810
811 for(; anExpE2.More(); anExpE2.Next()) {
4e57c75e 812 aListOfNewEdge.Append(anExpE2.Current());
7fd59977 813 }
814 theHistMap.Bind(anExpE.Current(), aListOfNewEdge);
815 }
816 }
817 return Standard_True;
818}
819
820
821// ------------------------------------------------------------------------------------------
822// static function: SplitUEdges
823// purpose:
824// ------------------------------------------------------------------------------------------
825Standard_Boolean SplitUEdges(const Handle(TopTools_HArray2OfShape)& theUEdges,
4e57c75e 826 const BOPDS_PDS& theDS,
827 TopTools_DataMapOfShapeListOfShape& theHistMap) {
828
4e57c75e 829 const BOPDS_VectorOfInterfVV& aVVs = theDS->InterfVV();
7fd59977 830
831 BRep_Builder aBB;
4e57c75e 832 Standard_Integer ueit = 0, upRow, lowCol, upCol;
7fd59977 833 TopTools_Array2OfShape aNewVertices(1,2,1,2);
4e57c75e 834 //
835 upRow = theUEdges->UpperRow();
836 lowCol = theUEdges->LowerCol();
837 upCol = theUEdges->UpperCol();
838 //
839 for(ueit = theUEdges->LowerRow(); ueit <= upRow; ueit++) {
840 const TopoDS_Shape& aE1 = theUEdges->Value(ueit, lowCol);
841 const TopoDS_Shape& aE2 = theUEdges->Value(ueit, upCol);
7fd59977 842
843 if(theHistMap.IsBound(aE1) || theHistMap.IsBound(aE2))
844 continue;
845
4e57c75e 846 Standard_Integer anEIndex1 = theDS->Index(aE1);
847 Standard_Integer anEIndex2 = theDS->Index(aE2);
7fd59977 848
849 TopoDS_Vertex aCommonVertex;
850 Standard_Real apar1 = 0., apar2 = 0.;
851 Standard_Boolean bvertexfound =
4e57c75e 852 FindCommonVertex(theDS, anEIndex1, anEIndex2, aCommonVertex, apar1, apar2);
853 //
7fd59977 854 if(!bvertexfound) {
855 TopoDS_Vertex V1 = TopExp::LastVertex(TopoDS::Edge(aE1));
856 TopoDS_Vertex V2 = TopExp::FirstVertex(TopoDS::Edge(aE2));
4e57c75e 857 Standard_Integer vindex1 = theDS->Index(V1);
858 Standard_Integer vindex2 = theDS->Index(V2);
7fd59977 859 Standard_Integer vvit = 0;
4e57c75e 860 Standard_Integer aNbVVs = aVVs.Extent();
861
862 for(vvit = 0; !bvertexfound && (vvit < aNbVVs); vvit++) {
863 //const BOPTools_VVInterference& aVV = aVVs(vvit);
864 const BOPDS_InterfVV& aVV = aVVs(vvit);
865
498ce76b 866 if(((vindex1 == aVV.Index1()) && (vindex2 == aVV.Index2())) ||
867 ((vindex1 == aVV.Index2()) && (vindex2 == aVV.Index1()))) {
4e57c75e 868
869 if(!aVV.HasIndexNew()) {
870 continue;
871 }
872 aCommonVertex = TopoDS::Vertex(theDS->Shape(aVV.IndexNew()));
873 bvertexfound = Standard_True;
874 apar1 = BRep_Tool::Parameter(V1, TopoDS::Edge(aE1));
875 apar2 = BRep_Tool::Parameter(V2, TopoDS::Edge(aE2));
876 }
7fd59977 877 }
878 }
879
880 if(bvertexfound) {
881 TopoDS_Vertex aV1, aV2;
882 Standard_Real f = 0., l = 0.;
883 //
884 TopoDS_Edge aNewE1 = TopoDS::Edge(aE1.EmptyCopied());
885 TopExp::Vertices(TopoDS::Edge(aE1), aV1, aV2);
886 aNewE1.Orientation(TopAbs_FORWARD);
887 aV1.Orientation(TopAbs_FORWARD);
888 aBB.Add(aNewE1, aV1);
889 aCommonVertex.Orientation(TopAbs_REVERSED);
890 aBB.Add(aNewE1, aCommonVertex);
891 BRep_Tool::Range(TopoDS::Edge(aE1), f, l);
892 aBB.Range(aNewE1, f, apar1);
893
894 //
895 TopoDS_Edge aNewE2 = TopoDS::Edge(aE2.EmptyCopied());
896 TopExp::Vertices(TopoDS::Edge(aE2), aV1, aV2);
897 aNewE2.Orientation(TopAbs_FORWARD);
898 aCommonVertex.Orientation(TopAbs_FORWARD);
899 aBB.Add(aNewE2, aCommonVertex);
900 aBB.Add(aNewE2, aV2);
901 BRep_Tool::Range(TopoDS::Edge(aE2), f, l);
902 aBB.Range(aNewE2, apar2, l);
903
904 TopTools_ListOfShape lst;
905 lst.Append(aNewE1);
906 theHistMap.Bind(aE1, lst);
907 lst.Clear();
908 lst.Append(aNewE2);
909 theHistMap.Bind(aE2, lst);
910 }
911 }
912 return Standard_True;
913}
914
915// ------------------------------------------------------------------------------------------
916// static function: FindFreeVertices
917// purpose:
918// ------------------------------------------------------------------------------------------
919void FindFreeVertices(const TopoDS_Shape& theShape,
4e57c75e 920 const TopTools_MapOfShape& theVerticesToAvoid,
921 TopTools_ListOfShape& theListOfVertex) {
7fd59977 922
923 theListOfVertex.Clear();
924 TopTools_IndexedDataMapOfShapeListOfShape aMap;
925 TopExp::MapShapesAndAncestors(theShape, TopAbs_VERTEX, TopAbs_EDGE, aMap);
926 Standard_Integer i = 0;
927
928 for(i = 1; i <= aMap.Extent(); i++) {
929 const TopoDS_Shape& aKey = aMap.FindKey(i);
930
931 if(theVerticesToAvoid.Contains(aKey))
932 continue;
933 const TopTools_ListOfShape& aList = aMap.FindFromIndex(i);
934
935 if(aList.Extent() < 2) {
936 theListOfVertex.Append(aKey);
937 }
938 }
939}
940
7fd59977 941// ------------------------------------------------------------------------------------------
942// static function: FindCommonVertex
943// purpose:
944// ------------------------------------------------------------------------------------------
4e57c75e 945Standard_Boolean FindCommonVertex(const BOPDS_PDS& theDS,
946 const Standard_Integer theEIndex1,
947 const Standard_Integer theEIndex2,
948 TopoDS_Vertex& theCommonVertex,
949 Standard_Real& theParamOnE1,
950 Standard_Real& theParamOnE2) {
951
952 const BOPDS_VectorOfInterfEE& aEEs = theDS->InterfEE();
7fd59977 953
954 Standard_Boolean bvertexfound = Standard_False;
955 TopoDS_Vertex aCommonVertex;
956 Standard_Integer eeit = 0;
957
4e57c75e 958 Standard_Integer aNbEEs;
959 aNbEEs = aEEs.Extent();
960 for(eeit = 0; eeit < aNbEEs; ++eeit) {
961 const BOPDS_InterfEE& aEE = aEEs(eeit);
7fd59977 962
963 if((theEIndex1 == aEE.Index1() && theEIndex2 == aEE.Index2()) ||
964 (theEIndex1 == aEE.Index2() && theEIndex2 == aEE.Index1())) {
965
4e57c75e 966 if(!aEE.HasIndexNew())
967 continue;
968
969 IntTools_CommonPrt aCP = aEE.CommonPart();
970 if(aCP.Type() == TopAbs_VERTEX) {
971 theCommonVertex = *(TopoDS_Vertex*)&theDS->Shape(aEE.IndexNew());
972 if (theEIndex1 == aEE.Index1()) {
1e143abb 973 IntTools_Tools::VertexParameters(aCP, theParamOnE1, theParamOnE2);
4e57c75e 974 } else {
1e143abb 975 IntTools_Tools::VertexParameters(aCP, theParamOnE2, theParamOnE1);
4e57c75e 976 }
977 //
978 bvertexfound = Standard_True;
979 break;
7fd59977 980 }
981 }
982 }
983 return bvertexfound;
984}
985
7fd59977 986// ----------------------------------------------------------------------------------------------------
987// static function: GetUEdges
988// purpose:
989// ----------------------------------------------------------------------------------------------------
990Standard_Boolean GetUEdges(const Standard_Integer theIndex,
4e57c75e 991 const Standard_Integer theRank,
992 const Handle(TopTools_HArray2OfShape)& theUEdges,
993 const TopoDS_Edge& theBoundEdge,
994 const TopoDS_Face& theFace,
995 TopoDS_Edge& theFirstUEdge,
996 TopoDS_Edge& theSecondUEdge) {
997 const TopoDS_Shape& aUE1 = theUEdges->Value(theIndex, theUEdges->LowerCol() + theRank);
998 const TopoDS_Shape& aUE2 = theUEdges->Value(theIndex + 1, theUEdges->LowerCol() + theRank);
7fd59977 999
1000 TopoDS_Face aFace = theFace;
1001 aFace.Orientation(TopAbs_FORWARD);
1002 TopoDS_Edge E1, E2;
1003 TopExp_Explorer anExp(aFace, TopAbs_EDGE);
1004
1005 for(; anExp.More(); anExp.Next()) {
1006 if(E1.IsNull() && aUE1.IsSame(anExp.Current())) {
1007 E1 = TopoDS::Edge(anExp.Current());
1008 }
1009 else if(E2.IsNull() && aUE2.IsSame(anExp.Current())) {
1010 E2 = TopoDS::Edge(anExp.Current());
1011 }
1012 }
1013
1014 if(E1.IsNull() || E2.IsNull())
1015 return Standard_False;
1016
1017 Standard_Real f, l;
1018 Handle(Geom2d_Curve) C1 = BRep_Tool::CurveOnSurface(E1, aFace, f, l);
1019
1020 if(C1.IsNull())
1021 return Standard_False;
4e57c75e 1022 gp_Pnt2d PU1 = (theRank == 0) ? C1->Value(l) : C1->Value(f);
7fd59977 1023 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(theBoundEdge, aFace, f, l);
1024
1025 if(C2.IsNull())
1026 return Standard_False;
1027 BRep_Tool::Range(theBoundEdge, f, l);
1028 gp_Pnt2d pf = C2->Value(f);
4e57c75e 1029 TopoDS_Vertex aV = (theRank == 0) ? TopExp::LastVertex(E1) : TopExp::FirstVertex(E1);
7fd59977 1030 Standard_Real aTolerance = BRep_Tool::Tolerance(aV);
1031 BRepAdaptor_Surface aBAS(aFace, Standard_False);
1032
1033 if(pf.Distance(PU1) > aBAS.UResolution(aTolerance)) {
1034 TopoDS_Edge atmpE = E1;
1035 E1 = E2;
1036 E2 = atmpE;
1037 }
1038 theFirstUEdge = E1;
1039 theSecondUEdge = E2;
1040 return Standard_True;
1041}
1042
1043// ----------------------------------------------------------------------------------------------------
1044// static function: FillGap
1045// purpose:
1046// ----------------------------------------------------------------------------------------------------
1047Standard_Boolean FillGap(const TopoDS_Vertex& theFirstVertex,
4e57c75e 1048 const TopoDS_Vertex& theLastVertex,
1049 const gp_Pnt2d& theFirstPoint,
1050 const gp_Pnt2d& theLastPoint,
1051 const TopoDS_Face& theFace,
1052 const TopoDS_Compound& theSectionEdges,
1053 TopTools_ListOfShape& theOrderedList) {
7fd59977 1054
1055 TopTools_IndexedDataMapOfShapeListOfShape aMap;
1056 TopExp::MapShapesAndAncestors(theSectionEdges, TopAbs_VERTEX, TopAbs_EDGE, aMap);
1057
1058 if(aMap.IsEmpty()) {
1059 return Standard_False;
1060 }
1061
1062 if(!aMap.Contains(theFirstVertex) ||
1063 !aMap.Contains(theLastVertex)) {
1064 return Standard_False;
1065 }
1066 TopTools_ListOfShape aListOfEdge;
1067// Standard_Integer i = 0;
1068// TopoDS_Vertex aCurVertex = theFirstVertex;
1069 TopTools_MapOfShape aMapToAvoid;
1070
1071 if(FindNextEdge(theFirstVertex, theLastVertex, aMap, aMapToAvoid, aListOfEdge)) {
1072 if(!aListOfEdge.IsEmpty()) {
1073 return CheckAndOrientEdges(aListOfEdge, theFirstPoint, theLastPoint, theFace, theOrderedList);
1074 }
1075 }
1076 return Standard_False;
1077}
1078
1079// ----------------------------------------------------------------------------------------------------
1080// static function: FindNextEdge
1081// purpose:
1082// ----------------------------------------------------------------------------------------------------
1083Standard_Boolean FindNextEdge(const TopoDS_Vertex& theFirstVertex,
4e57c75e 1084 const TopoDS_Vertex& theLastVertex,
1085 const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
1086 const TopTools_MapOfShape& theMapToAvoid,
1087 TopTools_ListOfShape& theOrderedList) {
7fd59977 1088 TopoDS_Vertex aCurVertex = theFirstVertex;
1089 TopTools_MapOfShape aMapToAvoid;
1090 aMapToAvoid = theMapToAvoid;
1091 TopTools_ListOfShape aListOfEdge;
1092 Standard_Integer i = 0;
1093
1094 for(i = 1; i <= theMapVE.Extent(); i++) {
1095 if(!theMapVE.Contains(aCurVertex))
1096 break;
1097 const TopTools_ListOfShape& lste = theMapVE.FindFromKey(aCurVertex);
1098 Standard_Boolean befound = Standard_False;
1099
1100 TopTools_ListIteratorOfListOfShape anIt(lste);
1101
1102 for(; anIt.More(); anIt.Next()) {
1103 TopoDS_Shape anEdge = anIt.Value();
1104 TopoDS_Vertex aSaveCurVertex = aCurVertex;
1105
1106 if(!aMapToAvoid.Contains(anEdge)) {
4e57c75e 1107 TopoDS_Vertex V1, V2;
1108 TopExp::Vertices(TopoDS::Edge(anEdge), V1, V2);
1109
1110 if(!aCurVertex.IsSame(V1)) {
1111 aCurVertex = V1;
1112 }
1113 else if(!aCurVertex.IsSame(V2)) {
1114 aCurVertex = V2;
1115 }
1116 aMapToAvoid.Add(anEdge);
1117 befound = Standard_True;
1118 aListOfEdge.Append(anEdge);
1119
1120 if(!aCurVertex.IsSame(theLastVertex)) {
1121 TopTools_ListOfShape aListtmp;
1122
1123 if(!FindNextEdge(aCurVertex, theLastVertex, theMapVE, aMapToAvoid, aListtmp)) {
1124 aListOfEdge.Clear();
1125 aCurVertex = aSaveCurVertex;
1126 continue;
1127 }
1128 else {
1129 aListOfEdge.Append(aListtmp);
1130 theOrderedList.Append(aListOfEdge);
1131 return Standard_True;
1132 }
1133 }
1134 break;
7fd59977 1135 }
1136 }
1137
1138 if(aCurVertex.IsSame(theLastVertex))
1139 break;
1140
1141 if(!befound) {
1142 return Standard_False;
1143 }
1144 }
1145
1146 if(aCurVertex.IsSame(theLastVertex)) {
1147 theOrderedList.Append(aListOfEdge);
1148 return Standard_True;
1149 }
1150 return Standard_False;
1151}
1152
1153// ----------------------------------------------------------------------------------------------------
1154// static function: CheckAndOrientEdges
1155// purpose:
1156// ----------------------------------------------------------------------------------------------------
1157Standard_Boolean CheckAndOrientEdges(const TopTools_ListOfShape& theOrderedList,
4e57c75e 1158 const gp_Pnt2d& theFirstPoint,
1159 const gp_Pnt2d& theLastPoint,
1160 const TopoDS_Face& theFace,
1161 TopTools_ListOfShape& theOrientedList) {
7fd59977 1162 TopTools_ListIteratorOfListOfShape anIt(theOrderedList);
1163
1164 if(!anIt.More())
1165 return Standard_True;
1166
1167 Standard_Real f, l;
1168 TopoDS_Edge aEPrev = TopoDS::Edge(anIt.Value());
1169 anIt.Next();
1170
1171 Handle(Geom2d_Curve) aCurve = BRep_Tool::CurveOnSurface(aEPrev, theFace, f, l);
1172 TopoDS_Vertex Vf, Vl;
1173 TopExp::Vertices(aEPrev, Vf, Vl);
1174 BRepAdaptor_Surface aBAS(theFace, Standard_False);
1175
1176 Standard_Real aTolerance1 = (Vf.IsNull()) ? Precision::Confusion() : BRep_Tool::Tolerance(Vf);
1177 Standard_Real aTolerance2 = (Vl.IsNull()) ? Precision::Confusion() : BRep_Tool::Tolerance(Vl);
1178 Standard_Real utol = aBAS.UResolution(aTolerance1);
1179 Standard_Real vtol = aBAS.VResolution(aTolerance1);
1180 aTolerance1 = (utol > vtol) ? utol : vtol;
1181 utol = aBAS.UResolution(aTolerance2);
1182 vtol = aBAS.VResolution(aTolerance2);
1183 aTolerance2 = (utol > vtol) ? utol : vtol;
1184
1185 gp_Pnt2d ap = aCurve->Value(f);
1186 Standard_Boolean bFirstFound = Standard_False;
1187 Standard_Boolean bLastFound = Standard_False;
1188 Standard_Boolean bforward = Standard_True;
1189
1190 if(ap.Distance(theFirstPoint) < aTolerance1) {
1191 bforward = Standard_True;
1192 if(theOrientedList.IsEmpty())
1193 theOrientedList.Append(aEPrev.Oriented(TopAbs_FORWARD));
1194 bFirstFound = Standard_True;
1195 }
1196 else if(ap.Distance(theLastPoint) < aTolerance1) {
1197 bforward = Standard_False;
1198 if(theOrientedList.IsEmpty())
1199 theOrientedList.Append(aEPrev.Oriented(TopAbs_REVERSED));
1200 bLastFound = Standard_True;
1201 }
1202 ap = aCurve->Value(l);
1203
1204 if(ap.Distance(theLastPoint) < aTolerance2) {
1205 bforward = Standard_True;
1206
1207 if(theOrientedList.IsEmpty())
1208 theOrientedList.Append(aEPrev.Oriented(TopAbs_FORWARD));
1209 bLastFound = Standard_True;
1210 }
1211 else if(ap.Distance(theFirstPoint) < aTolerance2) {
1212 bforward = Standard_False;
1213
1214 if(theOrientedList.IsEmpty())
1215 theOrientedList.Append(aEPrev.Oriented(TopAbs_REVERSED));
1216 bFirstFound = Standard_True;
1217 }
1218
1219 for(; anIt.More(); anIt.Next()) {
1220 const TopoDS_Edge& aE = TopoDS::Edge(anIt.Value());
1221 TopoDS_Vertex aV11, aV12;
1222 TopExp::Vertices(aEPrev, aV11, aV12);
1223 TopoDS_Vertex aV21, aV22;
1224 TopExp::Vertices(aE, aV21, aV22);
1225 TopAbs_Orientation anOri = TopAbs_FORWARD;
1226
1227 if(aV12.IsSame(aV21) || aV11.IsSame(aV22)) {
1228 anOri = (bforward) ? TopAbs_FORWARD : TopAbs_REVERSED;
1229 }
1230 else {
1231 anOri = (bforward) ? TopAbs_REVERSED : TopAbs_FORWARD;
1232 }
1233 theOrientedList.Append(aE.Oriented(anOri));
1234 aEPrev = aE;
1235 aTolerance1 = (aV21.IsNull()) ? Precision::Confusion() : BRep_Tool::Tolerance(aV21);
1236 aTolerance2 = (aV22.IsNull()) ? Precision::Confusion() : BRep_Tool::Tolerance(aV22);
1237 utol = aBAS.UResolution(aTolerance1);
1238 vtol = aBAS.VResolution(aTolerance1);
1239 aTolerance1 = (utol > vtol) ? utol : vtol;
1240 utol = aBAS.UResolution(aTolerance2);
1241 vtol = aBAS.VResolution(aTolerance2);
1242 aTolerance2 = (utol > vtol) ? utol : vtol;
1243 aCurve = BRep_Tool::CurveOnSurface(aE, theFace, f, l);
1244 ap = aCurve->Value(f);
1245
1246 if(ap.Distance(theFirstPoint) < aTolerance1) {
1247 bFirstFound = Standard_True;
1248 }
1249 else if(ap.Distance(theLastPoint) < aTolerance1) {
1250 bLastFound = Standard_True;
1251 }
1252 ap = aCurve->Value(l);
1253
1254 if(ap.Distance(theFirstPoint) < aTolerance2) {
1255 bFirstFound = Standard_True;
1256 }
1257 else if(ap.Distance(theLastPoint) < aTolerance2) {
1258 bLastFound = Standard_True;
1259 }
1260 }
1261
1262 if(!bFirstFound || !bLastFound)
1263 return Standard_False;
1264 return Standard_True;
1265}
1266
1267// ----------------------------------------------------------------------------------------------------
1268// static function: FindVertex
1269// purpose:
1270// ----------------------------------------------------------------------------------------------------
1271Standard_Boolean FindVertex(const TopoDS_Edge& theEdge,
4e57c75e 1272 const Standard_Integer theRank,
1273 const BOPDS_PDS& theDS,
1274 const TopTools_DataMapOfShapeListOfShape& theHistMap,
1275 TopoDS_Vertex& theVertex,
1276 BOPDS_Pave& thePave) {
7fd59977 1277
1278 if(!theHistMap.IsBound(theEdge))
1279 return Standard_False;
1280
1281 const TopTools_ListOfShape& lst = theHistMap.Find(theEdge);
1282
1283 if(lst.IsEmpty())
1284 return Standard_False;
7fd59977 1285
1286 TopoDS_Edge aNewEdge = TopoDS::Edge(lst.First());
1287 Standard_Real f, l;
1288 BRep_Tool::Range(aNewEdge, f, l);
1289
4e57c75e 1290 if(theRank == 0) {
1291 thePave.SetParameter(l);
7fd59977 1292 theVertex = TopExp::LastVertex(aNewEdge);
1293 }
1294 else {
4e57c75e 1295 thePave.SetParameter(f);
7fd59977 1296 theVertex = TopExp::FirstVertex(aNewEdge);
1297 }
4e57c75e 1298 Standard_Integer anIndex = theDS->Index(theVertex);
1299 if (anIndex == -1) {
1300 Standard_Integer i, i1, i2;
1301 i1=theDS->NbSourceShapes();
1302 i2=theDS->NbShapes();
1303 for (i=i1; i<i2; ++i) {
1304 const TopoDS_Shape& aSx=theDS->Shape(i);
1305 if(aSx.IsSame(theVertex)) {
1306 anIndex = i;
1307 break;
7fd59977 1308 }
1309 }
1310 }
4e57c75e 1311
7fd59977 1312 thePave.SetIndex(anIndex);
1313
1314 return Standard_True;
1315}
1316
1317// ----------------------------------------------------------------------------------------------------
1318// static function: FindNextVertex
1319// purpose:
1320// ----------------------------------------------------------------------------------------------------
1321Standard_Boolean FindNextVertex(const Standard_Integer theEdgeIndex,
4e57c75e 1322 const BOPDS_Pave& thePrevPave,
1323 const BOPDS_PDS& theDS,
1324 TopoDS_Vertex& theNextVertex,
1325 BOPDS_Pave& thePave) {
1326
1327 Standard_Boolean bTakePave, bFound;
1328 BOPDS_Pave aTmpPave;
1329 BOPDS_ListIteratorOfListOfPave aItP;
1330 //
1331 BOPDS_Pave anullpave;
1332 bFound = Standard_False;
1333 bTakePave = thePrevPave.IsEqual(anullpave);
1334
1335 BOPDS_ListOfPave aLP;
1336 theDS->Paves(theEdgeIndex, aLP);
1337 aItP.Initialize(aLP);
1338 for (; aItP.More(); aItP.Next()) {
1339 aTmpPave = aItP.Value();
1340 //
1341 if (bTakePave) {
1342 if (theDS->IsNewShape(aTmpPave.Index())) {
1343 theNextVertex = *(TopoDS_Vertex*)&theDS->Shape(aTmpPave.Index());
1344 thePave = aTmpPave;
1345 bFound = Standard_True;
1346 break;
7fd59977 1347 }
1348 }
4e57c75e 1349 //
1350 else if (aTmpPave.IsEqual(thePrevPave)) {
1351 bTakePave = Standard_True;
7fd59977 1352 }
1353 }
4e57c75e 1354
1355 return bFound;
7fd59977 1356}
1357
1358// ----------------------------------------------------------------------------------------------------
1359// static function: GetPave
1360// purpose:
1361// ----------------------------------------------------------------------------------------------------
4e57c75e 1362Standard_Boolean GetPave(const Standard_Integer theEdgeIndex,
1363 const Standard_Boolean isFirst,
1364 const BOPDS_PDS& theDS,
1365 BOPDS_Pave& thePave) {
7fd59977 1366
4e57c75e 1367 Handle(BOPDS_PaveBlock) aPB;
1368 BOPDS_ListOfPave aLP;
1369
1370 theDS->Paves(theEdgeIndex, aLP);
1371 if (!aLP.Extent()) {
1372 return Standard_False;
1373 }
1374 //
1375 if (isFirst) {
1376 thePave = aLP.First();
7fd59977 1377 }
1378 else {
4e57c75e 1379 thePave = aLP.Last();
7fd59977 1380 }
4e57c75e 1381
7fd59977 1382 return Standard_True;
1383}
1384
7fd59977 1385// ----------------------------------------------------------------------------------------------------
1386// static function: FindFromUEdge
1387// purpose:
1388// ----------------------------------------------------------------------------------------------------
1389Standard_Boolean FindFromUEdge(const TopoDS_Edge& theUE1Old,
4e57c75e 1390 const TopoDS_Edge& theUE2Old,
1391 const TopoDS_Edge& theUE1New,
1392 const TopoDS_Edge& theUE2New,
1393 const TopoDS_Face& theFace,
1394 const TopoDS_Compound& theSecEdges,
1395 const Standard_Integer theRank,
1396 const TopoDS_Edge& theBoundEdge,
1397 const Standard_Integer theBoundEdgeIndex,
1398 const BOPDS_PDS& theDS,
1399 const TopTools_DataMapOfShapeListOfShape& theHistMap,
1400 TopoDS_Compound& theSecEdgesNew,
1401 TopTools_ListOfShape& theListOfWireEdges,
1402 BOPDS_Pave& theFoundPave,
1403 Standard_Boolean& isOnUEdge) {
7fd59977 1404 theFoundPave.SetIndex(0);
4e57c75e 1405 theFoundPave.SetParameter(0.);
7fd59977 1406 isOnUEdge = Standard_True;
1407
7fd59977 1408 TopoDS_Face aFaceF = theFace;
1409 aFaceF.Orientation(TopAbs_FORWARD);
1410 TopoDS_Vertex aPrevVertex, aNextVertex;
1411 TopoDS_Compound aCompOfSecEdges = theSecEdges;
1412 TopTools_ListOfShape aListOfWireEdges;
1413// BRep_Builder aBB;
1414
4e57c75e 1415 BOPDS_Pave aPave1, aPave2;
7fd59977 1416 Standard_Real f = 0., l = 0.;
1417 gp_Pnt2d p1, p2;
1418 TopoDS_Vertex aFirstV, aLastV;
4e57c75e 1419 BOPDS_Pave atmpPave;
7fd59977 1420
4e57c75e 1421 if(!FindVertex(theUE1Old, theRank, theDS, theHistMap, aPrevVertex, atmpPave)) {
7fd59977 1422 return Standard_True;
1423 }
1424
1425 if(aPrevVertex.IsNull()) {
1426 return Standard_False;
1427 }
1428
1429 aFirstV = aPrevVertex;
1430 Standard_Boolean bSecFound = Standard_False;
1431 Handle(Geom2d_Curve) aC1 = BRep_Tool::CurveOnSurface(theUE1New, aFaceF, f, l);
4e57c75e 1432 p1 = (theRank == 0) ? aC1->Value(l) : aC1->Value(f);
1433 BOPDS_Pave afoundpave;
1434 BOPDS_ListOfPave aLP;
1435 theDS->Paves(theBoundEdgeIndex, aLP);
1436 Standard_Integer nbpave = aLP.Extent();
7fd59977 1437 Standard_Integer pit = 0;
4e57c75e 1438
1439 while(FindNextVertex(theBoundEdgeIndex, aPave1, theDS, aNextVertex, aPave2) && (pit < nbpave)) {
7fd59977 1440 aLastV = aNextVertex;
1441 Handle(Geom2d_Curve) aC2 = BRep_Tool::CurveOnSurface(theBoundEdge, aFaceF, f, l);
4e57c75e 1442 p2 = aC2->Value(aPave2.Parameter());
7fd59977 1443 TopTools_ListOfShape aOrderedList;
1444
1445 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
1446 // remove found edges...
1447 TopoDS_Compound aComp;
1448 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1449 aCompOfSecEdges = aComp;
1450 aListOfWireEdges.Append(aOrderedList);
1451 afoundpave = aPave2;
1452 isOnUEdge = Standard_False;
1453 bSecFound = Standard_True;
1454 break;
1455 }
1456 aPrevVertex = aNextVertex;
1457 aPave1 = aPave2;
1458 pit++;
1459 }
1460
4e57c75e 1461 if(!bSecFound && FindVertex(theUE2Old, theRank, theDS, theHistMap, aNextVertex, aPave2)) {
7fd59977 1462 aLastV = aNextVertex;
1463 Handle(Geom2d_Curve) aC2 = BRep_Tool::CurveOnSurface(theUE2New, aFaceF, f, l);
4e57c75e 1464 p2 = aC2->Value(aPave2.Parameter());
7fd59977 1465 TopTools_ListOfShape aOrderedList;
1466
1467 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
1468 // remove found edges...
1469 TopoDS_Compound aComp;
1470
1471 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1472 aCompOfSecEdges = aComp;
1473 aListOfWireEdges.Append(aOrderedList);
1474 afoundpave = aPave2;
1475 bSecFound = Standard_True;
1476 isOnUEdge = Standard_True;
1477 }
1478 }
1479
1480 if(bSecFound) {
1481 theFoundPave = afoundpave;
1482 theListOfWireEdges = aListOfWireEdges;
1483 theSecEdgesNew = aCompOfSecEdges;
1484 }
1485 return Standard_True;
1486}
1487
1488
1489// ----------------------------------------------------------------------------------------------------
1490// static function: FindFromVEdge
1491// purpose:
1492// ----------------------------------------------------------------------------------------------------
4e57c75e 1493Standard_Boolean FindFromVEdge(const BOPDS_Pave& thePrevPave,
1494 const Standard_Boolean& isOnUEdge,
1495 const TopoDS_Edge& theUE1Old,
1496 const TopoDS_Edge& theUE2Old,
1497 const TopoDS_Face& theFace,
1498 const TopoDS_Compound& theSecEdges,
1499 const Standard_Integer theRank,
1500 const TopoDS_Edge& theBoundEdge,
1501 const Standard_Integer theBoundEdgeIndex,
1502 const BOPDS_PDS& theDS,
1503 const TopTools_DataMapOfShapeListOfShape& theHistMap,
1504 TopTools_ListOfShape& theListOfWireEdges,
1505 Standard_Boolean& isSectionFound) {
1506
7fd59977 1507 theListOfWireEdges.Clear();
1508 isSectionFound = Standard_False;
4e57c75e 1509 //
7fd59977 1510 TopoDS_Face aFaceF = theFace;
1511 aFaceF.Orientation(TopAbs_FORWARD);
1512 TopoDS_Vertex aPrevVertex, aNextVertex;
1513 TopoDS_Compound aCompOfSecEdges = theSecEdges;
1514 TopTools_ListOfShape aListOfWireEdges;
1515// BRep_Builder aBB;
1516
4e57c75e 1517 BOPDS_Pave aPave1, aPave2;
7fd59977 1518
1519 if(isOnUEdge) {
1520 TopoDS_Vertex atmpVertex;
4e57c75e 1521 BOPDS_Pave aPaveOfE2;
7fd59977 1522
4e57c75e 1523 if(FindVertex(theUE2Old, theRank, theDS, theHistMap, atmpVertex, aPaveOfE2)) {
7fd59977 1524 if(thePrevPave.IsEqual(aPaveOfE2))
4e57c75e 1525 return Standard_True;
7fd59977 1526 }
1527 }
1528
1529 Standard_Real f = 0., l = 0.;
1530 gp_Pnt2d p1(0., 0.), p2(0., 0.);
1531 TopoDS_Vertex aFirstV, aLastV;
1532 Handle(Geom2d_Curve) aC1 = BRep_Tool::CurveOnSurface(theUE1Old, aFaceF, f, l);
1533 Handle(Geom2d_Curve) aC2 = BRep_Tool::CurveOnSurface(theBoundEdge, aFaceF, f, l);
1534 Standard_Boolean bSecFound = Standard_False;
1535
1536 aPave1 = thePrevPave;
1537
1538 if(isOnUEdge) {
4e57c75e 1539 BOPDS_Pave atmpPave;
7fd59977 1540
4e57c75e 1541 if(!GetPave(theBoundEdgeIndex, Standard_True, theDS, atmpPave)) {
7fd59977 1542 return Standard_False;
1543 }
1544 aPave1 = atmpPave;
1545 }
4e57c75e 1546 p1 = aC2->Value(aPave1.Parameter());
1547 aPrevVertex = TopoDS::Vertex(theDS->Shape(aPave1.Index()));
7fd59977 1548
4e57c75e 1549 BOPDS_ListOfPave aLP;
1550 theDS->Paves(theBoundEdgeIndex, aLP);
1551 Standard_Integer nbpave = aLP.Extent();
7fd59977 1552 Standard_Integer pit = 0;
1553 TopTools_Array1OfListOfShape anArrayOfListOfSec(1, nbpave);
1554
1555 // by pairs non continuously. begin
1556 Standard_Integer k = 0;
4e57c75e 1557 BOPDS_Pave aFirstPave = aPave1;
7fd59977 1558 TopoDS_Vertex aFirstVertex = aPrevVertex;
1559 gp_Pnt2d apfirst = p1;
4e57c75e 1560 BOPDS_ListOfPave aFirstPaves, aLastPaves;
7fd59977 1561 TColStd_ListOfInteger aListOfFlags;
1562 Standard_Integer apaircounter = 1;
1563
1564 for(k = 0; k < nbpave; k++) {
1565 aPave1 = aFirstPave;
1566 p1 = apfirst;
1567 aPrevVertex = aFirstVertex;
1568 Standard_Boolean bfound = Standard_False;
1569 pit = 0;
1570
4e57c75e 1571 while(FindNextVertex(theBoundEdgeIndex, aPave1, theDS, aNextVertex, aPave2) && (pit < nbpave)) {
7fd59977 1572 aFirstV = aPrevVertex;
1573 aLastV = aNextVertex;
4e57c75e 1574 p2 = aC2->Value(aPave2.Parameter());
7fd59977 1575
1576 TopTools_ListOfShape aOrderedList;
1577
1578 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
4e57c75e 1579 TopoDS_Compound aComp;
1580 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1581 aCompOfSecEdges = aComp;
1582
1583 anArrayOfListOfSec(apaircounter++).Append(aOrderedList);
1584 aFirstPaves.Append(aFirstPave);
1585 aLastPaves.Append(aPave2);
1586 aListOfFlags.Append(1);
1587 aFirstPave = aPave2;
1588 aFirstVertex = aNextVertex;
1589 apfirst = p2;
1590 aPrevVertex = aNextVertex;
1591 bSecFound = Standard_True;
1592 bfound = Standard_True;
7fd59977 1593 }
1594 aPave1 = aPave2;
1595 pit++;
1596 }
1597
4e57c75e 1598 if(FindVertex(theUE2Old, theRank, theDS, theHistMap, aNextVertex, aPave2)) {
7fd59977 1599 aFirstV = aPrevVertex;
1600 aLastV = aNextVertex;
1601 Handle(Geom2d_Curve) aC3 = BRep_Tool::CurveOnSurface(theUE2Old, aFaceF, f, l);
4e57c75e 1602 p2 = aC3->Value(aPave2.Parameter());
7fd59977 1603
1604 TopTools_ListOfShape aOrderedList;
1605
1606 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
4e57c75e 1607 TopoDS_Compound aComp;
1608 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1609 aCompOfSecEdges = aComp;
1610 anArrayOfListOfSec(apaircounter++).Append(aOrderedList);
1611 aFirstPaves.Append(aFirstPave);
1612 aLastPaves.Append(aPave2);
1613 aListOfFlags.Append(0);
1614 bSecFound = Standard_True;
1615 break;
7fd59977 1616 }
1617 }
1618
1619 if(!bfound) {
4e57c75e 1620 if(!FindNextVertex(theBoundEdgeIndex, aFirstPave, theDS, aNextVertex, aPave2)) {
1621 break;
7fd59977 1622 }
1623 aFirstPave = aPave2;
4e57c75e 1624 apfirst = aC2->Value(aPave2.Parameter());
7fd59977 1625 aFirstVertex = aNextVertex;
1626 }
1627 }
1628 // by pairs non continuously. end
1629
1630 // by pairs continuously. begin
1631 aPave1 = thePrevPave;
1632
1633 if(isOnUEdge) {
4e57c75e 1634 BOPDS_Pave atmpPave;
7fd59977 1635
4e57c75e 1636 if(!GetPave(theBoundEdgeIndex, Standard_True, theDS, atmpPave)) {
7fd59977 1637 return Standard_False;
1638 }
1639 aPave1 = atmpPave;
1640 }
4e57c75e 1641 p1 = aC2->Value(aPave1.Parameter());
1642 aPrevVertex = TopoDS::Vertex(theDS->Shape(aPave1.Index()));
7fd59977 1643
1644 pit = 0;
1645
4e57c75e 1646 while(FindNextVertex(theBoundEdgeIndex, aPave1, theDS, aNextVertex, aPave2) && (pit < nbpave)) {
7fd59977 1647 aFirstV = aPrevVertex;
1648 aLastV = aNextVertex;
4e57c75e 1649 p2 = aC2->Value(aPave2.Parameter());
7fd59977 1650
1651 Standard_Boolean bisinside = Standard_False;
1652 Standard_Integer apbindex = 0;
1653 Standard_Integer apbcounter = 1;
4e57c75e 1654 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1655 BOPDS_ListIteratorOfListOfPave aPIt1, aPIt2;
7fd59977 1656 TColStd_ListIteratorOfListOfInteger aFlagIt;
1657
1658 for(aPIt1.Initialize(aFirstPaves), aPIt2.Initialize(aLastPaves), aFlagIt.Initialize(aListOfFlags);
4e57c75e 1659 aPIt1.More() && aPIt2.More() && aFlagIt.More();
1660 aPIt1.Next(), aPIt2.Next(), aFlagIt.Next(), apbcounter++) {
7fd59977 1661
1662 Standard_Boolean bfin = Standard_False;
1663 Standard_Boolean blin = Standard_False;
1664
1665 if(aPave1.IsEqual(aPIt1.Value())) {
4e57c75e 1666 bfin = Standard_True;
7fd59977 1667 }
1668 else {
4e57c75e 1669 bfin = (aPave1.Parameter() > aPIt1.Value().Parameter());
7fd59977 1670 }
1671
1672 if(aFlagIt.Value()) {
4e57c75e 1673 if(aPave2.IsEqual(aPIt2.Value())) {
1674 blin = Standard_True;
1675 }
1676 else {
1677 blin = (aPave2.Parameter() < aPIt2.Value().Parameter());
1678 }
7fd59977 1679 }
1680 else {
4e57c75e 1681 if((aPave2.Index() == aPIt2.Value().Index()) && (aPave2.Index() > 0)) {
1682 Handle(Geom2d_Curve) pc = BRep_Tool::CurveOnSurface(theUE2Old, aFaceF, f, l);
1683 gp_Pnt2d p3 = pc->Value(aPIt2.Value().Parameter());
1684 TopoDS_Vertex aV = TopoDS::Vertex(theDS->Shape(aPave2.Index()));
1685 BRepAdaptor_Surface aBAS(aFaceF, Standard_False);
1686 Standard_Real aTolerance = BRep_Tool::Tolerance(aV);
1687 Standard_Real utol = aBAS.UResolution(aTolerance);
1688 Standard_Real vtol = aBAS.VResolution(aTolerance);
1689 aTolerance = (utol > vtol) ? utol : vtol;
1690
1691 if(p2.Distance(p3) < aTolerance)
1692 blin = Standard_True;
1693 }
7fd59977 1694 }
1695
1696 if(bfin && blin) {
4e57c75e 1697 apbindex = apbcounter;
1698 bisinside = Standard_True;
1699 break;
7fd59977 1700 }
1701 }
1702
1703 if(!bisinside) {
1704
1705 TopTools_ListOfShape aOrderedList;
1706
1707 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
4e57c75e 1708 TopoDS_Compound aComp;
1709 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1710 aCompOfSecEdges = aComp;
1711 aListOfWireEdges.Append(aOrderedList);
7fd59977 1712
4e57c75e 1713 bSecFound = Standard_True;
7fd59977 1714 }
1715 else {
4e57c75e 1716 TopoDS_Edge aESplit;
1717 // get split
1718 aPBIt.Initialize(theDS->PaveBlocks(theBoundEdgeIndex));
1719
1720 for(; aPBIt.More(); aPBIt.Next()) {
1721 const Handle(BOPDS_PaveBlock)& aPB1 = aPBIt.Value();
1722 if (aPB1->OriginalEdge() == theBoundEdgeIndex &&
1723 aPB1->Pave1().IsEqual(aPave1) &&
1724 aPB1->Pave2().IsEqual(aPave2) ) {
1725 if(aPB1->Edge() > 0) {
1726 aESplit = *(TopoDS_Edge*)&theDS->Shape(aPB1->Edge());
1727 break;
1728 }
1729 }
1730 }
1731
1732 if(!aESplit.IsNull()) {
1733 aListOfWireEdges.Append(aESplit);
1734 }
7fd59977 1735 }
1736 }
1737 else {
1738 if(apbindex > 0) {
4e57c75e 1739 TopTools_ListOfShape& aListOfSec = anArrayOfListOfSec(apbindex);
1740 aListOfWireEdges.Append(aListOfSec);
7fd59977 1741 }
1742 }
1743 aPave1 = aPave2;
1744 aPrevVertex = aNextVertex;
1745 p1 = p2;
1746 pit++;
1747 }
1748
4e57c75e 1749 if(FindVertex(theUE2Old, theRank, theDS, theHistMap, aNextVertex, aPave2)) {
7fd59977 1750 aFirstV = aPrevVertex;
1751 aLastV = aNextVertex;
1752 Handle(Geom2d_Curve) aC3 = BRep_Tool::CurveOnSurface(theUE2Old, aFaceF, f, l);
4e57c75e 1753 p2 = aC3->Value(aPave2.Parameter());
7fd59977 1754
1755 Standard_Boolean bisinside = Standard_False;
1756 Standard_Integer apbindex = 0;
1757 Standard_Integer apbcounter = 1;
4e57c75e 1758 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1759 BOPDS_ListIteratorOfListOfPave aPIt1, aPIt2;
7fd59977 1760 TColStd_ListIteratorOfListOfInteger aFlagIt;
1761
1762 for(aPIt1.Initialize(aFirstPaves), aPIt2.Initialize(aLastPaves), aFlagIt.Initialize(aListOfFlags);
4e57c75e 1763 aPIt1.More() && aPIt2.More() && aFlagIt.More();
1764 aPIt1.Next(), aPIt2.Next(), aFlagIt.Next(), apbcounter++) {
7fd59977 1765
1766 Standard_Boolean bfin = Standard_False;
1767 Standard_Boolean blin = Standard_False;
1768
1769 if(aPave1.IsEqual(aPIt1.Value())) {
4e57c75e 1770 bfin = Standard_True;
7fd59977 1771 }
1772 else {
4e57c75e 1773 bfin = (aPave1.Parameter() > aPIt1.Value().Parameter());
7fd59977 1774 }
1775
1776 if(aFlagIt.Value()) {
4e57c75e 1777 if(aPave2.IsEqual(aPIt2.Value())) {
1778 blin = Standard_True;
1779 }
1780 else {
1781 blin = (aPave2.Parameter() < aPIt2.Value().Parameter());
1782 }
7fd59977 1783 }
1784 else {
4e57c75e 1785 blin = Standard_True;
7fd59977 1786 }
1787
1788 if(bfin && blin) {
4e57c75e 1789 apbindex = apbcounter;
1790 bisinside = Standard_True;
1791 break;
7fd59977 1792 }
1793 }
1794
1795 if(!bisinside) {
1796
1797 TopTools_ListOfShape aOrderedList;
1798
1799 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
4e57c75e 1800 TopoDS_Compound aComp;
1801 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1802 aCompOfSecEdges = aComp;
1803 aListOfWireEdges.Append(aOrderedList);
7fd59977 1804
4e57c75e 1805 bSecFound = Standard_True;
7fd59977 1806 }
1807 else {
4e57c75e 1808 //add split
1809 TopoDS_Edge aESplit;
1810 // get split
1811 if(!GetPave(theBoundEdgeIndex, Standard_False, theDS, aPave2))
1812 return Standard_False;
1813 //
1814 aPBIt.Initialize(theDS->PaveBlocks(theBoundEdgeIndex));
1815 for(; aPBIt.More(); aPBIt.Next()) {
1816 const Handle(BOPDS_PaveBlock)& aPB1 = aPBIt.Value();
1817 if (aPB1->OriginalEdge() == theBoundEdgeIndex &&
1818 aPB1->Pave1().IsEqual(aPave1) &&
1819 aPB1->Pave2().IsEqual(aPave2) ) {
1820 if(aPB1->Edge() > 0) {
1821 aESplit = *(TopoDS_Edge*)&theDS->Shape(aPB1->Edge());
1822 break;
1823 }
1824 }
1825 }
1826
1827 if(!aESplit.IsNull()) {
1828 aListOfWireEdges.Append(aESplit);
1829 }
7fd59977 1830 }
1831 }
1832 else {
1833 if(apbindex > 0) {
4e57c75e 1834 TopTools_ListOfShape& aListOfSec = anArrayOfListOfSec(apbindex);
1835 aListOfWireEdges.Append(aListOfSec);
7fd59977 1836 }
1837 }
1838 }
1839 else {
1840 //add split
1841 TopoDS_Edge aESplit;
1842 // get split
4e57c75e 1843 if(!GetPave(theBoundEdgeIndex, Standard_False, theDS, aPave2))
7fd59977 1844 return Standard_False;
7fd59977 1845
4e57c75e 1846 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1847 aPBIt.Initialize(theDS->PaveBlocks(theBoundEdgeIndex));
7fd59977 1848 for(; aPBIt.More(); aPBIt.Next()) {
4e57c75e 1849 const Handle(BOPDS_PaveBlock)& aPB1 = aPBIt.Value();
1850 if (aPB1->OriginalEdge() == theBoundEdgeIndex &&
1851 aPB1->Pave1().IsEqual(aPave1) &&
1852 aPB1->Pave2().IsEqual(aPave2) ) {
1853 if(aPB1->Edge() > 0) {
1854 aESplit = *(TopoDS_Edge*)&theDS->Shape(aPB1->Edge());
1855 break;
1856 }
7fd59977 1857 }
1858 }
1859
1860 if(!aESplit.IsNull()) {
1861 aListOfWireEdges.Append(aESplit);
1862 }
1863 }
1864
1865 // by pairs continuously. end
1866 theListOfWireEdges = aListOfWireEdges;
1867 isSectionFound = bSecFound;
1868 return Standard_True;
1869}
1870
1871// ----------------------------------------------------------------------------------------------------
1872// static function: RemoveEdges
1873// purpose:
1874// ----------------------------------------------------------------------------------------------------
1875void RemoveEdges(const TopoDS_Compound& theSourceComp,
4e57c75e 1876 const TopTools_ListOfShape& theListToRemove,
1877 TopoDS_Compound& theResultComp) {
7fd59977 1878 BRep_Builder aBB;
1879 TopoDS_Compound aComp;
1880 aBB.MakeCompound(aComp);
1881 TopExp_Explorer anExp(theSourceComp, TopAbs_EDGE);
1882
1883 for(; anExp.More(); anExp.Next()) {
1884 Standard_Boolean bfound = Standard_False;
1885 TopTools_ListIteratorOfListOfShape anIt(theListToRemove);
1886
1887 for(; !bfound && anIt.More(); anIt.Next()) {
1888 bfound = anExp.Current().IsSame(anIt.Value());
1889 }
1890
1891 if(!bfound) {
1892 aBB.Add(aComp, anExp.Current());
1893 }
1894 }
1895 theResultComp = aComp;
1896}
1897
1898// ----------------------------------------------------------------------------------------------------
1899// static function: FilterSectionEdges
1900// purpose:
1901// ----------------------------------------------------------------------------------------------------
4e57c75e 1902Standard_Boolean FilterSectionEdges(const BOPDS_VectorOfCurve& theBCurves,
1903 const TopoDS_Face& theSecPlane,
1904 const BOPDS_PDS& theDS,
1905 TopoDS_Compound& theResult) {
7fd59977 1906
1907 theResult.Nullify();
7fd59977 1908
1909 BRep_Builder aBB;
1910 aBB.MakeCompound(theResult);
4e57c75e 1911 Standard_Integer aNbCurves = theBCurves.Extent();
7fd59977 1912 Standard_Integer cit = 0;
4e57c75e 1913 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1914
1915 for(cit = 0; cit < aNbCurves; ++cit) {
1916 const BOPDS_Curve& aBCurve = theBCurves(cit);
1917 const BOPDS_ListOfPaveBlock& aSectEdges = aBCurve.PaveBlocks();
7fd59977 1918
4e57c75e 1919 aPBIt.Initialize(aSectEdges);
7fd59977 1920 for (; aPBIt.More(); aPBIt.Next()) {
4e57c75e 1921 const Handle(BOPDS_PaveBlock)& aPB = aPBIt.Value();
1922 Standard_Integer nSect = aPB->Edge();
1923 const TopoDS_Shape& aS = theDS->Shape(nSect);
7fd59977 1924 TopoDS_Edge anEdge = TopoDS::Edge(aS);
1925 Standard_Boolean bAddEdge = Standard_True;
1926
1927 if(!theSecPlane.IsNull()) {
4e57c75e 1928 IntTools_BeanFaceIntersector anIntersector(anEdge, theSecPlane);
1929 Standard_Real f = 0., l = 0.;
1930 BRep_Tool::Range(anEdge, f, l);
1931 anIntersector.SetBeanParameters(f, l);
1932 //
1e143abb 1933 Handle(IntTools_Context) aContext = new IntTools_Context;
4e57c75e 1934 anIntersector.SetContext(aContext);
1935 //
1936 anIntersector.Perform();
1937
1938 if(anIntersector.IsDone()) {
1939 bAddEdge = Standard_False;
1940 Standard_Integer r = 0;
1941
1942 for(r = 1; r <= anIntersector.Result().Length(); r++) {
1943 const IntTools_Range& aRange = anIntersector.Result().Value(r);
1944
1945 if(((aRange.First() - f) < Precision::PConfusion()) &&
1946 ((l - aRange.Last()) < Precision::PConfusion())) {
1947 bAddEdge = Standard_True;
1948 break;
1949 }//if(((aRange.First() - f) < Precision::PConfusion()) &&
1950 }//for(r = 1; r <= anIntersector.Result().Length(); r++) {
1951 }//if(anIntersector.IsDone()) {
1952 }//if(!theSecPlane.IsNull()) {
7fd59977 1953
1954 if(bAddEdge) {
4e57c75e 1955 aBB.Add(theResult, aS);
7fd59977 1956 }
4e57c75e 1957 }//for (; aPBIt.More(); aPBIt.Next()) {
1958 }//for(cit = 0; cit < aNbCurves; ++cit) {
1959
7fd59977 1960 return Standard_True;
1961}
1962
1963
1964//=======================================================================
1965//function : ComputeAveragePlaneAndMaxDeviation
1966//purpose :
1967//=======================================================================
1968static Standard_Real ComputeAveragePlaneAndMaxDeviation(const TopoDS_Shape& aWire,
4e57c75e 1969 gp_Pln& thePlane,
1970 Standard_Boolean& IsSingular)
7fd59977 1971{
1972 Standard_Integer N = 40, nedges = 0;
1973
1974 TopoDS_Iterator iter( aWire );
1975 for (; iter.More(); iter.Next())
1976 nedges++;
1977
1978 TColgp_Array1OfPnt Pnts( 1, nedges*N );
1979 Standard_Integer ind = 1, i;
1980 for (iter.Initialize(aWire); iter.More(); iter.Next())
1981 {
1982 const TopoDS_Edge& anEdge = TopoDS::Edge( iter.Value() );
1983 BRepAdaptor_Curve aCurve(anEdge);
1984 GCPnts_UniformAbscissa Distribution( aCurve, N+1 );
1985 for (i = 1; i <= N; i++)
4e57c75e 1986 {
1987 Standard_Real par = Distribution.Parameter(i);
1988 Pnts( ind++ ) = aCurve.Value(par);
1989 }
7fd59977 1990 }
1991
1992 gp_Ax2 Axe;
1993 GeomLib::AxeOfInertia( Pnts, Axe, IsSingular );
1994 if (IsSingular)
1995 return -1;
1996
1997 thePlane = gp_Pln( Axe );
1998 Standard_Real MaxDeviation = 0;
1999 for (i = 1; i <= Pnts.Length(); i++)
2000 {
2001 Standard_Real dist = thePlane.Distance( Pnts(i) );
2002 if (dist > MaxDeviation)
4e57c75e 2003 MaxDeviation = dist;
7fd59977 2004 }
2005 return MaxDeviation;
2006}
2007
2008//=======================================================================
2009//function : ChooseSection
2010//purpose :
2011//=======================================================================
2012static Standard_Boolean ChooseSection(const TopoDS_Shape& Comp,
4e57c75e 2013 const gp_Ax2& bis,
2014 TopoDS_Shape& resWire,
2015 gp_Pln& resPlane,
2016 Standard_Boolean& IsSingular)
7fd59977 2017{
2018 IsSingular = Standard_False;
2019 Standard_Real TolDeviation = 0.01; //, TolConf = 1.e-4, TolAng = 1.e-5;
2020
2021// Standard_Integer N = 100;
2022 Standard_Integer ind, i, j;
2023
2024 //Simplest case
2025 TopoDS_Compound OldComp;
2026 BRep_Builder B;
2027 B.MakeCompound( OldComp );
2028 TopoDS_Iterator iter( Comp );
2029 for (; iter.More(); iter.Next())
2030 B.Add( OldComp, iter.Value() );
2031
2032 Standard_Boolean anError = Standard_False;
2033 //TopoDS_Wire NewWire [2];
2034 TopTools_SequenceOfShape Wseq;
2035 for (;;)
2036 {
2037 TopExp_Explorer explo( OldComp, TopAbs_EDGE );
2038 if (!explo.More())
4e57c75e 2039 break;
7fd59977 2040 TopoDS_Edge FirstEdge = TopoDS::Edge( explo.Current() );
2041 TopoDS_Wire NewWire = BRepLib_MakeWire( FirstEdge );
2042 B.Remove( OldComp, FirstEdge );
2043 if (NewWire.Closed())
4e57c75e 2044 {
2045 Wseq.Append(NewWire);
2046 continue;
2047 }
7fd59977 2048
2049 for (;;)
4e57c75e 2050 {
2051 TopoDS_Vertex Extremity [2];
2052 TopExp::Vertices( NewWire, Extremity[0], Extremity[1] );
2053 if (Extremity[0].IsNull() || Extremity[1].IsNull())
2054 {
2055 anError = Standard_True;
2056 break;
2057 }
2058 TopTools_IndexedDataMapOfShapeListOfShape VEmap;
2059 TopExp::MapShapesAndAncestors( OldComp, TopAbs_VERTEX, TopAbs_EDGE, VEmap );
2060 TopTools_ListOfShape Vedges [2];
2061 for (j = 0; j < 2; j++)
2062 if (VEmap.Contains( Extremity[j] ))
2063 Vedges[j] = VEmap.FindFromKey( Extremity[j] );
2064 if (Vedges[0].IsEmpty() && Vedges[1].IsEmpty())
2065 //no more edges in OldComp to continue NewWire
2066 break;
2067 Standard_Boolean Modified = Standard_False;
2068 for (j = 0; j < 2; j++)
2069 {
2070 if (Vedges[j].Extent() == 1)
2071 {
2072 const TopoDS_Edge& anEdge = TopoDS::Edge( Vedges[j].First() );
2073 NewWire = BRepLib_MakeWire( NewWire, anEdge );
2074 B.Remove( OldComp, anEdge );
2075 Modified = Standard_True;
2076 }
2077 }
2078 if (!Modified) //only multiple connections
2079 {
2080 ind = (Vedges[0].IsEmpty())? 1 : 0;
2081 TopTools_SequenceOfShape Edges;
2082 TopTools_ListIteratorOfListOfShape itl( Vedges[ind] );
2083 for (; itl.More(); itl.Next())
2084 Edges.Append( itl.Value() );
2085 Standard_Integer theind=0;
2086 Standard_Real MinDeviation = RealLast();
2087 for (j = 1; j <= Edges.Length(); j++)
2088 {
2089 TopoDS_Wire aWire = BRepLib_MakeWire( NewWire, TopoDS::Edge(Edges(j)) );
2090 gp_Pln aPlane;
2091 Standard_Boolean issing;
2092 Standard_Real Deviation = ComputeAveragePlaneAndMaxDeviation( aWire, aPlane, issing );
2093 if (Deviation < MinDeviation)
2094 {
2095 MinDeviation = Deviation;
2096 theind = j;
2097 }
2098 }
2099 NewWire = BRepLib_MakeWire( NewWire, TopoDS::Edge(Edges(theind)) );
2100 B.Remove( OldComp, Edges(theind) );
2101 }
2102 if (NewWire.Closed())
2103 break;
2104 }
7fd59977 2105 Wseq.Append(NewWire);
2106 if (anError)
4e57c75e 2107 break;
7fd59977 2108 }
2109
2110 Standard_Real Deviation=0.;
2111 Standard_Real MinAngle = RealLast();
2112 TopExp_Explorer Explo( OldComp, TopAbs_EDGE );
2113 if (!anError && !Explo.More())
2114 {
2115 if (Wseq.Length() == 1)
4e57c75e 2116 {
2117 resWire = Wseq.First();
2118 Deviation = ComputeAveragePlaneAndMaxDeviation( resWire, resPlane, IsSingular );
2119 return Standard_True;
2120 }
7fd59977 2121 else
4e57c75e 2122 {
2123 for (i = 1; i <= Wseq.Length(); i++)
2124 {
2125 TopoDS_Wire aWire = TopoDS::Wire( Wseq(i) );
2126 gp_Pln aPln;
2127 Standard_Boolean issing;
2128 Standard_Real aDeviation =
2129 ComputeAveragePlaneAndMaxDeviation( aWire, aPln, issing );
2130 if (issing)
2131 continue;
2132
2133 Standard_Real Angle = aPln.Axis().Angle( bis.Axis() );
2134 if (Angle > M_PI/2)
2135 Angle = M_PI - Angle;
2136
2137 if (Angle < MinAngle)
2138 {
2139 MinAngle = Angle;
2140 resWire = aWire;
2141 resPlane = aPln;
2142 Deviation = aDeviation;
2143 }
2144 }
2145 if (Deviation <= TolDeviation)
2146 return Standard_True;
2147 }
7fd59977 2148 }
2149 return Standard_False;
2150 //end of simplest case
2151}