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 // JPI : Commande smooth transferee dans GeomliteTest
18 // PMN : Ajout de la commande smooth
19 // JCT : Correction d'un trap dans la commande gcarc
21 #include <Standard_Stream.hxx>
23 #include <GeometryTest.hxx>
24 #include <DrawTrSurf.hxx>
26 #include <Draw_Appli.hxx>
27 #include <Draw_Interpretor.hxx>
28 #include <Geom2dGcc_Circ2d2TanRad.hxx>
29 #include <Geom2dGcc_Circ2d3Tan.hxx>
30 #include <Geom2dGcc_Circ2d2TanOn.hxx>
31 #include <Geom2dGcc_Circ2dTanOnRad.hxx>
32 #include <Geom2dGcc_Circ2dTanCen.hxx>
33 #include <Geom2dGcc_Lin2d2Tan.hxx>
34 #include <Geom2dGcc_Lin2dTanObl.hxx>
35 #include <Geom2dGcc.hxx>
36 #include <Geom2dGcc_QualifiedCurve.hxx>
37 #include <Geom2d_CartesianPoint.hxx>
38 #include <Geom2d_Circle.hxx>
39 #include <Geom2d_Line.hxx>
40 #include <Precision.hxx>
41 #include <GeomAPI_Interpolate.hxx>
42 #include <Draw_Marker3D.hxx>
43 #include <Geom2dAPI_Interpolate.hxx>
44 #include <Draw_Marker2D.hxx>
45 #include <TColgp_HArray1OfPnt.hxx>
46 #include <Geom_BSplineCurve.hxx>
47 #include <TColgp_HArray1OfPnt2d.hxx>
48 #include <Geom2d_BSplineCurve.hxx>
49 #include <DrawTrSurf_BSplineCurve.hxx>
50 #include <DrawTrSurf_BSplineCurve2d.hxx>
51 #include <TColgp_HArray1OfPnt.hxx>
52 #include <TColgp_Array1OfPnt.hxx>
53 #include <TColgp_Array1OfPnt2d.hxx>
54 #include <TColgp_HArray1OfVec.hxx>
55 #include <TColgp_Array1OfVec.hxx>
56 #include <TColStd_Array1OfReal.hxx>
57 #include <TColStd_HArray1OfReal.hxx>
58 #include <TColStd_HArray1OfBoolean.hxx>
59 #include <AppParCurves_MultiBSpCurve.hxx>
60 #include <AppDef_MultiLine.hxx>
61 #include <AppParCurves_HArray1OfConstraintCouple.hxx>
62 #include <AppParCurves_ConstraintCouple.hxx>
63 #include <GC_MakeSegment.hxx>
64 #include <GC_MakeArcOfCircle.hxx>
69 Standard_IMPORT Draw_Viewer dout;
71 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color);
74 static Standard_Integer solutions(Draw_Interpretor& di,
75 Geom2dGcc_Circ2d2TanRad& ct3, const char* name)
79 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
80 DrawTrSurf_CurveColor(col);
83 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
84 Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
85 Sprintf(solname,"%s_%d",name,i);
86 char* temp = solname; // pour portage WNT
87 DrawTrSurf::Set(temp,C);
93 di << "Circ2d2TanRad Not done";
98 static Standard_Integer solutions(Draw_Interpretor& di,
99 Geom2dGcc_Circ2d3Tan& ct3, const char* name)
103 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
104 DrawTrSurf_CurveColor(col);
107 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
108 Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
109 Sprintf(solname,"%s_%d",name,i);
110 char* temp = solname; // pour portage WNT
111 DrawTrSurf::Set(temp,C);
112 di << solname << " ";
117 di << "Circ2d3Tan Not done";
122 //=======================================================================
125 //=======================================================================
127 static Standard_Integer cirtang (Draw_Interpretor& di,Standard_Integer n, const char** a)
131 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
132 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
133 Handle(Geom2d_Curve) C3 = DrawTrSurf::GetCurve2d(a[4]);
135 Standard_Boolean ip1 = DrawTrSurf::GetPoint2d(a[2],P1);
136 Standard_Boolean ip2 = DrawTrSurf::GetPoint2d(a[3],P2);
137 Standard_Boolean ip3 = DrawTrSurf::GetPoint2d(a[4],P3);
139 Standard_Real tol = Precision::Confusion();
140 if (n > 5) tol = Draw::Atof(a[5]);
149 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
150 Geom2dGcc::Unqualified(C2),
151 Geom2dGcc::Unqualified(C3),
153 return solutions(di,ct3,a[1]);
158 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
159 Geom2dGcc::Unqualified(C2),
160 new Geom2d_CartesianPoint(P3),
162 return solutions(di,ct3,a[1]);
167 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
168 Geom2dGcc::Unqualified(C2),
169 Draw::Atof(a[4]),tol);
170 return solutions(di,ct3,a[1]);
177 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
178 Geom2dGcc::Unqualified(C3),
179 new Geom2d_CartesianPoint(P2),
181 return solutions(di,ct3,a[1]);
186 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
187 new Geom2d_CartesianPoint(P2),
188 new Geom2d_CartesianPoint(P3),
190 return solutions(di,ct3,a[1]);
195 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
196 new Geom2d_CartesianPoint(P2),
197 Draw::Atof(a[4]),tol);
198 return solutions(di,ct3,a[1]);
206 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
207 Geom2dGcc::Unqualified(C3),
210 return solutions(di,ct3,a[1]);
215 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
216 new Geom2d_CartesianPoint(P3),
219 return solutions(di,ct3,a[1]);
224 di << "Curve, radius, radius ???"<<"\n";
236 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
237 Geom2dGcc::Unqualified(C3),
238 new Geom2d_CartesianPoint(P1),
240 return solutions(di,ct3,a[1]);
245 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
246 new Geom2d_CartesianPoint(P1),
247 new Geom2d_CartesianPoint(P3),
249 return solutions(di,ct3,a[1]);
254 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
255 new Geom2d_CartesianPoint(P1),
256 Draw::Atof(a[4]),tol);
257 return solutions(di,ct3,a[1]);
264 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C3),
265 new Geom2d_CartesianPoint(P1),
266 new Geom2d_CartesianPoint(P2),
268 return solutions(di,ct3,a[1]);
273 Geom2dGcc_Circ2d3Tan ct3(new Geom2d_CartesianPoint(P1),
274 new Geom2d_CartesianPoint(P2),
275 new Geom2d_CartesianPoint(P3),
277 return solutions(di,ct3,a[1]);
282 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
283 new Geom2d_CartesianPoint(P2),
284 Draw::Atof(a[4]),tol);
285 return solutions(di,ct3,a[1]);
293 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
294 new Geom2d_CartesianPoint(P1),
297 return solutions(di,ct3,a[1]);
302 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
303 new Geom2d_CartesianPoint(P3),
306 return solutions(di,ct3,a[1]);
311 di << "Point, radius, radius ???"<<"\n";
323 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
324 Geom2dGcc::Unqualified(C3),
327 return solutions(di,ct3,a[1]);
332 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
333 new Geom2d_CartesianPoint(P3),
336 return solutions(di,ct3,a[1]);
341 di << "Radius - Curve - Radius ??"<<"\n";
349 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
350 new Geom2d_CartesianPoint(P2),
353 return solutions(di,ct3,a[1]);
359 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P2),
360 new Geom2d_CartesianPoint(P3),
363 return solutions(di,ct3,a[1]);
367 di << "Radius - Point - Radius ??"<<"\n";
373 di << "radius, radius ???"<<"\n";
380 //=======================================================================
383 //=======================================================================
385 static Standard_Integer lintang (Draw_Interpretor& di,Standard_Integer n, const char** a)
389 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
390 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
394 if (C1.IsNull() || C2.IsNull())
397 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
400 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(C2);
402 di << "Second argument must be a line";
405 Standard_Real ang = Draw::Atof(a[4]) * (M_PI / 180.0);
406 Geom2dGcc_Lin2dTanObl ct3(Geom2dGcc::Unqualified(C1),
408 Precision::Angular(),
409 (C1->FirstParameter()+C1->LastParameter())/2.,
412 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
413 Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
414 Sprintf(solname,"%s_%d",a[1],i);
415 char* temp = solname; // pour portage WNT
416 DrawTrSurf::Set(temp,LS);
417 di << solname << " ";
421 di << "Lin2dTanObl Not done" << "\n";
424 Geom2dGcc_Lin2d2Tan ct3(Geom2dGcc::Unqualified(C1),
425 Geom2dGcc::Unqualified(C2),
426 Precision::Angular(),
427 (C1->FirstParameter()+C1->LastParameter())/2.,
428 (C2->FirstParameter()+C2->LastParameter())/2.);
430 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
431 Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
432 Sprintf(solname,"%s_%d",a[1],i);
433 char* temp = solname; // pour portage WNT
434 DrawTrSurf::Set(temp,LS);
435 di << solname << " ";
439 di << "Lin2d2Tan Not done" << "\n";
442 DrawTrSurf_CurveColor(col);
447 //==================================================================================
448 static Standard_Integer interpol (Draw_Interpretor& di,Standard_Integer n, const char** a)
449 //==================================================================================
452 di <<"give a name to your curve !" << "\n";
456 Standard_Integer id,XX,YY,b, i, j;
457 di << "Pick points "<< "\n";
458 dout.Select(id, XX, YY, b);
459 Standard_Real zoom = dout.Zoom(id);
460 if (b != 1) return 0;
461 if (id < 0) return 0;
464 Standard_Boolean newcurve;
467 Handle(Draw_Marker3D) mark;
468 Handle(TColgp_HArray1OfPnt) Points = new TColgp_HArray1OfPnt(1, 1);
469 P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
470 Points->SetValue(1 , P);
471 Handle(TColgp_HArray1OfPnt) ThePoints = new TColgp_HArray1OfPnt(1, 2);
472 ThePoints->SetValue(1 , P);
473 mark = new Draw_Marker3D(Points->Value(1), Draw_X, Draw_vert);
476 Handle(Geom_BSplineCurve) C;
480 dout.Select(id,XX,YY,b, Standard_False);
481 P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
482 ThePoints->SetValue(i+1, P);
483 newcurve = Standard_False;
484 if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
487 mark = new Draw_Marker3D(ThePoints->Value(i), Draw_X, Draw_vert);
491 new TColgp_HArray1OfPnt(ThePoints->Lower(),ThePoints->Upper());
492 Points->ChangeArray1() = ThePoints->Array1();
493 newcurve = Standard_True;
495 GeomAPI_Interpolate anInterpolator(ThePoints,
498 anInterpolator.Perform() ;
499 if (anInterpolator.IsDone()) {
500 C = anInterpolator.Curve() ;
501 Handle(DrawTrSurf_BSplineCurve)
502 DC = new DrawTrSurf_BSplineCurve(C);
506 dout.RepaintView(id);
509 ThePoints = new TColgp_HArray1OfPnt(1, i+1);
510 for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
514 GeomAPI_Interpolate anInterpolator(ThePoints,
517 anInterpolator.Perform() ;
518 if (anInterpolator.IsDone()) {
519 C = anInterpolator.Curve() ;
520 DrawTrSurf::Set(a[1], C);
521 dout.RepaintView(id);
525 Handle(Draw_Marker2D) mark;
526 Handle(TColgp_HArray1OfPnt2d) Points = new TColgp_HArray1OfPnt2d(1, 1);
527 P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
528 Points->SetValue(1 , P2d);
529 Handle(TColgp_HArray1OfPnt2d) ThePoints = new TColgp_HArray1OfPnt2d(1, 2);
530 ThePoints->SetValue(1, P2d);
531 mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
534 Handle(Geom2d_BSplineCurve) C;
538 dout.Select(id,XX,YY,b, Standard_False);
539 P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
540 ThePoints->SetValue(i+1, P2d);
541 newcurve = Standard_False;
542 if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
545 mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
549 new TColgp_HArray1OfPnt2d(ThePoints->Lower(),ThePoints->Upper());
550 Points->ChangeArray1() = ThePoints->Array1();
551 newcurve = Standard_True;
553 Geom2dAPI_Interpolate a2dInterpolator(ThePoints,
556 a2dInterpolator.Perform() ;
557 if (a2dInterpolator.IsDone()) {
558 C = a2dInterpolator.Curve() ;
560 Handle(DrawTrSurf_BSplineCurve2d)
561 DC = new DrawTrSurf_BSplineCurve2d(C);
565 dout.RepaintView(id);
569 ThePoints = new TColgp_HArray1OfPnt2d(1, i+1);
570 for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
574 Geom2dAPI_Interpolate a2dInterpolator(Points,
577 a2dInterpolator.Perform() ;
578 if (a2dInterpolator.IsDone()) {
579 C = a2dInterpolator.Curve() ;
581 DrawTrSurf::Set(a[1], C);
582 dout.RepaintView(id);
588 // lecture du fichier.
589 // nbpoints, 2d ou 3d, puis valeurs.
590 const char* nomfic = a[2];
591 ifstream iFile(nomfic, ios::in);
592 if (!iFile) return 1;
593 Standard_Integer nbp, i;
594 Standard_Real x, y, z;
598 if (!strcmp(dimen,"3d")) {
599 Handle_TColgp_HArray1OfPnt Point =
600 new TColgp_HArray1OfPnt(1, nbp);
601 for (i = 1; i <= nbp; i++) {
602 iFile >> x >> y >> z;
603 Point->SetValue(i, gp_Pnt(x, y, z));
605 GeomAPI_Interpolate anInterpolator(Point,
608 anInterpolator.Perform() ;
609 if (anInterpolator.IsDone()) {
610 Handle(Geom_BSplineCurve) C =
611 anInterpolator.Curve();
612 DrawTrSurf::Set(a[1], C);
615 else if (!strcmp(dimen,"2d")) {
616 Handle(TColgp_HArray1OfPnt2d) PointPtr =
617 new TColgp_HArray1OfPnt2d(1, nbp);
618 for (i = 1; i <= nbp; i++) {
620 PointPtr->SetValue(i, gp_Pnt2d(x, y));
622 Geom2dAPI_Interpolate a2dInterpolator(PointPtr,
625 a2dInterpolator.Perform() ;
626 if (a2dInterpolator.IsDone()) {
627 Handle(Geom2d_BSplineCurve) C = a2dInterpolator.Curve() ;
628 DrawTrSurf::Set(a[1], C);
635 static Standard_Integer tanginterpol (Draw_Interpretor& di,
660 Standard_Boolean periodic_flag = Standard_False ;
668 Handle(Geom_BSplineCurve) NewCurvePtr ;
674 if (strcmp(a[num_read],"p") == 0) {
675 periodic_flag = Standard_True ;
678 num_parameters = Draw::Atoi(a[num_read]) ;
680 if (num_parameters < 2) {
683 if ( n < num_parameters * 3 + num_read) {
686 Handle_TColgp_HArray1OfPnt PointsArrayPtr=
687 new TColgp_HArray1OfPnt(1,num_parameters) ;
689 num_tangents = ((n - num_read) / 3) - num_parameters ;
690 num_tangents = Max (0,num_tangents) ;
691 num_tangents = Min (num_parameters, num_tangents) ;
693 num_start = num_read ;
695 while (num_read <= num_parameters * 3 + num_start ) {
696 for (jj = 1 ; jj <= 3 ; jj++) {
697 a_point.SetCoord(jj,Draw::Atof(a[num_read])) ;
700 PointsArrayPtr->SetValue(ii,a_point) ;
703 GeomAPI_Interpolate anInterpolator(PointsArrayPtr,
707 if (num_tangents > 0) {
708 TColgp_Array1OfVec TangentsArray(1,num_parameters) ;
709 Handle_TColStd_HArray1OfBoolean
711 new TColStd_HArray1OfBoolean(1,num_parameters) ;
713 for (ii = 1 ; ii <= num_tangents ; ii++) {
714 TangentFlagsPtr->SetValue(ii,Standard_True) ;
716 for (ii = num_tangents + 1 ; ii <= num_parameters ; ii++) {
717 TangentFlagsPtr->SetValue(ii,Standard_False) ;
720 while (ii <= num_tangents) {
721 for (jj = 1 ; jj <= 3 ; jj++) {
722 a_vector.SetCoord(jj,Draw::Atof(a[num_read])) ;
725 TangentsArray.SetValue(ii,a_vector) ;
730 anInterpolator.Load(TangentsArray,
733 anInterpolator.Perform() ;
734 if (anInterpolator.IsDone()) {
736 anInterpolator.Curve() ;
738 DrawTrSurf::Set(a[1],
746 //==================================================================================
747 static Standard_Integer gcarc (Draw_Interpretor& di,Standard_Integer n, const char** a)
748 //==================================================================================
752 if (!strcmp(a[2], "seg")) {
753 if (DrawTrSurf::GetPoint(a[3], P1)) {
754 if (DrawTrSurf::GetPoint(a[4], P2)) {
755 Handle(Geom_Curve) theline = GC_MakeSegment(P1,P2).Value();
756 DrawTrSurf::Set(a[1], theline);
761 else if (!strcmp(a[2], "cir")) {
762 if (DrawTrSurf::GetPoint(a[3], P1)) {
763 if (DrawTrSurf::GetPoint(a[4], P2)) {
764 if (DrawTrSurf::GetPoint(a[5], P3)) {
765 // if (DrawTrSurf::GetPoint(a[6], P4)) {
767 DrawTrSurf::GetPoint(a[6], P4);
768 gp_Vec V1 = gp_Vec(P2,P3);
769 Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,V1,P4).Value();
770 DrawTrSurf::Set(a[1], thearc);
774 Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,P2,P3).Value();
775 DrawTrSurf::Set(a[1], thearc);
783 di <<"give a name for arc and the type seg or cir then" << "\n";
784 di <<"give passing points p1 p2 for seg p1 p2 p3 or p1 p2 p3 p4 for cir (p2 p3 is a tgtvec)!" << "\n";
788 //=======================================================================
789 //function : ConstraintCommands
791 //=======================================================================
794 void GeometryTest::ConstraintCommands(Draw_Interpretor& theCommands)
797 static Standard_Boolean loaded = Standard_False;
799 loaded = Standard_True;
801 DrawTrSurf::BasicCommands(theCommands);
804 // constrained constructs
805 g = "GEOMETRY Constraints";
807 theCommands.Add("cirtang",
808 "cirtang cname curve/point/radius curve/point/radius curve/point/radius",
812 theCommands.Add("lintan",
813 "lintan lname curve1 curve2 [angle]",
818 theCommands.Add("interpol",
819 "interpol cname [fic]",
822 theCommands.Add("tanginterpol",
823 "tanginterpol curve [p] num_points points [tangents] modifier p = periodic",
827 theCommands.Add("gcarc",
828 "gcarc name seg/cir p1 p2 p3 p4",