Revision: 28565
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28565
Author:   joeedh
Date:     2010-05-04 10:59:32 +0200 (Tue, 04 May 2010)

Log Message:
-----------
adding up/down buttons for moving vgroups in the stack

Modified Paths:
--------------
    branches/render25/release/scripts/ui/properties_data_mesh.py
    branches/render25/source/blender/editors/object/object_intern.h
    branches/render25/source/blender/editors/object/object_ops.c
    branches/render25/source/blender/editors/object/object_vgroup.c
    branches/render25/source/blender/editors/space_view3d/drawobject.c
    branches/render25/source/blender/makesdna/DNA_object_types.h

Modified: branches/render25/release/scripts/ui/properties_data_mesh.py
===================================================================
--- branches/render25/release/scripts/ui/properties_data_mesh.py        
2010-05-04 07:34:46 UTC (rev 28564)
+++ branches/render25/release/scripts/ui/properties_data_mesh.py        
2010-05-04 08:59:32 UTC (rev 28565)
@@ -155,6 +155,9 @@
         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="")
         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', 
text="")
+        if group:
+            col.operator("object.vertex_group_move", icon='TRIA_UP', 
text="").direction = 'UP'
+            col.operator("object.vertex_group_move", icon='TRIA_DOWN', 
text="").direction = 'DOWN'
 
         if group:
             row = layout.row()

Modified: branches/render25/source/blender/editors/object/object_intern.h
===================================================================
--- branches/render25/source/blender/editors/object/object_intern.h     
2010-05-04 07:34:46 UTC (rev 28564)
+++ branches/render25/source/blender/editors/object/object_intern.h     
2010-05-04 08:59:32 UTC (rev 28565)
@@ -196,6 +196,7 @@
 void OBJECT_OT_vertex_group_mirror(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_set_active(struct wmOperatorType *ot);
 void OBJECT_OT_vertex_group_sort(struct wmOperatorType *ot);
+void OBJECT_OT_vertex_group_move(struct wmOperatorType *ot);
 
 void OBJECT_OT_game_property_new(struct wmOperatorType *ot);
 void OBJECT_OT_game_property_remove(struct wmOperatorType *ot);

Modified: branches/render25/source/blender/editors/object/object_ops.c
===================================================================
--- branches/render25/source/blender/editors/object/object_ops.c        
2010-05-04 07:34:46 UTC (rev 28564)
+++ branches/render25/source/blender/editors/object/object_ops.c        
2010-05-04 08:59:32 UTC (rev 28565)
@@ -176,6 +176,7 @@
        WM_operatortype_append(OBJECT_OT_vertex_group_mirror);
        WM_operatortype_append(OBJECT_OT_vertex_group_set_active);
        WM_operatortype_append(OBJECT_OT_vertex_group_sort);
+       WM_operatortype_append(OBJECT_OT_vertex_group_move);
 
        WM_operatortype_append(OBJECT_OT_game_property_new);
        WM_operatortype_append(OBJECT_OT_game_property_remove);

Modified: branches/render25/source/blender/editors/object/object_vgroup.c
===================================================================
--- branches/render25/source/blender/editors/object/object_vgroup.c     
2010-05-04 07:34:46 UTC (rev 28564)
+++ branches/render25/source/blender/editors/object/object_vgroup.c     
2010-05-04 08:59:32 UTC (rev 28565)
@@ -1920,41 +1920,38 @@
        ot->prop= prop;
 }
 
-static int vgroup_sort(void *def_a_ptr, void *def_b_ptr)
+/*creates the name_array parameter for vgroup_do_remap, call this before 
fiddling
+  with the order of vgroups then call vgroup_do_remap after*/
+static char *vgroup_init_remap(Object *ob)
 {
-       bDeformGroup *def_a= (bDeformGroup *)def_a_ptr;
-       bDeformGroup *def_b= (bDeformGroup *)def_b_ptr;
+       bDeformGroup *def;
+       int def_tot = BLI_countlist(&ob->defbase);
+       char *name_array= MEM_mallocN(MAX_VGROUP_NAME * sizeof(char) * def_tot, 
"sort vgroups");
+       char *name;
 
-       return strcmp(def_a->name, def_b->name);
+       name= name_array;
+       for(def = ob->defbase.first; def; def=def->next) {
+               BLI_strncpy(name, def->name, MAX_VGROUP_NAME);
+               name += MAX_VGROUP_NAME;
+       }
+
+       return name_array;
 }
 
