summaryrefslogtreecommitdiff
path: root/src/GeometryTest/GeometryTest_FairCurveCommands.cxx
blob: fb9df3abf82ff651587ad89752c735d6d6eac21c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
// File:	GeometryTest_FairCurveCommands.cxx
// Created:	Wed Oct  9 11:09:12 1996
// Author:	Philippe MANGIN
//		<pmn@sgi29>


#include <GeometryTest.ixx>

#include <Draw.hxx>
#include <DrawTrSurf.hxx>
#include <DrawTrSurf_Point.hxx>
#include <gp_Pnt2d.hxx>
#include <FairCurve_AnalysisCode.hxx>
#include <FairCurve_Batten.hxx>
#include <FairCurve_MinimalVariation.hxx>
#include <DrawFairCurve_Batten.hxx>
#include <DrawFairCurve_MinimalVariation.hxx>
#include <string.h>

//=======================================================================
Standard_Boolean IsGoodNumber(Standard_Integer argc, Standard_Integer waiting, Draw_Interpretor& di)
//=======================================================================
{
  // argc vaut 1 de plus, puisque argv[0] contient le nom de la commande
  if (argc != (waiting+1))
    {
      di << "Waiting "<< waiting << " arguments" << "\n";
      return Standard_False;
    }
  else
    return Standard_True;
}


//=======================================================================
static Standard_Integer 
BattenCurve(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,6,di)) return 1;

  const char *cp1 = argv[1];
  const char *cp2 = argv[2];
  const char *cangle1 = argv[3];
  const char *cangle2 = argv[4];
  const char *cheigth = argv[5];
  const char *BattenName = argv[6];

  FairCurve_AnalysisCode Iana;
  Standard_Real a1 = atof(cangle1),
                a2 = atof(cangle2),
                h  = atof(cheigth);
  gp_Pnt2d P1, P2;


  if (! DrawTrSurf::GetPoint2d(cp1, P1) ) return 1;
  if (! DrawTrSurf::GetPoint2d(cp2, P2) ) return 1;

  FairCurve_Batten* Bat = new FairCurve_Batten (P1, P2, h);
  Bat->SetAngle1(a1*PI/180);
  Bat->SetAngle2(a2*PI/180);
  
  Bat->Compute(Iana);
  
  Handle(DrawFairCurve_Batten) aBatten = new DrawFairCurve_Batten(Bat);

  if (aBatten.IsNull()) {
	di << " Batten null "<< "\n";
	return 1;
      }
  Draw::Set(BattenName,aBatten);

  return 0;
 // !!! Delete of Bat have to be make in DrawFairCurve_Batten destructor !!!!! 
}  


//=======================================================================
static Standard_Integer 
MVCurve(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,6,di)) return 1;

  const char *cp1 = argv[1];
  const char *cp2 = argv[2];
  const char *cangle1 = argv[3];
  const char *cangle2 = argv[4];
  const char *cheigth = argv[5];
  const char *MVCName = argv[6];

  FairCurve_AnalysisCode Iana;
  Standard_Real a1 = atof(cangle1),
                a2 = atof(cangle2),
                h  = atof(cheigth);
  gp_Pnt2d P1, P2;


  if (! DrawTrSurf::GetPoint2d(cp1, P1) ) return 1;
  if (! DrawTrSurf::GetPoint2d(cp2, P2) ) return 1;

  FairCurve_MinimalVariation* MVC = new  FairCurve_MinimalVariation (P1, P2, h);
  MVC->SetAngle1(a1*PI/180);
  MVC->SetAngle2(a2*PI/180);
  
  MVC->Compute(Iana);
  
  Handle(DrawFairCurve_MinimalVariation) aMVC = new DrawFairCurve_MinimalVariation(MVC);

  if (aMVC.IsNull()) {
	di << " MVC null "<< "\n";
	return 1;
      }
  Draw::Set(MVCName, aMVC);

  return 0;  
 // !!! Delete of Bat have to be make in DrawFairCurve_MinimalVariation destructor !!!!! 
}  

//=======================================================================
static Standard_Integer 
SetPoint(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,3,di)) return 1;

  const char *side = argv[1];
  const char *PointName = argv[2];
  const char *BattenName = argv[3];

  Standard_Integer cote = atoi(side);

  Handle(DrawTrSurf_Point)
     Pnt =  Handle(DrawTrSurf_Point)::DownCast(Draw::Get(PointName));
  if (Pnt.IsNull()) return 1;  
 
 
  Handle(DrawFairCurve_Batten) 
    Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
  if (Bat.IsNull()) return 1;  
 
  Bat->SetPoint(cote, Pnt->Point2d());
  Draw::Repaint();
  return 0;
}

//=======================================================================
static Standard_Integer 
SetAngle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,3,di)) return 1;

  const char *side = argv[1];
  const char *val = argv[2];
  const char *BattenName = argv[3];

  Standard_Real angle = atof(val); 
  Standard_Integer cote = atoi(side);
 
  Handle(DrawFairCurve_Batten) 
    Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
  if (Bat.IsNull()) return 1;  
 
  Bat->SetAngle(cote, angle);
  Draw::Repaint();
  return 0;
}


