From 21add8911d082d9b3044507cff4e0c240f243461 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 15 Jun 2012 13:04:07 +0200 Subject: [PATCH] First draft of makeThread --- src/Mod/Part/App/AppPartPy.cpp | 21 ++++++++++++ src/Mod/Part/App/TopoShape.cpp | 63 ++++++++++++++++++++++++++++++++++ src/Mod/Part/App/TopoShape.h | 2 ++ src/Mod/Part/MakeBottle.py | 8 +++-- 4 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 2132042df4..342c59069e 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -785,6 +785,24 @@ static PyObject * makeHelix(PyObject *self, PyObject *args) } } +static PyObject * makeThread(PyObject *self, PyObject *args) +{ + double pitch, height, depth, radius; + if (!PyArg_ParseTuple(args, "dddd", &pitch, &height, &depth, &radius)) + return 0; + + try { + TopoShape helix; + TopoDS_Shape wire = helix.makeThread(pitch, height, depth, radius); + return new TopoShapeWirePy(new TopoShape(wire)); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } +} + static PyObject * makeLine(PyObject *self, PyObject *args) { PyObject *obj1, *obj2; @@ -1475,6 +1493,9 @@ struct PyMethodDef Part_methods[] = { "By default a cylindrical surface is used to create the helix. If the fourth parameter is set\n" "(the apex given in degree) a conical surface is used instead"}, + {"makeThread" ,makeThread,METH_VARARGS, + "makeThread(pitch,depth,height,radius) -- Make a thread with a given pitch, depth, height and radius"}, + {"makeRevolution" ,makeRevolution,METH_VARARGS, "makeRevolution(Curve,[vmin,vmax,angle,pnt,dir]) -- Make a revolved shape\n" "by rotating the curve or a portion of it around an axis given by (pnt,dir).\n" diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index a42a3ec087..8ebac82421 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -105,6 +105,7 @@ # include # include # include +# include # include # include # include @@ -1560,6 +1561,68 @@ TopoDS_Shape TopoShape::makeHelix(Standard_Real pitch, Standard_Real height, return wire; } +TopoDS_Shape TopoShape::makeThread(Standard_Real pitch, + Standard_Real depth, + Standard_Real height, + Standard_Real radius) const +{ + if (pitch < Precision::Confusion()) + Standard_Failure::Raise("Pitch of thread too small"); + + if (depth < Precision::Confusion()) + Standard_Failure::Raise("Depth of thread too small"); + + if (height < Precision::Confusion()) + Standard_Failure::Raise("Height of thread too small"); + + if (radius < Precision::Confusion()) + Standard_Failure::Raise("Radius of thread too small"); + + //Threading : Create Surfaces + gp_Ax2 cylAx2(gp_Pnt(0.0,0.0,0.0) , gp::DZ()); + Handle(Geom_CylindricalSurface) aCyl1 = new Geom_CylindricalSurface(cylAx2 , radius); + Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(cylAx2 , radius+depth); + + //Threading : Define 2D Curves + gp_Pnt2d aPnt(2. * M_PI , height / 2.); + gp_Dir2d aDir(2. * M_PI , height / 4.); + gp_Ax2d aAx2d(aPnt , aDir); + + Standard_Real aMajor = 2. * M_PI; + Standard_Real aMinor = pitch; + + Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(aAx2d , aMajor , aMinor); + Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(aAx2d , aMajor , aMinor / 4); + + Handle(Geom2d_TrimmedCurve) aArc1 = new Geom2d_TrimmedCurve(anEllipse1 , 0 , M_PI); + Handle(Geom2d_TrimmedCurve) aArc2 = new Geom2d_TrimmedCurve(anEllipse2 , 0 , M_PI); + + gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0); + gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI); + + Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1 , anEllipsePnt2); + + //Threading : Build Edges and Wires + TopoDS_Edge aEdge1OnSurf1 = BRepBuilderAPI_MakeEdge(aArc1 , aCyl1); + TopoDS_Edge aEdge2OnSurf1 = BRepBuilderAPI_MakeEdge(aSegment , aCyl1); + TopoDS_Edge aEdge1OnSurf2 = BRepBuilderAPI_MakeEdge(aArc2 , aCyl2); + TopoDS_Edge aEdge2OnSurf2 = BRepBuilderAPI_MakeEdge(aSegment , aCyl2); + + TopoDS_Wire threadingWire1 = BRepBuilderAPI_MakeWire(aEdge1OnSurf1 , aEdge2OnSurf1); + TopoDS_Wire threadingWire2 = BRepBuilderAPI_MakeWire(aEdge1OnSurf2 , aEdge2OnSurf2); + + BRepLib::BuildCurves3d(threadingWire1); + BRepLib::BuildCurves3d(threadingWire2); + + BRepOffsetAPI_ThruSections aTool(Standard_True); + + aTool.AddWire(threadingWire1); + aTool.AddWire(threadingWire2); + aTool.CheckCompatibility(Standard_False); + + return aTool.Shape(); +} + 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 1d16b9e073..aaf521e051 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -163,6 +163,8 @@ public: TopoDS_Shape makeTube(double radius, double tol, int cont, int maxdeg, int maxsegm) const; TopoDS_Shape makeHelix(Standard_Real pitch, Standard_Real height, Standard_Real radius, Standard_Real angle=0, Standard_Boolean left=Standard_False) const; + TopoDS_Shape makeThread(Standard_Real pitch, Standard_Real depth, + Standard_Real height, Standard_Real radius) const; TopoDS_Shape makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid, Standard_Boolean isRuled) const; TopoDS_Shape makeOffset(double offset, double tol, diff --git a/src/Mod/Part/MakeBottle.py b/src/Mod/Part/MakeBottle.py index 65fb209716..1f4c2babf4 100644 --- a/src/Mod/Part/MakeBottle.py +++ b/src/Mod/Part/MakeBottle.py @@ -47,7 +47,8 @@ def makeBottle(myWidth=50.0, myHeight=70.0, myThickness=30.0): aTrsf=Base.Matrix() aTrsf.rotateZ(math.pi) # rotate around the z-axis - aMirroredWire=aWire.transformGeometry(aTrsf) + aMirroredWire=aWire.copy() + aMirroredWire.transformShape(aTrsf) myWireProfile=Part.Wire([aWire,aMirroredWire]) myFaceProfile=Part.Face(myWireProfile) @@ -80,8 +81,11 @@ def makeBottle(myWidth=50.0, myHeight=70.0, myThickness=30.0): # This doesn't work for any reason myBody = myBody.makeThickness([faceToRemove],-myThickness/50 , 1.e-3) + myThreading = Part.makeThread(myNeckHeight/10, myNeckRadius*0.06, myHeight/10, myNeckRadius*0.99) + myThreading.translate(Base.Vector(0,0,myHeight)) + myCompound = Part.Compound([myBody, myThreading]) - return myBody + return myCompound def makeBoreHole(): # create a document if needed