remove BM_ITER, BM_ITER_INDEX macros, use ELEM or MESH variants only (the maceros...
[blender-staging.git] / source / blender / bmesh / intern / bmesh_operators.c
index 44eed679cbef7cd5cc21d884da569461bd44d268..dce491efe72a4aab3487953bf54af6f535578248 100644 (file)
@@ -456,7 +456,7 @@ void BMO_slot_vec_get(BMOperator *op, const char *slotname, float r_vec[3])
  */
 
 static int bmo_mesh_flag_count(BMesh *bm, const char htype, const short oflag,
-                               int test_for_enabled)
+                               const short test_for_enabled)
 {
        const char iter_types[3] = {BM_VERTS_OF_MESH,
                                    BM_EDGES_OF_MESH,
@@ -467,13 +467,14 @@ static int bmo_mesh_flag_count(BMesh *bm, const char htype, const short oflag,
        BMIter iter;
        int count = 0;
        BMElemF *ele_f;
-       const char hflag_test = (test_for_enabled ? oflag : 0);
        int i;
 
+       BLI_assert(ELEM(TRUE, FALSE, test_for_enabled));
+
        for (i = 0; i < 3; i++) {
                if (htype & flag_types[i]) {
-                       BM_ITER(ele_f, &iter, bm, iter_types[i], NULL) {
-                               if (BMO_elem_flag_test(bm, ele_f, oflag) == hflag_test)
+                       BM_ITER_MESH (ele_f, &iter, bm, iter_types[i]) {
+                               if (BMO_elem_flag_test_bool(bm, ele_f, oflag) == test_for_enabled)
                                        count++;
                        }
                }
@@ -507,7 +508,7 @@ void BMO_mesh_flag_disable_all(BMesh *bm, BMOperator *UNUSED(op), const char hty
 
        for (i = 0; i < 3; i++) {
                if (htype & flag_types[i]) {
-                       BM_ITER(ele, &iter, bm, iter_types[i], NULL) {
+                       BM_ITER_MESH (ele, &iter, bm, iter_types[i]) {
                                BMO_elem_flag_disable(bm, ele, oflag);
                        }
                }
@@ -662,21 +663,21 @@ static void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, const char *slot
                /* TODO - collapse these loops into one */
 
                if (htype & BM_VERT) {
-                       BM_ITER(ele, &iter, bm, BM_VERTS_OF_MESH, NULL) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
                                ((BMHeader **)output->data.p)[i] = ele;
                                i++;
                        }
                }
 
                if (htype & BM_EDGE) {
-                       BM_ITER(ele, &iter, bm, BM_EDGES_OF_MESH, NULL) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
                                ((BMHeader **)output->data.p)[i] = ele;
                                i++;
                        }
                }
 
                if (htype & BM_FACE) {
-                       BM_ITER(ele, &iter, bm, BM_FACES_OF_MESH, NULL) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
                                ((BMHeader **)output->data.p)[i] = ele;
                                i++;
                        }
@@ -692,30 +693,30 @@ static void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, const char *slot
  */
 static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname,
                                        const char htype, const char hflag,
-                                       int test_for_enabled)
+                                       const short test_for_enabled)
 {
        BMOpSlot *output = BMO_slot_get(op, slotname);
        int totelement = 0, i = 0;
 
+       BLI_assert(ELEM(TRUE, FALSE, test_for_enabled));
+
        if (test_for_enabled)
-               totelement = BM_mesh_enabled_flag_count(bm, htype, hflag, TRUE);
+               totelement = BM_mesh_elem_hflag_count_enabled(bm, htype, hflag, TRUE);
        else
-               totelement = BM_mesh_disabled_flag_count(bm, htype, hflag, TRUE);
+               totelement = BM_mesh_elem_hflag_count_disabled(bm, htype, hflag, TRUE);
 
        if (totelement) {
                BMIter iter;
                BMElem *ele;
 
-               const char hflag_test = (test_for_enabled ? hflag : 0);
-
                bmo_slot_buffer_alloc(op, slotname, totelement);
 
                /* TODO - collapse these loops into one */
 
                if (htype & BM_VERT) {
-                       BM_ITER(ele, &iter, bm, BM_VERTS_OF_MESH, NULL) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
                                if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) &&
-                                   BM_elem_flag_test(ele, hflag) == hflag_test)
+                                   BM_elem_flag_test_bool(ele, hflag) == test_for_enabled)
                                {
                                        ((BMElem **)output->data.p)[i] = ele;
                                        i++;
@@ -724,9 +725,9 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl
                }
 
                if (htype & BM_EDGE) {
-                       BM_ITER(ele, &iter, bm, BM_EDGES_OF_MESH, NULL) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
                                if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) &&
-                                   BM_elem_flag_test(ele, hflag) == hflag_test)
+                                   BM_elem_flag_test_bool(ele, hflag) == test_for_enabled)
                                {
                                        ((BMElem **)output->data.p)[i] = ele;
                                        i++;
@@ -735,9 +736,9 @@ static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *sl
                }
 
                if (htype & BM_FACE) {
-                       BM_ITER(ele, &iter, bm, BM_FACES_OF_MESH, NULL) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
                                if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) &&
-                                   BM_elem_flag_test(ele, hflag) == hflag_test)
+                                   BM_elem_flag_test_bool(ele, hflag) == test_for_enabled)
                                {
                                        ((BMElem **)output->data.p)[i] = ele;
                                        i++;
@@ -786,8 +787,7 @@ void BMO_slot_buffer_append(BMOperator *output_op, const char *output_slot_name,
 
                /* copy slot data */
                memcpy(buf, output_slot->data.buf, elem_size * output_slot->len);
-               memcpy(((char*)buf) + elem_size * output_slot->len,
-                          other_slot->data.buf, elem_size * other_slot->len);
+               memcpy(((char *)buf) + elem_size * output_slot->len, other_slot->data.buf, elem_size * other_slot->len);
 
                output_slot->data.buf = buf;
                output_slot->len += other_slot->len;
@@ -802,11 +802,13 @@ void BMO_slot_buffer_append(BMOperator *output_op, const char *output_slot_name,
  */
 static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
                                       const char htype, const short oflag,
-                                      int test_for_enabled)
+                                      const short test_for_enabled)
 {
        BMOpSlot *slot = BMO_slot_get(op, slotname);
        int totelement, i = 0;
 
+       BLI_assert(ELEM(TRUE, FALSE, test_for_enabled));
+
        if (test_for_enabled)
                totelement = BMO_mesh_enabled_flag_count(bm, htype, oflag);
        else
@@ -818,7 +820,6 @@ static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slo
                BMIter iter;
                BMHeader *ele;
                BMHeader **ele_array;
-               const char hflag_test = (test_for_enabled ? oflag : 0);
 
                bmo_slot_buffer_alloc(op, slotname, totelement);
 
@@ -827,8 +828,8 @@ static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slo
                /* TODO - collapse these loops into one */
 
                if (htype & BM_VERT) {
-                       BM_ITER(ele, &iter, bm, BM_VERTS_OF_MESH, NULL) {
-                               if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag) == hflag_test) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
+                               if (BMO_elem_flag_test_bool(bm, (BMElemF *)ele, oflag) == test_for_enabled) {
                                        ele_array[i] = ele;
                                        i++;
                                }
@@ -836,8 +837,8 @@ static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slo
                }
 
                if (htype & BM_EDGE) {
-                       BM_ITER(ele, &iter, bm, BM_EDGES_OF_MESH, NULL) {
-                               if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag) == hflag_test) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
+                               if (BMO_elem_flag_test_bool(bm, (BMElemF *)ele, oflag) == test_for_enabled) {
                                        ele_array[i] = ele;
                                        i++;
                                }
@@ -845,8 +846,8 @@ static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slo
                }
 
                if (htype & BM_FACE) {
-                       BM_ITER(ele, &iter, bm, BM_FACES_OF_MESH, NULL) {
-                               if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag) == hflag_test) {
+                       BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
+                               if (BMO_elem_flag_test_bool(bm, (BMElemF *)ele, oflag) == test_for_enabled) {
                                        ele_array[i] = ele;
                                        i++;
                                }
@@ -1034,19 +1035,19 @@ static void bmo_flag_layer_alloc(BMesh *bm)
        bm->toolflagpool = newpool = BLI_mempool_create(sizeof(BMFlagLayer) * bm->totflags, 512, 512, 0);
        
        /* now go through and memcpy all the flags. Loops don't get a flag layer at this time.. */
-       BM_ITER_INDEX(ele, &iter, bm, BM_VERTS_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, i) {
                oldflags = ele->oflags;
                ele->oflags = BLI_mempool_calloc(newpool);
                memcpy(ele->oflags, oldflags, old_totflags_size);
                BM_elem_index_set(ele, i); /* set_inline */
        }
-       BM_ITER_INDEX(ele, &iter, bm, BM_EDGES_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) {
                oldflags = ele->oflags;
                ele->oflags = BLI_mempool_calloc(newpool);
                memcpy(ele->oflags, oldflags, old_totflags_size);
                BM_elem_index_set(ele, i); /* set_inline */
        }
-       BM_ITER_INDEX(ele, &iter, bm, BM_FACES_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) {
                oldflags = ele->oflags;
                ele->oflags = BLI_mempool_calloc(newpool);
                memcpy(ele->oflags, oldflags, old_totflags_size);
@@ -1079,19 +1080,19 @@ static void bmo_flag_layer_free(BMesh *bm)
        bm->toolflagpool = newpool = BLI_mempool_create(new_totflags_size, 512, 512, BLI_MEMPOOL_SYSMALLOC);
        
        /* now go through and memcpy all the flag */
-       BM_ITER_INDEX(ele, &iter, bm, BM_VERTS_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, i) {
                oldflags = ele->oflags;
                ele->oflags = BLI_mempool_calloc(newpool);
                memcpy(ele->oflags, oldflags, new_totflags_size);
                BM_elem_index_set(ele, i); /* set_inline */
        }
-       BM_ITER_INDEX(ele, &iter, bm, BM_EDGES_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) {
                oldflags = ele->oflags;
                ele->oflags = BLI_mempool_calloc(newpool);
                memcpy(ele->oflags, oldflags, new_totflags_size);
                BM_elem_index_set(ele, i); /* set_inline */
        }
-       BM_ITER_INDEX(ele, &iter, bm, BM_FACES_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) {
                oldflags = ele->oflags;
                ele->oflags = BLI_mempool_calloc(newpool);
                memcpy(ele->oflags, oldflags, new_totflags_size);
@@ -1114,15 +1115,15 @@ static void bmo_flag_layer_clear(BMesh *bm)
        const int totflags_offset = bm->totflags - 1;
 
        /* now go through and memcpy all the flag */
-       BM_ITER_INDEX(ele, &iter, bm, BM_VERTS_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, i) {
                memset(ele->oflags + totflags_offset, 0, sizeof(BMFlagLayer));
                BM_elem_index_set(ele, i); /* set_inline */
        }
-       BM_ITER_INDEX(ele, &iter, bm, BM_EDGES_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, i) {
                memset(ele->oflags + totflags_offset, 0, sizeof(BMFlagLayer));
                BM_elem_index_set(ele, i); /* set_inline */
        }
-       BM_ITER_INDEX(ele, &iter, bm, BM_FACES_OF_MESH, NULL, i) {
+       BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, i) {
                memset(ele->oflags + totflags_offset, 0, sizeof(BMFlagLayer));
                BM_elem_index_set(ele, i); /* set_inline */
        }