1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // IMPROVED by NIZNHY-PKV Thu Oct 12 16:03:33 2006
23 // File: NMTTools_PaveFiller_6.cxx
24 // Created: Fri Dec 19 10:27:31 2003
25 // Author: Peter KURNEV
28 #include <NMTTools_PaveFiller.ixx>
30 #include <Precision.hxx>
32 #include <TColStd_IndexedMapOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
35 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
36 #include <TColStd_ListOfInteger.hxx>
37 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
38 #include <TColStd_ListIteratorOfListOfInteger.hxx>
40 #include <Geom_TrimmedCurve.hxx>
41 #include <Geom2d_TrimmedCurve.hxx>
42 #include <Geom2d_Curve.hxx>
43 #include <GeomAdaptor_Curve.hxx>
45 #include <BndLib_Add3dCurve.hxx>
47 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Compound.hxx>
50 #include <TopoDS_Vertex.hxx>
51 #include <TopoDS_Edge.hxx>
55 #include <BRepLib.hxx>
56 #include <BRep_Builder.hxx>
57 #include <BRep_Tool.hxx>
58 #include <BRepBndLib.hxx>
60 #include <TopTools_IndexedMapOfShape.hxx>
61 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
62 #include <TopTools_ListOfShape.hxx>
63 #include <TopTools_ListIteratorOfListOfShape.hxx>
65 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
66 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
68 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
69 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
70 #include <BooleanOperations_OnceExplorer.hxx>
71 #include <BooleanOperations_ShapesDataStructure.hxx>
73 #include <IntTools_SequenceOfPntOn2Faces.hxx>
74 #include <IntTools_SequenceOfCurves.hxx>
75 #include <IntTools_FaceFace.hxx>
76 #include <IntTools_Tools.hxx>
77 #include <IntTools_ShrunkRange.hxx>
79 #include <BOPTools_CArray1OfSSInterference.hxx>
81 #include <BOPTools_SSInterference.hxx>
82 #include <BOPTools_ListOfPaveBlock.hxx>
83 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
84 #include <BOPTools_PaveBlock.hxx>
85 #include <BOPTools_ListIteratorOfListOfPave.hxx>
86 #include <BOPTools_Tools.hxx>
87 #include <BOPTools_PaveBlockIterator.hxx>
88 #include <BOPTools_Tools2D.hxx>
90 #include <NMTDS_Iterator.hxx>
91 #include <NMTDS_ShapesDataStructure.hxx>
92 #include <NMTDS_InterfPool.hxx>
94 #include <NMTTools_Tools.hxx>
95 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
96 #include <NMTTools_CommonBlockAPI.hxx>
97 #include <NMTTools_DataMapOfIntegerListOfPaveBlock.hxx>
98 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
100 #include <NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock.hxx>
101 #include <NMTTools_MapOfPaveBlock.hxx>
105 void SharedEdges1(const TopoDS_Face& aF1,
106 const TopoDS_Face& aF2,
107 TopTools_ListOfShape& aLS);
110 Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
111 IntTools_Context& aCtx);
113 //=======================================================================
114 // function: PerformFF
116 //=======================================================================
117 void NMTTools_PaveFiller::PerformFF()
119 myIsDone=Standard_False;
121 Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
122 Standard_Boolean bJustAdd;
123 Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
124 Standard_Integer aNbCurves, aNbPoints;
125 Standard_Real anApproxTol, aTolR3D, aTolR2D;
126 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
127 IntTools_SequenceOfPntOn2Faces aPnts;
128 IntTools_SequenceOfCurves aCvs;
129 //BooleanOperations_KindOfInterference aTypeFF=BooleanOperations_SurfaceSurface;
131 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
133 // F/F Interferences [BooleanOperations_SurfaceSurface]
134 myDSIt->Initialize(TopAbs_FACE, TopAbs_FACE);
136 // BlockLength correction
137 aNbFFs=myDSIt->BlockLength();
138 aBlockLength=aFFs.BlockLength();
139 if (aNbFFs > aBlockLength) {
140 aFFs.SetBlockLength(aNbFFs);
143 for (; myDSIt->More(); myDSIt->Next()) {
144 myDSIt->Current(n1, n2, bJustAdd);
156 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
157 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
160 bToApproxC3d = mySectionAttribute.Approximation();
161 bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
162 bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
166 IntTools_FaceFace aFF;
168 aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1,
169 bToApproxC2dOnS2, anApproxTol);
171 aFF.Perform(aF1, aF2);
173 bIsDone=aFF.IsDone();
176 //modified by NIZNHY-PKV Tue Jun 30 09:36:28 2009f
177 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
178 anIndexIn=aFFs.Append(anInterf);
179 //modified by NIZNHY-PKV Tue Jun 30 09:36:31 2009t
183 aTolR3D=aFF.TolReached3d();
184 aTolR2D=aFF.TolReached2d();
185 if (aTolR3D < 1.e-7){
189 aFF.PrepareLines3D();
191 const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
192 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
194 aNbCurves=aCvsX.Length();
195 aNbPoints=aPntsX.Length();
197 if (!aNbCurves && !aNbPoints) {
198 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
199 anIndexIn=aFFs.Append(anInterf);
204 BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
205 anIndexIn=aFFs.Append(anInterf);
208 }// for (; myDSIt.More(); myDSIt.Next())
210 myIsDone=Standard_True;
212 //=======================================================================
213 // function: MakeBlocks
215 //=======================================================================
216 void NMTTools_PaveFiller::MakeBlocks()
218 myIsDone=Standard_False;
220 Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D, bIsCoincided;
221 Standard_Boolean bIsMicroEdge, bHasES;
222 Standard_Integer i, aNbFFs, nF1, nF2;
223 Standard_Integer nV1, nV2, j, aNbCurves;
224 Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
225 NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
226 BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
227 BOPTools_ListIteratorOfListOfPaveBlock anIt;
229 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
231 aNbFFs=aFFs.Extent();
233 NMTTools_DataMapOfIntegerListOfPaveBlock aMFInOn;
234 NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock aItMF;
237 Standard_Integer aNbS, aNbF, nF, aNbOn, nSp;
238 TopAbs_ShapeEnum aType;
239 BOPTools_ListIteratorOfListOfPaveBlock anItPB;
240 NMTTools_ListIteratorOfListOfCommonBlock aItCB;
241 TColStd_ListIteratorOfListOfInteger aItF;
243 aNbS=myDS->NumberOfShapesOfTheObject();
244 for (i=1; i<=aNbS; ++i) {
245 const TopoDS_Shape& aS=myDS->Shape(i);
246 aType=aS.ShapeType();
248 if (aType==TopAbs_EDGE) {
249 const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
250 aItCB.Initialize(aLCB);
251 for (; aItCB.More(); aItCB.Next()) {
252 const NMTTools_CommonBlock& aCB=aItCB.Value();
253 const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
255 const TColStd_ListOfInteger& aLF=aCB.Faces();
258 aItF.Initialize(aLF);
259 for (; aItF.More(); aItF.Next()) {
261 if (aMFInOn.IsBound(nF)) {
262 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
266 BOPTools_ListOfPaveBlock aLPB;
268 aMFInOn.Bind(nF, aLPB);
272 } // for (; aItCB.More(); aItCB.Next()) {
273 }//if (aS.ShapeType()==TopAbs_EDGE) {
275 else if (aType==TopAbs_FACE) {
276 BOPTools_ListOfPaveBlock aLPBOn;
279 RealSplitsFace(nF, aLPBOn);
281 aNbOn=aLPBOn.Extent();
283 if (aMFInOn.IsBound(nF)) {
284 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
288 aMFInOn.Bind(nF, aLPBOn);
292 } // for (i=1; i<=aNbS; ++i) {
294 // Refine ListOfPaveBlocks
295 aItMF.Initialize(aMFInOn);
296 for(; aItMF.More(); aItMF.Next()) {
297 TColStd_MapOfInteger aMTmp;
298 BOPTools_ListOfPaveBlock aLPBX;
301 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
302 anItPB.Initialize(aLPB);
303 for (; anItPB.More(); anItPB.Next()) {
304 const BOPTools_PaveBlock& aPB=anItPB.Value();
306 if (aMTmp.Add(nSp)) {
316 // 1. Produce Section Edges from intersection curves
317 // between each pair of faces
318 aNbFFs=aFFs.Extent();
320 for (i=1; i<=aNbFFs; ++i) {
321 BOPTools_SSInterference& aFFi=aFFs(i);
324 aFFi.Indices(nF1, nF2);
325 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
326 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
328 BOPTools_ListOfPaveBlock aLPB;
332 BOPTools_ListIteratorOfListOfPaveBlock anItPB;
333 NMTTools_MapOfPaveBlock aMPB;
335 if (aMFInOn.IsBound(nF1)) {
336 const BOPTools_ListOfPaveBlock& aLPBF1=aMFInOn.Find(nF1);
337 anItPB.Initialize(aLPBF1);
338 for (; anItPB.More(); anItPB.Next()) {
339 const BOPTools_PaveBlock& aPB=anItPB.Value();
345 if (aMFInOn.IsBound(nF2)) {
346 const BOPTools_ListOfPaveBlock& aLPBF2=aMFInOn.Find(nF2);
347 anItPB.Initialize(aLPBF2);
348 for (; anItPB.More(); anItPB.Next()) {
349 const BOPTools_PaveBlock& aPB=anItPB.Value();
350 if (aMPB.Contains(aPB)) {
351 aFFi.AppendBlock(aPB);
361 TopTools_ListOfShape aLSE;
362 TColStd_ListOfInteger aLNE;
363 SharedEdges(nF1, nF2, aLNE, aLSE);
364 aFFi.SetSharedEdges(aLNE);
366 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
367 aNbCurves=aSCvs.Length();
372 // Contribution of Samtech www.samcef.com END
373 aTolR3D=aFFi.TolR3D();
374 aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
376 BOPTools_PaveSet aPSF;
378 PrepareSetForFace (nF1, nF2, aLPB, aPSF);
380 // Put Paves On Curves
381 for (j=1; j<=aNbCurves; ++j) {
382 BOPTools_Curve& aBC=aSCvs(j);
384 const IntTools_Curve& aC=aBC.Curve();
385 Handle (Geom_Curve) aC3D= aC.Curve();
387 PutPaveOnCurve (aPSF, aTolR3D, aBC);
390 // Put bounding paves on curves
391 for (j=1; j<=aNbCurves; ++j) {
392 BOPTools_Curve& aBC=aSCvs(j);
393 PutBoundPaveOnCurve (aBC, aFFi);
396 // Pave Blocks on Curves
397 bHasES=Standard_False;
398 for (j=1; j<=aNbCurves; ++j) {
399 BOPTools_Curve& aBC=aSCvs(j);
400 const IntTools_Curve& aIC= aBC.Curve();
401 BOPTools_PaveSet& aPaveSet=aBC.Set();
403 BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
404 for (; aPBIter.More(); aPBIter.Next()) {
405 BOPTools_PaveBlock& aPBNew=aPBIter.Value();
406 aPBNew.SetCurve(aIC);
407 aPBNew.SetFace1(nF1);
408 aPBNew.SetFace2(nF2);
410 nV1=aPBNew.Pave1().Index();
411 nV2=aPBNew.Pave2().Index();
412 aT1=aPBNew.Pave1().Param();
413 aT2=aPBNew.Pave2().Param();
415 if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
416 continue;// mkk ft ???
420 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPB, aTolR3D);
421 if (bIsExistingPaveBlock) {
425 bIsCoincided=CheckCoincidence(aPBNew, aLPB);
431 // to provide checking whether aPBNew already exists in list
432 // of section edges aLSE
433 // Thu Sep 14 14:35:18 2006
434 // Contribution of Samtech www.samcef.com BEGIN
436 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLSE, aTolR3D);
437 if (bIsExistingPaveBlock) {
440 // Contribution of Samtech www.samcef.com END
442 // Checking of validity in 2D
444 bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
453 const TopoDS_Vertex aV1=TopoDS::Vertex(myDS->Shape(nV1));//mpv
454 const TopoDS_Vertex aV2=TopoDS::Vertex(myDS->Shape(nV2));//mpv
456 BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
458 NMTTools_Tools::UpdateEdge (aES, aTolR3D);
459 bIsMicroEdge=IsMicroEdge(aES, myContext);
466 Handle(Geom2d_Curve) aC2D1, aC2D2;
468 aC2D1=aIC.FirstCurve2d();
469 aC2D2=aIC.SecondCurve2d();
471 NMTTools_Tools::MakePCurve(aES, aF1, aC2D1);
472 NMTTools_Tools::MakePCurve(aES, aF2, aC2D2);
475 aMEPB.Add(aES, aPBNew);
478 bHasES=Standard_True;
479 }// for (; aPBIter.More(); aPBIter.Next())
480 } // end of for (j=1; j<=aNbCurves; ++j)
483 myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF);
486 }// for (i=1; i<=aNbFFs; ++i)
487 //=============================================================
489 // II. Post treatment
491 // Input data: aMEPB, aMapEI
492 // Result : section edges in myDS
494 Standard_Integer aNbSE;
496 aNbSE=aMEPB.Extent();
498 // there is nothing to do here
503 TopoDS_Compound aCompound;
505 // 1. Make compound from SE
506 aBB.MakeCompound(aCompound);
507 for (i=1; i<=aNbSE; ++i) {
508 const TopoDS_Shape& aSE=aMEPB.FindKey(i);
509 aBB.Add(aCompound, aSE);
513 // 2. Intersect SE using auxiliary Filler
514 NMTTools_PaveFiller tPF;
516 tPF.SetCompositeShape(aCompound);
521 //tPF.PerformNewVertices(); qq
524 tPF.myPavePool.Resize (tPF.myNbEdges);
532 tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
533 tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
534 tPF.myPavePoolNew .Resize (tPF.myNbEdges);
536 tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
537 tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
541 tPF.RefinePavePool ();
543 tPF.myPavePoolNew.Destroy();
545 tPF.MakeSplitEdges();
546 tPF.UpdateCommonBlocks();
548 // 3. Treatment of the result of intersection
550 Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
551 TopAbs_ShapeEnum aType;
552 BOPTools_ListIteratorOfListOfPaveBlock aIt;
553 BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
555 const NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
556 const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
557 const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
559 aNbLines=tDS.NumberOfInsertedShapes();
560 aNbOld=tDS.NumberOfShapesOfTheObject();
562 // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
564 // 3.1.1.Old vertices [ links ]
565 for (i=1; i<=aNbOld; ++i) {
566 const TopoDS_Shape& aV=tDS.Shape(i);
567 aType=aV.ShapeType();
568 if (aType!=TopAbs_VERTEX) {
572 for (j=1; j<=aNbSE; ++j) {
573 const BOPTools_PaveBlock& aPBSE=aMEPB(j);
574 nV1=aPBSE.Pave1().Index();
575 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
576 if (aV1.IsSame(aV)) {
577 aMNewOld.Add(i, nV1);
580 nV2=aPBSE.Pave2().Index();
581 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
582 if (aV2.IsSame(aV)) {
583 aMNewOld.Add(i, nV2);
589 // 3.1.2. New vertices [ links ]
590 i=tDS.NumberOfSourceShapes()+1;
591 for (; i<=aNbLines; ++i) {
592 const TopoDS_Shape& aV=tDS.Shape(i);
593 aType=aV.ShapeType();
594 if (aType!=TopAbs_VERTEX) {
598 // Insert new vertex in myDS
599 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
600 myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
601 nV1=myDS->NumberOfInsertedShapes();
603 aMNewOld.Add(i, nV1);
606 // 3.2. Treatment of section edges (SE)
607 for (i=1; i<=aNbOld; ++i) {
608 const TopoDS_Shape& aE=tDS.Shape(i);
609 aType=aE.ShapeType();
610 if (aType!=TopAbs_EDGE) {
614 // block of section edge that we already have for this SE
615 BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
617 // Corresponding FF-interference
618 iFF=aMapEI.FindFromKey(aE);
619 BOPTools_SSInterference& aFFi=aFFs(iFF);
620 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
622 BOPTools_Curve& aBC=aSCvs(1);
624 const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
628 // no pave blocks -> use aPBSE and whole edge aE
629 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
631 nV1=aPBSE.Pave1().Index();
632 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
633 nV2=aPBSE.Pave2().Index();
634 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
636 anASSeq.SetNewSuccessor(nV1);
637 anASSeq.SetNewOrientation(aV1.Orientation());
638 anASSeq.SetNewSuccessor(nV2);
639 anASSeq.SetNewOrientation(aV2.Orientation());
641 myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
642 nE=myDS->NumberOfInsertedShapes();
645 aBC.AppendNewBlock(aPBSE);
653 const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
654 NMTTools_CommonBlockAPI aCBAPI(aLCB);
656 aIt.Initialize(aLPB);
657 for (; aIt.More(); aIt.Next()) {
658 BOPTools_PaveBlock aPB=aIt.Value();
660 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));
661 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));
663 if (aCBAPI.IsCommonBlock(aPB)) {
664 // it can be Common Block
665 Standard_Real aTolEx;
666 Handle(Geom2d_Curve) aC2D1, aC2D2;
667 TopoDS_Face aF1FWD, aF2FWD;
669 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
670 //const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
672 aPB=aCB.PaveBlock1();
673 mE=aPB.Edge(); // index of edge in tDS
674 const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
675 aTolEx=BRep_Tool::Tolerance(aEx);
678 aF1FWD.Orientation(TopAbs_FORWARD);
680 aF2FWD.Orientation(TopAbs_FORWARD);
682 NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1);
683 NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2);
684 NMTTools_Tools::UpdateEdge (aEx, aTolEx);
685 } //if (aCBAPI.IsCommonBlock(aPB))
688 mE=aPB.Edge(); // index of edge in tDS
689 const TopoDS_Shape& aSp=tDS.Shape(mE);
691 const BOPTools_Pave& aPave1=aPB.Pave1();
693 mV1=aPave1.Index(); // index in tDS
694 nV1=aMNewOld.FindFromKey(mV1); // index in myDS
695 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
697 const BOPTools_Pave& aPave2=aPB.Pave2();
700 nV2=aMNewOld.FindFromKey(mV2);
701 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
703 if (!aMNewOld.Contains(mE)) {
704 // add new SE to the myDS
705 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
707 anASSeq.SetNewSuccessor(nV1);
708 anASSeq.SetNewOrientation(aV1.Orientation());
710 anASSeq.SetNewSuccessor(nV2);
711 anASSeq.SetNewOrientation(aV2.Orientation());
713 myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
714 nE=myDS->NumberOfInsertedShapes();
716 aMNewOld.Add(mE, nE);
719 nE=aMNewOld.FindFromKey(mE);
722 BOPTools_PaveBlock aPBx;
723 BOPTools_Pave aP1, aP2;
739 aBC.AppendNewBlock(aPBx);
740 }// for (; aIt.More(); aIt.Next())
741 }// for (i=1; i<=aNbOld; ++i)
743 myIsDone=Standard_True;
745 //=======================================================================
746 // function: MakePCurves
748 //=======================================================================
749 void NMTTools_PaveFiller::MakePCurves()
751 Standard_Integer i, aNb, nF1, nF2, nE;
752 Standard_Integer aNbCB, aNbF, nSp, nF;
753 TopAbs_ShapeEnum aType;
754 TopoDS_Face aF1FWD, aF2FWD;
755 TColStd_ListIteratorOfListOfInteger aItF;
756 BOPTools_ListIteratorOfListOfPaveBlock anIt;
757 NMTTools_ListIteratorOfListOfCommonBlock aItCB;
759 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
762 for (i=1; i<=aNb; i++) {
763 BOPTools_SSInterference& aFF=aFFs(i);
764 aFF.Indices(nF1, nF2);
766 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
767 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
770 aF1FWD.Orientation(TopAbs_FORWARD);
772 aF2FWD.Orientation(TopAbs_FORWARD);
774 // In, On parts processing
775 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
777 anIt.Initialize(aLPBInOn);
778 for (; anIt.More(); anIt.Next()) {
779 const BOPTools_PaveBlock& aPB=anIt.Value();
781 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
783 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
784 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
787 // Check common blocks between edges and faces
788 // Build P-Curves if they were not built in previos block.
789 // The main case is :arguments for e.g aEdge, aFace -> no FFs,
790 // but p-curves are needed.
792 aNb=myDS->NumberOfShapesOfTheObject();
793 for (i=1; i<=aNb; ++i) {
794 const TopoDS_Shape& aS=myDS->Shape(i);
795 aType=aS.ShapeType();
797 if (aType!=TopAbs_EDGE) {
800 const TopoDS_Edge& aE=TopoDS::Edge(aS);
802 if (BRep_Tool::Degenerated(aE)) {
806 const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
812 aItCB.Initialize(aLCB);
813 for (; aItCB.More(); aItCB.Next()) {
814 const NMTTools_CommonBlock& aCB=aItCB.Value();
815 const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
817 const TColStd_ListOfInteger& aLF=aCB.Faces();
824 const TopoDS_Edge aSp=TopoDS::Edge(myDS->Shape(nSp));//mpv
826 aItF.Initialize(aLF);
827 for (; aItF.More(); aItF.Next()) {
829 aF1FWD=TopoDS::Face(myDS->Shape(nF));
830 aF1FWD.Orientation(TopAbs_FORWARD);
832 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aSp, aF1FWD);
833 } // for (; aItCB.More(); aItCB.Next()) {
834 }//if (aS.ShapeType()==TopAbs_EDGE) {
837 //=======================================================================
838 // function: IsExistingPaveBlock
840 //=======================================================================
841 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
842 const BOPTools_ListOfPaveBlock& aLPBR,
843 const Standard_Real aTolR3D)
845 Standard_Boolean bFlag;
846 Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
847 BOPTools_ListIteratorOfListOfPaveBlock anIt;
849 bFlag=Standard_False;
850 nVNew1=aPBNew.Pave1().Index();
851 nVNew2=aPBNew.Pave2().Index();
853 anIt.Initialize(aLPBR);
854 for (; anIt.More(); anIt.Next()) {
855 const BOPTools_PaveBlock& aPBR=anIt.Value();
856 nV1=aPBR.Pave1().Index();
857 nV2=aPBR.Pave2().Index();
858 if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
860 iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
868 //=======================================================================
869 // function: IsExistingPaveBlock
871 //=======================================================================
872 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
873 const TopTools_ListOfShape& aLSE,
874 const Standard_Real aTolR3D)
876 Standard_Boolean bFlag;
877 Standard_Integer aNbSE, iC;
878 Standard_Real aTolE, aTol;
879 TopTools_ListIteratorOfListOfShape anIt;
881 bFlag=Standard_False;
888 anIt.Initialize(aLSE);
889 for (; anIt.More(); anIt.Next()) {
890 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
891 aTolE=BRep_Tool::Tolerance(aE);
896 iC=CheckIntermediatePoint(aPBNew, aE, aTol);
903 //=======================================================================
904 // function: CheckIntermediatePoint
906 //=======================================================================
907 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
908 const BOPTools_PaveBlock& aPBR,
909 const Standard_Real aTolC)
912 Standard_Integer iVM, nE2;
915 const TopoDS_Edge aE2=TopoDS::Edge(myDS->Shape(nE2));//mpv
916 iVM=CheckIntermediatePoint(aPB, aE2, aTolC);
920 //=======================================================================
921 // function: CheckIntermediatePoint
923 //=======================================================================
924 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
925 const TopoDS_Edge& aE2,
926 const Standard_Real aTolC)
928 Standard_Real aT11, aT12, aTM, aTmp;
929 Standard_Integer iVM;
935 const BOPTools_Pave& aPave11=aPB.Pave1();
936 aT11=aPave11.Param();
938 const BOPTools_Pave& aPave12=aPB.Pave2();
939 aT12=aPave12.Param();
941 aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
943 const IntTools_Curve& aIC=aPB.Curve();
946 aBB.MakeVertex (aVM, aPM, aTolC);
948 iVM=myContext.ComputeVE(aVM, aE2, aTmp);
952 //=======================================================================
953 // function: PutBoundPaveOnCurve
955 //=======================================================================
956 void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
957 BOPTools_SSInterference& aFFi)
959 Standard_Boolean bHasBounds, bVF;
960 Standard_Integer nF1, nF2;
961 Standard_Real aT1, aT2, aTolR3D;
964 const IntTools_Curve& aIC=aBC.Curve();
965 bHasBounds=aIC.HasBounds ();
971 aIC.Bounds (aT1, aT2, aP1, aP2);
974 aFFi.Indices(nF1, nF2);
975 aTolR3D=aFFi.TolR3D();
977 const TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));//mpv
978 const TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));//mpv
980 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
982 PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
985 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
987 PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
990 //=======================================================================
991 // function: PutBoundPaveOnCurve
993 //=======================================================================
994 void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
995 const Standard_Real aT,
997 BOPTools_SSInterference& aFFi)
999 Standard_Boolean bFound1, bFound2;
1000 Standard_Integer nV;
1001 Standard_Real aTolV=aFFi.TolR3D();
1003 BOPTools_Pave aPave1, aPave2, aPave;
1004 BOPTools_PaveSet& aCPS=aBC.Set();
1005 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
1006 const IntTools_Curve& aIC=aBC.Curve();
1008 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
1009 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
1011 if (!bFound1 && !bFound2) {
1012 TopoDS_Vertex aNewVertex;
1013 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
1015 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
1016 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
1017 nV=myDS->NumberOfInsertedShapes();
1022 aFFiPS.Append(aPave);
1024 // Append Techno Vertex to the Curve
1025 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
1028 if (bFound1 && !bFound2) {
1032 aFFiPS.Append(aPave);
1034 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1035 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1038 if (!bFound1 && bFound2) {
1044 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1045 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1048 //=======================================================================
1049 // function: FindPave
1051 //=======================================================================
1052 Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
1053 const Standard_Real aTolPV,
1054 const BOPTools_PaveSet& aPS,
1055 BOPTools_Pave& aPave)
1057 Standard_Integer nV;
1058 Standard_Boolean bIsVertex=Standard_False;
1060 const BOPTools_ListOfPave& aLP=aPS.Set();
1061 BOPTools_ListIteratorOfListOfPave anIt(aLP);
1062 for (; anIt.More(); anIt.Next()) {
1063 const BOPTools_Pave& aPC=anIt.Value();
1065 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1066 bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
1074 //=======================================================================
1075 // function: PrepareSetForFace
1077 //=======================================================================
1078 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer ,//nF1,
1079 const Standard_Integer ,//nF2,
1080 const BOPTools_ListOfPaveBlock& aLPBC,
1081 BOPTools_PaveSet& aPSF)
1083 Standard_Integer nV1, nV2;
1084 TColStd_MapOfInteger aMap;
1085 BOPTools_ListIteratorOfListOfPaveBlock anIt;
1087 anIt.Initialize(aLPBC);
1088 for (; anIt.More(); anIt.Next()) {
1089 const BOPTools_PaveBlock& aPB=anIt.Value();
1090 const BOPTools_Pave& aPave1=aPB.Pave1();
1092 if (!aMap.Contains(nV1)) {
1094 aPSF.Append(aPave1);
1096 const BOPTools_Pave& aPave2=aPB.Pave2();
1098 if (!aMap.Contains(nV2)) {
1100 aPSF.Append(aPave2);
1104 //=======================================================================
1105 // function: PutPaveOnCurve
1107 //=======================================================================
1108 void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
1109 const Standard_Real aTolR3D,
1110 BOPTools_Curve& aBC)
1112 Standard_Integer nV;
1113 Standard_Boolean bIsVertexOnLine;
1115 BOPTools_ListIteratorOfListOfPave anIt;
1117 GeomAdaptor_Curve aGAC;
1119 const IntTools_Curve& aC=aBC.Curve();
1120 Handle (Geom_Curve) aC3D= aC.Curve();
1122 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
1124 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1125 anIt.Initialize(aLP);
1126 for (; anIt.More(); anIt.Next()) {
1127 const BOPTools_Pave& aPave=anIt.Value();
1130 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1133 BRepBndLib::Add(aV, aBBV);
1134 if (aBBC.IsOut(aBBV)){
1138 bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
1140 if (bIsVertexOnLine) {
1141 BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1142 BOPTools_PaveSet& aPS=aBC.Set();
1143 aPS.Append(aPaveNew);
1145 BOPTools_Tools::UpdateVertex (aC, aT, aV);
1152 //=======================================================================
1153 //function : SharedEdges1
1155 //=======================================================================
1157 void SharedEdges1(const TopoDS_Face& aF1,
1158 const TopoDS_Face& aF2,
1159 TopTools_ListOfShape& aLS)
1161 Standard_Integer i, aNbE, aNbF;;
1162 TopTools_IndexedDataMapOfShapeListOfShape aMEF;
1164 TopExp::MapShapesAndAncestors(aF1, TopAbs_EDGE, TopAbs_FACE, aMEF);
1165 TopExp::MapShapesAndAncestors(aF2, TopAbs_EDGE, TopAbs_FACE, aMEF);
1168 for (i=1; i<=aNbE; ++i) {
1169 const TopTools_ListOfShape& aLF=aMEF.FindFromIndex(i);
1173 const TopoDS_Shape& aF1x=aLF.First();
1174 const TopoDS_Shape& aF2x=aLF.Last();
1175 if (aF1x.IsSame(aF2x)) {
1179 const TopoDS_Shape& aE=aMEF.FindKey(i);
1186 //=======================================================================
1187 // function: CheckCoincidence
1189 //=======================================================================
1190 Standard_Boolean NMTTools_PaveFiller::CheckCoincidence(const BOPTools_PaveBlock& aPBNew,
1191 const BOPTools_ListOfPaveBlock& aLPBFF)
1194 Standard_Boolean bRet;
1196 Standard_Integer nV11, nV12, nV21, nV22, iVV, iVE, nE2;
1197 Standard_Integer iV, iCount, iCountExt;
1198 BOPTools_ListIteratorOfListOfPaveBlock anIt;
1200 const BOPTools_Pave& aPave11=aPBNew.Pave1();
1201 nV11=aPave11.Index();
1202 const TopoDS_Vertex& aV11=TopoDS::Vertex(myDS->Shape(nV11));
1205 const BOPTools_Pave& aPave12=aPBNew.Pave2();
1206 nV12=aPave12.Index();
1207 const TopoDS_Vertex& aV12=TopoDS::Vertex(myDS->Shape(nV12));
1211 anIt.Initialize(aLPBFF);
1212 for (; anIt.More(); anIt.Next()) {
1215 const BOPTools_PaveBlock& aPBR=anIt.Value();
1217 const BOPTools_Pave& aPave21=aPBR.Pave1();
1218 nV21=aPave21.Index();
1221 const BOPTools_Pave& aPave22=aPBR.Pave2();
1222 nV22=aPave22.Index();
1224 if (nV11==nV21 || nV11==nV22 || nV12==nV21 || nV12==nV22) {
1231 const TopoDS_Vertex& aV21=TopoDS::Vertex(myDS->Shape(nV21));
1232 const TopoDS_Vertex& aV22=TopoDS::Vertex(myDS->Shape(nV22));
1233 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->Shape(nE2));
1237 iVV=IntTools_Tools::ComputeVV (aV11, aV21);
1241 if (iCount>iCountExt) {
1246 iVV=IntTools_Tools::ComputeVV (aV11, aV22);
1250 if (iCount>iCountExt) {
1256 iVE=myContext.ComputeVE (aV11, aE2, aTE);
1259 if (iCount>iCountExt) {
1266 iVV=IntTools_Tools::ComputeVV (aV12, aV21);
1270 if (iCount>iCountExt) {
1275 iVV=IntTools_Tools::ComputeVV (aV12, aV22);
1279 if (iCount>iCountExt) {
1285 iVE=myContext.ComputeVE (aV12, aE2, aTE);
1288 if (iCount>iCountExt) {
1294 bRet=(Standard_Boolean)(iCount>iCountExt);
1298 //=======================================================================
1299 //function : IsMicroEdge
1301 //=======================================================================
1302 Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
1303 IntTools_Context& aCtx)
1305 Standard_Boolean bRet;
1306 Standard_Integer iErr;
1307 Standard_Real aT1, aT2, aTmp;
1308 Handle(Geom_Curve) aC3D;
1309 TopoDS_Vertex aV1, aV2;
1312 bRet=(BRep_Tool::Degenerated(aE) ||
1313 !BRep_Tool::IsGeometric(aE));
1318 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1319 TopExp::Vertices(aE, aV1, aV2);
1320 aT1=BRep_Tool::Parameter(aV1, aE);
1321 aT2=BRep_Tool::Parameter(aV2, aE);
1330 IntTools_ShrunkRange aSR (aE, aV1, aV2, aR, aCtx);
1331 iErr=aSR.ErrorStatus();