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_CurvePoint.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_CurvePoint.cpp')
-rw-r--r-- | source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp | 92 |
1 files changed, 47 insertions, 45 deletions
diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp index 3e2cc495785..e63d1c583d8 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp @@ -27,78 +27,80 @@ PyDoc_STRVAR(CurvePoint_doc, "\n" " Defult constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A CurvePoint object.\n" -" :type iBrother: :class:`CurvePoint`\n" +" :arg brother: A CurvePoint object.\n" +" :type brother: :class:`CurvePoint`\n" "\n" -".. method:: __init__(iA, iB, t2d)\n" +".. method:: __init__(first_vertex, second_vertex, t2d)\n" "\n" -" Builds a CurvePoint from two SVertex and an interpolation parameter.\n" +" Builds a CurvePoint from two SVertex objects and an interpolation parameter.\n" "\n" -" :arg iA: The first SVertex.\n" -" :type iA: :class:`SVertex`\n" -" :arg iB: The second SVertex.\n" -" :type iB: :class:`SVertex`\n" +" :arg first_vertex: The first SVertex.\n" +" :type first_vertex: :class:`SVertex`\n" +" :arg second_vertex: The second SVertex.\n" +" :type second_vertex: :class:`SVertex`\n" " :arg t2d: A 2D interpolation parameter used to linearly interpolate\n" -" iA and iB.\n" +" first_vertex and second_vertex.\n" " :type t2d: float\n" "\n" -".. method:: __init__(iA, iB, t2d)\n" +".. method:: __init__(first_point, second_point, t2d)\n" "\n" -" Builds a CurvePoint from two CurvePoint and an interpolation\n" +" Builds a CurvePoint from two CurvePoint objects and an interpolation\n" " parameter.\n" "\n" -" :arg iA: The first CurvePoint.\n" -" :type iA: :class:`CurvePoint`\n" -" :arg iB: The second CurvePoint.\n" -" :type iB: :class:`CurvePoint`\n" -" :arg t2d: The 2D interpolation parameter used to linearly\n" -" interpolate iA and iB.\n" +" :arg first_point: The first CurvePoint.\n" +" :type first_point: :class:`CurvePoint`\n" +" :arg second_point: The second CurvePoint.\n" +" :type second_point: :class:`CurvePoint`\n" +" :arg t2d: The 2D interpolation parameter used to linearly interpolate\n" +" first_point and second_point.\n" " :type t2d: float"); static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds) { - - PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0; - - if (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) ) - return -1; - - if( !obj1 ){ - self->cp = new CurvePoint(); - - } else if( !obj2 && BPy_CurvePoint_Check(obj1) ) { - self->cp = new CurvePoint( *(((BPy_CurvePoint *) obj1)->cp) ); - - } else if( obj3 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { - self->cp = new CurvePoint( ((BPy_SVertex *) obj1)->sv, - ((BPy_SVertex *) obj2)->sv, - PyFloat_AsDouble( obj3 ) ); - - } else if( obj3 && BPy_CurvePoint_Check(obj1) && BPy_CurvePoint_Check(obj2) ) { - CurvePoint *cp1 = ((BPy_CurvePoint *) obj1)->cp; - CurvePoint *cp2 = ((BPy_CurvePoint *) obj2)->cp; - if( !cp1 || cp1->A() == 0 || cp1->B() == 0 ) { + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t2d", NULL}; + static const char *kwlist_3[] = {"first_point", "second_point", "t2d", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float t2d; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &CurvePoint_Type, &obj1)) { + if (!obj1) + self->cp = new CurvePoint(); + else + self->cp = new CurvePoint(*(((BPy_CurvePoint *)obj1)->cp)); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, + &SVertex_Type, &obj1, &SVertex_Type, &obj2, &t2d)) + { + self->cp = new CurvePoint(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv, t2d); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_3, + &CurvePoint_Type, &obj1, &CurvePoint_Type, &obj2, &t2d)) + { + CurvePoint *cp1 = ((BPy_CurvePoint *)obj1)->cp; + CurvePoint *cp2 = ((BPy_CurvePoint *)obj2)->cp; + if (!cp1 || cp1->A() == 0 || cp1->B() == 0) { PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); return -1; } - if( !cp2 || cp2->A() == 0 || cp2->B() == 0 ) { + if (!cp2 || cp2->A() == 0 || cp2->B() == 0) { PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid CurvePoint object"); return -1; } - self->cp = new CurvePoint( cp1, cp2, PyFloat_AsDouble( obj3 ) ); - - } else { + self->cp = new CurvePoint(cp1, cp2, t2d); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_if0D.if0D = self->cp; self->py_if0D.borrowed = 0; - return 0; } |