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