0025084: Incorrect PCurve construction
[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
20#include <DBRep.hxx>
7fd59977 21
4e57c75e 22#include <NCollection_BaseAllocator.hxx>
23#include <NCollection_IncAllocator.hxx>
7fd59977 24
7fd59977 25#include <TopoDS_Shape.hxx>
4e57c75e 26#include <TopoDS_Compound.hxx>
7fd59977 27#include <BRep_Builder.hxx>
28
4e57c75e 29#include <BOPAlgo_PaveFiller.hxx>
30#include <BOPAlgo_Operation.hxx>
31#include <BOPAlgo_BOP.hxx>
92ae0f2f 32#include <BOPAlgo_MakerVolume.hxx>
4e57c75e 33#include <BOPDS_DS.hxx>
7fd59977 34#include <BOPTest_DrawableShape.hxx>
4e57c75e 35#include <BOPCol_ListOfShape.hxx>
7fd59977 36
4e57c75e 37#include <TCollection_AsciiString.hxx>
38#include <IntTools_FaceFace.hxx>
39#include <IntTools_Curve.hxx>
40#include <DrawTrSurf.hxx>
41#include <Draw_Color.hxx>
42#include <Draw.hxx>
da219023 43#include <BRepAlgoAPI_BooleanOperation.hxx>
44#include <BRepAlgoAPI_Common.hxx>
45#include <BRepAlgoAPI_Fuse.hxx>
46#include <BRepAlgoAPI_Cut.hxx>
47#include <BRepAlgoAPI_Section.hxx>
7fd59977 48
49//
4e57c75e 50static BOPAlgo_PaveFiller* pPF=NULL;
7fd59977 51//
7fd59977 52
4e57c75e 53static
54 Standard_Integer bopsmt(Draw_Interpretor& di,
55 Standard_Integer n,
56 const char** a,
57 const BOPAlgo_Operation aOp);
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**);
78static Standard_Integer bopnews (Draw_Interpretor&, Standard_Integer, const char**);
92ae0f2f 79//
80static Standard_Integer mkvolume (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 81
7fd59977 82//=======================================================================
83//function : BOPCommands
84//purpose :
85//=======================================================================
4e57c75e 86 void BOPTest::BOPCommands(Draw_Interpretor& theCommands)
7fd59977 87{
88 static Standard_Boolean done = Standard_False;
4e57c75e 89 if (done) return;
7fd59977 90 done = Standard_True;
91 // Chapter's name
4e57c75e 92 const char* g = "BOP commands";
93 // Commands
94
95 theCommands.Add("bop" , "use bop s1 s2" , __FILE__, bop, g);
96 theCommands.Add("bopcommon" , "use bopcommon r" , __FILE__, bopcommon, g);
97 theCommands.Add("bopfuse" , "use bopfuse r" , __FILE__,bopfuse, g);
98 theCommands.Add("bopcut" , "use bopcut" , __FILE__,bopcut, g);
99 theCommands.Add("boptuc" , "use boptuc" , __FILE__,boptuc, g);
100 theCommands.Add("bopsection", "use bopsection" , __FILE__,bopsection, g);
7fd59977 101 //
4e57c75e 102 theCommands.Add("bcommon" , "use bcommon r s1 s2" , __FILE__,bcommon, g);
103 theCommands.Add("bfuse" , "use bfuse r s1 s2" , __FILE__,bfuse, g);
104 theCommands.Add("bcut" , "use bcut r s1 s2" , __FILE__,bcut, g);
105 theCommands.Add("btuc" , "use btuc r s1 s2" , __FILE__,btuc, g);
106 theCommands.Add("bsection", "Use >bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]",
107 __FILE__, bsection, g);
7fd59977 108 //
c2c2f2b6 109 theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d]", __FILE__, bopcurves, g);
4e57c75e 110 theCommands.Add("bopnews", "use bopnews -v[e,f]" , __FILE__, bopnews, g);
92ae0f2f 111 //
112 theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-ni (do not intersect)] [-s (run in non parallel mode)]", __FILE__, mkvolume , g);
7fd59977 113}
4e57c75e 114
7fd59977 115//=======================================================================
116//function : bop
117//purpose :
118//=======================================================================
4e57c75e 119Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 120{
4e57c75e 121 char buf[32];
122 Standard_Integer iErr;
123 TopoDS_Shape aS1, aS2;
124 BOPCol_ListOfShape aLC;
125 //
126 if (n!=3) {
127 di << " use bop Shape1 Shape2\n";
7fd59977 128 return 1;
129 }
4e57c75e 130 //
131 aS1=DBRep::Get(a[1]);
132 aS2=DBRep::Get(a[2]);
133 //
134 if (aS1.IsNull() || aS2.IsNull()) {
135 di << " null shapes are not allowed \n";
7fd59977 136 return 1;
137 }
4e57c75e 138 //
139 aLC.Append(aS1);
140 aLC.Append(aS2);
141 //
5d05cf31 142 if (pPF!=NULL) {
4e57c75e 143 delete pPF;
5d05cf31 144 pPF=NULL;
7fd59977 145 }
5d05cf31 146 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
147 pPF=new BOPAlgo_PaveFiller(aAL);
4e57c75e 148 //
149 pPF->SetArguments(aLC);
150 //
151 pPF->Perform();
152 iErr=pPF->ErrorStatus();
153 if (iErr) {
154 Sprintf(buf, " ErrorStatus : %d\n", iErr);
155 di << buf;
156 return 0;
7fd59977 157 }
4e57c75e 158 //
7fd59977 159 return 0;
160}
7fd59977 161//=======================================================================
4e57c75e 162//function : bopcommon
7fd59977 163//purpose :
164//=======================================================================
4e57c75e 165Standard_Integer bopcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 166{
4e57c75e 167 return bopsmt(di, n, a, BOPAlgo_COMMON);
168}
169//=======================================================================
170//function : bopfuse
171//purpose :
172//=======================================================================
173Standard_Integer bopfuse(Draw_Interpretor& di, Standard_Integer n, const char** a)
174{
175 return bopsmt(di, n, a, BOPAlgo_FUSE);
176}
177//=======================================================================
178//function : bopcut
179//purpose :
180//=======================================================================
181Standard_Integer bopcut(Draw_Interpretor& di, Standard_Integer n, const char** a)
182{
183 return bopsmt(di, n, a, BOPAlgo_CUT);
184}
185//=======================================================================
186//function : boptuc
187//purpose :
188//=======================================================================
189Standard_Integer boptuc(Draw_Interpretor& di, Standard_Integer n, const char** a)
190{
191 return bopsmt(di, n, a, BOPAlgo_CUT21);
192}
193//=======================================================================
194//function : bopsection
195//purpose :
196//=======================================================================
197Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char** a)
198{
199 return bopsmt(di, n, a, BOPAlgo_SECTION);
200}
201//=======================================================================
202//function : bopsmt
203//purpose :
204//=======================================================================
205Standard_Integer bopsmt(Draw_Interpretor& di,
206 Standard_Integer n,
207 const char** a,
208 const BOPAlgo_Operation aOp)
209{
210 if (n<2) {
211 di << " use bopsmt r\n";
212 return 0;
7fd59977 213 }
4e57c75e 214 //
215 if (!pPF) {
216 di << " prepare PaveFiller first\n";
217 return 0;
218 }
219 //
220 if (pPF->ErrorStatus()) {
221 di << " PaveFiller has not been done\n";
222 return 0;
223 }
224 //
225 char buf[64];
226 Standard_Integer aNb, iErr;
227 BOPAlgo_BOP aBOP;
228 //
229 const BOPCol_ListOfShape& aLC=pPF->Arguments();
230 aNb=aLC.Extent();
231 if (aNb!=2) {
232 Sprintf (buf, " wrong number of arguments %s\n", aNb);
233 di << buf;
234 return 0;
235 }
236 //
237 const TopoDS_Shape& aS1=aLC.First();
238 const TopoDS_Shape& aS2=aLC.Last();
239 //
240 aBOP.AddArgument(aS1);
241 aBOP.AddTool(aS2);
242 aBOP.SetOperation(aOp);
243 //
244 aBOP.PerformWithFiller(*pPF);
245 iErr=aBOP.ErrorStatus();
246 if (iErr) {
247 Sprintf(buf, " ErrorStatus : %d\n", iErr);
248 di << buf;
249 return 0;
250 }
251 //
252 const TopoDS_Shape& aR=aBOP.Shape();
253 if (aR.IsNull()) {
254 di << " null shape\n";
255 return 0;
256 }
257 //
258 DBRep::Set(a[1], aR);
259 return 0;
7fd59977 260}
7fd59977 261//=======================================================================
262//function : bcommon
263//purpose :
264//=======================================================================
4e57c75e 265Standard_Integer bcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 266{
4e57c75e 267 return bsmt(di, n, a, BOPAlgo_COMMON);
7fd59977 268}
269//=======================================================================
270//function : bfuse
271//purpose :
272//=======================================================================
4e57c75e 273Standard_Integer bfuse (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 274{
4e57c75e 275 return bsmt(di, n, a, BOPAlgo_FUSE);
7fd59977 276}
7fd59977 277//=======================================================================
278//function : bcut
279//purpose :
280//=======================================================================
4e57c75e 281Standard_Integer bcut (Draw_Interpretor& di, Standard_Integer n, const char** a)
7fd59977 282{
4e57c75e 283 return bsmt(di, n, a, BOPAlgo_CUT);
284}
285//=======================================================================
286//function : btuc
287//purpose :
288//=======================================================================
289Standard_Integer btuc (Draw_Interpretor& di, Standard_Integer n, const char** a)
290{
291 return bsmt(di, n, a, BOPAlgo_CUT21);
7fd59977 292}
293//=======================================================================
294//function : bsection
295//purpose :
296//=======================================================================
297Standard_Integer bsection(Draw_Interpretor& di,
4e57c75e 298 Standard_Integer n,
299 const char** a)
7fd59977 300{
4e57c75e 301 const char* usage = " Usage: bsection Result s1 s2 [-n2d/-n2d1/-n2d2] [-na]\n";
7fd59977 302 if (n < 4) {
303 di << usage;
304 return 1;
305 }
306
4e57c75e 307 TopoDS_Shape aS1 = DBRep::Get(a[2]);
308 TopoDS_Shape aS2 = DBRep::Get(a[3]);
7fd59977 309
4e57c75e 310 if (aS1.IsNull() || aS2.IsNull()) {
7fd59977 311 di << " Null shapes are not allowed \n";
312 return 1;
313 }
314
da219023 315 Standard_Boolean bApp, bPC1, bPC2;
316 //
317 bApp = Standard_True;
318 bPC1 = Standard_True;
319 bPC2 = Standard_True;
320
7fd59977 321 Standard_Boolean isbadparameter = Standard_False;
322
323 if(n > 4) {
324 const char* key1 = a[4];
325 const char* key2 = (n > 5) ? a[5] : NULL;
326 const char* pcurveconf = NULL;
7fd59977 327
4e57c75e 328 if (key1 && (!strcasecmp(key1,"-n2d") || !strcasecmp(key1,"-n2d1") || !strcasecmp(key1,"-n2d2"))) {
7fd59977 329 pcurveconf = key1;
330 }
331 else {
4e57c75e 332 if (!strcasecmp(key1,"-na")) {
da219023 333 bApp = Standard_False;
7fd59977 334 }
335 else {
4e57c75e 336 isbadparameter = Standard_True;
7fd59977 337 }
338 }
4e57c75e 339 if (key2) {
4e57c75e 340 if(!strcasecmp(key2,"-na")) {
da219023 341 bApp = Standard_False;
7fd59977 342 }
343 else {
4e57c75e 344 isbadparameter = Standard_True;
7fd59977 345 }
346 }
7fd59977 347
4e57c75e 348 if(!isbadparameter && pcurveconf) {
4e57c75e 349 if (!strcasecmp(pcurveconf, "-n2d1")) {
da219023 350 bPC1 = Standard_False;
7fd59977 351 }
352 else {
4e57c75e 353 if (!strcasecmp(pcurveconf, "-n2d2")) {
da219023 354 bPC2 = Standard_False;
4e57c75e 355 }
356 else {
4e57c75e 357 if (!strcasecmp(pcurveconf, "-n2d")) {
da219023 358 bPC1 = Standard_False;
359 bPC2 = Standard_False;
4e57c75e 360 }
361 }
7fd59977 362 }
363 }
7fd59977 364 }
365
da219023 366 if(!isbadparameter) {
4e57c75e 367 Standard_Integer iErr;
368 char buf[80];
369 //
da219023 370 BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False);
371 aSec.Approximation(bApp);
372 aSec.ComputePCurveOn1(bPC1);
373 aSec.ComputePCurveOn2(bPC2);
4e57c75e 374 //
da219023 375 aSec.Build();
376 iErr=aSec.ErrorStatus();
377 if (!aSec.IsDone()) {
4e57c75e 378 Sprintf(buf, " ErrorStatus : %d\n", iErr);
379 di << buf;
380 return 0;
7fd59977 381 }
4e57c75e 382 //
da219023 383 const TopoDS_Shape& aR=aSec.Shape();
4e57c75e 384 if (aR.IsNull()) {
385 di << " null shape\n";
386 return 0;
387 }
388 DBRep::Set(a[1], aR);
389 return 0;
7fd59977 390 }
391 else {
392 di << usage;
393 return 1;
394 }
7fd59977 395}
7fd59977 396//=======================================================================
4e57c75e 397//function : bsmt
7fd59977 398//purpose :
399//=======================================================================
4e57c75e 400Standard_Integer bsmt (Draw_Interpretor& di,
401 Standard_Integer n,
402 const char** a,
403 const BOPAlgo_Operation aOp)
7fd59977 404{
4e57c75e 405 char buf[32];
406 Standard_Integer iErr;
407 TopoDS_Shape aS1, aS2;
408 BOPCol_ListOfShape aLC;
409 //
da219023 410 if (n!=4) {
4e57c75e 411 di << " use bx r s1 s2\n";
7fd59977 412 return 1;
413 }
4e57c75e 414 //
415 aS1=DBRep::Get(a[2]);
416 aS2=DBRep::Get(a[3]);
417 //
418 if (aS1.IsNull() || aS2.IsNull()) {
419 di << " null shapes are not allowed \n";
7fd59977 420 return 1;
421 }
4e57c75e 422 aLC.Append(aS1);
423 aLC.Append(aS2);
424 //
425 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
426 BOPAlgo_PaveFiller aPF(aAL);
427 //
428 aPF.SetArguments(aLC);
429 //
430 aPF.Perform();
431 iErr=aPF.ErrorStatus();
432 if (iErr) {
433 Sprintf(buf, " ErrorStatus : %d\n", iErr);
434 di << buf;
435 return 0;
7fd59977 436 }
437 //
da219023 438 BRepAlgoAPI_BooleanOperation* pBuilder=NULL;
439 //
440 if (aOp==BOPAlgo_COMMON) {
441 pBuilder=new BRepAlgoAPI_Common(aS1, aS2, aPF);
442 }
443 else if (aOp==BOPAlgo_FUSE) {
444 pBuilder=new BRepAlgoAPI_Fuse(aS1, aS2, aPF);
445 }
446 else if (aOp==BOPAlgo_CUT) {
447 pBuilder=new BRepAlgoAPI_Cut (aS1, aS2, aPF);
448 }
449 else if (aOp==BOPAlgo_CUT21) {
450 pBuilder=new BRepAlgoAPI_Cut(aS1, aS2, aPF, Standard_False);
451 }
4e57c75e 452 //
da219023 453 iErr = pBuilder->ErrorStatus();
454 if (!pBuilder->IsDone()) {
4e57c75e 455 Sprintf(buf, " ErrorStatus : %d\n", iErr);
456 di << buf;
457 return 0;
7fd59977 458 }
da219023 459 const TopoDS_Shape& aR=pBuilder->Shape();
4e57c75e 460 if (aR.IsNull()) {
461 di << " null shape\n";
462 return 0;
7fd59977 463 }
4e57c75e 464 DBRep::Set(a[1], aR);
7fd59977 465 return 0;
466}
467
468//=======================================================================
4e57c75e 469//function : bopnews
7fd59977 470//purpose :
471//=======================================================================
4e57c75e 472Standard_Integer bopnews (Draw_Interpretor& di,
473 Standard_Integer n,
474 const char** a)
7fd59977 475{
4e57c75e 476 if (n!=2) {
477 di << " use bopnews -v[e,f]\n";
478 return 0;
7fd59977 479 }
4e57c75e 480 //
481 if (pPF==NULL) {
482 di << " Prepare BOPAlgo_PaveFiller first >bop S1 S2\n";
7fd59977 483 return 0;
484 }
4e57c75e 485 //
486 char buf[32];
487 Standard_CString aText;
488 Standard_Integer i, i1, i2, iFound;
7fd59977 489 Draw_Color aTextColor(Draw_cyan);
4e57c75e 490 TopAbs_ShapeEnum aT;
491 Handle(BOPTest_DrawableShape) aDShape;
7fd59977 492 //
4e57c75e 493 const BOPDS_PDS& pDS=pPF->PDS();
7fd59977 494 //
4e57c75e 495 aT=TopAbs_SHAPE;
496 if (!strcmp (a[1], "-f")) {
497 aT=TopAbs_FACE;
7fd59977 498 }
4e57c75e 499 else if (!strcmp (a[1], "-e")){
500 aT=TopAbs_EDGE;
7fd59977 501 }
4e57c75e 502 else if (!strcmp (a[1], "-v")){
503 aT=TopAbs_VERTEX;
7fd59977 504 }
4e57c75e 505 else {
506 di << " use bopnews -v[e,f]\n";
507 return 0;
7fd59977 508 }
509 //
4e57c75e 510 iFound=0;
511 i1=pDS->NbSourceShapes();
512 i2=pDS->NbShapes();
513 for (i=i1; i<i2; ++i) {
514 const BOPDS_ShapeInfo& aSI=pDS->ShapeInfo(i);
515 if (aSI.ShapeType()==aT) {
516 const TopoDS_Shape& aS=aSI.Shape();
517 //
518 Sprintf (buf, "z%d", i);
519 aText=buf;
520 aDShape=new BOPTest_DrawableShape (aS, aText, aTextColor);
7fd59977 521 Draw::Set (aText, aDShape);
4e57c75e 522 //
523 Sprintf (buf, " z%d", i);
524 di << buf;
525 //
526 iFound=1;
7fd59977 527 }
528 }
4e57c75e 529 //
530 if (iFound) {
7fd59977 531 di << "\n";
532 }
7fd59977 533 else {
4e57c75e 534 di << " not found\n";
7fd59977 535 }
7fd59977 536 //
7fd59977 537 return 0;
538}
539
7fd59977 540//=======================================================================
4e57c75e 541//function : bopcurves
7fd59977 542//purpose :
543//=======================================================================
4e57c75e 544Standard_Integer bopcurves (Draw_Interpretor& di,
545 Standard_Integer n,
546 const char** a)
7fd59977 547{
4e57c75e 548 if (n<3) {
c2c2f2b6 549 di << " use bopcurves F1 F2 [-2d]\n";
4e57c75e 550 return 1;
7fd59977 551 }
552
4e57c75e 553 TopoDS_Shape S1 = DBRep::Get(a[1]);
554 TopoDS_Shape S2 = DBRep::Get(a[2]);
555 TopAbs_ShapeEnum aType;
7fd59977 556
4e57c75e 557 if (S1.IsNull() || S2.IsNull()) {
558 di << " Null shapes is not allowed \n";
559 return 1;
7fd59977 560 }
7fd59977 561
4e57c75e 562 aType=S1.ShapeType();
563 if (aType != TopAbs_FACE) {
564 di << " Type mismatch F1\n";
565 return 1;
7fd59977 566 }
4e57c75e 567 aType=S2.ShapeType();
568 if (aType != TopAbs_FACE) {
569 di << " Type mismatch F2\n";
570 return 1;
7fd59977 571 }
572
7fd59977 573
4e57c75e 574 const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
575 const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
7fd59977 576
c2c2f2b6 577 Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone, bMake2dCurves;
4e57c75e 578 Standard_Integer i, aNbCurves;
579 Standard_Real anAppTol, aTolR;
580 TCollection_AsciiString aNm("c_");
7fd59977 581
c2c2f2b6 582 bMake2dCurves = Standard_False;
583 if (n > 3) {
584 if (!strcasecmp(a[3],"-2d")) {
585 bMake2dCurves = Standard_True;
586 } else {
587 di << "Wrong key. To build 2d curves use: bopcurves F1 F2 -2d \n";
588 return 1;
589 }
590 }
591 //
592
593 aToApproxC3d = Standard_True;
594 aToApproxC2dOnS1 = bMake2dCurves;
595 aToApproxC2dOnS2 = bMake2dCurves;
4e57c75e 596 anAppTol=0.0000001;
7fd59977 597
7fd59977 598
4e57c75e 599 IntTools_FaceFace aFF;
7fd59977 600
4e57c75e 601 aFF.SetParameters (aToApproxC3d,
602 aToApproxC2dOnS1,
603 aToApproxC2dOnS2,
604 anAppTol);
7fd59977 605
4e57c75e 606 aFF.Perform (aF1, aF2);
7fd59977 607
4e57c75e 608 anIsDone=aFF.IsDone();
609 if (!anIsDone) {
610 di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
611 return 1;
7fd59977 612 }
613
c2c2f2b6 614 aFF.PrepareLines3D(Standard_False);
4e57c75e 615 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
7fd59977 616
4e57c75e 617 //
618 aTolR=aFF.TolReached3d();
619 di << "Tolerance Reached=" << aTolR << "\n";
7fd59977 620
4e57c75e 621 aNbCurves=aSCs.Length();
622 if (!aNbCurves) {
623 di << " has no 3d curve\n";
624 return 1;
7fd59977 625 }
c2c2f2b6 626 else
627 {
628 di << aNbCurves << " curve(s) found.\n";
629 }
7fd59977 630
4e57c75e 631 for (i=1; i<=aNbCurves; i++) {
632 const IntTools_Curve& anIC=aSCs(i);
7fd59977 633
c2c2f2b6 634 Handle (Geom_Curve) aC3D = anIC.Curve();
7fd59977 635
4e57c75e 636 if (aC3D.IsNull()) {
c2c2f2b6 637 di << " has Null 3d curve# " << i << "\n";
4e57c75e 638 continue;
7fd59977 639 }
7fd59977 640
4e57c75e 641 TCollection_AsciiString anIndx(i), aNmx;
c2c2f2b6 642 aNmx = aNm + anIndx;
643
644 Standard_CString nameC = aNmx.ToCString();
645
646 DrawTrSurf::Set(nameC, aC3D);
647 di << nameC << " ";
648 //
649 if (bMake2dCurves) {
650 Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
651 Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
652 //
653 if (aPC1.IsNull() && aPC2.IsNull()) {
654 di << " \n has Null 2d curves# " << i << "\n";
655 continue;
656 }
657 //
658 if (aPC1.IsNull()) {
659 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
660 pc2Nx = pc2N + anIndx;
661 Standard_CString nameC2d2 = pc2Nx.ToCString();
662 //
663 DrawTrSurf::Set(nameC2d2, aPC2);
664 di << "(" << nameC2d2 << ") ";
665 di << " \n Null first 2d curve of the curve #" << i << "\n";
666 continue;
667 } else {
668 TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
669 pc1Nx = pc1N + anIndx;
670 Standard_CString nameC2d1 = pc1Nx.ToCString();
671 //
672 DrawTrSurf::Set(nameC2d1, aPC1);
673 di << "(" << nameC2d1;
674 }
675 //
676 if (aPC2.IsNull()) {
677 di << ") \n Null second 2d curve of the curve #" << i << "\n";
678 continue;
679 } else {
680 TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
681 pc2Nx = pc2N + anIndx;
682 Standard_CString nameC2d2 = pc2Nx.ToCString();
683 //
684 DrawTrSurf::Set(nameC2d2, aPC2);
685 di << ", " << nameC2d2 << ") ";
686 }
687 }
7fd59977 688 }
7fd59977 689
7fd59977 690 di << "\n";
7fd59977 691
4e57c75e 692 return 0;
7fd59977 693}
92ae0f2f 694
695//=======================================================================
696//function : mkvolume
697//purpose :
698//=======================================================================
699Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a)
700{
701 const char* usage = "Usage: mkvolume r b1 b2 ... [-ni (do not intersect)] [-s (run in non parallel mode)]\n";
702 if (n < 3) {
703 di << usage;
704 return 1;
705 }
706 //
707 Standard_Boolean bToIntersect, bRunParallel;
708 Standard_Integer i, aNb;
709 //
710 aNb = n;
711 bToIntersect = Standard_True;
712 bRunParallel = Standard_True;
713 //
714 if (!strcmp(a[n-1], "-ni")) {
715 bToIntersect = Standard_False;
716 aNb = n-1;
717 }
718 else if (!strcmp(a[n-1], "-s")) {
719 bRunParallel = Standard_False;
720 aNb = n-1;
721 }
722 if (n > 3) {
723 if (!strcmp(a[n-2], "-ni")) {
724 bToIntersect = Standard_False;
725 aNb = n-2;
726 }
727 else if (!strcmp(a[n-2], "-s")) {
728 bRunParallel = Standard_False;
729 aNb = n-2;
730 }
731 }
732 //
733 if (aNb < 3) {
734 di << "no shapes to process.\n";
735 di << usage;
736 return 1;
737 }
738 //
739 BOPCol_ListOfShape aLS;
740 TopoDS_Shape aS;
741 for (i = 2; i < aNb; ++i) {
742 aS = DBRep::Get(a[i]);
743 if (!aS.IsNull()) {
744 aLS.Append(aS);
745 }
746 }
747 //
748 if (aLS.IsEmpty()) {
749 di << "no shapes to process.\n";
750 di << usage;
751 return 1;
752 }
753 //
754 BOPAlgo_MakerVolume aMV;
755 aMV.SetArguments(aLS);
756 aMV.SetIntersect(bToIntersect);
757 aMV.SetRunParallel(bRunParallel);
758 //
759 aMV.Perform();
760 if (aMV.ErrorStatus()) {
761 di << "Error status: " << aMV.ErrorStatus();
762 return 1;
763 }
764 //
765 const TopoDS_Shape& aR = aMV.Shape();
766 //
767 DBRep::Set(a[1], aR);
768 //
769 return 0;
770}
771