~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/interface/interface_anim.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * Contributor(s):
 
19
 *
 
20
 * ***** END GPL LICENSE BLOCK *****
 
21
 */
 
22
 
 
23
/** \file blender/editors/interface/interface_anim.c
 
24
 *  \ingroup edinterface
 
25
 */
1
26
 
2
27
#include <stdio.h>
3
28
#include <stdlib.h>
11
36
 
12
37
#include "BLI_listbase.h"
13
38
#include "BLI_string.h"
 
39
#include "BLI_string_utf8.h"
 
40
#include "BLI_utildefines.h"
14
41
 
 
42
#include "BKE_context.h"
15
43
#include "BKE_animsys.h"
16
 
#include "BKE_context.h"
17
44
#include "BKE_fcurve.h"
18
 
 
 
45
#include "BKE_global.h"
19
46
 
20
47
#include "ED_keyframing.h"
21
48
 
22
49
#include "UI_interface.h"
23
50
 
 
51
#include "RNA_access.h"
 
52
 
24
53
#include "WM_api.h"
25
54
#include "WM_types.h"
26
55
 
36
65
        FCurve *fcu;
37
66
        int driven;
38
67
 
39
 
        but->flag &= ~(UI_BUT_ANIMATED|UI_BUT_ANIMATED_KEY|UI_BUT_DRIVEN);
40
 
 
41
 
        fcu= ui_but_get_fcurve(but, NULL, &driven);
