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 // JPI : Commande smooth transferee dans GeomliteTest
22 // PMN : Ajout de la commande smooth
23 // JCT : Correction d'un trap dans la commande gcarc
25 #include <Standard_Stream.hxx>
27 #include <GeometryTest.hxx>
28 #include <DrawTrSurf.hxx>
30 #include <Draw_Appli.hxx>
31 #include <Draw_Interpretor.hxx>
32 #include <Geom2dGcc_Circ2d2TanRad.hxx>
33 #include <Geom2dGcc_Circ2d3Tan.hxx>
34 #include <Geom2dGcc_Circ2d2TanOn.hxx>
35 #include <Geom2dGcc_Circ2dTanOnRad.hxx>
36 #include <Geom2dGcc_Circ2dTanCen.hxx>
37 #include <Geom2dGcc_Lin2d2Tan.hxx>
38 #include <Geom2dGcc_Lin2dTanObl.hxx>
39 #include <Geom2dGcc.hxx>
40 #include <Geom2dGcc_QualifiedCurve.hxx>
41 #include <Geom2d_CartesianPoint.hxx>
42 #include <Geom2d_Circle.hxx>
43 #include <Geom2d_Line.hxx>
44 #include <Precision.hxx>
45 #include <GeomAPI_Interpolate.hxx>
46 #include <Draw_Marker3D.hxx>
47 #include <Geom2dAPI_Interpolate.hxx>
48 #include <Draw_Marker2D.hxx>
49 #include <TColgp_HArray1OfPnt.hxx>
50 #include <Geom_BSplineCurve.hxx>
51 #include <TColgp_HArray1OfPnt2d.hxx>
52 #include <Geom2d_BSplineCurve.hxx>
53 #include <DrawTrSurf_BSplineCurve.hxx>
54 #include <DrawTrSurf_BSplineCurve2d.hxx>
55 #include <TColgp_HArray1OfPnt.hxx>
56 #include <TColgp_Array1OfPnt.hxx>
57 #include <TColgp_Array1OfPnt2d.hxx>
58 #include <TColgp_HArray1OfVec.hxx>
59 #include <TColgp_Array1OfVec.hxx>
60 #include <TColStd_Array1OfReal.hxx>
61 #include <TColStd_HArray1OfReal.hxx>
62 #include <TColStd_HArray1OfBoolean.hxx>
63 #include <Handle_TColStd_HArray1OfReal.hxx>
64 #include <Handle_TColStd_HArray1OfBoolean.hxx>
65 #include <AppParCurves_MultiBSpCurve.hxx>
66 #include <AppDef_MultiLine.hxx>
67 #include <AppDef_TheVariational.hxx>
68 #include <AppParCurves_HArray1OfConstraintCouple.hxx>
69 #include <AppParCurves_ConstraintCouple.hxx>
70 #include <GC_MakeSegment.hxx>
71 #include <GC_MakeArcOfCircle.hxx>
76 Standard_IMPORT Draw_Viewer dout;
78 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color);
81 static Standard_Integer solutions(Draw_Interpretor& di,
82 Geom2dGcc_Circ2d2TanRad& ct3, const char* name)
86 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
87 DrawTrSurf_CurveColor(col);
90 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
91 Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
92 sprintf(solname,"%s_%d",name,i);
93 char* temp = solname; // pour portage WNT
94 DrawTrSurf::Set(temp,C);
100 di << "Circ2d2TanRad Not done";
105 static Standard_Integer solutions(Draw_Interpretor& di,
106 Geom2dGcc_Circ2d3Tan& ct3, const char* name)
110 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
111 DrawTrSurf_CurveColor(col);
114 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
115 Handle(Geom2d_Circle) C = new Geom2d_Circle(ct3.ThisSolution(i));
116 sprintf(solname,"%s_%d",name,i);
117 char* temp = solname; // pour portage WNT
118 DrawTrSurf::Set(temp,C);
119 di << solname << " ";
124 di << "Circ2d3Tan Not done";
129 //=======================================================================
132 //=======================================================================
134 static Standard_Integer cirtang (Draw_Interpretor& di,Standard_Integer n, const char** a)
138 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
139 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
140 Handle(Geom2d_Curve) C3 = DrawTrSurf::GetCurve2d(a[4]);
142 Standard_Boolean ip1 = DrawTrSurf::GetPoint2d(a[2],P1);
143 Standard_Boolean ip2 = DrawTrSurf::GetPoint2d(a[3],P2);
144 Standard_Boolean ip3 = DrawTrSurf::GetPoint2d(a[4],P3);
146 Standard_Real tol = Precision::Confusion();
147 if (n > 5) tol = atof(a[5]);
156 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
157 Geom2dGcc::Unqualified(C2),
158 Geom2dGcc::Unqualified(C3),
160 return solutions(di,ct3,a[1]);
165 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
166 Geom2dGcc::Unqualified(C2),
167 new Geom2d_CartesianPoint(P3),
169 return solutions(di,ct3,a[1]);
174 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
175 Geom2dGcc::Unqualified(C2),
177 return solutions(di,ct3,a[1]);
184 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
185 Geom2dGcc::Unqualified(C3),
186 new Geom2d_CartesianPoint(P2),
188 return solutions(di,ct3,a[1]);
193 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C1),
194 new Geom2d_CartesianPoint(P2),
195 new Geom2d_CartesianPoint(P3),
197 return solutions(di,ct3,a[1]);
202 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
203 new Geom2d_CartesianPoint(P2),
205 return solutions(di,ct3,a[1]);
213 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
214 Geom2dGcc::Unqualified(C3),
217 return solutions(di,ct3,a[1]);
222 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C1),
223 new Geom2d_CartesianPoint(P3),
226 return solutions(di,ct3,a[1]);
231 di << "Curve, radius, radius ???"<<"\n";
243 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
244 Geom2dGcc::Unqualified(C3),
245 new Geom2d_CartesianPoint(P1),
247 return solutions(di,ct3,a[1]);
252 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C2),
253 new Geom2d_CartesianPoint(P1),
254 new Geom2d_CartesianPoint(P3),
256 return solutions(di,ct3,a[1]);
261 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
262 new Geom2d_CartesianPoint(P1),
264 return solutions(di,ct3,a[1]);
271 Geom2dGcc_Circ2d3Tan ct3(Geom2dGcc::Unqualified(C3),
272 new Geom2d_CartesianPoint(P1),
273 new Geom2d_CartesianPoint(P2),
275 return solutions(di,ct3,a[1]);
280 Geom2dGcc_Circ2d3Tan ct3(new Geom2d_CartesianPoint(P1),
281 new Geom2d_CartesianPoint(P2),
282 new Geom2d_CartesianPoint(P3),
284 return solutions(di,ct3,a[1]);
289 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
290 new Geom2d_CartesianPoint(P2),
292 return solutions(di,ct3,a[1]);
300 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
301 new Geom2d_CartesianPoint(P1),
304 return solutions(di,ct3,a[1]);
309 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P1),
310 new Geom2d_CartesianPoint(P3),
313 return solutions(di,ct3,a[1]);
318 di << "Point, radius, radius ???"<<"\n";
330 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
331 Geom2dGcc::Unqualified(C3),
334 return solutions(di,ct3,a[1]);
339 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C2),
340 new Geom2d_CartesianPoint(P3),
343 return solutions(di,ct3,a[1]);
348 di << "Radius - Curve - Radius ??"<<"\n";
356 Geom2dGcc_Circ2d2TanRad ct3(Geom2dGcc::Unqualified(C3),
357 new Geom2d_CartesianPoint(P2),
360 return solutions(di,ct3,a[1]);
365 Geom2dGcc_Circ2d2TanRad ct3(new Geom2d_CartesianPoint(P2),
366 new Geom2d_CartesianPoint(P3),
369 return solutions(di,ct3,a[1]);
374 di << "Radius - Point - Radius ??"<<"\n";
381 di << "radius, radius ???"<<"\n";
389 //=======================================================================
392 //=======================================================================
394 static Standard_Integer lintang (Draw_Interpretor& di,Standard_Integer n, const char** a)
398 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
399 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
403 if (C1.IsNull() || C2.IsNull())
406 Draw_Color col = DrawTrSurf_CurveColor(Draw_Color(Draw_vert));
409 Handle(Geom2d_Line) L = Handle(Geom2d_Line)::DownCast(C2);
411 di << "Second argument must be a line";
414 Standard_Real ang = atof(a[4]) * (M_PI / 180.0);
415 Geom2dGcc_Lin2dTanObl ct3(Geom2dGcc::Unqualified(C1),
417 Precision::Angular(),
418 (C1->FirstParameter()+C1->LastParameter())/2.,
421 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
422 Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
423 sprintf(solname,"%s_%d",a[1],i);
424 char* temp = solname; // pour portage WNT
425 DrawTrSurf::Set(temp,LS);
426 di << solname << " ";
430 di << "Lin2dTanObl Not done" << "\n";
433 Geom2dGcc_Lin2d2Tan ct3(Geom2dGcc::Unqualified(C1),
434 Geom2dGcc::Unqualified(C2),
435 Precision::Angular(),
436 (C1->FirstParameter()+C1->LastParameter())/2.,
437 (C2->FirstParameter()+C2->LastParameter())/2.);
439 for (Standard_Integer i = 1 ; i <= ct3.NbSolutions() ; i++) {
440 Handle(Geom2d_Line) LS = new Geom2d_Line(ct3.ThisSolution(i));
441 sprintf(solname,"%s_%d",a[1],i);
442 char* temp = solname; // pour portage WNT
443 DrawTrSurf::Set(temp,LS);
444 di << solname << " ";
448 di << "Lin2d2Tan Not done" << "\n";
451 DrawTrSurf_CurveColor(col);
456 //==================================================================================
457 static Standard_Integer interpol (Draw_Interpretor& di,Standard_Integer n, const char** a)
458 //==================================================================================
461 di <<"give a name to your curve !" << "\n";
465 Standard_Integer id,XX,YY,b, i, j;
466 di << "Pick points "<< "\n";
467 dout.Select(id, XX, YY, b);
468 Standard_Real zoom = dout.Zoom(id);
469 if (b != 1) return 0;
470 if (id < 0) return 0;
473 Standard_Boolean newcurve;
476 Handle(Draw_Marker3D) mark;
477 Handle(TColgp_HArray1OfPnt) Points = new TColgp_HArray1OfPnt(1, 1);
478 P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
479 Points->SetValue(1 , P);
480 Handle(TColgp_HArray1OfPnt) ThePoints = new TColgp_HArray1OfPnt(1, 2);
481 ThePoints->SetValue(1 , P);
482 mark = new Draw_Marker3D(Points->Value(1), Draw_X, Draw_vert);
485 Handle(Geom_BSplineCurve) C;
489 dout.Select(id,XX,YY,b, Standard_False);
490 P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0);
491 ThePoints->SetValue(i+1, P);
492 newcurve = Standard_False;
493 if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
496 mark = new Draw_Marker3D(ThePoints->Value(i), Draw_X, Draw_vert);
500 new TColgp_HArray1OfPnt(ThePoints->Lower(),ThePoints->Upper());
501 Points->ChangeArray1() = ThePoints->Array1();
502 newcurve = Standard_True;
504 GeomAPI_Interpolate anInterpolator(ThePoints,
507 anInterpolator.Perform() ;
508 if (anInterpolator.IsDone()) {
509 C = anInterpolator.Curve() ;
510 Handle(DrawTrSurf_BSplineCurve)
511 DC = new DrawTrSurf_BSplineCurve(C);
515 dout.RepaintView(id);
518 ThePoints = new TColgp_HArray1OfPnt(1, i+1);
519 for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
523 GeomAPI_Interpolate anInterpolator(ThePoints,
526 anInterpolator.Perform() ;
527 if (anInterpolator.IsDone()) {
528 C = anInterpolator.Curve() ;
529 DrawTrSurf::Set(a[1], C);
530 dout.RepaintView(id);
534 Handle(Draw_Marker2D) mark;
535 Handle(TColgp_HArray1OfPnt2d) Points = new TColgp_HArray1OfPnt2d(1, 1);
536 P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
537 Points->SetValue(1 , P2d);
538 Handle(TColgp_HArray1OfPnt2d) ThePoints = new TColgp_HArray1OfPnt2d(1, 2);
539 ThePoints->SetValue(1, P2d);
540 mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
543 Handle(Geom2d_BSplineCurve) C;
547 dout.Select(id,XX,YY,b, Standard_False);
548 P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom);
549 ThePoints->SetValue(i+1, P2d);
550 newcurve = Standard_False;
551 if (!(ThePoints->Value(i)).IsEqual(ThePoints->Value(i+1), 1.e-06)) {
554 mark = new Draw_Marker2D(P2d, Draw_X, Draw_vert);
558 new TColgp_HArray1OfPnt2d(ThePoints->Lower(),ThePoints->Upper());
559 Points->ChangeArray1() = ThePoints->Array1();
560 newcurve = Standard_True;
562 Geom2dAPI_Interpolate a2dInterpolator(ThePoints,
565 a2dInterpolator.Perform() ;
566 if (a2dInterpolator.IsDone()) {
567 C = a2dInterpolator.Curve() ;
569 Handle(DrawTrSurf_BSplineCurve2d)
570 DC = new DrawTrSurf_BSplineCurve2d(C);
574 dout.RepaintView(id);
578 ThePoints = new TColgp_HArray1OfPnt2d(1, i+1);
579 for (j = 1; j <= i; j++) ThePoints->SetValue(j, Points->Value(j));
583 Geom2dAPI_Interpolate a2dInterpolator(Points,
586 a2dInterpolator.Perform() ;
587 if (a2dInterpolator.IsDone()) {
588 C = a2dInterpolator.Curve() ;
590 DrawTrSurf::Set(a[1], C);
591 dout.RepaintView(id);
597 // lecture du fichier.
598 // nbpoints, 2d ou 3d, puis valeurs.
599 const char* nomfic = a[2];
600 ifstream iFile(nomfic, ios::in);
601 if (!iFile) return 1;
602 Standard_Integer nbp, i;
603 Standard_Real x, y, z;
607 if (!strcmp(dimen,"3d")) {
608 Handle_TColgp_HArray1OfPnt Point =
609 new TColgp_HArray1OfPnt(1, nbp);
610 for (i = 1; i <= nbp; i++) {
611 iFile >> x >> y >> z;
612 Point->SetValue(i, gp_Pnt(x, y, z));
614 GeomAPI_Interpolate anInterpolator(Point,
617 anInterpolator.Perform() ;
618 if (anInterpolator.IsDone()) {
619 Handle(Geom_BSplineCurve) C =
620 anInterpolator.Curve();
621 DrawTrSurf::Set(a[1], C);
624 else if (!strcmp(dimen,"2d")) {
625 Handle(TColgp_HArray1OfPnt2d) PointPtr =
626 new TColgp_HArray1OfPnt2d(1, nbp);
627 for (i = 1; i <= nbp; i++) {
629 PointPtr->SetValue(i, gp_Pnt2d(x, y));
631 Geom2dAPI_Interpolate a2dInterpolator(PointPtr,
634 a2dInterpolator.Perform() ;
635 if (a2dInterpolator.IsDone()) {
636 Handle(Geom2d_BSplineCurve) C = a2dInterpolator.Curve() ;
637 DrawTrSurf::Set(a[1], C);
644 static Standard_Integer tanginterpol (Draw_Interpretor& di,
669 Standard_Boolean periodic_flag = Standard_False ;
677 Handle(Geom_BSplineCurve) NewCurvePtr ;
683 if (strcmp(a[num_read],"p") == 0) {
684 periodic_flag = Standard_True ;
687 num_parameters = atoi(a[num_read]) ;
689 if (num_parameters < 2) {
692 if ( n < num_parameters * 3 + num_read) {
695 Handle_TColgp_HArray1OfPnt PointsArrayPtr=
696 new TColgp_HArray1OfPnt(1,num_parameters) ;
698 num_tangents = ((n - num_read) / 3) - num_parameters ;
699 num_tangents = Max (0,num_tangents) ;
700 num_tangents = Min (num_parameters, num_tangents) ;
702 num_start = num_read ;
704 while (num_read <= num_parameters * 3 + num_start ) {
705 for (jj = 1 ; jj <= 3 ; jj++) {
706 a_point.SetCoord(jj,atof(a[num_read])) ;
709 PointsArrayPtr->SetValue(ii,a_point) ;
712 GeomAPI_Interpolate anInterpolator(PointsArrayPtr,
716 if (num_tangents > 0) {
717 TColgp_Array1OfVec TangentsArray(1,num_parameters) ;
718 Handle_TColStd_HArray1OfBoolean
720 new TColStd_HArray1OfBoolean(1,num_parameters) ;
722 for (ii = 1 ; ii <= num_tangents ; ii++) {
723 TangentFlagsPtr->SetValue(ii,Standard_True) ;
725 for (ii = num_tangents + 1 ; ii <= num_parameters ; ii++) {
726 TangentFlagsPtr->SetValue(ii,Standard_False) ;
729 while (ii <= num_tangents) {
730 for (jj = 1 ; jj <= 3 ; jj++) {
731 a_vector.SetCoord(jj,atof(a[num_read])) ;
734 TangentsArray.SetValue(ii,a_vector) ;
739 anInterpolator.Load(TangentsArray,
742 anInterpolator.Perform() ;
743 if (anInterpolator.IsDone()) {
745 anInterpolator.Curve() ;
747 DrawTrSurf::Set(a[1],
755 //==================================================================================
756 static Standard_Integer gcarc (Draw_Interpretor& di,Standard_Integer n, const char** a)
757 //==================================================================================
761 if (!strcmp(a[2], "seg")) {
762 if (DrawTrSurf::GetPoint(a[3], P1)) {
763 if (DrawTrSurf::GetPoint(a[4], P2)) {
764 Handle(Geom_Curve) theline = GC_MakeSegment(P1,P2).Value();
765 DrawTrSurf::Set(a[1], theline);
770 else if (!strcmp(a[2], "cir")) {
771 if (DrawTrSurf::GetPoint(a[3], P1)) {
772 if (DrawTrSurf::GetPoint(a[4], P2)) {
773 if (DrawTrSurf::GetPoint(a[5], P3)) {
774 // if (DrawTrSurf::GetPoint(a[6], P4)) {
776 DrawTrSurf::GetPoint(a[6], P4);
777 gp_Vec V1 = gp_Vec(P2,P3);
778 Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,V1,P4).Value();
779 DrawTrSurf::Set(a[1], thearc);
783 Handle(Geom_Curve)thearc = GC_MakeArcOfCircle(P1,P2,P3).Value();
784 DrawTrSurf::Set(a[1], thearc);
792 di <<"give a name for arc and the type seg or cir then" << "\n";
793 di <<"give passing points p1 p2 for seg p1 p2 p3 or p1 p2 p3 p4 for cir (p2 p3 is a tgtvec)!" << "\n";
797 //=======================================================================
798 //function : ConstraintCommands
800 //=======================================================================
803 void GeometryTest::ConstraintCommands(Draw_Interpretor& theCommands)
806 static Standard_Boolean loaded = Standard_False;
808 loaded = Standard_True;
810 DrawTrSurf::BasicCommands(theCommands);
813 // constrained constructs
814 g = "GEOMETRY Constraints";
816 theCommands.Add("cirtang",
817 "cirtang cname curve/point/radius curve/point/radius curve/point/radius",
821 theCommands.Add("lintan",
822 "lintan lname curve1 curve2 [angle]",
827 theCommands.Add("interpol",
828 "interpol cname [fic]",
831 theCommands.Add("tanginterpol",
832 "tanginterpol curve [p] num_points points [tangents] modifier p = periodic",
836 theCommands.Add("gcarc",
837 "gcarc name seg/cir p1 p2 p3 p4",