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