How to Use pipeShell?

I want to use a BRepOffsetAPI_MakePipeShell to make a threading of a screw. but it not work as I expect. Please help me.

My code :

TopoDS_Shape MyPipe(const TopoDS_Wire &wbase, const TopoDS_Wire &along, const double k)
{

  /// Calculate the length of the path
  //----------------------------------
  GProp_GProps lp;
  BRepGProp::LinearProperties(along, lp);
  double length(lp.Mass());

  /// Prepare the shell
  //-------------------
  BRepOffsetAPI_MakePipeShell ps( along );

  /// Create a linear law
  //---------------------
  Handle(Law_Linear) ll = new Law_Linear;
  ll->Set(0.0, 1.0, length, k);

  /// Create the section center point
  //---------------------------------
  //BRepBuilderAPI_MakeVertex MV( gp::Origin() );

  /// Get the first and last point of the path
  //------------------------------------------
  TopoDS_Vertex pfirst, plast;

  TopExp::Vertices(along, pfirst, plast);

  /// Update the law parameters
  //---------------------------
  ps.SetLaw(wbase, ll, pfirst, Standard_False, Standard_False);

  ps.Build();

  return(ps.Shape());
};


TopoDS_Shape MakeScrew()
{
 //Parameter
  Standard_Real aBoltR = 5;
  Standard_Real aBoltH = 48;
  Standard_Real aThreadingNum = aBoltH / 2;
  Standard_Real aThreadingH = 56;

  //Draw a spiral curve
  gp_Pnt2d aPnt(2. * M_PI * aThreadingNum, aBoltH / 2);
  gp_Dir2d aDir(2. * M_PI * aThreadingNum, aBoltH / 4.);
  gp_Dir2d aDir2(3,1);
  gp_Ax2d anAx2d(gp_Pnt2d(0,0), aDir2);

  gp_Lin2d aLine2d(anAx2d);
  Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(gp::XOY(), aBoltR * 0.98);
  Handle(Geom2d_TrimmedCurve) aSeg = GCE2d_MakeSegment(aLine2d, 0.0, M_PI*10.0);
  TopoDS_Edge aHelixEdge = BRepBuilderAPI_MakeEdge(aSeg, aCyl1,0.0,20.0*M_PI).Edge();
  TopoDS_Wire aSpine = BRepBuilderAPI_MakeWire(aHelixEdge);
  BRepLib::BuildCurves3d(aSpine);
  //return aSpine;

//   gp_Pnt origin;
//   gp_Vec normal;
//   aLine2d.D1(aLine2d->FirstParameter(), origin, normal);
//   gp_Dir v1 = gp::DX().IsParallel(normal, Precision::Angular()) ? gp::DY() : gp::DX();
//   gp_Ax2 center(origin, normal, v1);
  double dParamStart;
  double dParamEnd;
  gp_Pnt ptStart;
  gp_Vec vStart;
  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aHelixEdge,dParamStart,dParamEnd);
  if (!aCurve.IsNull())
  {
    // Get the normal at the start
    aCurve->D1(dParamStart, ptStart, vStart);
    // Check the type of curve
    if (aCurve->IsKind(STANDARD_TYPE(Geom_Circle)))
    {
      // This is the end of the cylinder
    }
  }

  gp_Ax2 anAx2(gp_Pnt(aBoltR, 0, 0), gp_Dir(vStart));
  Handle(Geom_Circle) aCircle = new Geom_Circle(anAx2, 1);

  Standard_Real aRotationalAngle = 90.0;
  gp_Pnt aTrianglePnt1 = aCircle->Value((0.0 + aRotationalAngle)/360.0*M_PI*2);
  gp_Pnt aTrianglePnt2 = aCircle->Value((120.0 + aRotationalAngle)/360.0*M_PI*2);
  gp_Pnt aTrianglePnt3 = aCircle->Value((240.0 + aRotationalAngle)/360.0*M_PI*2);
  TopoDS_Edge aTriangleEdge1 = BRepBuilderAPI_MakeEdge(aTrianglePnt1,aTrianglePnt2);
  TopoDS_Edge aTriangleEdge2 = BRepBuilderAPI_MakeEdge(aTrianglePnt2, aTrianglePnt3);
  TopoDS_Edge aTriangleEdge3 = BRepBuilderAPI_MakeEdge(aTrianglePnt3, aTrianglePnt1);
  TopoDS_Wire aTriangleWire = BRepBuilderAPI_MakeWire(aTriangleEdge1, aTriangleEdge2, aTriangleEdge3);
  TopoDS_Face aTriangleFace = BRepBuilderAPI_MakeFace(aTriangleWire);



  return MyPipe(aSpine,aTriangleWire, 1);

}

 

Attachments: 
Shawn Yang's picture

Could anyone help me?

Shawn Yang's picture

I got a solution about this problem.

BRepOffsetAPI_MakePipeShell ps( along );

ps.SetMode(Standrad_True);

Reference:

https://www.freecadweb.org/wiki/Thread_for_Screw_Tutorial

Thanks

pranav.pkasthana_133780's picture

There is still issue is in this line

return MyPipe(aSpine,aTriangleWire, 1);

Instead use 

MyPipe(aTriangleWire,aSpine, 1);