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.
This commit is contained in:
Campbell Barton 2012-03-01 16:04:37 +00:00
parent 216f74880e
commit 4a5078d6c9
8 changed files with 58 additions and 37 deletions

@ -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.

@ -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;

@ -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;

@ -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)) {

@ -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);
}

@ -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;

@ -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";

@ -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);