Ouliner: Added recursive setting of (visibility/selectability) for bones (Edit- and...
authorGaia Clary <gaia.clary@machinimatrix.org>
Tue, 12 Mar 2013 13:03:58 +0000 (13:03 +0000)
committerGaia Clary <gaia.clary@machinimatrix.org>
Tue, 12 Mar 2013 13:03:58 +0000 (13:03 +0000)
source/blender/editors/space_outliner/outliner_draw.c
source/blender/editors/space_outliner/outliner_select.c

index 0d6f316..e2b2cda 100644 (file)
@@ -132,6 +132,45 @@ static void outliner_rna_width(SpaceOops *soops, ListBase *lb, int *w, int start
 
 /* ****************************************************** */
 
+static void restrictbutton_recursive_ebone(bContext *C, EditBone *ebone_parent, int flag, bool set_flag)
+{
+       Object *obedit = CTX_data_edit_object(C);
+       bArmature *arm = obedit->data;
+       EditBone *ebone;
+       
+       for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+               if (ED_armature_ebone_is_child_recursive(ebone_parent, ebone)) {
+                       if (set_flag) {
+                               ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
+                               ebone->flag |= flag;
+                       }
+                       else {
+                               if (arm->layer & ebone->layer) {
+                                       ebone->flag &= ~flag;
+                               }
+                       }
+               }
+       }
+}
+
+static void restrictbutton_recursive_bone(bContext *C, bArmature *arm, Bone *bone_parent, int flag, bool set_flag)
+{
+       Bone *bone;
+       for (bone = bone_parent->childbase.first; bone; bone = bone->next) {
+               if (set_flag) {
+                       bone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
+                       bone->flag |= flag;
+               }
+               else {
+                       if (arm->layer & bone->layer) {
+                               bone->flag &= ~flag;
+                       }
+               }
+               restrictbutton_recursive_bone(C, arm, bone, flag, set_flag);
+       }
+
+}
+
 static void restrictbutton_recursive_child(bContext *C, Scene *scene, Object *ob_parent, char flag,
                                            bool state, bool deselect)
 {
@@ -224,19 +263,59 @@ static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *po
        WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
 }
 
-static void restrictbutton_bone_cb(bContext *C, void *UNUSED(poin), void *poin2)
+static void restrictbutton_bone_visibility_cb(bContext *C, void *poin, void *poin2)
 {
+       bArmature *arm = (bArmature *)poin;
        Bone *bone = (Bone *)poin2;
        if (bone && (bone->flag & BONE_HIDDEN_P))
                bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+
+       if (CTX_wm_window(C)->eventstate->ctrl) {
+               restrictbutton_recursive_bone(C, arm, bone, BONE_HIDDEN_P, (bone->flag & BONE_HIDDEN_P) != 0);
+       }
+
+       WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
+}
+
+static void restrictbutton_bone_select_cb(bContext *C, void *poin, void *poin2)
+{
+       bArmature *arm = (bArmature *)poin;
+       Bone *bone = (Bone *)poin2;
+       if (bone && (bone->flag & BONE_UNSELECTABLE))
+               bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+
+       if (CTX_wm_window(C)->eventstate->ctrl) {
+               restrictbutton_recursive_bone(C, arm, bone, BONE_UNSELECTABLE, (bone->flag & BONE_UNSELECTABLE) != 0);
+       }
+
        WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
 }
 
-static void restrictbutton_ebone_cb(bContext *C, void *UNUSED(poin), void *poin2)
+static void restrictbutton_ebone_select_cb(bContext *C, void *poin, void *poin2)
 {
        EditBone *ebone = (EditBone *)poin2;
-       if (ebone && (ebone->flag & BONE_HIDDEN_A))
+
+       if (ebone->flag & BONE_UNSELECTABLE) {
                ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+       }
+
+       if (CTX_wm_window(C)->eventstate->ctrl) {
+               restrictbutton_recursive_ebone(C, ebone, BONE_UNSELECTABLE, (ebone->flag & BONE_UNSELECTABLE) != 0);
+       }
+
+       WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
+}
+
+static void restrictbutton_ebone_visibility_cb(bContext *C, void *poin, void *poin2)
+{
+       EditBone *ebone = (EditBone *)poin2;
+       if (ebone->flag & BONE_HIDDEN_A) {
+                       ebone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+       }
+
+       if (CTX_wm_window(C)->eventstate->ctrl) {
+               restrictbutton_recursive_ebone(C, ebone, BONE_HIDDEN_A, (ebone->flag & BONE_HIDDEN_A) != 0);
+       }
 
        WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
 }
@@ -564,19 +643,20 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                        else if (tselem->type == TSE_POSE_CHANNEL) {
                                bPoseChannel *pchan = (bPoseChannel *)te->directdata;
                                Bone *bone = pchan->bone;
+                               ob = (Object *)tselem->id;
                                
                                uiBlockSetEmboss(block, UI_EMBOSSN);
                                bt = uiDefIconButBitI(block, ICONTOG, BONE_HIDDEN_P, 0, ICON_RESTRICT_VIEW_OFF,
                                                      (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow visibility in the 3D View"));
-                               uiButSetFunc(bt, restrictbutton_bone_cb, NULL, bone);
+                               uiButSetFunc(bt, restrictbutton_bone_visibility_cb, ob->data, bone);
                                
                                bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
                                                      (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(bone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow selection in the 3D View"));
-                               uiButSetFunc(bt, restrictbutton_bone_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_bone_select_cb, ob->data, bone);
                        }
                        else if (tselem->type == TSE_EBONE) {
                                EditBone *ebone = (EditBone *)te->directdata;
@@ -586,13 +666,13 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
                                                      (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow visibility in the 3D View"));
-                               uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, ebone);
+                               uiButSetFunc(bt, restrictbutton_ebone_visibility_cb, NULL, ebone);
                                
                                bt = uiDefIconButBitI(block, ICONTOG, BONE_UNSELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
                                                      (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)te->ys, UI_UNIT_X,
                                                      UI_UNIT_Y, &(ebone->flag), 0, 0, 0, 0,
                                                      TIP_("Restrict/Allow selection in the 3D View"));
-                               uiButSetFunc(bt, restrictbutton_ebone_cb, NULL, NULL);
+                               uiButSetFunc(bt, restrictbutton_ebone_select_cb, NULL, ebone);
                        }
                }
                
index 555b43a..46ecfee 100644 (file)
@@ -164,10 +164,10 @@ static void do_outliner_bone_select_recursive(bArmature *arm, Bone *bone_parent,
 {
        Bone *bone;
        for (bone = bone_parent->childbase.first; bone; bone = bone->next) {
-               if (select && PBONE_VISIBLE(arm, bone))
+               if (select && PBONE_SELECTABLE(arm, bone))
                        bone->flag |= BONE_SELECTED;
                else
-                       bone->flag &= ~BONE_SELECTED;
+                       bone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
                do_outliner_bone_select_recursive(arm, bone, select);
        }
 }
@@ -177,10 +177,10 @@ static void do_outliner_ebone_select_recursive(bArmature *arm, EditBone *ebone_p
        EditBone *ebone;
        for (ebone = ebone_parent->next; ebone; ebone = ebone->next) {
                if (ED_armature_ebone_is_child_recursive(ebone_parent, ebone)) {
-                       if (select && EBONE_VISIBLE(arm, ebone))
-                               ebone->flag |= BONE_SELECTED;
+                       if (select && EBONE_SELECTABLE(arm, ebone))
+                               ebone->flag |= BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL;
                        else
-                               ebone->flag &= ~BONE_SELECTED;
+                               ebone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
                }
        }
 }
@@ -226,7 +226,7 @@ static int  tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops
                }
 
                if (recursive) {
-                       /* Recursive select/deselect */
+                       /* Recursive select/deselect for Object hierarchies */
                        do_outliner_object_select_recursive(scene, ob, (ob->flag & SELECT) != 0);
                }
 
@@ -451,7 +451,7 @@ static int tree_element_active_posegroup(bContext *C, Scene *scene, TreeElement
        return 0;
 }
 
-static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set)
+static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, int set, bool recursive)
 {
        Object *ob = (Object *)tselem->id;
        bArmature *arm = ob->data;
@@ -470,7 +470,12 @@ static int tree_element_active_posechannel(bContext *C, Scene *scene, TreeElemen
                                pchan->bone->flag |= BONE_SELECTED;
                                arm->act_bone = pchan->bone;
                        }
-                       
+
+                       if (recursive) {
+                               /* Recursive select/deselect */
+                               do_outliner_bone_select_recursive(arm, pchan->bone, (pchan->bone->flag & BONE_SELECTED) != 0);
+                       }
+
                        WM_event_add_notifier(C, NC_OBJECT | ND_BONE_ACTIVE, ob);
 
                }
@@ -764,7 +769,7 @@ int tree_element_type_active(bContext *C, Scene *scene, SpaceOops *soops,
                case TSE_POSE_BASE:
                        return tree_element_active_pose(C, scene, te, tselem, set);
                case TSE_POSE_CHANNEL:
-                       return tree_element_active_posechannel(C, scene, te, tselem, set);
+                       return tree_element_active_posechannel(C, scene, te, tselem, set, recursive);
                case TSE_CONSTRAINT:
                        return tree_element_active_constraint(C, te, tselem, set);
                case TSE_R_LAYER:
@@ -817,7 +822,9 @@ static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, Spa
                        
                        /* always makes active object */
                        if (tselem->type != TSE_SEQUENCE && tselem->type != TSE_SEQ_STRIP && tselem->type != TSE_SEQUENCE_DUP)
-                               tree_element_set_active_object(C, scene, soops, te, 1 + (extend != 0 && tselem->type == 0), recursive);
+                               tree_element_set_active_object(C, scene, soops, te,
+                                                                                          1 + (extend != 0 && tselem->type == 0),
+                                                                                          recursive && tselem->type == 0 );
                        
                        if (tselem->type == 0) { // the lib blocks
                                /* editmode? */