add support for passing lists of verts/edges/faces to bmesh operators
authorCampbell Barton <ideasman42@gmail.com>
Sat, 30 Jun 2012 12:58:04 +0000 (12:58 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 30 Jun 2012 12:58:04 +0000 (12:58 +0000)
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 f606347baf6e4c2de6cf8b6aeb6488638b279da1..e281e75909809a36302949c5dceb7542bb8b5b45 100644 (file)
@@ -1034,7 +1034,7 @@ static BMOpDefine bmo_bevel_def = {
        {{BMO_OP_SLOT_ELEMENT_BUF, "geom"}, /* input edges and vertices */
         {BMO_OP_SLOT_ELEMENT_BUF, "face_spans"}, /* new geometry */
         {BMO_OP_SLOT_ELEMENT_BUF, "face_holes"}, /* new geometry */
-        {BMO_OP_SLOT_BOOL, "use_lengths"}, /* grab edge lengths from a PROP_FLT customdata laye */
+        {BMO_OP_SLOT_BOOL, "use_lengths"}, /* grab edge lengths from a PROP_FLT customdata layer */
         {BMO_OP_SLOT_BOOL, "use_even"}, /* corner vert placement: use shell/angle calculations  */
         {BMO_OP_SLOT_BOOL, "use_dist"}, /* corner vert placement: evaluate percent as a distance,
                                          * modifier uses this. We could do this as another float setting */
index c6dd33b7a4b90b9cca9c4ec406991c3bbff59015..aa005d1769b3108093a2f10b4a31cc46b8ea6413 100644 (file)
@@ -352,6 +352,8 @@ int BMO_vert_edge_flags_count(BMesh *bm, BMVert *v, const short oflag);
 void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slot_name,
                           const char hflag, const short oflag);
 
+void *BMO_slot_buffer_alloc(BMOperator *op, const char *slot_name, const int len);
+
 void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, const char *slot_name,
                               const char htype);
 
index 48d3cc3721ab00244ca18a618486891e91fbfd94..7cd73c6f065b470dfa6ac76d40ab4f683ed23d87 100644 (file)
@@ -625,7 +625,7 @@ void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slot_name,
        }
 }
 
-static void *bmo_slot_buffer_alloc(BMOperator *op, const char *slot_name, int len)
+void *BMO_slot_buffer_alloc(BMOperator *op, const char *slot_name, const int len)
 {
        BMOpSlot *slot = BMO_slot_get(op, slot_name);
        BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF);
@@ -658,7 +658,7 @@ void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, const char *slot_name,
                BMIter iter;
                BMHeader *ele;
 
-               bmo_slot_buffer_alloc(op, slot_name, totelement);
+               BMO_slot_buffer_alloc(op, slot_name, totelement);
 
                /* TODO - collapse these loops into one */
 
@@ -709,7 +709,7 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl
                BMIter iter;
                BMElem *ele;
 
-               bmo_slot_buffer_alloc(op, slot_name, totelement);
+               BMO_slot_buffer_alloc(op, slot_name, totelement);
 
                /* TODO - collapse these loops into one */
 
@@ -821,7 +821,7 @@ static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slo
                BMHeader *ele;
                BMHeader **ele_array;
 
-               bmo_slot_buffer_alloc(op, slot_name, totelement);
+               BMO_slot_buffer_alloc(op, slot_name, totelement);
 
                ele_array = (BMHeader **)slot->data.p;
 
index d64c1206d99ee8ede05df11fb27e421ccf5addbc..b71f5d9e08518f4e3a2c5348cdbeaca07669e3a7 100644 (file)
@@ -200,27 +200,58 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *
                                         "%.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)) {
-                                               BPY_BM_GENERIC_MESH_TEST("verts")
+                                               BPY_BM_GENERIC_MESH_TEST("verts");
                                                BMO_slot_buffer_from_all(bm, &bmop, slot_name, BM_VERT);
                                        }
                                        else if (BPy_BMEdgeSeq_Check(value)) {
-                                               BPY_BM_GENERIC_MESH_TEST("edges")
+                                               BPY_BM_GENERIC_MESH_TEST("edges");
                                                BMO_slot_buffer_from_all(bm, &bmop, slot_name, BM_EDGE);
                                        }
                                        else if (BPy_BMFaceSeq_Check(value)) {
-                                               BPY_BM_GENERIC_MESH_TEST("faces")
+                                               BPY_BM_GENERIC_MESH_TEST("faces");
                                                BMO_slot_buffer_from_all(bm, &bmop, slot_name, BM_FACE);
                                        }
                                        else if (BPy_BMElemSeq_Check(value)) {
-                                               BPY_BM_GENERIC_MESH_TEST("elements")
+                                               BMIter iter;
+                                               BMHeader *ele;
+                                               int tot;
+                                               unsigned int i;
 
-                                               PyErr_Format(PyExc_NotImplementedError,
-                                                            "%.200s: keyword \"%.200s\" parsing element lists not working yet!",
-                                                            self->opname, slot_name, slot->slot_type);
-                                               return NULL;
+                                               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, slot_name, tot);
+
+                                               i = 0;
+                                               BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) {
+                                                       ((void **)slot->data.buf)[i] = (void *)ele;
+                                                       i++;
+                                               }
+                                       }
+                                       /* keep this last */
+                                       else if (PySequence_Check(value)) {
+                                               BMElem **elem_array = NULL;
+                                               int elem_array_len;
+
+                                               elem_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
+                                                                                      &elem_array_len, BM_VERT | BM_EDGE | BM_FACE,
+                                                                                      TRUE, TRUE, slot_name);
+
+                                               /* error is set above */
+                                               if (elem_array == NULL) {
+                                                       return NULL;
+                                               }
+
+                                               BMO_slot_buffer_alloc(&bmop, 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,