summaryrefslogtreecommitdiff
path: root/src/SWDRAW/SWDRAW_ShapeCustom.cxx
blob: 6b16f1743a996649958a30d4da165515d9617d98 (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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
// File:	SWDRAW_ShapeCustom.cxx
// Created:	Tue Mar  9 14:56:39 1999
// Author:	Roman LYGIN
//		<rln@kinox.nnov.matra-dtv.fr>
//    abv 08.05.99: new command convtorevol

#include <SWDRAW_ShapeCustom.ixx>
#include <DBRep.hxx>
#include <SWDRAW.hxx>
#include <TopoDS_Shape.hxx>
#include <ShapeCustom.hxx>
#include <ShapeCustom_BSplineRestriction.hxx>
#include <ShapeCustom_RestrictionParameters.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Edge.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Curve.hxx>
#include <Geom2d_Curve.hxx>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <TopAbs.hxx>
#include <DrawTrSurf.hxx>
#include <TopExp_Explorer.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS.hxx>
#include <Geom_SweptSurface.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_SweptSurface.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_RectangularTrimmedSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_OffsetSurface.hxx>
#include <ShapeFix.hxx>
#include <GeomAbs_Shape.hxx>
#include <TColStd_Array2OfInteger.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_OffsetCurve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_OffsetCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom_Plane.hxx>
#include <TColStd_Array1OfReal.hxx>

static Standard_Integer ContToInteger( const GeomAbs_Shape Cont)
{
  Standard_Integer result =0;
  switch(Cont) {
    case GeomAbs_C0:
    case GeomAbs_G1: result = 0; break;
    case GeomAbs_C1:
    case GeomAbs_G2: result = 1; break;
    case GeomAbs_C2: result = 2; break;  
    case GeomAbs_C3: result = 3; break;
    default : result = 4; break;
  }
  return result;
}

static Standard_Integer directfaces(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if (argc < 3) { di<<"Donner un nom de SHAPE + un nom de RESULTAT"<<"\n"; return 1 /* Error */; }
  Standard_CString arg1 = argv[1];
  Standard_CString arg2 = argv[2];
  TopoDS_Shape Shape = DBRep::Get(arg2);
  if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1 /* Error */; }

  TopoDS_Shape result = ShapeCustom::DirectFaces (Shape);
  if (result.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; }
  else if (result == Shape) { di<<"No modif"<<"\n"; return 0; }
  di<<"DirectFaces -> Result : "<<arg1<<"\n";
  DBRep::Set (arg1,result);
  return 0; // Done
}

static Standard_Integer ckeckKnots(const TColStd_Array1OfReal& theKnots,
                                   Standard_Real theFirst,
                                   Standard_Real theLast)
{
  Standard_Integer i =1, nb = theKnots.Length();
  Standard_Integer aNum =0;
  for( ; i< nb; i++)
  {
    if(!aNum)
    {
      Standard_Real aDF = theKnots(i) - theFirst;
      if(fabs(aDF) <= Precision::PConfusion() ||
      aDF > Precision::PConfusion())
      {
        aNum++;
        continue;
      }
    }
    else 
    {
      Standard_Real aDL = theKnots(i) - theLast;
      if(fabs(aDL) <= Precision::PConfusion() ||
        aDL > Precision::PConfusion())
        break;
      aNum++;

    }

  }
  return aNum;
}

