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