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