0024002: Overall code and build procedure refactoring -- automatic
[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>
25#include <BOPTest_DrawableShape.hxx>
26#include <BOPTest_Objects.hxx>
27#include <BRep_Builder.hxx>
da219023 28#include <BRepAlgoAPI_BooleanOperation.hxx>
29#include <BRepAlgoAPI_Common.hxx>
da219023 30#include <BRepAlgoAPI_Cut.hxx>
42cf5bc1 31#include <BRepAlgoAPI_Fuse.hxx>
da219023 32#include <BRepAlgoAPI_Section.hxx>
42cf5bc1 33#include <DBRep.hxx>
34#include <Draw.hxx>
35#include <Draw_Color.hxx>
36#include <DrawTrSurf.hxx>
543a9964 37#include <Geom2d_Curve.hxx>
42cf5bc1 38#include <Geom_Curve.hxx>
39#include <IntTools_Curve.hxx>
40#include <IntTools_FaceFace.hxx>
41#include <IntTools_PntOn2Faces.hxx>
42#include <NCollection_BaseAllocator.hxx>
43#include <NCollection_IncAllocator.hxx>
44#include <TCollection_AsciiString.hxx>
45#include <TopoDS_Compound.hxx>
46#include <TopoDS_Iterator.hxx>
47#include <TopoDS_Shape.hxx>
543a9964 48
42cf5bc1 49#include <stdio.h>
50//
7fd59977 51//
4e57c75e 52static BOPAlgo_PaveFiller* pPF=NULL;
7fd59977 53//
7fd59977 54
4e57c75e 55static
56 Standard_Integer bopsmt(Draw_Interpretor& di,
57 Standard_Integer n,
58 const char** a,
59 const BOPAlgo_Operation aOp);
43cb0011 60//
4e57c75e 61static
62 Standard_Integer bsmt (Draw_Interpretor& di,
63 Standard_Integer n,
64 const char** a,
65 const BOPAlgo_Operation aOp);
7fd59977 66//
4e57c75e 67static Standard_Integer bop (Draw_Interpretor&, Standard_Integer, const char**);
68static Standard_Integer bopsection(Draw_Interpretor&, Standard_Integer, const char**);
69static Standard_Integer boptuc (Draw_Interpretor&, Standard_Integer, const char**);
70static Standard_Integer bopcut (Draw_Interpretor&, Standard_Integer, const char**);
71static Standard_Integer bopfuse (Draw_Interpretor&, Standard_Integer, const char**);
72static Standard_Integer bopcommon (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 73//
4e57c75e 74static Standard_Integer bsection (Draw_Interpretor&, Standard_Integer, const char**);
75static Standard_Integer btuc (Draw_Interpretor&, Standard_Integer, const char**);
76static Standard_Integer bcut (Draw_Interpretor&, Standard_Integer, const char**);
77static Standard_Integer bfuse (Draw_Interpretor&, Standard_Integer, const char**);
78static Standard_Integer bcommon (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 79//
4e57c75e 80static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char**);
81static Standard_Integer bopnews (Draw_Interpretor&, Standard_Integer, const char**);
92ae0f2f 82static Standard_Integer mkvolume (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 83
7fd59977 84//=======================================================================
85//function : BOPCommands
86//purpose :
87//=======================================================================
4e57c75e 88 void BOPTest::BOPCommands(Draw_Interpretor& theCommands)
7fd59977 89{
90 static Standard_Boolean done = Standard_False;
4e57c75e 91 if (done) return;
7fd59977 92 done = Standard_True;
93 // Chapter's name
43cb0011 94 const char* g = "BOPTest commands";
4e57c75e 95 // Commands
96
43cb0011 97 theCommands.Add("bop" , "use bop s1 s2" , __FILE__, bop, g);
b1d15f53 98 theCommands.Add("bopcommon" , "use bopcommon r" , __FILE__, bopcommon, g);
99 theCommands.Add("bopfuse" , "use bopfuse r" , __FILE__,bopfuse, g);
100 theCommands.Add("bopcut" , "use bopcut r" , __FILE__,bopcut, g);
101 theCommands.Add("boptuc" , "use boptuc r" , __FILE__,boptuc, g);
102 theCommands.Add("bopsection", "use bopsection r" , __FILE__,bopsection, g);
103 //
43cb0011 104 theCommands.Add("bcommon" , "use bcommon r s1 s2" , __FILE__,bcommon, g);
105 theCommands.Add("bfuse" , "use bfuse r s1 s2" , __FILE__,bfuse, g);
106 theCommands.Add("bcut" , "use bcut r s1 s2" , __FILE__,bcut, g);
107 theCommands.Add("btuc" , "use btuc r s1 s2" , __FILE__,btuc, g);
108 theCommands.Add("bsection", "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]",
4e57c75e 109 __FILE__, bsection, g);
7fd59977 110 //
99c5f9f0 111 theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d/-2d1/-2d2]",
112 __FILE__, bopcurves, g);
43cb0011 113 theCommands.Add("bopnews" , "use bopnews -v[e,f]" , __FILE__, bopnews, g);
114 theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni]",
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{
4e57c75e 126 char buf[32];
49b0c452 127 Standard_Boolean bRunParallel;
4e57c75e 128 Standard_Integer iErr;
b1d15f53 129 Standard_Real aTol;
4e57c75e 130 TopoDS_Shape aS1, aS2;
131 BOPCol_ListOfShape aLC;
132 //
43cb0011 133 if (n != 3) {
134 di << " use bop s1 s2 \n";
49b0c452 135 return 0;
7fd59977 136 }
4e57c75e 137 //
138 aS1=DBRep::Get(a[1]);
139 aS2=DBRep::Get(a[2]);
140 //
141 if (aS1.IsNull() || aS2.IsNull()) {
142 di << " null shapes are not allowed \n";
49b0c452 143 return 0;
7fd59977 144 }
4e57c75e 145 //
49b0c452 146 aTol=BOPTest_Objects::FuzzyValue();
49b0c452 147 bRunParallel=BOPTest_Objects::RunParallel();
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 }
5d05cf31 156 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
157 pPF=new BOPAlgo_PaveFiller(aAL);
4e57c75e 158 //
159 pPF->SetArguments(aLC);
b1d15f53 160 pPF->SetFuzzyValue(aTol);
49b0c452 161 pPF->SetRunParallel(bRunParallel);
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];
402 Standard_Boolean bRunParallel, bApp, bPC1, bPC2;
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();
b1d15f53 411 //
412 for (i = 4; i < n; ++i) {
413 if (!strcmp(a[i], "-n2d")) {
414 bPC1 = Standard_False;
415 bPC2 = Standard_False;
7fd59977 416 }
b1d15f53 417 else if (!strcmp(a[i], "-n2d1")) {
418 bPC1 = Standard_False;
7fd59977 419 }
b1d15f53 420 else if (!strcmp(a[i], "-n2d2")) {
421 bPC2 = Standard_False;
7fd59977 422 }
b1d15f53 423 else if (!strcmp(a[i], "-na")) {
424 bApp = Standard_False;
7fd59977 425 }
b1d15f53 426 }
427 //
b1d15f53 428 BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False);
49b0c452 429 //
b1d15f53 430 aSec.Approximation(bApp);
431 aSec.ComputePCurveOn1(bPC1);
432 aSec.ComputePCurveOn2(bPC2);
43cb0011 433 //
b1d15f53 434 aSec.SetFuzzyValue(aTol);
49b0c452 435 aSec.SetRunParallel(bRunParallel);
b1d15f53 436 //
437 aSec.Build();
438 iErr=aSec.ErrorStatus();
439 if (!aSec.IsDone()) {
440 Sprintf(buf, " ErrorStatus : %d\n", iErr);
441 di << buf;
4e57c75e 442 return 0;
7fd59977 443 }
b1d15f53 444 //
445 const TopoDS_Shape& aR=aSec.Shape();
446 if (aR.IsNull()) {
447 di << " null shape\n";
448 return 0;
7fd59977 449 }
b1d15f53 450 DBRep::Set(a[1], aR);
451 return 0;
7fd59977 452}
7fd59977 453//=======================================================================
4e57c75e 454//function : bsmt
7fd59977 455//purpose :
456//=======================================================================
4e57c75e 457Standard_Integer bsmt (Draw_Interpretor& di,
458 Standard_Integer n,
459 const char** a,
460 const BOPAlgo_Operation aOp)
7fd59977 461{
4e57c75e 462 char buf[32];
49b0c452 463 Standard_Boolean bRunParallel;
4e57c75e 464 Standard_Integer iErr;
465 TopoDS_Shape aS1, aS2;
466 BOPCol_ListOfShape aLC;
b1d15f53 467 Standard_Real aTol;
4e57c75e 468 //
43cb0011 469 if (n != 4) {
470 di << " use bx r s1 s2\n";
49b0c452 471 return 0;
7fd59977 472 }
4e57c75e 473 //
474 aS1=DBRep::Get(a[2]);
475 aS2=DBRep::Get(a[3]);
476 //
477 if (aS1.IsNull() || aS2.IsNull()) {
478 di << " null shapes are not allowed \n";
49b0c452 479 return 0;
7fd59977 480 }
49b0c452 481 aLC.Append(aS1);
482 aLC.Append(aS2);
483 //
484 aTol=BOPTest_Objects::FuzzyValue();
49b0c452 485 bRunParallel = BOPTest_Objects::RunParallel();
4e57c75e 486 //
487 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
49b0c452 488 //
489 //---------------------------------------------------------------
4e57c75e 490 BOPAlgo_PaveFiller aPF(aAL);
491 //
492 aPF.SetArguments(aLC);
49b0c452 493 aPF.SetFuzzyValue(aTol);
494 aPF.SetRunParallel(bRunParallel);
4e57c75e 495 //
496 aPF.Perform();
497 iErr=aPF.ErrorStatus();
498 if (iErr) {
499 Sprintf(buf, " ErrorStatus : %d\n", iErr);
500 di << buf;
501 return 0;
7fd59977 502 }
503 //
49b0c452 504 //---------------------------------------------------------------
505 BOPAlgo_BOP aBOP(aAL);
506 //
507 aBOP.AddArgument(aS1);
508 aBOP.AddTool(aS2);
509 aBOP.SetOperation(aOp);
510 aBOP.SetRunParallel(bRunParallel);
da219023 511 //
49b0c452 512 aBOP.PerformWithFiller(aPF);
4e57c75e 513 //
49b0c452 514 iErr=aBOP.ErrorStatus();
515 if (iErr) {
4e57c75e 516 Sprintf(buf, " ErrorStatus : %d\n", iErr);
517 di << buf;
518 return 0;
7fd59977 519 }
49b0c452 520 const TopoDS_Shape& aR=aBOP.Shape();
4e57c75e 521 if (aR.IsNull()) {
522 di << " null shape\n";
523 return 0;
7fd59977 524 }
49b0c452 525 //
4e57c75e 526 DBRep::Set(a[1], aR);
7fd59977 527 return 0;
528}
7fd59977 529//=======================================================================
4e57c75e 530//function : bopnews
7fd59977 531//purpose :
532//=======================================================================
4e57c75e 533Standard_Integer bopnews (Draw_Interpretor& di,
534 Standard_Integer n,
535 const char** a)
7fd59977 536{
4e57c75e 537 if (n!=2) {
538 di << " use bopnews -v[e,f]\n";
539 return 0;
7fd59977 540 }
4e57c75e 541 //
542 if (pPF==NULL) {
543 di << " Prepare BOPAlgo_PaveFiller first >bop S1 S2\n";
7fd59977 544 return 0;
545 }
4e57c75e 546 //
547 char buf[32];
548 Standard_CString aText;
549 Standard_Integer i, i1, i2, iFound;
7fd59977 550 Draw_Color aTextColor(Draw_cyan);
4e57c75e 551 TopAbs_ShapeEnum aT;
552 Handle(BOPTest_DrawableShape) aDShape;
7fd59977 553 //
4e57c75e 554 const BOPDS_PDS& pDS=pPF->PDS();
7fd59977 555 //
4e57c75e 556 aT=TopAbs_SHAPE;
557 if (!strcmp (a[1], "-f")) {
558 aT=TopAbs_FACE;
7fd59977 559 }
4e57c75e 560 else if (!strcmp (a[1], "-e")){
561 aT=TopAbs_EDGE;
7fd59977 562 }
4e57c75e 563 else if (!strcmp (a[1], "-v")){
564 aT=TopAbs_VERTEX;
7fd59977 565 }
4e57c75e 566 else {
567 di << " use bopnews -v[e,f]\n";
568 return 0;
7fd59977 569 }
570 //
4e57c75e 571 iFound=0;
572 i1=pDS->NbSourceShapes();
573 i2=pDS->NbShapes();
574 for (i=i1; i<i2; ++i) {
575 const BOPDS_ShapeInfo& aSI=pDS->ShapeInfo(i);
576 if (aSI.ShapeType()==aT) {
577 const TopoDS_Shape& aS=aSI.Shape();
578 //
579 Sprintf (buf, "z%d", i);
580 aText=buf;
581 aDShape=new BOPTest_DrawableShape (aS, aText, aTextColor);
7fd59977 582 Draw::Set (aText, aDShape);
4e57c75e 583 //
584 Sprintf (buf, " z%d", i);
585 di << buf;
586 //
587 iFound=1;
7fd59977 588 }
589 }
4e57c75e 590 //
591 if (iFound) {
7fd59977 592 di << "\n";
593 }
7fd59977 594 else {
4e57c75e 595 di << " not found\n";
7fd59977 596 }
7fd59977 597 //
7fd59977 598 return 0;
599}
7fd59977 600//=======================================================================
4e57c75e 601//function : bopcurves
7fd59977 602//purpose :
603//=======================================================================
4e57c75e 604Standard_Integer bopcurves (Draw_Interpretor& di,
605 Standard_Integer n,
606 const char** a)
7fd59977 607{
4e57c75e 608 if (n<3) {
99c5f9f0 609 di << " use bopcurves F1 F2 [-2d/-2d1/-2d2]\n";
4e57c75e 610 return 1;
7fd59977 611 }
99c5f9f0 612 //
4e57c75e 613 TopoDS_Shape S1 = DBRep::Get(a[1]);
614 TopoDS_Shape S2 = DBRep::Get(a[2]);
615 TopAbs_ShapeEnum aType;
99c5f9f0 616 //
4e57c75e 617 if (S1.IsNull() || S2.IsNull()) {
618 di << " Null shapes is not allowed \n";
619 return 1;
7fd59977 620 }
99c5f9f0 621 //
4e57c75e 622 aType=S1.ShapeType();
623 if (aType != TopAbs_FACE) {
624 di << " Type mismatch F1\n";
625 return 1;
7fd59977 626 }
4e57c75e 627 aType=S2.ShapeType();
628 if (aType != TopAbs_FACE) {
629 di << " Type mismatch F2\n";
630 return 1;
7fd59977 631 }
99c5f9f0 632 //
4e57c75e 633 const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
634 const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
99c5f9f0 635 //
636 Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
e9e644ed 637 Standard_Integer i, aNbCurves, aNbPoints;
4e57c75e 638 Standard_Real anAppTol, aTolR;
e9e644ed 639 TCollection_AsciiString aNm("c_"), aNp("p_");
99c5f9f0 640 //
641 anAppTol = 0.0000001;
642 aToApproxC3d = Standard_True;
643 aToApproxC2dOnS1 = Standard_False;
644 aToApproxC2dOnS2 = Standard_False;
645 //
c2c2f2b6 646 if (n > 3) {
647 if (!strcasecmp(a[3],"-2d")) {
99c5f9f0 648 aToApproxC2dOnS1 = Standard_True;
649 aToApproxC2dOnS2 = Standard_True;
650 }
651 else if (!strcasecmp(a[3],"-2d1")) {
652 aToApproxC2dOnS1 = Standard_True;
653 }
654 else if (!strcasecmp(a[3],"-2d2")) {
655 aToApproxC2dOnS2 = Standard_True;
656 }
657 else {
658 di << "Wrong key. To build 2d curves use: bopcurves F1 F2 -2d/-2d1/-2d2 \n";
c2c2f2b6 659 return 1;
660 }
661 }
662 //
4e57c75e 663 IntTools_FaceFace aFF;
99c5f9f0 664 //
4e57c75e 665 aFF.SetParameters (aToApproxC3d,
666 aToApproxC2dOnS1,
667 aToApproxC2dOnS2,
668 anAppTol);
99c5f9f0 669 //
4e57c75e 670 aFF.Perform (aF1, aF2);
99c5f9f0 671 //
4e57c75e 672 anIsDone=aFF.IsDone();
673 if (!anIsDone) {
d0820f2e 674 di << "Error: anIsDone=" << (Standard_Integer) anIsDone << "\n";
675 return 0;
7fd59977 676 }
99c5f9f0 677 //
c2c2f2b6 678 aFF.PrepareLines3D(Standard_False);
4e57c75e 679 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
e9e644ed 680 const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points();
4e57c75e 681 //
e9e644ed 682 aNbCurves = aSCs.Length();
683 aNbPoints = aSPs.Length();
684 if (!aNbCurves && !aNbPoints) {
685 di << " has no 3d curves\n";
686 di << " has no 3d points\n";
d0820f2e 687 return 0;
7fd59977 688 }
e9e644ed 689 //
690 aTolR=aFF.TolReached3d();
691 di << "Tolerance Reached=" << aTolR << "\n";
692 //
693 // curves
694 if (aNbCurves) {
c2c2f2b6 695 di << aNbCurves << " curve(s) found.\n";
e9e644ed 696 //
697 for (i=1; i<=aNbCurves; i++) {
698 const IntTools_Curve& anIC=aSCs(i);
7fd59977 699
e9e644ed 700 Handle (Geom_Curve) aC3D = anIC.Curve();
7fd59977 701
e9e644ed 702 if (aC3D.IsNull()) {
703 di << " has Null 3d curve# " << i << "\n";
704 continue;
705 }
7fd59977 706
e9e644ed 707 TCollection_AsciiString anIndx(i), aNmx;
708 aNmx = aNm + anIndx;
c2c2f2b6 709
e9e644ed 710 Standard_CString nameC = aNmx.ToCString();
c2c2f2b6 711
e9e644ed 712 DrawTrSurf::Set(nameC, aC3D);
713 di << nameC << " ";
c2c2f2b6 714 //
e9e644ed 715 Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
716 Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
c2c2f2b6 717 //
e9e644ed 718 if (!aPC1.IsNull() || !aPC2.IsNull()) {
719 di << "(";
99c5f9f0 720 //
721 if (!aPC1.IsNull()) {
e9e644ed 722 TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
723 pc1Nx = pc1N + anIndx;
724 Standard_CString nameC2d1 = pc1Nx.ToCString();
725 //
726 DrawTrSurf::Set(nameC2d1, aPC1);
727 di << nameC2d1;
99c5f9f0 728 }
e9e644ed 729 //
730 if (!aPC2.IsNull()) {
731 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
732 pc2Nx = pc2N + anIndx;
733 Standard_CString nameC2d2 = pc2Nx.ToCString();
734 //
735 DrawTrSurf::Set(nameC2d2, aPC2);
736 //
737 if (!aPC1.IsNull()) {
738 di << ", ";
739 }
740 di << nameC2d2;
741 }
742 di << ") ";
c2c2f2b6 743 }
744 }
e9e644ed 745 di << "\n";
746 }
747 //
748 // points
749 if (aNbPoints) {
750 di << aNbPoints << " point(s) found.\n";
751 //
752 for (i = 1; i <= aNbPoints; i++) {
753 const IntTools_PntOn2Faces& aPi = aSPs(i);
754 const gp_Pnt& aP = aPi.P1().Pnt();
755 //
756 TCollection_AsciiString anIndx(i), aNmx;
757 aNmx = aNp + anIndx;
758 Standard_CString nameP = aNmx.ToCString();
759 //
760 DrawTrSurf::Set(nameP, aP);
761 di << nameP << " ";
762 }
763 di << "\n";
7fd59977 764 }
99c5f9f0 765 //
4e57c75e 766 return 0;
7fd59977 767}
e322db46 768//=======================================================================
92ae0f2f 769//function : mkvolume
770//purpose :
771//=======================================================================
772Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a)
773{
92ae0f2f 774 if (n < 3) {
43cb0011 775 di << "Usage: mkvolume r b1 b2 ... [-c] [-ni]\n";
b1d15f53 776 di << "Options:\n";
777 di << " -c - use this option if the arguments are compounds\n";
778 di << " containing shapes that should be interfered;\n";
779 di << " -ni - use this option if the arguments should not be interfered;\n";
92ae0f2f 780 return 1;
781 }
782 //
b1d15f53 783 const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
784 //
785 Standard_Boolean bToIntersect, bRunParallel, bCompounds;
786 Standard_Integer i;
787 Standard_Real aTol;
788 TopoDS_Shape aS;
789 BOPCol_ListOfShape aLS;
92ae0f2f 790 //
49b0c452 791 aTol = BOPTest_Objects::FuzzyValue();
49b0c452 792 bRunParallel = BOPTest_Objects::RunParallel();
43cb0011 793 //
794 bToIntersect = Standard_True;
b1d15f53 795 bCompounds = Standard_False;
92ae0f2f 796 //
b1d15f53 797 for (i = 2; i < n; ++i) {
92ae0f2f 798 aS = DBRep::Get(a[i]);
799 if (!aS.IsNull()) {
800 aLS.Append(aS);
801 }
b1d15f53 802 else {
803 if (!strcmp(a[i], "-c")) {
804 bCompounds = Standard_True;
805 }
806 else if (!strcmp(a[i], "-ni")) {
807 bToIntersect = Standard_False;
808 }
b1d15f53 809 }
92ae0f2f 810 }
811 //
812 if (aLS.IsEmpty()) {
b1d15f53 813 di << "No shapes to process.\n";
92ae0f2f 814 di << usage;
815 return 1;
816 }
817 //
b1d15f53 818 // treat list of arguments for the case of compounds
819 if (bToIntersect && bCompounds) {
820 BOPCol_ListOfShape aLSx;
821 BOPCol_ListIteratorOfListOfShape aItLS;
822 //
823 aItLS.Initialize(aLS);
824 for (; aItLS.More(); aItLS.Next()) {
825 const TopoDS_Shape& aSx = aItLS.Value();
826 TopoDS_Iterator aItS(aSx);
827 for (; aItS.More(); aItS.Next()) {
828 const TopoDS_Shape& aSxS = aItS.Value();
829 aLSx.Append(aSxS);
830 }
831 }
832 //
833 aLS.Clear();
834 aLS.Assign(aLSx);
835 }
836 //
92ae0f2f 837 BOPAlgo_MakerVolume aMV;
838 aMV.SetArguments(aLS);
839 aMV.SetIntersect(bToIntersect);
840 aMV.SetRunParallel(bRunParallel);
b1d15f53 841 aMV.SetFuzzyValue(aTol);
92ae0f2f 842 //
843 aMV.Perform();
844 if (aMV.ErrorStatus()) {
845 di << "Error status: " << aMV.ErrorStatus();
846 return 1;
847 }
848 //
849 const TopoDS_Shape& aR = aMV.Shape();
850 //
851 DBRep::Set(a[1], aR);
852 //
853 return 0;
854}