use more rigid type checking for bmesh slot subtypes.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 26 Nov 2012 03:16:29 +0000 (03:16 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 26 Nov 2012 03:16:29 +0000 (03:16 +0000)
source/blender/bmesh/intern/bmesh_operator_api_inline.h
source/blender/bmesh/intern/bmesh_operators.c
source/blender/bmesh/operators/bmo_dupe.c
source/blender/bmesh/operators/bmo_extrude.c
source/blender/bmesh/operators/bmo_mirror.c
source/blender/bmesh/operators/bmo_removedoubles.c
source/blender/bmesh/operators/bmo_triangulate.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/modifiers/intern/MOD_array.c
source/blender/modifiers/intern/MOD_skin.c

index b405ecc184120ab20c067fad3530c38eb8f271dc..1f6e44e9320383c0e7d8dfd7fa7f12626d5bbde9 100644 (file)
@@ -72,12 +72,22 @@ BLI_INLINE void _bmo_elem_flag_toggle(BMesh *bm, BMFlagLayer *oflags, const shor
 BLI_INLINE void BMO_slot_map_int_insert(BMOperator *op, BMOpSlot *slot,
                                         void *element, int val)
 {
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INT);
+       BMO_slot_map_insert(op, slot, element, &val, sizeof(int));
+}
+
+BLI_INLINE void BMO_slot_map_bool_insert(BMOperator *op, BMOpSlot *slot,
+                                        void *element, int val)
+{
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_BOOL);
+       BLI_assert(val == FALSE || val == TRUE);
        BMO_slot_map_insert(op, slot, element, &val, sizeof(int));
 }
 
 BLI_INLINE void BMO_slot_map_float_insert(BMOperator *op, BMOpSlot *slot,
                                           void *element, float val)
 {
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_FLOAT);
        BMO_slot_map_insert(op, slot, element, &val, sizeof(float));
 }
 
@@ -90,9 +100,26 @@ BLI_INLINE void BMO_slot_map_float_insert(BMOperator *op, BMOpSlot *slot,
 BLI_INLINE void BMO_slot_map_ptr_insert(BMOperator *op, BMOpSlot *slot,
                                         const void *element, void *val)
 {
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL);
        BMO_slot_map_insert(op, slot, element, &val, sizeof(void *));
 }
 
+BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot,
+                                        const void *element, void *val)
+{
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_ELEM);
+       BMO_slot_map_insert(op, slot, element, &val, sizeof(void *));
+}
+
+
+/* no values */
+BLI_INLINE void BMO_slot_map_empty_insert(BMOperator *op, BMOpSlot *slot,
+                                        const void *element)
+{
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_EMPTY);
+       BMO_slot_map_insert(op, slot, element, NULL, 0);
+}
+
 BLI_INLINE int BMO_slot_map_contains(BMOpSlot *slot, const void *element)
 {
        BLI_assert(slot->slot_type == BMO_OP_SLOT_MAPPING);
@@ -126,7 +153,10 @@ BLI_INLINE void *BMO_slot_map_data_get(BMOpSlot *slot, const void *element)
 
 BLI_INLINE float BMO_slot_map_float_get(BMOpSlot *slot, const void *element)
 {
-       float *val = (float *) BMO_slot_map_data_get(slot, element);
+       float *val;
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_FLOAT);
+
+       val = (float *) BMO_slot_map_data_get(slot, element);
        if (val) return *val;
 
        return 0.0f;
@@ -134,15 +164,40 @@ BLI_INLINE float BMO_slot_map_float_get(BMOpSlot *slot, const void *element)
 
 BLI_INLINE int BMO_slot_map_int_get(BMOpSlot *slot, const void *element)
 {
-       int *val = (int *) BMO_slot_map_data_get(slot, element);
+       int *val;
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INT);
+
+       val = (int *) BMO_slot_map_data_get(slot, element);
+       if (val) return *val;
+
+       return 0;
+}
+
+BLI_INLINE int BMO_slot_map_bool_get(BMOpSlot *slot, const void *element)
+{
+       int *val;
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_BOOL);
+
+       val = (int *) BMO_slot_map_data_get(slot, element);
+       BLI_assert(val == NULL || *val == FALSE || *val == TRUE);
        if (val) return *val;
 
        return 0;
 }
 
