0031172: Unexpected result of BRepTools::OuterWire()
[occt.git] / src / GeomliteTest / GeomliteTest_SurfaceCommands.cxx
CommitLineData
b311480e 1// Created on: 1993-08-12
2// Created by: Bruno DUMORTIER
3// Copyright (c) 1993-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//
d5f74e42 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
973c2be1 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
7fd59977 17#include <GeomliteTest.hxx>
18#include <DrawTrSurf.hxx>
19#include <Draw.hxx>
20#include <Draw_Interpretor.hxx>
21#include <Draw_Appli.hxx>
22#include <Draw_Display.hxx>
23
24#include <GeomAbs_SurfaceType.hxx>
25#include <GeomAbs_IsoType.hxx>
26#include <GeomAbs_Shape.hxx>
27
28#include <Geom_Plane.hxx>
29#include <Geom_CylindricalSurface.hxx>
30#include <Geom_ConicalSurface.hxx>
31#include <Geom_SphericalSurface.hxx>
32#include <Geom_ToroidalSurface.hxx>
33#include <Geom_BezierSurface.hxx>
34#include <Geom_BSplineSurface.hxx>
35#include <Geom_SurfaceOfLinearExtrusion.hxx>
36#include <Geom_SurfaceOfRevolution.hxx>
37#include <Geom_RectangularTrimmedSurface.hxx>
38#include <Geom_OffsetSurface.hxx>
39#include <Geom_Surface.hxx>
40
41#include <Geom_TrimmedCurve.hxx>
42#include <Geom_OffsetCurve.hxx>
43#include <Geom_BezierCurve.hxx>
44#include <Geom_BSplineCurve.hxx>
45
46#include <Geom2d_TrimmedCurve.hxx>
47#include <Geom2d_OffsetCurve.hxx>
48
49#include <GeomAdaptor_Surface.hxx>
7fd59977 50#include <GeomAdaptor_Curve.hxx>
51#include <Geom2dAdaptor_Curve.hxx>
52
53#include <TColGeom_Array2OfBezierSurface.hxx>
54#include <TColgp_Array1OfPnt.hxx>
55#include <TColgp_Array2OfPnt.hxx>
56#include <TColStd_Array1OfReal.hxx>
57#include <TColStd_Array2OfReal.hxx>
58#include <TColStd_Array1OfInteger.hxx>
59#include <TColStd_HArray1OfInteger.hxx>
60#include <TColStd_HArray1OfReal.hxx>
61#include <TColStd_HArray2OfReal.hxx>
62
63#include <ElSLib.hxx>
64#include <ElCLib.hxx>
65#include <Precision.hxx>
66#include <Convert_CompBezierCurvesToBSplineCurve.hxx>
67#include <GeomConvert.hxx>
68#include <GeomConvert_BSplineCurveToBezierCurve.hxx>
69#include <GeomConvert_BSplineSurfaceToBezierSurface.hxx>
70#include <GeomConvert_CompBezierSurfacesToBSplineSurface.hxx>
71#include <Geom2dConvert.hxx>
72#include <Geom2dConvert_BSplineCurveToBezierCurve.hxx>
73#include <GeomLProp_SLProps.hxx>
74
75
76#include <DrawTrSurf_BezierSurface.hxx>
77#include <DrawTrSurf_BSplineSurface.hxx>
78#include <GeomConvert_ApproxSurface.hxx>
79#include <GeomLib_Tool.hxx>
80#include <TopoDS_Shape.hxx>
81#include <DBRep.hxx>
ec357c5c 82#include <Geom_Curve.hxx>
d99f0355 83#include <Message.hxx>
7fd59977 84
7fd59977 85#include <stdio.h>
03155c18 86#ifdef _WIN32
7fd59977 87Standard_IMPORT Draw_Viewer dout;
88#endif
7fd59977 89
90
91
92
93//=======================================================================
94//function : compute min max radius of curvature on a surface
95//purpose :
96//=======================================================================
97static Standard_Integer surface_radius (Draw_Interpretor& di,
98 Standard_Integer n,
99 const char** a)
100{
101 Standard_Integer report_curvature = 0 ;
102 Standard_Real UParameter,VParameter,radius,tolerance = 1.0e-7 ;
103
104 if (n < 4) return 1;
105 if (n >= 6) report_curvature = 1 ;
106
91322f44 107 UParameter = Draw::Atof(a[2]);
108 VParameter = Draw::Atof(a[3]);
7fd59977 109 Handle(Geom_Surface) SurfacePtr = DrawTrSurf::GetSurface(a[1]);
110 if (!SurfacePtr.IsNull()) {
111 GeomLProp_SLProps myProperties(SurfacePtr,
112 UParameter,
113 VParameter,
114 2,
115 tolerance);
116 if (myProperties.IsCurvatureDefined()) {
117 radius = myProperties.MinCurvature();
118
119 if (report_curvature) Draw::Set(a[4],radius);
120
121 if (Abs(radius) > tolerance) {
122 radius = 1.0e0/ radius ;
123 di << "Min Radius of Curvature : " << radius << "\n";
124 }
125 else {
586db386 126 di << "Min Radius of Curvature : infinite\n";
7fd59977 127 }
128
129 radius = myProperties.MaxCurvature();
130 if (report_curvature) Draw::Set(a[5],radius);
131 if (Abs(radius) > tolerance) {
132 radius = 1.0e0/ radius;
133 di << "Max Radius of Curvature : " << radius << "\n";
134 }
135 else
586db386 136 di << "Min Radius of Curvature : infinite\n";
7fd59977 137 }
138 else {
586db386 139 di << "Curvature not defined.\n";
7fd59977 140 }
141 }
142 else {
143 return 1;
144 }
145 return 0;
146}
147
148
149//=======================================================================
150//function : anasurface
151//purpose :
152//=======================================================================
153
154static Standard_Integer anasurface (Draw_Interpretor& ,
155 Standard_Integer n,
156 const char** a)
157{
158 if (n < 2) return 1;
159 gp_Ax3 loc;
160
161 Standard_Integer i;
162
163 if (n < 5) {
164 loc = gp_Ax3(gp_Pnt(0,0,0),gp_Dir(0,0,1),gp_Dir(1,0,0));
165 i = 2;
166 }
167 else if (n < 8) {
91322f44 168 loc = gp_Ax3(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
7fd59977 169 gp_Dir(0,0,1),gp_Dir(1,0,0));
170 i = 5;
171 }
172 else if (n < 11) {
91322f44 173 loc = gp_Ax3(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
174 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])));
7fd59977 175 i = 8;
176 }
177 else if (n < 14) {
91322f44 178 loc = gp_Ax3(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
179 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
180 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10])));
7fd59977 181 i = 11;
182 }
183 else
184 return 1;
185
186 Handle(Geom_Geometry) result;
187
188 if (!strcasecmp(a[0],"plane")) {
189 Handle(Geom_Plane) C = new Geom_Plane(loc);
190 result = C;
191 }
192 else {
193 if (i >= n) return 1;
91322f44 194 Standard_Real par1 = Draw::Atof(a[i]);
7fd59977 195
196 if (!strcasecmp(a[0],"cylinder")) {
197 Handle(Geom_CylindricalSurface) C =
198 new Geom_CylindricalSurface(loc,par1);
199 result = C;
200 }
201
202 else if (!strcasecmp(a[0],"sphere")) {
203 Handle(Geom_SphericalSurface) C =
204 new Geom_SphericalSurface(loc,par1);
205 result = C;
206 }
207
208 else {
209 if (i+1 >= n) return 1;
91322f44 210 Standard_Real par2 = Draw::Atof(a[i+1]);
7fd59977 211
212 if (!strcasecmp(a[0],"cone")) {
c6541a0c 213 par1 *= (M_PI / 180.0);
7fd59977 214 Handle(Geom_ConicalSurface) C =
215 new Geom_ConicalSurface(loc,par1,par2);
216 result = C;
217 }
218
219 else if (!strcasecmp(a[0],"torus")) {
220 Handle(Geom_ToroidalSurface) C =
221 new Geom_ToroidalSurface(loc,par1,par2);
222 result = C;
223 }
224 }
225 }
226
227 DrawTrSurf::Set(a[1],result);
228 return 0;
229}
230
231
232//=======================================================================
233//function : polesurface
234//purpose :
235//=======================================================================
236
237static Standard_Integer polesurface (Draw_Interpretor& , Standard_Integer n, const char** a)
238{
239 Standard_Integer k,j,i;
240
241
242 if (n < 4) return 1;
243
244 if (!strcasecmp(a[0],"beziersurf")) {
245
91322f44 246 Standard_Integer nup = Draw::Atoi(a[2]);
247 Standard_Integer nvp = Draw::Atoi(a[3]);
7fd59977 248 if (nup * nvp == 0) return 1;
249
250 i = (n - 4) / (nup * nvp);
251 if (i < 3 || i > 4) return 1;
252 Standard_Boolean hasw = i == 4;
253
254 TColgp_Array2OfPnt poles(1,nup,1,nvp);
255 TColStd_Array2OfReal weights(1,nup,1,nvp);
256
257 k = 4;
258 for (j = 1; j <= nvp; j++) {
259 for (i = 1; i <= nup; i++) {
91322f44 260 poles(i, j).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]),Draw::Atof(a[k+2]));
7fd59977 261 k += 3;
262 if (hasw) {
91322f44 263 weights(i, j) = Draw::Atof(a[k]);
7fd59977 264 k++;
265 }
266 }
267 }
268
269 Handle(Geom_BezierSurface) result;
270 if (hasw)
271 result = new Geom_BezierSurface(poles,weights);
272 else
273 result = new Geom_BezierSurface(poles);
274
275 DrawTrSurf::Set(a[1],result);
276 }
277
278 else {
91322f44 279 Standard_Integer udeg = Draw::Atoi(a[2]);
280 Standard_Integer nbuk = Draw::Atoi(a[3]);
7fd59977 281
282 Standard_Boolean uper = (*a[0] == 'u') || (*(a[0]+1) == 'u');
283 Standard_Boolean vper = (*a[0] == 'v') || (*(a[0]+1) == 'v');
284
285 TColStd_Array1OfReal uk (1, nbuk);
286 TColStd_Array1OfInteger umult(1, nbuk);
287 k = 4;
288 Standard_Integer SigmaU = 0;
289 for (i = 1; i<=nbuk; i++) {
91322f44 290 uk( i) = Draw::Atof(a[k]);
7fd59977 291 k++;
91322f44 292 umult( i) = Draw::Atoi(a[k]);
7fd59977 293 SigmaU += umult(i);
294 k++;
295 }
296
91322f44 297 Standard_Integer vdeg = Draw::Atoi(a[k]);
7fd59977 298 k++;
91322f44 299 Standard_Integer nbvk = Draw::Atoi(a[k]);
7fd59977 300 k++;
301
302 TColStd_Array1OfReal vk (1, nbvk);
303 TColStd_Array1OfInteger vmult(1, nbvk);
304 Standard_Integer SigmaV = 0;
305 for (i = 1; i<=nbvk; i++) {
91322f44 306 vk( i) = Draw::Atof(a[k]);
7fd59977 307 k++;
91322f44 308 vmult( i) = Draw::Atoi(a[k]);
7fd59977 309 SigmaV += vmult(i);
310 k++;
311 }
312
313 Standard_Integer nup,nvp;
314 if (uper)
315 nup = SigmaU - umult(nbuk);
316 else
317 nup = SigmaU - udeg -1;
318 if (vper)
319 nvp = SigmaV - vmult(nbvk);
320 else
321 nvp = SigmaV - vdeg -1;
322 TColgp_Array2OfPnt poles (1, nup, 1, nvp);
323 TColStd_Array2OfReal weights(1, nup, 1, nvp);
324
325 for (j = 1; j <= nvp; j++) {
326 for (i = 1; i <= nup; i++) {
91322f44 327 poles(i, j).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]),Draw::Atof(a[k+2]));
7fd59977 328 k += 3;
91322f44 329 weights(i, j) = Draw::Atof(a[k]);
7fd59977 330 k++;
331 }
332 }
333
334 Handle(Geom_BSplineSurface) result =
335 new Geom_BSplineSurface(poles, weights,
336 uk , vk ,
337 umult, vmult ,
338 udeg , vdeg ,
339 uper , vper );
340
341 DrawTrSurf::Set(a[1],result);
342 }
343
344 return 0;
345}
346
347//=======================================================================
348//function : algosurface
349//purpose :
350//=======================================================================
351
352static Standard_Integer algosurface (Draw_Interpretor& , Standard_Integer n, const char** a)
353{
354 if (n < 5) return 1;
355
356 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
357 if (GC.IsNull()) return 1;
358
359 gp_Dir D;
360 gp_Pnt P;
361
362 if (!strcasecmp(a[0],"extsurf")) {
91322f44 363 D.SetCoord(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 364 Handle(Geom_SurfaceOfLinearExtrusion) result =
365 new Geom_SurfaceOfLinearExtrusion(GC,D);
366
367 DrawTrSurf::Set(a[1],result);
368
369 }
370 else if (!strcasecmp(a[0],"revsurf")) {
371 if (n<8) return 1;
91322f44 372 P.SetCoord(Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
373 D.SetCoord(Draw::Atof(a[6]),Draw::Atof(a[7]),Draw::Atof(a[8]));
7fd59977 374
375 Handle(Geom_SurfaceOfRevolution) result =
376 new Geom_SurfaceOfRevolution(GC,gp_Ax1(P,D));
377
378 DrawTrSurf::Set(a[1],result);
379
380 }
381
382 return 0;
383
384}
385
386
387
388//=======================================================================
389//function : trimming
390//purpose :
391//=======================================================================
392
393static Standard_Integer trimming (Draw_Interpretor& ,
394 Standard_Integer n, const char** a)
395{
396 if (n < 3) return 1;
397
398 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
399 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[2]);
400 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
401
402 if (n == 3) {
403 if (!GC.IsNull()) {
404 Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(GC);
405 if (!T.IsNull()) GC = T->BasisCurve();
406 DrawTrSurf::Set(a[1],GC);
407 }
408 else if (!GC2d.IsNull()) {
409 Handle(Geom2d_TrimmedCurve) T = Handle(Geom2d_TrimmedCurve)::DownCast(GC2d);
410 if (!T.IsNull()) GC2d = T->BasisCurve();
411 DrawTrSurf::Set(a[1],GC2d);
412 }
413 else if (!GS.IsNull()) {
414 Handle(Geom_RectangularTrimmedSurface) T = Handle(Geom_RectangularTrimmedSurface)::DownCast(GS);
415 if (!T.IsNull()) GS = T->BasisSurface();
416 DrawTrSurf::Set(a[1],GS);
417 }
418 return 0;
419 }
420
421 if (n < 5) return 1;
422
91322f44 423 Standard_Real u1 = Draw::Atof(a[3]);
424 Standard_Real u2 = Draw::Atof(a[4]);
7fd59977 425
c5b42a1a 426 Standard_Real v1 = 0., v2 = 0.;
427 Standard_Boolean USense = Standard_True, VSense = Standard_True;
428
7fd59977 429 Handle(Geom_Geometry) result;
430 Handle(Geom2d_Curve) result2d;
431
432 if (!strcasecmp(a[0],"trim")) {
433 if (!GS.IsNull()) {
434 if (n<7) return 1;
c5b42a1a 435 v1 = Draw::Atof(a[5]);
436 v2 = Draw::Atof(a[6]);
437 if (n > 7)
438 {
439 USense = *a[7] != '0';
440 VSense = *a[8] != '0';
441 }
7fd59977 442 result =
c5b42a1a 443 new Geom_RectangularTrimmedSurface(GS, u1, u2, v1, v2, USense, VSense);
7fd59977 444 }
445 else if (!GC.IsNull()) {
c5b42a1a 446 if (n>5)
447 {
448 USense = *a[5] != '0';
449 }
450 result = new Geom_TrimmedCurve(GC, u1, u2, USense);
7fd59977 451 }
452 else if (!GC2d.IsNull()) {
c5b42a1a 453 if (n > 5)
454 {
455 USense = *a[5] != '0';
456 }
457 result2d = new Geom2d_TrimmedCurve(GC2d, u1, u2, USense);
7fd59977 458 }
459 else
460 return 1;
461 }
462 else {
463 if (GS.IsNull()) return 1;
c5b42a1a 464 Standard_Boolean Utrim = !strcasecmp(a[0], "trimu");
465 if (n > 5)
466 USense = *a[5] != '0';
467 result = new Geom_RectangularTrimmedSurface(GS, u1, u2, Utrim, USense);
7fd59977 468 }
469
470 if (!result.IsNull())
471 DrawTrSurf::Set(a[1], result);
472 else
473 DrawTrSurf::Set(a[1],result2d);
474
475 return 0;
476}
477
478//=======================================================================
479//function : converting
480//purpose :
481//=======================================================================
482
483static Standard_Integer converting(Draw_Interpretor& , Standard_Integer n, const char ** a)
484{
485 if ( n < 3) return 1;
486
487 Convert_ParameterisationType
488 Parameterisation = Convert_TgtThetaOver2 ;
489 if (strcmp(a[n-1], "qa") == 0) {
490 Parameterisation = Convert_QuasiAngular ;
491 }
492 else if (strcmp(a[n-1], "c1") == 0) {
493 Parameterisation = Convert_RationalC1 ;
494 }
495 else if (strcmp (a[n-1], "s1") == 0) {
496 Parameterisation = Convert_TgtThetaOver2_1 ;
497 }
498 else if (strcmp (a[n-1], "s2") == 0) {
499 Parameterisation = Convert_TgtThetaOver2_2;
500 }
501 else if (strcmp (a[n-1], "s3") == 0) {
502 Parameterisation = Convert_TgtThetaOver2_3 ;
503 }
504 else if (strcmp (a[n-1], "s4") == 0) {
505 Parameterisation = Convert_TgtThetaOver2_4 ;
506 }
507 else if (strcmp (a[n-1], "po") == 0) {
508 Parameterisation = Convert_Polynomial;
509 }
510
511 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
512 if ( GC.IsNull()) {
513 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
514 if ( GS.IsNull()) {
515 Handle(Geom2d_Curve) G2d = DrawTrSurf::GetCurve2d(a[2]);
516 if ( G2d.IsNull()) {
517 return 1;
518 }
519 else {
520 G2d = Geom2dConvert::CurveToBSplineCurve(G2d,
521 Parameterisation);
522 DrawTrSurf::Set(a[1], G2d);
523 }
524 }
525 else {
526 GS = GeomConvert::SurfaceToBSplineSurface( GS);
527 DrawTrSurf::Set(a[1], GS);
528 }
529 }
530 else {
531 GC = GeomConvert::CurveToBSplineCurve( GC,
532 Parameterisation);
533 DrawTrSurf::Set(a[1], GC);
534 }
535
536 return 0;
537}
538
539
540//=======================================================================
541//function : tobezier
542//purpose :
543//=======================================================================
544
545static Standard_Integer tobezier(Draw_Interpretor& di,
546 Standard_Integer n, const char** a)
547{
548 if ( n < 3) return 1;
549 Standard_Integer i,j,NbU,NbV,NbArc;
550 char* name = new char[100];
551
552 Handle(Geom2d_BSplineCurve) C2d =
553 DrawTrSurf::GetBSplineCurve2d(a[2]);
554 if ( C2d.IsNull()) {
555 Handle(Geom_BSplineCurve) C3d =
556 DrawTrSurf::GetBSplineCurve(a[2]);
557 if ( C3d.IsNull()) {
558 Handle(Geom_BSplineSurface) S =
559 DrawTrSurf::GetBSplineSurface(a[2]);
560 if ( S.IsNull()) return 1;
561 if (n == 7) {
562 Standard_Real U1, U2, V1, V2;
91322f44 563 U1 = Draw::Atof(a[3]);
564 U2 = Draw::Atof(a[4]);
565 V1 = Draw::Atof(a[5]);
566 V2 = Draw::Atof(a[6]);
7fd59977 567 GeomConvert_BSplineSurfaceToBezierSurface
568 Conv(S, U1, U2, V1, V2, Precision::PConfusion());
569 NbU = Conv.NbUPatches();
570 NbV = Conv.NbVPatches();
586db386 571 di << NbU << " X " << NbV << " patches in the result\n";
7fd59977 572 for (i = 1; i <= NbU; i++) {
573 for (j = 1; j <= NbV; j++) {
91322f44 574 Sprintf(name,"%s_%i_%i",a[1],i,j);
7fd59977 575 char *temp = name ;
576 DrawTrSurf::Set(temp,Conv.Patch(i,j));
577 }
578 }
579 }
580 else {
581 GeomConvert_BSplineSurfaceToBezierSurface Conv(S);
582 NbU = Conv.NbUPatches();
583 NbV = Conv.NbVPatches();
586db386 584 di << NbU << " X " << NbV << " patches in the result\n";
7fd59977 585 for (i = 1; i <= NbU; i++) {
586 for (j = 1; j <= NbV; j++) {
91322f44 587 Sprintf(name,"%s_%i_%i",a[1],i,j);
7fd59977 588 char *temp = name ;
589 DrawTrSurf::Set(temp,Conv.Patch(i,j));
590 }
591 }
592 }
593 }
594 else {
595 if (n==5) {
596 Standard_Real U1, U2;
91322f44 597 U1 = Draw::Atof(a[3]);
598 U2 = Draw::Atof(a[4]);
7fd59977 599 GeomConvert_BSplineCurveToBezierCurve Conv(C3d, U1, U2,
600 Precision::PConfusion());
601 NbArc = Conv.NbArcs();
586db386 602 di << NbArc << " arcs in the result\n";
7fd59977 603 for (i = 1; i <= NbArc; i++) {
91322f44 604 Sprintf(name,"%s_%i",a[1],i);
7fd59977 605 char *temp = name ;
606 DrawTrSurf::Set(temp,Conv.Arc(i));
607 }
608 }
609 else {
610 GeomConvert_BSplineCurveToBezierCurve Conv(C3d);
611 NbArc = Conv.NbArcs();
586db386 612 di << NbArc << " arcs in the result\n";
7fd59977 613 for (i = 1; i <= NbArc; i++) {
91322f44 614 Sprintf(name,"%s_%i",a[1],i);
7fd59977 615 char *temp = name ;
616 DrawTrSurf::Set(temp,Conv.Arc(i));
617 }
618 }
619 }
620 }
621 else {
622 if (n==5) {
623 Standard_Real U1, U2;
91322f44 624 U1 = Draw::Atof(a[3]);
625 U2 = Draw::Atof(a[4]);
7fd59977 626 Geom2dConvert_BSplineCurveToBezierCurve Conv(C2d, U1, U2,
627 Precision::PConfusion());
628 NbArc = Conv.NbArcs();
586db386 629 di << NbArc << " arcs in the result\n";
7fd59977 630 for (i = 1; i <= NbArc; i++) {
91322f44 631 Sprintf(name,"%s_%i",a[1],i);
7fd59977 632 char *temp = name ;
633 DrawTrSurf::Set(temp,Conv.Arc(i));
634 }
635 }
636 else {
637 Geom2dConvert_BSplineCurveToBezierCurve Conv(C2d);
638 NbArc = Conv.NbArcs();
586db386 639 di << NbArc << " arcs in the result\n";
7fd59977 640 for (i = 1; i <= NbArc; i++) {
91322f44 641 Sprintf(name,"%s_%i",a[1],i);
7fd59977 642 char *temp = name ;
643 DrawTrSurf::Set(temp,Conv.Arc(i));
644 }
645 }
646 }
647
648 return 0;
649}
650
651//=======================================================================
652//function : convbz
653//purpose :
654//=======================================================================
655
656static Standard_Integer convbz(Draw_Interpretor& di,
657 Standard_Integer n, const char** a)
658{
659 if ( n < 4) return 1;
660
661 Standard_Integer ii, jj, kk=0, NbU, NbV;
662 Standard_Real Tol = Precision::Confusion();
663
91322f44 664 NbU = Draw::Atoi(a[2]);
5b111128 665 Handle(Geom_Curve) aCurve (Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(a[3])));
666 if (aCurve.IsNull()) {
7fd59977 667 // Cas Surfacique
91322f44 668 NbV = Draw::Atoi(a[3]);
7fd59977 669 if (n<4+NbU*NbV) {
670 di << "The number of bezier surface have to be " << NbU*NbV << "\n";
671 return 1;
672 }
673 TColGeom_Array2OfBezierSurface BZ(1, NbU, 1, NbV);
674 kk = 4;
675 for (jj=1; jj<=NbV; jj++)
676 for(ii=1;ii<=NbU; ii++) {
677 BZ(ii,jj) =
678 Handle(Geom_BezierSurface)::DownCast(DrawTrSurf::Get(a[kk]));
679 if (BZ(ii,jj).IsNull()) {
586db386 680 di << "the Surface " << kk <<"is not a BezierSurface\n";
7fd59977 681 return 1;
682 }
683 kk++;
684 }
91322f44 685 if (kk<n) Tol = Draw::Atof(a[kk]);
7fd59977 686
687 GeomConvert_CompBezierSurfacesToBSplineSurface Conv(BZ, Tol);
688
689 if (! Conv.IsDone()) {
586db386 690 di << "Convert Not Done\n";
7fd59977 691 return 1;
692 }
693
694 Handle(Geom_BSplineSurface) BSurf =
695 new Geom_BSplineSurface(Conv.Poles()->Array2(),
696 Conv.UKnots()->Array1(),
697 Conv.VKnots()->Array1(),
698 Conv.UMultiplicities()->Array1(),
699 Conv.VMultiplicities()->Array1(),
700 Conv.UDegree(),
701 Conv.VDegree());
702
703 DrawTrSurf::Set(a[1], BSurf);
704 }
705 else { // cas de courbes
706 Convert_CompBezierCurvesToBSplineCurve Conv;
707 Handle(Geom_BezierCurve) BZ;
708 for (ii=1, kk=3; ii<=NbU; ii++,kk++) {
709 BZ = Handle(Geom_BezierCurve)::DownCast(DrawTrSurf::Get(a[kk]));
710 if (BZ.IsNull()) {
586db386 711 di << "the curve " << kk <<"is not a BezierCurve\n";
7fd59977 712 return 1;
713 }
714 TColgp_Array1OfPnt Poles(1, BZ->NbPoles());
715 BZ->Poles(Poles);
716 Conv.AddCurve(Poles);
717 }
718
719 Conv.Perform();
720
721 TColgp_Array1OfPnt Poles(1, Conv.NbPoles());
722 Conv.Poles(Poles);
723 TColStd_Array1OfInteger Mults(1, Conv.NbKnots());
724 TColStd_Array1OfReal Knots(1, Conv.NbKnots());
725 Conv.KnotsAndMults(Knots, Mults);
726 Handle(Geom_BSplineCurve) BS =
727 new (Geom_BSplineCurve) (Poles, Knots, Mults,
728 Conv.Degree());
729 DrawTrSurf::Set(a[1], BS);
730 }
731
732 return 0;
733}
734
735//=======================================================================
736//function : approxsurf
737//purpose : Approximation d'une Surface par une BSpline non rationnelle
738//=======================================================================
739
740
741static Standard_Integer approxsurf(Draw_Interpretor& di, Standard_Integer n, const char** a)
742{
743// " Tolerance (par defaut 0.1mm) "
744 Standard_Real Tol = 1.e-4;
745// " Ordres de continuites : 0, 1 ou 2 (par defaut 1)"
746 GeomAbs_Shape myUCont = GeomAbs_C1, myVCont = GeomAbs_C1;
747// " Degre maximum des carreaux de Bezier 14 par defaut "
748 Standard_Integer degU = 14, degV = 14;
749// " Nombre max de carreaux (par defaut 10)"
750 Standard_Integer nmax = 16;
751// "Code de precision par defaults"
752 Standard_Integer myPrec = 1;
753
754 if ( n>10 || n<3) return 1;
755
91322f44 756 if (n>3) Tol = Max(Draw::Atof(a[3]),1.e-10);
7fd59977 757
758 if (n==5) return 1;
759
760 if (n>5) {
91322f44 761 if (Draw::Atoi(a[4]) == 0) myUCont = GeomAbs_C0;
762 if (Draw::Atoi(a[4]) == 2) myUCont = GeomAbs_C2;
763 if (Draw::Atoi(a[5]) == 0) myVCont = GeomAbs_C0;
764 if (Draw::Atoi(a[5]) == 2) myVCont = GeomAbs_C2;
7fd59977 765 }
766
767 if (n==7) return 1;
768
769 if (n>7) {
91322f44 770 ( degU = (Draw::Atoi(a[6])));
771 ( degV = (Draw::Atoi(a[7])));
7fd59977 772 if ((degU<1) || (degU>24)) degU = 14;
773 if ((degV<1) || (degV>24)) degV = 14;
774 }
775
91322f44 776 if (n>8) nmax = Draw::Atoi(a[8]);
777 if (n>9) myPrec = Draw::Atoi(a[9]);
7fd59977 778
779 Handle(Geom_Surface) surf = DrawTrSurf::GetSurface(a[2]);
780 if (surf.IsNull()) return 1;
781 GeomConvert_ApproxSurface myApprox(surf,Tol,myUCont,myVCont,degU,degV,nmax,myPrec);
782 if ( myApprox.HasResult()) DrawTrSurf::Set(a[1], myApprox.Surface());
783 di<<a[1]<<"\n";
784 return 0;
785}
786
787//=======================================================================
788//function : offseting
789//purpose :
790//=======================================================================
791
792static Standard_Integer offseting (Draw_Interpretor& ,
793 Standard_Integer n, const char** a)
794{
795 if (n < 4) return 1;
796
797 // test the Geom2d curve
798 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]);
799 if (!C2d.IsNull()) {
91322f44 800 Handle(Geom2d_OffsetCurve) OC = new Geom2d_OffsetCurve(C2d,Draw::Atof(a[3]));
7fd59977 801 DrawTrSurf::Set(a[1],OC);
802 return 0;
803 }
804
805 Standard_Boolean yasurf = Standard_False;
806
807 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
808 Handle(Geom_Surface) GS;
809 if (GC.IsNull()) {
810 GS = DrawTrSurf::GetSurface(a[2]);
811 if (GS.IsNull())
812 return 1;
813 yasurf = Standard_True;
814 }
815
91322f44 816 Standard_Real dist = Draw::Atof(a[3]);
7fd59977 817
818 Handle(Geom_Geometry) result;
819
820 if (yasurf) {
821 Handle(Geom_OffsetSurface) GO = new Geom_OffsetSurface(GS,dist);
822 result = GO;
823 }
824 else {
825 if (n < 7) return 1;
91322f44 826 gp_Dir D(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
7fd59977 827 Handle(Geom_OffsetCurve) GT = new Geom_OffsetCurve(GC, dist, D);
828 result = GT;
829 }
830
831 DrawTrSurf::Set(a[1], result);
832 return 0;
833}
834
835//=======================================================================
836//function : sreverse
837//purpose :
838//=======================================================================
839
840static Standard_Integer sreverse (Draw_Interpretor& , Standard_Integer n, const char** a)
841{
842 if (n < 2) return 1;
843
844 Standard_Integer i;
845 for (i = 1; i < n; i++) {
846
847 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[i]);
848 if (!GS.IsNull()) {
849 if (*a[0] == 'u')
850 GS->UReverse();
851 else
852 GS->VReverse();
853 Draw::Repaint();
854 }
855 }
856
857 return 0;
858}
859
860//=======================================================================
861//function : iso
862//purpose :
863//=======================================================================
864
865static Standard_Integer iso (Draw_Interpretor& , Standard_Integer n, const char** a)
866{
867 if (n < 4) return 1;
868
869 Handle(Geom_Curve) C;
91322f44 870 Standard_Real par = Draw::Atof(a[3]);
7fd59977 871 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
872 if (!GS.IsNull()) {
873 if (*a[0] == 'u')
874 C = GS->UIso(par);
875 else
876 C = GS->VIso(par);
877 DrawTrSurf::Set(a[1],C);
878 }
879
880 return 0;
881}
882
883
884//=======================================================================
885//function : value
886//purpose :
887//=======================================================================
888
889static Standard_Integer value (Draw_Interpretor& ,
890 Standard_Integer n, const char** a)
891{
892 if (n < 5) return 1;
893
894 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[1]);
895 if (GS.IsNull()) return 1;
896
91322f44 897 Standard_Real U = Draw::Atof(a[2]);
898 Standard_Real V = Draw::Atof(a[3]);
7fd59977 899
900 Standard_Boolean DrawPoint = ( n%3 == 2);
901 if ( DrawPoint) n--;
902
903 gp_Pnt P;
904 if (n >= 13) {
905 gp_Vec DU,DV;
906 if (n >= 22) {
907 gp_Vec D2U,D2V,D2UV;
908 GS->D2(U,V,P,DU,DV,D2U,D2V,D2UV);
909 Draw::Set(a[13],D2U.X());
910 Draw::Set(a[14],D2U.Y());
911 Draw::Set(a[15],D2U.Z());
912 Draw::Set(a[16],D2V.X());
913 Draw::Set(a[17],D2V.Y());
914 Draw::Set(a[18],D2V.Z());
915 Draw::Set(a[19],D2UV.X());
916 Draw::Set(a[20],D2UV.Y());
917 Draw::Set(a[21],D2UV.Z());
918 }
919 else
920 GS->D1(U,V,P,DU,DV);
921
922 Draw::Set(a[7],DU.X());
923 Draw::Set(a[8],DU.Y());
924 Draw::Set(a[9],DU.Z());
925 Draw::Set(a[10],DV.X());
926 Draw::Set(a[11],DV.Y());
927 Draw::Set(a[12],DV.Z());
928 }
929 else
930 GS->D0(U,V,P);
931
932 if ( n > 6) {
933 Draw::Set(a[4],P.X());
934 Draw::Set(a[5],P.Y());
935 Draw::Set(a[6],P.Z());
936 }
937 if ( DrawPoint) {
938 DrawTrSurf::Set(a[n],P);
939 }
940
941 return 0;
942}
943
944//=======================================================================
945//function : movepole
946//purpose :
947//=======================================================================
948
949static Standard_Integer movepole (Draw_Interpretor& , Standard_Integer n, const char** a)
950{
951 if (n < 6) return 1;
952 Standard_Boolean BSpline = Standard_False;
953
954 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
955 Handle(Geom_BSplineSurface) GBs;
956 if (GBz.IsNull()) {
957 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
958 if (GBs.IsNull())
c48e2889 959 {
7fd59977 960 return 1;
c48e2889 961 }
962 BSpline = Standard_True;
7fd59977 963 }
964
91322f44 965 Standard_Real dx = Draw::Atof(a[n-3]);
966 Standard_Real dy = Draw::Atof(a[n-2]);
967 Standard_Real dz = Draw::Atof(a[n-1]);
7fd59977 968
969 Standard_Integer nup, nvp;
970 if( !BSpline) {
971 nup = GBz->NbUPoles();
972 nvp = GBz->NbVPoles();
973 }
974 else {
975 nup = GBs->NbUPoles();
976 nvp = GBs->NbVPoles();
977 }
978
979 Standard_Integer FirstRow=0, LastRow=0, FirstCol=0, LastCol=0;
980 // Rem : Row = indice ligne. -> variation en U.
981 // Col = indice colonne.-> variation en V.
982
983 if (!strcasecmp(a[0],"movep")) {
984 if (n<7) return 1;
91322f44 985 FirstRow = Draw::Atoi(a[2]);
986 FirstCol = Draw::Atoi(a[3]);
7fd59977 987 if ( FirstRow < 1 || FirstRow > nup ||
988 FirstCol < 1 || FirstCol > nvp ) return 1;
989 LastRow = FirstRow;
990 LastCol = FirstCol;
991 }
992 else if (!strcasecmp(a[0],"moverowp")) {
91322f44 993 FirstRow = Draw::Atoi(a[2]);
7fd59977 994 if ( FirstRow < 1 || FirstRow > nup ) return 1;
995 LastRow = FirstRow;
996 FirstCol = 1;
997 LastCol = nvp;
998 }
999 else if (!strcasecmp(a[0],"movecolp")) {
91322f44 1000 FirstCol = Draw::Atoi(a[2]);
7fd59977 1001 if ( FirstCol < 1 || FirstCol > nvp ) return 1;
1002 LastCol = FirstCol;
1003 FirstRow = 1;
1004 LastRow = nup;
1005 }
1006
1007 gp_Pnt P;
1008
1009 for ( Standard_Integer i = FirstRow; i<= LastRow; i++) {
1010 for ( Standard_Integer j = FirstCol; j<= LastCol; j++) {
1011 if( !BSpline) {
1012 P = GBz->Pole(i,j);
1013 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
1014 GBz->SetPole(i,j,P);
1015 }
1016 else {
1017 P = GBs->Pole(i,j);
1018 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
1019 GBs->SetPole(i,j,P);
1020 }
1021 }
1022 }
1023
1024 Draw::Repaint();
1025
1026 return 0;
1027}
1028
1029
1030//=======================================================================
1031//function : movepoint
1032//purpose :
1033//=======================================================================
1034
1035static Standard_Integer movepoint (Draw_Interpretor& , Standard_Integer n, const char** a)
1036{
1037 if (n < 7) return 1;
1038
1039 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1040 if (GBs.IsNull()) {
1041 return 1;
1042 }
1043
91322f44 1044 Standard_Real u = Draw::Atof(a[2]);
1045 Standard_Real v = Draw::Atof(a[3]);
7fd59977 1046
91322f44 1047 Standard_Real dx = Draw::Atof(a[4]);
1048 Standard_Real dy = Draw::Atof(a[5]);
1049 Standard_Real dz = Draw::Atof(a[6]);
7fd59977 1050
1051 Standard_Integer index1u = 0;
1052 Standard_Integer index2u = 0;
1053 Standard_Integer index1v = 0;
1054 Standard_Integer index2v = 0;
1055
1056 Standard_Integer fmodifu, lmodifu, fmodifv, lmodifv;
1057 if (n == 11) {
91322f44 1058 index1u = Draw::Atoi(a[7]);
1059 index2u = Draw::Atoi(a[8]);
1060 index1v = Draw::Atoi(a[9]);
1061 index2v = Draw::Atoi(a[10]);
7fd59977 1062 }
1063 else {
1064 index1u = 2;
1065 index2u = GBs->NbUPoles()-1;
1066 index1v = 2;
1067 index2v = GBs->NbVPoles()-1;
1068 }
1069
1070 gp_Pnt p;
1071 GBs->D0(u, v, p);
1072 p.SetCoord(p.X()+dx, p.Y()+dy, p.Z()+dz);
1073 GBs->MovePoint(u, v, p, index1u, index2u, index1v, index2v, fmodifu, lmodifu, fmodifv, lmodifv);
1074 Draw::Repaint();
1075 return 0;
1076}
1077
1078
1079//=======================================================================
1080//function : insertknot
1081//purpose :
1082//=======================================================================
1083
1084static Standard_Integer insertknot (Draw_Interpretor& , Standard_Integer n, const char** a)
1085{
1086 if (n < 3) return 1;
1087
1088 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1089
1090 if (GBs.IsNull()) return 1;
1091
1092 Standard_Real knot=0;
1093 Standard_Integer mult = 0;
1094 Standard_Integer index=0;
1095 if ( !strcasecmp(a[0],"insertuknot") ||
1096 !strcasecmp(a[0],"insertvknot") ) {
1097 if (n<4) return 1;
91322f44 1098 knot = Draw::Atof(a[2]);
1099 mult = Draw::Atoi(a[3]);
7fd59977 1100 }
1101 else if ( !strcasecmp(a[0],"remuknot") ||
1102 !strcasecmp(a[0],"remvknot") ) {
91322f44 1103 index = Draw::Atoi(a[2]);
1104 if (n>=4) mult = Draw::Atoi(a[3]);
7fd59977 1105 }
1106
1107 Standard_Real tol = RealLast();
1108
1109 if (!strcasecmp(a[0],"insertuknot")) {
1110 GBs->InsertUKnot(knot,mult,Precision::PConfusion());
1111 }
1112 else if (!strcasecmp(a[0],"insertvknot")) {
1113 GBs->InsertVKnot(knot,mult,Precision::PConfusion());
1114 }
1115 else if (!strcasecmp(a[0],"remuknot")) {
91322f44 1116 if (n>=5) tol = Draw::Atof(a[4]);
7fd59977 1117 if (!GBs->RemoveUKnot(index,mult,tol))
1118 return 1;
1119 }
1120 else if (!strcasecmp(a[0],"remvknot")) {
91322f44 1121 if (n>=5) tol = Draw::Atof(a[4]);
7fd59977 1122 if (!GBs->RemoveVKnot(index,mult,tol))
1123 return 1;
1124 }
1125
1126 Draw::Repaint();
1127 return 0;
1128}
1129
1130//=======================================================================
1131//function : incdegree
1132//purpose :
1133//=======================================================================
1134
1135static Standard_Integer incdegree (Draw_Interpretor& di, Standard_Integer n, const char** a)
1136{
1137 if (n < 3) return 1;
1138
91322f44 1139 Standard_Integer NewDeg = Draw::Atoi(a[2]);
7fd59977 1140 Standard_Boolean BSpline = Standard_False;
1141
1142 Standard_Integer UDeg=0, VDeg=0;
1143
1144 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1145 Handle(Geom_BSplineSurface) GBs;
1146
1147 if (GBz.IsNull()) {
1148 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1149 if (GBs.IsNull())
1150 return 1;
1151 BSpline = Standard_True;
1152 }
1153
1154 Standard_Integer Degree=0;
1155 if ( !strcasecmp(a[0],"incudeg")) {
1156 UDeg = NewDeg;
1157 if (BSpline) {
1158 Degree = GBs->UDegree();
1159 VDeg = GBs->VDegree();
1160 }
1161 else {
1162 Degree = GBz->UDegree();
1163 VDeg = GBz->VDegree();
1164 }
1165 }
1166 else if ( !strcasecmp(a[0],"incvdeg")) {
1167 VDeg = NewDeg;
1168 if (BSpline) {
1169 Degree = GBs->VDegree();
1170 UDeg = GBs->UDegree();
1171 }
1172 else {
1173 Degree = GBz->VDegree();
1174 UDeg = GBz->UDegree();
1175 }
1176 }
1177
1178 if (Degree > NewDeg) {
1179 di<<"The Degree must be greater than " << Degree <<"\n";
1180 return 1;
1181 }
1182
1183 if ( BSpline) {
1184 GBs->IncreaseDegree(UDeg, VDeg);
1185 }
1186 else {
1187 GBz->Increase(UDeg, VDeg);
1188 }
1189
1190 Draw::Repaint();
1191 return 0;
1192}
1193
1194//=======================================================================
1195//function : rempole
1196//purpose :
1197//=======================================================================
1198
1199static Standard_Integer rempole (Draw_Interpretor& di, Standard_Integer n, const char** a)
1200{
1201 if (n < 3) return 1;
1202
91322f44 1203 Standard_Integer NewIndex = Draw::Atoi(a[2]);
7fd59977 1204 Standard_Boolean BSpline = Standard_False;
1205
1206 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1207 Handle(Geom_BSplineSurface) GBs;
1208
1209 if (GBz.IsNull()) {
1210 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1211 if (GBs.IsNull())
1212 return 1;
1213 BSpline = Standard_True;
1214 }
1215
7fd59977 1216 if ( !strcasecmp(a[0],"remrowpole")) {
1217 if ( BSpline) {
586db386 1218 di << " Error : Cannot remove a polerow on a BSplineSurface \n";
7fd59977 1219 }
1220 else {
1221 GBz->RemovePoleRow(NewIndex);
1222 }
1223 }
1224 else if ( !strcasecmp(a[0],"remcolpole")) {
1225 if ( BSpline) {
586db386 1226 di << " Error : Cannot remove a polecol on a BSplineSurface \n";
7fd59977 1227 }
1228 else {
1229 GBz->RemovePoleCol(NewIndex);
1230 }
1231 }
1232
1233 Draw::Repaint();
1234 return 0;
1235}
1236
1237//=======================================================================
1238//function : sfindp
1239//purpose :
1240//=======================================================================
1241
1242static Standard_Integer sfindp (Draw_Interpretor& , Standard_Integer n, const char** a)
1243{
1244 if (n < 7) return 1;
1245 Standard_Boolean BSpline = Standard_False;
1246
1247 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1248 Handle(Geom_BSplineSurface) GBs;
1249 if (GBz.IsNull()) {
1250 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1251 if (GBs.IsNull())
c48e2889 1252 {
7fd59977 1253 return 1;
c48e2889 1254 }
1255 BSpline = Standard_True;
7fd59977 1256 }
1257
1258 Standard_Integer UIndex = 0;
1259 Standard_Integer VIndex = 0;
91322f44 1260 Standard_Integer view = Draw::Atoi(a[2]);
1261 Standard_Real x = Draw::Atof(a[3]);
1262 Standard_Real y = Draw::Atof(a[4]);
7fd59977 1263
1264 Draw_Display d = dout.MakeDisplay(view);
1265
1266 if( !BSpline) {
1267 Handle(DrawTrSurf_BezierSurface) DBz =
1268 new DrawTrSurf_BezierSurface(GBz);
1269 DBz->FindPole( x, y, d, 5, UIndex,VIndex);
1270 }
1271 else {
1272 Handle(DrawTrSurf_BSplineSurface) DBs =
1273 new DrawTrSurf_BSplineSurface(GBs);
1274 DBs->FindPole( x, y, d, 5, UIndex,VIndex);
1275 }
1276
1277 Draw::Set(a[5],UIndex);
1278 Draw::Set(a[6],VIndex);
1279
1280 return 0;
1281}
1282
1283
1284//=======================================================================
1285//function : ssetperiodic
1286//purpose :
1287//=======================================================================
1288
1289static Standard_Integer ssetperiodic (Draw_Interpretor& , Standard_Integer n, const char** a)
1290{
1291 if (n < 2) return 1;
1292
1293 Standard_Integer i;
1294
1295 if (!strcasecmp(a[0],"setuperiodic")) {
1296 for (i = 1; i < n; i++) {
1297 Handle(Geom_BSplineSurface)
1298 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1299 if (!GBs.IsNull()) {
1300 GBs->SetUPeriodic();
1301 Draw::Repaint();
1302 }
1303 }
1304 }
1305 else if (!strcasecmp(a[0],"setvperiodic")){
1306 for (i = 1; i < n; i++) {
1307 Handle(Geom_BSplineSurface)
1308 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1309 if (!GBs.IsNull()) {
1310 GBs->SetVPeriodic();
1311 Draw::Repaint();
1312 }
1313 }
1314 }
1315 else if (!strcasecmp(a[0],"setunotperiodic")){
1316 for (i = 1; i < n; i++) {
1317 Handle(Geom_BSplineSurface)
1318 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1319 if (!GBs.IsNull()) {
1320 GBs->SetUNotPeriodic();
1321 Draw::Repaint();
1322 }
1323 }
1324 }
1325 else if (!strcasecmp(a[0],"setvnotperiodic")){
1326 for (i = 1; i < n; i++) {
1327 Handle(Geom_BSplineSurface)
1328 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1329 if (!GBs.IsNull()) {
1330 GBs->SetVNotPeriodic();
1331 Draw::Repaint();
1332 }
1333 }
1334 }
1335 return 0;
1336}
1337
1338//=======================================================================
1339//function : exchuv
1340//purpose :
1341//=======================================================================
1342
1343static Standard_Integer exchuv (Draw_Interpretor& , Standard_Integer n, const char** a)
1344{
1345 if (n < 2) return 1;
1346
1347 Standard_Integer i;
1348 for (i = 1; i < n; i++) {
1349
1350 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1351 if (!GBs.IsNull()) {
1352 GBs->ExchangeUV();
1353 Draw::Repaint();
1354 }
1355 else {
1356 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[i]);
1357 if (!GBz.IsNull()) {
1358 GBz->ExchangeUV();
1359 Draw::Repaint();
1360 }
1361 }
1362 }
1363
1364 return 0;
1365}
1366
1367//=======================================================================
1368//function : segsur
1369//purpose :
1370//=======================================================================
1371
1372static Standard_Integer segsur (Draw_Interpretor& , Standard_Integer n, const char** a)
1373{
6fd9bdf2 1374 if (n < 6 || n > 8) return 1;
7fd59977 1375
1376 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1377 Handle(Geom_BSplineSurface) GBs;
1378 if (GBz.IsNull()) {
1379 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1380 if (GBs.IsNull())
1381 return 1;
6fd9bdf2 1382
1383 Standard_Real aUTolerance = Precision::PConfusion();
1384 Standard_Real aVTolerance = Precision::PConfusion();
1385 if (n >= 7)
1386 aUTolerance = aVTolerance = Draw::Atof(a[6]);
1387 if (n == 8)
1388 aVTolerance = Draw::Atof(a[7]);
1389
1390 GBs->Segment(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]), aUTolerance, aVTolerance);
7fd59977 1391 }
1392 else {
91322f44 1393 GBz->Segment(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
7fd59977 1394 }
1395
1396 Draw::Repaint();
1397 return 0;
1398}
1399
1400static Standard_Integer compBsplSur (Draw_Interpretor& , Standard_Integer n, const char** a)
1401{
1402 if (n < 2)
1403 {
d99f0355 1404 Message::SendFail() << "Syntax error: Invalid number of parameters";
7fd59977 1405 return 1;
1406 }
1407
1408 Handle(Geom_BSplineSurface) GBs1 = DrawTrSurf::GetBSplineSurface(a[1]);
1409 Handle(Geom_BSplineSurface) GBs2 = DrawTrSurf::GetBSplineSurface(a[2]);
1410 if (GBs1.IsNull() || GBs2.IsNull()) {
d99f0355 1411 Message::SendFail() << "Syntax error: Invalid surface";
7fd59977 1412 return 1;
1413 }
1414
1415 Standard_Real aU11,aU12,aV11,aV12;
1416 GBs1->Bounds(aU11,aU12,aV11,aV12);
1417
1418 Standard_Real aU21,aU22,aV21,aV22;
1419 GBs2->Bounds(aU21,aU22,aV21,aV22);
1420
1421 Standard_Real aUmin = Max(aU11,aU21);
1422 Standard_Real aUmax = Min(aU12,aU22);
1423
1424 Standard_Real aVmin = Max(aV11,aV21);
1425 Standard_Real aVmax = Min(aV12,aV22);
1426
1427 Standard_Integer nbP = 100;
1428 Standard_Real aStepU = (aUmax - aUmin)/nbP;
1429 Standard_Real aStepV = (aVmax - aVmin)/nbP;
1430 Standard_Integer nbErr =0;
1431 Standard_Integer i =1;
1432 for( ; i <= nbP +1; i++)
1433 {
1434 Standard_Real aU = aUmin + aStepU*(i-1);
1435 Standard_Integer j =1;
1436 for( ; j <= nbP +1; j++)
1437 {
1438 Standard_Real aV = aVmin + aStepV*(j-1);
1439 gp_Pnt aP1 = GBs1->Value(aU,aV);
1440 gp_Pnt aP2 = GBs2->Value(aU,aV);
1441 Standard_Real aDist = aP1.SquareDistance(aP2);
08cd2f6b 1442 if(aDist > Precision::SquareConfusion())
7fd59977 1443 {
1444 nbErr++;
1445 Standard_Real aD = sqrt(aDist);
04232180 1446 std::cout<<"Surfaces differ for U,V,Dist: "<<aU<<" "<<aV<<" "<<aD<<std::endl;
7fd59977 1447 }
1448 }
1449 }
1450
1451
1452 Draw::Repaint();
1453 return 0;
1454}
1455
1456//=======================================================================
1457//function : setuvorigin
1458//purpose :
1459//=======================================================================
1460
1461static Standard_Integer setuvorigin (Draw_Interpretor& , Standard_Integer n, const char** a)
1462{
1463 if (n < 3) return 1;
1464
1465 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1466 if (GBs.IsNull())
1467 return 1;
1468 if ( !strcasecmp(a[0],"setuorigin")) {
91322f44 1469 GBs->SetUOrigin(Draw::Atoi(a[2]));
7fd59977 1470 }
1471 else if ( !strcasecmp(a[0],"setvorigin")) {
91322f44 1472 GBs->SetVOrigin(Draw::Atoi(a[2]));
7fd59977 1473 }
1474 else
1475 return 1;
1476
1477 Draw::Repaint();
1478 return 0;
1479}
1480
1481
1482//=======================================================================
1483//function : parameters
1484//purpose :
1485//=======================================================================
1486
1487static Standard_Integer parameters (Draw_Interpretor& di, Standard_Integer n, const char** a)
1488{
1489 if(n == 8)
1490 {
1491 // try to find parameters on a Surface
1492 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[1]);
586db386 1493 if( S.IsNull() ) { di << "Unknown surface\n"; return 1; }
91322f44 1494 gp_Pnt P(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
1495 Standard_Real Tol = Draw::Atof(a[5]), U = 0., V = 0.;
7fd59977 1496 Standard_Boolean res = GeomLib_Tool::Parameters(S,P,Tol,U,V);
1497
1498 Draw::Set(a[6],U);
1499 Draw::Set(a[7],V);
1500
586db386 1501 if( !res ) { di << "Wrong point\n"; return 1; }
7fd59977 1502 }
1503 else if(n == 7)
1504 {
1505 // try to find parameters on a 3d Curve
1506 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[1]);
586db386 1507 if( C.IsNull() ) { di << "Unknown curve\n"; return 1; }
91322f44 1508 gp_Pnt P(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
1509 Standard_Real Tol = Draw::Atof(a[5]), U = 0.;
7fd59977 1510 Standard_Boolean res = GeomLib_Tool::Parameter(C,P,Tol,U);
1511
1512 Draw::Set(a[6],U);
1513
586db386 1514 if( !res ) { di << "Wrong point\n"; return 1; }
7fd59977 1515 }
1516 else if(n == 6)
1517 {
1518 // try to find parameters on a 2d Curve
1519 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[1]);
586db386 1520 if( C.IsNull() ) { di << "Unknown curve 2d\n"; return 1; }
91322f44 1521 gp_Pnt2d P(Draw::Atof(a[2]), Draw::Atof(a[3]));
1522 Standard_Real Tol = Draw::Atof(a[4]), U = 0.;
7fd59977 1523 Standard_Boolean res = GeomLib_Tool::Parameter(C,P,Tol,U);
1524
1525 Draw::Set(a[5],U);
1526
586db386 1527 if( !res ) { di << "Wrong point\n"; return 1; }
7fd59977 1528 }
1529 else
1530 {
586db386 1531 di << "Invalid parameters!\n";
1532 di << "Usage:\n";
1533 di << "parameters Surf X Y Z Tol U V\n";
1534 di << "parameters Curv X Y Z Tol U\n";
1535 di << "parameters Curv2d X Y Tol U\n";
7fd59977 1536 return 1;
1537 }
1538
1539 return 0;
1540}
1541
1542
1543//=======================================================================
1544//function : bounds
1545//purpose :
1546//=======================================================================
1547
1548Standard_Integer bounds(Draw_Interpretor&, Standard_Integer n, const char** a)
1549{
1550 Standard_Real U1, U2, V1, V2;
1551 if ( n == 4) { // compute on a curve or a 2d curve
1552 Handle(Geom_Curve) C3d = DrawTrSurf::GetCurve(a[1]);
1553 if ( C3d.IsNull()) { // 2dcurve
1554 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[1]);
1555 if ( C2d.IsNull()) return 1;
1556 U1 = C2d->FirstParameter();
1557 U2 = C2d->LastParameter();
1558 }
1559 else { // 3dcurve
1560 U1 = C3d->FirstParameter();
1561 U2 = C3d->LastParameter();
1562 }
1563 Draw::Set(a[2],U1);
1564 Draw::Set(a[3],U2);
1565 }
1566 else if ( n == 6) { // compute on a Surface
1567 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[1]);
1568 if ( S.IsNull()) return 1;
1569 S->Bounds(U1,U2,V1,V2);
1570
1571 Draw::Set(a[2],U1);
1572 Draw::Set(a[3],U2);
1573 Draw::Set(a[4],V1);
1574 Draw::Set(a[5],V2);
1575 }
1576
1577 return 0;
1578}
1579
1580//=======================================================================
1581//function : SurfaceCommands
1582//purpose :
1583//=======================================================================
1584
1585
1586void GeomliteTest::SurfaceCommands(Draw_Interpretor& theCommands)
1587{
1588 static Standard_Boolean loaded = Standard_False;
1589 if (loaded) return;
1590 loaded = Standard_True;
1591
1592 DrawTrSurf::BasicCommands(theCommands);
1593
1594 const char* g;
1595 // analytic surfaces
1596 g = "GEOMETRY surfaces creation";
1597
1598 theCommands.Add("plane",
1599 "plane name [x y z [dx dy dz [ux uy uz]]]",
1600 __FILE__,
1601 anasurface,g);
1602
1603 theCommands.Add("cone",
1604 "cone name [x y z [dx dy dz [ux uy uz]]] semi-angle radius",
1605 __FILE__,
1606 anasurface,g);
1607
1608 theCommands.Add("cylinder",
1609 "cylinder name [x y z [dx dy dz [ux uy uz]]] radius",
1610 __FILE__,
1611 anasurface,g);
1612
1613 theCommands.Add("sphere",
1614 "sphere name [x y z [dx dy dz [ux uy uz]]] radius",
1615 __FILE__,
1616 anasurface,g);
1617
1618 theCommands.Add("torus",
1619 "torus name [x y z [dx dy dz [ux uy uz]]] major minor",
1620 __FILE__,
1621 anasurface,g);
1622
1623 theCommands.Add("beziersurf",
1624 "beziersurf name nbupoles nbvpoles pole, [weight]",
1625 __FILE__,
1626 polesurface,g);
1627
1628 theCommands.Add("bsplinesurf",
1629 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1630 __FILE__,
1631 polesurface,g);
1632
1633 theCommands.Add("upbsplinesurf",
1634 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1635 __FILE__,
1636 polesurface,g);
1637
1638 theCommands.Add("vpbsplinesurf",
1639 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1640 __FILE__,
1641 polesurface,g);
1642
1643 theCommands.Add("uvpbsplinesurf",
1644 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1645 __FILE__,
1646 polesurface,g);
1647
1648 theCommands.Add("extsurf",
1649 "extsurf name curvename dx dy dz",
1650 __FILE__,
1651 algosurface,g);
1652
1653 theCommands.Add("revsurf",
1654 "revsurf name curvename x y z dx dy dz",
1655 __FILE__,
1656 algosurface,g);
1657
1658 theCommands.Add("offset",
1659 "offset name basename distance [dx dy dz]",
1660 __FILE__,
1661 offseting,g);
1662
1663 theCommands.Add("trim",
c5b42a1a 1664 "trim newname name [u1 u2 [v1 v2] [usense=1 vsense=1]]"
1665 "\n\t\t: Creates either a new trimmed curve from a curve"
1666 "\n\t\t: or a new trimmed surface in u and v from a surface."
1667 "\n\t\t: Removes trim when called without arguments."
1668 "\n\t\t: - u1 u2 lower and upper parameters of trimming on U direction"
1669 "\n\t\t: - v1 v2 lower and upper parameters of trimming on V direction"
1670 "\n\t\t: - usense vsense senses on U and V directions: 1 - true, 0 - false;"
1671 "\n\t\t Senses are used for the construction only if the surface is periodic"
1672 "\n\t\t in the corresponding parametric direction, and define the available part of the surface",
7fd59977 1673 __FILE__,
1674 trimming,g);
1675
1676 theCommands.Add("trimu",
c5b42a1a 1677 "trimu newname name u1 u2 [usense=1]"
1678 "\n\t\t: Creates a u-trimmed surface."
1679 "\n\t\t: - u1 u2 lower and upper parameters of trimming on U direction"
1680 "\n\t\t: - usense sense on U direction: 1 - true, 0 - false;"
1681 "\n\t\t usense is used for the construction only if the surface is u-periodic"
1682 "\n\t\t in the u parametric direction, and define the available part of the surface",
7fd59977 1683 __FILE__,
1684 trimming,g);
1685
1686 theCommands.Add("trimv",
c5b42a1a 1687 "trimv newname name v1 v2 [vsense=1]"
1688 "\n\t\t: Creates a v-trimmed surface."
1689 "\n\t\t: - u1 u2 lower and upper parameters of trimming on V direction"
1690 "\n\t\t: - vsense sense on V direction: 1 - true, 0 - false;"
1691 "\n\t\t vsense is used for the construction only if the surface is v-periodic"
1692 "\n\t\t in the v parametric direction, and define the available part of the surface",
7fd59977 1693 __FILE__,
1694 trimming,g);
1695
1696 theCommands.Add("convert",
1697 "convert result c2d/c3d/surf [qa,c1,s1,s2,s3,s4,po]",
1698 __FILE__,
1699 converting,g);
1700
1701 theCommands.Add("tobezier",
1702 "tobezier result c2d/c3d/surf [ufirst, ulast / ufirst, ulast, vfirst, vlast]",
1703 __FILE__,
1704 tobezier,g);
1705
1706 theCommands.Add("convertfrombezier",
1707 "convertfrombezier result nbu [nbv] bz1 [bz2 .... bzn] [tol]",
1708 __FILE__,
1709 convbz,g);
1710
1711 theCommands.Add("approxsurf",
1712 "approxsurf name surf [Tol [CnU CnV [degU degV [nmax]]]] ",
1713 __FILE__,
1714 approxsurf,g);
1715
1716 g = "GEOMETRY Curves and Surfaces modification";
1717
1718 theCommands.Add("ureverse",
1719 "ureverse name ... ",
1720 __FILE__,
1721 sreverse,g);
1722
1723 theCommands.Add("vreverse",
1724 "vreverse name ... ",
1725 __FILE__,
1726 sreverse,g);
1727
1728 theCommands.Add("movep",
1729 "movep name row col dx dy dz",
1730 __FILE__,
1731 movepole,g);
1732
1733 theCommands.Add("moverowp",
1734 "moverowp name row dx dy dz",
1735 __FILE__,
1736 movepole,g);
1737
1738 theCommands.Add("movecolp",
1739 "movecolp name col dx dy dz",
1740 __FILE__,
1741 movepole,g);
1742
1743 theCommands.Add("movepoint",
1744 "movepoint name u v dx dy dz [index1u index2u index2v index2v",
1745 __FILE__,
1746 movepoint,g);
1747
1748 theCommands.Add("insertuknot",
1749 "insertuknot name knot mult",
1750 __FILE__,
1751 insertknot,g);
1752
1753 theCommands.Add("insertvknot",
1754 "insertvknot name knot mult",
1755 __FILE__,
1756 insertknot,g);
1757
1758 theCommands.Add("remuknot",
1759 "remuknot name index [mult] [tol]",
1760 __FILE__,
1761 insertknot,g);
1762
1763 theCommands.Add("remvknot",
1764 "remvknot name index [mult] [tol]",
1765 __FILE__,
1766 insertknot,g);
1767
1768 theCommands.Add("incudeg",
1769 "incudeg name degree",
1770 __FILE__,
1771 incdegree,g);
1772
1773 theCommands.Add("incvdeg",
1774 "incvdeg name degree",
1775 __FILE__,
1776 incdegree,g);
1777
1778 theCommands.Add("remrowpole",
1779 "remrowpole name index",
1780 __FILE__,
1781 rempole,g);
1782
1783 theCommands.Add("remcolpole",
1784 "remcolpole name index",
1785 __FILE__,
1786 rempole,g);
1787
1788 theCommands.Add("sfindp",
1789 "sfindp name view x y Uindex Vindex",
1790 __FILE__,
1791 sfindp,g);
1792
1793 theCommands.Add("setuperiodic",
1794 "setuperiodic name ...",
1795 __FILE__,
1796 ssetperiodic,g);
1797
1798 theCommands.Add("setvperiodic",
1799 "setvperiodic name ...",
1800 __FILE__,
1801 ssetperiodic,g);
1802
1803 theCommands.Add("setunotperiodic",
1804 "setunotperiodic name ...",
1805 __FILE__,
1806 ssetperiodic,g);
1807
1808 theCommands.Add("setvnotperiodic",
1809 "setvnotperiodic name ...",
1810 __FILE__,
1811 ssetperiodic,g);
1812
1813 theCommands.Add("exchuv",
1814 "exchuv name ...",
1815 __FILE__,
1816 exchuv,g);
1817
1818 theCommands.Add("segsur",
6fd9bdf2 1819 "segsur name Ufirst Ulast Vfirst Vlast [Utol [Vtol]]",
7fd59977 1820 __FILE__,
1821 segsur , g);
1822
1823 theCommands.Add("setuorigin",
1824 "setuorigin name knotindex",
1825 __FILE__,
1826 setuvorigin , g);
1827
1828 theCommands.Add("setvorigin",
1829 "setvorigin name knotindex",
1830 __FILE__,
1831 setuvorigin , g);
1832
1833 g = "GEOMETRY curves creation";
1834
1835
1836 theCommands.Add("uiso",
1837 "uiso curvename surfacename u",
1838 __FILE__,
1839 iso,g);
1840
1841 theCommands.Add("viso",
1842 "viso curvename surfacename v",
1843 __FILE__,
1844 iso,g);
1845
1846
1847 g = "GEOMETRY curves and surfaces analysis";
1848
1849 theCommands.Add("svalue",
1850 "svalue surfname U V X Y Z [DUX DUY DUZ DVX DVY DVZ [D2UX D2UY D2UZ D2VX D2VY D2VZ D2UVX D2UVY D2UVZ]]",
1851 __FILE__,
1852 value,g);
1853
1854 theCommands.Add("parameters",
1855 "parameters surf/curve X Y [Z] Tol U [V] : {X Y Z} point, {U V} output parameter(s)",
1856 __FILE__,
1857 parameters,g);
1858
1859 theCommands.Add("bounds",
1860 "bounds S/C/C2d U1 U2 [V1 V2]",
1861 __FILE__,
1862 bounds,g);
1863
1864 theCommands.Add("surface_radius",
1865 "surface_radius surface Uvalue <Real> Vvalue <Real> returns min max radius of curvature",
1866 __FILE__,
1867 surface_radius,g);
1868 theCommands.Add("compBsplSur","BsplSurf1 BSplSurf2",__FILE__,compBsplSur,g);
a7493ad4 1869
1870
7fd59977 1871}