static void expcurv2d(const Handle(Geom2d_Curve)& aCurve, TColStd_Array2OfInteger& Nb, const Standard_Integer Degree,
                      const Standard_Integer MaxSeg,
                      const Standard_Integer theCont,
                      Standard_Real theFirst,
                      Standard_Real theLast)   
{
  if(aCurve.IsNull()) return;
  
  if (aCurve->IsKind(STANDARD_TYPE(Geom2d_TrimmedCurve))) {
    Handle(Geom2d_TrimmedCurve) tmp = Handle(Geom2d_TrimmedCurve)::DownCast (aCurve);
    Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
    expcurv2d(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast);
    return;
  }
  if (aCurve->IsKind(STANDARD_TYPE(Geom2d_OffsetCurve))) {
    Handle(Geom2d_OffsetCurve) tmp = Handle(Geom2d_OffsetCurve)::DownCast (aCurve);
    Handle(Geom2d_Curve) BasCurve = tmp->BasisCurve();
    expcurv2d(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast);
    return;
  }
  Standard_Integer aCont = ContToInteger(aCurve->Continuity());
  if(aCurve->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
    Handle(Geom2d_BSplineCurve) Bs = Handle(Geom2d_BSplineCurve)::DownCast(aCurve);
    if(Bs->Degree() > Degree) Nb.ChangeValue(1,1)++; 
    if(Bs->NbKnots() -1 > MaxSeg)  Nb.ChangeValue(1,2)++;
    if(Bs->IsRational())  Nb.ChangeValue(1,3)++;
    if(aCont < theCont && Bs->NbKnots() > 2)
    {
      TColStd_Array1OfReal aKnots(1,Bs->NbKnots());
      Bs->Knots(aKnots);
      Standard_Integer nbInt = ckeckKnots(aKnots,theFirst,theLast);
      if(nbInt >1)
        Nb.ChangeValue(1,4)++;
    }
    return;  
  }
  if (aCurve->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
    Handle(Geom2d_BezierCurve) Bs = Handle(Geom2d_BezierCurve)::DownCast(aCurve); 
    if(Bs->Degree() > Degree) Nb.ChangeValue(2,1)++;
    if(Bs->IsRational() > ((unsigned int)MaxSeg) )  Nb.ChangeValue(2,3)++;
    if(aCont < theCont)
    {

      Nb.ChangeValue(2,4)++;
    }
    return;
  }
  else
    Nb.ChangeValue(1,5)++;
  return;
}

