[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52605] trunk/blender/source/blender/ python/bmesh: move bmesh operator calling into its own file.

Campbell Barton ideasman42 at gmail.com
Tue Nov 27 14:54:35 CET 2012


Revision: 52605
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52605
Author:   campbellbarton
Date:     2012-11-27 13:54:34 +0000 (Tue, 27 Nov 2012)
Log Message:
-----------
move bmesh operator calling into its own file.

Modified Paths:
--------------
    trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_ops_call.c
    trunk/blender/source/blender/python/bmesh/bmesh_py_ops_call.h

Modified: trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c
===================================================================
--- trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c	2012-11-27 13:45:28 UTC (rev 52604)
+++ trunk/blender/source/blender/python/bmesh/bmesh_py_ops.c	2012-11-27 13:54:34 UTC (rev 52605)
@@ -38,39 +38,19 @@
 
 #include "../generic/py_capi_utils.h"
 
-#include "../mathutils/mathutils.h"
-
 #include "bmesh.h"
 
+#include "bmesh_py_ops_call.h"
 #include "bmesh_py_ops.h"  /* own include */
 
 #include "bmesh_py_types.h"
 
-#include "bmesh_py_utils.h" /* own include */
+#include "bmesh_py_utils.h"
 
-static int bpy_bm_op_as_py_error(BMesh *bm)
-{
-	if (BMO_error_occurred(bm)) {
-		const char *errmsg;
-		if (BMO_error_get(bm, &errmsg, NULL)) {
-			PyErr_Format(PyExc_RuntimeError,
-			             "bmesh operator: %.200s",
-			             errmsg);
-			return -1;
-		}
-	}
-	return 0;
-}
-
 /* bmesh operator 'bmesh.ops.*' callable types
  * ******************************************* */
 PyTypeObject bmesh_op_Type;
 
-typedef struct {
-	PyObject_HEAD /* required python macro   */
-	const char *opname;
-} BPy_BMeshOpFunc;
-
 static PyObject *bpy_bmesh_op_CreatePyObject(const char *opname)
 {
 	BPy_BMeshOpFunc *self = PyObject_New(BPy_BMeshOpFunc, &bmesh_op_Type);
@@ -88,636 +68,7 @@
 }
 
 
