diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-25 01:19:18 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-25 01:19:18 +0400 |
commit | 47b6b60e5afd498337653356a52d399b7bf1da38 (patch) | |
tree | 21d6d11e48b62cc1a9860e949e51ca3166ac778f /source/blender/bmesh | |
parent | d92a4ceb351d6e7d1324e97892bff0b6252c24d5 (diff) |
code cleanup: no functional change - had both EDBM_editselection_* and BM_editselection_* funcs, replace EDBM_ funcs.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_construct.c | 35 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_core.c | 2 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_marking.c | 82 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_marking.h | 24 |
4 files changed, 100 insertions, 43 deletions
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index dee18e62930..cbdd5dd6983 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -803,6 +803,7 @@ BMesh *BM_mesh_copy(BMesh *bm_old) BMesh *bm_new; BMVert *v, *v2, **vtable = NULL; BMEdge *e, *e2, **edges = NULL, **etable = NULL; + BMElem **eletable; BLI_array_declare(edges); BMLoop *l, /* *l2, */ **loops = NULL; BLI_array_declare(loops); @@ -913,21 +914,29 @@ BMesh *BM_mesh_copy(BMesh *bm_old) /* copy over edit selection history */ for (ese = bm_old->selected.first; ese; ese = ese->next) { - void *ele = NULL; - - if (ese->htype == BM_VERT) - ele = vtable[BM_elem_index_get(ese->ele)]; - else if (ese->htype == BM_EDGE) - ele = etable[BM_elem_index_get(ese->ele)]; - else if (ese->htype == BM_FACE) { - ele = ftable[BM_elem_index_get(ese->ele)]; + BMElem *ele = NULL; + + switch (ese->htype) { + case BM_VERT: + eletable = (BMElem **)vtable; + break; + case BM_EDGE: + eletable = (BMElem **)etable; + break; + case BM_FACE: + eletable = (BMElem **)ftable; + break; + default: + eletable = NULL; + break; } - else { - BLI_assert(0); + + if (eletable) { + ele = eletable[BM_elem_index_get(ese->ele)]; + if (ele) { + BM_select_history_store(bm_new, ele); + } } - - if (ele) - BM_select_history_store(bm_new, ele); } MEM_freeN(etable); diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 7d4129b1205..f3f7614fe02 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -453,7 +453,7 @@ static void bm_kill_only_vert(BMesh *bm, BMVert *v) bm->totvert--; bm->elem_index_dirty |= BM_VERT; - BM_select_history_remove(bm, (BMElem *)v); + BM_select_history_remove(bm, v); if (v->head.data) CustomData_bmesh_free_block(&bm->vdata, &v->head.data); diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index 9200d7d2a98..57a5b20b689 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -566,7 +566,7 @@ BMFace *BM_active_face_get(BMesh *bm, int sloppy) * - #EM_editselection_normal * - #EM_editselection_plane */ -void BM_editselection_center(float r_center[3], BMEditSelection *ese) +void BM_editselection_center(BMEditSelection *ese, float r_center[3]) { if (ese->htype == BM_VERT) { BMVert *eve = (BMVert *)ese->ele; @@ -583,7 +583,7 @@ void BM_editselection_center(float r_center[3], BMEditSelection *ese) } } -void BM_editselection_normal(float r_normal[3], BMEditSelection *ese) +void BM_editselection_normal(BMEditSelection *ese, float r_normal[3]) { if (ese->htype == BM_VERT) { BMVert *eve = (BMVert *)ese->ele; @@ -617,14 +617,14 @@ void BM_editselection_normal(float r_normal[3], BMEditSelection *ese) /* Calculate a plane that is rightangles to the edge/vert/faces normal * also make the plane run along an axis that is related to the geometry, * because this is used for the manipulators Y axis. */ -void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese) +void BM_editselection_plane(BMEditSelection *ese, float r_plane[3]) { if (ese->htype == BM_VERT) { BMVert *eve = (BMVert *)ese->ele; float vec[3] = {0.0f, 0.0f, 0.0f}; if (ese->prev) { /* use previously selected data to make a useful vertex plane */ - BM_editselection_center(vec, ese->prev); + BM_editselection_center(ese->prev, vec); sub_v3_v3v3(r_plane, vec, eve->co); } else { @@ -674,7 +674,7 @@ void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese) else { BMVert *verts[4] = {NULL}; - BM_iter_as_array(bm, BM_VERTS_OF_FACE, efa, (void **)verts, 4); + BM_iter_as_array(NULL, BM_VERTS_OF_FACE, efa, (void **)verts, 4); if (efa->len == 4) { float vecA[3], vecB[3]; @@ -713,12 +713,14 @@ void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese) normalize_v3(r_plane); } -int BM_select_history_check(BMesh *bm, const BMElem *ele) + +/* --- macro wrapped funcs --- */ +int _bm_select_history_check(BMesh *bm, const BMHeader *ele) { BMEditSelection *ese; for (ese = bm->selected.first; ese; ese = ese->next) { - if (ese->ele == ele) { + if (ese->ele == (BMElem *)ele) { return TRUE; } } @@ -726,11 +728,11 @@ int BM_select_history_check(BMesh *bm, const BMElem *ele) return FALSE; } -int BM_select_history_remove(BMesh *bm, BMElem *ele) +int _bm_select_history_remove(BMesh *bm, BMHeader *ele) { BMEditSelection *ese; for (ese = bm->selected.first; ese; ese = ese->next) { - if (ese->ele == ele) { + if (ese->ele == (BMElem *)ele) { BLI_freelinkN(&(bm->selected), ese); return TRUE; } @@ -739,26 +741,29 @@ int BM_select_history_remove(BMesh *bm, BMElem *ele) return FALSE; } -void BM_select_history_clear(BMesh *bm) -{ - BLI_freelistN(&bm->selected); - bm->selected.first = bm->selected.last = NULL; -} - -void BM_select_history_store_notest(BMesh *bm, BMElem *ele) +void _bm_select_history_store_notest(BMesh *bm, BMHeader *ele) { BMEditSelection *ese = (BMEditSelection *) MEM_callocN(sizeof(BMEditSelection), "BMEdit Selection"); - ese->htype = ((BMHeader *)ele)->htype; - ese->ele = ele; + ese->htype = ele->htype; + ese->ele = (BMElem *)ele; BLI_addtail(&(bm->selected), ese); } -void BM_select_history_store(BMesh *bm, BMElem *ele) +void _bm_select_history_store(BMesh *bm, BMHeader *ele) { - if (!BM_select_history_check(bm, ele)) { - BM_select_history_store_notest(bm, ele); + if (!BM_select_history_check(bm, (BMElem *)ele)) { + BM_select_history_store_notest(bm, (BMElem *)ele); } } +/* --- end macro wrapped funcs --- */ + + +void BM_select_history_clear(BMesh *bm) +{ + BLI_freelistN(&bm->selected); + bm->selected.first = bm->selected.last = NULL; +} + void BM_select_history_validate(BMesh *bm) { @@ -775,6 +780,41 @@ void BM_select_history_validate(BMesh *bm) } } +/* utility function */ +int BM_select_history_active_get(BMesh *bm, BMEditSelection *ese) +{ + BMEditSelection *ese_last = bm->selected.last; + BMFace *efa = BM_active_face_get(bm, FALSE); + + ese->next = ese->prev = NULL; + + if (ese_last) { + if (ese_last->htype == BM_FACE) { /* if there is an active face, use it over the last selected face */ + if (efa) { + ese->ele = (BMElem *)efa; + } + else { + ese->ele = ese_last->ele; + } + ese->htype = BM_FACE; + } + else { + ese->ele = ese_last->ele; + ese->htype = ese_last->htype; + } + } + else if (efa) { /* no */ + ese->ele = (BMElem *)efa; + ese->htype = BM_FACE; + } + else { + ese->ele = NULL; + return FALSE; + } + + return TRUE; +} + void BM_mesh_elem_hflag_disable_test(BMesh *bm, const char htype, const char hflag, int respecthide, const char hflag_test) { diff --git a/source/blender/bmesh/intern/bmesh_marking.h b/source/blender/bmesh/intern/bmesh_marking.h index a3e97ea9677..03681707826 100644 --- a/source/blender/bmesh/intern/bmesh_marking.h +++ b/source/blender/bmesh/intern/bmesh_marking.h @@ -73,15 +73,23 @@ int BM_mesh_elem_hflag_count_disabled(BMesh *bm, const char htype, const char hf /* edit selection stuff */ void BM_active_face_set(BMesh *bm, BMFace *f); BMFace *BM_active_face_get(BMesh *bm, int sloppy); -void BM_editselection_center(float r_center[3], BMEditSelection *ese); -void BM_editselection_normal(float r_normal[3], BMEditSelection *ese); -void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese); - -int BM_select_history_check(BMesh *bm, const BMElem *ele); -int BM_select_history_remove(BMesh *bm, BMElem *ele); -void BM_select_history_store_notest(BMesh *bm, BMElem *ele); -void BM_select_history_store(BMesh *bm, BMElem *ele); + +void BM_editselection_center(BMEditSelection *ese, float r_center[3]); +void BM_editselection_normal(BMEditSelection *ese, float r_normal[3]); +void BM_editselection_plane(BMEditSelection *ese, float r_plane[3]); + +#define BM_select_history_check(bm, ele) _bm_select_history_check(bm, &(ele)->head) +#define BM_select_history_remove(bm, ele) _bm_select_history_remove(bm, &(ele)->head) +#define BM_select_history_store_notest(bm, ele) _bm_select_history_store_notest(bm, &(ele)->head) +#define BM_select_history_store(bm, ele) _bm_select_history_store(bm, &(ele)->head) + +int _bm_select_history_check(BMesh *bm, const BMHeader *ele); +int _bm_select_history_remove(BMesh *bm, BMHeader *ele); +void _bm_select_history_store_notest(BMesh *bm, BMHeader *ele); +void _bm_select_history_store(BMesh *bm, BMHeader *ele); + void BM_select_history_validate(BMesh *bm); void BM_select_history_clear(BMesh *em); +int BM_select_history_active_get(BMesh *bm, struct BMEditSelection *ese); #endif /* __BMESH_MARKING_H__ */ |