static void expcurv(const Handle(Geom_Curve)& aCurve, TColStd_Array2OfInteger& Nb, const Standard_Integer Degree,
                    const Standard_Integer MaxSeg,
                    const Standard_Integer theCont,
                    Standard_Real theFirst,
                    Standard_Real theLast)   
{
  if(aCurve.IsNull()) return;
  if (aCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
    Handle(Geom_TrimmedCurve) tmp = Handle(Geom_TrimmedCurve)::DownCast (aCurve);
    Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
    expcurv(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast);
    return;
  }
  if (aCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
    Handle(Geom_OffsetCurve) tmp = Handle(Geom_OffsetCurve)::DownCast (aCurve);
    Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
    expcurv(BasCurve,Nb,Degree,MaxSeg,theCont,theFirst,theLast);
    return;
  }

  Standard_Integer aCont = ContToInteger(aCurve->Continuity()); 
  if(aCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) {
    Handle(Geom_BSplineCurve) Bs = Handle(Geom_BSplineCurve)::DownCast(aCurve);
    if(Bs->Degree() > Degree) Nb.ChangeValue(1,1)++; 
    if(Bs->NbKnots() -1 > MaxSeg)  Nb.ChangeValue(1,2)++;
    if(Bs->IsRational())  Nb.ChangeValue(1,3)++;
    if(aCont < theCont && Bs->NbKnots() > 2) 
    {
      TColStd_Array1OfReal aKnots(1,Bs->NbKnots());
      Bs->Knots(aKnots);
      Standard_Integer nbInt = ckeckKnots(aKnots,theFirst,theLast);
      if(nbInt >1)
        Nb.ChangeValue(1,4)++;
    }
    return;  
  }
  if (aCurve->IsKind(STANDARD_TYPE(Geom_BezierCurve))) {
    Handle(Geom_BezierCurve) Bs = Handle(Geom_BezierCurve)::DownCast(aCurve); 
    if(Bs->Degree() > Degree) Nb.ChangeValue(2,1)++;
    if(Bs->IsRational() > ((unsigned int)MaxSeg) )  Nb.ChangeValue(2,3)++;
    if(aCont < theCont) 
      Nb.ChangeValue(2,4)++;
    return;
  }
  else
    Nb.ChangeValue(1,5)++;
  return;
}
static void expsurf(const Handle(Geom_Surface)& aSurface, TColStd_Array2OfInteger& NbSurf, const Standard_Integer Degree,
                    const Standard_Integer MaxSeg,
                    const Standard_Integer theCont)   
{
  if (aSurface.IsNull()) return;
  if (aSurface->IsKind(STANDARD_TYPE(Geom_SweptSurface))) {      
    Handle(Geom_SweptSurface) aSurf = Handle(Geom_SweptSurface)::DownCast(aSurface);
    Handle(Geom_Curve) BasCurve = aSurf->BasisCurve();
    expcurv(BasCurve,NbSurf,Degree,MaxSeg,theCont,BasCurve->FirstParameter(),
      BasCurve->LastParameter()); 
    return;  
  }
  if (aSurface->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
    Handle(Geom_RectangularTrimmedSurface) aSurf = Handle(Geom_RectangularTrimmedSurface)::DownCast(aSurface);
    Handle(Geom_Surface) theSurf = aSurf->BasisSurface();
    expsurf(theSurf,NbSurf,Degree,MaxSeg,theCont);
    return;
  }
  if(aSurface->IsKind(STANDARD_TYPE(Geom_OffsetSurface))) { 
    Handle(Geom_OffsetSurface) aSurf = Handle(Geom_OffsetSurface)::DownCast(aSurface);
    Handle(Geom_Surface) theSurf = aSurf->BasisSurface();
    expsurf(theSurf,NbSurf,Degree,MaxSeg,theCont);
    return;

  }
  Standard_Integer aCont = ContToInteger(aSurface->Continuity());

  if (aSurface->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) {
    Handle(Geom_BSplineSurface) BS = Handle(Geom_BSplineSurface)::DownCast(aSurface); 
    if(BS->UDegree() > Degree || BS->VDegree() > Degree) NbSurf.ChangeValue(1,1)++;
    if(((BS->NbUKnots()-1) * (BS->NbVKnots()-1)) >MaxSeg) NbSurf.ChangeValue(1,2)++;
    if(BS->IsURational() || BS->IsVRational()) NbSurf.ChangeValue(1,3)++;
    if(aCont < theCont)
      NbSurf.ChangeValue(1,4)++;
    return;
  }
  if (aSurface->IsKind(STANDARD_TYPE(Geom_BezierSurface))) { 
    Handle(Geom_BezierSurface) BS = Handle(Geom_BezierSurface)::DownCast(aSurface);
    if(BS->UDegree() > Degree || BS->VDegree() > Degree) NbSurf.ChangeValue(2,1)++;
    if(BS->IsURational() || BS->IsVRational()) NbSurf.ChangeValue(2,3)++;
    if(aCont < theCont)
      NbSurf.ChangeValue(2,4)++;
    return;
  }
  if(aSurface->IsKind(STANDARD_TYPE(Geom_Plane)))
  {
    NbSurf.ChangeValue(1,5)++;
  }
  else
    NbSurf.ChangeValue(2,5)++;
}

