diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-03-01 20:04:37 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-03-01 20:04:37 +0400 |
commit | 4a5078d6c9bf59840c0fe46876a9eb71aa3ad33a (patch) | |
tree | f11bd72c483993e38dcd2c927ff68eb279323dc2 /source | |
parent | 216f74880e86b7da22e708569b1de082da357dfb (diff) |
style cleanup
* add extra argument to BMO_slot_map_to_flag() to filter by vert/edge/face
* made BMO_slot_map_* / BMO_slot_buffer_* functions stricter with type checking.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/bmesh/bmesh_operator_api.h | 4 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operator_api_inline.c | 18 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_operators.c | 29 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_structure.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_extrude.c | 34 | ||||
-rw-r--r-- | source/blender/bmesh/operators/bmo_subdivide.c | 4 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_select.c | 2 | ||||
-rw-r--r-- | source/blender/editors/mesh/bmesh_tools.c | 2 |
8 files changed, 58 insertions, 37 deletions
diff --git a/source/blender/bmesh/bmesh_operator_api.h b/source/blender/bmesh/bmesh_operator_api.h index b5535b5bf58..e1e06fa9657 100644 --- a/source/blender/bmesh/bmesh_operator_api.h +++ b/source/blender/bmesh/bmesh_operator_api.h @@ -327,8 +327,8 @@ int BMO_vert_edge_flags_count(BMesh *bm, BMVert *v, const short oflag); /* flags all elements in a mapping. note that the mapping must only have * bmesh elements in it.*/ -void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, - const char *slotname, const short oflag); +void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slotname, + const short oflag, const char hflag); /* this part of the API is used to iterate over element buffer or * mapping slots. diff --git a/source/blender/bmesh/intern/bmesh_operator_api_inline.c b/source/blender/bmesh/intern/bmesh_operator_api_inline.c index 29d85790010..a7c8f1612eb 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api_inline.c +++ b/source/blender/bmesh/intern/bmesh_operator_api_inline.c @@ -88,7 +88,7 @@ BM_INLINE void BMO_slot_map_float_insert(BMesh *bm, BMOperator *op, const char * 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*)); + 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) @@ -96,7 +96,12 @@ BM_INLINE int BMO_slot_map_contains(BMesh *UNUSED(bm), BMOperator *op, const cha BMOpSlot *slot = BMO_slot_get(op, slotname); /*sanity check*/ - if (slot->slottype != BMO_OP_SLOT_MAPPING) return 0; + if (slot->slottype != BMO_OP_SLOT_MAPPING) { +#ifdef DEBUG + printf("%s: invalid type %d\n", __func__, slot->slottype); +#endif + return 0; + } if (!slot->data.ghash) return 0; return BLI_ghash_haskey(slot->data.ghash, element); @@ -109,7 +114,12 @@ BM_INLINE void *BMO_slot_map_data_get(BMesh *UNUSED(bm), BMOperator *op, const c BMOpSlot *slot = BMO_slot_get(op, slotname); /*sanity check*/ - if (slot->slottype != BMO_OP_SLOT_MAPPING) return NULL; + if (slot->slottype != BMO_OP_SLOT_MAPPING) { +#ifdef DEBUG + printf("%s: invalid type %d\n", __func__, slot->slottype); +#endif + return NULL; + } if (!slot->data.ghash) return NULL; mapping = (BMOElemMapping *)BLI_ghash_lookup(slot->data.ghash, element); @@ -140,7 +150,7 @@ BM_INLINE int BMO_slot_map_int_get(BMesh *bm, BMOperator *op, const char *slotna 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); + void **val = (void **) BMO_slot_map_data_get(bm, op, slotname, element); if (val) return *val; return NULL; diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c index 9d6d7fce15a..ddb63a42400 100644 --- a/source/blender/bmesh/intern/bmesh_operators.c +++ b/source/blender/bmesh/intern/bmesh_operators.c @@ -153,8 +153,8 @@ void BMO_op_init(BMesh *bm, BMOperator *op, const char *opname) op->exec = opdefines[opcode]->exec; /* memarena, used for operator's slot buffers */ - op->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "bmesh operator"); - BLI_memarena_use_calloc (op->arena); + op->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__); + BLI_memarena_use_calloc(op->arena); } /** @@ -267,7 +267,9 @@ void BMO_slot_copy(BMOperator *source_op, BMOperator *dest_op, const char *src, BMOElemMapping *srcmap, *dstmap; /* sanity check */ - if (!source_slot->data.ghash) return; + if (!source_slot->data.ghash) { + return; + } if (!dest_slot->data.ghash) { dest_slot->data.ghash = BLI_ghash_new(BLI_ghashutil_ptrhash, @@ -534,11 +536,7 @@ void BMO_slot_map_insert(BMesh *UNUSED(bm), BMOperator *op, const char *slotname { BMOElemMapping *mapping; BMOpSlot *slot = BMO_slot_get(op, slotname); - - /*sanity check*/ - if (slot->slottype != BMO_OP_SLOT_MAPPING) { - return; - } + BLI_assert(slot->slottype == BMO_OP_SLOT_MAPPING); mapping = (BMOElemMapping *) BLI_memarena_alloc(op->arena, sizeof(*mapping) + len); @@ -595,8 +593,8 @@ void *BMO_Grow_Array(BMesh *bm, BMOperator *op, int slotcode, int totadd) } #endif -void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, - const char *slotname, const short oflag) +void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slotname, + const short oflag, const char htype) { GHashIterator it; BMOpSlot *slot = BMO_slot_get(op, slotname); @@ -605,12 +603,13 @@ void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, BLI_assert(slot->slottype == BMO_OP_SLOT_MAPPING); /* sanity check */ - if (slot->slottype != BMO_OP_SLOT_MAPPING) return; if (!slot->data.ghash) return; BLI_ghashIterator_init(&it, slot->data.ghash); for ( ; (ele_f = BLI_ghashIterator_getKey(&it)); BLI_ghashIterator_step(&it)) { - BMO_elem_flag_enable(bm, ele_f, oflag); + if (ele_f->head.htype & htype) { + BMO_elem_flag_enable(bm, ele_f, oflag); + } } } @@ -865,7 +864,7 @@ void BMO_slot_buffer_flag_enable(BMesh *bm, BMOperator *op, const char *slotname BMHeader **data = slot->data.p; int i; - BLI_assert(slot->slottype > BMO_OP_SLOT_VEC); + BLI_assert(slot->slottype == BMO_OP_SLOT_ELEMENT_BUF); for (i = 0; i < slot->len; i++) { if (!(htype & data[i]->htype)) @@ -886,7 +885,9 @@ void BMO_slot_buffer_flag_disable(BMesh *bm, BMOperator *op, const char *slotnam BMOpSlot *slot = BMO_slot_get(op, slotname); BMHeader **data = slot->data.p; int i; - + + BLI_assert(slot->slottype == BMO_OP_SLOT_ELEMENT_BUF); + for (i = 0; i < slot->len; i++) { if (!(htype & data[i]->htype)) continue; diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index 97b10fab49f..03f116a03ba 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -234,7 +234,7 @@ BMEdge *bmesh_disk_edge_exists(BMVert *v1, BMVert *v2) BMEdge *e_iter, *e_first; if (v1->e) { - e_first = e_iter= v1->e; + e_first = e_iter = v1->e; do { if (bmesh_verts_in_edge(v1, v2, e_iter)) { diff --git a/source/blender/bmesh/operators/bmo_extrude.c b/source/blender/bmesh/operators/bmo_extrude.c index fee8b7ee254..4cc965dc372 100644 --- a/source/blender/bmesh/operators/bmo_extrude.c +++ b/source/blender/bmesh/operators/bmo_extrude.c @@ -29,9 +29,11 @@ #include "bmesh_operators_private.h" /* own include */ -#define EXT_INPUT 1 -#define EXT_KEEP 2 -#define EXT_DEL 4 +enum { + EXT_INPUT = 1, + EXT_KEEP = 2, + EXT_DEL = 4 +}; #define VERT_MARK 1 #define EDGE_MARK 1 @@ -192,7 +194,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) BMLoop *l, *l2; BMVert *verts[4], *v, *v2; BMFace *f; - int rlen, found, fwd, delorig = 0; + int found, fwd, delorig = FALSE; /* initialize our sub-operators */ BMO_op_init(bm, &dupeop, "dupe"); @@ -204,21 +206,27 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) if (!BMO_slot_bool_get(op, "alwayskeeporig")) { BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) { + int edge_face_tot; + if (!BMO_elem_flag_test(bm, e, EXT_INPUT)) { continue; } - found = FALSE; - f = BM_iter_new(&fiter, bm, BM_FACES_OF_EDGE, e); - for (rlen = 0; f; f = BM_iter_step(&fiter), rlen++) { + found = FALSE; /* found a face that isn't input? */ + edge_face_tot = 0; /* edge/face count */ + + BM_ITER(f, &fiter, bm, BM_FACES_OF_EDGE, e) { if (!BMO_elem_flag_test(bm, f, EXT_INPUT)) { found = TRUE; - delorig = 1; + delorig = TRUE; break; } + + edge_face_tot++; } - if ((found == FALSE) && (rlen > 1)) { + if ((edge_face_tot > 1) && (found == FALSE)) { + /* edge has a face user, that face isnt extrude input */ BMO_elem_flag_enable(bm, e, EXT_DEL); } } @@ -256,7 +264,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) } } - if (delorig) { + if (delorig == TRUE) { BMO_op_initf(bm, &delop, "del geom=%fvef context=%i", EXT_DEL, DEL_ONLYTAGGED); } @@ -267,11 +275,13 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op) if (bm->act_face && BMO_elem_flag_test(bm, bm->act_face, EXT_INPUT)) bm->act_face = BMO_slot_map_ptr_get(bm, &dupeop, "facemap", bm->act_face); - if (delorig) BMO_op_exec(bm, &delop); + if (delorig) { + BMO_op_exec(bm, &delop); + } /* if not delorig, reverse loops of original face */ if (!delorig) { - for (f = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); f; f = BM_iter_step(&iter)) { + BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) { if (BMO_elem_flag_test(bm, f, EXT_INPUT)) { BM_face_normal_flip(bm, f); } diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 4643de74e52..53cd7148005 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -755,10 +755,10 @@ void bmo_esubd_exec(BMesh *bmesh, BMOperator *op) params.off[2] = (float)BLI_drand() * 200.0f; BMO_slot_map_to_flag(bmesh, op, "custompatterns", - FACE_CUSTOMFILL); + FACE_CUSTOMFILL, BM_FACE); BMO_slot_map_to_flag(bmesh, op, "edgepercents", - EDGE_PERCENT); + EDGE_PERCENT, BM_EDGE); for (face = BM_iter_new(&fiter, bmesh, BM_FACES_OF_MESH, NULL); face; diff --git a/source/blender/editors/mesh/bmesh_select.c b/source/blender/editors/mesh/bmesh_select.c index fd881919519..749ff66997b 100644 --- a/source/blender/editors/mesh/bmesh_select.c +++ b/source/blender/editors/mesh/bmesh_select.c @@ -1087,7 +1087,7 @@ void MESH_OT_loop_select(wmOperatorType *ot) RNA_def_boolean(ot->srna, "ring", 0, "Select Ring", "Select ring"); } -void MESH_OT_edgering_select (wmOperatorType *ot) +void MESH_OT_edgering_select(wmOperatorType *ot) { /* description */ ot->name = "Edge Ring Select"; diff --git a/source/blender/editors/mesh/bmesh_tools.c b/source/blender/editors/mesh/bmesh_tools.c index b6abfe79b70..55b42ae7c29 100644 --- a/source/blender/editors/mesh/bmesh_tools.c +++ b/source/blender/editors/mesh/bmesh_tools.c @@ -3346,7 +3346,7 @@ static int mesh_separate_exec(bContext *C, wmOperator *op) if (type == 0) retval = mesh_separate_selected(bmain, scene, base, op); else if (type == 1) - retval = mesh_separate_material (bmain, scene, base, op); + retval = mesh_separate_material(bmain, scene, base, op); else if (type == 2) retval = mesh_separate_loose(bmain, scene, base, op); |