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