-BLI_INLINE void *BMO_slot_map_ptr_get(BMOpSlot *slot, const void *element)
+BLI_INLINE void *BMO_slot_map_ptr_get_(BMOpSlot *slot, const void *element)
+{
+       void **val = (void **) BMO_slot_map_data_get(slot, element);
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL);
+       if (val) return *val;
+
+       return NULL;
+}
+
+BLI_INLINE void *BMO_slot_map_elem_get(BMOpSlot *slot, const void *element)
 {
        void **val = (void **) BMO_slot_map_data_get(slot, element);
+       BLI_assert(slot->slot_subtype == BMO_OP_SLOT_SUBTYPE_MAP_ELEM);
        if (val) return *val;
 
        return NULL;
index 7fd9bcf1951fd162d843f3b8fdd055f802b2a159..fd26ac16224ef17e8d75b9c4bbfc624814ac4803 100644 (file)
@@ -131,8 +131,9 @@ static void bmo_op_slots_init(const BMOSlotType *slot_types, BMOpSlot *slot_args
 {
        unsigned int i;
        for (i = 0; slot_types[i].type; i++) {
-               slot_args[i].slot_name = slot_types[i].name;
-               slot_args[i].slot_type = slot_types[i].type;
+               slot_args[i].slot_name    = slot_types[i].name;
+               slot_args[i].slot_type    = slot_types[i].type;
+               slot_args[i].slot_subtype = slot_types[i].subtype;
                // slot_args[i].index = i;  // UNUSED
        }
 }
@@ -610,6 +611,9 @@ void BMO_slot_map_insert(BMOperator *op, BMOpSlot *slot,
        if (!slot->data.ghash) {
                slot->data.ghash = BLI_ghash_ptr_new("bmesh slot map hash");
        }
+       else {
+               BLI_assert(slot->data.ghash);
+       }
 
        BLI_ghash_insert(slot->data.ghash, (void *)element, mapping);
 }
index c4f6c821320d9c2d834d5ab654bdcd790afb51c2..591c758fbb2b4157cb717f13c0264af469eea975 100644 (file)
@@ -104,8 +104,7 @@ static BMEdge *copy_edge(BMOperator *op,
        if (rlen < 2) {
                /* not sure what non-manifold cases of greater then three
                 * radial should do. */
-               BMO_slot_map_ptr_insert(op, slot_boundarymap_out,
-                                       source_edge, target_edge);
+               BMO_slot_map_elem_insert(op, slot_boundarymap_out, source_edge, target_edge);
        }
 
        /* Insert new edge into the edge hash */
@@ -158,8 +157,8 @@ static BMFace *copy_face(BMOperator *op,
 
        /* create new face */
        target_face = BM_face_create(target_mesh, vtar, edar, source_face->len, FALSE);
-       BMO_slot_map_ptr_insert(op, slot_facemap_out, source_face, target_face);
-       BMO_slot_map_ptr_insert(op, slot_facemap_out, target_face, source_face);
+       BMO_slot_map_elem_insert(op, slot_facemap_out, source_face, target_face);
+       BMO_slot_map_elem_insert(op, slot_facemap_out, target_face, source_face);
 
        BM_elem_attrs_copy(source_mesh, target_mesh, source_face, target_face);
 
@@ -235,7 +234,7 @@ static void bmo_mesh_copy(BMOperator *op, BMesh *bm_src, BMesh *bm_dst)
                        }
 
                        if (isolated) {
-                               BMO_slot_map_ptr_insert(op, slot_isovertmap_out, v, v2);
+                               BMO_slot_map_elem_insert(op, slot_isovertmap_out, v, v2);
                        }
 
                        BMO_elem_flag_enable(bm_src, v, DUPE_DONE);
index 6a9d9c1e48b3966e3dd2b94eb9f935851707cbf7..25ebf32b25a99806d18d86fcef57e216573050c5 100644 (file)
@@ -354,7 +354,7 @@ void bmo_extrude_face_region_exec(BMesh *bm, BMOperator *op)
 
        slot_facemap_out = BMO_slot_get(dupeop.slots_out, "facemap.out");
        if (bm->act_face && BMO_elem_flag_test(bm, bm->act_face, EXT_INPUT)) {
-               bm->act_face = BMO_slot_map_ptr_get(slot_facemap_out, bm->act_face);
+               bm->act_face = BMO_slot_map_elem_get(slot_facemap_out, bm->act_face);
        }
 
        if (delorig) {
index 01bce976ec0f20edc4574f870831f25fc86c031d..6435f44f1d6d044bf2b3ab483269b7dfbd73edf2 100644 (file)
@@ -92,7 +92,7 @@ void bmo_mirror_exec(BMesh *bm, BMOperator *op)
        v = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL);
        for (i = 0; i < ototvert; i++) {
                if (fabsf(v->co[axis]) <= dist) {
-                       BMO_slot_map_ptr_insert(&weldop, slot_targetmap, vmap[i], v);
+                       BMO_slot_map_elem_insert(&weldop, slot_targetmap, vmap[i], v);
                }
                v = BM_iter_step(&iter);
        }
index 45e678b96bb47f6e3306f396716fa499a3dbd784..06d11c7b19d28c64e23642887c649f0775b83c76 100644 (file)
@@ -44,7 +44,7 @@ static void remdoubles_splitface(BMFace *f, BMesh *bm, BMOperator *op, BMOpSlot
        int split = FALSE;
 
        BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
-               v2 = BMO_slot_map_ptr_get(slot_targetmap, l->v);
+               v2 = BMO_slot_map_elem_get(slot_targetmap, l->v);
                /* ok: if v2 is NULL (e.g. not in the map) then it's
                 *     a target vert, otherwise it's a double */
                if ((v2 && BM_vert_in_face(f, v2)) &&
@@ -110,7 +110,7 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op)
 
        /* mark merge verts for deletion */
        BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-               if ((v2 = BMO_slot_map_ptr_get(slot_targetmap, v))) {
+               if ((v2 = BMO_slot_map_elem_get(slot_targetmap, v))) {
                        BMO_elem_flag_enable(bm, v, ELE_DEL);
 
                        /* merge the vertex flags, else we get randomly selected/unselected verts */
@@ -126,8 +126,8 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op)
 
        BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
                if (BMO_elem_flag_test(bm, e->v1, ELE_DEL) || BMO_elem_flag_test(bm, e->v2, ELE_DEL)) {
-                       v  = BMO_slot_map_ptr_get(slot_targetmap, e->v1);
-                       v2 = BMO_slot_map_ptr_get(slot_targetmap, e->v2);
+                       v  = BMO_slot_map_elem_get(slot_targetmap, e->v1);
+                       v2 = BMO_slot_map_elem_get(slot_targetmap, e->v2);
                        
                        if (!v) v = e->v1;
                        if (!v2) v2 = e->v2;
@@ -175,10 +175,10 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op)
                        v = l->v;
                        v2 = l->next->v;
                        if (BMO_elem_flag_test(bm, v, ELE_DEL)) {
-                               v = BMO_slot_map_ptr_get(slot_targetmap, v);
+                               v = BMO_slot_map_elem_get(slot_targetmap, v);
                        }
                        if (BMO_elem_flag_test(bm, v2, ELE_DEL)) {
-                               v2 = BMO_slot_map_ptr_get(slot_targetmap, v2);
+                               v2 = BMO_slot_map_elem_get(slot_targetmap, v2);
                        }
                        
                        e2 = v != v2 ? BM_edge_exists(v, v2) : NULL;
@@ -208,10 +208,10 @@ void bmo_weld_verts_exec(BMesh *bm, BMOperator *op)
                v2 = loops[1]->v;
 
                if (BMO_elem_flag_test(bm, v, ELE_DEL)) {
-                       v = BMO_slot_map_ptr_get(slot_targetmap, v);
+                       v = BMO_slot_map_elem_get(slot_targetmap, v);
                }
                if (BMO_elem_flag_test(bm, v2, ELE_DEL)) {
-                       v2 = BMO_slot_map_ptr_get(slot_targetmap, v2);
+                       v2 = BMO_slot_map_elem_get(slot_targetmap, v2);
                }
                
                f2 = BM_face_create_ngon(bm, v, v2, edges, a, TRUE);
@@ -360,7 +360,7 @@ void bmo_pointmerge_exec(BMesh *bm, BMOperator *op)
                        copy_v3_v3(snapv->co, vec);
                }
                else {
-                       BMO_slot_map_ptr_insert(&weldop, slot_targetmap, v, snapv);
+                       BMO_slot_map_elem_insert(&weldop, slot_targetmap, v, snapv);
                }
        }
 
@@ -414,9 +414,9 @@ void bmo_collapse_exec(BMesh *bm, BMOperator *op)
                        copy_v3_v3(edges[i]->v2->co, center);
                        
                        if (edges[i]->v1 != edges[0]->v1)
-                               BMO_slot_map_ptr_insert(&weldop, slot_targetmap, edges[i]->v1, edges[0]->v1);
+                               BMO_slot_map_elem_insert(&weldop, slot_targetmap, edges[i]->v1, edges[0]->v1);
                        if (edges[i]->v2 != edges[0]->v1)
-                               BMO_slot_map_ptr_insert(&weldop, slot_targetmap, edges[i]->v2, edges[0]->v1);
+                               BMO_slot_map_elem_insert(&weldop, slot_targetmap, edges[i]->v2, edges[0]->v1);
                }
        }
        
@@ -554,7 +554,7 @@ static void bmesh_find_doubles_common(BMesh *bm, BMOperator *op,
                                BMO_elem_flag_enable(bm, v_other, VERT_DOUBLE);
                                BMO_elem_flag_enable(bm, v_check, VERT_TARGET);
 
-                               BMO_slot_map_ptr_insert(optarget, optarget_slot, v_other, v_check);
+                               BMO_slot_map_elem_insert(optarget, optarget_slot, v_other, v_check);
                        }
                }
        }
