]> SALOME platform Git repositories - modules/geom.git/blob - src/NMTTools/NMTTools_PaveFiller_6.cxx
Salome HOME
New version of PartitionAlgo.
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_6.cxx
1 //
2 // IMPROVED by NIZNHY-PKV Thu Oct 12 16:03:33 2006
3 //
4 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // 
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.
11 // 
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.
16 //
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
20 //
21 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 //
23 // File:        NMTTools_PaveFiller_6.cxx
24 // Created:     Fri Dec 19 10:27:31 2003
25 // Author:      Peter KURNEV
26 //              <pkv@irinox>
27
28 #include <NMTTools_PaveFiller.ixx>
29
30 #include <Precision.hxx>
31
32 #include <TColStd_IndexedMapOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34
35 #include <Geom2d_Curve.hxx>
36 #include <Geom_TrimmedCurve.hxx>
37
38 #include <GeomAdaptor_Curve.hxx>
39 #include <BndLib_Add3dCurve.hxx>
40
41 #include <TopoDS_Face.hxx>
42 #include <TopoDS.hxx>
43 #include <TopoDS_Compound.hxx>
44
45 #include <TopExp.hxx>
46
47 #include <BRep_Builder.hxx>
48 #include <BRep_Tool.hxx>
49 #include <BRepBndLib.hxx>
50
51 #include <TopTools_IndexedMapOfShape.hxx>
52
53 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
54 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
55
56 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
57 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
58 #include <BooleanOperations_OnceExplorer.hxx>
59 #include <BooleanOperations_ShapesDataStructure.hxx>
60
61 #include <IntTools_SequenceOfPntOn2Faces.hxx>
62 #include <IntTools_SequenceOfCurves.hxx>
63 #include <IntTools_FaceFace.hxx>
64 #include <IntTools_Tools.hxx>
65
66 #include <BOPTools_CArray1OfSSInterference.hxx>
67 #include <BOPTools_ListIteratorOfListOfInterference.hxx>
68 #include <BOPTools_CArray1OfInterferenceLine.hxx>
69 #include <BOPTools_InterferenceLine.hxx>
70 #include <BOPTools_ListOfInterference.hxx>
71 #include <BOPTools_Interference.hxx>
72 #include <BOPTools_InterferencePool.hxx>
73 #include <BOPTools_SSInterference.hxx>
74 #include <BOPTools_ListOfPaveBlock.hxx>
75 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
76 #include <BOPTools_PaveBlock.hxx>
77 #include <BOPTools_ListIteratorOfListOfPave.hxx>
78 #include <BOPTools_Tools.hxx>
79 #include <BOPTools_PaveBlockIterator.hxx>
80 #include <BOPTools_Tools2D.hxx>
81
82 #include <NMTDS_ShapesDataStructure.hxx>
83 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
84 #include <NMTTools_CommonBlockAPI.hxx>
85 #include <Geom2d_Curve.hxx>
86 #include <NMTTools_Tools.hxx>
87 #include <BRepLib.hxx>
88 #include <Geom2d_TrimmedCurve.hxx>
89 //
90 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
91 #include <TopTools_ListOfShape.hxx>
92 #include <TopTools_ListIteratorOfListOfShape.hxx>
93 #include <TopoDS_Vertex.hxx>
94 #include <TopoDS.hxx>
95 #include <TopoDS_Edge.hxx>
96 #include <TColStd_ListOfInteger.hxx>
97 ////
98 #include <NMTTools_DataMapOfIntegerListOfPaveBlock.hxx>
99 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
100 #include <TColStd_ListIteratorOfListOfInteger.hxx>
101 #include <NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock.hxx>
102 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
103 #include <TColStd_MapOfInteger.hxx>
104 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
105 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
106 #include <TColStd_ListOfInteger.hxx>
107 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
108 #include <TColStd_ListIteratorOfListOfInteger.hxx>
109 #include <NMTTools_MapOfPaveBlock.hxx>
110
111 static 
112   Standard_Boolean IsPairFound(const Standard_Integer nF1,
113                                const Standard_Integer nF2,
114                                BOPTools_InterferencePool* myIntrPool,
115                                BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
116                                BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith);
117
118 static
119   void FMapWhat(const Standard_Integer nF,
120                 BOPTools_InterferencePool* myIntrPool,
121                 TColStd_IndexedMapOfInteger& aMapWhat);
122 static
123   void FMapWith(const Standard_Integer nF,
124                 BOPTools_InterferencePool* myIntrPool,
125                 TColStd_IndexedMapOfInteger& aMapWith);
126 static
127   Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
128                            const TColStd_IndexedMapOfInteger& aMapWith);
129
130 // Modified  Thu Sep 14 14:35:18 2006 
131 // Contribution of Samtech www.samcef.com BEGIN
132 static
133   void SharedEdges1(const TopoDS_Face& aF1,
134                     const TopoDS_Face& aF2,
135                     TopTools_ListOfShape& aLS);
136 // Contribution of Samtech www.samcef.com END
137
138 //=======================================================================
139 // function: PerformFF
140 // purpose: 
141 //=======================================================================
142   void NMTTools_PaveFiller::PerformFF() 
143 {
144   myIsDone=Standard_False;
145   //
146   Standard_Boolean bIsFound, bJustAdd, bIsComputed;
147   Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
148   Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
149   Standard_Integer aNbCurves, aNbPoints;
150   Standard_Real anApproxTol, aTolR3D, aTolR2D;
151   BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
152   IntTools_SequenceOfPntOn2Faces aPnts;
153   IntTools_SequenceOfCurves aCvs;
154   BooleanOperations_KindOfInterference aTypeFF=BooleanOperations_SurfaceSurface;
155   //
156   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
157   //
158   //  F/F Interferences  [BooleanOperations_SurfaceSurface]
159   myDSIt.Initialize(TopAbs_FACE, TopAbs_FACE);
160   //
161   // BlockLength correction
162   aNbFFs=ExpectedPoolLength();
163   aBlockLength=aFFs.BlockLength();
164   if (aNbFFs > aBlockLength) {
165     aFFs.SetBlockLength(aNbFFs);
166   }
167   //
168   for (; myDSIt.More(); myDSIt.Next()) {
169     myDSIt.Current(n1, n2, bJustAdd);
170     //
171     bIsComputed=myIntrPool->IsComputed(n1, n2);
172     if (bIsComputed) {
173       continue;
174     }
175     //
176     nF1 = n2;
177     nF2 = n1;
178     if(n1 < n2) {
179       nF1 = n1;
180       nF2 = n2;
181     }
182     anIndexIn=0;
183     aPnts.Clear();
184     aCvs.Clear();
185     //
186     bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
187     //
188     if (bJustAdd) {
189       if (!bIsFound) {
190         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
191       }
192       else{
193         BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
194         anIndexIn=aFFs.Append(anInterf);
195         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
196       }
197       continue;
198     }
199     //
200     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
201     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
202     //
203     // FF
204     bToApproxC3d     = mySectionAttribute.Approximation();
205     bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
206     bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
207     //
208     anApproxTol=1.e-7;
209     //
210     IntTools_FaceFace aFF;
211     //
212     aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1, 
213                        bToApproxC2dOnS2, anApproxTol);
214     //
215     aFF.Perform(aF1, aF2);
216     //
217     bIsDone=aFF.IsDone();
218     //
219     if (!bIsDone) {
220       if (!bIsFound) {
221         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
222       }
223       else {
224         BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
225         anIndexIn=aFFs.Append(anInterf);
226         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
227       }
228       continue;
229     }
230     //
231     aTolR3D=aFF.TolReached3d();
232     aTolR2D=aFF.TolReached2d();
233     if (aTolR3D < 1.e-7){
234       aTolR3D=1.e-7;
235     } 
236     //
237     aFF.PrepareLines3D();
238     //
239     const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
240     const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
241     //
242     aNbCurves=aCvsX.Length();
243     aNbPoints=aPntsX.Length();
244     //
245     if (!aNbCurves && !aNbPoints) {
246       BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
247       anIndexIn=aFFs.Append(anInterf);
248       myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
249       continue;
250     }
251     //
252     {
253       BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
254       anIndexIn=aFFs.Append(anInterf);
255       myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
256     }
257     //
258   }// for (; myDSIt.More(); myDSIt.Next()) 
259   //
260   myIsDone=Standard_True;
261 }
262 //=======================================================================
263 // function: MakeBlocks
264 // purpose: 
265 //=======================================================================
266   void NMTTools_PaveFiller::MakeBlocks()
267 {
268   myIsDone=Standard_False;
269   //
270   // Modified  Thu Sep 14 14:35:18 2006 
271   // Contribution of Samtech www.samcef.com BEGIN
272   Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D;//, bIsCoincided;
273   // Contribution of Samtech www.samcef.com END
274   //
275   Standard_Integer i, aNbFFs, nF1, nF2, aBid=0;
276   Standard_Integer nV1, nV2, j, aNbCurves;
277   Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
278   NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
279   BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
280   BOPTools_ListIteratorOfListOfPaveBlock anIt;  
281   //
282   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
283   //
284   aNbFFs=aFFs.Extent();
285   //
286   NMTTools_DataMapOfIntegerListOfPaveBlock aMFInOn;
287   NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock aItMF;
288   //
289   {
290     Standard_Integer aNbS, aNbF, nF, aNbOn, nSp;
291     TopAbs_ShapeEnum aType;
292     BOPTools_ListIteratorOfListOfPaveBlock anItPB;
293     NMTTools_ListIteratorOfListOfCommonBlock aItCB;
294     TColStd_ListIteratorOfListOfInteger aItF;
295     //
296     aNbS=myDS->NumberOfShapesOfTheObject();
297     for (i=1; i<=aNbS; ++i) {
298       const TopoDS_Shape& aS=myDS->Shape(i);
299       aType=aS.ShapeType();
300       //
301       if (aType==TopAbs_EDGE) {
302         const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
303         aItCB.Initialize(aLCB);
304         for (; aItCB.More(); aItCB.Next()) {
305           const NMTTools_CommonBlock& aCB=aItCB.Value();
306           const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
307           //
308           const TColStd_ListOfInteger& aLF=aCB.Faces();
309           aNbF=aLF.Extent();
310           if (aNbF) { 
311             aItF.Initialize(aLF);
312             for (; aItF.More(); aItF.Next()) {
313               nF=aItF.Value();
314               if (aMFInOn.IsBound(nF)) {
315                 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
316                 aLPB.Append(aPB1);
317               }
318               else {
319                 BOPTools_ListOfPaveBlock aLPB;
320                 aLPB.Append(aPB1);
321                 aMFInOn.Bind(nF, aLPB);
322               }
323             }
324           }// if (aNbF) { 
325         } // for (; aItCB.More(); aItCB.Next()) {
326       }//if (aS.ShapeType()==TopAbs_EDGE) {
327       //
328       else if (aType==TopAbs_FACE) {
329         BOPTools_ListOfPaveBlock aLPBOn;
330         //
331         nF=i;
332         RealSplitsFace(nF, aLPBOn);
333         //
334         aNbOn=aLPBOn.Extent();
335         if (aNbOn) {
336           if (aMFInOn.IsBound(nF)) {
337             BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
338             aLPB.Append(aLPBOn);
339           }
340           else {
341             aMFInOn.Bind(nF, aLPBOn);
342           }
343         }
344       }
345     } // for (i=1; i<=aNbS; ++i) { 
346     // 
347     // Refine ListOfPaveBlocks
348     aItMF.Initialize(aMFInOn);
349     for(; aItMF.More(); aItMF.Next()) {
350       TColStd_MapOfInteger aMTmp;
351       BOPTools_ListOfPaveBlock aLPBX;
352       //
353       nF=aItMF.Key();
354       BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
355       anItPB.Initialize(aLPB);
356       for (; anItPB.More(); anItPB.Next()) {
357         const BOPTools_PaveBlock& aPB=anItPB.Value();
358         nSp=aPB.Edge();
359         if (aMTmp.Add(nSp)) {
360           aLPBX.Append(aPB);
361         }
362       }
363       aLPB.Clear();
364       aLPB.Append(aLPBX);
365     }
366   }
367   //
368   // 1. Produce Section Edges from intersection curves
369   //    between each pair of faces
370   //
371   aNbFFs=aFFs.Extent();
372   //
373   for (i=1; i<=aNbFFs; ++i) {
374     
375     BOPTools_SSInterference& aFFi=aFFs(i);
376     // 
377     // Faces
378     aFFi.Indices(nF1, nF2);
379     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
380     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
381     //
382     BOPTools_ListOfPaveBlock aLPB;
383     //
384     {
385       BOPTools_ListIteratorOfListOfPaveBlock anItPB;
386       NMTTools_MapOfPaveBlock aMPB;
387       //
388       if (aMFInOn.IsBound(nF1)) {
389         const BOPTools_ListOfPaveBlock& aLPBF1=aMFInOn.Find(nF1);
390         anItPB.Initialize(aLPBF1);
391         for (; anItPB.More(); anItPB.Next()) {
392           const BOPTools_PaveBlock& aPB=anItPB.Value();
393           if (aMPB.Add(aPB)) {
394             aLPB.Append(aPB);
395           }
396         }
397       }
398       if (aMFInOn.IsBound(nF2)) {
399         const BOPTools_ListOfPaveBlock& aLPBF2=aMFInOn.Find(nF2);
400         anItPB.Initialize(aLPBF2);
401         for (; anItPB.More(); anItPB.Next()) {
402           const BOPTools_PaveBlock& aPB=anItPB.Value();
403           if (aMPB.Contains(aPB)) {
404             aFFi.AppendBlock(aPB);
405           }
406           else {
407             aLPB.Append(aPB);
408           }
409         }
410       }
411     }
412     //
413     TopTools_ListOfShape aLSE;
414     TColStd_ListOfInteger aLNE;
415     SharedEdges(nF1, nF2, aLNE, aLSE);
416     aFFi.SetSharedEdges(aLNE);
417     //
418     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
419     aNbCurves=aSCvs.Length();
420     if (!aNbCurves) {
421       continue;
422     }
423     //
424     // Contribution of Samtech www.samcef.com END
425     aTolR3D=aFFi.TolR3D();
426     aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
427     //
428     BOPTools_PaveSet aPSF;
429     //
430     PrepareSetForFace (nF1, nF2, aLPB, aPSF);
431     //
432     // Put Paves On Curves
433     for (j=1; j<=aNbCurves; ++j) {
434       BOPTools_Curve& aBC=aSCvs(j);
435       // DEBUG
436       const IntTools_Curve& aC=aBC.Curve();
437       Handle (Geom_Curve) aC3D= aC.Curve();
438       //
439       PutPaveOnCurve (aPSF, aTolR3D, aBC);
440     }
441     //
442     // Put bounding paves on curves
443     for (j=1; j<=aNbCurves; ++j) {
444       BOPTools_Curve& aBC=aSCvs(j);
445       PutBoundPaveOnCurve (aBC, aFFi);
446     }
447     //
448     //  Pave Blocks on Curves
449     for (j=1; j<=aNbCurves; ++j) {
450       BOPTools_Curve& aBC=aSCvs(j);
451       const IntTools_Curve& aIC= aBC.Curve();
452       BOPTools_PaveSet& aPaveSet=aBC.Set();
453       //
454       BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
455       for (; aPBIter.More(); aPBIter.Next()) {
456         BOPTools_PaveBlock& aPBNew=aPBIter.Value();
457         aPBNew.SetCurve(aIC);
458         aPBNew.SetFace1(nF1);
459         aPBNew.SetFace2(nF2);
460         //
461         nV1=aPBNew.Pave1().Index();
462         nV2=aPBNew.Pave2().Index();
463         aT1=aPBNew.Pave1().Param();
464         aT2=aPBNew.Pave2().Param();
465         // ???
466         if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
467           continue;// mkk ft
468         }
469         //
470         // 1
471         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPB, aTolR3D);
472         if (bIsExistingPaveBlock) {
473           continue;
474         }
475         //
476         // Modified  
477         // to provide checking whether aPBNew already exists in list
478         // of section edges aLSE
479         // Thu Sep 14 14:35:18 2006 
480         // Contribution of Samtech www.samcef.com BEGIN
481         // 3
482         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLSE, aTolR3D);
483         if (bIsExistingPaveBlock) {
484           continue;
485         }
486         // Contribution of Samtech www.samcef.com END
487         //
488         // Checking of validity in 2D
489         //
490         bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
491         if (!bIsValidIn2D) {
492           continue;
493         }
494         //
495         //aBC.AppendNewBlock(aPBNew);
496         //
497         // Make Section Edge  
498         TopoDS_Edge aES;
499         //
500         const TopoDS_Vertex aV1=TopoDS::Vertex(myDS->Shape(nV1));//mpv
501         const TopoDS_Vertex aV2=TopoDS::Vertex(myDS->Shape(nV2));//mpv
502         //
503         BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
504         //
505         {
506           Standard_Real aTolR2D;
507           //
508           aTolR2D=aFFi.TolR2D();
509           Handle(Geom2d_Curve) aC2D1=aIC.FirstCurve2d();
510           Handle(Geom2d_Curve) aC2D2=aIC.SecondCurve2d();
511           //
512           NMTTools_Tools::MakePCurve(aES, aF1, aC2D1, aTolR2D);
513           NMTTools_Tools::MakePCurve(aES, aF2, aC2D2, aTolR2D);
514         }
515         //
516         aMEPB.Add(aES, aPBNew);
517         aMapEI.Add(aES, i);
518       }
519       
520     } // end of for (j=1; j<=aNbCurves; ++j)
521   }// for (i=1; i<=aNbFFs; ++i)
522   //=============================================================
523   //
524   // II. Post treatment 
525   //
526   // Input data: aMEPB, aMapEI
527   // Result    : section edges in myDS
528   //
529   Standard_Integer aNbSE;
530   //
531   aNbSE=aMEPB.Extent();
532   if (!aNbSE) {
533     // there is nothing to do here
534     return;
535   } 
536   //
537   BRep_Builder aBB;
538   TopoDS_Compound aCompound;
539   //
540   // 1. Make compound from SE
541   aBB.MakeCompound(aCompound);
542   for (i=1; i<=aNbSE; ++i) {
543     const TopoDS_Shape& aSE=aMEPB.FindKey(i);
544     aBB.Add(aCompound, aSE);
545   }
546   //
547   //
548   // 2. Intersect SE using auxiliary Filler
549   NMTDS_ShapesDataStructure tDS;
550   //
551   tDS.SetCompositeShape(aCompound);
552   tDS.Init();
553   //
554   BOPTools_InterferencePool tIP(tDS);
555   NMTTools_PaveFiller tPF(tIP);
556   //
557   // 2.1.VV
558   tPF.Init();
559   tPF.PerformVV();
560   tPF.PerformNewVertices();
561   //
562   // 2.2.VE
563   tPF.myPavePool.Resize (tPF.myNbEdges);
564   tPF.PrepareEdges();
565   tPF.PerformVE();
566   //
567   // 2.3.VF
568   tPF.PerformVF();
569   //
570   // 2.4.EE
571   tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
572   tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
573   tPF.myPavePoolNew    .Resize (tPF.myNbEdges);
574   
575   tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
576   tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
577   //
578   tPF.PerformEE();
579   //
580   tPF.RefinePavePool ();
581   //
582   tPF.myPavePoolNew.Destroy();
583   //
584   tPF.MakeSplitEdges();
585   tPF.UpdateCommonBlocks();
586   //
587   // 3. Treatment of the result of intersection
588   //
589   Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
590   TopAbs_ShapeEnum aType;
591   BOPTools_ListIteratorOfListOfPaveBlock aIt;
592   BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
593   //
594   const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
595   const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
596   //
597   aNbLines=tDS.NumberOfInsertedShapes();
598   aNbOld=tDS.NumberOfShapesOfTheObject();
599   // 
600   // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
601   //
602   // 3.1.1.Old vertices [ links ]
603   for (i=1; i<=aNbOld; ++i) {
604     const TopoDS_Shape& aV=tDS.Shape(i);
605     aType=aV.ShapeType();
606     if (aType!=TopAbs_VERTEX) {
607       continue;
608     }
609     //
610     for (j=1; j<=aNbSE; ++j) {
611       const BOPTools_PaveBlock& aPBSE=aMEPB(j);
612       nV1=aPBSE.Pave1().Index();
613       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
614       if (aV1.IsSame(aV)) {
615         aMNewOld.Add(i, nV1);
616         break;
617       }
618       nV2=aPBSE.Pave2().Index();
619       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
620       if (aV2.IsSame(aV)) {
621         aMNewOld.Add(i, nV2);
622         break;
623       }
624     }
625   }
626   //
627   // 3.1.2. New vertices [ links ]
628   i=tDS.NumberOfSourceShapes()+1;
629   for (; i<=aNbLines; ++i) {
630     const TopoDS_Shape& aV=tDS.Shape(i);
631     aType=aV.ShapeType();
632     if (aType!=TopAbs_VERTEX) {
633       continue;
634     }
635     //
636     // Insert new vertex in myDS
637     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
638     myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
639     nV1=myDS->NumberOfInsertedShapes();
640     // link
641     aMNewOld.Add(i, nV1);
642   }
643   //
644   // 3.2. Treatment of section edges (SE)
645   for (i=1; i<=aNbOld; ++i) {
646     const TopoDS_Shape& aE=tDS.Shape(i);
647     aType=aE.ShapeType();
648     if (aType!=TopAbs_EDGE) {
649       continue;
650     }
651     //
652     //  block of section edge that we already have for this SE
653     BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
654     //
655     // Corresponding FF-interference
656     iFF=aMapEI.FindFromKey(aE);
657     BOPTools_SSInterference& aFFi=aFFs(iFF);
658     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
659     //
660     BOPTools_Curve& aBC=aSCvs(1); 
661     //
662     const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
663     aNbPB=aLPB.Extent();
664     //
665     if (!aNbPB) {
666       // no pave blocks -> use aPBSE and whole edge aE
667       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
668       //
669       nV1=aPBSE.Pave1().Index();
670       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
671       nV2=aPBSE.Pave2().Index();
672       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
673       //
674       anASSeq.SetNewSuccessor(nV1);
675       anASSeq.SetNewOrientation(aV1.Orientation());
676       anASSeq.SetNewSuccessor(nV2);
677       anASSeq.SetNewOrientation(aV2.Orientation());
678       //
679       myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
680       nE=myDS->NumberOfInsertedShapes();
681       //
682       aPBSE.SetEdge(nE);
683       aBC.AppendNewBlock(aPBSE);
684       //
685       continue;
686     }
687     //
688     nF1=aPBSE.Face1();
689     nF2=aPBSE.Face2();
690     //
691     const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
692     NMTTools_CommonBlockAPI aCBAPI(aLCB);
693     //
694     aIt.Initialize(aLPB);
695     for (; aIt.More(); aIt.Next()) {
696       BOPTools_PaveBlock aPB=aIt.Value();
697       //
698       const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));
699       const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));
700       //
701       if (aCBAPI.IsCommonBlock(aPB)) {
702         // it can be Common Block
703         Standard_Real aTolEx;
704         Handle(Geom2d_Curve) aC2D1, aC2D2;
705         TopoDS_Face aF1FWD, aF2FWD;
706         //
707         NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
708         const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
709         //
710         aPB=aCB.PaveBlock1();
711         mE=aPB.Edge(); // index of edge in tDS
712         const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
713         aTolEx=BRep_Tool::Tolerance(aEx);
714         //
715         // The code till the if block end is restored from V2_2_2 revision
716         //
717         aF1FWD=aF1;
718         aF1FWD.Orientation(TopAbs_FORWARD);
719         NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1, aTolEx);
720         //
721         aF2FWD=aF2;
722         aF2FWD.Orientation(TopAbs_FORWARD);
723         NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2, aTolEx);
724       } //if (aCBAPI.IsCommonBlock(aPB))
725       //
726       // new SE
727       mE=aPB.Edge(); // index of edge in tDS
728       const TopoDS_Shape& aSp=tDS.Shape(mE);
729       //
730       const BOPTools_Pave& aPave1=aPB.Pave1();
731       aT1=aPave1.Param();
732       mV1=aPave1.Index();            // index in tDS
733       nV1=aMNewOld.FindFromKey(mV1); // index in myDS
734       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
735       //
736       const BOPTools_Pave& aPave2=aPB.Pave2();
737       aT2=aPave2.Param();
738       mV2=aPave2.Index();
739       nV2=aMNewOld.FindFromKey(mV2);
740       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
741       //
742       if (!aMNewOld.Contains(mE)) {
743         // add new SE to the myDS
744         BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
745         //
746         anASSeq.SetNewSuccessor(nV1);
747         anASSeq.SetNewOrientation(aV1.Orientation());
748
749         anASSeq.SetNewSuccessor(nV2);
750         anASSeq.SetNewOrientation(aV2.Orientation());
751         
752         myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
753         nE=myDS->NumberOfInsertedShapes();
754         //
755         aMNewOld.Add(mE, nE);
756       }
757       else {
758         nE=aMNewOld.FindFromKey(mE);
759       }
760       // Form PaveBlock;
761       BOPTools_PaveBlock aPBx;
762       BOPTools_Pave aP1, aP2;
763       //
764       aPBx.SetFace1(nF1);
765       aPBx.SetFace1(nF2);
766       //
767       aP1.SetIndex(nV1);
768       aP1.SetParam(aT1);
769       //
770       aP2.SetIndex(nV2);
771       aP2.SetParam(aT2);
772       //
773       aPBx.SetPave1(aP1);
774       aPBx.SetPave2(aP2);
775       //
776       aPBx.SetEdge(nE);
777       //
778       aBC.AppendNewBlock(aPBx);
779     }// for (; aIt.More(); aIt.Next()) 
780   }// for (i=1; i<=aNbOld; ++i) 
781   //
782   myIsDone=Standard_True;
783 }
784 //=======================================================================
785 // function: MakePCurves
786 // purpose: 
787 //=======================================================================
788   void NMTTools_PaveFiller::MakePCurves()
789 {
790   Standard_Integer i, aNb,  nF1, nF2, nE;
791   TopoDS_Face aF1FWD, aF2FWD;
792   BOPTools_ListIteratorOfListOfPaveBlock anIt;
793   //
794   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
795   //
796   aNb=aFFs.Extent();
797   for (i=1; i<=aNb; i++) {
798     BOPTools_SSInterference& aFF=aFFs(i);
799     aFF.Indices(nF1, nF2);
800     //
801     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
802     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
803     //
804     aF1FWD=aF1;
805     aF1FWD.Orientation(TopAbs_FORWARD);
806     aF2FWD=aF2;
807     aF2FWD.Orientation(TopAbs_FORWARD);
808     //
809     // In, On parts processing
810     const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
811     //
812     anIt.Initialize(aLPBInOn);
813     for (; anIt.More(); anIt.Next()) {
814       const BOPTools_PaveBlock& aPB=anIt.Value();
815       nE=aPB.Edge();
816       const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
817       
818       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
819       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
820     }
821   } 
822 }
823 //=======================================================================
824 // function: IsExistingPaveBlock
825 // purpose: 
826 //=======================================================================
827    Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
828                                                              const BOPTools_ListOfPaveBlock& aLPBR,
829                                                              const Standard_Real aTolR3D)
830 {
831   Standard_Boolean bFlag;
832   Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
833   BOPTools_ListIteratorOfListOfPaveBlock anIt;
834   //
835   bFlag=Standard_False;
836   nVNew1=aPBNew.Pave1().Index();
837   nVNew2=aPBNew.Pave2().Index();
838   //
839   anIt.Initialize(aLPBR);
840   for (; anIt.More(); anIt.Next()) {
841     const BOPTools_PaveBlock& aPBR=anIt.Value();
842     nV1=aPBR.Pave1().Index();
843     nV2=aPBR.Pave2().Index();
844     if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
845       //
846       iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
847       if (!iC) {
848         return !bFlag;
849       }
850     }
851   }
852   return bFlag;
853 }
854 //=======================================================================
855 // function: IsExistingPaveBlock
856 // purpose: 
857 //=======================================================================
858   Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
859                                                             const TopTools_ListOfShape& aLSE,
860                                                             const Standard_Real aTolR3D)
861 {
862   Standard_Boolean bFlag;
863   Standard_Integer aNbSE, iC;
864   TopTools_ListIteratorOfListOfShape anIt;
865   //
866   bFlag=Standard_False;
867   //
868   aNbSE=aLSE.Extent();
869   if (!aNbSE) {
870     return bFlag;
871   }
872   //
873   anIt.Initialize(aLSE);
874   for (; anIt.More(); anIt.Next()) {
875     const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
876     iC=CheckIntermediatePoint(aPBNew, aE, aTolR3D);
877     if (!iC) {
878       return !bFlag;
879     }
880   }
881   return bFlag;
882 }
883 //=======================================================================
884 // function: CheckIntermediatePoint
885 // purpose: 
886 //=======================================================================
887   Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
888                                                                const BOPTools_PaveBlock& aPBR,
889                                                                const Standard_Real aTolC)
890                                                          
891 {
892   Standard_Integer iVM, nE2;
893   //
894   nE2=aPBR.Edge();
895   const TopoDS_Edge aE2=TopoDS::Edge(myDS->Shape(nE2));//mpv
896   iVM=CheckIntermediatePoint(aPB, aE2, aTolC);
897   //
898   return iVM;
899 }
900 //=======================================================================
901 // function: CheckIntermediatePoint
902 // purpose: 
903 //=======================================================================
904   Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
905                                                                const TopoDS_Edge& aE2,
906                                                                const Standard_Real aTolC)
907 {
908   Standard_Real aT11, aT12, aTM, aTmp;
909   Standard_Integer iVM;
910   gp_Pnt aPM;
911   BRep_Builder aBB;
912   TopoDS_Vertex aVM;
913   // 
914   // Vertex
915   const BOPTools_Pave& aPave11=aPB.Pave1();
916   aT11=aPave11.Param();
917   // 
918   const BOPTools_Pave& aPave12=aPB.Pave2();
919   aT12=aPave12.Param();
920   //
921   aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
922   //
923   const IntTools_Curve& aIC=aPB.Curve();
924   aIC.D0(aTM, aPM);
925   //
926   aBB.MakeVertex (aVM, aPM, aTolC);
927   //
928   iVM=myContext.ComputeVE(aVM, aE2, aTmp); 
929   //
930   return iVM;
931 }
932 //=======================================================================
933 // function: PutBoundPaveOnCurve
934 // purpose: 
935 //=======================================================================
936   void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
937                                                 BOPTools_SSInterference& aFFi)
938
939   Standard_Boolean bHasBounds, bVF;
940   Standard_Integer nF1, nF2;
941   Standard_Real aT1, aT2, aTolR3D;
942   gp_Pnt aP1, aP2;
943   //
944   const IntTools_Curve& aIC=aBC.Curve();
945   bHasBounds=aIC.HasBounds ();
946   if (!bHasBounds){
947     return;
948   }
949   //
950   // Bounds
951   aIC.Bounds (aT1, aT2, aP1, aP2);
952   //
953   // Faces
954   aFFi.Indices(nF1, nF2);
955   aTolR3D=aFFi.TolR3D();
956   //
957   const TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));//mpv
958   const TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));//mpv
959   //
960   bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
961   if (bVF) {
962     PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
963   }
964   //
965   bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
966   if (bVF) {
967     PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
968   }
969 }
970 //=======================================================================
971 // function: PutBoundPaveOnCurve
972 // purpose: 
973 //=======================================================================
974   void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
975                                                 const Standard_Real aT,
976                                                 BOPTools_Curve& aBC,
977                                                 BOPTools_SSInterference& aFFi)
978
979   Standard_Boolean bFound1, bFound2;
980   Standard_Integer nV;
981   Standard_Real aTolV=aFFi.TolR3D();
982
983   BOPTools_Pave aPave1, aPave2, aPave;
984   BOPTools_PaveSet& aCPS=aBC.Set();
985   BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
986   const IntTools_Curve& aIC=aBC.Curve();
987   //
988   bFound1=FindPave(aP, aTolV, aCPS  , aPave1);
989   bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
990   //
991   if (!bFound1 && !bFound2) {
992     TopoDS_Vertex aNewVertex;
993     BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
994     //
995     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
996     myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
997     nV=myDS->NumberOfInsertedShapes();
998     aPave.SetIndex(nV);
999     aPave.SetParam(aT);
1000
1001     aCPS.Append(aPave);
1002     aFFiPS.Append(aPave);
1003     //
1004     // Append Techno Vertex to the Curve
1005     TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
1006     aTVs.Append(nV);
1007   }
1008   
1009   if (bFound1 && !bFound2) {
1010     nV=aPave1.Index();
1011     aPave.SetIndex(nV);
1012     aPave.SetParam(aT);
1013     aFFiPS.Append(aPave);
1014     //
1015     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1016     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1017   }
1018   
1019   if (!bFound1 && bFound2) {
1020     nV=aPave2.Index();
1021     aPave.SetIndex(nV);
1022     aPave.SetParam(aT);
1023     aCPS.Append(aPave);
1024     //
1025     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1026     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1027   }
1028 }
1029 //=======================================================================
1030 // function: FindPave
1031 // purpose: 
1032 //=======================================================================
1033   Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
1034                                                  const Standard_Real aTolPV, 
1035                                                  const BOPTools_PaveSet& aPS,
1036                                                  BOPTools_Pave& aPave)
1037 {
1038   Standard_Integer nV;
1039   Standard_Boolean bIsVertex=Standard_False;
1040  
1041   const BOPTools_ListOfPave& aLP=aPS.Set();
1042   BOPTools_ListIteratorOfListOfPave anIt(aLP);
1043   for (; anIt.More(); anIt.Next()) {
1044     const BOPTools_Pave& aPC=anIt.Value();
1045     nV=aPC.Index();
1046     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1047     bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
1048     if (bIsVertex) {
1049       aPave=aPC;
1050       return bIsVertex;
1051     }
1052   }
1053   return bIsVertex;
1054 }
1055 //=======================================================================
1056 // function: PrepareSetForFace
1057 // purpose: 
1058 //=======================================================================
1059   void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer ,//nF1,
1060                                               const Standard_Integer ,//nF2,
1061                                               const BOPTools_ListOfPaveBlock& aLPBC,
1062                                               BOPTools_PaveSet& aPSF)
1063 {
1064   Standard_Integer nV1, nV2; 
1065   TColStd_MapOfInteger aMap;
1066   BOPTools_ListIteratorOfListOfPaveBlock anIt;
1067   //
1068   anIt.Initialize(aLPBC);
1069   for (; anIt.More(); anIt.Next()) {
1070     const BOPTools_PaveBlock& aPB=anIt.Value();
1071     const BOPTools_Pave& aPave1=aPB.Pave1();
1072     nV1=aPave1.Index();
1073     if (!aMap.Contains(nV1)) {
1074       aMap.Add(nV1);
1075       aPSF.Append(aPave1);
1076     }
1077     const BOPTools_Pave& aPave2=aPB.Pave2();
1078     nV2=aPave2.Index();
1079     if (!aMap.Contains(nV2)) {
1080       aMap.Add(nV2);
1081       aPSF.Append(aPave2);
1082     }
1083   }
1084 }
1085 //=======================================================================
1086 // function: PutPaveOnCurve
1087 // purpose: 
1088 //=======================================================================
1089   void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
1090                                            const Standard_Real aTolR3D,
1091                                            BOPTools_Curve& aBC)
1092
1093   Standard_Integer nV;
1094   Standard_Boolean bIsVertexOnLine;
1095   Standard_Real aT;
1096   BOPTools_ListIteratorOfListOfPave anIt;
1097   Bnd_Box aBBC;
1098   GeomAdaptor_Curve aGAC;
1099   //
1100   const IntTools_Curve& aC=aBC.Curve();
1101   Handle (Geom_Curve) aC3D= aC.Curve();
1102   aGAC.Load(aC3D);
1103   BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
1104   //
1105   const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1106   anIt.Initialize(aLP);
1107   for (; anIt.More(); anIt.Next()) {
1108     const BOPTools_Pave& aPave=anIt.Value();
1109     //
1110     nV=aPave.Index();
1111     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1112     //
1113     Bnd_Box aBBV;
1114     BRepBndLib::Add(aV, aBBV);
1115     if (aBBC.IsOut(aBBV)){
1116       continue; 
1117     }
1118     //
1119     bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
1120     //
1121     if (bIsVertexOnLine) {
1122       BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1123       BOPTools_PaveSet& aPS=aBC.Set();
1124       aPS.Append(aPaveNew);
1125       //<-B
1126       BOPTools_Tools::UpdateVertex (aC, aT, aV);
1127     }
1128   }
1129 }
1130 /////////////
1131 //=======================================================================
1132 // function: IsPairFound
1133 // purpose: 
1134 //=======================================================================
1135 Standard_Boolean IsPairFound(const Standard_Integer nF1,
1136                              const Standard_Integer nF2,
1137                              BOPTools_InterferencePool* myIntrPool,
1138                              BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
1139                              BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith)
1140 {
1141   Standard_Boolean bIsFound;
1142   //
1143   if (!aMapWhat.Contains(nF1)) {
1144     TColStd_IndexedMapOfInteger aMWhat;
1145     FMapWhat(nF1, myIntrPool, aMWhat);
1146     aMapWhat.Add(nF1, aMWhat);
1147   }
1148   //
1149   if (!aMapWith.Contains(nF2)) {
1150     TColStd_IndexedMapOfInteger aMWith;
1151     FMapWith(nF2, myIntrPool, aMWith);
1152     aMapWith.Add(nF2, aMWith);
1153   }
1154   //
1155   const TColStd_IndexedMapOfInteger& aMWht=aMapWhat.FindFromKey(nF1);
1156   const TColStd_IndexedMapOfInteger& aMWit=aMapWith.FindFromKey(nF2);
1157   //
1158   bIsFound=IsFound(aMWht, aMWit);
1159   //
1160   return bIsFound;
1161 }
1162 //=======================================================================
1163 // function: FMapWhat
1164 // purpose: 
1165 //=======================================================================
1166 void FMapWhat(const Standard_Integer nF,
1167               BOPTools_InterferencePool* myIntrPool,
1168               TColStd_IndexedMapOfInteger& aMapWhat)
1169                     
1170 {
1171   Standard_Integer nE, nV;
1172  
1173   
1174
1175   BooleanOperations_ShapesDataStructure* myDS=myIntrPool->DS();
1176   BooleanOperations_OnceExplorer aExp(*myDS);
1177   //
1178   //  What
1179   aMapWhat.Add(nF);
1180   aExp.Init(nF, TopAbs_VERTEX);
1181   for (; aExp.More(); aExp.Next()) {
1182     nV=aExp.Current();
1183     aMapWhat.Add(nV);
1184   }
1185   //
1186   aExp.Init(nF, TopAbs_EDGE);
1187   for (; aExp.More(); aExp.Next()) {
1188     nE=aExp.Current();
1189     aMapWhat.Add(nE);
1190   }
1191 }
1192 //=======================================================================
1193 // function: FMapWith
1194 // purpose: 
1195 //=======================================================================
1196 void FMapWith(const Standard_Integer nF,
1197               BOPTools_InterferencePool* myIntrPool,
1198               TColStd_IndexedMapOfInteger& aMapWith)
1199 {
1200   TColStd_IndexedMapOfInteger aMapWhat;
1201   
1202   FMapWhat(nF, myIntrPool, aMapWhat);
1203   //
1204   // With
1205   Standard_Integer i, aNb, anIndex, aWhat, aWith;
1206   BOPTools_ListIteratorOfListOfInterference anIt;
1207   
1208   const BOPTools_CArray1OfInterferenceLine& anArrIL= myIntrPool->InterferenceTable();
1209
1210   aNb=aMapWhat.Extent();
1211   for (i=1; i<=aNb; i++) {
1212     aWhat=aMapWhat(i);
1213     
1214     const BOPTools_InterferenceLine& aWithLine=anArrIL(aWhat);
1215   
1216     const BOPTools_ListOfInterference& aLI=aWithLine.List();
1217     anIt.Initialize(aLI);
1218     for (; anIt.More(); anIt.Next()) {
1219       const BOPTools_Interference& anIntf=anIt.Value();
1220       anIndex=anIntf.Index();
1221       if (anIndex) {
1222         aWith=anIntf.With();
1223         aMapWith.Add(aWith);
1224       }
1225     }
1226   }
1227 }
1228 //=======================================================================
1229 // function: IsFound
1230 // purpose: 
1231 //=======================================================================
1232 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
1233                          const TColStd_IndexedMapOfInteger& aMapWith)
1234 {
1235   Standard_Boolean bFlag=Standard_False;
1236   Standard_Integer i, aNb, aWhat;
1237
1238   aNb=aMapWhat.Extent();
1239   for (i=1; i<=aNb; i++) {
1240     aWhat=aMapWhat(i);
1241     if (aMapWith.Contains(aWhat)) {
1242       return !bFlag;
1243     }
1244   }
1245   return bFlag;
1246 }
1247 // Modified  Thu Sep 14 14:35:18 2006 
1248 // Contribution of Samtech www.samcef.com BEGIN
1249 //=======================================================================
1250 //function : SharedEdges1
1251 //purpose  : 
1252 //=======================================================================
1253 void SharedEdges1(const TopoDS_Face& aF1,
1254                   const TopoDS_Face& aF2,
1255                   TopTools_ListOfShape& aLS)
1256 {
1257   Standard_Integer i, aNbE, aNbF;;
1258   TopTools_IndexedDataMapOfShapeListOfShape aMEF;
1259   //
1260   TopExp::MapShapesAndAncestors(aF1, TopAbs_EDGE, TopAbs_FACE, aMEF);
1261   TopExp::MapShapesAndAncestors(aF2, TopAbs_EDGE, TopAbs_FACE, aMEF);
1262   //
1263   aNbE=aMEF.Extent();
1264   for (i=1; i<=aNbE; ++i) {
1265     const TopTools_ListOfShape& aLF=aMEF.FindFromIndex(i);
1266     aNbF=aLF.Extent();
1267     if (aNbF>1) {
1268       if (aNbF==2) {
1269         const TopoDS_Shape& aF1x=aLF.First();
1270         const TopoDS_Shape& aF2x=aLF.Last();
1271         if (aF1x.IsSame(aF2x)) {
1272           continue;
1273         }
1274       }
1275       const TopoDS_Shape& aE=aMEF.FindKey(i);
1276       aLS.Append (aE);
1277     }
1278   }
1279 }
1280 //modified by NIZNHY-PKV Tue Oct 24 12:00:50 2006 
1281 // it seems that the method is not used  
1282 //=======================================================================
1283 // function: CheckCoincidence
1284 // purpose: 
1285 //=======================================================================
1286   Standard_Boolean NMTTools_PaveFiller::CheckCoincidence(const BOPTools_PaveBlock& aPBNew,
1287                                                          const BOPTools_ListOfPaveBlock& aLPBFF)
1288                                                          
1289 {
1290   Standard_Boolean bRet;
1291   Standard_Real aTE;
1292   Standard_Integer nV11, nV12, nV21, nV22, iVV, iVE, nE2;
1293   Standard_Integer iV, iCount, iCountExt;
1294   // V11
1295   const BOPTools_Pave& aPave11=aPBNew.Pave1();
1296   nV11=aPave11.Index();
1297   const TopoDS_Vertex& aV11=TopoDS::Vertex(myDS->Shape(nV11));
1298   
1299   // V12
1300   const BOPTools_Pave& aPave12=aPBNew.Pave2();
1301   nV12=aPave12.Index();
1302   const TopoDS_Vertex& aV12=TopoDS::Vertex(myDS->Shape(nV12));
1303   //
1304   iCountExt=1;
1305   iCount=0;
1306   BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPBFF);
1307   
1308   //
1309   for (; anIt.More(); anIt.Next()) {
1310     iCount=0;
1311     //
1312     const BOPTools_PaveBlock& aPBR=anIt.Value();
1313     // V21
1314     const BOPTools_Pave& aPave21=aPBR.Pave1();
1315     nV21=aPave21.Index();
1316     const TopoDS_Vertex& aV21=TopoDS::Vertex(myDS->Shape(nV21));
1317     // V22
1318     const BOPTools_Pave& aPave22=aPBR.Pave2();
1319     nV22=aPave22.Index();
1320     const TopoDS_Vertex& aV22=TopoDS::Vertex(myDS->Shape(nV22));
1321     // E2
1322     nE2=aPBR.Edge();
1323     const TopoDS_Edge& aE2=TopoDS::Edge(myDS->Shape(nE2));
1324     //
1325     // VV
1326     iV=0;
1327     iVV=IntTools_Tools::ComputeVV (aV11, aV21);
1328     if (!iVV) {
1329       iCount++;
1330       iV++;
1331       if (iCount>iCountExt) {
1332         break;
1333       }
1334     }
1335     //
1336     iVV=IntTools_Tools::ComputeVV (aV11, aV22);
1337     if (!iVV) {
1338       iCount++;
1339       iV++;
1340       if (iCount>iCountExt) {
1341         break;
1342       }
1343     }
1344     // VE
1345     if (!iV) {
1346       iVE=myContext.ComputeVE (aV11, aE2, aTE);
1347       if (!iVE) {
1348         iCount++;
1349         if (iCount>iCountExt) {
1350           break;
1351         }
1352       }
1353     }
1354     // VV
1355     iV=0;
1356     iVV=IntTools_Tools::ComputeVV (aV12, aV21);
1357     if (!iVV) {
1358       iCount++;
1359       iV++;
1360       if (iCount>iCountExt) {
1361         break;
1362       }
1363     }
1364     //
1365     iVV=IntTools_Tools::ComputeVV (aV12, aV22);
1366     if (!iVV) {
1367       iCount++;
1368       iV++;
1369       if (iCount>iCountExt) {
1370         break;
1371       }
1372     }
1373     // VE
1374     if (!iV) {
1375       iVE=myContext.ComputeVE (aV12, aE2, aTE);
1376       if (!iVE) {
1377         iCount++;
1378         if (iCount>iCountExt) {
1379           break;
1380         }
1381       }
1382     }
1383   } // next aPBR
1384   bRet=(Standard_Boolean)(iCount>iCountExt);
1385   return bRet;
1386 }
1387 //
1388 // Contribution of Samtech www.samcef.com END