static Standard_Integer expshape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if (argc <4) {
    di << "Incorrect number of arguments. Must be 3" << "\n";
    return 1 /* Error */;
  }
  Standard_CString arg2 = argv[1];
  TopoDS_Shape Shape = DBRep::Get(arg2);
  Standard_Integer Degree = atoi(argv[2]);
  Standard_Integer MaxSeg = atoi(argv[3]);
  GeomAbs_Shape aCont3 = GeomAbs_C0;
  Standard_Integer k = 4;
  if( argc > k)
  {
    if(strcmp(argv[k],"C0") == 0)  aCont3 = GeomAbs_C0;
    else if (strcmp(argv[k],"C1") == 0)  aCont3 = GeomAbs_C1;
    else if (strcmp(argv[k],"C2") == 0)  aCont3 = GeomAbs_C2;
    else if (strcmp(argv[k],"C3") == 0)  aCont3 = GeomAbs_C3;
    else if (strcmp(argv[k],"CN") == 0)  aCont3 = GeomAbs_CN;
    else if (strcmp(argv[k],"G1") == 0)  aCont3 = GeomAbs_C0;
    else if (strcmp(argv[k],"G2") == 0)  aCont3 = GeomAbs_C1;
    else {
      di<< "Invalid argument Cont3e" << "\n"; return 1; }


  }

  Standard_Integer aCont = ContToInteger(aCont3);
  TColStd_Array2OfInteger NbSurf(1,2,1,5);
  TColStd_Array2OfInteger NbCurv(1,2,1,5);
  TColStd_Array2OfInteger NbCurv2d(1,2,1,5);
  Standard_Integer nbSeam =0;
  NbSurf.Init(0);
  NbCurv.Init(0);
  NbCurv2d.Init(0);
  if (Shape.IsNull()) { di << "Shape unknown: " << arg2 << "\n"; return 1 /* Error */; }
  TopExp_Explorer Ex;
  
  Standard_Integer nbF =1;
  for (Ex.Init(Shape,TopAbs_FACE); Ex.More(); Ex.Next(),nbF++) {
    TopoDS_Face F = TopoDS::Face(Ex.Current());
    TopLoc_Location L;
    Handle(Geom_Surface) aSurface = BRep_Tool::Surface(F,L);
    expsurf(aSurface,NbSurf,Degree,MaxSeg,aCont);
    TopExp_Explorer exp;

    Standard_Integer nbE = 1;
    for(exp.Init(F,TopAbs_EDGE); exp.More(); exp.Next(),nbE++) {
      TopoDS_Edge E = TopoDS::Edge(exp.Current());
      if(BRep_Tool::IsClosed(E,F))
        nbSeam++;
      Standard_Real First,Last;
      Handle(Geom_Curve) aCurve = BRep_Tool::Curve(E,L,First, Last);
      expcurv(aCurve,NbCurv,Degree,MaxSeg,aCont,First, Last);
      Standard_Real First2d,Last2d;
      Handle(Geom2d_Curve) aCurve2d = BRep_Tool::CurveOnSurface(E,F,First2d,Last2d);
      expcurv2d(aCurve2d,NbCurv2d,Degree,MaxSeg,aCont,First2d,Last2d);
    }
  }
  di<<"Number of seam edges - "<<nbSeam<<"\n";
  //if(NbSurf.Value(1,1) !=0)
  di<< "Number of BSpline surfaces with degree more then "<< Degree << " - " <<NbSurf.Value(1,1)<<"\n";
  //if(NbSurf.Value(1,2) !=0)
  di<< "Number of BSpline surfaces with number of spans more then "<< MaxSeg << " - " <<NbSurf.Value(1,2)<<"\n";
  //if(NbSurf.Value(1,3) !=0)
  di<< "Number of Rational BSpline surfaces " << NbSurf.Value(1,3)<<"\n";
  //if(NbSurf.Value(1,4) !=0)
  di<< "Number of BSpline surfaces with continuity less than specified - " << NbSurf.Value(1,4)<<"\n";
  //if(NbSurf.Value(2,1) !=0)
  di<< "Number of Bezier surfaces with degree more then "<< Degree << " - " <<NbSurf.Value(2,1)<<"\n";
  //if(NbSurf.Value(2,3) !=0)
  di<< "Number of Rational Bezier surfaces " << " - " <<NbSurf.Value(2,3)<<"\n";
  //if(NbSurf.Value(2,4) !=0)
  di<< "Number of Bezier surfaces with continuity less than specified - " << NbSurf.Value(2,4)<<"\n";

  //if(NbSurf.Value(1,5) !=0)
  di<< "Number of Planes - " << NbSurf.Value(1,5)<<"\n";
  //if(NbSurf.Value(2,5) !=0)
  di<< "Number of other surfaces - " << NbSurf.Value(2,5)<<"\n";

  //if(NbCurv.Value(1,1) !=0)
  di<< "Number of BSpline curves with degree more then "<< Degree << " - " <<NbCurv.Value(1,1)<<"\n";
  //if(NbCurv.Value(1,2) !=0)
  di<< "Number of BSpline curves with number of spans more then - "<< MaxSeg << " - " <<NbCurv.Value(1,2)<<"\n";
  //if(NbCurv.Value(1,3) !=0)
  di<< "Number of Rational BSpline curves " << NbCurv.Value(1,3)<<"\n";
  //if(NbCurv.Value(1,4) !=0)
  di<< "Number of  BSpline curves with less continuity - " << NbCurv.Value(1,4)<<"\n";
  //if(NbCurv.Value(2,1) !=0)
  di<< "Number of Bezier curves with degree more then - "<< Degree << " - " <<NbCurv.Value(2,1)<<"\n";
  //if(NbCurv.Value(2,3) !=0)
  di<< "Number of Rational Bezier curves " << " - " <<NbCurv.Value(2,3)<<"\n"; 
  //if(NbCurv.Value(2,4) !=0)
  di<< "Number of  Bezier curves with less continuity - " << NbCurv.Value(2,4)<<"\n";

  //if(NbCurv.Value(1,5) !=0)
  di<< "Number of  other curves - " << NbCurv.Value(1,5)<<"\n";

  //if(NbCurv2d.Value(1,1) !=0)
  di<< "Number of BSpline pcurves with degree more then - "<< Degree << " - " <<NbCurv2d.Value(1,1)<<"\n";
  //if(NbCurv2d.Value(1,2) !=0)
  di<< "Number of BSpline pcurves with number of spans more then "<< MaxSeg << " - " <<NbCurv2d.Value(1,2)<<"\n";
  //if(NbCurv2d.Value(1,3) !=0)
  di<< "Number of Rational BSpline pcurves - " << NbCurv2d.Value(1,3)<<"\n";
  // if(NbCurv2d.Value(1,4) !=0)
  di<< "Number of  BSpline pcurves with less continuity - " << NbCurv2d.Value(1,4)<<"\n";
  //if(NbCurv2d.Value(2,1) !=0)
  di<< "Number of Bezier pcurves with degree more then "<< Degree <<" - " <<" - " <<NbCurv2d.Value(2,1)<<"\n";
  //if(NbCurv2d.Value(2,3) !=0)
  di<< "Number of Rational Bezier pcurves " << " - " <<NbCurv2d.Value(2,3)<<"\n";
  //if(NbCurv2d.Value(2,4) !=0)
  di<< "Number of  Bezier pcurves with less continuity - " << NbCurv2d.Value(2,4)<<"\n";

  //if(NbCurv2d.Value(1,5) !=0)
  di<< "Number of  other pcurves - " << NbCurv2d.Value(1,5)<<"\n";
  return 0;
}

