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/Interface0D/ViewVertex | |
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/Interface0D/ViewVertex')
-rw-r--r-- | source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp | 33 | ||||
-rw-r--r-- | source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp | 15 |
2 files changed, 16 insertions, 32 deletions
diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp index a0e0717ef37..b2b2f8bda28 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp @@ -21,42 +21,29 @@ PyDoc_STRVAR(NonTVertex_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(svertex)\n" "\n" -" Copy constructor.\n" +" Build a NonTVertex from a SVertex.\n" "\n" -" :arg iBrother: A NonTVertex object.\n" -" :type iBrother: :class:`NonTVertex`\n" -"\n" -".. method:: __init__(iSVertex)\n" -"\n" -" Builds a NonTVertex from a SVertex.\n" -"\n" -" :arg iSVertex: An SVertex object.\n" -" :type iSVertex: :class:`SVertex`"); +" :arg svertex: An SVertex object.\n" +" :type svertex: :class:`SVertex`"); + +/* Note: No copy constructor in Python because the C++ copy constructor is 'protected'. */ static int NonTVertex_init(BPy_NonTVertex *self, PyObject *args, PyObject *kwds) { + static const char *kwlist[] = {"svertex", NULL}; PyObject *obj = 0; - if (!PyArg_ParseTuple(args, "|O!", &SVertex_Type, &obj)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist, &SVertex_Type, &obj)) return -1; - - if (!obj) { + if (!obj) self->ntv = new NonTVertex(); - - } else if(((BPy_SVertex *)obj)->sv) { + else self->ntv = new NonTVertex(((BPy_SVertex *)obj)->sv); - - } else { - PyErr_SetString(PyExc_TypeError, "invalid argument"); - return -1; - } - self->py_vv.vv = self->ntv; self->py_vv.py_if0D.if0D = self->ntv; self->py_vv.py_if0D.borrowed = 0; - return 0; } diff --git a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp index 55c8b64d13c..e501bb7f713 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp @@ -25,18 +25,15 @@ PyDoc_STRVAR(TVertex_doc, "\n" ".. method:: __init__()\n" "\n" -" Default constructor.\n" -"\n" -".. method:: __init__(iBrother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg iBrother: A TVertex object.\n" -" :type iBrother: :class:`TVertex`"); +" Default constructor."); + +/* Note: No copy constructor in Python because the C++ copy constructor is 'protected'. */ static int TVertex_init(BPy_TVertex *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) + static const char *kwlist[] = {NULL}; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "", (char **)kwlist)) return -1; self->tv = new TVertex(); self->py_vv.vv = self->tv; |