0028786: Refactoring of the Warning/Error reporting system of Boolean Operations...
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_7.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
4e57c75e 3// Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4// Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5// EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6//
973c2be1 7// This file is part of Open CASCADE Technology software library.
4e57c75e 8//
d5f74e42 9// This library is free software; you can redistribute it and/or modify it under
10// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 11// by the Free Software Foundation, with special exception defined in the file
12// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13// distribution for complete text of the license and disclaimer of any warranty.
4e57c75e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
4e57c75e 17
42cf5bc1 18#include <BOPAlgo_PaveFiller.hxx>
19#include <BOPAlgo_SectionAttribute.hxx>
3510db62 20#include <BOPAlgo_Tools.hxx>
319da2e4 21#include <BOPCol_IndexedMapOfShape.hxx>
505abfb8 22#include <BOPCol_NCVector.hxx>
c7b59798 23#include <BOPCol_Parallel.hxx>
4e57c75e 24#include <BOPDS_CommonBlock.hxx>
42cf5bc1 25#include <BOPDS_Curve.hxx>
26#include <BOPDS_DS.hxx>
27#include <BOPDS_FaceInfo.hxx>
28#include <BOPDS_Interf.hxx>
29#include <BOPDS_Iterator.hxx>
30#include <BOPDS_ListOfPaveBlock.hxx>
31#include <BOPDS_MapOfPaveBlock.hxx>
4e57c75e 32#include <BOPDS_Pave.hxx>
42cf5bc1 33#include <BOPDS_PaveBlock.hxx>
4e57c75e 34#include <BOPDS_ShapeInfo.hxx>
4e57c75e 35#include <BOPDS_VectorOfCurve.hxx>
36#include <BOPDS_VectorOfFaceInfo.hxx>
42cf5bc1 37#include <BOPDS_VectorOfInterfFF.hxx>
38#include <BOPDS_VectorOfListOfPaveBlock.hxx>
f1baf495 39#include <BOPTools_AlgoTools.hxx>
40#include <BOPTools_AlgoTools2D.hxx>
42cf5bc1 41#include <BRep_Builder.hxx>
42#include <BRep_Tool.hxx>
43#include <BRepBndLib.hxx>
44#include <Geom2d_Curve.hxx>
45#include <Geom_Curve.hxx>
46#include <Geom_Plane.hxx>
47#include <Geom_RectangularTrimmedSurface.hxx>
48#include <Geom_Surface.hxx>
3510db62 49#include <GeomAPI_ProjectPointOnCurve.hxx>
50#include <GeomAPI_ProjectPointOnSurf.hxx>
42cf5bc1 51#include <gp_Pnt.hxx>
52#include <IntTools_Context.hxx>
3510db62 53#include <IntTools_Tools.hxx>
42cf5bc1 54#include <TopExp.hxx>
55#include <TopExp_Explorer.hxx>
3510db62 56#include <TopoDS.hxx>
42cf5bc1 57#include <TopoDS_Edge.hxx>
58#include <TopoDS_Face.hxx>
59#include <TopoDS_Vertex.hxx>
f1baf495 60
319da2e4 61
f1baf495 62static
63 Standard_Boolean IsBasedOnPlane(const TopoDS_Face& aF);
4e57c75e 64
505abfb8 65
4e57c75e 66static void UpdateVertices(const TopoDS_Edge& aE,
67 const TopoDS_Face& aF);
68
69//=======================================================================
505abfb8 70//class : BOPAlgo_SplitEdge
71//purpose :
72//=======================================================================
36f4947b 73class BOPAlgo_SplitEdge : public BOPAlgo_Algo {
74
505abfb8 75 public:
36f4947b 76 DEFINE_STANDARD_ALLOC
77
78 BOPAlgo_SplitEdge() :
79 BOPAlgo_Algo() {
505abfb8 80 myT1=0.;
81 myT2=0.;
3510db62 82 myTol = 0.;
505abfb8 83 }
84 //
36f4947b 85 virtual ~BOPAlgo_SplitEdge() {
505abfb8 86 }
87 //
88 void SetData(const TopoDS_Edge& aE,
89 const TopoDS_Vertex& aV1,
90 const Standard_Real aT1,
91 const TopoDS_Vertex& aV2,
92 const Standard_Real aT2) {
93 myE=aE;
94 myV1=aV1;
95 myT1=aT1;
96 myV2=aV2;
97 myT2=aT2;
98 myESp=aE;
99 }
100 //
101 void SetPaveBlock(const Handle(BOPDS_PaveBlock)& aPB) {
102 myPB=aPB;
103 }
104 //
105 Handle(BOPDS_PaveBlock)& PaveBlock() {
106 return myPB;
107 }
108 //
109 void SetCommonBlock(const Handle(BOPDS_CommonBlock)& aCB) {
110 myCB=aCB;
111 }
112 //
113 Handle(BOPDS_CommonBlock)& CommonBlock() {
114 return myCB;
115 }
116 //
117 const TopoDS_Edge& SplitEdge() const {
118 return myESp;
119 }
120 //
121 const Bnd_Box Box() {
122 return myBox;
123 }
124 //
3510db62 125 Standard_Real Tolerance() const {
126 return myTol;
127 }
128 //
129 void SetDS(const BOPDS_PDS theDS) {
130 myDS = theDS;
131 }
132 //
133 void SetContext(const Handle(IntTools_Context)& aContext) {
134 myContext = aContext;
135 }
136 //
36f4947b 137 virtual void Perform () {
138 BOPAlgo_Algo::UserBreak();
3510db62 139 myTol = BOPAlgo_Tools::ComputeToleranceOfCB(myCB, myDS, myContext);
505abfb8 140 BOPTools_AlgoTools::MakeSplitEdge(myE,
141 myV1, myT1,
142 myV2, myT2,
143 myESp);
3510db62 144 BRepBndLib::Add(myESp, myBox);
145 myBox.SetGap(myBox.GetGap() + Precision::Confusion());
505abfb8 146 }
147 //
148 protected:
149 // ->
150 TopoDS_Edge myE;
151 TopoDS_Vertex myV1;
152 Standard_Real myT1;
153 TopoDS_Vertex myV2;
154 Standard_Real myT2;
155 // <->
156 Handle(BOPDS_PaveBlock) myPB;
157 Handle(BOPDS_CommonBlock) myCB;
158 // <-
159 TopoDS_Edge myESp;
160 Bnd_Box myBox;
3510db62 161 Standard_Real myTol;
162 //
163 BOPDS_PDS myDS;
164 Handle(IntTools_Context) myContext;
505abfb8 165};
166//
167//=======================================================================
168typedef BOPCol_NCVector
169 <BOPAlgo_SplitEdge> BOPAlgo_VectorOfSplitEdge;
170//
3510db62 171typedef BOPCol_ContextFunctor
505abfb8 172 <BOPAlgo_SplitEdge,
3510db62 173 BOPAlgo_VectorOfSplitEdge,
174 Handle(IntTools_Context),
175 IntTools_Context> BOPAlgo_SplitEdgeFunctor;
505abfb8 176//
3510db62 177typedef BOPCol_ContextCnt
505abfb8 178 <BOPAlgo_SplitEdgeFunctor,
3510db62 179 BOPAlgo_VectorOfSplitEdge,
180 Handle(IntTools_Context)> BOPAlgo_SplitEdgeCnt;
505abfb8 181//
182//=======================================================================
f1baf495 183//class : BOPAlgo_MPC
184//purpose :
185//=======================================================================
36f4947b 186class BOPAlgo_MPC : public BOPAlgo_Algo {
187
f1baf495 188 public:
36f4947b 189 DEFINE_STANDARD_ALLOC
190
191 BOPAlgo_MPC() :
192 BOPAlgo_Algo(),
193 myFlag(Standard_False) {
f1baf495 194 };
195 //
36f4947b 196 virtual ~BOPAlgo_MPC(){
f1baf495 197 };
198 //
199 void SetEdge(const TopoDS_Edge& aE) {
200 myE=aE;
201 }
202 //
203 const TopoDS_Edge& Edge() const {
204 return myE;
205 }
206 //
207 void SetFace(const TopoDS_Face& aF) {
208 myF=aF;
209 }
210 //
211 const TopoDS_Face& Face() const {
212 return myF;
213 }
214 //
215 void SetFlag(const Standard_Boolean bFlag) {
216 myFlag=bFlag;
217 }
218 //
219 Standard_Boolean Flag() const {
220 return myFlag;
221 }
222 //
905522ee 223 void SetData(const TopoDS_Edge& aEz,
224 const TopoDS_Vertex& aV1,
225 const Standard_Real aT1,
226 const TopoDS_Vertex& aV2,
227 const Standard_Real aT2) {
228 myEz=aEz;
229 myV1=aV1;
230 myT1=aT1;
231 myV2=aV2;
232 myT2=aT2;
233 }
234 //
235 void SetContext(const Handle(IntTools_Context)& aContext) {
236 myContext=aContext;
237 }
238 //
239 const Handle(IntTools_Context)& Context()const {
240 return myContext;
241 }
242 //
36f4947b 243 virtual void Perform() {
905522ee 244 Standard_Integer iErr;
245 //
246 iErr=1;
247 if (!myEz.IsNull()) {
248 TopoDS_Edge aSpz;
249 //
250 BOPTools_AlgoTools::MakeSplitEdge(myEz,myV1, myT1,
251 myV2, myT2, aSpz);
252 //
253 iErr=
254 BOPTools_AlgoTools2D::AttachExistingPCurve(aSpz,
255 myE,
256 myF,
257 myContext);
258 }
259 //
260 if (iErr) {
51db0179 261 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(myE, myF, myContext);
905522ee 262 }
263 //
f1baf495 264 if (myFlag) {
265 UpdateVertices(myE, myF);
266 }
267 }
268 //
269 protected:
270 Standard_Boolean myFlag;
271 TopoDS_Edge myE;
272 TopoDS_Face myF;
905522ee 273 TopoDS_Edge myEz;
274 TopoDS_Vertex myV1;
275 Standard_Real myT1;
276 TopoDS_Vertex myV2;
277 Standard_Real myT2;
278 //
279 Handle(IntTools_Context) myContext;
f1baf495 280};
281//
282//=======================================================================
283typedef BOPCol_NCVector
284 <BOPAlgo_MPC> BOPAlgo_VectorOfMPC;
285//
905522ee 286typedef BOPCol_ContextFunctor
f1baf495 287 <BOPAlgo_MPC,
905522ee 288 BOPAlgo_VectorOfMPC,
289 Handle(IntTools_Context),
290 IntTools_Context> BOPAlgo_MPCFunctor;
f1baf495 291//
905522ee 292typedef BOPCol_ContextCnt
f1baf495 293 <BOPAlgo_MPCFunctor,
905522ee 294 BOPAlgo_VectorOfMPC,
295 Handle(IntTools_Context)> BOPAlgo_MPCCnt;
f1baf495 296//
297//=======================================================================
298//class : BOPAlgo_BPC
299//purpose :
300//=======================================================================
301class BOPAlgo_BPC {
302 public:
303 BOPAlgo_BPC(){
304 };
305 //
306 ~BOPAlgo_BPC(){
307 };
308 //
309 void SetFace(const TopoDS_Face& aF) {
310 myF=aF;
311 }
312 //
313 void SetEdge(const TopoDS_Edge& aE) {
314 myE=aE;
315 }
316 //
2078dfc7 317 const TopoDS_Edge& GetEdge() const {
318 return myE;
319 }
320 const TopoDS_Face& GetFace() const {
321 return myF;
322 }
92efcf78 323 const Handle(Geom2d_Curve)& GetCurve2d() const {
2078dfc7 324 return myCurve;
325 }
326 Standard_Boolean IsToUpdate() const {
327 return myToUpdate;
328 }
329 //
f1baf495 330 void Perform() {
2078dfc7 331 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnPlane (myE, myF, myCurve, myToUpdate);
f1baf495 332 };
333 //
334 protected:
335 TopoDS_Edge myE;
336 TopoDS_Face myF;
92efcf78 337 Handle(Geom2d_Curve) myCurve;
2078dfc7 338 Standard_Boolean myToUpdate;
f1baf495 339};
340//=======================================================================
341typedef BOPCol_NCVector
342 <BOPAlgo_BPC> BOPAlgo_VectorOfBPC;
343//
c7b59798 344typedef BOPCol_Functor
f1baf495 345 <BOPAlgo_BPC,
346 BOPAlgo_VectorOfBPC> BOPAlgo_BPCFunctor;
347//
c7b59798 348typedef BOPCol_Cnt
f1baf495 349 <BOPAlgo_BPCFunctor,
350 BOPAlgo_VectorOfBPC> BOPAlgo_BPCCnt;
351//
352//
353//=======================================================================
4e57c75e 354// function: MakeSplitEdges
355// purpose:
356//=======================================================================
505abfb8 357void BOPAlgo_PaveFiller::MakeSplitEdges()
4e57c75e 358{
4e57c75e 359 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
33ba8565 360 Standard_Integer aNbPBP = aPBP.Extent();
4e57c75e 361 if(!aNbPBP) {
362 return;
363 }
364 //
78c66ef1 365 Standard_Boolean bCB, bV1, bV2;
505abfb8 366 Standard_Integer i, nE, nV1, nV2, nSp, aNbPB, aNbVBSE, k;
4e57c75e 367 Standard_Real aT1, aT2;
3510db62 368 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
505abfb8 369 Handle(BOPDS_PaveBlock) aPB;
370 BOPDS_MapOfPaveBlock aMPB(100);
371 TopoDS_Vertex aV1, aV2;
372 TopoDS_Edge aE;
373 BOPAlgo_VectorOfSplitEdge aVBSE;
374
4e57c75e 375 //
3510db62 376 UpdateCommonBlocksWithSDVertices();
377 //
378 aNbPBP=aPBP.Extent();
379 //
4e57c75e 380 for (i=0; i<aNbPBP; ++i) {
381 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
382 //
383 aNbPB=aLPB.Extent();
4e57c75e 384 if (aNbPB==1) {
385 aPB=aLPB.First();
386 aPB->Indices(nV1, nV2);
387 bV1=myDS->IsNewShape(nV1);
388 bV2=myDS->IsNewShape(nV2);
3510db62 389 bCB=myDS->IsCommonBlock(aPB);
4e57c75e 390 //
3510db62 391 if (!(bV1 || bV2)) { // no new vertices here
edfa30de 392 if (!myNonDestructive || !bCB) {
393 if (bCB) {
394 if (!aPB->HasEdge()) {
395 const Handle(BOPDS_CommonBlock)& aCB = myDS->CommonBlock(aPB);
396 nE = aCB->PaveBlock1()->OriginalEdge();
397 aCB->SetEdge(nE);
398 // Compute tolerance of the common block and update the edge
399 Standard_Real aTol = BOPAlgo_Tools::ComputeToleranceOfCB(aCB, myDS, myContext);
400 myDS->UpdateEdgeTolerance(nE, aTol);
401 }
402 }
403 else {
404 nE = aPB->OriginalEdge();
405 aPB->SetEdge(nE);
3510db62 406 }
407 continue;
408 }
4e57c75e 409 }
410 }
411 //
412 aItPB.Initialize(aLPB);
413 for (; aItPB.More(); aItPB.Next()) {
414 aPB=aItPB.Value();
3510db62 415 nE=aPB->OriginalEdge();
416 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
417 if (aSIE.HasFlag()){
418 continue;
419 }
420 //
5a77460e 421 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
4e57c75e 422 bCB=!aCB.IsNull();
423 if (bCB) {
4e57c75e 424 aPB=aCB->PaveBlock1();
425 }
426 //
427 if (aMPB.Add(aPB)) {
428 nE=aPB->OriginalEdge();
78c66ef1 429 aPB->Indices(nV1, nV2);
430 aPB->Range(aT1, aT2);
4e57c75e 431 //
505abfb8 432 aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
433 aE.Orientation(TopAbs_FORWARD);
434 //
435 aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
436 aV1.Orientation(TopAbs_FORWARD);
4e57c75e 437 //
505abfb8 438 aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
439 aV2.Orientation(TopAbs_REVERSED);
440 //
441 BOPAlgo_SplitEdge& aBSE=aVBSE.Append1();
442 //
443 aBSE.SetData(aE, aV1, aT1, aV2, aT2);
444 aBSE.SetPaveBlock(aPB);
4e57c75e 445 if (bCB) {
505abfb8 446 aBSE.SetCommonBlock(aCB);
4e57c75e 447 }
3510db62 448 aBSE.SetDS(myDS);
36f4947b 449 aBSE.SetProgressIndicator(myProgressIndicator);
505abfb8 450 }
451 } // for (; aItPB.More(); aItPB.Next()) {
452 } // for (i=0; i<aNbPBP; ++i) {
453 //
454 aNbVBSE=aVBSE.Extent();
455 //======================================================
3510db62 456 BOPAlgo_SplitEdgeCnt::Perform(myRunParallel, aVBSE, myContext);
505abfb8 457 //======================================================
458 //
459 BOPDS_ShapeInfo aSI;
4e57c75e 460 //
505abfb8 461 aSI.SetShapeType(TopAbs_EDGE);
462 //
463 for (k=0; k < aNbVBSE; ++k) {
464 BOPAlgo_SplitEdge& aBSE=aVBSE(k);
465 //
466 const TopoDS_Edge& aSp=aBSE.SplitEdge();
467 const Bnd_Box& aBox=aBSE.Box();
468 //
469 Handle(BOPDS_PaveBlock) aPBk=aBSE.PaveBlock();
470 Handle(BOPDS_CommonBlock)& aCBk=aBSE.CommonBlock();
471 //
472 aSI.SetShape(aSp);
473 aSI.ChangeBox()=aBox;
474 //
475 nSp=myDS->Append(aSI);
476 //
477 if (!aCBk.IsNull()) {
3510db62 478 myDS->UpdateEdgeTolerance(nSp, aBSE.Tolerance());
505abfb8 479 aCBk->SetEdge(nSp);
480 }
481 else {
482 aPBk->SetEdge(nSp);
483 }
484 }
4e57c75e 485}
3510db62 486
4e57c75e 487//=======================================================================
78c66ef1 488// function: SplitEdge
489// purpose:
490//=======================================================================
491Standard_Integer BOPAlgo_PaveFiller::SplitEdge(const Standard_Integer nE,
492 const Standard_Integer nV1,
493 const Standard_Real aT1,
494 const Standard_Integer nV2,
495 const Standard_Real aT2)
496{
497 Standard_Integer nSp;
498 TopoDS_Vertex aV1, aV2;
499 TopoDS_Edge aE, aSp;
500 BOPDS_ShapeInfo aSI;
501 //
502 aSI.SetShapeType(TopAbs_EDGE);
503 //
504 aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
505 aE.Orientation(TopAbs_FORWARD);
506 //
507 aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
508 aV1.Orientation(TopAbs_FORWARD);
509 //
510 aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
511 aV2.Orientation(TopAbs_REVERSED);
512 //
513 BOPTools_AlgoTools::MakeSplitEdge(aE, aV1, aT1, aV2, aT2, aSp);
514 //
515 aSI.SetShape(aSp);
516 //
517 Bnd_Box& aBox=aSI.ChangeBox();
518 BRepBndLib::Add(aSp, aBox);
3510db62 519 aBox.SetGap(aBox.GetGap() + Precision::Confusion());
78c66ef1 520 //
521 nSp=myDS->Append(aSI);
522 return nSp;
523}
78c66ef1 524//=======================================================================
4e57c75e 525// function: MakePCurves
526// purpose:
527//=======================================================================
505abfb8 528void BOPAlgo_PaveFiller::MakePCurves()
4e57c75e 529{
0c5a6d47 530 if (myAvoidBuildPCurve ||
531 (!mySectionAttribute.PCurveOnS1() && !mySectionAttribute.PCurveOnS2()))
532 return;
905522ee 533 Standard_Boolean bHasPC;
534 Standard_Integer i, nF1, nF2, aNbC, k, nE, aNbFF, aNbFI, nEx;
319da2e4 535 Standard_Integer j, aNbPBIn, aNbPBOn;
4e57c75e 536 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
4e57c75e 537 TopoDS_Face aF1F, aF2F;
f1baf495 538 BOPAlgo_VectorOfMPC aVMPC;
4e57c75e 539 //
4e57c75e 540 // 1. Process Common Blocks
541 const BOPDS_VectorOfFaceInfo& aFIP=myDS->FaceInfoPool();
542 //
543 aNbFI=aFIP.Extent();
544 for (i=0; i<aNbFI; ++i) {
545 const BOPDS_FaceInfo& aFI=aFIP(i);
546 nF1=aFI.Index();
547 //
548 aF1F=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
549 aF1F.Orientation(TopAbs_FORWARD);
550 // In
551 const BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.PaveBlocksIn();
319da2e4 552 aNbPBIn = aMPBIn.Extent();
553 for (j = 1; j <= aNbPBIn; ++j) {
554 const Handle(BOPDS_PaveBlock)& aPB = aMPBIn(j);
4e57c75e 555 nE=aPB->Edge();
556 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
557 //
f1baf495 558 BOPAlgo_MPC& aMPC=aVMPC.Append1();
559 aMPC.SetEdge(aE);
560 aMPC.SetFace(aF1F);
36f4947b 561 aMPC.SetProgressIndicator(myProgressIndicator);
4e57c75e 562 }
f1baf495 563 //
4e57c75e 564 // On
565 const BOPDS_IndexedMapOfPaveBlock& aMPBOn=aFI.PaveBlocksOn();
319da2e4 566 aNbPBOn = aMPBOn.Extent();
567 for (j = 1; j <= aNbPBOn; ++j) {
568 const Handle(BOPDS_PaveBlock)& aPB = aMPBOn(j);
905522ee 569 nE=aPB->Edge();
570 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
571 bHasPC=BOPTools_AlgoTools2D::HasCurveOnSurface (aE, aF1F);
572 if (bHasPC) {
573 continue;
574 }
575 //
576 Handle(BOPDS_CommonBlock) aCB=myDS->CommonBlock(aPB);
c04c30b3 577 if (aCB.IsNull()) {
905522ee 578 continue;
579 }
580 //
581 const BOPDS_ListOfPaveBlock& aLPB=aCB->PaveBlocks();
582 if (aLPB.Extent()<2) {
583 continue;
584 }
585 //
586 BOPAlgo_MPC& aMPC=aVMPC.Append1();
587 //
588 aItLPB.Initialize(aLPB);
589 for(; aItLPB.More(); aItLPB.Next()) {
590 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
591 if (aPBx==aPB) {
592 continue;
593 }
594 //
595 nEx=aPBx->OriginalEdge();
596 const TopoDS_Edge& aEx=(*(TopoDS_Edge *)(&myDS->Shape(nEx)));
597 bHasPC=BOPTools_AlgoTools2D::HasCurveOnSurface (aEx, aF1F);
598 if (!bHasPC) {
599 continue;
600 }
601 //
602 Standard_Integer nV1x, nV2x;
603 Standard_Real aT1x, aT2x;
604 TopoDS_Vertex aV1x, aV2x;
605 TopoDS_Edge aEz;
606 //
607 aEz=aEx;
608 aEz.Orientation(TopAbs_FORWARD);
609 //
610 aPBx->Indices(nV1x, nV2x);
611 aPBx->Range(aT1x, aT2x);
612 //
613 aV1x=(*(TopoDS_Vertex *)(&myDS->Shape(nV1x)));
614 aV1x.Orientation(TopAbs_FORWARD);
4e57c75e 615 //
905522ee 616 aV2x=(*(TopoDS_Vertex *)(&myDS->Shape(nV2x)));
617 aV2x.Orientation(TopAbs_REVERSED);
618 //
619 aMPC.SetData(aEz, aV1x, aT1x, aV2x, aT2x);
620 //
621 break;
4e57c75e 622 }
905522ee 623 //
624 aMPC.SetEdge(aE);
625 aMPC.SetFace(aF1F);
626 aMPC.SetProgressIndicator(myProgressIndicator);
4e57c75e 627 }
f1baf495 628 }// for (i=0; i<aNbFI; ++i) {
4e57c75e 629 //
630 // 2. Process section edges
f1baf495 631 Standard_Boolean bPCurveOnS[2];
632 Standard_Integer m;
633 TopoDS_Face aFf[2];
634 //
635 bPCurveOnS[0]=mySectionAttribute.PCurveOnS1();
636 bPCurveOnS[1]=mySectionAttribute.PCurveOnS2();
637 //
638 if (bPCurveOnS[0] || bPCurveOnS[1]) {
639 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
640 aNbFF=aFFs.Extent();
641 for (i=0; i<aNbFF; ++i) {
642 const BOPDS_InterfFF& aFF=aFFs(i);
643 aFF.Indices(nF1, nF2);
644 //
645 aFf[0]=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
646 aFf[0].Orientation(TopAbs_FORWARD);
647 //
648 aFf[1]=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
649 aFf[1].Orientation(TopAbs_FORWARD);
650 //
651 const BOPDS_VectorOfCurve& aVNC=aFF.Curves();
652 aNbC=aVNC.Extent();
653 for (k=0; k<aNbC; ++k) {
654 const BOPDS_Curve& aNC=aVNC(k);
655 const BOPDS_ListOfPaveBlock& aLPB=aNC.PaveBlocks();
656 aItLPB.Initialize(aLPB);
657 for(; aItLPB.More(); aItLPB.Next()) {
658 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
659 nE=aPB->Edge();
660 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
661 //
662 for (m=0; m<2; ++m) {
663 if (bPCurveOnS[m]) {
664 BOPAlgo_MPC& aMPC=aVMPC.Append1();
665 aMPC.SetEdge(aE);
666 aMPC.SetFace(aFf[m]);
667 aMPC.SetFlag(bPCurveOnS[m]);
36f4947b 668 aMPC.SetProgressIndicator(myProgressIndicator);
f1baf495 669 }
670 }
4e57c75e 671 }
672 }
f1baf495 673 }// for (i=0; i<aNbFF; ++i) {
674 }//if (bPCurveOnS1 || bPCurveOnS2 ) {
675 //
676 //======================================================
905522ee 677 BOPAlgo_MPCCnt::Perform(myRunParallel, aVMPC, myContext);
f1baf495 678 //======================================================
4e57c75e 679}
4e57c75e 680//=======================================================================
4e57c75e 681//function : UpdateVertices
682//purpose : update tolerances of vertices comparing extremities of
683// 3d and 2d curves
684//=======================================================================
505abfb8 685void UpdateVertices(const TopoDS_Edge& aE,
686 const TopoDS_Face& aF)
4e57c75e 687{
688 Standard_Integer j;
689 Standard_Real aT[2], aUx, aVx, aTolV2, aD2, aD;
690 gp_Pnt aP3D, aP3Dx;
691 gp_Pnt2d aP2Dx;
692 Handle(Geom_Surface) aS;
693 Handle(Geom_Curve) aC3D;
694 Handle(Geom2d_Curve) aC2D;
695 TopoDS_Edge aEf;
696 TopoDS_Vertex aV[2];
697 BRep_Builder aBB;
698 //
699 aEf=aE;
700 aEf.Orientation(TopAbs_FORWARD);
701 //
702 TopExp::Vertices(aEf, aV[0], aV[1]);
703 //
704 aS=BRep_Tool::Surface(aF);
705 aC3D=BRep_Tool::Curve(aEf, aT[0], aT[1]);
706 aC2D=BRep_Tool::CurveOnSurface(aEf, aF, aT[0], aT[1]);
707 //
708 for (j=0; j<2; ++j) {
709 aTolV2=BRep_Tool::Tolerance(aV[j]);
710 aTolV2=aTolV2*aTolV2;
711 //
712 aC3D->D0(aT[j], aP3D);
713 aC2D->D0(aT[j], aP2Dx);
714 aP2Dx.Coord(aUx, aVx);
715 aS->D0(aUx, aVx, aP3Dx);
716 aD2=aP3D.SquareDistance(aP3Dx);
717 if (aD2>aTolV2) {
718 aD=sqrt(aD2);
719 aBB.UpdateVertex(aV[j], aD);
720 }
721 }
722}
f1baf495 723//=======================================================================
724// function: Prepare
725// purpose:
726//=======================================================================
727void BOPAlgo_PaveFiller::Prepare()
728{
3510db62 729 if (myNonDestructive) {
730 // do not allow storing pcurves in original edges if non-destructive mode is on
731 return;
732 }
f1baf495 733 TopAbs_ShapeEnum aType[] = {
734 TopAbs_VERTEX,
735 TopAbs_EDGE,
736 TopAbs_FACE
737 };
25dfc507 738 Standard_Boolean bIsBasedOnPlane;
319da2e4 739 Standard_Integer i, aNb, n1, nF, aNbF;
f1baf495 740 TopExp_Explorer aExp;
319da2e4 741 BOPCol_IndexedMapOfShape aMF;
f1baf495 742 //
f1baf495 743 aNb=3;
744 for(i=0; i<aNb; ++i) {
745 myIterator->Initialize(aType[i], aType[2]);
746 for (; myIterator->More(); myIterator->Next()) {
25dfc507 747 myIterator->Value(n1, nF);
f1baf495 748 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
749 //
750 bIsBasedOnPlane=IsBasedOnPlane(aF);
751 if (bIsBasedOnPlane) {
752 aMF.Add(aF);
753 }
754 }
755 }
756 //
319da2e4 757 aNbF = aMF.Extent();
758 if (!aNbF) {
f1baf495 759 return;
760 }
761 //
2078dfc7 762 // Build pcurves of edges on planes; first collect pairs edge-face.
f1baf495 763 BOPAlgo_VectorOfBPC aVBPC;
764 //
319da2e4 765 for (i = 1; i <= aNbF; ++i) {
766 const TopoDS_Face& aF = *(TopoDS_Face*)&aMF(i);
f1baf495 767 aExp.Init(aF, aType[1]);
768 for (; aExp.More(); aExp.Next()) {
769 const TopoDS_Edge& aE=*((TopoDS_Edge *)&aExp.Current());
770 BOPAlgo_BPC& aBPC=aVBPC.Append1();
771 aBPC.SetEdge(aE);
772 aBPC.SetFace(aF);
773 }
774 }
775 //
776 //======================================================
777 BOPAlgo_BPCCnt::Perform(myRunParallel, aVBPC);
778 //======================================================
2078dfc7 779
780 // pcurves are built, and now update edges
781 BRep_Builder aBB;
782 TopoDS_Edge E;
783 for (i = 0; i < aVBPC.Extent(); i++) {
784 const BOPAlgo_BPC& aBPC=aVBPC(i);
785 if (aBPC.IsToUpdate()) {
786 Standard_Real aTolE = BRep_Tool::Tolerance(aBPC.GetEdge());
787 aBB.UpdateEdge(aBPC.GetEdge(), aBPC.GetCurve2d(), aBPC.GetFace(), aTolE);
788 }
789 }
f1baf495 790}
791//=======================================================================
792//function : IsBasedOnPlane
793//purpose :
794//=======================================================================
795Standard_Boolean IsBasedOnPlane(const TopoDS_Face& aF)
796{
797 TopLoc_Location aLoc;
798 Handle(Geom_RectangularTrimmedSurface) aGRTS;
799 Handle(Geom_Plane) aGP;
800
801 const Handle(Geom_Surface)& aS = BRep_Tool::Surface(aF, aLoc);
802 aGRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
803 if(!aGRTS.IsNull()) {
804 aGP = Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
805 }
806 else {
807 aGP = Handle(Geom_Plane)::DownCast(aS);
808 }
809 //
810 return (!aGP.IsNull());
811}