1 // Created on: 2003-10-21
2 // Created by: Mikhail KLOKOV
3 // Copyright (c) 2003-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
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>
22 #include <BRep_Builder.hxx>
23 #include <BRep_Tool.hxx>
24 #include <BRepAlgoAPI_Section.hxx>
25 #include <BRepFill_TrimShellCorner.hxx>
26 #include <BRepLib_MakeEdge.hxx>
27 #include <BRepLib_MakeWire.hxx>
28 #include <BRepTools_ReShape.hxx>
29 #include <gce_MakeLin.hxx>
30 #include <GCPnts_UniformAbscissa.hxx>
31 #include <Geom2d_Curve.hxx>
32 #include <Geom_Curve.hxx>
33 #include <GeomLib.hxx>
36 #include <gp_Pnt2d.hxx>
37 #include <IntTools_BeanFaceIntersector.hxx>
38 #include <IntTools_Context.hxx>
39 #include <IntTools_Range.hxx>
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>
49 #include <TopExp_Explorer.hxx>
50 #include <TopLoc_Location.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>
58 #include <TopTools_Array1OfListOfShape.hxx>
59 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
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>
65 #include <TopTools_SequenceOfShape.hxx>
67 static 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);
74 static Standard_Boolean MakeFacesNonSec(const Standard_Integer theIndex,
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);
82 static Standard_Boolean MakeFacesSec(const Standard_Integer theIndex,
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);
92 static Standard_Boolean SplitUEdges(const Handle(TopTools_HArray2OfShape)& theUEdges,
93 const BOPDS_PDS& theDS,
94 TopTools_DataMapOfShapeListOfShape& theHistMap);
96 static void FindFreeVertices(const TopoDS_Shape& theShape,
97 const TopTools_MapOfShape& theVerticesToAvoid,
98 TopTools_ListOfShape& theListOfVertex);
100 static Standard_Boolean CheckAndOrientEdges(const TopTools_ListOfShape& theOrderedList,
101 const gp_Pnt2d& theFirstPoint,
102 const gp_Pnt2d& theLastPoint,
103 const TopoDS_Face& theFace,
104 TopTools_ListOfShape& theOrientedList);
106 static Standard_Boolean FillGap(const TopoDS_Vertex& theFirstVertex,
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);
114 static Standard_Boolean FindNextEdge(const TopoDS_Vertex& theFirstVertex,
115 const TopoDS_Vertex& theLastVertex,
116 const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
117 const TopTools_MapOfShape& theMapToAvoid,
118 TopTools_ListOfShape& theOrderedList);
120 static Standard_Boolean FindVertex(const TopoDS_Edge& theEdge,
121 const Standard_Integer theRank,
122 const BOPDS_PDS& theDS,
123 const TopTools_DataMapOfShapeListOfShape& theHistMap,
124 TopoDS_Vertex& theVertex,
125 BOPDS_Pave& thePave);
127 static Standard_Boolean FindNextVertex(const Standard_Integer theEdgeIndex,
128 const BOPDS_Pave& thePrevPave,
129 const BOPDS_PDS& theDS,
130 TopoDS_Vertex& theNextVertex,
131 BOPDS_Pave& thePave);
133 static Standard_Boolean GetPave(const Standard_Integer theEdgeIndex,
134 const Standard_Boolean isFirst,
135 const BOPDS_PDS& theDS,
136 BOPDS_Pave& thePave);
138 static Standard_Boolean FindFromUEdge(const TopoDS_Edge& theUE1Old,
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);
154 static 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);
168 static void RemoveEdges(const TopoDS_Compound& theSourceComp,
169 const TopTools_ListOfShape& theListToRemove,
170 TopoDS_Compound& theResultComp);
172 static Standard_Boolean FilterSectionEdges(const BOPDS_VectorOfCurve& theBCurves,
173 const TopoDS_Face& theSecPlane,
174 const BOPDS_PDS& theDS,
175 TopoDS_Compound& theResult);
177 static Standard_Boolean GetUEdges(const Standard_Integer theIndex,
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);
185 static Standard_Real ComputeAveragePlaneAndMaxDeviation(const TopoDS_Shape& aWire,
187 Standard_Boolean& IsSingular);
189 static Standard_Boolean ChooseSection(const TopoDS_Shape& Comp,
191 TopoDS_Shape& resWire,
193 Standard_Boolean& IsSingular);
195 // ===========================================================================================
196 // function: Constructor
198 // ===========================================================================================
199 BRepFill_TrimShellCorner::BRepFill_TrimShellCorner(const Handle(TopTools_HArray2OfShape)& theFaces,
200 const gp_Ax2& theAxeOfBisPlane,
201 const TopoDS_Face& theSecPlane) :
202 myAxeOfBisPlane(theAxeOfBisPlane),
203 myDone(Standard_False),
204 myHasSection(Standard_False)
206 myFaces = new TopTools_HArray2OfShape(theFaces->LowerRow(), theFaces->UpperRow(),
207 theFaces->LowerCol(), theFaces->UpperCol());
208 myFaces->ChangeArray2() = theFaces->Array2();
209 mySecPln = theSecPlane;
212 // ===========================================================================================
213 // function: Constructor
215 // ===========================================================================================
216 BRepFill_TrimShellCorner::BRepFill_TrimShellCorner(const Handle(TopTools_HArray2OfShape)& theFaces,
217 const gp_Ax2& theAxeOfBisPlane,
218 const TopoDS_Wire& theSpine,
219 const TopoDS_Face& theSecPlane):
220 myAxeOfBisPlane(theAxeOfBisPlane),
221 myDone(Standard_False),
222 myHasSection(Standard_False)
224 myFaces = new TopTools_HArray2OfShape(theFaces->LowerRow(), theFaces->UpperRow(),
225 theFaces->LowerCol(), theFaces->UpperCol());
226 myFaces->ChangeArray2() = theFaces->Array2();
228 mySecPln = theSecPlane;
231 // ===========================================================================================
232 // function: SetSpine
234 // ===========================================================================================
235 void BRepFill_TrimShellCorner::SetSpine(const TopoDS_Wire& theSpine)
240 // ===========================================================================================
241 // function: AddBounds
243 // ===========================================================================================
244 void BRepFill_TrimShellCorner::AddBounds(const Handle(TopTools_HArray2OfShape)& theBounds)
246 myBounds = new TopTools_HArray2OfShape(theBounds->LowerRow(), theBounds->UpperRow(),
247 theBounds->LowerCol(), theBounds->UpperCol());
248 myBounds->ChangeArray2() = theBounds->Array2();
251 // ===========================================================================================
252 // function: AddUEdges
254 // ===========================================================================================
255 void BRepFill_TrimShellCorner::AddUEdges(const Handle(TopTools_HArray2OfShape)& theUEdges)
257 myUEdges = new TopTools_HArray2OfShape(theUEdges->LowerRow(), theUEdges->UpperRow(),
258 theUEdges->LowerCol(), theUEdges->UpperCol());
259 myUEdges->ChangeArray2() = theUEdges->Array2();
262 // ===========================================================================================
265 // ===========================================================================================
266 void BRepFill_TrimShellCorner::Perform()
268 Standard_Integer anIndex1, anIndex2, nF1, nF2, i, j, aNbP, aNbC;
269 Standard_Boolean bhassec;
271 myDone = Standard_False;
274 if(myFaces->RowLength() != 2)
276 Standard_Integer ii = 0, jj = 0;
279 for(jj = myFaces->LowerCol(); jj <= myFaces->UpperCol(); jj++) {
281 aBB.MakeShell(aShell);
283 for(ii = myFaces->LowerRow(); ii <= myFaces->UpperRow(); ii++) {
284 aBB.Add(aShell, myFaces->Value(ii, jj));
286 aShell.Closed (BRep_Tool::IsClosed (aShell));
288 if(jj == myFaces->LowerCol()) {
296 BOPAlgo_PaveFiller aPF;
297 BOPCol_ListOfShape aLS;
298 aLS.Append(myShape1);
299 aLS.Append(myShape2);
300 aPF.SetArguments(aLS);
303 if (aPF.ErrorStatus()) {
307 const BOPDS_PDS& theDS = aPF.PDS();
309 BOPDS_VectorOfInterfFF& aFFs = theDS->InterfFF();
310 Standard_Integer aNbFFs = aFFs.Extent();
312 if(!SplitUEdges(myUEdges, theDS, myHistMap)) {
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());
320 anIndex1 = theDS->Index(aF1);
321 anIndex2 = theDS->Index(aF2);
323 if((anIndex1 == -1) || (anIndex2 == -1))
326 for (i=0; i < aNbFFs; ++i) {
327 BOPDS_InterfFF& aFFi = aFFs(i);
328 aFFi.Indices(nF1, nF2);
330 BOPDS_VectorOfPoint& aVP=aFFi.ChangePoints();
332 BOPDS_VectorOfCurve& aVC=aFFi.ChangeCurves();
334 if (!aNbP && !aNbC) {
335 if (!theDS->HasInterfSubShapes(nF1, nF2)) {
340 if((nF1 == anIndex1) && (nF2 == anIndex2)) {
341 const BOPDS_VectorOfCurve& aVC = aFFi.Curves();
342 bhassec = Standard_False;
344 for (j = 0; j < aNbC; ++j) {
345 const BOPDS_Curve& aBCurve = aVC(j);
346 const BOPDS_ListOfPaveBlock& aSectEdges = aBCurve.PaveBlocks();
348 if (aSectEdges.Extent()) {
349 bhassec = Standard_True;
355 if(!MakeFacesNonSec(ii, myUEdges, myBounds, theDS, anIndex1, anIndex2, myHistMap)) {
361 if(!MakeFacesSec(ii, myUEdges, myBounds, theDS, anIndex1, anIndex2,
362 i, myAxeOfBisPlane, myHistMap)) {
371 myDone = Standard_True;
374 // ===========================================================================================
377 // ===========================================================================================
378 Standard_Boolean BRepFill_TrimShellCorner::IsDone() const
383 // ===========================================================================================
384 // function: HasSection
386 // ===========================================================================================
387 Standard_Boolean BRepFill_TrimShellCorner::HasSection() const
392 // ===========================================================================================
393 // function: Modified
395 // ===========================================================================================
396 void BRepFill_TrimShellCorner::Modified(const TopoDS_Shape& theShape,
397 TopTools_ListOfShape& theModified)
401 if(myHistMap.IsBound(theShape)) {
402 theModified = myHistMap.Find(theShape);
406 // ----------------------------------------------------------------------------------------------------
407 // static function: MakeFacesNonSec
409 // ----------------------------------------------------------------------------------------------------
410 Standard_Boolean MakeFacesNonSec(const Standard_Integer theIndex,
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)
418 Standard_Boolean bHasNewEdge = Standard_False;
419 TopoDS_Edge aNewEdge;
422 const TopoDS_Shape& aE1 = theBounds->Value(theIndex, 1);
423 const TopoDS_Shape& aE2 = theBounds->Value(theIndex, 2);
425 // search common vertex between bounds. begin
426 TopoDS_Vertex aCommonVertex;
427 Standard_Integer anIndex1 = theDS->Index(aE1);
428 Standard_Integer anIndex2 = theDS->Index(aE2);
429 Standard_Real apar1 = 0., apar2 = 0.;
431 Standard_Boolean bvertexfound =
432 FindCommonVertex(theDS, anIndex1, anIndex2, aCommonVertex, apar1, apar2);
433 // search common vertex between bounds. end
435 Handle(BRepTools_ReShape) aSubstitutor = new BRepTools_ReShape();
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;
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);
448 if(theHistMap.IsBound(aShape1)) {
449 const TopTools_ListOfShape& lst = theHistMap.Find(aShape1);
452 aUE1 = TopoDS::Edge(lst.First());
455 if(theHistMap.IsBound(aShape2)) {
456 const TopTools_ListOfShape& lst = theHistMap.Find(aShape2);
459 aUE2 = TopoDS::Edge(lst.First());
462 if(!aShape1.IsSame(aUE1))
463 aSubstitutor->Replace(aShape1.Oriented(TopAbs_FORWARD), aUE1.Oriented(TopAbs_FORWARD));
465 if(!aShape2.IsSame(aUE2))
466 aSubstitutor->Replace(aShape2.Oriented(TopAbs_FORWARD), aUE2.Oriented(TopAbs_FORWARD));
468 TopoDS_Vertex V1 = TopExp::LastVertex(aUE1);
469 TopoDS_Vertex V2 = TopExp::FirstVertex(aUE2);
472 acommonflag = (acommonflag == 0) ? ueit : 3;
473 aCommonVertices.Append(V1);
476 // search common vertices between uedges. end
479 if(aCommonVertices.Extent() != 1)
480 return Standard_False;
483 aNewEdge = BRepLib_MakeEdge(TopoDS::Vertex(aCommonVertices.First()), aCommonVertex);
485 aNewEdge = BRepLib_MakeEdge(aCommonVertex, TopoDS::Vertex(aCommonVertices.First()));
487 bHasNewEdge = Standard_True;
490 if(aCommonVertices.Extent() == 2) {
491 aNewEdge = BRepLib_MakeEdge(TopoDS::Vertex(aCommonVertices.First()),
492 TopoDS::Vertex(aCommonVertices.Last()));
493 bHasNewEdge = Standard_True;
495 Standard_Integer fit = 0;
497 for(fit = 1; fit <= 2; fit++) {
498 TopoDS_Compound aComp;
499 TopTools_MapOfShape aMapV;
500 aBB.MakeCompound(aComp);
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;
506 if(theHistMap.IsBound(aShape)) {
507 const TopTools_ListOfShape& lst = theHistMap.Find(aShape);
510 aUE = TopoDS::Edge(lst.First());
512 const TopoDS_Shape& aV = (fit == 1) ? TopExp::FirstVertex(TopoDS::Edge(aUE)) : TopExp::LastVertex(TopoDS::Edge(aUE));
517 aBB.Add(aComp, aNewEdge);
519 TopTools_ListOfShape alonevertices;
520 FindFreeVertices(aComp, aMapV, alonevertices);
522 if(!alonevertices.IsEmpty() && (alonevertices.Extent() != 2))
523 return Standard_False;
525 Standard_Integer aFaceIndex = (fit == 1) ? theFaceIndex1 : theFaceIndex2;
526 TopoDS_Shape aFace = theDS->Shape(aFaceIndex);
527 TopAbs_Orientation aFaceOri = aFace.Orientation();
528 aFace.Orientation(TopAbs_FORWARD);
530 TopExp_Explorer anExpE(aFace, TopAbs_EDGE);
533 aNewEdge.Orientation(TopAbs_FORWARD);
536 TopTools_ListOfShape aOrderedList;
538 if(!alonevertices.IsEmpty()) {
539 Standard_Integer anEIndex = (fit == 1) ? anIndex1 : anIndex2;
540 Standard_Boolean bfound1 = Standard_False;
541 Standard_Boolean bfound2 = Standard_False;
542 Standard_Real aparam1 = 0., aparam2 = 0.;
544 BOPDS_ListOfPave aLP;
545 theDS->Paves(anEIndex, aLP);
546 BOPDS_ListIteratorOfListOfPave aIt;
548 for ( ; aIt.More(); aIt.Next()) {
549 const BOPDS_Pave& aPave = aIt.Value();
550 TopoDS_Shape aV = theDS->Shape(aPave.Index());
552 if(aV.IsSame(alonevertices.First())) {
554 aparam1 = aPave.Parameter();
555 bfound1 = Standard_True;
559 if(aV.IsSame(alonevertices.Last())) {
561 aparam2 = aPave.Parameter();
562 bfound2 = Standard_True;
567 if(bfound1 && bfound2) {
568 TopoDS_Edge aNewBoundE;
571 aNewBoundE = TopoDS::Edge(aE1.EmptyCopied());
574 aNewBoundE = TopoDS::Edge(aE2.EmptyCopied());
576 TopoDS_Vertex aV1, aV2;
578 if(aparam1 < aparam2) {
579 aV1 = TopoDS::Vertex(alonevertices.First());
580 aV2 = TopoDS::Vertex(alonevertices.Last());
583 aV1 = TopoDS::Vertex(alonevertices.Last());
584 aV2 = TopoDS::Vertex(alonevertices.First());
585 Standard_Real tmp = aparam1;
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);
596 aOrderedList.Append(aNewBoundE);
599 TopExp_Explorer anExpV(aNewEdge, TopAbs_VERTEX);
600 Standard_Boolean bfoundv = Standard_False;
602 for(; !bfoundv && anExpV.More(); anExpV.Next()) {
603 if(aV2.IsSame(anExpV.Current()))
604 bfoundv = Standard_True;
608 aOrderedList.Append(aNewEdge);
610 aOrderedList.Prepend(aNewEdge);
614 return Standard_False;
619 aOrderedList.Append(aNewEdge);
623 if(!aOrderedList.IsEmpty()) {
626 TopTools_ListIteratorOfListOfShape anItE(aOrderedList);
628 for(; anItE.More(); anItE.Next()) {
629 aBB.Add(aW, anItE.Value());
632 aSubstitutor->Replace(aE1.Oriented(TopAbs_FORWARD), aW);
634 aSubstitutor->Replace(aE2.Oriented(TopAbs_FORWARD), aW);
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);
644 anExpE.Init(aFace, TopAbs_EDGE);
646 for(; anExpE.More(); anExpE.Next()) {
647 TopoDS_Shape aNewValue = aSubstitutor->Value(anExpE.Current());
649 if(aNewValue.IsNull() || aNewValue.IsSame(anExpE.Current()))
652 if(theHistMap.IsBound(anExpE.Current()))
654 TopTools_ListOfShape aListOfNewEdge;
655 TopExp_Explorer anExpE2(aNewValue, TopAbs_EDGE);
657 for(; anExpE2.More(); anExpE2.Next()) {
658 aListOfNewEdge.Append(anExpE2.Current());
660 theHistMap.Bind(anExpE.Current(), aListOfNewEdge);
664 return Standard_True;
667 // ----------------------------------------------------------------------------------------------------
668 // static function: MakeFacesSec
670 // ----------------------------------------------------------------------------------------------------
671 Standard_Boolean MakeFacesSec(const Standard_Integer theIndex,
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)
681 const BOPDS_VectorOfInterfFF& aFFs = theDS->InterfFF();
682 const BOPDS_InterfFF& aFFi = aFFs(theSSInterfIndex);
683 const BOPDS_VectorOfCurve& aBCurves = aFFi.Curves();
685 TopoDS_Compound aSecEdges;
686 TopoDS_Face aSecPlane;
688 if(!FilterSectionEdges(aBCurves, aSecPlane, theDS, aSecEdges))
689 return Standard_False;
691 TopoDS_Shape SecWire;
693 Standard_Boolean IsSingular;
694 Standard_Boolean WireFound = ChooseSection( aSecEdges, AxeOfBisPlane, SecWire, SecPlane, IsSingular );
697 //aSecEdges = SecWire;
698 TopoDS_Compound aComp;
700 BB.MakeCompound(aComp);
701 TopExp_Explorer explo( SecWire, TopAbs_EDGE );
703 for (; explo.More(); explo.Next())
704 BB.Add( aComp, explo.Current() );
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();
713 for(fit = 0; fit < 2; fit++) {
714 Standard_Integer aFaceIndex = (fit == 0) ? theFaceIndex1 : theFaceIndex2;
715 TopoDS_Face aFace = TopoDS::Face(theDS->Shape(aFaceIndex));
716 TopAbs_Orientation aFaceOri = aFace.Orientation();
717 TopoDS_Face aFaceF = aFace;
718 aFaceF.Orientation(TopAbs_FORWARD);
719 TopoDS_Edge aBoundEdge = TopoDS::Edge(theBounds->Value(theIndex, theBounds->LowerCol() +fit));
720 Standard_Integer aBoundEdgeIndex = theDS->Index(aBoundEdge);
724 if(!GetUEdges(theIndex, fit, theUEdges, aBoundEdge, aFaceF, aUE1, aUE2))
725 return Standard_False;
727 TopoDS_Edge aUE1old = aUE1;
728 TopoDS_Edge aUE2old = aUE2;
730 if(theHistMap.IsBound(aUE1)) {
731 const TopTools_ListOfShape& lst = theHistMap.Find(aUE1);
734 const TopoDS_Shape& anEdge = lst.First().Oriented(aUE1.Orientation());
736 if(!aUE1.IsSame(anEdge))
737 aSubstitutor->Replace(aUE1.Oriented(TopAbs_FORWARD), anEdge.Oriented(TopAbs_FORWARD));
738 aUE1 = TopoDS::Edge(anEdge);
742 if(theHistMap.IsBound(aUE2)) {
743 const TopTools_ListOfShape& lst = theHistMap.Find(aUE2);
746 const TopoDS_Shape& anEdge = lst.First().Oriented(aUE2.Orientation());
748 if(!aUE2.IsSame(anEdge))
749 aSubstitutor->Replace(aUE2.Oriented(TopAbs_FORWARD), anEdge.Oriented(TopAbs_FORWARD));
750 aUE2 = TopoDS::Edge(anEdge);
753 TopoDS_Vertex aPrevVertex, aNextVertex;
754 TopoDS_Compound aCompOfSecEdges = aSecEdges;
755 TopTools_ListOfShape aListOfWireEdges;
758 Standard_Boolean isPave1OnUEdge = Standard_True;
760 if(FindFromUEdge(aUE1old, aUE2old, aUE1, aUE2, aFace, aSecEdges, fit, aBoundEdge, aBoundEdgeIndex,
761 theDS, theHistMap, aCompOfSecEdges, aListOfWireEdges, aPave1, isPave1OnUEdge)) {
762 TopTools_ListOfShape aSecondListOfEdges;
763 Standard_Boolean bisSectionFound = Standard_False;
765 if(!FindFromVEdge(aPave1, isPave1OnUEdge, aUE1old, aUE2old, aFace, aCompOfSecEdges, fit, aBoundEdge,
766 aBoundEdgeIndex, theDS, theHistMap, aSecondListOfEdges, bisSectionFound)) {
767 return Standard_False;
770 if(!bisSectionFound && aListOfWireEdges.IsEmpty()) {
771 return Standard_False;
773 aListOfWireEdges.Append(aSecondListOfEdges);
776 return Standard_False;
779 if(!aListOfWireEdges.IsEmpty()) {
782 TopTools_ListIteratorOfListOfShape aEIt(aListOfWireEdges);
784 for(; aEIt.More(); aEIt.Next()) {
785 if(!aBoundEdge.IsSame(aEIt.Value()))
786 aBB.Add(aW, aEIt.Value());
788 aSubstitutor->Replace(aBoundEdge.Oriented(TopAbs_FORWARD), aW);
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);
798 TopExp_Explorer anExpE(aFace, TopAbs_EDGE);
800 for(; anExpE.More(); anExpE.Next()) {
801 TopoDS_Shape aNewValue = aSubstitutor->Value(anExpE.Current());
803 if(aNewValue.IsNull() || aNewValue.IsSame(anExpE.Current()))
806 if(theHistMap.IsBound(anExpE.Current()))
808 TopTools_ListOfShape aListOfNewEdge;
809 TopExp_Explorer anExpE2(aNewValue, TopAbs_EDGE);
811 for(; anExpE2.More(); anExpE2.Next()) {
812 aListOfNewEdge.Append(anExpE2.Current());
814 theHistMap.Bind(anExpE.Current(), aListOfNewEdge);
817 return Standard_True;
821 // ------------------------------------------------------------------------------------------
822 // static function: SplitUEdges
824 // ------------------------------------------------------------------------------------------
825 Standard_Boolean SplitUEdges(const Handle(TopTools_HArray2OfShape)& theUEdges,
826 const BOPDS_PDS& theDS,
827 TopTools_DataMapOfShapeListOfShape& theHistMap) {
829 const BOPDS_VectorOfInterfVV& aVVs = theDS->InterfVV();
832 Standard_Integer ueit = 0, upRow, lowCol, upCol;
833 TopTools_Array2OfShape aNewVertices(1,2,1,2);
835 upRow = theUEdges->UpperRow();
836 lowCol = theUEdges->LowerCol();
837 upCol = theUEdges->UpperCol();
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);
843 if(theHistMap.IsBound(aE1) || theHistMap.IsBound(aE2))
846 Standard_Integer anEIndex1 = theDS->Index(aE1);
847 Standard_Integer anEIndex2 = theDS->Index(aE2);
849 TopoDS_Vertex aCommonVertex;
850 Standard_Real apar1 = 0., apar2 = 0.;
851 Standard_Boolean bvertexfound =
852 FindCommonVertex(theDS, anEIndex1, anEIndex2, aCommonVertex, apar1, apar2);
855 TopoDS_Vertex V1 = TopExp::LastVertex(TopoDS::Edge(aE1));
856 TopoDS_Vertex V2 = TopExp::FirstVertex(TopoDS::Edge(aE2));
857 Standard_Integer vindex1 = theDS->Index(V1);
858 Standard_Integer vindex2 = theDS->Index(V2);
859 Standard_Integer vvit = 0;
860 Standard_Integer aNbVVs = aVVs.Extent();
862 for(vvit = 0; !bvertexfound && (vvit < aNbVVs); vvit++) {
863 //const BOPTools_VVInterference& aVV = aVVs(vvit);
864 const BOPDS_InterfVV& aVV = aVVs(vvit);
866 if(((vindex1 == aVV.Index1()) && (vindex2 == aVV.Index2())) ||
867 ((vindex1 == aVV.Index2()) && (vindex2 == aVV.Index1()))) {
869 if(!aVV.HasIndexNew()) {
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));
881 TopoDS_Vertex aV1, aV2;
882 Standard_Real f = 0., l = 0.;
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);
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);
904 TopTools_ListOfShape lst;
906 theHistMap.Bind(aE1, lst);
909 theHistMap.Bind(aE2, lst);
912 return Standard_True;
915 // ------------------------------------------------------------------------------------------
916 // static function: FindFreeVertices
918 // ------------------------------------------------------------------------------------------
919 void FindFreeVertices(const TopoDS_Shape& theShape,
920 const TopTools_MapOfShape& theVerticesToAvoid,
921 TopTools_ListOfShape& theListOfVertex) {
923 theListOfVertex.Clear();
924 TopTools_IndexedDataMapOfShapeListOfShape aMap;
925 TopExp::MapShapesAndAncestors(theShape, TopAbs_VERTEX, TopAbs_EDGE, aMap);
926 Standard_Integer i = 0;
928 for(i = 1; i <= aMap.Extent(); i++) {
929 const TopoDS_Shape& aKey = aMap.FindKey(i);
931 if(theVerticesToAvoid.Contains(aKey))
933 const TopTools_ListOfShape& aList = aMap.FindFromIndex(i);
935 if(aList.Extent() < 2) {
936 theListOfVertex.Append(aKey);
941 // ------------------------------------------------------------------------------------------
942 // static function: FindCommonVertex
944 // ------------------------------------------------------------------------------------------
945 Standard_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) {
952 const BOPDS_VectorOfInterfEE& aEEs = theDS->InterfEE();
954 Standard_Boolean bvertexfound = Standard_False;
955 TopoDS_Vertex aCommonVertex;
956 Standard_Integer eeit = 0;
958 Standard_Integer aNbEEs;
959 aNbEEs = aEEs.Extent();
960 for(eeit = 0; eeit < aNbEEs; ++eeit) {
961 const BOPDS_InterfEE& aEE = aEEs(eeit);
963 if((theEIndex1 == aEE.Index1() && theEIndex2 == aEE.Index2()) ||
964 (theEIndex1 == aEE.Index2() && theEIndex2 == aEE.Index1())) {
966 if(!aEE.HasIndexNew())
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()) {
973 IntTools_Tools::VertexParameters(aCP, theParamOnE1, theParamOnE2);
975 IntTools_Tools::VertexParameters(aCP, theParamOnE2, theParamOnE1);
978 bvertexfound = Standard_True;
986 // ----------------------------------------------------------------------------------------------------
987 // static function: GetUEdges
989 // ----------------------------------------------------------------------------------------------------
990 Standard_Boolean GetUEdges(const Standard_Integer theIndex,
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);
1000 TopoDS_Face aFace = theFace;
1001 aFace.Orientation(TopAbs_FORWARD);
1003 TopExp_Explorer anExp(aFace, TopAbs_EDGE);
1005 for(; anExp.More(); anExp.Next()) {
1006 if(E1.IsNull() && aUE1.IsSame(anExp.Current())) {
1007 E1 = TopoDS::Edge(anExp.Current());
1009 else if(E2.IsNull() && aUE2.IsSame(anExp.Current())) {
1010 E2 = TopoDS::Edge(anExp.Current());
1014 if(E1.IsNull() || E2.IsNull())
1015 return Standard_False;
1018 Handle(Geom2d_Curve) C1 = BRep_Tool::CurveOnSurface(E1, aFace, f, l);
1021 return Standard_False;
1022 gp_Pnt2d PU1 = (theRank == 0) ? C1->Value(l) : C1->Value(f);
1023 Handle(Geom2d_Curve) C2 = BRep_Tool::CurveOnSurface(theBoundEdge, aFace, f, l);
1026 return Standard_False;
1027 BRep_Tool::Range(theBoundEdge, f, l);
1028 gp_Pnt2d pf = C2->Value(f);
1029 TopoDS_Vertex aV = (theRank == 0) ? TopExp::LastVertex(E1) : TopExp::FirstVertex(E1);
1030 Standard_Real aTolerance = BRep_Tool::Tolerance(aV);
1031 BRepAdaptor_Surface aBAS(aFace, Standard_False);
1033 if(pf.Distance(PU1) > aBAS.UResolution(aTolerance)) {
1034 TopoDS_Edge atmpE = E1;
1039 theSecondUEdge = E2;
1040 return Standard_True;
1043 // ----------------------------------------------------------------------------------------------------
1044 // static function: FillGap
1046 // ----------------------------------------------------------------------------------------------------
1047 Standard_Boolean FillGap(const TopoDS_Vertex& theFirstVertex,
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) {
1055 TopTools_IndexedDataMapOfShapeListOfShape aMap;
1056 TopExp::MapShapesAndAncestors(theSectionEdges, TopAbs_VERTEX, TopAbs_EDGE, aMap);
1058 if(aMap.IsEmpty()) {
1059 return Standard_False;
1062 if(!aMap.Contains(theFirstVertex) ||
1063 !aMap.Contains(theLastVertex)) {
1064 return Standard_False;
1066 TopTools_ListOfShape aListOfEdge;
1067 // Standard_Integer i = 0;
1068 // TopoDS_Vertex aCurVertex = theFirstVertex;
1069 TopTools_MapOfShape aMapToAvoid;
1071 if(FindNextEdge(theFirstVertex, theLastVertex, aMap, aMapToAvoid, aListOfEdge)) {
1072 if(!aListOfEdge.IsEmpty()) {
1073 return CheckAndOrientEdges(aListOfEdge, theFirstPoint, theLastPoint, theFace, theOrderedList);
1076 return Standard_False;
1079 // ----------------------------------------------------------------------------------------------------
1080 // static function: FindNextEdge
1082 // ----------------------------------------------------------------------------------------------------
1083 Standard_Boolean FindNextEdge(const TopoDS_Vertex& theFirstVertex,
1084 const TopoDS_Vertex& theLastVertex,
1085 const TopTools_IndexedDataMapOfShapeListOfShape& theMapVE,
1086 const TopTools_MapOfShape& theMapToAvoid,
1087 TopTools_ListOfShape& theOrderedList) {
1088 TopoDS_Vertex aCurVertex = theFirstVertex;
1089 TopTools_MapOfShape aMapToAvoid;
1090 aMapToAvoid = theMapToAvoid;
1091 TopTools_ListOfShape aListOfEdge;
1092 Standard_Integer i = 0;
1094 for(i = 1; i <= theMapVE.Extent(); i++) {
1095 if(!theMapVE.Contains(aCurVertex))
1097 const TopTools_ListOfShape& lste = theMapVE.FindFromKey(aCurVertex);
1098 Standard_Boolean befound = Standard_False;
1100 TopTools_ListIteratorOfListOfShape anIt(lste);
1102 for(; anIt.More(); anIt.Next()) {
1103 TopoDS_Shape anEdge = anIt.Value();
1104 TopoDS_Vertex aSaveCurVertex = aCurVertex;
1106 if(!aMapToAvoid.Contains(anEdge)) {
1107 TopoDS_Vertex V1, V2;
1108 TopExp::Vertices(TopoDS::Edge(anEdge), V1, V2);
1110 if(!aCurVertex.IsSame(V1)) {
1113 else if(!aCurVertex.IsSame(V2)) {
1116 aMapToAvoid.Add(anEdge);
1117 befound = Standard_True;
1118 aListOfEdge.Append(anEdge);
1120 if(!aCurVertex.IsSame(theLastVertex)) {
1121 TopTools_ListOfShape aListtmp;
1123 if(!FindNextEdge(aCurVertex, theLastVertex, theMapVE, aMapToAvoid, aListtmp)) {
1124 aListOfEdge.Clear();
1125 aCurVertex = aSaveCurVertex;
1129 aListOfEdge.Append(aListtmp);
1130 theOrderedList.Append(aListOfEdge);
1131 return Standard_True;
1138 if(aCurVertex.IsSame(theLastVertex))
1142 return Standard_False;
1146 if(aCurVertex.IsSame(theLastVertex)) {
1147 theOrderedList.Append(aListOfEdge);
1148 return Standard_True;
1150 return Standard_False;
1153 // ----------------------------------------------------------------------------------------------------
1154 // static function: CheckAndOrientEdges
1156 // ----------------------------------------------------------------------------------------------------
1157 Standard_Boolean CheckAndOrientEdges(const TopTools_ListOfShape& theOrderedList,
1158 const gp_Pnt2d& theFirstPoint,
1159 const gp_Pnt2d& theLastPoint,
1160 const TopoDS_Face& theFace,
1161 TopTools_ListOfShape& theOrientedList) {
1162 TopTools_ListIteratorOfListOfShape anIt(theOrderedList);
1165 return Standard_True;
1168 TopoDS_Edge aEPrev = TopoDS::Edge(anIt.Value());
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);
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;
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;
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;
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;
1202 ap = aCurve->Value(l);
1204 if(ap.Distance(theLastPoint) < aTolerance2) {
1205 bforward = Standard_True;
1207 if(theOrientedList.IsEmpty())
1208 theOrientedList.Append(aEPrev.Oriented(TopAbs_FORWARD));
1209 bLastFound = Standard_True;
1211 else if(ap.Distance(theFirstPoint) < aTolerance2) {
1212 bforward = Standard_False;
1214 if(theOrientedList.IsEmpty())
1215 theOrientedList.Append(aEPrev.Oriented(TopAbs_REVERSED));
1216 bFirstFound = Standard_True;
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;
1227 if(aV12.IsSame(aV21) || aV11.IsSame(aV22)) {
1228 anOri = (bforward) ? TopAbs_FORWARD : TopAbs_REVERSED;
1231 anOri = (bforward) ? TopAbs_REVERSED : TopAbs_FORWARD;
1233 theOrientedList.Append(aE.Oriented(anOri));
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);
1246 if(ap.Distance(theFirstPoint) < aTolerance1) {
1247 bFirstFound = Standard_True;
1249 else if(ap.Distance(theLastPoint) < aTolerance1) {
1250 bLastFound = Standard_True;
1252 ap = aCurve->Value(l);
1254 if(ap.Distance(theFirstPoint) < aTolerance2) {
1255 bFirstFound = Standard_True;
1257 else if(ap.Distance(theLastPoint) < aTolerance2) {
1258 bLastFound = Standard_True;
1262 if(!bFirstFound || !bLastFound)
1263 return Standard_False;
1264 return Standard_True;
1267 // ----------------------------------------------------------------------------------------------------
1268 // static function: FindVertex
1270 // ----------------------------------------------------------------------------------------------------
1271 Standard_Boolean FindVertex(const TopoDS_Edge& theEdge,
1272 const Standard_Integer theRank,
1273 const BOPDS_PDS& theDS,
1274 const TopTools_DataMapOfShapeListOfShape& theHistMap,
1275 TopoDS_Vertex& theVertex,
1276 BOPDS_Pave& thePave) {
1278 if(!theHistMap.IsBound(theEdge))
1279 return Standard_False;
1281 const TopTools_ListOfShape& lst = theHistMap.Find(theEdge);
1284 return Standard_False;
1286 TopoDS_Edge aNewEdge = TopoDS::Edge(lst.First());
1288 BRep_Tool::Range(aNewEdge, f, l);
1291 thePave.SetParameter(l);
1292 theVertex = TopExp::LastVertex(aNewEdge);
1295 thePave.SetParameter(f);
1296 theVertex = TopExp::FirstVertex(aNewEdge);
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)) {
1312 thePave.SetIndex(anIndex);
1314 return Standard_True;
1317 // ----------------------------------------------------------------------------------------------------
1318 // static function: FindNextVertex
1320 // ----------------------------------------------------------------------------------------------------
1321 Standard_Boolean FindNextVertex(const Standard_Integer theEdgeIndex,
1322 const BOPDS_Pave& thePrevPave,
1323 const BOPDS_PDS& theDS,
1324 TopoDS_Vertex& theNextVertex,
1325 BOPDS_Pave& thePave) {
1327 Standard_Boolean bTakePave, bFound;
1328 BOPDS_Pave aTmpPave;
1329 BOPDS_ListIteratorOfListOfPave aItP;
1331 BOPDS_Pave anullpave;
1332 bFound = Standard_False;
1333 bTakePave = thePrevPave.IsEqual(anullpave);
1335 BOPDS_ListOfPave aLP;
1336 theDS->Paves(theEdgeIndex, aLP);
1337 aItP.Initialize(aLP);
1338 for (; aItP.More(); aItP.Next()) {
1339 aTmpPave = aItP.Value();
1342 if (theDS->IsNewShape(aTmpPave.Index())) {
1343 theNextVertex = *(TopoDS_Vertex*)&theDS->Shape(aTmpPave.Index());
1345 bFound = Standard_True;
1350 else if (aTmpPave.IsEqual(thePrevPave)) {
1351 bTakePave = Standard_True;
1358 // ----------------------------------------------------------------------------------------------------
1359 // static function: GetPave
1361 // ----------------------------------------------------------------------------------------------------
1362 Standard_Boolean GetPave(const Standard_Integer theEdgeIndex,
1363 const Standard_Boolean isFirst,
1364 const BOPDS_PDS& theDS,
1365 BOPDS_Pave& thePave) {
1367 Handle(BOPDS_PaveBlock) aPB;
1368 BOPDS_ListOfPave aLP;
1370 theDS->Paves(theEdgeIndex, aLP);
1371 if (!aLP.Extent()) {
1372 return Standard_False;
1376 thePave = aLP.First();
1379 thePave = aLP.Last();
1382 return Standard_True;
1385 // ----------------------------------------------------------------------------------------------------
1386 // static function: FindFromUEdge
1388 // ----------------------------------------------------------------------------------------------------
1389 Standard_Boolean FindFromUEdge(const TopoDS_Edge& theUE1Old,
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) {
1404 theFoundPave.SetIndex(0);
1405 theFoundPave.SetParameter(0.);
1406 isOnUEdge = Standard_True;
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;
1415 BOPDS_Pave aPave1, aPave2;
1416 Standard_Real f = 0., l = 0.;
1418 TopoDS_Vertex aFirstV, aLastV;
1419 BOPDS_Pave atmpPave;
1421 if(!FindVertex(theUE1Old, theRank, theDS, theHistMap, aPrevVertex, atmpPave)) {
1422 return Standard_True;
1425 if(aPrevVertex.IsNull()) {
1426 return Standard_False;
1429 aFirstV = aPrevVertex;
1430 Standard_Boolean bSecFound = Standard_False;
1431 Handle(Geom2d_Curve) aC1 = BRep_Tool::CurveOnSurface(theUE1New, aFaceF, f, l);
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();
1437 Standard_Integer pit = 0;
1439 while(FindNextVertex(theBoundEdgeIndex, aPave1, theDS, aNextVertex, aPave2) && (pit < nbpave)) {
1440 aLastV = aNextVertex;
1441 Handle(Geom2d_Curve) aC2 = BRep_Tool::CurveOnSurface(theBoundEdge, aFaceF, f, l);
1442 p2 = aC2->Value(aPave2.Parameter());
1443 TopTools_ListOfShape aOrderedList;
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;
1456 aPrevVertex = aNextVertex;
1461 if(!bSecFound && FindVertex(theUE2Old, theRank, theDS, theHistMap, aNextVertex, aPave2)) {
1462 aLastV = aNextVertex;
1463 Handle(Geom2d_Curve) aC2 = BRep_Tool::CurveOnSurface(theUE2New, aFaceF, f, l);
1464 p2 = aC2->Value(aPave2.Parameter());
1465 TopTools_ListOfShape aOrderedList;
1467 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
1468 // remove found edges...
1469 TopoDS_Compound aComp;
1471 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1472 aCompOfSecEdges = aComp;
1473 aListOfWireEdges.Append(aOrderedList);
1474 afoundpave = aPave2;
1475 bSecFound = Standard_True;
1476 isOnUEdge = Standard_True;
1481 theFoundPave = afoundpave;
1482 theListOfWireEdges = aListOfWireEdges;
1483 theSecEdgesNew = aCompOfSecEdges;
1485 return Standard_True;
1489 // ----------------------------------------------------------------------------------------------------
1490 // static function: FindFromVEdge
1492 // ----------------------------------------------------------------------------------------------------
1493 Standard_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) {
1507 theListOfWireEdges.Clear();
1508 isSectionFound = Standard_False;
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;
1517 BOPDS_Pave aPave1, aPave2;
1520 TopoDS_Vertex atmpVertex;
1521 BOPDS_Pave aPaveOfE2;
1523 if(FindVertex(theUE2Old, theRank, theDS, theHistMap, atmpVertex, aPaveOfE2)) {
1524 if(thePrevPave.IsEqual(aPaveOfE2))
1525 return Standard_True;
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;
1536 aPave1 = thePrevPave;
1539 BOPDS_Pave atmpPave;
1541 if(!GetPave(theBoundEdgeIndex, Standard_True, theDS, atmpPave)) {
1542 return Standard_False;
1546 p1 = aC2->Value(aPave1.Parameter());
1547 aPrevVertex = TopoDS::Vertex(theDS->Shape(aPave1.Index()));
1549 BOPDS_ListOfPave aLP;
1550 theDS->Paves(theBoundEdgeIndex, aLP);
1551 Standard_Integer nbpave = aLP.Extent();
1552 Standard_Integer pit = 0;
1553 TopTools_Array1OfListOfShape anArrayOfListOfSec(1, nbpave);
1555 // by pairs non continuously. begin
1556 Standard_Integer k = 0;
1557 BOPDS_Pave aFirstPave = aPave1;
1558 TopoDS_Vertex aFirstVertex = aPrevVertex;
1559 gp_Pnt2d apfirst = p1;
1560 BOPDS_ListOfPave aFirstPaves, aLastPaves;
1561 TColStd_ListOfInteger aListOfFlags;
1562 Standard_Integer apaircounter = 1;
1564 for(k = 0; k < nbpave; k++) {
1565 aPave1 = aFirstPave;
1567 aPrevVertex = aFirstVertex;
1568 Standard_Boolean bfound = Standard_False;
1571 while(FindNextVertex(theBoundEdgeIndex, aPave1, theDS, aNextVertex, aPave2) && (pit < nbpave)) {
1572 aFirstV = aPrevVertex;
1573 aLastV = aNextVertex;
1574 p2 = aC2->Value(aPave2.Parameter());
1576 TopTools_ListOfShape aOrderedList;
1578 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
1579 TopoDS_Compound aComp;
1580 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1581 aCompOfSecEdges = aComp;
1583 anArrayOfListOfSec(apaircounter++).Append(aOrderedList);
1584 aFirstPaves.Append(aFirstPave);
1585 aLastPaves.Append(aPave2);
1586 aListOfFlags.Append(1);
1587 aFirstPave = aPave2;
1588 aFirstVertex = aNextVertex;
1590 aPrevVertex = aNextVertex;
1591 bSecFound = Standard_True;
1592 bfound = Standard_True;
1598 if(FindVertex(theUE2Old, theRank, theDS, theHistMap, aNextVertex, aPave2)) {
1599 aFirstV = aPrevVertex;
1600 aLastV = aNextVertex;
1601 Handle(Geom2d_Curve) aC3 = BRep_Tool::CurveOnSurface(theUE2Old, aFaceF, f, l);
1602 p2 = aC3->Value(aPave2.Parameter());
1604 TopTools_ListOfShape aOrderedList;
1606 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
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;
1620 if(!FindNextVertex(theBoundEdgeIndex, aFirstPave, theDS, aNextVertex, aPave2)) {
1623 aFirstPave = aPave2;
1624 apfirst = aC2->Value(aPave2.Parameter());
1625 aFirstVertex = aNextVertex;
1628 // by pairs non continuously. end
1630 // by pairs continuously. begin
1631 aPave1 = thePrevPave;
1634 BOPDS_Pave atmpPave;
1636 if(!GetPave(theBoundEdgeIndex, Standard_True, theDS, atmpPave)) {
1637 return Standard_False;
1641 p1 = aC2->Value(aPave1.Parameter());
1642 aPrevVertex = TopoDS::Vertex(theDS->Shape(aPave1.Index()));
1646 while(FindNextVertex(theBoundEdgeIndex, aPave1, theDS, aNextVertex, aPave2) && (pit < nbpave)) {
1647 aFirstV = aPrevVertex;
1648 aLastV = aNextVertex;
1649 p2 = aC2->Value(aPave2.Parameter());
1651 Standard_Boolean bisinside = Standard_False;
1652 Standard_Integer apbindex = 0;
1653 Standard_Integer apbcounter = 1;
1654 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1655 BOPDS_ListIteratorOfListOfPave aPIt1, aPIt2;
1656 TColStd_ListIteratorOfListOfInteger aFlagIt;
1658 for(aPIt1.Initialize(aFirstPaves), aPIt2.Initialize(aLastPaves), aFlagIt.Initialize(aListOfFlags);
1659 aPIt1.More() && aPIt2.More() && aFlagIt.More();
1660 aPIt1.Next(), aPIt2.Next(), aFlagIt.Next(), apbcounter++) {
1662 Standard_Boolean bfin = Standard_False;
1663 Standard_Boolean blin = Standard_False;
1665 if(aPave1.IsEqual(aPIt1.Value())) {
1666 bfin = Standard_True;
1669 bfin = (aPave1.Parameter() > aPIt1.Value().Parameter());
1672 if(aFlagIt.Value()) {
1673 if(aPave2.IsEqual(aPIt2.Value())) {
1674 blin = Standard_True;
1677 blin = (aPave2.Parameter() < aPIt2.Value().Parameter());
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;
1691 if(p2.Distance(p3) < aTolerance)
1692 blin = Standard_True;
1697 apbindex = apbcounter;
1698 bisinside = Standard_True;
1705 TopTools_ListOfShape aOrderedList;
1707 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
1708 TopoDS_Compound aComp;
1709 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1710 aCompOfSecEdges = aComp;
1711 aListOfWireEdges.Append(aOrderedList);
1713 bSecFound = Standard_True;
1716 TopoDS_Edge aESplit;
1718 aPBIt.Initialize(theDS->PaveBlocks(theBoundEdgeIndex));
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());
1732 if(!aESplit.IsNull()) {
1733 aListOfWireEdges.Append(aESplit);
1739 TopTools_ListOfShape& aListOfSec = anArrayOfListOfSec(apbindex);
1740 aListOfWireEdges.Append(aListOfSec);
1744 aPrevVertex = aNextVertex;
1749 if(FindVertex(theUE2Old, theRank, theDS, theHistMap, aNextVertex, aPave2)) {
1750 aFirstV = aPrevVertex;
1751 aLastV = aNextVertex;
1752 Handle(Geom2d_Curve) aC3 = BRep_Tool::CurveOnSurface(theUE2Old, aFaceF, f, l);
1753 p2 = aC3->Value(aPave2.Parameter());
1755 Standard_Boolean bisinside = Standard_False;
1756 Standard_Integer apbindex = 0;
1757 Standard_Integer apbcounter = 1;
1758 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1759 BOPDS_ListIteratorOfListOfPave aPIt1, aPIt2;
1760 TColStd_ListIteratorOfListOfInteger aFlagIt;
1762 for(aPIt1.Initialize(aFirstPaves), aPIt2.Initialize(aLastPaves), aFlagIt.Initialize(aListOfFlags);
1763 aPIt1.More() && aPIt2.More() && aFlagIt.More();
1764 aPIt1.Next(), aPIt2.Next(), aFlagIt.Next(), apbcounter++) {
1766 Standard_Boolean bfin = Standard_False;
1767 Standard_Boolean blin = Standard_False;
1769 if(aPave1.IsEqual(aPIt1.Value())) {
1770 bfin = Standard_True;
1773 bfin = (aPave1.Parameter() > aPIt1.Value().Parameter());
1776 if(aFlagIt.Value()) {
1777 if(aPave2.IsEqual(aPIt2.Value())) {
1778 blin = Standard_True;
1781 blin = (aPave2.Parameter() < aPIt2.Value().Parameter());
1785 blin = Standard_True;
1789 apbindex = apbcounter;
1790 bisinside = Standard_True;
1797 TopTools_ListOfShape aOrderedList;
1799 if(FillGap(aFirstV, aLastV, p1, p2, aFaceF, aCompOfSecEdges, aOrderedList)) {
1800 TopoDS_Compound aComp;
1801 RemoveEdges(aCompOfSecEdges, aOrderedList, aComp);
1802 aCompOfSecEdges = aComp;
1803 aListOfWireEdges.Append(aOrderedList);
1805 bSecFound = Standard_True;
1809 TopoDS_Edge aESplit;
1811 if(!GetPave(theBoundEdgeIndex, Standard_False, theDS, aPave2))
1812 return Standard_False;
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());
1827 if(!aESplit.IsNull()) {
1828 aListOfWireEdges.Append(aESplit);
1834 TopTools_ListOfShape& aListOfSec = anArrayOfListOfSec(apbindex);
1835 aListOfWireEdges.Append(aListOfSec);
1841 TopoDS_Edge aESplit;
1843 if(!GetPave(theBoundEdgeIndex, Standard_False, theDS, aPave2))
1844 return Standard_False;
1846 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1847 aPBIt.Initialize(theDS->PaveBlocks(theBoundEdgeIndex));
1848 for(; aPBIt.More(); aPBIt.Next()) {
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());
1860 if(!aESplit.IsNull()) {
1861 aListOfWireEdges.Append(aESplit);
1865 // by pairs continuously. end
1866 theListOfWireEdges = aListOfWireEdges;
1867 isSectionFound = bSecFound;
1868 return Standard_True;
1871 // ----------------------------------------------------------------------------------------------------
1872 // static function: RemoveEdges
1874 // ----------------------------------------------------------------------------------------------------
1875 void RemoveEdges(const TopoDS_Compound& theSourceComp,
1876 const TopTools_ListOfShape& theListToRemove,
1877 TopoDS_Compound& theResultComp) {
1879 TopoDS_Compound aComp;
1880 aBB.MakeCompound(aComp);
1881 TopExp_Explorer anExp(theSourceComp, TopAbs_EDGE);
1883 for(; anExp.More(); anExp.Next()) {
1884 Standard_Boolean bfound = Standard_False;
1885 TopTools_ListIteratorOfListOfShape anIt(theListToRemove);
1887 for(; !bfound && anIt.More(); anIt.Next()) {
1888 bfound = anExp.Current().IsSame(anIt.Value());
1892 aBB.Add(aComp, anExp.Current());
1895 theResultComp = aComp;
1898 // ----------------------------------------------------------------------------------------------------
1899 // static function: FilterSectionEdges
1901 // ----------------------------------------------------------------------------------------------------
1902 Standard_Boolean FilterSectionEdges(const BOPDS_VectorOfCurve& theBCurves,
1903 const TopoDS_Face& theSecPlane,
1904 const BOPDS_PDS& theDS,
1905 TopoDS_Compound& theResult) {
1907 theResult.Nullify();
1910 aBB.MakeCompound(theResult);
1911 Standard_Integer aNbCurves = theBCurves.Extent();
1912 Standard_Integer cit = 0;
1913 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
1915 for(cit = 0; cit < aNbCurves; ++cit) {
1916 const BOPDS_Curve& aBCurve = theBCurves(cit);
1917 const BOPDS_ListOfPaveBlock& aSectEdges = aBCurve.PaveBlocks();
1919 aPBIt.Initialize(aSectEdges);
1920 for (; aPBIt.More(); aPBIt.Next()) {
1921 const Handle(BOPDS_PaveBlock)& aPB = aPBIt.Value();
1922 Standard_Integer nSect = aPB->Edge();
1923 const TopoDS_Shape& aS = theDS->Shape(nSect);
1924 TopoDS_Edge anEdge = TopoDS::Edge(aS);
1925 Standard_Boolean bAddEdge = Standard_True;
1927 if(!theSecPlane.IsNull()) {
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);
1933 Handle(IntTools_Context) aContext = new IntTools_Context;
1934 anIntersector.SetContext(aContext);
1936 anIntersector.Perform();
1938 if(anIntersector.IsDone()) {
1939 bAddEdge = Standard_False;
1940 Standard_Integer r = 0;
1942 for(r = 1; r <= anIntersector.Result().Length(); r++) {
1943 const IntTools_Range& aRange = anIntersector.Result().Value(r);
1945 if(((aRange.First() - f) < Precision::PConfusion()) &&
1946 ((l - aRange.Last()) < Precision::PConfusion())) {
1947 bAddEdge = Standard_True;
1949 }//if(((aRange.First() - f) < Precision::PConfusion()) &&
1950 }//for(r = 1; r <= anIntersector.Result().Length(); r++) {
1951 }//if(anIntersector.IsDone()) {
1952 }//if(!theSecPlane.IsNull()) {
1955 aBB.Add(theResult, aS);
1957 }//for (; aPBIt.More(); aPBIt.Next()) {
1958 }//for(cit = 0; cit < aNbCurves; ++cit) {
1960 return Standard_True;
1964 //=======================================================================
1965 //function : ComputeAveragePlaneAndMaxDeviation
1967 //=======================================================================
1968 static Standard_Real ComputeAveragePlaneAndMaxDeviation(const TopoDS_Shape& aWire,
1970 Standard_Boolean& IsSingular)
1972 Standard_Integer N = 40, nedges = 0;
1974 TopoDS_Iterator iter( aWire );
1975 for (; iter.More(); iter.Next())
1978 TColgp_Array1OfPnt Pnts( 1, nedges*N );
1979 Standard_Integer ind = 1, i;
1980 for (iter.Initialize(aWire); iter.More(); iter.Next())
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++)
1987 Standard_Real par = Distribution.Parameter(i);
1988 Pnts( ind++ ) = aCurve.Value(par);
1993 GeomLib::AxeOfInertia( Pnts, Axe, IsSingular );
1997 thePlane = gp_Pln( Axe );
1998 Standard_Real MaxDeviation = 0;
1999 for (i = 1; i <= Pnts.Length(); i++)
2001 Standard_Real dist = thePlane.Distance( Pnts(i) );
2002 if (dist > MaxDeviation)
2003 MaxDeviation = dist;
2005 return MaxDeviation;
2008 //=======================================================================
2009 //function : ChooseSection
2011 //=======================================================================
2012 static Standard_Boolean ChooseSection(const TopoDS_Shape& Comp,
2014 TopoDS_Shape& resWire,
2016 Standard_Boolean& IsSingular)
2018 IsSingular = Standard_False;
2019 Standard_Real TolDeviation = 0.01; //, TolConf = 1.e-4, TolAng = 1.e-5;
2021 // Standard_Integer N = 100;
2022 Standard_Integer ind, i, j;
2025 TopoDS_Compound OldComp;
2027 B.MakeCompound( OldComp );
2028 TopoDS_Iterator iter( Comp );
2029 for (; iter.More(); iter.Next())
2030 B.Add( OldComp, iter.Value() );
2032 Standard_Boolean anError = Standard_False;
2033 //TopoDS_Wire NewWire [2];
2034 TopTools_SequenceOfShape Wseq;
2037 TopExp_Explorer explo( OldComp, TopAbs_EDGE );
2040 TopoDS_Edge FirstEdge = TopoDS::Edge( explo.Current() );
2041 TopoDS_Wire NewWire = BRepLib_MakeWire( FirstEdge );
2042 B.Remove( OldComp, FirstEdge );
2043 if (NewWire.Closed())
2045 Wseq.Append(NewWire);
2051 TopoDS_Vertex Extremity [2];
2052 TopExp::Vertices( NewWire, Extremity[0], Extremity[1] );
2053 if (Extremity[0].IsNull() || Extremity[1].IsNull())
2055 anError = Standard_True;
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
2067 Standard_Boolean Modified = Standard_False;
2068 for (j = 0; j < 2; j++)
2070 if (Vedges[j].Extent() == 1)
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;
2078 if (!Modified) //only multiple connections
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++)
2089 TopoDS_Wire aWire = BRepLib_MakeWire( NewWire, TopoDS::Edge(Edges(j)) );
2091 Standard_Boolean issing;
2092 Standard_Real Deviation = ComputeAveragePlaneAndMaxDeviation( aWire, aPlane, issing );
2093 if (Deviation < MinDeviation)
2095 MinDeviation = Deviation;
2099 NewWire = BRepLib_MakeWire( NewWire, TopoDS::Edge(Edges(theind)) );
2100 B.Remove( OldComp, Edges(theind) );
2102 if (NewWire.Closed())
2105 Wseq.Append(NewWire);
2110 Standard_Real Deviation=0.;
2111 Standard_Real MinAngle = RealLast();
2112 TopExp_Explorer Explo( OldComp, TopAbs_EDGE );
2113 if (!anError && !Explo.More())
2115 if (Wseq.Length() == 1)
2117 resWire = Wseq.First();
2118 Deviation = ComputeAveragePlaneAndMaxDeviation( resWire, resPlane, IsSingular );
2119 return Standard_True;
2123 for (i = 1; i <= Wseq.Length(); i++)
2125 TopoDS_Wire aWire = TopoDS::Wire( Wseq(i) );
2127 Standard_Boolean issing;
2128 Standard_Real aDeviation =
2129 ComputeAveragePlaneAndMaxDeviation( aWire, aPln, issing );
2133 Standard_Real Angle = aPln.Axis().Angle( bis.Axis() );
2135 Angle = M_PI - Angle;
2137 if (Angle < MinAngle)
2142 Deviation = aDeviation;
2145 if (Deviation <= TolDeviation)
2146 return Standard_True;
2149 return Standard_False;
2150 //end of simplest case