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