//=======================================================================
static Standard_Integer 
SetCurvature(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,3,di)) return 1;

  const char *side = argv[1];
  const char *val = argv[2];
  const char *MVCName = argv[3];

  Standard_Real rho = atof(val); 
  Standard_Integer cote = atoi(side);
 
  Handle(DrawFairCurve_MinimalVariation) 
    MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
  if (MVC.IsNull()) return 1;  
 
  MVC->SetCurvature(cote, rho);
  Draw::Repaint(); 
  return 0;
}



//=======================================================================
static Standard_Integer 
SetSlide(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,2,di)) return 1;

  const char *val = argv[1];
  const char *BattenName = argv[2];

  Standard_Real slide = atof(val); 
 
  Handle(DrawFairCurve_Batten) 
    Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
  if (Bat.IsNull()) return 1;  

  Bat->SetSliding(slide);
  Draw::Repaint();
  return 0;
}


//=======================================================================
static Standard_Integer 
FreeAngle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,2,di)) return 1;

  const char *side = argv[1];
  const char *BattenName = argv[2];
 
  Standard_Integer cote = atoi(side);
 
  Handle(DrawFairCurve_Batten) 
    Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
  if (Bat.IsNull()) return 1;  
 
  Bat->FreeAngle(cote);
  Draw::Repaint();
  return 0;
}

//=======================================================================
static Standard_Integer 
FreeCurvature(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,2,di)) return 1;

  const char *side = argv[1];
  const char *MVCName = argv[2];
 
  Standard_Integer cote = atoi(side);
 
  Handle(DrawFairCurve_MinimalVariation) 
    MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
  if (MVC.IsNull()) return 1;  
 
  MVC->FreeCurvature(cote);
  Draw::Repaint();
  return 0;
}

//=======================================================================
static Standard_Integer 
FreeSlide(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,1,di)) return 1;

  const char *BattenName = argv[1];
 
  Handle(DrawFairCurve_Batten) 
    Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
  if (Bat.IsNull()) return 1;  
 
  Bat->FreeSliding();
  Draw::Repaint();
  return 0;
}

//=======================================================================
static Standard_Integer 
SetHeight(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,2,di)) return 1;

  const char *val = argv[1];
  const char *BattenName = argv[2];

  Standard_Real Height = atof(val); 
 
  Handle(DrawFairCurve_Batten) 
    Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
  if (Bat.IsNull()) return 1;  
 
  Bat->SetHeight(Height);
  Draw::Repaint();
  return 0;
}

//=======================================================================
static Standard_Integer 
SetSlope(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,2,di)) return 1;

  const char *val = argv[1];
  const char *BattenName = argv[2];

  Standard_Real Slope = atof(val); 
 
  Handle(DrawFairCurve_Batten) 
    Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
  if (Bat.IsNull()) return 1;  
 
  Bat->SetSlope(Slope);
  Draw::Repaint();
  return 0;
}
//=======================================================================
static Standard_Integer 
SetPhysicalRatio(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
//=======================================================================
{
   if (!IsGoodNumber(argc,2,di)) return 1;

  const char *val = argv[1];
  const char *MVCName = argv[2];

  Standard_Real ratio = atof(val); 
 
  Handle(DrawFairCurve_MinimalVariation) 
      MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
  if (MVC.IsNull()) return 1;  
 
  MVC->SetPhysicalRatio(ratio);
  Draw::Repaint();
  return 0;
}


//=======================================================================
void GeometryTest::FairCurveCommands(Draw_Interpretor& TheCommande) 
//=======================================================================

{ 
  const char* g;

  g = "FairCurve command";
  
  TheCommande.Add("battencurve","battencurve P1 P2 Angle1 Angle2 Heigth BattenName", 
                   __FILE__,BattenCurve, g);
  TheCommande.Add("minvarcurve","MVCurve P1 P2 Angle1 Angle2 Heigth MVCName", 
                   __FILE__,MVCurve, g);
  TheCommande.Add("setpoint","setpoint side point BattenName ",__FILE__, SetPoint, g);
  TheCommande.Add("setangle","setangle side angle BattenName ",__FILE__, SetAngle, g);
  TheCommande.Add("setslide","setangle slidingfactor BattenName ",__FILE__, SetSlide, g);
  TheCommande.Add("freeangle","freeangle side BattenName",__FILE__, FreeAngle, g);
  TheCommande.Add("freeslide","freeslide BattenName",__FILE__, FreeSlide, g);
  TheCommande.Add("setheight","setheight height BattenName ",__FILE__, SetHeight, g);
  TheCommande.Add("setslope","setslope slope BattenName ",__FILE__, SetSlope, g);
  TheCommande.Add("setcurvature","setcurvature side rho MVCName ",__FILE__, SetCurvature, g);
  TheCommande.Add("freecurvature","freecurvature side  MVCName ",__FILE__, FreeCurvature, g);
  TheCommande.Add("setphysicalratio","physicalratio ratio MVCName ",__FILE__, SetPhysicalRatio, g);   
}