Salome HOME
a7014e3038ceea9947a04e545584c44434df8acf
[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   //
369   // 1. Produce Section Edges from intersection curves
370   //    between each pair of faces
371   //
372   aNbFFs=aFFs.Extent();
373   //
374   for (i=1; i<=aNbFFs; ++i) {
375     
376     BOPTools_SSInterference& aFFi=aFFs(i);
377     // 
378     // Faces
379     aFFi.Indices(nF1, nF2);
380     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
381     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
382     //
383     BOPTools_ListOfPaveBlock aLPB;
384     //
385     //---
386     {
387       BOPTools_ListIteratorOfListOfPaveBlock anItPB;
388       NMTTools_MapOfPaveBlock aMPB;
389       //
390       if (aMFInOn.IsBound(nF1)) {
391         const BOPTools_ListOfPaveBlock& aLPBF1=aMFInOn.Find(nF1);
392         anItPB.Initialize(aLPBF1);
393         for (; anItPB.More(); anItPB.Next()) {
394           const BOPTools_PaveBlock& aPB=anItPB.Value();
395           if (aMPB.Add(aPB)) {
396             aLPB.Append(aPB);
397           }
398         }
399       }
400       if (aMFInOn.IsBound(nF2)) {
401         const BOPTools_ListOfPaveBlock& aLPBF2=aMFInOn.Find(nF2);
402         anItPB.Initialize(aLPBF2);
403         for (; anItPB.More(); anItPB.Next()) {
404           const BOPTools_PaveBlock& aPB=anItPB.Value();
405           if (aMPB.Contains(aPB)) {
406             aFFi.AppendBlock(aPB);
407           }
408           else {
409             aLPB.Append(aPB);
410           }
411         }
412       }
413     }
414     //---
415     //
416     TopTools_ListOfShape aLSE;
417     TColStd_ListOfInteger aLNE;
418     SharedEdges(nF1, nF2, aLNE, aLSE);
419     aFFi.SetSharedEdges(aLNE);
420     //
421     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
422     aNbCurves=aSCvs.Length();
423     if (!aNbCurves) {
424       continue;
425     }
426     //
427     // Contribution of Samtech www.samcef.com END
428     aTolR3D=aFFi.TolR3D();
429     aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
430     //
431     BOPTools_PaveSet aPSF;
432     //
433     PrepareSetForFace (nF1, nF2, aLPB, aPSF);
434     //
435     // Put Paves On Curves
436     for (j=1; j<=aNbCurves; ++j) {
437       BOPTools_Curve& aBC=aSCvs(j);
438       // DEBUG
439       const IntTools_Curve& aC=aBC.Curve();
440       Handle (Geom_Curve) aC3D= aC.Curve();
441       //
442       PutPaveOnCurve (aPSF, aTolR3D, aBC);
443     }
444     //
445     // Put bounding paves on curves
446     for (j=1; j<=aNbCurves; ++j) {
447       BOPTools_Curve& aBC=aSCvs(j);
448       PutBoundPaveOnCurve (aBC, aFFi);
449     }
450     //
451     //  Pave Blocks on Curves
452     for (j=1; j<=aNbCurves; ++j) {
453       BOPTools_Curve& aBC=aSCvs(j);
454       const IntTools_Curve& aIC= aBC.Curve();
455       BOPTools_PaveSet& aPaveSet=aBC.Set();
456       //
457       BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
458       for (; aPBIter.More(); aPBIter.Next()) {
459         BOPTools_PaveBlock& aPBNew=aPBIter.Value();
460         aPBNew.SetCurve(aIC);
461         aPBNew.SetFace1(nF1);
462         aPBNew.SetFace2(nF2);
463         //
464         nV1=aPBNew.Pave1().Index();
465         nV2=aPBNew.Pave2().Index();
466         aT1=aPBNew.Pave1().Param();
467         aT2=aPBNew.Pave2().Param();
468         // ???
469         if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
470           continue;// mkk ft
471         }
472         //
473         // 1
474         
475         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPB, aTolR3D);
476         if (bIsExistingPaveBlock) {
477           continue;
478         }
479         //
480         bIsCoincided=CheckCoincidence(aPBNew, aLPB);
481         if(bIsCoincided) {
482           continue;
483         }
484         //
485         // Modified  
486         // to provide checking whether aPBNew already exists in list
487         // of section edges aLSE
488         // Thu Sep 14 14:35:18 2006 
489         // Contribution of Samtech www.samcef.com BEGIN
490         // 2
491         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLSE, aTolR3D);
492         if (bIsExistingPaveBlock) {
493           continue;
494         }
495         // Contribution of Samtech www.samcef.com END
496         //
497         // Checking of validity in 2D
498         //
499         bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
500         if (!bIsValidIn2D) {
501           continue;
502         }
503         //
504         //
505         // Make Section Edge  
506         TopoDS_Edge aES;
507         //
508         const TopoDS_Vertex aV1=TopoDS::Vertex(myDS->Shape(nV1));//mpv
509         const TopoDS_Vertex aV2=TopoDS::Vertex(myDS->Shape(nV2));//mpv
510         //
511         BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
512         //
513         //modified by NIZNHY-PKV Thu Nov 16 11:13:46 2006f SKL/PartC5
514         {
515           Handle(Geom2d_Curve) aC2D1, aC2D2;
516           //
517           aC2D1=aIC.FirstCurve2d();
518           aC2D2=aIC.SecondCurve2d();
519           //
520           NMTTools_Tools::MakePCurve(aES, aF1, aC2D1);
521           NMTTools_Tools::MakePCurve(aES, aF2, aC2D2);
522           NMTTools_Tools::UpdateEdge (aES, aTolR3D);
523         }
524         
525         //
526         /*
527         {
528           Standard_Real aTolR2D;
529           Handle(Geom2d_Curve) aC2D1, aC2D2;
530           //
531           aTolR2D=aFFi.TolR2D();
532           aC2D1=aIC.FirstCurve2d();
533           aC2D2=aIC.SecondCurve2d();
534           //
535           NMTTools_Tools::MakePCurve(aES, aF1, aC2D1, aTolR2D);
536           NMTTools_Tools::MakePCurve(aES, aF2, aC2D2, aTolR2D);
537         }
538         */
539         //modified by NIZNHY-PKV Thu Nov 16 11:17:34 2006t
540         //
541         aMEPB.Add(aES, aPBNew);
542         aMapEI.Add(aES, i);
543       }
544       
545     } // end of for (j=1; j<=aNbCurves; ++j)
546   }// for (i=1; i<=aNbFFs; ++i)
547   //=============================================================
548   //
549   // II. Post treatment 
550   //
551   // Input data: aMEPB, aMapEI
552   // Result    : section edges in myDS
553   //
554   Standard_Integer aNbSE;
555   //
556   aNbSE=aMEPB.Extent();
557   if (!aNbSE) {
558     // there is nothing to do here
559     return;
560   } 
561   //
562   BRep_Builder aBB;
563   TopoDS_Compound aCompound;
564   //
565   // 1. Make compound from SE
566   aBB.MakeCompound(aCompound);
567   for (i=1; i<=aNbSE; ++i) {
568     const TopoDS_Shape& aSE=aMEPB.FindKey(i);
569     aBB.Add(aCompound, aSE);
570   }
571   //
572   //
573   // 2. Intersect SE using auxiliary Filler
574   NMTDS_ShapesDataStructure tDS;
575   //
576   tDS.SetCompositeShape(aCompound);
577   tDS.Init();
578   //
579   BOPTools_InterferencePool tIP(tDS);
580   NMTTools_PaveFiller tPF(tIP);
581   //
582   // 2.1.VV
583   tPF.Init();
584   tPF.PerformVV();
585   tPF.PerformNewVertices();
586   //
587   // 2.2.VE
588   tPF.myPavePool.Resize (tPF.myNbEdges);
589   tPF.PrepareEdges();
590   tPF.PerformVE();
591   //
592   // 2.3.VF
593   tPF.PerformVF();
594   //
595   // 2.4.EE
596   tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
597   tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
598   tPF.myPavePoolNew    .Resize (tPF.myNbEdges);
599   
600   tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
601   tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
602   //
603   tPF.PerformEE();
604   //
605   tPF.RefinePavePool ();
606   //
607   tPF.myPavePoolNew.Destroy();
608   //
609   tPF.MakeSplitEdges();
610   tPF.UpdateCommonBlocks();
611   //
612   // 3. Treatment of the result of intersection
613   //
614   Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
615   TopAbs_ShapeEnum aType;
616   BOPTools_ListIteratorOfListOfPaveBlock aIt;
617   BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
618   //
619   const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
620   const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
621   //
622   aNbLines=tDS.NumberOfInsertedShapes();
623   aNbOld=tDS.NumberOfShapesOfTheObject();
624   // 
625   // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
626   //
627   // 3.1.1.Old vertices [ links ]
628   for (i=1; i<=aNbOld; ++i) {
629     const TopoDS_Shape& aV=tDS.Shape(i);
630     aType=aV.ShapeType();
631     if (aType!=TopAbs_VERTEX) {
632       continue;
633     }
634     //
635     for (j=1; j<=aNbSE; ++j) {
636       const BOPTools_PaveBlock& aPBSE=aMEPB(j);
637       nV1=aPBSE.Pave1().Index();
638       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
639       if (aV1.IsSame(aV)) {
640         aMNewOld.Add(i, nV1);
641         break;
642       }
643       nV2=aPBSE.Pave2().Index();
644       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
645       if (aV2.IsSame(aV)) {
646         aMNewOld.Add(i, nV2);
647         break;
648       }
649     }
650   }
651   //
652   // 3.1.2. New vertices [ links ]
653   i=tDS.NumberOfSourceShapes()+1;
654   for (; i<=aNbLines; ++i) {
655     const TopoDS_Shape& aV=tDS.Shape(i);
656     aType=aV.ShapeType();
657     if (aType!=TopAbs_VERTEX) {
658       continue;
659     }
660     //
661     // Insert new vertex in myDS
662     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
663     myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
664     nV1=myDS->NumberOfInsertedShapes();
665     // link
666     aMNewOld.Add(i, nV1);
667   }
668   //
669   // 3.2. Treatment of section edges (SE)
670   for (i=1; i<=aNbOld; ++i) {
671     const TopoDS_Shape& aE=tDS.Shape(i);
672     aType=aE.ShapeType();
673     if (aType!=TopAbs_EDGE) {
674       continue;
675     }
676     //
677     //  block of section edge that we already have for this SE
678     BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
679     //
680     // Corresponding FF-interference
681     iFF=aMapEI.FindFromKey(aE);
682     BOPTools_SSInterference& aFFi=aFFs(iFF);
683     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
684     //
685     BOPTools_Curve& aBC=aSCvs(1); 
686     //
687     const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
688     aNbPB=aLPB.Extent();
689     //
690     if (!aNbPB) {
691       // no pave blocks -> use aPBSE and whole edge aE
692       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
693       //
694       nV1=aPBSE.Pave1().Index();
695       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
696       nV2=aPBSE.Pave2().Index();
697       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
698       //
699       anASSeq.SetNewSuccessor(nV1);
700       anASSeq.SetNewOrientation(aV1.Orientation());
701       anASSeq.SetNewSuccessor(nV2);
702       anASSeq.SetNewOrientation(aV2.Orientation());
703       //
704       myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
705       nE=myDS->NumberOfInsertedShapes();
706       //
707       aPBSE.SetEdge(nE);
708       aBC.AppendNewBlock(aPBSE);
709       //
710       continue;
711     }
712     //
713     nF1=aPBSE.Face1();
714     nF2=aPBSE.Face2();
715     //
716     const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
717     NMTTools_CommonBlockAPI aCBAPI(aLCB);
718     //
719     aIt.Initialize(aLPB);
720     for (; aIt.More(); aIt.Next()) {
721       BOPTools_PaveBlock aPB=aIt.Value();
722       //
723       const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));
724       const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));
725       //
726       if (aCBAPI.IsCommonBlock(aPB)) {
727         // it can be Common Block
728         Standard_Real aTolEx;
729         Handle(Geom2d_Curve) aC2D1, aC2D2;
730         TopoDS_Face aF1FWD, aF2FWD;
731         //
732         NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
733         const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
734         //
735         aPB=aCB.PaveBlock1();
736         mE=aPB.Edge(); // index of edge in tDS
737         const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
738         aTolEx=BRep_Tool::Tolerance(aEx);
739         //
740         aF1FWD=aF1;
741         aF1FWD.Orientation(TopAbs_FORWARD);
742         aF2FWD=aF2;
743         aF2FWD.Orientation(TopAbs_FORWARD);
744         //
745         //modified by NIZNHY-PKV Thu Nov 16 12:49:13 2006f SKL/PartC5
746         //NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1, aTolEx);
747         //NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2, aTolEx);
748         NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1);
749         NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2);
750         NMTTools_Tools::UpdateEdge (aEx, aTolEx);
751         //modified by NIZNHY-PKV Thu Nov 16 12:49:24 2006t 
752       } //if (aCBAPI.IsCommonBlock(aPB))
753       //
754       // new SE
755       mE=aPB.Edge(); // index of edge in tDS
756       const TopoDS_Shape& aSp=tDS.Shape(mE);
757       //
758       const BOPTools_Pave& aPave1=aPB.Pave1();
759       aT1=aPave1.Param();
760       mV1=aPave1.Index();            // index in tDS
761       nV1=aMNewOld.FindFromKey(mV1); // index in myDS
762       const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
763       //
764       const BOPTools_Pave& aPave2=aPB.Pave2();
765       aT2=aPave2.Param();
766       mV2=aPave2.Index();
767       nV2=aMNewOld.FindFromKey(mV2);
768       const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
769       //
770       if (!aMNewOld.Contains(mE)) {
771         // add new SE to the myDS
772         BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
773         //
774         anASSeq.SetNewSuccessor(nV1);
775         anASSeq.SetNewOrientation(aV1.Orientation());
776
777         anASSeq.SetNewSuccessor(nV2);
778         anASSeq.SetNewOrientation(aV2.Orientation());
779         
780         myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
781         nE=myDS->NumberOfInsertedShapes();
782         //
783         aMNewOld.Add(mE, nE);
784       }
785       else {
786         nE=aMNewOld.FindFromKey(mE);
787       }
788       // Form PaveBlock;
789       BOPTools_PaveBlock aPBx;
790       BOPTools_Pave aP1, aP2;
791       //
792       aPBx.SetFace1(nF1);
793       aPBx.SetFace1(nF2);
794       //
795       aP1.SetIndex(nV1);
796       aP1.SetParam(aT1);
797       //
798       aP2.SetIndex(nV2);
799       aP2.SetParam(aT2);
800       //
801       aPBx.SetPave1(aP1);
802       aPBx.SetPave2(aP2);
803       //
804       aPBx.SetEdge(nE);
805       //
806       aBC.AppendNewBlock(aPBx);
807     }// for (; aIt.More(); aIt.Next()) 
808   }// for (i=1; i<=aNbOld; ++i) 
809   //
810   myIsDone=Standard_True;
811 }
812 //=======================================================================
813 // function: MakePCurves
814 // purpose: 
815 //=======================================================================
816   void NMTTools_PaveFiller::MakePCurves()
817 {
818   Standard_Integer i, aNb,  nF1, nF2, nE;
819   TopoDS_Face aF1FWD, aF2FWD;
820   BOPTools_ListIteratorOfListOfPaveBlock anIt;
821   //
822   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
823   //
824   aNb=aFFs.Extent();
825   for (i=1; i<=aNb; i++) {
826     BOPTools_SSInterference& aFF=aFFs(i);
827     aFF.Indices(nF1, nF2);
828     //
829     const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
830     const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
831     //
832     aF1FWD=aF1;
833     aF1FWD.Orientation(TopAbs_FORWARD);
834     aF2FWD=aF2;
835     aF2FWD.Orientation(TopAbs_FORWARD);
836     //
837     // In, On parts processing
838     const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
839     //
840     anIt.Initialize(aLPBInOn);
841     for (; anIt.More(); anIt.Next()) {
842       const BOPTools_PaveBlock& aPB=anIt.Value();
843       nE=aPB.Edge();
844       const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
845       
846       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
847       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
848     }
849   } 
850 }
851 //=======================================================================
852 // function: IsExistingPaveBlock
853 // purpose: 
854 //=======================================================================
855    Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
856                                                              const BOPTools_ListOfPaveBlock& aLPBR,
857                                                              const Standard_Real aTolR3D)
858 {
859   Standard_Boolean bFlag;
860   Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
861   BOPTools_ListIteratorOfListOfPaveBlock anIt;
862   //
863   bFlag=Standard_False;
864   nVNew1=aPBNew.Pave1().Index();
865   nVNew2=aPBNew.Pave2().Index();
866   //
867   anIt.Initialize(aLPBR);
868   for (; anIt.More(); anIt.Next()) {
869     const BOPTools_PaveBlock& aPBR=anIt.Value();
870     nV1=aPBR.Pave1().Index();
871     nV2=aPBR.Pave2().Index();
872     if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
873       //
874       iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
875       if (!iC) {
876         return !bFlag;
877       }
878     }
879   }
880   return bFlag;
881 }
882 //=======================================================================
883 // function: IsExistingPaveBlock
884 // purpose: 
885 //=======================================================================
886   Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
887                                                             const TopTools_ListOfShape& aLSE,
888                                                             const Standard_Real aTolR3D)
889 {
890   Standard_Boolean bFlag;
891   Standard_Integer aNbSE, iC;
892   TopTools_ListIteratorOfListOfShape anIt;
893   //
894   bFlag=Standard_False;
895   //
896   aNbSE=aLSE.Extent();
897   if (!aNbSE) {
898     return bFlag;
899   }
900   //
901   anIt.Initialize(aLSE);
902   for (; anIt.More(); anIt.Next()) {
903     const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
904     iC=CheckIntermediatePoint(aPBNew, aE, aTolR3D);
905     if (!iC) {
906       return !bFlag;
907     }
908   }
909   return bFlag;
910 }
911 //=======================================================================
912 // function: CheckIntermediatePoint
913 // purpose: 
914 //=======================================================================
915   Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
916                                                                const BOPTools_PaveBlock& aPBR,
917                                                                const Standard_Real aTolC)
918                                                          
919 {
920   Standard_Integer iVM, nE2;
921   //
922   nE2=aPBR.Edge();
923   const TopoDS_Edge aE2=TopoDS::Edge(myDS->Shape(nE2));//mpv
924   iVM=CheckIntermediatePoint(aPB, aE2, aTolC);
925   //
926   return iVM;
927 }
928 //=======================================================================
929 // function: CheckIntermediatePoint
930 // purpose: 
931 //=======================================================================
932   Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
933                                                                const TopoDS_Edge& aE2,
934                                                                const Standard_Real aTolC)
935 {
936   Standard_Real aT11, aT12, aTM, aTmp;
937   Standard_Integer iVM;
938   gp_Pnt aPM;
939   BRep_Builder aBB;
940   TopoDS_Vertex aVM;
941   // 
942   // Vertex
943   const BOPTools_Pave& aPave11=aPB.Pave1();
944   aT11=aPave11.Param();
945   // 
946   const BOPTools_Pave& aPave12=aPB.Pave2();
947   aT12=aPave12.Param();
948   //
949   aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
950   //
951   const IntTools_Curve& aIC=aPB.Curve();
952   aIC.D0(aTM, aPM);
953   //
954   aBB.MakeVertex (aVM, aPM, aTolC);
955   //
956   iVM=myContext.ComputeVE(aVM, aE2, aTmp); 
957   //
958   return iVM;
959 }
960 //=======================================================================
961 // function: PutBoundPaveOnCurve
962 // purpose: 
963 //=======================================================================
964   void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
965                                                 BOPTools_SSInterference& aFFi)
966
967   Standard_Boolean bHasBounds, bVF;
968   Standard_Integer nF1, nF2;
969   Standard_Real aT1, aT2, aTolR3D;
970   gp_Pnt aP1, aP2;
971   //
972   const IntTools_Curve& aIC=aBC.Curve();
973   bHasBounds=aIC.HasBounds ();
974   if (!bHasBounds){
975     return;
976   }
977   //
978   // Bounds
979   aIC.Bounds (aT1, aT2, aP1, aP2);
980   //
981   // Faces
982   aFFi.Indices(nF1, nF2);
983   aTolR3D=aFFi.TolR3D();
984   //
985   const TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));//mpv
986   const TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));//mpv
987   //
988   bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
989   if (bVF) {
990     PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
991   }
992   //
993   bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
994   if (bVF) {
995     PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
996   }
997 }
998 //=======================================================================
999 // function: PutBoundPaveOnCurve
1000 // purpose: 
1001 //=======================================================================
1002   void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
1003                                                 const Standard_Real aT,
1004                                                 BOPTools_Curve& aBC,
1005                                                 BOPTools_SSInterference& aFFi)
1006
1007   Standard_Boolean bFound1, bFound2;
1008   Standard_Integer nV;
1009   Standard_Real aTolV=aFFi.TolR3D();
1010
1011   BOPTools_Pave aPave1, aPave2, aPave;
1012   BOPTools_PaveSet& aCPS=aBC.Set();
1013   BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
1014   const IntTools_Curve& aIC=aBC.Curve();
1015   //
1016   bFound1=FindPave(aP, aTolV, aCPS  , aPave1);
1017   bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
1018   //
1019   if (!bFound1 && !bFound2) {
1020     TopoDS_Vertex aNewVertex;
1021     BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
1022     //
1023     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
1024     myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
1025     nV=myDS->NumberOfInsertedShapes();
1026     aPave.SetIndex(nV);
1027     aPave.SetParam(aT);
1028
1029     aCPS.Append(aPave);
1030     aFFiPS.Append(aPave);
1031     //
1032     // Append Techno Vertex to the Curve
1033     TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
1034     aTVs.Append(nV);
1035   }
1036   
1037   if (bFound1 && !bFound2) {
1038     nV=aPave1.Index();
1039     aPave.SetIndex(nV);
1040     aPave.SetParam(aT);
1041     aFFiPS.Append(aPave);
1042     //
1043     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1044     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1045   }
1046   
1047   if (!bFound1 && bFound2) {
1048     nV=aPave2.Index();
1049     aPave.SetIndex(nV);
1050     aPave.SetParam(aT);
1051     aCPS.Append(aPave);
1052     //
1053     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1054     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1055   }
1056 }
1057 //=======================================================================
1058 // function: FindPave
1059 // purpose: 
1060 //=======================================================================
1061   Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
1062                                                  const Standard_Real aTolPV, 
1063                                                  const BOPTools_PaveSet& aPS,
1064                                                  BOPTools_Pave& aPave)
1065 {
1066   Standard_Integer nV;
1067   Standard_Boolean bIsVertex=Standard_False;
1068  
1069   const BOPTools_ListOfPave& aLP=aPS.Set();
1070   BOPTools_ListIteratorOfListOfPave anIt(aLP);
1071   for (; anIt.More(); anIt.Next()) {
1072     const BOPTools_Pave& aPC=anIt.Value();
1073     nV=aPC.Index();
1074     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1075     bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
1076     if (bIsVertex) {
1077       aPave=aPC;
1078       return bIsVertex;
1079     }
1080   }
1081   return bIsVertex;
1082 }
1083 //=======================================================================
1084 // function: PrepareSetForFace
1085 // purpose: 
1086 //=======================================================================
1087   void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer ,//nF1,
1088                                               const Standard_Integer ,//nF2,
1089                                               const BOPTools_ListOfPaveBlock& aLPBC,
1090                                               BOPTools_PaveSet& aPSF)
1091 {
1092   Standard_Integer nV1, nV2; 
1093   TColStd_MapOfInteger aMap;
1094   BOPTools_ListIteratorOfListOfPaveBlock anIt;
1095   //
1096   anIt.Initialize(aLPBC);
1097   for (; anIt.More(); anIt.Next()) {
1098     const BOPTools_PaveBlock& aPB=anIt.Value();
1099     const BOPTools_Pave& aPave1=aPB.Pave1();
1100     nV1=aPave1.Index();
1101     if (!aMap.Contains(nV1)) {
1102       aMap.Add(nV1);
1103       aPSF.Append(aPave1);
1104     }
1105     const BOPTools_Pave& aPave2=aPB.Pave2();
1106     nV2=aPave2.Index();
1107     if (!aMap.Contains(nV2)) {
1108       aMap.Add(nV2);
1109       aPSF.Append(aPave2);
1110     }
1111   }
1112 }
1113 //=======================================================================
1114 // function: PutPaveOnCurve
1115 // purpose: 
1116 //=======================================================================
1117   void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
1118                                            const Standard_Real aTolR3D,
1119                                            BOPTools_Curve& aBC)
1120
1121   Standard_Integer nV;
1122   Standard_Boolean bIsVertexOnLine;
1123   Standard_Real aT;
1124   BOPTools_ListIteratorOfListOfPave anIt;
1125   Bnd_Box aBBC;
1126   GeomAdaptor_Curve aGAC;
1127   //
1128   const IntTools_Curve& aC=aBC.Curve();
1129   Handle (Geom_Curve) aC3D= aC.Curve();
1130   aGAC.Load(aC3D);
1131   BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
1132   //
1133   const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1134   anIt.Initialize(aLP);
1135   for (; anIt.More(); anIt.Next()) {
1136     const BOPTools_Pave& aPave=anIt.Value();
1137     //
1138     nV=aPave.Index();
1139     const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1140     //
1141     Bnd_Box aBBV;
1142     BRepBndLib::Add(aV, aBBV);
1143     if (aBBC.IsOut(aBBV)){
1144       continue; 
1145     }
1146     //
1147     bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
1148     //
1149     if (bIsVertexOnLine) {
1150       BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1151       BOPTools_PaveSet& aPS=aBC.Set();
1152       aPS.Append(aPaveNew);
1153       //<-B
1154       BOPTools_Tools::UpdateVertex (aC, aT, aV);
1155     }
1156   }
1157 }
1158 /////////////
1159 //=======================================================================
1160 // function: IsPairFound
1161 // purpose: 
1162 //=======================================================================
1163 Standard_Boolean IsPairFound(const Standard_Integer nF1,
1164                              const Standard_Integer nF2,
1165                              BOPTools_InterferencePool* myIntrPool,
1166                              BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
1167                              BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith)
1168 {
1169   Standard_Boolean bIsFound;
1170   //
1171   if (!aMapWhat.Contains(nF1)) {
1172     TColStd_IndexedMapOfInteger aMWhat;
1173     FMapWhat(nF1, myIntrPool, aMWhat);
1174     aMapWhat.Add(nF1, aMWhat);
1175   }
1176   //
1177   if (!aMapWith.Contains(nF2)) {
1178     TColStd_IndexedMapOfInteger aMWith;
1179     FMapWith(nF2, myIntrPool, aMWith);
1180     aMapWith.Add(nF2, aMWith);
1181   }
1182   //
1183   const TColStd_IndexedMapOfInteger& aMWht=aMapWhat.FindFromKey(nF1);
1184   const TColStd_IndexedMapOfInteger& aMWit=aMapWith.FindFromKey(nF2);
1185   //
1186   bIsFound=IsFound(aMWht, aMWit);
1187   //
1188   return bIsFound;
1189 }
1190 //=======================================================================
1191 // function: FMapWhat
1192 // purpose: 
1193 //=======================================================================
1194 void FMapWhat(const Standard_Integer nF,
1195               BOPTools_InterferencePool* myIntrPool,
1196               TColStd_IndexedMapOfInteger& aMapWhat)
1197                     
1198 {
1199   Standard_Integer nE, nV;
1200  
1201   
1202
1203   BooleanOperations_ShapesDataStructure* myDS=myIntrPool->DS();
1204   BooleanOperations_OnceExplorer aExp(*myDS);
1205   //
1206   //  What
1207   aMapWhat.Add(nF);
1208   aExp.Init(nF, TopAbs_VERTEX);
1209   for (; aExp.More(); aExp.Next()) {
1210     nV=aExp.Current();
1211     aMapWhat.Add(nV);
1212   }
1213   //
1214   aExp.Init(nF, TopAbs_EDGE);
1215   for (; aExp.More(); aExp.Next()) {
1216     nE=aExp.Current();
1217     aMapWhat.Add(nE);
1218   }
1219 }
1220 //=======================================================================
1221 // function: FMapWith
1222 // purpose: 
1223 //=======================================================================
1224 void FMapWith(const Standard_Integer nF,
1225               BOPTools_InterferencePool* myIntrPool,
1226               TColStd_IndexedMapOfInteger& aMapWith)
1227 {
1228   TColStd_IndexedMapOfInteger aMapWhat;
1229   
1230   FMapWhat(nF, myIntrPool, aMapWhat);
1231   //
1232   // With
1233   Standard_Integer i, aNb, anIndex, aWhat, aWith;
1234   BOPTools_ListIteratorOfListOfInterference anIt;
1235   
1236   const BOPTools_CArray1OfInterferenceLine& anArrIL= myIntrPool->InterferenceTable();
1237
1238   aNb=aMapWhat.Extent();
1239   for (i=1; i<=aNb; i++) {
1240     aWhat=aMapWhat(i);
1241     
1242     const BOPTools_InterferenceLine& aWithLine=anArrIL(aWhat);
1243   
1244     const BOPTools_ListOfInterference& aLI=aWithLine.List();
1245     anIt.Initialize(aLI);
1246     for (; anIt.More(); anIt.Next()) {
1247       const BOPTools_Interference& anIntf=anIt.Value();
1248       anIndex=anIntf.Index();
1249       if (anIndex) {
1250         aWith=anIntf.With();
1251         aMapWith.Add(aWith);
1252       }
1253     }
1254   }
1255 }
1256 //=======================================================================
1257 // function: IsFound
1258 // purpose: 
1259 //=======================================================================
1260 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
1261                          const TColStd_IndexedMapOfInteger& aMapWith)
1262 {
1263   Standard_Boolean bFlag=Standard_False;
1264   Standard_Integer i, aNb, aWhat;
1265
1266   aNb=aMapWhat.Extent();
1267   for (i=1; i<=aNb; i++) {
1268     aWhat=aMapWhat(i);
1269     if (aMapWith.Contains(aWhat)) {
1270       return !bFlag;
1271     }
1272   }
1273   return bFlag;
1274 }
1275 // Modified  Thu Sep 14 14:35:18 2006 
1276 // Contribution of Samtech www.samcef.com BEGIN
1277 //=======================================================================
1278 //function : SharedEdges1
1279 //purpose  : 
1280 //=======================================================================
1281 void SharedEdges1(const TopoDS_Face& aF1,
1282                   const TopoDS_Face& aF2,
1283                   TopTools_ListOfShape& aLS)
1284 {
1285   Standard_Integer i, aNbE, aNbF;;
1286   TopTools_IndexedDataMapOfShapeListOfShape aMEF;
1287   //
1288   TopExp::MapShapesAndAncestors(aF1, TopAbs_EDGE, TopAbs_FACE, aMEF);
1289   TopExp::MapShapesAndAncestors(aF2, TopAbs_EDGE, TopAbs_FACE, aMEF);
1290   //
1291   aNbE=aMEF.Extent();
1292   for (i=1; i<=aNbE; ++i) {
1293     const TopTools_ListOfShape& aLF=aMEF.FindFromIndex(i);
1294     aNbF=aLF.Extent();
1295     if (aNbF>1) {
1296       if (aNbF==2) {
1297         const TopoDS_Shape& aF1x=aLF.First();
1298         const TopoDS_Shape& aF2x=aLF.Last();
1299         if (aF1x.IsSame(aF2x)) {
1300           continue;
1301         }
1302       }
1303       const TopoDS_Shape& aE=aMEF.FindKey(i);
1304       aLS.Append (aE);
1305     }
1306   }
1307 }
1308
1309 //=======================================================================
1310 // function: CheckCoincidence
1311 // purpose: 
1312 //=======================================================================
1313   Standard_Boolean NMTTools_PaveFiller::CheckCoincidence(const BOPTools_PaveBlock& aPBNew,
1314                                                          const BOPTools_ListOfPaveBlock& aLPBFF)
1315                                                          
1316 {
1317   Standard_Boolean bRet;
1318   Standard_Real aTE;
1319   Standard_Integer nV11, nV12, nV21, nV22, iVV, iVE, nE2;
1320   Standard_Integer iV, iCount, iCountExt;
1321   BOPTools_ListIteratorOfListOfPaveBlock anIt;
1322   // V11
1323   const BOPTools_Pave& aPave11=aPBNew.Pave1();
1324   nV11=aPave11.Index();
1325   const TopoDS_Vertex& aV11=TopoDS::Vertex(myDS->Shape(nV11));
1326   
1327   // V12
1328   const BOPTools_Pave& aPave12=aPBNew.Pave2();
1329   nV12=aPave12.Index();
1330   const TopoDS_Vertex& aV12=TopoDS::Vertex(myDS->Shape(nV12));
1331   //
1332   iCountExt=1;
1333   iCount=0;
1334   anIt.Initialize(aLPBFF);
1335   for (; anIt.More(); anIt.Next()) {
1336     iCount=0;
1337     //
1338     const BOPTools_PaveBlock& aPBR=anIt.Value();
1339     // V21
1340     const BOPTools_Pave& aPave21=aPBR.Pave1();
1341     nV21=aPave21.Index();
1342     
1343     // V22
1344     const BOPTools_Pave& aPave22=aPBR.Pave2();
1345     nV22=aPave22.Index();
1346     //modified by NIZNHY-PKV Wed Nov 15 13:08:13 2006f
1347     if (nV11==nV21 || nV11==nV22 || nV12==nV21 || nV12==nV22) {
1348       continue;
1349     }
1350     //modified by NIZNHY-PKV Wed Nov 15 13:08:15 2006t
1351     // E2
1352     nE2=aPBR.Edge();
1353     //
1354     const TopoDS_Vertex& aV21=TopoDS::Vertex(myDS->Shape(nV21));
1355     const TopoDS_Vertex& aV22=TopoDS::Vertex(myDS->Shape(nV22));
1356     const TopoDS_Edge& aE2=TopoDS::Edge(myDS->Shape(nE2));
1357     //
1358     // VV
1359     iV=0;
1360     iVV=IntTools_Tools::ComputeVV (aV11, aV21);
1361     if (!iVV) {
1362       iCount++;
1363       iV++;
1364       if (iCount>iCountExt) {
1365         break;
1366       }
1367     }
1368     //
1369     iVV=IntTools_Tools::ComputeVV (aV11, aV22);
1370     if (!iVV) {
1371       iCount++;
1372       iV++;
1373       if (iCount>iCountExt) {
1374         break;
1375       }
1376     }
1377     // VE
1378     if (!iV) {
1379       iVE=myContext.ComputeVE (aV11, aE2, aTE);
1380       if (!iVE) {
1381         iCount++;
1382         if (iCount>iCountExt) {
1383           break;
1384         }
1385       }
1386     }
1387     // VV
1388     iV=0;
1389     iVV=IntTools_Tools::ComputeVV (aV12, aV21);
1390     if (!iVV) {
1391       iCount++;
1392       iV++;
1393       if (iCount>iCountExt) {
1394         break;
1395       }
1396     }
1397     //
1398     iVV=IntTools_Tools::ComputeVV (aV12, aV22);
1399     if (!iVV) {
1400       iCount++;
1401       iV++;
1402       if (iCount>iCountExt) {
1403         break;
1404       }
1405     }
1406     // VE
1407     if (!iV) {
1408       iVE=myContext.ComputeVE (aV12, aE2, aTE);
1409       if (!iVE) {
1410         iCount++;
1411         if (iCount>iCountExt) {
1412           break;
1413         }
1414       }
1415     }
1416   } // next aPBR
1417   bRet=(Standard_Boolean)(iCount>iCountExt);
1418   return bRet;
1419 }
1420 //
1421 // Contribution of Samtech www.samcef.com END