0029484: Avoid inheritance of the BRepAlgoAPI_Check from BRepBuilderAPI_MakeShape
[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>
42cf5bc1 31#include <DBRep.hxx>
32#include <Draw.hxx>
42cf5bc1 33#include <DrawTrSurf.hxx>
543a9964 34#include <Geom2d_Curve.hxx>
42cf5bc1 35#include <Geom_Curve.hxx>
36#include <IntTools_Curve.hxx>
37#include <IntTools_FaceFace.hxx>
38#include <IntTools_PntOn2Faces.hxx>
39#include <NCollection_BaseAllocator.hxx>
42cf5bc1 40#include <TCollection_AsciiString.hxx>
41#include <TopoDS_Compound.hxx>
42#include <TopoDS_Iterator.hxx>
43#include <TopoDS_Shape.hxx>
1155d05a 44#include <TopTools_ListOfShape.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);
03cca6f7 104 theCommands.Add("bsection", "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]"
105 "Builds section between shapes. Options:\n"
106 "-n2d/-n2d1/-n2d2 - disable the PCurve construction;\n"
107 "-na - disables the approximation of the section curves.\n",
4e57c75e 108 __FILE__, bsection, g);
7fd59977 109 //
5652dc62 110 theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d/-2d1/-2d2] "
111 "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]",
99c5f9f0 112 __FILE__, bopcurves, g);
291fced1 113 theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni] [-ai]",
b1d15f53 114 __FILE__, mkvolume , g);
7fd59977 115}
4e57c75e 116
7fd59977 117//=======================================================================
118//function : bop
119//purpose :
120//=======================================================================
43cb0011 121Standard_Integer bop(Draw_Interpretor& di,
122 Standard_Integer n,
123 const char** a)
7fd59977 124{
3510db62 125 Standard_Boolean bRunParallel, bNonDestructive;
b1d15f53 126 Standard_Real aTol;
4e57c75e 127 TopoDS_Shape aS1, aS2;
1155d05a 128 TopTools_ListOfShape aLC;
4e57c75e 129 //
43cb0011 130 if (n != 3) {
131 di << " use bop s1 s2 \n";
49b0c452 132 return 0;
7fd59977 133 }
4e57c75e 134 //
135 aS1=DBRep::Get(a[1]);
136 aS2=DBRep::Get(a[2]);
137 //
138 if (aS1.IsNull() || aS2.IsNull()) {
139 di << " null shapes are not allowed \n";
49b0c452 140 return 0;
7fd59977 141 }
4e57c75e 142 //
49b0c452 143 aTol=BOPTest_Objects::FuzzyValue();
49b0c452 144 bRunParallel=BOPTest_Objects::RunParallel();
3510db62 145 bNonDestructive = BOPTest_Objects::NonDestructive();
483ce1bd 146 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
49b0c452 147 //
4e57c75e 148 aLC.Append(aS1);
149 aLC.Append(aS2);
150 //
5d05cf31 151 if (pPF!=NULL) {
4e57c75e 152 delete pPF;
5d05cf31 153 pPF=NULL;
7fd59977 154 }
488e5b9d 155 Handle(NCollection_BaseAllocator)aAL=
156 NCollection_BaseAllocator::CommonBaseAllocator();
5d05cf31 157 pPF=new BOPAlgo_PaveFiller(aAL);
4e57c75e 158 //
159 pPF->SetArguments(aLC);
b1d15f53 160 pPF->SetFuzzyValue(aTol);
49b0c452 161 pPF->SetRunParallel(bRunParallel);
3510db62 162 pPF->SetNonDestructive(bNonDestructive);
483ce1bd 163 pPF->SetGlue(aGlue);
944768d2 164 pPF->SetUseOBB(BOPTest_Objects::UseOBB());
4e57c75e 165 //
166 pPF->Perform();
33ba8565 167 BOPTest::ReportAlerts(*pPF);
4e57c75e 168 //
7fd59977 169 return 0;
170}
7fd59977 171//=======================================================================
4e57c75e 172//function : bopcommon
7fd59977 173//purpose :
174//=======================================================================
43cb0011 175Standard_Integer bopcommon (Draw_Interpretor& di,
176 Standard_Integer n,
177 const char** a)
7fd59977 178{
4e57c75e 179 return bopsmt(di, n, a, BOPAlgo_COMMON);
180}
181//=======================================================================
182//function : bopfuse
183//purpose :
184//=======================================================================
43cb0011 185Standard_Integer bopfuse(Draw_Interpretor& di,
186 Standard_Integer n,
187 const char** a)
4e57c75e 188{
189 return bopsmt(di, n, a, BOPAlgo_FUSE);
190}
191//=======================================================================
192//function : bopcut
193//purpose :
194//=======================================================================
43cb0011 195Standard_Integer bopcut(Draw_Interpretor& di,
196 Standard_Integer n,
197 const char** a)
4e57c75e 198{
199 return bopsmt(di, n, a, BOPAlgo_CUT);
200}
201//=======================================================================
202//function : boptuc
203//purpose :
204//=======================================================================
43cb0011 205Standard_Integer boptuc(Draw_Interpretor& di,
206 Standard_Integer n,
207 const char** a)
4e57c75e 208{
209 return bopsmt(di, n, a, BOPAlgo_CUT21);
210}
211//=======================================================================
4e57c75e 212//function : bopsmt
213//purpose :
214//=======================================================================
215Standard_Integer bopsmt(Draw_Interpretor& di,
216 Standard_Integer n,
217 const char** a,
218 const BOPAlgo_Operation aOp)
219{
220 if (n<2) {
43cb0011 221 di << " use bopsmt r\n";
4e57c75e 222 return 0;
7fd59977 223 }
4e57c75e 224 //
225 if (!pPF) {
226 di << " prepare PaveFiller first\n";
227 return 0;
228 }
229 //
33ba8565 230 if (pPF->HasErrors()) {
4e57c75e 231 di << " PaveFiller has not been done\n";
232 return 0;
233 }
234 //
235 char buf[64];
49b0c452 236 Standard_Boolean bRunParallel;
33ba8565 237 Standard_Integer aNb;
4e57c75e 238 BOPAlgo_BOP aBOP;
239 //
1155d05a 240 const TopTools_ListOfShape& aLC=pPF->Arguments();
4e57c75e 241 aNb=aLC.Extent();
242 if (aNb!=2) {
243 Sprintf (buf, " wrong number of arguments %s\n", aNb);
244 di << buf;
245 return 0;
246 }
49b0c452 247 //
248 bRunParallel=BOPTest_Objects::RunParallel();
4e57c75e 249 //
250 const TopoDS_Shape& aS1=aLC.First();
251 const TopoDS_Shape& aS2=aLC.Last();
252 //
253 aBOP.AddArgument(aS1);
254 aBOP.AddTool(aS2);
255 aBOP.SetOperation(aOp);
49b0c452 256 aBOP.SetRunParallel (bRunParallel);
98b37659 257 aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
4e57c75e 258 //
259 aBOP.PerformWithFiller(*pPF);
33ba8565 260 BOPTest::ReportAlerts(aBOP);
261 if (aBOP.HasErrors()) {
4e57c75e 262 return 0;
263 }
264 //
265 const TopoDS_Shape& aR=aBOP.Shape();
266 if (aR.IsNull()) {
267 di << " null shape\n";
268 return 0;
269 }
270 //
271 DBRep::Set(a[1], aR);
272 return 0;
7fd59977 273}
7fd59977 274//=======================================================================
85915310 275//function : bopsection
276//purpose :
277//=======================================================================
43cb0011 278Standard_Integer bopsection(Draw_Interpretor& di,
279 Standard_Integer n,
280 const char** a)
85915310 281{
282 if (n<2) {
43cb0011 283 di << " use bopsection r\n";
85915310 284 return 0;
285 }
286 //
287 if (!pPF) {
288 di << " prepare PaveFiller first\n";
289 return 0;
290 }
291 //
33ba8565 292 if (pPF->HasErrors()) {
85915310 293 di << " PaveFiller has not been done\n";
294 return 0;
295 }
296 //
297 char buf[64];
49b0c452 298 Standard_Boolean bRunParallel;
33ba8565 299 Standard_Integer aNb;
85915310 300 BOPAlgo_Section aBOP;
301 //
1155d05a 302 const TopTools_ListOfShape& aLC=pPF->Arguments();
85915310 303 aNb=aLC.Extent();
304 if (aNb!=2) {
305 Sprintf (buf, " wrong number of arguments %s\n", aNb);
306 di << buf;
307 return 0;
308 }
309 //
49b0c452 310 bRunParallel=BOPTest_Objects::RunParallel();
311 //
85915310 312 const TopoDS_Shape& aS1=aLC.First();
313 const TopoDS_Shape& aS2=aLC.Last();
314 //
315 aBOP.AddArgument(aS1);
316 aBOP.AddArgument(aS2);
49b0c452 317 aBOP.SetRunParallel (bRunParallel);
98b37659 318 aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
85915310 319 //
320 aBOP.PerformWithFiller(*pPF);
33ba8565 321 BOPTest::ReportAlerts(aBOP);
322 if (aBOP.HasErrors()) {
85915310 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 //
3510db62 397 Standard_Boolean bRunParallel, bNonDestructive, bApp, bPC1, bPC2;
b1d15f53 398 Standard_Real aTol;
da219023 399 //
400 bApp = Standard_True;
401 bPC1 = Standard_True;
402 bPC2 = Standard_True;
49b0c452 403 aTol = BOPTest_Objects::FuzzyValue();
404 bRunParallel = BOPTest_Objects::RunParallel();
3510db62 405 bNonDestructive = BOPTest_Objects::NonDestructive();
483ce1bd 406 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
b1d15f53 407 //
33ba8565 408 for (Standard_Integer i = 4; i < n; ++i) {
b1d15f53 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);
3510db62 432 aSec.SetNonDestructive(bNonDestructive);
483ce1bd 433 aSec.SetGlue(aGlue);
944768d2 434 aSec.SetUseOBB(BOPTest_Objects::UseOBB());
b1d15f53 435 //
436 aSec.Build();
33ba8565 437 //
438 if (aSec.HasWarnings()) {
439 Standard_SStream aSStream;
440 aSec.DumpWarnings(aSStream);
441 di << aSStream;
442 }
443 //
b1d15f53 444 if (!aSec.IsDone()) {
33ba8565 445 Standard_SStream aSStream;
446 aSec.DumpErrors(aSStream);
447 di << aSStream;
4e57c75e 448 return 0;
7fd59977 449 }
b1d15f53 450 //
451 const TopoDS_Shape& aR=aSec.Shape();
452 if (aR.IsNull()) {
453 di << " null shape\n";
454 return 0;
7fd59977 455 }
b1d15f53 456 DBRep::Set(a[1], aR);
457 return 0;
7fd59977 458}
7fd59977 459//=======================================================================
4e57c75e 460//function : bsmt
7fd59977 461//purpose :
462//=======================================================================
4e57c75e 463Standard_Integer bsmt (Draw_Interpretor& di,
464 Standard_Integer n,
465 const char** a,
466 const BOPAlgo_Operation aOp)
7fd59977 467{
3510db62 468 Standard_Boolean bRunParallel, bNonDestructive;
4e57c75e 469 TopoDS_Shape aS1, aS2;
1155d05a 470 TopTools_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);
944768d2 504 aPF.SetUseOBB(BOPTest_Objects::UseOBB());
4e57c75e 505 //
506 aPF.Perform();
33ba8565 507 BOPTest::ReportAlerts(aPF);
508 if (aPF.HasErrors()) {
4e57c75e 509 return 0;
7fd59977 510 }
511 //
49b0c452 512 //---------------------------------------------------------------
513 BOPAlgo_BOP aBOP(aAL);
514 //
515 aBOP.AddArgument(aS1);
516 aBOP.AddTool(aS2);
517 aBOP.SetOperation(aOp);
518 aBOP.SetRunParallel(bRunParallel);
98b37659 519 aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
da219023 520 //
49b0c452 521 aBOP.PerformWithFiller(aPF);
33ba8565 522 BOPTest::ReportAlerts(aBOP);
523 if (aBOP.HasErrors()) {
4e57c75e 524 return 0;
7fd59977 525 }
49b0c452 526 const TopoDS_Shape& aR=aBOP.Shape();
4e57c75e 527 if (aR.IsNull()) {
528 di << " null shape\n";
529 return 0;
7fd59977 530 }
49b0c452 531 //
4e57c75e 532 DBRep::Set(a[1], aR);
7fd59977 533 return 0;
534}
7fd59977 535//=======================================================================
4e57c75e 536//function : bopcurves
7fd59977 537//purpose :
538//=======================================================================
4e57c75e 539Standard_Integer bopcurves (Draw_Interpretor& di,
540 Standard_Integer n,
541 const char** a)
7fd59977 542{
4e57c75e 543 if (n<3) {
5652dc62 544 di << "Usage: bopcurves F1 F2 [-2d/-2d1/-2d2] "
545 "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]\n";
4e57c75e 546 return 1;
7fd59977 547 }
99c5f9f0 548 //
4e57c75e 549 TopoDS_Shape S1 = DBRep::Get(a[1]);
550 TopoDS_Shape S2 = DBRep::Get(a[2]);
551 TopAbs_ShapeEnum aType;
99c5f9f0 552 //
4e57c75e 553 if (S1.IsNull() || S2.IsNull()) {
5652dc62 554 di << " Null shapes are not allowed \n";
4e57c75e 555 return 1;
7fd59977 556 }
99c5f9f0 557 //
4e57c75e 558 aType=S1.ShapeType();
559 if (aType != TopAbs_FACE) {
560 di << " Type mismatch F1\n";
561 return 1;
7fd59977 562 }
4e57c75e 563 aType=S2.ShapeType();
564 if (aType != TopAbs_FACE) {
565 di << " Type mismatch F2\n";
566 return 1;
7fd59977 567 }
99c5f9f0 568 //
4e57c75e 569 const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
570 const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
99c5f9f0 571 //
572 Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
d677b214 573 Standard_Integer aNbCurves, aNbPoints;
5652dc62 574 Standard_Real anAppTol;
47e3009d 575 IntSurf_ListOfPntOn2S aListOfPnts;
e9e644ed 576 TCollection_AsciiString aNm("c_"), aNp("p_");
99c5f9f0 577 //
578 anAppTol = 0.0000001;
579 aToApproxC3d = Standard_True;
580 aToApproxC2dOnS1 = Standard_False;
581 aToApproxC2dOnS2 = Standard_False;
47e3009d 582
99c5f9f0 583 //
5652dc62 584 Standard_Boolean bExtOut = Standard_False;
47e3009d 585 for(Standard_Integer i = 3; i < n; i++)
586 {
587 if (!strcasecmp(a[i],"-2d")) {
99c5f9f0 588 aToApproxC2dOnS1 = Standard_True;
589 aToApproxC2dOnS2 = Standard_True;
590 }
47e3009d 591 else if (!strcasecmp(a[i],"-2d1")) {
99c5f9f0 592 aToApproxC2dOnS1 = Standard_True;
593 }
47e3009d 594 else if (!strcasecmp(a[i],"-2d2")) {
99c5f9f0 595 aToApproxC2dOnS2 = Standard_True;
596 }
47e3009d 597 else if (!strcasecmp(a[i],"-p")) {
598 IntSurf_PntOn2S aPt;
599 const Standard_Real aU1 = Draw::Atof(a[++i]);
600 const Standard_Real aV1 = Draw::Atof(a[++i]);
601 const Standard_Real aU2 = Draw::Atof(a[++i]);
602 const Standard_Real aV2 = Draw::Atof(a[++i]);
603
604 aPt.SetValue(aU1, aV1, aU2, aV2);
605 aListOfPnts.Append(aPt);
606 }
5652dc62 607 else if (!strcasecmp(a[i],"-v")) {
608 bExtOut = Standard_True;
609 }
99c5f9f0 610 else {
5652dc62 611 di << "Wrong key.\n";
612 di << "To build 2d curves use one of the following keys: -2d/-2d1/-2d2\n";
613 di << "To add start points use the following key: -p u1 v1 u2 v2\n";
614 di << "For extended output use the following key: -v\n";
c2c2f2b6 615 return 1;
616 }
617 }
618 //
4e57c75e 619 IntTools_FaceFace aFF;
99c5f9f0 620 //
4e57c75e 621 aFF.SetParameters (aToApproxC3d,
622 aToApproxC2dOnS1,
623 aToApproxC2dOnS2,
624 anAppTol);
47e3009d 625 aFF.SetList(aListOfPnts);
99c5f9f0 626 //
4e57c75e 627 aFF.Perform (aF1, aF2);
99c5f9f0 628 //
4e57c75e 629 anIsDone=aFF.IsDone();
630 if (!anIsDone) {
5652dc62 631 di << "Error: Intersection failed\n";
d0820f2e 632 return 0;
7fd59977 633 }
99c5f9f0 634 //
c2c2f2b6 635 aFF.PrepareLines3D(Standard_False);
4e57c75e 636 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
e9e644ed 637 const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points();
4e57c75e 638 //
e9e644ed 639 aNbCurves = aSCs.Length();
640 aNbPoints = aSPs.Length();
641 if (!aNbCurves && !aNbPoints) {
642 di << " has no 3d curves\n";
643 di << " has no 3d points\n";
d0820f2e 644 return 0;
7fd59977 645 }
e9e644ed 646 //
e9e644ed 647 // curves
648 if (aNbCurves) {
5652dc62 649 Standard_Real aTolR = 0.;
650 if (!bExtOut) {
651 // find maximal tolerance
652 for (Standard_Integer i = 1; i <= aNbCurves; i++) {
653 const IntTools_Curve& anIC = aSCs(i);
654 if (aTolR < anIC.Tolerance()) {
655 aTolR = anIC.Tolerance();
656 }
657 }
658 di << "Tolerance Reached=" << aTolR << "\n";
659 }
660 //
c2c2f2b6 661 di << aNbCurves << " curve(s) found.\n";
e9e644ed 662 //
d677b214 663 for (Standard_Integer i=1; i<=aNbCurves; i++) {
e9e644ed 664 const IntTools_Curve& anIC=aSCs(i);
7fd59977 665
e9e644ed 666 Handle (Geom_Curve) aC3D = anIC.Curve();
7fd59977 667
e9e644ed 668 if (aC3D.IsNull()) {
669 di << " has Null 3d curve# " << i << "\n";
670 continue;
671 }
7fd59977 672
e9e644ed 673 TCollection_AsciiString anIndx(i), aNmx;
674 aNmx = aNm + anIndx;
c2c2f2b6 675
e9e644ed 676 Standard_CString nameC = aNmx.ToCString();
c2c2f2b6 677
e9e644ed 678 DrawTrSurf::Set(nameC, aC3D);
679 di << nameC << " ";
c2c2f2b6 680 //
e9e644ed 681 Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
682 Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
c2c2f2b6 683 //
e9e644ed 684 if (!aPC1.IsNull() || !aPC2.IsNull()) {
685 di << "(";
99c5f9f0 686 //
687 if (!aPC1.IsNull()) {
e9e644ed 688 TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
689 pc1Nx = pc1N + anIndx;
690 Standard_CString nameC2d1 = pc1Nx.ToCString();
691 //
692 DrawTrSurf::Set(nameC2d1, aPC1);
693 di << nameC2d1;
99c5f9f0 694 }
e9e644ed 695 //
696 if (!aPC2.IsNull()) {
697 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
698 pc2Nx = pc2N + anIndx;
699 Standard_CString nameC2d2 = pc2Nx.ToCString();
700 //
701 DrawTrSurf::Set(nameC2d2, aPC2);
702 //
703 if (!aPC1.IsNull()) {
704 di << ", ";
705 }
706 di << nameC2d2;
707 }
708 di << ") ";
c2c2f2b6 709 }
5652dc62 710 //
711 if (bExtOut) {
712 di << "\nTolerance: " << anIC.Tolerance() << "\n";
713 di << "Tangential tolerance: " << anIC.TangentialTolerance() << "\n";
714 di << "\n";
715 }
716 }
717 if (!bExtOut) {
718 di << "\n";
c2c2f2b6 719 }
e9e644ed 720 }
721 //
722 // points
723 if (aNbPoints) {
724 di << aNbPoints << " point(s) found.\n";
725 //
d677b214 726 for (Standard_Integer i = 1; i <= aNbPoints; i++) {
e9e644ed 727 const IntTools_PntOn2Faces& aPi = aSPs(i);
728 const gp_Pnt& aP = aPi.P1().Pnt();
729 //
730 TCollection_AsciiString anIndx(i), aNmx;
731 aNmx = aNp + anIndx;
732 Standard_CString nameP = aNmx.ToCString();
733 //
734 DrawTrSurf::Set(nameP, aP);
735 di << nameP << " ";
736 }
737 di << "\n";
7fd59977 738 }
99c5f9f0 739 //
4e57c75e 740 return 0;
7fd59977 741}
92ae0f2f 742//=======================================================================
743//function : mkvolume
744//purpose :
745//=======================================================================
746Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a)
747{
92ae0f2f 748 if (n < 3) {
291fced1 749 di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-ai]\n";
b1d15f53 750 di << "Options:\n";
751 di << " -c - use this option if the arguments are compounds\n";
752 di << " containing shapes that should be interfered;\n";
753 di << " -ni - use this option if the arguments should not be interfered;\n";
291fced1 754 di << " -ai - use this option to avoid internal for solids shapes in the result.\n";
92ae0f2f 755 return 1;
756 }
757 //
b1d15f53 758 const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
759 //
291fced1 760 Standard_Boolean bToIntersect, bRunParallel, bNonDestructive;
761 Standard_Boolean bCompounds, bAvoidInternal;
b1d15f53 762 Standard_Integer i;
763 Standard_Real aTol;
764 TopoDS_Shape aS;
1155d05a 765 TopTools_ListOfShape aLS;
92ae0f2f 766 //
49b0c452 767 aTol = BOPTest_Objects::FuzzyValue();
49b0c452 768 bRunParallel = BOPTest_Objects::RunParallel();
3510db62 769 bNonDestructive = BOPTest_Objects::NonDestructive();
483ce1bd 770 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
43cb0011 771 //
772 bToIntersect = Standard_True;
b1d15f53 773 bCompounds = Standard_False;
291fced1 774 bAvoidInternal = Standard_False;
92ae0f2f 775 //
b1d15f53 776 for (i = 2; i < n; ++i) {
92ae0f2f 777 aS = DBRep::Get(a[i]);
778 if (!aS.IsNull()) {
779 aLS.Append(aS);
780 }
b1d15f53 781 else {
782 if (!strcmp(a[i], "-c")) {
783 bCompounds = Standard_True;
784 }
785 else if (!strcmp(a[i], "-ni")) {
786 bToIntersect = Standard_False;
787 }
291fced1 788 else if (!strcmp(a[i], "-ai")) {
789 bAvoidInternal = Standard_True;
790 }
b1d15f53 791 }
92ae0f2f 792 }
793 //
794 if (aLS.IsEmpty()) {
b1d15f53 795 di << "No shapes to process.\n";
92ae0f2f 796 di << usage;
797 return 1;
798 }
799 //
b1d15f53 800 // treat list of arguments for the case of compounds
801 if (bToIntersect && bCompounds) {
1155d05a 802 TopTools_ListOfShape aLSx;
803 TopTools_ListIteratorOfListOfShape aItLS;
b1d15f53 804 //
805 aItLS.Initialize(aLS);
806 for (; aItLS.More(); aItLS.Next()) {
807 const TopoDS_Shape& aSx = aItLS.Value();
808 TopoDS_Iterator aItS(aSx);
809 for (; aItS.More(); aItS.Next()) {
810 const TopoDS_Shape& aSxS = aItS.Value();
811 aLSx.Append(aSxS);
812 }
813 }
814 //
815 aLS.Clear();
816 aLS.Assign(aLSx);
817 }
818 //
92ae0f2f 819 BOPAlgo_MakerVolume aMV;
820 aMV.SetArguments(aLS);
821 aMV.SetIntersect(bToIntersect);
822 aMV.SetRunParallel(bRunParallel);
b1d15f53 823 aMV.SetFuzzyValue(aTol);
3510db62 824 aMV.SetNonDestructive(bNonDestructive);
291fced1 825 aMV.SetAvoidInternalShapes(bAvoidInternal);
483ce1bd 826 aMV.SetGlue(aGlue);
944768d2 827 aMV.SetUseOBB(BOPTest_Objects::UseOBB());
92ae0f2f 828 //
829 aMV.Perform();
33ba8565 830 BOPTest::ReportAlerts(aMV);
831 if (aMV.HasErrors()) {
832 return 0;
92ae0f2f 833 }
834 //
835 const TopoDS_Shape& aR = aMV.Shape();
836 //
837 DBRep::Set(a[1], aR);
838 //
839 return 0;
840}