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