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