Added 'delete unlocked vertex groups' option.
authorSybren A. Stüvel <sybren@stuvel.eu>
Mon, 31 Oct 2016 14:31:47 +0000 (15:31 +0100)
committerSybren A. Stüvel <sybren@stuvel.eu>
Mon, 31 Oct 2016 14:31:47 +0000 (15:31 +0100)
release/scripts/startup/bl_ui/properties_data_mesh.py
source/blender/blenkernel/BKE_object_deform.h
source/blender/blenkernel/intern/object_deform.c
source/blender/editors/object/object_vgroup.c

index 5416735494b0e2209b51604e993df48cf00b4df5..59907692fe0a5b17a785b13c6ea63888eea42654 100644 (file)
@@ -38,6 +38,7 @@ class MESH_MT_vertex_group_specials(Menu):
         layout.operator("object.vertex_group_mirror", text="Mirror Vertex Group (Topology)", icon='ARROW_LEFTRIGHT').use_topology = True
         layout.operator("object.vertex_group_remove_from", icon='X', text="Remove from All Groups").use_all_groups = True
         layout.operator("object.vertex_group_remove_from", icon='X', text="Clear Active Group").use_all_verts = True
+        layout.operator("object.vertex_group_remove", icon='X', text="Delete All Unlocked Groups").all_unlocked = True
         layout.operator("object.vertex_group_remove", icon='X', text="Delete All Groups").all = True
         layout.separator()
         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock All").action = 'LOCK'
index a0a885c2a04c03695a46f45e43519f9bbf7e8c77..19a2220006a7fb5bf7db3b79a42356fec80f162e 100644 (file)
@@ -51,9 +51,11 @@ bool BKE_object_defgroup_clear(struct Object *ob, struct bDeformGroup *dg, const
 bool BKE_object_defgroup_clear_all(struct Object *ob, const bool use_selection);
 
 void BKE_object_defgroup_remove(struct Object *ob, struct bDeformGroup *defgroup);
+void BKE_object_defgroup_remove_all_ex(struct Object *ob, bool only_unlocked);
 void BKE_object_defgroup_remove_all(struct Object *ob);
 
 
+
 /* Select helpers */
 enum eVGroupSelect;
 bool *BKE_object_defgroup_subset_from_select_type(
index b5f63588423ea109764e34c21d6f925af701be7a..b5e1ded35bbefe6fe13efac275f02790b69ee3c1 100644 (file)
@@ -408,8 +408,9 @@ void BKE_object_defgroup_remove(Object *ob, bDeformGroup *defgroup)
 
 /**
  * Remove all vgroups from object. Work in Object and Edit modes.
+ * When only_unlocked=true, locked vertex groups are not removed.
  */
-void BKE_object_defgroup_remove_all(Object *ob)
+void BKE_object_defgroup_remove_all_ex(struct Object *ob, bool only_unlocked)
 {
        bDeformGroup *dg = (bDeformGroup *)ob->defbase.first;
        const bool edit_mode = BKE_object_is_in_editmode_vgroup(ob);
@@ -418,10 +419,12 @@ void BKE_object_defgroup_remove_all(Object *ob)
                while (dg) {
                        bDeformGroup *next_dg = dg->next;
 
-                       if (edit_mode)
-                               object_defgroup_remove_edit_mode(ob, dg);
-                       else
-                               object_defgroup_remove_object_mode(ob, dg);
+                       if (!only_unlocked || (dg->flag & DG_LOCK_WEIGHT) == 0) {
+                               if (edit_mode)
+                                       object_defgroup_remove_edit_mode(ob, dg);
+                               else
+                                       object_defgroup_remove_object_mode(ob, dg);
+                       }
 
                        dg = next_dg;
                }
@@ -445,6 +448,15 @@ void BKE_object_defgroup_remove_all(Object *ob)
        }
 }
 
+/**
+ * Remove all vgroups from object. Work in Object and Edit modes.
+ */
+void BKE_object_defgroup_remove_all(struct Object *ob)
+{
+       BKE_object_defgroup_remove_all_ex(ob, false);
+}
+
+
 /**
  * Get MDeformVert vgroup data from given object. Should only be used in Object mode.
  *
index bd016b7fcfb298a959bde1c3a9d7e12cc4d03ed2..82da6f589125eb674e941187f70a1a02c1e413e0 100644 (file)
@@ -2604,6 +2604,8 @@ static int vertex_group_remove_exec(bContext *C, wmOperator *op)
 
        if (RNA_boolean_get(op->ptr, "all"))
                BKE_object_defgroup_remove_all(ob);
+       else if (RNA_boolean_get(op->ptr, "all_unlocked"))
+               BKE_object_defgroup_remove_all_ex(ob, true);
        else
                vgroup_delete_active(ob);
 
@@ -2633,6 +2635,7 @@ void OBJECT_OT_vertex_group_remove(wmOperatorType *ot)
 
        /* properties */
        RNA_def_boolean(ot->srna, "all", 0, "All", "Remove all vertex groups");
+       RNA_def_boolean(ot->srna, "all_unlocked", 0, "All Unlocked", "Remove all unlocked vertex groups");
 }
 
 static int vertex_group_assign_exec(bContext *C, wmOperator *UNUSED(op))