index 775fa0cb60d67f9378724195012fdf17edf1793b..46f08d8ead748deab625afb0277beaa1589feda0 100644 (file)
@@ -65,9 +65,9 @@ void bmo_triangulate_exec(BMesh *bm, BMOperator *op)
 
                BM_face_triangulate(bm, face, projectverts, EDGE_NEW, FACE_NEW, newfaces, use_beauty);
 
-               BMO_slot_map_ptr_insert(op, slot_facemap_out, face, face);
+               BMO_slot_map_elem_insert(op, slot_facemap_out, face, face);
                for (i = 0; newfaces[i]; i++) {
-                       BMO_slot_map_ptr_insert(op, slot_facemap_out, newfaces[i], face);
+                       BMO_slot_map_elem_insert(op, slot_facemap_out, newfaces[i], face);
                }
        }
        
index 9bc926598dbe329d0c66db0e3d1f8ebeac5d57c3..507b93d959f99ba04567f114c76c8c5affaf2516 100644 (file)
@@ -354,21 +354,21 @@ static short edbm_extrude_edge(Object *obedit, BMEditMesh *em, const char hflag,
                                                        if ((fabsf(co1[0]) < mmd->tolerance) &&
                                                            (fabsf(co2[0]) < mmd->tolerance))
                                                        {
-                                                               BMO_slot_map_ptr_insert(&extop, slot_edges_exclude, edge, NULL);
+                                                               BMO_slot_map_empty_insert(&extop, slot_edges_exclude, edge);
                                                        }
                                                }
                                                if (mmd->flag & MOD_MIR_AXIS_Y) {
                                                        if ((fabsf(co1[1]) < mmd->tolerance) &&
                                                            (fabsf(co2[1]) < mmd->tolerance))
                                                        {
-                                                               BMO_slot_map_ptr_insert(&extop, slot_edges_exclude, edge, NULL);
+                                                               BMO_slot_map_empty_insert(&extop, slot_edges_exclude, edge);
                                                        }
                                                }
                                                if (mmd->flag & MOD_MIR_AXIS_Z) {
                                                        if ((fabsf(co1[2]) < mmd->tolerance) &&
                                                            (fabsf(co2[2]) < mmd->tolerance))
                                                        {
-                                                               BMO_slot_map_ptr_insert(&extop, slot_edges_exclude, edge, NULL);
+                                                               BMO_slot_map_empty_insert(&extop, slot_edges_exclude, edge);
                                                        }
                                                }
                                        }
