0025691: Visualization, TKService - fix font corruption on FreeType 2.5.4
[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#include <BOPTest.ixx>
17
18#include <stdio.h>
19
49b0c452 20#include <TCollection_AsciiString.hxx>
21
7fd59977 22#include <DBRep.hxx>
49b0c452 23#include <DrawTrSurf.hxx>
24#include <Draw_Color.hxx>
25#include <Draw.hxx>
7fd59977 26
4e57c75e 27#include <NCollection_BaseAllocator.hxx>
28#include <NCollection_IncAllocator.hxx>
7fd59977 29
7fd59977 30#include <TopoDS_Shape.hxx>
4e57c75e 31#include <TopoDS_Compound.hxx>
b1d15f53 32#include <TopoDS_Iterator.hxx>
33//
7fd59977 34#include <BRep_Builder.hxx>
35
49b0c452 36#include <IntTools_FaceFace.hxx>
37#include <IntTools_Curve.hxx>
38
39#include <BOPCol_ListOfShape.hxx>
40
41#include <BOPDS_DS.hxx>
42
4e57c75e 43#include <BOPAlgo_PaveFiller.hxx>
44#include <BOPAlgo_Operation.hxx>
45#include <BOPAlgo_BOP.hxx>
92ae0f2f 46#include <BOPAlgo_MakerVolume.hxx>
49b0c452 47#include <BOPAlgo_Section.hxx>
7fd59977 48
da219023 49#include <BRepAlgoAPI_BooleanOperation.hxx>
50#include <BRepAlgoAPI_Common.hxx>
51#include <BRepAlgoAPI_Fuse.hxx>
52#include <BRepAlgoAPI_Cut.hxx>
53#include <BRepAlgoAPI_Section.hxx>
49b0c452 54
55#include <BOPTest_DrawableShape.hxx>
56#include <BOPTest_Objects.hxx>
7fd59977 57
58//
4e57c75e 59static BOPAlgo_PaveFiller* pPF=NULL;
7fd59977 60//
7fd59977 61
4e57c75e 62static
63 Standard_Integer bopsmt(Draw_Interpretor& di,
64 Standard_Integer n,
65 const char** a,
66 const BOPAlgo_Operation aOp);
67static
68 Standard_Integer bsmt (Draw_Interpretor& di,
69 Standard_Integer n,
70 const char** a,
71 const BOPAlgo_Operation aOp);
7fd59977 72//
4e57c75e 73static Standard_Integer bop (Draw_Interpretor&, Standard_Integer, const char**);
74static Standard_Integer bopsection(Draw_Interpretor&, Standard_Integer, const char**);
75static Standard_Integer boptuc (Draw_Interpretor&, Standard_Integer, const char**);
76static Standard_Integer bopcut (Draw_Interpretor&, Standard_Integer, const char**);
77static Standard_Integer bopfuse (Draw_Interpretor&, Standard_Integer, const char**);
78static Standard_Integer bopcommon (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 79//
4e57c75e 80static Standard_Integer bsection (Draw_Interpretor&, Standard_Integer, const char**);
81static Standard_Integer btuc (Draw_Interpretor&, Standard_Integer, const char**);
82static Standard_Integer bcut (Draw_Interpretor&, Standard_Integer, const char**);
83static Standard_Integer bfuse (Draw_Interpretor&, Standard_Integer, const char**);
84static Standard_Integer bcommon (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 85//
4e57c75e 86static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char**);
87static Standard_Integer bopnews (Draw_Interpretor&, Standard_Integer, const char**);
92ae0f2f 88//
e322db46 89static Standard_Integer bparallelmode(Draw_Interpretor&, Standard_Integer, const char**);
90//
92ae0f2f 91static Standard_Integer mkvolume (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 92
7fd59977 93//=======================================================================
94//function : BOPCommands
95//purpose :
96//=======================================================================
4e57c75e 97 void BOPTest::BOPCommands(Draw_Interpretor& theCommands)
7fd59977 98{
99 static Standard_Boolean done = Standard_False;
4e57c75e 100 if (done) return;
7fd59977 101 done = Standard_True;
102 // Chapter's name
4e57c75e 103 const char* g = "BOP commands";
104 // Commands
105
b1d15f53 106 theCommands.Add("bop" , "use bop s1 s2 [tol]" , __FILE__, bop, g);
107 theCommands.Add("bopcommon" , "use bopcommon r" , __FILE__, bopcommon, g);
108 theCommands.Add("bopfuse" , "use bopfuse r" , __FILE__,bopfuse, g);
109 theCommands.Add("bopcut" , "use bopcut r" , __FILE__,bopcut, g);
110 theCommands.Add("boptuc" , "use boptuc r" , __FILE__,boptuc, g);
111 theCommands.Add("bopsection", "use bopsection r" , __FILE__,bopsection, g);
112 //
113 theCommands.Add("bcommon" , "use bcommon r s1 s2 [tol]" , __FILE__,bcommon, g);
114 theCommands.Add("bfuse" , "use bfuse r s1 s2 [tol]" , __FILE__,bfuse, g);
115 theCommands.Add("bcut" , "use bcut r s1 s2 [tol]" , __FILE__,bcut, g);
116 theCommands.Add("btuc" , "use btuc r s1 s2 [tol]" , __FILE__,btuc, g);
117 theCommands.Add("bsection", "Use >bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]",
4e57c75e 118 __FILE__, bsection, g);
7fd59977 119 //
c2c2f2b6 120 theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d]", __FILE__, bopcurves, g);
4e57c75e 121 theCommands.Add("bopnews", "use bopnews -v[e,f]" , __FILE__, bopnews, g);
b1d15f53 122 theCommands.Add("bparallelmode", "bparallelmode [1/0] : show / set parallel mode for boolean operations",
123 __FILE__, bparallelmode, g);
124 theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni] [-s] [tol]",
125 __FILE__, mkvolume , g);
7fd59977 126}
4e57c75e 127
7fd59977 128//=======================================================================
129//function : bop
130//purpose :
131//=======================================================================
49b0c452 132Standard_Integer bop(Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 133{
4e57c75e 134 char buf[32];
49b0c452 135 Standard_Boolean bRunParallel;
4e57c75e 136 Standard_Integer iErr;
b1d15f53 137 Standard_Real aTol;
4e57c75e 138 TopoDS_Shape aS1, aS2;
139 BOPCol_ListOfShape aLC;
140 //
b1d15f53 141 if (n < 3 || n > 4) {
142 di << " use bop Shape1 Shape2 [tol]\n";
49b0c452 143 return 0;
7fd59977 144 }
4e57c75e 145 //
146 aS1=DBRep::Get(a[1]);
147 aS2=DBRep::Get(a[2]);
148 //
149 if (aS1.IsNull() || aS2.IsNull()) {
150 di << " null shapes are not allowed \n";
49b0c452 151 return 0;
7fd59977 152 }
4e57c75e 153 //
49b0c452 154 aTol=BOPTest_Objects::FuzzyValue();
b1d15f53 155 if (n == 4) {
156 aTol = Draw::Atof(a[3]);
157 }
158 //
49b0c452 159 bRunParallel=BOPTest_Objects::RunParallel();
160 //
4e57c75e 161 aLC.Append(aS1);
162 aLC.Append(aS2);
163 //
5d05cf31 164 if (pPF!=NULL) {
4e57c75e 165 delete pPF;
5d05cf31 166 pPF=NULL;
7fd59977 167 }
5d05cf31 168 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
169 pPF=new BOPAlgo_PaveFiller(aAL);
4e57c75e 170 //
171 pPF->SetArguments(aLC);
b1d15f53 172 pPF->SetFuzzyValue(aTol);
49b0c452 173 pPF->SetRunParallel(bRunParallel);
4e57c75e 174 //
175 pPF->Perform();
176 iErr=pPF->ErrorStatus();
177 if (iErr) {
178 Sprintf(buf, " ErrorStatus : %d\n", iErr);
179 di << buf;
180 return 0;
7fd59977 181 }
4e57c75e 182 //
7fd59977 183 return 0;
184}
7fd59977 185//=======================================================================
4e57c75e 186//function : bopcommon
7fd59977 187//purpose :
188//=======================================================================
4e57c75e 189Standard_Integer bopcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 190{
4e57c75e 191 return bopsmt(di, n, a, BOPAlgo_COMMON);
192}
193//=======================================================================
194//function : bopfuse
195//purpose :
196//=======================================================================
197Standard_Integer bopfuse(Draw_Interpretor& di, Standard_Integer n, const char** a)
198{
199 return bopsmt(di, n, a, BOPAlgo_FUSE);
200}
201//=======================================================================
202//function : bopcut
203//purpose :
204//=======================================================================
205Standard_Integer bopcut(Draw_Interpretor& di, Standard_Integer n, const char** a)
206{
207 return bopsmt(di, n, a, BOPAlgo_CUT);
208}
209//=======================================================================
210//function : boptuc
211//purpose :
212//=======================================================================
213Standard_Integer boptuc(Draw_Interpretor& di, Standard_Integer n, const char** a)
214{
215 return bopsmt(di, n, a, BOPAlgo_CUT21);
216}
217//=======================================================================
4e57c75e 218//function : bopsmt
219//purpose :
220//=======================================================================
221Standard_Integer bopsmt(Draw_Interpretor& di,
222 Standard_Integer n,
223 const char** a,
224 const BOPAlgo_Operation aOp)
225{
226 if (n<2) {
b1d15f53 227 di << " use bopsmt r\n [tol]";
4e57c75e 228 return 0;
7fd59977 229 }
4e57c75e 230 //
231 if (!pPF) {
232 di << " prepare PaveFiller first\n";
233 return 0;
234 }
235 //
236 if (pPF->ErrorStatus()) {
237 di << " PaveFiller has not been done\n";
238 return 0;
239 }
240 //
241 char buf[64];
49b0c452 242 Standard_Boolean bRunParallel;
4e57c75e 243 Standard_Integer aNb, iErr;
244 BOPAlgo_BOP aBOP;
245 //
246 const BOPCol_ListOfShape& aLC=pPF->Arguments();
247 aNb=aLC.Extent();
248 if (aNb!=2) {
249 Sprintf (buf, " wrong number of arguments %s\n", aNb);
250 di << buf;
251 return 0;
252 }
49b0c452 253 //
254 bRunParallel=BOPTest_Objects::RunParallel();
4e57c75e 255 //
256 const TopoDS_Shape& aS1=aLC.First();
257 const TopoDS_Shape& aS2=aLC.Last();
258 //
259 aBOP.AddArgument(aS1);
260 aBOP.AddTool(aS2);
261 aBOP.SetOperation(aOp);
49b0c452 262 aBOP.SetRunParallel (bRunParallel);
4e57c75e 263 //
264 aBOP.PerformWithFiller(*pPF);
265 iErr=aBOP.ErrorStatus();
266 if (iErr) {
267 Sprintf(buf, " ErrorStatus : %d\n", iErr);
268 di << buf;
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//=======================================================================
285Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char** a)
286{
287 if (n<2) {
288 di << " use bopsmt r\n";
289 return 0;
290 }
291 //
292 if (!pPF) {
293 di << " prepare PaveFiller first\n";
294 return 0;
295 }
296 //
297 if (pPF->ErrorStatus()) {
298 di << " PaveFiller has not been done\n";
299 return 0;
300 }
301 //
302 char buf[64];
49b0c452 303 Standard_Boolean bRunParallel;
85915310 304 Standard_Integer aNb, iErr;
305 BOPAlgo_Section aBOP;
306 //
307 const BOPCol_ListOfShape& aLC=pPF->Arguments();
308 aNb=aLC.Extent();
309 if (aNb!=2) {
310 Sprintf (buf, " wrong number of arguments %s\n", aNb);
311 di << buf;
312 return 0;
313 }
314 //
49b0c452 315 bRunParallel=BOPTest_Objects::RunParallel();
316 //
85915310 317 const TopoDS_Shape& aS1=aLC.First();
318 const TopoDS_Shape& aS2=aLC.Last();
319 //
320 aBOP.AddArgument(aS1);
321 aBOP.AddArgument(aS2);
49b0c452 322 aBOP.SetRunParallel (bRunParallel);
85915310 323 //
324 aBOP.PerformWithFiller(*pPF);
325 iErr=aBOP.ErrorStatus();
326 if (iErr) {
327 Sprintf(buf, " ErrorStatus : %d\n", iErr);
328 di << buf;
329 return 0;
330 }
331 //
332 const TopoDS_Shape& aR=aBOP.Shape();
333 if (aR.IsNull()) {
334 di << " null shape\n";
335 return 0;
336 }
337 //
338 DBRep::Set(a[1], aR);
339 return 0;
340}
341//=======================================================================
7fd59977 342//function : bcommon
343//purpose :
344//=======================================================================
4e57c75e 345Standard_Integer bcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 346{
4e57c75e 347 return bsmt(di, n, a, BOPAlgo_COMMON);
7fd59977 348}
349//=======================================================================
350//function : bfuse
351//purpose :
352//=======================================================================
4e57c75e 353Standard_Integer bfuse (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 354{
4e57c75e 355 return bsmt(di, n, a, BOPAlgo_FUSE);
7fd59977 356}
7fd59977 357//=======================================================================
358//function : bcut
359//purpose :
360//=======================================================================
4e57c75e 361Standard_Integer bcut (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 362{
4e57c75e 363 return bsmt(di, n, a, BOPAlgo_CUT);
364}
365//=======================================================================
366//function : btuc
367//purpose :
368//=======================================================================
369Standard_Integer btuc (Draw_Interpretor& di, Standard_Integer n, const char** a)
370{
371 return bsmt(di, n, a, BOPAlgo_CUT21);
7fd59977 372}
373//=======================================================================
374//function : bsection
375//purpose :
376//=======================================================================
377Standard_Integer bsection(Draw_Interpretor& di,
4e57c75e 378 Standard_Integer n,
379 const char** a)
7fd59977 380{
b1d15f53 381 const char* usage = " Usage: bsection Result s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]\n";
7fd59977 382 if (n < 4) {
383 di << usage;
49b0c452 384 return 0;
7fd59977 385 }
b1d15f53 386 //
4e57c75e 387 TopoDS_Shape aS1 = DBRep::Get(a[2]);
388 TopoDS_Shape aS2 = DBRep::Get(a[3]);
b1d15f53 389 //
4e57c75e 390 if (aS1.IsNull() || aS2.IsNull()) {
7fd59977 391 di << " Null shapes are not allowed \n";
49b0c452 392 return 0;
7fd59977 393 }
49b0c452 394 //
395 char buf[80];
396 Standard_Boolean bRunParallel, bApp, bPC1, bPC2;
397 Standard_Integer i, iErr;
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();
b1d15f53 405 //
406 for (i = 4; i < n; ++i) {
407 if (!strcmp(a[i], "-n2d")) {
408 bPC1 = Standard_False;
409 bPC2 = Standard_False;
7fd59977 410 }
b1d15f53 411 else if (!strcmp(a[i], "-n2d1")) {
412 bPC1 = Standard_False;
7fd59977 413 }
b1d15f53 414 else if (!strcmp(a[i], "-n2d2")) {
415 bPC2 = Standard_False;
7fd59977 416 }
b1d15f53 417 else if (!strcmp(a[i], "-na")) {
418 bApp = Standard_False;
7fd59977 419 }
b1d15f53 420 else {
421 aTol = Draw::Atof(a[i]);
4e57c75e 422 }
b1d15f53 423 }
424 //
b1d15f53 425 BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False);
49b0c452 426 //
b1d15f53 427 aSec.Approximation(bApp);
428 aSec.ComputePCurveOn1(bPC1);
429 aSec.ComputePCurveOn2(bPC2);
430 aSec.SetFuzzyValue(aTol);
49b0c452 431 aSec.SetRunParallel(bRunParallel);
b1d15f53 432 //
433 aSec.Build();
434 iErr=aSec.ErrorStatus();
435 if (!aSec.IsDone()) {
436 Sprintf(buf, " ErrorStatus : %d\n", iErr);
437 di << buf;
4e57c75e 438 return 0;
7fd59977 439 }
b1d15f53 440 //
441 const TopoDS_Shape& aR=aSec.Shape();
442 if (aR.IsNull()) {
443 di << " null shape\n";
444 return 0;
7fd59977 445 }
b1d15f53 446 DBRep::Set(a[1], aR);
447 return 0;
7fd59977 448}
7fd59977 449//=======================================================================
4e57c75e 450//function : bsmt
7fd59977 451//purpose :
452//=======================================================================
4e57c75e 453Standard_Integer bsmt (Draw_Interpretor& di,
454 Standard_Integer n,
455 const char** a,
456 const BOPAlgo_Operation aOp)
7fd59977 457{
4e57c75e 458 char buf[32];
49b0c452 459 Standard_Boolean bRunParallel;
4e57c75e 460 Standard_Integer iErr;
461 TopoDS_Shape aS1, aS2;
462 BOPCol_ListOfShape aLC;
b1d15f53 463 Standard_Real aTol;
4e57c75e 464 //
b1d15f53 465 if (n < 4 || n > 5) {
466 di << " use bx r s1 s2 [tol]\n";
49b0c452 467 return 0;
7fd59977 468 }
4e57c75e 469 //
470 aS1=DBRep::Get(a[2]);
471 aS2=DBRep::Get(a[3]);
472 //
473 if (aS1.IsNull() || aS2.IsNull()) {
474 di << " null shapes are not allowed \n";
49b0c452 475 return 0;
7fd59977 476 }
49b0c452 477 aLC.Append(aS1);
478 aLC.Append(aS2);
479 //
480 aTol=BOPTest_Objects::FuzzyValue();
b1d15f53 481 if (n == 5) {
482 aTol = Draw::Atof(a[4]);
483 }
484 //
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) {
c2c2f2b6 609 di << " use bopcurves F1 F2 [-2d]\n";
4e57c75e 610 return 1;
7fd59977 611 }
612
4e57c75e 613 TopoDS_Shape S1 = DBRep::Get(a[1]);
614 TopoDS_Shape S2 = DBRep::Get(a[2]);
615 TopAbs_ShapeEnum aType;
7fd59977 616
4e57c75e 617 if (S1.IsNull() || S2.IsNull()) {
618 di << " Null shapes is not allowed \n";
619 return 1;
7fd59977 620 }
7fd59977 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 }
632
7fd59977 633
4e57c75e 634 const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
635 const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
7fd59977 636
49b0c452 637 Standard_Boolean aToApproxC3d, aToApproxC2dOnS1,
638 aToApproxC2dOnS2, anIsDone, bMake2dCurves;
4e57c75e 639 Standard_Integer i, aNbCurves;
640 Standard_Real anAppTol, aTolR;
641 TCollection_AsciiString aNm("c_");
7fd59977 642
c2c2f2b6 643 bMake2dCurves = Standard_False;
644 if (n > 3) {
645 if (!strcasecmp(a[3],"-2d")) {
646 bMake2dCurves = Standard_True;
647 } else {
648 di << "Wrong key. To build 2d curves use: bopcurves F1 F2 -2d \n";
649 return 1;
650 }
651 }
652 //
653
654 aToApproxC3d = Standard_True;
655 aToApproxC2dOnS1 = bMake2dCurves;
656 aToApproxC2dOnS2 = bMake2dCurves;
4e57c75e 657 anAppTol=0.0000001;
7fd59977 658
7fd59977 659
4e57c75e 660 IntTools_FaceFace aFF;
7fd59977 661
4e57c75e 662 aFF.SetParameters (aToApproxC3d,
663 aToApproxC2dOnS1,
664 aToApproxC2dOnS2,
665 anAppTol);
7fd59977 666
4e57c75e 667 aFF.Perform (aF1, aF2);
7fd59977 668
4e57c75e 669 anIsDone=aFF.IsDone();
670 if (!anIsDone) {
671 di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
672 return 1;
7fd59977 673 }
674
c2c2f2b6 675 aFF.PrepareLines3D(Standard_False);
4e57c75e 676 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
7fd59977 677
4e57c75e 678 //
679 aTolR=aFF.TolReached3d();
680 di << "Tolerance Reached=" << aTolR << "\n";
7fd59977 681
4e57c75e 682 aNbCurves=aSCs.Length();
683 if (!aNbCurves) {
684 di << " has no 3d curve\n";
685 return 1;
7fd59977 686 }
49b0c452 687 else {
c2c2f2b6 688 di << aNbCurves << " curve(s) found.\n";
689 }
7fd59977 690
4e57c75e 691 for (i=1; i<=aNbCurves; i++) {
692 const IntTools_Curve& anIC=aSCs(i);
7fd59977 693
c2c2f2b6 694 Handle (Geom_Curve) aC3D = anIC.Curve();
7fd59977 695
4e57c75e 696 if (aC3D.IsNull()) {
c2c2f2b6 697 di << " has Null 3d curve# " << i << "\n";
4e57c75e 698 continue;
7fd59977 699 }
7fd59977 700
4e57c75e 701 TCollection_AsciiString anIndx(i), aNmx;
c2c2f2b6 702 aNmx = aNm + anIndx;
703
704 Standard_CString nameC = aNmx.ToCString();
705
706 DrawTrSurf::Set(nameC, aC3D);
707 di << nameC << " ";
708 //
709 if (bMake2dCurves) {
710 Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
711 Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
712 //
713 if (aPC1.IsNull() && aPC2.IsNull()) {
714 di << " \n has Null 2d curves# " << i << "\n";
715 continue;
716 }
717 //
718 if (aPC1.IsNull()) {
719 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
720 pc2Nx = pc2N + anIndx;
721 Standard_CString nameC2d2 = pc2Nx.ToCString();
722 //
723 DrawTrSurf::Set(nameC2d2, aPC2);
724 di << "(" << nameC2d2 << ") ";
725 di << " \n Null first 2d curve of the curve #" << i << "\n";
726 continue;
49b0c452 727 }
728 else {
c2c2f2b6 729 TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
730 pc1Nx = pc1N + anIndx;
731 Standard_CString nameC2d1 = pc1Nx.ToCString();
732 //
733 DrawTrSurf::Set(nameC2d1, aPC1);
734 di << "(" << nameC2d1;
735 }
736 //
737 if (aPC2.IsNull()) {
738 di << ") \n Null second 2d curve of the curve #" << i << "\n";
739 continue;
49b0c452 740 }
741 else {
c2c2f2b6 742 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
743 pc2Nx = pc2N + anIndx;
744 Standard_CString nameC2d2 = pc2Nx.ToCString();
745 //
746 DrawTrSurf::Set(nameC2d2, aPC2);
747 di << ", " << nameC2d2 << ") ";
748 }
749 }
7fd59977 750 }
7fd59977 751
7fd59977 752 di << "\n";
7fd59977 753
4e57c75e 754 return 0;
7fd59977 755}
e322db46 756//=======================================================================
92ae0f2f 757//function : mkvolume
758//purpose :
759//=======================================================================
760Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a)
761{
92ae0f2f 762 if (n < 3) {
b1d15f53 763 di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-s] [tol]\n";
764 di << "Options:\n";
765 di << " -c - use this option if the arguments are compounds\n";
766 di << " containing shapes that should be interfered;\n";
767 di << " -ni - use this option if the arguments should not be interfered;\n";
768 di << " -s - use this option to run the operation in non parallel mode;\n";
769 di << " tol - additional tolerance value (real).\n";
92ae0f2f 770 return 1;
771 }
772 //
b1d15f53 773 const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
774 //
775 Standard_Boolean bToIntersect, bRunParallel, bCompounds;
776 Standard_Integer i;
777 Standard_Real aTol;
778 TopoDS_Shape aS;
779 BOPCol_ListOfShape aLS;
92ae0f2f 780 //
49b0c452 781 aTol = BOPTest_Objects::FuzzyValue();
92ae0f2f 782 bToIntersect = Standard_True;
49b0c452 783 bRunParallel = BOPTest_Objects::RunParallel();
b1d15f53 784 bCompounds = Standard_False;
92ae0f2f 785 //
b1d15f53 786 for (i = 2; i < n; ++i) {
92ae0f2f 787 aS = DBRep::Get(a[i]);
788 if (!aS.IsNull()) {
789 aLS.Append(aS);
790 }
b1d15f53 791 else {
792 if (!strcmp(a[i], "-c")) {
793 bCompounds = Standard_True;
794 }
795 else if (!strcmp(a[i], "-ni")) {
796 bToIntersect = Standard_False;
797 }
798 else if (!strcmp(a[i], "-s")) {
799 bRunParallel = Standard_False;
800 }
801 else {
802 aTol = Draw::Atof(a[i]);
803 }
804 }
92ae0f2f 805 }
806 //
807 if (aLS.IsEmpty()) {
b1d15f53 808 di << "No shapes to process.\n";
92ae0f2f 809 di << usage;
810 return 1;
811 }
812 //
b1d15f53 813 // treat list of arguments for the case of compounds
814 if (bToIntersect && bCompounds) {
815 BOPCol_ListOfShape aLSx;
816 BOPCol_ListIteratorOfListOfShape aItLS;
817 //
818 aItLS.Initialize(aLS);
819 for (; aItLS.More(); aItLS.Next()) {
820 const TopoDS_Shape& aSx = aItLS.Value();
821 TopoDS_Iterator aItS(aSx);
822 for (; aItS.More(); aItS.Next()) {
823 const TopoDS_Shape& aSxS = aItS.Value();
824 aLSx.Append(aSxS);
825 }
826 }
827 //
828 aLS.Clear();
829 aLS.Assign(aLSx);
830 }
831 //
92ae0f2f 832 BOPAlgo_MakerVolume aMV;
833 aMV.SetArguments(aLS);
834 aMV.SetIntersect(bToIntersect);
835 aMV.SetRunParallel(bRunParallel);
b1d15f53 836 aMV.SetFuzzyValue(aTol);
92ae0f2f 837 //
838 aMV.Perform();
839 if (aMV.ErrorStatus()) {
840 di << "Error status: " << aMV.ErrorStatus();
841 return 1;
842 }
843 //
844 const TopoDS_Shape& aR = aMV.Shape();
845 //
846 DBRep::Set(a[1], aR);
847 //
848 return 0;
849}
49b0c452 850//=======================================================================
851//function : bparallelmode
852//purpose :
853//=======================================================================
854Standard_Integer bparallelmode(Draw_Interpretor& di, Standard_Integer n, const char** a)
855{
856 if (n == 2)
857 {
858 Standard_Boolean isParallelOn = Draw::Atoi (a[1]) == 1;
859 if (isParallelOn == 1)
860 {
861 BOPAlgo_Algo::SetParallelMode(Standard_True);
862 di << "Parallel mode for boolean operations has been enabled";
863 }
864 else
865 {
866 BOPAlgo_Algo::SetParallelMode(Standard_False);
867 di << "Parallel mode for boolean operations has been disabled";
868 }
869 }
870 else
871 {
872 di << "Parallel mode state for boolean operations: "
873 << (BOPAlgo_Algo::GetParallelMode()? "enabled" : "disabled");
874 }
875
876 return 0;
877}