0024510: Remove unused local variables
[occt.git] / src / GeometryTest / GeometryTest_FairCurveCommands.cxx
CommitLineData
b311480e 1// Created on: 1996-10-09
2// Created by: Philippe MANGIN
3// Copyright (c) 1996-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <GeometryTest.ixx>
18
19#include <Draw.hxx>
20#include <DrawTrSurf.hxx>
21#include <DrawTrSurf_Point.hxx>
22#include <gp_Pnt2d.hxx>
23#include <FairCurve_AnalysisCode.hxx>
24#include <FairCurve_Batten.hxx>
25#include <FairCurve_MinimalVariation.hxx>
26#include <DrawFairCurve_Batten.hxx>
27#include <DrawFairCurve_MinimalVariation.hxx>
28#include <string.h>
29
30//=======================================================================
31Standard_Boolean IsGoodNumber(Standard_Integer argc, Standard_Integer waiting, Draw_Interpretor& di)
32//=======================================================================
33{
34 // argc vaut 1 de plus, puisque argv[0] contient le nom de la commande
35 if (argc != (waiting+1))
36 {
37 di << "Waiting "<< waiting << " arguments" << "\n";
38 return Standard_False;
39 }
40 else
41 return Standard_True;
42}
43
44
45//=======================================================================
46static Standard_Integer
47BattenCurve(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
48//=======================================================================
49{
50 if (!IsGoodNumber(argc,6,di)) return 1;
51
52 const char *cp1 = argv[1];
53 const char *cp2 = argv[2];
54 const char *cangle1 = argv[3];
55 const char *cangle2 = argv[4];
56 const char *cheigth = argv[5];
57 const char *BattenName = argv[6];
58
7fd59977 59 FairCurve_AnalysisCode Iana;
91322f44 60 Standard_Real a1 = Draw::Atof(cangle1),
61 a2 = Draw::Atof(cangle2),
62 h = Draw::Atof(cheigth);
7fd59977 63 gp_Pnt2d P1, P2;
64
65
66 if (! DrawTrSurf::GetPoint2d(cp1, P1) ) return 1;
67 if (! DrawTrSurf::GetPoint2d(cp2, P2) ) return 1;
68
69 FairCurve_Batten* Bat = new FairCurve_Batten (P1, P2, h);
c6541a0c
D
70 Bat->SetAngle1(a1*M_PI/180);
71 Bat->SetAngle2(a2*M_PI/180);
7fd59977 72
96a95605 73 Bat->Compute(Iana);
7fd59977 74
75 Handle(DrawFairCurve_Batten) aBatten = new DrawFairCurve_Batten(Bat);
76
77 if (aBatten.IsNull()) {
78 di << " Batten null "<< "\n";
79 return 1;
80 }
81 Draw::Set(BattenName,aBatten);
82
83 return 0;
84 // !!! Delete of Bat have to be make in DrawFairCurve_Batten destructor !!!!!
85}
86
87
88//=======================================================================
89static Standard_Integer
90MVCurve(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
91//=======================================================================
92{
93 if (!IsGoodNumber(argc,6,di)) return 1;
94
95 const char *cp1 = argv[1];
96 const char *cp2 = argv[2];
97 const char *cangle1 = argv[3];
98 const char *cangle2 = argv[4];
99 const char *cheigth = argv[5];
100 const char *MVCName = argv[6];
101
7fd59977 102 FairCurve_AnalysisCode Iana;
91322f44 103 Standard_Real a1 = Draw::Atof(cangle1),
104 a2 = Draw::Atof(cangle2),
105 h = Draw::Atof(cheigth);
7fd59977 106 gp_Pnt2d P1, P2;
107
108
109 if (! DrawTrSurf::GetPoint2d(cp1, P1) ) return 1;
110 if (! DrawTrSurf::GetPoint2d(cp2, P2) ) return 1;
111
112 FairCurve_MinimalVariation* MVC = new FairCurve_MinimalVariation (P1, P2, h);
c6541a0c
D
113 MVC->SetAngle1(a1*M_PI/180);
114 MVC->SetAngle2(a2*M_PI/180);
7fd59977 115
96a95605 116 MVC->Compute(Iana);
7fd59977 117
118 Handle(DrawFairCurve_MinimalVariation) aMVC = new DrawFairCurve_MinimalVariation(MVC);
119
120 if (aMVC.IsNull()) {
121 di << " MVC null "<< "\n";
122 return 1;
123 }
124 Draw::Set(MVCName, aMVC);
125
126 return 0;
127 // !!! Delete of Bat have to be make in DrawFairCurve_MinimalVariation destructor !!!!!
128}
129
130//=======================================================================
131static Standard_Integer
132SetPoint(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
133//=======================================================================
134{
135 if (!IsGoodNumber(argc,3,di)) return 1;
136
137 const char *side = argv[1];
138 const char *PointName = argv[2];
139 const char *BattenName = argv[3];
140
91322f44 141 Standard_Integer cote = Draw::Atoi(side);
7fd59977 142
143 Handle(DrawTrSurf_Point)
144 Pnt = Handle(DrawTrSurf_Point)::DownCast(Draw::Get(PointName));
145 if (Pnt.IsNull()) return 1;
146
147
148 Handle(DrawFairCurve_Batten)
149 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
150 if (Bat.IsNull()) return 1;
151
152 Bat->SetPoint(cote, Pnt->Point2d());
153 Draw::Repaint();
154 return 0;
155}
156
157//=======================================================================
158static Standard_Integer
159SetAngle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
160//=======================================================================
161{
162 if (!IsGoodNumber(argc,3,di)) return 1;
163
164 const char *side = argv[1];
165 const char *val = argv[2];
166 const char *BattenName = argv[3];
167
91322f44 168 Standard_Real angle = Draw::Atof(val);
169 Standard_Integer cote = Draw::Atoi(side);
7fd59977 170
171 Handle(DrawFairCurve_Batten)
172 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
173 if (Bat.IsNull()) return 1;
174
175 Bat->SetAngle(cote, angle);
176 Draw::Repaint();
177 return 0;
178}
179
180
181//=======================================================================
182static Standard_Integer
183SetCurvature(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
184//=======================================================================
185{
186 if (!IsGoodNumber(argc,3,di)) return 1;
187
188 const char *side = argv[1];
189 const char *val = argv[2];
190 const char *MVCName = argv[3];
191
91322f44 192 Standard_Real rho = Draw::Atof(val);
193 Standard_Integer cote = Draw::Atoi(side);
7fd59977 194
195 Handle(DrawFairCurve_MinimalVariation)
196 MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
197 if (MVC.IsNull()) return 1;
198
199 MVC->SetCurvature(cote, rho);
200 Draw::Repaint();
201 return 0;
202}
203
204
205
206//=======================================================================
207static Standard_Integer
208SetSlide(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
209//=======================================================================
210{
211 if (!IsGoodNumber(argc,2,di)) return 1;
212
213 const char *val = argv[1];
214 const char *BattenName = argv[2];
215
91322f44 216 Standard_Real slide = Draw::Atof(val);
7fd59977 217
218 Handle(DrawFairCurve_Batten)
219 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
220 if (Bat.IsNull()) return 1;
221
222 Bat->SetSliding(slide);
223 Draw::Repaint();
224 return 0;
225}
226
227
228//=======================================================================
229static Standard_Integer
230FreeAngle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
231//=======================================================================
232{
233 if (!IsGoodNumber(argc,2,di)) return 1;
234
235 const char *side = argv[1];
236 const char *BattenName = argv[2];
237
91322f44 238 Standard_Integer cote = Draw::Atoi(side);
7fd59977 239
240 Handle(DrawFairCurve_Batten)
241 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
242 if (Bat.IsNull()) return 1;
243
244 Bat->FreeAngle(cote);
245 Draw::Repaint();
246 return 0;
247}
248
249//=======================================================================
250static Standard_Integer
251FreeCurvature(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
252//=======================================================================
253{
254 if (!IsGoodNumber(argc,2,di)) return 1;
255
256 const char *side = argv[1];
257 const char *MVCName = argv[2];
258
91322f44 259 Standard_Integer cote = Draw::Atoi(side);
7fd59977 260
261 Handle(DrawFairCurve_MinimalVariation)
262 MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
263 if (MVC.IsNull()) return 1;
264
265 MVC->FreeCurvature(cote);
266 Draw::Repaint();
267 return 0;
268}
269
270//=======================================================================
271static Standard_Integer
272FreeSlide(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
273//=======================================================================
274{
275 if (!IsGoodNumber(argc,1,di)) return 1;
276
277 const char *BattenName = argv[1];
278
279 Handle(DrawFairCurve_Batten)
280 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
281 if (Bat.IsNull()) return 1;
282
283 Bat->FreeSliding();
284 Draw::Repaint();
285 return 0;
286}
287
288//=======================================================================
289static Standard_Integer
290SetHeight(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
291//=======================================================================
292{
293 if (!IsGoodNumber(argc,2,di)) return 1;
294
295 const char *val = argv[1];
296 const char *BattenName = argv[2];
297
91322f44 298 Standard_Real Height = Draw::Atof(val);
7fd59977 299
300 Handle(DrawFairCurve_Batten)
301 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
302 if (Bat.IsNull()) return 1;
303
304 Bat->SetHeight(Height);
305 Draw::Repaint();
306 return 0;
307}
308
309//=======================================================================
310static Standard_Integer
311SetSlope(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
312//=======================================================================
313{
314 if (!IsGoodNumber(argc,2,di)) return 1;
315
316 const char *val = argv[1];
317 const char *BattenName = argv[2];
318
91322f44 319 Standard_Real Slope = Draw::Atof(val);
7fd59977 320
321 Handle(DrawFairCurve_Batten)
322 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
323 if (Bat.IsNull()) return 1;
324
325 Bat->SetSlope(Slope);
326 Draw::Repaint();
327 return 0;
328}
329//=======================================================================
330static Standard_Integer
331SetPhysicalRatio(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
332//=======================================================================
333{
334 if (!IsGoodNumber(argc,2,di)) return 1;
335
336 const char *val = argv[1];
337 const char *MVCName = argv[2];
338
91322f44 339 Standard_Real ratio = Draw::Atof(val);
7fd59977 340
341 Handle(DrawFairCurve_MinimalVariation)
342 MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
343 if (MVC.IsNull()) return 1;
344
345 MVC->SetPhysicalRatio(ratio);
346 Draw::Repaint();
347 return 0;
348}
349
350
351//=======================================================================
352void GeometryTest::FairCurveCommands(Draw_Interpretor& TheCommande)
353//=======================================================================
354
355{
356 const char* g;
357
358 g = "FairCurve command";
359
360 TheCommande.Add("battencurve","battencurve P1 P2 Angle1 Angle2 Heigth BattenName",
361 __FILE__,BattenCurve, g);
362 TheCommande.Add("minvarcurve","MVCurve P1 P2 Angle1 Angle2 Heigth MVCName",
363 __FILE__,MVCurve, g);
364 TheCommande.Add("setpoint","setpoint side point BattenName ",__FILE__, SetPoint, g);
365 TheCommande.Add("setangle","setangle side angle BattenName ",__FILE__, SetAngle, g);
366 TheCommande.Add("setslide","setangle slidingfactor BattenName ",__FILE__, SetSlide, g);
367 TheCommande.Add("freeangle","freeangle side BattenName",__FILE__, FreeAngle, g);
368 TheCommande.Add("freeslide","freeslide BattenName",__FILE__, FreeSlide, g);
369 TheCommande.Add("setheight","setheight height BattenName ",__FILE__, SetHeight, g);
370 TheCommande.Add("setslope","setslope slope BattenName ",__FILE__, SetSlope, g);
371 TheCommande.Add("setcurvature","setcurvature side rho MVCName ",__FILE__, SetCurvature, g);
372 TheCommande.Add("freecurvature","freecurvature side MVCName ",__FILE__, FreeCurvature, g);
373 TheCommande.Add("setphysicalratio","physicalratio ratio MVCName ",__FILE__, SetPhysicalRatio, g);
374}