2.5 - More armature/bone operator tweaks
authorJoshua Leung <aligorith@gmail.com>
Sun, 26 Jul 2009 11:01:56 +0000 (11:01 +0000)
committerJoshua Leung <aligorith@gmail.com>
Sun, 26 Jul 2009 11:01:56 +0000 (11:01 +0000)
* Restored quick operators for moving bones between layers and switching visible armature layers. The popup used here (based on the layers template) is not optimal yet - you can click on multiple layer buttons to enable/disable them, but you need to move your mouse outside the area for it to confirm.

* Separate armatures works again. I've tweaked the arguments to ED_object_duplicate() to make this work (besides, the other users of this wouldn't have been affected).

* Added some missing special (transform) operators to the menus + keymaps

source/blender/editors/armature/armature_intern.h
source/blender/editors/armature/armature_ops.c
source/blender/editors/armature/editarmature.c
source/blender/editors/armature/poseobject.c
source/blender/editors/include/ED_object.h
source/blender/editors/object/object_edit.c
source/blender/editors/space_view3d/view3d_header.c

index bf329270b8c1e6f67a691e3a64f145828ae74287..0c8c0e8e64450ea6f8db711cb0cd6c10356f39ae 100644 (file)
@@ -63,6 +63,9 @@ void ARMATURE_OT_flip_names(struct wmOperatorType *ot);
 
 void ARMATURE_OT_flags_set(struct wmOperatorType *ot);
 
 
 void ARMATURE_OT_flags_set(struct wmOperatorType *ot);
 
+void ARMATURE_OT_armature_layers(struct wmOperatorType *ot);
+void ARMATURE_OT_bone_layers(struct wmOperatorType *ot);
+
 /* ******************************************************* */
 /* Pose-Mode Operators */
 void POSE_OT_hide(struct wmOperatorType *ot);
 /* ******************************************************* */
 /* Pose-Mode Operators */
 void POSE_OT_hide(struct wmOperatorType *ot);
@@ -99,6 +102,9 @@ void POSE_OT_flip_names(struct wmOperatorType *ot);
 
 void POSE_OT_flags_set(struct wmOperatorType *ot);
 
 
 void POSE_OT_flags_set(struct wmOperatorType *ot);
 
+void POSE_OT_armature_layers(struct wmOperatorType *ot);
+void POSE_OT_bone_layers(struct wmOperatorType *ot);
+
 /* ******************************************************* */
 /* Etch-A-Ton */
 
 /* ******************************************************* */
 /* Etch-A-Ton */
 
index bfe3befe1b34bd93c63ac8766ef0bfc5512f3f3a..389a0a5174a371a3fdc28a149c8e386846a0a1bf 100644 (file)
@@ -55,6 +55,7 @@
 #include "ED_armature.h"
 #include "ED_screen.h"
 #include "ED_object.h"
 #include "ED_armature.h"
 #include "ED_screen.h"
 #include "ED_object.h"
+#include "ED_transform.h"
 
 #include "armature_intern.h"
 
 
 #include "armature_intern.h"
 
@@ -137,6 +138,9 @@ void ED_operatortypes_armature(void)
        WM_operatortype_append(ARMATURE_OT_flip_names);
        
        WM_operatortype_append(ARMATURE_OT_flags_set);
        WM_operatortype_append(ARMATURE_OT_flip_names);
        
        WM_operatortype_append(ARMATURE_OT_flags_set);
+       
+       WM_operatortype_append(ARMATURE_OT_armature_layers);
+       WM_operatortype_append(ARMATURE_OT_bone_layers);
 
        /* SKETCH */    
        WM_operatortype_append(SKETCH_OT_gesture);
 
        /* SKETCH */    
        WM_operatortype_append(SKETCH_OT_gesture);
@@ -182,6 +186,9 @@ void ED_operatortypes_armature(void)
        
        WM_operatortype_append(POSE_OT_flags_set);
        
        
        WM_operatortype_append(POSE_OT_flags_set);
        
