From e4aa0049c1e466f96453858a5ac6e8a9ba1ac1b9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 14 Aug 2014 11:16:54 +0200 Subject: [PATCH] + support First and Last keywords in discretize --- src/Mod/Part/App/GeometryCurvePy.xml | 22 +++++++++++++++-- src/Mod/Part/App/GeometryCurvePyImp.cpp | 33 ++++++++++++++----------- src/Mod/Part/App/TopoShapeEdgePy.xml | 22 +++++++++++++++-- src/Mod/Part/App/TopoShapeEdgePyImp.cpp | 33 ++++++++++++++----------- src/Mod/Part/App/TopoShapeWirePy.xml | 22 +++++++++++++++-- src/Mod/Part/App/TopoShapeWirePyImp.cpp | 33 ++++++++++++++----------- 6 files changed, 114 insertions(+), 51 deletions(-) diff --git a/src/Mod/Part/App/GeometryCurvePy.xml b/src/Mod/Part/App/GeometryCurvePy.xml index 32d481af50..14470aed97 100644 --- a/src/Mod/Part/App/GeometryCurvePy.xml +++ b/src/Mod/Part/App/GeometryCurvePy.xml @@ -28,12 +28,30 @@ The function accepts keywords as argument: discretize(Number=n) => gives a list of 'n' equidistant points discretize(Distance=d) => gives a list of equidistant points with distance 'd' discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the curve -discretize(Angular=a,Curvatre=c) => gives a list of points with an angular deflection of 'a' - and a curvature deflection of 'c' +discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a' + and a curvature deflection of 'c'. Optionally a minimum number of points + can be set which by default is set to 2. + +Optionally you can set the keywords 'First' and 'Last' to define a sub-range of the parameter range +of the curve. If no keyword is given then it depends on whether the argument is an int or float. If it's an int then the behaviour is as if using the keyword 'Number', if it's float then the behaviour is as if using the keyword 'Distance'. + +Example: + +import Part +c=Part.Circle() +c.Radius=5 +p=c.discretize(Number=50,First=3.14) +s=Part.Compound([Part.Vertex(i) for i in p]) +Part.show(s) + + +p=c.discretize(Angular=0.09,Curvature=0.01,Last=3.14,Minimum=100) +s=Part.Compound([Part.Vertex(i) for i in p]) +Part.show(s) diff --git a/src/Mod/Part/App/GeometryCurvePyImp.cpp b/src/Mod/Part/App/GeometryCurvePyImp.cpp index e60b9e3deb..3b96aebd6e 100644 --- a/src/Mod/Part/App/GeometryCurvePyImp.cpp +++ b/src/Mod/Part/App/GeometryCurvePyImp.cpp @@ -129,6 +129,8 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) bool uniformAbscissaDistance = false; int numPoints = -1; double distance = -1; + double first = adapt.FirstParameter(); + double last = adapt.LastParameter(); // use no kwds PyObject* dist_or_num; @@ -148,16 +150,16 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) } else { // use Number kwds - static char* kwds_numPoints[] = {"Number",NULL}; + static char* kwds_numPoints[] = {"Number","First","Last",NULL}; PyErr_Clear(); - if (PyArg_ParseTupleAndKeywords(args, kwds, "i", kwds_numPoints, &numPoints)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) { uniformAbscissaPoints = true; } else { // use Abscissa kwds - static char* kwds_Distance[] = {"Distance",NULL}; + static char* kwds_Distance[] = {"Distance","First","Last",NULL}; PyErr_Clear(); - if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Distance, &distance)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) { uniformAbscissaDistance = true; } } @@ -166,9 +168,9 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) if (uniformAbscissaPoints || uniformAbscissaDistance) { GCPnts_UniformAbscissa discretizer; if (uniformAbscissaPoints) - discretizer.Initialize (adapt, numPoints); + discretizer.Initialize (adapt, numPoints, first, last); else - discretizer.Initialize (adapt, distance); + discretizer.Initialize (adapt, distance, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; @@ -181,17 +183,17 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of wire failed"); + PyErr_SetString(PyExc_Exception, "Discretization of curve failed"); return 0; } } // use Deflection kwds - static char* kwds_Deflection[] = {"Deflection",NULL}; + static char* kwds_Deflection[] = {"Deflection","First","Last",NULL}; PyErr_Clear(); double deflection; - if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Deflection, &deflection)) { - GCPnts_UniformDeflection discretizer(adapt, deflection); + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) { + GCPnts_UniformDeflection discretizer(adapt, deflection, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); @@ -203,18 +205,19 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of wire failed"); + PyErr_SetString(PyExc_Exception, "Discretization of curve failed"); return 0; } } // use TangentialDeflection kwds - static char* kwds_TangentialDeflection[] = {"Angular","Curvature",NULL}; + static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL}; PyErr_Clear(); double angular; double curvature; - if (PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwds_TangentialDeflection, &angular, &curvature)) { - GCPnts_TangentialDeflection discretizer(adapt, angular, curvature); + int minimumPoints = 2; + if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) { + GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints); if (discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); @@ -226,7 +229,7 @@ PyObject* GeometryCurvePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of wire failed"); + PyErr_SetString(PyExc_Exception, "Discretization of curve failed"); return 0; } } diff --git a/src/Mod/Part/App/TopoShapeEdgePy.xml b/src/Mod/Part/App/TopoShapeEdgePy.xml index 68720421a3..5e98c29c63 100644 --- a/src/Mod/Part/App/TopoShapeEdgePy.xml +++ b/src/Mod/Part/App/TopoShapeEdgePy.xml @@ -76,12 +76,30 @@ The function accepts keywords as argument: discretize(Number=n) => gives a list of 'n' equidistant points discretize(Distance=d) => gives a list of equidistant points with distance 'd' discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the edge -discretize(Angular=a,Curvatre=c) => gives a list of points with an angular deflection of 'a' - and a curvature deflection of 'c' +discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a' + and a curvature deflection of 'c'. Optionally a minimum number of points + can be set which by default is set to 2. + +Optionally you can set the keywords 'First' and 'Last' to define a sub-range of the parameter range +of the edge. If no keyword is given then it depends on whether the argument is an int or float. If it's an int then the behaviour is as if using the keyword 'Number', if it's float then the behaviour is as if using the keyword 'Distance'. + +Example: + +import Part +c=Part.Circle() +c.Radius=5 +p=c.discretize(Number=50,First=3.14) +s=Part.Compound([Part.Vertex(i) for i in p]) +Part.show(s) + + +p=c.discretize(Angular=0.09,Curvature=0.01,Last=3.14,Minimum=100) +s=Part.Compound([Part.Vertex(i) for i in p]) +Part.show(s) diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index 6421db4c88..75afedeaa9 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -397,6 +397,8 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) bool uniformAbscissaDistance = false; int numPoints = -1; double distance = -1; + double first = adapt.FirstParameter(); + double last = adapt.LastParameter(); // use no kwds PyObject* dist_or_num; @@ -416,16 +418,16 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) } else { // use Number kwds - static char* kwds_numPoints[] = {"Number",NULL}; + static char* kwds_numPoints[] = {"Number","First","Last",NULL}; PyErr_Clear(); - if (PyArg_ParseTupleAndKeywords(args, kwds, "i", kwds_numPoints, &numPoints)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) { uniformAbscissaPoints = true; } else { // use Abscissa kwds - static char* kwds_Distance[] = {"Distance",NULL}; + static char* kwds_Distance[] = {"Distance","First","Last",NULL}; PyErr_Clear(); - if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Distance, &distance)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) { uniformAbscissaDistance = true; } } @@ -434,9 +436,9 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) if (uniformAbscissaPoints || uniformAbscissaDistance) { GCPnts_UniformAbscissa discretizer; if (uniformAbscissaPoints) - discretizer.Initialize (adapt, numPoints); + discretizer.Initialize (adapt, numPoints, first, last); else - discretizer.Initialize (adapt, distance); + discretizer.Initialize (adapt, distance, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; @@ -449,17 +451,17 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of curve failed"); + PyErr_SetString(PyExc_Exception, "Discretization of edge failed"); return 0; } } // use Deflection kwds - static char* kwds_Deflection[] = {"Deflection",NULL}; + static char* kwds_Deflection[] = {"Deflection","First","Last",NULL}; PyErr_Clear(); double deflection; - if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Deflection, &deflection)) { - GCPnts_UniformDeflection discretizer(adapt, deflection); + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) { + GCPnts_UniformDeflection discretizer(adapt, deflection, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); @@ -471,18 +473,19 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of curve failed"); + PyErr_SetString(PyExc_Exception, "Discretization of edge failed"); return 0; } } // use TangentialDeflection kwds - static char* kwds_TangentialDeflection[] = {"Angular","Curvature",NULL}; + static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL}; PyErr_Clear(); double angular; double curvature; - if (PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwds_TangentialDeflection, &angular, &curvature)) { - GCPnts_TangentialDeflection discretizer(adapt, angular, curvature); + int minimumPoints = 2; + if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) { + GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints); if (discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); @@ -494,7 +497,7 @@ PyObject* TopoShapeEdgePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of curve failed"); + PyErr_SetString(PyExc_Exception, "Discretization of edge failed"); return 0; } } diff --git a/src/Mod/Part/App/TopoShapeWirePy.xml b/src/Mod/Part/App/TopoShapeWirePy.xml index f797ec4e8a..b7695da708 100644 --- a/src/Mod/Part/App/TopoShapeWirePy.xml +++ b/src/Mod/Part/App/TopoShapeWirePy.xml @@ -58,12 +58,30 @@ The function accepts keywords as argument: discretize(Number=n) => gives a list of 'n' equidistant points discretize(Distance=d) => gives a list of equidistant points with distance 'd' discretize(Deflection=d) => gives a list of points with a maximum deflection 'd' to the wire -discretize(Angular=a,Curvatre=c) => gives a list of points with an angular deflection of 'a' - and a curvature deflection of 'c' +discretize(Angular=a,Curvature=c,[Minimum=m]) => gives a list of points with an angular deflection of 'a' + and a curvature deflection of 'c'. Optionally a minimum number of points + can be set which by default is set to 2. + +Optionally you can set the keywords 'First' and 'Last' to define a sub-range of the parameter range +of the wire. If no keyword is given then it depends on whether the argument is an int or float. If it's an int then the behaviour is as if using the keyword 'Number', if it's float then the behaviour is as if using the keyword 'Distance'. + +Example: + +import Part +c=Part.Circle() +c.Radius=5 +p=c.discretize(Number=50,First=3.14) +s=Part.Compound([Part.Vertex(i) for i in p]) +Part.show(s) + + +p=c.discretize(Angular=0.09,Curvature=0.01,Last=3.14,Minimum=100) +s=Part.Compound([Part.Vertex(i) for i in p]) +Part.show(s) diff --git a/src/Mod/Part/App/TopoShapeWirePyImp.cpp b/src/Mod/Part/App/TopoShapeWirePyImp.cpp index 6dad3bc7fd..7a906e3f05 100644 --- a/src/Mod/Part/App/TopoShapeWirePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeWirePyImp.cpp @@ -338,6 +338,8 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) bool uniformAbscissaDistance = false; int numPoints = -1; double distance = -1; + double first = adapt.FirstParameter(); + double last = adapt.LastParameter(); // use no kwds PyObject* dist_or_num; @@ -357,16 +359,16 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) } else { // use Number kwds - static char* kwds_numPoints[] = {"Number",NULL}; + static char* kwds_numPoints[] = {"Number","First","Last",NULL}; PyErr_Clear(); - if (PyArg_ParseTupleAndKeywords(args, kwds, "i", kwds_numPoints, &numPoints)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "i|dd", kwds_numPoints, &numPoints, &first, &last)) { uniformAbscissaPoints = true; } else { // use Abscissa kwds - static char* kwds_Distance[] = {"Distance",NULL}; + static char* kwds_Distance[] = {"Distance","First","Last",NULL}; PyErr_Clear(); - if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Distance, &distance)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Distance, &distance, &first, &last)) { uniformAbscissaDistance = true; } } @@ -375,9 +377,9 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) if (uniformAbscissaPoints || uniformAbscissaDistance) { GCPnts_UniformAbscissa discretizer; if (uniformAbscissaPoints) - discretizer.Initialize (adapt, numPoints); + discretizer.Initialize (adapt, numPoints, first, last); else - discretizer.Initialize (adapt, distance); + discretizer.Initialize (adapt, distance, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; @@ -390,17 +392,17 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of wire failed"); + PyErr_SetString(PyExc_Exception, "Discretization of wire failed"); return 0; } } // use Deflection kwds - static char* kwds_Deflection[] = {"Deflection",NULL}; + static char* kwds_Deflection[] = {"Deflection","First","Last",NULL}; PyErr_Clear(); double deflection; - if (PyArg_ParseTupleAndKeywords(args, kwds, "d", kwds_Deflection, &deflection)) { - GCPnts_UniformDeflection discretizer(adapt, deflection); + if (PyArg_ParseTupleAndKeywords(args, kwds, "d|dd", kwds_Deflection, &deflection, &first, &last)) { + GCPnts_UniformDeflection discretizer(adapt, deflection, first, last); if (discretizer.IsDone () && discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); @@ -412,18 +414,19 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of wire failed"); + PyErr_SetString(PyExc_Exception, "Discretization of wire failed"); return 0; } } // use TangentialDeflection kwds - static char* kwds_TangentialDeflection[] = {"Angular","Curvature",NULL}; + static char* kwds_TangentialDeflection[] = {"Angular","Curvature","First","Last","Minimum",NULL}; PyErr_Clear(); double angular; double curvature; - if (PyArg_ParseTupleAndKeywords(args, kwds, "dd", kwds_TangentialDeflection, &angular, &curvature)) { - GCPnts_TangentialDeflection discretizer(adapt, angular, curvature); + int minimumPoints = 2; + if (PyArg_ParseTupleAndKeywords(args, kwds, "dd|ddi", kwds_TangentialDeflection, &angular, &curvature, &first, &last, &minimumPoints)) { + GCPnts_TangentialDeflection discretizer(adapt, first, last, angular, curvature, minimumPoints); if (discretizer.NbPoints () > 0) { Py::List points; int nbPoints = discretizer.NbPoints (); @@ -435,7 +438,7 @@ PyObject* TopoShapeWirePy::discretize(PyObject *args, PyObject *kwds) return Py::new_reference_to(points); } else { - PyErr_SetString(PyExc_Exception, "Descretization of wire failed"); + PyErr_SetString(PyExc_Exception, "Discretization of wire failed"); return 0; } }