0026619: Tolerances of operands are modified using bop
[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>
42cf5bc1 25#include <BOPTest_Objects.hxx>
26#include <BRep_Builder.hxx>
da219023 27#include <BRepAlgoAPI_BooleanOperation.hxx>
28#include <BRepAlgoAPI_Common.hxx>
da219023 29#include <BRepAlgoAPI_Cut.hxx>
42cf5bc1 30#include <BRepAlgoAPI_Fuse.hxx>
da219023 31#include <BRepAlgoAPI_Section.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>
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);
104 theCommands.Add("bsection", "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]",
4e57c75e 105 __FILE__, bsection, g);
7fd59977 106 //
47e3009d 107 theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d/-2d1/-2d2] [-p u1 v1 u2 v2]",
99c5f9f0 108 __FILE__, bopcurves, g);
43cb0011 109 theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni]",
b1d15f53 110 __FILE__, mkvolume , g);
7fd59977 111}
4e57c75e 112
7fd59977 113//=======================================================================
114//function : bop
115//purpose :
116//=======================================================================
43cb0011 117Standard_Integer bop(Draw_Interpretor& di,
118 Standard_Integer n,
119 const char** a)
7fd59977 120{
4e57c75e 121 char buf[32];
3510db62 122 Standard_Boolean bRunParallel, bNonDestructive;
4e57c75e 123 Standard_Integer iErr;
b1d15f53 124 Standard_Real aTol;
4e57c75e 125 TopoDS_Shape aS1, aS2;
126 BOPCol_ListOfShape aLC;
127 //
43cb0011 128 if (n != 3) {
129 di << " use bop s1 s2 \n";
49b0c452 130 return 0;
7fd59977 131 }
4e57c75e 132 //
133 aS1=DBRep::Get(a[1]);
134 aS2=DBRep::Get(a[2]);
135 //
136 if (aS1.IsNull() || aS2.IsNull()) {
137 di << " null shapes are not allowed \n";
49b0c452 138 return 0;
7fd59977 139 }
4e57c75e 140 //
49b0c452 141 aTol=BOPTest_Objects::FuzzyValue();
49b0c452 142 bRunParallel=BOPTest_Objects::RunParallel();
3510db62 143 bNonDestructive = BOPTest_Objects::NonDestructive();
49b0c452 144 //
4e57c75e 145 aLC.Append(aS1);
146 aLC.Append(aS2);
147 //
5d05cf31 148 if (pPF!=NULL) {
4e57c75e 149 delete pPF;
5d05cf31 150 pPF=NULL;
7fd59977 151 }
488e5b9d 152 Handle(NCollection_BaseAllocator)aAL=
153 NCollection_BaseAllocator::CommonBaseAllocator();
5d05cf31 154 pPF=new BOPAlgo_PaveFiller(aAL);
4e57c75e 155 //
156 pPF->SetArguments(aLC);
b1d15f53 157 pPF->SetFuzzyValue(aTol);
49b0c452 158 pPF->SetRunParallel(bRunParallel);
3510db62 159 pPF->SetNonDestructive(bNonDestructive);
4e57c75e 160 //
161 pPF->Perform();
162 iErr=pPF->ErrorStatus();
163 if (iErr) {
164 Sprintf(buf, " ErrorStatus : %d\n", iErr);
165 di << buf;
166 return 0;
7fd59977 167 }
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 //
230 if (pPF->ErrorStatus()) {
231 di << " PaveFiller has not been done\n";
232 return 0;
233 }
234 //
235 char buf[64];
49b0c452 236 Standard_Boolean bRunParallel;
4e57c75e 237 Standard_Integer aNb, iErr;
238 BOPAlgo_BOP aBOP;
239 //
240 const BOPCol_ListOfShape& aLC=pPF->Arguments();
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);
4e57c75e 257 //
258 aBOP.PerformWithFiller(*pPF);
259 iErr=aBOP.ErrorStatus();
260 if (iErr) {
261 Sprintf(buf, " ErrorStatus : %d\n", iErr);
262 di << buf;
263 return 0;
264 }
265 //
266 const TopoDS_Shape& aR=aBOP.Shape();
267 if (aR.IsNull()) {
268 di << " null shape\n";
269 return 0;
270 }
271 //
272 DBRep::Set(a[1], aR);
273 return 0;
7fd59977 274}
7fd59977 275//=======================================================================
85915310 276//function : bopsection
277//purpose :
278//=======================================================================
43cb0011 279Standard_Integer bopsection(Draw_Interpretor& di,
280 Standard_Integer n,
281 const char** a)
85915310 282{
283 if (n<2) {
43cb0011 284 di << " use bopsection r\n";
85915310 285 return 0;
286 }
287 //
288 if (!pPF) {
289 di << " prepare PaveFiller first\n";
290 return 0;
291 }
292 //
293 if (pPF->ErrorStatus()) {
294 di << " PaveFiller has not been done\n";
295 return 0;
296 }
297 //
298 char buf[64];
49b0c452 299 Standard_Boolean bRunParallel;
85915310 300 Standard_Integer aNb, iErr;
301 BOPAlgo_Section aBOP;
302 //
303 const BOPCol_ListOfShape& aLC=pPF->Arguments();
304 aNb=aLC.Extent();
305 if (aNb!=2) {
306 Sprintf (buf, " wrong number of arguments %s\n", aNb);
307 di << buf;
308 return 0;
309 }
310 //
49b0c452 311 bRunParallel=BOPTest_Objects::RunParallel();
312 //
85915310 313 const TopoDS_Shape& aS1=aLC.First();
314 const TopoDS_Shape& aS2=aLC.Last();
315 //
316 aBOP.AddArgument(aS1);
317 aBOP.AddArgument(aS2);
49b0c452 318 aBOP.SetRunParallel (bRunParallel);
85915310 319 //
320 aBOP.PerformWithFiller(*pPF);
321 iErr=aBOP.ErrorStatus();
322 if (iErr) {
323 Sprintf(buf, " ErrorStatus : %d\n", iErr);
324 di << buf;
325 return 0;
326 }
327 //
328 const TopoDS_Shape& aR=aBOP.Shape();
329 if (aR.IsNull()) {
330 di << " null shape\n";
331 return 0;
332 }
333 //
334 DBRep::Set(a[1], aR);
335 return 0;
336}
337//=======================================================================
7fd59977 338//function : bcommon
339//purpose :
340//=======================================================================
43cb0011 341Standard_Integer bcommon (Draw_Interpretor& di,
342 Standard_Integer n,
343 const char** a)
7fd59977 344{
4e57c75e 345 return bsmt(di, n, a, BOPAlgo_COMMON);
7fd59977 346}
347//=======================================================================
348//function : bfuse
349//purpose :
350//=======================================================================
43cb0011 351Standard_Integer bfuse (Draw_Interpretor& di,
352 Standard_Integer n,
353 const char** a)
7fd59977 354{
4e57c75e 355 return bsmt(di, n, a, BOPAlgo_FUSE);
7fd59977 356}
7fd59977 357//=======================================================================
358//function : bcut
359//purpose :
360//=======================================================================
43cb0011 361Standard_Integer bcut (Draw_Interpretor& di,
362 Standard_Integer n,
363 const char** a)
7fd59977 364{
4e57c75e 365 return bsmt(di, n, a, BOPAlgo_CUT);
366}
367//=======================================================================
368//function : btuc
369//purpose :
370//=======================================================================
43cb0011 371Standard_Integer btuc (Draw_Interpretor& di,
372 Standard_Integer n,
373 const char** a)
4e57c75e 374{
375 return bsmt(di, n, a, BOPAlgo_CUT21);
7fd59977 376}
377//=======================================================================
378//function : bsection
379//purpose :
380//=======================================================================
381Standard_Integer bsection(Draw_Interpretor& di,
4e57c75e 382 Standard_Integer n,
383 const char** a)
7fd59977 384{
7fd59977 385 if (n < 4) {
43cb0011 386 di << "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]\n";
49b0c452 387 return 0;
7fd59977 388 }
b1d15f53 389 //
43cb0011 390 TopoDS_Shape aS1, aS2;
b1d15f53 391 //
43cb0011 392 aS1=DBRep::Get(a[2]);
393 aS2=DBRep::Get(a[3]);
4e57c75e 394 if (aS1.IsNull() || aS2.IsNull()) {
7fd59977 395 di << " Null shapes are not allowed \n";
49b0c452 396 return 0;
7fd59977 397 }
49b0c452 398 //
399 char buf[80];
3510db62 400 Standard_Boolean bRunParallel, bNonDestructive, bApp, bPC1, bPC2;
49b0c452 401 Standard_Integer i, iErr;
b1d15f53 402 Standard_Real aTol;
da219023 403 //
404 bApp = Standard_True;
405 bPC1 = Standard_True;
406 bPC2 = Standard_True;
49b0c452 407 aTol = BOPTest_Objects::FuzzyValue();
408 bRunParallel = BOPTest_Objects::RunParallel();
3510db62 409 bNonDestructive = BOPTest_Objects::NonDestructive();
b1d15f53 410 //
411 for (i = 4; i < n; ++i) {
412 if (!strcmp(a[i], "-n2d")) {
413 bPC1 = Standard_False;
414 bPC2 = Standard_False;
7fd59977 415 }
b1d15f53 416 else if (!strcmp(a[i], "-n2d1")) {
417 bPC1 = Standard_False;
7fd59977 418 }
b1d15f53 419 else if (!strcmp(a[i], "-n2d2")) {
420 bPC2 = Standard_False;
7fd59977 421 }
b1d15f53 422 else if (!strcmp(a[i], "-na")) {
423 bApp = Standard_False;
7fd59977 424 }
b1d15f53 425 }
426 //
b1d15f53 427 BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False);
49b0c452 428 //
b1d15f53 429 aSec.Approximation(bApp);
430 aSec.ComputePCurveOn1(bPC1);
431 aSec.ComputePCurveOn2(bPC2);
43cb0011 432 //
b1d15f53 433 aSec.SetFuzzyValue(aTol);
49b0c452 434 aSec.SetRunParallel(bRunParallel);
3510db62 435 aSec.SetNonDestructive(bNonDestructive);
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];
3510db62 463 Standard_Boolean bRunParallel, bNonDestructive;
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();
3510db62 486 bNonDestructive = BOPTest_Objects::NonDestructive();
4e57c75e 487 //
488e5b9d 488 Handle(NCollection_BaseAllocator)aAL=
489 NCollection_BaseAllocator::CommonBaseAllocator();
49b0c452 490 //
491 //---------------------------------------------------------------
4e57c75e 492 BOPAlgo_PaveFiller aPF(aAL);
493 //
494 aPF.SetArguments(aLC);
49b0c452 495 aPF.SetFuzzyValue(aTol);
496 aPF.SetRunParallel(bRunParallel);
3510db62 497 aPF.SetNonDestructive(bNonDestructive);
4e57c75e 498 //
499 aPF.Perform();
500 iErr=aPF.ErrorStatus();
501 if (iErr) {
502 Sprintf(buf, " ErrorStatus : %d\n", iErr);
503 di << buf;
504 return 0;
7fd59977 505 }
506 //
49b0c452 507 //---------------------------------------------------------------
508 BOPAlgo_BOP aBOP(aAL);
509 //
510 aBOP.AddArgument(aS1);
511 aBOP.AddTool(aS2);
512 aBOP.SetOperation(aOp);
513 aBOP.SetRunParallel(bRunParallel);
da219023 514 //
49b0c452 515 aBOP.PerformWithFiller(aPF);
4e57c75e 516 //
49b0c452 517 iErr=aBOP.ErrorStatus();
518 if (iErr) {
4e57c75e 519 Sprintf(buf, " ErrorStatus : %d\n", iErr);
520 di << buf;
521 return 0;
7fd59977 522 }
49b0c452 523 const TopoDS_Shape& aR=aBOP.Shape();
4e57c75e 524 if (aR.IsNull()) {
525 di << " null shape\n";
526 return 0;
7fd59977 527 }
49b0c452 528 //
4e57c75e 529 DBRep::Set(a[1], aR);
7fd59977 530 return 0;
531}
7fd59977 532//=======================================================================
4e57c75e 533//function : bopcurves
7fd59977 534//purpose :
535//=======================================================================
4e57c75e 536Standard_Integer bopcurves (Draw_Interpretor& di,
537 Standard_Integer n,
538 const char** a)
7fd59977 539{
4e57c75e 540 if (n<3) {
99c5f9f0 541 di << " use bopcurves F1 F2 [-2d/-2d1/-2d2]\n";
4e57c75e 542 return 1;
7fd59977 543 }
99c5f9f0 544 //
4e57c75e 545 TopoDS_Shape S1 = DBRep::Get(a[1]);
546 TopoDS_Shape S2 = DBRep::Get(a[2]);
547 TopAbs_ShapeEnum aType;
99c5f9f0 548 //
4e57c75e 549 if (S1.IsNull() || S2.IsNull()) {
550 di << " Null shapes is not allowed \n";
551 return 1;
7fd59977 552 }
99c5f9f0 553 //
4e57c75e 554 aType=S1.ShapeType();
555 if (aType != TopAbs_FACE) {
556 di << " Type mismatch F1\n";
557 return 1;
7fd59977 558 }
4e57c75e 559 aType=S2.ShapeType();
560 if (aType != TopAbs_FACE) {
561 di << " Type mismatch F2\n";
562 return 1;
7fd59977 563 }
99c5f9f0 564 //
4e57c75e 565 const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
566 const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
99c5f9f0 567 //
568 Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
d677b214 569 Standard_Integer aNbCurves, aNbPoints;
4e57c75e 570 Standard_Real anAppTol, aTolR;
47e3009d 571 IntSurf_ListOfPntOn2S aListOfPnts;
e9e644ed 572 TCollection_AsciiString aNm("c_"), aNp("p_");
99c5f9f0 573 //
574 anAppTol = 0.0000001;
575 aToApproxC3d = Standard_True;
576 aToApproxC2dOnS1 = Standard_False;
577 aToApproxC2dOnS2 = Standard_False;
47e3009d 578
99c5f9f0 579 //
47e3009d 580 for(Standard_Integer i = 3; i < n; i++)
581 {
582 if (!strcasecmp(a[i],"-2d")) {
99c5f9f0 583 aToApproxC2dOnS1 = Standard_True;
584 aToApproxC2dOnS2 = Standard_True;
585 }
47e3009d 586 else if (!strcasecmp(a[i],"-2d1")) {
99c5f9f0 587 aToApproxC2dOnS1 = Standard_True;
588 }
47e3009d 589 else if (!strcasecmp(a[i],"-2d2")) {
99c5f9f0 590 aToApproxC2dOnS2 = Standard_True;
591 }
47e3009d 592 else if (!strcasecmp(a[i],"-p")) {
593 IntSurf_PntOn2S aPt;
594 const Standard_Real aU1 = Draw::Atof(a[++i]);
595 const Standard_Real aV1 = Draw::Atof(a[++i]);
596 const Standard_Real aU2 = Draw::Atof(a[++i]);
597 const Standard_Real aV2 = Draw::Atof(a[++i]);
598
599 aPt.SetValue(aU1, aV1, aU2, aV2);
600 aListOfPnts.Append(aPt);
601 }
99c5f9f0 602 else {
47e3009d 603 di << "Wrong key. To build 2d curves use: bopcurves F1 F2 [-2d/-2d1/-2d2] [-p u1 v1 u2 v2]\n";
c2c2f2b6 604 return 1;
605 }
47e3009d 606
c2c2f2b6 607 }
47e3009d 608
c2c2f2b6 609 //
4e57c75e 610 IntTools_FaceFace aFF;
99c5f9f0 611 //
4e57c75e 612 aFF.SetParameters (aToApproxC3d,
613 aToApproxC2dOnS1,
614 aToApproxC2dOnS2,
615 anAppTol);
47e3009d 616 aFF.SetList(aListOfPnts);
99c5f9f0 617 //
4e57c75e 618 aFF.Perform (aF1, aF2);
99c5f9f0 619 //
4e57c75e 620 anIsDone=aFF.IsDone();
621 if (!anIsDone) {
d0820f2e 622 di << "Error: anIsDone=" << (Standard_Integer) anIsDone << "\n";
623 return 0;
7fd59977 624 }
99c5f9f0 625 //
c2c2f2b6 626 aFF.PrepareLines3D(Standard_False);
4e57c75e 627 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
e9e644ed 628 const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points();
4e57c75e 629 //
e9e644ed 630 aNbCurves = aSCs.Length();
631 aNbPoints = aSPs.Length();
632 if (!aNbCurves && !aNbPoints) {
633 di << " has no 3d curves\n";
634 di << " has no 3d points\n";
d0820f2e 635 return 0;
7fd59977 636 }
e9e644ed 637 //
638 aTolR=aFF.TolReached3d();
639 di << "Tolerance Reached=" << aTolR << "\n";
640 //
641 // curves
642 if (aNbCurves) {
c2c2f2b6 643 di << aNbCurves << " curve(s) found.\n";
e9e644ed 644 //
d677b214 645 for (Standard_Integer i=1; i<=aNbCurves; i++) {
e9e644ed 646 const IntTools_Curve& anIC=aSCs(i);
7fd59977 647
e9e644ed 648 Handle (Geom_Curve) aC3D = anIC.Curve();
7fd59977 649
e9e644ed 650 if (aC3D.IsNull()) {
651 di << " has Null 3d curve# " << i << "\n";
652 continue;
653 }
7fd59977 654
e9e644ed 655 TCollection_AsciiString anIndx(i), aNmx;
656 aNmx = aNm + anIndx;
c2c2f2b6 657
e9e644ed 658 Standard_CString nameC = aNmx.ToCString();
c2c2f2b6 659
e9e644ed 660 DrawTrSurf::Set(nameC, aC3D);
661 di << nameC << " ";
c2c2f2b6 662 //
e9e644ed 663 Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
664 Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
c2c2f2b6 665 //
e9e644ed 666 if (!aPC1.IsNull() || !aPC2.IsNull()) {
667 di << "(";
99c5f9f0 668 //
669 if (!aPC1.IsNull()) {
e9e644ed 670 TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
671 pc1Nx = pc1N + anIndx;
672 Standard_CString nameC2d1 = pc1Nx.ToCString();
673 //
674 DrawTrSurf::Set(nameC2d1, aPC1);
675 di << nameC2d1;
99c5f9f0 676 }
e9e644ed 677 //
678 if (!aPC2.IsNull()) {
679 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
680 pc2Nx = pc2N + anIndx;
681 Standard_CString nameC2d2 = pc2Nx.ToCString();
682 //
683 DrawTrSurf::Set(nameC2d2, aPC2);
684 //
685 if (!aPC1.IsNull()) {
686 di << ", ";
687 }
688 di << nameC2d2;
689 }
690 di << ") ";
c2c2f2b6 691 }
692 }
e9e644ed 693 di << "\n";
694 }
695 //
696 // points
697 if (aNbPoints) {
698 di << aNbPoints << " point(s) found.\n";
699 //
d677b214 700 for (Standard_Integer i = 1; i <= aNbPoints; i++) {
e9e644ed 701 const IntTools_PntOn2Faces& aPi = aSPs(i);
702 const gp_Pnt& aP = aPi.P1().Pnt();
703 //
704 TCollection_AsciiString anIndx(i), aNmx;
705 aNmx = aNp + anIndx;
706 Standard_CString nameP = aNmx.ToCString();
707 //
708 DrawTrSurf::Set(nameP, aP);
709 di << nameP << " ";
710 }
711 di << "\n";
7fd59977 712 }
99c5f9f0 713 //
4e57c75e 714 return 0;
7fd59977 715}
e322db46 716//=======================================================================
92ae0f2f 717//function : mkvolume
718//purpose :
719//=======================================================================
720Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a)
721{
92ae0f2f 722 if (n < 3) {
43cb0011 723 di << "Usage: mkvolume r b1 b2 ... [-c] [-ni]\n";
b1d15f53 724 di << "Options:\n";
725 di << " -c - use this option if the arguments are compounds\n";
726 di << " containing shapes that should be interfered;\n";
727 di << " -ni - use this option if the arguments should not be interfered;\n";
92ae0f2f 728 return 1;
729 }
730 //
b1d15f53 731 const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
732 //
3510db62 733 Standard_Boolean bToIntersect, bRunParallel, bNonDestructive, bCompounds;
b1d15f53 734 Standard_Integer i;
735 Standard_Real aTol;
736 TopoDS_Shape aS;
737 BOPCol_ListOfShape aLS;
92ae0f2f 738 //
49b0c452 739 aTol = BOPTest_Objects::FuzzyValue();
49b0c452 740 bRunParallel = BOPTest_Objects::RunParallel();
3510db62 741 bNonDestructive = BOPTest_Objects::NonDestructive();
43cb0011 742 //
743 bToIntersect = Standard_True;
b1d15f53 744 bCompounds = Standard_False;
92ae0f2f 745 //
b1d15f53 746 for (i = 2; i < n; ++i) {
92ae0f2f 747 aS = DBRep::Get(a[i]);
748 if (!aS.IsNull()) {
749 aLS.Append(aS);
750 }
b1d15f53 751 else {
752 if (!strcmp(a[i], "-c")) {
753 bCompounds = Standard_True;
754 }
755 else if (!strcmp(a[i], "-ni")) {
756 bToIntersect = Standard_False;
757 }
b1d15f53 758 }
92ae0f2f 759 }
760 //
761 if (aLS.IsEmpty()) {
b1d15f53 762 di << "No shapes to process.\n";
92ae0f2f 763 di << usage;
764 return 1;
765 }
766 //
b1d15f53 767 // treat list of arguments for the case of compounds
768 if (bToIntersect && bCompounds) {
769 BOPCol_ListOfShape aLSx;
770 BOPCol_ListIteratorOfListOfShape aItLS;
771 //
772 aItLS.Initialize(aLS);
773 for (; aItLS.More(); aItLS.Next()) {
774 const TopoDS_Shape& aSx = aItLS.Value();
775 TopoDS_Iterator aItS(aSx);
776 for (; aItS.More(); aItS.Next()) {
777 const TopoDS_Shape& aSxS = aItS.Value();
778 aLSx.Append(aSxS);
779 }
780 }
781 //
782 aLS.Clear();
783 aLS.Assign(aLSx);
784 }
785 //
92ae0f2f 786 BOPAlgo_MakerVolume aMV;
787 aMV.SetArguments(aLS);
788 aMV.SetIntersect(bToIntersect);
789 aMV.SetRunParallel(bRunParallel);
b1d15f53 790 aMV.SetFuzzyValue(aTol);
3510db62 791 aMV.SetNonDestructive(bNonDestructive);
92ae0f2f 792 //
793 aMV.Perform();
794 if (aMV.ErrorStatus()) {
795 di << "Error status: " << aMV.ErrorStatus();
796 return 1;
797 }
798 //
799 const TopoDS_Shape& aR = aMV.Shape();
800 //
801 DBRep::Set(a[1], aR);
802 //
803 return 0;
804}