Graph Editor: H/Shift-H now hide and unhide selected curves (Gooseberry Request)
authorJoshua Leung <aligorith@gmail.com>
Wed, 19 Nov 2014 13:24:42 +0000 (02:24 +1300)
committerJoshua Leung <aligorith@gmail.com>
Wed, 19 Nov 2014 13:24:42 +0000 (02:24 +1300)
Revised the tools for managing which FCurves are visible in the Graph Editor
curves area. Now, there are the following tools in place:
* V (channels region only) = Hide all curves except those in selected channels  [OLD]

* H       = Hide all selected curves  [NEW]
* Shift-H = Show all previously hidden curves [NEW]

I've removed the old operator to toggle visibility status of selected curves,
as it doesn't seem that useful anymore.

release/scripts/startup/bl_ui/space_graph.py
source/blender/editors/animation/anim_channels_edit.c
source/blender/editors/space_graph/graph_ops.c

index 6fc3d9e4f2b610477987ea5cd666ff3b48b63eec..a8155402a1eda5305c1360de101103d35bb63b72 100644 (file)
@@ -189,6 +189,8 @@ class GRAPH_MT_channel(Menu):
 
         layout.separator()
         layout.operator("anim.channels_editable_toggle")
+        layout.operator("graph.hide")
+        layout.operator("graph.unhide")
         layout.operator("anim.channels_visibility_set")
         layout.operator_menu_enum("graph.extrapolation_type", "type", text="Extrapolation Mode")
 
index b6ab04077114f2c72073d51a39d28b2e3b4f2dc8..33c9aabd23de48766371f8cd0b0964cba57d9c6e 100644 (file)
@@ -1665,7 +1665,7 @@ static int animchannels_visibility_set_exec(bContext *C, wmOperator *UNUSED(op))
 static void ANIM_OT_channels_visibility_set(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name = "Set Visibility";
+       ot->name = "Show Selected Curves Only";
        ot->idname = "ANIM_OT_channels_visibility_set";
        ot->description = "Make only the selected animation channels visible in the Graph Editor";
        
@@ -1677,83 +1677,6 @@ static void ANIM_OT_channels_visibility_set(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
-
-/* ******************** Toggle Channel Visibility Operator *********************** */
-/* NOTE: this operator is only valid in the Graph Editor channels region */
-
-static int animchannels_visibility_toggle_exec(bContext *C, wmOperator *UNUSED(op))
-{
-       bAnimContext ac;
-       ListBase anim_data = {NULL, NULL};
-       ListBase all_data = {NULL, NULL};
-       bAnimListElem *ale;
-       int filter;
-       short vis = ACHANNEL_SETFLAG_ADD;
-       
-       /* get editor data */
-       if (ANIM_animdata_get_context(C, &ac) == 0)
-               return OPERATOR_CANCELLED;
-               
-       /* get list of all channels that selection may need to be flushed to 
-        * - hierarchy mustn't affect what we have access to here...
-        */
-       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS);
-       ANIM_animdata_filter(&ac, &all_data, filter, ac.data, ac.datatype);
-               
-       /* filter data
-        * - restrict this to only applying on settings we can get to in the list
-        */
-       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_NODUPLIS);
-       ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-       
-       /* See if we should be making showing all selected or hiding */
-       for (ale = anim_data.first; ale; ale = ale->next) {
-               /* set the setting in the appropriate way (if available) */
-               if (ANIM_channel_setting_get(&ac, ale, ACHANNEL_SETTING_VISIBLE)) {
-                       vis = ACHANNEL_SETFLAG_CLEAR;
-                       break;
-               }
-       }
-
-       /* Now set the flags */
-       for (ale = anim_data.first; ale; ale = ale->next) {
-               /* hack: skip object channels for now, since flushing those will always flush everything, but they are always included */
-               /* TODO: find out why this is the case, and fix that */
-               if (ale->type == ANIMTYPE_OBJECT)
-                       continue;
-               
-               /* change the setting */
-               ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, vis);
-               
-               /* now, also flush selection status up/down as appropriate */
-               ANIM_flush_setting_anim_channels(&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, (vis == ACHANNEL_SETFLAG_ADD));
-       }
-       
-       /* cleanup */
-       ANIM_animdata_freelist(&anim_data);
-       BLI_freelistN(&all_data);
-       
-       /* send notifier that things have changed */
-       WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
-       
-       return OPERATOR_FINISHED;
-}
-
-static void ANIM_OT_channels_visibility_toggle(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name = "Toggle Visibility";
-       ot->idname = "ANIM_OT_channels_visibility_toggle";
-       ot->description = "Toggle visibility in Graph Editor of all selected animation channels";
-       
-       /* api callbacks */
-       ot->exec = animchannels_visibility_toggle_exec;
-       ot->poll = ED_operator_graphedit_active;
-       
-       /* flags */
-       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
 /* ********************** Set Flags Operator *********************** */
 
 /* defines for setting animation-channel flags */
@@ -3042,7 +2965,6 @@ void ED_operatortypes_animchannels(void)
        WM_operatortype_append(ANIM_OT_channels_expand);
        WM_operatortype_append(ANIM_OT_channels_collapse);
        
-       WM_operatortype_append(ANIM_OT_channels_visibility_toggle);
        WM_operatortype_append(ANIM_OT_channels_visibility_set);
        
        WM_operatortype_append(ANIM_OT_channels_fcurves_enable);
@@ -3113,7 +3035,6 @@ void ED_keymap_animchannels(wmKeyConfig *keyconf)
        
        /* Graph Editor only */
        WM_keymap_add_item(keymap, "ANIM_OT_channels_visibility_set", VKEY, KM_PRESS, 0, 0);
-       WM_keymap_add_item(keymap, "ANIM_OT_channels_visibility_toggle", VKEY, KM_PRESS, KM_SHIFT, 0);
 }
 
 /* ************************************************************************** */