index d4463098f07883a1791514680085e6d8c20c6a92..3ca2c3643450be6be460fddb52b5c7f0a19780d5 100644 (file)
@@ -274,10 +274,10 @@ static void bm_merge_dm_transform(BMesh *bm, DerivedMesh *dm, float mat[4][4],
                        v2 = BMO_iter_map_value_p(&oiter);
                        /* check in case the target vertex (v2) is already marked
                         * for merging */
-                       while ((v3 = BMO_slot_map_ptr_get(slot_targetmap, v2))) {
+                       while ((v3 = BMO_slot_map_elem_get(slot_targetmap, v2))) {
                                v2 = v3;
                        }
-                       BMO_slot_map_ptr_insert(weld_op, slot_targetmap, v, v2);
+                       BMO_slot_map_elem_insert(weld_op, slot_targetmap, v, v2);
                }
 
                BMO_op_finish(bm, &find_op);
@@ -319,7 +319,7 @@ static void merge_first_last(BMesh *bm,
        slot_targetmap = BMO_slot_get(weld_op->slots_in, "targetmap");
        BMO_ITER (v, &oiter, find_op.slots_out, "targetmap.out", 0) {
                v2 = BMO_iter_map_value_p(&oiter);
-               BMO_slot_map_ptr_insert(weld_op, slot_targetmap, v, v2);
+               BMO_slot_map_elem_insert(weld_op, slot_targetmap, v, v2);
        }
 
        BMO_op_finish(bm, &find_op);
@@ -494,11 +494,11 @@ static DerivedMesh *arrayModifier_doArray(ArrayModifierData *amd,
 
                                /* check in case the target vertex (v2) is already marked
                                 * for merging */
-                               while ((v3 = BMO_slot_map_ptr_get(slot_targetmap, v2))) {
+                               while ((v3 = BMO_slot_map_elem_get(slot_targetmap, v2))) {
                                        v2 = v3;
                                }
 
-                               BMO_slot_map_ptr_insert(&weld_op, slot_targetmap, v, v2);
+                               BMO_slot_map_elem_insert(&weld_op, slot_targetmap, v, v2);
                        }
 
                        #undef _E
index 9f702957fa5de1cd1b16fd9d7c503a9271a4d4c3..a37835e11dc9d77caf055ec8a351190e755f9e2f 100644 (file)
@@ -1093,7 +1093,7 @@ static BMFace *collapse_face_corners(BMesh *bm, BMFace *f, int n,
                v_safe = shortest_edge->v1;
                v_merge = shortest_edge->v2;
                mid_v3_v3v3(v_safe->co, v_safe->co, v_merge->co);
-               BMO_slot_map_ptr_insert(&op, slot_targetmap, v_merge, v_safe);
+               BMO_slot_map_elem_insert(&op, slot_targetmap, v_merge, v_safe);
                BMO_op_exec(bm, &op);
                BMO_op_finish(bm, &op);
 
@@ -1287,8 +1287,7 @@ static void skin_fix_hole_no_good_verts(BMesh *bm, Frame *frame, BMFace *split_f
                    "weld_verts");
        slot_targetmap = BMO_slot_get(op.slots_in, "targetmap");
        for (i = 0; i < 4; i++) {
-               BMO_slot_map_ptr_insert(&op, slot_targetmap,
-                                       verts[i], frame->verts[best_order[i]]);
+               BMO_slot_map_elem_insert(&op, slot_targetmap, verts[i], frame->verts[best_order[i]]);
        }
        BMO_op_exec(bm, &op);
        BMO_op_finish(bm, &op);