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