Blender  V2.59
interface_anim.c
Go to the documentation of this file.
00001 /*
00002  * $Id: interface_anim.c 38871 2011-07-31 06:03:14Z gsrb3d $
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  * Contributor(s):
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 
00033 
00034 #include "DNA_anim_types.h"
00035 #include "DNA_scene_types.h"
00036 #include "DNA_screen_types.h"
00037 
00038 #include "BLI_listbase.h"
00039 #include "BLI_string.h"
00040 
00041 #include "BKE_context.h"
00042 #include "BKE_fcurve.h"
00043 
00044 
00045 #include "ED_keyframing.h"
00046 
00047 #include "UI_interface.h"
00048 
00049 #include "WM_api.h"
00050 #include "WM_types.h"
00051 
00052 #include "interface_intern.h"
00053 
00054 static FCurve *ui_but_get_fcurve(uiBut *but, bAction **action, int *driven)
00055 {
00056         return rna_get_fcurve(&but->rnapoin, but->rnaprop, but->rnaindex, action, driven);
00057 }
00058 
00059 void ui_but_anim_flag(uiBut *but, float cfra)
00060 {
00061         FCurve *fcu;
00062         int driven;
00063 
00064         but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN);
00065 
00066         fcu= ui_but_get_fcurve(but, NULL, &driven);
00067 
00068         if(fcu) {
00069                 if(!driven) {
00070                         but->flag |= UI_BUT_ANIMATED;
00071                         
00072                         if(fcurve_frame_has_keyframe(fcu, cfra, 0))
00073                                 but->flag |= UI_BUT_ANIMATED_KEY;
00074                 }
00075                 else {
00076                         but->flag |= UI_BUT_DRIVEN;
00077                 }
00078         }
00079 }
00080 
00081 int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen)
00082 {
00083         FCurve *fcu;
00084         ChannelDriver *driver;
00085         int driven;
00086 
00087         fcu= ui_but_get_fcurve(but, NULL, &driven);
00088 
00089         if(fcu && driven) {
00090                 driver= fcu->driver;
00091 
00092                 if(driver && driver->type == DRIVER_TYPE_PYTHON) {
00093                         BLI_strncpy(str, driver->expression, maxlen);
00094                         return 1;
00095                 }
00096         }
00097 
00098         return 0;
00099 }
00100 
00101 int ui_but_anim_expression_set(uiBut *but, const char *str)
00102 {
00103         FCurve *fcu;
00104         ChannelDriver *driver;
00105         int driven;
00106 
00107         fcu= ui_but_get_fcurve(but, NULL, &driven);
00108 
00109         if(fcu && driven) {
00110                 driver= fcu->driver;
00111 
00112                 if(driver && driver->type == DRIVER_TYPE_PYTHON) {
00113                         BLI_strncpy(driver->expression, str, sizeof(driver->expression));
00114                         driver->flag |= DRIVER_FLAG_RECOMPILE;
00115                         WM_event_add_notifier(but->block->evil_C, NC_ANIMATION|ND_KEYFRAME, NULL);
00116                         return 1;
00117                 }
00118         }
00119 
00120         return 0;
00121 }
00122 
00123 void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
00124 {
00125         ID *id;
00126         bAction *action;
00127         FCurve *fcu;
00128         int driven;
00129 
00130         fcu= ui_but_get_fcurve(but, &action, &driven);
00131 
00132         if(fcu && !driven) {
00133                 id= but->rnapoin.id.data;
00134                 
00135                 // TODO: this should probably respect the keyingset only option for anim
00136                 if(autokeyframe_cfra_can_key(scene, id)) {
00137                         ReportList *reports = CTX_wm_reports(C);
00138                         short flag = ANIM_get_keyframing_flags(scene, 1);
00139                         
00140                         fcu->flag &= ~FCURVE_SELECTED;
00141                         insert_keyframe(reports, id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
00142                         WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
00143                 }
00144         }
00145 }
00146 
00147 void ui_but_anim_insert_keyframe(bContext *C)
00148 {
00149         /* this operator calls uiContextActiveProperty */
00150         WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
00151 }
00152 
00153 void ui_but_anim_delete_keyframe(bContext *C)
00154 {
00155         /* this operator calls uiContextActiveProperty */
00156         WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
00157 }
00158 
00159 void ui_but_anim_add_driver(bContext *C)
00160 {
00161         /* this operator calls uiContextActiveProperty */
00162         WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
00163 }
00164 
00165 void ui_but_anim_remove_driver(bContext *C)
00166 {
00167         /* this operator calls uiContextActiveProperty */
00168         WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
00169 }
00170 
00171 void ui_but_anim_copy_driver(bContext *C)
00172 {
00173         /* this operator calls uiContextActiveProperty */
00174         WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
00175 }
00176 
00177 void ui_but_anim_paste_driver(bContext *C)
00178 {
00179         /* this operator calls uiContextActiveProperty */
00180         WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
00181 }
00182 
00183 void ui_but_anim_add_keyingset(bContext *C)
00184 {
00185         /* this operator calls uiContextActiveProperty */
00186         WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
00187 }
00188 
00189 void ui_but_anim_remove_keyingset(bContext *C)
00190 {
00191         /* this operator calls uiContextActiveProperty */
00192         WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
00193 }