diff --git a/src/Mod/Part/App/TopoShapeEdgePy.xml b/src/Mod/Part/App/TopoShapeEdgePy.xml index 873b3fb72..40def1030 100644 --- a/src/Mod/Part/App/TopoShapeEdgePy.xml +++ b/src/Mod/Part/App/TopoShapeEdgePy.xml @@ -24,7 +24,12 @@ Vector = valueAt(pos) - Get the point at the given parameter [0|Length] if defined - + + + Float = parameterAt(Vertex) - Get the parameter at the given vertex if lying on the edge + + + Vector = normalAt(pos) - Get the normal vector at the given parameter [0|Length] if defined @@ -64,6 +69,11 @@ Discretizes the edge using a given deflection or number of points and returns a list of points + + + Splits the edge at the given parameter values and builds a wire out of it + + Set or get the tolerance of the vertex diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index ec5bc0905..329c6bd6c 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -23,10 +23,13 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include # include # include # include +# include +# include # include # include # include @@ -47,6 +50,7 @@ # include # include # include +# include # include #endif @@ -55,12 +59,14 @@ #include #include +#include #include #include #include "TopoShape.h" #include "TopoShapeFacePy.h" #include "TopoShapeVertexPy.h" +#include "TopoShapeWirePy.h" #include "TopoShapeEdgePy.h" #include "TopoShapeEdgePy.cpp" @@ -185,6 +191,35 @@ PyObject* TopoShapeEdgePy::valueAt(PyObject *args) return new Base::VectorPy(new Base::Vector3d(V.X(),V.Y(),V.Z())); } +PyObject* TopoShapeEdgePy::parameterAt(PyObject *args) +{ + PyObject* pnt; + PyObject* face=0; + if (!PyArg_ParseTuple(args, "O!|O!",&TopoShapeVertexPy::Type,&pnt, + &TopoShapeFacePy::Type,&face)) + return 0; + + try { + const TopoDS_Shape& v = static_cast(pnt)->getTopoShapePtr()->_Shape; + const TopoDS_Edge& e = TopoDS::Edge(getTopoShapePtr()->_Shape); + + if (face) { + const TopoDS_Shape& f = static_cast(face)->getTopoShapePtr()->_Shape; + Standard_Real par = BRep_Tool::Parameter(TopoDS::Vertex(v), e, TopoDS::Face(f)); + return PyFloat_FromDouble(par); + } + else { + Standard_Real par = BRep_Tool::Parameter(TopoDS::Vertex(v), e); + return PyFloat_FromDouble(par); + } + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } +} + PyObject* TopoShapeEdgePy::tangentAt(PyObject *args) { double u; @@ -443,6 +478,74 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args) return 0; } +PyObject* TopoShapeEdgePy::split(PyObject *args) +{ + PyObject* float_or_list; + if (!PyArg_ParseTuple(args, "O", &float_or_list)) + return 0; + + try { + BRepAdaptor_Curve adapt(TopoDS::Edge(getTopoShapePtr()->_Shape)); + Standard_Real f = adapt.FirstParameter(); + Standard_Real l = adapt.LastParameter(); + + std::vector par; + par.push_back(f); + if (PyFloat_Check(float_or_list)) { + double val = PyFloat_AsDouble(float_or_list); + if (val == f || val == l) { + PyErr_SetString(PyExc_ValueError, "Cannot split edge at start or end point"); + return 0; + } + else if (val < f || val > l) { + PyErr_SetString(PyExc_ValueError, "Value out of parameter range"); + return 0; + } + par.push_back(val); + } + else if (PyList_Check(float_or_list)) { + Py::List list(float_or_list); + for (Py::List::iterator it = list.begin(); it != list.end(); ++it) { + double val = (double)Py::Float(*it); + if (val == f || val == l) { + PyErr_SetString(PyExc_ValueError, "Cannot split edge at start or end point"); + return 0; + } + else if (val < f || val > l) { + PyErr_SetString(PyExc_ValueError, "Value out of parameter range"); + return 0; + } + par.push_back(val); + } + } + else { + PyErr_SetString(PyExc_TypeError, "Either float or list of floats expected"); + return 0; + } + + par.push_back(l); + std::sort(par.begin(), par.end()); + + BRepBuilderAPI_MakeWire mkWire; + Handle_Geom_Curve c = adapt.Curve().Curve(); + std::vector::iterator end = par.end() - 1; + for (std::vector::iterator it = par.begin(); it != end; ++it) { + BRepBuilderAPI_MakeEdge mkBuilder(c, it[0], it[1]); + mkWire.Add(mkBuilder.Edge()); + } + + return new TopoShapeWirePy(new TopoShape(mkWire.Shape())); + } + catch (Standard_Failure) { + Handle_Standard_Failure e = Standard_Failure::Caught(); + PyErr_SetString(PyExc_Exception, e->GetMessageString()); + return 0; + } + + PyErr_SetString(PyExc_Exception, "Geometry is not a curve"); + return 0; +} + PyObject* TopoShapeEdgePy::setTolerance(PyObject *args) { double tol;