Back to index

salome-geom  6.5.0
NMTTools_PaveFiller_6.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File:        NMTTools_PaveFiller_6.cxx
00023 //  Created:     Fri Dec 19 10:27:31 2003
00024 //  Author:      Peter KURNEV
00025 
00026 #include <NMTTools_PaveFiller.hxx>
00027 
00028 #include <Basics_OCCTVersion.hxx>
00029 
00030 #include <Precision.hxx>
00031 
00032 #include <TColStd_IndexedMapOfInteger.hxx>
00033 #include <TColStd_MapOfInteger.hxx>
00034 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
00035 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
00036 #include <TColStd_ListOfInteger.hxx>
00037 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00038 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
00039 
00040 
00041 #include <Geom_TrimmedCurve.hxx>
00042 #include <Geom2d_TrimmedCurve.hxx>
00043 #include <Geom2d_Curve.hxx>
00044 #include <GeomAdaptor_Curve.hxx>
00045 #include <GeomAdaptor_Surface.hxx>
00046 #include <Geom_Surface.hxx>
00047 
00048 #include <BndLib_Add3dCurve.hxx>
00049 
00050 #include <TopoDS_Face.hxx>
00051 #include <TopoDS.hxx>
00052 #include <TopoDS_Compound.hxx>
00053 #include <TopoDS_Vertex.hxx>
00054 #include <TopoDS_Edge.hxx>
00055 
00056 #include <TopExp.hxx>
00057 
00058 #include <BRepLib.hxx>
00059 #include <BRep_Builder.hxx>
00060 #include <BRep_Tool.hxx>
00061 #include <BRepBndLib.hxx>
00062 
00063 #include <TopTools_IndexedMapOfShape.hxx>
00064 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00065 #include <TopTools_ListOfShape.hxx>
00066 #include <TopTools_ListIteratorOfListOfShape.hxx>
00067 
00068 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
00069 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
00070 
00071 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
00072 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
00073 #include <BooleanOperations_OnceExplorer.hxx>
00074 #include <BooleanOperations_ShapesDataStructure.hxx>
00075 
00076 #include <IntTools_SequenceOfPntOn2Faces.hxx>
00077 #include <IntTools_SequenceOfCurves.hxx>
00078 #include <IntTools_FaceFace.hxx>
00079 #include <IntTools_Tools.hxx>
00080 #include <IntTools_ShrunkRange.hxx>
00081 #include <IntTools_Context.hxx>
00082 
00083 #include <BOPTools_CArray1OfSSInterference.hxx>
00084 #include <BOPTools_VSInterference.hxx>
00085 #include <BOPTools_ESInterference.hxx>
00086 #include <BOPTools_SSInterference.hxx>
00087 #include <BOPTools_ListOfPaveBlock.hxx>
00088 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
00089 #include <BOPTools_PaveBlock.hxx>
00090 #include <BOPTools_ListIteratorOfListOfPave.hxx>
00091 #include <BOPTools_Tools.hxx>
00092 #include <BOPTools_PaveBlockIterator.hxx>
00093 #include <BOPTools_Tools2D.hxx>
00094 #include <BOPTools_Tools3D.hxx>
00095 #include <BOPTools_Curve.hxx>
00096 
00097 #include <NMTDS_Iterator.hxx>
00098 #include <NMTDS_ShapesDataStructure.hxx>
00099 #include <NMTDS_InterfPool.hxx>
00100 
00101 #include <NMTTools_Tools.hxx>
00102 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
00103 #include <NMTTools_CommonBlock.hxx>
00104 #include <NMTTools_CommonBlockAPI.hxx>
00105 #include <NMTTools_ListOfCommonBlock.hxx>
00106 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
00107 #include <NMTTools_DataMapOfIntegerListOfPaveBlock.hxx>
00108 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
00109 #include <NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock.hxx>
00110 #include <NMTTools_MapOfPaveBlock.hxx>
00111 #include <NMTTools_MapIteratorOfMapOfPaveBlock.hxx>
00112 #include <NMTTools_FaceInfo.hxx>
00113 #include <NMTTools_DataMapIteratorOfDataMapOfIntegerFaceInfo.hxx>
00114 
00115 static
00116   Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
00117                                const Handle(IntTools_Context)& aCtx);
00118 
00119 //=======================================================================
00120 // function: PerformFF
00121 // purpose:
00122 //=======================================================================
00123   void NMTTools_PaveFiller::PerformFF()
00124 {
00125   myIsDone=Standard_False;
00126   //
00127   Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
00128   Standard_Boolean bJustAdd, bToSplit;
00129   Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
00130   Standard_Integer aNbCurves, aNbPoints;
00131   Standard_Real anApproxTol, aTolR3D, aTolR2D;
00132   BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
00133   IntTools_SequenceOfPntOn2Faces aPnts;
00134   IntTools_SequenceOfCurves aCvs;
00135   //
00136   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
00137   //
00138   //  F/F Interferences  [BooleanOperations_SurfaceSurface]
00139   myDSIt->Initialize(TopAbs_FACE, TopAbs_FACE);
00140   //
00141   // BlockLength correction
00142   aNbFFs=myDSIt->BlockLength();
00143   aBlockLength=aFFs.BlockLength();
00144   if (aNbFFs > aBlockLength) {
00145     aFFs.SetBlockLength(aNbFFs);
00146   }
00147   //
00148   //modified by NIZNHY-PKV Thu Sep 15 08:02:52 2011f
00149   bToSplit=Standard_False;
00150   //modified by NIZNHY-PKV Thu Sep 15 08:02:55 2011t
00151   //
00152   for (; myDSIt->More(); myDSIt->Next()) {
00153     myDSIt->Current(n1, n2, bJustAdd);
00154     //
00155     nF1 = n2;
00156     nF2 = n1;
00157     if(n1 < n2) {
00158       nF1 = n1;
00159       nF2 = n2;
00160     }
00161     anIndexIn=0;
00162     aPnts.Clear();
00163     aCvs.Clear();
00164     //
00165     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
00166     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
00167     //
00168     // FF
00169     bToApproxC3d     = mySectionAttribute.Approximation();
00170     bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
00171     bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
00172     //
00173     anApproxTol=1.e-7;
00174     //
00175     IntTools_FaceFace aFF;
00176     //
00177     aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1,
00178                        bToApproxC2dOnS2, anApproxTol);
00179     //
00180     aFF.Perform(aF1, aF2);
00181     //
00182     bIsDone=aFF.IsDone();
00183     //
00184     if (!bIsDone) {
00185       BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
00186       anIndexIn=aFFs.Append(anInterf);
00187       continue;
00188     }
00189     //
00190     aTolR3D=aFF.TolReached3d();
00191     aTolR2D=aFF.TolReached2d();
00192     if (aTolR3D < 1.e-7){
00193       aTolR3D=1.e-7;
00194     }
00195     //
00196     //modified by NIZNHY-PKV Thu Sep 15 08:03:02 2011f
00197 #if OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
00198     aFF.PrepareLines3D(bToSplit);
00199 #else
00200     aFF.PrepareLines3D();
00201 #endif // OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
00202     //modified by NIZNHY-PKV Thu Sep 15 08:03:04 2011t
00203     //
00204     const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
00205     const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
00206     //
00207     aNbCurves=aCvsX.Length();
00208     aNbPoints=aPntsX.Length();
00209     //
00210     if (!aNbCurves && !aNbPoints) {
00211       BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
00212       anIndexIn=aFFs.Append(anInterf);
00213       continue;
00214     }
00215     //
00216     {
00217       BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
00218       anIndexIn=aFFs.Append(anInterf);
00219     }
00220     //
00221   }// for (; myDSIt.More(); myDSIt.Next())
00222   //
00223   myIsDone=Standard_True;
00224 }
00225 
00226 //=======================================================================
00227 // function: MakeBlocks
00228 // purpose:
00229 //=======================================================================
00230 void NMTTools_PaveFiller::MakeBlocks()
00231 {
00232   myIsDone=Standard_False;
00233   //
00234   Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D, bIsCoincided;
00235   Standard_Boolean bIsMicroEdge, bHasES;
00236   Standard_Integer i, aNbFFs, nF1, nF2;
00237   Standard_Integer nV1, nV2, j, aNbCurves;
00238   Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
00239   TopoDS_Face aF1, aF2;
00240   NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
00241   BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
00242   BOPTools_ListIteratorOfListOfPaveBlock anIt;
00243   //
00244   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
00245   //
00246 
00247   //
00248   // 1. Make Section Edges from intersection curves
00249   //    between each pair of faces
00250   aNbFFs=aFFs.Extent();
00251   if (!aNbFFs) {
00252     return;
00253   }
00254   //
00255   FillFaceInfo();
00256   //
00257   for (i=1; i<=aNbFFs; ++i) {
00258     BOPTools_ListOfPaveBlock aLPB;
00259     TColStd_MapOfInteger aMVStick;
00260     TopTools_ListOfShape aLSE;
00261     TColStd_ListOfInteger aLNE;
00262     BOPTools_PaveSet aPSF;
00263     NMTTools_MapOfPaveBlock aMPBX;
00264     TColStd_MapIteratorOfMapOfInteger aItMI;
00265     NMTTools_MapIteratorOfMapOfPaveBlock aItMPB;
00266     //
00267     BOPTools_SSInterference& aFFi=aFFs(i);
00268     //
00269     // Faces
00270     aFFi.Indices(nF1, nF2);
00271     aF1=*((TopoDS_Face*)(&myDS->Shape(nF1)));
00272     aF2=*((TopoDS_Face*)(&myDS->Shape(nF2)));
00273     //
00274     SharedEdges(nF1, nF2, aLNE, aLSE);
00275     aFFi.SetSharedEdges(aLNE);
00276     //
00277     // aMVStick
00278     const NMTTools_FaceInfo& aFI1=myFaceInfo.Find(nF1);
00279     const NMTTools_FaceInfo& aFI2=myFaceInfo.Find(nF2);
00280     //
00281     const TColStd_MapOfInteger& aMVOn1=aFI1.VerticesOn();
00282     const TColStd_MapOfInteger& aMVIn1=aFI1.VerticesIn();
00283     const TColStd_MapOfInteger& aMVOn2=aFI2.VerticesOn();
00284     const TColStd_MapOfInteger& aMVIn2=aFI2.VerticesIn();
00285     //
00286     for (j=0; j<2; ++j) {
00287       const TColStd_MapOfInteger& aMV1=(!j) ? aMVOn1 :aMVIn1;
00288       aItMI.Initialize(aMV1);
00289       for (; aItMI.More(); aItMI.Next()) {
00290        nV1=aItMI.Key();
00291        if (aMVOn2.Contains(nV1) || aMVIn2.Contains(nV1)) {
00292          aMVStick.Add(nV1);
00293        }
00294       }
00295     }
00296     //
00297     //  aLPB
00298     const NMTTools_MapOfPaveBlock& aMPBIn1=aFI1.PaveBlocksIn();
00299     const NMTTools_MapOfPaveBlock& aMPBOn1=aFI1.PaveBlocksOn();
00300     const NMTTools_MapOfPaveBlock& aMPBIn2=aFI2.PaveBlocksIn();
00301     const NMTTools_MapOfPaveBlock& aMPBOn2=aFI2.PaveBlocksOn();
00302     //
00303     aMPBX.Clear();
00304     for (j=0; j<4; ++j) {
00305       NMTTools_MapOfPaveBlock *pMPB;
00306       //
00307       if (!j) {
00308        pMPB=((NMTTools_MapOfPaveBlock*)&aMPBIn1);
00309       }
00310       else if (j==1) {
00311        pMPB=((NMTTools_MapOfPaveBlock*)&aMPBOn1);
00312       }
00313       else if (j==2) {
00314        pMPB=((NMTTools_MapOfPaveBlock*)&aMPBIn2);
00315       }
00316       else if (j==3) {
00317        pMPB=((NMTTools_MapOfPaveBlock*)&aMPBOn2);
00318       }
00319       //
00320       const NMTTools_MapOfPaveBlock& aMPB=*pMPB;
00321       aItMPB.Initialize(aMPB);
00322       for (; aItMPB.More(); aItMPB.Next()) {
00323        const BOPTools_PaveBlock& aPB=aItMPB.Key();
00324        if (aMPBX.Add(aPB)) {
00325          aLPB.Append(aPB);
00326        }
00327        //
00328        else {
00329          if (j>1) {
00330            aFFi.AppendBlock(aPB);
00331          }
00332        }
00333        //
00334       }
00335     }
00336     //
00337     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
00338     aNbCurves=aSCvs.Length();
00339     if (!aNbCurves) {
00340       continue;
00341     }
00342     //
00343     aTolR3D=aFFi.TolR3D();
00344     aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
00345     //
00346     CorrectTolR3D(aFFi, aMVStick, aTolR3D);
00347     //
00348     PrepareSetForFace (nF1, nF2, aLPB, aPSF);
00349     //
00350     // Put Paves On Curves
00351     for (j=1; j<=aNbCurves; ++j) {
00352       BOPTools_Curve& aBC=aSCvs(j);
00353       const IntTools_Curve& aC=aBC.Curve();
00354       // DEBUG f
00355       Handle(Geom_Curve) aC3D = aC.Curve();
00356       // DEBUG t
00357       PutPaveOnCurve (aPSF, aTolR3D, aBC);
00358     }
00359     //
00360     // Put bounding paves on curves
00361     for (j=1; j<=aNbCurves; ++j) {
00362       BOPTools_Curve& aBC=aSCvs(j);
00363       PutBoundPaveOnCurve (aBC, aFFi);
00364     }
00365     //modified by NIZNHY-PKV Wed Sep 14 13:12:14 2011f
00366 #if OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
00367     //
00368     // Put closing pave if needded
00369     for (j=1; j<=aNbCurves; ++j) {
00370       BOPTools_Curve& aBC=aSCvs(j);
00371       PutClosingPaveOnCurve (aBC, aFFi);
00372     }
00373 #endif // OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
00374     //modified by NIZNHY-PKV Wed Sep 14 13:12:17 2011t
00375     //
00376     //  Pave Blocks on Curves
00377     bHasES=Standard_False;
00378     for (j=1; j<=aNbCurves; ++j) {
00379       BOPTools_Curve& aBC=aSCvs(j);
00380       const IntTools_Curve& aIC= aBC.Curve();
00381       BOPTools_PaveSet& aPaveSet=aBC.Set();
00382       //
00383       BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
00384       for (; aPBIter.More(); aPBIter.Next()) {
00385         BOPTools_PaveBlock& aPBNew=aPBIter.Value();
00386         aPBNew.SetCurve(aIC);
00387         aPBNew.SetFace1(nF1);
00388         aPBNew.SetFace2(nF2);
00389         //
00390         nV1=aPBNew.Pave1().Index();
00391         nV2=aPBNew.Pave2().Index();
00392         aT1=aPBNew.Pave1().Param();
00393         aT2=aPBNew.Pave2().Param();
00394         //
00395         if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
00396           continue;// mkk ft ???
00397         }
00398         //
00399         // 1
00400         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPB, aTolR3D);
00401         if (bIsExistingPaveBlock) {
00402           continue;
00403         }
00404         //
00405         bIsCoincided=CheckCoincidence(aPBNew, aLPB);
00406         if(bIsCoincided) {
00407           continue;
00408         }
00409         //
00410         // 2
00411         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLSE, aTolR3D);
00412         if (bIsExistingPaveBlock) {
00413           continue;
00414         }
00415        //
00416         // Checking of validity in 2D
00417         //
00418         bIsValidIn2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
00419         if (!bIsValidIn2D) {
00420           continue;
00421         }
00422         //
00423         //
00424         // Make Section Edge
00425         TopoDS_Edge aES;
00426         //
00427         const TopoDS_Vertex aV1=TopoDS::Vertex(myDS->Shape(nV1));
00428         const TopoDS_Vertex aV2=TopoDS::Vertex(myDS->Shape(nV2));
00429         //
00430         {
00431           Standard_Real aT;
00432           //
00433           myContext->IsVertexOnLine(aV1, aIC, aTolR3D, aT);
00434           BOPTools_Tools::UpdateVertex (aIC, aT, aV1);
00435           //
00436           myContext->IsVertexOnLine(aV2, aIC, aTolR3D, aT);
00437           BOPTools_Tools::UpdateVertex (aIC, aT, aV2);
00438         }
00439         //
00440         BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
00441         //
00442         NMTTools_Tools::UpdateEdge (aES, aTolR3D);
00443         bIsMicroEdge=IsMicroEdge(aES, myContext);
00444         if (bIsMicroEdge) {
00445           continue;
00446         }
00447         //
00448         {
00449           Handle(Geom2d_Curve) aC2D1, aC2D2;
00450           //
00451           aC2D1=aIC.FirstCurve2d();
00452           aC2D2=aIC.SecondCurve2d();
00453           //
00454           NMTTools_Tools::MakePCurve(aES, aF1, aC2D1);
00455           NMTTools_Tools::MakePCurve(aES, aF2, aC2D2);
00456         }
00457         //
00458         aMEPB.Add(aES, aPBNew);
00459         aMapEI.Add(aES, i);
00460         //
00461         bHasES=Standard_True;
00462       }// for (; aPBIter.More(); aPBIter.Next())
00463     } // end of for (j=1; j<=aNbCurves; ++j)
00464     // qqf
00465     if (bHasES) {
00466       myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF);
00467     }
00468     // qqt
00469   }// for (i=1; i<=aNbFFs; ++i)
00470   //=============================================================
00471   //
00472   // II. Post treatment
00473   //
00474   // Input data: aMEPB, aMapEI
00475   // Result    : section edges in myDS
00476   //
00477   Standard_Integer aNbSE;
00478   //
00479   aNbSE=aMEPB.Extent();
00480   if (!aNbSE) {
00481     // there is nothing to do here
00482     return;
00483   }
00484   //
00485   BRep_Builder aBB;
00486   TopoDS_Compound aCompound;
00487   //
00488   // 1. Make compound from SE
00489   aBB.MakeCompound(aCompound);
00490   for (i=1; i<=aNbSE; ++i) {
00491     const TopoDS_Shape& aSE=aMEPB.FindKey(i);
00492     aBB.Add(aCompound, aSE);
00493   }
00494   //
00495   //
00496   // 2. Intersect SE using auxiliary Filler
00497   NMTTools_PaveFiller tPF;
00498   //
00499   tPF.SetCompositeShape(aCompound);
00500   //
00501   // 2.1.VV
00502   tPF.Init();
00503   tPF.PerformVV();
00504   //
00505   // 2.2.VE
00506   tPF.myPavePool.Resize (tPF.myNbEdges);
00507   tPF.PrepareEdges();
00508   tPF.PerformVE();
00509   //
00510   // 2.3.VF
00511   tPF.PerformVF();
00512   //
00513   // 2.4.EE
00514   tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
00515   tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
00516   tPF.myPavePoolNew    .Resize (tPF.myNbEdges);
00517 
00518   tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
00519   tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
00520   //
00521   tPF.PerformEE();
00522   //
00523   tPF.RefinePavePool ();
00524   //
00525   tPF.myPavePoolNew.Destroy();
00526   //
00527   tPF.MakeSplitEdges();
00528   tPF.UpdateCommonBlocks();
00529   //
00530   // 3. Treatment of the result of intersection
00531   //
00532   Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
00533   TopAbs_ShapeEnum aType;
00534   BOPTools_ListIteratorOfListOfPaveBlock aIt;
00535   BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
00536   //
00537   const NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
00538   const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
00539   const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
00540   //
00541   aNbLines=tDS.NumberOfInsertedShapes();
00542   aNbOld=tDS.NumberOfShapesOfTheObject();
00543   //
00544   // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
00545   //
00546   // 3.1.1.Old vertices [ links ]
00547   for (i=1; i<=aNbOld; ++i) {
00548     const TopoDS_Shape& aV=tDS.Shape(i);
00549     aType=aV.ShapeType();
00550     if (aType!=TopAbs_VERTEX) {
00551       continue;
00552     }
00553     //
00554     for (j=1; j<=aNbSE; ++j) {
00555       const BOPTools_PaveBlock& aPBSE=aMEPB(j);
00556       nV1=aPBSE.Pave1().Index();
00557       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
00558       if (aV1.IsSame(aV)) {
00559         aMNewOld.Add(i, nV1);
00560         break;
00561       }
00562       nV2=aPBSE.Pave2().Index();
00563       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
00564       if (aV2.IsSame(aV)) {
00565         aMNewOld.Add(i, nV2);
00566         break;
00567       }
00568     }
00569   }
00570   //
00571   // 3.1.2. New vertices [ links ]
00572   i=tDS.NumberOfSourceShapes()+1;
00573   for (; i<=aNbLines; ++i) {
00574     const TopoDS_Shape& aV=tDS.Shape(i);
00575     aType=aV.ShapeType();
00576     if (aType!=TopAbs_VERTEX) {
00577       continue;
00578     }
00579     //
00580     // Insert new vertex in myDS
00581     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
00582     myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
00583     nV1=myDS->NumberOfInsertedShapes();
00584     // link
00585     aMNewOld.Add(i, nV1);
00586   }
00587   //
00588   // 3.2. Treatment of section edges (SE)
00589   for (i=1; i<=aNbOld; ++i) {
00590     const TopoDS_Shape& aE=tDS.Shape(i);
00591     aType=aE.ShapeType();
00592     if (aType!=TopAbs_EDGE) {
00593       continue;
00594     }
00595     //
00596     //  block of section edge that we already have for this SE
00597     BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
00598     //
00599     // Corresponding FF-interference
00600     iFF=aMapEI.FindFromKey(aE);
00601     BOPTools_SSInterference& aFFi=aFFs(iFF);
00602     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
00603     //
00604     BOPTools_Curve& aBC=aSCvs(1);
00605     //
00606     const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
00607     aNbPB=aLPB.Extent();
00608     //
00609     if (!aNbPB) {
00610       // no pave blocks -> use aPBSE and whole edge aE
00611       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
00612       //
00613       nV1=aPBSE.Pave1().Index();
00614       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
00615       nV2=aPBSE.Pave2().Index();
00616       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
00617       //
00618       anASSeq.SetNewSuccessor(nV1);
00619       anASSeq.SetNewOrientation(aV1.Orientation());
00620       anASSeq.SetNewSuccessor(nV2);
00621       anASSeq.SetNewOrientation(aV2.Orientation());
00622       //
00623       myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
00624       nE=myDS->NumberOfInsertedShapes();
00625       //
00626       aPBSE.SetEdge(nE);
00627       aBC.AppendNewBlock(aPBSE);
00628       //
00629       continue;
00630     }
00631     //
00632     nF1=aPBSE.Face1();
00633     nF2=aPBSE.Face2();
00634     //
00635     const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
00636     NMTTools_CommonBlockAPI aCBAPI(aLCB);
00637     //
00638     aIt.Initialize(aLPB);
00639     for (; aIt.More(); aIt.Next()) {
00640       BOPTools_PaveBlock aPB=aIt.Value();
00641       //
00642       const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));
00643       const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));
00644       //
00645       if (aCBAPI.IsCommonBlock(aPB)) {
00646         // it can be Common Block
00647         Standard_Real aTolEx;
00648         Handle(Geom2d_Curve) aC2D1, aC2D2;
00649         TopoDS_Face aF1FWD, aF2FWD;
00650         //
00651         NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
00652         //const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
00653         //
00654         aPB=aCB.PaveBlock1();
00655         mE=aPB.Edge(); // index of edge in tDS
00656         const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
00657         aTolEx=BRep_Tool::Tolerance(aEx);
00658         //
00659         aF1FWD=aF1;
00660         aF1FWD.Orientation(TopAbs_FORWARD);
00661         aF2FWD=aF2;
00662         aF2FWD.Orientation(TopAbs_FORWARD);
00663         //
00664         NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1);
00665         NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2);
00666         NMTTools_Tools::UpdateEdge (aEx, aTolEx);
00667       } //if (aCBAPI.IsCommonBlock(aPB))
00668       //
00669       // new SE
00670       mE=aPB.Edge(); // index of edge in tDS
00671       const TopoDS_Shape& aSp=tDS.Shape(mE);
00672       //
00673       const BOPTools_Pave& aPave1=aPB.Pave1();
00674       aT1=aPave1.Param();
00675       mV1=aPave1.Index();            // index in tDS
00676       nV1=aMNewOld.FindFromKey(mV1); // index in myDS
00677       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
00678       //
00679       const BOPTools_Pave& aPave2=aPB.Pave2();
00680       aT2=aPave2.Param();
00681       mV2=aPave2.Index();
00682       nV2=aMNewOld.FindFromKey(mV2);
00683       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
00684       //
00685       if (!aMNewOld.Contains(mE)) {
00686         // add new SE to the myDS
00687         BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
00688         //
00689         anASSeq.SetNewSuccessor(nV1);
00690         anASSeq.SetNewOrientation(aV1.Orientation());
00691 
00692         anASSeq.SetNewSuccessor(nV2);
00693         anASSeq.SetNewOrientation(aV2.Orientation());
00694 
00695         myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
00696         nE=myDS->NumberOfInsertedShapes();
00697         //
00698         aMNewOld.Add(mE, nE);
00699       }
00700       else {
00701         nE=aMNewOld.FindFromKey(mE);
00702       }
00703       // Form PaveBlock;
00704       BOPTools_PaveBlock aPBx;
00705       BOPTools_Pave aP1, aP2;
00706       //
00707       aPBx.SetFace1(nF1);
00708       aPBx.SetFace1(nF2);
00709       //
00710       aP1.SetIndex(nV1);
00711       aP1.SetParam(aT1);
00712       //
00713       aP2.SetIndex(nV2);
00714       aP2.SetParam(aT2);
00715       //
00716       aPBx.SetPave1(aP1);
00717       aPBx.SetPave2(aP2);
00718       //
00719       aPBx.SetEdge(nE);
00720       //
00721       aBC.AppendNewBlock(aPBx);
00722     }// for (; aIt.More(); aIt.Next())
00723   }// for (i=1; i<=aNbOld; ++i)
00724   //
00725   myIsDone=Standard_True;
00726 }
00727 
00728 //=======================================================================
00729 // function: MakePCurves
00730 // purpose:
00731 //=======================================================================
00732 void NMTTools_PaveFiller::MakePCurves()
00733 {
00734   Standard_Integer i, aNb,  nF1, nF2, nE;
00735   Standard_Integer aNbCB, aNbF, nSp, nF;
00736   TopAbs_ShapeEnum aType;
00737   TopoDS_Face aF1FWD, aF2FWD;
00738   TColStd_ListIteratorOfListOfInteger aItF;
00739   BOPTools_ListIteratorOfListOfPaveBlock anIt;
00740   NMTTools_ListIteratorOfListOfCommonBlock aItCB;
00741   //
00742   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
00743   //
00744   aNb=aFFs.Extent();
00745   for (i=1; i<=aNb; i++) {
00746     BOPTools_SSInterference& aFF=aFFs(i);
00747     aFF.Indices(nF1, nF2);
00748     //
00749     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
00750     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
00751     //
00752     aF1FWD=aF1;
00753     aF1FWD.Orientation(TopAbs_FORWARD);
00754     aF2FWD=aF2;
00755     aF2FWD.Orientation(TopAbs_FORWARD);
00756     //
00757     // In, On parts processing
00758     const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
00759     //
00760     anIt.Initialize(aLPBInOn);
00761     for (; anIt.More(); anIt.Next()) {
00762       const BOPTools_PaveBlock& aPB=anIt.Value();
00763       nE=aPB.Edge();
00764       const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
00765 
00766       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
00767       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
00768     }
00769   }
00770   // Check common blocks between edges and faces
00771   // Build P-Curves if they were not built in previos block.
00772   // The main case is :arguments for e.g aEdge, aFace -> no FFs,
00773   // but p-curves are needed.
00774   //
00775   aNb=myDS->NumberOfShapesOfTheObject();
00776   for (i=1; i<=aNb; ++i) {
00777     const TopoDS_Shape& aS=myDS->Shape(i);
00778     aType=aS.ShapeType();
00779     //
00780     if (aType!=TopAbs_EDGE) {
00781       continue;
00782     }
00783     const TopoDS_Edge& aE=TopoDS::Edge(aS);
00784     //
00785     if (BRep_Tool::Degenerated(aE)) {
00786       continue;
00787     }
00788     //
00789     const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
00790     aNbCB=aLCB.Extent();
00791     if (!aNbCB) {
00792       continue;
00793     }
00794     //
00795     aItCB.Initialize(aLCB);
00796     for (; aItCB.More(); aItCB.Next()) {
00797       const NMTTools_CommonBlock& aCB=aItCB.Value();
00798       const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
00799       //
00800       const TColStd_ListOfInteger& aLF=aCB.Faces();
00801       aNbF=aLF.Extent();
00802       if (!aNbF) {
00803         continue;
00804       }
00805       //
00806       nSp=aPB1.Edge();
00807       const TopoDS_Edge aSp=TopoDS::Edge(myDS->Shape(nSp));//mpv
00808       //
00809       aItF.Initialize(aLF);
00810       for (; aItF.More(); aItF.Next()) {
00811         nF=aItF.Value();
00812         aF1FWD=TopoDS::Face(myDS->Shape(nF));
00813         aF1FWD.Orientation(TopAbs_FORWARD);
00814         //
00815         BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aSp, aF1FWD);
00816       } // for (; aItCB.More(); aItCB.Next()) {
00817     }//if (aS.ShapeType()==TopAbs_EDGE) {
00818   }
00819 }
00820 
00821 //=======================================================================
00822 // function: IsExistingPaveBlock
00823 // purpose:
00824 //=======================================================================
00825 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
00826                                                           const BOPTools_ListOfPaveBlock& aLPBR,
00827                                                           const Standard_Real aTolR3D)
00828 {
00829   Standard_Boolean bFlag;
00830   Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
00831   BOPTools_ListIteratorOfListOfPaveBlock anIt;
00832   //
00833   bFlag=Standard_False;
00834   nVNew1=aPBNew.Pave1().Index();
00835   nVNew2=aPBNew.Pave2().Index();
00836   //
00837   anIt.Initialize(aLPBR);
00838   for (; anIt.More(); anIt.Next()) {
00839     const BOPTools_PaveBlock& aPBR=anIt.Value();
00840     nV1=aPBR.Pave1().Index();
00841     nV2=aPBR.Pave2().Index();
00842     if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
00843       //
00844       iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
00845       if (!iC) {
00846         return !bFlag;
00847       }
00848     }
00849   }
00850   return bFlag;
00851 }
00852 
00853 //=======================================================================
00854 // function: IsExistingPaveBlock
00855 // purpose:
00856 //=======================================================================
00857 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
00858                                                           const TopTools_ListOfShape& aLSE,
00859                                                           const Standard_Real aTolR3D)
00860 {
00861   Standard_Boolean bFlag;
00862   Standard_Integer aNbSE, iC;
00863   Standard_Real aTolE, aTol;
00864   TopTools_ListIteratorOfListOfShape anIt;
00865   //
00866   bFlag=Standard_False;
00867   //
00868   aNbSE=aLSE.Extent();
00869   if (!aNbSE) {
00870     return bFlag;
00871   }
00872   //
00873   anIt.Initialize(aLSE);
00874   for (; anIt.More(); anIt.Next()) {
00875     const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
00876     aTolE=BRep_Tool::Tolerance(aE);
00877     aTol=aTolR3D;
00878     if (aTolE>aTol) {
00879       aTol=aTolE;
00880     }
00881     iC=CheckIntermediatePoint(aPBNew, aE, aTol);
00882     if (!iC) {
00883       return !bFlag;
00884     }
00885   }
00886   return bFlag;
00887 }
00888 
00889 //=======================================================================
00890 // function: CheckIntermediatePoint
00891 // purpose:
00892 //=======================================================================
00893 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
00894                                                              const BOPTools_PaveBlock& aPBR,
00895                                                              const Standard_Real aTolC)
00896 {
00897   Standard_Integer iVM, nE2;
00898   //
00899   nE2=aPBR.Edge();
00900   const TopoDS_Edge aE2=TopoDS::Edge(myDS->Shape(nE2));//mpv
00901   iVM=CheckIntermediatePoint(aPB, aE2, aTolC);
00902   //
00903   return iVM;
00904 }
00905 
00906 //=======================================================================
00907 // function: CheckIntermediatePoint
00908 // purpose:
00909 //=======================================================================
00910 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
00911                                                              const TopoDS_Edge& aE2,
00912                                                              const Standard_Real aTolC)
00913 {
00914   Standard_Real aT11, aT12, aTM, aTmp;
00915   Standard_Integer iVM;
00916   gp_Pnt aPM;
00917   BRep_Builder aBB;
00918   TopoDS_Vertex aVM;
00919   //
00920   // Vertex
00921   const BOPTools_Pave& aPave11=aPB.Pave1();
00922   aT11=aPave11.Param();
00923   //
00924   const BOPTools_Pave& aPave12=aPB.Pave2();
00925   aT12=aPave12.Param();
00926   //
00927   aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
00928   //
00929   const IntTools_Curve& aIC=aPB.Curve();
00930   aIC.D0(aTM, aPM);
00931   //
00932   aBB.MakeVertex (aVM, aPM, aTolC);
00933   //
00934   iVM=myContext->ComputeVE(aVM, aE2, aTmp);
00935   //
00936   return iVM;
00937 }
00938 
00939 //=======================================================================
00940 // function: PutBoundPaveOnCurve
00941 // purpose:
00942 //=======================================================================
00943 void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
00944                                               BOPTools_SSInterference& aFFi)
00945 {
00946   Standard_Boolean bHasBounds, bVF;
00947   Standard_Integer nF1, nF2;
00948   Standard_Real aT1, aT2, aTolR3D;
00949   gp_Pnt aP1, aP2;
00950   //
00951   const IntTools_Curve& aIC=aBC.Curve();
00952   bHasBounds=aIC.HasBounds ();
00953   if (!bHasBounds){
00954     return;
00955   }
00956   //
00957   // Bounds
00958   aIC.Bounds (aT1, aT2, aP1, aP2);
00959   //
00960   // Faces
00961   aFFi.Indices(nF1, nF2);
00962   aTolR3D=aFFi.TolR3D();
00963   //
00964   const TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));//mpv
00965   const TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));//mpv
00966   //
00967   bVF=myContext->IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
00968   if (bVF) {
00969     PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
00970   }
00971   //
00972   bVF=myContext->IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
00973   if (bVF) {
00974     PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
00975   }
00976 }
00977 
00978 //=======================================================================
00979 // function: PutBoundPaveOnCurve
00980 // purpose:
00981 //=======================================================================
00982 void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
00983                                               const Standard_Real aT,
00984                                               BOPTools_Curve& aBC,
00985                                               BOPTools_SSInterference& aFFi)
00986 {
00987   Standard_Boolean bFound1, bFound2;
00988   Standard_Integer nV;
00989   Standard_Real aTolV=aFFi.TolR3D();
00990 
00991   BOPTools_Pave aPave1, aPave2, aPave;
00992   BOPTools_PaveSet& aCPS=aBC.Set();
00993   BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
00994   const IntTools_Curve& aIC=aBC.Curve();
00995   //
00996   bFound1=FindPave(aP, aTolV, aCPS  , aPave1);
00997   bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
00998   //
00999   if (!bFound1 && !bFound2) {
01000     TopoDS_Vertex aNewVertex;
01001     BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
01002     //
01003     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
01004     myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
01005     nV=myDS->NumberOfInsertedShapes();
01006     aPave.SetIndex(nV);
01007     aPave.SetParam(aT);
01008 
01009     aCPS.Append(aPave);
01010     aFFiPS.Append(aPave);
01011     //
01012     // Append Techno Vertex to the Curve
01013     TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
01014     aTVs.Append(nV);
01015   }
01016   if (bFound1 && !bFound2) {
01017     nV=aPave1.Index();
01018     aPave.SetIndex(nV);
01019     aPave.SetParam(aT);
01020     aFFiPS.Append(aPave);
01021     //
01022     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
01023     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
01024   }
01025 
01026   if (!bFound1 && bFound2) {
01027     nV=aPave2.Index();
01028     aPave.SetIndex(nV);
01029     aPave.SetParam(aT);
01030     aCPS.Append(aPave);
01031     //
01032     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
01033     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
01034   }
01035 }
01036 
01037 //=======================================================================
01038 // function: FindPave
01039 // purpose:
01040 //=======================================================================
01041 Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
01042                                                const Standard_Real aTolPV,
01043                                                const BOPTools_PaveSet& aPS,
01044                                                BOPTools_Pave& aPave)
01045 {
01046   Standard_Integer nV;
01047   Standard_Boolean bIsVertex=Standard_False;
01048 
01049   const BOPTools_ListOfPave& aLP=aPS.Set();
01050   BOPTools_ListIteratorOfListOfPave anIt(aLP);
01051   for (; anIt.More(); anIt.Next()) {
01052     const BOPTools_Pave& aPC=anIt.Value();
01053     nV=aPC.Index();
01054     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
01055     bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
01056     if (bIsVertex) {
01057       aPave=aPC;
01058       return bIsVertex;
01059     }
01060   }
01061   return bIsVertex;
01062 }
01063 
01064 //=======================================================================
01065 // function: PrepareSetForFace
01066 // purpose:
01067 //=======================================================================
01068 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer ,//nF1,
01069                                             const Standard_Integer ,//nF2,
01070                                             const BOPTools_ListOfPaveBlock& aLPBC,
01071                                             BOPTools_PaveSet& aPSF)
01072 {
01073   Standard_Integer nV1, nV2;
01074   TColStd_MapOfInteger aMap;
01075   BOPTools_ListIteratorOfListOfPaveBlock anIt;
01076   //
01077   anIt.Initialize(aLPBC);
01078   for (; anIt.More(); anIt.Next()) {
01079     const BOPTools_PaveBlock& aPB=anIt.Value();
01080     const BOPTools_Pave& aPave1=aPB.Pave1();
01081     nV1=aPave1.Index();
01082     if (!aMap.Contains(nV1)) {
01083       aMap.Add(nV1);
01084       aPSF.Append(aPave1);
01085     }
01086     const BOPTools_Pave& aPave2=aPB.Pave2();
01087     nV2=aPave2.Index();
01088     if (!aMap.Contains(nV2)) {
01089       aMap.Add(nV2);
01090       aPSF.Append(aPave2);
01091     }
01092   }
01093 }
01094 
01095 //=======================================================================
01096 // function: CheckCoincidence
01097 // purpose:
01098 //=======================================================================
01099 Standard_Boolean NMTTools_PaveFiller::CheckCoincidence(const BOPTools_PaveBlock& aPBNew,
01100                                                        const BOPTools_ListOfPaveBlock& aLPBFF)
01101 {
01102   Standard_Boolean bRet;
01103   Standard_Real aTE;
01104   Standard_Integer nV11, nV12, nV21, nV22, iVV, iVE, nE2;
01105   Standard_Integer iV, iCount, iCountExt;
01106   BOPTools_ListIteratorOfListOfPaveBlock anIt;
01107   // V11
01108   const BOPTools_Pave& aPave11=aPBNew.Pave1();
01109   nV11=aPave11.Index();
01110   const TopoDS_Vertex& aV11=TopoDS::Vertex(myDS->Shape(nV11));
01111 
01112   // V12
01113   const BOPTools_Pave& aPave12=aPBNew.Pave2();
01114   nV12=aPave12.Index();
01115   const TopoDS_Vertex& aV12=TopoDS::Vertex(myDS->Shape(nV12));
01116   //
01117   iCountExt=1;
01118   iCount=0;
01119   anIt.Initialize(aLPBFF);
01120   for (; anIt.More(); anIt.Next()) {
01121     iCount=0;
01122     //
01123     const BOPTools_PaveBlock& aPBR=anIt.Value();
01124     // V21
01125     const BOPTools_Pave& aPave21=aPBR.Pave1();
01126     nV21=aPave21.Index();
01127 
01128     // V22
01129     const BOPTools_Pave& aPave22=aPBR.Pave2();
01130     nV22=aPave22.Index();
01131     //
01132     if (nV11==nV21 || nV11==nV22 || nV12==nV21 || nV12==nV22) {
01133       continue;
01134     }
01135     //
01136     // E2
01137     nE2=aPBR.Edge();
01138     //
01139     const TopoDS_Vertex& aV21=TopoDS::Vertex(myDS->Shape(nV21));
01140     const TopoDS_Vertex& aV22=TopoDS::Vertex(myDS->Shape(nV22));
01141     const TopoDS_Edge& aE2=TopoDS::Edge(myDS->Shape(nE2));
01142     //
01143     // VV
01144     iV=0;
01145     iVV=IntTools_Tools::ComputeVV (aV11, aV21);
01146     if (!iVV) {
01147       iCount++;
01148       iV++;
01149       if (iCount>iCountExt) {
01150         break;
01151       }
01152     }
01153     //
01154     iVV=IntTools_Tools::ComputeVV (aV11, aV22);
01155     if (!iVV) {
01156       iCount++;
01157       iV++;
01158       if (iCount>iCountExt) {
01159         break;
01160       }
01161     }
01162     // VE
01163     if (!iV) {
01164       iVE=myContext->ComputeVE (aV11, aE2, aTE);
01165       if (!iVE) {
01166         iCount++;
01167         if (iCount>iCountExt) {
01168           break;
01169         }
01170       }
01171     }
01172     // VV
01173     iV=0;
01174     iVV=IntTools_Tools::ComputeVV (aV12, aV21);
01175     if (!iVV) {
01176       iCount++;
01177       iV++;
01178       if (iCount>iCountExt) {
01179         break;
01180       }
01181     }
01182     //
01183     iVV=IntTools_Tools::ComputeVV (aV12, aV22);
01184     if (!iVV) {
01185       iCount++;
01186       iV++;
01187       if (iCount>iCountExt) {
01188         break;
01189       }
01190     }
01191     // VE
01192     if (!iV) {
01193       iVE=myContext->ComputeVE (aV12, aE2, aTE);
01194       if (!iVE) {
01195         iCount++;
01196         if (iCount>iCountExt) {
01197           break;
01198         }
01199       }
01200     }
01201   } // next aPBR
01202   bRet=(Standard_Boolean)(iCount>iCountExt);
01203   return bRet;
01204 }
01205 
01206 //=======================================================================
01207 //function : IsMicroEdge
01208 //purpose  :
01209 //=======================================================================
01210 Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
01211                              const Handle(IntTools_Context)& aCtx)
01212 {
01213   Standard_Boolean bRet;
01214   Standard_Integer iErr;
01215   Standard_Real aT1, aT2, aTmp;
01216   Handle(Geom_Curve) aC3D;
01217   TopoDS_Vertex aV1, aV2;
01218   IntTools_Range aR;
01219   //
01220   bRet=(BRep_Tool::Degenerated(aE) ||
01221         !BRep_Tool::IsGeometric(aE));
01222   if (bRet) {
01223     return bRet;
01224   }
01225   //
01226   aC3D=BRep_Tool::Curve(aE, aT1, aT2);
01227   TopExp::Vertices(aE, aV1, aV2);
01228   aT1=BRep_Tool::Parameter(aV1, aE);
01229   aT2=BRep_Tool::Parameter(aV2, aE);
01230   if (aT2<aT1) {
01231     aTmp=aT1;
01232     aT1=aT2;
01233     aT2=aTmp;
01234   }
01235   //
01236   aR.SetFirst(aT1);
01237   aR.SetLast(aT2);
01238   IntTools_ShrunkRange aSR (aE, aV1, aV2, aR, aCtx);
01239   iErr=aSR.ErrorStatus();
01240   bRet=!aSR.IsDone();
01241   //
01242   return bRet;
01243 }
01244 //=======================================================================
01245 // function: PutPaveOnCurve
01246 // purpose:
01247 //=======================================================================
01248 void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
01249                                          const Standard_Real aTolR3D,
01250                                          BOPTools_Curve& aBC)
01251 {
01252   Standard_Integer nV;
01253   Standard_Boolean bIsVertexOnLine;
01254   Standard_Real aT;
01255   BOPTools_ListIteratorOfListOfPave anIt;
01256   Bnd_Box aBBC;
01257   GeomAdaptor_Curve aGAC;
01258   //
01259   const IntTools_Curve& aC=aBC.Curve();
01260   Handle (Geom_Curve) aC3D= aC.Curve();
01261   aGAC.Load(aC3D);
01262   BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
01263   //
01264   const BOPTools_ListOfPave& aLP=aPaveSet.Set();
01265   anIt.Initialize(aLP);
01266   for (; anIt.More(); anIt.Next()) {
01267     const BOPTools_Pave& aPave=anIt.Value();
01268     //
01269     nV=aPave.Index();
01270     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));
01271     //
01272     Bnd_Box aBBV;
01273     BRepBndLib::Add(aV, aBBV);
01274     if (aBBC.IsOut(aBBV)){
01275       continue;
01276     }
01277     //
01278     bIsVertexOnLine=myContext->IsVertexOnLine(aV, aC, aTolR3D, aT);
01279     //
01280     //
01281     if (bIsVertexOnLine) {
01282       BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
01283       BOPTools_PaveSet& aPS=aBC.Set();
01284       aPS.Append(aPaveNew);
01285       //<-B
01286     }
01287   }
01288 }
01289 //
01290 //=======================================================================
01291 //function : FillFaceInfo
01292 //purpose  :
01293 //=======================================================================
01294 void NMTTools_PaveFiller::FillFaceInfo()
01295 {
01296   Standard_Integer i, aNbS, aNbFFs, nF, aNbVFs, aNbEFs, j, n1, n2, nX, aNbF;
01297   TopAbs_ShapeEnum aType;
01298   TopoDS_Shape aS;
01299   TColStd_ListIteratorOfListOfInteger aItF;
01300   BOPTools_ListIteratorOfListOfPaveBlock anItPB;
01301   NMTTools_DataMapIteratorOfDataMapOfIntegerFaceInfo aItMFI;
01302   NMTTools_ListIteratorOfListOfCommonBlock aItCB;
01303   //
01304   myFaceInfo.Clear();
01305   //
01306   BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
01307   BOPTools_CArray1OfVSInterference& aVFs=myIP->VSInterferences();
01308   BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
01309   //
01310   aNbFFs=aFFs.Extent();
01311   if (!aNbFFs) {
01312     return;
01313   }
01314   //
01315   // 0.
01316   for (i=1; i<=aNbFFs; ++i) {
01317     NMTTools_FaceInfo aFI;
01318     //
01319     BOPTools_SSInterference& aFFi=aFFs(i);
01320     aFFi.Indices(n1, n2);
01321     myFaceInfo.Bind(n1, aFI);
01322     myFaceInfo.Bind(n2, aFI);
01323   }
01324   //
01325   // 1.
01326   aNbS=myDS->NumberOfShapesOfTheObject();
01327   for (i=1; i<=aNbS; ++i) {
01328     aS=myDS->Shape(i);
01329     aType=aS.ShapeType();
01330     if (aType==TopAbs_EDGE) {
01331       const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
01332       aItCB.Initialize(aLCB);
01333       for (; aItCB.More(); aItCB.Next()) {
01334        const NMTTools_CommonBlock& aCB=aItCB.Value();
01335        const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
01336        const TColStd_ListOfInteger& aLF=aCB.Faces();
01337        aNbF=aLF.Extent();
01338        if (!aNbF) {
01339          continue;
01340        }
01341        //
01342        aItF.Initialize(aLF);
01343        for (; aItF.More(); aItF.Next()) {
01344          nF=aItF.Value();
01345          if (!myFaceInfo.IsBound(nF)) {
01346            continue;
01347          }
01348          //
01349          NMTTools_FaceInfo& aFI=myFaceInfo.ChangeFind(nF);
01350          aFI.ChangePaveBlocksIn().Add(aPB1);
01351          //
01352          n1=aPB1.Pave1().Index();
01353          n2=aPB1.Pave2().Index();
01354          aFI.ChangeVerticesIn().Add(n1);
01355          aFI.ChangeVerticesIn().Add(n2);
01356        }
01357       }
01358     }// if (aType==TopAbs_EDGE) {
01359     else if (aType==TopAbs_FACE) {
01360       if (!myFaceInfo.IsBound(i)) {
01361        continue;
01362       }
01363       //
01364       BOPTools_ListOfPaveBlock aLPBOn;
01365       //
01366       nF=i;
01367       NMTTools_FaceInfo& aFI=myFaceInfo.ChangeFind(nF);
01368       //
01369       RealSplitsFace(nF, aLPBOn);
01370       //
01371       anItPB.Initialize(aLPBOn);
01372       for (; anItPB.More(); anItPB.Next()) {
01373        const BOPTools_PaveBlock &aPB=anItPB.Value();
01374        aFI.ChangePaveBlocksOn().Add(aPB);
01375        //
01376        n1=aPB.Pave1().Index();
01377        n2=aPB.Pave2().Index();
01378        aFI.ChangeVerticesOn().Add(n1);
01379        aFI.ChangeVerticesOn().Add(n2);
01380       }
01381       //
01382     }// else if (aType==TopAbs_FACE) {
01383   }// for (i=1; i<=aNbS; ++i) {
01384   //
01385   // 2.
01386   aItMFI.Initialize(myFaceInfo);
01387   for (; aItMFI.More(); aItMFI.Next()) {
01388     nF=aItMFI.Key();
01389     NMTTools_FaceInfo& aFI=*((NMTTools_FaceInfo*)&aItMFI.Value());
01390     //
01391     aFI.SetIndex(nF);
01392     //
01393     //
01394     // 2.1 aVFs
01395     aNbVFs=aVFs.Extent();
01396     for (j=1; j<=aNbVFs; ++j) {
01397       BOPTools_VSInterference& aVFj=aVFs(j);
01398       aVFj.Indices(n1, n2);
01399       if (nF==n1) {
01400        aFI.ChangeVerticesIn().Add(n2);
01401       }
01402       else if (nF==n2){
01403        aFI.ChangeVerticesIn().Add(n1);
01404       }
01405     }//  for (j=1; j<=aNbVFs; ++j) {
01406     //
01407     // 2.2 aEFs
01408     aNbEFs=aEFs.Extent();
01409     for (j=1; j<=aNbEFs; ++j) {
01410       BOPTools_ESInterference& aEFj=aEFs(j);
01411       aEFj.Indices(n1, n2);
01412       if (!(nF==n1 || nF==n2)) {
01413        continue;
01414       }
01415       //
01416       nX=aEFj.NewShape();
01417       if (nX<1) {
01418        continue;
01419       }
01420       //
01421       aS=myDS->Shape(nX);
01422       aType=aS.ShapeType();
01423       if (aType!=TopAbs_VERTEX) {
01424        continue;
01425       }
01426       //
01427       aFI.ChangeVerticesIn().Add(nX);
01428     }//  for (j=1; j<=aNbEFs; ++j) {
01429   }// for (; aItMFI.More(); aItMFI.Next()) {
01430 }
01431 
01432 
01433 #include <gp_Pnt.hxx>
01434 #include <gp_Dir.hxx>
01435 #include <gp_Vec.hxx>
01436 #include <GeomAPI_ProjectPointOnSurf.hxx>
01437 //=======================================================================
01438 //function : CorrectTolR3D
01439 //purpose  : Attempt to correct the value of tolerance aTolR3D for
01440 //           the intersection curve in order to
01441 //           compel it to pass through the sticks.
01442 //           Prerequisites:
01443 //             2. The are based on B-Spline surfaces;
01444 //             1. There is at least the one intersection curve;
01445 //             2. The faces have stick vertices to catch the curve;
01446 //             3. The intersection angle is rather small (0.7-7 deg)
01447 //
01448 //=======================================================================
01449 void NMTTools_PaveFiller::CorrectTolR3D(const BOPTools_SSInterference& aFF,
01450                                    const TColStd_MapOfInteger& aMVStick,
01451                                    Standard_Real& aTolR3D)
01452 
01453 {
01454   Standard_Boolean bHasBounds;
01455   Standard_Integer i, nF[2], nV, aNbCurves;
01456   Standard_Real aT1, aT2, aU, aV, aT, aA, aTolV, aTolVmax;
01457   Standard_Real aTolR, aTolTresh, aAmin, aAmax;
01458   TColStd_MapIteratorOfMapOfInteger aIt;
01459   gp_Pnt aP, aP1, aP2;
01460   gp_Dir aDN[2];
01461   gp_Vec aVT;
01462   Handle(Geom_Surface) aS[2];
01463   Handle(Geom_Curve) aC3D;
01464   GeomAdaptor_Surface aGAS;
01465   GeomAbs_SurfaceType aType;
01466   TopoDS_Face aF[2];
01467   //
01468   aTolTresh=0.0005;
01469   aAmin=0.012;// 0.7-7 deg
01470   aAmax=0.12;
01471   //
01472   if (!aMVStick.Extent()) {
01473     return;
01474   }
01475   //
01476   BOPTools_SSInterference& aFFi=*((BOPTools_SSInterference*)&aFF);
01477   BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
01478   aNbCurves=aSCvs.Length();
01479   if (aNbCurves!=1){
01480     return;
01481   }
01482   //
01483   aFFi.Indices(nF[0], nF[1]);
01484   for (i=0; i<2; ++i) {
01485     aF[i]=*((TopoDS_Face*)(&myDS->Shape(nF[i])));
01486     aS[i]=BRep_Tool::Surface(aF[i]);
01487     aGAS.Load(aS[i]);
01488     aType=aGAS.GetType();
01489     if (aType!=GeomAbs_BSplineSurface) {
01490       return;
01491     }
01492   }
01493   //
01494   BOPTools_Curve& aBC=aSCvs(1);
01495   const IntTools_Curve& aIC=aBC.Curve();
01496   bHasBounds=aIC.HasBounds();
01497   if (!bHasBounds){
01498     return;
01499   }
01500   //
01501   aIC.Bounds (aT1, aT2, aP1, aP2);
01502   aT=IntTools_Tools::IntermediatePoint(aT1, aT2);
01503   aC3D=aIC.Curve();
01504   aC3D->D0(aT, aP);
01505   //
01506   for (i=0; i<2; ++i) {
01507     GeomAPI_ProjectPointOnSurf& aPPS=myContext->ProjPS(aF[i]);
01508     aPPS.Perform(aP);
01509     aPPS.LowerDistanceParameters(aU, aV);
01510     BOPTools_Tools3D::GetNormalToSurface(aS[i], aU, aV, aDN[i]);
01511   }
01512   //
01513   aA=aDN[0].Angle(aDN[1]);
01514   aA=fabs(aA);
01515   if (aA > 0.5*M_PI) {
01516     aA = M_PI - aA;
01517   }
01518   //
01519   if (aA<aAmin || aA>aAmax) {
01520     return;
01521   }
01522   //
01523   aTolVmax=-1.;
01524   aIt.Initialize(aMVStick);
01525   for (; aIt.More(); aIt.Next()) {
01526     nV=aIt.Key();
01527     const TopoDS_Vertex& aV=*((TopoDS_Vertex*)(&myDS->Shape(nV)));
01528     aTolV=BRep_Tool::Tolerance(aV);
01529     if (aTolV>aTolVmax) {
01530       aTolVmax=aTolV;
01531     }
01532   }
01533   //
01534 
01535   aTolR=aTolVmax/aA;
01536   if (aTolR<aTolTresh) {
01537     aTolR3D=aTolR;
01538   }
01539 }
01540 
01541 //modified by NIZNHY-PKV Wed Sep 14 13:21:13 2011f
01542 #if OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
01543 //=======================================================================
01544 // function: PutClosingPaveOnCurve
01545 // purpose:
01546 //=======================================================================
01547 void NMTTools_PaveFiller::PutClosingPaveOnCurve(BOPTools_Curve& aBC,
01548                                           BOPTools_SSInterference& aFFi)
01549 {
01550   Standard_Boolean bIsClosed, bHasBounds, bAdded;
01551   Standard_Integer nVC, j;
01552   Standard_Real aT[2], aTolR3D, aTC, dT, aTx;
01553   gp_Pnt aP[2] ;
01554   BOPTools_Pave aPVx;
01555   BOPTools_ListIteratorOfListOfPave aItLP;
01556   //
01557   const IntTools_Curve& aIC=aBC.Curve();
01558   const Handle (Geom_Curve)& aC3D=aIC.Curve();
01559   if(aC3D.IsNull()) {
01560     return;
01561   }
01562   //
01563   bIsClosed=IntTools_Tools::IsClosed(aC3D);
01564   if (!bIsClosed) {
01565     return;
01566   }
01567   //
01568   bHasBounds=aIC.HasBounds ();
01569   if (!bHasBounds){
01570     return;
01571   }
01572   //
01573   bAdded=Standard_False;
01574   dT=Precision::PConfusion();
01575   aTolR3D=aFFi.TolR3D();
01576   aIC.Bounds (aT[0], aT[1], aP[0], aP[1]);
01577   //
01578   BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
01579   BOPTools_PaveSet& aCPS=aBC.Set();
01580   //
01581   const BOPTools_ListOfPave& aLP=aCPS.Set();
01582   aItLP.Initialize(aLP);
01583   for (; aItLP.More() && !bAdded; aItLP.Next()) {
01584     const BOPTools_Pave& aPC=aItLP.Value();
01585     nVC=aPC.Index();
01586     const TopoDS_Vertex aVC=TopoDS::Vertex(myDS->Shape(nVC));
01587     aTC=aPC.Param();
01588     //
01589     for (j=0; j<2; ++j) {
01590       if (fabs(aTC-aT[j]) < dT) {
01591        aTx=(!j) ? aT[1] : aT[0];
01592        aPVx.SetIndex(nVC);
01593        aPVx.SetParam(aTx);
01594        //
01595        aCPS.Append(aPVx);
01596        aFFiPS.Append(aPVx);
01597        //
01598        bAdded=Standard_True;
01599        break;
01600       }
01601     }
01602   }
01603 }
01604 #endif // OCC_VERSION_LARGE > 0x06050100 // For OCCT6.5.2 and higher
01605 //modified by NIZNHY-PKV Wed Sep 14 13:21:17 2011t