Warnings on vc14 were eliminated
[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
505abfb8 69//=======================================================================
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//
4e57c75e 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{
359 Standard_Integer aNbPBP;
360 //
361 myErrorStatus=0;
362 //
363 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
364 aNbPBP=aPBP.Extent();
365 if(!aNbPBP) {
366 return;
367 }
368 //
78c66ef1 369 Standard_Boolean bCB, bV1, bV2;
505abfb8 370 Standard_Integer i, nE, nV1, nV2, nSp, aNbPB, aNbVBSE, k;
4e57c75e 371 Standard_Real aT1, aT2;
3510db62 372 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
505abfb8 373 Handle(BOPDS_PaveBlock) aPB;
374 BOPDS_MapOfPaveBlock aMPB(100);
375 TopoDS_Vertex aV1, aV2;
376 TopoDS_Edge aE;
377 BOPAlgo_VectorOfSplitEdge aVBSE;
378
3510db62 379 //
380 UpdateCommonBlocksWithSDVertices();
381 //
382 aNbPBP=aPBP.Extent();
4e57c75e 383 //
384 for (i=0; i<aNbPBP; ++i) {
385 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
386 //
387 aNbPB=aLPB.Extent();
4e57c75e 388 if (aNbPB==1) {
389 aPB=aLPB.First();
390 aPB->Indices(nV1, nV2);
391 bV1=myDS->IsNewShape(nV1);
392 bV2=myDS->IsNewShape(nV2);
3510db62 393 bCB=myDS->IsCommonBlock(aPB);
4e57c75e 394 //
3510db62 395 if (!(bV1 || bV2)) { // no new vertices here
396 if (!myNonDestructive || (myNonDestructive && !bCB)) {
397 nE = aPB->OriginalEdge();
398 aPB->SetEdge(nE);
399 if (!myNonDestructive && bCB) {
400 const Handle(BOPDS_CommonBlock)& aCB = myDS->CommonBlock(aPB);
401 Standard_Real aTol = BOPAlgo_Tools::ComputeToleranceOfCB(aCB, myDS, myContext);
402 myDS->UpdateEdgeTolerance(nE, aTol);
403 }
404 continue;
405 }
4e57c75e 406 }
407 }
408 //
409 aItPB.Initialize(aLPB);
410 for (; aItPB.More(); aItPB.Next()) {
411 aPB=aItPB.Value();
3510db62 412 nE=aPB->OriginalEdge();
413 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
414 if (aSIE.HasFlag()){
415 continue;
416 }
417 //
5a77460e 418 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
4e57c75e 419 bCB=!aCB.IsNull();
420 if (bCB) {
421 myDS->SortPaveBlocks(aCB);
422 aPB=aCB->PaveBlock1();
423 }
424 //
425 if (aMPB.Add(aPB)) {
426 nE=aPB->OriginalEdge();
78c66ef1 427 aPB->Indices(nV1, nV2);
428 aPB->Range(aT1, aT2);
4e57c75e 429 //
505abfb8 430 aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
431 aE.Orientation(TopAbs_FORWARD);
432 //
433 aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
434 aV1.Orientation(TopAbs_FORWARD);
4e57c75e 435 //
505abfb8 436 aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
437 aV2.Orientation(TopAbs_REVERSED);
438 //
439 BOPAlgo_SplitEdge& aBSE=aVBSE.Append1();
440 //
441 aBSE.SetData(aE, aV1, aT1, aV2, aT2);
442 aBSE.SetPaveBlock(aPB);
4e57c75e 443 if (bCB) {
505abfb8 444 aBSE.SetCommonBlock(aCB);
4e57c75e 445 }
3510db62 446 aBSE.SetDS(myDS);
36f4947b 447 aBSE.SetProgressIndicator(myProgressIndicator);
505abfb8 448 }
449 } // for (; aItPB.More(); aItPB.Next()) {
450 } // for (i=0; i<aNbPBP; ++i) {
451 //
452 aNbVBSE=aVBSE.Extent();
453 //======================================================
3510db62 454 BOPAlgo_SplitEdgeCnt::Perform(myRunParallel, aVBSE, myContext);
505abfb8 455 //======================================================
456 //
457 BOPDS_ShapeInfo aSI;
4e57c75e 458 //
505abfb8 459 aSI.SetShapeType(TopAbs_EDGE);
460 //
461 for (k=0; k < aNbVBSE; ++k) {
462 BOPAlgo_SplitEdge& aBSE=aVBSE(k);
463 //
464 const TopoDS_Edge& aSp=aBSE.SplitEdge();
465 const Bnd_Box& aBox=aBSE.Box();
466 //
467 Handle(BOPDS_PaveBlock) aPBk=aBSE.PaveBlock();
468 Handle(BOPDS_CommonBlock)& aCBk=aBSE.CommonBlock();
469 //
470 aSI.SetShape(aSp);
471 aSI.ChangeBox()=aBox;
472 //
473 nSp=myDS->Append(aSI);
474 //
475 if (!aCBk.IsNull()) {
3510db62 476 myDS->UpdateEdgeTolerance(nSp, aBSE.Tolerance());
505abfb8 477 aCBk->SetEdge(nSp);
478 }
479 else {
480 aPBk->SetEdge(nSp);
481 }
482 }
4e57c75e 483}
3510db62 484
78c66ef1 485//=======================================================================
486// function: SplitEdge
487// purpose:
488//=======================================================================
489Standard_Integer BOPAlgo_PaveFiller::SplitEdge(const Standard_Integer nE,
490 const Standard_Integer nV1,
491 const Standard_Real aT1,
492 const Standard_Integer nV2,
493 const Standard_Real aT2)
494{
495 Standard_Integer nSp;
496 TopoDS_Vertex aV1, aV2;
497 TopoDS_Edge aE, aSp;
498 BOPDS_ShapeInfo aSI;
499 //
500 aSI.SetShapeType(TopAbs_EDGE);
501 //
502 aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
503 aE.Orientation(TopAbs_FORWARD);
504 //
505 aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
506 aV1.Orientation(TopAbs_FORWARD);
507 //
508 aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
509 aV2.Orientation(TopAbs_REVERSED);
510 //
511 BOPTools_AlgoTools::MakeSplitEdge(aE, aV1, aT1, aV2, aT2, aSp);
512 //
513 aSI.SetShape(aSp);
514 //
515 Bnd_Box& aBox=aSI.ChangeBox();
516 BRepBndLib::Add(aSp, aBox);
3510db62 517 aBox.SetGap(aBox.GetGap() + Precision::Confusion());
78c66ef1 518 //
519 nSp=myDS->Append(aSI);
520 return nSp;
521}
4e57c75e 522//=======================================================================
523// function: MakePCurves
524// purpose:
525//=======================================================================
505abfb8 526void BOPAlgo_PaveFiller::MakePCurves()
4e57c75e 527{
0c5a6d47 528 if (myAvoidBuildPCurve ||
529 (!mySectionAttribute.PCurveOnS1() && !mySectionAttribute.PCurveOnS2()))
530 return;
905522ee 531 Standard_Boolean bHasPC;
532 Standard_Integer i, nF1, nF2, aNbC, k, nE, aNbFF, aNbFI, nEx;
319da2e4 533 Standard_Integer j, aNbPBIn, aNbPBOn;
4e57c75e 534 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
4e57c75e 535 TopoDS_Face aF1F, aF2F;
f1baf495 536 BOPAlgo_VectorOfMPC aVMPC;
4e57c75e 537 //
538 myErrorStatus=0;
539 //
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//=======================================================================
681// function: RefineFaceInfoOn
682// purpose:
683//=======================================================================
505abfb8 684void BOPAlgo_PaveFiller::RefineFaceInfoOn()
4e57c75e 685{
686 Standard_Integer aNbPBP;
687 //
688 myErrorStatus=0;
689 //
690 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
691 aNbPBP=aPBP.Extent();
692 if(!aNbPBP) {
693 return;
694 }
695 //
696 Standard_Boolean bV1, bV2;
697 Standard_Integer i, nV1, nV2, aNbPB;
698 Handle(BOPDS_PaveBlock) aPB;
699 //
700 for (i=0; i<aNbPBP; ++i) {
701 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
702 //
703 aNbPB=aLPB.Extent();
704 if (aNbPB==1) {
705 aPB=aLPB.First();
706 aPB->Indices(nV1, nV2);
707 bV1=myDS->IsNewShape(nV1);
708 bV2=myDS->IsNewShape(nV2);
709 //
710 if (!(bV1 || bV2)) {
5a77460e 711 if (!myDS->IsCommonBlock(aPB)) {
4e57c75e 712 // the PB seems to be untouced
713 aLPB.Clear();
3510db62 714 Standard_Integer nE = aPB->OriginalEdge();
715 if (nE >= 0) {
716 myDS->ChangeShapeInfo(nE).SetReference(-1);
717 }
4e57c75e 718 continue;
719 }
720 }//if (!(bV1 || bV2)) {
721 }//if (aNbPB==1) {
722 }//for (i=0; i<aNbPBP; ++i) {
723 myDS->RefineFaceInfoOn();
724}
4e57c75e 725//=======================================================================
726//function : UpdateVertices
727//purpose : update tolerances of vertices comparing extremities of
728// 3d and 2d curves
729//=======================================================================
505abfb8 730void UpdateVertices(const TopoDS_Edge& aE,
731 const TopoDS_Face& aF)
4e57c75e 732{
733 Standard_Integer j;
734 Standard_Real aT[2], aUx, aVx, aTolV2, aD2, aD;
735 gp_Pnt aP3D, aP3Dx;
736 gp_Pnt2d aP2Dx;
737 Handle(Geom_Surface) aS;
738 Handle(Geom_Curve) aC3D;
739 Handle(Geom2d_Curve) aC2D;
740 TopoDS_Edge aEf;
741 TopoDS_Vertex aV[2];
742 BRep_Builder aBB;
743 //
744 aEf=aE;
745 aEf.Orientation(TopAbs_FORWARD);
746 //
747 TopExp::Vertices(aEf, aV[0], aV[1]);
748 //
749 aS=BRep_Tool::Surface(aF);
750 aC3D=BRep_Tool::Curve(aEf, aT[0], aT[1]);
751 aC2D=BRep_Tool::CurveOnSurface(aEf, aF, aT[0], aT[1]);
752 //
753 for (j=0; j<2; ++j) {
754 aTolV2=BRep_Tool::Tolerance(aV[j]);
755 aTolV2=aTolV2*aTolV2;
756 //
757 aC3D->D0(aT[j], aP3D);
758 aC2D->D0(aT[j], aP2Dx);
759 aP2Dx.Coord(aUx, aVx);
760 aS->D0(aUx, aVx, aP3Dx);
761 aD2=aP3D.SquareDistance(aP3Dx);
762 if (aD2>aTolV2) {
763 aD=sqrt(aD2);
764 aBB.UpdateVertex(aV[j], aD);
765 }
766 }
767}
f1baf495 768//=======================================================================
769// function: Prepare
770// purpose:
771//=======================================================================
772void BOPAlgo_PaveFiller::Prepare()
773{
3510db62 774 if (myNonDestructive) {
775 // do not allow storing pcurves in original edges if non-destructive mode is on
776 return;
777 }
f1baf495 778 TopAbs_ShapeEnum aType[] = {
779 TopAbs_VERTEX,
780 TopAbs_EDGE,
781 TopAbs_FACE
782 };
25dfc507 783 Standard_Boolean bIsBasedOnPlane;
319da2e4 784 Standard_Integer i, aNb, n1, nF, aNbF;
f1baf495 785 TopExp_Explorer aExp;
319da2e4 786 BOPCol_IndexedMapOfShape aMF;
f1baf495 787 //
788 myErrorStatus=0;
789 //
790 aNb=3;
791 for(i=0; i<aNb; ++i) {
792 myIterator->Initialize(aType[i], aType[2]);
793 for (; myIterator->More(); myIterator->Next()) {
25dfc507 794 myIterator->Value(n1, nF);
f1baf495 795 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
796 //
797 bIsBasedOnPlane=IsBasedOnPlane(aF);
798 if (bIsBasedOnPlane) {
799 aMF.Add(aF);
800 }
801 }
802 }
803 //
319da2e4 804 aNbF = aMF.Extent();
805 if (!aNbF) {
f1baf495 806 return;
807 }
808 //
2078dfc7 809 // Build pcurves of edges on planes; first collect pairs edge-face.
f1baf495 810 BOPAlgo_VectorOfBPC aVBPC;
811 //
319da2e4 812 for (i = 1; i <= aNbF; ++i) {
813 const TopoDS_Face& aF = *(TopoDS_Face*)&aMF(i);
f1baf495 814 aExp.Init(aF, aType[1]);
815 for (; aExp.More(); aExp.Next()) {
816 const TopoDS_Edge& aE=*((TopoDS_Edge *)&aExp.Current());
817 BOPAlgo_BPC& aBPC=aVBPC.Append1();
818 aBPC.SetEdge(aE);
819 aBPC.SetFace(aF);
820 }
821 }
822 //
823 //======================================================
824 BOPAlgo_BPCCnt::Perform(myRunParallel, aVBPC);
825 //======================================================
2078dfc7 826
827 // pcurves are built, and now update edges
828 BRep_Builder aBB;
829 TopoDS_Edge E;
830 for (i = 0; i < aVBPC.Extent(); i++) {
831 const BOPAlgo_BPC& aBPC=aVBPC(i);
832 if (aBPC.IsToUpdate()) {
833 Standard_Real aTolE = BRep_Tool::Tolerance(aBPC.GetEdge());
834 aBB.UpdateEdge(aBPC.GetEdge(), aBPC.GetCurve2d(), aBPC.GetFace(), aTolE);
835 }
836 }
f1baf495 837}
838//=======================================================================
839//function : IsBasedOnPlane
840//purpose :
841//=======================================================================
842Standard_Boolean IsBasedOnPlane(const TopoDS_Face& aF)
843{
844 TopLoc_Location aLoc;
845 Handle(Geom_RectangularTrimmedSurface) aGRTS;
846 Handle(Geom_Plane) aGP;
847
848 const Handle(Geom_Surface)& aS = BRep_Tool::Surface(aF, aLoc);
849 aGRTS = Handle(Geom_RectangularTrimmedSurface)::DownCast(aS);
850 if(!aGRTS.IsNull()) {
851 aGP = Handle(Geom_Plane)::DownCast(aGRTS->BasisSurface());
852 }
853 else {
854 aGP = Handle(Geom_Plane)::DownCast(aS);
855 }
856 //
857 return (!aGP.IsNull());
858}