0030058: Visualization, Select3D_SensitivePrimitiveArray - the selection is not fast...
[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);
99c5f9f0 650 //
4e57c75e 651 aFF.Perform (aF1, aF2);
99c5f9f0 652 //
4e57c75e 653 anIsDone=aFF.IsDone();
654 if (!anIsDone) {
5652dc62 655 di << "Error: Intersection failed\n";
d0820f2e 656 return 0;
7fd59977 657 }
99c5f9f0 658 //
c2c2f2b6 659 aFF.PrepareLines3D(Standard_False);
4e57c75e 660 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
e9e644ed 661 const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points();
4e57c75e 662 //
e9e644ed 663 aNbCurves = aSCs.Length();
664 aNbPoints = aSPs.Length();
665 if (!aNbCurves && !aNbPoints) {
666 di << " has no 3d curves\n";
667 di << " has no 3d points\n";
d0820f2e 668 return 0;
7fd59977 669 }
e9e644ed 670 //
e9e644ed 671 // curves
672 if (aNbCurves) {
5652dc62 673 Standard_Real aTolR = 0.;
674 if (!bExtOut) {
675 // find maximal tolerance
676 for (Standard_Integer i = 1; i <= aNbCurves; i++) {
677 const IntTools_Curve& anIC = aSCs(i);
678 if (aTolR < anIC.Tolerance()) {
679 aTolR = anIC.Tolerance();
680 }
681 }
682 di << "Tolerance Reached=" << aTolR << "\n";
683 }
684 //
c2c2f2b6 685 di << aNbCurves << " curve(s) found.\n";
e9e644ed 686 //
d677b214 687 for (Standard_Integer i=1; i<=aNbCurves; i++) {
e9e644ed 688 const IntTools_Curve& anIC=aSCs(i);
7fd59977 689
e9e644ed 690 Handle (Geom_Curve) aC3D = anIC.Curve();
7fd59977 691
e9e644ed 692 if (aC3D.IsNull()) {
693 di << " has Null 3d curve# " << i << "\n";
694 continue;
695 }
7fd59977 696
e9e644ed 697 TCollection_AsciiString anIndx(i), aNmx;
698 aNmx = aNm + anIndx;
c2c2f2b6 699
e9e644ed 700 Standard_CString nameC = aNmx.ToCString();
c2c2f2b6 701
e9e644ed 702 DrawTrSurf::Set(nameC, aC3D);
703 di << nameC << " ";
c2c2f2b6 704 //
e9e644ed 705 Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
706 Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
c2c2f2b6 707 //
e9e644ed 708 if (!aPC1.IsNull() || !aPC2.IsNull()) {
709 di << "(";
99c5f9f0 710 //
711 if (!aPC1.IsNull()) {
e9e644ed 712 TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
713 pc1Nx = pc1N + anIndx;
714 Standard_CString nameC2d1 = pc1Nx.ToCString();
715 //
716 DrawTrSurf::Set(nameC2d1, aPC1);
717 di << nameC2d1;
99c5f9f0 718 }
e9e644ed 719 //
720 if (!aPC2.IsNull()) {
721 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
722 pc2Nx = pc2N + anIndx;
723 Standard_CString nameC2d2 = pc2Nx.ToCString();
724 //
725 DrawTrSurf::Set(nameC2d2, aPC2);
726 //
727 if (!aPC1.IsNull()) {
728 di << ", ";
729 }
730 di << nameC2d2;
731 }
732 di << ") ";
c2c2f2b6 733 }
5652dc62 734 //
735 if (bExtOut) {
736 di << "\nTolerance: " << anIC.Tolerance() << "\n";
737 di << "Tangential tolerance: " << anIC.TangentialTolerance() << "\n";
738 di << "\n";
739 }
740 }
741 if (!bExtOut) {
742 di << "\n";
c2c2f2b6 743 }
e9e644ed 744 }
745 //
746 // points
747 if (aNbPoints) {
748 di << aNbPoints << " point(s) found.\n";
749 //
d677b214 750 for (Standard_Integer i = 1; i <= aNbPoints; i++) {
e9e644ed 751 const IntTools_PntOn2Faces& aPi = aSPs(i);
752 const gp_Pnt& aP = aPi.P1().Pnt();
753 //
754 TCollection_AsciiString anIndx(i), aNmx;
755 aNmx = aNp + anIndx;
756 Standard_CString nameP = aNmx.ToCString();
757 //
758 DrawTrSurf::Set(nameP, aP);
759 di << nameP << " ";
760 }
761 di << "\n";
7fd59977 762 }
99c5f9f0 763 //
4e57c75e 764 return 0;
7fd59977 765}
92ae0f2f 766//=======================================================================
767//function : mkvolume
768//purpose :
769//=======================================================================
770Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a)
771{
92ae0f2f 772 if (n < 3) {
291fced1 773 di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-ai]\n";
b1d15f53 774 di << "Options:\n";
775 di << " -c - use this option if the arguments are compounds\n";
776 di << " containing shapes that should be interfered;\n";
777 di << " -ni - use this option if the arguments should not be interfered;\n";
291fced1 778 di << " -ai - use this option to avoid internal for solids shapes in the result.\n";
92ae0f2f 779 return 1;
780 }
781 //
b1d15f53 782 const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
783 //
291fced1 784 Standard_Boolean bToIntersect, bRunParallel, bNonDestructive;
785 Standard_Boolean bCompounds, bAvoidInternal;
b1d15f53 786 Standard_Integer i;
787 Standard_Real aTol;
788 TopoDS_Shape aS;
1155d05a 789 TopTools_ListOfShape aLS;
92ae0f2f 790 //
49b0c452 791 aTol = BOPTest_Objects::FuzzyValue();
49b0c452 792 bRunParallel = BOPTest_Objects::RunParallel();
3510db62 793 bNonDestructive = BOPTest_Objects::NonDestructive();
483ce1bd 794 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
43cb0011 795 //
796 bToIntersect = Standard_True;
b1d15f53 797 bCompounds = Standard_False;
291fced1 798 bAvoidInternal = Standard_False;
92ae0f2f 799 //
b1d15f53 800 for (i = 2; i < n; ++i) {
92ae0f2f 801 aS = DBRep::Get(a[i]);
802 if (!aS.IsNull()) {
803 aLS.Append(aS);
804 }
b1d15f53 805 else {
806 if (!strcmp(a[i], "-c")) {
807 bCompounds = Standard_True;
808 }
809 else if (!strcmp(a[i], "-ni")) {
810 bToIntersect = Standard_False;
811 }
291fced1 812 else if (!strcmp(a[i], "-ai")) {
813 bAvoidInternal = Standard_True;
814 }
b1d15f53 815 }
92ae0f2f 816 }
817 //
818 if (aLS.IsEmpty()) {
b1d15f53 819 di << "No shapes to process.\n";
92ae0f2f 820 di << usage;
821 return 1;
822 }
823 //
b1d15f53 824 // treat list of arguments for the case of compounds
825 if (bToIntersect && bCompounds) {
1155d05a 826 TopTools_ListOfShape aLSx;
827 TopTools_ListIteratorOfListOfShape aItLS;
b1d15f53 828 //
829 aItLS.Initialize(aLS);
830 for (; aItLS.More(); aItLS.Next()) {
831 const TopoDS_Shape& aSx = aItLS.Value();
832 TopoDS_Iterator aItS(aSx);
833 for (; aItS.More(); aItS.Next()) {
834 const TopoDS_Shape& aSxS = aItS.Value();
835 aLSx.Append(aSxS);
836 }
837 }
838 //
839 aLS.Clear();
840 aLS.Assign(aLSx);
841 }
842 //
92ae0f2f 843 BOPAlgo_MakerVolume aMV;
844 aMV.SetArguments(aLS);
845 aMV.SetIntersect(bToIntersect);
846 aMV.SetRunParallel(bRunParallel);
b1d15f53 847 aMV.SetFuzzyValue(aTol);
3510db62 848 aMV.SetNonDestructive(bNonDestructive);
291fced1 849 aMV.SetAvoidInternalShapes(bAvoidInternal);
483ce1bd 850 aMV.SetGlue(aGlue);
944768d2 851 aMV.SetUseOBB(BOPTest_Objects::UseOBB());
948fe6ca 852 aMV.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
92ae0f2f 853 //
854 aMV.Perform();
d9ca2e0c 855 BOPTest::ReportAlerts(aMV.GetReport());
4f7d41ea 856
857 // Store the history of Volume Maker into the session
948fe6ca 858 if (BRepTest_Objects::IsHistoryNeeded())
859 BRepTest_Objects::SetHistory(aLS, aMV);
4f7d41ea 860
33ba8565 861 if (aMV.HasErrors()) {
862 return 0;
92ae0f2f 863 }
864 //
865 const TopoDS_Shape& aR = aMV.Shape();
866 //
867 DBRep::Set(a[1], aR);
868 //
869 return 0;
870}