-#define DEF_GROUP_SIZE (sizeof(((bDeformGroup *)NULL)->name))
-static int vertex_group_sort_exec(bContext *C, wmOperator *op)
+static int vgroup_do_remap(Object *ob, char *name_array, wmOperator *op)
 {
-       Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       MDeformVert *dvert= NULL;
        bDeformGroup *def;
        int def_tot = BLI_countlist(&ob->defbase);
+       int *sort_map_update= MEM_mallocN(MAX_VGROUP_NAME * sizeof(int) * 
def_tot + 1, "sort vgroups"); /* needs a dummy index at the start*/
+       int *sort_map= sort_map_update + 1;
        char *name;
-       char *name_array= MEM_mallocN(DEF_GROUP_SIZE * sizeof(char) * def_tot, 
"sort vgroups");
-       int *sort_map_update= MEM_mallocN(DEF_GROUP_SIZE * sizeof(int) * 
def_tot + 1, "sort vgroups"); /* needs a dummy index at the start*/
-       int *sort_map= sort_map_update + 1;
        int i;
 
-       MDeformVert *dvert= NULL;
-       int dvert_tot;
-
        name= name_array;
-       for(def = ob->defbase.first; def; def=def->next){
-               BLI_strncpy(name, def->name, DEF_GROUP_SIZE);
-               name += DEF_GROUP_SIZE;
-       }
-
-       BLI_sortlist(&ob->defbase, vgroup_sort);
-
-       name= name_array;
        for(def= ob->defbase.first, i=0; def; def=def->next, i++){
                sort_map[i]= BLI_findstringindex(&ob->defbase, name, 
offsetof(bDeformGroup, name));
-               name += DEF_GROUP_SIZE;
+               name += MAX_VGROUP_NAME;
        }
 
        if(ob->mode == OB_MODE_EDIT) {
@@ -1975,8 +1972,12 @@
                }
        }
        else {
+               int dvert_tot=0;
+
                ED_vgroup_give_array(ob->data, &dvert, &dvert_tot);
-               while(dvert_tot--) {
+
+               /*create as necassary*/
+               while(dvert && dvert_tot--) {
                        if(dvert->totweight)
                                defvert_remap(dvert, sort_map);
                        dvert++;
@@ -1988,22 +1989,46 @@
                sort_map[i]++;
 
        sort_map_update[0]= 0;
-
        vgroup_remap_update_users(ob, sort_map_update);
 
        ob->actdef= sort_map_update[ob->actdef];
 
-       MEM_freeN(name_array);
-       MEM_freeN(sort_map_update);
+       return OPERATOR_FINISHED;
+}
 
-       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob);
+static int vgroup_sort(void *def_a_ptr, void *def_b_ptr)
+{
+       bDeformGroup *def_a= (bDeformGroup *)def_a_ptr;
+       bDeformGroup *def_b= (bDeformGroup *)def_b_ptr;
 
-       return OPERATOR_FINISHED;
+       return strcmp(def_a->name, def_b->name);
 }
-#undef DEF_GROUP_SIZE
 
+static int vertex_group_sort_exec(bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       char *name_array;
+       int ret;
 
+       /*init remapping*/
+       name_array = vgroup_init_remap(ob);
+
+       /*sort vgroup names*/
+       BLI_sortlist(&ob->defbase, vgroup_sort);
+
+       /*remap vgroup data to map to correct names*/
+       ret = vgroup_do_remap(ob, name_array, op);
+
+       if (ret != OPERATOR_CANCELLED) {
+               DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+               WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob);
+       }
+
+       if (name_array) MEM_freeN(name_array);
+
+       return ret;
+}
+
 void OBJECT_OT_vertex_group_sort(wmOperatorType *ot)
 {
        ot->name= "Sort Vertex Groups";
@@ -2017,3 +2042,63 @@
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
+
+static int vgroup_move_exec(bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+       bDeformGroup *def;
+       char *name_array;
+       int dir= RNA_enum_get(op->ptr, "direction"), ret;
+
+       def = BLI_findlink(&ob->defbase, ob->actdef - 1);
+       if (!def) {
+               return OPERATOR_CANCELLED;
+       }
+
+       name_array = vgroup_init_remap(ob);
+
+       if (dir == 1) { /*up*/
+               void *prev = def->prev;
+
+               BLI_remlink(&ob->defbase, def);
+               BLI_insertlinkbefore(&ob->defbase, prev, def);
+       } else { /*down*/
+               void *next = def->next;
+
+               BLI_remlink(&ob->defbase, def);
+               BLI_insertlinkafter(&ob->defbase, next, def);
+       }
+
+       ret = vgroup_do_remap(ob, name_array, op);
+
+       if (name_array) MEM_freeN(name_array);
+
+       if (ret != OPERATOR_CANCELLED) {
+               DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+               WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob);
+       }
+
+       return ret;
+}
+
+void OBJECT_OT_vertex_group_move(wmOperatorType *ot)
+{
+       static EnumPropertyItem vgroup_slot_move[] = {
+               {1, "UP", 0, "Up", ""},
+               {-1, "DOWN", 0, "Down", ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       /* identifiers */
+       ot->name= "Move Vertex Group";
+       ot->idname= "OBJECT_OT_vertex_group_move";
+
+       /* api callbacks */
+       ot->poll= vertex_group_poll;
+       ot->exec= vgroup_move_exec;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       RNA_def_enum(ot->srna, "direction", vgroup_slot_move, 0, "Direction", 
"Direction to move, UP or DOWN");
+}

Modified: branches/render25/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/render25/source/blender/editors/space_view3d/drawobject.c  
2010-05-04 07:34:46 UTC (rev 28564)
+++ branches/render25/source/blender/editors/space_view3d/drawobject.c  
2010-05-04 08:59:32 UTC (rev 28565)
@@ -3864,7 +3864,7 @@
                float *cd2=0,*cdata2=0;
 
                /* setup gl flags */
-               if(ob_dt > OB_WIRE) {
+               if (1) { //ob_dt > OB_WIRE) {
                        glEnableClientState(GL_NORMAL_ARRAY);
 
                        if(part->draw&PART_DRAW_MAT_COL)
@@ -3874,13 +3874,13 @@
                        glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
                        glEnable(GL_COLOR_MATERIAL);
                }
-               else {
+               /*else {
                        glDisableClientState(GL_NORMAL_ARRAY);
 
                        glDisable(GL_COLOR_MATERIAL);
                        glDisable(GL_LIGHTING);
                        UI_ThemeColor(TH_WIRE);
-               }
+               }*/
 
                if(totchild && (part->draw&PART_DRAW_PARENT)==0)
                        totpart=0;
@@ -3894,7 +3894,7 @@
                        if(path->steps > 0) {
                                glVertexPointer(3, GL_FLOAT, 
sizeof(ParticleCacheKey), path->co);
 
-                               if(ob_dt > OB_WIRE) {
+                               if(1) { //ob_dt > OB_WIRE) {
                                        glNormalPointer(GL_FLOAT, 
sizeof(ParticleCacheKey), path->vel);
                                        if(part->draw&PART_DRAW_MAT_COL)
                                                glColorPointer(3, GL_FLOAT, 
sizeof(ParticleCacheKey), path->col);
@@ -3910,7 +3910,7 @@
                        path=cache[a];
                        glVertexPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), 
path->co);
 
-                       if(ob_dt > OB_WIRE) {
+                       if(1) { //ob_dt > OB_WIRE) {
                                glNormalPointer(GL_FLOAT, 
sizeof(ParticleCacheKey), path->vel);
                                if(part->draw&PART_DRAW_MAT_COL)
                                        glColorPointer(3, GL_FLOAT, 
sizeof(ParticleCacheKey), path->col);
@@ -3921,7 +3921,7 @@
 
 
                /* restore & clean up */
-               if(ob_dt > OB_WIRE) {
+               if(1) { //ob_dt > OB_WIRE) {
                        if(part->draw&PART_DRAW_MAT_COL)
                                glDisable(GL_COLOR_ARRAY);
                        glDisable(GL_COLOR_MATERIAL);

Modified: branches/render25/source/blender/makesdna/DNA_object_types.h
===================================================================
--- branches/render25/source/blender/makesdna/DNA_object_types.h        
2010-05-04 07:34:46 UTC (rev 28564)
+++ branches/render25/source/blender/makesdna/DNA_object_types.h        
2010-05-04 08:59:32 UTC (rev 28565)
@@ -62,6 +62,7 @@
        struct bDeformGroup *next, *prev;
        char name[32];
 } bDeformGroup;
+#define MAX_VGROUP_NAME 32
 
 /**
  * The following illustrates the orientation of the 


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to