add bmesh/python operator support for vector and matrix args.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 2 Jul 2012 20:28:43 +0000 (20:28 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 2 Jul 2012 20:28:43 +0000 (20:28 +0000)
also rename BMO_OP_SLOT_PNT to BMO_OP_SLOT_PTR (matches RNA and sounds less like 'point')

source/blender/bmesh/intern/bmesh_opdefines.c
source/blender/bmesh/intern/bmesh_operator_api.h
source/blender/bmesh/intern/bmesh_operators.c
source/blender/python/bmesh/bmesh_py_ops.c

index 1d3385eaab636de6f0d55583d5aa42a9768d8b7c..931937263e418dd18fd8ce215b60a98ca0df088a 100644 (file)
@@ -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,
index 620800cca169e4ebe77f636c09094dda80f0852c..74087c00940af720e7b36bcf65c99f9652ab2c16 100644 (file)
@@ -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,
 
index efd028331852db69bb3ea26a20b0bcf12cad63e4..5447e6b5a556d590c5bb1081641b3a44de6b4cce 100644 (file)
@@ -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;
index c0ab4abb677648758650a5f37c6a8642296edcf7..53ddcecd7a89c755efb04742d026043b097860db 100644 (file)
@@ -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