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-21 06:57:44 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-21 06:57:44 +0400
commit39f8c6e189c89f4097f5d979612cb71bd8773030 (patch)
treed9a4ace57a1dc75f9e968ac0c1cae92ef995c145 /source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp
parent92436c94d3adbbfc285bd7b3041db36e66dae5d5 (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_ViewEdgeIterator.cpp')
-rw-r--r--source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp
index 066d223f6e9..e8678fde48c 100644
--- a/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp
+++ b/source/blender/freestyle/intern/python/Iterator/BPy_ViewEdgeIterator.cpp
@@ -33,40 +33,43 @@ PyDoc_STRVAR(ViewEdgeIterator_doc,
" ViewVertex of begin.\n"
" :type orientation: bool\n"
"\n"
-".. method:: __init__(it)\n"
+".. method:: __init__(brother)\n"
"\n"
" Copy constructor.\n"
"\n"
-" :arg it: A ViewEdgeIterator object.\n"
-" :type it: :class:`ViewEdgeIterator`");
+" :arg brother: A ViewEdgeIterator object.\n"
+" :type brother: :class:`ViewEdgeIterator`");
-static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args)
+static int check_begin(PyObject *obj, void *v)
{
- PyObject *obj1 = 0, *obj2 = 0;
+ if (obj != 0 && obj != Py_None && !BPy_ViewEdge_Check(obj))
+ return 0;
+ *((PyObject **)v) = obj;
+ return 1;
+}
- if (!PyArg_ParseTuple(args, "O|O", &obj1, &obj2))
- return -1;
+static int ViewEdgeIterator_init(BPy_ViewEdgeIterator *self, PyObject *args, PyObject *kwds)
+{
+ static const char *kwlist_1[] = {"brother", NULL};
+ static const char *kwlist_2[] = {"begin", "orientation", NULL};
+ PyObject *obj1 = 0, *obj2 = 0;
- if (BPy_ViewEdgeIterator_Check(obj1)) {
+ if (PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_1, &ViewEdgeIterator_Type, &obj1)) {
self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(*(((BPy_ViewEdgeIterator *)obj1)->ve_it));
-
- } else {
- ViewEdge *begin;
- if (obj1 == Py_None)
- begin = NULL;
- else if (BPy_ViewEdge_Check(obj1))
- begin = ((BPy_ViewEdge *)obj1)->ve;
- else {
- PyErr_SetString(PyExc_TypeError, "1st argument must be either a ViewEdge object or None");
- return -1;
- }
- bool orientation = (obj2) ? bool_from_PyBool(obj2) : true;
-
+ }
+ else if (PyErr_Clear(), (obj1 = obj2 = 0),
+ PyArg_ParseTupleAndKeywords(args, kwds, "|O&O!", (char **)kwlist_2,
+ check_begin, &obj1, &PyBool_Type, &obj2))
+ {
+ ViewEdge *begin = (!obj1 || obj1 == Py_None) ? NULL : ((BPy_ViewEdge *)obj1)->ve;
+ bool orientation = (!obj2) ? true : bool_from_PyBool(obj2);
self->ve_it = new ViewEdgeInternal::ViewEdgeIterator(begin, orientation);
}
-
+ else {
+ PyErr_SetString(PyExc_TypeError, "invalid argument(s)");
+ return -1;
+ }
self->py_it.it = self->ve_it;
-
return 0;
}