diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-02-25 23:43:51 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-02-25 23:43:51 +0400 |
commit | 55e68985e7cf868481d3ffcb845f94e3c52a5043 (patch) | |
tree | ee679ecb5c00a258972f6ca0f8ecc1c777695f1f /source | |
parent | 0096370db89eaf315a8c75b29076b9b85c83409a (diff) |
bmesh api:
* added BM_elem_flag_set, BMO_elem_flag_set. to avoid 'if(...) enable(); else disable();' all over the place.
* added bmesh_operator_api_inline.c, the header file was getting messy.
Diffstat (limited to 'source')
21 files changed, 272 insertions, 280 deletions
diff --git a/source/blender/bmesh/CMakeLists.txt b/source/blender/bmesh/CMakeLists.txt index 48f653f4759..f7dacef88d3 100644 --- a/source/blender/bmesh/CMakeLists.txt +++ b/source/blender/bmesh/CMakeLists.txt @@ -90,6 +90,7 @@ set(SRC intern/bmesh_mods.c intern/bmesh_newcore.c intern/bmesh_opdefines.c + intern/bmesh_operator_api_inline.c intern/bmesh_operators.c intern/bmesh_operators_private.h intern/bmesh_polygon.c diff --git a/source/blender/bmesh/bmesh.h b/source/blender/bmesh/bmesh.h index 6190e3215c6..a3f7c07e69d 100644 --- a/source/blender/bmesh/bmesh.h +++ b/source/blender/bmesh/bmesh.h @@ -372,6 +372,7 @@ void bmesh_end_edit(BMesh *bm, int flag); #include "bmesh_iterators.h" #include "bmesh_walkers.h" #include "intern/bmesh_inline.c" +#include "intern/bmesh_operator_api_inline.c" #ifdef __cplusplus } diff --git a/source/blender/bmesh/bmesh_operator_api.h b/source/blender/bmesh/bmesh_operator_api.h index b9c9bd52966..80f2856b066 100644 --- a/source/blender/bmesh/bmesh_operator_api.h +++ b/source/blender/bmesh/bmesh_operator_api.h @@ -73,6 +73,7 @@ extern "C" { * semantically similar to the iterator api in bmesh_iterators.h). */ +struct BMesh; struct GHashIterator; /* slot type arrays are terminated by the last member @@ -182,15 +183,10 @@ void BMO_op_finish(struct BMesh *bm, struct BMOperator *op); #define BMO_elem_flag_test(bm, element, oflag) ((element)->oflags[bm->stackdepth-1].f & (oflag)) #define BMO_elem_flag_enable(bm, element, oflag) ((element)->oflags[bm->stackdepth-1].f |= (oflag)) #define BMO_elem_flag_disable(bm, element, oflag) ((element)->oflags[bm->stackdepth-1].f &= ~(oflag)) +#define BMO_elem_flag_set(bm, element, oflag, val)((val) ? BMO_elem_flag_enable(bm, element, oflag) : \ + BMO_elem_flag_disable(bm, element, oflag)) #define BMO_elem_flag_toggle(bm, element, oflag) ((element)->oflags[bm->stackdepth-1].f ^= (oflag)) -/* profiling showed a significant amount of time spent in BMO_elem_flag_test */ -#if 0 -void BMO_elem_flag_enable(struct BMesh *bm, void *element, const short oflag); -void BMO_elem_flag_disable(struct BMesh *bm, void *element, const short oflag); -int BMO_elem_flag_test(struct BMesh *bm, void *element, const short oflag); -#endif - /* count the number of elements with a specific flag. * type can be a bitmask of BM_FACE, BM_EDGE, or BM_FACE. */ int BMO_mesh_flag_count(struct BMesh *bm, const short oflag, const char htype); @@ -339,44 +335,11 @@ int BMO_slot_map_count(struct BMesh *bm, struct BMOperator *op, const char *slot */ int BMO_vert_edge_flags_count(BMesh *bm, BMVert *v, const short oflag); -/* inserts a key/value mapping into a mapping slot. note that it copies the - * value, it doesn't store a reference to it. */ - -#if 0 - -BM_INLINE void BMO_slot_map_insert(BMesh *bm, BMOperator *op, const char *slotname, - void *element, void *data, int len); - -/* inserts a key/float mapping pair into a mapping slot. */ -BM_INLINE void BMO_slot_map_float_insert(BMesh *bm, BMOperator *op, const char *slotname, - void *element, float val); - -/* returns 1 if the specified pointer is in the map. */ -BM_INLINE int BMO_slot_map_contains(BMesh *bm, BMOperator *op, const char *slotname, void *element); - -/* returns a point to the value of a specific key. */ -BM_INLINE void *BMO_slot_map_data_get(BMesh *bm, BMOperator *op, const char *slotname, void *element); - -/* returns the float part of a key/float pair. */ -BM_INLINE float BMO_slot_map_float_get(BMesh *bm, BMOperator *op, const char *slotname, void *element); - -#endif - /* flags all elements in a mapping. note that the mapping must only have * bmesh elements in it.*/ void BMO_slot_map_to_flag(struct BMesh *bm, struct BMOperator *op, const char *slotname, const short oflag); -/* pointer versoins of BMO_slot_map_float_get and BMO_slot_map_float_insert. - * - * do NOT use these for non-operator-api-allocated memory! instead - * use BMO_slot_map_data_get and BMO_slot_map_insert, which copies the data. */ - -#if 0 -BM_INLINE void BMO_slot_map_ptr_insert(BMesh *bm, BMOperator *op, const char *slotname, void *key, void *val); -BM_INLINE void *BMO_slot_map_ptr_get(BMesh *bm, BMOperator *op, const char *slotname, void *key); -#endif - /* this part of the API is used to iterate over element buffer or * mapping slots. * @@ -453,104 +416,6 @@ typedef struct BMOElemMapping { extern const int BMO_OPSLOT_TYPEINFO[BMO_OP_SLOT_TOTAL_TYPES]; -BM_INLINE void BMO_slot_map_insert(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, - void *element, void *data, int len) -{ - BMOElemMapping *mapping; - BMOpSlot *slot = BMO_slot_get(op, slotname); - - /*sanity check*/ - if (slot->slottype != BMO_OP_SLOT_MAPPING) { - return; - } - - mapping = (BMOElemMapping *) BLI_memarena_alloc(op->arena, sizeof(*mapping) + len); - - mapping->element = (BMHeader*) element; - mapping->len = len; - memcpy(mapping + 1, data, len); - - if (!slot->data.ghash) { - slot->data.ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, - BLI_ghashutil_ptrcmp, "bmesh op"); - } - - BLI_ghash_insert(slot->data.ghash, element, mapping); -} - -BM_INLINE void BMO_slot_map_int_insert(BMesh *bm, BMOperator *op, const char *slotname, - void *element, int val) -{ - BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(int)); -} - -BM_INLINE void BMO_slot_map_float_insert(BMesh *bm, BMOperator *op, const char *slotname, - void *element, float val) -{ - BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(float)); -} - -BM_INLINE void BMO_slot_map_ptr_insert(BMesh *bm, BMOperator *op, const char *slotname, - void *element, void *val) -{ - BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(void*)); -} - -BM_INLINE int BMO_slot_map_contains(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, void *element) -{ - BMOpSlot *slot = BMO_slot_get(op, slotname); - - /*sanity check*/ - if (slot->slottype != BMO_OP_SLOT_MAPPING) return 0; - if (!slot->data.ghash) return 0; - - return BLI_ghash_haskey(slot->data.ghash, element); -} - -BM_INLINE void *BMO_slot_map_data_get(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, - void *element) -{ - BMOElemMapping *mapping; - BMOpSlot *slot = BMO_slot_get(op, slotname); - - /*sanity check*/ - if (slot->slottype != BMO_OP_SLOT_MAPPING) return NULL; - if (!slot->data.ghash) return NULL; - - mapping = (BMOElemMapping *)BLI_ghash_lookup(slot->data.ghash, element); - - if (!mapping) return NULL; - - return mapping + 1; -} - -BM_INLINE float BMO_slot_map_float_get(BMesh *bm, BMOperator *op, const char *slotname, - void *element) -{ - float *val = (float*) BMO_slot_map_data_get(bm, op, slotname, element); - if (val) return *val; - - return 0.0f; -} - -BM_INLINE int BMO_slot_map_int_get(BMesh *bm, BMOperator *op, const char *slotname, - void *element) -{ - int *val = (int*) BMO_slot_map_data_get(bm, op, slotname, element); - if (val) return *val; - - return 0; -} - -BM_INLINE void *BMO_slot_map_ptr_get(BMesh *bm, BMOperator *op, const char *slotname, - void *element) -{ - void **val = (void**) BMO_slot_map_data_get(bm, op, slotname, element); - if (val) return *val; - - return NULL; -} - #ifdef __cplusplus } #endif diff --git a/source/blender/bmesh/intern/bmesh_inline.c b/source/blender/bmesh/intern/bmesh_inline.c index 4433aaa0fc6..b855c4b865a 100644 --- a/source/blender/bmesh/intern/bmesh_inline.c +++ b/source/blender/bmesh/intern/bmesh_inline.c @@ -46,6 +46,12 @@ BM_INLINE void BM_elem_flag_disable(void *element, const char hflag) ((BMHeader *)element)->hflag &= ~hflag; } +BM_INLINE void BM_elem_flag_set(void *element, const char hflag, const int val) +{ + if (val) BM_elem_flag_enable(element, hflag); + else BM_elem_flag_disable(element, hflag); +} + BM_INLINE void BM_elem_flag_toggle(void *element, const char hflag) { ((BMHeader *)element)->hflag ^= hflag; diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index 8a8ccb5efb1..21ecc245707 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -115,12 +115,7 @@ void BM_mesh_select_mode_flush(BMesh *bm) ok = FALSE; } - if (ok) { - BM_elem_flag_enable(f, BM_ELEM_SELECT); - } - else { - BM_elem_flag_disable(f, BM_ELEM_SELECT); - } + BM_elem_flag_set(f, BM_ELEM_SELECT, ok); } } else if (bm->selectmode & SCE_SELECT_EDGE) { @@ -139,12 +134,7 @@ void BM_mesh_select_mode_flush(BMesh *bm) ok = FALSE; } - if (ok) { - BM_elem_flag_enable(f, BM_ELEM_SELECT); - } - else { - BM_elem_flag_disable(f, BM_ELEM_SELECT); - } + BM_elem_flag_set(f, BM_ELEM_SELECT, ok); } } @@ -802,9 +792,6 @@ void BM_mesh_elem_flag_enable_all(BMesh *bm, const char htype, const char hflag) /***************** Mesh Hiding stuff *********** */ -#define BM_ELEM_HIDE_SET(ele, hide) \ - (hide) ? BM_elem_flag_enable(ele, BM_ELEM_HIDDEN) : BM_elem_flag_disable(ele, BM_ELEM_HIDDEN); - static void vert_flush_hide_set(BMesh *bm, BMVert *v) { BMIter iter; @@ -815,7 +802,7 @@ static void vert_flush_hide_set(BMesh *bm, BMVert *v) hide = hide && BM_elem_flag_test(e, BM_ELEM_HIDDEN); } - BM_ELEM_HIDE_SET(v, hide); + BM_elem_flag_set(v, BM_ELEM_HIDDEN, hide); } static void edge_flush_hide(BMesh *bm, BMEdge *e) @@ -828,7 +815,7 @@ static void edge_flush_hide(BMesh *bm, BMEdge *e) hide = hide && BM_elem_flag_test(f, BM_ELEM_HIDDEN); } - BM_ELEM_HIDE_SET(e, hide); + BM_elem_flag_set(e, BM_ELEM_HIDDEN, hide); } void BM_vert_hide_set(BMesh *bm, BMVert *v, int hide) @@ -838,13 +825,13 @@ void BM_vert_hide_set(BMesh *bm, BMVert *v, int hide) BMEdge *e; BMFace *f; - BM_ELEM_HIDE_SET(v, hide); + BM_elem_flag_set(v, BM_ELEM_HIDDEN, hide); BM_ITER(e, &iter, bm, BM_EDGES_OF_VERT, v) { - BM_ELEM_HIDE_SET(e, hide); + BM_elem_flag_set(e, BM_ELEM_HIDDEN, hide); BM_ITER(f, &fiter, bm, BM_FACES_OF_EDGE, e) { - BM_ELEM_HIDE_SET(f, hide); + BM_elem_flag_set(f, BM_ELEM_HIDDEN, hide); } } } @@ -857,10 +844,10 @@ void BM_edge_hide_set(BMesh *bm, BMEdge *e, int hide) /* edge hiding: faces around the edge */ BM_ITER(f, &iter, bm, BM_FACES_OF_EDGE, e) { - BM_ELEM_HIDE_SET(f, hide); + BM_elem_flag_set(f, BM_ELEM_HIDDEN, hide); } - BM_ELEM_HIDE_SET(e, hide); + BM_elem_flag_set(e, BM_ELEM_HIDDEN, hide); /* hide vertices if necassary */ vert_flush_hide_set(bm, e->v1); @@ -872,7 +859,7 @@ void BM_face_hide_set(BMesh *bm, BMFace *f, int hide) BMIter iter; BMLoop *l; - BM_ELEM_HIDE_SET(f, hide); + BM_elem_flag_set(f, BM_ELEM_HIDDEN, hide); BM_ITER(l, &iter, bm, BM_LOOPS_OF_FACE, f) { edge_flush_hide(bm, l->e); @@ -883,9 +870,6 @@ void BM_face_hide_set(BMesh *bm, BMFace *f, int hide) } } -#undef BM_ELEM_HIDE_SET - - void BM_elem_hide_set(BMesh *bm, void *element, int hide) { BMHeader *h = element; diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index 9621e593f3a..b5132312d3c 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -355,9 +355,7 @@ static void bmesh_rationalize_normals(BMesh *bm, int undo) bmesh_righthandfaces_exec(bm, &bmop); BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) { - if (BMO_elem_flag_test(bm, f, FACE_FLIP)) - BM_elem_flag_enable(f, BM_ELEM_TAG); - else BM_elem_flag_disable(f, BM_ELEM_TAG); + BM_elem_flag_set(f, BM_ELEM_TAG, BMO_elem_flag_test(bm, f, FACE_FLIP)); } BMO_pop(bm); diff --git a/source/blender/bmesh/intern/bmesh_operator_api_inline.c b/source/blender/bmesh/intern/bmesh_operator_api_inline.c new file mode 100644 index 00000000000..8e32f2710e2 --- /dev/null +++ b/source/blender/bmesh/intern/bmesh_operator_api_inline.c @@ -0,0 +1,141 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Joseph Eagar, Geoffrey Bantle, Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/bmesh/intern/bmesh_operator_api_inline.c + * \ingroup bmesh + * + * BMesh inline operator functions. + */ + +#ifndef __BMESH_OPERATOR_API_INLINE_C__ +#define __BMESH_OPERATOR_API_INLINE_C__ + +#include "bmesh.h" + +/* inserts a key/value mapping into a mapping slot. note that it copies the + * value, it doesn't store a reference to it. */ + +BM_INLINE void BMO_slot_map_insert(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, + void *element, void *data, int len) +{ + BMOElemMapping *mapping; + BMOpSlot *slot = BMO_slot_get(op, slotname); + + /*sanity check*/ + if (slot->slottype != BMO_OP_SLOT_MAPPING) { + return; + } + + mapping = (BMOElemMapping *) BLI_memarena_alloc(op->arena, sizeof(*mapping) + len); + + mapping->element = (BMHeader*) element; + mapping->len = len; + memcpy(mapping + 1, data, len); + + if (!slot->data.ghash) { + slot->data.ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, + BLI_ghashutil_ptrcmp, "bmesh op"); + } + + BLI_ghash_insert(slot->data.ghash, element, mapping); +} + +BM_INLINE void BMO_slot_map_int_insert(BMesh *bm, BMOperator *op, const char *slotname, + void *element, int val) +{ + BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(int)); +} + +BM_INLINE void BMO_slot_map_float_insert(BMesh *bm, BMOperator *op, const char *slotname, + void *element, float val) +{ + BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(float)); +} + + +/* pointer versoins of BMO_slot_map_float_get and BMO_slot_map_float_insert. + * + * do NOT use these for non-operator-api-allocated memory! instead + * use BMO_slot_map_data_get and BMO_slot_map_insert, which copies the data. */ + +BM_INLINE void BMO_slot_map_ptr_insert(BMesh *bm, BMOperator *op, const char *slotname, + void *element, void *val) +{ + BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(void*)); +} + +BM_INLINE int BMO_slot_map_contains(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, void *element) +{ + BMOpSlot *slot = BMO_slot_get(op, slotname); + + /*sanity check*/ + if (slot->slottype != BMO_OP_SLOT_MAPPING) return 0; + if (!slot->data.ghash) return 0; + + return BLI_ghash_haskey(slot->data.ghash, element); +} + +BM_INLINE void *BMO_slot_map_data_get(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, + void *element) +{ + BMOElemMapping *mapping; + BMOpSlot *slot = BMO_slot_get(op, slotname); + + /*sanity check*/ + if (slot->slottype != BMO_OP_SLOT_MAPPING) return NULL; + if (!slot->data.ghash) return NULL; + + mapping = (BMOElemMapping *)BLI_ghash_lookup(slot->data.ghash, element); + + if (!mapping) return NULL; + + return mapping + 1; +} + +BM_INLINE float BMO_slot_map_float_get(BMesh *bm, BMOperator *op, const char *slotname, + void *element) +{ + float *val = (float*) BMO_slot_map_data_get(bm, op, slotname, element); + if (val) return *val; + + return 0.0f; +} + +BM_INLINE int BMO_slot_map_int_get(BMesh *bm, BMOperator *op, const char *slotname, + void *element) +{ + int *val = (int*) BMO_slot_map_data_get(bm, op, slotname, element); + if (val) return *val; + + return 0; +} + +BM_INLINE void *BMO_slot_map_ptr_get(BMesh *bm, BMOperator *op, const char *slotname, + void *element) +{ + void **val = (void**) BMO_slot_map_data_get(bm, op, slotname, element); + if (val) return *val; + + return NULL; +} + +#endif /* __BMESH_OPERATOR_API_INLINE_C__ */ diff --git a/source/blender/bmesh/intern/bmesh_queries.c b/source/blender/bmesh/intern/bmesh_queries.c index 2eb9e6e918f..a8c4cd71845 100644 --- a/source/blender/bmesh/intern/bmesh_queries.c +++ b/source/blender/bmesh/intern/bmesh_queries.c @@ -140,7 +140,9 @@ int BM_verts_in_face(BMesh *bm, BMFace *f, BMVert **varr, int len) int i, count = 0; - for (i = 0; i < len; i++) BMO_elem_flag_enable(bm, varr[i], BM_OVERLAP); + for (i = 0; i < len; i++) { + BMO_elem_flag_enable(bm, varr[i], BM_OVERLAP); + } #ifdef USE_BMESH_HOLES for (lst = f->loops.first; lst; lst = lst->next) diff --git a/source/blender/bmesh/operators/bmo_create.c b/source/blender/bmesh/operators/bmo_create.c index 6ba0c91fb4d..610790393f1 100644 --- a/source/blender/bmesh/operators/bmo_create.c +++ b/source/blender/bmesh/operators/bmo_create.c @@ -1407,6 +1407,8 @@ void bmesh_contextual_create_exec(BMesh *bm, BMOperator *op) printf("cannot find nice quad from concave set of vertices\n"); } - if (f) BMO_elem_flag_enable(bm, f, ELE_OUT); + if (f) { + BMO_elem_flag_enable(bm, f, ELE_OUT); + } } } diff --git a/source/blender/bmesh/operators/bmo_dissolve.c b/source/blender/bmesh/operators/bmo_dissolve.c index 2ee70bb4644..ddef478a4aa 100644 --- a/source/blender/bmesh/operators/bmo_dissolve.c +++ b/source/blender/bmesh/operators/bmo_dissolve.c @@ -88,12 +88,7 @@ void dissolvefaces_exec(BMesh *bm, BMOperator *op) BMVert *v; BM_ITER(v, &viter, bm, BM_VERTS_OF_MESH, NULL) { - if (BM_vert_edge_count(v) == 2) { - BMO_elem_flag_disable(bm, v, VERT_MARK); - } - else { - BMO_elem_flag_enable(bm, v, VERT_MARK); - } + BMO_elem_flag_set(bm, v, VERT_MARK, (BM_vert_edge_count(v) != 2)); } } @@ -251,12 +246,7 @@ void dissolveedges_exec(BMesh *bm, BMOperator *op) if (use_verts) { BM_ITER(v, &viter, bm, BM_VERTS_OF_MESH, NULL) { - if (BM_vert_edge_count(v) == 2) { - BMO_elem_flag_disable(bm, v, VERT_MARK); - } - else { - BMO_elem_flag_enable(bm, v, VERT_MARK); - } + BMO_elem_flag_set(bm, v, VERT_MARK, (BM_vert_edge_count(v) != 2)); } } diff --git a/source/blender/bmesh/operators/bmo_dupe.c b/source/blender/bmesh/operators/bmo_dupe.c index d7626673e43..09b0e2042f4 100644 --- a/source/blender/bmesh/operators/bmo_dupe.c +++ b/source/blender/bmesh/operators/bmo_dupe.c @@ -407,7 +407,9 @@ void splitop_exec(BMesh *bm, BMOperator *op) break; } } - if (!found) BMO_elem_flag_enable(bm, e, SPLIT_INPUT); + if (!found) { + BMO_elem_flag_enable(bm, e, SPLIT_INPUT); + } } for (v = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); v; v = BM_iter_step(&iter)) { @@ -419,8 +421,9 @@ void splitop_exec(BMesh *bm, BMOperator *op) break; } } - if (!found) BMO_elem_flag_enable(bm, v, SPLIT_INPUT); - + if (!found) { + BMO_elem_flag_enable(bm, v, SPLIT_INPUT); + } } } diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index 2c6a0e0de6a..b194428deba 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -215,7 +215,9 @@ void extrude_edge_context_exec(BMesh *bm, BMOperator *op) } } - if (!found && (rlen > 1)) BMO_elem_flag_enable(bm, e, EXT_DEL); + if (!found && (rlen > 1)) { + BMO_elem_flag_enable(bm, e, EXT_DEL); + } } } @@ -243,8 +245,9 @@ void extrude_edge_context_exec(BMesh *bm, BMOperator *op) } BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) { - if (BMO_elem_flag_test(bm, f, EXT_INPUT)) + if (BMO_elem_flag_test(bm, f, EXT_INPUT)) { BMO_elem_flag_enable(bm, f, EXT_DEL); + } } if (delorig) { diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index e674a3f2856..9cf17490d58 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -248,7 +248,7 @@ void bmesh_create_grid_exec(BMesh *bm, BMOperator *op) eve = BM_vert_create(bm, vec, NULL); BMO_elem_flag_enable(bm, eve, VERT_MARK); - if (a) { + if (a != 0) { e = BM_edge_create(bm, preveve, eve, NULL, TRUE); BMO_elem_flag_enable(bm, e, EDGE_ORIG); } diff --git a/source/blender/bmesh/operators/bmo_removedoubles.c b/source/blender/bmesh/operators/bmo_removedoubles.c index 2eb1cf7db3e..bd528faa43e 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.c +++ b/source/blender/bmesh/operators/bmo_removedoubles.c @@ -124,10 +124,12 @@ void bmesh_weldverts_exec(BMesh *bm, BMOperator *op) if (!v) v = e->v1; if (!v2) v2 = e->v2; - if (v == v2) + if (v == v2) { BMO_elem_flag_enable(bm, e, EDGE_COL); - else if (!BM_edge_exists(v, v2)) + } + else if (!BM_edge_exists(v, v2)) { BM_edge_create(bm, v, v2, e, TRUE); + } BMO_elem_flag_enable(bm, e, ELE_DEL); } diff --git a/source/blender/bmesh/operators/bmo_triangulate.c b/source/blender/bmesh/operators/bmo_triangulate.c index a14af618411..b4ec3d740d4 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.c +++ b/source/blender/bmesh/operators/bmo_triangulate.c @@ -89,8 +89,9 @@ void bmesh_beautify_fill_exec(BMesh *bm, BMOperator *op) BMO_slot_buffer_flag_enable(bm, op, "constrain_edges", EDGE_MARK, BM_EDGE); BMO_ITER(f, &siter, bm, op, "faces", BM_FACE) { - if (f->len == 3) + if (f->len == 3) { BMO_elem_flag_enable(bm, f, FACE_MARK); + } } while (!stop) { diff --git a/source/blender/bmesh/operators/bmo_utils.c b/source/blender/bmesh/operators/bmo_utils.c index d80535efb76..1acdf05ef35 100644 --- a/source/blender/bmesh/operators/bmo_utils.c +++ b/source/blender/bmesh/operators/bmo_utils.c @@ -170,8 +170,9 @@ static void bmesh_regionextend_extend(BMesh *bm, BMOperator *op, int usefaces) BMO_ITER(f, &siter, bm, op, "geom", BM_FACE) { BM_ITER(l, &liter, bm, BM_LOOPS_OF_FACE, f) { BM_ITER(f2, &fiter, bm, BM_FACES_OF_EDGE, l->e) { - if (!BMO_elem_flag_test(bm, f2, SEL_ORIG)) + if (!BMO_elem_flag_test(bm, f2, SEL_ORIG)) { BMO_elem_flag_enable(bm, f2, SEL_FLAG); + } } } } @@ -595,21 +596,21 @@ void bmesh_similarfaces_exec(BMesh *bm, BMOperator *op) for (i = 0; i < num_total; i++) { fm = f_ext[i].f; if (!BMO_elem_flag_test(bm, fm, FACE_MARK) && !BM_elem_flag_test(fm, BM_ELEM_HIDDEN)) { - int cont = 1; - for (idx = 0; idx < num_sels && cont == 1; idx++) { + int cont = TRUE; + for (idx = 0; idx < num_sels && cont == TRUE; idx++) { fs = f_ext[indices[idx]].f; switch (type) { case SIMFACE_MATERIAL: if (fm->mat_nr == fs->mat_nr) { BMO_elem_flag_enable(bm, fm, FACE_MARK); - cont = 0; + cont = FALSE; } break; case SIMFACE_IMAGE: if (f_ext[i].t == f_ext[indices[idx]].t) { BMO_elem_flag_enable(bm, fm, FACE_MARK); - cont = 0; + cont = FALSE; } break; @@ -617,7 +618,7 @@ void bmesh_similarfaces_exec(BMesh *bm, BMOperator *op) angle = RAD2DEGF(angle_v3v3(fs->no, fm->no)); /* if the angle between the normals -> 0 */ if (angle / 180.0f <= thresh) { BMO_elem_flag_enable(bm, fm, FACE_MARK); - cont = 0; + cont = FALSE; } break; @@ -626,7 +627,7 @@ void bmesh_similarfaces_exec(BMesh *bm, BMOperator *op) if (angle / 180.0f <= thresh) { /* and dot product difference -> 0 */ if (fabsf(f_ext[i].d - f_ext[indices[idx]].d) <= thresh) { BMO_elem_flag_enable(bm, fm, FACE_MARK); - cont = 0; + cont = FALSE; } } break; @@ -634,14 +635,14 @@ void bmesh_similarfaces_exec(BMesh *bm, BMOperator *op) case SIMFACE_AREA: if (fabsf(f_ext[i].area - f_ext[indices[idx]].area) <= thresh) { BMO_elem_flag_enable(bm, fm, FACE_MARK); - cont = 0; + cont = FALSE; } break; case SIMFACE_PERIMETER: if (fabsf(f_ext[i].perim - f_ext[indices[idx]].perim) <= thresh) { BMO_elem_flag_enable(bm, fm, FACE_MARK); - cont = 0; + cont = FALSE; } break; } @@ -769,14 +770,14 @@ void bmesh_similaredges_exec(BMesh *bm, BMOperator *op) for (i = 0; i < num_total; i++) { e = e_ext[i].e; if (!BMO_elem_flag_test(bm, e, EDGE_MARK) && !BM_elem_flag_test(e, BM_ELEM_HIDDEN)) { - int cont = 1; - for (idx = 0; idx < num_sels && cont == 1; idx++) { + int cont = TRUE; + for (idx = 0; idx < num_sels && cont == TRUE; idx++) { es = e_ext[indices[idx]].e; switch (type) { case SIMEDGE_LENGTH: if (fabsf(e_ext[i].length - e_ext[indices[idx]].length) <= thresh) { BMO_elem_flag_enable(bm, e, EDGE_MARK); - cont = 0; + cont = FALSE; } break; @@ -789,14 +790,14 @@ void bmesh_similaredges_exec(BMesh *bm, BMOperator *op) if (angle / 90.0f <= thresh) { BMO_elem_flag_enable(bm, e, EDGE_MARK); - cont = 0; + cont = FALSE; } break; case SIMEDGE_FACE: if (e_ext[i].faces == e_ext[indices[idx]].faces) { BMO_elem_flag_enable(bm, e, EDGE_MARK); - cont = 0; + cont = FALSE; } break; @@ -805,12 +806,12 @@ void bmesh_similaredges_exec(BMesh *bm, BMOperator *op) if (e_ext[indices[idx]].faces == 2) { if (fabsf(e_ext[i].angle - e_ext[indices[idx]].angle) <= thresh) { BMO_elem_flag_enable(bm, e, EDGE_MARK); - cont = 0; + cont = FALSE; } } } else { - cont = 0; + cont = FALSE; } break; @@ -823,7 +824,7 @@ void bmesh_similaredges_exec(BMesh *bm, BMOperator *op) if (c1 && c2 && fabsf(*c1 - *c2) <= thresh) { BMO_elem_flag_enable(bm, e, EDGE_MARK); - cont = 0; + cont = FALSE; } } break; @@ -831,14 +832,14 @@ void bmesh_similaredges_exec(BMesh *bm, BMOperator *op) case SIMEDGE_SEAM: if (BM_elem_flag_test(e, BM_ELEM_SEAM) == BM_elem_flag_test(es, BM_ELEM_SEAM)) { BMO_elem_flag_enable(bm, e, EDGE_MARK); - cont = 0; + cont = FALSE; } break; case SIMEDGE_SHARP: if (BM_elem_flag_test(e, BM_ELEM_SMOOTH) == BM_elem_flag_test(es, BM_ELEM_SMOOTH)) { BMO_elem_flag_enable(bm, e, EDGE_MARK); - cont = 0; + cont = FALSE; } break; } @@ -925,22 +926,22 @@ void bmesh_similarverts_exec(BMesh *bm, BMOperator *op) for (i = 0; i < num_total; i++) { v = v_ext[i].v; if (!BMO_elem_flag_test(bm, v, VERT_MARK) && !BM_elem_flag_test(v, BM_ELEM_HIDDEN)) { - int cont = 1; - for (idx = 0; idx < num_sels && cont == 1; idx++) { + int cont = TRUE; + for (idx = 0; idx < num_sels && cont == TRUE; idx++) { vs = v_ext[indices[idx]].v; switch (type) { case SIMVERT_NORMAL: /* compare the angle between the normals */ if (RAD2DEGF(angle_v3v3(v->no, vs->no)) / 180.0f <= thresh) { BMO_elem_flag_enable(bm, v, VERT_MARK); - cont = 0; + cont = FALSE; } break; case SIMVERT_FACE: /* number of adjacent faces */ if (v_ext[i].num_faces == v_ext[indices[idx]].num_faces) { BMO_elem_flag_enable(bm, v, VERT_MARK); - cont = 0; + cont = FALSE; } break; @@ -951,7 +952,7 @@ void bmesh_similarverts_exec(BMesh *bm, BMOperator *op) for (v2 = 0; v2 < v_ext[indices[idx]].dvert->totweight; v2++) { if (v_ext[i].dvert->dw[v1].def_nr == v_ext[indices[idx]].dvert->dw[v2].def_nr) { BMO_elem_flag_enable(bm, v, VERT_MARK); - cont = 0; + cont = FALSE; break; } } diff --git a/source/blender/bmesh/tools/BME_bevel.c b/source/blender/bmesh/tools/BME_bevel.c index 23e4ad7e289..134b7f9eb0c 100644 --- a/source/blender/bmesh/tools/BME_bevel.c +++ b/source/blender/bmesh/tools/BME_bevel.c @@ -731,7 +731,10 @@ static void BME_bevel_add_vweight(BME_TransData_Head *td, BMesh *bm, BMVert *v, { BME_TransData *vtd; - if (BMO_elem_flag_test(bm, v, BME_BEVEL_NONMAN)) return; + if (BMO_elem_flag_test(bm, v, BME_BEVEL_NONMAN)) { + return; + } + BMO_elem_flag_enable(bm, v, BME_BEVEL_BEVEL); if ((vtd = BME_get_transdata(td, v))) { if (options & BME_BEVEL_EMIN) { @@ -767,18 +770,23 @@ static void bevel_init_verts(BMesh *bm, int options, BME_TransData_Head *td) BMIter iter; float weight; BM_ITER(v, &iter, bm, BM_VERTS_OF_MESH, NULL) { - weight = 0.0; + weight = 0.0f; if (!BMO_elem_flag_test(bm, v, BME_BEVEL_NONMAN)) { /* modifiers should not use selection */ if (options & BME_BEVEL_SELECT) { - if(BM_elem_flag_test(v, BM_ELEM_SELECT)) weight = 1.0; + if (BM_elem_flag_test(v, BM_ELEM_SELECT)) { + weight = 1.0f; + } } /* bevel weight NYI */ - else if(options & BME_BEVEL_WEIGHT) + else if (options & BME_BEVEL_WEIGHT) { weight = BM_elem_float_data_get(&bm->vdata, v, CD_BWEIGHT); - else - weight = 1.0; - if(weight > 0.0) { + } + else { + weight = 1.0f; + } + + if (weight > 0.0f) { BMO_elem_flag_enable(bm, v, BME_BEVEL_BEVEL); BME_assign_transdata(td, bm, v, v->co, v->co, NULL, NULL, 1.0, weight, -1, NULL); } @@ -804,6 +812,7 @@ static void bevel_init_edges(BMesh *bm, int options, BME_TransData_Head *td) else { weight = 1.0; } + if(weight > 0.0) { BMO_elem_flag_enable(bm, e, BME_BEVEL_BEVEL); BMO_elem_flag_enable(bm, e->v1, BME_BEVEL_BEVEL); @@ -836,15 +845,18 @@ static BMesh *BME_bevel_initialize(BMesh *bm, int options, int UNUSED(defgrp_ind BMO_elem_flag_enable(bm, v, BME_BEVEL_ORIG); if(v->e) { BME_assign_transdata(td, bm, v, v->co, v->co, NULL, NULL, 0, -1, -1, NULL); - if (!BM_vert_is_manifold(bm, v)) + if (!BM_vert_is_manifold(bm, v)) { BMO_elem_flag_enable(bm, v, BME_BEVEL_NONMAN); + } + /* test wire ver */ len = BM_vert_edge_count(v); if (len == 2 && BM_vert_is_wire(bm, v)) BMO_elem_flag_disable(bm, v, BME_BEVEL_NONMAN); } - else + else { BMO_elem_flag_enable(bm, v, BME_BEVEL_NONMAN); + } } BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { @@ -854,13 +866,22 @@ static BMesh *BME_bevel_initialize(BMesh *bm, int options, int UNUSED(defgrp_ind BMO_elem_flag_enable(bm, e->v2, BME_BEVEL_NONMAN); BMO_elem_flag_enable(bm, e, BME_BEVEL_NONMAN); } - if(BMO_elem_flag_test(bm, e->v1, BME_BEVEL_NONMAN) || BMO_elem_flag_test(bm, e->v2, BME_BEVEL_NONMAN)) BMO_elem_flag_enable(bm, e, BME_BEVEL_NONMAN); + if(BMO_elem_flag_test(bm, e->v1, BME_BEVEL_NONMAN) || BMO_elem_flag_test(bm, e->v2, BME_BEVEL_NONMAN)) { + BMO_elem_flag_enable(bm, e, BME_BEVEL_NONMAN); + } } - BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) + BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) { BMO_elem_flag_enable(bm, f, BME_BEVEL_ORIG); - if(options & BME_BEVEL_VERT) bevel_init_verts(bm, options, td); - else bevel_init_edges(bm, options, td); + } + + if(options & BME_BEVEL_VERT) { + bevel_init_verts(bm, options, td); + } + else { + bevel_init_edges(bm, options, td); + } + return bm; } diff --git a/source/blender/editors/mesh/bmesh_select.c b/source/blender/editors/mesh/bmesh_select.c index 65d44928e37..ec64caa8253 100644 --- a/source/blender/editors/mesh/bmesh_select.c +++ b/source/blender/editors/mesh/bmesh_select.c @@ -1162,27 +1162,25 @@ static void edgetag_context_set(BMEditMesh *em, Scene *scene, BMEdge *e, int val BM_elem_select_set(em->bm, e, val); break; case EDGE_MODE_TAG_SEAM: - if (val) {BM_elem_flag_enable(e, BM_ELEM_SEAM);} - else {BM_elem_flag_disable(e, BM_ELEM_SEAM);} + BM_elem_flag_set(e, BM_ELEM_SEAM, val); break; case EDGE_MODE_TAG_SHARP: - if (val) {BM_elem_flag_disable(e, BM_ELEM_SMOOTH);} - else {BM_elem_flag_enable(e, BM_ELEM_SMOOTH);} + BM_elem_flag_set(e, BM_ELEM_SMOOTH, !val); break; case EDGE_MODE_TAG_CREASE: { float *crease = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_CREASE); - if (val) {*crease = 1.0f;} - else {*crease = 0.0f;} + if (val) *crease = 1.0f; + else *crease = 0.0f; break; } case EDGE_MODE_TAG_BEVEL: { float *bweight = CustomData_bmesh_get(&em->bm->edata, e->head.data, CD_BWEIGHT); - if (val) {*bweight = 1.0f;} - else {*bweight = 0.0f;} + if (val) *bweight = 1.0f; + else *bweight = 0.0f; break; } } @@ -1786,9 +1784,10 @@ static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event return OPERATOR_CANCELLED; if (limit) { + /* hflag no-seam --> bmo-tag */ BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { - if (!BM_elem_flag_test(e, BM_ELEM_SEAM)) BMO_elem_flag_enable(bm, e, BM_ELEM_SELECT); - else BMO_elem_flag_disable(bm, e, BM_ELEM_SELECT); /* is this needed ? */ + /* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ + BMO_elem_flag_set(bm, e, BM_ELEM_SELECT, !BM_elem_flag_test(e, BM_ELEM_SEAM)); } } @@ -1868,18 +1867,14 @@ static int select_linked_exec(bContext *C, wmOperator *op) BMFace *efa; BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { - if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { - BM_elem_flag_enable(efa, BM_ELEM_TAG); - } - else { - BM_elem_flag_disable(efa, BM_ELEM_TAG); - } + BM_elem_flag_set(efa, BM_ELEM_TAG, (BM_elem_flag_test(efa, BM_ELEM_SELECT) && + !BM_elem_flag_test(efa, BM_ELEM_HIDDEN))); } if (limit) { BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { - if (!BM_elem_flag_test(e, BM_ELEM_SEAM)) BMO_elem_flag_enable(bm, e, BM_ELEM_SELECT); - else BMO_elem_flag_disable(bm, e, BM_ELEM_SELECT); /* is this needed ? */ + /* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ + BMO_elem_flag_set(bm, e, BM_ELEM_SELECT, !BM_elem_flag_test(e, BM_ELEM_SEAM)); } } @@ -2044,6 +2039,7 @@ static void walker_deselect_nth(BMEditMesh *em, int nth, int offset, BMHeader *h BMO_push(bm, NULL); BM_ITER(h, &iter, bm, itertype, NULL) { if (BM_elem_flag_test(h, BM_ELEM_SELECT)) { + /* BMESH_TODO, don't use 'BM_ELEM_SELECT' here, its a HFLAG only! */ BMO_elem_flag_enable(bm, (BMElemF *)h, BM_ELEM_SELECT); } } diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index ada11483f36..91aaa36c77d 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -1500,15 +1500,11 @@ void EDBM_reveal_mesh(BMEditMesh *em) BMHeader *ele; int i; - /* Use index field to remember what was hidden before all is revealed. */ + /* Use tag flag to remember what was hidden before all is revealed. + * BM_ELEM_HIDDEN --> BM_ELEM_TAG */ for (i = 0; i < 3; i++) { BM_ITER(ele, &iter, em->bm, iter_types[i], NULL) { - if (BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) { - BM_elem_flag_enable(ele, BM_ELEM_TAG); - } - else { - BM_elem_flag_disable(ele, BM_ELEM_TAG); - } + BM_elem_flag_set(ele, BM_ELEM_TAG, BM_elem_flag_test(ele, BM_ELEM_HIDDEN)); } } @@ -1759,10 +1755,7 @@ static void mesh_set_smooth_faces(BMEditMesh *em, short smooth) BM_ITER(efa, &iter, em->bm, BM_FACES_OF_MESH, NULL) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { - if (smooth) - BM_elem_flag_enable(efa, BM_ELEM_SMOOTH); - else - BM_elem_flag_disable(efa, BM_ELEM_SMOOTH); + BM_elem_flag_set(efa, BM_ELEM_SMOOTH, smooth); } } } @@ -2365,13 +2358,9 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) ED_view3d_ob_project_mat_get(rv3d, obedit, projectMat); + /* BM_ELEM_SELECT --> BM_ELEM_TAG */ BM_ITER(e, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { - if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { - BM_elem_flag_enable(e, BM_ELEM_TAG); - } - else { - BM_elem_flag_disable(e, BM_ELEM_TAG); - } + BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT)); } /* handle case of one vert selected. identify @@ -2507,12 +2496,7 @@ static int mesh_rip_invoke(bContext *C, wmOperator *op, wmEvent *event) BMO_slot_buffer_hflag_enable(bm, &bmop, side?"edgeout2":"edgeout1", BM_ELEM_SELECT, BM_EDGE, TRUE); BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { - if (BM_elem_flag_test(e, BM_ELEM_SELECT)) { - BM_elem_flag_enable(e, BM_ELEM_TAG); - } - else { - BM_elem_flag_disable(e, BM_ELEM_TAG); - } + BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT)); } /* constrict edge selection again */ diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index 22bf1daa6e1..67adac9bea2 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2053,12 +2053,7 @@ static void createTransEditVerts(bContext *C, TransInfo *t) // transform now requires awareness for select mode, so we tag the f1 flags in verts if(selectmode & SCE_SELECT_VERTEX) { BM_ITER(eve, &iter, bm, BM_VERTS_OF_MESH, NULL) { - if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { - BM_elem_flag_enable(eve, BM_ELEM_TAG); - } - else { - BM_elem_flag_disable(eve, BM_ELEM_TAG); - } + BM_elem_flag_set(eve, BM_ELEM_TAG, BM_elem_flag_test(eve, BM_ELEM_SELECT)); } } else if(selectmode & SCE_SELECT_EDGE) { diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 4a6ef28baac..3deb4636200 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -1437,12 +1437,8 @@ static void weld_align_uv(bContext *C, int tool) /* flush vertex tags to edges */ BM_ITER(eed, &iter, em->bm, BM_EDGES_OF_MESH, NULL) { - if (BM_elem_flag_test(eed->v1, BM_ELEM_TAG) && BM_elem_flag_test(eed->v2, BM_ELEM_TAG)) { - BM_elem_flag_enable(eed, BM_ELEM_TAG); - } - else { - BM_elem_flag_disable(eed, BM_ELEM_TAG); - } + BM_elem_flag_set(eed, BM_ELEM_TAG, (BM_elem_flag_test(eed->v1, BM_ELEM_TAG) && + BM_elem_flag_test(eed->v2, BM_ELEM_TAG))); } /* find a vertex with only one tagged edge */ |