From 57668d84cf17d5e883bdfe9ec584c0683d8db860 Mon Sep 17 00:00:00 2001 From: Philipp Oeser Date: Thu, 22 Jul 2021 10:10:57 +0200 Subject: Make polls for removing mesh data layers consistent This was reported in T90026 for attributes, but was also true for: - UVMaps - Vertex Colors - Sculpt Vertex Colors - Face Maps For Vertex groups and Shapekeys this was already done (in that their remove poll would check if there is a vertex group or shapekey to begin with), now make this consistent across all mentioned types. Thx @vvv for the initial patch (where this was done for attributes only) ref T90026 Reviewed By: HooglyBoogly Maniphest Tasks: T90026 Differential Revision: https://developer.blender.org/D11990 --- source/blender/editors/mesh/mesh_data.c | 65 ++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/mesh/mesh_data.c') diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c index 73b3fb9724e..b2379610f65 100644 --- a/source/blender/editors/mesh/mesh_data.c +++ b/source/blender/editors/mesh/mesh_data.c @@ -482,8 +482,34 @@ bool ED_mesh_color_remove_named(Mesh *me, const char *name) return false; } +/*********************** General poll ************************/ + +static bool layers_poll(bContext *C) +{ + Object *ob = ED_object_context(C); + ID *data = (ob) ? ob->data : NULL; + return (ob && !ID_IS_LINKED(ob) && ob->type == OB_MESH && data && !ID_IS_LINKED(data)); +} + /*********************** Sculpt Vertex colors operators ************************/ +static bool sculpt_vertex_color_remove_poll(bContext *C) +{ + if (!layers_poll(C)) { + return false; + } + + Object *ob = ED_object_context(C); + Mesh *me = ob->data; + CustomData *vdata = GET_CD_DATA(me, vdata); + const int active = CustomData_get_active_layer(vdata, CD_PROP_COLOR); + if (active != -1) { + return true; + } + + return false; +} + /* NOTE: keep in sync with #ED_mesh_uv_texture_add. */ int ED_mesh_sculpt_color_add(Mesh *me, const char *name, const bool active_set, const bool do_init) { @@ -591,11 +617,21 @@ bool ED_mesh_sculpt_color_remove_named(Mesh *me, const char *name) /*********************** UV texture operators ************************/ -static bool layers_poll(bContext *C) +static bool uv_texture_remove_poll(bContext *C) { + if (!layers_poll(C)) { + return false; + } + Object *ob = ED_object_context(C); - ID *data = (ob) ? ob->data : NULL; - return (ob && !ID_IS_LINKED(ob) && ob->type == OB_MESH && data && !ID_IS_LINKED(data)); + Mesh *me = ob->data; + CustomData *ldata = GET_CD_DATA(me, ldata); + const int active = CustomData_get_active_layer(ldata, CD_MLOOPUV); + if (active != -1) { + return true; + } + + return false; } static int mesh_uv_texture_add_exec(bContext *C, wmOperator *UNUSED(op)) @@ -657,7 +693,7 @@ void MESH_OT_uv_texture_remove(wmOperatorType *ot) ot->idname = "MESH_OT_uv_texture_remove"; /* api callbacks */ - ot->poll = layers_poll; + ot->poll = uv_texture_remove_poll; ot->exec = mesh_uv_texture_remove_exec; /* flags */ @@ -666,6 +702,23 @@ void MESH_OT_uv_texture_remove(wmOperatorType *ot) /*********************** vertex color operators ************************/ +static bool vertex_color_remove_poll(bContext *C) +{ + if (!layers_poll(C)) { + return false; + } + + Object *ob = ED_object_context(C); + Mesh *me = ob->data; + CustomData *ldata = GET_CD_DATA(me, ldata); + const int active = CustomData_get_active_layer(ldata, CD_MLOOPCOL); + if (active != -1) { + return true; + } + + return false; +} + static int mesh_vertex_color_add_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = ED_object_context(C); @@ -714,7 +767,7 @@ void MESH_OT_vertex_color_remove(wmOperatorType *ot) /* api callbacks */ ot->exec = mesh_vertex_color_remove_exec; - ot->poll = layers_poll; + ot->poll = vertex_color_remove_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -770,7 +823,7 @@ void MESH_OT_sculpt_vertex_color_remove(wmOperatorType *ot) /* api callbacks */ ot->exec = mesh_sculpt_vertex_color_remove_exec; - ot->poll = layers_poll; + ot->poll = sculpt_vertex_color_remove_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; -- cgit v1.2.3