1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <QANewModTopOpe_Tools.ixx>
16 #include <BRepAlgoAPI_Cut.hxx>
17 #include <BRepAlgoAPI_Common.hxx>
20 #include <TopoDS_Face.hxx>
21 #include <TopoDS_Edge.hxx>
23 #include <BRepTools.hxx>
24 #include <BRep_Tool.hxx>
25 #include <BRep_Builder.hxx>
26 #include <Geom_Surface.hxx>
27 #include <IntTools_Context.hxx>
28 #include <TopExp_Explorer.hxx>
30 #include <GeomAPI_ProjectPointOnSurf.hxx>
31 #include <TopTools_IndexedMapOfShape.hxx>
32 #include <TopTools_DataMapOfIntegerShape.hxx>
34 #include <TColStd_Array1OfReal.hxx>
35 #include <TColStd_IndexedMapOfReal.hxx>
36 #include <TColStd_ListOfInteger.hxx>
37 #include <TColStd_ListIteratorOfListOfInteger.hxx>
39 #include <BOPAlgo_PaveFiller.hxx>
40 #include <BOPDS_DS.hxx>
41 #include <BOPAlgo_Builder.hxx>
42 #include <BOPAlgo_BOP.hxx>
43 #include <IntTools_CommonPrt.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <BOPDS_CommonBlock.hxx>
46 #include <BOPTools_AlgoTools3D.hxx>
48 #include <NCollection_Array1.hxx>
51 static Standard_Boolean AddShapeToHistoryMap(const TopoDS_Shape& theOldShape,
52 const TopoDS_Shape& theNewShape,
53 TopTools_IndexedDataMapOfShapeListOfShape& theHistoryMap);
55 static void FillEdgeHistoryMap(BRepAlgoAPI_BooleanOperation& theBOP,
56 TopTools_IndexedDataMapOfShapeListOfShape& theHistoryMap);
58 static void SortVertexOnEdge(const TopoDS_Edge& theEdge,
59 const TopTools_ListOfShape& theListOfVertex,
60 TopTools_ListOfShape& theListOfVertexSorted);
62 static TopAbs_State GetEdgeState(const BOPDS_PDS& pDS,
63 const Handle(BOPDS_PaveBlock)& aPB);
65 // ========================================================================================
68 // ========================================================================================
69 Standard_Integer QANewModTopOpe_Tools::NbPoints(const BOPAlgo_PPaveFiller& theDSFiller)
71 Standard_Integer i, anbpoints, aNb;
73 const BOPDS_PDS& pDS = theDSFiller->PDS();
77 BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
79 for (i = 0; i < aNb; ++i) {
80 BOPDS_InterfFF& aFF=aFFs(i);
81 const BOPDS_VectorOfPoint& aVP=aFF.Points();
82 anbpoints += aVP.Extent();
86 BOPDS_VectorOfInterfEF& aEFs=pDS->InterfEF();
88 for (i = 0; i < aNb; ++i) {
89 BOPDS_InterfEF& aEF=aEFs(i);
90 IntTools_CommonPrt aCP = aEF.CommonPart();
91 if(aCP.Type() == TopAbs_VERTEX) {
97 BOPDS_VectorOfInterfEE& aEEs=pDS->InterfEE();
99 for (i = 0; i < aNb; ++i) {
100 BOPDS_InterfEE& aEE=aEEs(i);
101 IntTools_CommonPrt aCP = aEE.CommonPart();
102 if(aCP.Type() == TopAbs_VERTEX) {
110 // ========================================================================================
111 // function: NewVertex
113 // ========================================================================================
114 TopoDS_Shape QANewModTopOpe_Tools::NewVertex(const BOPAlgo_PPaveFiller& theDSFiller,
115 const Standard_Integer theIndex)
117 TopoDS_Shape aVertex;
118 Standard_Integer i, j, anbpoints, aNb, aNbP;
120 const BOPDS_PDS& pDS = theDSFiller->PDS();
124 BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
126 for (i = 0; i < aNb; ++i) {
127 BOPDS_InterfFF& aFF=aFFs(i);
128 const BOPDS_VectorOfPoint& aVP=aFF.Points();
130 for(j = 0; j < aNbP; ++j) {
133 if (theIndex == anbpoints) {
134 const BOPDS_Point& aNP = aVP(j);
135 return pDS->Shape(aNP.Index());
141 BOPDS_VectorOfInterfEF& aEFs=pDS->InterfEF();
143 for (i = 0; i < aNb; ++i) {
144 BOPDS_InterfEF& aEF=aEFs(i);
145 IntTools_CommonPrt aCP = aEF.CommonPart();
146 if(aCP.Type() == TopAbs_VERTEX) {
149 if (theIndex == anbpoints) {
150 return pDS->Shape(aEF.IndexNew());
156 BOPDS_VectorOfInterfEE& aEEs=pDS->InterfEE();
158 for (i = 0; i < aNb; ++i) {
159 BOPDS_InterfEE& aEE=aEEs(i);
160 IntTools_CommonPrt aCP = aEE.CommonPart();
161 if(aCP.Type() == TopAbs_VERTEX) {
164 if (theIndex == anbpoints) {
165 return pDS->Shape(aEE.IndexNew());
174 // ========================================================================================
175 // function: HasDomain
177 // ========================================================================================
178 Standard_Boolean QANewModTopOpe_Tools::HasSameDomain
179 (const BOPAlgo_PBuilder& theBuilder,
180 const TopoDS_Shape& theFace)
182 Standard_Integer bRet;
183 bRet = Standard_False;
185 if(theFace.IsNull() || (theFace.ShapeType() != TopAbs_FACE))
188 BOPCol_ListIteratorOfListOfShape aIt;
189 const BOPCol_DataMapOfShapeListOfShape& aImages = theBuilder->Images();
190 if (!aImages.IsBound(theFace)) {
193 const BOPCol_ListOfShape& aLF=aImages.Find(theFace);
195 if (aLF.Extent() == 0) {
198 const BOPCol_DataMapOfShapeShape& aShapesSD = theBuilder->ShapesSD();
201 for (; aIt.More(); aIt.Next()) {
202 const TopoDS_Shape& aFsp = aIt.Value();
203 if (aShapesSD.IsBound(aFsp)) {
204 bRet = Standard_True;
212 // ========================================================================================
213 // function: SameDomain
215 // ========================================================================================
216 void QANewModTopOpe_Tools::SameDomain
217 (const BOPAlgo_PBuilder& theBuilder,
218 const TopoDS_Shape& theFace,
219 TopTools_ListOfShape& theResultList)
221 theResultList.Clear();
223 if(theFace.IsNull() || (theFace.ShapeType() != TopAbs_FACE))
226 BOPCol_ListIteratorOfListOfShape aIt;
227 const BOPCol_ListOfShape& aLF=theBuilder->Splits().Find(theFace);
229 if (aLF.Extent() == 0) {
232 const BOPCol_DataMapOfShapeShape& aShapesSD = theBuilder->ShapesSD();
233 const BOPCol_DataMapOfShapeShape& aOrigins = theBuilder->Origins();
236 for (; aIt.More(); aIt.Next()) {
237 const TopoDS_Shape& aFSp = aIt.Value();
238 if (aShapesSD.IsBound(aFSp)) {
239 const TopoDS_Shape& aFSD = aShapesSD.Find(aFSp);
240 const TopoDS_Shape& aFOr = aOrigins.Find(aFSD);
241 if (theFace.IsEqual(aFOr)) {
242 BOPCol_DataMapIteratorOfDataMapOfShapeShape aItSD;
243 aItSD.Initialize(aShapesSD);
244 for (; aItSD.More(); aItSD.Next()) {
245 const TopoDS_Shape& aS = aItSD.Value();
246 if (aFSD.IsEqual(aS)) {
247 const TopoDS_Shape& aSK = aItSD.Key();
248 const TopoDS_Shape& aSKOr = aOrigins.Find(aSK);
249 if (!aSKOr.IsEqual(theFace)) {
250 theResultList.Append(aSKOr);
255 theResultList.Append(aFOr);
261 // ========================================================================================
264 // ========================================================================================
265 Standard_Boolean QANewModTopOpe_Tools::IsSplit(const BOPAlgo_PPaveFiller& theDSFiller,
266 const TopoDS_Shape& theEdge,
267 const TopAbs_State theState)
269 if(theEdge.IsNull() || (theEdge.ShapeType() != TopAbs_EDGE))
270 return Standard_False;
272 Standard_Integer index;
274 const BOPDS_PDS& pDS = theDSFiller->PDS();
275 index = pDS->Index(theEdge);
277 return Standard_False;
280 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(index);
281 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
282 aPBIt.Initialize(aLPB);
283 for (; aPBIt.More(); aPBIt.Next()) {
284 const Handle(BOPDS_PaveBlock)& aPB = aPBIt.Value();
286 TopAbs_State aSplitState = GetEdgeState(pDS, aPB);
288 if(aSplitState == theState) {
289 return Standard_True;
293 return Standard_False;
296 // ========================================================================================
299 // ========================================================================================
300 void QANewModTopOpe_Tools::Splits(const BOPAlgo_PPaveFiller& theDSFiller,
301 const TopoDS_Shape& theEdge,
302 const TopAbs_State theState,
303 TopTools_ListOfShape& theResultList)
305 theResultList.Clear();
307 if(theEdge.IsNull() || (theEdge.ShapeType() != TopAbs_EDGE))
310 Standard_Integer index, nSp;
312 const BOPDS_PDS& pDS = theDSFiller->PDS();
313 index = pDS->Index(theEdge);
318 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(index);
319 BOPDS_ListIteratorOfListOfPaveBlock aPBIt;
320 aPBIt.Initialize(aLPB);
321 for (; aPBIt.More(); aPBIt.Next()) {
322 const Handle(BOPDS_PaveBlock)& aPB = aPBIt.Value();
325 TopAbs_State aSplitState = GetEdgeState(pDS, aPB);
327 if(aSplitState == theState) {
328 TopoDS_Shape aSplit = pDS->Shape(nSp);
329 theResultList.Append(aSplit);
334 // ========================================================================================
337 // ========================================================================================
338 Standard_Boolean QANewModTopOpe_Tools::SplitE(const TopoDS_Edge& theEdge,
339 TopTools_ListOfShape& theSplits)
341 // prequesitory : <Eanc> is a valid edge.
342 TopAbs_Orientation oEanc = theEdge.Orientation();
343 TopoDS_Shape aLocalShape = theEdge.Oriented(TopAbs_FORWARD);
344 TopoDS_Edge EFOR = TopoDS::Edge(aLocalShape);
345 TopTools_ListOfShape aListOfVertex;
346 TopExp_Explorer exv(EFOR,TopAbs_VERTEX);
348 for (;exv.More(); exv.Next()) {
349 const TopoDS_Shape& v = exv.Current();
350 aListOfVertex.Append(v);
352 Standard_Integer nv = aListOfVertex.Extent();
354 if (nv <= 2) return Standard_False;
355 TopTools_ListOfShape aListOfVertexSorted;
357 SortVertexOnEdge(EFOR, aListOfVertex, aListOfVertexSorted);
360 TopTools_ListIteratorOfListOfShape anIt(aListOfVertexSorted);
363 v0 = TopoDS::Vertex(anIt.Value());
366 else return Standard_False;
368 for (; anIt.More(); anIt.Next()) {
369 TopoDS_Vertex v = TopoDS::Vertex(anIt.Value());
371 // prequesitory: par0 < par
372 Standard_Real par0 = BRep_Tool::Parameter(v0, EFOR);
373 Standard_Real par = BRep_Tool::Parameter(v, EFOR);
375 // here, ed has the same geometries than Ein, but with no subshapes.
376 TopoDS_Edge ed = TopoDS::Edge(EFOR.EmptyCopied());
378 v0.Orientation(TopAbs_FORWARD);
380 v.Orientation(TopAbs_REVERSED);
382 BB.Range(ed, par0, par);
384 theSplits.Append(ed.Oriented(oEanc));
387 return Standard_True;
391 // ========================================================================================
392 // function: EdgeCurveAncestors
394 // ========================================================================================
395 Standard_Boolean QANewModTopOpe_Tools::EdgeCurveAncestors(const BOPAlgo_PPaveFiller& theDSFiller,
396 const TopoDS_Shape& theEdge,
397 TopoDS_Shape& theFace1,
398 TopoDS_Shape& theFace2)
403 Standard_Integer i, j, aNb, aNbC, nE, nF1, nF2;
404 BOPDS_ListIteratorOfListOfPaveBlock aIt;
406 const BOPDS_PDS& pDS = theDSFiller->PDS();
407 BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF();
410 for (i = 0; i < aNb; ++i) {
411 BOPDS_InterfFF& aFF=aFFs(i);
413 const BOPDS_VectorOfCurve& aVC = aFF.Curves();
415 for (j = 0; j < aNbC; ++j) {
416 const BOPDS_Curve& aNC = aVC(j);
417 const BOPDS_ListOfPaveBlock& aLPB = aNC.PaveBlocks();
418 aIt.Initialize(aLPB);
419 for (; aIt.More(); aIt.Next()) {
420 const Handle(BOPDS_PaveBlock)& aPB = aIt.Value();
422 const TopoDS_Shape& aE = pDS->Shape(nE);
423 if (theEdge.IsSame(aE)) {
424 aFF.Indices(nF1, nF2);
425 theFace1 = pDS->Shape(nF1);
426 theFace2 = pDS->Shape(nF2);
427 return Standard_True;
433 return Standard_False;
436 // ========================================================================================
437 // function: EdgeSectionAncestors
439 // ========================================================================================
440 Standard_Boolean QANewModTopOpe_Tools::EdgeSectionAncestors(const BOPAlgo_PPaveFiller& theDSFiller,
441 const TopoDS_Shape& theEdge,
442 TopTools_ListOfShape& LF1,
443 TopTools_ListOfShape& LF2,
444 TopTools_ListOfShape& LE1,
445 TopTools_ListOfShape& LE2)
447 if(theEdge.ShapeType() != TopAbs_EDGE)
448 return Standard_False;
450 const BOPDS_PDS& pDS = theDSFiller->PDS();
451 Standard_Integer i = 0, nb = 0, nF, nE, nEOr;
452 BOPCol_MapOfInteger aMIF;
453 nb = pDS->NbSourceShapes();
455 nE = pDS->Index(theEdge);
456 const BOPDS_ListOfPaveBlock& aLPB1 = pDS->PaveBlocks(nE);
457 if (!aLPB1.Extent()) {
458 return Standard_False;
461 const Handle(BOPDS_PaveBlock)& aPB1 = aLPB1.First();
462 const Handle(BOPDS_CommonBlock)& aCB=pDS->CommonBlock(aPB1);
464 return Standard_False;
467 const BOPCol_ListOfInteger& aLIF = aCB->Faces();
468 BOPCol_ListIteratorOfListOfInteger aItLI;
469 aItLI.Initialize(aLIF);
470 for ( ; aItLI.More(); aItLI.Next()) {
472 if(pDS->Rank(nF) == 0)
473 LF1.Append(pDS->Shape(nF));
475 LF2.Append(pDS->Shape(nF));
480 const BOPDS_ListOfPaveBlock& aLPB = aCB->PaveBlocks();
481 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
482 aItPB.Initialize(aLPB);
483 for (; aItPB.More(); aItPB.Next()) {
484 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
485 nEOr = aPB->OriginalEdge();
487 if(pDS->Rank(nEOr) == 0)
488 LE1.Append(pDS->Shape(nEOr));
490 LE2.Append(pDS->Shape(nEOr));
492 //find edge ancestors
493 for(i = 0; i < nb; ++i) {
494 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(i);
495 if(aSI.ShapeType() != TopAbs_FACE) {
498 const BOPCol_ListOfInteger& aSubShapes = aSI.SubShapes();
499 aItLI.Initialize(aSubShapes);
500 for (; aItLI.More(); aItLI.Next()) {
501 if (nEOr == aItLI.Value()) {
503 if(pDS->Rank(i) == 0) LF1.Append(pDS->Shape(i));
504 else LF2.Append(pDS->Shape(i));
505 }//if (aMIF.Add(i)) {
506 }//if (nEOr == aItLI.Value()) {
507 }//for (; aItLI.More(); aItLI.Next()) {
508 }//for(i = 0; i < nb; ++i) {
511 Standard_Boolean r = (!LF1.IsEmpty() && !LF2.IsEmpty());
512 r = r && (!LE1.IsEmpty() || !LE2.IsEmpty());
516 // ========================================================================================
519 // ========================================================================================
520 Standard_Boolean QANewModTopOpe_Tools::BoolOpe(const TopoDS_Shape& theFace1,
521 const TopoDS_Shape& theFace2,
522 Standard_Boolean& IsCommonFound,
523 TopTools_IndexedDataMapOfShapeListOfShape& theHistoryMap)
525 IsCommonFound = Standard_False;
526 theHistoryMap.Clear();
528 Standard_Integer iSenseFlag;
530 BOPAlgo_PaveFiller aDSFiller;
531 BOPCol_ListOfShape aLS;
532 aLS.Append(theFace1);
533 aLS.Append(theFace2);
534 aDSFiller.SetArguments(aLS);
537 if (aDSFiller.ErrorStatus()) {
538 return Standard_False;
541 const BOPDS_PDS& pDS = aDSFiller.PDS();
543 Standard_Integer aNb = 0, aNbSps;
544 Standard_Integer i = 0;
545 TopTools_IndexedMapOfShape aMapV;
548 BRepAlgoAPI_Common aCommon(theFace1, theFace2, aDSFiller);
550 if(!aCommon.IsDone()) {
551 return Standard_False;
554 TopExp_Explorer anExp(aCommon.Shape(), TopAbs_FACE);
556 IsCommonFound = Standard_False;
557 return Standard_True;
560 IsCommonFound = Standard_True;
561 TopExp::MapShapes(aCommon.Shape(), TopAbs_VERTEX, aMapV);
562 // fill edge history.begin
563 FillEdgeHistoryMap(aCommon, theHistoryMap);
564 // fill edge history.end
566 // fill face history.begin
567 BOPDS_VectorOfInterfFF& aFFs = pDS->InterfFF();
569 Standard_Boolean bReverseFlag = Standard_True;
570 Standard_Boolean fillhistory = Standard_True;
572 for (i=0; i<aNb; ++i) {
573 BOPDS_InterfFF& aFF = aFFs(i);
574 Standard_Integer nF1, nF2;
575 aFF.Indices(nF1, nF2);
577 const TopoDS_Face& aF1 = *(TopoDS_Face*)(&pDS->Shape(nF1));
578 const TopoDS_Face& aF2 = *(TopoDS_Face*)(&pDS->Shape(nF2));
580 BOPCol_ListOfInteger aLSE;
581 pDS->SharedEdges(nF1, nF2, aLSE, aDSFiller.Allocator());
582 aNbSps = aLSE.Extent();
585 fillhistory = Standard_False;
589 Standard_Integer nE = aLSE.First();
590 const TopoDS_Edge& aSpE = *(TopoDS_Edge*)(&pDS->Shape(nE));
592 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aSpE, aF1, aDNF1);
593 BOPTools_AlgoTools3D::GetNormalToFaceOnEdge (aSpE, aF2, aDNF2);
594 iSenseFlag=BOPTools_AlgoTools3D::SenseFlag (aDNF1, aDNF2);
596 if(iSenseFlag == 1) {
597 fillhistory = Standard_True;
598 bReverseFlag = Standard_False;
600 else if(iSenseFlag == -1) {
601 fillhistory = Standard_True;
602 bReverseFlag = Standard_True;
605 fillhistory = Standard_False;
610 for(; anExp.More(); anExp.Next()) {
611 TopoDS_Shape aResShape = anExp.Current();
613 if(theFace1.Orientation() == aResShape.Orientation()) {
614 AddShapeToHistoryMap(theFace1, aResShape, theHistoryMap);
618 AddShapeToHistoryMap(theFace2, aResShape, theHistoryMap);
620 else if(theFace2.Orientation() == aResShape.Orientation()) {
621 AddShapeToHistoryMap(theFace2, aResShape, theHistoryMap);
625 AddShapeToHistoryMap(theFace1, aResShape, theHistoryMap);
628 aResShape.Orientation(theFace1.Orientation());
629 AddShapeToHistoryMap(theFace1, aResShape, theHistoryMap);
630 aResShape.Orientation(theFace2.Orientation());
634 AddShapeToHistoryMap(theFace2, aResShape, theHistoryMap);
638 // fill face history.end
641 BRepAlgoAPI_Cut aCut1(theFace1, theFace2, aDSFiller);
644 return Standard_False;
645 TopExp::MapShapes(aCut1.Shape(), TopAbs_VERTEX, aMapV);
646 // fill edge history.begin
647 FillEdgeHistoryMap(aCut1, theHistoryMap);
648 // fill edge history.end
650 // fill face history.begin
651 TopExp_Explorer anExp(aCut1.Shape(), TopAbs_FACE);
653 for(; anExp.More(); anExp.Next()) {
654 TopoDS_Shape aResShape = anExp.Current();
655 aResShape.Orientation(theFace1.Orientation());
656 AddShapeToHistoryMap(theFace1, aResShape, theHistoryMap);
658 // fill face history.end
662 BRepAlgoAPI_Cut aCut2(theFace1, theFace2, aDSFiller, Standard_False);
665 return Standard_False;
666 TopExp::MapShapes(aCut2.Shape(), TopAbs_VERTEX, aMapV);
667 // fill edge history.begin
668 FillEdgeHistoryMap(aCut2, theHistoryMap);
669 // fill edge history.end
671 // fill face history.begin
672 TopExp_Explorer anExp(aCut2.Shape(), TopAbs_FACE);
674 for(; anExp.More(); anExp.Next()) {
675 TopoDS_Shape aResShape = anExp.Current();
676 aResShape.Orientation(theFace2.Orientation());
677 AddShapeToHistoryMap(theFace2, aResShape, theHistoryMap);
679 // fill face history.end
682 // fill vertex history.begin
683 BOPDS_VectorOfInterfVV& aVVs = pDS->InterfVV();
686 for (i = 0; i < aNb; ++i) {
687 BOPDS_InterfVV& aVVi = aVVs(i);
688 if (!aVVi.HasIndexNew()) {
691 Standard_Integer aNewShapeIndex = aVVi.IndexNew();
693 const TopoDS_Shape& aNewVertex = pDS->Shape(aNewShapeIndex);
695 if(!aMapV.Contains(aNewVertex)) {
699 const TopoDS_Shape& aV1 = pDS->Shape(aVVi.Index1());
700 const TopoDS_Shape& aV2 = pDS->Shape(aVVi.Index2());
701 AddShapeToHistoryMap(aV1, aNewVertex, theHistoryMap);
702 AddShapeToHistoryMap(aV2, aNewVertex, theHistoryMap);
705 BOPDS_VectorOfInterfVE& aVEs = pDS->InterfVE();
708 for (i = 0; i < aNb; ++i) {
709 BOPDS_InterfVE& aVEi = aVEs(i);
711 Standard_Integer anIndex = aVEi.Index1();
712 const TopoDS_Shape& aNewVertex = pDS->Shape(anIndex);
714 if(!aMapV.Contains(aNewVertex))
717 AddShapeToHistoryMap(aNewVertex, aNewVertex, theHistoryMap);
720 BOPDS_VectorOfInterfVF& aVSs = pDS->InterfVF();
723 for (i = 0; i < aNb; ++i) {
724 BOPDS_InterfVF& aVSi = aVSs(i);
726 Standard_Integer anIndex = aVSi.Index1();
727 const TopoDS_Shape& aNewVertex = pDS->Shape(anIndex);
729 if(!aMapV.Contains(aNewVertex))
732 AddShapeToHistoryMap(aNewVertex, aNewVertex, theHistoryMap);
734 // fill vertex history.end
735 return Standard_True;
738 // --------------------------------------------------------------------------------------------
739 // static function: AddShapeToHistoryMap
741 // --------------------------------------------------------------------------------------------
742 Standard_Boolean AddShapeToHistoryMap(const TopoDS_Shape& theOldShape,
743 const TopoDS_Shape& theNewShape,
744 TopTools_IndexedDataMapOfShapeListOfShape& theHistoryMap) {
746 if(!theHistoryMap.Contains(theOldShape)) {
747 TopTools_ListOfShape aList;
748 aList.Append(theNewShape);
749 theHistoryMap.Add(theOldShape, aList);
750 return Standard_True;
753 Standard_Boolean found = Standard_False;
754 TopTools_ListOfShape& aList = theHistoryMap.ChangeFromKey(theOldShape);
755 TopTools_ListIteratorOfListOfShape aVIt(aList);
757 for(; aVIt.More(); aVIt.Next()) {
758 if(theNewShape.IsSame(aVIt.Value())) {
759 found = Standard_True;
765 aList.Append(theNewShape);
770 // --------------------------------------------------------------------------------------------
771 // static function: FillEdgeHistoryMap
773 // --------------------------------------------------------------------------------------------
774 void FillEdgeHistoryMap(BRepAlgoAPI_BooleanOperation& theBOP,
775 TopTools_IndexedDataMapOfShapeListOfShape& theHistoryMap) {
777 TopExp_Explorer anExp;
778 anExp.Init(theBOP.Shape1(), TopAbs_EDGE);
780 for(; anExp.More(); anExp.Next()) {
781 const TopTools_ListOfShape& aList = theBOP.Modified(anExp.Current());
782 TopTools_ListIteratorOfListOfShape anIt(aList);
784 for(; anIt.More(); anIt.Next()) {
785 AddShapeToHistoryMap(anExp.Current(), anIt.Value(), theHistoryMap);
789 anExp.Init(theBOP.Shape2(), TopAbs_EDGE);
791 for(; anExp.More(); anExp.Next()) {
792 const TopTools_ListOfShape& aList = theBOP.Modified(anExp.Current());
793 TopTools_ListIteratorOfListOfShape anIt(aList);
795 for(; anIt.More(); anIt.Next()) {
796 AddShapeToHistoryMap(anExp.Current(), anIt.Value(), theHistoryMap);
801 // --------------------------------------------------------------------------------------------
802 // static function: SortVertexOnEdge
804 // --------------------------------------------------------------------------------------------
805 void SortVertexOnEdge(const TopoDS_Edge& theEdge,
806 const TopTools_ListOfShape& theListOfVertex,
807 TopTools_ListOfShape& theListOfVertexSorted) {
809 TopTools_DataMapOfIntegerShape mapiv;// mapiv.Find(iV) = V
810 TColStd_IndexedMapOfReal mappar; // mappar.FindIndex(parV) = iV
811 TopTools_ListIteratorOfListOfShape itlove(theListOfVertex);
813 for (; itlove.More(); itlove.Next()){
814 const TopoDS_Vertex& v = TopoDS::Vertex(itlove.Value());
815 Standard_Real par = BRep_Tool::Parameter(v, theEdge);
816 Standard_Integer iv = mappar.Add(par);
819 Standard_Integer nv = mapiv.Extent();
820 NCollection_Array1<Standard_Real> tabpar(1,nv);
821 Standard_Integer i = 0;
823 for ( i = 1; i <= nv; i++) {
824 Standard_Real p = mappar.FindKey(i);
825 tabpar.SetValue(i,p);
827 theListOfVertexSorted.Clear();
828 std::sort (tabpar.begin(), tabpar.end());
830 for (i = 1; i <= nv; i++) {
831 Standard_Real par = tabpar.Value(i);
832 Standard_Integer iv = mappar.FindIndex(par);
833 const TopoDS_Shape& v = mapiv.Find(iv);
834 theListOfVertexSorted.Append(v);
838 // --------------------------------------------------------------------------------------------
839 // static function: GetEdgeState
841 // --------------------------------------------------------------------------------------------
842 static TopAbs_State GetEdgeState(const BOPDS_PDS& pDS,
843 const Handle(BOPDS_PaveBlock)& aPB)
845 Standard_Integer j, aNbFI;
846 Standard_Boolean bIn;
847 TopAbs_State aState = TopAbs_ON;
849 const BOPDS_VectorOfFaceInfo& aVFI = pDS->FaceInfoPool();
850 aNbFI = aVFI.Extent();
852 for (j = 0; j < aNbFI; ++j) {
853 const BOPDS_FaceInfo& aFI = aVFI(j);
854 bIn = aFI.PaveBlocksIn().Contains(aPB);