static Standard_Integer scaleshape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if (argc !=4) {
    di << "Incorrect number of arguments. Must be 4" << "\n";
    return 1 /* Error */;
  }
  Standard_CString arg2 = argv[2];
  TopoDS_Shape Shape = DBRep::Get(arg2);
  if (Shape.IsNull()) { di << "Shape unknown: " << arg2 << "\n"; return 1 /* Error */; }

  TopoDS_Shape result = ShapeCustom::ScaleShape (Shape, atof(argv[3]));
  if (result.IsNull()) { di << "NO RESULT" << "\n"; return 1; }
  else if (result == Shape) { di << "NO MODIFICATIONS" << "\n"; return 0; }
  DBRep::Set (argv[1],result);
  return 0;
}
static Standard_Integer BSplRes(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if (argc < 11) {
    di << "Incorrect number of arguments. Must be 10" << "\n";
    return 1 /* Error */;
  }
  Standard_CString arg2 = argv[2];
  TopoDS_Shape Shape = DBRep::Get(arg2);
  if (Shape.IsNull()) { di << "Shape unknown: " << arg2 << "\n"; return 1 /* Error */; }
  GeomAbs_Shape aCont3;
  if(strcmp(argv[7],"C0") == 0)  aCont3 = GeomAbs_C0;
  else if (strcmp(argv[7],"C1") == 0)  aCont3 = GeomAbs_C1;
  else if (strcmp(argv[7],"C2") == 0)  aCont3 = GeomAbs_C2;
  else if (strcmp(argv[7],"C3") == 0)  aCont3 = GeomAbs_C3;
  else if (strcmp(argv[7],"CN") == 0)  aCont3 = GeomAbs_CN;
  else if (strcmp(argv[7],"G1") == 0)  aCont3 = GeomAbs_C0;
  else if (strcmp(argv[7],"G2") == 0)  aCont3 = GeomAbs_C1;
  else {
    di<< "Invalid argument Cont3e" << "\n"; return 1; }
  GeomAbs_Shape aCont2;
  if(strcmp(argv[8],"C0") == 0)  aCont2 = GeomAbs_C0;
  else if (strcmp(argv[8],"C1") == 0)  aCont2 = GeomAbs_C1;
  else if (strcmp(argv[8],"C2") == 0)  aCont2 = GeomAbs_C2;
  else if (strcmp(argv[8],"C3") == 0)  aCont2 = GeomAbs_C3;
  else if (strcmp(argv[8],"CN") == 0)  aCont2 = GeomAbs_CN;
  else if (strcmp(argv[8],"G1") == 0)  aCont2 = GeomAbs_C0;
  else if (strcmp(argv[8],"G2") == 0)  aCont2 = GeomAbs_C1;
  else {
    di<< "Invalid argument Cont3e" << "\n"; return 1; }

  Handle(ShapeCustom_RestrictionParameters) aParameters = new ShapeCustom_RestrictionParameters;
  TopoDS_Shape result = ShapeCustom::BSplineRestriction (Shape, atof(argv[3]), atof(argv[4]), atoi(argv[5]),atoi(argv[6]),aCont3,aCont2,(Standard_Boolean) atoi(argv[9]),(Standard_Boolean) atoi(argv[10]),aParameters);
  if (result.IsNull()) { di << "NO RESULT" << "\n"; return 1; }
  else if (result == Shape) { 
    di << "NO MODIFICATIONS" << "\n";
    DBRep::Set (argv[1],result); return 0; 
  }
  ShapeFix::SameParameter(result,Standard_False);

  DBRep::Set (argv[1],result);
  return 0;
}

