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