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