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