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:
authorCampbell Barton <ideasman42@gmail.com>2012-11-20 06:56:42 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-11-20 06:56:42 +0400
commit050e220a98fde3d077c974d19416babb08147360 (patch)
tree3f406448f722f090824a35f9a12174031dbc9270 /source/blender/python/bmesh/bmesh_py_ops.c
parent609528737a5a613562a171a9308ecf06310a1428 (diff)
bmesh py api: add support for return values from bmesh operators.
Diffstat (limited to 'source/blender/python/bmesh/bmesh_py_ops.c')
-rw-r--r--source/blender/python/bmesh/bmesh_py_ops.c67
1 files changed, 63 insertions, 4 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c
index 8be52dcbe30..a00e09b00ad 100644
--- a/source/blender/python/bmesh/bmesh_py_ops.c
+++ b/source/blender/python/bmesh/bmesh_py_ops.c
@@ -90,6 +90,7 @@ static PyObject *bpy_bmesh_op_repr(BPy_BMeshOpFunc *self)
static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
{
+ PyObject *ret;
BPy_BMesh *py_bm;
BMesh *bm;
@@ -316,13 +317,71 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *
}
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();
+
+ 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);
+ }
}
- Py_RETURN_NONE;
+ BMO_op_finish(bm, &bmop);
+ return ret;
}