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