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