Patch #6759: this speeds up the vertex group editing workflow a bit.
authorJoshua Leung <aligorith@gmail.com>
Wed, 30 May 2007 10:36:17 +0000 (10:36 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 30 May 2007 10:36:17 +0000 (10:36 +0000)
The hotkey Ctrl-G in EditMode for Meshes and Lattices, brings up a menu giving the user options to assign/remove selected vertices to a new/the active Vertex Group.

The hotkey Ctrl-Shift-G in EditMode for Meshes and Lattices, brings up a menu giving the user options to change the active Vertex Group and delete the current Vertex Group.

source/blender/include/BIF_editdeform.h
source/blender/src/editdeform.c
source/blender/src/space.c

index 69f036528874d839892ab3fa4c03f8bb8695df4b..2a8f43c14e75cce5fb568d89bceafd66ce611a0a 100644 (file)
@@ -67,5 +67,8 @@ void vertexgroup_select_by_name(struct Object *ob, char *name);
 
 extern void object_apply_deform(struct Object *ob);
 
+void vgroup_assign_with_menu(void);
+void vgroup_operation_with_menu(void);
+
 #endif
 
index 305d01a8aea620a9b7866705db0021fbe5cd58df..7a086ed5be3629d132b55215c4adf5024be0dace 100644 (file)
 #include "BKE_mesh.h"
 #include "BKE_utildefines.h"
 
+#include "BIF_interface.h"
 #include "BIF_editdeform.h"
 #include "BIF_editmesh.h"
+#include "BIF_space.h"
 #include "BIF_toolbox.h"
 
 #include "BSE_edit.h"
 
+#include "butspace.h"
+#include "mydevice.h"
 #include "editmesh.h"
 #include "multires.h"
 
@@ -788,6 +792,99 @@ void vertexgroup_select_by_name(Object *ob, char *name)
        ob->actdef=0;   // this signals on painting to create a new one, if a bone in posemode is selected */
 }
 
+/* This function provides a shortcut for adding/removing verts from 
+ * vertex groups. It is called by the Ctrl-G hotkey in EditMode for Meshes
+ * and Lattices. (currently only restricted to those two)
+ * It is only responsible for 
+ */
+void vgroup_assign_with_menu(void)
+{
+       Object *ob= G.obedit;
+       int defCount;
+       int mode;
+       
+       /* prevent crashes */
+       if (ob==NULL) return;
+       
+       defCount= BLI_countlist(&ob->defbase);
+       
+       /* give user choices of adding to current/new or removing from current */
+       if (defCount && ob->actdef)
+               mode = pupmenu("Vertex Groups %t|Add Selected to New Group %x1|Add Selected to Active Group %x2|Remove Selected from Active Group %x3");
+       else
+               mode= pupmenu("Vertex Groups %t|Add Selected to New Group %x1");
+       
+       /* handle choices */
+       switch (mode) {
+               case 1: /* add to new group */
+                       add_defgroup(ob);
+                       assign_verts_defgroup();
+                       allqueue(REDRAWVIEW3D, 1);
+                       BIF_undo_push("Assign to vertex group");
+                       break;
+               case 2: /* add to current group */
+                       assign_verts_defgroup();
+                       allqueue(REDRAWVIEW3D, 1);
+                       BIF_undo_push("Assign to vertex group");
+                       break;
+               case 3: /* remove from current group */
+                       remove_verts_defgroup(0);
+                       allqueue(REDRAWVIEW3D, 1);
+                       BIF_undo_push("Remove from vertex group");
+                       break;
+       }
+}
+
+/* This function provides a shortcut for commonly used vertex group 
+ * functions - change weight (not implemented), change active group, delete active group,
+ * when Ctrl-Shift-G is used in EditMode, for Meshes and Lattices (only for now).
+ */
+void vgroup_operation_with_menu(void)
+{
+       Object *ob= G.obedit;
+       int defCount;
+       int mode;
+       
+       /* prevent crashes and useless cases */
+       if (ob==NULL) return;
+       
+       defCount= BLI_countlist(&ob->defbase);
+       if (defCount == 0) return;
+       
+       /* give user choices of adding to current/new or removing from current */
+       if (ob->actdef)
+               mode = pupmenu("Vertex Groups %t|Change Active Group%x1|Delete Active Group%x2");
+       else
+               mode= pupmenu("Vertex Groups %t|Change Active Group%x1");
+       
+       /* handle choices */
+       switch (mode) {
+               case 1: /* change active group*/
+                       {
+                               char *menustr= get_vertexgroup_menustr(ob);
+                               short nr;
+                               
+                               if (menustr) {
+                                       nr= pupmenu(menustr);
+                                       
+                                       if ((nr >= 1) && (nr <= defCount)) 
+                                               ob->actdef= nr;
+                                               
+                                       MEM_freeN(menustr);
+                               }
+                               allqueue(REDRAWBUTSALL, 0);
+                       }
+                       break;
+               case 2: /* delete active group  */
+                       {
+                               del_defgroup(ob);
+                               allqueue (REDRAWVIEW3D, 1);
+                               allqueue(REDRAWOOPS, 0);
+                               BIF_undo_push("Delete vertex group");
+                       }
+                       break;
+       }
+}
 
 /* ******************* other deform edit stuff ********** */
 
index a528fd260ff0a1aebed0021389747acaffd611f3..ec43d55a2bdcc11bb9cd131dd9eec5345d3121a2 100644 (file)
@@ -97,6 +97,7 @@
 #include "BIF_drawscript.h"
 #include "BIF_editarmature.h"
 #include "BIF_editconstraint.h"
+#include "BIF_editdeform.h"
 #include "BIF_editfont.h"
 #include "BIF_editgroup.h"
 #include "BIF_editkey.h"
@@ -1835,8 +1836,20 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                
                                break;
                        case GKEY:
-                               if(G.qual == LR_CTRLKEY) 
-                                       group_operation_with_menu();
+                               if((G.qual == LR_CTRLKEY)) {
+                                       if(G.obedit) {
+                                               if(ELEM(G.obedit->type, OB_MESH, OB_LATTICE))
+                                                       vgroup_assign_with_menu();
+                                       }
+                                       else
+                                               group_operation_with_menu();
+                               }
+                               else if((G.qual == (LR_CTRLKEY|LR_SHIFTKEY))) {
+                                       if(G.obedit) {
+                                               if(ELEM(G.obedit->type, OB_MESH, OB_LATTICE))
+                                                       vgroup_operation_with_menu();
+                                       }
+                               }
                                else if((G.qual==LR_SHIFTKEY))
                                        if(G.obedit) {
                                                if(G.obedit->type==OB_MESH)