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