Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-24 06:39:38 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-24 06:39:38 +0400
commit3df023ae82eef0ea105dc61c9730af87b59a07d1 (patch)
tree2d2a4e753c1129fc91f360f0457d30859cd38737 /source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
parentd38a335d47f1632000db5172877499ff0184d114 (diff)
Freestyle Python API improvements - part 8.
* Proper handling of keyword arguments was implemented in Operators and ContextFunctions, as well as in methods of Interface0D, Interface1D, Iterator, their subclasses, Noise and IntegrationType. * Operators' methods and functions in the ContextFunctions module were renamed from CamelCase to lower cases + underscores. Style modules were updated accordingly. * Additional code clean-up was also made.
Diffstat (limited to 'source/blender/freestyle/intern/python/BPy_IntegrationType.cpp')
-rw-r--r--source/blender/freestyle/intern/python/BPy_IntegrationType.cpp58
1 files changed, 20 insertions, 38 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
index b56a5f96894..8b447129eca 100644
--- a/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
+++ b/source/blender/freestyle/intern/python/BPy_IntegrationType.cpp
@@ -46,14 +46,14 @@ extern "C" {
//------------------------ MODULE FUNCTIONS ----------------------------------
PyDoc_STRVAR(Integrator_integrate_doc,
-".. function:: integrate(fun, it, it_end, integration_type)\n"
+".. function:: integrate(func, it, it_end, integration_type)\n"
"\n"
" Returns a single value from a set of values evaluated at each 0D\n"
" element of this 1D element.\n"
"\n"
-" :arg fun: The UnaryFunction0D used to compute a value at each\n"
+" :arg func: The UnaryFunction0D used to compute a value at each\n"
" Interface0D.\n"
-" :type fun: :class:`UnaryFunction0D`\n"
+" :type func: :class:`UnaryFunction0D`\n"
" :arg it: The Interface0DIterator used to iterate over the 0D\n"
" elements of this 1D element. The integration will occur over\n"
" the 0D elements starting from the one pointed by it.\n"
@@ -65,41 +65,23 @@ PyDoc_STRVAR(Integrator_integrate_doc,
" single value from a set of values.\n"
" :type integration_type: :class:`IntegrationType`\n"
" :return: The single value obtained for the 1D element. The return\n"
-" value type is float if fun is of the :class:`UnaryFunction0DDouble`\n"
-" or :class:`UnaryFunction0DFloat` type, and int if fun is of the\n"
+" value type is float if func is of the :class:`UnaryFunction0DDouble`\n"
+" or :class:`UnaryFunction0DFloat` type, and int if func is of the\n"
" :class:`UnaryFunction0DUnsigned` type.\n"
" :rtype: int or float");
-static PyObject * Integrator_integrate(PyObject *self, PyObject *args)
+static PyObject * Integrator_integrate(PyObject *self, PyObject *args, PyObject *kwds)
{
+ static const char *kwlist[] = {"func", "it", "it_end", "integration_type", NULL};
PyObject *obj1, *obj4 = 0;
BPy_Interface0DIterator *obj2, *obj3;
-#if 1
- if (!PyArg_ParseTuple(args, "O!O!O!|O!", &UnaryFunction0D_Type, &obj1,
- &Interface0DIterator_Type, &obj2, &Interface0DIterator_Type, &obj3,
- &IntegrationType_Type, &obj4))
- return NULL;
-#else
- if (!PyArg_ParseTuple(args, "OOO|O", &obj1, &obj2, &obj3, &obj4))
- return NULL;
- if (!BPy_UnaryFunction0D_Check(obj1)) {
- PyErr_SetString(PyExc_TypeError, "argument 1 must be a UnaryFunction0D object");
- return NULL;
- }
- if (!BPy_Interface0DIterator_Check(obj2)) {
- PyErr_SetString(PyExc_TypeError, "argument 2 must be a Interface0DIterator object");
- return NULL;
- }
- if (!BPy_Interface0DIterator_Check(obj3)) {
- PyErr_SetString(PyExc_TypeError, "argument 3 must be a Interface0DIterator object");
- return NULL;
- }
- if (obj4 && !BPy_IntegrationType_Check(obj4)) {
- PyErr_SetString(PyExc_TypeError, "argument 4 must be a IntegrationType object");
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!O!O!|O!", (char **)kwlist,
+ &UnaryFunction0D_Type, &obj1, &Interface0DIterator_Type, &obj2,
+ &Interface0DIterator_Type, &obj3, &IntegrationType_Type, &obj4))
+ {
return NULL;
}
-#endif
Interface0DIterator it(*(obj2->if0D_it)), it_end(*(obj3->if0D_it));
IntegrationType t = (obj4) ? IntegrationType_from_BPy_IntegrationType(obj4) : MEAN;
@@ -108,20 +90,20 @@ static PyObject * Integrator_integrate(PyObject *self, PyObject *args)
UnaryFunction0D<double> *fun = ((BPy_UnaryFunction0DDouble *)obj1)->uf0D_double;
double res = integrate(*fun, it, it_end, t);
return PyFloat_FromDouble(res);
-
- } else if (BPy_UnaryFunction0DFloat_Check(obj1)) {
+ }
+ else if (BPy_UnaryFunction0DFloat_Check(obj1)) {
UnaryFunction0D<float> *fun = ((BPy_UnaryFunction0DFloat *)obj1)->uf0D_float;
float res = integrate(*fun, it, it_end, t);
return PyFloat_FromDouble(res);
-
- } else if (BPy_UnaryFunction0DUnsigned_Check(obj1)) {
+ }
+ else if (BPy_UnaryFunction0DUnsigned_Check(obj1)) {
UnaryFunction0D<unsigned int> *fun = ((BPy_UnaryFunction0DUnsigned *)obj1)->uf0D_unsigned;
unsigned int res = integrate(*fun, it, it_end, t);
return PyLong_FromLong(res);
-
- } else {
- string msg("unsupported function type: " + string(obj1->ob_type->tp_name));
- PyErr_SetString(PyExc_TypeError, msg.c_str());
+ }
+ else {
+ string class_name(Py_TYPE(obj1)->tp_name);
+ PyErr_SetString(PyExc_TypeError, ("unsupported function type: " + class_name).c_str());
return NULL;
}
}
@@ -133,7 +115,7 @@ PyDoc_STRVAR(module_docstring, "The Blender Freestyle.Integrator submodule\n\n")
/*-----------------------Integrator module functions definitions---------------------------*/
static PyMethodDef module_functions[] = {
- {"integrate", (PyCFunction) Integrator_integrate, METH_VARARGS, Integrator_integrate_doc},
+ {"integrate", (PyCFunction) Integrator_integrate, METH_VARARGS | METH_KEYWORDS, Integrator_integrate_doc},
{NULL, NULL, 0, NULL}
};