Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-15 03:48:34 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-02-15 03:48:34 +0400
commit731d08d4974ce695e7d1446b934d0656a4d82942 (patch)
tree6568f2d1befa6c4cac0005bc4dcf3e239363757f /source/blender/freestyle/intern/python/BPy_Id.cpp
parent9e3bf44011285917db1e1061a2f459722674b1b9 (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/BPy_Id.cpp')
-rw-r--r--source/blender/freestyle/intern/python/BPy_Id.cpp120
1 files changed, 53 insertions, 67 deletions
diff --git a/source/blender/freestyle/intern/python/BPy_Id.cpp b/source/blender/freestyle/intern/python/BPy_Id.cpp
index 8f8336f6c17..54942abb58d 100644
--- a/source/blender/freestyle/intern/python/BPy_Id.cpp
+++ b/source/blender/freestyle/intern/python/BPy_Id.cpp
@@ -76,68 +76,6 @@ static PyObject * Id___repr__(BPy_Id* self)
return PyUnicode_FromFormat("[ first: %i, second: %i ](BPy_Id)", self->id->getFirst(), self->id->getSecond() );
}
-static char Id_getFirst___doc__[] =
-".. method:: getFirst()\n"
-"\n"
-" Returns the first Id number.\n"
-"\n"
-" :return: The first Id number.\n"
-" :rtype: int\n";
-
-static PyObject *Id_getFirst( BPy_Id *self ) {
- return PyLong_FromLong( self->id->getFirst() );
-}
-
-static char Id_getSecond___doc__[] =
-".. method:: getSecond()\n"
-"\n"
-" Returns the second Id number.\n"
-"\n"
-" :return: The second Id number.\n"
-" :rtype: int\n";
-
-static PyObject *Id_getSecond( BPy_Id *self) {
- return PyLong_FromLong( self->id->getSecond() );
-}
-
-static char Id_setFirst___doc__[] =
-".. method:: setFirst(iFirst)\n"
-"\n"
-" Sets the first number constituting the Id.\n"
-"\n"
-" :arg iFirst: The first number constituting the Id.\n"
-" :type iFirst: int\n";
-
-static PyObject *Id_setFirst( BPy_Id *self , PyObject *args) {
- unsigned int i;
-
- if( !PyArg_ParseTuple(args, "i", &i) )
- return NULL;
-
- self->id->setFirst( i );
-
- Py_RETURN_NONE;
-}
-
-static char Id_setSecond___doc__[] =
-".. method:: setSecond(iSecond)\n"
-"\n"
-" Sets the second number constituting the Id.\n"
-"\n"
-" :arg iSecond: The second number constituting the Id.\n"
-" :type iSecond: int\n";
-
-static PyObject *Id_setSecond( BPy_Id *self , PyObject *args) {
- unsigned int i;
-
- if( !PyArg_ParseTuple(args, "i", &i) )
- return NULL;
-
- self->id->setSecond( i );
-
- Py_RETURN_NONE;
-}
-
static PyObject * Id_RichCompare(BPy_Id *o1, BPy_Id *o2, int opid) {
switch(opid){
case Py_LT:
@@ -165,13 +103,61 @@ static PyObject * Id_RichCompare(BPy_Id *o1, BPy_Id *o2, int opid) {
/*----------------------Id instance definitions ----------------------------*/
static PyMethodDef BPy_Id_methods[] = {
- {"getFirst", ( PyCFunction ) Id_getFirst, METH_NOARGS, Id_getFirst___doc__},
- {"getSecond", ( PyCFunction ) Id_getSecond, METH_NOARGS, Id_getSecond___doc__},
- {"setFirst", ( PyCFunction ) Id_setFirst, METH_VARARGS, Id_setFirst___doc__},
- {"setSecond", ( PyCFunction ) Id_setSecond, METH_VARARGS, Id_setSecond___doc__},
{NULL, NULL, 0, NULL}
};
+/*----------------------Id get/setters ----------------------------*/
+
+PyDoc_STRVAR(Id_first_doc,
+"The first number constituting the Id.\n"
+"\n"
+":type: int"
+);
+
+static PyObject *Id_first_get(BPy_Id *self, void *UNUSED(closure))
+{
+ return PyLong_FromLong(self->id->getFirst());
+}
+
+static int Id_first_set(BPy_Id *self, PyObject *value, void *UNUSED(closure))
+{
+ int scalar;
+ if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "value must be an integer");
+ return -1;
+ }
+ self->id->setFirst(scalar);
+ return 0;
+}
+
+PyDoc_STRVAR(Id_second_doc,
+"The second number constituting the Id.\n"
+"\n"
+":type: int"
+);
+
+static PyObject *Id_second_get(BPy_Id *self, void *UNUSED(closure))
+{
+ return PyLong_FromLong(self->id->getSecond());
+}
+
+static int Id_second_set(BPy_Id *self, PyObject *value, void *UNUSED(closure))
+{
+ int scalar;
+ if ((scalar = PyLong_AsLong(value)) == -1 && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "value must be an integer");
+ return -1;
+ }
+ self->id->setSecond(scalar);
+ return 0;
+}
+
+static PyGetSetDef BPy_Id_getseters[] = {
+ {(char *)"first", (getter)Id_first_get, (setter)Id_first_set, (char *)Id_first_doc, NULL},
+ {(char *)"second", (getter)Id_second_get, (setter)Id_second_set, (char *)Id_second_doc, NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
+};
+
/*-----------------------BPy_Id type definition ------------------------------*/
PyTypeObject Id_Type = {
@@ -204,7 +190,7 @@ PyTypeObject Id_Type = {
0, /* tp_iternext */
BPy_Id_methods, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ BPy_Id_getseters, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */