[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52391] trunk/blender/source/blender/ python/bmesh/bmesh_py_ops.c: bmesh py api: add support for return values from bmesh operators.
Campbell Barton
ideasman42 at gmail.com
Tue Nov 20 03:56:50 CET 2012
Revision: 52391
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52391
Author: campbellbarton
Date: 2012-11-20 02:56:42 +0000 (Tue, 20 Nov 2012)
Log Message:
-----------
bmesh py api: add support for return values from bmesh operators.
Modified Paths:
--------------
trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c 2012-11-20 02:03:20 UTC (rev 52390)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c 2012-11-20 02:56:42 UTC (rev 52391)
@@ -90,6 +90,7 @@
static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
{
+ PyObject *ret;
BPy_BMesh *py_bm;
BMesh *bm;
@@ -316,13 +317,71 @@
}
BMO_op_exec(bm, &bmop);
- BMO_op_finish(bm, &bmop);
- if (bpy_bm_op_as_py_error(bm) == -1) {
- return NULL;
+ /* from here until the end of the function, no returns, just set 'ret' */
+ if (UNLIKELY(bpy_bm_op_as_py_error(bm) == -1)) {
+ ret = NULL; /* exception raised above */
}
+ else if (bmop.slots_out[0].slot_name == NULL) {
+ ret = (Py_INCREF(Py_None), Py_None);
+ }
+ else {
+ /* build return value */
+ int i;
+ ret = PyDict_New();
- Py_RETURN_NONE;
+ for (i = 0; bmop.slots_out[i].slot_name; i++) {
+ // BMOpDefine *op_def = opdefines[bmop.type];
+ // BMOSlotType *slot_type = op_def->slot_types_out[i];
+ BMOpSlot *slot = &bmop.slots_out[i];
+ PyObject *item = NULL;
+
+ /* keep switch in same order as above */
+ switch (slot->slot_type) {
+ case BMO_OP_SLOT_BOOL:
+ item = PyBool_FromLong(slot->data.i);
+ break;
+ case BMO_OP_SLOT_INT:
+ item = PyLong_FromSsize_t((Py_ssize_t)slot->data.i);
+ break;
+ case BMO_OP_SLOT_FLT:
+ item = PyFloat_FromDouble((double)slot->data.f);
+ break;
+ case BMO_OP_SLOT_MAT:
+ item = Matrix_CreatePyObject(slot->data.p, 4, 4, Py_NEW, NULL);
+ break;
+ case BMO_OP_SLOT_VEC:
+ item = Vector_CreatePyObject(slot->data.vec, slot->len, Py_NEW, NULL);
+ break;
+ case BMO_OP_SLOT_ELEMENT_BUF:
+ {
+ const int size = slot->len;
+ int j;
+
+ item = PyList_New(size);
+ for (j = 0; j < size; j++) {
+ BMHeader *ele = ((BMHeader **)slot->data.buf)[i];
+ PyList_SET_ITEM(item, j, ele ? BPy_BMElem_CreatePyObject(bm, ele) : (Py_INCREF(Py_None), Py_None));
+ }
+ break;
+ }
+ case BMO_OP_SLOT_MAPPING:
+ item = (Py_INCREF(Py_None), Py_None);
+ // TODO
+ break;
+ }
+ BLI_assert(item != NULL);
+ if (item == NULL) {
+ item = (Py_INCREF(Py_None), Py_None);
+ }
+
+ PyDict_SetItemString(ret, slot->slot_name, item);
+ Py_DECREF(item);
+ }
+ }
+
+ BMO_op_finish(bm, &bmop);
+ return ret;
}
More information about the Bf-blender-cvs
mailing list