+       WM_operatortype_append(POSE_OT_armature_layers);
+       WM_operatortype_append(POSE_OT_bone_layers);
+       
        /* POSELIB */
        WM_operatortype_append(POSELIB_OT_browse_interactive);
        
        /* POSELIB */
        WM_operatortype_append(POSELIB_OT_browse_interactive);
        
@@ -243,7 +250,7 @@ void ED_keymap_armature(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "ARMATURE_OT_fill", FKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "ARMATURE_OT_merge", MKEY, KM_PRESS, KM_ALT, 0);
        
        WM_keymap_add_item(keymap, "ARMATURE_OT_fill", FKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "ARMATURE_OT_merge", MKEY, KM_PRESS, KM_ALT, 0);
        
-       WM_keymap_add_item(keymap, "ARMATURE_OT_separate", PKEY, KM_PRESS, /*KM_CTRL|KM_ALT*/0, 0);
+       WM_keymap_add_item(keymap, "ARMATURE_OT_separate", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
        
                /* set flags */
        kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
        
                /* set flags */
        kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
@@ -252,6 +259,18 @@ void ED_keymap_armature(wmWindowManager *wm)
                RNA_enum_set(kmi->ptr, "mode", 1); // enable
        kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
                RNA_enum_set(kmi->ptr, "mode", 0); // clear
                RNA_enum_set(kmi->ptr, "mode", 1); // enable
        kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
                RNA_enum_set(kmi->ptr, "mode", 0); // clear
+               
+               /* armature/bone layers */
+       WM_keymap_add_item(keymap, "ARMATURE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "ARMATURE_OT_bone_layers", MKEY, KM_PRESS, 0, 0);
+       
+               /* special transforms: */
+               /*      1) envelope/b-bone size */
+       kmi= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0);
+               RNA_enum_set(kmi->ptr, "mode", TFM_BONESIZE);
+               /*      2) set roll */
+       kmi= WM_keymap_add_item(keymap, "TFM_OT_transform", RKEY, KM_PRESS, KM_CTRL, 0);
+               RNA_enum_set(kmi->ptr, "mode", TFM_BONE_ROLL);
        
        /* Armature -> Etch-A-Ton ------------------------ */
        WM_keymap_add_item(keymap, "SKETCH_OT_delete", XKEY, KM_PRESS, 0, 0);
        
        /* Armature -> Etch-A-Ton ------------------------ */
        WM_keymap_add_item(keymap, "SKETCH_OT_delete", XKEY, KM_PRESS, 0, 0);
@@ -270,7 +289,7 @@ void ED_keymap_armature(wmWindowManager *wm)
        
        WM_keymap_add_item(keymap, "POSE_OT_apply", AKEY, KM_PRESS, KM_CTRL, 0);
        
        
        WM_keymap_add_item(keymap, "POSE_OT_apply", AKEY, KM_PRESS, KM_CTRL, 0);
        
-       /*clear pose*/
+       // TODO: clear pose
        WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "POSE_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0);
        WM_keymap_add_item(keymap, "POSE_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
@@ -307,13 +326,22 @@ void ED_keymap_armature(wmWindowManager *wm)
        
        WM_keymap_add_item(keymap, "POSE_OT_groups_menu", GKEY, KM_PRESS, KM_CTRL, 0);
        
        
        WM_keymap_add_item(keymap, "POSE_OT_groups_menu", GKEY, KM_PRESS, KM_CTRL, 0);
        
-       /* set flags */
+               /* set flags */
        kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
                RNA_enum_set(kmi->ptr, "mode", 2); // toggle
        kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
                RNA_enum_set(kmi->ptr, "mode", 1); // enable
        kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
                RNA_enum_set(kmi->ptr, "mode", 0); // clear
        kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
                RNA_enum_set(kmi->ptr, "mode", 2); // toggle
        kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
                RNA_enum_set(kmi->ptr, "mode", 1); // enable
        kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
                RNA_enum_set(kmi->ptr, "mode", 0); // clear
+               
+               /* armature/bone layers */
+       WM_keymap_add_item(keymap, "POSE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
+       WM_keymap_add_item(keymap, "POSE_OT_bone_layers", MKEY, KM_PRESS, 0, 0);
+       
+               /* special transforms: */
+               /*      1) envelope/b-bone size */
+       kmi= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, KM_ALT, 0);
+               RNA_enum_set(kmi->ptr, "mode", TFM_BONESIZE);
        
        // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
        WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe_menu", IKEY, KM_PRESS, 0, 0);
        
        // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
        WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe_menu", IKEY, KM_PRESS, 0, 0);
index f20c38a02468acf76b35db0f36a359b2041b4b41..95d4e2634908935cf523db5b9b282391e474b821 100644 (file)
@@ -99,9 +99,7 @@
 
 /* ************* XXX *************** */
 static int okee() {return 0;}
 
 /* ************* XXX *************** */
 static int okee() {return 0;}
-static int pupmenu() {return 0;}
 static void BIF_undo_push() {}
 static void BIF_undo_push() {}
-static void adduplicate() {}
 /* ************* XXX *************** */
 
 /* **************** tools on Editmode Armature **************** */
 /* ************* XXX *************** */
 
 /* **************** tools on Editmode Armature **************** */
@@ -1043,9 +1041,7 @@ static int separate_armature_exec (bContext *C, wmOperator *op)
        ED_armature_edit_free(obedit);
        
        /* 2) duplicate base */
        ED_armature_edit_free(obedit);
        
        /* 2) duplicate base */
-       adduplicate(1, USER_DUP_ARM); /* no transform and zero so do get a linked dupli */
-       
-       newbase= BASACT; /* basact is set in adduplicate() */
+       newbase= ED_object_add_duplicate(scene, oldbase, USER_DUP_ARM); /* only duplicate linked armature */
        newob= newbase->object;         
        newbase->flag &= ~SELECT;
        
        newob= newbase->object;         
        newbase->flag &= ~SELECT;
        
@@ -1064,8 +1060,6 @@ static int separate_armature_exec (bContext *C, wmOperator *op)
        
        /* 5) restore original conditions */
        obedit= oldob;
        
        /* 5) restore original conditions */
        obedit= oldob;
-       BASACT= oldbase;
-       BASACT->flag |= SELECT;
        
        ED_armature_to_edit(obedit);
        
        
        ED_armature_to_edit(obedit);
        
@@ -1274,7 +1268,6 @@ static int pose_setflag_exec (bContext *C, wmOperator *op)
 /* callback for editbones setflag */
 static int armature_bones_setflag_exec (bContext *C, wmOperator *op)
 {
 /* callback for editbones setflag */
 static int armature_bones_setflag_exec (bContext *C, wmOperator *op)
 {
-       Object *ob= CTX_data_active_object(C);
        int flag= RNA_enum_get(op->ptr, "type");
        int mode= RNA_enum_get(op->ptr, "mode");
        
        int flag= RNA_enum_get(op->ptr, "type");
        int mode= RNA_enum_get(op->ptr, "mode");
        
index e9ebdb87a3cd04b02b470359fee285e18032b877..174bb39d7b93c0dc049e7cc31e459964e0c520df 100644 (file)
@@ -89,7 +89,6 @@
 #include "armature_intern.h"
 
 /* ************* XXX *************** */
 #include "armature_intern.h"
 
 /* ************* XXX *************** */
-static int movetolayer_short_buts() {return 1;}
 static int pupmenu() {return 0;}
 static void error() {};
 static void BIF_undo_push() {}
 static int pupmenu() {return 0;}
 static void error() {};
 static void BIF_undo_push() {}
@@ -1683,90 +1682,270 @@ void pose_activate_flipped_bone(Scene *scene)
        }
 }
 
        }
 }
 
