diff options
Diffstat (limited to 'source/blender/freestyle/intern/python/Interface0D')
6 files changed, 166 insertions, 178 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; } 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}, diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp index 4fabfc508db..7954cf7fed8 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp @@ -23,27 +23,12 @@ PyDoc_STRVAR(ViewVertex_doc, ":class:`NonTVertex` when it corresponds to a vertex of the initial\n" "input mesh (it is the case for vertices such as corners for example).\n" "Thus, this class can be specialized into two classes, the\n" -":class:`TVertex` class and the :class:`NonTVertex` class.\n" -"\n" -".. method:: __init__()\n" -"\n" -" Default constructor.\n" -"\n" -".. method:: __init__(iBrother)\n" -"\n" -" Copy constructor.\n" -"\n" -" :arg iBrother: A ViewVertex object.\n" -" :type iBrother: :class:`ViewVertex`"); +":class:`TVertex` class and the :class:`NonTVertex` class."); static int ViewVertex_init(BPy_ViewVertex *self, PyObject *args, PyObject *kwds) { - if (!PyArg_ParseTuple(args, "")) - return -1; - self->vv = 0; // ViewVertex is abstract - self->py_if0D.if0D = self->vv; - self->py_if0D.borrowed = 0; - return 0; + PyErr_SetString(PyExc_TypeError, "cannot instantiate abstract class"); + return -1; } PyDoc_STRVAR(ViewVertex_edges_begin_doc, diff --git a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp index ad83a6933c3..09ebbfd1b3a 100644 --- a/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp @@ -9,8 +9,6 @@ extern "C" { #endif -#include "../../../python/mathutils/mathutils.h" /* for Vector callbacks */ - /////////////////////////////////////////////////////////////////////////////////////////// //------------------------INSTANCE METHODS ---------------------------------- @@ -24,71 +22,74 @@ PyDoc_STRVAR(StrokeVertex_doc, "\n" " Default constructor.\n" "\n" -".. method:: __init__(iBrother)\n" +".. method:: __init__(brother)\n" "\n" " Copy constructor.\n" "\n" -" :arg iBrother: A StrokeVertex object.\n" -" :type iBrother: :class:`StrokeVertex`\n" +" :arg brother: A StrokeVertex object.\n" +" :type brother: :class:`StrokeVertex`\n" "\n" -".. method:: __init__(iA, iB, t3)\n" +".. method:: __init__(first_vertex, second_vertex, t3d)\n" "\n" -" Builds a stroke vertex from 2 stroke vertices and an interpolation\n" +" Build a stroke vertex from 2 stroke vertices and an interpolation\n" " parameter.\n" "\n" -" :arg iA: The first StrokeVertex.\n" -" :type iA: :class:`StrokeVertex`\n" -" :arg iB: The second StrokeVertex.\n" -" :type iB: :class:`StrokeVertex`\n" -" :arg t3: An interpolation parameter.\n" -" :type t3: float\n" +" :arg first_vertex: The first StrokeVertex.\n" +" :type first_vertex: :class:`StrokeVertex`\n" +" :arg second_vertex: The second StrokeVertex.\n" +" :type second_vertex: :class:`StrokeVertex`\n" +" :arg t3d: An interpolation parameter.\n" +" :type t3d: float\n" "\n" -".. method:: __init__(iPoint)\n" +".. method:: __init__(point)\n" "\n" -" Builds a stroke vertex from a CurvePoint\n" +" Build a stroke vertex from a CurvePoint\n" "\n" -" :arg iPoint: A CurvePoint object.\n" -" :type iPoint: :class:`CurvePoint`\n" +" :arg point: A CurvePoint object.\n" +" :type point: :class:`CurvePoint`\n" "\n" -".. method:: __init__(iSVertex)\n" +".. method:: __init__(svertex)\n" "\n" -" Builds a stroke vertex from a SVertex\n" +" Build a stroke vertex from a SVertex\n" "\n" -" :arg iSVertex: An SVertex object.\n" -" :type iSVertex: :class:`SVertex`\n" +" :arg svertex: An SVertex object.\n" +" :type svertex: :class:`SVertex`\n" "\n" -".. method:: __init__(iSVertex, iAttribute)\n" +".. method:: __init__(svertex, attribute)\n" "\n" -" Builds a stroke vertex from an SVertex and a StrokeAttribute object.\n" +" Build a stroke vertex from an SVertex and a StrokeAttribute object.\n" "\n" -" :arg iSVertex: An SVertex object.\n" -" :type iSVertex: :class:`SVertex`\n" -" :arg iAttribute: A StrokeAttribute object.\n" -" :type iAttribute: :class:`StrokeAttribute`"); +" :arg svertex: An SVertex object.\n" +" :type svertex: :class:`SVertex`\n" +" :arg attribute: A StrokeAttribute object.\n" +" :type attribute: :class:`StrokeAttribute`"); static int StrokeVertex_init(BPy_StrokeVertex *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->sv = new StrokeVertex(); - - } else if (!obj2 && BPy_StrokeVertex_Check(obj1) && ((BPy_StrokeVertex *) obj1)->sv) { - self->sv = new StrokeVertex( *(((BPy_StrokeVertex *) obj1)->sv) ); - - } else if (!obj2 && BPy_CurvePoint_Check(obj1) && ((BPy_CurvePoint *) obj1)->cp) { - self->sv = new StrokeVertex( ((BPy_CurvePoint *) obj1)->cp ); - - } else if (!obj2 && BPy_SVertex_Check(obj1) && ((BPy_SVertex *) obj1)->sv) { - self->sv = new StrokeVertex( ((BPy_SVertex *) obj1)->sv ); - - } else if (obj3 && BPy_StrokeVertex_Check(obj1) && BPy_StrokeVertex_Check(obj2)) { - StrokeVertex *sv1 = ((BPy_StrokeVertex *) obj1)->sv; - StrokeVertex *sv2 = ((BPy_StrokeVertex *) obj2)->sv; + static const char *kwlist_1[] = {"brother", NULL}; + static const char *kwlist_2[] = {"first_vertex", "second_vertex", "t3d", NULL}; + static const char *kwlist_3[] = {"point", NULL}; + static const char *kwlist_4[] = {"svertex", "attribute", NULL}; + PyObject *obj1 = 0, *obj2 = 0; + float t3d; + + if (PyArg_ParseTupleAndKeywords(args, kwds, "|O!", (char **)kwlist_1, &StrokeVertex_Type, &obj1)) { + if (!obj1) { + self->sv = new StrokeVertex(); + } else { + if (!((BPy_StrokeVertex *)obj1)->sv) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); + return -1; + } + self->sv = new StrokeVertex(*(((BPy_StrokeVertex *)obj1)->sv)); + } + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!O!f", (char **)kwlist_2, + &StrokeVertex_Type, &obj1, &StrokeVertex_Type, &obj2, &t3d)) + { + StrokeVertex *sv1 = ((BPy_StrokeVertex *)obj1)->sv; + StrokeVertex *sv2 = ((BPy_StrokeVertex *)obj2)->sv; if (!sv1 || (sv1->A() == 0 && sv1->B() == 0)) { PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid StrokeVertex object"); return -1; @@ -97,17 +98,34 @@ static int StrokeVertex_init(BPy_StrokeVertex *self, PyObject *args, PyObject *k PyErr_SetString(PyExc_TypeError, "argument 2 is an invalid StrokeVertex object"); return -1; } - self->sv = new StrokeVertex(sv1, sv2, PyFloat_AsDouble(obj3)); - - } else { + self->sv = new StrokeVertex(sv1, sv2, t3d); + } + else if (PyErr_Clear(), + PyArg_ParseTupleAndKeywords(args, kwds, "O!", (char **)kwlist_3, &CurvePoint_Type, &obj1)) + { + CurvePoint *cp = ((BPy_CurvePoint *)obj1)->cp; + if (!cp || cp->A() == 0 || cp->B() == 0) { + PyErr_SetString(PyExc_TypeError, "argument 1 is an invalid CurvePoint object"); + return -1; + } + self->sv = new StrokeVertex(cp); + } + else if (PyErr_Clear(), (obj2 = 0), + PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!", (char **)kwlist_4, + &SVertex_Type, &obj1, &StrokeAttribute_Type, &obj2)) + { + if (!obj2) + self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv); + else + self->sv = new StrokeVertex(((BPy_SVertex *)obj1)->sv, *(((BPy_StrokeAttribute *)obj2)->sa)); + } + else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_cp.cp = self->sv; self->py_cp.py_if0D.if0D = self->sv; self->py_cp.py_if0D.borrowed = 0; - return 0; } 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; |