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