42
 
 
43
 
        if(fcu) {
44
 
                if(!driven) {
 
68
        but->flag &= ~(UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN);
 
69
 
 
70
        fcu = ui_but_get_fcurve(but, NULL, &driven);
 
71
 
 
72
        if (fcu) {
 
73
                if (!driven) {
45
74
                        but->flag |= UI_BUT_ANIMATED;
46
75
                        
47
 
                        if(fcurve_frame_has_keyframe(fcu, cfra, 0))
 
76
                        if (fcurve_frame_has_keyframe(fcu, cfra, 0))
48
77
                                but->flag |= UI_BUT_ANIMATED_KEY;
49
78
                }
50
79
                else {
53
82
        }
54
83
}
55
84
 
56
 
int ui_but_anim_expression_get(uiBut *but, char *str, int maxlen)
 
85
int ui_but_anim_expression_get(uiBut *but, char *str, size_t maxlen)
57
86
{
58
87
        FCurve *fcu;
59
88
        ChannelDriver *driver;
60
89
        int driven;
61
90
 
62
 
        fcu= ui_but_get_fcurve(but, NULL, &driven);
63
 
 
64
 
        if(fcu && driven) {
65
 
                driver= fcu->driver;
66
 
 
67
 
                if(driver && driver->type == DRIVER_TYPE_PYTHON) {
 
91
        fcu = ui_but_get_fcurve(but, NULL, &driven);
 
92
 
 
93
        if (fcu && driven) {
 
94
                driver = fcu->driver;
 
95
 
 
96
                if (driver && driver->type == DRIVER_TYPE_PYTHON) {
68
97
                        BLI_strncpy(str, driver->expression, maxlen);
69
98
                        return 1;
70
99
                }
79
108
        ChannelDriver *driver;
80
109
        int driven;
81
110
 
82
 
        fcu= ui_but_get_fcurve(but, NULL, &driven);
83
 
 
84
 
        if(fcu && driven) {
85
 
                driver= fcu->driver;
86
 
 
87
 
                if(driver && driver->type == DRIVER_TYPE_PYTHON) {
88
 
                        BLI_strncpy(driver->expression, str, sizeof(driver->expression));
 
111
        fcu = ui_but_get_fcurve(but, NULL, &driven);
 
112
 
 
113
        if (fcu && driven) {
 
114
                driver = fcu->driver;
 
115
                
 
116
                if (driver && driver->type == DRIVER_TYPE_PYTHON) {
 
117
                        BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
 
118
                        driver->flag |= DRIVER_FLAG_RECOMPILE;
 
119
                        WM_event_add_notifier(but->block->evil_C, NC_ANIMATION | ND_KEYFRAME, NULL);
89
120
                        return 1;
90
121
                }
91
122
        }
93
124
        return 0;
94
125
}
95
126
 
 
127
/* create new expression for button (i.e. a "scripted driver"), if it can be created... */
 
128
int ui_but_anim_expression_create(uiBut *but, const char *str)
 
129
{
 
130
        bContext *C = but->block->evil_C;
 
131
        ID *id;
 
132
        FCurve *fcu;
 
133
        char *path;
 
134
        short ok = 0;
 
135
        
 
136
        /* button must have RNA-pointer to a numeric-capable property */
 
137
        if (ELEM(NULL, but->rnapoin.data, but->rnaprop)) {
 
138
                if (G.debug & G_DEBUG)
 
139
                        printf("ERROR: create expression failed - button has no RNA info attached\n");
 
140
                return 0;
 
141
        }
 
142
        
 
143
        /* make sure we have animdata for this */
 
144
        // FIXME: until materials can be handled by depsgraph, don't allow drivers to be created for them
 
145
        id = (ID *)but->rnapoin.id.data;
 
146
        if ((id == NULL) || (GS(id->name) == ID_MA) || (GS(id->name) == ID_TE)) {
 
147
                if (G.debug & G_DEBUG)
 
148
                        printf("ERROR: create expression failed - invalid id-datablock for adding drivers (%p)\n", id);
 
149
                return 0;
 
150
        }
 
151
        
 
152
        /* get path */
 
153
        path = RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
 
154
        
 
155
        /* create driver */
 
156
        fcu = verify_driver_fcurve(id, path, but->rnaindex, 1);
 
157
        if (fcu) {
 
158
                ChannelDriver *driver = fcu->driver;
 
159
                
 
160
                if (driver) {
 
161
                        /* set type of driver */
 
162
                        driver->type = DRIVER_TYPE_PYTHON;
 
163
                        
 
164
                        /* set the expression */
 
165
                        // TODO: need some way of identifying variables used
 
166
                        BLI_strncpy_utf8(driver->expression, str, sizeof(driver->expression));
 
167
 
 
168
                        /* updates */
 
169
                        driver->flag |= DRIVER_FLAG_RECOMPILE;
 
170
                        WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, NULL);
 
171
                }
 
172
        }
 
173
        
 
174
        MEM_freeN(path);
 
175
        
 
176
        return ok;
 
177
}
 
178
 
96
179
void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra)
97
180
{
98
181
        ID *id;
100
183
        FCurve *fcu;
101
184
        int driven;
102
185
 
103
 
        fcu= ui_but_get_fcurve(but, &action, &driven);
 
186
        fcu = ui_but_get_fcurve(but, &action, &driven);
104
187
 
105
 
        if(fcu && !driven) {
106
 
                id= but->rnapoin.id.data;
 
188
        if (fcu && !driven) {
 
189
                id = but->rnapoin.id.data;
107
190
                
108
191
                // TODO: this should probably respect the keyingset only option for anim
109
 
                if(autokeyframe_cfra_can_key(scene, id)) {
 
192
                if (autokeyframe_cfra_can_key(scene, id)) {
 
193
                        ReportList *reports = CTX_wm_reports(C);
110
194
                        short flag = ANIM_get_keyframing_flags(scene, 1);
111
195
                        
112
196
                        fcu->flag &= ~FCURVE_SELECTED;
113
 
                        insert_keyframe(id, action, ((fcu->grp)?(fcu->grp->name):(NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
114
 
                        WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
115
 
                }
116
 
        }
117
 
}
118
 
 
119
 
void uiAnimContextProperty(const bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop, int *index)
120
 
{
121
 
        ARegion *ar= CTX_wm_region(C);
122
 
        uiBlock *block;
123
 
        uiBut *but;
124
 
 
125
 
        memset(ptr, 0, sizeof(*ptr));
126
 
        *prop= NULL;
127
 
        *index= 0;
128
 
 
129
 
        if(ar) {
130
 
                for(block=ar->uiblocks.first; block; block=block->next) {
131
 
                        for(but=block->buttons.first; but; but= but->next) {
132
 
                                if((but->active || but->flag & UI_BUT_LAST_ACTIVE) && but->rnapoin.id.data) {
133
 
                                        *ptr= but->rnapoin;
134
 
                                        *prop= but->rnaprop;
135
 
                                        *index= but->rnaindex;
136
 
                                        return;
137
 
                                }
138
 
                        }
 
197
                        insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)), fcu->rna_path, fcu->array_index, cfra, flag);
 
198
                        WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
139
199
                }
140
200
        }
141
201
}
142
202
 
143
203
void ui_but_anim_insert_keyframe(bContext *C)
144
204
{
145
 
        /* this operator calls uiAnimContextProperty above */
 
205
        /* this operator calls uiContextActiveProperty */
146
206
        WM_operator_name_call(C, "ANIM_OT_keyframe_insert_button", WM_OP_INVOKE_DEFAULT, NULL);
147
207
}
148
208
 
149
209
void ui_but_anim_delete_keyframe(bContext *C)
150
210
{
151
 
        /* this operator calls uiAnimContextProperty above */
 
211
        /* this operator calls uiContextActiveProperty */
152
212
        WM_operator_name_call(C, "ANIM_OT_keyframe_delete_button", WM_OP_INVOKE_DEFAULT, NULL);
153
213
}
154
214
 
155
215
void ui_but_anim_add_driver(bContext *C)
156
216
{
157
 
        /* this operator calls uiAnimContextProperty above */
 
217
        /* this operator calls uiContextActiveProperty */
158
218
        WM_operator_name_call(C, "ANIM_OT_driver_button_add", WM_OP_INVOKE_DEFAULT, NULL);
159
219
}
160
220
 
161
221
void ui_but_anim_remove_driver(bContext *C)
162
222
{
163
 
        /* this operator calls uiAnimContextProperty above */
 
223
        /* this operator calls uiContextActiveProperty */
164
224
        WM_operator_name_call(C, "ANIM_OT_driver_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
165
225
}
166
226
 
167
227
void ui_but_anim_copy_driver(bContext *C)
168
228
{
169
 
        /* this operator calls uiAnimContextProperty above */
 
229
        /* this operator calls uiContextActiveProperty */
170
230
        WM_operator_name_call(C, "ANIM_OT_copy_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
171
231
}
172
232
 
173
233
void ui_but_anim_paste_driver(bContext *C)
174
234
{
175
 
        /* this operator calls uiAnimContextProperty above */
 
235
        /* this operator calls uiContextActiveProperty */
176
236
        WM_operator_name_call(C, "ANIM_OT_paste_driver_button", WM_OP_INVOKE_DEFAULT, NULL);
177
237
}
178
238
 
179
239
void ui_but_anim_add_keyingset(bContext *C)
180
240
{
181
 
        /* this operator calls uiAnimContextProperty above */
 
241
        /* this operator calls uiContextActiveProperty */
182
242
        WM_operator_name_call(C, "ANIM_OT_keyingset_button_add", WM_OP_INVOKE_DEFAULT, NULL);
183
243
}
184
244
 
185
245
void ui_but_anim_remove_keyingset(bContext *C)
186
246
{
187
 
        /* this operator calls uiAnimContextProperty above */
 
247
        /* this operator calls uiContextActiveProperty */
188
248
        WM_operator_name_call(C, "ANIM_OT_keyingset_button_remove", WM_OP_INVOKE_DEFAULT, NULL);
189
249
}