0027900: Coding rules - drop redundant Name parameter from V3d_Viewer constructor
[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-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <ViewerTest.hxx>
18 #include <BRepTest.hxx>
19 #include <TColgp_Array1OfPnt2d.hxx>
20 #include <DBRep.hxx>
21 #include <Draw_Interpretor.hxx>
22 #include <Draw_Appli.hxx>
23 #include <BRepFilletAPI_MakeFillet.hxx>
24 //#include <BRepAlgo_BooleanOperation.hxx>
25 //#include <BRepAlgo_Fuse.hxx>
26 //#include <BRepAlgo_Cut.hxx>
27 #include <BiTgte_Blend.hxx>
28 #include <TopOpeBRepBuild_HBuilder.hxx>
29 #include <TopTools_ListIteratorOfListOfShape.hxx>
30 #include <TopAbs_ShapeEnum.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopoDS.hxx>
36 #include <TopExp.hxx>
37 #include <TopExp_Explorer.hxx>
38
39 #include <FilletSurf_Builder.hxx>
40 #include <ChFi3d_FilletShape.hxx>
41 #include <Geom_TrimmedCurve.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <FilletSurf_StatusType.hxx>
44 #include <FilletSurf_ErrorTypeStatus.hxx>
45 #include <TopAbs.hxx>
46 #include <DrawTrSurf.hxx>
47 #include <TopTools_HArray1OfShape.hxx>
48
49 #include <AIS_InteractiveContext.hxx>
50 #include <AIS_InteractiveObject.hxx>
51 #include <AIS_Shape.hxx>
52
53 #ifdef _WIN32
54 //#define strcasecmp strcmp Already defined in Standard
55 # include <stdio.h>
56 #endif
57
58 extern  Handle(AIS_Shape) GetAISShapeFromName(const char* name);
59
60
61 static Standard_Real t3d = 1.e-4;
62 static Standard_Real t2d = 1.e-5;
63 static Standard_Real ta  = 1.e-2;
64 static Standard_Real fl  = 1.e-3;
65 static Standard_Real tapp_angle = 1.e-2;
66 static GeomAbs_Shape blend_cont = GeomAbs_C1;
67
68 static BRepFilletAPI_MakeFillet* Rakk = 0;
69
70
71 static void printtolblend(Draw_Interpretor& di)
72 {
73   di<<"tolerance ang : "<<ta<<"\n";
74   di<<"tolerance 3d  : "<<t3d<<"\n";
75   di<<"tolerance 2d  : "<<t2d<<"\n";
76   di<<"fleche        : "<<fl<<"\n";
77
78   di<<"tolblend "<<ta<<" "<<t3d<<" "<<t2d<<" "<<fl<<"\n";
79 }
80
81 static Standard_Integer VBLEND(Draw_Interpretor& di, Standard_Integer narg, const char** a)
82 {
83   if(Rakk != 0) {delete Rakk; Rakk = 0;}
84   printtolblend(di);
85   if (narg<5) return 1;
86   
87   Standard_Integer NbToPick = (narg -4)/2;
88   Handle(TopTools_HArray1OfShape) arr = new TopTools_HArray1OfShape(1,NbToPick);
89   if(ViewerTest::PickShapes(TopAbs_EDGE,arr)){
90     for(Standard_Integer i=1;i<=NbToPick;i++){
91       TopoDS_Shape PickSh = arr->Value(i);
92       if(!PickSh.IsNull()){
93         DBRep::Set(a[(2*i+2)],PickSh);
94       }
95     }
96   }
97   
98   TopoDS_Shape V = DBRep::Get(a[2]);
99   if(V.IsNull()) return 1;
100   ChFi3d_FilletShape FSh = ChFi3d_Rational;
101   if (narg%2 == 0) {
102     if (!strcasecmp(a[narg-1], "Q")) {
103       FSh = ChFi3d_QuasiAngular;
104     }
105     else if (!strcasecmp(a[narg-1], "P")) {
106       FSh = ChFi3d_Polynomial;
107     }
108   }
109   Rakk = new BRepFilletAPI_MakeFillet(V,FSh);
110   Rakk->SetParams(ta,t3d,t2d,t3d,t2d,fl);
111   Rakk->SetContinuity(blend_cont, tapp_angle);
112   Standard_Real Rad;
113   TopoDS_Edge E;
114   Standard_Integer nbedge = 0;
115   for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){
116     Rad = Draw::Atof(a[2*ii + 1]);
117     TopoDS_Shape aLocalShape = DBRep::Get(a[(2*ii+2)],TopAbs_EDGE);
118     E = TopoDS::Edge(aLocalShape);
119 //    E = TopoDS::Edge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE));
120     if(!E.IsNull()){
121       Rakk->Add(Rad,E);
122       nbedge++;
123     }
124   }
125   if(!nbedge) return 1;
126   Rakk->Build();
127   if(!Rakk->IsDone()) return 1;
128   TopoDS_Shape res = Rakk->Shape();
129   DBRep::Set(a[1],res);
130
131
132   // visu resultat...
133   Handle(AIS_Shape) AS = GetAISShapeFromName(a[1]);
134   Handle(AIS_Shape) Start = GetAISShapeFromName(a[2]);
135   Handle(AIS_InteractiveContext) Ctx = ViewerTest::GetAISContext();
136   Ctx->Erase(Start,Standard_False);
137   if(Ctx->IsDisplayed(AS))
138     Ctx->Redisplay(AS);
139   else
140     Ctx->Display(AS);
141   return 0;
142 }
143
144
145
146
147 void  ViewerTest::FilletCommands(Draw_Interpretor& theCommands)
148 {
149   const char* g = "Viewer Fillet construction commands";
150   theCommands.Add("vblend",
151                   "vblend result object rad1 ed1 rad2 ed2 ... [R/Q/P]",__FILE__,
152                   VBLEND,g);
153 }