-/* This function pops up the move-to-layer popup widgets when the user
- * presses either SHIFT-MKEY or MKEY in PoseMode OR EditMode (for Armatures)
- */
-void pose_movetolayer(Scene *scene)
+
+/* ********************************************** */
+
+/* Present a popup to get the layers that should be used */
+// TODO: move to wm?
+static uiBlock *wm_layers_select_create_menu(bContext *C, ARegion *ar, void *arg_op)
 {
 {
-       Object *obedit= scene->obedit; // XXX context
-       Object *ob= OBACT;
-       bArmature *arm;
-       short lay= 0;
-       short shift= 0; // XXX
+       wmOperator *op= arg_op;
+       uiBlock *block;
+       uiLayout *layout;
+       uiStyle *style= U.uistyles.first;
        
        
-       if (ob==NULL) return;
-       arm= ob->data;
+       block= uiBeginBlock(C, ar, "_popup", UI_EMBOSS);
+       uiBlockClearFlag(block, UI_BLOCK_LOOP);
+       uiBlockSetFlag(block, UI_BLOCK_KEEP_OPEN);
        
        
-       if (shift) {
-               /* armature layers */
-               lay= arm->layer;
-               if ( movetolayer_short_buts(&lay, "Armature Layers")==0 ) return;
-               if (lay==0) return;
-               arm->layer= lay;
-               if(ob->pose)
-                       ob->pose->proxy_layer= lay;
+       layout= uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, 150, 20, style);
+               uiItemL(layout, op->type->name, 0);
+               uiTemplateLayers(layout, op->ptr, "layers"); /* must have a property named layers setup */
                
                
-       }
-       else if (obedit) {
-               /* the check for editbone layer moving needs to occur before posemode one to work */
-               EditBone *ebo;
-               EditBone *flipBone;
-               
-               for (ebo= arm->edbo->first; ebo; ebo= ebo->next) {
-                       if (arm->layer & ebo->layer) {
-                               if (ebo->flag & BONE_SELECTED)
-                                       lay |= ebo->layer;
-                       }
-               }
-               if (lay==0) return;
+       uiPopupBoundsBlock(block, 4.0f, 0, 0);
+       uiEndBlock(C, block);
+       
+       return block;
+}
+
+/* ------------------- */
+
+/* Present a popup to get the layers that should be used */
+static int pose_armature_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt)
+{
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm= (ob)? ob->data : NULL;
+       PointerRNA ptr;
+       int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */
+       
+       /* sanity checking */
+       if (arm == NULL)
+               return OPERATOR_CANCELLED;
                
                
-               if ( movetolayer_short_buts(&lay, "Bone Layers")==0 ) return;
-               if (lay==0) return;
+       /* get RNA pointer to armature data to use that to retrieve the layers as ints to init the operator */
+       RNA_id_pointer_create((ID *)arm, &ptr);
+       RNA_boolean_get_array(&ptr, "layer", layers);
+       RNA_boolean_set_array(op->ptr, "layers", layers);
+       
+               /* part to sync with other similar operators... */
+       /* pass on operator, so return modal */
+       uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT);
+       return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH;
+}
+
+/* Set the visible layers for the active armature (edit and pose modes) */
+static int pose_armature_layers_exec (bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm= (ob)? ob->data : NULL;
+       PointerRNA ptr;
+       int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */
+       
+       /* get the values set in the operator properties */
+       RNA_boolean_get_array(op->ptr, "layers", layers);
+       
+       /* get pointer for armature, and write data there... */
+       RNA_id_pointer_create((ID *)arm, &ptr);
+       RNA_boolean_set_array(&ptr, "layer", layers);
+       
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
+       
+       return OPERATOR_FINISHED;
+}
+
+
+void POSE_OT_armature_layers (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Change Armature Layers";
+       ot->idname= "POSE_OT_armature_layers";
+       ot->description= "Change the visible armature layers.";
+       
+       /* callbacks */
+       ot->invoke= pose_armature_layers_invoke;
+       ot->exec= pose_armature_layers_exec;
+       ot->poll= ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers to make visible.");
+}
+
+void ARMATURE_OT_armature_layers (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Change Armature Layers";
+       ot->idname= "ARMATURE_OT_armature_layers";
+       ot->description= "Change the visible armature layers.";
+       
+       /* callbacks */
+       ot->invoke= pose_armature_layers_invoke;
+       ot->exec= pose_armature_layers_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers to make visible.");
+}
+
+/* ------------------- */
+
+/* Present a popup to get the layers that should be used */
+static int pose_bone_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt)
+{
+       int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */
+       
+       /* get layers that are active already */
+       memset(&layers, 0, sizeof(layers)); /* set all layers to be off by default */
+       
+       CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pchans) 
+       {
+               short bit;
                
                
-               for (ebo= arm->edbo->first; ebo; ebo= ebo->next) {
-                       if (arm->layer & ebo->layer) {
-                               if (ebo->flag & BONE_SELECTED) {
-                                       ebo->layer= lay;
-                                       if (arm->flag & ARM_MIRROR_EDIT) {
-                                               flipBone = ED_armature_bone_get_mirrored(arm->edbo, ebo);
-                                               if (flipBone)
-                                                       flipBone->layer = lay;
-                                       }
-                               }
-                       }
+               /* loop over the bits for this pchan's layers, adding layers where they're needed */
+               for (bit= 0; bit < 16; bit++) {
+                       if (pchan->bone->layer & (1<<bit))
+                               layers[bit]= 1;
                }
                }
-               
-               BIF_undo_push("Move Bone Layer");
        }
        }