static Standard_Integer convtorevol(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
{
  if (argc < 3) { di<<"Convert surfaces to revolution: convtorevol result shape"<<"\n"; return 1; }

  Standard_CString arg1 = argv[1];
  Standard_CString arg2 = argv[2];
  TopoDS_Shape Shape = DBRep::Get(arg2);
  if (Shape.IsNull()) { di<<"Shape unknown : "<<arg2<<"\n"; return 1; }

  TopoDS_Shape result = ShapeCustom::ConvertToRevolution (Shape);
  if (result.IsNull()) { di<<"NO RESULT"<<"\n"; return 1; }
  else if (result == Shape) { di<<"No modif"<<"\n"; return 0; }
  di<<"ConvertToRevolution -> Result : "<<arg1<<"\n";
  DBRep::Set (arg1,result);
  return 0; // Done
}  

//======================================================================
//function : InitCommands
//purpose  : 
//=======================================================================

void SWDRAW_ShapeCustom::InitCommands(Draw_Interpretor& theCommands) 
{
  static Standard_Integer initactor = 0;
  if (initactor) return;  initactor = 1;

  Standard_CString g = SWDRAW::GroupName();

  theCommands.Add ("directfaces", "directfaces result shape", __FILE__, directfaces, g);
  theCommands.Add ("expshape", "expshape shape maxdegree maxseg [min_continuity]", __FILE__, expshape, g);
  theCommands.Add ("scaleshape", "scaleshape result shape scale", __FILE__, scaleshape, g);
  theCommands.Add ("bsplres", "BSplineRestriction result shape tol3d tol2d reqdegree reqnbsegments continuity3d continuity2d PriorDeg RationalConvert", __FILE__,BSplRes, g);
  theCommands.Add ("convtorevol", "convtorevol result shape", __FILE__, convtorevol, g);
}