[Bf-blender-cvs] [57668d84cf1] master: Make polls for removing mesh data layers consistent

Philipp Oeser noreply at git.blender.org
Thu Jul 22 10:19:03 CEST 2021


Commit: 57668d84cf17d5e883bdfe9ec584c0683d8db860
Author: Philipp Oeser
Date:   Thu Jul 22 10:10:57 2021 +0200
Branches: master
https://developer.blender.org/rB57668d84cf17d5e883bdfe9ec584c0683d8db860

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

===================================================================

M	source/blender/editors/geometry/geometry_attributes.c
M	source/blender/editors/mesh/mesh_data.c
M	source/blender/editors/object/object_facemap_ops.c

===================================================================

diff --git a/source/blender/editors/geometry/geometry_attributes.c b/source/blender/editors/geometry/geometry_attributes.c
index 9b034d82a51..5cb491f116a 100644
--- a/source/blender/editors/geometry/geometry_attributes.c
+++ b/source/blender/editors/geometry/geometry_attributes.c
@@ -47,6 +47,21 @@ static bool geometry_attributes_poll(bContext *C)
          BKE_id_attributes_supported(data);
 }
 
+static bool geometry_attributes_remove_poll(bContext *C)
+{
+  if (!geometry_attributes_poll(C)) {
+    return false;
+  }
+
+  Object *ob = ED_object_context(C);
+  ID *data = (ob) ? ob->data : NULL;
+  if (BKE_id_attributes_active_get(data) != NULL) {
+    return true;
+  }
+
+  return false;
+}
+
 static const EnumPropertyItem *geometry_attribute_domain_itemf(bContext *C,
                                                                PointerRNA *UNUSED(ptr),
                                                                PropertyRNA *UNUSED(prop),
@@ -160,7 +175,7 @@ void GEOMETRY_OT_attribute_remove(wmOperatorType *ot)
 
   /* api callbacks */
   ot->exec = geometry_attribute_remove_exec;
-  ot->poll = geometry_attributes_poll;
+  ot->poll = geometry_attributes_remove_poll;
 
   /* flags */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
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;
diff --git a/source/blender/editors/object/object_facemap_ops.c b/source/blender/editors/object/object_facemap_ops.c
index 3d4d3c8f622..92f3d28878c 100644
--- a/source/blender/editors/object/object_facemap_ops.c
+++ b/source/blender/editors/object/object_facemap_ops.c
@@ -176,6 +176,21 @@ static bool face_map_supported_edit_mode_poll(bContext *C)
   return false;
 }
 
+static bool face_map_supported_remove_poll(bContext *C)
+{
+  if (!face_map_supported_poll(C)) {
+    return false;
+  }
+
+  Object *ob = ED_object_context(C);
+  bFaceMap *fmap = BLI_findlink(&ob->fmaps, ob->actfmap - 1);
+  if (fmap) {
+    return true;
+  }
+
+  return false;
+}
+
 static int face_map_add_exec(bContext *C, wmOperator *UNUSED(op))
 {
   Object *ob = ED_object_context(C);
@@ -225,7 +240,7 @@ void OBJECT_OT_face_map_remove(struct wmOperatorType *ot)
   ot->description = "Remove a face map from the active object";
 
   /* api callbacks */
-  ot->poll = face_map_supported_poll;
+  ot->poll = face_map_supported_remove_poll;
   ot->exec = face_map_remove_exec;
 
   /* flags */



More information about the Bf-blender-cvs mailing list