0024510: Remove unused local variables
[occt.git] / src / GeometryTest / GeometryTest_SurfaceCommands.cxx
1 // Created on: 1993-08-12
2 // Created by: Joelle CHAUVET
3 // Copyright (c) 1993-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
9 // under the terms of the GNU Lesser General Public 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 // 09/06/97 : JPI : suppression des commandes redondantes suite a la creation de GeomliteTest
18 // Modified:    Mon Jan 18 11:06:46 1999
19 //              option -NS dans la commande tuyau pour distinguer les tuyaux
20 //              a section evolutive des tuyaux a N sections avec N = 2
21
22 #include <GeometryTest.hxx>
23 #include <DrawTrSurf.hxx>
24 #include <Draw.hxx>
25 #include <Draw_Interpretor.hxx>
26 #include <Draw_Appli.hxx>
27 #include <Draw_Display.hxx>
28
29 #include <GeomAbs_SurfaceType.hxx>
30 #include <GeomAbs_IsoType.hxx>
31 #include <GeomAbs_Shape.hxx>
32
33 #include <Geom_BSplineSurface.hxx>
34 #include <Geom_BSplineCurve.hxx>
35 #include <GeomConvert.hxx>
36
37
38 #include <GeomAdaptor_Surface.hxx>
39 #include <GeomAdaptor_Curve.hxx>
40 #include <Geom2dAdaptor_Curve.hxx>
41
42 #include <TColgp_Array1OfPnt.hxx>
43 #include <TColgp_Array2OfPnt.hxx>
44 #include <TColStd_Array1OfReal.hxx>
45 #include <TColStd_Array2OfReal.hxx>
46 #include <TColStd_Array1OfInteger.hxx>
47 #include <TColStd_HArray1OfReal.hxx>
48 #include <TColStd_HArray2OfReal.hxx>
49 #include <TColGeom_SequenceOfCurve.hxx>
50
51 #include <Precision.hxx>
52
53 #include <GeomFill.hxx>
54 #include <GeomFill_BSplineCurves.hxx>
55 #include <GeomFill_Pipe.hxx>
56 #include <GeomFill_SectionGenerator.hxx>
57 #include <GeomFill_Line.hxx>
58 #include <GeomFill_AppSurf.hxx>
59
60
61 #include <DrawTrSurf_BezierSurface.hxx>
62 #include <DrawTrSurf_BSplineSurface.hxx>
63
64 #ifdef WNT
65 #include <stdio.h>
66 //#define strcasecmp strcmp Already defined
67 Standard_IMPORT Draw_Viewer dout;
68 #endif
69
70
71
72
73 //=======================================================================
74 //function : sweep
75 //purpose  : 
76 //=======================================================================
77
78 static Standard_Integer sweep (Draw_Interpretor&,
79                                Standard_Integer n, const char** a)
80 {
81   GeomFill_Trihedron Option = GeomFill_IsCorrectedFrenet;
82   Standard_Integer ipath =2, isection =4 , NbSeg=30, MaxDegree = 10;
83   Standard_Real Tol = 1.e-4;
84
85   if (n < 4 ) return 1;
86   
87   if (! strcmp(a[2],"-FX")) {
88     ipath = 3;
89     Option = GeomFill_IsFixed;
90   }
91   if (! strcmp(a[2],"-FR")) {
92     ipath = 3;
93     Option = GeomFill_IsFrenet;
94   }
95   if (! strcmp(a[2],"-CF")) {
96     ipath = 3;
97     Option = GeomFill_IsCorrectedFrenet;
98   }
99   if (! strcmp(a[2],"-CN")) {
100     ipath = 3;
101     isection = 7;
102     Option = GeomFill_IsConstantNormal;
103   }
104   if (! strcmp(a[2],"-DX")) {
105     ipath = 3;
106     isection = 5;
107     Option = GeomFill_IsDarboux;
108   }
109
110   GeomFill_Pipe Pipe;
111   Pipe.GenerateParticularCase(Standard_True);
112   
113   if (Option == GeomFill_IsDarboux) {
114     Handle(Geom2d_Curve) path = DrawTrSurf::GetCurve2d(a[ipath]);
115     if ( path.IsNull()) return 1;
116     
117     Handle(Geom_Surface) Support = DrawTrSurf::GetSurface(a[ipath+1]);
118     if ( Support.IsNull()) return 1;
119
120     Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+2]);
121     if ( firstS.IsNull()) return 1;
122     
123     Pipe.Init(path, Support, firstS);
124   }
125   else if (Option == GeomFill_IsConstantNormal) {
126     gp_Dir D ( Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5]) );
127     Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[6]);
128     Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[7]);
129     Pipe.Init(path, firstS, D);
130   }
131   else  {
132     Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[ipath]);
133     if ( path.IsNull()) return 1;
134     
135     Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[ipath+1]);
136     if ( firstS.IsNull()) return 1;
137
138     Pipe.Init(path, firstS, Option);
139   }     
140
141   if (n >=isection+2) { 
142     MaxDegree = Draw::Atoi(a[isection+1]);
143     if (n >isection+2) NbSeg = Draw::Atoi(a[isection+2]);
144   }
145     
146   Pipe.Perform(Tol, Standard_False,  GeomAbs_C2, MaxDegree, NbSeg);
147
148   DrawTrSurf::Set(a[1], Pipe.Surface());
149   return 0;
150   
151 }   
152 //=======================================================================
153 //function : tuyau
154 //purpose  : 
155 //=======================================================================
156
157 static Standard_Integer tuyau (Draw_Interpretor&,
158                                Standard_Integer n, const char** a)
159 {
160   if ( n < 4) return 1;
161
162   GeomAbs_Shape Cont = GeomAbs_C2;
163   GeomFill_Pipe Pipe;
164   Pipe.GenerateParticularCase(Standard_True);
165
166   Standard_Boolean Option_NS = Standard_False;
167   Standard_Integer indice_path = 2, narg = n;
168   if (! strcmp(a[1],"-NS")) {
169     Option_NS = Standard_True;
170     indice_path++;
171     narg--;
172   }
173   Handle(Geom_Curve) path = DrawTrSurf::GetCurve(a[indice_path]);
174   if ( path.IsNull()) return 1;
175
176   Standard_Integer isect = indice_path+1;
177   Handle(Geom_Curve) firstS = DrawTrSurf::GetCurve(a[isect]);
178   if ( firstS.IsNull()) {
179     if ( narg == 4) { 
180       // tuyau a rayon constant.
181       Pipe.Init(path, Draw::Atof(a[isect]));
182     }
183     else 
184       return 1;
185   }
186   else {
187     if ( narg == 4) {
188       // tuyau a section constante.
189       Pipe.Init(path,firstS, GeomFill_IsCorrectedFrenet);
190     }
191     else {
192       if ( narg == 5 && !Option_NS) {
193         // tuyau a section evolutive
194         Handle(Geom_Curve) lastS = DrawTrSurf::GetCurve(a[isect+1]);
195         Cont = GeomAbs_C2;
196         Pipe.Init(path, firstS, lastS); 
197       }
198       else { 
199         // tuyau a N sections, N>=2
200         TColGeom_SequenceOfCurve Seq;
201         Seq.Clear();
202         Seq.Append(firstS);
203         for (Standard_Integer i=isect+1;i<n;i++) {
204           Handle(Geom_Curve) nextS = DrawTrSurf::GetCurve(a[i]);
205           Seq.Append(nextS);
206         }
207         Cont = GeomAbs_C2;
208         Pipe.Init(path, Seq); 
209       }
210     }
211   }
212
213   Pipe.Perform(1.e-4, Standard_False,  Cont);
214   DrawTrSurf::Set(a[indice_path-1], Pipe.Surface());
215
216   return 0;
217 }
218
219 //=======================================================================
220 //function : ruled
221 //purpose  : 
222 //=======================================================================
223
224 static Standard_Integer ruled(Draw_Interpretor& di,
225                               Standard_Integer n, const char** a)
226 {
227   if ( n < 4) return 1;
228
229   Handle(Geom_Curve) C1 = DrawTrSurf::GetCurve(a[2]);
230   if ( C1.IsNull()) {
231     di << " C1 is not a Curve ==> Command failed" << "\n";
232     return 1;
233   }
234   Handle(Geom_Curve) C2 = DrawTrSurf::GetCurve(a[3]);
235   if ( C2.IsNull()) {
236     di << " C2 is not a Curve ==> Command failed" << "\n";
237     return 1;
238   }
239   
240   Handle(Geom_Surface) S = GeomFill::Surface(C1,C2);
241   if ( S.IsNull()) return 1;
242
243   DrawTrSurf::Set(a[1],S);
244   return 0;
245 }
246
247 //=======================================================================
248 //function : appsurf
249 //purpose  : 
250 //=======================================================================
251
252 static Standard_Integer appsurf(Draw_Interpretor& di,
253                                 Standard_Integer n, const char** a)
254 {
255   if ( n < 4) return 1;
256   
257   GeomFill_SectionGenerator Section;
258   Standard_Integer i;
259   Handle(Geom_Curve) C;
260   for ( i = 2; i < n; i++) {
261     C = DrawTrSurf::GetCurve(a[i]);
262     if (C.IsNull()) 
263       return 1;
264     Section.AddCurve(C);
265   }
266   
267   Section.Perform(Precision::PConfusion());
268
269   Handle(GeomFill_Line) Line = new GeomFill_Line(n-2);
270   Standard_Integer NbIt = 0;
271   GeomFill_AppSurf App( 3, 8, Precision::Confusion(), Precision::PConfusion(),
272                         NbIt);
273
274   App.Perform( Line, Section);
275
276   if ( !App.IsDone()) {
277     di << "    Approximation aux fraises " << "\n";
278   }
279
280   Standard_Integer UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots;
281   App.SurfShape(UDegree, VDegree, NbUPoles, NbVPoles, NbUKnots, NbVKnots);
282
283   Handle(Geom_BSplineSurface) GBS = new 
284     Geom_BSplineSurface(App.SurfPoles(),
285                         App.SurfWeights(),
286                         App.SurfUKnots(),
287                         App.SurfVKnots(),
288                         App.SurfUMults(),
289                         App.SurfVMults(),
290                         App.UDegree(),
291                         App.VDegree());
292
293   DrawTrSurf::Set(a[1],GBS);
294   return 0;
295 }
296
297 static Standard_Integer fillcurves(Draw_Interpretor& /*di*/,
298                                    Standard_Integer n, const char** a)
299 {
300   if ( n < 6) return 1;
301   
302   Standard_Integer i;
303   Handle(Geom_Curve) aC;
304   Handle(Geom_BSplineCurve) C[4];
305   for ( i = 2; i < 6; i++) {
306     aC = DrawTrSurf::GetCurve(a[i]);
307     if (aC.IsNull()) 
308       return 1;
309     C[i-2] = GeomConvert::CurveToBSplineCurve(aC, Convert_RationalC1);
310   }
311
312   Standard_Integer ist = 2;
313   GeomFill_FillingStyle Style = GeomFill_CoonsStyle;
314   if(n > 6) ist = Draw::Atoi(a[6]);
315
316   if(ist == 1) Style =  GeomFill_StretchStyle;
317   if(ist == 2) Style =  GeomFill_CoonsStyle;
318   if(ist == 3) Style =  GeomFill_CurvedStyle;
319
320   GeomFill_BSplineCurves aFilling(C[0], C[1], C[2], C[3], Style);
321    
322   const Handle(Geom_BSplineSurface)& GBS = aFilling.Surface();
323   DrawTrSurf::Set(a[1],GBS);
324   return 0;
325 }
326
327 //=======================================================================
328 //function : SurfaceCommands
329 //purpose  : 
330 //=======================================================================
331
332
333 void  GeometryTest::SurfaceCommands(Draw_Interpretor& theCommands)
334 {
335   static Standard_Boolean loaded = Standard_False;
336   if (loaded) return;
337   loaded = Standard_True;
338
339   DrawTrSurf::BasicCommands(theCommands);
340
341   const char* g;
342
343   g = "GEOMETRY surfaces creation";
344
345
346   theCommands.Add("tuyau",
347                   "tuyau [-NS] result Path Curve/Radius [Curve2] [Curve3] ... \n the option -NS is used only with 2 sections.\n With it, <result> is going from the first section to the last section \n Without, <result> is a pipe by evolutive section ",
348                   __FILE__,
349                   tuyau,g);
350
351   theCommands.Add("partuyau",
352                   "tuyau result Path Curve/Radius [Curve2]\n the parametrization of the surface in the V direction will be as the Path",
353                   __FILE__,
354                   tuyau,g);
355
356   theCommands.Add("sweep", "sweep result [options] path [Surf] curve [Tol [nbsegment]]\n sweep the the curve along the path, options are \n -FX : Tangent and Normal are fixed\n -FR : Tangent and Normal are given by Frenet trihedron \n -CF : Tangente is given by Frenet, \n     the Normal is computed to minimize the torsion \n -DX : Tangent and Normal are given by Darboux trihedron \n     <path> have to be a 2d curve,\n     <Surf> have to be defined\n -CN dx dy dz : Normal is given by dx dy dz" ,
357                   __FILE__,
358                   sweep, g);
359
360   theCommands.Add("ruled",
361                   "ruled result C1 C2",
362                   __FILE__,
363                   ruled,g);
364
365   theCommands.Add("appsurf",
366                   "appsurf result C1 C2 C3 .....: \n\tCreate a surface passing through the curves",
367                   __FILE__,
368                   appsurf,g);
369  
370  theCommands.Add("fillcurves",
371                   "fillcurves result C1 C2 C3 C4 [style 1/2/3]: \n\tCreate a surface filling frame of 4 curves",
372                   __FILE__,
373                   fillcurves,g);
374
375 }
376
377
378
379