Integration of OCCT 6.5.0 from SVN
[occt.git] / src / ViewerTest / ViewerTest_FilletCommands.cxx
1 // File:        ViewerTest_FilletCommands.cxx
2 // Created:     Fri Nov 20 16:58:22 1998
3 // Author:      Robert COUBLANC
4 //              <rob@robox.paris1.matra-dtv.fr>
5
6 #ifdef HAVE_CONFIG_H
7 # include <config.h>
8 #endif
9
10 #include <ViewerTest.hxx>
11 #include <string.h>
12 #include <BRepTest.hxx>
13 #include <TColgp_Array1OfPnt2d.hxx>
14 #include <DBRep.hxx>
15 #include <Draw_Interpretor.hxx>
16 #include <Draw_Appli.hxx>
17 #include <BRepFilletAPI_MakeFillet.hxx>
18 //#include <BRepAlgo_BooleanOperation.hxx>
19 //#include <BRepAlgo_Fuse.hxx>
20 //#include <BRepAlgo_Cut.hxx>
21 #include <BiTgte_Blend.hxx>
22 #include <TopOpeBRepBuild_HBuilder.hxx>
23 #include <TopTools_ListIteratorOfListOfShape.hxx>
24 #include <TopAbs_ShapeEnum.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopoDS_Compound.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Vertex.hxx>
29 #include <TopoDS.hxx>
30 #include <TopExp.hxx>
31 #include <TopExp_Explorer.hxx>
32
33 #include <FilletSurf_Builder.hxx>
34 #include <ChFi3d_FilletShape.hxx>
35 #include <Geom_TrimmedCurve.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <FilletSurf_StatusType.hxx>
38 #include <FilletSurf_ErrorTypeStatus.hxx>
39 #include <TopAbs.hxx>
40 #include <DrawTrSurf.hxx>
41 #include <TopTools_HArray1OfShape.hxx>
42
43 #include <AIS_InteractiveContext.hxx>
44 #include <AIS_InteractiveObject.hxx>
45 #include <AIS_Shape.hxx>
46
47 #ifdef HAVE_STRINGS_H
48 # include <strings.h>
49 #endif
50 #ifdef WNT
51 //#define strcasecmp strcmp Already defined in Standard
52 #include <stdio.h>
53 #endif
54
55 extern  Handle(AIS_Shape) GetAISShapeFromName(const char* name);
56
57
58 static Standard_Real t3d = 1.e-4;
59 static Standard_Real t2d = 1.e-5;
60 static Standard_Real ta  = 1.e-2;
61 static Standard_Real fl  = 1.e-3;
62 static Standard_Real tapp_angle = 1.e-2;
63 static GeomAbs_Shape blend_cont = GeomAbs_C1;
64
65 static BRepFilletAPI_MakeFillet* Rakk = 0;
66 #ifdef DEB
67 static BRepFilletAPI_MakeFillet* Rake = 0;
68 static char name[100];
69 #endif
70
71
72 static void printtolblend(Draw_Interpretor& di)
73 {
74   di<<"tolerance ang : "<<ta<<"\n";
75   di<<"tolerance 3d  : "<<t3d<<"\n";
76   di<<"tolerance 2d  : "<<t2d<<"\n";
77   di<<"fleche        : "<<fl<<"\n";
78
79   di<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<"\n";
80 }
81
82 // Unused :
83 #ifdef DEB
84 static Standard_Integer tolblend(Draw_Interpretor& di, Standard_Integer narg, const char** a)
85 {
86   if(narg == 1){
87     printtolblend(di);
88     return 0;
89   }
90   else if(narg == 5){
91     ta = atof(a[1]);
92     t3d = atof(a[2]);
93     t2d = atof(a[3]);
94     fl = atof(a[4]);
95     return 0;
96   }
97   return 1;
98 }
99 #endif
100
101 static Standard_Integer VBLEND(Draw_Interpretor& di, Standard_Integer narg, const char** a)
102 {
103   if(Rakk != 0) {delete Rakk; Rakk = 0;}
104   printtolblend(di);
105   if (narg<5) return 1;
106   
107   Standard_Integer NbToPick = (narg -4)/2;
108 #ifdef DEB
109   Standard_Boolean autonaming = !strcasecmp(a[3],".");
110 #endif
111   Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
112   if(ViewerTest::PickShapes(TopAbs_EDGE,arr)){
113     for(Standard_Integer i=1;i<=NbToPick;i++){
114       TopoDS_Shape PickSh = arr->Value(i);
115       if(!PickSh.IsNull()){
116         DBRep::Set(a[(2*i+2)],PickSh);
117       }
118     }
119   }
120   
121   TopoDS_Shape V = DBRep::Get(a[2]);
122   if(V.IsNull()) return 1;
123   ChFi3d_FilletShape FSh = ChFi3d_Rational;
124   if (narg%2 == 0) {
125     if (!strcasecmp(a[narg-1], "Q")) {
126       FSh = ChFi3d_QuasiAngular;
127     }
128     else if (!strcasecmp(a[narg-1], "P")) {
129       FSh = ChFi3d_Polynomial;
130     }
131   }
132   Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
133   Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
134   Rakk->SetContinuity(blend_cont, tapp_angle);
135   Standard_Real Rad;
136   TopoDS_Edge E;
137   Standard_Integer nbedge = 0;
138   for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
139     Rad = atof(a[2*ii + 1]);
140     TopoDS_Shape aLocalShape = DBRep::Get(a[(2*ii+2)],TopAbs_EDGE);
141     E = TopoDS::Edge(aLocalShape);
142 //    E = TopoDS::Edge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE));
143     if(!E.IsNull()){
144       Rakk->Add(Rad,E);
145       nbedge++;
146     }
147   }
148   if(!nbedge) return 1;
149   Rakk->Build();
150   if(!Rakk->IsDone()) return 1;
151   TopoDS_Shape res = Rakk->Shape();
152   DBRep::Set(a[1],res);
153
154
155   // visu resultat...
156   Handle(AIS_Shape) AS = GetAISShapeFromName(a[1]);
157   Handle(AIS_Shape) Start = GetAISShapeFromName(a[2]);
158   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
159   Ctx->Erase(Start,Standard_False);
160   if(Ctx->IsDisplayed(AS))
161     Ctx->Redisplay(AS);
162   else
163     Ctx->Display(AS);
164   return 0;
165 }
166
167
168
169
170 void  ViewerTest::FilletCommands(Draw_Interpretor& theCommands)
171 {
172   const char* g = "Viewer Fillet construction commands";
173   theCommands.Add("vblend",
174                   "vblend result object rad1 ed1 rad2 ed2 ... [R/Q/P]",__FILE__,
175                   VBLEND,g);
176 }