]> SALOME platform Git repositories - modules/geom.git/blob - src/NMTTools/NMTTools_PaveFiller_6.cxx
Salome HOME
PAL11298: Problem with MakePartition in one time (SIGSEGV) solved.
[modules/geom.git] / src / NMTTools / NMTTools_PaveFiller_6.cxx
1 // File:        NMTTools_PaveFiller_6.cxx
2 // Created:     Fri Dec 19 10:27:31 2003
3 // Author:      Peter KURNEV
4 //              <pkv@irinox>
5
6 #include <NMTTools_PaveFiller.ixx>
7
8 #include <Precision.hxx>
9
10 #include <TColStd_IndexedMapOfInteger.hxx>
11 #include <TColStd_MapOfInteger.hxx>
12
13 #include <Geom2d_Curve.hxx>
14 #include <Geom2d_TrimmedCurve.hxx>
15 #include <Geom_TrimmedCurve.hxx>
16
17 #include <GeomAdaptor_Curve.hxx>
18 #include <BndLib_Add3dCurve.hxx>
19
20 #include <TopoDS_Face.hxx>
21 #include <TopoDS.hxx>
22 #include <TopoDS_Compound.hxx>
23
24 #include <TopExp.hxx>
25
26 #include <BRep_Builder.hxx>
27 #include <BRep_Tool.hxx>
28 #include <BRepBndLib.hxx>
29 #include <BRepLib.hxx>
30
31 #include <TopTools_IndexedMapOfShape.hxx>
32
33 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
34 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
35
36 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
37 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
38 #include <BooleanOperations_OnceExplorer.hxx>
39 #include <BooleanOperations_ShapesDataStructure.hxx>
40
41 #include <IntTools_SequenceOfPntOn2Faces.hxx>
42 #include <IntTools_SequenceOfCurves.hxx>
43 #include <IntTools_FaceFace.hxx>
44 #include <IntTools_Tools.hxx>
45
46 #include <BOPTools_CArray1OfSSInterference.hxx>
47 #include <BOPTools_ListIteratorOfListOfInterference.hxx>
48 #include <BOPTools_CArray1OfInterferenceLine.hxx>
49 #include <BOPTools_InterferenceLine.hxx>
50 #include <BOPTools_ListOfInterference.hxx>
51 #include <BOPTools_Interference.hxx>
52 #include <BOPTools_InterferencePool.hxx>
53 #include <BOPTools_SSInterference.hxx>
54 #include <BOPTools_ListOfPaveBlock.hxx>
55 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
56 #include <BOPTools_PaveBlock.hxx>
57 #include <BOPTools_ListIteratorOfListOfPave.hxx>
58 #include <BOPTools_Tools.hxx>
59 #include <BOPTools_PaveBlockIterator.hxx>
60 #include <BOPTools_Tools2D.hxx>
61
62 #include <NMTDS_ShapesDataStructure.hxx>
63 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
64 #include <NMTTools_CommonBlockAPI.hxx>
65 #include <NMTTools_Tools.hxx>
66
67 static 
68   Standard_Boolean IsPairFound(const Standard_Integer nF1,
69                                const Standard_Integer nF2,
70                                BOPTools_InterferencePool* myIntrPool,
71                                BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
72                                BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith);
73
74 static
75   void FMapWhat(const Standard_Integer nF,
76                 BOPTools_InterferencePool* myIntrPool,
77                 TColStd_IndexedMapOfInteger& aMapWhat);
78 static
79   void FMapWith(const Standard_Integer nF,
80                 BOPTools_InterferencePool* myIntrPool,
81                 TColStd_IndexedMapOfInteger& aMapWith);
82 static
83   Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
84                            const TColStd_IndexedMapOfInteger& aMapWith);
85
86
87 //=======================================================================
88 // function: PerformFF
89 // purpose: 
90 //=======================================================================
91   void NMTTools_PaveFiller::PerformFF() 
92 {
93   myIsDone=Standard_False;
94   //
95   Standard_Boolean bIsFound, bJustAdd, bIsComputed;
96   Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
97   Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
98   Standard_Integer aNbCurves, aNbPoints;
99   Standard_Real anApproxTol, aTolR3D, aTolR2D;
100   BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
101   IntTools_SequenceOfPntOn2Faces aPnts;
102   IntTools_SequenceOfCurves aCvs;
103   BooleanOperations_KindOfInterference aTypeFF=BooleanOperations_SurfaceSurface;
104   //
105   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
106   //
107   //  F/F Interferences  [BooleanOperations_SurfaceSurface]
108   myDSIt.Initialize(TopAbs_FACE, TopAbs_FACE);
109   //
110   // BlockLength correction
111   aNbFFs=ExpectedPoolLength();
112   aBlockLength=aFFs.BlockLength();
113   if (aNbFFs > aBlockLength) {
114     aFFs.SetBlockLength(aNbFFs);
115   }
116   //
117   for (; myDSIt.More(); myDSIt.Next()) {
118     myDSIt.Current(n1, n2, bJustAdd);
119     //
120     bIsComputed=myIntrPool->IsComputed(n1, n2);
121     if (bIsComputed) {
122       continue;
123     }
124     //
125     nF1 = n2;
126     nF2 = n1;
127     if(n1 < n2) {
128       nF1 = n1;
129       nF2 = n2;
130     }
131     anIndexIn=0;
132     aPnts.Clear();
133     aCvs.Clear();
134     //
135     bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
136     //
137     if (bJustAdd) {
138       if (!bIsFound) {
139         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
140       }
141       else{
142         BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
143         anIndexIn=aFFs.Append(anInterf);
144         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
145       }
146       continue;
147     }
148     //
149     const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
150     const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
151     //
152     // FF
153     bToApproxC3d     = mySectionAttribute.Approximation();
154     bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
155     bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
156     //
157     anApproxTol=1.e-7;
158     //
159     IntTools_FaceFace aFF;
160     //
161     aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1, 
162                        bToApproxC2dOnS2, anApproxTol);
163     //
164     aFF.Perform(aF1, aF2);
165     //
166     bIsDone=aFF.IsDone();
167     //
168     if (!bIsDone) {
169       if (!bIsFound) {
170         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
171       }
172       else {
173         BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
174         anIndexIn=aFFs.Append(anInterf);
175         myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
176       }
177       continue;
178     }
179     //
180     aTolR3D=aFF.TolReached3d();
181     aTolR2D=aFF.TolReached2d();
182     if (aTolR3D < 1.e-7){
183       aTolR3D=1.e-7;
184     } 
185     //
186     aFF.PrepareLines3D();
187     //
188     const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
189     const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
190     //
191     aNbCurves=aCvsX.Length();
192     aNbPoints=aPntsX.Length();
193     //
194     if (!aNbCurves && !aNbPoints) {
195       BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
196       anIndexIn=aFFs.Append(anInterf);
197       myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
198       continue;
199     }
200     //
201     {
202       BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
203       anIndexIn=aFFs.Append(anInterf);
204       myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
205     }
206     //
207   }// for (; myDSIt.More(); myDSIt.Next()) 
208   //
209   myIsDone=Standard_True;
210 }
211 //=======================================================================
212 // function: MakeBlocks
213 // purpose: 
214 //=======================================================================
215   void NMTTools_PaveFiller::MakeBlocks()
216 {
217   myIsDone=Standard_False;
218   //
219   Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D;
220   Standard_Integer i, aNbFFs, nF1, nF2, aBid=0;
221   Standard_Integer nV1, nV2, j, aNbCurves;
222   Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
223   NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
224   BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
225   BOPTools_ListIteratorOfListOfPaveBlock anIt;  
226   //
227   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
228   //
229   // 1. Produce Section Edges from intersection curves
230   //    between each pair of faces
231   //
232   aNbFFs=aFFs.Extent();
233   for (i=1; i<=aNbFFs; ++i) {
234     BOPTools_SSInterference& aFFi=aFFs(i);
235     // 
236     // Faces
237     aFFi.Indices(nF1, nF2);
238     const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
239     const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
240     //
241     BOPTools_ListOfPaveBlock aLPB, aLPBC;
242     //
243     {
244       Standard_Integer nFj1, nFj2, nE;
245       TColStd_IndexedMapOfInteger aMFence;
246       BOPTools_ListOfPaveBlock aLPBCx;
247       //
248       for (j=1; j<=aNbFFs; ++j) {
249         BOPTools_SSInterference& aFFj=aFFs(j);
250         aFFj.Indices(nFj1, nFj2);
251         //
252         if ((nF1==nFj1 && nFj2!=nF2) ||
253             (nF1==nFj2 && nFj1!=nF2) ||
254             (nF2==nFj1 && nFj2!=nF1) ||
255             (nF2==nFj2 && nFj1!=nF1)) {
256           RealSplitsInFace (aBid, nFj1, nFj2, aLPBCx);
257           RealSplitsInFace (aBid, nFj2, nFj1, aLPBCx);
258           RealSplitsOnFace (aBid, nFj1, nFj2, aLPBCx);
259         }
260       }
261       //
262       anIt.Initialize(aLPBCx);
263       for (; anIt.More(); anIt.Next()) {
264         const BOPTools_PaveBlock& aPBCx=anIt.Value();
265         //
266         nE=aPBCx.Edge();
267         if (!aMFence.Contains(nE)) {
268           aMFence.Add(nE);
269           aLPBC.Append(aPBCx);
270         }
271       }
272     }
273     //
274     //
275     RealSplitsInFace (aBid, nF1, nF2, aLPB);
276     RealSplitsInFace (aBid, nF2, nF1, aLPB);
277     RealSplitsOnFace (aBid, nF1, nF2, aLPB);
278     //
279     anIt.Initialize(aLPB);
280     for (; anIt.More(); anIt.Next()) {
281       const BOPTools_PaveBlock& aPB=anIt.Value();
282       aFFi.AppendBlock(aPB);
283     }
284     //
285     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
286     aNbCurves=aSCvs.Length();
287     if (!aNbCurves) {
288       continue;
289     }
290     //
291     aTolR3D=aFFi.TolR3D();
292     aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
293     //
294     BOPTools_PaveSet aPSF;
295     //
296     PrepareSetForFace (nF1, nF2, aLPBC, aPSF);
297     //PrepareSetForFace (nF1, nF2, aPSF);
298     //
299     // Put Paves On Curves
300     for (j=1; j<=aNbCurves; ++j) {
301       BOPTools_Curve& aBC=aSCvs(j);
302       // DEBUG
303       const IntTools_Curve& aC=aBC.Curve();
304       Handle (Geom_Curve) aC3D= aC.Curve();
305       //
306       PutPaveOnCurve (aPSF, aTolR3D, aBC);
307     }
308     //
309     // Put bounding paves on curves
310     for (j=1; j<=aNbCurves; ++j) {
311       BOPTools_Curve& aBC=aSCvs(j);
312       PutBoundPaveOnCurve (aBC, aFFi);
313     }
314     //
315     //  Pave Blocks on Curves
316     for (j=1; j<=aNbCurves; ++j) {
317       BOPTools_Curve& aBC=aSCvs(j);
318       const IntTools_Curve& aIC= aBC.Curve();
319       BOPTools_PaveSet& aPaveSet=aBC.Set();
320       //
321       BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
322       for (; aPBIter.More(); aPBIter.Next()) {
323         BOPTools_PaveBlock& aPBNew=aPBIter.Value();
324         aPBNew.SetCurve(aIC);
325         aPBNew.SetFace1(nF1);
326         aPBNew.SetFace2(nF2);
327         //
328         nV1=aPBNew.Pave1().Index();
329         nV2=aPBNew.Pave2().Index();
330         aT1=aPBNew.Pave1().Param();
331         aT2=aPBNew.Pave2().Param();
332         // ???
333         if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
334           continue;// mkk ft
335         }
336         //
337         // 1
338         const BOPTools_ListOfPaveBlock& aLPBFF=aFFi.PaveBlocks();
339         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPBFF, aTolR3D);
340         //bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aFFi);
341         if (bIsExistingPaveBlock) {
342           continue;
343         }
344         // 2
345         bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPBC, aTolR3D);
346         if (bIsExistingPaveBlock) {
347           continue;
348         }
349         // Checking of validity in 2D
350         //
351         bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
352         if (!bIsValidIn2D) {
353           continue;
354         }
355         //
356         //aBC.AppendNewBlock(aPBNew);
357         //
358         // Make Section Edge  
359         TopoDS_Edge aES;
360         //
361         const TopoDS_Vertex& aV1=TopoDS::Vertex(myDS->Shape(nV1));
362         const TopoDS_Vertex& aV2=TopoDS::Vertex(myDS->Shape(nV2));
363         //
364         BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
365         //
366         {
367           Standard_Real aTolR2D;
368           //
369           aTolR2D=aFFi.TolR2D();
370           Handle(Geom2d_Curve) aC2D1=aIC.FirstCurve2d();
371           Handle(Geom2d_Curve) aC2D2=aIC.SecondCurve2d();
372           //
373           NMTTools_Tools::MakePCurve(aES, aF1, aC2D1, aTolR2D);
374           NMTTools_Tools::MakePCurve(aES, aF2, aC2D2, aTolR2D);
375         }
376         //
377         aMEPB.Add(aES, aPBNew);
378         aMapEI.Add(aES, i);
379       }
380     } // end of for (j=1; j<=aNbCurves; ++j)
381   }// for (i=1; i<=aNbFFs; ++i)
382   //=============================================================
383   //
384   // II. Post treatment 
385   //
386   // Input data: aMEPB, aMapEI
387   // Result    : section edges in myDS
388   //
389   Standard_Integer aNbSE;
390   //
391   aNbSE=aMEPB.Extent();
392   if (!aNbSE) {
393     // there is nothing to do here
394     return;
395   } 
396   //
397   BRep_Builder aBB;
398   TopoDS_Compound aCompound;
399   //
400   // 1. Make compound from SE
401   aBB.MakeCompound(aCompound);
402   for (i=1; i<=aNbSE; ++i) {
403     const TopoDS_Shape& aSE=aMEPB.FindKey(i);
404     aBB.Add(aCompound, aSE);
405   }
406   //
407   //
408   // 2. Intersect SE using auxiliary Filler
409   NMTDS_ShapesDataStructure tDS;
410   //
411   tDS.SetCompositeShape(aCompound);
412   tDS.Init();
413   //
414   BOPTools_InterferencePool tIP(tDS);
415   NMTTools_PaveFiller tPF(tIP);
416   //
417   // 2.1.VV
418   tPF.Init();
419   tPF.PerformVV();
420   tPF.PerformNewVertices();
421   //
422   // 2.2.VE
423   tPF.myPavePool.Resize (tPF.myNbEdges);
424   tPF.PrepareEdges();
425   tPF.PerformVE();
426   //
427   // 2.3.VF
428   tPF.PerformVF();
429   //
430   // 2.4.EE
431   tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
432   tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
433   tPF.myPavePoolNew    .Resize (tPF.myNbEdges);
434   
435   tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
436   tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
437   //
438   tPF.PerformEE();
439   //
440   tPF.RefinePavePool ();
441   //
442   tPF.myPavePoolNew.Destroy();
443   //
444   tPF.MakeSplitEdges();
445   tPF.UpdateCommonBlocks();
446   //
447   // 3. Treatment of the result of intersection
448   //
449   Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
450   TopAbs_ShapeEnum aType;
451   BOPTools_ListIteratorOfListOfPaveBlock aIt;
452   BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
453   //
454   const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
455   const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
456   //
457   aNbLines=tDS.NumberOfInsertedShapes();
458   aNbOld=tDS.NumberOfShapesOfTheObject();
459   // 
460   // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
461   //
462   // 3.1.1.Old vertices [ links ]
463   for (i=1; i<=aNbOld; ++i) {
464     const TopoDS_Shape& aV=tDS.Shape(i);
465     aType=aV.ShapeType();
466     if (aType!=TopAbs_VERTEX) {
467       continue;
468     }
469     //
470     for (j=1; j<=aNbSE; ++j) {
471       const BOPTools_PaveBlock& aPBSE=aMEPB(j);
472       nV1=aPBSE.Pave1().Index();
473       const TopoDS_Shape& aV1=myDS->Shape(nV1);
474       if (aV1.IsSame(aV)) {
475         aMNewOld.Add(i, nV1);
476         break;
477       }
478       nV2=aPBSE.Pave2().Index();
479       const TopoDS_Shape& aV2=myDS->Shape(nV2);
480       if (aV2.IsSame(aV)) {
481         aMNewOld.Add(i, nV2);
482         break;
483       }
484     }
485   }
486   //
487   // 3.1.2. New vertices [ links ]
488   i=tDS.NumberOfSourceShapes()+1;
489   for (; i<=aNbLines; ++i) {
490     const TopoDS_Shape& aV=tDS.Shape(i);
491     aType=aV.ShapeType();
492     if (aType!=TopAbs_VERTEX) {
493       continue;
494     }
495     //
496     // Insert new vertex in myDS
497     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
498     myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
499     nV1=myDS->NumberOfInsertedShapes();
500     // link
501     aMNewOld.Add(i, nV1);
502   }
503   //
504   // 3.2. Treatment of section edges (SE)
505   for (i=1; i<=aNbOld; ++i) {
506     const TopoDS_Shape& aE=tDS.Shape(i);
507     aType=aE.ShapeType();
508     if (aType!=TopAbs_EDGE) {
509       continue;
510     }
511     //
512     //  block of section edge that we already have for this SE
513     BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
514     //
515     // Corresponding FF-interference
516     iFF=aMapEI.FindFromKey(aE);
517     BOPTools_SSInterference& aFFi=aFFs(iFF);
518     BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
519     //
520     BOPTools_Curve& aBC=aSCvs(1); 
521     //
522     const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
523     aNbPB=aLPB.Extent();
524     //
525     if (!aNbPB) {
526       // no pave blocks -> use aPBSE and whole edge aE
527       BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
528       //
529       nV1=aPBSE.Pave1().Index();
530       const TopoDS_Shape& aV1=myDS->Shape(nV1);
531       nV2=aPBSE.Pave2().Index();
532       const TopoDS_Shape& aV2=myDS->Shape(nV2);
533       //
534       anASSeq.SetNewSuccessor(nV1);
535       anASSeq.SetNewOrientation(aV1.Orientation());
536       anASSeq.SetNewSuccessor(nV2);
537       anASSeq.SetNewOrientation(aV2.Orientation());
538       //
539       myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
540       nE=myDS->NumberOfInsertedShapes();
541       //
542       aPBSE.SetEdge(nE);
543       aBC.AppendNewBlock(aPBSE);
544       //
545       continue;
546     }
547     //
548     nF1=aPBSE.Face1();
549     nF2=aPBSE.Face2();
550     //
551     //modified by NIZNHY-PKV Thu Jan 26 10:17:04 2006f
552     //const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
553     //const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
554     //modified by NIZNHY-PKV Thu Jan 26 10:17:08 2006t
555     //
556     const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
557     NMTTools_CommonBlockAPI aCBAPI(aLCB);
558     //
559     aIt.Initialize(aLPB);
560     for (; aIt.More(); aIt.Next()) {
561       BOPTools_PaveBlock aPB=aIt.Value();
562       //
563       ////modified by NIZNHY-PKV Thu Jan 26 10:16:36 2006f
564       const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
565       const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
566       ////modified by NIZNHY-PKV Thu Jan 26 10:16:39 2006t
567       //
568       if (aCBAPI.IsCommonBlock(aPB)) {
569         // it can be Common Block
570         Standard_Real aTolEx;
571         Handle(Geom2d_Curve) aC2D1, aC2D2;
572         TopoDS_Face aF1FWD, aF2FWD;
573         //
574         NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
575         const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
576         //
577         aPB=aCB.PaveBlock1();
578         mE=aPB.Edge(); // index of edge in tDS
579         const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
580         aTolEx=BRep_Tool::Tolerance(aEx);
581         //
582         // <- Block A was here
583         //
584         aF1FWD=aF1;
585         aF1FWD.Orientation(TopAbs_FORWARD);
586         NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1, aTolEx);
587         //
588         aF2FWD=aF2;
589         aF2FWD.Orientation(TopAbs_FORWARD);
590         NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2, aTolEx);
591       } //if (aCBAPI.IsCommonBlock(aPB))
592       //
593       // new SE
594       mE=aPB.Edge(); // index of edge in tDS
595       const TopoDS_Shape& aSp=tDS.Shape(mE);
596       //
597       const BOPTools_Pave& aPave1=aPB.Pave1();
598       aT1=aPave1.Param();
599       mV1=aPave1.Index();            // index in tDS
600       nV1=aMNewOld.FindFromKey(mV1); // index in myDS
601       const TopoDS_Shape& aV1=myDS->Shape(nV1);
602       //
603       const BOPTools_Pave& aPave2=aPB.Pave2();
604       aT2=aPave2.Param();
605       mV2=aPave2.Index();
606       nV2=aMNewOld.FindFromKey(mV2);
607       const TopoDS_Shape& aV2=myDS->Shape(nV2);
608       //
609       if (!aMNewOld.Contains(mE)) {
610         // add new SE to the myDS
611         BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
612         //
613         anASSeq.SetNewSuccessor(nV1);
614         anASSeq.SetNewOrientation(aV1.Orientation());
615
616         anASSeq.SetNewSuccessor(nV2);
617         anASSeq.SetNewOrientation(aV2.Orientation());
618         
619         myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
620         nE=myDS->NumberOfInsertedShapes();
621         //
622         aMNewOld.Add(mE, nE);
623       }
624       else {
625         nE=aMNewOld.FindFromKey(mE);
626       }
627       // Form PaveBlock;
628       BOPTools_PaveBlock aPBx;
629       BOPTools_Pave aP1, aP2;
630       //
631       aPBx.SetFace1(nF1);
632       aPBx.SetFace1(nF2);
633       //
634       aP1.SetIndex(nV1);
635       aP1.SetParam(aT1);
636       //
637       aP2.SetIndex(nV2);
638       aP2.SetParam(aT2);
639       //
640       aPBx.SetPave1(aP1);
641       aPBx.SetPave2(aP2);
642       //
643       aPBx.SetEdge(nE);
644       //
645       aBC.AppendNewBlock(aPBx);
646     }// for (; aIt.More(); aIt.Next()) 
647   }// for (i=1; i<=aNbOld; ++i) 
648   //
649   myIsDone=Standard_True;
650 }
651 //=======================================================================
652 // function: MakePCurves
653 // purpose: 
654 //=======================================================================
655   void NMTTools_PaveFiller::MakePCurves()
656 {
657   Standard_Integer i, aNb,  nF1, nF2, nE;
658   TopoDS_Face aF1FWD, aF2FWD;
659   BOPTools_ListIteratorOfListOfPaveBlock anIt;
660   //
661   BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
662   //
663   aNb=aFFs.Extent();
664   for (i=1; i<=aNb; i++) {
665     BOPTools_SSInterference& aFF=aFFs(i);
666     aFF.Indices(nF1, nF2);
667     //
668     const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
669     const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
670     //
671     aF1FWD=aF1;
672     aF1FWD.Orientation(TopAbs_FORWARD);
673     aF2FWD=aF2;
674     aF2FWD.Orientation(TopAbs_FORWARD);
675     //
676     // In, On parts processing
677     const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
678     //
679     anIt.Initialize(aLPBInOn);
680     for (; anIt.More(); anIt.Next()) {
681       const BOPTools_PaveBlock& aPB=anIt.Value();
682       nE=aPB.Edge();
683       const TopoDS_Edge& aE=TopoDS::Edge(myDS->Shape(nE));
684       
685       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
686       BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
687     }
688   } 
689 }
690 //=======================================================================
691 // function: IsExistingPaveBlock
692 // purpose: 
693 //=======================================================================
694    Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
695                                                              const BOPTools_ListOfPaveBlock& aLPBR,
696                                                              const Standard_Real aTolR3D)
697 {
698   Standard_Boolean bFlag;
699   Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
700   BOPTools_ListIteratorOfListOfPaveBlock anIt;
701   //
702   bFlag=Standard_False;
703   nVNew1=aPBNew.Pave1().Index();
704   nVNew2=aPBNew.Pave2().Index();
705   //
706   anIt.Initialize(aLPBR);
707   for (; anIt.More(); anIt.Next()) {
708     const BOPTools_PaveBlock& aPBR=anIt.Value();
709     nV1=aPBR.Pave1().Index();
710     nV2=aPBR.Pave2().Index();
711     if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
712       //
713       iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
714       if (!iC) {
715         return !bFlag;
716       }
717     }
718   }
719   return bFlag;
720 }
721 //=======================================================================
722 // function: CheckIntermediatePoint
723 // purpose: 
724 //=======================================================================
725   Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
726                                                                const BOPTools_PaveBlock& aPBR,
727                                                                const Standard_Real aTolC)
728                                                          
729 {
730   Standard_Real aT11, aT12, aTM, aTmp;
731   Standard_Integer iVM, nE2;
732   gp_Pnt aPM;
733   BRep_Builder aBB;
734   TopoDS_Vertex aVM;
735   // 
736   // Vertex
737   const BOPTools_Pave& aPave11=aPB.Pave1();
738   aT11=aPave11.Param();
739   // 
740   const BOPTools_Pave& aPave12=aPB.Pave2();
741   aT12=aPave12.Param();
742   //
743   aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
744   //
745   const IntTools_Curve& aIC=aPB.Curve();
746   aIC.D0(aTM, aPM);
747   //
748   aBB.MakeVertex (aVM, aPM, aTolC);
749   //
750   //Edge
751   nE2=aPBR.Edge();
752   const TopoDS_Edge& aE2=TopoDS::Edge(myDS->GetShape(nE2));
753   // VE
754   iVM=myContext.ComputeVE(aVM, aE2, aTmp); 
755   //
756   return iVM;
757 }
758 //=======================================================================
759 // function: PutBoundPaveOnCurve
760 // purpose: 
761 //=======================================================================
762   void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
763                                                 BOPTools_SSInterference& aFFi)
764
765   Standard_Boolean bHasBounds, bVF;
766   Standard_Integer nF1, nF2;
767   Standard_Real aT1, aT2, aTolR3D;
768   gp_Pnt aP1, aP2;
769   //
770   const IntTools_Curve& aIC=aBC.Curve();
771   bHasBounds=aIC.HasBounds ();
772   if (!bHasBounds){
773     return;
774   }
775   //
776   // Bounds
777   aIC.Bounds (aT1, aT2, aP1, aP2);
778   //
779   // Faces
780   aFFi.Indices(nF1, nF2);
781   aTolR3D=aFFi.TolR3D();
782   //
783   const TopoDS_Face& aF1=TopoDS::Face(myDS->GetShape(nF1));
784   const TopoDS_Face& aF2=TopoDS::Face(myDS->GetShape(nF2));
785   //
786   bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
787   if (bVF) {
788     PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
789   }
790   //
791   bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
792   if (bVF) {
793     PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
794   }
795 }
796 //=======================================================================
797 // function: PutBoundPaveOnCurve
798 // purpose: 
799 //=======================================================================
800   void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
801                                                 const Standard_Real aT,
802                                                 BOPTools_Curve& aBC,
803                                                 BOPTools_SSInterference& aFFi)
804
805   Standard_Boolean bFound1, bFound2;
806   Standard_Integer nV;
807   Standard_Real aTolV=aFFi.TolR3D();
808
809   BOPTools_Pave aPave1, aPave2, aPave;
810   BOPTools_PaveSet& aCPS=aBC.Set();
811   BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
812   const IntTools_Curve& aIC=aBC.Curve();
813   //
814   bFound1=FindPave(aP, aTolV, aCPS  , aPave1);
815   bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
816   //
817   if (!bFound1 && !bFound2) {
818     TopoDS_Vertex aNewVertex;
819     BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
820     //
821     BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
822     myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
823     nV=myDS->NumberOfInsertedShapes();
824     aPave.SetIndex(nV);
825     aPave.SetParam(aT);
826
827     aCPS.Append(aPave);
828     aFFiPS.Append(aPave);
829     //
830     // Append Techno Vertex to the Curve
831     TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
832     aTVs.Append(nV);
833   }
834   
835   if (bFound1 && !bFound2) {
836     nV=aPave1.Index();
837     aPave.SetIndex(nV);
838     aPave.SetParam(aT);
839     aFFiPS.Append(aPave);
840     //
841     const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
842     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
843   }
844   
845   if (!bFound1 && bFound2) {
846     nV=aPave2.Index();
847     aPave.SetIndex(nV);
848     aPave.SetParam(aT);
849     aCPS.Append(aPave);
850     //
851     const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
852     BOPTools_Tools::UpdateVertex (aIC, aT, aV);
853   }
854 }
855 //=======================================================================
856 // function: FindPave
857 // purpose: 
858 //=======================================================================
859   Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
860                                                  const Standard_Real aTolPV, 
861                                                  const BOPTools_PaveSet& aPS,
862                                                  BOPTools_Pave& aPave)
863 {
864   Standard_Integer nV;
865   Standard_Boolean bIsVertex=Standard_False;
866  
867   const BOPTools_ListOfPave& aLP=aPS.Set();
868   BOPTools_ListIteratorOfListOfPave anIt(aLP);
869   for (; anIt.More(); anIt.Next()) {
870     const BOPTools_Pave& aPC=anIt.Value();
871     nV=aPC.Index();
872     const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
873     bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
874     if (bIsVertex) {
875       aPave=aPC;
876       return bIsVertex;
877     }
878   }
879   return bIsVertex;
880 }
881 //=======================================================================
882 // function: PrepareSetForFace
883 // purpose: 
884 //=======================================================================
885   void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer nF1,
886                                               const Standard_Integer nF2,
887                                               const BOPTools_ListOfPaveBlock& aLPBC,
888                                               BOPTools_PaveSet& aPSF)
889 {
890   Standard_Integer nV1, nV2; 
891   TColStd_MapOfInteger aMap;
892   BOPTools_ListOfPaveBlock aLPB1, aLPB2, aLPBS;
893   BOPTools_ListIteratorOfListOfPaveBlock anIt;
894   //
895   RealSplitsFace(nF1, aLPB1);
896   anIt.Initialize(aLPB1);
897   for (; anIt.More(); anIt.Next()) {
898     const BOPTools_PaveBlock& aPB=anIt.Value();
899     aLPBS.Append(aPB);
900   }
901   //
902   RealSplitsFace(nF2, aLPB2);
903   anIt.Initialize(aLPB2);
904   for (; anIt.More(); anIt.Next()) {
905     const BOPTools_PaveBlock& aPB=anIt.Value();
906     aLPBS.Append(aPB);
907   }
908   //
909   anIt.Initialize(aLPBC);
910   for (; anIt.More(); anIt.Next()) {
911     const BOPTools_PaveBlock& aPB=anIt.Value();
912     aLPBS.Append(aPB);
913   }
914   //
915   anIt.Initialize(aLPBS);
916   for (; anIt.More(); anIt.Next()) {
917     const BOPTools_PaveBlock& aPB=anIt.Value();
918     const BOPTools_Pave& aPave1=aPB.Pave1();
919     nV1=aPave1.Index();
920     if (!aMap.Contains(nV1)) {
921       aMap.Add(nV1);
922       aPSF.Append(aPave1);
923     }
924     const BOPTools_Pave& aPave2=aPB.Pave2();
925     nV2=aPave2.Index();
926     if (!aMap.Contains(nV2)) {
927       aMap.Add(nV2);
928       aPSF.Append(aPave2);
929     }
930   }
931 }
932 //=======================================================================
933 // function: PutPaveOnCurve
934 // purpose: 
935 //=======================================================================
936   void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
937                                            const Standard_Real aTolR3D,
938                                            BOPTools_Curve& aBC)
939
940   Standard_Integer nV;
941   Standard_Boolean bIsVertexOnLine;
942   Standard_Real aT;
943   BOPTools_ListIteratorOfListOfPave anIt;
944   Bnd_Box aBBC;
945   GeomAdaptor_Curve aGAC;
946   //
947   const IntTools_Curve& aC=aBC.Curve();
948   Handle (Geom_Curve) aC3D= aC.Curve();
949   aGAC.Load(aC3D);
950   BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
951   //
952   const BOPTools_ListOfPave& aLP=aPaveSet.Set();
953   anIt.Initialize(aLP);
954   for (; anIt.More(); anIt.Next()) {
955     const BOPTools_Pave& aPave=anIt.Value();
956     //
957     nV=aPave.Index();
958     const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
959     //
960     Bnd_Box aBBV;
961     BRepBndLib::Add(aV, aBBV);
962     if (aBBC.IsOut(aBBV)){
963       continue; 
964     }
965     //
966     bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
967     //
968     if (bIsVertexOnLine) {
969       BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
970       BOPTools_PaveSet& aPS=aBC.Set();
971       aPS.Append(aPaveNew);
972       //<-B
973       BOPTools_Tools::UpdateVertex (aC, aT, aV);
974     }
975   }
976 }
977 /////////////
978 //=======================================================================
979 // function: IsPairFound
980 // purpose: 
981 //=======================================================================
982 Standard_Boolean IsPairFound(const Standard_Integer nF1,
983                              const Standard_Integer nF2,
984                              BOPTools_InterferencePool* myIntrPool,
985                              BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
986                              BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith)
987 {
988   Standard_Boolean bIsFound;
989   //
990   if (!aMapWhat.Contains(nF1)) {
991     TColStd_IndexedMapOfInteger aMWhat;
992     FMapWhat(nF1, myIntrPool, aMWhat);
993     aMapWhat.Add(nF1, aMWhat);
994   }
995   //
996   if (!aMapWith.Contains(nF2)) {
997     TColStd_IndexedMapOfInteger aMWith;
998     FMapWith(nF2, myIntrPool, aMWith);
999     aMapWith.Add(nF2, aMWith);
1000   }
1001   //
1002   const TColStd_IndexedMapOfInteger& aMWht=aMapWhat.FindFromKey(nF1);
1003   const TColStd_IndexedMapOfInteger& aMWit=aMapWith.FindFromKey(nF2);
1004   //
1005   bIsFound=IsFound(aMWht, aMWit);
1006   //
1007   return bIsFound;
1008 }
1009 //=======================================================================
1010 // function: FMapWhat
1011 // purpose: 
1012 //=======================================================================
1013 void FMapWhat(const Standard_Integer nF,
1014               BOPTools_InterferencePool* myIntrPool,
1015               TColStd_IndexedMapOfInteger& aMapWhat)
1016                     
1017 {
1018   Standard_Integer nE, nV;
1019  
1020   
1021
1022   BooleanOperations_ShapesDataStructure* myDS=myIntrPool->DS();
1023   BooleanOperations_OnceExplorer aExp(*myDS);
1024   //
1025   //  What
1026   aMapWhat.Add(nF);
1027   aExp.Init(nF, TopAbs_VERTEX);
1028   for (; aExp.More(); aExp.Next()) {
1029     nV=aExp.Current();
1030     aMapWhat.Add(nV);
1031   }
1032   //
1033   aExp.Init(nF, TopAbs_EDGE);
1034   for (; aExp.More(); aExp.Next()) {
1035     nE=aExp.Current();
1036     aMapWhat.Add(nE);
1037   }
1038 }
1039 //=======================================================================
1040 // function: FMapWith
1041 // purpose: 
1042 //=======================================================================
1043 void FMapWith(const Standard_Integer nF,
1044               BOPTools_InterferencePool* myIntrPool,
1045               TColStd_IndexedMapOfInteger& aMapWith)
1046 {
1047   TColStd_IndexedMapOfInteger aMapWhat;
1048   
1049   FMapWhat(nF, myIntrPool, aMapWhat);
1050   //
1051   // With
1052   Standard_Integer i, aNb, anIndex, aWhat, aWith;
1053   BOPTools_ListIteratorOfListOfInterference anIt;
1054   
1055   const BOPTools_CArray1OfInterferenceLine& anArrIL= myIntrPool->InterferenceTable();
1056
1057   aNb=aMapWhat.Extent();
1058   for (i=1; i<=aNb; i++) {
1059     aWhat=aMapWhat(i);
1060     
1061     const BOPTools_InterferenceLine& aWithLine=anArrIL(aWhat);
1062   
1063     const BOPTools_ListOfInterference& aLI=aWithLine.List();
1064     anIt.Initialize(aLI);
1065     for (; anIt.More(); anIt.Next()) {
1066       const BOPTools_Interference& anIntf=anIt.Value();
1067       anIndex=anIntf.Index();
1068       if (anIndex) {
1069         aWith=anIntf.With();
1070         aMapWith.Add(aWith);
1071       }
1072     }
1073   }
1074 }
1075 //=======================================================================
1076 // function: IsFound
1077 // purpose: 
1078 //=======================================================================
1079 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
1080                          const TColStd_IndexedMapOfInteger& aMapWith)
1081 {
1082   Standard_Boolean bFlag=Standard_False;
1083   Standard_Integer i, aNb, aWhat;
1084
1085   aNb=aMapWhat.Extent();
1086   for (i=1; i<=aNb; i++) {
1087     aWhat=aMapWhat(i);
1088     if (aMapWith.Contains(aWhat)) {
1089       return !bFlag;
1090     }
1091   }
1092   return bFlag;
1093 }
1094 //
1095 //   Block A
1096 //
1097       //
1098         // Commented out by EAP in the frame of PAL9151
1099         //
1100 //      Standard_Boolean bHasPCOnF, bFound;
1101 //      Standard_Integer nF, k, nEOrx, nF1x, nF2x;
1102 //      Standard_Real aTolEx, aT1x, aT2x;
1103 //      BOPTools_ListIteratorOfListOfPaveBlock aItPBx;
1104         //
1105 //      for (k=0; k<2; ++k) {   
1106 //        nF=(!k) ? nF1 : nF2;
1107 //        const TopoDS_Face& aF=TopoDS::Face(myDS->Shape(nF));
1108 //        //
1109 //        bHasPCOnF=BOPTools_Tools2D::HasCurveOnSurface(aEx, aF); 
1110 //        if (bHasPCOnF) {
1111 //          continue;
1112 //        }
1113 //        //
1114 //        bFound=Standard_False;
1115 //        aItPBx.Initialize(aLPBx);
1116 //        for (; aItPBx.More(); aItPBx.Next()) {
1117 //          BOPTools_PaveBlock& aPBx=aIt.Value();
1118 //          nEOrx=aPBx.OriginalEdge();
1119 //          const TopoDS_Shape& aEOrx=tDS.Shape(nEOrx);
1120 //          BOPTools_PaveBlock& aPBSEx=aMEPB.ChangeFromKey(aEOrx);
1121 //          aT1x=aPBSEx.Pave1().Param();
1122 //          aT2x=aPBSEx.Pave2().Param();
1123 //          const IntTools_Curve& aICx=aPBSEx.Curve();
1124 //          //
1125 //          nF1x=aPBSEx.Face1();
1126 //          nF2x=aPBSEx.Face2();
1127 //          //
1128 //          if (nF1x==nF) {
1129 //            Handle(Geom2d_Curve) aC2D1x=aICx.FirstCurve2d();
1130 //            Handle(Geom2d_TrimmedCurve)aC2D1xT =new Geom2d_TrimmedCurve(aC2D1x, aT1x, aT2x);
1131 //            aBB.UpdateEdge(aEx, aC2D1xT, aF, aTolEx);
1132 //            bFound=!bFound;
1133 //            break;
1134 //          }
1135 //          //
1136 //          if (nF2x==nF) {
1137 //            Handle(Geom2d_Curve) aC2D2x=aICx.SecondCurve2d();
1138 //            Handle(Geom2d_TrimmedCurve)aC2D2xT =new Geom2d_TrimmedCurve(aC2D2x, aT1x, aT2x);
1139 //            aBB.UpdateEdge(aEx, aC2D2xT, aF, aTolEx);
1140 //            bFound=!bFound;
1141 //            break;
1142 //          }
1143 //        }
1144 //        if (bFound){
1145 //          BRepLib::SameParameter(aEx, aTolEx, Standard_True);
1146 //        }
1147 //      }
1148         //
1149         // The code till the if block end is restored from V2_2_2 revision
1150