1 // Created on: 1993-08-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 // Modified by xab, Tue Mar 11 18:31:18 1997
22 // Modified by PMN 14/04/97 : Passage a Geomlite
23 // Modified by JPI 01/08/97 : ajout de la commande approxcurve
25 #include <GeomliteTest.hxx>
26 #include <Draw_Appli.hxx>
27 #include <DrawTrSurf.hxx>
28 #include <DrawTrSurf_Curve.hxx>
29 #include <DrawTrSurf_Curve2d.hxx>
30 #include <DrawTrSurf_BezierCurve.hxx>
31 #include <DrawTrSurf_BSplineCurve.hxx>
32 #include <DrawTrSurf_BezierCurve2d.hxx>
33 #include <DrawTrSurf_BSplineCurve2d.hxx>
34 #include <Draw_Marker3D.hxx>
35 #include <Draw_Marker2D.hxx>
37 #include <Draw_Interpretor.hxx>
38 #include <Draw_Color.hxx>
39 #include <Draw_Display.hxx>
41 #include <BSplCLib.hxx>
45 #include <gp_Parab2d.hxx>
46 #include <gp_Elips2d.hxx>
47 #include <gp_Hypr2d.hxx>
49 #include <Geom_Line.hxx>
50 #include <Geom_Circle.hxx>
51 #include <Geom_Ellipse.hxx>
52 #include <Geom_Parabola.hxx>
53 #include <Geom_Hyperbola.hxx>
54 #include <Geom_BezierCurve.hxx>
55 #include <Geom_BSplineCurve.hxx>
56 #include <GeomAdaptor_Surface.hxx>
57 #include <GeomAdaptor_HSurface.hxx>
59 #include <GeomLib.hxx>
60 #include <GeomConvert.hxx>
61 #include <Geom2dConvert.hxx>
63 #include <Geom2d_Line.hxx>
64 #include <Geom2d_Circle.hxx>
65 #include <Geom2d_Ellipse.hxx>
66 #include <Geom2d_Parabola.hxx>
67 #include <Geom2d_Hyperbola.hxx>
68 #include <Geom2d_BezierCurve.hxx>
69 #include <Geom2d_BSplineCurve.hxx>
71 #include <GeomLProp.hxx>
72 #include <GeomLProp_CLProps.hxx>
73 #include <Geom2dLProp_CLProps2d.hxx>
74 #include <Geom2dLProp_CurAndInf2d.hxx>
76 #include <TColgp_Array1OfPnt.hxx>
77 #include <TColgp_Array1OfPnt2d.hxx>
78 #include <TColStd_Array1OfReal.hxx>
79 #include <TColStd_Array1OfInteger.hxx>
81 #include <GeomAbs_SurfaceType.hxx>
82 #include <GeomAbs_CurveType.hxx>
84 #include <Precision.hxx>
88 #include <TColStd_HArray1OfReal.hxx>
89 #include <TColStd_HArray2OfReal.hxx>
90 #include <TColStd_HArray1OfInteger.hxx>
91 #include <TColStd_Array1OfReal.hxx>
92 #include <TColStd_Array1OfInteger.hxx>
94 #include <TColGeom_HArray1OfBSplineCurve.hxx>
95 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
96 #include <Convert_CompPolynomialToPoles.hxx>
97 #include <CPnts_AbscissaPoint.hxx>
98 #include <GCPnts_AbscissaPoint.hxx>
101 #include <GeomAbs_Shape.hxx>
102 #include <Geom_Curve.hxx>
103 #include <GeomConvert.hxx>
104 #include <GeomConvert_ApproxCurve.hxx>
105 #include <Geom2dConvert_ApproxCurve.hxx>
106 #include <Geom2d_Curve.hxx>
108 #include <GeomAdaptor_HCurve.hxx>
109 #include <GeomAdaptor_Curve.hxx>
110 #include <Geom2dAdaptor_HCurve.hxx>
111 #include <GeomAdaptor_HCurve.hxx>
112 #include <Approx_CurvilinearParameter.hxx>
113 #include <Approx_CurveOnSurface.hxx>
115 Standard_IMPORT Draw_Viewer dout;
118 //=======================================================================
119 //function : anacurve
121 //=======================================================================
123 static Standard_Integer anacurve (Draw_Interpretor& , Standard_Integer n, const char** a)
127 Handle(Geom_Geometry) result;
128 Handle(Geom2d_Curve) result2d;
130 if (!strcmp(a[0],"line")) {
132 result2d = new Geom2d_Line(gp_Pnt2d(atof(a[2]),atof(a[3])),
133 gp_Dir2d(atof(a[4]),atof(a[5])));
135 result = new Geom_Line(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
136 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])));
141 else if (!strcmp(a[0],"circle")) {
144 new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
149 new Geom_Circle(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
154 new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
155 gp_Dir2d(atof(a[4]),atof(a[5]))),
159 new Geom_Circle(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
160 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7]))),
164 new Geom_Circle(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
165 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])),
166 gp_Dir(atof(a[8]),atof(a[9]),atof(a[10]))),
172 else if (!strcmp(a[0],"parabola")) {
175 new Geom2d_Parabola(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
180 new Geom_Parabola(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
185 new Geom2d_Parabola(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
186 gp_Dir2d(atof(a[4]),atof(a[5]))),
190 new Geom_Parabola(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
191 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7]))),
195 new Geom_Parabola(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
196 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])),
197 gp_Dir(atof(a[8]),atof(a[9]),atof(a[10]))),
203 else if (!strcmp(a[0],"ellipse")) {
206 new Geom2d_Ellipse(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
208 atof(a[4]),atof(a[5]));
211 new Geom_Ellipse(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
213 atof(a[5]),atof(a[6]));
216 new Geom2d_Ellipse(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
217 gp_Dir2d(atof(a[4]),atof(a[5]))),
218 atof(a[6]), atof(a[7]));
221 new Geom_Ellipse(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
222 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7]))),
223 atof(a[8]), atof(a[9]));
226 new Geom_Ellipse(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
227 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])),
228 gp_Dir(atof(a[8]),atof(a[9]),atof(a[10]))),
229 atof(a[11]), atof(a[12]));
234 else if (!strcmp(a[0],"hyperbola")) {
237 new Geom2d_Hyperbola(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
239 atof(a[4]),atof(a[5]));
242 new Geom_Hyperbola(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
244 atof(a[5]),atof(a[6]));
247 new Geom2d_Hyperbola(gp_Ax22d(gp_Pnt2d(atof(a[2]),atof(a[3])),
248 gp_Dir2d(atof(a[4]),atof(a[5]))),
249 atof(a[6]), atof(a[7]));
252 new Geom_Hyperbola(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
253 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7]))),
254 atof(a[8]), atof(a[9]));
257 new Geom_Hyperbola(gp_Ax2(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
258 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])),
259 gp_Dir(atof(a[8]),atof(a[9]),atof(a[10]))),
260 atof(a[11]), atof(a[12]));
265 if (!result.IsNull())
266 DrawTrSurf::Set(a[1],result);
267 else if (!result2d.IsNull())
268 DrawTrSurf::Set(a[1],result2d);
275 //=======================================================================
276 //function : polecurve
278 //=======================================================================
280 static Standard_Integer polecurve (Draw_Interpretor& , Standard_Integer n, const char** a)
282 Standard_Integer k,i;
287 if (!strcmp(a[0],"beziercurve")) {
289 Standard_Integer np = atoi(a[2]);
290 if (np == 0) return 1;
293 if (i < 3 || i > 4) return 1;
294 Standard_Boolean hasw = i == 4;
296 TColgp_Array1OfPnt poles(1,np);
297 TColStd_Array1OfReal weights(1,np);
300 for (i = 1; i <= np; i++) {
301 poles(i).SetCoord(atof(a[k]),atof(a[k+1]),atof(a[k+2]));
304 weights(i) = atof(a[k]);
309 Handle(Geom_BezierCurve) result;
311 result = new Geom_BezierCurve(poles,weights);
313 result = new Geom_BezierCurve(poles);
315 DrawTrSurf::Set(a[1],result);
318 else if (!strcmp((*a[0] == 'p') ? a[0]+1 : a[0],"bsplinecurve")) {
319 Standard_Integer deg = atoi(a[2]);
320 Standard_Integer nbk = atoi(a[3]);
322 TColStd_Array1OfReal knots(1, nbk);
323 TColStd_Array1OfInteger mults(1, nbk);
325 Standard_Integer Sigma = 0;
326 for (i = 1; i<=nbk; i++) {
327 knots( i) = atof(a[k]);
329 mults( i) = atoi(a[k]);
334 Standard_Boolean periodic = *a[0] == 'p';
337 np = Sigma - mults(nbk);
341 TColgp_Array1OfPnt poles (1, np);
342 TColStd_Array1OfReal weights(1, np);
344 for (i = 1; i <= np; i++) {
345 poles(i).SetCoord(atof(a[k]),atof(a[k+1]),atof(a[k+2]));
347 weights(i) = atof(a[k]);
351 Handle(Geom_BSplineCurve) result =
352 new Geom_BSplineCurve(poles, weights, knots, mults, deg, periodic);
353 DrawTrSurf::Set(a[1],result);
359 //=======================================================================
360 //function : polecurve2d
362 //=======================================================================
364 static Standard_Integer polecurve2d (Draw_Interpretor& , Standard_Integer n, const char** a)
366 Standard_Integer k,i;
371 if (!strcmp(a[0],"2dbeziercurve")) {
373 Standard_Integer np = atoi(a[2]);
374 if (np == 0) return 1;
377 if (i < 2 || i > 3) return 1;
378 Standard_Boolean hasw = i == 3;
380 TColgp_Array1OfPnt2d poles(1,np);
381 TColStd_Array1OfReal weights(1,np);
384 for (i = 1; i <= np; i++) {
385 poles(i).SetCoord(atof(a[k]),atof(a[k+1]));
388 weights(i) = atof(a[k]);
393 Handle(Geom2d_BezierCurve) result;
395 result = new Geom2d_BezierCurve(poles,weights);
397 result = new Geom2d_BezierCurve(poles);
399 DrawTrSurf::Set(a[1],result);
402 else if (!strcmp((*(a[0]+2) == 'p') ? a[0]+3 : a[0]+2,"bsplinecurve")) {
403 Standard_Integer deg = atoi(a[2]);
404 Standard_Integer nbk = atoi(a[3]);
406 TColStd_Array1OfReal knots(1, nbk);
407 TColStd_Array1OfInteger mults(1, nbk);
409 Standard_Integer Sigma = 0;
410 for (i = 1; i<=nbk; i++) {
411 knots( i) = atof(a[k]);
413 mults( i) = atoi(a[k]);
418 Standard_Boolean periodic = *(a[0]+2) == 'p';
421 np = Sigma - mults(nbk);
425 TColgp_Array1OfPnt2d poles (1, np);
426 TColStd_Array1OfReal weights(1, np);
428 for (i = 1; i <= np; i++) {
429 poles(i).SetCoord(atof(a[k]),atof(a[k+1]));
431 weights(i) = atof(a[k]);
435 Handle(Geom2d_BSplineCurve) result =
436 new Geom2d_BSplineCurve(poles, weights, knots, mults, deg, periodic);
437 DrawTrSurf::Set(a[1],result);
443 //=======================================================================
446 //=======================================================================
448 static Standard_Integer reverse (Draw_Interpretor& , Standard_Integer n, const char** a)
453 for (i = 1; i < n; i++) {
455 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[i]);
460 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[i]);
461 if (!GC2d.IsNull()) {
469 //=======================================================================
470 //function : cmovepole
472 //=======================================================================
474 static Standard_Integer cmovepole (Draw_Interpretor& , Standard_Integer n, const char** a)
478 Standard_Real dx = atof(a[3]);
479 Standard_Real dy = atof(a[4]);
481 if (n >= 6) dz = atof(a[5]);
482 Standard_Integer Index = atoi(a[2]);
484 Handle(Geom_BezierCurve) G1 = DrawTrSurf::GetBezierCurve(a[1]);
486 gp_Pnt P = G1->Pole(Index);
487 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
488 G1->SetPole(Index,P);
494 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
496 gp_Pnt P = G2->Pole(Index);
497 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
498 G2->SetPole(Index,P);
503 Handle(Geom2d_BezierCurve) G3 = DrawTrSurf::GetBezierCurve2d(a[1]);
505 gp_Pnt2d P = G3->Pole(Index);
506 P.SetCoord(P.X()+dx, P.Y()+dy);
507 G3->SetPole(Index,P);
513 Handle(Geom2d_BSplineCurve) G4 = DrawTrSurf::GetBSplineCurve2d(a[1]);
515 gp_Pnt2d P = G4->Pole(Index);
516 P.SetCoord(P.X()+dx, P.Y()+dy);
517 G4->SetPole(Index,P);
527 //=======================================================================
528 //function : cmovetangent
530 //=======================================================================
532 static Standard_Integer cmovetangent (Draw_Interpretor& di, Standard_Integer n, const char** a)
534 Standard_Integer dimension,
565 if (dimension == 3) {
566 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
573 condition = Max(atoi(a[9]), -1) ;
574 condition = Min(condition, G2->Degree()-1) ;
579 tangent.SetCoord(tx,ty,tz) ;
581 G2->MovePointAndTangent(u,
588 if (! error_status) {
592 di << "Not enought degree of freedom increase degree please" << "\n";
599 Handle(Geom2d_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve2d(a[1]);
604 condition = Max(atoi(a[7]), -1) ;
605 condition = Min(condition, G2->Degree()-1) ;
610 tangent.SetCoord(tx,ty) ;
612 G2->MovePointAndTangent(u,
619 if (! error_status) {
623 di << "Not enought degree of freedom increase degree please" << "\n";
633 //=======================================================================
634 //function : cmovepoint
636 //=======================================================================
638 static Standard_Integer cmovepoint (Draw_Interpretor& , Standard_Integer n, const char** a)
642 Standard_Real dx = atof(a[3]);
643 Standard_Real dy = atof(a[4]);
645 if (n >= 6 && n != 7) dz = atof(a[5]);
646 Standard_Real u = atof(a[2]);
647 Standard_Integer index1 = 0;
648 Standard_Integer index2 = 0;
649 Standard_Integer fmodif, lmodif;
659 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
663 index2 = G2->NbPoles()-1;
667 p.SetCoord(p.X()+dx, p.Y()+dy, p.Z()+dz);
668 G2->MovePoint(u, p, index1, index2, fmodif, lmodif);
673 Handle(Geom2d_BSplineCurve) G4 = DrawTrSurf::GetBSplineCurve2d(a[1]);
677 index2 = G4->NbPoles()-1;
681 p.SetCoord(p.X()+dx, p.Y()+dy);
682 G4->MovePoint(u, p, index1, index2, fmodif, lmodif);
689 //=======================================================================
690 //function : cinsertknot
692 //=======================================================================
694 static Standard_Integer cinsertknot (Draw_Interpretor& , Standard_Integer n, const char** a)
698 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
699 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
701 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
704 Standard_Real knot = atof(a[2]);
705 Standard_Integer mult = 1;
706 if (n == 4) mult = atoi(a[3]);
708 GBs->InsertKnot(knot,mult,Precision::PConfusion());
710 GBs2d->InsertKnot(knot,mult,Precision::PConfusion());
714 // multiple insertion
715 if (n % 2 != 0) return 1;
716 Standard_Integer i,nbk = (n-2) / 2;
717 TColStd_Array1OfReal knots(1,nbk);
718 TColStd_Array1OfInteger mults(1,nbk);
719 for (i = 2; i < n; i += 2) {
720 knots(i/2) = atof(a[i]);
721 mults(i/2) = atoi(a[i+1]);
725 GBs->InsertKnots(knots,mults,Precision::PConfusion());
727 GBs2d->InsertKnots(knots,mults,Precision::PConfusion());
735 //=======================================================================
736 //function : csetknot
738 //=======================================================================
740 static Standard_Integer csetknot (Draw_Interpretor& , Standard_Integer n, const char** a)
744 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
745 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
747 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
749 Standard_Integer index = atoi(a[2]);
750 Standard_Real knot = atof(a[3]);
754 GBs->SetKnot(index,knot);
756 GBs2d->SetKnot(index,knot);
759 Standard_Integer mult = atoi(a[4]);
761 GBs->SetKnot(index,knot,mult);
763 GBs2d->SetKnot(index,knot,mult);
770 //=======================================================================
771 //function : cremknot
773 //=======================================================================
775 static Standard_Integer cremknot (Draw_Interpretor& di, Standard_Integer n, const char** a)
779 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
780 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
782 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
784 Standard_Integer index = atoi(a[2]);
785 Standard_Integer mult = 0;
786 if (n >= 4) mult = atoi(a[3]);
788 Standard_Real tol = RealLast();
789 if (n >= 5) tol = atof(a[4]);
792 if (!GBs->RemoveKnot(index,mult,tol))
793 di << "Remove knots failed"<<"\n";
796 if (!GBs2d->RemoveKnot(index,mult,tol))
797 di << "Remove knots failed"<<"\n";
804 //=======================================================================
805 //function : increasedegree
807 //=======================================================================
809 static Standard_Integer increasedegree (Draw_Interpretor& , Standard_Integer n, const char** a)
813 Standard_Integer Deg = atoi(a[2]);
815 Handle(Geom_BezierCurve) GBz = DrawTrSurf::GetBezierCurve(a[1]);
816 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
817 Handle(Geom2d_BezierCurve) GBz2d = DrawTrSurf::GetBezierCurve2d(a[1]);
818 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
822 else if (!GBs.IsNull())
823 GBs->IncreaseDegree(Deg);
824 else if (!GBz2d.IsNull())
825 GBz2d->Increase(Deg);
826 else if (!GBs2d.IsNull())
827 GBs2d->IncreaseDegree(Deg);
835 //=======================================================================
836 //function : removepole
838 //=======================================================================
840 static Standard_Integer removepole (Draw_Interpretor& di, Standard_Integer n, const char** a)
844 Standard_Integer Index = atoi(a[2]);
846 Handle(Geom_BezierCurve) GBZ = DrawTrSurf::GetBezierCurve(a[1]);
847 Handle(Geom2d_BezierCurve) GBZ2d = DrawTrSurf::GetBezierCurve2d(a[1]);
849 GBZ->RemovePole(Index);
851 else if (!GBZ2d.IsNull()) {
852 GBZ2d->RemovePole(Index);
855 di << "rempole needs a bezier curve";
863 //=======================================================================
864 //function : insertpole
866 //=======================================================================
868 static Standard_Integer insertpole (Draw_Interpretor& di, Standard_Integer n, const char** a)
872 Standard_Integer Index = atoi(a[2]);
874 Handle(Geom_BezierCurve) GBZ = DrawTrSurf::GetBezierCurve(a[1]);
875 Handle(Geom2d_BezierCurve) GBZ2d = DrawTrSurf::GetBezierCurve2d(a[1]);
877 gp_Pnt P (atof(a[3]),atof(a[4]),atof(a[5]));
879 GBZ->InsertPoleAfter(Index,P,atof(a[6]));
881 GBZ->InsertPoleAfter(Index,P);
883 else if (!GBZ2d.IsNull()) {
884 gp_Pnt2d P (atof(a[3]),atof(a[4]));
886 GBZ2d->InsertPoleAfter(Index,P,atof(a[5]));
888 GBZ2d->InsertPoleAfter(Index,P);
891 di << "insertpole needs a bezier curve";
899 //=======================================================================
902 //=======================================================================
904 static Standard_Integer cfindp (Draw_Interpretor& , Standard_Integer n, const char** a)
908 Standard_Integer Index = 0;
909 Standard_Integer view = atoi(a[2]);
910 Standard_Real x = atof(a[3]);
911 Standard_Real y = atof(a[4]);
913 Draw_Display d = dout.MakeDisplay(view);
915 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
917 Handle(DrawTrSurf_BezierCurve) DBz =
918 Handle(DrawTrSurf_BezierCurve)::DownCast(D);
920 DBz->FindPole( x, y, d, 5, Index);
922 Handle(DrawTrSurf_BSplineCurve) DBs =
923 Handle(DrawTrSurf_BSplineCurve)::DownCast(D);
925 DBs->FindPole( x, y, d, 5, Index);
927 Handle(DrawTrSurf_BezierCurve2d) DBz =
928 Handle(DrawTrSurf_BezierCurve2d)::DownCast(D);
930 DBz->FindPole( x, y, d, 5, Index);
932 Handle(DrawTrSurf_BSplineCurve2d) DBs =
933 Handle(DrawTrSurf_BSplineCurve2d)::DownCast(D);
935 DBs->FindPole( x, y, d, 5, Index);
942 Draw::Set(a[5],Index);
948 //=======================================================================
949 //function : csetperiodic
951 //=======================================================================
953 static Standard_Integer csetperiodic (Draw_Interpretor& , Standard_Integer n, const char** a)
957 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
958 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
960 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
962 if (!strcmp(a[0],"setperiodic")) {
966 GBs2d->SetPeriodic();
968 else if (!strcmp(a[0],"setnotperiodic")) {
970 GBs->SetNotPeriodic();
972 GBs2d->SetNotPeriodic();
979 //=======================================================================
982 //=======================================================================
984 static Standard_Integer value (Draw_Interpretor& ,
985 Standard_Integer n, const char** a)
989 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
990 if (GC.IsNull()) return 1;
992 Standard_Real U = atof(a[2]);
994 Standard_Boolean DrawPoint = ( n%3 == 1);
1002 if (n < 12) return 1;
1005 Draw::Set(a[9] ,D2.X());
1006 Draw::Set(a[10],D2.Y());
1007 Draw::Set(a[11],D2.Z());
1011 Draw::Set(a[6],D1.X());
1012 Draw::Set(a[7],D1.Y());
1013 Draw::Set(a[8],D1.Z());
1019 Draw::Set(a[3],P.X());
1020 Draw::Set(a[4],P.Y());
1021 Draw::Set(a[5],P.Z());
1024 DrawTrSurf::Set(a[n],P);
1031 //=======================================================================
1032 //function : value2d
1034 //=======================================================================
1036 static Standard_Integer value2d (Draw_Interpretor& ,
1037 Standard_Integer n, const char** a)
1039 if (n < 4) return 1;
1041 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
1042 if (GC.IsNull()) return 1;
1044 Standard_Real U = atof(a[2]);
1046 Standard_Boolean DrawPoint = ( n%2 == 0);
1047 if ( DrawPoint ) n--;
1051 if (n < 7) return 1;
1054 if (n < 9) return 1;
1057 Draw::Set(a[7] ,D2.X());
1058 Draw::Set(a[8],D2.Y());
1062 Draw::Set(a[5],D1.X());
1063 Draw::Set(a[6],D1.Y());
1069 Draw::Set(a[3],P.X());
1070 Draw::Set(a[4],P.Y());
1073 DrawTrSurf::Set(a[n], P);
1079 //=======================================================================
1080 //function : segment
1082 //=======================================================================
1084 static Standard_Integer segment (Draw_Interpretor& , Standard_Integer n, const char** a)
1086 if (n < 4) return 1;
1088 Handle(Geom_BezierCurve) GBz = DrawTrSurf::GetBezierCurve(a[1]);
1089 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1090 Handle(Geom2d_BezierCurve) GBz2d = DrawTrSurf::GetBezierCurve2d(a[1]);
1091 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1093 Standard_Real f = atof(a[2]), l = atof(a[3]);
1097 else if (!GBs.IsNull())
1099 else if (!GBz2d.IsNull())
1100 GBz2d->Segment(f,l);
1101 else if (!GBs2d.IsNull())
1102 GBs2d->Segment(f,l);
1111 //=======================================================================
1112 //function : setorigin
1114 //=======================================================================
1116 static Standard_Integer setorigin (Draw_Interpretor& , Standard_Integer n, const char** a)
1118 if (n < 3) return 1;
1120 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1121 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1124 GBs->SetOrigin(atoi(a[2]));
1125 if (!GBs2d.IsNull())
1126 GBs2d->SetOrigin(atoi(a[2]));
1135 //=======================================================================
1138 //=======================================================================
1140 static Standard_Integer point(Draw_Interpretor& , Standard_Integer n, const char** a)
1142 if (n < 4) return 1;
1144 gp_Pnt P(atof(a[2]),atof(a[3]),atof(a[4]));
1145 DrawTrSurf::Set(a[1],P);
1148 gp_Pnt2d P(atof(a[2]),atof(a[3]));
1149 DrawTrSurf::Set(a[1],P);
1155 //=======================================================================
1158 //=======================================================================
1160 static Standard_Integer coord(Draw_Interpretor&,
1161 Standard_Integer n, const char** a)
1165 if ( !DrawTrSurf::GetPoint2d(a[1],P)) return 1;
1166 Draw::Set(a[2],P.X());
1167 Draw::Set(a[3],P.Y());
1171 if ( !DrawTrSurf::GetPoint(a[1],P)) return 1;
1172 Draw::Set(a[2],P.X());
1173 Draw::Set(a[3],P.Y());
1174 Draw::Set(a[4],P.Z());
1182 //=======================================================================
1185 //=======================================================================
1186 static Standard_Integer minmaxcurandinf(Draw_Interpretor& di,
1187 Standard_Integer argc, const char** argv)
1189 if (argc < 2) return 1;
1191 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(argv[1]);
1192 if (C1.IsNull()) return 1;
1195 Geom2dLProp_CurAndInf2d Sommets;
1197 Sommets.PerformCurExt (C1);
1198 if (Sommets.IsDone() && !Sommets.IsEmpty()) {
1199 for (Standard_Integer i = 1; i <= Sommets.NbPoints(); i++){
1200 Couleur = Draw_vert;
1201 if (Sommets.Type(i) == LProp_MinCur) {
1202 Couleur = Draw_orange;
1203 di << " Maximum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1206 di << " Minimum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1208 gp_Pnt2d P = C1->Value(Sommets.Parameter(i));
1209 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Couleur);
1215 Geom2dLProp_CurAndInf2d Sommets2;
1216 Sommets2.PerformInf (C1);
1218 if (Sommets2.IsDone() && !Sommets2.IsEmpty()) {
1219 for (Standard_Integer i = 1; i <= Sommets2.NbPoints(); i++){
1220 gp_Pnt2d P = C1->Value(Sommets2.Parameter(i));
1221 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Draw_bleu);
1223 di << " Inflexion at U ="<<Sommets2.Parameter(i)<<"\n";
1229 //=======================================================================
1230 //function : shcurvature
1231 //purpose : affiche le peigne de courbure
1232 //=======================================================================
1233 static Standard_Integer shcurvature(Draw_Interpretor&,
1234 Standard_Integer argc, const char** argv)
1236 if (argc < 2) return 1;
1238 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1239 ::DownCast(Draw::Get(argv[1]));
1240 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1241 ::DownCast(Draw::Get(argv[1]));
1244 if (C3d.IsNull()) return 1;
1245 C3d->ShowCurvature();
1248 C2d->ShowCurvature();
1254 //=======================================================================
1255 //function : clcurvature
1256 //purpose : efface le peigne de courbure
1257 //=======================================================================
1258 static Standard_Integer clcurvature(Draw_Interpretor&,
1259 Standard_Integer argc, const char** argv)
1261 if (argc < 2) return 1;
1262 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1263 ::DownCast(Draw::Get(argv[1]));
1264 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1265 ::DownCast(Draw::Get(argv[1]));
1268 if (C3d.IsNull()) return 1;
1269 C3d->ClearCurvature();
1272 C2d->ClearCurvature();
1278 //=======================================================================
1279 //function : radiusmax
1280 //purpose : definit le rayon de courbure maximum a afficher
1281 //=======================================================================
1282 static Standard_Integer radiusmax(Draw_Interpretor&,
1283 Standard_Integer argc, const char** argv)
1285 if (argc < 3) return 1;
1286 Standard_Real Radius = atof(argv[2]);
1287 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1288 ::DownCast(Draw::Get(argv[1]));
1289 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1290 ::DownCast(Draw::Get(argv[1]));
1293 if (C3d.IsNull()) return 1;
1294 C3d->SetRadiusMax(Radius);
1297 C2d->SetRadiusMax(Radius);
1303 //=======================================================================
1304 //function : radiusratio
1305 //purpose : definit le ratio du rayon de courbure a afficher
1306 //=======================================================================
1307 static Standard_Integer radiusratio(Draw_Interpretor&,
1308 Standard_Integer argc, const char** argv)
1310 if (argc < 3) return 1;
1311 Standard_Real Ratio = atof(argv[2]);
1312 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1313 ::DownCast(Draw::Get(argv[1]));
1314 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1315 ::DownCast(Draw::Get(argv[1]));
1318 if (C3d.IsNull()) return 1;
1319 C3d->SetRadiusRatio(Ratio);
1322 C2d->SetRadiusRatio(Ratio);
1328 //=======================================================================
1331 //=======================================================================
1332 static Standard_Integer localprop(Draw_Interpretor& di,
1333 Standard_Integer argc, const char** argv)
1335 if (argc < 3) return 1;
1337 Standard_Real U = atof(argv[2]);
1339 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(argv[1]);
1340 Handle(Geom_Curve) C3d;
1344 C3d = DrawTrSurf::GetCurve(argv[1]);
1345 if (C3d.IsNull()) return 1;
1346 GeomLProp_CLProps Prop (C3d,2,Precision::Confusion());
1347 Prop.SetParameter(U);
1348 Handle(Draw_Marker3D)drp = new Draw_Marker3D(Prop.Value(),
1352 if (Prop.IsTangentDefined()) {
1353 Standard_Real K = Prop.Curvature();
1354 di <<" Curvature : "<<K<<"\n";
1356 if (Abs(K) > Precision::Confusion()) {
1357 Standard_Real R = 1/Abs(K);
1359 Prop.CentreOfCurvature(Center);
1364 gp_Dir AxC = Nor^Tang;
1365 gp_Ax2 Axe(Center,AxC,Nor);
1366 Handle(Geom_Circle) Cir3d = new Geom_Circle(Axe,R);
1367 Handle(DrawTrSurf_Curve) dr;
1368 dr = new DrawTrSurf_Curve(Cir3d);
1374 di <<"Tangent undefined."<<"\n";
1377 Geom2dLProp_CLProps2d Prop (C2d,2,Precision::Confusion());
1378 Prop.SetParameter(U);
1379 Handle(Draw_Marker2D) drp = new Draw_Marker2D(Prop.Value(),
1383 if (Prop.IsTangentDefined()) {
1384 Standard_Real K = Prop.Curvature();
1387 di <<" Curvature : "<<K<<"\n";
1389 if (Abs(K) > Precision::Confusion()) {
1390 Standard_Real R = 1/Abs(K);
1391 Prop.CentreOfCurvature(Center);
1392 gp_Ax2d Axe(Center,gp::DX2d());
1393 Handle(Geom2d_Circle) Cir2d = new Geom2d_Circle(Axe,R);
1394 Handle(DrawTrSurf_Curve2d) dr;
1395 dr = new DrawTrSurf_Curve2d(Cir2d,Draw_rouge,30,Standard_False);
1401 di <<"Tangent undefined."<<"\n";
1405 //=======================================================================
1406 //function : rawcont
1408 //=======================================================================
1410 static Standard_Integer rawcont(Draw_Interpretor& di, Standard_Integer n, const char** a)
1412 if (n < 5) return 1;
1414 Handle(Geom_Curve) GC1;
1415 GC1 = DrawTrSurf::GetCurve(a[1]);
1416 Handle(Geom_Curve) GC2;
1417 GC2 = DrawTrSurf::GetCurve(a[2]);
1418 Standard_Real param1 =
1420 Standard_Real param2 =
1422 if (GC1.IsNull() || GC2.IsNull())
1430 if (a_point2.SquareDistance(a_point1) < Precision::Confusion()) {
1431 GeomAbs_Shape cont =
1432 GeomLProp::Continuity(GC1,
1438 Precision::Confusion(),
1439 Precision::Angular()) ;
1442 di << " C0 Continuity " << "\n" ;
1445 di << " G1 Continuity " << "\n" ;
1448 di << " C1 Continuity " << "\n" ;
1451 di << " G2 Continuity " << "\n" ;
1454 di << " C2 Continuity " << "\n" ;
1457 di << " C3 Continuity " << "\n" ;
1460 di << " CN Continuity " << "\n" ;
1467 di << " not C0 continuity " << "\n" ;
1471 //=======================================================================
1472 //function : approxcurveonsurf
1474 //=======================================================================
1475 static Standard_Integer approxcurveonsurf(Draw_Interpretor& di, Standard_Integer n, const char** a)
1477 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1478 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1479 Standard_Integer MaxDeg = 14; // Maximum degree
1480 Standard_Integer MaxSeg = 16; /*1*/ // Maximum number of segments
1482 if ( n>8 || n<4) return 1;
1484 if (n>4) Tol = Max(atof(a[4]),1.e-10);
1487 if (atoi(a[5]) == 0) Continuity = GeomAbs_C0;
1488 if (atoi(a[5]) == 2) Continuity = GeomAbs_C2;
1492 MaxDeg = atoi(a[6]);
1493 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1496 if (n>7) MaxSeg = atoi(a[7]);
1497 Handle(Geom2d_Curve) curve2d = DrawTrSurf::GetCurve2d(a[2]);
1498 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[3]);
1500 Handle(Geom2dAdaptor_HCurve) A2d = new (Geom2dAdaptor_HCurve)(curve2d);
1501 Handle(GeomAdaptor_HSurface) AS = new (GeomAdaptor_HSurface)(Surf);
1503 Approx_CurveOnSurface App(A2d, AS, A2d->FirstParameter(), A2d->LastParameter(),
1504 Tol, Continuity, MaxDeg, MaxSeg,
1505 Standard_True, Standard_False);
1507 if(App.HasResult()) {
1508 Handle(Geom_BSplineCurve) BSCurve = App.Curve3d();
1509 DrawTrSurf::Set(a[1], BSCurve);
1513 di << "Approximation failed !" << "\n";
1518 //=======================================================================
1519 //function : approxcurve
1521 //=======================================================================
1522 static Standard_Integer approxcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1524 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1525 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1526 Standard_Integer MaxDeg = 14; // Maximum degree
1527 Standard_Integer MaxSeg = 16; // Maximum number of segments
1529 Standard_Integer Case, shift;
1530 // Case == 1 : 3d approximation without reparametrization
1531 // Case == 2 : 2d approximation without reparametrization
1532 // Case == 3 : 3d approximation with reparametrization
1533 // Case == 4 : curve_on_surface approximation with reparametrization
1534 // Case == 5 : 2 curves_on_surfaces approximation with reparametrization
1536 Handle(Geom_Curve) curve;
1537 Handle(Geom2d_Curve) curve2d, curve2d2;
1538 Handle(Geom_Surface) surface, surface2;
1542 if (!strcmp(a[1],"-L")) {
1543 // aproximation with curvilinear abscissa reparametrization
1544 if (n > 11 || n < 4) return 1;
1546 curve = DrawTrSurf::GetCurve(a[3]);
1547 if (!curve.IsNull()) {
1552 // approx curve_on_surface
1553 if (n < 5) return 1;
1554 curve2d = DrawTrSurf::GetCurve2d(a[3]);
1555 surface = DrawTrSurf::GetSurface(a[4]);
1556 if (curve2d.IsNull() || surface.IsNull()) {
1560 curve2d2 = DrawTrSurf::GetCurve2d(a[5]);
1561 surface2 = DrawTrSurf::GetSurface(a[6]);
1562 if (curve2d2.IsNull() || surface2.IsNull()) {
1567 // approx 2 curves_on_surfaces
1579 // aproximation without reparamitrization
1580 if ( n>7 || n<3) return 1;
1582 curve = DrawTrSurf::GetCurve(a[2]);
1583 if (curve.IsNull()) {
1584 curve2d = DrawTrSurf::GetCurve2d(a[2]);
1585 if (curve2d.IsNull()) {
1594 if (n>shift) Tol = Max(atof(a[shift]),1.e-10);
1597 if (atoi(a[shift+1]) == 0) Continuity = GeomAbs_C0;
1598 if (atoi(a[shift+1]) == 2) Continuity = GeomAbs_C2;
1602 MaxDeg = atoi(a[shift+2]);
1603 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1606 if (n>shift+3) MaxSeg = atoi(a[shift+3]);
1609 GeomConvert_ApproxCurve appr(curve, Tol, Continuity, MaxSeg, MaxDeg);
1610 if(appr.HasResult()) {
1612 Standard_SStream aSStream;
1613 appr.Dump(aSStream);
1615 Handle(Geom_BSplineCurve) BSCurve = appr.Curve();
1616 DrawTrSurf::Set(a[1], BSCurve);
1620 else if (Case == 2) {
1621 Geom2dConvert_ApproxCurve appr(curve2d, Tol, Continuity, MaxSeg, MaxDeg);
1622 if(appr.HasResult()) {
1624 Standard_SStream aSStream;
1625 appr.Dump(aSStream);
1627 Handle(Geom2d_BSplineCurve) BSCurve = appr.Curve();
1628 DrawTrSurf::Set(a[1], BSCurve);
1632 else if (Case == 3) {
1633 Handle(Adaptor3d_HCurve) HACur = new GeomAdaptor_HCurve(curve);
1634 Approx_CurvilinearParameter appr(HACur, Tol, Continuity, MaxDeg, MaxSeg);
1635 if(appr.HasResult()) {
1637 Standard_SStream aSStream;
1638 appr.Dump(aSStream);
1640 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1641 DrawTrSurf::Set(a[2], BSCurve);
1644 else if (Case == 4) {
1645 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1646 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1647 Approx_CurvilinearParameter appr(HACur2d, HASur, Tol, Continuity, MaxDeg, MaxSeg);
1648 if(appr.HasResult()) {
1650 Standard_SStream aSStream;
1651 appr.Dump(aSStream);
1653 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1654 DrawTrSurf::Set(a[2], BSCurve);
1658 else if (Case == 5) {
1659 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1660 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1661 Handle(Adaptor2d_HCurve2d) HACur2d2 = new Geom2dAdaptor_HCurve(curve2d2);
1662 Handle(Adaptor3d_HSurface) HASur2 = new GeomAdaptor_HSurface(surface2);
1663 Approx_CurvilinearParameter appr(HACur2d, HASur, HACur2d2, HASur2, Tol, Continuity, MaxDeg, MaxSeg);
1664 if(appr.HasResult()) {
1666 Standard_SStream aSStream;
1667 appr.Dump(aSStream);
1669 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1670 DrawTrSurf::Set(a[2], BSCurve);
1678 //=======================================================================
1679 //function : newbspline
1680 //purpose : reduce the multiplicity of the knots to their minimum
1681 // compared to the degree of the curve
1682 //=======================================================================
1684 static Standard_Integer splitc1(Draw_Interpretor& di,
1685 Standard_Integer n, const char** c)
1687 {Standard_Real tolerance=1.0e-5,
1688 angular_tolerance = 1.0e-4 ;
1689 Standard_Integer optiontab,i;
1693 optiontab=atoi(c[2]);
1695 tolerance=atof(c[3]);
1697 angular_tolerance = atof(c[4]) ;
1699 Handle(Geom_Curve) ACurve = Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(c[1])) ;
1701 Standard_Real f = ACurve->FirstParameter();
1702 Standard_Real l = ACurve->LastParameter();
1704 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1705 di << " Error: Infinite curves" << "\n";
1709 Handle(Geom_BSplineCurve) BS = GeomConvert::CurveToBSplineCurve(ACurve);
1711 if ( BS.IsNull()) return 1;
1714 Handle(TColGeom_HArray1OfBSplineCurve) tabBS;
1715 GeomConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1719 for (i=0;i<=(tabBS->Length()-1);i++){
1720 sprintf(name,"%s_%d",c[1],i+1);
1721 Standard_CString new_name = name ;
1722 DrawTrSurf::Set(new_name,
1724 di.AppendElement(name);
1728 GeomConvert::C0BSplineToC1BSplineCurve(BS,
1730 angular_tolerance) ;
1732 DrawTrSurf::Set(c[1],BS);
1737 //=======================================================================
1738 //function : splitc12d
1739 //purpose : reduce the multiplicity of the knots to their minimum
1740 // compared to the degree of the curve
1741 //=======================================================================
1743 static Standard_Integer splitc12d(Draw_Interpretor& di,
1744 Standard_Integer n, const char** c)
1746 {Standard_Real tolerance=1.0e-5,
1747 angular_tolerance = 1.0e-4 ;
1748 Standard_Integer optiontab,i;
1752 optiontab=atoi(c[2]);
1754 tolerance=atof(c[3]);
1756 angular_tolerance = atof(c[4]) ;
1757 Handle(Geom2d_Curve) ACurve = Handle(Geom2d_Curve)::DownCast(DrawTrSurf::GetCurve2d(c[1])) ;
1759 Standard_Real f = ACurve->FirstParameter();
1760 Standard_Real l = ACurve->LastParameter();
1762 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1763 di << " Error: Infinite curves" << "\n";
1767 Handle(Geom2d_BSplineCurve) BS = Geom2dConvert::CurveToBSplineCurve(ACurve);
1769 if ( BS.IsNull()) return 1;
1772 Handle(TColGeom2d_HArray1OfBSplineCurve) tabBS;
1773 Geom2dConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1777 for (i=0;i<=(tabBS->Length()-1);i++){
1778 sprintf(name,"%s_%d",c[1],i+1);
1779 Standard_CString new_name = name ;
1780 DrawTrSurf::Set(new_name,
1782 di.AppendElement(name);
1786 Geom2dConvert::C0BSplineToC1BSplineCurve(BS,tolerance);
1787 DrawTrSurf::Set(c[1],BS);
1792 //=======================================================================
1793 //function : canceldenom
1794 //purpose : set the value of the denominator cancel its first
1795 // derivative on the boundaries of the surface if possible
1796 //=======================================================================
1798 static Standard_Integer canceldenom(Draw_Interpretor& ,
1799 Standard_Integer n, const char** c)
1801 {Standard_Integer uoption,voption;
1802 Standard_Boolean udirection=Standard_False;
1803 Standard_Boolean vdirection=Standard_False;
1808 udirection=Standard_True;
1810 vdirection=Standard_True;
1811 Handle(Geom_BSplineSurface) BSurf = Handle(Geom_BSplineSurface)::DownCast(DrawTrSurf::GetBSplineSurface(c[1]));
1812 GeomLib::CancelDenominatorDerivative(BSurf,udirection,vdirection);
1813 DrawTrSurf::Set(c[1],BSurf);
1817 //=======================================================================
1819 //purpose : eval curve's length
1820 //=======================================================================
1822 static Standard_Integer length(Draw_Interpretor& di,
1823 Standard_Integer n, const char** a)
1826 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
1827 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[1]);
1828 Standard_Real Tol = Precision::Confusion(), L;
1829 if (n==3) Tol = atof(a[2]);
1832 GeomAdaptor_Curve AC(GC);
1833 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1835 else if (!GC2d.IsNull()) {
1836 Geom2dAdaptor_Curve AC(GC2d);
1837 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1840 di << a[1] << "is not a curve" << "\n";
1844 di << "The length " << a[1] << " is " << L << "\n";
1850 //=======================================================================
1851 //function : CurveCommands
1853 //=======================================================================
1855 void GeomliteTest::CurveCommands(Draw_Interpretor& theCommands)
1858 static Standard_Boolean loaded = Standard_False;
1860 loaded = Standard_True;
1862 DrawTrSurf::BasicCommands(theCommands);
1868 g = "GEOMETRY curves creation";
1871 theCommands.Add("point",
1872 "point name x y [z]",
1876 theCommands.Add("line",
1877 "line name pos dir",
1881 theCommands.Add("circle",
1882 "circle name x y [z [dx dy dz]] [ux uy [uz]] radius",
1886 theCommands.Add("ellipse",
1887 "ellipse name x y [z [dx dy dz]] [ux uy [uz]] major minor",
1890 theCommands.Add("parabola",
1891 "parabola name x y [z [dx dy dz]] [ux uy [uz]] focal",
1894 theCommands.Add("hyperbola",
1895 "hyperbola name x y [z [dx dy dz]] [ux uy [uz]] major minor",
1899 theCommands.Add("beziercurve",
1900 "beziercurve name nbpole pole, [weight]",
1904 theCommands.Add("bsplinecurve",
1905 "bsplinecurve name degree nbknots knot, umult pole, weight",
1909 theCommands.Add("pbsplinecurve",
1910 "pbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
1914 theCommands.Add("2dbeziercurve",
1915 "2dbeziercurve name nbpole pole, [weight]",
1919 theCommands.Add("2dbsplinecurve",
1920 "2dbsplinecurve name degree nbknots knot, umult pole, weight",
1924 theCommands.Add("2dpbsplinecurve",
1925 "2dpbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
1929 g = "GEOMETRY Curves and Surfaces modification";
1931 theCommands.Add("reverse",
1932 "reverse name ... ",
1936 theCommands.Add("cmovep",
1937 "cmovep name index dx dy dz",
1941 theCommands.Add("cmovepoint",
1942 "cmovepoint name u dx dy [dz index1 index2]",
1946 theCommands.Add("cmovetangent",
1947 "cmovetangent name u x y [z] tx ty [tz constraint = 0]",
1951 theCommands.Add("insertknot",
1952 "insertknot name knot [mult = 1] [knot mult ...]",
1956 theCommands.Add("setknot",
1957 "setknot name index knot [mult]",
1961 theCommands.Add("remknot",
1962 "remknot name index [mult] [tol]",
1966 theCommands.Add("incdeg",
1967 "incdeg name degree",
1971 theCommands.Add("rempole",
1972 "rempole name index",
1976 theCommands.Add("insertpole",
1977 "insertpole name index x y [z] [weight]",
1981 theCommands.Add("cfindp",
1982 "cfindp name view x y index",
1986 theCommands.Add("setperiodic",
1987 "setperiodic name ...",
1991 theCommands.Add("setnotperiodic",
1992 "setnotperiodic name",
1996 theCommands.Add("segment",
1997 "segment name Ufirst Ulast",
2001 theCommands.Add("setorigin",
2002 "setorigin name knotindex",
2006 g = "GEOMETRY curves and surfaces analysis";
2008 theCommands.Add("cvalue",
2009 "cvalue curvename U X Y Z [D1X D1Y D1Z D2X D2Y D2Z]",
2013 theCommands.Add("2dcvalue",
2014 "2dcvalue curvename U X Y [D1X D1Y D2X D2Y]",
2018 theCommands.Add("coord",
2019 "coord P x y [z]: set in x y [z] the coordinates of P",
2023 theCommands.Add("minmaxcurandinf",
2024 "minmaxcurandinf curve",
2028 theCommands.Add("shcurvature",
2029 "shcurvature curvename",
2033 theCommands.Add("clcurvature",
2034 "clcurvature curvename",
2039 theCommands.Add("radiusmax",
2040 "radiusmax curvename radius",
2044 theCommands.Add("radiusratio",
2045 "radiusratio curvename ratio",
2048 theCommands.Add("localprop",
2049 "localprop curvename U",
2052 theCommands.Add("rawcont",
2053 "rawcont curve1 curve2 u1 u2",
2056 theCommands.Add("approxcurve",
2057 "approxcurve [-L] name curve1 [Surf1] [curve2d2 Surf2] [Tol [cont [maxdeg [maxseg]]]] ",
2061 theCommands.Add("approxcurveonsurf",
2062 "approxcurveonsurf name curve2d surface [Tol [cont [maxdeg [maxseg]]]] ",
2064 approxcurveonsurf,g);
2066 theCommands.Add("length", "length curve [Tol]",
2071 theCommands.Add("splitc1",
2072 "splitc1 bspline resultinarray(0/1) [tol] [angtol] ",
2076 theCommands.Add("splitc12d",
2077 "splitc12d bspline2d resultinarray(0/1) [tol] [angtol] ",
2080 theCommands.Add("canceldenom",
2081 "canceldenom BSpline-Surface UDirection(0/1) VDirection(0/1)",