0025584: Wrong result obtained by PerformInfinitePoint Test
[occt.git] / src / BOPTest / BOPTest_BOPCommands.cxx
CommitLineData
b311480e 1// Created on: 2000-03-16
2// Created by: Peter KURNEV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16#include <BOPTest.ixx>
17
18#include <stdio.h>
19
20#include <DBRep.hxx>
7fd59977 21
4e57c75e 22#include <NCollection_BaseAllocator.hxx>
23#include <NCollection_IncAllocator.hxx>
7fd59977 24
7fd59977 25#include <TopoDS_Shape.hxx>
4e57c75e 26#include <TopoDS_Compound.hxx>
b1d15f53 27#include <TopoDS_Iterator.hxx>
28//
7fd59977 29#include <BRep_Builder.hxx>
30
4e57c75e 31#include <BOPAlgo_PaveFiller.hxx>
32#include <BOPAlgo_Operation.hxx>
33#include <BOPAlgo_BOP.hxx>
92ae0f2f 34#include <BOPAlgo_MakerVolume.hxx>
4e57c75e 35#include <BOPDS_DS.hxx>
7fd59977 36#include <BOPTest_DrawableShape.hxx>
4e57c75e 37#include <BOPCol_ListOfShape.hxx>
7fd59977 38
4e57c75e 39#include <TCollection_AsciiString.hxx>
40#include <IntTools_FaceFace.hxx>
41#include <IntTools_Curve.hxx>
42#include <DrawTrSurf.hxx>
43#include <Draw_Color.hxx>
44#include <Draw.hxx>
da219023 45#include <BRepAlgoAPI_BooleanOperation.hxx>
46#include <BRepAlgoAPI_Common.hxx>
47#include <BRepAlgoAPI_Fuse.hxx>
48#include <BRepAlgoAPI_Cut.hxx>
49#include <BRepAlgoAPI_Section.hxx>
85915310 50#include <BOPAlgo_Section.hxx>
7fd59977 51
52//
4e57c75e 53static BOPAlgo_PaveFiller* pPF=NULL;
7fd59977 54//
7fd59977 55
4e57c75e 56static
57 Standard_Integer bopsmt(Draw_Interpretor& di,
58 Standard_Integer n,
59 const char** a,
60 const BOPAlgo_Operation aOp);
61static
62 Standard_Integer bsmt (Draw_Interpretor& di,
63 Standard_Integer n,
64 const char** a,
65 const BOPAlgo_Operation aOp);
7fd59977 66//
4e57c75e 67static Standard_Integer bop (Draw_Interpretor&, Standard_Integer, const char**);
68static Standard_Integer bopsection(Draw_Interpretor&, Standard_Integer, const char**);
69static Standard_Integer boptuc (Draw_Interpretor&, Standard_Integer, const char**);
70static Standard_Integer bopcut (Draw_Interpretor&, Standard_Integer, const char**);
71static Standard_Integer bopfuse (Draw_Interpretor&, Standard_Integer, const char**);
72static Standard_Integer bopcommon (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 73//
4e57c75e 74static Standard_Integer bsection (Draw_Interpretor&, Standard_Integer, const char**);
75static Standard_Integer btuc (Draw_Interpretor&, Standard_Integer, const char**);
76static Standard_Integer bcut (Draw_Interpretor&, Standard_Integer, const char**);
77static Standard_Integer bfuse (Draw_Interpretor&, Standard_Integer, const char**);
78static Standard_Integer bcommon (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 79//
4e57c75e 80static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char**);
81static Standard_Integer bopnews (Draw_Interpretor&, Standard_Integer, const char**);
92ae0f2f 82//
e322db46 83static Standard_Integer bparallelmode(Draw_Interpretor&, Standard_Integer, const char**);
84//
92ae0f2f 85static Standard_Integer mkvolume (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 86
7fd59977 87//=======================================================================
88//function : BOPCommands
89//purpose :
90//=======================================================================
4e57c75e 91 void BOPTest::BOPCommands(Draw_Interpretor& theCommands)
7fd59977 92{
93 static Standard_Boolean done = Standard_False;
4e57c75e 94 if (done) return;
7fd59977 95 done = Standard_True;
96 // Chapter's name
4e57c75e 97 const char* g = "BOP commands";
98 // Commands
99
b1d15f53 100 theCommands.Add("bop" , "use bop s1 s2 [tol]" , __FILE__, bop, g);
101 theCommands.Add("bopcommon" , "use bopcommon r" , __FILE__, bopcommon, g);
102 theCommands.Add("bopfuse" , "use bopfuse r" , __FILE__,bopfuse, g);
103 theCommands.Add("bopcut" , "use bopcut r" , __FILE__,bopcut, g);
104 theCommands.Add("boptuc" , "use boptuc r" , __FILE__,boptuc, g);
105 theCommands.Add("bopsection", "use bopsection r" , __FILE__,bopsection, g);
106 //
107 theCommands.Add("bcommon" , "use bcommon r s1 s2 [tol]" , __FILE__,bcommon, g);
108 theCommands.Add("bfuse" , "use bfuse r s1 s2 [tol]" , __FILE__,bfuse, g);
109 theCommands.Add("bcut" , "use bcut r s1 s2 [tol]" , __FILE__,bcut, g);
110 theCommands.Add("btuc" , "use btuc r s1 s2 [tol]" , __FILE__,btuc, g);
111 theCommands.Add("bsection", "Use >bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]",
4e57c75e 112 __FILE__, bsection, g);
7fd59977 113 //
c2c2f2b6 114 theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d]", __FILE__, bopcurves, g);
4e57c75e 115 theCommands.Add("bopnews", "use bopnews -v[e,f]" , __FILE__, bopnews, g);
b1d15f53 116 theCommands.Add("bparallelmode", "bparallelmode [1/0] : show / set parallel mode for boolean operations",
117 __FILE__, bparallelmode, g);
118 theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni] [-s] [tol]",
119 __FILE__, mkvolume , g);
7fd59977 120}
4e57c75e 121
7fd59977 122//=======================================================================
123//function : bop
124//purpose :
125//=======================================================================
4e57c75e 126Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 127{
4e57c75e 128 char buf[32];
129 Standard_Integer iErr;
b1d15f53 130 Standard_Real aTol;
4e57c75e 131 TopoDS_Shape aS1, aS2;
132 BOPCol_ListOfShape aLC;
133 //
b1d15f53 134 if (n < 3 || n > 4) {
135 di << " use bop Shape1 Shape2 [tol]\n";
7fd59977 136 return 1;
137 }
4e57c75e 138 //
139 aS1=DBRep::Get(a[1]);
140 aS2=DBRep::Get(a[2]);
141 //
142 if (aS1.IsNull() || aS2.IsNull()) {
143 di << " null shapes are not allowed \n";
7fd59977 144 return 1;
145 }
4e57c75e 146 //
b1d15f53 147 aTol = 0.;
148 if (n == 4) {
149 aTol = Draw::Atof(a[3]);
150 }
151 //
4e57c75e 152 aLC.Append(aS1);
153 aLC.Append(aS2);
154 //
5d05cf31 155 if (pPF!=NULL) {
4e57c75e 156 delete pPF;
5d05cf31 157 pPF=NULL;
7fd59977 158 }
5d05cf31 159 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
160 pPF=new BOPAlgo_PaveFiller(aAL);
4e57c75e 161 //
162 pPF->SetArguments(aLC);
b1d15f53 163 pPF->SetFuzzyValue(aTol);
4e57c75e 164 //
165 pPF->Perform();
166 iErr=pPF->ErrorStatus();
167 if (iErr) {
168 Sprintf(buf, " ErrorStatus : %d\n", iErr);
169 di << buf;
170 return 0;
7fd59977 171 }
4e57c75e 172 //
7fd59977 173 return 0;
174}
7fd59977 175//=======================================================================
4e57c75e 176//function : bopcommon
7fd59977 177//purpose :
178//=======================================================================
4e57c75e 179Standard_Integer bopcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 180{
4e57c75e 181 return bopsmt(di, n, a, BOPAlgo_COMMON);
182}
183//=======================================================================
184//function : bopfuse
185//purpose :
186//=======================================================================
187Standard_Integer bopfuse(Draw_Interpretor& di, Standard_Integer n, const char** a)
188{
189 return bopsmt(di, n, a, BOPAlgo_FUSE);
190}
191//=======================================================================
192//function : bopcut
193//purpose :
194//=======================================================================
195Standard_Integer bopcut(Draw_Interpretor& di, Standard_Integer n, const char** a)
196{
197 return bopsmt(di, n, a, BOPAlgo_CUT);
198}
199//=======================================================================
200//function : boptuc
201//purpose :
202//=======================================================================
203Standard_Integer boptuc(Draw_Interpretor& di, Standard_Integer n, const char** a)
204{
205 return bopsmt(di, n, a, BOPAlgo_CUT21);
206}
207//=======================================================================
4e57c75e 208//function : bopsmt
209//purpose :
210//=======================================================================
211Standard_Integer bopsmt(Draw_Interpretor& di,
212 Standard_Integer n,
213 const char** a,
214 const BOPAlgo_Operation aOp)
215{
216 if (n<2) {
b1d15f53 217 di << " use bopsmt r\n [tol]";
4e57c75e 218 return 0;
7fd59977 219 }
4e57c75e 220 //
221 if (!pPF) {
222 di << " prepare PaveFiller first\n";
223 return 0;
224 }
225 //
226 if (pPF->ErrorStatus()) {
227 di << " PaveFiller has not been done\n";
228 return 0;
229 }
230 //
231 char buf[64];
232 Standard_Integer aNb, iErr;
233 BOPAlgo_BOP aBOP;
234 //
235 const BOPCol_ListOfShape& aLC=pPF->Arguments();
236 aNb=aLC.Extent();
237 if (aNb!=2) {
238 Sprintf (buf, " wrong number of arguments %s\n", aNb);
239 di << buf;
240 return 0;
241 }
242 //
243 const TopoDS_Shape& aS1=aLC.First();
244 const TopoDS_Shape& aS2=aLC.Last();
245 //
246 aBOP.AddArgument(aS1);
247 aBOP.AddTool(aS2);
248 aBOP.SetOperation(aOp);
249 //
250 aBOP.PerformWithFiller(*pPF);
251 iErr=aBOP.ErrorStatus();
252 if (iErr) {
253 Sprintf(buf, " ErrorStatus : %d\n", iErr);
254 di << buf;
255 return 0;
256 }
257 //
258 const TopoDS_Shape& aR=aBOP.Shape();
259 if (aR.IsNull()) {
260 di << " null shape\n";
261 return 0;
262 }
263 //
264 DBRep::Set(a[1], aR);
265 return 0;
7fd59977 266}
7fd59977 267//=======================================================================
85915310 268//function : bopsection
269//purpose :
270//=======================================================================
271Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char** a)
272{
273 if (n<2) {
274 di << " use bopsmt r\n";
275 return 0;
276 }
277 //
278 if (!pPF) {
279 di << " prepare PaveFiller first\n";
280 return 0;
281 }
282 //
283 if (pPF->ErrorStatus()) {
284 di << " PaveFiller has not been done\n";
285 return 0;
286 }
287 //
288 char buf[64];
289 Standard_Integer aNb, iErr;
290 BOPAlgo_Section aBOP;
291 //
292 const BOPCol_ListOfShape& aLC=pPF->Arguments();
293 aNb=aLC.Extent();
294 if (aNb!=2) {
295 Sprintf (buf, " wrong number of arguments %s\n", aNb);
296 di << buf;
297 return 0;
298 }
299 //
300 const TopoDS_Shape& aS1=aLC.First();
301 const TopoDS_Shape& aS2=aLC.Last();
302 //
303 aBOP.AddArgument(aS1);
304 aBOP.AddArgument(aS2);
305 //
306 aBOP.PerformWithFiller(*pPF);
307 iErr=aBOP.ErrorStatus();
308 if (iErr) {
309 Sprintf(buf, " ErrorStatus : %d\n", iErr);
310 di << buf;
311 return 0;
312 }
313 //
314 const TopoDS_Shape& aR=aBOP.Shape();
315 if (aR.IsNull()) {
316 di << " null shape\n";
317 return 0;
318 }
319 //
320 DBRep::Set(a[1], aR);
321 return 0;
322}
323//=======================================================================
7fd59977 324//function : bcommon
325//purpose :
326//=======================================================================
4e57c75e 327Standard_Integer bcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 328{
4e57c75e 329 return bsmt(di, n, a, BOPAlgo_COMMON);
7fd59977 330}
331//=======================================================================
332//function : bfuse
333//purpose :
334//=======================================================================
4e57c75e 335Standard_Integer bfuse (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 336{
4e57c75e 337 return bsmt(di, n, a, BOPAlgo_FUSE);
7fd59977 338}
7fd59977 339//=======================================================================
340//function : bcut
341//purpose :
342//=======================================================================
4e57c75e 343Standard_Integer bcut (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 344{
4e57c75e 345 return bsmt(di, n, a, BOPAlgo_CUT);
346}
347//=======================================================================
348//function : btuc
349//purpose :
350//=======================================================================
351Standard_Integer btuc (Draw_Interpretor& di, Standard_Integer n, const char** a)
352{
353 return bsmt(di, n, a, BOPAlgo_CUT21);
7fd59977 354}
355//=======================================================================
356//function : bsection
357//purpose :
358//=======================================================================
359Standard_Integer bsection(Draw_Interpretor& di,
4e57c75e 360 Standard_Integer n,
361 const char** a)
7fd59977 362{
b1d15f53 363 const char* usage = " Usage: bsection Result s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]\n";
7fd59977 364 if (n < 4) {
365 di << usage;
366 return 1;
367 }
b1d15f53 368 //
4e57c75e 369 TopoDS_Shape aS1 = DBRep::Get(a[2]);
370 TopoDS_Shape aS2 = DBRep::Get(a[3]);
b1d15f53 371 //
4e57c75e 372 if (aS1.IsNull() || aS2.IsNull()) {
7fd59977 373 di << " Null shapes are not allowed \n";
374 return 1;
375 }
b1d15f53 376 //
da219023 377 Standard_Boolean bApp, bPC1, bPC2;
b1d15f53 378 Standard_Integer i;
379 Standard_Real aTol;
da219023 380 //
381 bApp = Standard_True;
382 bPC1 = Standard_True;
383 bPC2 = Standard_True;
b1d15f53 384 aTol = 0.;
385 //
386 for (i = 4; i < n; ++i) {
387 if (!strcmp(a[i], "-n2d")) {
388 bPC1 = Standard_False;
389 bPC2 = Standard_False;
7fd59977 390 }
b1d15f53 391 else if (!strcmp(a[i], "-n2d1")) {
392 bPC1 = Standard_False;
7fd59977 393 }
b1d15f53 394 else if (!strcmp(a[i], "-n2d2")) {
395 bPC2 = Standard_False;
7fd59977 396 }
b1d15f53 397 else if (!strcmp(a[i], "-na")) {
398 bApp = Standard_False;
7fd59977 399 }
b1d15f53 400 else {
401 aTol = Draw::Atof(a[i]);
4e57c75e 402 }
b1d15f53 403 }
404 //
405 Standard_Integer iErr;
406 char buf[80];
407 //
408 BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False);
409 aSec.Approximation(bApp);
410 aSec.ComputePCurveOn1(bPC1);
411 aSec.ComputePCurveOn2(bPC2);
412 aSec.SetFuzzyValue(aTol);
413 //
414 aSec.Build();
415 iErr=aSec.ErrorStatus();
416 if (!aSec.IsDone()) {
417 Sprintf(buf, " ErrorStatus : %d\n", iErr);
418 di << buf;
4e57c75e 419 return 0;
7fd59977 420 }
b1d15f53 421 //
422 const TopoDS_Shape& aR=aSec.Shape();
423 if (aR.IsNull()) {
424 di << " null shape\n";
425 return 0;
7fd59977 426 }
b1d15f53 427 DBRep::Set(a[1], aR);
428 return 0;
7fd59977 429}
b1d15f53 430
7fd59977 431//=======================================================================
4e57c75e 432//function : bsmt
7fd59977 433//purpose :
434//=======================================================================
4e57c75e 435Standard_Integer bsmt (Draw_Interpretor& di,
436 Standard_Integer n,
437 const char** a,
438 const BOPAlgo_Operation aOp)
7fd59977 439{
4e57c75e 440 char buf[32];
441 Standard_Integer iErr;
442 TopoDS_Shape aS1, aS2;
443 BOPCol_ListOfShape aLC;
b1d15f53 444 Standard_Real aTol;
4e57c75e 445 //
b1d15f53 446 if (n < 4 || n > 5) {
447 di << " use bx r s1 s2 [tol]\n";
7fd59977 448 return 1;
449 }
4e57c75e 450 //
451 aS1=DBRep::Get(a[2]);
452 aS2=DBRep::Get(a[3]);
453 //
454 if (aS1.IsNull() || aS2.IsNull()) {
455 di << " null shapes are not allowed \n";
7fd59977 456 return 1;
457 }
b1d15f53 458 //
459 aTol = 0.;
460 if (n == 5) {
461 aTol = Draw::Atof(a[4]);
462 }
463 //
4e57c75e 464 aLC.Append(aS1);
465 aLC.Append(aS2);
466 //
467 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
468 BOPAlgo_PaveFiller aPF(aAL);
469 //
470 aPF.SetArguments(aLC);
b1d15f53 471 aPF.SetFuzzyValue(aTol);
4e57c75e 472 //
473 aPF.Perform();
474 iErr=aPF.ErrorStatus();
475 if (iErr) {
476 Sprintf(buf, " ErrorStatus : %d\n", iErr);
477 di << buf;
478 return 0;
7fd59977 479 }
480 //
da219023 481 BRepAlgoAPI_BooleanOperation* pBuilder=NULL;
482 //
483 if (aOp==BOPAlgo_COMMON) {
484 pBuilder=new BRepAlgoAPI_Common(aS1, aS2, aPF);
485 }
486 else if (aOp==BOPAlgo_FUSE) {
487 pBuilder=new BRepAlgoAPI_Fuse(aS1, aS2, aPF);
488 }
489 else if (aOp==BOPAlgo_CUT) {
490 pBuilder=new BRepAlgoAPI_Cut (aS1, aS2, aPF);
491 }
492 else if (aOp==BOPAlgo_CUT21) {
493 pBuilder=new BRepAlgoAPI_Cut(aS1, aS2, aPF, Standard_False);
494 }
4e57c75e 495 //
da219023 496 iErr = pBuilder->ErrorStatus();
497 if (!pBuilder->IsDone()) {
4e57c75e 498 Sprintf(buf, " ErrorStatus : %d\n", iErr);
499 di << buf;
500 return 0;
7fd59977 501 }
da219023 502 const TopoDS_Shape& aR=pBuilder->Shape();
4e57c75e 503 if (aR.IsNull()) {
504 di << " null shape\n";
505 return 0;
7fd59977 506 }
4e57c75e 507 DBRep::Set(a[1], aR);
7fd59977 508 return 0;
509}
510
511//=======================================================================
4e57c75e 512//function : bopnews
7fd59977 513//purpose :
514//=======================================================================
4e57c75e 515Standard_Integer bopnews (Draw_Interpretor& di,
516 Standard_Integer n,
517 const char** a)
7fd59977 518{
4e57c75e 519 if (n!=2) {
520 di << " use bopnews -v[e,f]\n";
521 return 0;
7fd59977 522 }
4e57c75e 523 //
524 if (pPF==NULL) {
525 di << " Prepare BOPAlgo_PaveFiller first >bop S1 S2\n";
7fd59977 526 return 0;
527 }
4e57c75e 528 //
529 char buf[32];
530 Standard_CString aText;
531 Standard_Integer i, i1, i2, iFound;
7fd59977 532 Draw_Color aTextColor(Draw_cyan);
4e57c75e 533 TopAbs_ShapeEnum aT;
534 Handle(BOPTest_DrawableShape) aDShape;
7fd59977 535 //
4e57c75e 536 const BOPDS_PDS& pDS=pPF->PDS();
7fd59977 537 //
4e57c75e 538 aT=TopAbs_SHAPE;
539 if (!strcmp (a[1], "-f")) {
540 aT=TopAbs_FACE;
7fd59977 541 }
4e57c75e 542 else if (!strcmp (a[1], "-e")){
543 aT=TopAbs_EDGE;
7fd59977 544 }
4e57c75e 545 else if (!strcmp (a[1], "-v")){
546 aT=TopAbs_VERTEX;
7fd59977 547 }
4e57c75e 548 else {
549 di << " use bopnews -v[e,f]\n";
550 return 0;
7fd59977 551 }
552 //
4e57c75e 553 iFound=0;
554 i1=pDS->NbSourceShapes();
555 i2=pDS->NbShapes();
556 for (i=i1; i<i2; ++i) {
557 const BOPDS_ShapeInfo& aSI=pDS->ShapeInfo(i);
558 if (aSI.ShapeType()==aT) {
559 const TopoDS_Shape& aS=aSI.Shape();
560 //
561 Sprintf (buf, "z%d", i);
562 aText=buf;
563 aDShape=new BOPTest_DrawableShape (aS, aText, aTextColor);
7fd59977 564 Draw::Set (aText, aDShape);
4e57c75e 565 //
566 Sprintf (buf, " z%d", i);
567 di << buf;
568 //
569 iFound=1;
7fd59977 570 }
571 }
4e57c75e 572 //
573 if (iFound) {
7fd59977 574 di << "\n";
575 }
7fd59977 576 else {
4e57c75e 577 di << " not found\n";
7fd59977 578 }
7fd59977 579 //
7fd59977 580 return 0;
581}
582
7fd59977 583//=======================================================================
4e57c75e 584//function : bopcurves
7fd59977 585//purpose :
586//=======================================================================
4e57c75e 587Standard_Integer bopcurves (Draw_Interpretor& di,
588 Standard_Integer n,
589 const char** a)
7fd59977 590{
4e57c75e 591 if (n<3) {
c2c2f2b6 592 di << " use bopcurves F1 F2 [-2d]\n";
4e57c75e 593 return 1;
7fd59977 594 }
595
4e57c75e 596 TopoDS_Shape S1 = DBRep::Get(a[1]);
597 TopoDS_Shape S2 = DBRep::Get(a[2]);
598 TopAbs_ShapeEnum aType;
7fd59977 599
4e57c75e 600 if (S1.IsNull() || S2.IsNull()) {
601 di << " Null shapes is not allowed \n";
602 return 1;
7fd59977 603 }
7fd59977 604
4e57c75e 605 aType=S1.ShapeType();
606 if (aType != TopAbs_FACE) {
607 di << " Type mismatch F1\n";
608 return 1;
7fd59977 609 }
4e57c75e 610 aType=S2.ShapeType();
611 if (aType != TopAbs_FACE) {
612 di << " Type mismatch F2\n";
613 return 1;
7fd59977 614 }
615
7fd59977 616
4e57c75e 617 const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
618 const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
7fd59977 619
c2c2f2b6 620 Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone, bMake2dCurves;
4e57c75e 621 Standard_Integer i, aNbCurves;
622 Standard_Real anAppTol, aTolR;
623 TCollection_AsciiString aNm("c_");
7fd59977 624
c2c2f2b6 625 bMake2dCurves = Standard_False;
626 if (n > 3) {
627 if (!strcasecmp(a[3],"-2d")) {
628 bMake2dCurves = Standard_True;
629 } else {
630 di << "Wrong key. To build 2d curves use: bopcurves F1 F2 -2d \n";
631 return 1;
632 }
633 }
634 //
635
636 aToApproxC3d = Standard_True;
637 aToApproxC2dOnS1 = bMake2dCurves;
638 aToApproxC2dOnS2 = bMake2dCurves;
4e57c75e 639 anAppTol=0.0000001;
7fd59977 640
7fd59977 641
4e57c75e 642 IntTools_FaceFace aFF;
7fd59977 643
4e57c75e 644 aFF.SetParameters (aToApproxC3d,
645 aToApproxC2dOnS1,
646 aToApproxC2dOnS2,
647 anAppTol);
7fd59977 648
4e57c75e 649 aFF.Perform (aF1, aF2);
7fd59977 650
4e57c75e 651 anIsDone=aFF.IsDone();
652 if (!anIsDone) {
653 di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
654 return 1;
7fd59977 655 }
656
c2c2f2b6 657 aFF.PrepareLines3D(Standard_False);
4e57c75e 658 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
7fd59977 659
4e57c75e 660 //
661 aTolR=aFF.TolReached3d();
662 di << "Tolerance Reached=" << aTolR << "\n";
7fd59977 663
4e57c75e 664 aNbCurves=aSCs.Length();
665 if (!aNbCurves) {
666 di << " has no 3d curve\n";
667 return 1;
7fd59977 668 }
c2c2f2b6 669 else
670 {
671 di << aNbCurves << " curve(s) found.\n";
672 }
7fd59977 673
4e57c75e 674 for (i=1; i<=aNbCurves; i++) {
675 const IntTools_Curve& anIC=aSCs(i);
7fd59977 676
c2c2f2b6 677 Handle (Geom_Curve) aC3D = anIC.Curve();
7fd59977 678
4e57c75e 679 if (aC3D.IsNull()) {
c2c2f2b6 680 di << " has Null 3d curve# " << i << "\n";
4e57c75e 681 continue;
7fd59977 682 }
7fd59977 683
4e57c75e 684 TCollection_AsciiString anIndx(i), aNmx;
c2c2f2b6 685 aNmx = aNm + anIndx;
686
687 Standard_CString nameC = aNmx.ToCString();
688
689 DrawTrSurf::Set(nameC, aC3D);
690 di << nameC << " ";
691 //
692 if (bMake2dCurves) {
693 Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
694 Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
695 //
696 if (aPC1.IsNull() && aPC2.IsNull()) {
697 di << " \n has Null 2d curves# " << i << "\n";
698 continue;
699 }
700 //
701 if (aPC1.IsNull()) {
702 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
703 pc2Nx = pc2N + anIndx;
704 Standard_CString nameC2d2 = pc2Nx.ToCString();
705 //
706 DrawTrSurf::Set(nameC2d2, aPC2);
707 di << "(" << nameC2d2 << ") ";
708 di << " \n Null first 2d curve of the curve #" << i << "\n";
709 continue;
710 } else {
711 TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
712 pc1Nx = pc1N + anIndx;
713 Standard_CString nameC2d1 = pc1Nx.ToCString();
714 //
715 DrawTrSurf::Set(nameC2d1, aPC1);
716 di << "(" << nameC2d1;
717 }
718 //
719 if (aPC2.IsNull()) {
720 di << ") \n Null second 2d curve of the curve #" << i << "\n";
721 continue;
722 } else {
723 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
724 pc2Nx = pc2N + anIndx;
725 Standard_CString nameC2d2 = pc2Nx.ToCString();
726 //
727 DrawTrSurf::Set(nameC2d2, aPC2);
728 di << ", " << nameC2d2 << ") ";
729 }
730 }
7fd59977 731 }
7fd59977 732
7fd59977 733 di << "\n";
7fd59977 734
4e57c75e 735 return 0;
7fd59977 736}
92ae0f2f 737
738//=======================================================================
e322db46 739//function : bparallelmode
740//purpose :
741//=======================================================================
742Standard_Integer bparallelmode(Draw_Interpretor& di, Standard_Integer n, const char** a)
743{
744 if (n == 2)
745 {
746 Standard_Boolean isParallelOn = Draw::Atoi (a[1]) == 1;
747 if (isParallelOn == 1)
748 {
749 BOPAlgo_Algo::SetParallelMode(Standard_True);
750 di << "Parallel mode for boolean operations has been enabled";
751 }
752 else
753 {
754 BOPAlgo_Algo::SetParallelMode(Standard_False);
755 di << "Parallel mode for boolean operations has been disabled";
756 }
757 }
758 else
759 {
760 di << "Parallel mode state for boolean operations: "
761 << (BOPAlgo_Algo::GetParallelMode()? "enabled" : "disabled");
762 }
763
764 return 0;
765}
766
767//=======================================================================
92ae0f2f 768//function : mkvolume
769//purpose :
770//=======================================================================
771Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a)
772{
92ae0f2f 773 if (n < 3) {
b1d15f53 774 di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-s] [tol]\n";
775 di << "Options:\n";
776 di << " -c - use this option if the arguments are compounds\n";
777 di << " containing shapes that should be interfered;\n";
778 di << " -ni - use this option if the arguments should not be interfered;\n";
779 di << " -s - use this option to run the operation in non parallel mode;\n";
780 di << " tol - additional tolerance value (real).\n";
92ae0f2f 781 return 1;
782 }
783 //
b1d15f53 784 const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
785 //
786 Standard_Boolean bToIntersect, bRunParallel, bCompounds;
787 Standard_Integer i;
788 Standard_Real aTol;
789 TopoDS_Shape aS;
790 BOPCol_ListOfShape aLS;
92ae0f2f 791 //
b1d15f53 792 aTol = 0.;
92ae0f2f 793 bToIntersect = Standard_True;
794 bRunParallel = Standard_True;
b1d15f53 795 bCompounds = Standard_False;
92ae0f2f 796 //
b1d15f53 797 for (i = 2; i < n; ++i) {
92ae0f2f 798 aS = DBRep::Get(a[i]);
799 if (!aS.IsNull()) {
800 aLS.Append(aS);
801 }
b1d15f53 802 else {
803 if (!strcmp(a[i], "-c")) {
804 bCompounds = Standard_True;
805 }
806 else if (!strcmp(a[i], "-ni")) {
807 bToIntersect = Standard_False;
808 }
809 else if (!strcmp(a[i], "-s")) {
810 bRunParallel = Standard_False;
811 }
812 else {
813 aTol = Draw::Atof(a[i]);
814 }
815 }
92ae0f2f 816 }
817 //
818 if (aLS.IsEmpty()) {
b1d15f53 819 di << "No shapes to process.\n";
92ae0f2f 820 di << usage;
821 return 1;
822 }
823 //
b1d15f53 824 // treat list of arguments for the case of compounds
825 if (bToIntersect && bCompounds) {
826 BOPCol_ListOfShape aLSx;
827 BOPCol_ListIteratorOfListOfShape aItLS;
828 //
829 aItLS.Initialize(aLS);
830 for (; aItLS.More(); aItLS.Next()) {
831 const TopoDS_Shape& aSx = aItLS.Value();
832 TopoDS_Iterator aItS(aSx);
833 for (; aItS.More(); aItS.Next()) {
834 const TopoDS_Shape& aSxS = aItS.Value();
835 aLSx.Append(aSxS);
836 }
837 }
838 //
839 aLS.Clear();
840 aLS.Assign(aLSx);
841 }
842 //
92ae0f2f 843 BOPAlgo_MakerVolume aMV;
844 aMV.SetArguments(aLS);
845 aMV.SetIntersect(bToIntersect);
846 aMV.SetRunParallel(bRunParallel);
b1d15f53 847 aMV.SetFuzzyValue(aTol);
92ae0f2f 848 //
849 aMV.Perform();
850 if (aMV.ErrorStatus()) {
851 di << "Error status: " << aMV.ErrorStatus();
852 return 1;
853 }
854 //
855 const TopoDS_Shape& aR = aMV.Shape();
856 //
857 DBRep::Set(a[1], aR);
858 //
859 return 0;
860}