-static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
-{
-	PyObject *ret;
-	BPy_BMesh *py_bm;
-	BMesh *bm;
 
-	BMOperator bmop;
-
-	if ((PyTuple_GET_SIZE(args) == 1) &&
-	    (py_bm = (BPy_BMesh *)PyTuple_GET_ITEM(args, 0)) &&
-	    (BPy_BMesh_Check(py_bm))
-		)
-	{
-		BPY_BM_CHECK_OBJ(py_bm);
-		bm = py_bm->bm;
-	}
-	else {
-		PyErr_SetString(PyExc_TypeError,
-		                "calling a bmesh operator expects a single BMesh (non keyword) "
-		                "as the first argument");
-		return NULL;
-	}
-
-	/* TODO - error check this!, though we do the error check on attribute access */
-	/* TODO - make flags optional */
-	BMO_op_init(bm, &bmop, BMO_FLAG_DEFAULTS, self->opname);
-
-	if (kw && PyDict_Size(kw) > 0) {
-		/* setup properties, see bpy_rna.c: pyrna_py_to_prop()
-		 * which shares this logic for parsing properties */
-
-		PyObject *key, *value;
-		Py_ssize_t pos = 0;
-		while (PyDict_Next(kw, &pos, &key, &value)) {
-			const char *slot_name = _PyUnicode_AsString(key);
-			BMOpSlot *slot = BMO_slot_get(bmop.slots_in, slot_name);
-
-			if (slot == NULL) {
-				PyErr_Format(PyExc_TypeError,
-				             "%.200s: keyword \"%.200s\" is invalid for this operator",
-				             self->opname, slot_name);
-				return NULL;
-			}
-
-			/* now assign the value */
-			switch (slot->slot_type) {
-				case BMO_OP_SLOT_BOOL:
-				{
-					int param;
-
-					param = PyLong_AsLong(value);
-
-					if (param < 0) {
-						PyErr_Format(PyExc_TypeError,
-						             "%.200s: keyword \"%.200s\" expected True/False or 0/1, not %.200s",
-						             self->opname, slot_name, Py_TYPE(value)->tp_name);
-						return NULL;
-					}
-					else {
-						BMO_SLOT_AS_BOOL(slot) = param;
-					}
-
-					break;
-				}
-				case BMO_OP_SLOT_INT:
-				{
-					int overflow;
-					long param = PyLong_AsLongAndOverflow(value, &overflow);
-					if (overflow || (param > INT_MAX) || (param < INT_MIN)) {
-						PyErr_Format(PyExc_ValueError,
-						             "%.200s: keyword \"%.200s\" value not in 'int' range "
-						             "(" STRINGIFY(INT_MIN) ", " STRINGIFY(INT_MAX) ")",
-						             self->opname, slot_name, Py_TYPE(value)->tp_name);
-						return NULL;
-					}
-					else if (param == -1 && PyErr_Occurred()) {
-						PyErr_Format(PyExc_TypeError,
-						             "%.200s: keyword \"%.200s\" expected an int, not %.200s",
-						             self->opname, slot_name, Py_TYPE(value)->tp_name);
-						return NULL;
-					}
-					else {
-						BMO_SLOT_AS_INT(slot) = (int)param;
-					}
-					break;
-				}
-				case BMO_OP_SLOT_FLT:
-				{
-					float param = PyFloat_AsDouble(value);
-					if (param == -1 && PyErr_Occurred()) {
-						PyErr_Format(PyExc_TypeError,
-						             "%.200s: keyword \"%.200s\" expected a float, not %.200s",
-						             self->opname, slot_name, Py_TYPE(value)->tp_name);
-						return NULL;
-					}
-					else {
-						BMO_SLOT_AS_FLOAT(slot) = param;
-					}
-					break;
-				}
-				case BMO_OP_SLOT_MAT:
-				{
-					/* XXX - BMesh operator design is crappy here, operator slot should define matrix size,
-					 * not the caller! */
-					unsigned short size;
-					if (!MatrixObject_Check(value)) {
-						PyErr_Format(PyExc_TypeError,
-						             "%.200s: keyword \"%.200s\" expected a Matrix, not %.200s",
-						             self->opname, slot_name, Py_TYPE(value)->tp_name);
-						return NULL;
-					}
-					else if (BaseMath_ReadCallback((MatrixObject *)value) == -1) {
-						return NULL;
-					}
-					else if (((size = ((MatrixObject *)value)->num_col) != ((MatrixObject *)value)->num_row) ||
-					         (ELEM(size, 3, 4) == FALSE))
-					{
-						PyErr_Format(PyExc_TypeError,
-						             "%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix Matrix",
-						             self->opname, slot_name);
-						return NULL;
-					}
-
-					BMO_slot_mat_set(&bmop, bmop.slots_in, slot_name, ((MatrixObject *)value)->matrix, size);
-					break;
-				}
-				case BMO_OP_SLOT_VEC:
-				{
-					/* passing slot name here is a bit non-descriptive */
-					if (mathutils_array_parse(BMO_SLOT_AS_VECTOR(slot), 3, 3, value, slot_name) == -1) {
-						return NULL;
-					}
-					break;
-				}
-				case BMO_OP_SLOT_ELEMENT_BUF:
-				{
-					if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) {
-						if (!BPy_BMElem_Check(value) ||
-						    !(((BPy_BMElem *)value)->ele->head.htype & slot->slot_subtype.elem))
-						{
-							PyErr_Format(PyExc_TypeError,
-							             "%.200s: keyword \"%.200s\" expected a %.200s not *.200s",
-							             self->opname, slot_name,
-							             BPy_BMElem_StringFromHType(slot->slot_subtype.elem & BM_ALL_NOLOOP),
-							             Py_TYPE(value)->tp_name);
-							return NULL;
-						}
-						else if (((BPy_BMElem *)value)->bm == NULL) {
-							PyErr_Format(PyExc_TypeError,
-							             "%.200s: keyword \"%.200s\" invalidated element",
-							             self->opname, slot_name);
-							return NULL;
-						}
-
-						BMO_slot_buffer_from_single(&bmop, slot, &((BPy_BMElem *)value)->ele->head);
-					}
-					else {
-						/* there are many ways we could interpret arguments, for now...
-						 * - verts/edges/faces from the mesh direct,
-						 *   this way the operator takes every item.
-						 * - `TODO` a plain python sequence (list) of elements.
-						 * - `TODO`  an iterator. eg.
-						 *   face.verts
-						 * - `TODO`  (type, flag) pair, eg.
-						 *   ('VERT', {'TAG'})
-						 */
-
-#define BPY_BM_GENERIC_MESH_TEST(type_string)  \
-	if (((BPy_BMGeneric *)value)->bm != bm) {                                             \
-	    PyErr_Format(PyExc_NotImplementedError,                                           \
-	                 "%.200s: keyword \"%.200s\" " type_string " are from another bmesh", \
-	                 self->opname, slot_name, slot->slot_type);                           \
-	    return NULL;                                                                      \
-	} (void)0
-
-#define BPY_BM_ELEM_TYPE_TEST(type_string)  \
-	if ((slot->slot_subtype.elem & BM_VERT) == 0) { \
-	    PyErr_Format(PyExc_TypeError, \
-	                 "%.200s: keyword \"%.200s\" expected " \
-	                 "a list of %.200s not " type_string, \
-	                 self->opname, slot_name, \
-	                 BPy_BMElem_StringFromHType(slot->slot_subtype.elem & BM_ALL_NOLOOP)); \
-	    return NULL; \
-	} (void)0
-
-						if (BPy_BMVertSeq_Check(value)) {
-							BPY_BM_GENERIC_MESH_TEST("verts");
-							BPY_BM_ELEM_TYPE_TEST("verts");
-
-							BMO_slot_buffer_from_all(bm, &bmop, bmop.slots_in, slot_name, BM_VERT);
-						}
-						else if (BPy_BMEdgeSeq_Check(value)) {
-							BPY_BM_GENERIC_MESH_TEST("edges");
-							BPY_BM_ELEM_TYPE_TEST("edges");
-							BMO_slot_buffer_from_all(bm, &bmop, bmop.slots_in, slot_name, BM_EDGE);
-						}
-						else if (BPy_BMFaceSeq_Check(value)) {
-							BPY_BM_GENERIC_MESH_TEST("faces");
-							BPY_BM_ELEM_TYPE_TEST("faces");
-							BMO_slot_buffer_from_all(bm, &bmop, bmop.slots_in, slot_name, BM_FACE);
-						}
-
-#undef BPY_BM_ELEM_TYPE_TEST
-
-						else if (BPy_BMElemSeq_Check(value)) {
-							BMIter iter;
-							BMHeader *ele;
-							int tot;
-							unsigned int i;
-
-							BPY_BM_GENERIC_MESH_TEST("elements");
-
-							/* this will loop over all elements which is a shame but
-							 * we need to know this before alloc */
-							/* calls bpy_bmelemseq_length() */
-							tot = Py_TYPE(value)->tp_as_sequence->sq_length((PyObject *)self);
-
-							BMO_slot_buffer_alloc(&bmop, bmop.slots_in, slot_name, tot);
-
-							i = 0;
-							BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) {
-								slot->data.buf[i] = ele;
-								i++;
-							}
-						}
-						/* keep this last */
-						else if (PySequence_Check(value)) {
-							BMElem **elem_array = NULL;
-							Py_ssize_t elem_array_len;
-
-							elem_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
-							                                       &elem_array_len, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
-							                                       TRUE, TRUE, slot_name);
-
-							/* error is set above */
-							if (elem_array == NULL) {
-								return NULL;
-							}
-
-							BMO_slot_buffer_alloc(&bmop, bmop.slots_in, slot_name, elem_array_len);
-							memcpy(slot->data.buf, elem_array, sizeof(void *) * elem_array_len);
-							PyMem_FREE(elem_array);
-						}
-						else {
-							PyErr_Format(PyExc_TypeError,
-							             "%.200s: keyword \"%.200s\" expected "
-							             "a bmesh sequence, list, (htype, flag) pair, not %.200s",
-							             self->opname, slot_name, Py_TYPE(value)->tp_name);
-							return NULL;
-						}
-					}
-#undef BPY_BM_GENERIC_MESH_TEST
-
-					break;
-				}
-				case BMO_OP_SLOT_MAPPING:
-				{
-					/* first check types */
-					if (slot->slot_subtype.map != BMO_OP_SLOT_SUBTYPE_MAP_EMPTY) {
-						if (!PyDict_Check(value)) {
-							PyErr_Format(PyExc_TypeError,
-							             "%.200s: keyword \"%.200s\" expected "
-							             "a dict, not %.200s",

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list