diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-07-03 00:28:43 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-07-03 00:28:43 +0400 |
commit | 2ed69a95f499081aacc15c0295f3461c38430554 (patch) | |
tree | a17a6ba86b8e05ae97de5a9a5a02312ae0153553 | |
parent | 2d8a9a0cc393aabb5a3b2bc83ed063098875f799 (diff) |
add bmesh/python operator support for vector and matrix args.
also rename BMO_OP_SLOT_PNT to BMO_OP_SLOT_PTR (matches RNA and sounds less like 'point')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_opdefines.c | 16 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operator_api.h | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 8 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_ops.c | 47 |
4 files changed, 55 insertions, 18 deletions
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 1d3385eaab6..931937263e4 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -528,8 +528,8 @@ static BMOpDefine bmo_transform_def = { */ static BMOpDefine bmo_object_load_bmesh_def = { "object_load_bmesh", - {{BMO_OP_SLOT_PNT, "scene"}, - {BMO_OP_SLOT_PNT, "object"}, + {{BMO_OP_SLOT_PTR, "scene"}, + {BMO_OP_SLOT_PTR, "object"}, {0, /* null-terminating sentinel */}}, bmo_object_load_bmesh_exec, 0, @@ -543,8 +543,8 @@ static BMOpDefine bmo_object_load_bmesh_def = { */ static BMOpDefine bmo_bmesh_to_mesh_def = { "bmesh_to_mesh", - {{BMO_OP_SLOT_PNT, "mesh"}, //pointer to a mesh structure to fill in - {BMO_OP_SLOT_PNT, "object"}, //pointer to an object structure + {{BMO_OP_SLOT_PTR, "mesh"}, //pointer to a mesh structure to fill in + {BMO_OP_SLOT_PTR, "object"}, //pointer to an object structure {BMO_OP_SLOT_BOOL, "notessellation"}, //don't calculate mfaces {0, /* null-terminating sentinel */}}, bmo_bmesh_to_mesh_exec, @@ -559,8 +559,8 @@ static BMOpDefine bmo_bmesh_to_mesh_def = { */ static BMOpDefine bmo_mesh_to_bmesh_def = { "mesh_to_bmesh", - {{BMO_OP_SLOT_PNT, "mesh"}, //pointer to a Mesh structure - {BMO_OP_SLOT_PNT, "object"}, //pointer to an Object structure + {{BMO_OP_SLOT_PTR, "mesh"}, //pointer to a Mesh structure + {BMO_OP_SLOT_PTR, "object"}, //pointer to an Object structure {BMO_OP_SLOT_BOOL, "set_shapekey"}, //load active shapekey coordinates into verts {0, /* null-terminating sentinel */}}, bmo_mesh_to_bmesh_exec, @@ -737,7 +737,7 @@ static BMOpDefine bmo_duplicate_def = { {BMO_OP_SLOT_MAPPING, "facemap"}, {BMO_OP_SLOT_MAPPING, "boundarymap"}, {BMO_OP_SLOT_MAPPING, "isovertmap"}, - {BMO_OP_SLOT_PNT, "dest"}, /* destination bmesh, if NULL will use current on */ + {BMO_OP_SLOT_PTR, "dest"}, /* destination bmesh, if NULL will use current on */ {0} /* null-terminating sentinel */}, bmo_duplicate_exec, 0 @@ -749,7 +749,7 @@ static BMOpDefine bmo_split_def = { {BMO_OP_SLOT_ELEMENT_BUF, "geomout"}, {BMO_OP_SLOT_MAPPING, "boundarymap"}, {BMO_OP_SLOT_MAPPING, "isovertmap"}, - {BMO_OP_SLOT_PNT, "dest"}, /* destination bmesh, if NULL will use current on */ + {BMO_OP_SLOT_PTR, "dest"}, /* destination bmesh, if NULL will use current on */ {BMO_OP_SLOT_BOOL, "use_only_faces"}, /* when enabled. don't duplicate loose verts/edges */ {0} /* null-terminating sentinel */}, bmo_split_exec, diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index 620800cca16..74087c00940 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -99,7 +99,7 @@ enum { /* normally store pointers to object, scene, * _never_ store arrays corresponding to mesh elements with this */ - BMO_OP_SLOT_PNT = 4, + BMO_OP_SLOT_PTR = 4, BMO_OP_SLOT_MAT = 5, BMO_OP_SLOT_VEC = 8, diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index efd02833185..5447e6b5a55 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -378,8 +378,8 @@ void BMO_slot_mat3_set(BMOperator *op, const char *slot_name, float r_mat[3][3]) void BMO_slot_ptr_set(BMOperator *op, const char *slot_name, void *p) { BMOpSlot *slot = BMO_slot_get(op, slot_name); - BLI_assert(slot->slot_type == BMO_OP_SLOT_PNT); - if (!(slot->slot_type == BMO_OP_SLOT_PNT)) + BLI_assert(slot->slot_type == BMO_OP_SLOT_PTR); + if (!(slot->slot_type == BMO_OP_SLOT_PTR)) return; slot->data.p = p; @@ -430,8 +430,8 @@ int BMO_slot_bool_get(BMOperator *op, const char *slot_name) void *BMO_slot_ptr_get(BMOperator *op, const char *slot_name) { BMOpSlot *slot = BMO_slot_get(op, slot_name); - BLI_assert(slot->slot_type == BMO_OP_SLOT_PNT); - if (!(slot->slot_type == BMO_OP_SLOT_PNT)) + BLI_assert(slot->slot_type == BMO_OP_SLOT_PTR); + if (!(slot->slot_type == BMO_OP_SLOT_PTR)) return NULL; return slot->data.p; diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c index c0ab4abb677..53ddcecd7a8 100644 --- a/source/blender/python/bmesh/bmesh_py_ops.c +++ b/source/blender/python/bmesh/bmesh_py_ops.c @@ -163,6 +163,7 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" expected an int, not %.200s", self->opname, slot_name, Py_TYPE(value)->tp_name); + return NULL; } else { slot->data.i = (int)param; @@ -176,12 +177,47 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" expected a float, not %.200s", self->opname, slot_name, Py_TYPE(value)->tp_name); + return NULL; } else { slot->data.f = 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, 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(slot->data.vec, 3, 3, value, slot_name) == -1) { + return NULL; + } + break; + } case BMO_OP_SLOT_ELEMENT_BUF: { /* there are many ways we could interpret arguments, for now... @@ -194,12 +230,12 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * * ('VERT', {'TAG'}) */ -#define BPY_BM_GENERIC_MESH_TEST(type_string) \ +#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; \ + PyErr_Format(PyExc_NotImplementedError, \ + "%.200s: keyword \"%.200s\" " type_string " are from another bmesh", \ + self->opname, slot_name, slot->slot_type); \ + return NULL; \ } (void)0 if (BPy_BMVertSeq_Check(value)) { @@ -258,6 +294,7 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * "%.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 |