-       else if (ob->flag & OB_POSEMODE) {
-               /* pose-channel layers */
-               bPoseChannel *pchan;
-               
-               if (pose_has_protected_selected(ob, 0, 1))
-                       return;
-               
-               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                       if (arm->layer & pchan->bone->layer) {
-                               if (pchan->bone->flag & BONE_SELECTED)
-                                       lay |= pchan->bone->layer;
-                       }
-               }
-               if (lay==0) return;
-               
-               if ( movetolayer_short_buts(&lay, "Bone Layers")==0 ) return;
-               if (lay==0) return;
+       CTX_DATA_END;
+       
+       /* copy layers to operator */
+       RNA_boolean_set_array(op->ptr, "layers", layers);
+       
+               /* part to sync with other similar operators... */
+       /* pass on operator, so return modal */
+       uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT);
+       return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH;
+}
+
+/* Set the visible layers for the active armature (edit and pose modes) */
+static int pose_bone_layers_exec (bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm= (ob)? ob->data : NULL;
+       PointerRNA ptr;
+       int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */
+       
+       /* get the values set in the operator properties */
+       RNA_boolean_get_array(op->ptr, "layers", layers);
+       
+       /* set layers of pchans based on the values set in the operator props */
+       CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pchans) 
+       {
+               /* get pointer for pchan, and write flags this way */
+               RNA_pointer_create((ID *)arm, &RNA_Bone, pchan->bone, &ptr);
+               RNA_boolean_set_array(&ptr, "layer", layers);
+       }
+       CTX_DATA_END;
+       
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
+       
+       return OPERATOR_FINISHED;
+}
+
+void POSE_OT_bone_layers (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Change Bone Layers";
+       ot->idname= "POSE_OT_bone_layers";
+       ot->description= "Change the layers that the selected bones belong to.";
+       
+       /* callbacks */
+       ot->invoke= pose_bone_layers_invoke;
+       ot->exec= pose_bone_layers_exec;
+       ot->poll= ED_operator_posemode;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers that bone belongs to.");
+}
+
+/* ------------------- */
+
+/* Present a popup to get the layers that should be used */
+static int armature_bone_layers_invoke (bContext *C, wmOperator *op, wmEvent *evt)
+{
+       int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */
+       
+       /* get layers that are active already */
+       memset(&layers, 0, sizeof(layers)); /* set all layers to be off by default */
+       
+       CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) 
+       {
+               short bit;
                
                
-               for (pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
-                       if (arm->layer & pchan->bone->layer) {
-                               if (pchan->bone->flag & BONE_SELECTED)
-                                       pchan->bone->layer= lay;
-                       }
+               /* loop over the bits for this pchan's layers, adding layers where they're needed */
+               for (bit= 0; bit < 16; bit++) {
+                       if (ebone->layer & (1<<bit))
+                               layers[bit]= 1;
                }
                }
-               
-               BIF_undo_push("Move Bone Layer");
        }
        }
