1 // Copyright (C) 2007-2010 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 // File: NMTTools_PaveFiller_6.cxx
23 // Created: Fri Dec 19 10:27:31 2003
24 // Author: Peter KURNEV
26 #include <NMTTools_PaveFiller.ixx>
28 #include <Precision.hxx>
30 #include <TColStd_IndexedMapOfInteger.hxx>
31 #include <TColStd_MapOfInteger.hxx>
32 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
33 #include <TColStd_DataMapOfIntegerListOfInteger.hxx>
34 #include <TColStd_ListOfInteger.hxx>
35 #include <TColStd_DataMapIteratorOfDataMapOfIntegerListOfInteger.hxx>
36 #include <TColStd_ListIteratorOfListOfInteger.hxx>
38 #include <Geom_TrimmedCurve.hxx>
39 #include <Geom2d_TrimmedCurve.hxx>
40 #include <Geom2d_Curve.hxx>
41 #include <GeomAdaptor_Curve.hxx>
43 #include <BndLib_Add3dCurve.hxx>
45 #include <TopoDS_Face.hxx>
47 #include <TopoDS_Compound.hxx>
48 #include <TopoDS_Vertex.hxx>
49 #include <TopoDS_Edge.hxx>
53 #include <BRepLib.hxx>
54 #include <BRep_Builder.hxx>
55 #include <BRep_Tool.hxx>
56 #include <BRepBndLib.hxx>
58 #include <TopTools_IndexedMapOfShape.hxx>
59 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
60 #include <TopTools_ListOfShape.hxx>
61 #include <TopTools_ListIteratorOfListOfShape.hxx>
63 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
64 #include <BOPTColStd_IndexedDataMapOfIntegerInteger.hxx>
66 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
67 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
68 #include <BooleanOperations_OnceExplorer.hxx>
69 #include <BooleanOperations_ShapesDataStructure.hxx>
71 #include <IntTools_SequenceOfPntOn2Faces.hxx>
72 #include <IntTools_SequenceOfCurves.hxx>
73 #include <IntTools_FaceFace.hxx>
74 #include <IntTools_Tools.hxx>
75 #include <IntTools_ShrunkRange.hxx>
77 #include <BOPTools_CArray1OfSSInterference.hxx>
79 #include <BOPTools_SSInterference.hxx>
80 #include <BOPTools_ListOfPaveBlock.hxx>
81 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
82 #include <BOPTools_PaveBlock.hxx>
83 #include <BOPTools_ListIteratorOfListOfPave.hxx>
84 #include <BOPTools_Tools.hxx>
85 #include <BOPTools_PaveBlockIterator.hxx>
86 #include <BOPTools_Tools2D.hxx>
88 #include <NMTDS_Iterator.hxx>
89 #include <NMTDS_ShapesDataStructure.hxx>
90 #include <NMTDS_InterfPool.hxx>
92 #include <NMTTools_Tools.hxx>
93 #include <NMTTools_IndexedDataMapOfShapePaveBlock.hxx>
94 #include <NMTTools_CommonBlockAPI.hxx>
95 #include <NMTTools_DataMapOfIntegerListOfPaveBlock.hxx>
96 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
98 #include <NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock.hxx>
99 #include <NMTTools_MapOfPaveBlock.hxx>
102 Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
103 IntTools_Context& aCtx);
105 //=======================================================================
106 // function: PerformFF
108 //=======================================================================
109 void NMTTools_PaveFiller::PerformFF()
111 myIsDone=Standard_False;
113 Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
114 Standard_Boolean bJustAdd;
115 Standard_Integer n1, n2, anIndexIn, nF1, nF2, aBlockLength, aNbFFs;
116 Standard_Integer aNbCurves, aNbPoints;
117 Standard_Real anApproxTol, aTolR3D, aTolR2D;
118 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
119 IntTools_SequenceOfPntOn2Faces aPnts;
120 IntTools_SequenceOfCurves aCvs;
122 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
124 // F/F Interferences [BooleanOperations_SurfaceSurface]
125 myDSIt->Initialize(TopAbs_FACE, TopAbs_FACE);
127 // BlockLength correction
128 aNbFFs=myDSIt->BlockLength();
129 aBlockLength=aFFs.BlockLength();
130 if (aNbFFs > aBlockLength) {
131 aFFs.SetBlockLength(aNbFFs);
134 for (; myDSIt->More(); myDSIt->Next()) {
135 myDSIt->Current(n1, n2, bJustAdd);
147 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
148 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
151 bToApproxC3d = mySectionAttribute.Approximation();
152 bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
153 bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
157 IntTools_FaceFace aFF;
159 aFF.SetParameters (bToApproxC3d, bToApproxC2dOnS1,
160 bToApproxC2dOnS2, anApproxTol);
162 aFF.Perform(aF1, aF2);
164 bIsDone=aFF.IsDone();
167 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
168 anIndexIn=aFFs.Append(anInterf);
172 aTolR3D=aFF.TolReached3d();
173 aTolR2D=aFF.TolReached2d();
174 if (aTolR3D < 1.e-7){
178 aFF.PrepareLines3D();
180 const IntTools_SequenceOfCurves& aCvsX=aFF.Lines();
181 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFF.Points();
183 aNbCurves=aCvsX.Length();
184 aNbPoints=aPntsX.Length();
186 if (!aNbCurves && !aNbPoints) {
187 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
188 anIndexIn=aFFs.Append(anInterf);
193 BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvsX, aPntsX);
194 anIndexIn=aFFs.Append(anInterf);
197 }// for (; myDSIt.More(); myDSIt.Next())
199 myIsDone=Standard_True;
202 //=======================================================================
203 // function: MakeBlocks
205 //=======================================================================
206 void NMTTools_PaveFiller::MakeBlocks()
208 myIsDone=Standard_False;
210 Standard_Boolean bIsExistingPaveBlock, bIsValidIn2D, bIsCoincided;
211 Standard_Boolean bIsMicroEdge, bHasES;
212 Standard_Integer i, aNbFFs, nF1, nF2;
213 Standard_Integer nV1, nV2, j, aNbCurves;
214 Standard_Real aTolR3D, aTol2D, aT1, aT2, aTolPPC=Precision::PConfusion();
215 NMTTools_IndexedDataMapOfShapePaveBlock aMEPB;
216 BooleanOperations_IndexedDataMapOfShapeInteger aMapEI;
217 BOPTools_ListIteratorOfListOfPaveBlock anIt;
219 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
221 aNbFFs=aFFs.Extent();
223 NMTTools_DataMapOfIntegerListOfPaveBlock aMFInOn;
224 NMTTools_DataMapIteratorOfDataMapOfIntegerListOfPaveBlock aItMF;
227 Standard_Integer aNbS, aNbF, nF, aNbOn, nSp;
228 TopAbs_ShapeEnum aType;
229 BOPTools_ListIteratorOfListOfPaveBlock anItPB;
230 NMTTools_ListIteratorOfListOfCommonBlock aItCB;
231 TColStd_ListIteratorOfListOfInteger aItF;
233 aNbS=myDS->NumberOfShapesOfTheObject();
234 for (i=1; i<=aNbS; ++i) {
235 const TopoDS_Shape& aS=myDS->Shape(i);
236 aType=aS.ShapeType();
238 if (aType==TopAbs_EDGE) {
239 const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
240 aItCB.Initialize(aLCB);
241 for (; aItCB.More(); aItCB.Next()) {
242 const NMTTools_CommonBlock& aCB=aItCB.Value();
243 const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
245 const TColStd_ListOfInteger& aLF=aCB.Faces();
248 aItF.Initialize(aLF);
249 for (; aItF.More(); aItF.Next()) {
251 if (aMFInOn.IsBound(nF)) {
252 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
256 BOPTools_ListOfPaveBlock aLPB;
258 aMFInOn.Bind(nF, aLPB);
262 } // for (; aItCB.More(); aItCB.Next()) {
263 }//if (aS.ShapeType()==TopAbs_EDGE) {
265 else if (aType==TopAbs_FACE) {
266 BOPTools_ListOfPaveBlock aLPBOn;
269 RealSplitsFace(nF, aLPBOn);
271 aNbOn=aLPBOn.Extent();
273 if (aMFInOn.IsBound(nF)) {
274 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
278 aMFInOn.Bind(nF, aLPBOn);
282 } // for (i=1; i<=aNbS; ++i) {
284 // Refine ListOfPaveBlocks
285 aItMF.Initialize(aMFInOn);
286 for(; aItMF.More(); aItMF.Next()) {
287 TColStd_MapOfInteger aMTmp;
288 BOPTools_ListOfPaveBlock aLPBX;
291 BOPTools_ListOfPaveBlock& aLPB=aMFInOn.ChangeFind(nF);
292 anItPB.Initialize(aLPB);
293 for (; anItPB.More(); anItPB.Next()) {
294 const BOPTools_PaveBlock& aPB=anItPB.Value();
296 if (aMTmp.Add(nSp)) {
306 // 1. Produce Section Edges from intersection curves
307 // between each pair of faces
308 aNbFFs=aFFs.Extent();
310 for (i=1; i<=aNbFFs; ++i) {
311 BOPTools_SSInterference& aFFi=aFFs(i);
314 aFFi.Indices(nF1, nF2);
315 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
316 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
318 BOPTools_ListOfPaveBlock aLPB;
322 BOPTools_ListIteratorOfListOfPaveBlock anItPB;
323 NMTTools_MapOfPaveBlock aMPB;
325 if (aMFInOn.IsBound(nF1)) {
326 const BOPTools_ListOfPaveBlock& aLPBF1=aMFInOn.Find(nF1);
327 anItPB.Initialize(aLPBF1);
328 for (; anItPB.More(); anItPB.Next()) {
329 const BOPTools_PaveBlock& aPB=anItPB.Value();
335 if (aMFInOn.IsBound(nF2)) {
336 const BOPTools_ListOfPaveBlock& aLPBF2=aMFInOn.Find(nF2);
337 anItPB.Initialize(aLPBF2);
338 for (; anItPB.More(); anItPB.Next()) {
339 const BOPTools_PaveBlock& aPB=anItPB.Value();
340 if (aMPB.Contains(aPB)) {
341 aFFi.AppendBlock(aPB);
351 TopTools_ListOfShape aLSE;
352 TColStd_ListOfInteger aLNE;
353 SharedEdges(nF1, nF2, aLNE, aLSE);
354 aFFi.SetSharedEdges(aLNE);
356 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
357 aNbCurves=aSCvs.Length();
362 // Contribution of Samtech www.samcef.com END
363 aTolR3D=aFFi.TolR3D();
364 aTol2D=(aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
366 BOPTools_PaveSet aPSF;
368 PrepareSetForFace (nF1, nF2, aLPB, aPSF);
370 // Put Paves On Curves
371 for (j=1; j<=aNbCurves; ++j) {
372 BOPTools_Curve& aBC=aSCvs(j);
374 const IntTools_Curve& aC=aBC.Curve();
375 Handle(Geom_Curve) aC3D = aC.Curve();
377 PutPaveOnCurve (aPSF, aTolR3D, aBC);
380 // Put bounding paves on curves
381 for (j=1; j<=aNbCurves; ++j) {
382 BOPTools_Curve& aBC=aSCvs(j);
383 PutBoundPaveOnCurve (aBC, aFFi);
386 // Pave Blocks on Curves
387 bHasES=Standard_False;
388 for (j=1; j<=aNbCurves; ++j) {
389 BOPTools_Curve& aBC=aSCvs(j);
390 const IntTools_Curve& aIC= aBC.Curve();
391 BOPTools_PaveSet& aPaveSet=aBC.Set();
393 BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
394 for (; aPBIter.More(); aPBIter.Next()) {
395 BOPTools_PaveBlock& aPBNew=aPBIter.Value();
396 aPBNew.SetCurve(aIC);
397 aPBNew.SetFace1(nF1);
398 aPBNew.SetFace2(nF2);
400 nV1=aPBNew.Pave1().Index();
401 nV2=aPBNew.Pave2().Index();
402 aT1=aPBNew.Pave1().Param();
403 aT2=aPBNew.Pave2().Param();
405 if((nV1==nV2) && (Abs(aT2 - aT1) < aTolPPC)) {
406 continue;// mkk ft ???
410 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLPB, aTolR3D);
411 if (bIsExistingPaveBlock) {
415 bIsCoincided=CheckCoincidence(aPBNew, aLPB);
421 // to provide checking whether aPBNew already exists in list
422 // of section edges aLSE
423 // Thu Sep 14 14:35:18 2006
424 // Contribution of Samtech www.samcef.com BEGIN
426 bIsExistingPaveBlock=IsExistingPaveBlock(aPBNew, aLSE, aTolR3D);
427 if (bIsExistingPaveBlock) {
430 // Contribution of Samtech www.samcef.com END
432 // Checking of validity in 2D
434 bIsValidIn2D=myContext.IsValidBlockForFaces(aT1, aT2, aIC, aF1, aF2, aTol2D);
443 const TopoDS_Vertex aV1=TopoDS::Vertex(myDS->Shape(nV1));
444 const TopoDS_Vertex aV2=TopoDS::Vertex(myDS->Shape(nV2));
446 //modified by NIZNHY-PKV Thu Apr 22 07:54:35 2010f
450 myContext.IsVertexOnLine(aV1, aIC, aTolR3D, aT);
451 BOPTools_Tools::UpdateVertex (aIC, aT, aV1);
453 myContext.IsVertexOnLine(aV2, aIC, aTolR3D, aT);
454 BOPTools_Tools::UpdateVertex (aIC, aT, aV2);
456 //modified by NIZNHY-PKV Thu Apr 22 07:54:37 2010t
458 BOPTools_Tools::MakeSectEdge (aIC, aV1, aT1, aV2, aT2, aES);
460 NMTTools_Tools::UpdateEdge (aES, aTolR3D);
461 bIsMicroEdge=IsMicroEdge(aES, myContext);
467 Handle(Geom2d_Curve) aC2D1, aC2D2;
469 aC2D1=aIC.FirstCurve2d();
470 aC2D2=aIC.SecondCurve2d();
472 NMTTools_Tools::MakePCurve(aES, aF1, aC2D1);
473 NMTTools_Tools::MakePCurve(aES, aF2, aC2D2);
476 aMEPB.Add(aES, aPBNew);
479 bHasES=Standard_True;
480 }// for (; aPBIter.More(); aPBIter.Next())
481 } // end of for (j=1; j<=aNbCurves; ++j)
484 myIP->Add(nF1, nF2, Standard_True, NMTDS_TI_FF);
487 }// for (i=1; i<=aNbFFs; ++i)
488 //=============================================================
490 // II. Post treatment
492 // Input data: aMEPB, aMapEI
493 // Result : section edges in myDS
495 Standard_Integer aNbSE;
497 aNbSE=aMEPB.Extent();
499 // there is nothing to do here
504 TopoDS_Compound aCompound;
506 // 1. Make compound from SE
507 aBB.MakeCompound(aCompound);
508 for (i=1; i<=aNbSE; ++i) {
509 const TopoDS_Shape& aSE=aMEPB.FindKey(i);
510 aBB.Add(aCompound, aSE);
514 // 2. Intersect SE using auxiliary Filler
515 NMTTools_PaveFiller tPF;
517 tPF.SetCompositeShape(aCompound);
522 //tPF.PerformNewVertices(); qq
525 tPF.myPavePool.Resize (tPF.myNbEdges);
533 tPF.myCommonBlockPool.Resize (tPF.myNbEdges);
534 tPF.mySplitShapesPool.Resize (tPF.myNbEdges);
535 tPF.myPavePoolNew .Resize (tPF.myNbEdges);
537 tPF.PreparePaveBlocks(TopAbs_VERTEX, TopAbs_EDGE);
538 tPF.PreparePaveBlocks(TopAbs_EDGE, TopAbs_EDGE);
542 tPF.RefinePavePool ();
544 tPF.myPavePoolNew.Destroy();
546 tPF.MakeSplitEdges();
547 tPF.UpdateCommonBlocks();
549 // 3. Treatment of the result of intersection
551 Standard_Integer aNbOld, aNbLines, aNbPB, mV1, mV2, nE, mE, iFF;
552 TopAbs_ShapeEnum aType;
553 BOPTools_ListIteratorOfListOfPaveBlock aIt;
554 BOPTColStd_IndexedDataMapOfIntegerInteger aMNewOld;
556 const NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
557 const BOPTools_SplitShapesPool& aSSP=tPF.mySplitShapesPool;
558 const NMTTools_CommonBlockPool& aCBP=tPF.myCommonBlockPool;
560 aNbLines=tDS.NumberOfInsertedShapes();
561 aNbOld=tDS.NumberOfShapesOfTheObject();
563 // 3.1 Links between indices in tDS and DS (kept in aMNewOld)
565 // 3.1.1.Old vertices [ links ]
566 for (i=1; i<=aNbOld; ++i) {
567 const TopoDS_Shape& aV=tDS.Shape(i);
568 aType=aV.ShapeType();
569 if (aType!=TopAbs_VERTEX) {
573 for (j=1; j<=aNbSE; ++j) {
574 const BOPTools_PaveBlock& aPBSE=aMEPB(j);
575 nV1=aPBSE.Pave1().Index();
576 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
577 if (aV1.IsSame(aV)) {
578 aMNewOld.Add(i, nV1);
581 nV2=aPBSE.Pave2().Index();
582 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
583 if (aV2.IsSame(aV)) {
584 aMNewOld.Add(i, nV2);
590 // 3.1.2. New vertices [ links ]
591 i=tDS.NumberOfSourceShapes()+1;
592 for (; i<=aNbLines; ++i) {
593 const TopoDS_Shape& aV=tDS.Shape(i);
594 aType=aV.ShapeType();
595 if (aType!=TopAbs_VERTEX) {
599 // Insert new vertex in myDS
600 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
601 myDS->InsertShapeAndAncestorsSuccessors(aV, anASSeq);
602 nV1=myDS->NumberOfInsertedShapes();
604 aMNewOld.Add(i, nV1);
607 // 3.2. Treatment of section edges (SE)
608 for (i=1; i<=aNbOld; ++i) {
609 const TopoDS_Shape& aE=tDS.Shape(i);
610 aType=aE.ShapeType();
611 if (aType!=TopAbs_EDGE) {
615 // block of section edge that we already have for this SE
616 BOPTools_PaveBlock& aPBSE=aMEPB.ChangeFromKey(aE);
618 // Corresponding FF-interference
619 iFF=aMapEI.FindFromKey(aE);
620 BOPTools_SSInterference& aFFi=aFFs(iFF);
621 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
623 BOPTools_Curve& aBC=aSCvs(1);
625 const BOPTools_ListOfPaveBlock& aLPB=aSSP(tDS.RefEdge(i));
629 // no pave blocks -> use aPBSE and whole edge aE
630 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
632 nV1=aPBSE.Pave1().Index();
633 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
634 nV2=aPBSE.Pave2().Index();
635 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
637 anASSeq.SetNewSuccessor(nV1);
638 anASSeq.SetNewOrientation(aV1.Orientation());
639 anASSeq.SetNewSuccessor(nV2);
640 anASSeq.SetNewOrientation(aV2.Orientation());
642 myDS->InsertShapeAndAncestorsSuccessors(aE, anASSeq);
643 nE=myDS->NumberOfInsertedShapes();
646 aBC.AppendNewBlock(aPBSE);
654 const NMTTools_ListOfCommonBlock& aLCB=aCBP(tDS.RefEdge(i));
655 NMTTools_CommonBlockAPI aCBAPI(aLCB);
657 aIt.Initialize(aLPB);
658 for (; aIt.More(); aIt.Next()) {
659 BOPTools_PaveBlock aPB=aIt.Value();
661 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));
662 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));
664 if (aCBAPI.IsCommonBlock(aPB)) {
665 // it can be Common Block
666 Standard_Real aTolEx;
667 Handle(Geom2d_Curve) aC2D1, aC2D2;
668 TopoDS_Face aF1FWD, aF2FWD;
670 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
671 //const BOPTools_ListOfPaveBlock& aLPBx=aCB.PaveBlocks();
673 aPB=aCB.PaveBlock1();
674 mE=aPB.Edge(); // index of edge in tDS
675 const TopoDS_Edge& aEx=TopoDS::Edge(tDS.Shape(mE));
676 aTolEx=BRep_Tool::Tolerance(aEx);
679 aF1FWD.Orientation(TopAbs_FORWARD);
681 aF2FWD.Orientation(TopAbs_FORWARD);
683 NMTTools_Tools::MakePCurve(aEx, aF1FWD, aC2D1);
684 NMTTools_Tools::MakePCurve(aEx, aF2FWD, aC2D2);
685 NMTTools_Tools::UpdateEdge (aEx, aTolEx);
686 } //if (aCBAPI.IsCommonBlock(aPB))
689 mE=aPB.Edge(); // index of edge in tDS
690 const TopoDS_Shape& aSp=tDS.Shape(mE);
692 const BOPTools_Pave& aPave1=aPB.Pave1();
694 mV1=aPave1.Index(); // index in tDS
695 nV1=aMNewOld.FindFromKey(mV1); // index in myDS
696 const TopoDS_Shape aV1=myDS->Shape(nV1);//mpv
698 const BOPTools_Pave& aPave2=aPB.Pave2();
701 nV2=aMNewOld.FindFromKey(mV2);
702 const TopoDS_Shape aV2=myDS->Shape(nV2);//mpv
704 if (!aMNewOld.Contains(mE)) {
705 // add new SE to the myDS
706 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
708 anASSeq.SetNewSuccessor(nV1);
709 anASSeq.SetNewOrientation(aV1.Orientation());
711 anASSeq.SetNewSuccessor(nV2);
712 anASSeq.SetNewOrientation(aV2.Orientation());
714 myDS->InsertShapeAndAncestorsSuccessors(aSp, anASSeq);
715 nE=myDS->NumberOfInsertedShapes();
717 aMNewOld.Add(mE, nE);
720 nE=aMNewOld.FindFromKey(mE);
723 BOPTools_PaveBlock aPBx;
724 BOPTools_Pave aP1, aP2;
740 aBC.AppendNewBlock(aPBx);
741 }// for (; aIt.More(); aIt.Next())
742 }// for (i=1; i<=aNbOld; ++i)
744 myIsDone=Standard_True;
747 //=======================================================================
748 // function: MakePCurves
750 //=======================================================================
751 void NMTTools_PaveFiller::MakePCurves()
753 Standard_Integer i, aNb, nF1, nF2, nE;
754 Standard_Integer aNbCB, aNbF, nSp, nF;
755 TopAbs_ShapeEnum aType;
756 TopoDS_Face aF1FWD, aF2FWD;
757 TColStd_ListIteratorOfListOfInteger aItF;
758 BOPTools_ListIteratorOfListOfPaveBlock anIt;
759 NMTTools_ListIteratorOfListOfCommonBlock aItCB;
761 BOPTools_CArray1OfSSInterference& aFFs=myIP->SSInterferences();
764 for (i=1; i<=aNb; i++) {
765 BOPTools_SSInterference& aFF=aFFs(i);
766 aFF.Indices(nF1, nF2);
768 const TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));//mpv
769 const TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));//mpv
772 aF1FWD.Orientation(TopAbs_FORWARD);
774 aF2FWD.Orientation(TopAbs_FORWARD);
776 // In, On parts processing
777 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
779 anIt.Initialize(aLPBInOn);
780 for (; anIt.More(); anIt.Next()) {
781 const BOPTools_PaveBlock& aPB=anIt.Value();
783 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
785 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF1FWD);
786 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF2FWD);
789 // Check common blocks between edges and faces
790 // Build P-Curves if they were not built in previos block.
791 // The main case is :arguments for e.g aEdge, aFace -> no FFs,
792 // but p-curves are needed.
794 aNb=myDS->NumberOfShapesOfTheObject();
795 for (i=1; i<=aNb; ++i) {
796 const TopoDS_Shape& aS=myDS->Shape(i);
797 aType=aS.ShapeType();
799 if (aType!=TopAbs_EDGE) {
802 const TopoDS_Edge& aE=TopoDS::Edge(aS);
804 if (BRep_Tool::Degenerated(aE)) {
808 const NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(i));
814 aItCB.Initialize(aLCB);
815 for (; aItCB.More(); aItCB.Next()) {
816 const NMTTools_CommonBlock& aCB=aItCB.Value();
817 const BOPTools_PaveBlock &aPB1=aCB.PaveBlock1();
819 const TColStd_ListOfInteger& aLF=aCB.Faces();
826 const TopoDS_Edge aSp=TopoDS::Edge(myDS->Shape(nSp));//mpv
828 aItF.Initialize(aLF);
829 for (; aItF.More(); aItF.Next()) {
831 aF1FWD=TopoDS::Face(myDS->Shape(nF));
832 aF1FWD.Orientation(TopAbs_FORWARD);
834 BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aSp, aF1FWD);
835 } // for (; aItCB.More(); aItCB.Next()) {
836 }//if (aS.ShapeType()==TopAbs_EDGE) {
840 //=======================================================================
841 // function: IsExistingPaveBlock
843 //=======================================================================
844 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
845 const BOPTools_ListOfPaveBlock& aLPBR,
846 const Standard_Real aTolR3D)
848 Standard_Boolean bFlag;
849 Standard_Integer nVNew1, nVNew2, nV1, nV2, iC;
850 BOPTools_ListIteratorOfListOfPaveBlock anIt;
852 bFlag=Standard_False;
853 nVNew1=aPBNew.Pave1().Index();
854 nVNew2=aPBNew.Pave2().Index();
856 anIt.Initialize(aLPBR);
857 for (; anIt.More(); anIt.Next()) {
858 const BOPTools_PaveBlock& aPBR=anIt.Value();
859 nV1=aPBR.Pave1().Index();
860 nV2=aPBR.Pave2().Index();
861 if (nVNew1==nV1 || nVNew1==nV2 || nVNew2==nV1 || nVNew2==nV2) {
863 iC=CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
872 //=======================================================================
873 // function: IsExistingPaveBlock
875 //=======================================================================
876 Standard_Boolean NMTTools_PaveFiller::IsExistingPaveBlock(const BOPTools_PaveBlock& aPBNew,
877 const TopTools_ListOfShape& aLSE,
878 const Standard_Real aTolR3D)
880 Standard_Boolean bFlag;
881 Standard_Integer aNbSE, iC;
882 Standard_Real aTolE, aTol;
883 TopTools_ListIteratorOfListOfShape anIt;
885 bFlag=Standard_False;
892 anIt.Initialize(aLSE);
893 for (; anIt.More(); anIt.Next()) {
894 const TopoDS_Edge& aE=TopoDS::Edge(anIt.Value());
895 aTolE=BRep_Tool::Tolerance(aE);
900 iC=CheckIntermediatePoint(aPBNew, aE, aTol);
908 //=======================================================================
909 // function: CheckIntermediatePoint
911 //=======================================================================
912 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
913 const BOPTools_PaveBlock& aPBR,
914 const Standard_Real aTolC)
916 Standard_Integer iVM, nE2;
919 const TopoDS_Edge aE2=TopoDS::Edge(myDS->Shape(nE2));//mpv
920 iVM=CheckIntermediatePoint(aPB, aE2, aTolC);
925 //=======================================================================
926 // function: CheckIntermediatePoint
928 //=======================================================================
929 Standard_Integer NMTTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
930 const TopoDS_Edge& aE2,
931 const Standard_Real aTolC)
933 Standard_Real aT11, aT12, aTM, aTmp;
934 Standard_Integer iVM;
940 const BOPTools_Pave& aPave11=aPB.Pave1();
941 aT11=aPave11.Param();
943 const BOPTools_Pave& aPave12=aPB.Pave2();
944 aT12=aPave12.Param();
946 aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
948 const IntTools_Curve& aIC=aPB.Curve();
951 aBB.MakeVertex (aVM, aPM, aTolC);
953 iVM=myContext.ComputeVE(aVM, aE2, aTmp);
958 //=======================================================================
959 // function: PutBoundPaveOnCurve
961 //=======================================================================
962 void NMTTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
963 BOPTools_SSInterference& aFFi)
965 Standard_Boolean bHasBounds, bVF;
966 Standard_Integer nF1, nF2;
967 Standard_Real aT1, aT2, aTolR3D;
970 const IntTools_Curve& aIC=aBC.Curve();
971 bHasBounds=aIC.HasBounds ();
977 aIC.Bounds (aT1, aT2, aP1, aP2);
980 aFFi.Indices(nF1, nF2);
981 aTolR3D=aFFi.TolR3D();
983 const TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));//mpv
984 const TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));//mpv
986 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
988 PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
991 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
993 PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
997 //=======================================================================
998 // function: PutBoundPaveOnCurve
1000 //=======================================================================
1001 void NMTTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
1002 const Standard_Real aT,
1003 BOPTools_Curve& aBC,
1004 BOPTools_SSInterference& aFFi)
1006 Standard_Boolean bFound1, bFound2;
1007 Standard_Integer nV;
1008 Standard_Real aTolV=aFFi.TolR3D();
1010 BOPTools_Pave aPave1, aPave2, aPave;
1011 BOPTools_PaveSet& aCPS=aBC.Set();
1012 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
1013 const IntTools_Curve& aIC=aBC.Curve();
1015 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
1016 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
1018 if (!bFound1 && !bFound2) {
1019 TopoDS_Vertex aNewVertex;
1020 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
1022 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
1023 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
1024 nV=myDS->NumberOfInsertedShapes();
1029 aFFiPS.Append(aPave);
1031 // Append Techno Vertex to the Curve
1032 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
1035 if (bFound1 && !bFound2) {
1039 aFFiPS.Append(aPave);
1041 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1042 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1045 if (!bFound1 && bFound2) {
1051 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1052 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1056 //=======================================================================
1057 // function: FindPave
1059 //=======================================================================
1060 Standard_Boolean NMTTools_PaveFiller::FindPave(const gp_Pnt& aP,
1061 const Standard_Real aTolPV,
1062 const BOPTools_PaveSet& aPS,
1063 BOPTools_Pave& aPave)
1065 Standard_Integer nV;
1066 Standard_Boolean bIsVertex=Standard_False;
1068 const BOPTools_ListOfPave& aLP=aPS.Set();
1069 BOPTools_ListIteratorOfListOfPave anIt(aLP);
1070 for (; anIt.More(); anIt.Next()) {
1071 const BOPTools_Pave& aPC=anIt.Value();
1073 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1074 bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
1083 //=======================================================================
1084 // function: PrepareSetForFace
1086 //=======================================================================
1087 void NMTTools_PaveFiller::PrepareSetForFace(const Standard_Integer ,//nF1,
1088 const Standard_Integer ,//nF2,
1089 const BOPTools_ListOfPaveBlock& aLPBC,
1090 BOPTools_PaveSet& aPSF)
1092 Standard_Integer nV1, nV2;
1093 TColStd_MapOfInteger aMap;
1094 BOPTools_ListIteratorOfListOfPaveBlock anIt;
1096 anIt.Initialize(aLPBC);
1097 for (; anIt.More(); anIt.Next()) {
1098 const BOPTools_PaveBlock& aPB=anIt.Value();
1099 const BOPTools_Pave& aPave1=aPB.Pave1();
1101 if (!aMap.Contains(nV1)) {
1103 aPSF.Append(aPave1);
1105 const BOPTools_Pave& aPave2=aPB.Pave2();
1107 if (!aMap.Contains(nV2)) {
1109 aPSF.Append(aPave2);
1114 //=======================================================================
1115 // function: CheckCoincidence
1117 //=======================================================================
1118 Standard_Boolean NMTTools_PaveFiller::CheckCoincidence(const BOPTools_PaveBlock& aPBNew,
1119 const BOPTools_ListOfPaveBlock& aLPBFF)
1121 Standard_Boolean bRet;
1123 Standard_Integer nV11, nV12, nV21, nV22, iVV, iVE, nE2;
1124 Standard_Integer iV, iCount, iCountExt;
1125 BOPTools_ListIteratorOfListOfPaveBlock anIt;
1127 const BOPTools_Pave& aPave11=aPBNew.Pave1();
1128 nV11=aPave11.Index();
1129 const TopoDS_Vertex& aV11=TopoDS::Vertex(myDS->Shape(nV11));
1132 const BOPTools_Pave& aPave12=aPBNew.Pave2();
1133 nV12=aPave12.Index();
1134 const TopoDS_Vertex& aV12=TopoDS::Vertex(myDS->Shape(nV12));
1138 anIt.Initialize(aLPBFF);
1139 for (; anIt.More(); anIt.Next()) {
1142 const BOPTools_PaveBlock& aPBR=anIt.Value();
1144 const BOPTools_Pave& aPave21=aPBR.Pave1();
1145 nV21=aPave21.Index();
1148 const BOPTools_Pave& aPave22=aPBR.Pave2();
1149 nV22=aPave22.Index();
1151 if (nV11==nV21 || nV11==nV22 || nV12==nV21 || nV12==nV22) {
1158 const TopoDS_Vertex& aV21=TopoDS::Vertex(myDS->Shape(nV21));
1159 const TopoDS_Vertex& aV22=TopoDS::Vertex(myDS->Shape(nV22));
1160 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->Shape(nE2));
1164 iVV=IntTools_Tools::ComputeVV (aV11, aV21);
1168 if (iCount>iCountExt) {
1173 iVV=IntTools_Tools::ComputeVV (aV11, aV22);
1177 if (iCount>iCountExt) {
1183 iVE=myContext.ComputeVE (aV11, aE2, aTE);
1186 if (iCount>iCountExt) {
1193 iVV=IntTools_Tools::ComputeVV (aV12, aV21);
1197 if (iCount>iCountExt) {
1202 iVV=IntTools_Tools::ComputeVV (aV12, aV22);
1206 if (iCount>iCountExt) {
1212 iVE=myContext.ComputeVE (aV12, aE2, aTE);
1215 if (iCount>iCountExt) {
1221 bRet=(Standard_Boolean)(iCount>iCountExt);
1225 //=======================================================================
1226 //function : IsMicroEdge
1228 //=======================================================================
1229 Standard_Boolean IsMicroEdge(const TopoDS_Edge& aE,
1230 IntTools_Context& aCtx)
1232 Standard_Boolean bRet;
1233 Standard_Integer iErr;
1234 Standard_Real aT1, aT2, aTmp;
1235 Handle(Geom_Curve) aC3D;
1236 TopoDS_Vertex aV1, aV2;
1239 bRet=(BRep_Tool::Degenerated(aE) ||
1240 !BRep_Tool::IsGeometric(aE));
1245 aC3D=BRep_Tool::Curve(aE, aT1, aT2);
1246 TopExp::Vertices(aE, aV1, aV2);
1247 aT1=BRep_Tool::Parameter(aV1, aE);
1248 aT2=BRep_Tool::Parameter(aV2, aE);
1257 IntTools_ShrunkRange aSR (aE, aV1, aV2, aR, aCtx);
1258 iErr=aSR.ErrorStatus();
1264 //=======================================================================
1265 // function: PutPaveOnCurve
1267 //=======================================================================
1268 void NMTTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
1269 const Standard_Real aTolR3D,
1270 BOPTools_Curve& aBC)
1272 Standard_Integer nV;
1273 Standard_Boolean bIsVertexOnLine;
1275 BOPTools_ListIteratorOfListOfPave anIt;
1277 GeomAdaptor_Curve aGAC;
1279 const IntTools_Curve& aC=aBC.Curve();
1280 Handle (Geom_Curve) aC3D= aC.Curve();
1282 BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBBC);
1284 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1285 anIt.Initialize(aLP);
1286 for (; anIt.More(); anIt.Next()) {
1287 const BOPTools_Pave& aPave=anIt.Value();
1290 const TopoDS_Vertex aV=TopoDS::Vertex(myDS->Shape(nV));//mpv
1293 BRepBndLib::Add(aV, aBBV);
1294 if (aBBC.IsOut(aBBV)){
1298 bIsVertexOnLine=myContext.IsVertexOnLine(aV, aC, aTolR3D, aT);
1300 if (bIsVertexOnLine) {
1301 BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1302 BOPTools_PaveSet& aPS=aBC.Set();
1303 aPS.Append(aPaveNew);
1305 //modified by NIZNHY-PKV Thu Apr 22 10:36:45 2010f
1306 //BOPTools_Tools::UpdateVertex (aC, aT, aV);
1307 //modified by NIZNHY-PKV Thu Apr 22 10:36:48 2010t