diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-21 06:57:44 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-21 06:57:44 +0400 |
commit | 39f8c6e189c89f4097f5d979612cb71bd8773030 (patch) | |
tree | d9a4ace57a1dc75f9e968ac0c1cae92ef995c145 /source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp | |
parent | 92436c94d3adbbfc285bd7b3041db36e66dae5d5 (diff) |
Freestyle Python API improvements - part 5.
Handling of keyword arguments in Python wrapper class constructors was revised.
This revision is mainly focused on Interface0D, Interface1D, Iterator, and
their subclasses, as well as a few additional view map component classes.
Implementation notes: Because of the extensive use of constructor overloading
in the underlying C++ classes, the corresponding Python wrappers try to parse
arguments through multiple calls of PyArg_ParseTupleAndKeywords() if needed.
The downside of this implementation is that most argument errors result in the
same error message ("invalid argument(s)") without indicating what is wrong.
For now this issue is left for future work.
* Now the instantiation of ViewVertex is prohibited since the underlying
C++ class is an abstract class.
* Removed the .cast_to_interface0diterator() method from CurvePointIterator
and StrokeVertexIterator. Instead the constructor of Interface0DIterator now
accepts the instances of these two iterator classes to construct a nested
Interface0DIterator instance that can be passed to Function0D functor objects.
Specifically, an iterator 'it' is passed to a functor 'func' as follows:
func(Interface0DIterator(it))
instead of:
func(it.cast_to_interface0diterator())
* Boolean arguments of class constructors only accept values of boolean type.
Input values of other types are considered as error.
* Additional code clean-up was made.
Diffstat (limited to 'source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp index 5323fe1c146..1c727582b7b 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_ChainingIterator.cpp @@ -25,17 +25,17 @@ PyDoc_STRVAR(ChainingIterator_doc, "they will be included in the adjacency iterator (i.e, the adjacent\n" "iterator will only stop on \"valid\" edges).\n" "\n" -".. method:: __init__(iRestrictToSelection=True, iRestrictToUnvisited=True, begin=None, orientation=True)\n" +".. method:: __init__(restrict_to_selection=True, restrict_to_unvisited=True, begin=None, orientation=True)\n" "\n" " Builds a Chaining Iterator from the first ViewEdge used for\n" " iteration and its orientation.\n" "\n" -" :arg iRestrictToSelection: Indicates whether to force the chaining\n" +" :arg restrict_to_selection: Indicates whether to force the chaining\n" " to stay within the set of selected ViewEdges or not.\n" -" :type iRestrictToSelection: bool\n" -" :arg iRestrictToUnvisited: Indicates whether a ViewEdge that has\n" +" :type restrict_to_selection: bool\n" +" :arg restrict_to_unvisited: Indicates whether a ViewEdge that has\n" " already been chained must be ignored ot not.\n" -" :type iRestrictToUnvisited: bool\n" +" :type restrict_to_unvisited: bool\n" " :arg begin: The ViewEdge from which to start the chain.\n" " :type begin: :class:`ViewEdge` or None\n" " :arg orientation: The direction to follow to explore the graph. If\n" @@ -49,33 +49,38 @@ PyDoc_STRVAR(ChainingIterator_doc, " :arg brother: \n" " :type brother: ChainingIterator"); -static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args) +static int check_begin(PyObject *obj, void *v) { - PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; + if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj)) + return 0; + *((PyObject **)v) = obj; + return 1; +} - if (!PyArg_ParseTuple(args, "|OOOO", &obj1, &obj2, &obj3, &obj4)) - return -1; +static int ChainingIterator___init__(BPy_ChainingIterator *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"restrict_to_selection", "restrict_to_unvisited", "begin", "orientation", NULL}; + PyObject *obj1 = 0, *obj2 = 0, *obj3 = 0, *obj4 = 0; - if (obj1 && BPy_ChainingIterator_Check(obj1)) { + if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ChainingIterator_Type, &obj1)) { self->c_it = new ChainingIterator(*(((BPy_ChainingIterator *)obj1)->c_it)); - - } else { - bool restrictToSelection = (obj1) ? bool_from_PyBool(obj1) : true; - bool restrictToUnvisited = (obj2) ? bool_from_PyBool(obj2) : true; - ViewEdge *begin; - if (!obj3 || obj3 == Py_None) - begin = NULL; - else if (BPy_ViewEdge_Check(obj3)) - begin = ((BPy_ViewEdge *)obj3)->ve; - else { - PyErr_SetString(PyExc_TypeError, "3rd argument must be either a ViewEdge object or None"); - return -1; - } - bool orientation = (obj4) ? bool_from_PyBool(obj4) : true; - - self->c_it = new ChainingIterator(restrictToSelection, restrictToUnvisited, begin, orientation); } - + else if (PyErr_Clear(), (obj1 = obj2 = obj3 = obj4 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "|O!O!O&O!", (char **)kwlist_2, + &PyBool_Type, &obj1, &PyBool_Type, &obj2, check_begin, &obj3, + &PyBool_Type, &obj4)) + { + bool restrict_to_selection = (!obj1) ? true : bool_from_PyBool(obj1); + bool restrict_to_unvisited = (!obj2) ? true : bool_from_PyBool(obj2); + ViewEdge *begin = (!obj3 || obj3 == Py_None) ? NULL : ((BPy_ViewEdge *)obj3)->ve; + bool orientation = (!obj4) ? true : bool_from_PyBool(obj4); + self->c_it = new ChainingIterator(restrict_to_selection, restrict_to_unvisited, begin, orientation); + } + else { + PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); + return -1; + } self->py_ve_it.ve_it = self->c_it; self->py_ve_it.py_it.it = self->c_it; |