+       CTX_DATA_END;
+       
+       /* copy layers to operator */
+       RNA_boolean_set_array(op->ptr, "layers", layers);
+       
+               /* part to sync with other similar operators... */
+       /* pass on operator, so return modal */
+       uiPupBlockOperator(C, wm_layers_select_create_menu, op, WM_OP_EXEC_DEFAULT);
+       return OPERATOR_RUNNING_MODAL|OPERATOR_PASS_THROUGH;
+}
+
+/* Set the visible layers for the active armature (edit and pose modes) */
+static int armature_bone_layers_exec (bContext *C, wmOperator *op)
+{
+       Object *ob= CTX_data_active_object(C);
+       bArmature *arm= (ob)? ob->data : NULL;
+       PointerRNA ptr;
+       int layers[16]; /* hardcoded for now - we can only have 16 armature layers, so this should be fine... */
+       
+       /* get the values set in the operator properties */
+       RNA_boolean_get_array(op->ptr, "layers", layers);
+       
+       /* set layers of pchans based on the values set in the operator props */
+       CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones) 
+       {
+               /* get pointer for pchan, and write flags this way */
+               RNA_pointer_create((ID *)arm, &RNA_EditBone, ebone, &ptr);
+               RNA_boolean_set_array(&ptr, "layers", layers);
+       }
+       CTX_DATA_END;
+       
+       /* note, notifier might evolve */
+       WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob);
+       
+       return OPERATOR_FINISHED;
+}
+
+void ARMATURE_OT_bone_layers (wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Change Bone Layers";
+       ot->idname= "ARMATURE_OT_bone_layers";
+       ot->description= "Change the layers that the selected bones belong to.";
+       
+       /* callbacks */
+       ot->invoke= armature_bone_layers_invoke;
+       ot->exec= armature_bone_layers_exec;
+       ot->poll= ED_operator_editarmature;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+       RNA_def_boolean_array(ot->srna, "layers", 16, NULL, "Layers", "Armature layers that bone belongs to.");
 }
 
 }
 
