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