diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 2662593c5..2132042df 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -1043,14 +1043,36 @@ static PyObject * makeTube(PyObject *self, PyObject *args) PyObject *pshape; double radius; double tolerance=0.001; + char* scont = "C0"; + int maxdegree = 3; + int maxsegment = 30; // Path + radius - if (!PyArg_ParseTuple(args, "O!d", &(TopoShapePy::Type), &pshape, &radius)) + if (!PyArg_ParseTuple(args, "O!d|sii", &(TopoShapePy::Type), &pshape, &radius, &scont, &maxdegree, &maxsegment)) return 0; + std::string str_cont = scont; + int cont; + if (str_cont == "C0") + cont = (int)GeomAbs_C0; + else if (str_cont == "C1") + cont = (int)GeomAbs_C1; + else if (str_cont == "C2") + cont = (int)GeomAbs_C2; + else if (str_cont == "C3") + cont = (int)GeomAbs_C3; + else if (str_cont == "CN") + cont = (int)GeomAbs_CN; + else if (str_cont == "G1") + cont = (int)GeomAbs_G1; + else if (str_cont == "G2") + cont = (int)GeomAbs_G2; + else + cont = (int)GeomAbs_C0; + try { const TopoDS_Shape& path_shape = static_cast(pshape)->getTopoShapePtr()->_Shape; TopoShape myShape(path_shape); - TopoDS_Shape face = myShape.makeTube(radius, tolerance); + TopoDS_Shape face = myShape.makeTube(radius, tolerance, cont, maxdegree, maxsegment); return new TopoShapeFacePy(new TopoShape(face)); } catch (Standard_Failure) { @@ -1465,7 +1487,8 @@ struct PyMethodDef Part_methods[] = { "these must have the same number of edges."}, {"makeTube" ,makeTube,METH_VARARGS, - "makeTube(edge,float) -- Create a tube."}, + "makeTube(edge,radius,[continuity,max degree,max segments]) -- Create a tube.\n" + "continuity is a string which must be 'C0','C1','C2','C3','CN','G1' or 'G1',"}, {"makeSweepSurface" ,makeSweepSurface,METH_VARARGS, "makeSweepSurface(edge(path),edge(profile),[float]) -- Create a profile along a path."}, diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index f78bc5026..22ccd16ad 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -32,7 +32,9 @@ # include # include # include +# include # include +# include # include # include # include @@ -1343,7 +1345,8 @@ TopoDS_Shape TopoShape::makePipeShell(const TopTools_ListOfShape& profiles, return mkPipeShell.Shape(); } -TopoDS_Shape TopoShape::makeTube(double radius, double tol) const +#if 0 +TopoDS_Shape TopoShape::makeTube() const { // http://opencascade.blogspot.com/2009/11/surface-modeling-part3.html if (this->_Shape.IsNull()) @@ -1378,43 +1381,54 @@ TopoDS_Shape TopoShape::makeTube(double radius, double tol) const ); return mkBuilder.Face(); } - -// for testing -static Handle(Law_Function) CreateBsFunction (const Standard_Real theFirst, const Standard_Real theLast) +#else +static Handle(Law_Function) CreateBsFunction (const Standard_Real theFirst, const Standard_Real theLast, const Standard_Real theRadius) { //Handle_Law_BSpline aBs; //Handle_Law_BSpFunc aFunc = new Law_BSpFunc (aBs, theFirst, theLast); Handle_Law_Linear aFunc = new Law_Linear(); - aFunc->Set(theFirst, 2.0, theLast, 3.0); + aFunc->Set(theFirst, theRadius, theLast, theRadius); return aFunc; } -// for testing -TopoDS_Shape TopoShape::makeTube() const +TopoDS_Shape TopoShape::makeTube(double radius, double tol, int cont, int maxdegree, int maxsegm) const { // http://opencascade.blogspot.com/2009/11/surface-modeling-part3.html - Standard_Real theTol = 0.001; + Standard_Real theTol = tol; Standard_Boolean theIsPolynomial = Standard_True; Standard_Boolean myIsElem = Standard_True; - GeomAbs_Shape theContinuity = GeomAbs_G1; - Standard_Integer theMaxDegree = 3; - Standard_Integer theMaxSegment = 1000; + GeomAbs_Shape theContinuity = GeomAbs_Shape(cont); + Standard_Integer theMaxDegree = maxdegree; + Standard_Integer theMaxSegment = maxsegm; if (this->_Shape.IsNull()) Standard_Failure::Raise("Cannot sweep along empty spine"); - if (this->_Shape.ShapeType() != TopAbs_EDGE) - Standard_Failure::Raise("Spine shape is not an edge"); - const TopoDS_Edge& path_edge = TopoDS::Edge(this->_Shape); - BRepAdaptor_Curve path_adapt(path_edge); + Handle(Adaptor3d_HCurve) myPath; + if (this->_Shape.ShapeType() == TopAbs_EDGE) { + const TopoDS_Edge& path_edge = TopoDS::Edge(this->_Shape); + BRepAdaptor_Curve path_adapt(path_edge); + myPath = new BRepAdaptor_HCurve(path_adapt); + theContinuity = GeomAbs_C0; + } + //else if (this->_Shape.ShapeType() == TopAbs_WIRE) { + // const TopoDS_Wire& path_wire = TopoDS::Wire(this->_Shape); + // BRepAdaptor_CompCurve path_adapt(path_wire); + // myPath = new BRepAdaptor_HCompCurve(path_adapt); + //} + //else { + // Standard_Failure::Raise("Spine shape is neither an edge nor a wire"); + //} + else { + Standard_Failure::Raise("Spine shape is not an edge"); + } //circular profile - Handle(Geom_Circle) aCirc = new Geom_Circle (gp::XOY(), 1.0); + Handle(Geom_Circle) aCirc = new Geom_Circle (gp::XOY(), radius); aCirc->Rotate (gp::OZ(), Standard_PI/2.); //perpendicular section - Handle(BRepAdaptor_HCurve) myPath = new BRepAdaptor_HCurve(path_adapt); - Handle(Law_Function) myEvol = ::CreateBsFunction (myPath->FirstParameter(), myPath->LastParameter()); + Handle(Law_Function) myEvol = ::CreateBsFunction (myPath->FirstParameter(), myPath->LastParameter(), radius); Handle(GeomFill_SectionLaw) aSec = new GeomFill_EvolvedSection(aCirc, myEvol); Handle(GeomFill_LocationLaw) aLoc = new GeomFill_CurveAndTrihedron(new GeomFill_CorrectedFrenet); aLoc->SetCurve (myPath); @@ -1438,6 +1452,7 @@ TopoDS_Shape TopoShape::makeTube() const return TopoDS_Shape(); } +#endif TopoDS_Shape TopoShape::makeSweep(const TopoDS_Shape& profile, double tol, int fillMode) const { diff --git a/src/Mod/Part/App/TopoShape.h b/src/Mod/Part/App/TopoShape.h index 0cf1087f9..1de76b1ca 100644 --- a/src/Mod/Part/App/TopoShape.h +++ b/src/Mod/Part/App/TopoShape.h @@ -158,8 +158,7 @@ public: TopoDS_Shape makeThickSolid(const TopTools_ListOfShape& remFace, Standard_Real offset, Standard_Real tolerance) const; TopoDS_Shape makeSweep(const TopoDS_Shape& profile, double, int) const; - TopoDS_Shape makeTube(double radius, double tol) const; - TopoDS_Shape makeTube() const; + 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 makeLoft(const TopTools_ListOfShape& profiles, Standard_Boolean isSolid,