+
 #if 0
 // XXX old sys
 /* for use with pose_relax only */
 #if 0
 // XXX old sys
 /* for use with pose_relax only */
index 8d4819d2d71015385cbe0137811dc899939f4679..c8a72a2aa97dc372b22475073d3f56b333b16cfa 100644 (file)
@@ -54,8 +54,8 @@ void ED_base_object_activate(struct bContext *C, struct Base *base);
 void ED_base_object_free_and_unlink(struct Scene *scene, struct Base *base);
 
 void ED_object_apply_obmat(struct Object *ob);
 void ED_base_object_free_and_unlink(struct Scene *scene, struct Base *base);
 
 void ED_object_apply_obmat(struct Object *ob);
-       /* single object duplicate, if dupflag==0, fully linked, else it uses U.dupflag */
-struct Base *ED_object_add_duplicate(struct Scene *scene, struct Base *base, int usedupflag);
+       /* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */
+struct Base *ED_object_add_duplicate(struct Scene *scene, struct Base *base, int dupflag);
 
 void ED_object_parent(struct Object *ob, struct Object *parent, int type, const char *substr);
 
 
 void ED_object_parent(struct Object *ob, struct Object *parent, int type, const char *substr);
 
index 1752f48990d61b22031868578d0d608501b738ba..1ee3f1b2f538277f364d1b0d305379dc349afc9e 100644 (file)
@@ -6301,12 +6301,11 @@ static Base *object_add_duplicate_internal(Scene *scene, Base *base, int dupflag
        return basen;
 }
 
        return basen;
 }
 
-/* single object duplicate, if dupflag==0, fully linked, else it uses U.dupflag */
+/* single object duplicate, if dupflag==0, fully linked, else it uses the flags given */
 /* leaves selection of base/object unaltered */
 /* leaves selection of base/object unaltered */
