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/Interface0D/BPy_CurvePoint.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/Interface0D/BPy_CurvePoint.cpp')
-rw-r--r--source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp182
1 files changed, 75 insertions, 107 deletions
diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp
index e213edd5c79..3e2cc495785 100644
--- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp
+++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp
@@ -9,9 +9,9 @@ extern "C" {
///////////////////////////////////////////////////////////////////////////////////////////
-//------------------------INSTANCE METHODS ----------------------------------
+/*----------------------CurvePoint methods----------------------------*/
-static char CurvePoint___doc__[] =
+PyDoc_STRVAR(CurvePoint_doc,
"Class hierarchy: :class:`Interface0D` > :class:`CurvePoint`\n"
"\n"
"Class to represent a point of a curve. A CurvePoint can be any point\n"
@@ -57,15 +57,15 @@ static char CurvePoint___doc__[] =
" :type iB: :class:`CurvePoint`\n"
" :arg t2d: The 2D interpolation parameter used to linearly\n"
" interpolate iA and iB.\n"
-" :type t2d: float\n";
+" :type t2d: float");
-static int CurvePoint___init__(BPy_CurvePoint *self, PyObject *args, PyObject *kwds)
+static int CurvePoint_init(BPy_CurvePoint *self, PyObject *args, PyObject *kwds)
{
PyObject *obj1 = 0, *obj2 = 0 , *obj3 = 0;
- if (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) )
- return -1;
+ if (! PyArg_ParseTuple(args, "|OOO!", &obj1, &obj2, &PyFloat_Type, &obj3) )
+ return -1;
if( !obj1 ){
self->cp = new CurvePoint();
@@ -102,131 +102,99 @@ static int CurvePoint___init__(BPy_CurvePoint *self, PyObject *args, PyObject *k
return 0;
}
-static char CurvePoint_A___doc__[] =
-".. method:: A()\n"
-"\n"
-" Returns the first SVertex upon which the CurvePoint is built.\n"
-"\n"
-" :return: The first SVertex.\n"
-" :rtype: :class:`SVertex`\n";
+///bool operator== (const CurvePoint &b)
-static PyObject * CurvePoint_A( BPy_CurvePoint *self ) {
- SVertex *A = self->cp->A();
- if( A )
- return BPy_SVertex_from_SVertex( *A );
+static PyMethodDef BPy_CurvePoint_methods[] = {
+ {NULL, NULL, 0, NULL}
+};
- Py_RETURN_NONE;
-}
+/*----------------------CurvePoint get/setters ----------------------------*/
-static char CurvePoint_B___doc__[] =
-".. method:: B()\n"
+PyDoc_STRVAR(CurvePoint_first_svertex_doc,
+"The first SVertex upon which the CurvePoint is built.\n"
"\n"
-" Returns the second SVertex upon which the CurvePoint is built.\n"
-"\n"
-" :return: The second SVertex.\n"
-" :rtype: :class:`SVertex`\n";
-
-static PyObject * CurvePoint_B( BPy_CurvePoint *self ) {
- SVertex *B = self->cp->B();
- if( B )
- return BPy_SVertex_from_SVertex( *B );
+":type: int");
+static PyObject *CurvePoint_first_svertex_get(BPy_CurvePoint *self, void *UNUSED(closure))
+{
+ SVertex *A = self->cp->A();
+ if (A)
+ return BPy_SVertex_from_SVertex(*A);
Py_RETURN_NONE;
}
-static char CurvePoint_t2d___doc__[] =
-".. method:: t2d()\n"
-"\n"
-" Returns the 2D interpolation parameter.\n"
-"\n"
-" :return: The 2D interpolation parameter.\n"
-" :rtype: float\n";
-
-static PyObject * CurvePoint_t2d( BPy_CurvePoint *self ) {
- return PyFloat_FromDouble( self->cp->t2d() );
+static int CurvePoint_first_svertex_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure))
+{
+ if (!BPy_SVertex_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
+ return -1;
+ }
+ self->cp->setA(((BPy_SVertex *)value)->sv);
+ return 0;
}
-static char CurvePoint_setA___doc__[] =
-".. method:: setA(iA)\n"
+PyDoc_STRVAR(CurvePoint_second_svertex_doc,
+"The second SVertex upon which the CurvePoint is built.\n"
"\n"
-" Sets the first SVertex upon which to build the CurvePoint.\n"
-"\n"
-" :arg iA: The first SVertex.\n"
-" :type iA: :class:`SVertex`\n";
-
-static PyObject *CurvePoint_setA( BPy_CurvePoint *self , PyObject *args) {
- PyObject *py_sv;
-
- if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) ))
- return NULL;
-
- self->cp->setA( ((BPy_SVertex *) py_sv)->sv );
+":type: int");
+static PyObject *CurvePoint_second_svertex_get(BPy_CurvePoint *self, void *UNUSED(closure))
+{
+ SVertex *B = self->cp->B();
+ if (B)
+ return BPy_SVertex_from_SVertex(*B);
Py_RETURN_NONE;
}
-static char CurvePoint_setB___doc__[] =
-".. method:: setB(iB)\n"
-"\n"
-" Sets the first SVertex upon which to build the CurvePoint.\n"
-"\n"
-" :arg iB: The second SVertex.\n"
-" :type iB: :class:`SVertex`\n";
-
-static PyObject *CurvePoint_setB( BPy_CurvePoint *self , PyObject *args) {
- PyObject *py_sv;
-
- if(!( PyArg_ParseTuple(args, "O!", &SVertex_Type, &py_sv) ))
- return NULL;
-
- self->cp->setB( ((BPy_SVertex *) py_sv)->sv );
-
- Py_RETURN_NONE;
+static int CurvePoint_second_svertex_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure))
+{
+ if (!BPy_SVertex_Check(value)) {
+ PyErr_SetString(PyExc_TypeError, "value must be an SVertex");
+ return -1;
+ }
+ self->cp->setB(((BPy_SVertex *)value)->sv);
+ return 0;
}
-static char CurvePoint_setT2d___doc__[] =
-".. method:: setT2d(t)\n"
-"\n"
-" Sets the 2D interpolation parameter to use.\n"
+PyDoc_STRVAR(CurvePoint_t2d_doc,
+"The 2D interpolation parameter.\n"
"\n"
-" :arg t: The 2D interpolation parameter.\n"
-" :type t: float\n";
+":type: float");
-static PyObject *CurvePoint_setT2d( BPy_CurvePoint *self , PyObject *args) {
- float t;
-
- if(!( PyArg_ParseTuple(args, "f", &t) ))
- return NULL;
-
- self->cp->setT2d( t );
+static PyObject *CurvePoint_t2d_get(BPy_CurvePoint *self, void *UNUSED(closure))
+{
+ return PyFloat_FromDouble(self->cp->t2d());
+}
- Py_RETURN_NONE;
+static int CurvePoint_t2d_set(BPy_CurvePoint *self, PyObject *value, void *UNUSED(closure))
+{
+ float scalar;
+ if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
+ PyErr_SetString(PyExc_TypeError, "value must be a number");
+ return -1;
+ }
+ self->cp->setT2d(scalar);
+ return 0;
}
-static char CurvePoint_curvatureFredo___doc__[] =
-".. method:: curvatureFredo()\n"
-"\n"
-" Returns the angle in radians.\n"
+PyDoc_STRVAR(CurvePoint_curvature_fredo_doc,
+"The angle (Fredo's curvature) in radians.\n"
"\n"
-" :return: The angle in radians.\n"
-" :rtype: float\n";
+":type: float");
-static PyObject *CurvePoint_curvatureFredo( BPy_CurvePoint *self , PyObject *args) {
- return PyFloat_FromDouble( self->cp->curvatureFredo() );
+static PyObject *CurvePoint_curvature_fredo_get(BPy_CurvePoint *self, void *UNUSED(closure))
+{
+ return PyFloat_FromDouble(self->cp->curvatureFredo());
}
-///bool operator== (const CurvePoint &b)
+// todo - CurvePoint.directionFredo()
-/*----------------------CurvePoint instance definitions ----------------------------*/
-static PyMethodDef BPy_CurvePoint_methods[] = {
- {"A", ( PyCFunction ) CurvePoint_A, METH_NOARGS, CurvePoint_A___doc__},
- {"B", ( PyCFunction ) CurvePoint_B, METH_NOARGS, CurvePoint_B___doc__},
- {"t2d", ( PyCFunction ) CurvePoint_t2d, METH_NOARGS, CurvePoint_t2d___doc__},
- {"setA", ( PyCFunction ) CurvePoint_setA, METH_VARARGS, CurvePoint_setA___doc__},
- {"setB", ( PyCFunction ) CurvePoint_setB, METH_VARARGS, CurvePoint_setB___doc__},
- {"setT2d", ( PyCFunction ) CurvePoint_setT2d, METH_VARARGS, CurvePoint_setT2d___doc__},
- {"curvatureFredo", ( PyCFunction ) CurvePoint_curvatureFredo, METH_NOARGS, CurvePoint_curvatureFredo___doc__},
- {NULL, NULL, 0, NULL}
+static PyGetSetDef BPy_CurvePoint_getseters[] = {
+ {(char *)"first_svertex", (getter)CurvePoint_first_svertex_get, (setter)CurvePoint_first_svertex_set, (char *)CurvePoint_first_svertex_doc, NULL},
+ {(char *)"second_svertex", (getter)CurvePoint_second_svertex_get, (setter)CurvePoint_second_svertex_set, (char *)CurvePoint_second_svertex_doc, NULL},
+ {(char *)"t2d", (getter)CurvePoint_t2d_get, (setter)CurvePoint_t2d_set, (char *)CurvePoint_t2d_doc, NULL},
+ {(char *)"curvature_fredo", (getter)CurvePoint_curvature_fredo_get, (setter)NULL, (char *)CurvePoint_curvature_fredo_doc, NULL},
+ {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
/*-----------------------BPy_CurvePoint type definition ------------------------------*/
@@ -251,7 +219,7 @@ PyTypeObject CurvePoint_Type = {
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- CurvePoint___doc__, /* tp_doc */
+ CurvePoint_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
@@ -260,13 +228,13 @@ PyTypeObject CurvePoint_Type = {
0, /* tp_iternext */
BPy_CurvePoint_methods, /* tp_methods */
0, /* tp_members */
- 0, /* tp_getset */
+ BPy_CurvePoint_getseters, /* tp_getset */
&Interface0D_Type, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- (initproc)CurvePoint___init__, /* tp_init */
+ (initproc)CurvePoint_init, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};