index 62b6b59df29f972201b915e6c8f24b9a4d6f80a3..a4f5750bc7de2c5d0f681c0f77ec73bffbaa62d0 100644 (file)
@@ -34,6 +34,7 @@
 
 #include "DNA_scene_types.h"
 
+#include "BLI_blenlib.h"
 #include "BLI_utildefines.h"
 #include "BLI_math_base.h"
 
@@ -200,6 +201,139 @@ static void GRAPH_OT_cursor_set(wmOperatorType *ot)
        RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Value", "", -100.0f, 100.0f);
 }
 
+/* Hide/UnHide Curves ----------------------------------------------------------------------------- */
+
+static int graphview_curves_hide_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       bAnimContext ac;
+       ListBase anim_data = {NULL, NULL};
+       ListBase all_data = {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+               
+       /* get list of all channels that selection may need to be flushed to 
+        * - hierarchy must not affect what we have access to here...
+        */
+       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS);
+       ANIM_animdata_filter(&ac, &all_data, filter, ac.data, ac.datatype);
+       
+       /* filter data
+        * - of the remaining visible curves, we want to hide the ones that are selected 
+        */
+       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_NODUPLIS);
+       ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+       
+       for (ale = anim_data.first; ale; ale = ale->next) {
+               /* hack: skip object channels for now, since flushing those will always flush everything, but they are always included */
+               /* TODO: find out why this is the case, and fix that */
+               if (ale->type == ANIMTYPE_OBJECT)
+                       continue;
+               
+               /* change the hide setting, and unselect it... */
+               ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR);
+               ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_SELECT,  ACHANNEL_SETFLAG_CLEAR);
+               
+               /* now, also flush selection status up/down as appropriate */
+               ANIM_flush_setting_anim_channels(&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, false);
+       }
+       
+       /* cleanup */
+       ANIM_animdata_freelist(&anim_data);
+       BLI_freelistN(&all_data);
+       
+       /* send notifier that things have changed */
+       WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+
+static void GRAPH_OT_hide(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Hide Curves";
+       ot->idname = "GRAPH_OT_hide";
+       ot->description = "Hide selected curves from Graph Editor view";
+       
+       /* api callbacks */
+       ot->exec = graphview_curves_hide_exec;
+       ot->poll = ED_operator_graphedit_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/* ........ */
+
+static int graphview_curves_unhide_exec(bContext *C, wmOperator *UNUSED(op))
+{
+       bAnimContext ac;
+       ListBase anim_data = {NULL, NULL};
+       ListBase all_data = {NULL, NULL};
+       bAnimListElem *ale;
+       int filter;
+       
+       /* get editor data */
+       if (ANIM_animdata_get_context(C, &ac) == 0)
+               return OPERATOR_CANCELLED;
+               
+       /* get list of all channels that selection may need to be flushed to 
+        * - hierarchy must not affect what we have access to here...
+        */
+       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS);
+       ANIM_animdata_filter(&ac, &all_data, filter, ac.data, ac.datatype);
+       
+       /* filter data
+        * - just go through all visible channels, ensuring that everything is set to be curve-visible
+        */
+       filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS);
+       ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+       
+       for (ale = anim_data.first; ale; ale = ale->next) {
+               /* hack: skip object channels for now, since flushing those will always flush everything, but they are always included */
+               /* TODO: find out why this is the case, and fix that */
+               if (ale->type == ANIMTYPE_OBJECT)
+                       continue;
+               
+               /* select if it is not visible */
+               if (ANIM_channel_setting_get(&ac, ale, ACHANNEL_SETTING_VISIBLE) == 0)
+                       ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_SELECT, ACHANNEL_SETFLAG_ADD);
+               
+               /* change the visibility setting */
+               ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
+               
+               /* now, also flush selection status up/down as appropriate */
+               ANIM_flush_setting_anim_channels(&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, true);
+       }
+       
+       /* cleanup */
+       ANIM_animdata_freelist(&anim_data);
+       BLI_freelistN(&all_data);
+       
+       /* send notifier that things have changed */
+       WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
+       
+       return OPERATOR_FINISHED;
+}
+
+static void GRAPH_OT_unhide(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name = "Unhide Curves";
+       ot->idname = "GRAPH_OT_unhide";
+       ot->description = "Make previously hidden curves visible again in Graph Editor view";
+       
+       /* api callbacks */
+       ot->exec = graphview_curves_unhide_exec;
+       ot->poll = ED_operator_graphedit_active;
+       
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /* ************************** registration - operator types **********************************/
 
 void graphedit_operatortypes(void)
@@ -215,6 +349,9 @@ void graphedit_operatortypes(void)
        WM_operatortype_append(GRAPH_OT_ghost_curves_create);
        WM_operatortype_append(GRAPH_OT_ghost_curves_clear);
        
+       WM_operatortype_append(GRAPH_OT_hide);
+       WM_operatortype_append(GRAPH_OT_unhide);
+       
        /* keyframes */
        /* selection */
        WM_operatortype_append(GRAPH_OT_clickselect);
@@ -448,7 +585,12 @@ void graphedit_keymap(wmKeyConfig *keyconf)
        
        /* find (i.e. a shortcut for setting the name filter) */
        WM_keymap_add_item(keymap, "ANIM_OT_channels_find", FKEY, KM_PRESS, KM_CTRL, 0);
-
+       
+       /* hide/unhide selected curves */
+       WM_keymap_add_item(keymap, "GRAPH_OT_hide", HKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "GRAPH_OT_unhide", HKEY, KM_PRESS, KM_SHIFT, 0);
+       
+       
        /* channels */
        /* Channels are not directly handled by the Graph Editor module, but are inherited from the Animation module. 
         * All the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as these