-Base *ED_object_add_duplicate(Scene *scene, Base *base, int usedupflag)
+Base *ED_object_add_duplicate(Scene *scene, Base *base, int dupflag)
 {
        Base *basen;
 {
        Base *basen;
-       int dupflag= usedupflag?U.dupflag:0;
 
        clear_id_newpoins();
        clear_sca_new_poins();  /* sensor/contr/act */
 
        clear_id_newpoins();
        clear_sca_new_poins();  /* sensor/contr/act */
index 529db1cbb06aa8b7d0ff10e0684868141c9183b7..25cf4fe6862682f88ca20858d2a7703bfba4154c 100644 (file)
@@ -2745,15 +2745,6 @@ static void view3d_edit_armature_parentmenu(bContext *C, uiLayout *layout, void
        uiItemO(layout, NULL, 0, "ARMATURE_OT_parent_clear");
 }
 
        uiItemO(layout, NULL, 0, "ARMATURE_OT_parent_clear");
 }
 
-#if 0
-void do_view3d_edit_armature_rollmenu(bContext *C, void *arg, int event)
-{
-               /* "Set Roll|Ctrl R" - interactively set bone roll */
-               initTransform(TFM_BONE_ROLL, CTX_NONE);
-               Transform();
-}
-#endif
-
 static void view3d_edit_armature_rollmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
        /* 0 = 'Global', 1 = 'Cursor' */
 static void view3d_edit_armature_rollmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
        /* 0 = 'Global', 1 = 'Cursor' */
@@ -2761,14 +2752,13 @@ static void view3d_edit_armature_rollmenu(bContext *C, uiLayout *layout, void *a
        uiItemEnumO(layout, "Clear Roll (Z-Axis Up)", 0, "ARMATURE_OT_calculate_roll", "type", 0);
        uiItemEnumO(layout, "Roll to Cursor", 0, "ARMATURE_OT_calculate_roll", "type", 1);
        
        uiItemEnumO(layout, "Clear Roll (Z-Axis Up)", 0, "ARMATURE_OT_calculate_roll", "type", 0);
        uiItemEnumO(layout, "Roll to Cursor", 0, "ARMATURE_OT_calculate_roll", "type", 1);
        
-       //uiDefBut(block, SEPR, 0, "",                          0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-       //uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Set Roll|Ctrl R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 3, "");
+       uiItemS(layout);
+       
+       uiItemEnumO(layout, "Set Roll", 0, "TFM_OT_transform", "mode", TFM_BONE_ROLL);
 }
 
 static void view3d_edit_armature_settingsmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
 }
 
 static void view3d_edit_armature_settingsmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
-       PointerRNA ptr;
-       
        uiItemEnumO(layout, "Toggle a Setting", 0, "ARMATURE_OT_flags_set", "mode", 2);
        uiItemEnumO(layout, "Enable a Setting", 0, "ARMATURE_OT_flags_set", "mode", 1);
        uiItemEnumO(layout, "Disable a Setting", 0, "ARMATURE_OT_flags_set", "mode", 0);
        uiItemEnumO(layout, "Toggle a Setting", 0, "ARMATURE_OT_flags_set", "mode", 2);
        uiItemEnumO(layout, "Enable a Setting", 0, "ARMATURE_OT_flags_set", "mode", 1);
        uiItemEnumO(layout, "Disable a Setting", 0, "ARMATURE_OT_flags_set", "mode", 0);
@@ -2791,11 +2781,6 @@ static void do_view3d_edit_armaturemenu(bContext *C, void *arg, int event)
        case 7: /* Warp */
                initTransform(TFM_WARP, CTX_NONE);
                Transform();
        case 7: /* Warp */
                initTransform(TFM_WARP, CTX_NONE);
                Transform();
