1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
17  * All rights reserved.
18  */
19 
20 #pragma once
21 
22 /** \file
23  * \ingroup bke
24  */
25 
26 #include "DNA_curve_types.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 struct AnimationEvalContext;
33 struct ChannelDriver;
34 struct DriverTarget;
35 struct DriverVar;
36 struct FCurve;
37 struct PathResolvedRNA;
38 struct PointerRNA;
39 struct PropertyRNA;
40 
41 /* ************** F-Curve Drivers ***************** */
42 
43 /* With these iterators for convenience, the variables "tarIndex" and "dtar" can be
44  * accessed directly from the code using them, but it is not recommended that their
45  * values be changed to point at other slots...
46  */
47 
48 /* convenience looper over ALL driver targets for a given variable (even the unused ones) */
49 #define DRIVER_TARGETS_LOOPER_BEGIN(dvar) \
50   { \
51     DriverTarget *dtar = &dvar->targets[0]; \
52     int tarIndex = 0; \
53     for (; tarIndex < MAX_DRIVER_TARGETS; tarIndex++, dtar++)
54 
55 /* convenience looper over USED driver targets only */
56 #define DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar) \
57   { \
58     DriverTarget *dtar = &dvar->targets[0]; \
59     int tarIndex = 0; \
60     for (; tarIndex < dvar->num_targets; tarIndex++, dtar++)
61 
62 /* tidy up for driver targets loopers */
63 #define DRIVER_TARGETS_LOOPER_END \
64   } \
65   ((void)0)
66 
67 /* ---------------------- */
68 
69 void fcurve_free_driver(struct FCurve *fcu);
70 struct ChannelDriver *fcurve_copy_driver(const struct ChannelDriver *driver);
71 
72 void driver_variables_copy(struct ListBase *dst_vars, const struct ListBase *src_vars);
73 
74 void BKE_driver_target_matrix_to_rot_channels(
75     float mat[4][4], int auto_order, int rotation_mode, int channel, bool angles, float r_buf[4]);
76 
77 void driver_free_variable(struct ListBase *variables, struct DriverVar *dvar);
78 void driver_free_variable_ex(struct ChannelDriver *driver, struct DriverVar *dvar);
79 
80 void driver_change_variable_type(struct DriverVar *dvar, int type);
81 void driver_variable_name_validate(struct DriverVar *dvar);
82 struct DriverVar *driver_add_new_variable(struct ChannelDriver *driver);
83 
84 float driver_get_variable_value(struct ChannelDriver *driver, struct DriverVar *dvar);
85 bool driver_get_variable_property(struct ChannelDriver *driver,
86                                   struct DriverTarget *dtar,
87                                   struct PointerRNA *r_ptr,
88                                   struct PropertyRNA **r_prop,
89                                   int *r_index);
90 
91 bool BKE_driver_has_simple_expression(struct ChannelDriver *driver);
92 bool BKE_driver_expression_depends_on_time(struct ChannelDriver *driver);
93 void BKE_driver_invalidate_expression(struct ChannelDriver *driver,
94                                       bool expr_changed,
95                                       bool varname_changed);
96 
97 float evaluate_driver(struct PathResolvedRNA *anim_rna,
98                       struct ChannelDriver *driver,
99                       struct ChannelDriver *driver_orig,
100                       const struct AnimationEvalContext *anim_eval_context);
101 
102 #ifdef __cplusplus
103 }
104 #endif
105