0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / GeomliteTest / GeomliteTest_SurfaceCommands.cxx
index 3194970..8e76d21 100644 (file)
 #include <GeomLib_Tool.hxx>
 #include <TopoDS_Shape.hxx>
 #include <DBRep.hxx>
+#include <Geom_Curve.hxx>
 
-//#ifdef WNT
 #include <stdio.h>
 #ifdef _WIN32
-//#define strcasecmp strcmp Already defined
 Standard_IMPORT Draw_Viewer dout;
 #endif
 
@@ -124,7 +123,7 @@ static Standard_Integer surface_radius (Draw_Interpretor& di,
        di << "Min Radius of Curvature : " << radius  << "\n";
       }
       else {
-       di << "Min Radius of Curvature :  infinite" << "\n";
+       di << "Min Radius of Curvature :  infinite\n";
       }
     
       radius = myProperties.MaxCurvature();
@@ -134,10 +133,10 @@ static Standard_Integer surface_radius (Draw_Interpretor& di,
        di << "Max Radius of Curvature : " << radius  << "\n";
       }
       else
-       di << "Min Radius of Curvature :  infinite" << "\n";
+       di << "Min Radius of Curvature :  infinite\n";
     }
     else {
-      di << "Curvature not defined." << "\n";
+      di << "Curvature not defined.\n";
     }
   }
   else {
@@ -549,7 +548,7 @@ static Standard_Integer tobezier(Draw_Interpretor& di,
          Conv(S, U1, U2, V1, V2, Precision::PConfusion());
        NbU = Conv.NbUPatches();
        NbV = Conv.NbVPatches();
-       di << NbU << " X " << NbV << " patches in the result" << "\n";
+       di << NbU << " X " << NbV << " patches in the result\n";
        for (i = 1; i <= NbU; i++) {
          for (j = 1; j <= NbV; j++) {
            Sprintf(name,"%s_%i_%i",a[1],i,j);
@@ -562,7 +561,7 @@ static Standard_Integer tobezier(Draw_Interpretor& di,
        GeomConvert_BSplineSurfaceToBezierSurface Conv(S);
        NbU = Conv.NbUPatches();
        NbV = Conv.NbVPatches();
-       di << NbU << " X " << NbV << " patches in the result" << "\n";
+       di << NbU << " X " << NbV << " patches in the result\n";
        for (i = 1; i <= NbU; i++) {
          for (j = 1; j <= NbV; j++) {
            Sprintf(name,"%s_%i_%i",a[1],i,j);
@@ -580,7 +579,7 @@ static Standard_Integer tobezier(Draw_Interpretor& di,
        GeomConvert_BSplineCurveToBezierCurve Conv(C3d, U1, U2, 
                                                   Precision::PConfusion());
        NbArc = Conv.NbArcs();
-       di << NbArc << " arcs in the result" << "\n";
+       di << NbArc << " arcs in the result\n";
        for (i = 1; i <= NbArc; i++) {
          Sprintf(name,"%s_%i",a[1],i);
          char *temp = name ;
@@ -590,7 +589,7 @@ static Standard_Integer tobezier(Draw_Interpretor& di,
       else {
        GeomConvert_BSplineCurveToBezierCurve Conv(C3d);
        NbArc = Conv.NbArcs();
-       di << NbArc << " arcs in the result" << "\n";
+       di << NbArc << " arcs in the result\n";
        for (i = 1; i <= NbArc; i++) {
          Sprintf(name,"%s_%i",a[1],i);
          char *temp = name ;
@@ -607,7 +606,7 @@ static Standard_Integer tobezier(Draw_Interpretor& di,
       Geom2dConvert_BSplineCurveToBezierCurve Conv(C2d, U1, U2, 
                                                   Precision::PConfusion());
       NbArc = Conv.NbArcs();
-      di << NbArc << " arcs in the result" << "\n";
+      di << NbArc << " arcs in the result\n";
       for (i = 1; i <= NbArc; i++) {
        Sprintf(name,"%s_%i",a[1],i);
        char *temp = name ;
@@ -617,7 +616,7 @@ static Standard_Integer tobezier(Draw_Interpretor& di,
     else {
       Geom2dConvert_BSplineCurveToBezierCurve Conv(C2d);
       NbArc = Conv.NbArcs();
-      di << NbArc << " arcs in the result" << "\n";
+      di << NbArc << " arcs in the result\n";
       for (i = 1; i <= NbArc; i++) {
        Sprintf(name,"%s_%i",a[1],i);
        char *temp = name ;
@@ -643,8 +642,8 @@ static Standard_Integer convbz(Draw_Interpretor& di,
   Standard_Real Tol = Precision::Confusion();
   
   NbU = Draw::Atoi(a[2]);
-  if ( (Handle(Geom_Curve)::
-       DownCast(DrawTrSurf::Get(a[3]))).IsNull()) {    
+  Handle(Geom_Curve) aCurve (Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(a[3])));
+  if (aCurve.IsNull()) {
     // Cas Surfacique
     NbV = Draw::Atoi(a[3]);
     if (n<4+NbU*NbV) {
@@ -658,7 +657,7 @@ static Standard_Integer convbz(Draw_Interpretor& di,
        BZ(ii,jj) = 
          Handle(Geom_BezierSurface)::DownCast(DrawTrSurf::Get(a[kk]));
        if (BZ(ii,jj).IsNull()) {
-         di << "the Surface " << kk <<"is not a BezierSurface" << "\n";
+         di << "the Surface " << kk <<"is not a BezierSurface\n";
          return 1;
        }
        kk++;
@@ -668,7 +667,7 @@ static Standard_Integer convbz(Draw_Interpretor& di,
     GeomConvert_CompBezierSurfacesToBSplineSurface Conv(BZ, Tol);
     
     if (! Conv.IsDone()) {
-      di << "Convert Not Done" << "\n";
+      di << "Convert Not Done\n";
       return 1;
     }
 
@@ -689,7 +688,7 @@ static Standard_Integer convbz(Draw_Interpretor& di,
     for (ii=1, kk=3; ii<=NbU; ii++,kk++) {
       BZ =  Handle(Geom_BezierCurve)::DownCast(DrawTrSurf::Get(a[kk]));
       if (BZ.IsNull()) {
-         di << "the curve " << kk <<"is not a BezierCurve" << "\n";
+         di << "the curve " << kk <<"is not a BezierCurve\n";
          return 1;
        }
       TColgp_Array1OfPnt Poles(1, BZ->NbPoles());
@@ -937,8 +936,10 @@ static Standard_Integer movepole (Draw_Interpretor& , Standard_Integer n, const
   if (GBz.IsNull()) {
     GBs = DrawTrSurf::GetBSplineSurface(a[1]);
     if (GBs.IsNull())
+    {
       return 1;
-      BSpline = Standard_True;
+    }
+    BSpline = Standard_True;
   }
 
   Standard_Real dx = Draw::Atof(a[n-3]);
@@ -1194,7 +1195,7 @@ static Standard_Integer rempole (Draw_Interpretor& di, Standard_Integer n, const
   
   if ( !strcasecmp(a[0],"remrowpole")) {
     if ( BSpline) {
-      di << " Error : Cannot remove a polerow on a BSplineSurface " << "\n";
+      di << " Error : Cannot remove a polerow on a BSplineSurface \n";
     }
     else {
       GBz->RemovePoleRow(NewIndex);
@@ -1202,7 +1203,7 @@ static Standard_Integer rempole (Draw_Interpretor& di, Standard_Integer n, const
   }
   else if ( !strcasecmp(a[0],"remcolpole")) {
     if ( BSpline) {
-      di << " Error : Cannot remove a polecol on a BSplineSurface " << "\n";
+      di << " Error : Cannot remove a polecol on a BSplineSurface \n";
     }
     else {
       GBz->RemovePoleCol(NewIndex);
@@ -1228,8 +1229,10 @@ static Standard_Integer sfindp (Draw_Interpretor& , Standard_Integer n, const ch
   if (GBz.IsNull()) {
     GBs = DrawTrSurf::GetBSplineSurface(a[1]);
     if (GBs.IsNull())
+    {
       return 1;
-      BSpline = Standard_True;
+    }
+    BSpline = Standard_True;
   }
 
   Standard_Integer UIndex = 0;
@@ -1348,7 +1351,7 @@ static Standard_Integer exchuv (Draw_Interpretor& , Standard_Integer n, const ch
 
 static Standard_Integer segsur (Draw_Interpretor& , Standard_Integer n, const char** a)
 {
-  if (n < 6) return 1;
+  if (n < 6 || n > 8) return 1;
 
   Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
   Handle(Geom_BSplineSurface) GBs;
@@ -1356,7 +1359,15 @@ static Standard_Integer segsur (Draw_Interpretor& , Standard_Integer n, const ch
     GBs = DrawTrSurf::GetBSplineSurface(a[1]);
     if (GBs.IsNull())
       return 1;
-    GBs->Segment(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5])); 
+
+    Standard_Real aUTolerance = Precision::PConfusion();
+    Standard_Real aVTolerance = Precision::PConfusion();
+    if (n >= 7)
+      aUTolerance = aVTolerance = Draw::Atof(a[6]);
+    if (n == 8)
+      aVTolerance = Draw::Atof(a[7]);
+
+    GBs->Segment(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]), aUTolerance, aVTolerance); 
   }
   else {
     GBz->Segment(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
@@ -1370,14 +1381,14 @@ static Standard_Integer compBsplSur (Draw_Interpretor& , Standard_Integer n, con
 {
   if (n < 2) 
   {
-    cout<<"Invalid number of parameters"<<endl;
+    std::cout<<"Invalid number of parameters"<<std::endl;
     return 1;
   }
 
   Handle(Geom_BSplineSurface) GBs1 = DrawTrSurf::GetBSplineSurface(a[1]);
   Handle(Geom_BSplineSurface) GBs2 = DrawTrSurf::GetBSplineSurface(a[2]);
   if (GBs1.IsNull() || GBs2.IsNull()) {
-    cout<<"Invalid surface"<<endl;
+    std::cout<<"Invalid surface"<<std::endl;
     return 1;
   }
    
@@ -1412,7 +1423,7 @@ static Standard_Integer compBsplSur (Draw_Interpretor& , Standard_Integer n, con
       {
         nbErr++;
         Standard_Real aD = sqrt(aDist);
-        cout<<"Surfaces differ for U,V,Dist: "<<aU<<" "<<aV<<" "<<aD<<endl;
+        std::cout<<"Surfaces differ for U,V,Dist: "<<aU<<" "<<aV<<" "<<aD<<std::endl;
       }
     }
   }
@@ -1459,7 +1470,7 @@ static Standard_Integer parameters (Draw_Interpretor& di, Standard_Integer n, co
     { 
       // try to find parameters on a Surface
       Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[1]);
-      if( S.IsNull() ) { di << "Unknown surface" << "\n"; return 1; }
+      if( S.IsNull() ) { di << "Unknown surface\n"; return 1; }
       gp_Pnt P(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
       Standard_Real Tol = Draw::Atof(a[5]), U = 0., V = 0.;
       Standard_Boolean res = GeomLib_Tool::Parameters(S,P,Tol,U,V);
@@ -1467,41 +1478,41 @@ static Standard_Integer parameters (Draw_Interpretor& di, Standard_Integer n, co
       Draw::Set(a[6],U);
       Draw::Set(a[7],V);
 
-      if( !res ) { di << "Wrong point" << "\n"; return 1; }
+      if( !res ) { di << "Wrong point\n"; return 1; }
     }
   else if(n == 7)
     {
       // try to find parameters on a 3d Curve
       Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[1]);
-      if( C.IsNull() ) { di << "Unknown curve" << "\n"; return 1; }
+      if( C.IsNull() ) { di << "Unknown curve\n"; return 1; }
       gp_Pnt P(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4]));
       Standard_Real Tol = Draw::Atof(a[5]), U = 0.;
       Standard_Boolean res = GeomLib_Tool::Parameter(C,P,Tol,U);
     
       Draw::Set(a[6],U);
 
-    if( !res ) { di << "Wrong point" << "\n"; return 1; }
+    if( !res ) { di << "Wrong point\n"; return 1; }
     }
   else if(n == 6)
     {
       // try to find parameters on a 2d Curve
       Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[1]);
-      if( C.IsNull() ) { di << "Unknown curve 2d" << "\n";  return 1; }
+      if( C.IsNull() ) { di << "Unknown curve 2d\n";  return 1; }
       gp_Pnt2d P(Draw::Atof(a[2]), Draw::Atof(a[3]));
       Standard_Real Tol = Draw::Atof(a[4]), U = 0.;
       Standard_Boolean res = GeomLib_Tool::Parameter(C,P,Tol,U);
     
       Draw::Set(a[5],U);
 
-      if( !res ) { di << "Wrong point" << "\n"; return 1; }
+      if( !res ) { di << "Wrong point\n"; return 1; }
     }
   else
     {
-      di << "Invalid parameters!" << "\n";
-      di << "Usage:" << "\n";
-      di << "parameters Surf X Y Z Tol U V" << "\n";
-      di << "parameters Curv X Y Z Tol U" << "\n";
-      di << "parameters Curv2d X Y Tol U" << "\n";
+      di << "Invalid parameters!\n";
+      di << "Usage:\n";
+      di << "parameters Surf X Y Z Tol U V\n";
+      di << "parameters Curv X Y Z Tol U\n";
+      di << "parameters Curv2d X Y Tol U\n";
       return 1;
     }
 
@@ -1767,7 +1778,7 @@ void  GeomliteTest::SurfaceCommands(Draw_Interpretor& theCommands)
                  exchuv,g);
 
   theCommands.Add("segsur",
-                 "segsur name Ufirst Ulast Vfirst Vlast",
+                 "segsur name Ufirst Ulast Vfirst Vlast [Utol [Vtol]]",
                  __FILE__,
                  segsur , g);