0024399: ICC warnings 3280 "declaration hides..."
[occt.git] / src / BRepTest / BRepTest_FilletCommands.cxx
1 // Created on: 1994-06-20
2 // Created by: Modeling
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
25
26 #include <string.h>
27 #include <BRepTest.hxx>
28 #include <TColgp_Array1OfPnt2d.hxx>
29 #include <DBRep.hxx>
30 #include <Draw_Interpretor.hxx>
31 #include <Draw_Appli.hxx>
32 #include <BRepFilletAPI_MakeFillet.hxx>
33 #include <BRepAlgo_BooleanOperation.hxx>
34 #include <BRepAlgo_Fuse.hxx>
35 #include <BRepAlgo_Cut.hxx>
36 #include <BiTgte_Blend.hxx>
37 #include <TopOpeBRepBuild_HBuilder.hxx>
38 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 #include <TopAbs_ShapeEnum.hxx>
40 #include <TopoDS_Shape.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Vertex.hxx>
44 #include <TopoDS.hxx>
45 #include <TopExp.hxx>
46 #include <TopExp_Explorer.hxx>
47
48 //#include <BOPTools_DSFiller.hxx>
49 #include <BOPAlgo_PaveFiller.hxx>
50
51 #include <BRepAlgoAPI_BooleanOperation.hxx>
52 #include <BRepAlgoAPI_Fuse.hxx>
53 #include <BRepAlgoAPI_Cut.hxx>
54 #include <BRepAlgoAPI_Section.hxx>
55
56 #include <FilletSurf_Builder.hxx>
57 #include <ChFi3d_FilletShape.hxx>
58 #include <Geom_TrimmedCurve.hxx>
59 #include <TopTools_ListOfShape.hxx>
60 #include <FilletSurf_StatusType.hxx>
61 #include <FilletSurf_ErrorTypeStatus.hxx>
62 #include <TopAbs.hxx>
63 #include <DrawTrSurf.hxx>
64
65 #ifdef WNT
66 //#define strcasecmp strcmp Already defined
67 #endif
68 #ifdef HAVE_STRINGS_H
69 # include <strings.h>
70 #endif
71 #include <stdio.h>
72 //#endif
73
74
75 static Standard_Real t3d = 1.e-4;
76 static Standard_Real t2d = 1.e-5;
77 static Standard_Real ta  = 1.e-2;
78 static Standard_Real fl  = 1.e-3;
79 static Standard_Real tapp_angle = 1.e-2;
80 static GeomAbs_Shape blend_cont = GeomAbs_C1;
81
82 static BRepFilletAPI_MakeFillet* Rakk = 0;
83 static BRepFilletAPI_MakeFillet* Rake = 0;
84 static char name[100];
85
86
87 static Standard_Integer contblend(Draw_Interpretor& di, Standard_Integer narg, const char** a)
88 {
89   if(narg ==1) {
90     //cout<<"tolerance angular of approximation  : "<< tapp_angle <<endl;
91     //cout<<"internal continuity                 : ";
92     di<<"tolerance angular of approximation  : "<< tapp_angle <<"\n";
93     di<<"internal continuity                 : ";
94     switch (blend_cont) {
95       case GeomAbs_C0:
96          //cout << ""<<endl;
97          di << "C0"<<"\n";
98          break;
99       case GeomAbs_C1:
100          //cout << "C1"<<endl;
101          di << "C1"<<"\n";
102          break;
103       case GeomAbs_C2:
104          //cout << "C2"<<endl;
105          di << "C2"<<"\n";
106          break;
107        default:
108          break;
109        }
110     return 0;
111   }
112   else {
113     if (narg >3) return 1;
114     if (narg == 3) {  tapp_angle = Abs(Draw::Atof(a[2])); }
115     char c=a[1][1];
116     switch (c) {
117     case '0':
118       blend_cont = GeomAbs_C0;
119       break;
120     case '2':
121       blend_cont = GeomAbs_C2;
122       break;
123     default :
124        blend_cont = GeomAbs_C1;    
125     }
126     return 0;
127   }
128 }
129
130 static void printtolblend(Draw_Interpretor& di)
131 {
132   //cout<<"tolerance ang : "<<ta<<endl;
133   //cout<<"tolerance 3d  : "<<t3d<<endl;
134   //cout<<"tolerance 2d  : "<<t2d<<endl;
135   //cout<<"fleche        : "<<fl<<endl;
136
137   //cout<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<endl;
138
139   di<<"tolerance ang : "<<ta<<"\n";
140   di<<"tolerance 3d  : "<<t3d<<"\n";
141   di<<"tolerance 2d  : "<<t2d<<"\n";
142   di<<"fleche        : "<<fl<<"\n";
143
144   di<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<"\n";
145 }
146
147 static Standard_Integer tolblend(Draw_Interpretor& di, Standard_Integer narg, const char** a)
148 {
149   if(narg == 1){
150     printtolblend(di);
151     return 0;
152   }
153   else if(narg == 5){
154     ta = Draw::Atof(a[1]);
155     t3d = Draw::Atof(a[2]);
156     t2d = Draw::Atof(a[3]);
157     fl = Draw::Atof(a[4]);
158     return 0;
159   }
160   return 1;
161 }
162 static Standard_Integer BLEND(Draw_Interpretor& di, Standard_Integer narg, const char** a)
163 {
164   if(Rakk != 0) {delete Rakk; Rakk = 0;}
165   printtolblend(di);
166   if (narg<5) return 1;
167   TopoDS_Shape V = DBRep::Get(a[2]);
168   if(V.IsNull()) return 1;
169   ChFi3d_FilletShape FSh = ChFi3d_Rational;
170   if (narg%2 == 0) {
171     if (!strcasecmp(a[narg-1], "Q")) {
172       FSh = ChFi3d_QuasiAngular;
173     }
174     else if (!strcasecmp(a[narg-1], "P")) {
175       FSh = ChFi3d_Polynomial;
176     }
177   }
178   Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
179   Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
180   Rakk->SetContinuity(blend_cont, tapp_angle);
181   Standard_Real Rad;
182   TopoDS_Edge E;
183   Standard_Integer nbedge = 0;
184   for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
185     Rad = Draw::Atof(a[2*ii + 1]);
186     TopoDS_Shape aLocalEdge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE));
187     E = TopoDS::Edge(aLocalEdge);
188 //    E = TopoDS::Edge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE));
189     if(!E.IsNull()){
190       Rakk->Add(Rad,E);
191       nbedge++;
192     }
193   }
194   if(!nbedge) return 1;
195   Rakk->Build();
196   if(!Rakk->IsDone()) return 1;
197   TopoDS_Shape res = Rakk->Shape();
198   DBRep::Set(a[1],res);
199   return 0;
200 }
201
202 static void PrintHist(const TopoDS_Shape& S,
203                       TopTools_ListIteratorOfListOfShape& It,
204                       Standard_Integer& nbgen)
205 {
206   TopoDS_Compound C;
207   BRep_Builder B;
208   B.MakeCompound(C);
209   B.Add(C,S);
210   char localname[100];
211   if(nbgen<10){
212     Sprintf(localname,"generated_00%d", nbgen++);
213   }
214   else if(nbgen<100){
215     Sprintf(localname,"generated_0%d", nbgen++);
216   }
217   else {
218     Sprintf(localname,"generated_%d", nbgen++);
219   }
220   for(; It.More(); It.Next()){
221     B.Add(C,It.Value());
222   }
223   DBRep::Set(localname,C);
224 }
225   
226 static Standard_Integer CheckHist(Draw_Interpretor& di, 
227                                   Standard_Integer , 
228                                   const char** )
229 {
230   if(Rakk == 0) {
231     //cout<<"No active Builder"<<endl;
232     di<<"No active Builder"<<"\n";
233     return 1;
234   }
235   if(!Rakk->IsDone()) {
236     //cout<<"Active Builder Not Done"<<endl;
237     di<<"Active Builder Not Done"<<"\n";
238     return 1;
239   }
240   Standard_Integer nbc = Rakk->NbContours();
241   Standard_Integer nbgen = 0;
242   TopTools_ListIteratorOfListOfShape It;
243   TopoDS_Shape curshape;
244   for(Standard_Integer i = 1; i <= nbc; i++){
245     curshape = Rakk->FirstVertex(i);
246     It.Initialize(Rakk->Generated(curshape));
247     PrintHist(curshape,It,nbgen);
248     Standard_Integer nbe = Rakk->NbEdges(i);
249     for(Standard_Integer j = 1; j <= nbe; j++){
250       curshape = Rakk->Edge(i,j);
251       It.Initialize(Rakk->Generated(curshape));
252       PrintHist(curshape,It,nbgen);
253     }
254     curshape = Rakk->LastVertex(i);
255     It.Initialize(Rakk->Generated(curshape));
256     PrintHist(curshape,It,nbgen);
257   }
258   //cout<<"foreach g [lsort [dir gen*]] { wclick; puts [dname $g]; donl $g; }"<<endl;
259   di<<"foreach g [lsort [dir gen*]] { wclick; puts [dname $g]; donl $g; }"<<"\n";
260   return 0;
261 }
262
263 static Standard_Integer MKEVOL(Draw_Interpretor& di, 
264                                Standard_Integer narg, 
265                                const char** a)
266 {
267   if(Rake != 0) {delete Rake; Rake = 0;}
268   printtolblend(di);
269   if (narg < 3) return 1;
270   TopoDS_Shape V = DBRep::Get(a[2]);
271   Rake = new BRepFilletAPI_MakeFillet(V);
272   Rake->SetParams(ta,t3d,t2d,t3d,t2d,fl);
273   Rake->SetContinuity(blend_cont, tapp_angle);
274   if (narg == 4) {
275     ChFi3d_FilletShape FSh = ChFi3d_Rational;
276     if (!strcasecmp(a[3], "Q")) {
277       FSh = ChFi3d_QuasiAngular;
278     }
279     else if (!strcasecmp(a[3], "P")) {
280       FSh = ChFi3d_Polynomial;
281     }
282     Rake->SetFilletShape(FSh);
283   }
284   strcpy(name, a[1]);
285   return 0;
286 }
287
288 static Standard_Integer UPDATEVOL(Draw_Interpretor& di, 
289                                   Standard_Integer narg, 
290                                   const char** a)
291 {
292   if(Rake == 0){
293     //cout << "MakeFillet not initialized"<<endl;
294     di << "MakeFillet not initialized"<<"\n";
295     return 1 ;
296   }
297   if(narg%2 != 0 || narg < 4) return 1;
298   TColgp_Array1OfPnt2d uandr(1,(narg/2)-1);
299   Standard_Real Rad, Par;
300   TopoDS_Shape aLocalEdge(DBRep::Get(a[1],TopAbs_EDGE));
301   TopoDS_Edge E = TopoDS::Edge(aLocalEdge);
302 //  TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[1],TopAbs_EDGE));
303   for (Standard_Integer ii = 1; ii <= (narg/2)-1; ii++){
304     Par = Draw::Atof(a[2*ii]);
305     Rad = Draw::Atof(a[2*ii + 1]);
306     uandr.ChangeValue(ii).SetCoord(Par,Rad);
307   }
308   Rake->Add(uandr,E);
309   return 0;
310 }
311
312 static Standard_Integer BUILDEVOL(Draw_Interpretor& di, 
313                                   Standard_Integer, 
314                                   const char**)
315 {
316   if(Rake == 0){
317     //cout << "MakeFillet not initialized"<<endl;
318     di << "MakeFillet not initialized"<<"\n";
319     return 1 ;
320   }
321   Rake->Build();
322   if(Rake->IsDone()){
323     TopoDS_Shape result = Rake->Shape();
324     DBRep::Set(name,result);
325     if(Rake != 0) {delete Rake; Rake = 0;}
326     return 0;
327   }
328   if(Rake != 0) {delete Rake; Rake = 0;}
329   return 1;
330 }
331
332
333
334
335 //**********************************************
336 // command fuse and cut with fillets *
337 //**********************************************
338
339 Standard_Integer topoblend(Draw_Interpretor& di, Standard_Integer narg, const char** a)
340 {
341   printtolblend(di);
342   if(narg != 5) return 1;
343   Standard_Boolean fuse  = !strcmp(a[0],"fubl");
344   TopoDS_Shape S1 = DBRep::Get(a[2]);
345   TopoDS_Shape S2 = DBRep::Get(a[3]);
346   Standard_Real Rad = Draw::Atof(a[4]);
347   BRepAlgo_BooleanOperation* BC;
348   if(fuse){
349     BC = new BRepAlgo_Fuse(S1,S2);
350   }
351   else{
352     BC = new BRepAlgo_Cut(S1,S2);
353   }
354   TopoDS_Shape ShapeCut = BC->Shape();
355   
356   Handle(TopOpeBRepBuild_HBuilder) build = BC->Builder();
357   TopTools_ListIteratorOfListOfShape its;
358   
359   TopoDS_Compound result;
360   BRep_Builder B; 
361   B.MakeCompound(result);
362   
363   TopExp_Explorer ex;
364   for (ex.Init(ShapeCut,TopAbs_SOLID); ex.More(); ex.Next()) {
365     const TopoDS_Shape& cutsol = ex.Current();  
366     
367     BRepFilletAPI_MakeFillet fill(cutsol);
368     fill.SetParams(ta,t3d,t2d,t3d,t2d,fl);
369     fill.SetContinuity(blend_cont, tapp_angle);
370     its = build->Section();
371     while (its.More()) {
372       TopoDS_Edge E = TopoDS::Edge(its.Value());
373       fill.Add(Rad,E);
374       its.Next();
375     }
376     
377     fill.Build();
378     if(fill.IsDone()){
379       B.Add(result,fill.Shape());
380     }
381     else {
382       B.Add(result,cutsol);
383     }
384   }
385   
386   delete BC;
387   DBRep::Set(a[1],result);
388   return 0;
389 }
390
391 //**********************************************
392 // bfuse or bcut and then blend the section
393 //**********************************************
394
395 Standard_Integer boptopoblend(Draw_Interpretor& di, Standard_Integer narg, const char** a)
396 {
397   printtolblend(di);
398   if(narg != 5) return 1;
399
400   Standard_Boolean fuse  = !strcmp(a[0],"bfuseblend");
401   TopoDS_Shape S1 = DBRep::Get(a[2]);
402   TopoDS_Shape S2 = DBRep::Get(a[3]);
403   if (S1.IsNull() || S2.IsNull()) {
404     printf(" Null shapes are not allowed \n");
405     return 1;
406   }
407   Standard_Real Rad = Draw::Atof(a[4]);
408
409   BOPAlgo_PaveFiller theDSFiller;
410   BOPCol_ListOfShape aLS;
411   aLS.Append(S1); 
412   aLS.Append(S2); 
413   theDSFiller.SetArguments(aLS);
414   //
415   theDSFiller.Perform();
416   if (theDSFiller.ErrorStatus()) {
417     printf("Check types of the arguments, please\n");
418     return 1;
419   }
420
421   BRepAlgoAPI_BooleanOperation* pBuilder=NULL;
422
423   if (fuse)
424     pBuilder = new BRepAlgoAPI_Fuse( S1, S2, theDSFiller );
425   else
426     pBuilder = new BRepAlgoAPI_Cut ( S1, S2, theDSFiller );
427
428   Standard_Boolean anIsDone = pBuilder->IsDone();
429   if (!anIsDone)
430     {
431       printf("boolean operation not done ErrorStatus()=%d\n", pBuilder->ErrorStatus());
432       return 1;
433     }
434
435   TopoDS_Shape ResultOfBop = pBuilder->Shape();
436   
437   delete pBuilder;
438   pBuilder = new BRepAlgoAPI_Section( S1, S2, theDSFiller );
439   TopoDS_Shape theSection = pBuilder->Shape();
440
441   TopoDS_Compound result;
442   BRep_Builder BB; 
443   BB.MakeCompound(result);
444   
445   TopExp_Explorer Explo( ResultOfBop, TopAbs_SOLID );
446   for (; Explo.More(); Explo.Next())
447     {
448       const TopoDS_Shape& aSolid = Explo.Current();
449
450       BRepFilletAPI_MakeFillet Blender(aSolid);
451       Blender.SetParams(ta,t3d,t2d,t3d,t2d,fl);
452       Blender.SetContinuity( blend_cont, tapp_angle );
453
454       TopExp_Explorer expsec( theSection, TopAbs_EDGE );
455       for (; expsec.More(); expsec.Next())
456         {
457           TopoDS_Edge anEdge = TopoDS::Edge(expsec.Current());
458           Blender.Add( Rad, anEdge );
459         }
460
461       Blender.Build();
462       if (Blender.IsDone())
463         BB.Add( result, Blender.Shape() );
464       else
465         BB.Add( result, aSolid );
466     }
467
468   delete pBuilder;
469   DBRep::Set( a[1], result );
470   return 0;
471 }
472
473
474 static Standard_Integer blend1(Draw_Interpretor& di, Standard_Integer narg, const char** a)
475 {
476   if (narg<5) return 1;
477   TopoDS_Shape V = DBRep::Get(a[2]);
478   if(V.IsNull()) return 1;
479   Standard_Integer nb ,i;
480   Standard_Real Rad;
481   Standard_Boolean simul=Standard_False;
482   const char *ns0=(a[1]);
483   Rad = Draw::Atof(a[3]);
484   TopTools_ListOfShape E;
485   for (i=4; i <=(narg-1) ; i++){
486     TopoDS_Shape edge= DBRep::Get(a[i],TopAbs_EDGE);
487    if (edge.IsNull()) return 1 ;
488    if(edge.ShapeType()!=TopAbs_EDGE) return 1;
489     E.Append(edge);
490   } 
491   FilletSurf_Builder aRakk(V,E,Rad);
492   if (simul) aRakk.Simulate();
493   else  aRakk.Perform();
494
495   //if (Rakk.IsDone()==FilletSurf_IsNotOk) 
496   // { FilletSurf_ErrorTypeStatus err=Rakk.StatusError();
497   //   if (err==FilletSurf_EmptyList) cout<< "StatusError=EmptyList"<<endl;
498   //   else if (err==FilletSurf_EdgeNotG1) cout<< "StatusError=NotG1"<<endl;
499   //   else if (err==FilletSurf_FacesNotG1) cout<< "StatusError=facesNotG1"<<endl;   
500   //   else if (err==FilletSurf_EdgeNotOnShape) 
501   //   cout<< "StatusError=edgenotonshape"<<endl;
502   //   else if (err==FilletSurf_NotSharpEdge ) cout<< "StatusError=notsharpedge"<<endl;
503   //   else if (err==FilletSurf_PbFilletCompute) cout <<"StatusError=PBFillet"<<endl;
504   // }
505   // else {
506   //  if (Rakk.IsDone()==FilletSurf_IsPartial) cout <<"resultat partiel"<<endl; 
507   if (aRakk.IsDone()==FilletSurf_IsNotOk)
508    { FilletSurf_ErrorTypeStatus err=aRakk.StatusError();
509      if (err==FilletSurf_EmptyList) di<< "StatusError=EmptyList"<<"\n";
510      else if (err==FilletSurf_EdgeNotG1) di<< "StatusError=NotG1"<<"\n";
511      else if (err==FilletSurf_FacesNotG1) di<< "StatusError=facesNotG1"<<"\n";
512      else if (err==FilletSurf_EdgeNotOnShape)
513      di<< "StatusError=edgenotonshape"<<"\n";
514      else if (err==FilletSurf_NotSharpEdge ) di<< "StatusError=notsharpedge"<<"\n";
515      else if (err==FilletSurf_PbFilletCompute) di <<"StatusError=PBFillet"<<"\n";
516    }
517    else {
518     if (aRakk.IsDone()==FilletSurf_IsPartial) di <<"partial result"<<"\n";
519  
520     nb=aRakk.NbSurface();
521     char localname [100];
522     char *temp; 
523     
524     // affichage du type d'arret 
525     
526    if (!simul)
527    { 
528     //if (Rakk.StartSectionStatus()==FilletSurf_NoExtremityOnEdge)
529     //  {cout<<" type deb conges = WLBLOUT"<<endl;}
530     //else if (Rakk.StartSectionStatus()==FilletSurf_OneExtremityOnEdge )
531     //  { cout<<" type deb conges = WLBLSTOP"<<endl;}
532     //else if (Rakk.StartSectionStatus()==FilletSurf_TwoExtremityOnEdge)
533     //  {cout<<" type deb conges = WLBLEND"<<endl;}
534     if (aRakk.StartSectionStatus()==FilletSurf_NoExtremityOnEdge)
535       {di<<" type start fillets = WLBLOUT"<<"\n";}
536     else if (aRakk.StartSectionStatus()==FilletSurf_OneExtremityOnEdge)
537       { di<<" type start fillets = WLBLSTOP"<<"\n";}
538     else if (aRakk.StartSectionStatus()==FilletSurf_TwoExtremityOnEdge)
539       {di<<" type start fillets = WLBLEND"<<"\n";}
540     
541     //if (Rakk.EndSectionStatus()==FilletSurf_NoExtremityOnEdge) 
542     //  {cout<<" type fin  conges = WLBLOUT"<<endl;}
543     //else if (Rakk.EndSectionStatus()==FilletSurf_OneExtremityOnEdge) 
544     //  {cout<<" type fin  conges = WLBLSTOP"<<endl;}
545     //else if (Rakk.EndSectionStatus()==FilletSurf_TwoExtremityOnEdge) 
546     //  { cout<<" type fin  conges = WLBLEND"<<endl;}
547     if (aRakk.EndSectionStatus()==FilletSurf_NoExtremityOnEdge)
548       {di<<" type end fillets = WLBLOUT"<<"\n";}
549     else if (aRakk.EndSectionStatus()==FilletSurf_OneExtremityOnEdge)
550       {di<<" type end fillets = WLBLSTOP"<<"\n";}
551     else if (aRakk.EndSectionStatus()==FilletSurf_TwoExtremityOnEdge)
552       { di<<" type end fillets = WLBLEND"<<"\n";}
553     Standard_Real f,l;
554     f = aRakk.FirstParameter();
555     l = aRakk.LastParameter();
556     //cout<<"parameter on edge start : "<<f<<endl;
557     //cout<<"parameter on edge end   : "<<l<<endl;
558     di<<"parametre on edge start : "<<f<<"\n";
559     di<<"parametre on edge end   : "<<l<<"\n";
560     for (i=1;i<=nb;i++){
561       //precision 
562       //cout<<"precision "<< i << "= "<<Rakk.TolApp3d(i)<<endl;
563       di<<"precision "<< i << "= "<<aRakk.TolApp3d(i)<<"\n";
564       
565       // display resulting surfaces  
566       Sprintf(localname, "%s%d" ,ns0,i);
567       temp = localname;
568       DrawTrSurf::Set(temp,aRakk.SurfaceFillet(i));
569       di << localname<< " ";
570       
571       // display curves 3d 
572       Sprintf(localname, "%s%d" ,"courb1",i);
573       temp =localname; 
574       DrawTrSurf::Set(temp,aRakk.CurveOnFace1(i));
575       di << localname<< " ";
576       Sprintf(localname, "%s%d" ,"courb2",i);
577       temp =localname;
578       DrawTrSurf::Set(temp,aRakk.CurveOnFace2(i));
579       di << localname<< " ";     
580       
581       // display supports 
582       Sprintf(localname, "%s%d" ,"face1",i);
583       temp =localname ;
584       DBRep::Set(temp,aRakk.SupportFace1(i));
585       di << localname<< " ";
586       Sprintf(localname, "%s%d" ,"face2",i);
587       temp =localname; 
588       DBRep::Set(temp,aRakk.SupportFace2(i));
589       di << localname<< " ";
590       
591       // display Pcurves on faces 
592       Sprintf(localname, "%s%d" ,"pcurveonface1",i);
593       temp =localname ;
594       DrawTrSurf::Set(temp,aRakk.PCurveOnFace1(i));
595       di << localname<< " ";
596       Sprintf(localname, "%s%d" ,"pcurveonface2",i);
597       temp =localname; 
598       DrawTrSurf::Set(temp,aRakk.PCurveOnFace2(i));
599       di << localname<< " ";
600       
601       // display Pcurves on the fillet
602       Sprintf(localname, "%s%d" ,"pcurveonconge1",i);
603       temp =localname;
604       DrawTrSurf::Set(temp,aRakk.PCurve1OnFillet(i));
605       di << localname<< " ";
606       Sprintf(localname, "%s%d" ,"pcurveonconge2",i);
607       temp =localname; 
608       DrawTrSurf::Set(temp,aRakk.PCurve2OnFillet(i));
609       di << localname<< " ";
610       
611     } }
612    else{
613    Standard_Integer j;
614   
615    for (i=1;i<=nb;i++)
616     {Standard_Integer s=aRakk.NbSection(i);
617     for (j=1;j<=s;j++)
618      {Handle(Geom_TrimmedCurve Sec);
619      aRakk.Section(i,j,Sec);
620     Sprintf(localname, "%s%d%d" ,"sec",i,j);
621      temp =localname;
622     DrawTrSurf::Set (temp,Sec);
623     di << localname<< " ";}
624    }}
625  }
626   return 0;
627 }
628
629 //=======================================================================
630 //function : rollingball
631 //purpose  : 
632 //=======================================================================
633
634 Standard_Integer rollingball(Draw_Interpretor& di, Standard_Integer n, const char** a)
635 {
636   if ( n < 2) return 1;
637
638   TopoDS_Shape S = DBRep::Get(a[2]);
639   if ( S.IsNull()) return 1;
640   Standard_Real Rad = Draw::Atof(a[3]);
641   
642   Standard_Real Tol = t3d; //the same as blend ! 1.e-7;
643   
644   BiTgte_Blend Roll;
645   Roll.Init(S,Rad,Tol,Standard_False);
646   
647   Standard_Integer Nb = 0;
648   for ( Standard_Integer i = 4; i <= n-1; i++) {
649     if ( !strcmp(a[i],"@")) {
650       Nb++;
651       continue;
652     }
653
654     if ( Nb == 0) { // return stop faces.
655       TopoDS_Shape aLocalFace(DBRep::Get(a[i],TopAbs_FACE));
656       TopoDS_Face F1 = TopoDS::Face(aLocalFace);
657 //      TopoDS_Face F1 = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
658       if ( F1.IsNull()) {
659         //cout << " Stop face not referenced." << endl;
660         di << " Stop face not referenced." << "\n";
661         return 1;
662       }
663       Roll.SetStoppingFace(F1);
664     }
665     else if (Nb == 1) { // return faces on which the ball rotates
666       TopoDS_Shape aLocalFace(DBRep::Get(a[i],TopAbs_FACE));
667       TopoDS_Face F1 = TopoDS::Face(aLocalFace);
668 //      TopoDS_Face F1 = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
669       i++;
670       if ( !strcmp(a[i],"@")) {
671         //cout << " Even number of ball support faces is required " << endl;
672         di << " Even number of ball support faces is required " << "\n";
673         return 1;
674       }
675       aLocalFace = DBRep::Get(a[i],TopAbs_FACE);
676       TopoDS_Face F2 = TopoDS::Face(aLocalFace);
677 //      TopoDS_Face F2 = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
678       if ( F1.IsNull() || F2.IsNull()) {
679         //cout << " Support face not referenced." << endl;
680         di << " Support face not referenced." << "\n";
681         return 1;
682       }
683       Roll.SetFaces(F1,F2);
684     }
685     else if (Nb == 2) { // return the edge on which the ball rotates
686       TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_EDGE));
687       TopoDS_Edge E = TopoDS::Edge(aLocalShape);
688 //      TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[i],TopAbs_EDGE));
689       if ( E.IsNull()) {
690         //cout << " Edge not referenced." << endl;
691         di << " Edge not referenced." << "\n";
692         return 1;
693       }
694       Roll.SetEdge(E);
695     }
696
697   }
698   Standard_Boolean BuildShape = (!strcmp(a[0],"brollingball"));
699
700   Roll.Perform(BuildShape);
701
702   Standard_Boolean ComputeBranches = (!strcmp(a[0],"trollingball"));
703   char localname[100];
704   if (ComputeBranches) {
705     Standard_Integer NbBranches = Roll.NbBranches();
706     for (Standard_Integer i = 1; i <= NbBranches; i++) {
707       Standard_Integer From,To;
708       Roll.IndicesOfBranche(i,From,To);
709       //cout << " Indexes of the " << i << "th Branch : ";
710       //cout << "   " << From << "     " << To << endl;
711       di << " Indexes of the " << i << "th Branch : ";
712       di << "   " << From << "     " << To << "\n";
713       for (Standard_Integer j = From; j <= To; j++) {
714         const TopoDS_Shape& CurF = Roll.Face(j);
715         Sprintf(localname,"%s_%d_%d",a[1],i,j);
716         DBRep::Set(localname,CurF);
717       }
718     }
719     
720   }
721   else 
722     DBRep::Set(a[1],Roll.Shape());
723
724   return 0;
725 }
726
727 //=======================================================================
728 //function : FilletCommands
729 //purpose  : 
730 //=======================================================================
731
732 void  BRepTest::FilletCommands(Draw_Interpretor& theCommands)
733 {
734   static Standard_Boolean done = Standard_False;
735   if (done) return;
736   done = Standard_True;
737
738   DBRep::BasicCommands(theCommands);
739
740   const char* g = "TOPOLOGY Fillet construction commands";
741    
742   theCommands.Add("continuityblend",
743                   "continuityblend C0/C1/C2  [tangle]",__FILE__,
744                   contblend,g);
745
746   theCommands.Add("tolblend",
747                   "tolblend [ta t3d t2d fl]",__FILE__,
748                   tolblend,g);
749
750   theCommands.Add("blend",
751                   "blend result object rad1 ed1 rad2 ed2 ... [R/Q/P]",__FILE__,
752                   BLEND,g);
753
754   theCommands.Add("checkhist",
755                   "checkhist",__FILE__,
756                   CheckHist,g);
757
758   theCommands.Add("mkevol",
759                   "mkevol result object (then use updatevol) [R/Q/P]",__FILE__,
760                   MKEVOL,g);
761
762   theCommands.Add("updatevol",
763                   "updatevol edge u1 rad1 u2 rad2 ...",__FILE__,
764                   UPDATEVOL,g);
765
766   theCommands.Add("buildevol",
767                   "buildevol end of the evol fillet computation",__FILE__,
768                   BUILDEVOL,g);
769
770   theCommands.Add("fubl",
771                   "fubl result shape1 shape2 radius",__FILE__,
772                   topoblend,g);
773   
774   theCommands.Add("cubl",
775                   "cubl result shape tool radius",__FILE__,
776                   topoblend,g);
777
778   theCommands.Add("bfuseblend",
779                   "bfuseblend result shape1 shape2 radius",__FILE__,
780                   boptopoblend,g);
781   
782   theCommands.Add("bcutblend",
783                   "bcutblend result shape tool radius",__FILE__,
784                   boptopoblend,g);
785
786   theCommands.Add("blend1",
787                   "blend1 result object rad ed1  ed2 ...",__FILE__,
788                   blend1,g); 
789
790   theCommands.Add("rollingball",
791                   "rollingball  r S radius [stopf1 ..] @ [f1 f2 ..] @ [e1 ..]",
792                   __FILE__,
793                   rollingball);
794
795   theCommands.Add("brollingball",
796                   "brollingball r S radius [stopf1 ..] @ [f1 f2 ..] @ [e1 ..]",
797                   __FILE__,
798                   rollingball);
799
800   theCommands.Add("trollingball",
801                   "trollingball r S radius [stopf1 ..] @ [f1 f2 ..] @ [e1 ..]",
802                   __FILE__,
803                   rollingball);
804 }