-       
-       case 17: /* move to layer */
-               pose_movetolayer();
-               break;
-       
        case 23: /* bone sketching panel */
                add_blockhandler(curarea, VIEW3D_HANDLER_BONESKETCH, UI_PNL_UNSTOW);
                break;
        case 23: /* bone sketching panel */
                add_blockhandler(curarea, VIEW3D_HANDLER_BONESKETCH, UI_PNL_UNSTOW);
                break;
@@ -2847,12 +2832,10 @@ static void view3d_edit_armaturemenu(bContext *C, uiLayout *layout, void *arg_un
        
        uiItemS(layout);
        
        
        uiItemS(layout);
        
-#if 0
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Switch Armature Layers|Shift M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 17, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Move Bone To Layer|M",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 17, "");
-               
-       uiDefBut(block, SEPR, 0, "",                            0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-#endif
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_armature_layers");
+       uiItemO(layout, NULL, 0, "ARMATURE_OT_bone_layers");
+       
+       uiItemS(layout);
        
        uiItemMenuF(layout, "Parent", 0, view3d_edit_armature_parentmenu);
        
        
        uiItemMenuF(layout, "Parent", 0, view3d_edit_armature_parentmenu);
        
@@ -2927,8 +2910,6 @@ static void view3d_pose_armature_poselibmenu(bContext *C, uiLayout *layout, void
 
 static void view3d_pose_armature_settingsmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
 
 static void view3d_pose_armature_settingsmenu(bContext *C, uiLayout *layout, void *arg_unused)
 {
-       PointerRNA ptr;
-       
        uiItemEnumO(layout, "Toggle a Setting", 0, "POSE_OT_flags_set", "mode", 2);
        uiItemEnumO(layout, "Enable a Setting", 0, "POSE_OT_flags_set", "mode", 1);
        uiItemEnumO(layout, "Disable a Setting", 0, "POSE_OT_flags_set", "mode", 0);
        uiItemEnumO(layout, "Toggle a Setting", 0, "POSE_OT_flags_set", "mode", 2);
        uiItemEnumO(layout, "Enable a Setting", 0, "POSE_OT_flags_set", "mode", 1);
        uiItemEnumO(layout, "Disable a Setting", 0, "POSE_OT_flags_set", "mode", 0);
@@ -2944,9 +2925,6 @@ static void do_view3d_pose_armaturemenu(bContext *C, void *arg, int event)
        case 5:
                pose_copy_menu();
                break;
        case 5:
                pose_copy_menu();
                break;
-       case 14: /* move bone to layer / change armature layer */
-               pose_movetolayer();
-               break;
        case 15:
                pose_relax();
                break;
        case 15:
                pose_relax();
                break;
@@ -3004,23 +2982,18 @@ static void view3d_pose_armaturemenu(bContext *C, uiLayout *layout, void *arg_un
        
        uiItemO(layout, "Flip Left/Right Names", 0, "POSE_OT_flip_names");
        
        
        uiItemO(layout, "Flip Left/Right Names", 0, "POSE_OT_flip_names");
        
-       //separator + move layer operators...
-       
        uiItemS(layout);
        
        uiItemS(layout);
        
-       uiItemMenuF(layout, "Show/Hide Bones", 0, view3d_pose_armature_showhidemenu);
+       uiItemO(layout, NULL, 0, "POSE_OT_armature_layers");
+       uiItemO(layout, NULL, 0, "POSE_OT_bone_layers");
        
        uiItemS(layout);
        
        
        uiItemS(layout);
        
+       uiItemMenuF(layout, "Show/Hide Bones", 0, view3d_pose_armature_showhidemenu);
        uiItemMenuF(layout, "Bone Settings", 0, view3d_pose_armature_settingsmenu);
        
 #if 0
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Copy Attributes...|Ctrl C",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
        uiItemMenuF(layout, "Bone Settings", 0, view3d_pose_armature_settingsmenu);
        
 #if 0
        uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Copy Attributes...|Ctrl C",                      0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 5, "");
-
-       uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
-       
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Switch Armature Layers|Shift M", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 14, "");
-       uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Move Bone To Layer|M",   0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 14, "");
 #endif
 }
 
 #endif
 }