Open CASCADE学习|2个TCL命令转C++

1、torus aTorus 10 2

该命令的实现代码为:

static Standard_Integer anasurface (Draw_Interpretor& ,
            Standard_Integer  n, 
            const char** a)
{
  if (n < 2) return 1;
  gp_Ax3 loc;
​
  Standard_Integer i;
​
  if (n < 5) {
    loc = gp_Ax3(gp_Pnt(0,0,0),gp_Dir(0,0,1),gp_Dir(1,0,0));
    i = 2;
  }
  else if (n < 8) {
    loc = gp_Ax3(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
     gp_Dir(0,0,1),gp_Dir(1,0,0));
    i = 5;
  }
  else if (n < 11) {
    loc = gp_Ax3(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
     gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])));
    i = 8;
  }
  else if (n < 14) {
    loc = gp_Ax3(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
     gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
     gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10])));
    i = 11;
  }
  else
    return 1;
​
  Handle(Geom_Geometry) result;
​
  if (!strcasecmp(a[0],"plane")) {
    Handle(Geom_Plane) C = new Geom_Plane(loc);
    result = C;
  }
  else {
    if (i >= n) return 1;
    Standard_Real par1 = Draw::Atof(a[i]);
    
    if (!strcasecmp(a[0],"cylinder")) {
      Handle(Geom_CylindricalSurface) C = 
  new Geom_CylindricalSurface(loc,par1);
      result = C;
    }
    
    else if (!strcasecmp(a[0],"sphere")) {
      Handle(Geom_SphericalSurface) C = 
  new Geom_SphericalSurface(loc,par1);
      result = C;
    }
    
    else {
      if (i+1 >= n) return 1;
      Standard_Real par2 = Draw::Atof(a[i+1]);
      
      if (!strcasecmp(a[0],"cone")) {
  par1 *= (M_PI / 180.0);
  Handle(Geom_ConicalSurface) C =
    new Geom_ConicalSurface(loc,par1,par2);
  result = C;
      }
    
      else if (!strcasecmp(a[0],"torus")) {
  Handle(Geom_ToroidalSurface) C =
    new Geom_ToroidalSurface(loc,par1,par2);
  result = C;
      }
    }    
  }
​
  DrawTrSurf::Set(a[1],result);
  return 0;
}

转化为C++代码:

gp_Ax3 loc = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1), gp_Dir(1, 0, 0));Handle(Geom_ToroidalSurface) aTorus =new Geom_ToroidalSurface(loc, 10, 2);

2、mkedgecurve aHelixEdge 0.01

该命令的实现代码为:

static Standard_Integer mkedgecurve (Draw_Interpretor& ,Standard_Integer n,const char** a)
{
​
  if (n < 3) return 1;
  Standard_Real Tolerance = Draw::Atof(a[2]) ;
​
  TopoDS_Shape S = DBRep::Get(a[1]);
  
  if (S.IsNull()) return 1;
  
   BRepLib::BuildCurves3d(S,
        Tolerance) ;
   return 0 ;
}

转化为C++代码:

BRepLib::BuildCurves3d(aHelixEdge,0.01);

你可能感兴趣的:(Open,CASCADE,学习,c++,Open,CASCADE)