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