0026365: Optimization of work of OSD_Parallel class members for GeomLib_CheckCurveOnS...
[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
17 #include <BOPAlgo_BOP.hxx>
18 #include <BOPAlgo_MakerVolume.hxx>
19 #include <BOPAlgo_Operation.hxx>
20 #include <BOPAlgo_PaveFiller.hxx>
21 #include <BOPAlgo_Section.hxx>
22 #include <BOPDS_DS.hxx>
23 #include <BOPTest.hxx>
24 #include <BOPTest_Objects.hxx>
25 #include <BRep_Builder.hxx>
26 #include <BRepAlgoAPI_BooleanOperation.hxx>
27 #include <BRepAlgoAPI_Common.hxx>
28 #include <BRepAlgoAPI_Cut.hxx>
29 #include <BRepAlgoAPI_Fuse.hxx>
30 #include <BRepAlgoAPI_Section.hxx>
31 #include <BRepTest_Objects.hxx>
32 #include <DBRep.hxx>
33 #include <Draw.hxx>
34 #include <DrawTrSurf.hxx>
35 #include <Geom2d_Curve.hxx>
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>
41 #include <TCollection_AsciiString.hxx>
42 #include <TopoDS_Compound.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopTools_ListOfShape.hxx>
46
47 #include <stdio.h>
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 //
59 static
60   Standard_Integer bsmt (Draw_Interpretor& di, 
61                        Standard_Integer n, 
62                        const char** a,
63                        const BOPAlgo_Operation aOp);
64 //
65 static Standard_Integer bop       (Draw_Interpretor&, Standard_Integer, const char**);
66 static Standard_Integer bopsection(Draw_Interpretor&, Standard_Integer, const char**);
67 static Standard_Integer boptuc    (Draw_Interpretor&, Standard_Integer, const char**);
68 static Standard_Integer bopcut    (Draw_Interpretor&, Standard_Integer, const char**);
69 static Standard_Integer bopfuse   (Draw_Interpretor&, Standard_Integer, const char**);
70 static Standard_Integer bopcommon (Draw_Interpretor&, Standard_Integer, const char**);
71 //
72 static Standard_Integer bsection  (Draw_Interpretor&, Standard_Integer, const char**);
73 static Standard_Integer btuc      (Draw_Interpretor&, Standard_Integer, const char**);
74 static Standard_Integer bcut      (Draw_Interpretor&, Standard_Integer, const char**);
75 static Standard_Integer bfuse     (Draw_Interpretor&, Standard_Integer, const char**);
76 static Standard_Integer bcommon   (Draw_Interpretor&, Standard_Integer, const char**);
77 //
78 static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char**);
79 static Standard_Integer mkvolume   (Draw_Interpretor&, Standard_Integer, const char**);
80
81 //=======================================================================
82 //function : BOPCommands
83 //purpose  : 
84 //=======================================================================
85   void BOPTest::BOPCommands(Draw_Interpretor& theCommands)
86 {
87   static Standard_Boolean done = Standard_False;
88   if (done) return;
89   done = Standard_True;
90   // Chapter's name
91   const char* g = "BOPTest commands";
92   // Commands
93   
94   theCommands.Add("bop"       , "use bop s1 s2" , __FILE__, bop, g);
95   theCommands.Add("bopcommon" , "use bopcommon r"     , __FILE__, bopcommon, g);
96   theCommands.Add("bopfuse"   , "use bopfuse r"       , __FILE__,bopfuse, g);
97   theCommands.Add("bopcut"    , "use bopcut r"        , __FILE__,bopcut, g);
98   theCommands.Add("boptuc"    , "use boptuc r"        , __FILE__,boptuc, g);
99   theCommands.Add("bopsection", "use bopsection r"    , __FILE__,bopsection, g);
100   //
101   theCommands.Add("bcommon" , "use bcommon r s1 s2" , __FILE__,bcommon, g);
102   theCommands.Add("bfuse"   , "use bfuse r s1 s2"   , __FILE__,bfuse, g);
103   theCommands.Add("bcut"    , "use bcut r s1 s2"    , __FILE__,bcut, g);
104   theCommands.Add("btuc"    , "use btuc r s1 s2"    , __FILE__,btuc, g);
105   theCommands.Add("bsection", "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]"
106                                "Builds section between shapes. Options:\n"
107                                "-n2d/-n2d1/-n2d2 - disable the PCurve construction;\n"
108                                "-na - disables the approximation of the section curves.\n",
109                                                       __FILE__, bsection, g);
110   //
111   theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d/-2d1/-2d2] "
112                                "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]",
113                                                       __FILE__, bopcurves, g);
114   theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni] [-ai]",
115                   __FILE__, mkvolume , g);
116 }
117
118 //=======================================================================
119 //function : bop
120 //purpose  : 
121 //=======================================================================
122 Standard_Integer bop(Draw_Interpretor& di, 
123                      Standard_Integer n, 
124                      const char** a)
125 {
126   Standard_Boolean bRunParallel, bNonDestructive;
127   Standard_Real aTol;
128   TopoDS_Shape aS1, aS2;
129   TopTools_ListOfShape aLC;
130   //
131   if (n != 3) {
132     di << " use bop s1 s2 \n";
133     return 0;
134   }
135   //
136   aS1=DBRep::Get(a[1]);
137   aS2=DBRep::Get(a[2]);
138   //
139   if (aS1.IsNull() || aS2.IsNull()) {
140     di << " null shapes are not allowed \n";
141     return 0;
142   }
143   //
144   aTol=BOPTest_Objects::FuzzyValue();
145   bRunParallel=BOPTest_Objects::RunParallel();
146   bNonDestructive = BOPTest_Objects::NonDestructive();
147   BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
148   //
149   aLC.Append(aS1);
150   aLC.Append(aS2);
151   //
152   if (pPF!=NULL) {
153     delete pPF;
154     pPF=NULL;
155   }
156   Handle(NCollection_BaseAllocator)aAL=
157     NCollection_BaseAllocator::CommonBaseAllocator();
158   pPF=new BOPAlgo_PaveFiller(aAL);
159   //
160   pPF->SetArguments(aLC);
161   pPF->SetFuzzyValue(aTol);
162   pPF->SetRunParallel(bRunParallel);
163   pPF->SetNonDestructive(bNonDestructive);
164   pPF->SetGlue(aGlue);
165   pPF->SetUseOBB(BOPTest_Objects::UseOBB());
166   //
167   pPF->Perform();
168   BOPTest::ReportAlerts(pPF->GetReport());
169   //
170   return 0;
171 }
172 //=======================================================================
173 //function : bopcommon
174 //purpose  : 
175 //=======================================================================
176 Standard_Integer bopcommon (Draw_Interpretor& di, 
177                             Standard_Integer n, 
178                             const char** a)
179 {
180   return bopsmt(di, n, a, BOPAlgo_COMMON);
181 }
182 //=======================================================================
183 //function : bopfuse
184 //purpose  : 
185 //=======================================================================
186 Standard_Integer bopfuse(Draw_Interpretor& di, 
187                          Standard_Integer n, 
188                          const char** a)
189 {
190   return bopsmt(di, n, a, BOPAlgo_FUSE);
191 }
192 //=======================================================================
193 //function : bopcut
194 //purpose  : 
195 //=======================================================================
196 Standard_Integer bopcut(Draw_Interpretor& di, 
197                         Standard_Integer n, 
198                         const char** a)
199 {
200   return bopsmt(di, n, a, BOPAlgo_CUT);
201 }
202 //=======================================================================
203 //function : boptuc
204 //purpose  : 
205 //=======================================================================
206 Standard_Integer boptuc(Draw_Interpretor& di, 
207                         Standard_Integer n, 
208                         const char** a)
209 {
210   return bopsmt(di, n, a, BOPAlgo_CUT21);
211 }
212 //=======================================================================
213 //function : bopsmt
214 //purpose  : 
215 //=======================================================================
216 Standard_Integer bopsmt(Draw_Interpretor& di,
217                         Standard_Integer n,
218                         const char** a,
219                         const BOPAlgo_Operation aOp)
220 {
221   if (n<2) {
222     di << " use bopsmt r\n";
223     return 0;
224   }
225   //
226   if (!pPF) {
227     di << " prepare PaveFiller first\n";
228     return 0;
229   }
230   //
231   if (pPF->HasErrors()) {
232     di << " PaveFiller has not been done\n";
233     return 0;
234   }
235   //
236   char buf[64];
237   Standard_Boolean bRunParallel;
238   Standard_Integer aNb;
239   BOPAlgo_BOP aBOP;
240   //
241   const TopTools_ListOfShape& aLC=pPF->Arguments();
242   aNb=aLC.Extent();
243   if (aNb!=2) {
244     Sprintf (buf, " wrong number of arguments %s\n", aNb);
245     di << buf;
246     return 0;
247   }
248   // 
249   bRunParallel=BOPTest_Objects::RunParallel();
250   //
251   const TopoDS_Shape& aS1=aLC.First();
252   const TopoDS_Shape& aS2=aLC.Last();
253   //
254   aBOP.AddArgument(aS1);
255   aBOP.AddTool(aS2);
256   aBOP.SetOperation(aOp);
257   aBOP.SetRunParallel (bRunParallel);
258   aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
259   aBOP.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
260   //
261   aBOP.PerformWithFiller(*pPF);
262   BOPTest::ReportAlerts(aBOP.GetReport());
263
264   // Store the history of Boolean operation into the session
265   if (BRepTest_Objects::IsHistoryNeeded())
266     BRepTest_Objects::SetHistory(aBOP.History());
267
268   if (aBOP.HasErrors()) {
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;
280 }
281 //=======================================================================
282 //function : bopsection
283 //purpose  : 
284 //=======================================================================
285 Standard_Integer bopsection(Draw_Interpretor& di, 
286                             Standard_Integer n, 
287                             const char** a)
288 {
289   if (n<2) {
290     di << " use bopsection r\n";
291     return 0;
292   }
293   //
294   if (!pPF) {
295     di << " prepare PaveFiller first\n";
296     return 0;
297   }
298   //
299   if (pPF->HasErrors()) {
300     di << " PaveFiller has not been done\n";
301     return 0;
302   }
303   //
304   char buf[64];
305   Standard_Boolean bRunParallel;
306   Standard_Integer aNb;
307   BOPAlgo_Section aBOP;
308   //
309   const TopTools_ListOfShape& aLC=pPF->Arguments();
310   aNb=aLC.Extent();
311   if (aNb!=2) {
312     Sprintf (buf, " wrong number of arguments %s\n", aNb);
313     di << buf;
314     return 0;
315   }
316   //
317   bRunParallel=BOPTest_Objects::RunParallel();
318   //
319   const TopoDS_Shape& aS1=aLC.First();
320   const TopoDS_Shape& aS2=aLC.Last();
321   //
322   aBOP.AddArgument(aS1);
323   aBOP.AddArgument(aS2);
324   aBOP.SetRunParallel (bRunParallel);
325   aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
326   aBOP.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
327   //
328   aBOP.PerformWithFiller(*pPF);
329   BOPTest::ReportAlerts(aBOP.GetReport());
330
331   // Store the history of Section operation into the session
332   if (BRepTest_Objects::IsHistoryNeeded())
333     BRepTest_Objects::SetHistory(aBOP.History());
334
335   if (aBOP.HasErrors()) {
336     return 0;
337   }
338   //
339   const TopoDS_Shape& aR=aBOP.Shape();
340   if (aR.IsNull()) {
341     di << " null shape\n";
342     return 0;
343   }
344   //
345   DBRep::Set(a[1], aR);
346   return 0;
347 }
348 //=======================================================================
349 //function : bcommon
350 //purpose  : 
351 //=======================================================================
352 Standard_Integer bcommon (Draw_Interpretor& di, 
353                           Standard_Integer n, 
354                           const char** a)
355 {
356   return bsmt(di, n, a, BOPAlgo_COMMON);
357 }
358 //=======================================================================
359 //function : bfuse
360 //purpose  : 
361 //=======================================================================
362 Standard_Integer bfuse (Draw_Interpretor& di, 
363                         Standard_Integer n, 
364                         const char** a)
365 {
366   return bsmt(di, n, a, BOPAlgo_FUSE);
367 }
368 //=======================================================================
369 //function : bcut
370 //purpose  : 
371 //=======================================================================
372 Standard_Integer bcut (Draw_Interpretor& di, 
373                        Standard_Integer n, 
374                        const char** a)
375 {
376   return bsmt(di, n, a, BOPAlgo_CUT);
377 }
378 //=======================================================================
379 //function : btuc
380 //purpose  : 
381 //=======================================================================
382 Standard_Integer btuc (Draw_Interpretor& di, 
383                        Standard_Integer n, 
384                        const char** a)
385 {
386   return bsmt(di, n, a, BOPAlgo_CUT21);
387 }
388 //=======================================================================
389 //function : bsection
390 //purpose  : 
391 //=======================================================================
392 Standard_Integer  bsection(Draw_Interpretor& di, 
393                            Standard_Integer n, 
394                            const char** a)
395 {
396   if (n < 4) {
397     di << "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]\n";
398     return 0;
399   }
400   //
401   TopoDS_Shape aS1, aS2;
402   //
403   aS1=DBRep::Get(a[2]);
404   aS2=DBRep::Get(a[3]);
405   if (aS1.IsNull() || aS2.IsNull()) {
406     di << " Null shapes are not allowed \n";
407     return 0;
408   }
409   // 
410   Standard_Boolean bRunParallel, bNonDestructive, bApp, bPC1, bPC2;
411   Standard_Real aTol;
412   //
413   bApp = Standard_True;
414   bPC1 = Standard_True;
415   bPC2 = Standard_True;
416   aTol = BOPTest_Objects::FuzzyValue(); 
417   bRunParallel = BOPTest_Objects::RunParallel();
418   bNonDestructive = BOPTest_Objects::NonDestructive();
419   BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
420   //
421   for (Standard_Integer i = 4; i < n; ++i) {
422     if (!strcmp(a[i], "-n2d")) {
423       bPC1 = Standard_False;
424       bPC2 = Standard_False;
425     }
426     else if (!strcmp(a[i], "-n2d1")) {
427       bPC1 = Standard_False;
428     }
429     else if (!strcmp(a[i], "-n2d2")) {
430       bPC2 = Standard_False;
431     }
432     else if (!strcmp(a[i], "-na")) {
433       bApp = Standard_False;
434     }
435   }
436   //
437   BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False);
438   //
439   aSec.Approximation(bApp);
440   aSec.ComputePCurveOn1(bPC1);
441   aSec.ComputePCurveOn2(bPC2);
442   //
443   aSec.SetFuzzyValue(aTol);
444   aSec.SetRunParallel(bRunParallel);
445   aSec.SetNonDestructive(bNonDestructive);
446   aSec.SetGlue(aGlue);
447   aSec.SetUseOBB(BOPTest_Objects::UseOBB());
448   //
449   aSec.Build();
450
451   // Store the history of Section operation into the session
452   if (BRepTest_Objects::IsHistoryNeeded())
453     BRepTest_Objects::SetHistory(aSec.History());
454
455   //
456   if (aSec.HasWarnings()) {
457     Standard_SStream aSStream;
458     aSec.DumpWarnings(aSStream);
459     di << aSStream;
460   }
461   //
462   if (!aSec.IsDone()) {
463     Standard_SStream aSStream;
464     aSec.DumpErrors(aSStream);
465     di << aSStream;
466     return 0;
467   }
468   //
469   const TopoDS_Shape& aR=aSec.Shape();
470   if (aR.IsNull()) {
471     di << " null shape\n";
472     return 0;
473   }
474   DBRep::Set(a[1], aR);
475   return 0;
476 }
477 //=======================================================================
478 //function : bsmt
479 //purpose  : 
480 //=======================================================================
481 Standard_Integer bsmt (Draw_Interpretor& di, 
482                        Standard_Integer n, 
483                        const char** a,
484                        const BOPAlgo_Operation aOp)
485 {
486   Standard_Boolean bRunParallel, bNonDestructive;
487   TopoDS_Shape aS1, aS2;
488   TopTools_ListOfShape aLC;
489   Standard_Real aTol;
490   //
491   if (n != 4) {
492     di << " use bx r s1 s2\n";
493     return 0;
494   }
495   //
496   aS1=DBRep::Get(a[2]);
497   aS2=DBRep::Get(a[3]);
498   //
499   if (aS1.IsNull() || aS2.IsNull()) {
500     di << " null shapes are not allowed \n";
501     return 0;
502   }
503   aLC.Append(aS1);
504   aLC.Append(aS2);
505   // 
506   aTol=BOPTest_Objects::FuzzyValue();
507   bRunParallel = BOPTest_Objects::RunParallel();
508   bNonDestructive = BOPTest_Objects::NonDestructive();
509   BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
510   //
511   Handle(NCollection_BaseAllocator)aAL=
512     NCollection_BaseAllocator::CommonBaseAllocator();
513   //
514   //---------------------------------------------------------------
515   BOPAlgo_PaveFiller aPF(aAL);
516   //
517   aPF.SetArguments(aLC);
518   aPF.SetFuzzyValue(aTol); 
519   aPF.SetRunParallel(bRunParallel);
520   aPF.SetNonDestructive(bNonDestructive);
521   aPF.SetGlue(aGlue);
522   aPF.SetUseOBB(BOPTest_Objects::UseOBB());
523   //
524   aPF.Perform();
525   BOPTest::ReportAlerts(aPF.GetReport());
526   if (aPF.HasErrors()) {
527     return 0;
528   }
529   //
530   //---------------------------------------------------------------
531   BOPAlgo_BOP aBOP(aAL);
532   //
533   aBOP.AddArgument(aS1);
534   aBOP.AddTool(aS2);
535   aBOP.SetOperation(aOp);
536   aBOP.SetRunParallel(bRunParallel);
537   aBOP.SetCheckInverted(BOPTest_Objects::CheckInverted());
538   aBOP.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
539   //
540   aBOP.PerformWithFiller(aPF);
541   BOPTest::ReportAlerts(aBOP.GetReport());
542
543   // Store the history of Boolean operation into the session
544   if (BRepTest_Objects::IsHistoryNeeded())
545     BRepTest_Objects::SetHistory(aPF.Arguments(), aBOP);
546
547   if (aBOP.HasErrors()) {
548     return 0;
549   }
550   const TopoDS_Shape& aR=aBOP.Shape();
551   if (aR.IsNull()) {
552     di << " null shape\n";
553     return 0;
554   }
555   //
556   DBRep::Set(a[1], aR);
557   return 0;
558 }
559 //=======================================================================
560 //function : bopcurves
561 //purpose  : 
562 //=======================================================================
563 Standard_Integer bopcurves (Draw_Interpretor& di, 
564                             Standard_Integer n, 
565                             const char** a)
566 {
567   if (n<3) {
568     di << "Usage: bopcurves F1 F2 [-2d/-2d1/-2d2] "
569           "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]\n";
570     return 1;
571   }
572   //
573   TopoDS_Shape S1 = DBRep::Get(a[1]);
574   TopoDS_Shape S2 = DBRep::Get(a[2]);
575   TopAbs_ShapeEnum aType;
576   //
577   if (S1.IsNull() || S2.IsNull()) {
578     di << " Null shapes are not allowed \n";
579     return 1;
580   }
581   //
582   aType=S1.ShapeType();
583   if (aType != TopAbs_FACE) {
584     di << " Type mismatch F1\n";
585     return 1;
586   }
587   aType=S2.ShapeType();
588   if (aType != TopAbs_FACE) {
589     di << " Type mismatch F2\n";
590     return 1;
591   }
592   //
593   const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
594   const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
595   //
596   Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
597   Standard_Integer aNbCurves, aNbPoints;
598   Standard_Real anAppTol;
599   IntSurf_ListOfPntOn2S aListOfPnts;
600   TCollection_AsciiString aNm("c_"), aNp("p_");
601   //
602   anAppTol = 0.0000001;
603   aToApproxC3d = Standard_True;
604   aToApproxC2dOnS1 = Standard_False;
605   aToApproxC2dOnS2 = Standard_False;
606
607   //
608   Standard_Boolean bExtOut = Standard_False;
609   for(Standard_Integer i = 3; i < n; i++)
610   {
611     if (!strcasecmp(a[i],"-2d")) {
612       aToApproxC2dOnS1 = Standard_True;
613       aToApproxC2dOnS2 = Standard_True;
614     } 
615     else if (!strcasecmp(a[i],"-2d1")) {
616       aToApproxC2dOnS1 = Standard_True;
617     }
618     else if (!strcasecmp(a[i],"-2d2")) {
619       aToApproxC2dOnS2 = Standard_True;
620     }
621     else if (!strcasecmp(a[i],"-p")) {
622       IntSurf_PntOn2S aPt;
623       const Standard_Real aU1 = Draw::Atof(a[++i]);
624       const Standard_Real aV1 = Draw::Atof(a[++i]);
625       const Standard_Real aU2 = Draw::Atof(a[++i]);
626       const Standard_Real aV2 = Draw::Atof(a[++i]);
627
628       aPt.SetValue(aU1, aV1, aU2, aV2);
629       aListOfPnts.Append(aPt);
630     }
631     else if (!strcasecmp(a[i],"-v")) {
632       bExtOut = Standard_True;
633     }
634     else {
635       di << "Wrong key.\n";
636       di << "To build 2d curves use one of the following keys: -2d/-2d1/-2d2\n";
637       di << "To add start points use the following key: -p u1 v1 u2 v2\n";
638       di << "For extended output use the following key: -v\n";
639       return 1;
640     }
641   }
642   //
643   IntTools_FaceFace aFF;
644   //
645   aFF.SetParameters (aToApproxC3d,
646                      aToApproxC2dOnS1,
647                      aToApproxC2dOnS2,
648                      anAppTol);
649   aFF.SetList(aListOfPnts);
650   aFF.SetFuzzyValue (BOPTest_Objects::FuzzyValue());
651   //
652   aFF.Perform (aF1, aF2, BOPTest_Objects::RunParallel());
653   //
654   anIsDone=aFF.IsDone();
655   if (!anIsDone) {
656     di << "Error: Intersection failed\n";
657     return 0;
658   }
659   //
660   aFF.PrepareLines3D(Standard_False);
661   const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
662   const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points();
663   //
664   aNbCurves = aSCs.Length();
665   aNbPoints = aSPs.Length();
666   if (!aNbCurves && !aNbPoints) {
667     di << " has no 3d curves\n";
668     di << " has no 3d points\n";
669     return 0;
670   }
671   //
672   // curves
673   if (aNbCurves) {
674     Standard_Real aTolR = 0.;
675     if (!bExtOut) {
676       // find maximal tolerance
677       for (Standard_Integer i = 1; i <= aNbCurves; i++) {
678         const IntTools_Curve& anIC = aSCs(i);
679         if (aTolR < anIC.Tolerance()) {
680           aTolR = anIC.Tolerance();
681         }
682       }
683       di << "Tolerance Reached=" << aTolR << "\n";
684     }
685     //
686     di << aNbCurves << " curve(s) found.\n";
687     //
688     for (Standard_Integer i=1; i<=aNbCurves; i++) {
689       const IntTools_Curve& anIC=aSCs(i);
690
691       Handle (Geom_Curve)  aC3D = anIC.Curve();
692
693       if (aC3D.IsNull()) {
694         di << " has Null 3d curve# " << i << "\n";
695         continue;
696       }
697
698       TCollection_AsciiString anIndx(i), aNmx;
699       aNmx = aNm + anIndx;
700
701       Standard_CString nameC = aNmx.ToCString();
702
703       DrawTrSurf::Set(nameC, aC3D);
704       di << nameC << " ";
705       //
706       Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d();
707       Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d();
708       //
709       if (!aPC1.IsNull() || !aPC2.IsNull()) {
710         di << "(";
711         //
712         if (!aPC1.IsNull()) {
713           TCollection_AsciiString pc1N("c2d1_"), pc1Nx;
714           pc1Nx = pc1N + anIndx;
715           Standard_CString nameC2d1 = pc1Nx.ToCString();
716           //
717           DrawTrSurf::Set(nameC2d1, aPC1);
718           di << nameC2d1;
719         }
720         //
721         if (!aPC2.IsNull()) {
722           TCollection_AsciiString pc2N("c2d2_"), pc2Nx;
723           pc2Nx = pc2N + anIndx;
724           Standard_CString nameC2d2 = pc2Nx.ToCString();
725           //
726           DrawTrSurf::Set(nameC2d2, aPC2);
727           //
728           if (!aPC1.IsNull()) {
729             di << ", ";
730           }
731           di << nameC2d2;
732         }
733         di << ") ";
734       }
735       //
736       if (bExtOut) {
737         di << "\nTolerance: " << anIC.Tolerance() << "\n";
738         di << "Tangential tolerance: " << anIC.TangentialTolerance() << "\n";
739         di << "\n";
740       }
741     }
742     if (!bExtOut) {
743       di << "\n";
744     }
745   }
746   //
747   // points
748   if (aNbPoints) {
749     di << aNbPoints << " point(s) found.\n";
750     //
751     for (Standard_Integer i = 1; i <= aNbPoints; i++) {
752       const IntTools_PntOn2Faces& aPi = aSPs(i);
753       const gp_Pnt& aP = aPi.P1().Pnt();
754       //
755       TCollection_AsciiString anIndx(i), aNmx;
756       aNmx = aNp + anIndx;
757       Standard_CString nameP = aNmx.ToCString();
758       //
759       DrawTrSurf::Set(nameP, aP);
760       di << nameP << " ";
761     }
762     di << "\n";
763   }
764   //
765   return 0;
766 }
767 //=======================================================================
768 //function : mkvolume
769 //purpose  : 
770 //=======================================================================
771 Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a) 
772 {
773   if (n < 3) {
774     di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-ai]\n";
775     di << "Options:\n";
776     di << " -c  - use this option if the arguments are compounds\n";
777     di << "       containing shapes that should be interfered;\n";
778     di << " -ni - use this option if the arguments should not be interfered;\n";
779     di << " -ai - use this option to avoid internal for solids shapes in the result.\n";
780     return 1;
781   }
782   //
783   const char* usage = "Type mkvolume without arguments for the usage of the command.\n";
784   //
785   Standard_Boolean bToIntersect, bRunParallel, bNonDestructive;
786   Standard_Boolean bCompounds, bAvoidInternal;
787   Standard_Integer i;
788   Standard_Real aTol;
789   TopoDS_Shape aS;
790   TopTools_ListOfShape aLS;
791   //
792   aTol = BOPTest_Objects::FuzzyValue();
793   bRunParallel = BOPTest_Objects::RunParallel();
794   bNonDestructive = BOPTest_Objects::NonDestructive();
795   BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
796   //
797   bToIntersect = Standard_True;
798   bCompounds = Standard_False;
799   bAvoidInternal = Standard_False;
800   //
801   for (i = 2; i < n; ++i) {
802     aS = DBRep::Get(a[i]);
803     if (!aS.IsNull()) {
804       aLS.Append(aS);
805     }
806     else {
807       if (!strcmp(a[i], "-c")) {
808         bCompounds = Standard_True;
809       }
810       else if (!strcmp(a[i], "-ni")) {
811         bToIntersect = Standard_False;
812       }
813       else if (!strcmp(a[i], "-ai")) {
814         bAvoidInternal = Standard_True;
815       }
816     }
817   }
818   //
819   if (aLS.IsEmpty()) {
820     di << "No shapes to process.\n";
821     di << usage;
822     return 1;
823   }
824   //
825   // treat list of arguments for the case of compounds
826   if (bToIntersect && bCompounds) {
827     TopTools_ListOfShape aLSx;
828     TopTools_ListIteratorOfListOfShape aItLS;
829     //
830     aItLS.Initialize(aLS);
831     for (; aItLS.More(); aItLS.Next()) {
832       const TopoDS_Shape& aSx = aItLS.Value();
833       TopoDS_Iterator aItS(aSx);
834       for (; aItS.More(); aItS.Next()) {
835         const TopoDS_Shape& aSxS = aItS.Value();
836         aLSx.Append(aSxS);
837       }
838     }
839     //
840     aLS.Clear();
841     aLS.Assign(aLSx);
842   }
843   //
844   BOPAlgo_MakerVolume aMV;
845   aMV.SetArguments(aLS);
846   aMV.SetIntersect(bToIntersect);
847   aMV.SetRunParallel(bRunParallel);
848   aMV.SetFuzzyValue(aTol);
849   aMV.SetNonDestructive(bNonDestructive);
850   aMV.SetAvoidInternalShapes(bAvoidInternal);
851   aMV.SetGlue(aGlue);
852   aMV.SetUseOBB(BOPTest_Objects::UseOBB());
853   aMV.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
854   //
855   aMV.Perform();
856   BOPTest::ReportAlerts(aMV.GetReport());
857
858   // Store the history of Volume Maker into the session
859   if (BRepTest_Objects::IsHistoryNeeded())
860     BRepTest_Objects::SetHistory(aLS, aMV);
861
862   if (aMV.HasErrors()) {
863     return 0;
864   }
865   //
866   const TopoDS_Shape& aR = aMV.Shape();
867   //
868   DBRep::Set(a[1], aR);
869   //
870   return 0;
871 }