2 // IMPROVED by NIZNHY-PKV Thu Oct 12 16:03:33 2006
4 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License.
12 // This library is distributed in the hope that it will be useful
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Lesser General Public License for more details.
17 // You should have received a copy of the GNU Lesser General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: NMTTools_PaveFiller_6.cxx
24 // Created: Fri Dec 19 10:27:31 2003
25 // Author: Peter KURNEV
28 #include <NMTTools_PaveFiller.ixx>
30 #include <Precision.hxx>
32 #include <TColStd_IndexedMapOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
35 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
36 #include <TColStd_ListOfInteger.hxx>
37 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
38 #include <TColStd_ListIteratorOfListOfInteger.hxx>
40 #include <Geom_TrimmedCurve.hxx>
41 #include <Geom2d_TrimmedCurve.hxx>
42 #include <Geom2d_Curve.hxx>
43 #include <GeomAdaptor_Curve.hxx>
45 #include <BndLib_Add3dCurve.hxx>
47 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Compound.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <TopoDS_Edge.hxx>
55 #include <BRepLib.hxx>
56 #include <BRep_Builder.hxx>
57 #include <BRep_Tool.hxx>
58 #include <BRepBndLib.hxx>
60 #include <TopTools_IndexedMapOfShape.hxx>
61 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
62 #include <TopTools_ListOfShape.hxx>
63 #include <TopTools_ListIteratorOfListOfShape.hxx>
65 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
66 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
68 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
69 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
70 #include <BooleanOperations_OnceExplorer.hxx>
71 #include <BooleanOperations_ShapesDataStructure.hxx>
73 #include <IntTools_SequenceOfPntOn2Faces.hxx>
74 #include <IntTools_SequenceOfCurves.hxx>
75 #include <IntTools_FaceFace.hxx>
76 #include <IntTools_Tools.hxx>
77 #include <IntTools_ShrunkRange.hxx>
79 #include <BOPTools_CArray1OfSSInterference.hxx>
81 #include <BOPTools_SSInterference.hxx>
82 #include <BOPTools_ListOfPaveBlock.hxx>
83 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
84 #include <BOPTools_PaveBlock.hxx>
85 #include <BOPTools_ListIteratorOfListOfPave.hxx>
86 #include <BOPTools_Tools.hxx>
87 #include <BOPTools_PaveBlockIterator.hxx>
88 #include <BOPTools_Tools2D.hxx>
90 #include <NMTDS_Iterator.hxx>
91 #include <NMTDS_ShapesDataStructure.hxx>
92 #include <NMTDS_InterfPool.hxx>
94 #include <NMTTools_Tools.hxx>
95 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
96 #include <NMTTools_CommonBlockAPI.hxx>
97 #include <NMTTools_DataMapOfIntegerListOfPaveBlock.hxx>
98 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
100 #include <NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock.hxx>
101 #include <NMTTools_MapOfPaveBlock.hxx>
104 void SharedEdges1(const TopoDS_Face& aF1,
105 const TopoDS_Face& aF2,
106 TopTools_ListOfShape& aLS);
108 Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
109 IntTools_Context& aCtx);
111 //=======================================================================
112 // function: PerformFF
114 //=======================================================================
115 void NMTTools_PaveFiller::PerformFF()
117 myIsDone=Standard_False;
119 Standard_Boolean bJustAdd;//, bIsComputed, bIsFound;
120 Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
121 Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
122 Standard_Integer aNbCurves, aNbPoints;
123 Standard_Real anApproxTol, aTolR3D, aTolR2D;
124 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
125 IntTools_SequenceOfPntOn2Faces aPnts;
126 IntTools_SequenceOfCurves aCvs;
127 BooleanOperations_KindOfInterference aTypeFF=BooleanOperations_SurfaceSurface;
129 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
131 // F/F Interferences [BooleanOperations_SurfaceSurface]
132 myDSIt->Initialize(TopAbs_FACE, TopAbs_FACE);
134 // BlockLength correction
135 aNbFFs=myDSIt->BlockLength();
136 aBlockLength=aFFs.BlockLength();
137 if (aNbFFs > aBlockLength) {
138 aFFs.SetBlockLength(aNbFFs);
141 for (; myDSIt->More(); myDSIt->Next()) {
142 myDSIt->Current(n1, n2, bJustAdd);
154 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
155 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
158 bToApproxC3d = mySectionAttribute.Approximation();
159 bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
160 bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
164 IntTools_FaceFace aFF;
166 aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1,
167 bToApproxC2dOnS2, anApproxTol);
169 aFF.Perform(aF1, aF2);
171 bIsDone=aFF.IsDone();
177 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
180 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
181 anIndexIn=aFFs.Append(anInterf);
182 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
188 aTolR3D=aFF.TolReached3d();
189 aTolR2D=aFF.TolReached2d();
190 if (aTolR3D < 1.e-7){
194 aFF.PrepareLines3D();
196 const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
197 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
199 aNbCurves=aCvsX.Length();
200 aNbPoints=aPntsX.Length();
202 if (!aNbCurves && !aNbPoints) {
203 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
204 anIndexIn=aFFs.Append(anInterf);
209 BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
210 anIndexIn=aFFs.Append(anInterf);
213 }// for (; myDSIt.More(); myDSIt.Next())
215 myIsDone=Standard_True;
217 //=======================================================================
218 // function: MakeBlocks
220 //=======================================================================
221 void NMTTools_PaveFiller::MakeBlocks()
223 myIsDone=Standard_False;
225 Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D, bIsCoincided;
226 Standard_Boolean bIsMicroEdge, bHasES;
227 Standard_Integer i, aNbFFs, nF1, nF2, aBid=0;
228 Standard_Integer nV1, nV2, j, aNbCurves;
229 Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
230 NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
231 BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
232 BOPTools_ListIteratorOfListOfPaveBlock anIt;
234 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
236 aNbFFs=aFFs.Extent();
238 NMTTools_DataMapOfIntegerListOfPaveBlock aMFInOn;
239 NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock aItMF;
242 Standard_Integer aNbS, aNbF, nF, aNbOn, nSp;
243 TopAbs_ShapeEnum aType;
244 BOPTools_ListIteratorOfListOfPaveBlock anItPB;
245 NMTTools_ListIteratorOfListOfCommonBlock aItCB;
246 TColStd_ListIteratorOfListOfInteger aItF;
248 aNbS=myDS->NumberOfShapesOfTheObject();
249 for (i=1; i<=aNbS; ++i) {
250 const TopoDS_Shape& aS=myDS->Shape(i);
251 aType=aS.ShapeType();
253 if (aType==TopAbs_EDGE) {
254 const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
255 aItCB.Initialize(aLCB);
256 for (; aItCB.More(); aItCB.Next()) {
257 const NMTTools_CommonBlock& aCB=aItCB.Value();
258 const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
260 const TColStd_ListOfInteger& aLF=aCB.Faces();
263 aItF.Initialize(aLF);
264 for (; aItF.More(); aItF.Next()) {
266 if (aMFInOn.IsBound(nF)) {
267 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
271 BOPTools_ListOfPaveBlock aLPB;
273 aMFInOn.Bind(nF, aLPB);
277 } // for (; aItCB.More(); aItCB.Next()) {
278 }//if (aS.ShapeType()==TopAbs_EDGE) {
280 else if (aType==TopAbs_FACE) {
281 BOPTools_ListOfPaveBlock aLPBOn;
284 RealSplitsFace(nF, aLPBOn);
286 aNbOn=aLPBOn.Extent();
288 if (aMFInOn.IsBound(nF)) {
289 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
293 aMFInOn.Bind(nF, aLPBOn);
297 } // for (i=1; i<=aNbS; ++i) {
299 // Refine ListOfPaveBlocks
300 aItMF.Initialize(aMFInOn);
301 for(; aItMF.More(); aItMF.Next()) {
302 TColStd_MapOfInteger aMTmp;
303 BOPTools_ListOfPaveBlock aLPBX;
306 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
307 anItPB.Initialize(aLPB);
308 for (; anItPB.More(); anItPB.Next()) {
309 const BOPTools_PaveBlock& aPB=anItPB.Value();
311 if (aMTmp.Add(nSp)) {
321 // 1. Produce Section Edges from intersection curves
322 // between each pair of faces
323 aNbFFs=aFFs.Extent();
325 for (i=1; i<=aNbFFs; ++i) {
326 BOPTools_SSInterference& aFFi=aFFs(i);
329 aFFi.Indices(nF1, nF2);
330 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
331 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
333 BOPTools_ListOfPaveBlock aLPB;
337 BOPTools_ListIteratorOfListOfPaveBlock anItPB;
338 NMTTools_MapOfPaveBlock aMPB;
340 if (aMFInOn.IsBound(nF1)) {
341 const BOPTools_ListOfPaveBlock& aLPBF1=aMFInOn.Find(nF1);
342 anItPB.Initialize(aLPBF1);
343 for (; anItPB.More(); anItPB.Next()) {
344 const BOPTools_PaveBlock& aPB=anItPB.Value();
350 if (aMFInOn.IsBound(nF2)) {
351 const BOPTools_ListOfPaveBlock& aLPBF2=aMFInOn.Find(nF2);
352 anItPB.Initialize(aLPBF2);
353 for (; anItPB.More(); anItPB.Next()) {
354 const BOPTools_PaveBlock& aPB=anItPB.Value();
355 if (aMPB.Contains(aPB)) {
356 aFFi.AppendBlock(aPB);
366 TopTools_ListOfShape aLSE;
367 TColStd_ListOfInteger aLNE;
368 SharedEdges(nF1, nF2, aLNE, aLSE);
369 aFFi.SetSharedEdges(aLNE);
371 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
372 aNbCurves=aSCvs.Length();
377 // Contribution of Samtech www.samcef.com END
378 aTolR3D=aFFi.TolR3D();
379 aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
381 BOPTools_PaveSet aPSF;
383 PrepareSetForFace (nF1, nF2, aLPB, aPSF);
385 // Put Paves On Curves
386 for (j=1; j<=aNbCurves; ++j) {
387 BOPTools_Curve& aBC=aSCvs(j);
389 const IntTools_Curve& aC=aBC.Curve();
390 Handle (Geom_Curve) aC3D= aC.Curve();
392 PutPaveOnCurve (aPSF, aTolR3D, aBC);
395 // Put bounding paves on curves
396 for (j=1; j<=aNbCurves; ++j) {
397 BOPTools_Curve& aBC=aSCvs(j);
398 PutBoundPaveOnCurve (aBC, aFFi);
401 // Pave Blocks on Curves
402 bHasES=Standard_False;
403 for (j=1; j<=aNbCurves; ++j) {
404 BOPTools_Curve& aBC=aSCvs(j);
405 const IntTools_Curve& aIC= aBC.Curve();
406 BOPTools_PaveSet& aPaveSet=aBC.Set();
408 BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
409 for (; aPBIter.More(); aPBIter.Next()) {
410 BOPTools_PaveBlock& aPBNew=aPBIter.Value();
411 aPBNew.SetCurve(aIC);
412 aPBNew.SetFace1(nF1);
413 aPBNew.SetFace2(nF2);
415 nV1=aPBNew.Pave1().Index();
416 nV2=aPBNew.Pave2().Index();
417 aT1=aPBNew.Pave1().Param();
418 aT2=aPBNew.Pave2().Param();
420 if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
421 continue;// mkk ft ???
425 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPB, aTolR3D);
426 if (bIsExistingPaveBlock) {
430 bIsCoincided=CheckCoincidence(aPBNew, aLPB);
436 // to provide checking whether aPBNew already exists in list
437 // of section edges aLSE
438 // Thu Sep 14 14:35:18 2006
439 // Contribution of Samtech www.samcef.com BEGIN
441 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLSE, aTolR3D);
442 if (bIsExistingPaveBlock) {
445 // Contribution of Samtech www.samcef.com END
447 // Checking of validity in 2D
449 bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
458 const TopoDS_Vertex aV1=TopoDS::Vertex(myDS->Shape(nV1));//mpv
459 const TopoDS_Vertex aV2=TopoDS::Vertex(myDS->Shape(nV2));//mpv
461 BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
463 NMTTools_Tools::UpdateEdge (aES, aTolR3D);
464 bIsMicroEdge=IsMicroEdge(aES, myContext);
471 Handle(Geom2d_Curve) aC2D1, aC2D2;
473 aC2D1=aIC.FirstCurve2d();
474 aC2D2=aIC.SecondCurve2d();
476 NMTTools_Tools::MakePCurve(aES, aF1, aC2D1);
477 NMTTools_Tools::MakePCurve(aES, aF2, aC2D2);
480 aMEPB.Add(aES, aPBNew);
483 bHasES=Standard_True;
484 }// for (; aPBIter.More(); aPBIter.Next())
485 } // end of for (j=1; j<=aNbCurves; ++j)
488 myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF);
491 }// for (i=1; i<=aNbFFs; ++i)
492 //=============================================================
494 // II. Post treatment
496 // Input data: aMEPB, aMapEI
497 // Result : section edges in myDS
499 Standard_Integer aNbSE;
501 aNbSE=aMEPB.Extent();
503 // there is nothing to do here
508 TopoDS_Compound aCompound;
510 // 1. Make compound from SE
511 aBB.MakeCompound(aCompound);
512 for (i=1; i<=aNbSE; ++i) {
513 const TopoDS_Shape& aSE=aMEPB.FindKey(i);
514 aBB.Add(aCompound, aSE);
518 // 2. Intersect SE using auxiliary Filler
519 NMTTools_PaveFiller tPF;
521 tPF.SetCompositeShape(aCompound);
526 //tPF.PerformNewVertices(); qq
529 tPF.myPavePool.Resize (tPF.myNbEdges);
537 tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
538 tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
539 tPF.myPavePoolNew .Resize (tPF.myNbEdges);
541 tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
542 tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
546 tPF.RefinePavePool ();
548 tPF.myPavePoolNew.Destroy();
550 tPF.MakeSplitEdges();
551 tPF.UpdateCommonBlocks();
553 // 3. Treatment of the result of intersection
555 Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
556 TopAbs_ShapeEnum aType;
557 BOPTools_ListIteratorOfListOfPaveBlock aIt;
558 BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
560 const NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
561 const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
562 const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
564 aNbLines=tDS.NumberOfInsertedShapes();
565 aNbOld=tDS.NumberOfShapesOfTheObject();
567 // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
569 // 3.1.1.Old vertices [ links ]
570 for (i=1; i<=aNbOld; ++i) {
571 const TopoDS_Shape& aV=tDS.Shape(i);
572 aType=aV.ShapeType();
573 if (aType!=TopAbs_VERTEX) {
577 for (j=1; j<=aNbSE; ++j) {
578 const BOPTools_PaveBlock& aPBSE=aMEPB(j);
579 nV1=aPBSE.Pave1().Index();
580 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
581 if (aV1.IsSame(aV)) {
582 aMNewOld.Add(i, nV1);
585 nV2=aPBSE.Pave2().Index();
586 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
587 if (aV2.IsSame(aV)) {
588 aMNewOld.Add(i, nV2);
594 // 3.1.2. New vertices [ links ]
595 i=tDS.NumberOfSourceShapes()+1;
596 for (; i<=aNbLines; ++i) {
597 const TopoDS_Shape& aV=tDS.Shape(i);
598 aType=aV.ShapeType();
599 if (aType!=TopAbs_VERTEX) {
603 // Insert new vertex in myDS
604 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
605 myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
606 nV1=myDS->NumberOfInsertedShapes();
608 aMNewOld.Add(i, nV1);
611 // 3.2. Treatment of section edges (SE)
612 for (i=1; i<=aNbOld; ++i) {
613 const TopoDS_Shape& aE=tDS.Shape(i);
614 aType=aE.ShapeType();
615 if (aType!=TopAbs_EDGE) {
619 // block of section edge that we already have for this SE
620 BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
622 // Corresponding FF-interference
623 iFF=aMapEI.FindFromKey(aE);
624 BOPTools_SSInterference& aFFi=aFFs(iFF);
625 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
627 BOPTools_Curve& aBC=aSCvs(1);
629 const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
633 // no pave blocks -> use aPBSE and whole edge aE
634 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
636 nV1=aPBSE.Pave1().Index();
637 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
638 nV2=aPBSE.Pave2().Index();
639 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
641 anASSeq.SetNewSuccessor(nV1);
642 anASSeq.SetNewOrientation(aV1.Orientation());
643 anASSeq.SetNewSuccessor(nV2);
644 anASSeq.SetNewOrientation(aV2.Orientation());
646 myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
647 nE=myDS->NumberOfInsertedShapes();
650 aBC.AppendNewBlock(aPBSE);
658 const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
659 NMTTools_CommonBlockAPI aCBAPI(aLCB);
661 aIt.Initialize(aLPB);
662 for (; aIt.More(); aIt.Next()) {
663 BOPTools_PaveBlock aPB=aIt.Value();
665 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));
666 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));
668 if (aCBAPI.IsCommonBlock(aPB)) {
669 // it can be Common Block
670 Standard_Real aTolEx;
671 Handle(Geom2d_Curve) aC2D1, aC2D2;
672 TopoDS_Face aF1FWD, aF2FWD;
674 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
675 const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
677 aPB=aCB.PaveBlock1();
678 mE=aPB.Edge(); // index of edge in tDS
679 const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
680 aTolEx=BRep_Tool::Tolerance(aEx);
683 aF1FWD.Orientation(TopAbs_FORWARD);
685 aF2FWD.Orientation(TopAbs_FORWARD);
687 NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1);
688 NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2);
689 NMTTools_Tools::UpdateEdge (aEx, aTolEx);
690 } //if (aCBAPI.IsCommonBlock(aPB))
693 mE=aPB.Edge(); // index of edge in tDS
694 const TopoDS_Shape& aSp=tDS.Shape(mE);
696 const BOPTools_Pave& aPave1=aPB.Pave1();
698 mV1=aPave1.Index(); // index in tDS
699 nV1=aMNewOld.FindFromKey(mV1); // index in myDS
700 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
702 const BOPTools_Pave& aPave2=aPB.Pave2();
705 nV2=aMNewOld.FindFromKey(mV2);
706 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
708 if (!aMNewOld.Contains(mE)) {
709 // add new SE to the myDS
710 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
712 anASSeq.SetNewSuccessor(nV1);
713 anASSeq.SetNewOrientation(aV1.Orientation());
715 anASSeq.SetNewSuccessor(nV2);
716 anASSeq.SetNewOrientation(aV2.Orientation());
718 myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
719 nE=myDS->NumberOfInsertedShapes();
721 aMNewOld.Add(mE, nE);
724 nE=aMNewOld.FindFromKey(mE);
727 BOPTools_PaveBlock aPBx;
728 BOPTools_Pave aP1, aP2;
744 aBC.AppendNewBlock(aPBx);
745 }// for (; aIt.More(); aIt.Next())
746 }// for (i=1; i<=aNbOld; ++i)
748 myIsDone=Standard_True;
750 //=======================================================================
751 // function: MakePCurves
753 //=======================================================================
754 void NMTTools_PaveFiller::MakePCurves()
756 Standard_Integer i, aNb, nF1, nF2, nE;
757 Standard_Integer aNbCB, aNbF, nSp, nF;
758 TopAbs_ShapeEnum aType;
759 TopoDS_Face aF1FWD, aF2FWD;
760 TColStd_ListIteratorOfListOfInteger aItF;
761 BOPTools_ListIteratorOfListOfPaveBlock anIt;
762 NMTTools_ListIteratorOfListOfCommonBlock aItCB;
764 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
767 for (i=1; i<=aNb; i++) {
768 BOPTools_SSInterference& aFF=aFFs(i);
769 aFF.Indices(nF1, nF2);
771 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
772 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
775 aF1FWD.Orientation(TopAbs_FORWARD);
777 aF2FWD.Orientation(TopAbs_FORWARD);
779 // In, On parts processing
780 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
782 anIt.Initialize(aLPBInOn);
783 for (; anIt.More(); anIt.Next()) {
784 const BOPTools_PaveBlock& aPB=anIt.Value();
786 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
788 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
789 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
792 // Check common blocks between edges and faces
793 // Build P-Curves if they were not built in previos block.
795 // The main case is :arguments for e.g aEdge, aFace -> no FFs,
796 // but p-curves are needed.
798 aNb=myDS->NumberOfShapesOfTheObject();
799 for (i=1; i<=aNb; ++i) {
800 const TopoDS_Shape& aS=myDS->Shape(i);
801 aType=aS.ShapeType();
803 if (aType!=TopAbs_EDGE) {
806 const TopoDS_Edge& aE=TopoDS::Edge(aS);
808 if (BRep_Tool::Degenerated(aE)) {
812 const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
818 aItCB.Initialize(aLCB);
819 for (; aItCB.More(); aItCB.Next()) {
820 const NMTTools_CommonBlock& aCB=aItCB.Value();
821 const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
823 const TColStd_ListOfInteger& aLF=aCB.Faces();
830 const TopoDS_Edge aSp=TopoDS::Edge(myDS->Shape(nSp));//mpv
832 aItF.Initialize(aLF);
833 for (; aItF.More(); aItF.Next()) {
835 aF1FWD=TopoDS::Face(myDS->Shape(nF));
836 aF1FWD.Orientation(TopAbs_FORWARD);
838 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aSp, aF1FWD);
839 } // for (; aItCB.More(); aItCB.Next()) {
840 }//if (aS.ShapeType()==TopAbs_EDGE) {
843 //=======================================================================
844 // function: IsExistingPaveBlock
846 //=======================================================================
847 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
848 const BOPTools_ListOfPaveBlock& aLPBR,
849 const Standard_Real aTolR3D)
851 Standard_Boolean bFlag;
852 Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
853 BOPTools_ListIteratorOfListOfPaveBlock anIt;
855 bFlag=Standard_False;
856 nVNew1=aPBNew.Pave1().Index();
857 nVNew2=aPBNew.Pave2().Index();
859 anIt.Initialize(aLPBR);
860 for (; anIt.More(); anIt.Next()) {
861 const BOPTools_PaveBlock& aPBR=anIt.Value();
862 nV1=aPBR.Pave1().Index();
863 nV2=aPBR.Pave2().Index();
864 if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
866 iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
874 //=======================================================================
875 // function: IsExistingPaveBlock
877 //=======================================================================
878 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
879 const TopTools_ListOfShape& aLSE,
880 const Standard_Real aTolR3D)
882 Standard_Boolean bFlag;
883 Standard_Integer aNbSE, iC;
884 Standard_Real aTolE, aTol;
885 TopTools_ListIteratorOfListOfShape anIt;
887 bFlag=Standard_False;
894 anIt.Initialize(aLSE);
895 for (; anIt.More(); anIt.Next()) {
896 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
897 //modified by NIZNHY-PKV Mon Nov 17 09:54:43 2008f //0019974
898 aTolE=BRep_Tool::Tolerance(aE);
903 iC=CheckIntermediatePoint(aPBNew, aE, aTol);
904 //iC=CheckIntermediatePoint(aPBNew, aE, aTolR3D);
905 //modified by NIZNHY-PKV Mon Nov 17 09:54:45 2008t
912 //=======================================================================
913 // function: CheckIntermediatePoint
915 //=======================================================================
916 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
917 const BOPTools_PaveBlock& aPBR,
918 const Standard_Real aTolC)
921 Standard_Integer iVM, nE2;
924 const TopoDS_Edge aE2=TopoDS::Edge(myDS->Shape(nE2));//mpv
925 iVM=CheckIntermediatePoint(aPB, aE2, aTolC);
929 //=======================================================================
930 // function: CheckIntermediatePoint
932 //=======================================================================
933 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
934 const TopoDS_Edge& aE2,
935 const Standard_Real aTolC)
937 Standard_Real aT11, aT12, aTM, aTmp;
938 Standard_Integer iVM;
944 const BOPTools_Pave& aPave11=aPB.Pave1();
945 aT11=aPave11.Param();
947 const BOPTools_Pave& aPave12=aPB.Pave2();
948 aT12=aPave12.Param();
950 aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
952 const IntTools_Curve& aIC=aPB.Curve();
955 aBB.MakeVertex (aVM, aPM, aTolC);
957 iVM=myContext.ComputeVE(aVM, aE2, aTmp);
961 //=======================================================================
962 // function: PutBoundPaveOnCurve
964 //=======================================================================
965 void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
966 BOPTools_SSInterference& aFFi)
968 Standard_Boolean bHasBounds, bVF;
969 Standard_Integer nF1, nF2;
970 Standard_Real aT1, aT2, aTolR3D;
973 const IntTools_Curve& aIC=aBC.Curve();
974 bHasBounds=aIC.HasBounds ();
980 aIC.Bounds (aT1, aT2, aP1, aP2);
983 aFFi.Indices(nF1, nF2);
984 aTolR3D=aFFi.TolR3D();
986 const TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));//mpv
987 const TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));//mpv
989 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
991 PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
994 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
996 PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
999 //=======================================================================
1000 // function: PutBoundPaveOnCurve
1002 //=======================================================================
1003 void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
1004 const Standard_Real aT,
1005 BOPTools_Curve& aBC,
1006 BOPTools_SSInterference& aFFi)
1008 Standard_Boolean bFound1, bFound2;
1009 Standard_Integer nV;
1010 Standard_Real aTolV=aFFi.TolR3D();
1012 BOPTools_Pave aPave1, aPave2, aPave;
1013 BOPTools_PaveSet& aCPS=aBC.Set();
1014 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
1015 const IntTools_Curve& aIC=aBC.Curve();
1017 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
1018 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
1020 if (!bFound1 && !bFound2) {
1021 TopoDS_Vertex aNewVertex;
1022 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
1024 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
1025 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
1026 nV=myDS->NumberOfInsertedShapes();
1031 aFFiPS.Append(aPave);
1033 // Append Techno Vertex to the Curve
1034 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
1037 if (bFound1 && !bFound2) {
1041 aFFiPS.Append(aPave);
1043 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1044 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1047 if (!bFound1 && bFound2) {
1053 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1054 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1057 //=======================================================================
1058 // function: FindPave
1060 //=======================================================================
1061 Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
1062 const Standard_Real aTolPV,
1063 const BOPTools_PaveSet& aPS,
1064 BOPTools_Pave& aPave)
1066 Standard_Integer nV;
1067 Standard_Boolean bIsVertex=Standard_False;
1069 const BOPTools_ListOfPave& aLP=aPS.Set();
1070 BOPTools_ListIteratorOfListOfPave anIt(aLP);
1071 for (; anIt.More(); anIt.Next()) {
1072 const BOPTools_Pave& aPC=anIt.Value();
1074 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1075 bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
1083 //=======================================================================
1084 // function: PrepareSetForFace
1086 //=======================================================================
1087 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer ,//nF1,
1088 const Standard_Integer ,//nF2,
1089 const BOPTools_ListOfPaveBlock& aLPBC,
1090 BOPTools_PaveSet& aPSF)
1092 Standard_Integer nV1, nV2;
1093 TColStd_MapOfInteger aMap;
1094 BOPTools_ListIteratorOfListOfPaveBlock anIt;
1096 anIt.Initialize(aLPBC);
1097 for (; anIt.More(); anIt.Next()) {
1098 const BOPTools_PaveBlock& aPB=anIt.Value();
1099 const BOPTools_Pave& aPave1=aPB.Pave1();
1101 if (!aMap.Contains(nV1)) {
1103 aPSF.Append(aPave1);
1105 const BOPTools_Pave& aPave2=aPB.Pave2();
1107 if (!aMap.Contains(nV2)) {
1109 aPSF.Append(aPave2);
1113 //=======================================================================
1114 // function: PutPaveOnCurve
1116 //=======================================================================
1117 void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
1118 const Standard_Real aTolR3D,
1119 BOPTools_Curve& aBC)
1121 Standard_Integer nV;
1122 Standard_Boolean bIsVertexOnLine;
1124 BOPTools_ListIteratorOfListOfPave anIt;
1126 GeomAdaptor_Curve aGAC;
1128 const IntTools_Curve& aC=aBC.Curve();
1129 Handle (Geom_Curve) aC3D= aC.Curve();
1131 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
1133 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1134 anIt.Initialize(aLP);
1135 for (; anIt.More(); anIt.Next()) {
1136 const BOPTools_Pave& aPave=anIt.Value();
1139 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1142 BRepBndLib::Add(aV, aBBV);
1143 if (aBBC.IsOut(aBBV)){
1147 bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
1149 if (bIsVertexOnLine) {
1150 BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1151 BOPTools_PaveSet& aPS=aBC.Set();
1152 aPS.Append(aPaveNew);
1154 BOPTools_Tools::UpdateVertex (aC, aT, aV);
1161 //=======================================================================
1162 //function : SharedEdges1
1164 //=======================================================================
1165 void SharedEdges1(const TopoDS_Face& aF1,
1166 const TopoDS_Face& aF2,
1167 TopTools_ListOfShape& aLS)
1169 Standard_Integer i, aNbE, aNbF;;
1170 TopTools_IndexedDataMapOfShapeListOfShape aMEF;
1172 TopExp::MapShapesAndAncestors(aF1, TopAbs_EDGE, TopAbs_FACE, aMEF);
1173 TopExp::MapShapesAndAncestors(aF2, TopAbs_EDGE, TopAbs_FACE, aMEF);
1176 for (i=1; i<=aNbE; ++i) {
1177 const TopTools_ListOfShape& aLF=aMEF.FindFromIndex(i);
1181 const TopoDS_Shape& aF1x=aLF.First();
1182 const TopoDS_Shape& aF2x=aLF.Last();
1183 if (aF1x.IsSame(aF2x)) {
1187 const TopoDS_Shape& aE=aMEF.FindKey(i);
1193 //=======================================================================
1194 // function: CheckCoincidence
1196 //=======================================================================
1197 Standard_Boolean NMTTools_PaveFiller::CheckCoincidence(const BOPTools_PaveBlock& aPBNew,
1198 const BOPTools_ListOfPaveBlock& aLPBFF)
1201 Standard_Boolean bRet;
1203 Standard_Integer nV11, nV12, nV21, nV22, iVV, iVE, nE2;
1204 Standard_Integer iV, iCount, iCountExt;
1205 BOPTools_ListIteratorOfListOfPaveBlock anIt;
1207 const BOPTools_Pave& aPave11=aPBNew.Pave1();
1208 nV11=aPave11.Index();
1209 const TopoDS_Vertex& aV11=TopoDS::Vertex(myDS->Shape(nV11));
1212 const BOPTools_Pave& aPave12=aPBNew.Pave2();
1213 nV12=aPave12.Index();
1214 const TopoDS_Vertex& aV12=TopoDS::Vertex(myDS->Shape(nV12));
1218 anIt.Initialize(aLPBFF);
1219 for (; anIt.More(); anIt.Next()) {
1222 const BOPTools_PaveBlock& aPBR=anIt.Value();
1224 const BOPTools_Pave& aPave21=aPBR.Pave1();
1225 nV21=aPave21.Index();
1228 const BOPTools_Pave& aPave22=aPBR.Pave2();
1229 nV22=aPave22.Index();
1231 if (nV11==nV21 || nV11==nV22 || nV12==nV21 || nV12==nV22) {
1238 const TopoDS_Vertex& aV21=TopoDS::Vertex(myDS->Shape(nV21));
1239 const TopoDS_Vertex& aV22=TopoDS::Vertex(myDS->Shape(nV22));
1240 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->Shape(nE2));
1244 iVV=IntTools_Tools::ComputeVV (aV11, aV21);
1248 if (iCount>iCountExt) {
1253 iVV=IntTools_Tools::ComputeVV (aV11, aV22);
1257 if (iCount>iCountExt) {
1263 iVE=myContext.ComputeVE (aV11, aE2, aTE);
1266 if (iCount>iCountExt) {
1273 iVV=IntTools_Tools::ComputeVV (aV12, aV21);
1277 if (iCount>iCountExt) {
1282 iVV=IntTools_Tools::ComputeVV (aV12, aV22);
1286 if (iCount>iCountExt) {
1292 iVE=myContext.ComputeVE (aV12, aE2, aTE);
1295 if (iCount>iCountExt) {
1301 bRet=(Standard_Boolean)(iCount>iCountExt);
1305 //=======================================================================
1306 //function : IsMicroEdge
1308 //=======================================================================
1309 Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
1310 IntTools_Context& aCtx)
1312 Standard_Boolean bRet;
1313 Standard_Integer iErr;
1314 Standard_Real aT1, aT2, aTmp;
1315 Handle(Geom_Curve) aC3D;
1316 TopoDS_Vertex aV1, aV2;
1319 bRet=(BRep_Tool::Degenerated(aE) ||
1320 !BRep_Tool::IsGeometric(aE));
1325 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1326 TopExp::Vertices(aE, aV1, aV2);
1327 aT1=BRep_Tool::Parameter(aV1, aE);
1328 aT2=BRep_Tool::Parameter(aV2, aE);
1337 IntTools_ShrunkRange aSR (aE, aV1, aV2, aR, aCtx);
1338 iErr=aSR.ErrorStatus();