diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-15 03:48:34 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-02-15 03:48:34 +0400 |
commit | 731d08d4974ce695e7d1446b934d0656a4d82942 (patch) | |
tree | 6568f2d1befa6c4cac0005bc4dcf3e239363757f /source/blender/freestyle/intern/python/Interface1D | |
parent | 9e3bf44011285917db1e1061a2f459722674b1b9 (diff) |
Freestyle Python API improvements - part 3.
Major API updates were made to address code review comments.
This revision mostly focuses on Python wrappers of C++ 0D and 1D elements (i.e.,
Interface0D and Interface1D, as well as their subclasses).
* Most getter/setter methods were reimplemented as attributes using PyGetSetDef.
Vector attributes are now implemented based on mathutils callbacks. Boolean
attributes now only accept boolean values.
* The __getitem__ method was removed and the Sequence protocol was used instead.
* The naming of methods and attributes was fixed to follow the naming conventions
of the Blender Python API (i.e., lower case + underscores for methods and attributes,
and CamelCase for classes). Some naming inconsistency within the Freestyle Python
API was also addressed.
* The Freestyle API had a number of method names including prefix/suffix "A" and
"B", and their meanings were inconsistent (i.e., referring to different things
depending on the classes). The names with these two letters were replaced with
more straightforward names. Also some attribute names were changed so as to indicate
the type of the value (e.g., FEdge.next_fedge instead of FEdge.next_edge) in line
with other names explicitly indicating what the value is (e.g., SVertex.viewvertex).
* In addition, some code clean-up was done in both C++ and Python.
Notes:
In summary, the following irregular naming changes were made through this revision
(those resulting from regular changes of naming conventions are not listed):
- CurvePoint: {A,B} --> {first,second}_svertex
- FEdge: vertex{A,B} --> {first,second}_svertex
- FEdge: {next,previous}Edge --> {next,previous}_fedge
- FEdgeSharp: normal{A,B} --> normal_{right,left}
- FEdgeSharp: {a,b}FaceMark --> face_mark_{right,left}
- FEdgeSharp: {a,b}Material --> material_{right,left}
- FEdgeSharp: {a,b}MaterialIndex --> material_index_{right,left}
- FrsCurve: empty --> is_empty
- FrsCurve: nSegments --> segments_size
- TVertex: mate() --> get_mate()
- ViewEdge: fedge{A,B} --> {first,last}_fedge
- ViewEdge: setaShape, aShape --> occlude
- ViewEdge: {A,B} --> {first,last}_viewvertex
- ViewMap: getScene3dBBox --> scene_bbox
Diffstat (limited to 'source/blender/freestyle/intern/python/Interface1D')
8 files changed, 1025 insertions, 1203 deletions
diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp index a7b710f796b..be3d97f5f78 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FEdge.cpp @@ -12,9 +12,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- - -static char FEdge___doc__[] = +/*----------------------FEdge methods ----------------------------*/ + +PyDoc_STRVAR(FEdge_doc, "Class hierarchy: :class:`Interface1D` > :class:`FEdge`\n" "\n" "Base Class for feature edges. This FEdge can represent a silhouette,\n" @@ -45,23 +45,23 @@ static char FEdge___doc__[] = " :arg vA: The first SVertex.\n" " :type vA: :class:`SVertex`\n" " :arg vB: The second SVertex.\n" -" :type vB: :class:`SVertex`\n"; +" :type vB: :class:`SVertex`"); -static int FEdge___init__(BPy_FEdge *self, PyObject *args, PyObject *kwds) +static int FEdge_init(BPy_FEdge *self, PyObject *args, PyObject *kwds) { PyObject *obj1 = 0, *obj2 = 0; - if (! PyArg_ParseTuple(args, "|OO", &obj1, &obj2) ) - return -1; + if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) + return -1; - if( !obj1 ){ + if (!obj1) { self->fe = new FEdge(); - } else if( !obj2 && BPy_FEdge_Check(obj1) ) { - self->fe = new FEdge(*( ((BPy_FEdge *) obj1)->fe )); - - } else if( obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { - self->fe = new FEdge( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv ); + } else if(!obj2 && BPy_FEdge_Check(obj1)) { + self->fe = new FEdge(*(((BPy_FEdge *)obj1)->fe)); + + } else if(obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) { + self->fe = new FEdge(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); @@ -74,296 +74,234 @@ static int FEdge___init__(BPy_FEdge *self, PyObject *args, PyObject *kwds) return 0; } -static char FEdge_vertexA___doc__[] = -".. method:: vertexA()\n" -"\n" -" Returns the first SVertex.\n" -"\n" -" :return: The first SVertex.\n" -" :rtype: :class:`SVertex`\n"; +static PyMethodDef BPy_FEdge_methods[] = { + {NULL, NULL, 0, NULL} +}; -static PyObject * FEdge_vertexA( BPy_FEdge *self ) { - SVertex *A = self->fe->vertexA(); - if( A ){ - return BPy_SVertex_from_SVertex( *A ); - } - - Py_RETURN_NONE; -} +/*----------------------FEdge sequence protocol ----------------------------*/ -static char FEdge_vertexB___doc__[] = -".. method:: vertexB()\n" -"\n" -" Returns the second SVertex.\n" -"\n" -" :return: The second SVertex.\n" -" :rtype: :class:`SVertex`\n"; +static Py_ssize_t FEdge_sq_length(BPy_FEdge *self) +{ + return 2; +} -static PyObject * FEdge_vertexB( BPy_FEdge *self ) { - SVertex *B = self->fe->vertexB(); - if( B ){ - return BPy_SVertex_from_SVertex( *B ); +static PyObject *FEdge_sq_item(BPy_FEdge *self, int keynum) +{ + if (keynum < 0) + keynum += FEdge_sq_length(self); + if (keynum == 0 || keynum == 1) { + SVertex *v = self->fe->operator[](keynum); + if (v) + return BPy_SVertex_from_SVertex(*v); + Py_RETURN_NONE; } - - Py_RETURN_NONE; + PyErr_Format(PyExc_IndexError, "FEdge[index]: index %d out of range", keynum); + return NULL; } +static PySequenceMethods BPy_FEdge_as_sequence = { + (lenfunc)FEdge_sq_length, /* sq_length */ + NULL, /* sq_concat */ + NULL, /* sq_repeat */ + (ssizeargfunc)FEdge_sq_item, /* sq_item */ + NULL, /* sq_slice */ + NULL, /* sq_ass_item */ + NULL, /* *was* sq_ass_slice */ + NULL, /* sq_contains */ + NULL, /* sq_inplace_concat */ + NULL, /* sq_inplace_repeat */ +}; -static PyObject * FEdge___getitem__( BPy_FEdge *self, PyObject *args ) { - int i; - - if(!( PyArg_ParseTuple(args, "i", &i) )) - return NULL; - if(!(i == 0 || i == 1)) { - PyErr_SetString(PyExc_IndexError, "index must be either 0 or 1"); - return NULL; - } - - SVertex *v = self->fe->operator[](i); - if( v ) - return BPy_SVertex_from_SVertex( *v ); - - Py_RETURN_NONE; -} +/*----------------------FEdge get/setters ----------------------------*/ -static char FEdge_nextEdge___doc__[] = -".. method:: nextEdge()\n" +PyDoc_STRVAR(FEdge_first_svertex_doc, +"The first SVertex constituting this FEdge.\n" "\n" -" Returns the FEdge following this one in the ViewEdge. If this FEdge\n" -" is the last of the ViewEdge, None is returned.\n" -"\n" -" :return: The edge following this one in the ViewEdge.\n" -" :rtype: :class:`FEdge`\n"; - -static PyObject * FEdge_nextEdge( BPy_FEdge *self ) { - FEdge *fe = self->fe->nextEdge(); - if( fe ) - return Any_BPy_FEdge_from_FEdge( *fe ); +":type: :class:`SVertex`"); +static PyObject *FEdge_first_svertex_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + SVertex *A = self->fe->vertexA(); + if (A) + return BPy_SVertex_from_SVertex(*A); Py_RETURN_NONE; } -static char FEdge_previousEdge___doc__[] = -".. method:: previousEdge()\n" -"\n" -" Returns the FEdge preceding this one in the ViewEdge. If this FEdge\n" -" is the first one of the ViewEdge, None is returned.\n" -"\n" -" :return: The edge preceding this one in the ViewEdge.\n" -" :rtype: :class:`FEdge`\n"; - -static PyObject * FEdge_previousEdge( BPy_FEdge *self ) { - FEdge *fe = self->fe->previousEdge(); - if( fe ) - return Any_BPy_FEdge_from_FEdge( *fe ); - - Py_RETURN_NONE; +static int FEdge_first_svertex_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->fe->setVertexA(((BPy_SVertex *)value)->sv); + return 0; } -static char FEdge_viewedge___doc__[] = -".. method:: viewedge()\n" -"\n" -" Returns the ViewEdge to which this FEdge belongs to.\n" +PyDoc_STRVAR(FEdge_second_svertex_doc, +"The second SVertex constituting this FEdge.\n" "\n" -" :return: The ViewEdge to which this FEdge belongs to.\n" -" :rtype: :class:`ViewEdge`\n"; - -static PyObject * FEdge_viewedge( BPy_FEdge *self ) { - ViewEdge *ve = self->fe->viewedge(); - if( ve ) - return BPy_ViewEdge_from_ViewEdge( *ve ); +":type: :class:`SVertex`"); +static PyObject *FEdge_second_svertex_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + SVertex *B = self->fe->vertexB(); + if (B) + return BPy_SVertex_from_SVertex(*B); Py_RETURN_NONE; } -static char FEdge_isSmooth___doc__[] = -".. method:: isSmooth()\n" -"\n" -" Returns true if this FEdge is a smooth FEdge.\n" -"\n" -" :return: True if this FEdge is a smooth FEdge.\n" -" :rtype: bool\n"; - -static PyObject * FEdge_isSmooth( BPy_FEdge *self ) { - return PyBool_from_bool( self->fe->isSmooth() ); +static int FEdge_second_svertex_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_SVertex_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an SVertex"); + return -1; + } + self->fe->setVertexB(((BPy_SVertex *)value)->sv); + return 0; } - -static char FEdge_setVertexA___doc__[] = -".. method:: setVertexA(vA)\n" -"\n" -" Sets the first SVertex.\n" -"\n" -" :arg vA: An SVertex object.\n" -" :type vA: :class:`SVertex`\n"; - -static PyObject *FEdge_setVertexA( BPy_FEdge *self , PyObject *args) { - PyObject *py_sv; - if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) )) - return NULL; - - self->fe->setVertexA( ((BPy_SVertex *) py_sv)->sv ); +PyDoc_STRVAR(FEdge_next_fedge_doc, +"The FEdge following this one in the ViewEdge. The value is None if\n" +"this FEdge is the last of the ViewEdge.\n" +"\n" +":type: :class:`FEdge`"); +static PyObject *FEdge_next_fedge_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + FEdge *fe = self->fe->nextEdge(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); Py_RETURN_NONE; } -static char FEdge_setVertexB___doc__[] = -".. method:: setVertexB(vB)\n" -"\n" -" Sets the second SVertex.\n" -"\n" -" :arg vB: An SVertex object.\n" -" :type vB: :class:`SVertex`\n"; - -static PyObject *FEdge_setVertexB( BPy_FEdge *self , PyObject *args) { - PyObject *py_sv; - - if(!( PyArg_ParseTuple(args, "O", &py_sv) && BPy_SVertex_Check(py_sv) )) { - cout << "ERROR: FEdge_setVertexB" << endl; - Py_RETURN_NONE; +static int FEdge_next_fedge_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_FEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an FEdge"); + return -1; } - - self->fe->setVertexB( ((BPy_SVertex *) py_sv)->sv ); - - Py_RETURN_NONE; + self->fe->setNextEdge(((BPy_FEdge *)value)->fe); + return 0; } -static char FEdge_setId___doc__[] = -".. method:: setId(id)\n" -"\n" -" Sets the Id of this FEdge.\n" +PyDoc_STRVAR(FEdge_previous_fedge_doc, +"The FEdge preceding this one in the ViewEdge. The value is None if\n" +"this FEdge is the first one of the ViewEdge.\n" "\n" -" :arg id: An Id object.\n" -" :type id: :class:`Id`\n"; - -static PyObject *FEdge_setId( BPy_FEdge *self , PyObject *args) { - PyObject *py_id; - - if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) - return NULL; - - self->fe->setId(*( ((BPy_Id *) py_id)->id )); +":type: :class:`FEdge`"); +static PyObject *FEdge_previous_fedge_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + FEdge *fe = self->fe->previousEdge(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); Py_RETURN_NONE; } -static char FEdge_setNextEdge___doc__[] = -".. method:: setNextEdge(iEdge)\n" -"\n" -" Sets the pointer to the next FEdge.\n" -"\n" -" :arg iEdge: An FEdge object.\n" -" :type iEdge: :class:`FEdge`\n"; - -static PyObject *FEdge_setNextEdge( BPy_FEdge *self , PyObject *args) { - PyObject *py_fe; - - if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) - return NULL; - - self->fe->setNextEdge( ((BPy_FEdge *) py_fe)->fe ); - - Py_RETURN_NONE; +static int FEdge_previous_fedge_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_FEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an FEdge"); + return -1; + } + self->fe->setPreviousEdge(((BPy_FEdge *)value)->fe); + return 0; } -static char FEdge_setPreviousEdge___doc__[] = -".. method:: setPreviousEdge(iEdge)\n" +PyDoc_STRVAR(FEdge_viewedge_doc, +"The ViewEdge to which this FEdge belongs to.\n" "\n" -" Sets the pointer to the previous FEdge.\n" -"\n" -" :arg iEdge: An FEdge object.\n" -" :type iEdge: :class:`FEdge`\n"; - -static PyObject *FEdge_setPreviousEdge( BPy_FEdge *self , PyObject *args) { - PyObject *py_fe; - - if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) - return NULL; - - self->fe->setPreviousEdge( ((BPy_FEdge *) py_fe)->fe ); +":type: :class:`ViewEdge`"); +static PyObject *FEdge_viewedge_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + ViewEdge *ve = self->fe->viewedge(); + if (ve) + return BPy_ViewEdge_from_ViewEdge(*ve); Py_RETURN_NONE; } -static char FEdge_setNature___doc__[] = -".. method:: setNature(iNature)\n" -"\n" -" Sets the nature of this FEdge.\n" -"\n" -" :arg iNature: A Nature object.\n" -" :type iNature: :class:`Nature`\n"; +static int FEdge_viewedge_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_ViewEdge_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an ViewEdge"); + return -1; + } + self->fe->setViewEdge(((BPy_ViewEdge *)value)->ve); + return 0; +} -static PyObject * FEdge_setNature( BPy_FEdge *self, PyObject *args ) { - PyObject *py_n; +PyDoc_STRVAR(FEdge_is_smooth_doc, +"True if this FEdge is a smooth FEdge.\n" +"\n" +":type: bool"); - if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) )) - return NULL; - - PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i ); - self->fe->setNature( PyLong_AsLong(i) ); +static PyObject *FEdge_is_smooth_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->fe->isSmooth()); +} - Py_RETURN_NONE; +static int FEdge_is_smooth_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!PyBool_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be boolean"); + return -1; + } + self->fe->setSmooth(bool_from_PyBool(value)); + return 0; } -static char FEdge_setViewEdge___doc__[] = -".. method:: setViewEdge(iViewEdge)\n" -"\n" -" Sets the ViewEdge to which this FEdge belongs to.\n" +PyDoc_STRVAR(FEdge_id_doc, +"The Id of this FEdge.\n" "\n" -" :arg iViewEdge: A ViewEdge object.\n" -" :type iViewEdge: :class:`ViewEdge`\n"; +":type: :class:`Id`"); -static PyObject * FEdge_setViewEdge( BPy_FEdge *self, PyObject *args ) { - PyObject *py_ve; - - if(!( PyArg_ParseTuple(args, "O!", &ViewEdge_Type, &py_ve) )) - return NULL; - - ViewEdge *ve = ((BPy_ViewEdge *) py_ve)->ve; - self->fe->setViewEdge( ve ); +static PyObject *FEdge_id_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + Id id(self->fe->getId()); + return BPy_Id_from_Id(id); // return a copy +} - Py_RETURN_NONE; +static int FEdge_id_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->fe->setId(*(((BPy_Id *)value)->id)); + return 0; } -static char FEdge_setSmooth___doc__[] = -".. method:: setSmooth(iFlag)\n" -"\n" -" Sets the flag telling whether this FEdge is smooth or sharp. True\n" -" for Smooth, false for Sharp.\n" +PyDoc_STRVAR(FEdge_nature_doc, +"The nature of this FEdge.\n" "\n" -" :arg iFlag: True for Smooth, false for Sharp.\n" -" :type iFlag: bool\n"; - -static PyObject *FEdge_setSmooth( BPy_FEdge *self , PyObject *args) { - PyObject *py_b; - - if(!( PyArg_ParseTuple(args, "O", &py_b) )) - return NULL; +":type: :class:`Nature`"); - self->fe->setSmooth( bool_from_PyBool(py_b) ); +static PyObject *FEdge_nature_get(BPy_FEdge *self, void *UNUSED(closure)) +{ + return BPy_Nature_from_Nature(self->fe->getNature()); +} - Py_RETURN_NONE; +static int FEdge_nature_set(BPy_FEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Nature_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a Nature"); + return -1; + } + self->fe->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); + return 0; } -/*----------------------FEdge instance definitions ----------------------------*/ - -static PyMethodDef BPy_FEdge_methods[] = { - {"vertexA", ( PyCFunction ) FEdge_vertexA, METH_NOARGS, FEdge_vertexA___doc__}, - {"vertexB", ( PyCFunction ) FEdge_vertexB, METH_NOARGS, FEdge_vertexB___doc__}, - {"__getitem__", ( PyCFunction ) FEdge___getitem__, METH_VARARGS, "(int i) Returns the first SVertex if i=0, the seccond SVertex if i=1."}, - {"nextEdge", ( PyCFunction ) FEdge_nextEdge, METH_NOARGS, FEdge_nextEdge___doc__}, - {"previousEdge", ( PyCFunction ) FEdge_previousEdge, METH_NOARGS, FEdge_previousEdge___doc__}, - {"viewedge", ( PyCFunction ) FEdge_viewedge, METH_NOARGS, FEdge_viewedge___doc__}, - {"isSmooth", ( PyCFunction ) FEdge_isSmooth, METH_NOARGS, FEdge_isSmooth___doc__}, - {"setVertexA", ( PyCFunction ) FEdge_setVertexA, METH_VARARGS, FEdge_setVertexA___doc__}, - {"setVertexB", ( PyCFunction ) FEdge_setVertexB, METH_VARARGS, FEdge_setVertexB___doc__}, - {"setId", ( PyCFunction ) FEdge_setId, METH_VARARGS, FEdge_setId___doc__}, - {"setNextEdge", ( PyCFunction ) FEdge_setNextEdge, METH_VARARGS, FEdge_setNextEdge___doc__}, - {"setPreviousEdge", ( PyCFunction ) FEdge_setPreviousEdge, METH_VARARGS, FEdge_setPreviousEdge___doc__}, - {"setSmooth", ( PyCFunction ) FEdge_setSmooth, METH_VARARGS, FEdge_setSmooth___doc__}, - {"setViewEdge", ( PyCFunction ) FEdge_setViewEdge, METH_VARARGS, FEdge_setViewEdge___doc__}, - {"setNature", ( PyCFunction ) FEdge_setNature, METH_VARARGS, FEdge_setNature___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_FEdge_getseters[] = { + {(char *)"first_svertex", (getter)FEdge_first_svertex_get, (setter)FEdge_first_svertex_set, (char *)FEdge_first_svertex_doc, NULL}, + {(char *)"second_svertex", (getter)FEdge_second_svertex_get, (setter)FEdge_second_svertex_set, (char *)FEdge_second_svertex_doc, NULL}, + {(char *)"next_fedge", (getter)FEdge_next_fedge_get, (setter)FEdge_next_fedge_set, (char *)FEdge_next_fedge_doc, NULL}, + {(char *)"previous_fedge", (getter)FEdge_previous_fedge_get, (setter)FEdge_previous_fedge_set, (char *)FEdge_previous_fedge_doc, NULL}, + {(char *)"viewedge", (getter)FEdge_viewedge_get, (setter)FEdge_viewedge_set, (char *)FEdge_viewedge_doc, NULL}, + {(char *)"is_smooth", (getter)FEdge_is_smooth_get, (setter)FEdge_is_smooth_set, (char *)FEdge_is_smooth_doc, NULL}, + {(char *)"id", (getter)FEdge_id_get, (setter)FEdge_id_set, (char *)FEdge_id_doc, NULL}, + {(char *)"nature", (getter)FEdge_nature_get, (setter)FEdge_nature_set, (char *)FEdge_nature_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FEdge type definition ------------------------------*/ @@ -380,7 +318,7 @@ PyTypeObject FEdge_Type = { 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ - 0, /* tp_as_sequence */ + &BPy_FEdge_as_sequence, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -389,7 +327,7 @@ PyTypeObject FEdge_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FEdge___doc__, /* tp_doc */ + FEdge_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -398,13 +336,13 @@ PyTypeObject FEdge_Type = { 0, /* tp_iternext */ BPy_FEdge_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_FEdge_getseters, /* tp_getset */ &Interface1D_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)FEdge___init__, /* tp_init */ + (initproc)FEdge_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp index 5b20db3a267..e5b984e41bd 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_FrsCurve.cpp @@ -11,9 +11,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------CurvePoint methods ----------------------------*/ -static char FrsCurve___doc__[] = +PyDoc_STRVAR(FrsCurve_doc, "Class hierarchy: :class:`Interface1D` > :class:`Curve`\n" "\n" "Base class for curves made of CurvePoints. :class:`SVertex` is the\n" @@ -36,25 +36,25 @@ static char FrsCurve___doc__[] = " Builds a Curve from its Id.\n" "\n" " :arg iId: An Id object.\n" -" :type iId: :class:`Id`\n"; +" :type iId: :class:`Id`"); -static int FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) +static int FrsCurve_init(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) { PyObject *obj = 0; - if (! PyArg_ParseTuple(args, "|O", &obj) ) - return -1; + if (!PyArg_ParseTuple(args, "|O", &obj)) + return -1; - if( !obj ){ + if (!obj) { self->c = new Curve(); - - } else if( BPy_FrsCurve_Check(obj) ) { + + } else if (BPy_FrsCurve_Check(obj)) { self->c = new Curve(*( ((BPy_FrsCurve *) obj)->c )); - - } else if( BPy_Id_Check(obj) ) { + + } else if (BPy_Id_Check(obj)) { self->c = new Curve(*( ((BPy_Id *) obj)->id )); - + } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return -1; @@ -66,24 +66,25 @@ static int FrsCurve___init__(BPy_FrsCurve *self, PyObject *args, PyObject *kwds) return 0; } -static char FrsCurve_push_vertex_back___doc__[] = +PyDoc_STRVAR(FrsCurve_push_vertex_back_doc, ".. method:: push_vertex_back(iVertex)\n" "\n" " Adds a single vertex at the end of the Curve.\n" "\n" " :arg iVertex: A vertex object.\n" -" :type iVertex: :class:`SVertex` or :class:`CurvePoint`\n"; +" :type iVertex: :class:`SVertex` or :class:`CurvePoint`"); -static PyObject * FrsCurve_push_vertex_back( BPy_FrsCurve *self, PyObject *args ) { +static PyObject * FrsCurve_push_vertex_back( BPy_FrsCurve *self, PyObject *args ) +{ PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &obj) )) + if (!PyArg_ParseTuple(args, "O", &obj)) return NULL; - if( BPy_CurvePoint_Check(obj) ) { - self->c->push_vertex_back( ((BPy_CurvePoint *) obj)->cp ); - } else if( BPy_SVertex_Check(obj) ) { - self->c->push_vertex_back( ((BPy_SVertex *) obj)->sv ); + if (BPy_CurvePoint_Check(obj)) { + self->c->push_vertex_back(((BPy_CurvePoint *)obj)->cp); + } else if (BPy_SVertex_Check(obj)) { + self->c->push_vertex_back(((BPy_SVertex *)obj)->sv); } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return NULL; @@ -92,24 +93,25 @@ static PyObject * FrsCurve_push_vertex_back( BPy_FrsCurve *self, PyObject *args Py_RETURN_NONE; } -static char FrsCurve_push_vertex_front___doc__[] = +PyDoc_STRVAR(FrsCurve_push_vertex_front_doc, ".. method:: push_vertex_front(iVertex)\n" "\n" " Adds a single vertex at the front of the Curve.\n" "\n" " :arg iVertex: A vertex object.\n" -" :type iVertex: :class:`SVertex` or :class:`CurvePoint`\n"; +" :type iVertex: :class:`SVertex` or :class:`CurvePoint`"); -static PyObject * FrsCurve_push_vertex_front( BPy_FrsCurve *self, PyObject *args ) { +static PyObject * FrsCurve_push_vertex_front( BPy_FrsCurve *self, PyObject *args ) +{ PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &obj) )) + if (!PyArg_ParseTuple(args, "O", &obj)) return NULL; - if( BPy_CurvePoint_Check(obj) ) { - self->c->push_vertex_front( ((BPy_CurvePoint *) obj)->cp ); - } else if( BPy_SVertex_Check(obj) ) { - self->c->push_vertex_front( ((BPy_SVertex *) obj)->sv ); + if (BPy_CurvePoint_Check(obj)) { + self->c->push_vertex_front(((BPy_CurvePoint *)obj)->cp); + } else if( BPy_SVertex_Check(obj)) { + self->c->push_vertex_front(((BPy_SVertex *)obj)->sv); } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return NULL; @@ -118,38 +120,38 @@ static PyObject * FrsCurve_push_vertex_front( BPy_FrsCurve *self, PyObject *args Py_RETURN_NONE; } -static char FrsCurve_empty___doc__[] = -".. method:: empty()\n" -"\n" -" Returns true if the Curve doesn't have any Vertex yet.\n" +static PyMethodDef BPy_FrsCurve_methods[] = { + {"push_vertex_back", (PyCFunction)FrsCurve_push_vertex_back, METH_VARARGS, FrsCurve_push_vertex_back_doc}, + {"push_vertex_front", (PyCFunction)FrsCurve_push_vertex_front, METH_VARARGS, FrsCurve_push_vertex_front_doc}, + {NULL, NULL, 0, NULL} +}; + +/*----------------------CurvePoint get/setters ----------------------------*/ + +PyDoc_STRVAR(FrsCurve_is_empty_doc, +"True if the Curve doesn't have any Vertex yet.\n" "\n" -" :return: True if the Curve has no vertices.\n" -" :rtype: bool\n"; +":type: bool"); -static PyObject * FrsCurve_empty( BPy_FrsCurve *self ) { - return PyBool_from_bool( self->c->empty() ); +static PyObject *FrsCurve_is_empty_get(BPy_FrsCurve *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->c->empty()); } -static char FrsCurve_nSegments___doc__[] = -".. method:: nSegments()\n" +PyDoc_STRVAR(FrsCurve_segments_size_doc, +"The number of segments in the polyline constituing the Curve.\n" "\n" -" Returns the number of segments in the polyline constituing the\n" -" Curve.\n" -"\n" -" :return: The number of segments.\n" -" :rtype: int\n"; +":type: int"); -static PyObject * FrsCurve_nSegments( BPy_FrsCurve *self ) { - return PyLong_FromLong( self->c->nSegments() ); +static PyObject *FrsCurve_segments_size_get(BPy_FrsCurve *self, void *UNUSED(closure)) +{ + return PyLong_FromLong(self->c->nSegments()); } -/*----------------------FrsCurve instance definitions ----------------------------*/ -static PyMethodDef BPy_FrsCurve_methods[] = { - {"push_vertex_back", ( PyCFunction ) FrsCurve_push_vertex_back, METH_VARARGS, FrsCurve_push_vertex_back___doc__}, - {"push_vertex_front", ( PyCFunction ) FrsCurve_push_vertex_front, METH_VARARGS, FrsCurve_push_vertex_front___doc__}, - {"empty", ( PyCFunction ) FrsCurve_empty, METH_NOARGS, FrsCurve_empty___doc__}, - {"nSegments", ( PyCFunction ) FrsCurve_nSegments, METH_NOARGS, FrsCurve_nSegments___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_FrsCurve_getseters[] = { + {(char *)"is_empty", (getter)FrsCurve_is_empty_get, (setter)NULL, (char *)FrsCurve_is_empty_doc, NULL}, + {(char *)"segments_size", (getter)FrsCurve_segments_size_get, (setter)NULL, (char *)FrsCurve_segments_size_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FrsCurve type definition ------------------------------*/ @@ -175,7 +177,7 @@ PyTypeObject FrsCurve_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FrsCurve___doc__, /* tp_doc */ + FrsCurve_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -184,13 +186,13 @@ PyTypeObject FrsCurve_Type = { 0, /* tp_iternext */ BPy_FrsCurve_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_FrsCurve_getseters, /* tp_getset */ &Interface1D_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)FrsCurve___init__, /* tp_init */ + (initproc)FrsCurve_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp index fe215588275..f0cc91b9a79 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_Stroke.cpp @@ -13,7 +13,7 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------Stroke methods ----------------------------*/ // Stroke () // template<class InputVertexIterator> Stroke (InputVertexIterator iBegin, InputVertexIterator iEnd) @@ -21,7 +21,7 @@ extern "C" { // pb: - need to be able to switch representation: InputVertexIterator <=> position // - is it even used ? not even in SWIG version -static char Stroke___doc__[] = +PyDoc_STRVAR(Stroke_doc, "Class hierarchy: :class:`Interface1D` > :class:`Stroke`\n" "\n" "Class to define a stroke. A stroke is made of a set of 2D vertices\n" @@ -49,25 +49,26 @@ static char Stroke___doc__[] = " :arg iBegin: The iterator pointing to the first vertex.\n" " :type iBegin: InputVertexIterator\n" " :arg iEnd: The iterator pointing to the end of the vertex list.\n" -" :type iEnd: InputVertexIterator\n"; +" :type iEnd: InputVertexIterator"); -static int Stroke___init__(BPy_Stroke *self, PyObject *args, PyObject *kwds) +static int Stroke_init(BPy_Stroke *self, PyObject *args, PyObject *kwds) { PyObject *obj1 = NULL, *obj2 = NULL; - if (! PyArg_ParseTuple(args, "|OO", &obj1, &obj2) ) - return -1; + if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) + return -1; - if( !obj1 ){ + if (!obj1) { self->s = new Stroke(); - } else if ( !obj2 && BPy_Stroke_Check(obj1) ) { - self->s = new Stroke(*( ((BPy_Stroke *)obj1)->s )); + } else if (!obj2 && BPy_Stroke_Check(obj1)) { + self->s = new Stroke(*(((BPy_Stroke *)obj1)->s)); - } else if ( obj2 ) { + } else if (obj2) { PyErr_SetString(PyExc_TypeError, "Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd) not implemented"); return -1; + } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; @@ -79,41 +80,30 @@ static int Stroke___init__(BPy_Stroke *self, PyObject *args, PyObject *kwds) return 0; } -static PyObject * Stroke___iter__( PyObject *self ) { +static PyObject * Stroke_iter(PyObject *self) +{ StrokeInternal::StrokeVertexIterator sv_it( ((BPy_Stroke *)self)->s->strokeVerticesBegin() ); return BPy_StrokeVertexIterator_from_StrokeVertexIterator( sv_it, 0 ); } -static Py_ssize_t Stroke_length( BPy_Stroke *self ) { +static Py_ssize_t Stroke_sq_length(BPy_Stroke *self) +{ return self->s->strokeVerticesSize(); } -static PyObject * Stroke_item( BPy_Stroke *self, Py_ssize_t i ) { - if (i < 0 || i >= (Py_ssize_t)self->s->strokeVerticesSize()) { - PyErr_SetString(PyExc_IndexError, "subscript index out of range"); - return NULL; - } - return BPy_StrokeVertex_from_StrokeVertex( self->s->strokeVerticeAt(i) ); -} - -static PyObject * Stroke___getitem__( BPy_Stroke *self, PyObject *item ) { - long i; - - if (!PyLong_Check(item)) { - PyErr_SetString(PyExc_TypeError, "subscript indices must be integers"); - return NULL; - } - i = PyLong_AsLong(item); - if (i == -1 && PyErr_Occurred()) +static PyObject *Stroke_sq_item(BPy_Stroke *self, int keynum) +{ + if (keynum < 0) + keynum += Stroke_sq_length(self); + if (keynum < 0 || keynum >= Stroke_sq_length(self)) { + PyErr_Format(PyExc_IndexError, "Stroke[index]: index %d out of range", keynum); return NULL; - if (i < 0) { - i += self->s->strokeVerticesSize(); } - return Stroke_item(self, i); + return BPy_StrokeVertex_from_StrokeVertex(self->s->strokeVerticeAt(keynum)); } -static char Stroke_ComputeSampling___doc__[] = -".. method:: ComputeSampling(iNVertices)\n" +PyDoc_STRVAR(Stroke_compute_sampling_doc, +".. method:: compute_sampling(iNVertices)\n" "\n" " Compute the sampling needed to get iNVertices vertices. If the\n" " specified number of vertices is less than the actual number of\n" @@ -125,19 +115,19 @@ static char Stroke_ComputeSampling___doc__[] = " :type iNVertices: int\n" " :return: The sampling that must be used in the Resample(float)\n" " method.\n" -" :rtype: float\n"; +" :rtype: float"); -static PyObject * Stroke_ComputeSampling( BPy_Stroke *self, PyObject *args ) { +static PyObject * Stroke_compute_sampling(BPy_Stroke *self, PyObject *args) +{ int i; - if(!( PyArg_ParseTuple(args, "i", &i) )) + if (!PyArg_ParseTuple(args, "i", &i)) return NULL; - - return PyFloat_FromDouble( self->s->ComputeSampling( i ) ); + return PyFloat_FromDouble(self->s->ComputeSampling(i)); } -static char Stroke_Resample___doc__[] = -".. method:: Resample(iNPoints)\n" +PyDoc_STRVAR(Stroke_resample_doc, +".. method:: resample(iNPoints)\n" "\n" " Resamples the stroke so that it eventually has iNPoints. That means\n" " it is going to add iNPoints-vertices_size, if vertices_size is the\n" @@ -147,34 +137,33 @@ static char Stroke_Resample___doc__[] = " :arg iNPoints: The number of vertices we eventually want in our stroke.\n" " :type iNPoints: int\n" "\n" -".. method:: Resample(iSampling)\n" +".. method:: resample(iSampling)\n" "\n" " Resamples the stroke with a given sampling. If the sampling is\n" " smaller than the actual sampling value, no resampling is done.\n" "\n" " :arg iSampling: The new sampling value.\n" -" :type iSampling: float\n"; +" :type iSampling: float"); -static PyObject * Stroke_Resample( BPy_Stroke *self, PyObject *args ) { +static PyObject * Stroke_resample(BPy_Stroke *self, PyObject *args) +{ PyObject *obj; - if(!( PyArg_ParseTuple(args, "O", &obj) )) + if (!PyArg_ParseTuple(args, "O", &obj)) return NULL; - - if( PyLong_Check(obj) ) - self->s->Resample( (int) PyLong_AsLong(obj) ); - else if( PyFloat_Check(obj) ) - self->s->Resample( (float) PyFloat_AsDouble(obj) ); - else { + if (PyLong_Check(obj)) { + self->s->Resample((int)PyLong_AsLong(obj)); + } else if (PyFloat_Check(obj)) { + self->s->Resample((float)PyFloat_AsDouble(obj)); + } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return NULL; } - Py_RETURN_NONE; } -static char Stroke_InsertVertex___doc__[] = -".. method:: InsertVertex(iVertex, next)\n" +PyDoc_STRVAR(Stroke_insert_vertex_doc, +".. method:: insert_vertex(iVertex, next)\n" "\n" " Inserts the stroke vertex iVertex in the stroke before next. The\n" " length, curvilinear abscissa are updated consequently.\n" @@ -183,290 +172,241 @@ static char Stroke_InsertVertex___doc__[] = " :type iVertex: :class:`StrokeVertex`\n" " :arg next: A StrokeVertexIterator pointing to the StrokeVertex\n" " before which iVertex must be inserted.\n" -" :type next: :class:`StrokeVertexIterator`\n"; +" :type next: :class:`StrokeVertexIterator`"); -static PyObject * Stroke_InsertVertex( BPy_Stroke *self, PyObject *args ) { +static PyObject * Stroke_insert_vertex(BPy_Stroke *self, PyObject *args) +{ PyObject *py_sv = 0, *py_sv_it = 0; - if(!( PyArg_ParseTuple(args, "O!O!", &StrokeVertex_Type, &py_sv, &StrokeVertexIterator_Type, &py_sv_it) )) + if (!PyArg_ParseTuple(args, "O!O!", &StrokeVertex_Type, &py_sv, &StrokeVertexIterator_Type, &py_sv_it)) return NULL; - - StrokeVertex *sv = ((BPy_StrokeVertex *) py_sv)->sv; - StrokeInternal::StrokeVertexIterator sv_it(*( ((BPy_StrokeVertexIterator *) py_sv_it)->sv_it )); - self->s->InsertVertex( sv, sv_it ); - + StrokeVertex *sv = ((BPy_StrokeVertex *)py_sv)->sv; + StrokeInternal::StrokeVertexIterator sv_it(*(((BPy_StrokeVertexIterator *)py_sv_it)->sv_it)); + self->s->InsertVertex(sv, sv_it); Py_RETURN_NONE; } -static char Stroke_RemoveVertex___doc__[] = -".. method:: RemoveVertex(iVertex)\n" +PyDoc_STRVAR(Stroke_remove_vertex_doc, +".. method:: remove_vertex(iVertex)\n" "\n" " Removes the stroke vertex iVertex from the stroke. The length and\n" " curvilinear abscissa are updated consequently.\n" "\n" " :arg iVertex: \n" -" :type iVertex: :class:`StrokeVertex`\n"; +" :type iVertex: :class:`StrokeVertex`"); -static PyObject * Stroke_RemoveVertex( BPy_Stroke *self, PyObject *args ) { +static PyObject * Stroke_remove_vertex( BPy_Stroke *self, PyObject *args ) +{ PyObject *py_sv; - if(!( PyArg_ParseTuple(args, "O!", &StrokeVertex_Type, &py_sv) )) + if (!PyArg_ParseTuple(args, "O!", &StrokeVertex_Type, &py_sv)) return NULL; - - if( ((BPy_StrokeVertex *) py_sv)->sv ) - self->s->RemoveVertex( ((BPy_StrokeVertex *) py_sv)->sv ); - else { + if (((BPy_StrokeVertex *)py_sv)->sv) { + self->s->RemoveVertex(((BPy_StrokeVertex *)py_sv)->sv); + } else { PyErr_SetString(PyExc_TypeError, "invalid argument"); return NULL; } - Py_RETURN_NONE; } -static char Stroke_UpdateLength___doc__[] = -".. method:: UpdateLength()\n" +PyDoc_STRVAR(Stroke_update_length_doc, +".. method:: update_length()\n" "\n" -" Updates the 2D length of the Stroke.\n"; +" Updates the 2D length of the Stroke."); -static PyObject * Stroke_UpdateLength( BPy_Stroke *self ) { +static PyObject * Stroke_update_length(BPy_Stroke *self) +{ self->s->UpdateLength(); - Py_RETURN_NONE; } -static char Stroke_getLength2D___doc__[] = -".. method:: getLength2D()\n" +PyDoc_STRVAR(Stroke_stroke_vertices_begin_doc, +".. method:: stroke_vertices_begin(t=0.0)\n" "\n" -" Returns the 2D length of the Stroke.\n" +" Returns a StrokeVertexIterator pointing on the first StrokeVertex of\n" +" the Stroke. O ne can specify a sampling value to resample the Stroke\n" +" on the fly if needed.\n" "\n" -" :return: the 2D length of the Stroke.\n" -" :rtype: float\n"; - -static PyObject * Stroke_getLength2D( BPy_Stroke *self ) { - return PyFloat_FromDouble( self->s->getLength2D() ); -} +" :arg t: The resampling value with which we want our Stroke to be\n" +" resampled. If 0 is specified, no resampling is done.\n" +" :type t: float\n" +" :return: A StrokeVertexIterator pointing on the first StrokeVertex.\n" +" :rtype: :class:`StrokeVertexIterator`"); -static char Stroke_getMediumType___doc__[] = -".. method:: getMediumType()\n" -"\n" -" Returns the MediumType used for this Stroke.\n" -"\n" -" :return: the MediumType used for this Stroke.\n" -" :rtype: :class:`MediumType`\n"; +static PyObject * Stroke_stroke_vertices_begin( BPy_Stroke *self , PyObject *args) +{ + float f = 0; -static PyObject * Stroke_getMediumType( BPy_Stroke *self ) { - return BPy_MediumType_from_MediumType( self->s->getMediumType() ); + if (!PyArg_ParseTuple(args, "|f", &f)) + return NULL; + StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesBegin(f)); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, 0); } -static char Stroke_getTextureId___doc__[] = -".. method:: getTextureId()\n" +PyDoc_STRVAR(Stroke_stroke_vertices_end_doc, +".. method:: strokeVerticesEnd()\n" "\n" -" Returns the ID of the texture used to simulate th marks system for\n" -" this Stroke\n" +" Returns a StrokeVertexIterator pointing after the last StrokeVertex\n" +" of the Stroke.\n" "\n" -" :return: The texture ID.\n" -" :rtype: int\n"; +" :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n" +" :rtype: :class:`StrokeVertexIterator`"); -static PyObject * Stroke_getTextureId( BPy_Stroke *self ) { - return PyLong_FromLong( self->s->getTextureId() ); +static PyObject * Stroke_stroke_vertices_end(BPy_Stroke *self) +{ + StrokeInternal::StrokeVertexIterator sv_it(self->s->strokeVerticesEnd()); + return BPy_StrokeVertexIterator_from_StrokeVertexIterator(sv_it, 1); } -static char Stroke_hasTips___doc__[] = -".. method:: hasTips()\n" +PyDoc_STRVAR(Stroke_stroke_vertices_size_doc, +".. method:: stroke_vertices_size()\n" "\n" -" Returns true if this Stroke uses a texture with tips, false\n" -" otherwise.\n" +" Returns the number of StrokeVertex constituing the Stroke.\n" "\n" -" :return: True if this Stroke uses a texture with tips.\n" -" :rtype: bool\n"; +" :return: The number of stroke vertices.\n" +" :rtype: int"); -static PyObject * Stroke_hasTips( BPy_Stroke *self ) { - return PyBool_from_bool( self->s->hasTips() ); +static PyObject * Stroke_stroke_vertices_size(BPy_Stroke *self) +{ + return PyLong_FromLong(self->s->strokeVerticesSize()); } -static char Stroke_setId___doc__[] = -".. method:: setId(id)\n" -"\n" -" Sets the Id of the Stroke.\n" -"\n" -" :arg id: the Id of the Stroke.\n" -" :type id: :class:`Id`\n"; - -static PyObject *Stroke_setId( BPy_Stroke *self , PyObject *args) { - PyObject *py_id; - - if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) - return NULL; - - self->s->setId(*( ((BPy_Id *) py_id)->id )); +static PyMethodDef BPy_Stroke_methods[] = { + {"compute_sampling", (PyCFunction)Stroke_compute_sampling, METH_VARARGS, Stroke_compute_sampling_doc}, + {"resample", (PyCFunction)Stroke_resample, METH_VARARGS, Stroke_resample_doc}, + {"remove_vertex", (PyCFunction)Stroke_remove_vertex, METH_VARARGS, Stroke_remove_vertex_doc}, + {"insert_vertex", (PyCFunction)Stroke_insert_vertex, METH_VARARGS, Stroke_insert_vertex_doc}, + {"update_length", (PyCFunction)Stroke_update_length, METH_NOARGS, Stroke_update_length_doc}, + {"stroke_vertices_begin", (PyCFunction)Stroke_stroke_vertices_begin, METH_VARARGS, Stroke_stroke_vertices_begin_doc}, + {"stroke_vertices_end", (PyCFunction)Stroke_stroke_vertices_end, METH_NOARGS, Stroke_stroke_vertices_end_doc}, + {"stroke_vertices_size", (PyCFunction)Stroke_stroke_vertices_size, METH_NOARGS, Stroke_stroke_vertices_size_doc}, + {NULL, NULL, 0, NULL} +}; - Py_RETURN_NONE; -} +/*----------------------Stroke get/setters ----------------------------*/ -static char Stroke_setLength___doc__[] = -".. method:: setLength(iLength)\n" +PyDoc_STRVAR(Stroke_medium_type_doc, +"The MediumType used for this Stroke.\n" "\n" -" Sets the 2D length of the Stroke.\n" -"\n" -" :arg iLength: The 2D length of the Stroke.\n" -" :type iLength: float\n"; - -static PyObject *Stroke_setLength( BPy_Stroke *self , PyObject *args) { - float f; - - if(!( PyArg_ParseTuple(args, "f", &f) )) - return NULL; +":type: :class:`MediumType`"); - self->s->setLength( f ); - - Py_RETURN_NONE; +static PyObject *Stroke_medium_type_get(BPy_Stroke *self, void *UNUSED(closure)) +{ + return BPy_MediumType_from_MediumType(self->s->getMediumType()); } -static char Stroke_setMediumType___doc__[] = -".. method:: setMediumType(iType)\n" -"\n" -" Sets the medium type that must be used for this Stroke.\n" -"\n" -" :arg iType: A MediumType object.\n" -" :type iType: :class:`MediumType`\n"; - -static PyObject *Stroke_setMediumType( BPy_Stroke *self , PyObject *args) { - PyObject *py_mt; - - if(!( PyArg_ParseTuple(args, "O!", &MediumType_Type, &py_mt) )) - return NULL; - - self->s->setMediumType( MediumType_from_BPy_MediumType(py_mt) ); - - Py_RETURN_NONE; +static int Stroke_medium_type_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_MediumType_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a MediumType"); + return -1; + } + self->s->setMediumType(MediumType_from_BPy_MediumType(value)); + return 0; } -static char Stroke_setTextureId___doc__[] = -".. method:: setTextureId(iId)\n" +PyDoc_STRVAR(Stroke_texture_id_doc, +"The ID of the texture used to simulate th marks system for this Stroke.\n" "\n" -" Sets the texture ID to be used to simulate the marks system for this\n" -" Stroke.\n" -"\n" -" :arg iId: A texture ID.\n" -" :type iId: int\n"; - -static PyObject *Stroke_setTextureId( BPy_Stroke *self , PyObject *args) { - unsigned int i; +":type: int"); - if(!( PyArg_ParseTuple(args, "I", &i) )) - return NULL; - - self->s->setTextureId( i ); +static PyObject *Stroke_texture_id_get(BPy_Stroke *self, void *UNUSED(closure)) +{ + return PyLong_FromLong( self->s->getTextureId() ); +} - Py_RETURN_NONE; +static int Stroke_texture_id_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) +{ + unsigned int i = PyLong_AsUnsignedLong(value); + if(PyErr_Occurred()) + return -1; + self->s->setTextureId(i); + return 0; } -static char Stroke_setTips___doc__[] = -".. method:: setTips(iTips)\n" +PyDoc_STRVAR(Stroke_tips_doc, +"True if this Stroke uses a texture with tips, and false otherwise.\n" "\n" -" Sets the flag telling whether this stroke is using a texture with\n" -" tips or not.\n" -"\n" -" :arg iTips: True if this stroke uses a texture with tips.\n" -" :type iTips: bool\n"; - -static PyObject *Stroke_setTips( BPy_Stroke *self , PyObject *args) { - PyObject *py_b; - - if(!( PyArg_ParseTuple(args, "O", &py_b) )) - return NULL; +":type: bool"); - self->s->setTips( bool_from_PyBool(py_b) ); +static PyObject *Stroke_tips_get(BPy_Stroke *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->s->hasTips()); +} - Py_RETURN_NONE; +static int Stroke_tips_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) +{ + if (!PyBool_Check(value)) + return -1; + self->s->setTips(bool_from_PyBool(value)); + return 0; } -static char Stroke_strokeVerticesBegin___doc__[] = -".. method:: strokeVerticesBegin(t=0.0)\n" +PyDoc_STRVAR(Stroke_length_2d_doc, +"The 2D length of the Stroke.\n" "\n" -" Returns a StrokeVertexIterator pointing on the first StrokeVertex of\n" -" the Stroke. O ne can specify a sampling value to resample the Stroke\n" -" on the fly if needed.\n" -"\n" -" :arg t: The resampling value with which we want our Stroke to be\n" -" resampled. If 0 is specified, no resampling is done.\n" -" :type t: float\n" -" :return: A StrokeVertexIterator pointing on the first StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`\n"; - -static PyObject * Stroke_strokeVerticesBegin( BPy_Stroke *self , PyObject *args) { - float f = 0; +":type: float"); - if(!( PyArg_ParseTuple(args, "|f", &f) )) - return NULL; +static PyObject *Stroke_length_2d_get(BPy_Stroke *self, void *UNUSED(closure)) +{ + return PyFloat_FromDouble(self->s->getLength2D()); +} - StrokeInternal::StrokeVertexIterator sv_it( self->s->strokeVerticesBegin(f) ); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator( sv_it, 0 ); +static int Stroke_length_2d_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) +{ + float scalar; + if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) { /* parsed item not a number */ + PyErr_SetString(PyExc_TypeError, "value must be a number"); + return -1; + } + self->s->setLength(scalar); + return 0; } -static char Stroke_strokeVerticesEnd___doc__[] = -".. method:: strokeVerticesEnd()\n" +PyDoc_STRVAR(Stroke_id_doc, +"The Id of this Stroke.\n" "\n" -" Returns a StrokeVertexIterator pointing after the last StrokeVertex\n" -" of the Stroke.\n" -"\n" -" :return: A StrokeVertexIterator pointing after the last StrokeVertex.\n" -" :rtype: :class:`StrokeVertexIterator`\n"; +":type: :class:`Id`"); -static PyObject * Stroke_strokeVerticesEnd( BPy_Stroke *self ) { - StrokeInternal::StrokeVertexIterator sv_it( self->s->strokeVerticesEnd() ); - return BPy_StrokeVertexIterator_from_StrokeVertexIterator( sv_it, 1 ); +static PyObject *Stroke_id_get(BPy_Stroke *self, void *UNUSED(closure)) +{ + Id id(self->s->getId()); + return BPy_Id_from_Id(id); // return a copy } -static char Stroke_strokeVerticesSize___doc__[] = -".. method:: strokeVerticesSize()\n" -"\n" -" Returns the number of StrokeVertex constituing the Stroke.\n" -"\n" -" :return: The number of stroke vertices.\n" -" :rtype: int\n"; - -static PyObject * Stroke_strokeVerticesSize( BPy_Stroke *self ) { - return PyLong_FromLong( self->s->strokeVerticesSize() ); +static int Stroke_id_set(BPy_Stroke *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->s->setId(*(((BPy_Id *)value)->id)); + return 0; } - -/*----------------------Stroke instance definitions ----------------------------*/ -static PyMethodDef BPy_Stroke_methods[] = { - {"__getitem__", ( PyCFunction ) Stroke___getitem__, METH_O, "(int i) Returns the i-th StrokeVertex constituting the Stroke."}, - {"ComputeSampling", ( PyCFunction ) Stroke_ComputeSampling, METH_VARARGS, Stroke_ComputeSampling___doc__}, - {"Resample", ( PyCFunction ) Stroke_Resample, METH_VARARGS, Stroke_Resample___doc__}, - {"RemoveVertex", ( PyCFunction ) Stroke_RemoveVertex, METH_VARARGS, Stroke_RemoveVertex___doc__}, - {"InsertVertex", ( PyCFunction ) Stroke_InsertVertex, METH_VARARGS, Stroke_InsertVertex___doc__}, - {"UpdateLength", ( PyCFunction ) Stroke_UpdateLength, METH_NOARGS, Stroke_UpdateLength___doc__}, - {"getLength2D", ( PyCFunction ) Stroke_getLength2D, METH_NOARGS, Stroke_getLength2D___doc__}, - {"getMediumType", ( PyCFunction ) Stroke_getMediumType, METH_NOARGS, Stroke_getMediumType___doc__}, - {"getTextureId", ( PyCFunction ) Stroke_getTextureId, METH_NOARGS, Stroke_getTextureId___doc__}, - {"hasTips", ( PyCFunction ) Stroke_hasTips, METH_NOARGS, Stroke_hasTips___doc__}, - {"setId", ( PyCFunction ) Stroke_setId, METH_VARARGS, Stroke_setId___doc__}, - {"setLength", ( PyCFunction ) Stroke_setLength, METH_VARARGS, Stroke_setLength___doc__}, - {"setMediumType", ( PyCFunction ) Stroke_setMediumType, METH_VARARGS, Stroke_setMediumType___doc__}, - {"setTextureId", ( PyCFunction ) Stroke_setTextureId, METH_VARARGS, Stroke_setTextureId___doc__}, - {"setTips", ( PyCFunction ) Stroke_setTips, METH_VARARGS, Stroke_setTips___doc__}, - {"strokeVerticesBegin", ( PyCFunction ) Stroke_strokeVerticesBegin, METH_VARARGS, Stroke_strokeVerticesBegin___doc__}, - {"strokeVerticesEnd", ( PyCFunction ) Stroke_strokeVerticesEnd, METH_NOARGS, Stroke_strokeVerticesEnd___doc__}, - {"strokeVerticesSize", ( PyCFunction ) Stroke_strokeVerticesSize, METH_NOARGS, Stroke_strokeVerticesSize___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_Stroke_getseters[] = { + {(char *)"medium_type", (getter)Stroke_medium_type_get, (setter)Stroke_medium_type_set, (char *)Stroke_medium_type_doc, NULL}, + {(char *)"texture_id", (getter)Stroke_texture_id_get, (setter)Stroke_texture_id_set, (char *)Stroke_texture_id_doc, NULL}, + {(char *)"tips", (getter)Stroke_tips_get, (setter)Stroke_tips_set, (char *)Stroke_tips_doc, NULL}, + {(char *)"length_2d", (getter)Stroke_length_2d_get, (setter)Stroke_length_2d_set, (char *)Stroke_length_2d_doc, NULL}, + {(char *)"id", (getter)Stroke_id_get, (setter)Stroke_id_set, (char *)Stroke_id_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_Stroke type definition ------------------------------*/ -static PySequenceMethods Stroke_as_sequence = { - (lenfunc)Stroke_length, /* sq_length */ - NULL, /* sq_concat */ - NULL, /* sq_repeat */ - (ssizeargfunc)Stroke_item, /* sq_item */ - NULL, /* sq_slice */ - NULL, /* sq_ass_item */ - NULL, /* sq_ass_slice */ - NULL, /* sq_contains */ - NULL, /* sq_inplace_concat */ - NULL, /* sq_inplace_repeat */ +static PySequenceMethods BPy_Stroke_as_sequence = { + (lenfunc)Stroke_sq_length, /* sq_length */ + NULL, /* sq_concat */ + NULL, /* sq_repeat */ + (ssizeargfunc)Stroke_sq_item, /* sq_item */ + NULL, /* sq_slice */ + NULL, /* sq_ass_item */ + NULL, /* *was* sq_ass_slice */ + NULL, /* sq_contains */ + NULL, /* sq_inplace_concat */ + NULL, /* sq_inplace_repeat */ }; PyTypeObject Stroke_Type = { @@ -481,7 +421,7 @@ PyTypeObject Stroke_Type = { 0, /* tp_reserved */ 0, /* tp_repr */ 0, /* tp_as_number */ - &Stroke_as_sequence, /* tp_as_sequence */ + &BPy_Stroke_as_sequence, /* tp_as_sequence */ 0, /* tp_as_mapping */ 0, /* tp_hash */ 0, /* tp_call */ @@ -490,22 +430,22 @@ PyTypeObject Stroke_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - Stroke___doc__, /* tp_doc */ + Stroke_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ - (getiterfunc)Stroke___iter__, /* tp_iter */ + (getiterfunc)Stroke_iter, /* tp_iter */ 0, /* tp_iternext */ BPy_Stroke_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_Stroke_getseters, /* tp_getset */ &Interface1D_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)Stroke___init__, /* tp_init */ + (initproc)Stroke_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp index e35ea82ace2..8e1cb42f37c 100644 --- a/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/BPy_ViewEdge.cpp @@ -14,9 +14,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- - -static char ViewEdge___doc__[] = +/*----------------------ViewEdge methods ----------------------------*/ + +PyDoc_STRVAR(ViewEdge_doc, "Class hierarchy: :class:`Interface1D` > :class:`ViewEdge`\n" "\n" "Class defining a ViewEdge. A ViewEdge in an edge of the image graph.\n" @@ -32,385 +32,267 @@ static char ViewEdge___doc__[] = " Copy constructor.\n" "\n" " :arg iBrother: A ViewEdge object.\n" -" :type iBrother: :class:`ViewEdge`\n"; +" :type iBrother: :class:`ViewEdge`"); -static int ViewEdge___init__(BPy_ViewEdge *self, PyObject *args, PyObject *kwds) +static int ViewEdge_init(BPy_ViewEdge *self, PyObject *args, PyObject *kwds) { - if ( !PyArg_ParseTuple(args, "") ) - return -1; + if (!PyArg_ParseTuple(args, "")) + return -1; self->ve = new ViewEdge(); self->py_if1D.if1D = self->ve; self->py_if1D.borrowed = 0; - return 0; } -static char ViewEdge_A___doc__[] = -".. method:: A()\n" -"\n" -" Returns the first ViewVertex.\n" +PyDoc_STRVAR(ViewEdge_update_fedges_doc, +".. method:: update_fedges()\n" "\n" -" :return: The first ViewVertex.\n" -" :rtype: :class:`ViewVertex`\n"; +" Sets Viewedge to this for all embedded fedges.\n"); -static PyObject * ViewEdge_A( BPy_ViewEdge *self ) { - ViewVertex *v = self->ve->A(); - if( v ){ - return Any_BPy_ViewVertex_from_ViewVertex( *v ); - } - +static PyObject * ViewEdge_update_fedges(BPy_ViewEdge *self) +{ + self->ve->UpdateFEdges(); Py_RETURN_NONE; } -static char ViewEdge_B___doc__[] = -".. method:: B()\n" -"\n" -" Returns the second ViewVertex.\n" -"\n" -" :return: The second ViewVertex.\n" -" :rtype: :class:`ViewVertex`\n"; +static PyMethodDef BPy_ViewEdge_methods[] = { + {"update_fedges", (PyCFunction)ViewEdge_update_fedges, METH_NOARGS, ViewEdge_update_fedges_doc}, + {NULL, NULL, 0, NULL} +}; -static PyObject * ViewEdge_B( BPy_ViewEdge *self ) { - ViewVertex *v = self->ve->B(); - if( v ){ - return Any_BPy_ViewVertex_from_ViewVertex( *v ); - } - - Py_RETURN_NONE; -} +/*----------------------ViewEdge get/setters ----------------------------*/ -static char ViewEdge_fedgeA___doc__[] = -".. method:: fedgeA()\n" +PyDoc_STRVAR(ViewEdge_first_viewvertex_doc, +"The first ViewVertex.\n" "\n" -" Returns the first FEdge that constitutes this ViewEdge.\n" -"\n" -" :return: The first FEdge constituting this ViewEdge.\n" -" :rtype: :class:`FEdge`\n"; +":type: :class:`ViewVertex`"); -static PyObject * ViewEdge_fedgeA( BPy_ViewEdge *self ) { - FEdge *A = self->ve->fedgeA(); - if( A ){ - return Any_BPy_FEdge_from_FEdge( *A ); - } - +static PyObject *ViewEdge_first_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + ViewVertex *v = self->ve->A(); + if (v) + return Any_BPy_ViewVertex_from_ViewVertex(*v); Py_RETURN_NONE; } -static char ViewEdge_fedgeB___doc__[] = -".. method:: fedgeB()\n" -"\n" -" Returns the last FEdge that constitutes this ViewEdge.\n" -"\n" -" :return: The last FEdge constituting this ViewEdge.\n" -" :rtype: :class:`FEdge`\n"; - -static PyObject * ViewEdge_fedgeB( BPy_ViewEdge *self ) { - FEdge *B = self->ve->fedgeB(); - if( B ){ - return Any_BPy_FEdge_from_FEdge( *B ); - } - - Py_RETURN_NONE; +static int ViewEdge_first_viewvertex_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if(!BPy_ViewVertex_Check(value)) + return -1; + self->ve->setA(((BPy_ViewVertex *)value)->vv); + return 0; } -static char ViewEdge_viewShape___doc__[] = -".. method:: viewShape()\n" -"\n" -" Returns the ViewShape to which this ViewEdge belongs to.\n" +PyDoc_STRVAR(ViewEdge_last_viewvertex_doc, +"The second ViewVertex.\n" "\n" -" :return: The ViewShape to which this ViewEdge belongs to.\n" -" :rtype: :class:`ViewShape`\n"; +":type: :class:`ViewVertex`"); -static PyObject * ViewEdge_viewShape( BPy_ViewEdge *self ) { - ViewShape *vs = self->ve->viewShape(); - if( vs ){ - return BPy_ViewShape_from_ViewShape( *vs ); - } - +static PyObject *ViewEdge_last_viewvertex_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + ViewVertex *v = self->ve->B(); + if (v) + return Any_BPy_ViewVertex_from_ViewVertex(*v); Py_RETURN_NONE; } -static char ViewEdge_aShape___doc__[] = -".. method:: aShape()\n" -"\n" -" Returns the shape that is occluded by the ViewShape to which this\n" -" ViewEdge belongs to. If no object is occluded, None is returned.\n" -"\n" -" :return: The occluded ViewShape.\n" -" :rtype: :class:`ViewShape`\n"; - -static PyObject * ViewEdge_aShape( BPy_ViewEdge *self ) { - ViewShape *vs = self->ve->aShape(); - if( vs ){ - return BPy_ViewShape_from_ViewShape( *vs ); - } - - Py_RETURN_NONE; +static int ViewEdge_last_viewvertex_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if(!BPy_ViewVertex_Check(value)) + return -1; + self->ve->setB(((BPy_ViewVertex *)value)->vv); + return 0; } -static char ViewEdge_isClosed___doc__[] = -".. method:: isClosed()\n" +PyDoc_STRVAR(ViewEdge_first_fedge_doc, +"The first FEdge that constitutes this ViewEdge.\n" "\n" -" Tells whether this ViewEdge forms a closed loop or not.\n" -"\n" -" :return: True if this ViewEdge forms a closed loop.\n" -" :rtype: bool\n"; +":type: :class:`FEdge`"); -static PyObject * ViewEdge_isClosed( BPy_ViewEdge *self ) { - return PyBool_from_bool( self->ve->isClosed() ); +static PyObject *ViewEdge_first_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + FEdge *fe = self->ve->fedgeA(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); + Py_RETURN_NONE; } -static char ViewEdge_getChainingTimeStamp___doc__[] = -".. method:: getChainingTimeStamp()\n" -"\n" -" Returns the time stamp of this ViewEdge.\n" -"\n" -" :return: The time stamp.\n" -" :rtype: int\n"; - -static PyObject * ViewEdge_getChainingTimeStamp( BPy_ViewEdge *self ) { - return PyLong_FromLong( self->ve->getChainingTimeStamp() ); +static int ViewEdge_first_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if(!BPy_FEdge_Check(value)) + return -1; + self->ve->setFEdgeA(((BPy_FEdge *)value)->fe); + return 0; } -static char ViewEdge_setChainingTimeStamp___doc__[] = -".. method:: setChainingTimeStamp(ts)\n" +PyDoc_STRVAR(ViewEdge_last_fedge_doc, +"The last FEdge that constitutes this ViewEdge.\n" "\n" -" Sets the time stamp value.\n" -"\n" -" :arg ts: The time stamp.\n" -" :type ts: int\n"; - -static PyObject * ViewEdge_setChainingTimeStamp( BPy_ViewEdge *self, PyObject *args) { - int timestamp = 0 ; - - if( !PyArg_ParseTuple(args, "i", ×tamp) ) - return NULL; - - self->ve->setChainingTimeStamp( timestamp ); +":type: :class:`FEdge`"); +static PyObject *ViewEdge_last_fedge_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + FEdge *fe = self->ve->fedgeB(); + if (fe) + return Any_BPy_FEdge_from_FEdge(*fe); Py_RETURN_NONE; } -static char ViewEdge_setA___doc__[] = -".. method:: setA(iA)\n" -"\n" -" Sets the first ViewVertex of the ViewEdge.\n" -"\n" -" :arg iA: The first ViewVertex of the ViewEdge.\n" -" :type iA: :class:`ViewVertex`\n"; - -static PyObject *ViewEdge_setA( BPy_ViewEdge *self , PyObject *args) { - PyObject *py_vv; - - if(!( PyArg_ParseTuple(args, "O!", &ViewVertex_Type, &py_vv) )) - return NULL; - - self->ve->setA( ((BPy_ViewVertex *) py_vv)->vv ); - - Py_RETURN_NONE; +static int ViewEdge_last_fedge_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if(!BPy_FEdge_Check(value)) + return -1; + self->ve->setFEdgeB(((BPy_FEdge *)value)->fe); + return 0; } -static char ViewEdge_setB___doc__[] = -".. method:: setB(iB)\n" -"\n" -" Sets the last ViewVertex of the ViewEdge.\n" +PyDoc_STRVAR(ViewEdge_viewshape_doc, +"The ViewShape to which this ViewEdge belongs to.\n" "\n" -" :arg iB: The last ViewVertex of the ViewEdge.\n" -" :type iB: :class:`ViewVertex`\n"; - -static PyObject *ViewEdge_setB( BPy_ViewEdge *self , PyObject *args) { - PyObject *py_vv; - - if(!( PyArg_ParseTuple(args, "O!", &ViewVertex_Type, &py_vv) )) - return NULL; - - self->ve->setB( ((BPy_ViewVertex *) py_vv)->vv ); +":type: :class:`ViewShape`"); +static PyObject *ViewEdge_viewshape_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + ViewShape *vs = self->ve->viewShape(); + if (vs) + return BPy_ViewShape_from_ViewShape(*vs); Py_RETURN_NONE; } -static char ViewEdge_setNature___doc__[] = -".. method:: setNature(iNature)\n" -"\n" -" Sets the nature of the ViewEdge.\n" -"\n" -" :arg iNature: The nature of the ViewEdge.\n" -" :type iNature: :class:`Nature`\n"; - -static PyObject * ViewEdge_setNature( BPy_ViewEdge *self, PyObject *args ) { - PyObject *py_n; - - if(!( PyArg_ParseTuple(args, "O!", &Nature_Type, &py_n) )) - return NULL; - - PyObject *i = (PyObject *) &( ((BPy_Nature *) py_n)->i ); - self->ve->setNature( PyLong_AsLong(i) ); - - Py_RETURN_NONE; +static int ViewEdge_viewshape_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_ViewShape_Check(value)) + return -1; + self->ve->setShape(((BPy_ViewShape *)value)->vs); + return 0; } -static char ViewEdge_setFEdgeA___doc__[] = -".. method:: setFEdgeA(iFEdge)\n" -"\n" -" Sets the first FEdge of the ViewEdge.\n" +PyDoc_STRVAR(ViewEdge_occludee_doc, +"The shape that is occluded by the ViewShape to which this ViewEdge\n" +"belongs to. If no object is occluded, this property is set to None.\n" "\n" -" :arg iFEdge: The first FEdge of the ViewEdge.\n" -" :type iFEdge: :class:`FEdge`\n"; - -static PyObject * ViewEdge_setFEdgeA( BPy_ViewEdge *self, PyObject *args ) { - PyObject *py_fe; - - if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) - return NULL; - - self->ve->setFEdgeA( ((BPy_FEdge *) py_fe)->fe ); +":type: :class:`ViewShape`"); +static PyObject *ViewEdge_occludee_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + ViewShape *vs = self->ve->aShape(); + if (vs) + return BPy_ViewShape_from_ViewShape(*vs); Py_RETURN_NONE; } -static char ViewEdge_setFEdgeB___doc__[] = -".. method:: setFEdgeB(iFEdge)\n" -"\n" -" Sets the last FEdge of the ViewEdge.\n" -"\n" -" :arg iFEdge: The last FEdge of the ViewEdge.\n" -" :type iFEdge: :class:`FEdge`\n"; - -static PyObject * ViewEdge_setFEdgeB( BPy_ViewEdge *self, PyObject *args ) { - PyObject *py_fe; - - if(!( PyArg_ParseTuple(args, "O!", &FEdge_Type, &py_fe) )) - return NULL; - - self->ve->setFEdgeB( ((BPy_FEdge *) py_fe)->fe ); - - Py_RETURN_NONE; +static int ViewEdge_occludee_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if(!BPy_ViewShape_Check(value)) + return -1; + self->ve->setaShape(((BPy_ViewShape *)value)->vs); + return 0; } -static char ViewEdge_setShape___doc__[] = -".. method:: setShape(iVShape)\n" +PyDoc_STRVAR(ViewEdge_is_closed_doc, +"True if this ViewEdge forms a closed loop.\n" "\n" -" Sets the ViewShape to which this ViewEdge belongs to.\n" -"\n" -" :arg iVShape: The ViewShape to which this ViewEdge belongs to.\n" -" :type iVShape: :class:`ViewShape`\n"; - -static PyObject * ViewEdge_setShape( BPy_ViewEdge *self, PyObject *args ) { - PyObject *py_vs; +":type: bool"); - if(!( PyArg_ParseTuple(args, "O", &ViewShape_Type, &py_vs) )) - return NULL; - - self->ve->setShape( ((BPy_ViewShape *) py_vs)->vs ); - - Py_RETURN_NONE; +static PyObject *ViewEdge_is_closed_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->ve->isClosed()); } -static char ViewEdge_setId___doc__[] = -".. method:: setId(id)\n" +PyDoc_STRVAR(ViewEdge_id_doc, +"The Id of this ViewEdge.\n" "\n" -" Sets the ViewEdge id.\n" -"\n" -" :arg id: An Id object.\n" -" :type id: :class:`Id`\n"; - -static PyObject * ViewEdge_setId( BPy_ViewEdge *self, PyObject *args ) { - PyObject *py_id; +":type: :class:`Id`"); - if(!( PyArg_ParseTuple(args, "O!", &Id_Type, &py_id) )) - return NULL; - - Id id(*( ((BPy_Id *) py_id)->id )); - self->ve->setId( id ); +static PyObject *ViewEdge_id_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + Id id(self->ve->getId()); + return BPy_Id_from_Id(id); // return a copy +} - Py_RETURN_NONE; +static int ViewEdge_id_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Id_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be an Id"); + return -1; + } + self->ve->setId(*(((BPy_Id *)value)->id)); + return 0; } -static char ViewEdge_UpdateFEdges___doc__[] = -".. method:: UpdateFEdges()\n" +PyDoc_STRVAR(ViewEdge_nature_doc, +"The nature of this ViewEdge.\n" "\n" -" Sets Viewedge to this for all embedded fedges.\n"; +":type: :class:`Nature`"); -static PyObject * ViewEdge_UpdateFEdges( BPy_ViewEdge *self ) { - self->ve->UpdateFEdges(); +static PyObject *ViewEdge_nature_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + return BPy_Nature_from_Nature(self->ve->getNature()); +} - Py_RETURN_NONE; +static int ViewEdge_nature_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + if (!BPy_Nature_Check(value)) { + PyErr_SetString(PyExc_TypeError, "value must be a Nature"); + return -1; + } + self->ve->setNature(PyLong_AsLong((PyObject *)&((BPy_Nature *)value)->i)); + return 0; } -static char ViewEdge_setaShape___doc__[] = -".. method:: setaShape(iShape)\n" +PyDoc_STRVAR(ViewEdge_qi_doc, +"The quantitative invisibility.\n" "\n" -" Sets the occluded ViewShape.\n" -"\n" -" :arg iShape: A ViewShape object.\n" -" :type iShape: :class:`ViewShape`\n"; - -static PyObject * ViewEdge_setaShape( BPy_ViewEdge *self, PyObject *args ) { - PyObject *py_vs; - - if(!( PyArg_ParseTuple(args, "O!", &ViewShape_Type, &py_vs) )) - return NULL; - - ViewShape *vs = ((BPy_ViewShape *) py_vs)->vs; - self->ve->setaShape( vs ); +":type: int"); - Py_RETURN_NONE; +static PyObject *ViewEdge_qi_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + return PyLong_FromLong(self->ve->qi()); } -static char ViewEdge_setQI___doc__[] = -".. method:: setQI(qi)\n" -"\n" -" Sets the quantitative invisibility value of the ViewEdge.\n" -"\n" -" :arg qi: The quantitative invisibility.\n" -" :type qi: int\n"; - -static PyObject * ViewEdge_setQI( BPy_ViewEdge *self, PyObject *args ) { +static int ViewEdge_qi_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ int qi; - if(!( PyArg_ParseTuple(args, "i", &qi) )) - return NULL; + if((qi = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) + return -1; + self->ve->setQI(qi); + return 0; +} - self->ve->setQI( qi ); +PyDoc_STRVAR(ViewEdge_chaining_time_stamp_doc, +"The time stamp of this ViewEdge.\n" +"\n" +":type: int"); - Py_RETURN_NONE; +static PyObject *ViewEdge_chaining_time_stamp_get(BPy_ViewEdge *self, void *UNUSED(closure)) +{ + return PyLong_FromLong(self->ve->getChainingTimeStamp()); } -static char ViewEdge_qi___doc__[] = -".. method:: getChainingTimeStamp()\n" -"\n" -" Returns the quantitative invisibility value of the ViewEdge.\n" -"\n" -" :return: The quantitative invisibility.\n" -" :rtype: int\n"; +static int ViewEdge_chaining_time_stamp_set(BPy_ViewEdge *self, PyObject *value, void *UNUSED(closure)) +{ + int timestamp; -static PyObject * ViewEdge_qi( BPy_ViewEdge *self ) { - return PyLong_FromLong( self->ve->qi() ); + if ((timestamp = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) + return -1; + self->ve->setChainingTimeStamp(timestamp); + return 0; } -/*----------------------ViewEdge instance definitions ----------------------------*/ -static PyMethodDef BPy_ViewEdge_methods[] = { - {"A", ( PyCFunction ) ViewEdge_A, METH_NOARGS, ViewEdge_A___doc__}, - {"B", ( PyCFunction ) ViewEdge_B, METH_NOARGS, ViewEdge_B___doc__}, - {"fedgeA", ( PyCFunction ) ViewEdge_fedgeA, METH_NOARGS, ViewEdge_fedgeA___doc__}, - {"fedgeB", ( PyCFunction ) ViewEdge_fedgeB, METH_NOARGS, ViewEdge_fedgeB___doc__}, - {"viewShape", ( PyCFunction ) ViewEdge_viewShape, METH_NOARGS, ViewEdge_viewShape___doc__}, - {"aShape", ( PyCFunction ) ViewEdge_aShape, METH_NOARGS, ViewEdge_aShape___doc__}, - {"isClosed", ( PyCFunction ) ViewEdge_isClosed, METH_NOARGS, ViewEdge_isClosed___doc__}, - {"getChainingTimeStamp", ( PyCFunction ) ViewEdge_getChainingTimeStamp, METH_NOARGS, ViewEdge_getChainingTimeStamp___doc__}, - {"setChainingTimeStamp", ( PyCFunction ) ViewEdge_setChainingTimeStamp, METH_VARARGS, ViewEdge_setChainingTimeStamp___doc__}, - {"setA", ( PyCFunction ) ViewEdge_setA, METH_VARARGS, ViewEdge_setA___doc__}, - {"setB", ( PyCFunction ) ViewEdge_setB, METH_VARARGS, ViewEdge_setB___doc__}, - {"setNature", ( PyCFunction ) ViewEdge_setNature, METH_VARARGS, ViewEdge_setNature___doc__}, - {"setFEdgeA", ( PyCFunction ) ViewEdge_setFEdgeA, METH_VARARGS, ViewEdge_setFEdgeA___doc__}, - {"setFEdgeB", ( PyCFunction ) ViewEdge_setFEdgeB, METH_VARARGS, ViewEdge_setFEdgeB___doc__}, - {"setShape", ( PyCFunction ) ViewEdge_setShape, METH_VARARGS, ViewEdge_setShape___doc__}, - {"setId", ( PyCFunction ) ViewEdge_setId, METH_VARARGS, ViewEdge_setId___doc__}, - {"UpdateFEdges", ( PyCFunction ) ViewEdge_UpdateFEdges, METH_NOARGS, ViewEdge_UpdateFEdges___doc__}, - {"setaShape", ( PyCFunction ) ViewEdge_setaShape, METH_VARARGS, ViewEdge_setaShape___doc__}, - {"setQI", ( PyCFunction ) ViewEdge_setQI, METH_VARARGS, ViewEdge_setQI___doc__}, - {"qi", ( PyCFunction ) ViewEdge_qi, METH_NOARGS, ViewEdge_qi___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_ViewEdge_getseters[] = { + {(char *)"first_viewvertex", (getter)ViewEdge_first_viewvertex_get, (setter)ViewEdge_first_viewvertex_set, (char *)ViewEdge_first_viewvertex_doc, NULL}, + {(char *)"last_viewvertex", (getter)ViewEdge_last_viewvertex_get, (setter)ViewEdge_last_viewvertex_set, (char *)ViewEdge_last_viewvertex_doc, NULL}, + {(char *)"first_fedge", (getter)ViewEdge_first_fedge_get, (setter)ViewEdge_first_fedge_set, (char *)ViewEdge_first_fedge_doc, NULL}, + {(char *)"last_fedge", (getter)ViewEdge_last_fedge_get, (setter)ViewEdge_last_fedge_set, (char *)ViewEdge_last_fedge_doc, NULL}, + {(char *)"viewshape", (getter)ViewEdge_viewshape_get, (setter)ViewEdge_viewshape_set, (char *)ViewEdge_viewshape_doc, NULL}, + {(char *)"occludee", (getter)ViewEdge_occludee_get, (setter)ViewEdge_occludee_set, (char *)ViewEdge_occludee_doc, NULL}, + {(char *)"is_closed", (getter)ViewEdge_is_closed_get, (setter)NULL, (char *)ViewEdge_is_closed_doc, NULL}, + {(char *)"id", (getter)ViewEdge_id_get, (setter)ViewEdge_id_set, (char *)ViewEdge_id_doc, NULL}, + {(char *)"nature", (getter)ViewEdge_nature_get, (setter)ViewEdge_nature_set, (char *)ViewEdge_nature_doc, NULL}, + {(char *)"qi", (getter)ViewEdge_qi_get, (setter)ViewEdge_qi_set, (char *)ViewEdge_qi_doc, NULL}, + {(char *)"chaining_time_stamp", (getter)ViewEdge_chaining_time_stamp_get, (setter)ViewEdge_chaining_time_stamp_set, (char *)ViewEdge_chaining_time_stamp_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_ViewEdge type definition ------------------------------*/ @@ -436,7 +318,7 @@ PyTypeObject ViewEdge_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - ViewEdge___doc__, /* tp_doc */ + ViewEdge_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -445,13 +327,13 @@ PyTypeObject ViewEdge_Type = { 0, /* tp_iternext */ BPy_ViewEdge_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_ViewEdge_getseters, /* tp_getset */ &Interface1D_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)ViewEdge___init__, /* tp_init */ + (initproc)ViewEdge_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp index 39d644b7714..aef1086a641 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.cpp @@ -9,9 +9,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------FEdgeSharp methods ----------------------------*/ -static char FEdgeSharp___doc__[] = +PyDoc_STRVAR(FEdgeSharp_doc, "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSharp`\n" "\n" "Class defining a sharp FEdge. A Sharp FEdge corresponds to an initial\n" @@ -39,288 +39,320 @@ static char FEdgeSharp___doc__[] = " :arg vA: The first SVertex object.\n" " :type vA: :class:`SVertex`\n" " :arg vB: The second SVertex object.\n" -" :type vB: :class:`SVertex`\n"; +" :type vB: :class:`SVertex`"); -static int FEdgeSharp___init__(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds) +static int FEdgeSharp_init(BPy_FEdgeSharp *self, PyObject *args, PyObject *kwds) { PyObject *obj1 = 0, *obj2 = 0; - if (! PyArg_ParseTuple(args, "|OO", &obj1, &obj2) ) - return -1; + if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) + return -1; - if( !obj1 ){ + if (!obj1) { self->fes = new FEdgeSharp(); - - } else if( !obj2 && BPy_FEdgeSharp_Check(obj1) ) { - self->fes = new FEdgeSharp(*( ((BPy_FEdgeSharp *) obj1)->fes )); - - } else if( obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { - self->fes = new FEdgeSharp( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv ); + + } else if (!obj2 && BPy_FEdgeSharp_Check(obj1)) { + self->fes = new FEdgeSharp(*(((BPy_FEdgeSharp *)obj1)->fes)); + + } else if (obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) { + self->fes = new FEdgeSharp(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); return -1; } - self->py_fe.fe = self->fes; self->py_fe.py_if1D.if1D = self->fes; self->py_fe.py_if1D.borrowed = 0; - return 0; } -static char FEdgeSharp_normalA___doc__[] = -".. method:: normalA()\n" -"\n" -" Returns the normal to the face lying on the right of the FEdge. If\n" -" this FEdge is a border, it has no Face on its right and therefore, no\n" -" normal.\n" -"\n" -" :return: The normal to the face lying on the right of the FEdge.\n" -" :rtype: :class:`mathutils.Vector`\n"; +static PyMethodDef BPy_FEdgeSharp_methods[] = { + {NULL, NULL, 0, NULL} +}; -static PyObject * FEdgeSharp_normalA( BPy_FEdgeSharp *self ) { - Vec3r v( self->fes->normalA() ); - return Vector_from_Vec3r( v ); -} +/*----------------------mathutils callbacks ----------------------------*/ -static char FEdgeSharp_normalB___doc__[] = -".. method:: normalB()\n" -"\n" -" Returns the normal to the face lying on the left of the FEdge.\n" -"\n" -" :return: The normal to the face lying on the left of the FEdge.\n" -" :rtype: :class:`mathutils.Vector`\n"; +/* subtype */ +#define MATHUTILS_SUBTYPE_NORMAL_A 1 +#define MATHUTILS_SUBTYPE_NORMAL_B 2 -static PyObject * FEdgeSharp_normalB( BPy_FEdgeSharp *self ) { - Vec3r v( self->fes->normalB() ); - return Vector_from_Vec3r( v ); +static int FEdgeSharp_mathutils_check(BaseMathObject *bmo) +{ + if (!BPy_FEdgeSharp_Check(bmo->cb_user)) + return -1; + return 0; } -static char FEdgeSharp_aMaterialIndex___doc__[] = -".. method:: aMaterialIndex()\n" -"\n" -" Returns the index of the material of the face lying on the right of\n" -" the FEdge. If this FEdge is a border, it has no Face on its right and\n" -" therefore, no material.\n" -"\n" -" :return: The index of the material of the face lying on the right of\n" -" the FEdge.\n" -" :rtype: int\n"; +static int FEdgeSharp_mathutils_get(BaseMathObject *bmo, int subtype) +{ + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: + { + Vec3r p(self->fes->normalA()); + bmo->data[0] = p[0]; + bmo->data[1] = p[1]; + bmo->data[2] = p[2]; + } + break; + case MATHUTILS_SUBTYPE_NORMAL_B: + { + Vec3r p(self->fes->normalB()); + bmo->data[0] = p[0]; + bmo->data[1] = p[1]; + bmo->data[2] = p[2]; + } + break; + default: + return -1; + } + return 0; +} -static PyObject * FEdgeSharp_aMaterialIndex( BPy_FEdgeSharp *self ) { - return PyLong_FromLong( self->fes->aFrsMaterialIndex() ); +static int FEdgeSharp_mathutils_set(BaseMathObject *bmo, int subtype) +{ + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: + { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->fes->setNormalA(p); + } + break; + case MATHUTILS_SUBTYPE_NORMAL_B: + { + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->fes->setNormalB(p); + } + break; + default: + return -1; + } + return 0; } -static char FEdgeSharp_bMaterialIndex___doc__[] = -".. method:: bMaterialIndex()\n" -"\n" -" Returns the index of the material of the face lying on the left of\n" -" the FEdge.\n" -"\n" -" :return: The index of the material of the face lying on the left of\n" -" the FEdge.\n" -" :rtype: int\n"; +static int FEdgeSharp_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) +{ + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: + { + Vec3r p(self->fes->normalA()); + bmo->data[index] = p[index]; + } + break; + case MATHUTILS_SUBTYPE_NORMAL_B: + { + Vec3r p(self->fes->normalB()); + bmo->data[index] = p[index]; + } + break; + default: + return -1; + } + return 0; +} -static PyObject * FEdgeSharp_bMaterialIndex( BPy_FEdgeSharp *self ) { - return PyLong_FromLong( self->fes->bFrsMaterialIndex() ); +static int FEdgeSharp_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) +{ + BPy_FEdgeSharp *self = (BPy_FEdgeSharp *)bmo->cb_user; + switch (subtype) { + case MATHUTILS_SUBTYPE_NORMAL_A: + { + Vec3r p(self->fes->normalA()); + p[index] = bmo->data[index]; + self->fes->setNormalA(p); + } + break; + case MATHUTILS_SUBTYPE_NORMAL_B: + { + Vec3r p(self->fes->normalB()); + p[index] = bmo->data[index]; + self->fes->setNormalB(p); + } + break; + default: + return -1; + } + return 0; } -static char FEdgeSharp_aMaterial___doc__[] = -".. method:: aMaterial()\n" -"\n" -" Returns the material of the face lying on the right of the FEdge. If\n" -" this FEdge is a border, it has no Face on its right and therefore, no\n" -" material.\n" -"\n" -" :return: The material of the face lying on the right of the FEdge.\n" -" :rtype: :class:`Material`\n"; +static Mathutils_Callback FEdgeSharp_mathutils_cb = { + FEdgeSharp_mathutils_check, + FEdgeSharp_mathutils_get, + FEdgeSharp_mathutils_set, + FEdgeSharp_mathutils_get_index, + FEdgeSharp_mathutils_set_index +}; -static PyObject * FEdgeSharp_aMaterial( BPy_FEdgeSharp *self ) { - FrsMaterial m( self->fes->aFrsMaterial() ); - return BPy_FrsMaterial_from_FrsMaterial(m); +static unsigned char FEdgeSharp_mathutils_cb_index = -1; + +void FEdgeSharp_mathutils_register_callback() +{ + FEdgeSharp_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSharp_mathutils_cb); } -static char FEdgeSharp_bMaterial___doc__[] = -".. method:: bMaterial()\n" -"\n" -" Returns the material of the face lying on the left of the FEdge.\n" +/*----------------------FEdgeSharp get/setters ----------------------------*/ + +PyDoc_STRVAR(FEdgeSharp_normal_right_doc, +"The normal to the face lying on the right of the FEdge. If this FEdge\n" +"is a border, it has no Face on its right and therefore no normal.\n" "\n" -" :return: The material of the face lying on the left of the FEdge.\n" -" :rtype: :class:`Material`\n"; +":type: :class:`mathutils.Vector`"); -static PyObject * FEdgeSharp_bMaterial( BPy_FEdgeSharp *self ) { - FrsMaterial m( self->fes->aFrsMaterial() ); - return BPy_FrsMaterial_from_FrsMaterial(m); +static PyObject *FEdgeSharp_normal_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSharp_mathutils_cb_index, MATHUTILS_SUBTYPE_NORMAL_A); } -static char FEdgeSharp_aFaceMark___doc__[] = -".. method:: aFaceMark()\n" -"\n" -" Returns the face mark of the face lying on the right of the FEdge.\n" -" If this FEdge is a border, it has no face on the right, and thus\n" -" false is returned.\n" -"\n" -" :return: The face mark of the face lying on the right of the FEdge.\n" -" :rtype: bool\n"; - -static PyObject * FEdgeSharp_aFaceMark( BPy_FEdgeSharp *self ) { - return PyBool_from_bool( self->fes->aFaceMark() ); +static int FEdgeSharp_normal_right_set(BPy_FEdgeSharp *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; + } + Vec3r p(v[0], v[1], v[2]); + self->fes->setNormalA(p); + return 0; } -static char FEdgeSharp_bFaceMark___doc__[] = -".. method:: bFaceMark()\n" +PyDoc_STRVAR(FEdgeSharp_normal_left_doc, +"The normal to the face lying on the left of the FEdge.\n" "\n" -" Returns the face mark of the face lying on the left of the FEdge.\n" -"\n" -" :return: The face mark of the face lying on the left of the FEdge.\n" -" :rtype: bool\n"; +":type: :class:`mathutils.Vector`"); -static PyObject * FEdgeSharp_bFaceMark( BPy_FEdgeSharp *self ) { - return PyBool_from_bool( self->fes->bFaceMark() ); +static PyObject *FEdgeSharp_normal_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSharp_mathutils_cb_index, MATHUTILS_SUBTYPE_NORMAL_B); } -static char FEdgeSharp_setNormalA___doc__[] = -".. method:: setNormalA(iNormal)\n" -"\n" -" Sets the normal to the face lying on the right of the FEdge.\n" -"\n" -" :arg iNormal: A three-dimensional vector.\n" -" :type iNormal: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; - -static PyObject * FEdgeSharp_setNormalA( BPy_FEdgeSharp *self, PyObject *args ) { - PyObject *obj = 0; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) - return NULL; - Vec3r *v = Vec3r_ptr_from_PyObject(obj); - 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 FEdgeSharp_normal_left_set(BPy_FEdgeSharp *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->fes->setNormalA( *v ); - delete v; - - Py_RETURN_NONE; + Vec3r p(v[0], v[1], v[2]); + self->fes->setNormalB(p); + return 0; } -static char FEdgeSharp_setNormalB___doc__[] = -".. method:: setNormalB(iNormal)\n" -"\n" -" Sets the normal to the face lying on the left of the FEdge.\n" +PyDoc_STRVAR(FEdgeSharp_material_index_right_doc, +"The index of the material of the face lying on the right of the FEdge.\n" +"If this FEdge is a border, it has no Face on its right and therefore\n" +"no material.\n" "\n" -" :arg iNormal: A three-dimensional vector.\n" -" :type iNormal: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; - -static PyObject * FEdgeSharp_setNormalB( BPy_FEdgeSharp *self, PyObject *args ) { - PyObject *obj = 0; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) - return NULL; - Vec3r *v = Vec3r_ptr_from_PyObject(obj); - if( !v ) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return NULL; - } - self->fes->setNormalB( *v ); - delete v; +":type: int"); - Py_RETURN_NONE; +static PyObject *FEdgeSharp_material_index_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + return PyLong_FromLong(self->fes->aFrsMaterialIndex()); } -static char FEdgeSharp_setaMaterialIndex___doc__[] = -".. method:: setaMaterialIndex(i)\n" -"\n" -" Sets the index of the material lying on the right of the FEdge.\n" -"\n" -" :arg i: A material index.\n" -" :type i: int\n"; +static int FEdgeSharp_material_index_right_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +{ + unsigned int i = PyLong_AsUnsignedLong(value); + if(PyErr_Occurred()) + return -1; + self->fes->setaFrsMaterialIndex(i); + return 0; +} -static PyObject * FEdgeSharp_setaMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) { - unsigned int i; +PyDoc_STRVAR(FEdgeSharp_material_index_left_doc, +"The index of the material of the face lying on the left of the FEdge.\n" +"\n" +":type: int"); - if(!( PyArg_ParseTuple(args, "I", &i) )) - return NULL; - - self->fes->setaFrsMaterialIndex( i ); +static PyObject *FEdgeSharp_material_index_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + return PyLong_FromLong(self->fes->aFrsMaterialIndex()); +} - Py_RETURN_NONE; +static int FEdgeSharp_material_index_left_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +{ + unsigned int i = PyLong_AsUnsignedLong(value); + if(PyErr_Occurred()) + return -1; + self->fes->setbFrsMaterialIndex(i); + return 0; } -static char FEdgeSharp_setbMaterialIndex___doc__[] = -".. method:: setbMaterialIndex(i)\n" +PyDoc_STRVAR(FEdgeSharp_material_right_doc, +"The material of the face lying on the right of the FEdge. If this FEdge\n" +"is a border, it has no Face on its right and therefore no material.\n" "\n" -" Sets the index of the material lying on the left of the FEdge.\n" -"\n" -" :arg i: A material index.\n" -" :type i: int\n"; +":type: :class:`Material`"); -static PyObject * FEdgeSharp_setbMaterialIndex( BPy_FEdgeSharp *self, PyObject *args ) { - unsigned int i; +static PyObject *FEdgeSharp_material_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + // FIXME aFrsMaterial() returns a const reference. + FrsMaterial m(self->fes->aFrsMaterial()); + return BPy_FrsMaterial_from_FrsMaterial(m); +} - if(!( PyArg_ParseTuple(args, "I", &i) )) - return NULL; - - self->fes->setbFrsMaterialIndex( i ); +PyDoc_STRVAR(FEdgeSharp_material_left_doc, +"The material of the face lying on the left of the FEdge.\n" +"\n" +":type: :class:`Material`"); - Py_RETURN_NONE; +static PyObject *FEdgeSharp_material_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + // FIXME bFrsMaterial() returns a const reference. + FrsMaterial m(self->fes->bFrsMaterial()); + return BPy_FrsMaterial_from_FrsMaterial(m); } -static char FEdgeSharp_setaFaceMark___doc__[] = -".. method:: setaFaceMark(i)\n" -"\n" -" Sets the face mark of the face lying on the right of the FEdge.\n" +PyDoc_STRVAR(FEdgeSharp_face_mark_right_doc, +"The face mark of the face lying on the right of the FEdge. If this FEdge\n" +"is a border, it has no face on the right and thus this property is set to\n" +"false.\n" "\n" -" :arg i: A face mark.\n" -" :type i: bool\n"; +":type: bool"); -static PyObject * FEdgeSharp_setaFaceMark( BPy_FEdgeSharp *self, PyObject *args ) { - PyObject *obj; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) - return NULL; - - self->fes->setaFaceMark( bool_from_PyBool(obj) ); +static PyObject *FEdgeSharp_face_mark_right_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->fes->aFaceMark()); +} - Py_RETURN_NONE; +static int FEdgeSharp_face_mark_right_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +{ + if(!PyBool_Check(value)) + return -1; + self->fes->setaFaceMark(bool_from_PyBool(value)); + return 0; } -static char FEdgeSharp_setbFaceMark___doc__[] = -".. method:: setbFaceMark(i)\n" +PyDoc_STRVAR(FEdgeSharp_face_mark_left_doc, +"The face mark of the face lying on the left of the FEdge.\n" "\n" -" Sets the face mark of the face lying on the left of the FEdge.\n" -"\n" -" :arg i: A face mark.\n" -" :type i: bool\n"; - -static PyObject * FEdgeSharp_setbFaceMark( BPy_FEdgeSharp *self, PyObject *args ) { - PyObject *obj; +":type: bool"); - if(!( PyArg_ParseTuple(args, "O", &obj) )) - return NULL; - - self->fes->setbFaceMark( bool_from_PyBool(obj) ); +static PyObject *FEdgeSharp_face_mark_left_get(BPy_FEdgeSharp *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->fes->bFaceMark()); +} - Py_RETURN_NONE; +static int FEdgeSharp_face_mark_left_set(BPy_FEdgeSharp *self, PyObject *value, void *UNUSED(closure)) +{ + if(!PyBool_Check(value)) + return -1; + self->fes->setbFaceMark(bool_from_PyBool(value)); + return 0; } -/*----------------------FEdgeSharp instance definitions ----------------------------*/ -static PyMethodDef BPy_FEdgeSharp_methods[] = { - {"normalA", ( PyCFunction ) FEdgeSharp_normalA, METH_NOARGS, FEdgeSharp_normalA___doc__}, - {"normalB", ( PyCFunction ) FEdgeSharp_normalB, METH_NOARGS, FEdgeSharp_normalB___doc__}, - {"aMaterialIndex", ( PyCFunction ) FEdgeSharp_aMaterialIndex, METH_NOARGS, FEdgeSharp_aMaterialIndex___doc__}, - {"bMaterialIndex", ( PyCFunction ) FEdgeSharp_bMaterialIndex, METH_NOARGS, FEdgeSharp_bMaterialIndex___doc__}, - {"aMaterial", ( PyCFunction ) FEdgeSharp_aMaterial, METH_NOARGS, FEdgeSharp_aMaterial___doc__}, - {"bMaterial", ( PyCFunction ) FEdgeSharp_bMaterial, METH_NOARGS, FEdgeSharp_bMaterial___doc__}, - {"aFaceMark", ( PyCFunction ) FEdgeSharp_aFaceMark, METH_NOARGS, FEdgeSharp_aFaceMark___doc__}, - {"bFaceMark", ( PyCFunction ) FEdgeSharp_bFaceMark, METH_NOARGS, FEdgeSharp_bFaceMark___doc__}, - {"setNormalA", ( PyCFunction ) FEdgeSharp_setNormalA, METH_VARARGS, FEdgeSharp_setNormalA___doc__}, - {"setNormalB", ( PyCFunction ) FEdgeSharp_setNormalB, METH_VARARGS, FEdgeSharp_setNormalB___doc__}, - {"setaMaterialIndex", ( PyCFunction ) FEdgeSharp_setaMaterialIndex, METH_VARARGS, FEdgeSharp_setaMaterialIndex___doc__}, - {"setbMaterialIndex", ( PyCFunction ) FEdgeSharp_setbMaterialIndex, METH_VARARGS, FEdgeSharp_setbMaterialIndex___doc__}, - {"setaFaceMark", ( PyCFunction ) FEdgeSharp_setaFaceMark, METH_NOARGS, FEdgeSharp_setaFaceMark___doc__}, - {"setbFaceMark", ( PyCFunction ) FEdgeSharp_setbFaceMark, METH_NOARGS, FEdgeSharp_setbFaceMark___doc__}, - {NULL, NULL, 0, NULL} +static PyGetSetDef BPy_FEdgeSharp_getseters[] = { + {(char *)"normal_right", (getter)FEdgeSharp_normal_right_get, (setter)FEdgeSharp_normal_right_set, (char *)FEdgeSharp_normal_right_doc, NULL}, + {(char *)"normal_left", (getter)FEdgeSharp_normal_left_get, (setter)FEdgeSharp_normal_left_set, (char *)FEdgeSharp_normal_left_doc, NULL}, + {(char *)"material_index_right", (getter)FEdgeSharp_material_index_right_get, (setter)FEdgeSharp_material_index_right_set, (char *)FEdgeSharp_material_index_right_doc, NULL}, + {(char *)"material_index_left", (getter)FEdgeSharp_material_index_left_get, (setter)FEdgeSharp_material_index_left_set, (char *)FEdgeSharp_material_index_left_doc, NULL}, + {(char *)"material_right", (getter)FEdgeSharp_material_right_get, (setter)NULL, (char *)FEdgeSharp_material_right_doc, NULL}, + {(char *)"material_left", (getter)FEdgeSharp_material_left_get, (setter)NULL, (char *)FEdgeSharp_material_left_doc, NULL}, + {(char *)"face_mark_right", (getter)FEdgeSharp_face_mark_right_get, (setter)FEdgeSharp_face_mark_right_set, (char *)FEdgeSharp_face_mark_right_doc, NULL}, + {(char *)"face_mark_left", (getter)FEdgeSharp_face_mark_left_get, (setter)FEdgeSharp_face_mark_left_set, (char *)FEdgeSharp_face_mark_left_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FEdgeSharp type definition ------------------------------*/ @@ -346,7 +378,7 @@ PyTypeObject FEdgeSharp_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FEdgeSharp___doc__, /* tp_doc */ + FEdgeSharp_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -355,13 +387,13 @@ PyTypeObject FEdgeSharp_Type = { 0, /* tp_iternext */ BPy_FEdgeSharp_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_FEdgeSharp_getseters, /* tp_getset */ &FEdge_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)FEdgeSharp___init__, /* tp_init */ + (initproc)FEdgeSharp_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h index 84b01e27c21..b0e35395b66 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSharp.h @@ -22,6 +22,10 @@ typedef struct { FEdgeSharp *fes; } BPy_FEdgeSharp; +/*---------------------------Python BPy_FEdgeSharp visible prototypes-----------*/ + +void FEdgeSharp_mathutils_register_callback(); + /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp index 3ddb4d060de..abda2ca1179 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp @@ -9,9 +9,9 @@ extern "C" { /////////////////////////////////////////////////////////////////////////////////////////// -//------------------------INSTANCE METHODS ---------------------------------- +/*----------------------FEdgeSmooth methods ----------------------------*/ -static char FEdgeSmooth___doc__[] = +PyDoc_STRVAR(FEdgeSmooth_doc, "Class hierarchy: :class:`Interface1D` > :class:`FEdge` > :class:`FEdgeSmooth`\n" "\n" "Class defining a smooth edge. This kind of edge typically runs across\n" @@ -36,23 +36,23 @@ static char FEdgeSmooth___doc__[] = " :arg vA: The first SVertex object.\n" " :type vA: :class:`SVertex`\n" " :arg vB: The second SVertex object.\n" -" :type vB: :class:`SVertex`\n"; +" :type vB: :class:`SVertex`"); -static int FEdgeSmooth___init__(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds) +static int FEdgeSmooth_init(BPy_FEdgeSmooth *self, PyObject *args, PyObject *kwds) { PyObject *obj1 = 0, *obj2 = 0; - if (! PyArg_ParseTuple(args, "|OO", &obj1, &obj2) ) - return -1; + if (!PyArg_ParseTuple(args, "|OO", &obj1, &obj2)) + return -1; - if( !obj1 ){ + if (!obj1) { self->fes = new FEdgeSmooth(); - - } else if( !obj2 && BPy_FEdgeSmooth_Check(obj1) ) { - self->fes = new FEdgeSmooth(*( ((BPy_FEdgeSmooth *) obj1)->fes )); - - } else if( obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2) ) { - self->fes = new FEdgeSmooth( ((BPy_SVertex *) obj1)->sv, ((BPy_SVertex *) obj2)->sv ); + + } else if (!obj2 && BPy_FEdgeSmooth_Check(obj1)) { + self->fes = new FEdgeSmooth(*(((BPy_FEdgeSmooth *)obj1)->fes)); + + } else if (obj2 && BPy_SVertex_Check(obj1) && BPy_SVertex_Check(obj2)) { + self->fes = new FEdgeSmooth(((BPy_SVertex *)obj1)->sv, ((BPy_SVertex *)obj2)->sv); } else { PyErr_SetString(PyExc_TypeError, "invalid argument(s)"); @@ -66,128 +66,148 @@ static int FEdgeSmooth___init__(BPy_FEdgeSmooth *self, PyObject *args, PyObject return 0; } -static char FEdgeSmooth_normal___doc__[] = -".. method:: normal()\n" -"\n" -" Returns the normal to the Face it is running accross.\n" -"\n" -" :return: The normal to the Face it is running accross.\n" -" :rtype: :class:`mathutils.Vector`\n"; +static PyMethodDef BPy_FEdgeSmooth_methods[] = { + {NULL, NULL, 0, NULL} +}; + +/*----------------------mathutils callbacks ----------------------------*/ -static PyObject * FEdgeSmooth_normal( BPy_FEdgeSmooth *self ) { - Vec3r v( self->fes->normal() ); - return Vector_from_Vec3r( v ); +static int FEdgeSmooth_mathutils_check(BaseMathObject *bmo) +{ + if (!BPy_FEdgeSmooth_Check(bmo->cb_user)) + return -1; + return 0; } -static char FEdgeSmooth_materialIndex___doc__[] = -".. method:: materialIndex()\n" -"\n" -" Returns the index of the material of the face it is running accross.\n" -"\n" -" :return: The index of the material of the face it is running accross.\n" -" :rtype: int\n"; +static int FEdgeSmooth_mathutils_get(BaseMathObject *bmo, int subtype) +{ + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(self->fes->normal()); + bmo->data[0] = p[0]; + bmo->data[1] = p[1]; + bmo->data[2] = p[2]; + return 0; +} -static PyObject * FEdgeSmooth_materialIndex( BPy_FEdgeSmooth *self ) { - return PyLong_FromLong( self->fes->frs_materialIndex() ); +static int FEdgeSmooth_mathutils_set(BaseMathObject *bmo, int subtype) +{ + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(bmo->data[0], bmo->data[1], bmo->data[2]); + self->fes->setNormal(p); + return 0; } -static char FEdgeSmooth_material___doc__[] = -".. method:: material()\n" -"\n" -" Returns the material of the face it is running accross.\n" -"\n" -" :return: The material of the face it is running accross.\n" -" :rtype: :class:`Material`\n"; +static int FEdgeSmooth_mathutils_get_index(BaseMathObject *bmo, int subtype, int index) +{ + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(self->fes->normal()); + bmo->data[index] = p[index]; + return 0; +} -static PyObject * FEdgeSmooth_material( BPy_FEdgeSmooth *self ) { - FrsMaterial m( self->fes->frs_material() ); - return BPy_FrsMaterial_from_FrsMaterial(m); +static int FEdgeSmooth_mathutils_set_index(BaseMathObject *bmo, int subtype, int index) +{ + BPy_FEdgeSmooth *self = (BPy_FEdgeSmooth *)bmo->cb_user; + Vec3r p(self->fes->normal()); + p[index] = bmo->data[index]; + self->fes->setNormal(p); + return 0; } -static char FEdgeSmooth_faceMark___doc__[] = -".. method:: faceMark()\n" -"\n" -" Returns the face mark of the face it is running across.\n" -"\n" -" :return: The face mark of the face it is running across.\n" -" :rtype: bool\n"; +static Mathutils_Callback FEdgeSmooth_mathutils_cb = { + FEdgeSmooth_mathutils_check, + FEdgeSmooth_mathutils_get, + FEdgeSmooth_mathutils_set, + FEdgeSmooth_mathutils_get_index, + FEdgeSmooth_mathutils_set_index +}; + +static unsigned char FEdgeSmooth_mathutils_cb_index = -1; -static PyObject * FEdgeSmooth_faceMark( BPy_FEdgeSmooth *self ) { - return PyBool_from_bool( self->fes->faceMark() ); +void FEdgeSmooth_mathutils_register_callback() +{ + FEdgeSmooth_mathutils_cb_index = Mathutils_RegisterCallback(&FEdgeSmooth_mathutils_cb); } -static char FEdgeSmooth_setNormal___doc__[] = -".. method:: setNormal(iNormal)\n" -"\n" -" Sets the normal to the Face it is running accross.\n" +/*----------------------FEdgeSmooth get/setters ----------------------------*/ + +PyDoc_STRVAR(FEdgeSmooth_normal_doc, +"The normal of the face that this FEdge is running across.\n" "\n" -" :arg iNormal: A three-dimensional vector.\n" -" :type iNormal: :class:`mathutils.Vector`, list or tuple of 3 real numbers\n"; - -static PyObject * FEdgeSmooth_setNormal( BPy_FEdgeSmooth *self, PyObject *args ) { - PyObject *obj = 0; - - if(!( PyArg_ParseTuple(args, "O", &obj) )) - return NULL; - Vec3r *v = Vec3r_ptr_from_PyObject(obj); - if( !v ) { - PyErr_SetString(PyExc_TypeError, "argument 1 must be a 3D vector (either a list of 3 elements or Vector)"); - return NULL; - } - self->fes->setNormal( *v ); - delete v; +":type: :class:`mathutils.Vector`"); - Py_RETURN_NONE; +static PyObject *FEdgeSmooth_normal_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) +{ + return Vector_CreatePyObject_cb((PyObject *)self, 3, FEdgeSmooth_mathutils_cb_index, 0); } -static char FEdgeSmooth_setMaterialIndex___doc__[] = -".. method:: setMaterialIndex(i)\n" -"\n" -" Sets the index of the material of the face it is running accross.\n" -"\n" -" :arg i: The index of the material of the face it is running accross.\n" -" :type i: int\n"; +static int FEdgeSmooth_normal_set(BPy_FEdgeSmooth *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; + } + Vec3r p(v[0], v[1], v[2]); + self->fes->setNormal(p); + return 0; +} -static PyObject * FEdgeSmooth_setMaterialIndex( BPy_FEdgeSmooth *self, PyObject *args ) { - unsigned int i; +PyDoc_STRVAR(FEdgeSmooth_material_index_doc, +"The index of the material of the face that this FEdge is running across.\n" +"\n" +":type: int"); - if(!( PyArg_ParseTuple(args, "I", &i) )) - return NULL; - - self->fes->setFrsMaterialIndex( i ); +static PyObject *FEdgeSmooth_material_index_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) +{ + return PyLong_FromLong(self->fes->frs_materialIndex()); +} - Py_RETURN_NONE; +static int FEdgeSmooth_material_index_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure)) +{ + unsigned int i = PyLong_AsUnsignedLong(value); + if(PyErr_Occurred()) + return -1; + self->fes->setFrsMaterialIndex(i); + return 0; } -static char FEdgeSmooth_setFaceMark___doc__[] = -".. method:: setFaceMark(i)\n" -"\n" -" Sets the face mark of the face it is running across.\n" +PyDoc_STRVAR(FEdgeSmooth_material_doc, +"The material of the face that this FEdge is running across.\n" "\n" -" :arg i: A face mark.\n" -" :type i: bool\n"; +":type: :class:`Material`"); -static PyObject * FEdgeSmooth_setFaceMark( BPy_FEdgeSmooth *self, PyObject *args ) { - PyObject *obj; +static PyObject *FEdgeSmooth_material_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) +{ + // FIXME frs_material() returns a const reference. + FrsMaterial m(self->fes->frs_material()); + return BPy_FrsMaterial_from_FrsMaterial(m); +} - if(!( PyArg_ParseTuple(args, "O", &obj) )) - return NULL; - - self->fes->setFaceMark( bool_from_PyBool(obj) ); +PyDoc_STRVAR(FEdgeSmooth_face_mark_doc, +"The face mark of the face that this FEdge is running across.\n" +"\n" +":type: bool"); - Py_RETURN_NONE; +static PyObject *FEdgeSmooth_face_mark_get(BPy_FEdgeSmooth *self, void *UNUSED(closure)) +{ + return PyBool_from_bool(self->fes->faceMark()); } -/*----------------------FEdgeSmooth instance definitions ----------------------------*/ -static PyMethodDef BPy_FEdgeSmooth_methods[] = { - {"normal", ( PyCFunction ) FEdgeSmooth_normal, METH_NOARGS, FEdgeSmooth_normal___doc__}, - {"materialIndex", ( PyCFunction ) FEdgeSmooth_materialIndex, METH_NOARGS, FEdgeSmooth_materialIndex___doc__}, - {"material", ( PyCFunction ) FEdgeSmooth_material, METH_NOARGS, FEdgeSmooth_material___doc__}, - {"faceMark", ( PyCFunction ) FEdgeSmooth_faceMark, METH_NOARGS, FEdgeSmooth_faceMark___doc__}, - {"setNormal", ( PyCFunction ) FEdgeSmooth_setNormal, METH_VARARGS, FEdgeSmooth_setNormal___doc__}, - {"setMaterialIndex", ( PyCFunction ) FEdgeSmooth_setMaterialIndex, METH_VARARGS, FEdgeSmooth_setMaterialIndex___doc__}, - {"setFaceMark", ( PyCFunction ) FEdgeSmooth_setFaceMark, METH_VARARGS, FEdgeSmooth_setFaceMark___doc__}, - {NULL, NULL, 0, NULL} +static int FEdgeSmooth_face_mark_set(BPy_FEdgeSmooth *self, PyObject *value, void *UNUSED(closure)) +{ + if(!PyBool_Check(value)) + return -1; + self->fes->setFaceMark(bool_from_PyBool(value)); + return 0; +} + +static PyGetSetDef BPy_FEdgeSmooth_getseters[] = { + {(char *)"normal", (getter)FEdgeSmooth_normal_get, (setter)FEdgeSmooth_normal_set, (char *)FEdgeSmooth_normal_doc, NULL}, + {(char *)"material_index", (getter)FEdgeSmooth_material_index_get, (setter)FEdgeSmooth_material_index_set, (char *)FEdgeSmooth_material_index_doc, NULL}, + {(char *)"material", (getter)FEdgeSmooth_material_get, (setter)NULL, (char *)FEdgeSmooth_material_doc, NULL}, + {(char *)"face_mark", (getter)FEdgeSmooth_face_mark_get, (setter)FEdgeSmooth_face_mark_set, (char *)FEdgeSmooth_face_mark_doc, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; /*-----------------------BPy_FEdgeSmooth type definition ------------------------------*/ @@ -213,7 +233,7 @@ PyTypeObject FEdgeSmooth_Type = { 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - FEdgeSmooth___doc__, /* tp_doc */ + FEdgeSmooth_doc, /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */ @@ -222,13 +242,13 @@ PyTypeObject FEdgeSmooth_Type = { 0, /* tp_iternext */ BPy_FEdgeSmooth_methods, /* tp_methods */ 0, /* tp_members */ - 0, /* tp_getset */ + BPy_FEdgeSmooth_getseters, /* tp_getset */ &FEdge_Type, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ 0, /* tp_dictoffset */ - (initproc)FEdgeSmooth___init__, /* tp_init */ + (initproc)FEdgeSmooth_init, /* tp_init */ 0, /* tp_alloc */ 0, /* tp_new */ }; diff --git a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h index d7b44bb1da7..7f7d0aaa3b7 100644 --- a/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h +++ b/source/blender/freestyle/intern/python/Interface1D/FEdge/BPy_FEdgeSmooth.h @@ -22,6 +22,10 @@ typedef struct { FEdgeSmooth *fes; } BPy_FEdgeSmooth; +/*---------------------------Python BPy_FEdgeSmooth visible prototypes-----------*/ + +void FEdgeSmooth_mathutils_register_callback(); + /////////////////////////////////////////////////////////////////////////////////////////// #ifdef __cplusplus |