1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 // File: NMTTools_PaveFiller_6.cxx
21 // Created: Fri Dec 19 10:27:31 2003
22 // Author: Peter KURNEV
25 #include <NMTTools_PaveFiller.ixx>
27 #include <Precision.hxx>
29 #include <TColStd_IndexedMapOfInteger.hxx>
30 #include <TColStd_MapOfInteger.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Geom_TrimmedCurve.hxx>
35 #include <GeomAdaptor_Curve.hxx>
36 #include <BndLib_Add3dCurve.hxx>
38 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Compound.hxx>
44 #include <BRep_Builder.hxx>
45 #include <BRep_Tool.hxx>
46 #include <BRepBndLib.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
50 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
51 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
53 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
54 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
55 #include <BooleanOperations_OnceExplorer.hxx>
56 #include <BooleanOperations_ShapesDataStructure.hxx>
58 #include <IntTools_SequenceOfPntOn2Faces.hxx>
59 #include <IntTools_SequenceOfCurves.hxx>
60 #include <IntTools_FaceFace.hxx>
61 #include <IntTools_Tools.hxx>
63 #include <BOPTools_CArray1OfSSInterference.hxx>
64 #include <BOPTools_ListIteratorOfListOfInterference.hxx>
65 #include <BOPTools_CArray1OfInterferenceLine.hxx>
66 #include <BOPTools_InterferenceLine.hxx>
67 #include <BOPTools_ListOfInterference.hxx>
68 #include <BOPTools_Interference.hxx>
69 #include <BOPTools_InterferencePool.hxx>
70 #include <BOPTools_SSInterference.hxx>
71 #include <BOPTools_ListOfPaveBlock.hxx>
72 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
73 #include <BOPTools_PaveBlock.hxx>
74 #include <BOPTools_ListIteratorOfListOfPave.hxx>
75 #include <BOPTools_Tools.hxx>
76 #include <BOPTools_PaveBlockIterator.hxx>
77 #include <BOPTools_Tools2D.hxx>
79 #include <NMTDS_ShapesDataStructure.hxx>
80 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
81 #include <NMTTools_CommonBlockAPI.hxx>
82 #include <Geom2d_Curve.hxx>
83 #include <NMTTools_Tools.hxx>
84 #include <BRepLib.hxx>
85 #include <Geom2d_TrimmedCurve.hxx>
88 Standard_Boolean IsPairFound(const Standard_Integer nF1,
89 const Standard_Integer nF2,
90 BOPTools_InterferencePool* myIntrPool,
91 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
92 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith);
95 void FMapWhat(const Standard_Integer nF,
96 BOPTools_InterferencePool* myIntrPool,
97 TColStd_IndexedMapOfInteger& aMapWhat);
99 void FMapWith(const Standard_Integer nF,
100 BOPTools_InterferencePool* myIntrPool,
101 TColStd_IndexedMapOfInteger& aMapWith);
103 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
104 const TColStd_IndexedMapOfInteger& aMapWith);
107 //=======================================================================
108 // function: PerformFF
110 //=======================================================================
111 void NMTTools_PaveFiller::PerformFF()
113 myIsDone=Standard_False;
115 Standard_Boolean bIsFound, bJustAdd, bIsComputed;
116 Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
117 Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
118 Standard_Integer aNbCurves, aNbPoints;
119 Standard_Real anApproxTol, aTolR3D, aTolR2D;
120 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
121 IntTools_SequenceOfPntOn2Faces aPnts;
122 IntTools_SequenceOfCurves aCvs;
123 BooleanOperations_KindOfInterference aTypeFF=BooleanOperations_SurfaceSurface;
125 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
127 // F/F Interferences [BooleanOperations_SurfaceSurface]
128 myDSIt.Initialize(TopAbs_FACE, TopAbs_FACE);
130 // BlockLength correction
131 aNbFFs=ExpectedPoolLength();
132 aBlockLength=aFFs.BlockLength();
133 if (aNbFFs > aBlockLength) {
134 aFFs.SetBlockLength(aNbFFs);
137 for (; myDSIt.More(); myDSIt.Next()) {
138 myDSIt.Current(n1, n2, bJustAdd);
140 bIsComputed=myIntrPool->IsComputed(n1, n2);
155 bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
159 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
162 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
163 anIndexIn=aFFs.Append(anInterf);
164 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
169 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
170 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
173 bToApproxC3d = mySectionAttribute.Approximation();
174 bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
175 bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
179 IntTools_FaceFace aFF;
181 aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1,
182 bToApproxC2dOnS2, anApproxTol);
184 aFF.Perform(aF1, aF2);
186 bIsDone=aFF.IsDone();
190 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
193 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
194 anIndexIn=aFFs.Append(anInterf);
195 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
200 aTolR3D=aFF.TolReached3d();
201 aTolR2D=aFF.TolReached2d();
202 if (aTolR3D < 1.e-7){
206 aFF.PrepareLines3D();
208 const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
209 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
211 aNbCurves=aCvsX.Length();
212 aNbPoints=aPntsX.Length();
214 if (!aNbCurves && !aNbPoints) {
215 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
216 anIndexIn=aFFs.Append(anInterf);
217 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
222 BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
223 anIndexIn=aFFs.Append(anInterf);
224 myIntrPool->AddInterference (nF1, nF2, aTypeFF, anIndexIn);
227 }// for (; myDSIt.More(); myDSIt.Next())
229 myIsDone=Standard_True;
231 //=======================================================================
232 // function: MakeBlocks
234 //=======================================================================
235 void NMTTools_PaveFiller::MakeBlocks()
237 myIsDone=Standard_False;
239 Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D;
240 Standard_Integer i, aNbFFs, nF1, nF2, aBid=0;
241 Standard_Integer nV1, nV2, j, aNbCurves;
242 Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
243 NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
244 BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
245 BOPTools_ListIteratorOfListOfPaveBlock anIt;
247 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
249 // 1. Produce Section Edges from intersection curves
250 // between each pair of faces
252 aNbFFs=aFFs.Extent();
253 for (i=1; i<=aNbFFs; ++i) {
254 BOPTools_SSInterference& aFFi=aFFs(i);
257 aFFi.Indices(nF1, nF2);
258 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
259 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
261 BOPTools_ListOfPaveBlock aLPB, aLPBC;
263 //modified by NIZNHY-PKV Fri Mar 11 15:43:02 2005 f
265 Standard_Integer nFj1, nFj2, nE;
266 TColStd_IndexedMapOfInteger aMFence;
267 BOPTools_ListOfPaveBlock aLPBCx;
269 for (j=1; j<=aNbFFs; ++j) {
270 BOPTools_SSInterference& aFFj=aFFs(j);
271 aFFj.Indices(nFj1, nFj2);
273 if ((nF1==nFj1 && nFj2!=nF2) ||
274 (nF1==nFj2 && nFj1!=nF2) ||
275 (nF2==nFj1 && nFj2!=nF1) ||
276 (nF2==nFj2 && nFj1!=nF1)) {
277 RealSplitsInFace (aBid, nFj1, nFj2, aLPBCx);
278 RealSplitsInFace (aBid, nFj2, nFj1, aLPBCx);
279 RealSplitsOnFace (aBid, nFj1, nFj2, aLPBCx);
283 anIt.Initialize(aLPBCx);
284 for (; anIt.More(); anIt.Next()) {
285 const BOPTools_PaveBlock& aPBCx=anIt.Value();
288 if (!aMFence.Contains(nE)) {
295 //modified by NIZNHY-PKV Fri Apr 1 09:49:57 2005t
297 RealSplitsInFace (aBid, nF1, nF2, aLPB);
298 RealSplitsInFace (aBid, nF2, nF1, aLPB);
299 RealSplitsOnFace (aBid, nF1, nF2, aLPB);
301 anIt.Initialize(aLPB);
302 for (; anIt.More(); anIt.Next()) {
303 const BOPTools_PaveBlock& aPB=anIt.Value();
304 aFFi.AppendBlock(aPB);
307 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
308 aNbCurves=aSCvs.Length();
313 aTolR3D=aFFi.TolR3D();
314 aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
316 BOPTools_PaveSet aPSF;
318 //modified by NIZNHY-PKV Fri Apr 1 10:53:09 2005f
319 PrepareSetForFace (nF1, nF2, aLPBC, aPSF);
320 //PrepareSetForFace (nF1, nF2, aPSF);
321 //modified by NIZNHY-PKV Thu Mar 31 16:16:47 2005t
323 // Put Paves On Curves
324 for (j=1; j<=aNbCurves; ++j) {
325 BOPTools_Curve& aBC=aSCvs(j);
327 const IntTools_Curve& aC=aBC.Curve();
328 Handle (Geom_Curve) aC3D= aC.Curve();
330 PutPaveOnCurve (aPSF, aTolR3D, aBC);
333 // Put bounding paves on curves
334 for (j=1; j<=aNbCurves; ++j) {
335 BOPTools_Curve& aBC=aSCvs(j);
336 PutBoundPaveOnCurve (aBC, aFFi);
339 // Pave Blocks on Curves
340 for (j=1; j<=aNbCurves; ++j) {
341 BOPTools_Curve& aBC=aSCvs(j);
342 const IntTools_Curve& aIC= aBC.Curve();
343 BOPTools_PaveSet& aPaveSet=aBC.Set();
345 BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
346 for (; aPBIter.More(); aPBIter.Next()) {
347 BOPTools_PaveBlock& aPBNew=aPBIter.Value();
348 aPBNew.SetCurve(aIC);
349 aPBNew.SetFace1(nF1);
350 aPBNew.SetFace2(nF2);
352 nV1=aPBNew.Pave1().Index();
353 nV2=aPBNew.Pave2().Index();
354 aT1=aPBNew.Pave1().Param();
355 aT2=aPBNew.Pave2().Param();
357 if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
361 //modified by NIZNHY-PKV Fri Apr 1 09:56:11 2005f
363 const BOPTools_ListOfPaveBlock& aLPBFF=aFFi.PaveBlocks();
364 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPBFF, aTolR3D);
365 //bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aFFi);
366 if (bIsExistingPaveBlock) {
370 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPBC, aTolR3D);
371 if (bIsExistingPaveBlock) {
374 //modified by NIZNHY-PKV Fri Apr 1 09:56:14 2005t
375 // Checking of validity in 2D
377 bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
382 //aBC.AppendNewBlock(aPBNew);
387 const TopoDS_Vertex& aV1=TopoDS::Vertex(myDS->Shape(nV1));
388 const TopoDS_Vertex& aV2=TopoDS::Vertex(myDS->Shape(nV2));
390 BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
393 Standard_Real aTolR2D;
395 aTolR2D=aFFi.TolR2D();
396 Handle(Geom2d_Curve) aC2D1=aIC.FirstCurve2d();
397 Handle(Geom2d_Curve) aC2D2=aIC.SecondCurve2d();
399 NMTTools_Tools::MakePCurve(aES, aF1, aC2D1, aTolR2D);
400 NMTTools_Tools::MakePCurve(aES, aF2, aC2D2, aTolR2D);
403 aMEPB.Add(aES, aPBNew);
406 } // end of for (j=1; j<=aNbCurves; ++j)
407 }// for (i=1; i<=aNbFFs; ++i)
408 //=============================================================
410 // II. Post treatment
412 // Input data: aMEPB, aMapEI
413 // Result : section edges in myDS
415 Standard_Integer aNbSE;
417 aNbSE=aMEPB.Extent();
419 // there is nothing to do here
424 TopoDS_Compound aCompound;
426 // 1. Make compound from SE
427 aBB.MakeCompound(aCompound);
428 for (i=1; i<=aNbSE; ++i) {
429 const TopoDS_Shape& aSE=aMEPB.FindKey(i);
430 aBB.Add(aCompound, aSE);
434 // 2. Intersect SE using auxiliary Filler
435 NMTDS_ShapesDataStructure tDS;
437 tDS.SetCompositeShape(aCompound);
440 BOPTools_InterferencePool tIP(tDS);
441 NMTTools_PaveFiller tPF(tIP);
446 tPF.PerformNewVertices();
449 tPF.myPavePool.Resize (tPF.myNbEdges);
457 tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
458 tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
459 tPF.myPavePoolNew .Resize (tPF.myNbEdges);
461 tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
462 tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
466 tPF.RefinePavePool ();
468 tPF.myPavePoolNew.Destroy();
470 tPF.MakeSplitEdges();
471 tPF.UpdateCommonBlocks();
473 // 3. Treatment of the result of intersection
475 Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
476 TopAbs_ShapeEnum aType;
477 BOPTools_ListIteratorOfListOfPaveBlock aIt;
478 BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
480 const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
481 const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
483 aNbLines=tDS.NumberOfInsertedShapes();
484 aNbOld=tDS.NumberOfShapesOfTheObject();
486 // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
488 // 3.1.1.Old vertices [ links ]
489 for (i=1; i<=aNbOld; ++i) {
490 const TopoDS_Shape& aV=tDS.Shape(i);
491 aType=aV.ShapeType();
492 if (aType!=TopAbs_VERTEX) {
496 for (j=1; j<=aNbSE; ++j) {
497 const BOPTools_PaveBlock& aPBSE=aMEPB(j);
498 nV1=aPBSE.Pave1().Index();
499 const TopoDS_Shape& aV1=myDS->Shape(nV1);
500 if (aV1.IsSame(aV)) {
501 aMNewOld.Add(i, nV1);
504 nV2=aPBSE.Pave2().Index();
505 const TopoDS_Shape& aV2=myDS->Shape(nV2);
506 if (aV2.IsSame(aV)) {
507 aMNewOld.Add(i, nV2);
513 // 3.1.2. New vertices [ links ]
514 i=tDS.NumberOfSourceShapes()+1;
515 for (; i<=aNbLines; ++i) {
516 const TopoDS_Shape& aV=tDS.Shape(i);
517 aType=aV.ShapeType();
518 if (aType!=TopAbs_VERTEX) {
522 // Insert new vertex in myDS
523 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
524 myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
525 nV1=myDS->NumberOfInsertedShapes();
527 aMNewOld.Add(i, nV1);
530 // 3.2. Treatment of section edges (SE)
531 for (i=1; i<=aNbOld; ++i) {
532 const TopoDS_Shape& aE=tDS.Shape(i);
533 aType=aE.ShapeType();
534 if (aType!=TopAbs_EDGE) {
538 // block of section edge that we already have for this SE
539 BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
541 // Corresponding FF-interference
542 iFF=aMapEI.FindFromKey(aE);
543 BOPTools_SSInterference& aFFi=aFFs(iFF);
544 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
546 BOPTools_Curve& aBC=aSCvs(1);
548 const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
552 // no pave blocks -> use aPBSE and whole edge aE
553 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
555 nV1=aPBSE.Pave1().Index();
556 const TopoDS_Shape& aV1=myDS->Shape(nV1);
557 nV2=aPBSE.Pave2().Index();
558 const TopoDS_Shape& aV2=myDS->Shape(nV2);
560 anASSeq.SetNewSuccessor(nV1);
561 anASSeq.SetNewOrientation(aV1.Orientation());
562 anASSeq.SetNewSuccessor(nV2);
563 anASSeq.SetNewOrientation(aV2.Orientation());
565 myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
566 nE=myDS->NumberOfInsertedShapes();
569 aBC.AppendNewBlock(aPBSE);
576 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
577 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
579 const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
580 NMTTools_CommonBlockAPI aCBAPI(aLCB);
582 aIt.Initialize(aLPB);
583 for (; aIt.More(); aIt.Next()) {
584 BOPTools_PaveBlock aPB=aIt.Value();
586 if (aCBAPI.IsCommonBlock(aPB)) {
587 // it can be Common Block
588 Standard_Real aTolEx;
589 Handle(Geom2d_Curve) aC2D1, aC2D2;
590 TopoDS_Face aF1FWD, aF2FWD;
592 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
593 const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
595 aPB=aCB.PaveBlock1();
596 mE=aPB.Edge(); // index of edge in tDS
597 const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
598 aTolEx=BRep_Tool::Tolerance(aEx);
600 // Commented out by EAP in the frame of PAL9151
602 // Standard_Boolean bHasPCOnF, bFound;
603 // Standard_Integer nF, k, nEOrx, nF1x, nF2x;
604 // Standard_Real aTolEx, aT1x, aT2x;
605 // BOPTools_ListIteratorOfListOfPaveBlock aItPBx;
607 // for (k=0; k<2; ++k) {
608 // nF=(!k) ? nF1 : nF2;
609 // const TopoDS_Face& aF=TopoDS::Face(myDS->Shape(nF));
611 // bHasPCOnF=BOPTools_Tools2D::HasCurveOnSurface(aEx, aF);
616 // bFound=Standard_False;
617 // aItPBx.Initialize(aLPBx);
618 // for (; aItPBx.More(); aItPBx.Next()) {
619 // BOPTools_PaveBlock& aPBx=aIt.Value();
620 // nEOrx=aPBx.OriginalEdge();
621 // const TopoDS_Shape& aEOrx=tDS.Shape(nEOrx);
622 // BOPTools_PaveBlock& aPBSEx=aMEPB.ChangeFromKey(aEOrx);
623 // aT1x=aPBSEx.Pave1().Param();
624 // aT2x=aPBSEx.Pave2().Param();
625 // const IntTools_Curve& aICx=aPBSEx.Curve();
627 // nF1x=aPBSEx.Face1();
628 // nF2x=aPBSEx.Face2();
631 // Handle(Geom2d_Curve) aC2D1x=aICx.FirstCurve2d();
632 // Handle(Geom2d_TrimmedCurve)aC2D1xT =new Geom2d_TrimmedCurve(aC2D1x, aT1x, aT2x);
633 // aBB.UpdateEdge(aEx, aC2D1xT, aF, aTolEx);
639 // Handle(Geom2d_Curve) aC2D2x=aICx.SecondCurve2d();
640 // Handle(Geom2d_TrimmedCurve)aC2D2xT =new Geom2d_TrimmedCurve(aC2D2x, aT1x, aT2x);
641 // aBB.UpdateEdge(aEx, aC2D2xT, aF, aTolEx);
647 // BRepLib::SameParameter(aEx, aTolEx, Standard_True);
651 // The code till the if block end is restored from V2_2_2 revision
654 aF1FWD.Orientation(TopAbs_FORWARD);
655 NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1, aTolEx);
658 aF2FWD.Orientation(TopAbs_FORWARD);
659 NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2, aTolEx);
660 } //if (aCBAPI.IsCommonBlock(aPB))
663 mE=aPB.Edge(); // index of edge in tDS
664 const TopoDS_Shape& aSp=tDS.Shape(mE);
666 const BOPTools_Pave& aPave1=aPB.Pave1();
668 mV1=aPave1.Index(); // index in tDS
669 nV1=aMNewOld.FindFromKey(mV1); // index in myDS
670 const TopoDS_Shape& aV1=myDS->Shape(nV1);
672 const BOPTools_Pave& aPave2=aPB.Pave2();
675 nV2=aMNewOld.FindFromKey(mV2);
676 const TopoDS_Shape& aV2=myDS->Shape(nV2);
678 if (!aMNewOld.Contains(mE)) {
679 // add new SE to the myDS
680 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
682 anASSeq.SetNewSuccessor(nV1);
683 anASSeq.SetNewOrientation(aV1.Orientation());
685 anASSeq.SetNewSuccessor(nV2);
686 anASSeq.SetNewOrientation(aV2.Orientation());
688 myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
689 nE=myDS->NumberOfInsertedShapes();
691 aMNewOld.Add(mE, nE);
694 nE=aMNewOld.FindFromKey(mE);
697 BOPTools_PaveBlock aPBx;
698 BOPTools_Pave aP1, aP2;
714 aBC.AppendNewBlock(aPBx);
715 }// for (; aIt.More(); aIt.Next())
716 }// for (i=1; i<=aNbOld; ++i)
718 myIsDone=Standard_True;
720 //=======================================================================
721 // function: MakePCurves
723 //=======================================================================
724 void NMTTools_PaveFiller::MakePCurves()
726 Standard_Integer i, aNb, nF1, nF2, nE;
727 TopoDS_Face aF1FWD, aF2FWD;
728 BOPTools_ListIteratorOfListOfPaveBlock anIt;
730 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
733 for (i=1; i<=aNb; i++) {
734 BOPTools_SSInterference& aFF=aFFs(i);
735 aFF.Indices(nF1, nF2);
737 const TopoDS_Face& aF1=TopoDS::Face(myDS->Shape(nF1));
738 const TopoDS_Face& aF2=TopoDS::Face(myDS->Shape(nF2));
741 aF1FWD.Orientation(TopAbs_FORWARD);
743 aF2FWD.Orientation(TopAbs_FORWARD);
745 // In, On parts processing
746 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
748 anIt.Initialize(aLPBInOn);
749 for (; anIt.More(); anIt.Next()) {
750 const BOPTools_PaveBlock& aPB=anIt.Value();
752 const TopoDS_Edge& aE=TopoDS::Edge(myDS->Shape(nE));
754 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
755 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
759 //modified by NIZNHY-PKV Fri Apr 1 09:36:06 2005f
760 //=======================================================================
761 // function: IsExistingPaveBlock
763 //=======================================================================
764 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
765 const BOPTools_ListOfPaveBlock& aLPBR,
766 const Standard_Real aTolR3D)
768 Standard_Boolean bFlag;
769 Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
770 BOPTools_ListIteratorOfListOfPaveBlock anIt;
772 bFlag=Standard_False;
773 nVNew1=aPBNew.Pave1().Index();
774 nVNew2=aPBNew.Pave2().Index();
776 anIt.Initialize(aLPBR);
777 for (; anIt.More(); anIt.Next()) {
778 const BOPTools_PaveBlock& aPBR=anIt.Value();
779 nV1=aPBR.Pave1().Index();
780 nV2=aPBR.Pave2().Index();
781 if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
783 iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
791 //modified by NIZNHY-PKV Fri Apr 1 09:36:06 2005t
792 //=======================================================================
793 // function: CheckIntermediatePoint
795 //=======================================================================
796 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
797 const BOPTools_PaveBlock& aPBR,
798 const Standard_Real aTolC)
801 Standard_Real aT11, aT12, aTM, aTmp;
802 Standard_Integer iVM, nE2;
808 const BOPTools_Pave& aPave11=aPB.Pave1();
809 aT11=aPave11.Param();
811 const BOPTools_Pave& aPave12=aPB.Pave2();
812 aT12=aPave12.Param();
814 aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
816 const IntTools_Curve& aIC=aPB.Curve();
819 aBB.MakeVertex (aVM, aPM, aTolC);
823 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->GetShape(nE2));
825 iVM=myContext.ComputeVE(aVM, aE2, aTmp);
829 //=======================================================================
830 // function: PutBoundPaveOnCurve
832 //=======================================================================
833 void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
834 BOPTools_SSInterference& aFFi)
836 Standard_Boolean bHasBounds, bVF;
837 Standard_Integer nF1, nF2;
838 Standard_Real aT1, aT2, aTolR3D;
841 const IntTools_Curve& aIC=aBC.Curve();
842 bHasBounds=aIC.HasBounds ();
848 aIC.Bounds (aT1, aT2, aP1, aP2);
851 aFFi.Indices(nF1, nF2);
852 aTolR3D=aFFi.TolR3D();
854 const TopoDS_Face& aF1=TopoDS::Face(myDS->GetShape(nF1));
855 const TopoDS_Face& aF2=TopoDS::Face(myDS->GetShape(nF2));
857 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
859 PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
862 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
864 PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
867 //=======================================================================
868 // function: PutBoundPaveOnCurve
870 //=======================================================================
871 void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
872 const Standard_Real aT,
874 BOPTools_SSInterference& aFFi)
876 Standard_Boolean bFound1, bFound2;
878 Standard_Real aTolV=aFFi.TolR3D();
880 BOPTools_Pave aPave1, aPave2, aPave;
881 BOPTools_PaveSet& aCPS=aBC.Set();
882 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
883 const IntTools_Curve& aIC=aBC.Curve();
885 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
886 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
888 if (!bFound1 && !bFound2) {
889 TopoDS_Vertex aNewVertex;
890 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
892 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
893 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
894 nV=myDS->NumberOfInsertedShapes();
899 aFFiPS.Append(aPave);
901 // Append Techno Vertex to the Curve
902 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
906 if (bFound1 && !bFound2) {
910 aFFiPS.Append(aPave);
912 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
913 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
916 if (!bFound1 && bFound2) {
922 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
923 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
926 //=======================================================================
927 // function: FindPave
929 //=======================================================================
930 Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
931 const Standard_Real aTolPV,
932 const BOPTools_PaveSet& aPS,
933 BOPTools_Pave& aPave)
936 Standard_Boolean bIsVertex=Standard_False;
938 const BOPTools_ListOfPave& aLP=aPS.Set();
939 BOPTools_ListIteratorOfListOfPave anIt(aLP);
940 for (; anIt.More(); anIt.Next()) {
941 const BOPTools_Pave& aPC=anIt.Value();
943 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
944 bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
952 //=======================================================================
953 // function: PrepareSetForFace
955 //=======================================================================
956 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer nF1,
957 const Standard_Integer nF2,
958 const BOPTools_ListOfPaveBlock& aLPBC,
959 BOPTools_PaveSet& aPSF)
961 Standard_Integer nV1, nV2;
962 TColStd_MapOfInteger aMap;
963 BOPTools_ListOfPaveBlock aLPB1, aLPB2, aLPBS;
964 BOPTools_ListIteratorOfListOfPaveBlock anIt;
966 RealSplitsFace(nF1, aLPB1);
967 anIt.Initialize(aLPB1);
968 for (; anIt.More(); anIt.Next()) {
969 const BOPTools_PaveBlock& aPB=anIt.Value();
973 RealSplitsFace(nF2, aLPB2);
974 anIt.Initialize(aLPB2);
975 for (; anIt.More(); anIt.Next()) {
976 const BOPTools_PaveBlock& aPB=anIt.Value();
980 anIt.Initialize(aLPBC);
981 for (; anIt.More(); anIt.Next()) {
982 const BOPTools_PaveBlock& aPB=anIt.Value();
986 anIt.Initialize(aLPBS);
987 for (; anIt.More(); anIt.Next()) {
988 const BOPTools_PaveBlock& aPB=anIt.Value();
989 const BOPTools_Pave& aPave1=aPB.Pave1();
991 if (!aMap.Contains(nV1)) {
995 const BOPTools_Pave& aPave2=aPB.Pave2();
997 if (!aMap.Contains(nV2)) {
1003 //=======================================================================
1004 // function: PutPaveOnCurve
1006 //=======================================================================
1007 void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
1008 const Standard_Real aTolR3D,
1009 BOPTools_Curve& aBC)
1011 Standard_Integer nV;
1012 Standard_Boolean bIsVertexOnLine;
1014 BOPTools_ListIteratorOfListOfPave anIt;
1016 GeomAdaptor_Curve aGAC;
1018 const IntTools_Curve& aC=aBC.Curve();
1019 Handle (Geom_Curve) aC3D= aC.Curve();
1021 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
1023 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1024 anIt.Initialize(aLP);
1025 for (; anIt.More(); anIt.Next()) {
1026 const BOPTools_Pave& aPave=anIt.Value();
1029 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
1032 BRepBndLib::Add(aV, aBBV);
1033 if (aBBC.IsOut(aBBV)){
1037 bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
1039 if (bIsVertexOnLine) {
1040 BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1041 BOPTools_PaveSet& aPS=aBC.Set();
1042 aPS.Append(aPaveNew);
1044 BOPTools_Tools::UpdateVertex (aC, aT, aV);
1049 //=======================================================================
1050 // function: IsPairFound
1052 //=======================================================================
1053 Standard_Boolean IsPairFound(const Standard_Integer nF1,
1054 const Standard_Integer nF2,
1055 BOPTools_InterferencePool* myIntrPool,
1056 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
1057 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith)
1059 Standard_Boolean bIsFound;
1061 if (!aMapWhat.Contains(nF1)) {
1062 TColStd_IndexedMapOfInteger aMWhat;
1063 FMapWhat(nF1, myIntrPool, aMWhat);
1064 aMapWhat.Add(nF1, aMWhat);
1067 if (!aMapWith.Contains(nF2)) {
1068 TColStd_IndexedMapOfInteger aMWith;
1069 FMapWith(nF2, myIntrPool, aMWith);
1070 aMapWith.Add(nF2, aMWith);
1073 const TColStd_IndexedMapOfInteger& aMWht=aMapWhat.FindFromKey(nF1);
1074 const TColStd_IndexedMapOfInteger& aMWit=aMapWith.FindFromKey(nF2);
1076 bIsFound=IsFound(aMWht, aMWit);
1080 //=======================================================================
1081 // function: FMapWhat
1083 //=======================================================================
1084 void FMapWhat(const Standard_Integer nF,
1085 BOPTools_InterferencePool* myIntrPool,
1086 TColStd_IndexedMapOfInteger& aMapWhat)
1089 Standard_Integer nE, nV;
1093 BooleanOperations_ShapesDataStructure* myDS=myIntrPool->DS();
1094 BooleanOperations_OnceExplorer aExp(*myDS);
1098 aExp.Init(nF, TopAbs_VERTEX);
1099 for (; aExp.More(); aExp.Next()) {
1104 aExp.Init(nF, TopAbs_EDGE);
1105 for (; aExp.More(); aExp.Next()) {
1110 //=======================================================================
1111 // function: FMapWith
1113 //=======================================================================
1114 void FMapWith(const Standard_Integer nF,
1115 BOPTools_InterferencePool* myIntrPool,
1116 TColStd_IndexedMapOfInteger& aMapWith)
1118 TColStd_IndexedMapOfInteger aMapWhat;
1120 FMapWhat(nF, myIntrPool, aMapWhat);
1123 Standard_Integer i, aNb, anIndex, aWhat, aWith;
1124 BOPTools_ListIteratorOfListOfInterference anIt;
1126 const BOPTools_CArray1OfInterferenceLine& anArrIL= myIntrPool->InterferenceTable();
1128 aNb=aMapWhat.Extent();
1129 for (i=1; i<=aNb; i++) {
1132 const BOPTools_InterferenceLine& aWithLine=anArrIL(aWhat);
1134 const BOPTools_ListOfInterference& aLI=aWithLine.List();
1135 anIt.Initialize(aLI);
1136 for (; anIt.More(); anIt.Next()) {
1137 const BOPTools_Interference& anIntf=anIt.Value();
1138 anIndex=anIntf.Index();
1140 aWith=anIntf.With();
1141 aMapWith.Add(aWith);
1146 //=======================================================================
1147 // function: IsFound
1149 //=======================================================================
1150 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
1151 const TColStd_IndexedMapOfInteger& aMapWith)
1153 Standard_Boolean bFlag=Standard_False;
1154 Standard_Integer i, aNb, aWhat;
1156 aNb=aMapWhat.Extent();
1157 for (i=1; i<=aNb; i++) {
1159 if (aMapWith.Contains(aWhat)) {
1166 //=======================================================================
1167 // function: PrepareSetForFace
1169 //=======================================================================
1170 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer nF1,
1171 const Standard_Integer nF2,
1172 BOPTools_PaveSet& aPSF)
1174 Standard_Integer nV1, nV2;
1175 TColStd_MapOfInteger aMap;
1176 BOPTools_ListOfPaveBlock aLPB1, aLPB2;
1177 BOPTools_ListIteratorOfListOfPaveBlock anIt;
1179 RealSplitsFace(nF1, aLPB1);
1180 RealSplitsFace(nF2, aLPB2);
1182 aLPB1.Append(aLPB2);
1184 anIt.Initialize(aLPB1);
1185 for (; anIt.More(); anIt.Next()) {
1186 const BOPTools_PaveBlock& aPB=anIt.Value();
1187 const BOPTools_Pave& aPave1=aPB.Pave1();
1189 if (!aMap.Contains(nV1)) {
1191 aPSF.Append(aPave1);
1193 const BOPTools_Pave& aPave2=aPB.Pave2();
1195 if (!aMap.Contains(nV2)) {
1197 aPSF.Append(aPave2);
1203 //=======================================================================
1204 // function: IsExistingPaveBlock
1206 //=======================================================================
1207 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
1208 const BOPTools_SSInterference& aFFi)
1210 Standard_Boolean bFlag;
1211 Standard_Real aTolR3D;
1213 aTolR3D=aFFi.TolR3D();
1214 const BOPTools_ListOfPaveBlock& aLPBR=aFFi.PaveBlocks();
1216 bFlag=IsExistingPaveBlock(aPBNew, aLPBR, aTolR3D);