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/BPy_SVertex.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/Interface0D/BPy_SVertex.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 0d0a772b4e5..f1ac241c66f 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -21,53 +21,52 @@ PyDoc_STRVAR(SVertex_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A SVertex object.\n" -" :type iBrother: :class:`SVertex`\n" +" :arg brother: A SVertex object.\n" +" :type brother: :class:`SVertex`\n" "\n" -".. method:: __init__(iPoint3D, id)\n" +".. method:: __init__(point_3d, id)\n" "\n" " Builds a SVertex from 3D coordinates and an Id.\n" "\n" -" :arg iPoint3D: A three-dimensional vector.\n" -" :type iPoint3D: :class:`mathutils.Vector`\n" +" :arg point_3d: A three-dimensional vector.\n" +" :type point_3d: :class:`mathutils.Vector`\n" " :arg id: An Id object.\n" " :type id: :class:`Id`"); -static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds) +static int convert_v3(PyObject *obj, void *v) { - PyObject *py_point = 0; - BPy_Id *py_id = 0; - - if (!PyArg_ParseTuple(args, "|OO!", &py_point, &Id_Type, &py_id)) - return -1; - - if (!py_point) { - self->sv = new SVertex(); - - } else if (!py_id && BPy_SVertex_Check(py_point)) { - self->sv = new SVertex( *(((BPy_SVertex *)py_point)->sv) ); + return float_array_from_PyObject(obj, (float *)v, 3); +} - } else if (py_point && py_id) { - Vec3r *v = Vec3r_ptr_from_PyObject(py_point); - if (!v) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return -1; - } - self->sv = new SVertex(*v, *(py_id->id)); - delete v; +static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds) +{ + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"point_3d", "id", NULL}; + PyObject *obj = 0; + float v[3]; - } else { + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &SVertex_Type, &obj)) { + if (!obj) + self->sv = new SVertex(); + else + self->sv = new SVertex(*(((BPy_SVertex *)obj)->sv)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O&O!", (char **)kwlist_2, convert_v3, v, &Id_Type, &obj)) + { + Vec3r point_3d(v[0], v[1], v[2]); + self->sv = new SVertex(point_3d, *(((BPy_Id *)obj)->id)); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_if0D.if0D = self->sv; self->py_if0D.borrowed = 0; - return 0; } @@ -115,7 +114,7 @@ static PyObject *SVertex_add_fedge( BPy_SVertex *self , PyObject *args) { Py_RETURN_NONE; } -// virtual bool operator== (const SVertex &iBrother) +// virtual bool operator== (const SVertex &brother) static PyMethodDef BPy_SVertex_methods[] = { {"add_normal", (PyCFunction)SVertex_add_normal, METH_VARARGS, SVertex_add_normal_doc}, |