Blender V2.61 - r43446

nla_ops.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
00019  * All rights reserved.
00020  *
00021  * 
00022  * Contributor(s): Joshua Leung (major recode)
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00032 #include <string.h>
00033 #include <stdio.h>
00034 
00035 #include "DNA_scene_types.h"
00036 
00037 
00038 #include "BLI_blenlib.h"
00039 #include "BLI_math.h"
00040 #include "BLI_rand.h"
00041 
00042 #include "BKE_context.h"
00043 #include "BKE_screen.h"
00044 
00045 #include "ED_anim_api.h"
00046 #include "ED_markers.h"
00047 #include "ED_screen.h"
00048 #include "ED_transform.h"
00049 
00050 #include "WM_api.h"
00051 #include "WM_types.h"
00052 
00053 #include "RNA_access.h"
00054 
00055 
00056 #include "nla_intern.h" // own include
00057 
00058 /* ************************** poll callbacks for operators **********************************/
00059 
00060 /* tweakmode is NOT enabled */
00061 int nlaop_poll_tweakmode_off (bContext *C)
00062 {
00063     Scene *scene;
00064     
00065     /* for now, we check 2 things: 
00066      *  1) active editor must be NLA
00067      *  2) tweakmode is currently set as a 'per-scene' flag 
00068      *     so that it will affect entire NLA data-sets,
00069      *     but not all AnimData blocks will be in tweakmode for 
00070      *     various reasons
00071      */
00072     if (ED_operator_nla_active(C) == 0)
00073         return 0;
00074     
00075     scene= CTX_data_scene(C);
00076     if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON))
00077         return 0;
00078     
00079     return 1;
00080 }
00081 
00082 /* tweakmode IS enabled */
00083 int nlaop_poll_tweakmode_on (bContext *C)
00084 {
00085     Scene *scene;
00086     
00087     /* for now, we check 2 things: 
00088      *  1) active editor must be NLA
00089      *  2) tweakmode is currently set as a 'per-scene' flag 
00090      *     so that it will affect entire NLA data-sets,
00091      *     but not all AnimData blocks will be in tweakmode for 
00092      *     various reasons
00093      */
00094     if (ED_operator_nla_active(C) == 0)
00095         return 0;
00096     
00097     scene= CTX_data_scene(C);
00098     if ((scene == NULL) || !(scene->flag & SCE_NLA_EDIT_ON))
00099         return 0;
00100     
00101     return 1;
00102 }
00103 
00104 /* is tweakmode enabled - for use in NLA operator code */
00105 short nlaedit_is_tweakmode_on (bAnimContext *ac)
00106 {
00107     if (ac && ac->scene)
00108         return (ac->scene->flag & SCE_NLA_EDIT_ON);
00109     return 0;
00110 }
00111 
00112 /* ************************** registration - operator types **********************************/
00113 
00114 void nla_operatortypes(void)
00115 {
00116     /* view */
00117     WM_operatortype_append(NLA_OT_properties);
00118     
00119     /* channels */
00120     WM_operatortype_append(NLA_OT_channels_click);
00121     
00122     WM_operatortype_append(NLA_OT_tracks_add);
00123     WM_operatortype_append(NLA_OT_delete_tracks);
00124     
00125     /* select */
00126     WM_operatortype_append(NLA_OT_click_select);
00127     WM_operatortype_append(NLA_OT_select_border);
00128     WM_operatortype_append(NLA_OT_select_all_toggle);
00129     WM_operatortype_append(NLA_OT_select_leftright);
00130     
00131     /* view */
00132     WM_operatortype_append(NLA_OT_view_all);
00133     WM_operatortype_append(NLA_OT_view_selected);
00134     
00135     /* edit */
00136     WM_operatortype_append(NLA_OT_tweakmode_enter);
00137     WM_operatortype_append(NLA_OT_tweakmode_exit);
00138     
00139     WM_operatortype_append(NLA_OT_actionclip_add);
00140     WM_operatortype_append(NLA_OT_transition_add);
00141     WM_operatortype_append(NLA_OT_soundclip_add);
00142     
00143     WM_operatortype_append(NLA_OT_meta_add);
00144     WM_operatortype_append(NLA_OT_meta_remove);
00145     
00146     WM_operatortype_append(NLA_OT_duplicate);
00147     WM_operatortype_append(NLA_OT_delete);
00148     WM_operatortype_append(NLA_OT_split);
00149     
00150     WM_operatortype_append(NLA_OT_mute_toggle);
00151     
00152     WM_operatortype_append(NLA_OT_swap);
00153     WM_operatortype_append(NLA_OT_move_up);
00154     WM_operatortype_append(NLA_OT_move_down);
00155     
00156     WM_operatortype_append(NLA_OT_action_sync_length);
00157     
00158     WM_operatortype_append(NLA_OT_apply_scale);
00159     WM_operatortype_append(NLA_OT_clear_scale);
00160     
00161     WM_operatortype_append(NLA_OT_snap);
00162     
00163     WM_operatortype_append(NLA_OT_fmodifier_add);
00164     WM_operatortype_append(NLA_OT_fmodifier_copy);
00165     WM_operatortype_append(NLA_OT_fmodifier_paste);
00166 }
00167 
00168 /* ************************** registration - keymaps **********************************/
00169 
00170 static void nla_keymap_channels(wmKeyMap *keymap)
00171 {
00172     wmKeyMapItem *kmi;
00173 
00174     /* NLA-specific (different to standard channels keymap) -------------------------- */
00175     /* selection */
00176         /* click-select */
00177         // XXX for now, only leftmouse.... 
00178     kmi = WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
00179     RNA_boolean_set(kmi->ptr, "extend", FALSE);
00180     kmi = WM_keymap_add_item(keymap, "NLA_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
00181     RNA_boolean_set(kmi->ptr, "extend", TRUE);
00182     
00183     /* channel operations */
00184         /* add tracks */
00185     kmi = WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
00186     RNA_boolean_set(kmi->ptr, "above_selected", FALSE);
00187     kmi = WM_keymap_add_item(keymap, "NLA_OT_tracks_add", AKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
00188     RNA_boolean_set(kmi->ptr, "above_selected", TRUE);
00189     
00190         /* delete tracks */
00191     WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", XKEY, KM_PRESS, 0, 0);
00192     WM_keymap_add_item(keymap, "NLA_OT_delete_tracks", DELKEY, KM_PRESS, 0, 0);
00193 }
00194 
00195 static void nla_keymap_main (wmKeyConfig *keyconf, wmKeyMap *keymap)
00196 {
00197     wmKeyMapItem *kmi;
00198     
00199     /* selection */
00200         /* click select */
00201     kmi = WM_keymap_add_item(keymap, "NLA_OT_click_select", SELECTMOUSE, KM_PRESS, 0, 0);
00202         RNA_boolean_set(kmi->ptr, "extend", FALSE);
00203     kmi= WM_keymap_add_item(keymap, "NLA_OT_click_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
00204         RNA_boolean_set(kmi->ptr, "extend", TRUE);
00205         
00206         /* select left/right */
00207     kmi = WM_keymap_add_item(keymap, "NLA_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
00208         RNA_boolean_set(kmi->ptr, "extend", FALSE);
00209         RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_TEST);
00210     kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", SELECTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
00211         RNA_boolean_set(kmi->ptr, "extend", TRUE);
00212         RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_TEST);
00213     
00214     kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", LEFTBRACKETKEY, KM_PRESS, 0, 0);
00215         RNA_boolean_set(kmi->ptr, "extend", FALSE);
00216         RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_LEFT);
00217     kmi= WM_keymap_add_item(keymap, "NLA_OT_select_leftright", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
00218         RNA_boolean_set(kmi->ptr, "extend", FALSE);
00219         RNA_enum_set(kmi->ptr, "mode", NLAEDIT_LRSEL_RIGHT);
00220         
00221     
00222         /* deselect all */
00223         /* TODO: uniformize with other select_all ops? */
00224     kmi = WM_keymap_add_item(keymap, "NLA_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
00225         RNA_boolean_set(kmi->ptr, "invert", FALSE);
00226     kmi = WM_keymap_add_item(keymap, "NLA_OT_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0);
00227         RNA_boolean_set(kmi->ptr, "invert", TRUE);
00228     
00229         /* borderselect */
00230     kmi = WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, 0, 0);
00231         RNA_boolean_set(kmi->ptr, "axis_range", FALSE);
00232     kmi = WM_keymap_add_item(keymap, "NLA_OT_select_border", BKEY, KM_PRESS, KM_ALT, 0);
00233         RNA_boolean_set(kmi->ptr, "axis_range", TRUE);
00234     
00235     /* view*/
00236         /* auto-set range */
00237     //WM_keymap_add_item(keymap, "NLA_OT_previewrange_set", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
00238     WM_keymap_add_item(keymap, "NLA_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
00239     WM_keymap_add_item(keymap, "NLA_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
00240     
00241     /* editing */
00242         /* tweakmode 
00243          *  - enter and exit are separate operators with the same hotkey... 
00244          *    This works as they use different poll()'s
00245          */
00246     WM_keymap_add_item(keymap, "NLA_OT_tweakmode_enter", TABKEY, KM_PRESS, 0, 0);
00247     WM_keymap_add_item(keymap, "NLA_OT_tweakmode_exit", TABKEY, KM_PRESS, 0, 0);
00248         
00249         /* add strips */
00250     WM_keymap_add_item(keymap, "NLA_OT_actionclip_add", AKEY, KM_PRESS, KM_SHIFT, 0);
00251     WM_keymap_add_item(keymap, "NLA_OT_transition_add", TKEY, KM_PRESS, KM_SHIFT, 0);
00252     WM_keymap_add_item(keymap, "NLA_OT_soundclip_add", KKEY, KM_PRESS, KM_SHIFT, 0);
00253     
00254         /* meta-strips */
00255     WM_keymap_add_item(keymap, "NLA_OT_meta_add", GKEY, KM_PRESS, KM_SHIFT, 0);
00256     WM_keymap_add_item(keymap, "NLA_OT_meta_remove", GKEY, KM_PRESS, KM_ALT, 0);
00257         
00258         /* duplicate */
00259     WM_keymap_add_item(keymap, "NLA_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);    
00260         
00261         /* delete */
00262     WM_keymap_add_item(keymap, "NLA_OT_delete", XKEY, KM_PRESS, 0, 0);
00263     WM_keymap_add_item(keymap, "NLA_OT_delete", DELKEY, KM_PRESS, 0, 0);
00264 
00265         /* split */
00266     WM_keymap_add_item(keymap, "NLA_OT_split", YKEY, KM_PRESS, 0, 0);
00267     
00268         /* toggles */
00269     WM_keymap_add_item(keymap, "NLA_OT_mute_toggle", HKEY, KM_PRESS, 0, 0);
00270     
00271         /* swap */
00272     WM_keymap_add_item(keymap, "NLA_OT_swap", FKEY, KM_PRESS, KM_ALT, 0);
00273         
00274         /* move up */
00275     WM_keymap_add_item(keymap, "NLA_OT_move_up", PAGEUPKEY, KM_PRESS, 0, 0);
00276         /* move down */
00277     WM_keymap_add_item(keymap, "NLA_OT_move_down", PAGEDOWNKEY, KM_PRESS, 0, 0);
00278     
00279         /* apply scale */
00280     WM_keymap_add_item(keymap, "NLA_OT_apply_scale", AKEY, KM_PRESS, KM_CTRL, 0);
00281         /* clear scale */
00282     WM_keymap_add_item(keymap, "NLA_OT_clear_scale", SKEY, KM_PRESS, KM_ALT, 0);
00283     
00284         /* snap */
00285     WM_keymap_add_item(keymap, "NLA_OT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
00286     
00287         /* add f-modifier */
00288     WM_keymap_add_item(keymap, "NLA_OT_fmodifier_add", MKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
00289     
00290     /* transform system */
00291     transform_keymap_for_space(keyconf, keymap, SPACE_NLA);
00292     
00293     /* special markers hotkeys for anim editors: see note in definition of this function */
00294     ED_marker_keymap_animedit_conflictfree(keymap);
00295 }
00296 
00297 /* --------------- */
00298 
00299 void nla_keymap(wmKeyConfig *keyconf)
00300 {
00301     wmKeyMap *keymap;
00302     
00303     /* keymap for all regions */
00304     keymap= WM_keymap_find(keyconf, "NLA Generic", SPACE_NLA, 0);
00305     WM_keymap_add_item(keymap, "NLA_OT_properties", NKEY, KM_PRESS, 0, 0);
00306     
00307     /* channels */
00308     /* Channels are not directly handled by the NLA Editor module, but are inherited from the Animation module. 
00309      * Most of the relevant operations, keymaps, drawing, etc. can therefore all be found in that module instead, as there
00310      * are many similarities with the other Animation Editors.
00311      *
00312      * However, those operations which involve clicking on channels and/or the placement of them in the view are implemented here instead
00313      */
00314     keymap= WM_keymap_find(keyconf, "NLA Channels", SPACE_NLA, 0);
00315     nla_keymap_channels(keymap);
00316     
00317     /* data */
00318     keymap= WM_keymap_find(keyconf, "NLA Editor", SPACE_NLA, 0);
00319     nla_keymap_main(keyconf, keymap);
00320 }
00321