diff options
Diffstat (limited to 'source/blender/freestyle/intern/python/Interface0D')
6 files changed, 568 insertions, 519 deletions
diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp index e213edd5c79..3e2cc495785 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp @@ -9,9 +9,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------CurvePoint methods----------------------------*/ -static char CurvePoint___doc__[] = +PyDoc_STRVAR(CurvePoint_doc, "Class hierarchy: :class:`Interface0D` > :class:`CurvePoint`\n" "\n" "Class to represent a point of a curve. A CurvePoint can be any point\n" @@ -57,15 +57,15 @@ static char CurvePoint___doc__[] = " :type iB: :class:`CurvePoint`\n" " :arg t2d: The 2D interpolation parameter used to linearly\n" " interpolate iA and iB.\n" -" :type t2d: float\n"; +" :type t2d: float"); -static int CurvePoint___init__(BPy_CurvePoint *self, PyObject *args, PyObject *kwds) +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 (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) ) + return -1; if( !obj1 ){ self->cp = new CurvePoint(); @@ -102,131 +102,99 @@ static int CurvePoint___init__(BPy_CurvePoint *self, PyObject *args, PyObject *k return 0; } -static char CurvePoint_A___doc__[] = -".. method:: A()\n" -"\n" -" Returns the first SVertex upon which the CurvePoint is built.\n" -"\n" -" :return: The first SVertex.\n" -" :rtype: :class:`SVertex`\n"; +///bool operator== (const CurvePoint &b) -static PyObject * CurvePoint_A( BPy_CurvePoint *self ) { - SVertex *A = self->cp->A(); - if( A ) - return BPy_SVertex_from_SVertex( *A ); +static PyMethodDef BPy_CurvePoint_methods[] = { + {NULL, NULL, 0, NULL} +}; - Py_RETURN_NONE; -} +/*----------------------CurvePoint get/setters ----------------------------*/ -static char CurvePoint_B___doc__[] = -".. method:: B()\n" +PyDoc_STRVAR(CurvePoint_first_svertex_doc, +"The first SVertex upon which the CurvePoint is built.\n" "\n" -" Returns the second SVertex upon which the CurvePoint is built.\n" -"\n" -" :return: The second SVertex.\n" -" :rtype: :class:`SVertex`\n"; - -static PyObject * CurvePoint_B( BPy_CurvePoint *self ) { - SVertex *B = self->cp->B(); - if( B ) - return BPy_SVertex_from_SVertex( *B ); +":type: int"); +static PyObject *CurvePoint_first_svertex_get(BPy_CurvePoint *self, void *UNUSED(closure)) +{ + SVertex *A = self->cp->A(); + if (A) + return BPy_SVertex_from_SVertex(*A); Py_RETURN_NONE; } -static char CurvePoint_t2d___doc__[] = -".. method:: t2d()\n" -"\n" -" Returns the 2D interpolation parameter.\n" -"\n" -" :return: The 2D interpolation parameter.\n" -" :rtype: float\n"; - -static PyObject * CurvePoint_t2d( BPy_CurvePoint *self ) { - return PyFloat_FromDouble( self->cp->t2d() ); +static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->cp->setA(((BPy_SVertex *)value)->sv); + return 0; } -static char CurvePoint_setA___doc__[] = -".. method:: setA(iA)\n" +PyDoc_STRVAR(CurvePoint_second_svertex_doc, +"The second SVertex upon which the CurvePoint is built.\n" "\n" -" Sets the first SVertex upon which to build the CurvePoint.\n" -"\n" -" :arg iA: The first SVertex.\n" -" :type iA: :class:`SVertex`\n"; - -static PyObject *CurvePoint_setA( BPy_CurvePoint *self , PyObject *args) { - PyObject *py_sv; - - if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) - return NULL; - - self->cp->setA( ((BPy_SVertex *) py_sv)->sv ); +":type: int"); +static PyObject *CurvePoint_second_svertex_get(BPy_CurvePoint *self, void *UNUSED(closure)) +{ + SVertex *B = self->cp->B(); + if (B) + return BPy_SVertex_from_SVertex(*B); Py_RETURN_NONE; } -static char CurvePoint_setB___doc__[] = -".. method:: setB(iB)\n" -"\n" -" Sets the first SVertex upon which to build the CurvePoint.\n" -"\n" -" :arg iB: The second SVertex.\n" -" :type iB: :class:`SVertex`\n"; - -static PyObject *CurvePoint_setB( BPy_CurvePoint *self , PyObject *args) { - PyObject *py_sv; - - if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) - return NULL; - - self->cp->setB( ((BPy_SVertex *) py_sv)->sv ); - - Py_RETURN_NONE; +static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->cp->setB(((BPy_SVertex *)value)->sv); + return 0; } -static char CurvePoint_setT2d___doc__[] = -".. method:: setT2d(t)\n" -"\n" -" Sets the 2D interpolation parameter to use.\n" +PyDoc_STRVAR(CurvePoint_t2d_doc, +"The 2D interpolation parameter.\n" "\n" -" :arg t: The 2D interpolation parameter.\n" -" :type t: float\n"; +":type: float"); -static PyObject *CurvePoint_setT2d( BPy_CurvePoint *self , PyObject *args) { - float t; - - if(!( PyArg_ParseTuple(args, "f", &t) )) - return NULL; - - self->cp->setT2d( t ); +static PyObject *CurvePoint_t2d_get(BPy_CurvePoint *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->cp->t2d()); +} - Py_RETURN_NONE; +static int CurvePoint_t2d_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure)) +{ + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->cp->setT2d(scalar); + return 0; } -static char CurvePoint_curvatureFredo___doc__[] = -".. method:: curvatureFredo()\n" -"\n" -" Returns the angle in radians.\n" +PyDoc_STRVAR(CurvePoint_curvature_fredo_doc, +"The angle (Fredo's curvature) in radians.\n" "\n" -" :return: The angle in radians.\n" -" :rtype: float\n"; +":type: float"); -static PyObject *CurvePoint_curvatureFredo( BPy_CurvePoint *self , PyObject *args) { - return PyFloat_FromDouble( self->cp->curvatureFredo() ); +static PyObject *CurvePoint_curvature_fredo_get(BPy_CurvePoint *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->cp->curvatureFredo()); } -///bool operator== (const CurvePoint &b) +// todo - CurvePoint.directionFredo() -/*----------------------CurvePoint instance definitions ----------------------------*/ -static PyMethodDef BPy_CurvePoint_methods[] = { - {"A", ( PyCFunction ) CurvePoint_A, METH_NOARGS, CurvePoint_A___doc__}, - {"B", ( PyCFunction ) CurvePoint_B, METH_NOARGS, CurvePoint_B___doc__}, - {"t2d", ( PyCFunction ) CurvePoint_t2d, METH_NOARGS, CurvePoint_t2d___doc__}, - {"setA", ( PyCFunction ) CurvePoint_setA, METH_VARARGS, CurvePoint_setA___doc__}, - {"setB", ( PyCFunction ) CurvePoint_setB, METH_VARARGS, CurvePoint_setB___doc__}, - {"setT2d", ( PyCFunction ) CurvePoint_setT2d, METH_VARARGS, CurvePoint_setT2d___doc__}, - {"curvatureFredo", ( PyCFunction ) CurvePoint_curvatureFredo, METH_NOARGS, CurvePoint_curvatureFredo___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_CurvePoint_getseters[] = { + {(char *)"first_svertex", (getter)CurvePoint_first_svertex_get, (setter)CurvePoint_first_svertex_set, (char *)CurvePoint_first_svertex_doc, NULL}, + {(char *)"second_svertex", (getter)CurvePoint_second_svertex_get, (setter)CurvePoint_second_svertex_set, (char *)CurvePoint_second_svertex_doc, NULL}, + {(char *)"t2d", (getter)CurvePoint_t2d_get, (setter)CurvePoint_t2d_set, (char *)CurvePoint_t2d_doc, NULL}, + {(char *)"curvature_fredo", (getter)CurvePoint_curvature_fredo_get, (setter)NULL, (char *)CurvePoint_curvature_fredo_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_CurvePoint type definition ------------------------------*/ @@ -251,7 +219,7 @@ PyTypeObject CurvePoint_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - CurvePoint___doc__, /* tp_doc */ + CurvePoint_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -260,13 +228,13 @@ PyTypeObject CurvePoint_Type = { 0, /* tp_iternext */ BPy_CurvePoint_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_CurvePoint_getseters, /* tp_getset */ &Interface0D_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)CurvePoint___init__, /* tp_init */ + (initproc)CurvePoint_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp index 14e6f143b84..0d0a772b4e5 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.cpp @@ -10,7 +10,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -static char SVertex___doc__[] = +/*----------------------SVertex methods ----------------------------*/ + +PyDoc_STRVAR(SVertex_doc, "Class hierarchy: :class:`Interface0D` > :class:`SVertex`\n" "\n" "Class to define a vertex of the embedding.\n" @@ -33,32 +35,29 @@ static char SVertex___doc__[] = " :arg iPoint3D: A three-dimensional vector.\n" " :type iPoint3D: :class:`mathutils.Vector`\n" " :arg id: An Id object.\n" -" :type id: :class:`Id`\n"; - -//------------------------INSTANCE METHODS ---------------------------------- +" :type id: :class:`Id`"); -static int SVertex___init__(BPy_SVertex *self, PyObject *args, PyObject *kwds) +static int SVertex_init(BPy_SVertex *self, PyObject *args, PyObject *kwds) { PyObject *py_point = 0; BPy_Id *py_id = 0; - - if (! PyArg_ParseTuple(args, "|OO!", &py_point, &Id_Type, &py_id) ) - return -1; + if (!PyArg_ParseTuple(args, "|OO!", &py_point, &Id_Type, &py_id)) + return -1; - if( !py_point ) { + if (!py_point) { self->sv = new SVertex(); - } else if( !py_id && BPy_SVertex_Check(py_point) ) { + } else if (!py_id && BPy_SVertex_Check(py_point)) { self->sv = new SVertex( *(((BPy_SVertex *)py_point)->sv) ); - } else if( py_point && py_id ) { + } else if (py_point && py_id) { Vec3r *v = Vec3r_ptr_from_PyObject(py_point); - if( !v ) { + 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) ); + self->sv = new SVertex(*v, *(py_id->id)); delete v; } else { @@ -68,192 +67,310 @@ static int SVertex___init__(BPy_SVertex *self, PyObject *args, PyObject *kwds) self->py_if0D.if0D = self->sv; self->py_if0D.borrowed = 0; - + return 0; } -static char SVertex_normals___doc__[] = -".. method:: normals()\n" +PyDoc_STRVAR(SVertex_add_normal_doc, +".. method:: add_normal(n)\n" "\n" -" Returns the normals for this Vertex as a list. In a smooth surface,\n" -" a vertex has exactly one normal. In a sharp surface, a vertex can\n" -" have any number of normals.\n" +" Adds a normal to the SVertex's set of normals. If the same normal\n" +" is already in the set, nothing changes.\n" "\n" -" :return: A list of normals.\n" -" :rtype: List of :class:`mathutils.Vector` objects\n"; +" :arg n: A three-dimensional vector.\n" +" :type n: :class:`mathutils.Vector`, list or tuple of 3 real numbers"); -static PyObject * SVertex_normals( BPy_SVertex *self ) { - PyObject *py_normals; - set< Vec3r > normals; - - py_normals = PyList_New(0); - normals = self->sv->normals(); - - for( set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++ ) { - Vec3r v( *set_iterator ); - PyList_Append( py_normals, Vector_from_Vec3r(v) ); +static PyObject *SVertex_add_normal( BPy_SVertex *self , PyObject *args) { + PyObject *py_normal; + + if (!PyArg_ParseTuple(args, "O", &py_normal)) + return NULL; + Vec3r *n = Vec3r_ptr_from_PyObject(py_normal); + if (!n) { + PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); + return NULL; } - - return py_normals; + self->sv->AddNormal(*n); + delete n; + + Py_RETURN_NONE; } -static char SVertex_normalsSize___doc__[] = -".. method:: normalsSize()\n" +PyDoc_STRVAR(SVertex_add_fedge_doc, +".. method:: add_fedge(fe)\n" "\n" -" Returns the number of different normals for this vertex.\n" +" Add an FEdge to the list of edges emanating from this SVertex.\n" "\n" -" :return: The number of normals.\n" -" :rtype: int\n"; +" :arg fe: An FEdge.\n" +" :type fe: :class:`FEdge`"); + +static PyObject *SVertex_add_fedge( BPy_SVertex *self , PyObject *args) { + PyObject *py_fe; -static PyObject * SVertex_normalsSize( BPy_SVertex *self ) { - return PyLong_FromLong( self->sv->normalsSize() ); + if (!PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe)) + return NULL; + + self->sv->AddFEdge(((BPy_FEdge *)py_fe)->fe); + + Py_RETURN_NONE; } -static char SVertex_viewvertex___doc__[] = -".. method:: viewvertex()\n" -"\n" -" If this SVertex is also a ViewVertex, this method returns the\n" -" ViewVertex. None is returned otherwise.\n" -"\n" -" :return: The ViewVertex object.\n" -" :rtype: :class:`ViewVertex`\n"; +// virtual bool operator== (const SVertex &iBrother) -static PyObject * SVertex_viewvertex( BPy_SVertex *self ) { - ViewVertex *vv = self->sv->viewvertex(); - if( vv ) - return Any_BPy_ViewVertex_from_ViewVertex( *vv ); +static PyMethodDef BPy_SVertex_methods[] = { + {"add_normal", (PyCFunction)SVertex_add_normal, METH_VARARGS, SVertex_add_normal_doc}, + {"add_fedge", (PyCFunction)SVertex_add_fedge, METH_VARARGS, SVertex_add_fedge_doc}, + {NULL, NULL, 0, NULL} +}; - Py_RETURN_NONE; +/*----------------------mathutils callbacks ----------------------------*/ + +/* subtype */ +#define MATHUTILS_SUBTYPE_POINT3D 1 +#define MATHUTILS_SUBTYPE_POINT2D 2 + +static int SVertex_mathutils_check(BaseMathObject *bmo) +{ + if (!BPy_SVertex_Check(bmo->cb_user)) + return -1; + return 0; } -static char SVertex_setPoint3D___doc__[] = -".. method:: setPoint3D(p)\n" -"\n" -" Sets the 3D coordinates of the SVertex.\n" -"\n" -" :arg p: A three-dimensional vector.\n" -" :type p: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; +static int SVertex_mathutils_get(BaseMathObject *bmo, int subtype) +{ + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: + bmo->data[0] = self->sv->getX(); + bmo->data[1] = self->sv->getY(); + bmo->data[2] = self->sv->getZ(); + break; + case MATHUTILS_SUBTYPE_POINT2D: + bmo->data[0] = self->sv->getProjectedX(); + bmo->data[1] = self->sv->getProjectedY(); + bmo->data[2] = self->sv->getProjectedZ(); + break; + default: + return -1; + } + return 0; +} -static PyObject *SVertex_setPoint3D( BPy_SVertex *self , PyObject *args) { - PyObject *py_point; +static int SVertex_mathutils_set(BaseMathObject *bmo, int subtype) +{ + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: + { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->sv->setPoint3D(p); + } + break; + case MATHUTILS_SUBTYPE_POINT2D: + { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->sv->setPoint2D(p); + } + break; + default: + return -1; + } + return 0; +} - if(!( PyArg_ParseTuple(args, "O", &py_point) )) - return NULL; - 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 NULL; +static int SVertex_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) +{ + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: + switch (index) { + case 0: bmo->data[0] = self->sv->getX(); break; + case 1: bmo->data[1] = self->sv->getY(); break; + case 2: bmo->data[2] = self->sv->getZ(); break; + default: + return -1; + } + break; + case MATHUTILS_SUBTYPE_POINT2D: + switch (index) { + case 0: bmo->data[0] = self->sv->getProjectedX(); break; + case 1: bmo->data[1] = self->sv->getProjectedY(); break; + case 2: bmo->data[2] = self->sv->getProjectedZ(); break; + default: + return -1; + } + break; + default: + return -1; } - self->sv->setPoint3D( *v ); - delete v; + return 0; +} - Py_RETURN_NONE; +static int SVertex_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) +{ + BPy_SVertex *self = (BPy_SVertex *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_POINT3D: + { + Vec3r p(self->sv->point3D()); + p[index] = bmo->data[index]; + self->sv->setPoint3D(p); + } + break; + case MATHUTILS_SUBTYPE_POINT2D: + { + Vec3r p(self->sv->point2D()); + p[index] = bmo->data[index]; + self->sv->setPoint2D(p); + } + break; + default: + return -1; + } + return 0; } -static char SVertex_setPoint2D___doc__[] = -".. method:: setPoint2D(p)\n" -"\n" -" Sets the 2D projected coordinates of the SVertex.\n" +static Mathutils_Callback SVertex_mathutils_cb = { + SVertex_mathutils_check, + SVertex_mathutils_get, + SVertex_mathutils_set, + SVertex_mathutils_get_index, + SVertex_mathutils_set_index +}; + +static unsigned char SVertex_mathutils_cb_index = -1; + +void SVertex_mathutils_register_callback() +{ + SVertex_mathutils_cb_index = Mathutils_RegisterCallback(&SVertex_mathutils_cb); +} + +/*----------------------SVertex get/setters ----------------------------*/ + +PyDoc_STRVAR(SVertex_point_3d_doc, +"The 3D coordinates of the SVertex.\n" "\n" -" :arg p: A three-dimensional vector.\n" -" :type p: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; +":type: mathutils.Vector"); -static PyObject *SVertex_setPoint2D( BPy_SVertex *self , PyObject *args) { - PyObject *py_point; +static PyObject *SVertex_point_3d_get(BPy_SVertex *self, void *UNUSED(closure)) +{ + return Vector_CreatePyObject_cb((PyObject *)self, 3, SVertex_mathutils_cb_index, MATHUTILS_SUBTYPE_POINT3D); +} - if(!( PyArg_ParseTuple(args, "O", &py_point) )) - return NULL; - 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 NULL; +static int SVertex_point_3d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure)) +{ + float v[3]; + if (!float_array_from_PyObject(value, v, 3)) { + PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector"); + return -1; } - self->sv->setPoint2D( *v ); - delete v; - - Py_RETURN_NONE; + Vec3r p(v[0], v[1], v[2]); + self->sv->setPoint3D(p); + return 0; } -static char SVertex_AddNormal___doc__[] = -".. method:: AddNormal(n)\n" -"\n" -" Adds a normal to the SVertex's set of normals. If the same normal\n" -" is already in the set, nothing changes.\n" +PyDoc_STRVAR(SVertex_point_2d_doc, +"The projected 3D coordinates of the SVertex.\n" "\n" -" :arg n: A three-dimensional vector.\n" -" :type n: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; +":type: mathutils.Vector"); -static PyObject *SVertex_AddNormal( BPy_SVertex *self , PyObject *args) { - PyObject *py_normal; +static PyObject *SVertex_point_2d_get(BPy_SVertex *self, void *UNUSED(closure)) +{ + return Vector_CreatePyObject_cb((PyObject *)self, 3, SVertex_mathutils_cb_index, MATHUTILS_SUBTYPE_POINT2D); +} - if(!( PyArg_ParseTuple(args, "O", &py_normal) )) - return NULL; - Vec3r *n = Vec3r_ptr_from_PyObject(py_normal); - if( !n ) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return NULL; +static int SVertex_point_2d_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure)) +{ + float v[3]; + if (!float_array_from_PyObject(value, v, 3)) { + PyErr_SetString(PyExc_ValueError, "value must be a 3-dimensional vector"); + return -1; } - self->sv->AddNormal( *n ); - delete n; - - Py_RETURN_NONE; + Vec3r p(v[0], v[1], v[2]); + self->sv->setPoint2D(p); + return 0; } -static char SVertex_setId___doc__[] = -".. method:: setId(id)\n" -"\n" -" Sets the identifier of the SVertex.\n" +PyDoc_STRVAR(SVertex_id_doc, +"The Id of this SVertex.\n" "\n" -" :arg id: The identifier.\n" -" :type id: :class:`Id`\n"; +":type: :class:`Id`"); -static PyObject *SVertex_setId( BPy_SVertex *self , PyObject *args) { - BPy_Id *py_id; +static PyObject *SVertex_id_get(BPy_SVertex *self, void *UNUSED(closure)) +{ + Id id(self->sv->getId()); + return BPy_Id_from_Id(id); // return a copy +} - if( !PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) ) - return NULL; +static int SVertex_id_set(BPy_SVertex *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->sv->setId(*(((BPy_Id *)value)->id)); + return 0; +} - self->sv->setId( *(py_id->id) ); +PyDoc_STRVAR(SVertex_normals_doc, +"The normals for this Vertex as a list. In a sharp surface, an SVertex\n" +"has exactly one normal. In a smooth surface, an SVertex can have any\n" +"number of normals.\n" +"\n" +":type: list of :class:`mathutils.Vector` objects"); - Py_RETURN_NONE; +static PyObject *SVertex_normals_get(BPy_SVertex *self, void *UNUSED(closure)) +{ + PyObject *py_normals; + set< Vec3r > normals; + + py_normals = PyList_New(0); + normals = self->sv->normals(); + for (set< Vec3r >::iterator set_iterator = normals.begin(); set_iterator != normals.end(); set_iterator++) { + Vec3r v(*set_iterator); + PyList_Append(py_normals, Vector_from_Vec3r(v)); + } + return py_normals; } -static char SVertex_AddFEdge___doc__[] = -".. method:: AddFEdge(fe)\n" -"\n" -" Add an FEdge to the list of edges emanating from this SVertex.\n" +PyDoc_STRVAR(SVertex_normals_size_doc, +"The number of different normals for this SVertex.\n" "\n" -" :arg fe: An FEdge.\n" -" :type fe: :class:`FEdge`\n"; +":type: int"); -static PyObject *SVertex_AddFEdge( BPy_SVertex *self , PyObject *args) { - PyObject *py_fe; +static PyObject *SVertex_normals_size_get(BPy_SVertex *self, void *UNUSED(closure)) +{ + return PyLong_FromLong(self->sv->normalsSize()); +} - if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) - return NULL; - - self->sv->AddFEdge( ((BPy_FEdge *) py_fe)->fe ); +PyDoc_STRVAR(SVertex_viewvertex_doc, +"If this SVertex is also a ViewVertex, this property refers to the\n" +"ViewVertex, and None otherwise.\n" +":type: :class:`ViewVertex`"); +static PyObject *SVertex_viewvertex_get(BPy_SVertex *self, void *UNUSED(closure)) +{ + ViewVertex *vv = self->sv->viewvertex(); + if (vv) + return Any_BPy_ViewVertex_from_ViewVertex(*vv); Py_RETURN_NONE; } -static char SVertex_curvatures___doc__[] = -".. method:: curvatures()\n" +PyDoc_STRVAR(SVertex_curvatures_doc, +"Curvature information expressed in the form of a seven-element tuple\n" +"(K1, e1, K2, e2, Kr, er, dKr), where K1 and K2 are scalar values\n" +"representing the first (maximum) and second (minimum) principal\n" +"curvatures at this SVertex, respectively; e1 and e2 are\n" +"three-dimensional vectors representing the first and second principal\n" +"directions, i.e. the directions of the normal plane where the\n" +"curvature takes its maximum and minimum values, respectively; and Kr,\n" +"er and dKr are the radial curvature, radial direction, and the\n" +"derivative of the radial curvature at this SVertex, repectively.\n" "\n" -" Returns curvature information in the form of a seven-element tuple\n" -" (K1, e1, K2, e2, Kr, er, dKr), where K1 and K2 are scalar values\n" -" representing the first (maximum) and second (minimum) principal\n" -" curvatures at this SVertex, respectively; e1 and e2 are\n" -" three-dimensional vectors representing the first and second principal\n" -" directions, i.e. the directions of the normal plane where the\n" -" curvature takes its maximum and minimum values, respectively; and Kr,\n" -" er and dKr are the radial curvature, radial direction, and the\n" -" derivative of the radial curvature at this SVertex, repectively.\n" -" :return: curvature information expressed by a seven-element tuple\n" -" (K1, e1, K2, e2, Kr, er, dKr).\n" -" :rtype: tuple\n"; - -static PyObject *SVertex_curvatures( BPy_SVertex *self , PyObject *args) { +":type: tuple"); + +static PyObject *SVertex_curvatures_get(BPy_SVertex *self, void *UNUSED(closure)) +{ const CurvatureInfo *info = self->sv->getCurvatureInfo(); if (!info) Py_RETURN_NONE; @@ -261,31 +378,25 @@ static PyObject *SVertex_curvatures( BPy_SVertex *self , PyObject *args) { Vec3r e2(info->e2.x(), info->e2.y(), info->e2.z()); Vec3r er(info->er.x(), info->er.y(), info->er.z()); PyObject *retval = PyTuple_New(7); - PyTuple_SET_ITEM( retval, 0, PyFloat_FromDouble(info->K1)); - PyTuple_SET_ITEM( retval, 2, Vector_from_Vec3r(e1)); - PyTuple_SET_ITEM( retval, 1, PyFloat_FromDouble(info->K2)); - PyTuple_SET_ITEM( retval, 3, Vector_from_Vec3r(e2)); - PyTuple_SET_ITEM( retval, 4, PyFloat_FromDouble(info->Kr)); - PyTuple_SET_ITEM( retval, 5, Vector_from_Vec3r(er)); - PyTuple_SET_ITEM( retval, 6, PyFloat_FromDouble(info->dKr)); + PyTuple_SET_ITEM(retval, 0, PyFloat_FromDouble(info->K1)); + PyTuple_SET_ITEM(retval, 2, Vector_from_Vec3r(e1)); + PyTuple_SET_ITEM(retval, 1, PyFloat_FromDouble(info->K2)); + PyTuple_SET_ITEM(retval, 3, Vector_from_Vec3r(e2)); + PyTuple_SET_ITEM(retval, 4, PyFloat_FromDouble(info->Kr)); + PyTuple_SET_ITEM(retval, 5, Vector_from_Vec3r(er)); + PyTuple_SET_ITEM(retval, 6, PyFloat_FromDouble(info->dKr)); return retval; } -// virtual bool operator== (const SVertex &iBrother) -// ViewVertex * viewvertex () - -/*----------------------SVertex instance definitions ----------------------------*/ -static PyMethodDef BPy_SVertex_methods[] = { - {"normals", ( PyCFunction ) SVertex_normals, METH_NOARGS, SVertex_normals___doc__}, - {"normalsSize", ( PyCFunction ) SVertex_normalsSize, METH_NOARGS, SVertex_normalsSize___doc__}, - {"viewvertex", ( PyCFunction ) SVertex_viewvertex, METH_NOARGS, SVertex_viewvertex___doc__}, - {"setPoint3D", ( PyCFunction ) SVertex_setPoint3D, METH_VARARGS, SVertex_setPoint3D___doc__}, - {"setPoint2D", ( PyCFunction ) SVertex_setPoint2D, METH_VARARGS, SVertex_setPoint2D___doc__}, - {"AddNormal", ( PyCFunction ) SVertex_AddNormal, METH_VARARGS, SVertex_AddNormal___doc__}, - {"setId", ( PyCFunction ) SVertex_setId, METH_VARARGS, SVertex_setId___doc__}, - {"AddFEdge", ( PyCFunction ) SVertex_AddFEdge, METH_VARARGS, SVertex_AddFEdge___doc__}, - {"curvatures", ( PyCFunction ) SVertex_curvatures, METH_NOARGS, SVertex_curvatures___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_SVertex_getseters[] = { + {(char *)"point_3d", (getter)SVertex_point_3d_get, (setter)SVertex_point_3d_set, (char *)SVertex_point_3d_doc, NULL}, + {(char *)"point_2d", (getter)SVertex_point_2d_get, (setter)SVertex_point_2d_set, (char *)SVertex_point_2d_doc, NULL}, + {(char *)"id", (getter)SVertex_id_get, (setter)SVertex_id_set, (char *)SVertex_id_doc, NULL}, + {(char *)"normals", (getter)SVertex_normals_get, (setter)NULL, (char *)SVertex_normals_doc, NULL}, + {(char *)"normals_size", (getter)SVertex_normals_size_get, (setter)NULL, (char *)SVertex_normals_size_doc, NULL}, + {(char *)"viewvertex", (getter)SVertex_viewvertex_get, (setter)NULL, (char *)SVertex_viewvertex_doc, NULL}, + {(char *)"curvatures", (getter)SVertex_curvatures_get, (setter)NULL, (char *)SVertex_curvatures_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_SVertex type definition ------------------------------*/ @@ -310,7 +421,7 @@ PyTypeObject SVertex_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - SVertex___doc__, /* tp_doc */ + SVertex_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -319,13 +430,13 @@ PyTypeObject SVertex_Type = { 0, /* tp_iternext */ BPy_SVertex_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_SVertex_getseters, /* tp_getset */ &Interface0D_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)SVertex___init__, /* tp_init */ + (initproc)SVertex_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; @@ -335,4 +446,3 @@ PyTypeObject SVertex_Type = { #ifdef __cplusplus } #endif - diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h index 7d310f2b7dc..61c65659a5e 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_SVertex.h @@ -23,6 +23,10 @@ typedef struct { SVertex *sv; } BPy_SVertex; +/*---------------------------Python BPy_SVertex visible prototypes-----------*/ + +void SVertex_mathutils_register_callback(); + /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp index c1fe6875ea7..4fabfc508db 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_ViewVertex.cpp @@ -10,9 +10,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------ViewVertex methods----------------------------*/ -static char ViewVertex___doc__[] = +PyDoc_STRVAR(ViewVertex_doc, "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex`\n" "\n" "Class to define a view vertex. A view vertex is a feature vertex\n" @@ -34,43 +34,20 @@ static char ViewVertex___doc__[] = " Copy constructor.\n" "\n" " :arg iBrother: A ViewVertex object.\n" -" :type iBrother: :class:`ViewVertex`\n"; +" :type iBrother: :class:`ViewVertex`"); -static int ViewVertex___init__( BPy_ViewVertex *self, PyObject *args, PyObject *kwds ) -{ - if( !PyArg_ParseTuple(args, "") ) - return -1; +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; } -static char ViewVertex_setNature___doc__[] = -".. method:: setNature(iNature)\n" -"\n" -" Sets the nature of the vertex.\n" -"\n" -" :arg iNature: A Nature object.\n" -" :type iNature: :class:`Nature`\n"; - -static PyObject * ViewVertex_setNature( BPy_ViewVertex *self, PyObject *args ) { - PyObject *py_n; - - if( !self->vv ) - Py_RETURN_NONE; - - if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) )) - return NULL; - - PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i ); - ((ViewVertex *) self->py_if0D.if0D)->setNature( PyLong_AsLong(i) ); - - Py_RETURN_NONE; -} - -static char ViewVertex_edgesBegin___doc__[] = -".. method:: edgesBegin()\n" +PyDoc_STRVAR(ViewVertex_edges_begin_doc, +".. method:: edges_begin()\n" "\n" " Returns an iterator over the ViewEdges that goes to or comes from\n" " this ViewVertex pointing to the first ViewEdge of the list. The\n" @@ -79,40 +56,40 @@ static char ViewVertex_edgesBegin___doc__[] = " (incoming/outgoing).\n" "\n" " :return: An orientedViewEdgeIterator pointing to the first ViewEdge.\n" -" :rtype: :class:`orientedViewEdgeIterator`\n"; +" :rtype: :class:`orientedViewEdgeIterator`"); -static PyObject * ViewVertex_edgesBegin( BPy_ViewVertex *self ) { - if( !self->vv ) +static PyObject * ViewVertex_edges_begin(BPy_ViewVertex *self) +{ + if (!self->vv) Py_RETURN_NONE; - - ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesBegin() ); - return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 0 ); + ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesBegin()); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, 0); } -static char ViewVertex_edgesEnd___doc__[] = -".. method:: edgesEnd()\n" +PyDoc_STRVAR(ViewVertex_edges_end_doc, +".. method:: edges_end()\n" "\n" " Returns an orientedViewEdgeIterator over the ViewEdges around this\n" " ViewVertex, pointing after the last ViewEdge.\n" "\n" " :return: An orientedViewEdgeIterator pointing after the last ViewEdge.\n" -" :rtype: :class:`orientedViewEdgeIterator`\n"; +" :rtype: :class:`orientedViewEdgeIterator`"); -static PyObject * ViewVertex_edgesEnd( BPy_ViewVertex *self ) { +static PyObject * ViewVertex_edges_end(BPy_ViewVertex *self) +{ #if 0 - if( !self->vv ) + if (!self->vv) Py_RETURN_NONE; - - ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesEnd() ); - return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 1 ); + ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesEnd()); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, 1); #else - PyErr_SetString(PyExc_NotImplementedError, "edgesEnd method currently disabled"); + PyErr_SetString(PyExc_NotImplementedError, "edges_end method currently disabled"); return NULL; #endif } -static char ViewVertex_edgesIterator___doc__[] = -".. method:: edgesIterator(iEdge)\n" +PyDoc_STRVAR(ViewVertex_edges_iterator_doc, +".. method:: edges_iterator(iEdge)\n" "\n" " Returns an orientedViewEdgeIterator pointing to the ViewEdge given\n" " as argument.\n" @@ -120,31 +97,58 @@ static char ViewVertex_edgesIterator___doc__[] = " :arg iEdge: A ViewEdge object.\n" " :type iEdge: :class:`ViewEdge`\n" " :return: An orientedViewEdgeIterator pointing to the given ViewEdge.\n" -" :rtype: :class:`orientedViewEdgeIterator`\n"; +" :rtype: :class:`orientedViewEdgeIterator`"); -static PyObject * ViewVertex_edgesIterator( BPy_ViewVertex *self, PyObject *args ) { +static PyObject * ViewVertex_edges_iterator(BPy_ViewVertex *self, PyObject *args) +{ PyObject *py_ve; - if( !self->vv ) + if (!self->vv) Py_RETURN_NONE; - - if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) + if (!PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve)) return NULL; - - ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve; - ViewVertexInternal::orientedViewEdgeIterator ove_it( self->vv->edgesIterator( ve ) ); - return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator( ove_it, 0 ); + ViewEdge *ve = ((BPy_ViewEdge *)py_ve)->ve; + ViewVertexInternal::orientedViewEdgeIterator ove_it(self->vv->edgesIterator(ve)); + return BPy_orientedViewEdgeIterator_from_orientedViewEdgeIterator(ove_it, 0); } -/*----------------------ViewVertex instance definitions ----------------------------*/ static PyMethodDef BPy_ViewVertex_methods[] = { - {"setNature", ( PyCFunction ) ViewVertex_setNature, METH_VARARGS, ViewVertex_setNature___doc__}, - {"edgesBegin", ( PyCFunction ) ViewVertex_edgesBegin, METH_NOARGS, ViewVertex_edgesBegin___doc__}, - {"edgesEnd", ( PyCFunction ) ViewVertex_edgesEnd, METH_NOARGS, ViewVertex_edgesEnd___doc__}, - {"edgesIterator", ( PyCFunction ) ViewVertex_edgesIterator, METH_VARARGS, ViewVertex_edgesIterator___doc__}, + {"edges_begin", (PyCFunction)ViewVertex_edges_begin, METH_NOARGS, ViewVertex_edges_begin_doc}, + {"edges_end", (PyCFunction)ViewVertex_edges_end, METH_NOARGS, ViewVertex_edges_end_doc}, + {"edges_iterator", (PyCFunction)ViewVertex_edges_iterator, METH_VARARGS, ViewVertex_edges_iterator_doc}, {NULL, NULL, 0, NULL} }; +/*----------------------ViewVertex get/setters ----------------------------*/ + +PyDoc_STRVAR(ViewVertex_nature_doc, +"The nature of this ViewVertex.\n" +"\n" +":type: :class:`Nature`"); + +static PyObject *ViewVertex_nature_get(BPy_ViewVertex *self, void *UNUSED(closure)) +{ + Nature::VertexNature nature = self->vv->getNature(); + if (PyErr_Occurred()) + return NULL; + return BPy_Nature_from_Nature(nature); // return a copy +} + +static int ViewVertex_nature_set(BPy_ViewVertex *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Nature_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a Nature"); + return -1; + } + self->vv->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); + return 0; +} + +static PyGetSetDef BPy_ViewVertex_getseters[] = { + {(char *)"nature", (getter)ViewVertex_nature_get, (setter)ViewVertex_nature_set, (char *)ViewVertex_nature_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ +}; + /*-----------------------BPy_ViewVertex type definition ------------------------------*/ PyTypeObject ViewVertex_Type = { PyVarObject_HEAD_INIT(NULL, 0) @@ -167,7 +171,7 @@ PyTypeObject ViewVertex_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewVertex___doc__, /* tp_doc */ + ViewVertex_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -176,13 +180,13 @@ PyTypeObject ViewVertex_Type = { 0, /* tp_iternext */ BPy_ViewVertex_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_ViewVertex_getseters, /* tp_getset */ &Interface0D_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)ViewVertex___init__, /* tp_init */ + (initproc)ViewVertex_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; 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 ebb2920353d..a0e0717ef37 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_NonTVertex.cpp @@ -9,9 +9,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------NonTVertex methods ----------------------------*/ -static char NonTVertex___doc__[] = +PyDoc_STRVAR(NonTVertex_doc, "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`NonTVertex`\n" "\n" "View vertex for corners, cusps, etc. associated to a single SVertex.\n" @@ -33,21 +33,20 @@ static char NonTVertex___doc__[] = " Builds a NonTVertex from a SVertex.\n" "\n" " :arg iSVertex: An SVertex object.\n" -" :type iSVertex: :class:`SVertex`\n"; +" :type iSVertex: :class:`SVertex`"); -static int NonTVertex___init__(BPy_NonTVertex *self, PyObject *args, PyObject *kwds) +static int NonTVertex_init(BPy_NonTVertex *self, PyObject *args, PyObject *kwds) { - PyObject *obj = 0; - if (! PyArg_ParseTuple(args, "|O!", &SVertex_Type, &obj) ) - return -1; + if (!PyArg_ParseTuple(args, "|O!", &SVertex_Type, &obj)) + return -1; - if( !obj ){ + if (!obj) { self->ntv = new NonTVertex(); - } else if( ((BPy_SVertex *) obj)->sv ) { - self->ntv = new NonTVertex( ((BPy_SVertex *) obj)->sv ); + } else if(((BPy_SVertex *)obj)->sv) { + self->ntv = new NonTVertex(((BPy_SVertex *)obj)->sv); } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); @@ -61,47 +60,38 @@ static int NonTVertex___init__(BPy_NonTVertex *self, PyObject *args, PyObject *k return 0; } -static char NonTVertex_svertex___doc__[] = -".. method:: svertex()\n" -"\n" -" Returns the SVertex on top of which this NonTVertex is built.\n" +static PyMethodDef BPy_NonTVertex_methods[] = { + {NULL, NULL, 0, NULL} +}; + +/*----------------------NonTVertex get/setters ----------------------------*/ + +PyDoc_STRVAR(NonTVertex_svertex_doc, +"The SVertex on top of which this NonTVertex is built.\n" "\n" -" :return: The SVertex on top of which this NonTVertex is built.\n" -" :rtype: :class:`SVertex`\n"; +":type: :class:`SVertex`"); -static PyObject * NonTVertex_svertex( BPy_NonTVertex *self ) { +static PyObject *NonTVertex_svertex_get(BPy_NonTVertex *self, void *UNUSED(closure)) +{ SVertex *v = self->ntv->svertex(); - if( v ){ - return BPy_SVertex_from_SVertex( *v ); - } - + if (v) + return BPy_SVertex_from_SVertex(*v); Py_RETURN_NONE; } -static char NonTVertex_setSVertex___doc__[] = -".. method:: setSVertex(iSVertex)\n" -"\n" -" Sets the SVertex on top of which this NonTVertex is built.\n" -"\n" -" :arg iSVertex: The SVertex on top of which this NonTVertex is built.\n" -" :type iSVertex: :class:`SVertex`\n"; - -static PyObject * NonTVertex_setSVertex( BPy_NonTVertex *self, PyObject *args) { - PyObject *py_sv; - - if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) - return NULL; - - self->ntv->setSVertex( ((BPy_SVertex *) py_sv)->sv ); - - Py_RETURN_NONE; +static int NonTVertex_svertex_set(BPy_NonTVertex *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->ntv->setSVertex(((BPy_SVertex *)value)->sv); + return 0; } -/*----------------------NonTVertex instance definitions ----------------------------*/ -static PyMethodDef BPy_NonTVertex_methods[] = { - {"svertex", ( PyCFunction ) NonTVertex_svertex, METH_NOARGS, NonTVertex_svertex___doc__}, - {"setSVertex", ( PyCFunction ) NonTVertex_setSVertex, METH_VARARGS, NonTVertex_setSVertex___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_NonTVertex_getseters[] = { + {(char *)"svertex", (getter)NonTVertex_svertex_get, (setter)NonTVertex_svertex_set, (char *)NonTVertex_svertex_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_NonTVertex type definition ------------------------------*/ @@ -126,7 +116,7 @@ PyTypeObject NonTVertex_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - NonTVertex___doc__, /* tp_doc */ + NonTVertex_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -135,13 +125,13 @@ PyTypeObject NonTVertex_Type = { 0, /* tp_iternext */ BPy_NonTVertex_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_NonTVertex_getseters, /* tp_getset */ &ViewVertex_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)NonTVertex___init__, /* tp_init */ + (initproc)NonTVertex_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; 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 14add743a37..55c8b64d13c 100644 --- a/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/ViewVertex/BPy_TVertex.cpp @@ -12,9 +12,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------TVertex methods ----------------------------*/ -static char TVertex___doc__[] = +PyDoc_STRVAR(TVertex_doc, "Class hierarchy: :class:`Interface0D` > :class:`ViewVertex` > :class:`TVertex`\n" "\n" "Class to define a T vertex, i.e. an intersection between two edges.\n" @@ -32,172 +32,145 @@ static char TVertex___doc__[] = " Copy constructor.\n" "\n" " :arg iBrother: A TVertex object.\n" -" :type iBrother: :class:`TVertex`\n"; +" :type iBrother: :class:`TVertex`"); -static int TVertex___init__(BPy_TVertex *self, PyObject *args, PyObject *kwds) +static int TVertex_init(BPy_TVertex *self, PyObject *args, PyObject *kwds) { - if( !PyArg_ParseTuple(args, "") ) - return -1; + if (!PyArg_ParseTuple(args, "")) + return -1; self->tv = new TVertex(); self->py_vv.vv = self->tv; self->py_vv.py_if0D.if0D = self->tv; self->py_vv.py_if0D.borrowed = 0; - return 0; } -static char TVertex_frontSVertex___doc__[] = -".. method:: frontSVertex()\n" +PyDoc_STRVAR(TVertex_get_svertex_doc, +".. method:: get_svertex(iFEdge)\n" "\n" -" Returns the SVertex that is closer to the viewpoint.\n" +" Returns the SVertex (among the 2) belonging to the given FEdge.\n" "\n" -" :return: The SVertex that is closer to the viewpoint.\n" -" :rtype: :class:`SVertex`\n"; +" :arg iFEdge: An FEdge object.\n" +" :type iFEdge: :class:`FEdge`\n" +" :return: The SVertex belonging to the given FEdge.\n" +" :rtype: :class:`SVertex`"); -static PyObject * TVertex_frontSVertex( BPy_TVertex *self ) { - SVertex *v = self->tv->frontSVertex(); - if( v ){ - return BPy_SVertex_from_SVertex( *v ); - } +static PyObject * TVertex_get_svertex( BPy_TVertex *self, PyObject *args) +{ + PyObject *py_fe; + if (!PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe)) + return NULL; + SVertex *sv = self->tv->getSVertex(((BPy_FEdge *)py_fe)->fe); + if (sv) + return BPy_SVertex_from_SVertex(*sv); Py_RETURN_NONE; } -static char TVertex_backSVertex___doc__[] = -".. method:: backSVertex()\n" +PyDoc_STRVAR(TVertex_get_mate_doc, +".. method:: get_mate(iEdgeA)\n" "\n" -" Returns the SVertex that is further away from the viewpoint.\n" +" Returns the mate edge of the ViewEdge given as argument. If the\n" +" ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n" +" frontEdgeB, frontEdgeA is returned. Same for back edges.\n" "\n" -" :return: The SVertex that is further away from the viewpoint.\n" -" :rtype: :class:`SVertex`\n"; +" :arg iEdgeA: A ViewEdge object.\n" +" :type iEdgeA: :class:`ViewEdge`\n" +" :return: The mate edge of the given ViewEdge.\n" +" :rtype: :class:`ViewEdge`"); -static PyObject * TVertex_backSVertex( BPy_TVertex *self ) { - SVertex *v = self->tv->backSVertex(); - if( v ){ - return BPy_SVertex_from_SVertex( *v ); - } +static PyObject * TVertex_get_mate( BPy_TVertex *self, PyObject *args) +{ + PyObject *py_ve; + if (!PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve)) + return NULL; + ViewEdge *ve = self->tv->mate(((BPy_ViewEdge *)py_ve)->ve); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); Py_RETURN_NONE; } -static char TVertex_setFrontSVertex___doc__[] = -".. method:: setFrontSVertex(iFrontSVertex)\n" -"\n" -" Sets the SVertex that is closer to the viewpoint.\n" -"\n" -" :arg iFrontSVertex: An SVertex object.\n" -" :type iFrontSVertex: :class:`SVertex`\n"; - -static PyObject * TVertex_setFrontSVertex( BPy_TVertex *self, PyObject *args) { - PyObject *py_sv; +static PyMethodDef BPy_TVertex_methods[] = { + {"get_svertex", (PyCFunction)TVertex_get_svertex, METH_VARARGS, TVertex_get_svertex_doc}, + {"get_mate", (PyCFunction)TVertex_get_mate, METH_VARARGS, TVertex_get_mate_doc}, + {NULL, NULL, 0, NULL} +}; - if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) - return NULL; +/*----------------------TVertex get/setters ----------------------------*/ - self->tv->setFrontSVertex( ((BPy_SVertex *) py_sv)->sv ); +PyDoc_STRVAR(TVertex_front_svertex_doc, +"The SVertex that is closer to the viewpoint.\n" +"\n" +":type: :class:`SVertex`"); +static PyObject *TVertex_front_svertex_get(BPy_TVertex *self, void *UNUSED(closure)) +{ + SVertex *v = self->tv->frontSVertex(); + if (v) + return BPy_SVertex_from_SVertex(*v); Py_RETURN_NONE; } -static char TVertex_setBackSVertex___doc__[] = -".. method:: setBackSVertex(iBackSVertex)\n" -"\n" -" Sets the SVertex that is further away from the viewpoint.\n" -"\n" -" :arg iBackSVertex: An SVertex object.\n" -" :type iBackSVertex: :class:`SVertex`\n"; - -static PyObject * TVertex_setBackSVertex( BPy_TVertex *self, PyObject *args) { - PyObject *py_sv; - - if(!( PyArg_ParseTuple(args, "O", &SVertex_Type, &py_sv) )) - return NULL; - - self->tv->setBackSVertex( ((BPy_SVertex *) py_sv)->sv ); - - Py_RETURN_NONE; +static int TVertex_front_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->tv->setFrontSVertex(((BPy_SVertex *)value)->sv); + return 0; } -static char TVertex_setId___doc__[] = -".. method:: setId(iId)\n" -"\n" -" Sets the Id.\n" +PyDoc_STRVAR(TVertex_back_svertex_doc, +"The SVertex that is further away from the viewpoint.\n" "\n" -" :arg iId: An Id object.\n" -" :type iId: :class:`Id`\n"; - -static PyObject * TVertex_setId( BPy_TVertex *self, PyObject *args) { - PyObject *py_id; - - if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) - return NULL; - - if( ((BPy_Id *) py_id)->id ) - self->tv->setId(*( ((BPy_Id *) py_id)->id )); +":type: :class:`SVertex`"); +static PyObject *TVertex_back_svertex_get(BPy_TVertex *self, void *UNUSED(closure)) +{ + SVertex *v = self->tv->backSVertex(); + if (v) + return BPy_SVertex_from_SVertex(*v); Py_RETURN_NONE; } -static char TVertex_getSVertex___doc__[] = -".. method:: getSVertex(iFEdge)\n" -"\n" -" Returns the SVertex (among the 2) belonging to the given FEdge.\n" -"\n" -" :arg iFEdge: An FEdge object.\n" -" :type iFEdge: :class:`FEdge`\n" -" :return: The SVertex belonging to the given FEdge.\n" -" :rtype: :class:`SVertex`\n"; - -static PyObject * TVertex_getSVertex( BPy_TVertex *self, PyObject *args) { - PyObject *py_fe; - - if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) - return NULL; - - SVertex *sv = self->tv->getSVertex( ((BPy_FEdge *) py_fe)->fe ); - if( sv ){ - return BPy_SVertex_from_SVertex( *sv ); +static int TVertex_back_svertex_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; } - - Py_RETURN_NONE; + self->tv->setBackSVertex(((BPy_SVertex *)value)->sv); + return 0; } -static char TVertex_mate___doc__[] = -".. method:: mate(iEdgeA)\n" -"\n" -" Returns the mate edge of the ViewEdge given as argument. If the\n" -" ViewEdge is frontEdgeA, frontEdgeB is returned. If the ViewEdge is\n" -" frontEdgeB, frontEdgeA is returned. Same for back edges.\n" +PyDoc_STRVAR(TVertex_id_doc, +"The Id of this TVertex.\n" "\n" -" :arg iEdgeA: A ViewEdge object.\n" -" :type iEdgeA: :class:`ViewEdge`\n" -" :return: The mate edge of the given ViewEdge.\n" -" :rtype: :class:`ViewEdge`\n"; +":type: :class:`Id`"); -static PyObject * TVertex_mate( BPy_TVertex *self, PyObject *args) { - PyObject *py_ve; - - if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) - return NULL; +static PyObject *TVertex_id_get(BPy_TVertex *self, void *UNUSED(closure)) +{ + Id id(self->tv->getId()); + return BPy_Id_from_Id(id); // return a copy +} - ViewEdge *ve = self->tv->mate( ((BPy_ViewEdge *) py_ve)->ve ); - if( ve ){ - return BPy_ViewEdge_from_ViewEdge( *ve ); +static int TVertex_id_set(BPy_TVertex *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; } - - Py_RETURN_NONE; + self->tv->setId(*(((BPy_Id *)value)->id)); + return 0; } -/*----------------------TVertex instance definitions ----------------------------*/ -static PyMethodDef BPy_TVertex_methods[] = { - {"frontSVertex", ( PyCFunction ) TVertex_frontSVertex, METH_NOARGS, TVertex_frontSVertex___doc__}, - {"backSVertex", ( PyCFunction ) TVertex_backSVertex, METH_NOARGS, TVertex_backSVertex___doc__}, - {"setFrontSVertex", ( PyCFunction ) TVertex_setFrontSVertex, METH_VARARGS, TVertex_setFrontSVertex___doc__}, - {"setBackSVertex", ( PyCFunction ) TVertex_setBackSVertex, METH_VARARGS, TVertex_setBackSVertex___doc__}, - {"setId", ( PyCFunction ) TVertex_setId, METH_VARARGS, TVertex_setId___doc__}, - {"getSVertex", ( PyCFunction ) TVertex_getSVertex, METH_VARARGS, TVertex_getSVertex___doc__}, - {"mate", ( PyCFunction ) TVertex_mate, METH_VARARGS, TVertex_mate___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_TVertex_getseters[] = { + {(char *)"front_svertex", (getter)TVertex_front_svertex_get, (setter)TVertex_front_svertex_set, (char *)TVertex_front_svertex_doc, NULL}, + {(char *)"back_svertex", (getter)TVertex_back_svertex_get, (setter)TVertex_back_svertex_set, (char *)TVertex_back_svertex_doc, NULL}, + {(char *)"id", (getter)TVertex_id_get, (setter)TVertex_id_set, (char *)TVertex_id_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_TVertex type definition ------------------------------*/ @@ -222,7 +195,7 @@ PyTypeObject TVertex_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - TVertex___doc__, /* tp_doc */ + TVertex_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -231,13 +204,13 @@ PyTypeObject TVertex_Type = { 0, /* tp_iternext */ BPy_TVertex_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_TVertex_getseters, /* tp_getset */ &ViewVertex_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)TVertex___init__, /* tp_init */ + (initproc)TVertex_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; |