1 // Created on: 1993-08-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by xab, Tue Mar 11 18:31:18 1997
18 // Modified by PMN 14/04/97 : Passage a Geomlite
19 // Modified by JPI 01/08/97 : ajout de la commande approxcurve
21 #include <GeomliteTest.hxx>
22 #include <Draw_Appli.hxx>
23 #include <DrawTrSurf.hxx>
24 #include <DrawTrSurf_Curve.hxx>
25 #include <DrawTrSurf_Curve2d.hxx>
26 #include <DrawTrSurf_BezierCurve.hxx>
27 #include <DrawTrSurf_BSplineCurve.hxx>
28 #include <DrawTrSurf_BezierCurve2d.hxx>
29 #include <DrawTrSurf_BSplineCurve2d.hxx>
30 #include <Draw_Marker3D.hxx>
31 #include <Draw_Marker2D.hxx>
33 #include <Draw_Interpretor.hxx>
34 #include <Draw_Color.hxx>
35 #include <Draw_Display.hxx>
37 #include <BSplCLib.hxx>
41 #include <gp_Parab2d.hxx>
42 #include <gp_Elips2d.hxx>
43 #include <gp_Hypr2d.hxx>
45 #include <Geom_Line.hxx>
46 #include <Geom_Circle.hxx>
47 #include <Geom_Ellipse.hxx>
48 #include <Geom_Parabola.hxx>
49 #include <Geom_Hyperbola.hxx>
50 #include <Geom_BezierCurve.hxx>
51 #include <Geom_BSplineCurve.hxx>
52 #include <GeomAdaptor_Surface.hxx>
53 #include <GeomAdaptor_HSurface.hxx>
55 #include <GeomLib.hxx>
56 #include <GeomConvert.hxx>
57 #include <Geom2dConvert.hxx>
59 #include <Geom2d_Line.hxx>
60 #include <Geom2d_Circle.hxx>
61 #include <Geom2d_Ellipse.hxx>
62 #include <Geom2d_Parabola.hxx>
63 #include <Geom2d_Hyperbola.hxx>
64 #include <Geom2d_BezierCurve.hxx>
65 #include <Geom2d_BSplineCurve.hxx>
67 #include <GeomLProp.hxx>
68 #include <GeomLProp_CLProps.hxx>
69 #include <Geom2dLProp_CLProps2d.hxx>
70 #include <Geom2dLProp_CurAndInf2d.hxx>
72 #include <TColgp_Array1OfPnt.hxx>
73 #include <TColgp_Array1OfPnt2d.hxx>
74 #include <TColStd_Array1OfReal.hxx>
75 #include <TColStd_Array1OfInteger.hxx>
77 #include <GeomAbs_SurfaceType.hxx>
78 #include <GeomAbs_CurveType.hxx>
80 #include <Precision.hxx>
84 #include <TColStd_HArray1OfReal.hxx>
85 #include <TColStd_HArray2OfReal.hxx>
86 #include <TColStd_HArray1OfInteger.hxx>
87 #include <TColStd_Array1OfReal.hxx>
88 #include <TColStd_Array1OfInteger.hxx>
90 #include <TColGeom_HArray1OfBSplineCurve.hxx>
91 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
92 #include <Convert_CompPolynomialToPoles.hxx>
93 #include <CPnts_AbscissaPoint.hxx>
94 #include <GCPnts_AbscissaPoint.hxx>
97 #include <GeomAbs_Shape.hxx>
98 #include <Geom_Curve.hxx>
99 #include <GeomConvert.hxx>
100 #include <GeomConvert_ApproxCurve.hxx>
101 #include <Geom2dConvert_ApproxCurve.hxx>
102 #include <Geom2d_Curve.hxx>
104 #include <GeomAdaptor_HCurve.hxx>
105 #include <GeomAdaptor_Curve.hxx>
106 #include <Geom2dAdaptor_HCurve.hxx>
107 #include <GeomAdaptor_HCurve.hxx>
108 #include <Approx_CurvilinearParameter.hxx>
109 #include <Approx_CurveOnSurface.hxx>
110 #include <Geom_BSplineSurface.hxx>
112 Standard_IMPORT Draw_Viewer dout;
115 //=======================================================================
116 //function : anacurve
118 //=======================================================================
120 static Standard_Integer anacurve (Draw_Interpretor& , Standard_Integer n, const char** a)
124 Handle(Geom_Geometry) result;
125 Handle(Geom2d_Curve) result2d;
127 if (!strcmp(a[0],"line")) {
129 result2d = new Geom2d_Line(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
130 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5])));
132 result = new Geom_Line(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
133 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])));
138 else if (!strcmp(a[0],"circle")) {
141 new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
146 new Geom_Circle(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
151 new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
152 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
156 new Geom_Circle(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
157 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
161 new Geom_Circle(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
162 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
163 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
169 else if (!strcmp(a[0],"parabola")) {
172 new Geom2d_Parabola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
177 new Geom_Parabola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
182 new Geom2d_Parabola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
183 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
187 new Geom_Parabola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
188 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
192 new Geom_Parabola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
193 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
194 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
200 else if (!strcmp(a[0],"ellipse")) {
203 new Geom2d_Ellipse(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
205 Draw::Atof(a[4]),Draw::Atof(a[5]));
208 new Geom_Ellipse(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
210 Draw::Atof(a[5]),Draw::Atof(a[6]));
213 new Geom2d_Ellipse(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
214 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
215 Draw::Atof(a[6]), Draw::Atof(a[7]));
218 new Geom_Ellipse(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
219 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
220 Draw::Atof(a[8]), Draw::Atof(a[9]));
223 new Geom_Ellipse(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
224 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
225 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
226 Draw::Atof(a[11]), Draw::Atof(a[12]));
231 else if (!strcmp(a[0],"hyperbola")) {
234 new Geom2d_Hyperbola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
236 Draw::Atof(a[4]),Draw::Atof(a[5]));
239 new Geom_Hyperbola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
241 Draw::Atof(a[5]),Draw::Atof(a[6]));
244 new Geom2d_Hyperbola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
245 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
246 Draw::Atof(a[6]), Draw::Atof(a[7]));
249 new Geom_Hyperbola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
250 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
251 Draw::Atof(a[8]), Draw::Atof(a[9]));
254 new Geom_Hyperbola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
255 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
256 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
257 Draw::Atof(a[11]), Draw::Atof(a[12]));
262 if (!result.IsNull())
263 DrawTrSurf::Set(a[1],result);
264 else if (!result2d.IsNull())
265 DrawTrSurf::Set(a[1],result2d);
272 //=======================================================================
273 //function : polecurve
275 //=======================================================================
277 static Standard_Integer polecurve (Draw_Interpretor& , Standard_Integer n, const char** a)
279 Standard_Integer k,i;
284 if (!strcmp(a[0],"beziercurve")) {
286 Standard_Integer np = Draw::Atoi(a[2]);
287 if (np == 0) return 1;
290 if (i < 3 || i > 4) return 1;
291 Standard_Boolean hasw = i == 4;
293 TColgp_Array1OfPnt poles(1,np);
294 TColStd_Array1OfReal weights(1,np);
297 for (i = 1; i <= np; i++) {
298 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]),Draw::Atof(a[k+2]));
301 weights(i) = Draw::Atof(a[k]);
306 Handle(Geom_BezierCurve) result;
308 result = new Geom_BezierCurve(poles,weights);
310 result = new Geom_BezierCurve(poles);
312 DrawTrSurf::Set(a[1],result);
315 else if (!strcmp((*a[0] == 'p') ? a[0]+1 : a[0],"bsplinecurve")) {
316 Standard_Integer deg = Draw::Atoi(a[2]);
317 Standard_Integer nbk = Draw::Atoi(a[3]);
319 TColStd_Array1OfReal knots(1, nbk);
320 TColStd_Array1OfInteger mults(1, nbk);
322 Standard_Integer Sigma = 0;
323 for (i = 1; i<=nbk; i++) {
324 knots( i) = Draw::Atof(a[k]);
326 mults( i) = Draw::Atoi(a[k]);
331 Standard_Boolean periodic = *a[0] == 'p';
334 np = Sigma - mults(nbk);
338 TColgp_Array1OfPnt poles (1, np);
339 TColStd_Array1OfReal weights(1, np);
341 for (i = 1; i <= np; i++) {
342 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]),Draw::Atof(a[k+2]));
344 weights(i) = Draw::Atof(a[k]);
348 Handle(Geom_BSplineCurve) result =
349 new Geom_BSplineCurve(poles, weights, knots, mults, deg, periodic);
350 DrawTrSurf::Set(a[1],result);
356 //=======================================================================
357 //function : polecurve2d
359 //=======================================================================
361 static Standard_Integer polecurve2d (Draw_Interpretor& , Standard_Integer n, const char** a)
363 Standard_Integer k,i;
368 if (!strcmp(a[0],"2dbeziercurve")) {
370 Standard_Integer np = Draw::Atoi(a[2]);
371 if (np == 0) return 1;
374 if (i < 2 || i > 3) return 1;
375 Standard_Boolean hasw = i == 3;
377 TColgp_Array1OfPnt2d poles(1,np);
378 TColStd_Array1OfReal weights(1,np);
381 for (i = 1; i <= np; i++) {
382 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]));
385 weights(i) = Draw::Atof(a[k]);
390 Handle(Geom2d_BezierCurve) result;
392 result = new Geom2d_BezierCurve(poles,weights);
394 result = new Geom2d_BezierCurve(poles);
396 DrawTrSurf::Set(a[1],result);
399 else if (!strcmp((*(a[0]+2) == 'p') ? a[0]+3 : a[0]+2,"bsplinecurve")) {
400 Standard_Integer deg = Draw::Atoi(a[2]);
401 Standard_Integer nbk = Draw::Atoi(a[3]);
403 TColStd_Array1OfReal knots(1, nbk);
404 TColStd_Array1OfInteger mults(1, nbk);
406 Standard_Integer Sigma = 0;
407 for (i = 1; i<=nbk; i++) {
408 knots( i) = Draw::Atof(a[k]);
410 mults( i) = Draw::Atoi(a[k]);
415 Standard_Boolean periodic = *(a[0]+2) == 'p';
418 np = Sigma - mults(nbk);
422 TColgp_Array1OfPnt2d poles (1, np);
423 TColStd_Array1OfReal weights(1, np);
425 for (i = 1; i <= np; i++) {
426 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]));
428 weights(i) = Draw::Atof(a[k]);
432 Handle(Geom2d_BSplineCurve) result =
433 new Geom2d_BSplineCurve(poles, weights, knots, mults, deg, periodic);
434 DrawTrSurf::Set(a[1],result);
440 //=======================================================================
443 //=======================================================================
445 static Standard_Integer reverse (Draw_Interpretor& , Standard_Integer n, const char** a)
450 for (i = 1; i < n; i++) {
452 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[i]);
457 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[i]);
458 if (!GC2d.IsNull()) {
466 //=======================================================================
467 //function : cmovepole
469 //=======================================================================
471 static Standard_Integer cmovepole (Draw_Interpretor& , Standard_Integer n, const char** a)
475 Standard_Real dx = Draw::Atof(a[3]);
476 Standard_Real dy = Draw::Atof(a[4]);
478 if (n >= 6) dz = Draw::Atof(a[5]);
479 Standard_Integer Index = Draw::Atoi(a[2]);
481 Handle(Geom_BezierCurve) G1 = DrawTrSurf::GetBezierCurve(a[1]);
483 gp_Pnt P = G1->Pole(Index);
484 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
485 G1->SetPole(Index,P);
491 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
493 gp_Pnt P = G2->Pole(Index);
494 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
495 G2->SetPole(Index,P);
500 Handle(Geom2d_BezierCurve) G3 = DrawTrSurf::GetBezierCurve2d(a[1]);
502 gp_Pnt2d P = G3->Pole(Index);
503 P.SetCoord(P.X()+dx, P.Y()+dy);
504 G3->SetPole(Index,P);
510 Handle(Geom2d_BSplineCurve) G4 = DrawTrSurf::GetBSplineCurve2d(a[1]);
512 gp_Pnt2d P = G4->Pole(Index);
513 P.SetCoord(P.X()+dx, P.Y()+dy);
514 G4->SetPole(Index,P);
524 //=======================================================================
525 //function : cmovetangent
527 //=======================================================================
529 static Standard_Integer cmovetangent (Draw_Interpretor& di, Standard_Integer n, const char** a)
531 Standard_Integer dimension,
542 u = Draw::Atof(a[2]);
543 x = Draw::Atof(a[3]);
544 y = Draw::Atof(a[4]);
562 if (dimension == 3) {
563 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
565 z = Draw::Atof(a[5]) ;
566 tx = Draw::Atof(a[6]) ;
567 ty = Draw::Atof(a[7]) ;
568 tz = Draw::Atof(a[8]) ;
570 condition = Max(Draw::Atoi(a[9]), -1) ;
571 condition = Min(condition, G2->Degree()-1) ;
576 tangent.SetCoord(tx,ty,tz) ;
578 G2->MovePointAndTangent(u,
585 if (! error_status) {
589 di << "Not enought degree of freedom increase degree please\n";
596 Handle(Geom2d_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve2d(a[1]);
598 tx = Draw::Atof(a[5]) ;
599 ty = Draw::Atof(a[6]) ;
601 condition = Max(Draw::Atoi(a[7]), -1) ;
602 condition = Min(condition, G2->Degree()-1) ;
607 tangent.SetCoord(tx,ty) ;
609 G2->MovePointAndTangent(u,
616 if (! error_status) {
620 di << "Not enought degree of freedom increase degree please\n";
630 //=======================================================================
631 //function : cmovepoint
633 //=======================================================================
635 static Standard_Integer cmovepoint (Draw_Interpretor& , Standard_Integer n, const char** a)
639 Standard_Real dx = Draw::Atof(a[3]);
640 Standard_Real dy = Draw::Atof(a[4]);
642 if (n >= 6 && n != 7) dz = Draw::Atof(a[5]);
643 Standard_Real u = Draw::Atof(a[2]);
644 Standard_Integer index1 = 0;
645 Standard_Integer index2 = 0;
646 Standard_Integer fmodif, lmodif;
648 index1 = Draw::Atoi(a[5]);
649 index2 = Draw::Atoi(a[6]);
652 index1 = Draw::Atoi(a[6]);
653 index2 = Draw::Atoi(a[7]);
656 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
660 index2 = G2->NbPoles()-1;
664 p.SetCoord(p.X()+dx, p.Y()+dy, p.Z()+dz);
665 G2->MovePoint(u, p, index1, index2, fmodif, lmodif);
670 Handle(Geom2d_BSplineCurve) G4 = DrawTrSurf::GetBSplineCurve2d(a[1]);
674 index2 = G4->NbPoles()-1;
678 p.SetCoord(p.X()+dx, p.Y()+dy);
679 G4->MovePoint(u, p, index1, index2, fmodif, lmodif);
686 //=======================================================================
687 //function : cinsertknot
689 //=======================================================================
691 static Standard_Integer cinsertknot (Draw_Interpretor& , Standard_Integer n, const char** a)
695 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
696 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
698 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
701 Standard_Real knot = Draw::Atof(a[2]);
702 Standard_Integer mult = 1;
703 if (n == 4) mult = Draw::Atoi(a[3]);
705 GBs->InsertKnot(knot,mult,Precision::PConfusion());
707 GBs2d->InsertKnot(knot,mult,Precision::PConfusion());
711 // multiple insertion
712 if (n % 2 != 0) return 1;
713 Standard_Integer i,nbk = (n-2) / 2;
714 TColStd_Array1OfReal knots(1,nbk);
715 TColStd_Array1OfInteger mults(1,nbk);
716 for (i = 2; i < n; i += 2) {
717 knots(i/2) = Draw::Atof(a[i]);
718 mults(i/2) = Draw::Atoi(a[i+1]);
722 GBs->InsertKnots(knots,mults,Precision::PConfusion());
724 GBs2d->InsertKnots(knots,mults,Precision::PConfusion());
732 //=======================================================================
733 //function : csetknot
735 //=======================================================================
737 static Standard_Integer csetknot (Draw_Interpretor& , Standard_Integer n, const char** a)
741 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
742 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
744 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
746 Standard_Integer index = Draw::Atoi(a[2]);
747 Standard_Real knot = Draw::Atof(a[3]);
751 GBs->SetKnot(index,knot);
753 GBs2d->SetKnot(index,knot);
756 Standard_Integer mult = Draw::Atoi(a[4]);
758 GBs->SetKnot(index,knot,mult);
760 GBs2d->SetKnot(index,knot,mult);
767 //=======================================================================
768 //function : cremknot
770 //=======================================================================
772 static Standard_Integer cremknot (Draw_Interpretor& di, Standard_Integer n, const char** a)
776 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
777 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
779 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
781 Standard_Integer index = Draw::Atoi(a[2]);
782 Standard_Integer mult = 0;
783 if (n >= 4) mult = Draw::Atoi(a[3]);
785 Standard_Real tol = RealLast();
786 if (n >= 5) tol = Draw::Atof(a[4]);
789 if (!GBs->RemoveKnot(index,mult,tol))
790 di << "Remove knots failed\n";
793 if (!GBs2d->RemoveKnot(index,mult,tol))
794 di << "Remove knots failed\n";
801 //=======================================================================
802 //function : increasedegree
804 //=======================================================================
806 static Standard_Integer increasedegree (Draw_Interpretor& , Standard_Integer n, const char** a)
810 Standard_Integer Deg = Draw::Atoi(a[2]);
812 Handle(Geom_BezierCurve) GBz = DrawTrSurf::GetBezierCurve(a[1]);
813 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
814 Handle(Geom2d_BezierCurve) GBz2d = DrawTrSurf::GetBezierCurve2d(a[1]);
815 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
819 else if (!GBs.IsNull())
820 GBs->IncreaseDegree(Deg);
821 else if (!GBz2d.IsNull())
822 GBz2d->Increase(Deg);
823 else if (!GBs2d.IsNull())
824 GBs2d->IncreaseDegree(Deg);
832 //=======================================================================
833 //function : removepole
835 //=======================================================================
837 static Standard_Integer removepole (Draw_Interpretor& di, Standard_Integer n, const char** a)
841 Standard_Integer Index = Draw::Atoi(a[2]);
843 Handle(Geom_BezierCurve) GBZ = DrawTrSurf::GetBezierCurve(a[1]);
844 Handle(Geom2d_BezierCurve) GBZ2d = DrawTrSurf::GetBezierCurve2d(a[1]);
846 GBZ->RemovePole(Index);
848 else if (!GBZ2d.IsNull()) {
849 GBZ2d->RemovePole(Index);
852 di << "rempole needs a bezier curve";
860 //=======================================================================
861 //function : insertpole
863 //=======================================================================
865 static Standard_Integer insertpole (Draw_Interpretor& di, Standard_Integer n, const char** a)
869 Standard_Integer Index = Draw::Atoi(a[2]);
871 Handle(Geom_BezierCurve) GBZ = DrawTrSurf::GetBezierCurve(a[1]);
872 Handle(Geom2d_BezierCurve) GBZ2d = DrawTrSurf::GetBezierCurve2d(a[1]);
874 gp_Pnt P (Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
876 GBZ->InsertPoleAfter(Index,P,Draw::Atof(a[6]));
878 GBZ->InsertPoleAfter(Index,P);
880 else if (!GBZ2d.IsNull()) {
881 gp_Pnt2d P (Draw::Atof(a[3]),Draw::Atof(a[4]));
883 GBZ2d->InsertPoleAfter(Index,P,Draw::Atof(a[5]));
885 GBZ2d->InsertPoleAfter(Index,P);
888 di << "insertpole needs a bezier curve";
896 //=======================================================================
899 //=======================================================================
901 static Standard_Integer cfindp (Draw_Interpretor& , Standard_Integer n, const char** a)
905 Standard_Integer Index = 0;
906 Standard_Integer view = Draw::Atoi(a[2]);
907 Standard_Real x = Draw::Atof(a[3]);
908 Standard_Real y = Draw::Atof(a[4]);
910 Draw_Display d = dout.MakeDisplay(view);
912 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
914 Handle(DrawTrSurf_BezierCurve) DBz =
915 Handle(DrawTrSurf_BezierCurve)::DownCast(D);
917 DBz->FindPole( x, y, d, 5, Index);
919 Handle(DrawTrSurf_BSplineCurve) DBs =
920 Handle(DrawTrSurf_BSplineCurve)::DownCast(D);
922 DBs->FindPole( x, y, d, 5, Index);
924 Handle(DrawTrSurf_BezierCurve2d) DBz2d =
925 Handle(DrawTrSurf_BezierCurve2d)::DownCast(D);
927 DBz2d->FindPole( x, y, d, 5, Index);
929 Handle(DrawTrSurf_BSplineCurve2d) DBs2d =
930 Handle(DrawTrSurf_BSplineCurve2d)::DownCast(D);
932 DBs2d->FindPole( x, y, d, 5, Index);
939 Draw::Set(a[5],Index);
945 //=======================================================================
946 //function : csetperiodic
948 //=======================================================================
950 static Standard_Integer csetperiodic (Draw_Interpretor& , Standard_Integer n, const char** a)
954 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
955 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
957 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
959 if (!strcmp(a[0],"setperiodic")) {
963 GBs2d->SetPeriodic();
965 else if (!strcmp(a[0],"setnotperiodic")) {
967 GBs->SetNotPeriodic();
969 GBs2d->SetNotPeriodic();
976 //=======================================================================
979 //=======================================================================
981 static Standard_Integer value (Draw_Interpretor& ,
982 Standard_Integer n, const char** a)
986 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
987 if (GC.IsNull()) return 1;
989 Standard_Real U = Draw::Atof(a[2]);
991 Standard_Boolean DrawPoint = ( n%3 == 1);
999 if (n < 12) return 1;
1002 Draw::Set(a[9] ,D2.X());
1003 Draw::Set(a[10],D2.Y());
1004 Draw::Set(a[11],D2.Z());
1008 Draw::Set(a[6],D1.X());
1009 Draw::Set(a[7],D1.Y());
1010 Draw::Set(a[8],D1.Z());
1016 Draw::Set(a[3],P.X());
1017 Draw::Set(a[4],P.Y());
1018 Draw::Set(a[5],P.Z());
1021 DrawTrSurf::Set(a[n],P);
1028 //=======================================================================
1029 //function : value2d
1031 //=======================================================================
1033 static Standard_Integer value2d (Draw_Interpretor& ,
1034 Standard_Integer n, const char** a)
1036 if (n < 4) return 1;
1038 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
1039 if (GC.IsNull()) return 1;
1041 Standard_Real U = Draw::Atof(a[2]);
1043 Standard_Boolean DrawPoint = ( n%2 == 0);
1044 if ( DrawPoint ) n--;
1048 if (n < 7) return 1;
1051 if (n < 9) return 1;
1054 Draw::Set(a[7] ,D2.X());
1055 Draw::Set(a[8],D2.Y());
1059 Draw::Set(a[5],D1.X());
1060 Draw::Set(a[6],D1.Y());
1066 Draw::Set(a[3],P.X());
1067 Draw::Set(a[4],P.Y());
1070 DrawTrSurf::Set(a[n], P);
1076 //=======================================================================
1077 //function : segment
1079 //=======================================================================
1081 static Standard_Integer segment (Draw_Interpretor& , Standard_Integer n, const char** a)
1083 if (n < 4) return 1;
1085 Handle(Geom_BezierCurve) GBz = DrawTrSurf::GetBezierCurve(a[1]);
1086 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1087 Handle(Geom2d_BezierCurve) GBz2d = DrawTrSurf::GetBezierCurve2d(a[1]);
1088 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1090 Standard_Real f = Draw::Atof(a[2]), l = Draw::Atof(a[3]);
1094 else if (!GBs.IsNull())
1096 else if (!GBz2d.IsNull())
1097 GBz2d->Segment(f,l);
1098 else if (!GBs2d.IsNull())
1099 GBs2d->Segment(f,l);
1108 //=======================================================================
1109 //function : setorigin
1111 //=======================================================================
1113 static Standard_Integer setorigin (Draw_Interpretor& , Standard_Integer n, const char** a)
1115 if (n < 3) return 1;
1117 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1118 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1121 GBs->SetOrigin(Draw::Atoi(a[2]));
1122 if (!GBs2d.IsNull())
1123 GBs2d->SetOrigin(Draw::Atoi(a[2]));
1132 //=======================================================================
1135 //=======================================================================
1137 static Standard_Integer point(Draw_Interpretor& , Standard_Integer n, const char** a)
1139 if (n < 4) return 1;
1141 gp_Pnt P(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]));
1142 DrawTrSurf::Set(a[1],P);
1145 gp_Pnt2d P(Draw::Atof(a[2]),Draw::Atof(a[3]));
1146 DrawTrSurf::Set(a[1],P);
1152 //=======================================================================
1155 //=======================================================================
1157 static Standard_Integer coord(Draw_Interpretor&,
1158 Standard_Integer n, const char** a)
1162 if ( !DrawTrSurf::GetPoint2d(a[1],P)) return 1;
1163 Draw::Set(a[2],P.X());
1164 Draw::Set(a[3],P.Y());
1168 if ( !DrawTrSurf::GetPoint(a[1],P)) return 1;
1169 Draw::Set(a[2],P.X());
1170 Draw::Set(a[3],P.Y());
1171 Draw::Set(a[4],P.Z());
1179 //=======================================================================
1182 //=======================================================================
1183 static Standard_Integer minmaxcurandinf(Draw_Interpretor& di,
1184 Standard_Integer argc, const char** argv)
1186 if (argc < 2) return 1;
1188 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(argv[1]);
1189 if (C1.IsNull()) return 1;
1192 Geom2dLProp_CurAndInf2d Sommets;
1194 Sommets.PerformCurExt (C1);
1195 if (Sommets.IsDone() && !Sommets.IsEmpty()) {
1196 for (Standard_Integer i = 1; i <= Sommets.NbPoints(); i++){
1197 Couleur = Draw_vert;
1198 if (Sommets.Type(i) == LProp_MinCur) {
1199 Couleur = Draw_orange;
1200 di << " Maximum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1203 di << " Minimum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1205 gp_Pnt2d P = C1->Value(Sommets.Parameter(i));
1206 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Couleur);
1212 Geom2dLProp_CurAndInf2d Sommets2;
1213 Sommets2.PerformInf (C1);
1215 if (Sommets2.IsDone() && !Sommets2.IsEmpty()) {
1216 for (Standard_Integer i = 1; i <= Sommets2.NbPoints(); i++){
1217 gp_Pnt2d P = C1->Value(Sommets2.Parameter(i));
1218 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Draw_bleu);
1220 di << " Inflexion at U ="<<Sommets2.Parameter(i)<<"\n";
1226 //=======================================================================
1227 //function : shcurvature
1228 //purpose : affiche le peigne de courbure
1229 //=======================================================================
1230 static Standard_Integer shcurvature(Draw_Interpretor&,
1231 Standard_Integer argc, const char** argv)
1233 if (argc < 2) return 1;
1235 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1236 ::DownCast(Draw::Get(argv[1]));
1237 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1238 ::DownCast(Draw::Get(argv[1]));
1241 if (C3d.IsNull()) return 1;
1242 C3d->ShowCurvature();
1245 C2d->ShowCurvature();
1251 //=======================================================================
1252 //function : clcurvature
1253 //purpose : efface le peigne de courbure
1254 //=======================================================================
1255 static Standard_Integer clcurvature(Draw_Interpretor&,
1256 Standard_Integer argc, const char** argv)
1258 if (argc < 2) return 1;
1259 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1260 ::DownCast(Draw::Get(argv[1]));
1261 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1262 ::DownCast(Draw::Get(argv[1]));
1265 if (C3d.IsNull()) return 1;
1266 C3d->ClearCurvature();
1269 C2d->ClearCurvature();
1275 //=======================================================================
1276 //function : radiusmax
1277 //purpose : definit le rayon de courbure maximum a afficher
1278 //=======================================================================
1279 static Standard_Integer radiusmax(Draw_Interpretor&,
1280 Standard_Integer argc, const char** argv)
1282 if (argc < 3) return 1;
1283 Standard_Real Radius = Draw::Atof(argv[2]);
1284 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1285 ::DownCast(Draw::Get(argv[1]));
1286 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1287 ::DownCast(Draw::Get(argv[1]));
1290 if (C3d.IsNull()) return 1;
1291 C3d->SetRadiusMax(Radius);
1294 C2d->SetRadiusMax(Radius);
1300 //=======================================================================
1301 //function : radiusratio
1302 //purpose : definit le ratio du rayon de courbure a afficher
1303 //=======================================================================
1304 static Standard_Integer radiusratio(Draw_Interpretor&,
1305 Standard_Integer argc, const char** argv)
1307 if (argc < 3) return 1;
1308 Standard_Real Ratio = Draw::Atof(argv[2]);
1309 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1310 ::DownCast(Draw::Get(argv[1]));
1311 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1312 ::DownCast(Draw::Get(argv[1]));
1315 if (C3d.IsNull()) return 1;
1316 C3d->SetRadiusRatio(Ratio);
1319 C2d->SetRadiusRatio(Ratio);
1325 //=======================================================================
1328 //=======================================================================
1329 static Standard_Integer localprop(Draw_Interpretor& di,
1330 Standard_Integer argc, const char** argv)
1332 if (argc < 3) return 1;
1334 Standard_Real U = Draw::Atof(argv[2]);
1336 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(argv[1]);
1337 Handle(Geom_Curve) C3d;
1341 C3d = DrawTrSurf::GetCurve(argv[1]);
1342 if (C3d.IsNull()) return 1;
1343 GeomLProp_CLProps Prop (C3d,2,Precision::Confusion());
1344 Prop.SetParameter(U);
1345 Handle(Draw_Marker3D)drp = new Draw_Marker3D(Prop.Value(),
1349 if (Prop.IsTangentDefined()) {
1350 Standard_Real K = Prop.Curvature();
1351 di <<" Curvature : "<<K<<"\n";
1353 if (Abs(K) > Precision::Confusion()) {
1354 Standard_Real R = 1/Abs(K);
1356 Prop.CentreOfCurvature(Center);
1361 gp_Dir AxC = Nor^Tang;
1362 gp_Ax2 Axe(Center,AxC,Nor);
1363 Handle(Geom_Circle) Cir3d = new Geom_Circle(Axe,R);
1364 Handle(DrawTrSurf_Curve) dr;
1365 dr = new DrawTrSurf_Curve(Cir3d);
1371 di <<"Tangent undefined.\n";
1374 Geom2dLProp_CLProps2d Prop (C2d,2,Precision::Confusion());
1375 Prop.SetParameter(U);
1376 Handle(Draw_Marker2D) drp = new Draw_Marker2D(Prop.Value(),
1380 if (Prop.IsTangentDefined()) {
1381 Standard_Real K = Prop.Curvature();
1384 di <<" Curvature : "<<K<<"\n";
1386 if (Abs(K) > Precision::Confusion()) {
1387 Standard_Real R = 1/Abs(K);
1388 Prop.CentreOfCurvature(Center);
1389 gp_Ax2d Axe(Center,gp::DX2d());
1390 Handle(Geom2d_Circle) Cir2d = new Geom2d_Circle(Axe,R);
1391 Handle(DrawTrSurf_Curve2d) dr;
1392 dr = new DrawTrSurf_Curve2d(Cir2d,Draw_rouge,30,Standard_False);
1398 di <<"Tangent undefined.\n";
1402 //=======================================================================
1403 //function : rawcont
1405 //=======================================================================
1407 static Standard_Integer rawcont(Draw_Interpretor& di, Standard_Integer n, const char** a)
1409 if (n < 5) return 1;
1411 Handle(Geom_Curve) GC1;
1412 GC1 = DrawTrSurf::GetCurve(a[1]);
1413 Handle(Geom_Curve) GC2;
1414 GC2 = DrawTrSurf::GetCurve(a[2]);
1415 Standard_Real param1 =
1417 Standard_Real param2 =
1419 if (GC1.IsNull() || GC2.IsNull())
1427 if (a_point2.SquareDistance(a_point1) < Precision::Confusion()) {
1428 GeomAbs_Shape cont =
1429 GeomLProp::Continuity(GC1,
1435 Precision::Confusion(),
1436 Precision::Angular()) ;
1439 di << " C0 Continuity \n" ;
1442 di << " G1 Continuity \n" ;
1445 di << " C1 Continuity \n" ;
1448 di << " G2 Continuity \n" ;
1451 di << " C2 Continuity \n" ;
1454 di << " C3 Continuity \n" ;
1457 di << " CN Continuity \n" ;
1464 di << " not C0 continuity \n" ;
1468 //=======================================================================
1469 //function : approxcurveonsurf
1471 //=======================================================================
1472 static Standard_Integer approxcurveonsurf(Draw_Interpretor& di, Standard_Integer n, const char** a)
1474 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1475 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1476 Standard_Integer MaxDeg = 14; // Maximum degree
1477 Standard_Integer MaxSeg = 16; /*1*/ // Maximum number of segments
1479 if ( n>8 || n<4) return 1;
1481 if (n>4) Tol = Max(Draw::Atof(a[4]),1.e-10);
1484 if (Draw::Atoi(a[5]) == 0) Continuity = GeomAbs_C0;
1485 if (Draw::Atoi(a[5]) == 2) Continuity = GeomAbs_C2;
1489 MaxDeg = Draw::Atoi(a[6]);
1490 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1493 if (n>7) MaxSeg = Draw::Atoi(a[7]);
1494 Handle(Geom2d_Curve) curve2d = DrawTrSurf::GetCurve2d(a[2]);
1495 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[3]);
1497 Handle(Geom2dAdaptor_HCurve) A2d = new (Geom2dAdaptor_HCurve)(curve2d);
1498 Handle(GeomAdaptor_HSurface) AS = new (GeomAdaptor_HSurface)(Surf);
1500 Approx_CurveOnSurface App(A2d, AS, A2d->FirstParameter(), A2d->LastParameter(),
1501 Tol, Continuity, MaxDeg, MaxSeg,
1502 Standard_True, Standard_False);
1504 if(App.HasResult()) {
1505 Handle(Geom_BSplineCurve) BSCurve = App.Curve3d();
1506 DrawTrSurf::Set(a[1], BSCurve);
1510 di << "Approximation failed !\n";
1515 //=======================================================================
1516 //function : approxcurve
1518 //=======================================================================
1519 static Standard_Integer approxcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1521 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1522 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1523 Standard_Integer MaxDeg = 14; // Maximum degree
1524 Standard_Integer MaxSeg = 16; // Maximum number of segments
1526 Standard_Integer Case, shift;
1527 // Case == 1 : 3d approximation without reparametrization
1528 // Case == 2 : 2d approximation without reparametrization
1529 // Case == 3 : 3d approximation with reparametrization
1530 // Case == 4 : curve_on_surface approximation with reparametrization
1531 // Case == 5 : 2 curves_on_surfaces approximation with reparametrization
1533 Handle(Geom_Curve) curve;
1534 Handle(Geom2d_Curve) curve2d, curve2d2;
1535 Handle(Geom_Surface) surface, surface2;
1539 if (!strcmp(a[1],"-L")) {
1540 // aproximation with curvilinear abscissa reparametrization
1541 if (n > 11 || n < 4) return 1;
1543 curve = DrawTrSurf::GetCurve(a[3]);
1544 if (!curve.IsNull()) {
1549 // approx curve_on_surface
1550 if (n < 5) return 1;
1551 curve2d = DrawTrSurf::GetCurve2d(a[3]);
1552 surface = DrawTrSurf::GetSurface(a[4]);
1553 if (curve2d.IsNull() || surface.IsNull()) {
1557 curve2d2 = DrawTrSurf::GetCurve2d(a[5]);
1558 surface2 = DrawTrSurf::GetSurface(a[6]);
1559 if (curve2d2.IsNull() || surface2.IsNull()) {
1564 // approx 2 curves_on_surfaces
1576 // aproximation without reparamitrization
1577 if ( n>7 || n<3) return 1;
1579 curve = DrawTrSurf::GetCurve(a[2]);
1580 if (curve.IsNull()) {
1581 curve2d = DrawTrSurf::GetCurve2d(a[2]);
1582 if (curve2d.IsNull()) {
1591 if (n>shift) Tol = Max(Draw::Atof(a[shift]),1.e-10);
1594 if (Draw::Atoi(a[shift+1]) == 0) Continuity = GeomAbs_C0;
1595 if (Draw::Atoi(a[shift+1]) == 2) Continuity = GeomAbs_C2;
1599 MaxDeg = Draw::Atoi(a[shift+2]);
1600 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1603 if (n>shift+3) MaxSeg = Draw::Atoi(a[shift+3]);
1606 GeomConvert_ApproxCurve appr(curve, Tol, Continuity, MaxSeg, MaxDeg);
1607 if(appr.HasResult()) {
1609 Standard_SStream aSStream;
1610 appr.Dump(aSStream);
1612 Handle(Geom_BSplineCurve) BSCurve = appr.Curve();
1613 DrawTrSurf::Set(a[1], BSCurve);
1617 else if (Case == 2) {
1618 Geom2dConvert_ApproxCurve appr(curve2d, Tol, Continuity, MaxSeg, MaxDeg);
1619 if(appr.HasResult()) {
1621 Standard_SStream aSStream;
1622 appr.Dump(aSStream);
1624 Handle(Geom2d_BSplineCurve) BSCurve = appr.Curve();
1625 DrawTrSurf::Set(a[1], BSCurve);
1629 else if (Case == 3) {
1630 Handle(Adaptor3d_HCurve) HACur = new GeomAdaptor_HCurve(curve);
1631 Approx_CurvilinearParameter appr(HACur, Tol, Continuity, MaxDeg, MaxSeg);
1632 if(appr.HasResult()) {
1634 Standard_SStream aSStream;
1635 appr.Dump(aSStream);
1637 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1638 DrawTrSurf::Set(a[2], BSCurve);
1641 else if (Case == 4) {
1642 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1643 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1644 Approx_CurvilinearParameter appr(HACur2d, HASur, Tol, Continuity, MaxDeg, MaxSeg);
1645 if(appr.HasResult()) {
1647 Standard_SStream aSStream;
1648 appr.Dump(aSStream);
1650 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1651 DrawTrSurf::Set(a[2], BSCurve);
1655 else if (Case == 5) {
1656 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1657 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1658 Handle(Adaptor2d_HCurve2d) HACur2d2 = new Geom2dAdaptor_HCurve(curve2d2);
1659 Handle(Adaptor3d_HSurface) HASur2 = new GeomAdaptor_HSurface(surface2);
1660 Approx_CurvilinearParameter appr(HACur2d, HASur, HACur2d2, HASur2, Tol, Continuity, MaxDeg, MaxSeg);
1661 if(appr.HasResult()) {
1663 Standard_SStream aSStream;
1664 appr.Dump(aSStream);
1666 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1667 DrawTrSurf::Set(a[2], BSCurve);
1675 //=======================================================================
1676 //function : newbspline
1677 //purpose : reduce the multiplicity of the knots to their minimum
1678 // compared to the degree of the curve
1679 //=======================================================================
1681 static Standard_Integer splitc1(Draw_Interpretor& di,
1682 Standard_Integer n, const char** c)
1684 {Standard_Real tolerance=1.0e-5,
1685 angular_tolerance = 1.0e-4 ;
1686 Standard_Integer optiontab,i;
1690 optiontab=Draw::Atoi(c[2]);
1692 tolerance=Draw::Atof(c[3]);
1694 angular_tolerance = Draw::Atof(c[4]) ;
1696 Handle(Geom_Curve) ACurve = Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(c[1])) ;
1698 Standard_Real f = ACurve->FirstParameter();
1699 Standard_Real l = ACurve->LastParameter();
1701 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1702 di << " Error: Infinite curves\n";
1706 Handle(Geom_BSplineCurve) BS = GeomConvert::CurveToBSplineCurve(ACurve);
1708 if ( BS.IsNull()) return 1;
1711 Handle(TColGeom_HArray1OfBSplineCurve) tabBS;
1712 GeomConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1716 for (i=0;i<=(tabBS->Length()-1);i++){
1717 Sprintf(name,"%s_%d",c[1],i+1);
1718 Standard_CString new_name = name ;
1719 DrawTrSurf::Set(new_name,
1721 di.AppendElement(name);
1725 GeomConvert::C0BSplineToC1BSplineCurve(BS,
1727 angular_tolerance) ;
1729 DrawTrSurf::Set(c[1],BS);
1734 //=======================================================================
1735 //function : splitc12d
1736 //purpose : reduce the multiplicity of the knots to their minimum
1737 // compared to the degree of the curve
1738 //=======================================================================
1740 static Standard_Integer splitc12d(Draw_Interpretor& di,
1741 Standard_Integer n, const char** c)
1743 {Standard_Real tolerance=1.0e-5,
1744 angular_tolerance = 1.0e-4 ;
1745 Standard_Integer optiontab,i;
1749 optiontab=Draw::Atoi(c[2]);
1751 tolerance=Draw::Atof(c[3]);
1753 angular_tolerance = Draw::Atof(c[4]) ;
1754 Handle(Geom2d_Curve) ACurve = Handle(Geom2d_Curve)::DownCast(DrawTrSurf::GetCurve2d(c[1])) ;
1756 Standard_Real f = ACurve->FirstParameter();
1757 Standard_Real l = ACurve->LastParameter();
1759 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1760 di << " Error: Infinite curves\n";
1764 Handle(Geom2d_BSplineCurve) BS = Geom2dConvert::CurveToBSplineCurve(ACurve);
1766 if ( BS.IsNull()) return 1;
1769 Handle(TColGeom2d_HArray1OfBSplineCurve) tabBS;
1770 Geom2dConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1774 for (i=0;i<=(tabBS->Length()-1);i++){
1775 Sprintf(name,"%s_%d",c[1],i+1);
1776 Standard_CString new_name = name ;
1777 DrawTrSurf::Set(new_name,
1779 di.AppendElement(name);
1783 Geom2dConvert::C0BSplineToC1BSplineCurve(BS,tolerance);
1784 DrawTrSurf::Set(c[1],BS);
1789 //=======================================================================
1790 //function : canceldenom
1791 //purpose : set the value of the denominator cancel its first
1792 // derivative on the boundaries of the surface if possible
1793 //=======================================================================
1795 static Standard_Integer canceldenom(Draw_Interpretor& ,
1796 Standard_Integer n, const char** c)
1798 {Standard_Integer uoption,voption;
1799 Standard_Boolean udirection=Standard_False;
1800 Standard_Boolean vdirection=Standard_False;
1802 uoption=Draw::Atoi(c[2]);
1803 voption=Draw::Atoi(c[3]);
1805 udirection=Standard_True;
1807 vdirection=Standard_True;
1808 Handle(Geom_BSplineSurface) BSurf = Handle(Geom_BSplineSurface)::DownCast(DrawTrSurf::GetBSplineSurface(c[1]));
1809 GeomLib::CancelDenominatorDerivative(BSurf,udirection,vdirection);
1810 DrawTrSurf::Set(c[1],BSurf);
1814 //=======================================================================
1816 //purpose : eval curve's length
1817 //=======================================================================
1819 static Standard_Integer length(Draw_Interpretor& di,
1820 Standard_Integer n, const char** a)
1823 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
1824 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[1]);
1825 Standard_Real Tol = Precision::Confusion(), L;
1826 if (n==3) Tol = Draw::Atof(a[2]);
1829 GeomAdaptor_Curve AC(GC);
1830 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1832 else if (!GC2d.IsNull()) {
1833 Geom2dAdaptor_Curve AC(GC2d);
1834 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1837 di << a[1] << "is not a curve\n";
1841 di << "The length " << a[1] << " is " << L << "\n";
1847 //=======================================================================
1848 //function : CurveCommands
1850 //=======================================================================
1852 void GeomliteTest::CurveCommands(Draw_Interpretor& theCommands)
1855 static Standard_Boolean loaded = Standard_False;
1857 loaded = Standard_True;
1859 DrawTrSurf::BasicCommands(theCommands);
1865 g = "GEOMETRY curves creation";
1868 theCommands.Add("point",
1869 "point name x y [z]",
1873 theCommands.Add("line",
1874 "line name pos dir",
1878 theCommands.Add("circle",
1879 "circle name x y [z [dx dy dz]] [ux uy [uz]] radius",
1883 theCommands.Add("ellipse",
1884 "ellipse name x y [z [dx dy dz]] [ux uy [uz]] major minor",
1887 theCommands.Add("parabola",
1888 "parabola name x y [z [dx dy dz]] [ux uy [uz]] focal",
1891 theCommands.Add("hyperbola",
1892 "hyperbola name x y [z [dx dy dz]] [ux uy [uz]] major minor",
1896 theCommands.Add("beziercurve",
1897 "beziercurve name nbpole pole, [weight]",
1901 theCommands.Add("bsplinecurve",
1902 "bsplinecurve name degree nbknots knot, umult pole, weight",
1906 theCommands.Add("pbsplinecurve",
1907 "pbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
1911 theCommands.Add("2dbeziercurve",
1912 "2dbeziercurve name nbpole pole, [weight]",
1916 theCommands.Add("2dbsplinecurve",
1917 "2dbsplinecurve name degree nbknots knot, umult pole, weight",
1921 theCommands.Add("2dpbsplinecurve",
1922 "2dpbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
1926 g = "GEOMETRY Curves and Surfaces modification";
1928 theCommands.Add("reverse",
1929 "reverse name ... ",
1933 theCommands.Add("cmovep",
1934 "cmovep name index dx dy dz",
1938 theCommands.Add("cmovepoint",
1939 "cmovepoint name u dx dy [dz index1 index2]",
1943 theCommands.Add("cmovetangent",
1944 "cmovetangent name u x y [z] tx ty [tz constraint = 0]",
1948 theCommands.Add("insertknot",
1949 "insertknot name knot [mult = 1] [knot mult ...]",
1953 theCommands.Add("setknot",
1954 "setknot name index knot [mult]",
1958 theCommands.Add("remknot",
1959 "remknot name index [mult] [tol]",
1963 theCommands.Add("incdeg",
1964 "incdeg name degree",
1968 theCommands.Add("rempole",
1969 "rempole name index",
1973 theCommands.Add("insertpole",
1974 "insertpole name index x y [z] [weight]",
1978 theCommands.Add("cfindp",
1979 "cfindp name view x y index",
1983 theCommands.Add("setperiodic",
1984 "setperiodic name ...",
1988 theCommands.Add("setnotperiodic",
1989 "setnotperiodic name",
1993 theCommands.Add("segment",
1994 "segment name Ufirst Ulast",
1998 theCommands.Add("setorigin",
1999 "setorigin name knotindex",
2003 g = "GEOMETRY curves and surfaces analysis";
2005 theCommands.Add("cvalue",
2006 "cvalue curvename U X Y Z [D1X D1Y D1Z D2X D2Y D2Z]",
2010 theCommands.Add("2dcvalue",
2011 "2dcvalue curvename U X Y [D1X D1Y D2X D2Y]",
2015 theCommands.Add("coord",
2016 "coord P x y [z]: set in x y [z] the coordinates of P",
2020 theCommands.Add("minmaxcurandinf",
2021 "minmaxcurandinf curve",
2025 theCommands.Add("shcurvature",
2026 "shcurvature curvename",
2030 theCommands.Add("clcurvature",
2031 "clcurvature curvename",
2036 theCommands.Add("radiusmax",
2037 "radiusmax curvename radius",
2041 theCommands.Add("radiusratio",
2042 "radiusratio curvename ratio",
2045 theCommands.Add("localprop",
2046 "localprop curvename U",
2049 theCommands.Add("rawcont",
2050 "rawcont curve1 curve2 u1 u2",
2053 theCommands.Add("approxcurve",
2054 "approxcurve [-L] name curve1 [Surf1] [curve2d2 Surf2] [Tol [cont [maxdeg [maxseg]]]] ",
2058 theCommands.Add("approxcurveonsurf",
2059 "approxcurveonsurf name curve2d surface [Tol [cont [maxdeg [maxseg]]]] ",
2061 approxcurveonsurf,g);
2063 theCommands.Add("length", "length curve [Tol]",
2068 theCommands.Add("splitc1",
2069 "splitc1 bspline resultinarray(0/1) [tol] [angtol] ",
2073 theCommands.Add("splitc12d",
2074 "splitc12d bspline2d resultinarray(0/1) [tol] [angtol] ",
2077 theCommands.Add("canceldenom",
2078 "canceldenom BSpline-Surface UDirection(0/1) VDirection(0/1)",