diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 91b1512a71..69948f597e 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -760,38 +760,8 @@ static PyObject * makeHelix(PyObject *self, PyObject *args) return 0; try { - if (pitch < Precision::Confusion()) - Standard_Failure::Raise("Pitch of helix too small"); - - if (height < Precision::Confusion()) - Standard_Failure::Raise("Height of helix too small"); - - gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); - Handle_Geom_Surface surf; - if (angle < 0) { - if (radius < Precision::Confusion()) - Standard_Failure::Raise("Radius of helix too small"); - surf = new Geom_CylindricalSurface(cylAx2, radius); - } - else { - angle = angle*(M_PI/180); - if (angle < Precision::Confusion()) - Standard_Failure::Raise("Angle of helix too small"); - surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius); - } - - gp_Pnt2d aPnt(0, 0); - gp_Dir2d aDir(2. * PI, pitch); - gp_Ax2d aAx2d(aPnt, aDir); - - Handle_Geom2d_Line line = new Geom2d_Line(aAx2d); - gp_Pnt2d beg = line->Value(0); - gp_Pnt2d end = line->Value(2.0*PI*(height/pitch)); - Handle_Geom2d_TrimmedCurve segm = GCE2d_MakeSegment(beg , end); - - TopoDS_Edge edgeOnSurf = BRepBuilderAPI_MakeEdge(segm , surf); - TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edgeOnSurf); - BRepLib::BuildCurves3d(wire); + TopoShape helix; + TopoDS_Shape wire = helix.makeHelix(pitch, height, radius, angle); return new TopoShapeWirePy(new TopoShape(wire)); } catch (Standard_Failure) { diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index a0a669b486..2e4a5cf809 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -547,39 +547,8 @@ App::DocumentObjectExecReturn *Helix::execute(void) Standard_Real myHeight = Height.getValue(); Standard_Real myRadius = Radius.getValue(); Standard_Real myAngle = Angle.getValue(); - - if (myPitch < Precision::Confusion()) - return new App::DocumentObjectExecReturn("Pitch of helix too small"); - - if (myHeight < Precision::Confusion()) - return new App::DocumentObjectExecReturn("Height of helix too small"); - - if (myRadius < Precision::Confusion()) - return new App::DocumentObjectExecReturn("Radius of helix too small"); - - gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); - Handle_Geom_Surface surf; - if (myAngle < Precision::Confusion()) { - surf = new Geom_CylindricalSurface(cylAx2, myRadius); - } - else { - myAngle = Base::toRadians(myAngle); - surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), myAngle, myRadius); - } - - gp_Pnt2d aPnt(0, 0); - gp_Dir2d aDir(2. * PI, myPitch); - gp_Ax2d aAx2d(aPnt, aDir); - - Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d); - gp_Pnt2d beg = line->Value(0); - gp_Pnt2d end = line->Value(sqrt(4.0*PI*PI+myPitch*myPitch)*(myHeight/myPitch)); - Handle(Geom2d_TrimmedCurve) segm = GCE2d_MakeSegment(beg , end); - - TopoDS_Edge edgeOnSurf = BRepBuilderAPI_MakeEdge(segm , surf); - TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edgeOnSurf); - BRepLib::BuildCurves3d(wire); - this->Shape.setValue(wire); + TopoShape helix; + this->Shape.setValue(helix.makeHelix(myPitch, myHeight, myRadius, myAngle)); } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 30de452f76..0ee407d9ec 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -26,6 +26,7 @@ #ifndef _PreComp_ # include # include +# include # include # include # include @@ -40,9 +41,11 @@ # include # include # include +# include # include # include # include +# include # include # include # include @@ -66,6 +69,9 @@ # include # include # include +# include +# include +# include # include # include # include @@ -1438,6 +1444,45 @@ TopoDS_Shape TopoShape::makeSweep(const TopoDS_Shape& profile, double tol, int f return mkBuilder.Face(); } +TopoDS_Shape TopoShape::makeHelix(Standard_Real pitch, Standard_Real height, + Standard_Real radius, Standard_Real angle) const +{ + if (pitch < Precision::Confusion()) + Standard_Failure::Raise("Pitch of helix too small"); + + if (height < Precision::Confusion()) + Standard_Failure::Raise("Height of helix too small"); + + if (radius < Precision::Confusion()) + Standard_Failure::Raise("Radius of helix too small"); + + gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); + Handle_Geom_Surface surf; + if (angle < Precision::Confusion()) { + surf = new Geom_CylindricalSurface(cylAx2, radius); + } + else { + angle = Base::toRadians(angle); + if (angle < Precision::Confusion()) + Standard_Failure::Raise("Angle of helix too small"); + surf = new Geom_ConicalSurface(gp_Ax3(cylAx2), angle, radius); + } + + gp_Pnt2d aPnt(0, 0); + gp_Dir2d aDir(2. * PI, pitch); + gp_Ax2d aAx2d(aPnt, aDir); + + Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d); + gp_Pnt2d beg = line->Value(0); + gp_Pnt2d end = line->Value(sqrt(4.0*PI*PI+pitch*pitch)*(height/pitch)); + Handle(Geom2d_TrimmedCurve) segm = GCE2d_MakeSegment(beg , end); + + TopoDS_Edge edgeOnSurf = BRepBuilderAPI_MakeEdge(segm , surf); + TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edgeOnSurf); + BRepLib::BuildCurves3d(wire); + return wire; +} + TopoDS_Shape TopoShape::makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid, Standard_Boolean isRuled) const diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 9def92645d..b91a32b836 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -198,7 +198,10 @@ public: TopoDS_Shape makeSweep(const TopoDS_Shape& profile, double, int) const; TopoDS_Shape makeTube(double radius, double tol) const; TopoDS_Shape makeTube() const; - TopoDS_Shape makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid, Standard_Boolean isRuled) const; + TopoDS_Shape makeHelix(Standard_Real pitch, Standard_Real height, + Standard_Real radius, Standard_Real angle=0) const; + TopoDS_Shape makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid, + Standard_Boolean isRuled) const; TopoDS_Shape makeOffset(double offset, double tol, bool intersection = false, bool selfInter = false, short offsetMode = 0, short join = 0);