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