Blender V4.3
drivers.cc File Reference
#include <cctype>
#include <cstdio>
#include <cstring>
#include "MEM_guardedalloc.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
#include "DNA_anim_types.h"
#include "DNA_texture_types.h"
#include "BKE_anim_data.hh"
#include "BKE_context.hh"
#include "BKE_fcurve.hh"
#include "BKE_fcurve_driver.h"
#include "BKE_report.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_build.hh"
#include "ED_keyframing.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
#include "WM_api.hh"
#include "WM_types.hh"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "RNA_path.hh"
#include "RNA_prototypes.hh"
#include "ANIM_fcurve.hh"
#include "anim_intern.hh"

Go to the source code of this file.

Functions

FCurveverify_driver_fcurve (ID *id, const char rna_path[], const int array_index, eDriverFCurveCreationMode creation_mode)
 
FCurvealloc_driver_fcurve (const char rna_path[], const int array_index, eDriverFCurveCreationMode creation_mode)
 
static int add_driver_with_target (ReportList *, ID *dst_id, const char dst_path[], int dst_index, ID *src_id, const char src_path[], int src_index, PointerRNA *dst_ptr, PropertyRNA *dst_prop, PointerRNA *src_ptr, PropertyRNA *src_prop, short flag, int driver_type)
 
int ANIM_add_driver_with_target (ReportList *reports, ID *dst_id, const char dst_path[], int dst_index, ID *src_id, const char src_path[], int src_index, short flag, int driver_type, short mapping_type)
 Main Driver Management API calls.
 
int ANIM_add_driver (ReportList *reports, ID *id, const char rna_path[], int array_index, short flag, int type)
 Main Driver Management API calls.
 
bool ANIM_remove_driver (ID *id, const char rna_path[], int array_index)
 Main Driver Management API calls.
 
void ANIM_drivers_copybuf_free ()
 
bool ANIM_driver_can_paste ()
 
bool ANIM_copy_driver (ReportList *reports, ID *id, const char rna_path[], int array_index, short)
 Main Driver Management API calls.
 
bool ANIM_paste_driver (ReportList *reports, ID *id, const char rna_path[], int array_index, short)
 Main Driver Management API calls.
 
void ANIM_driver_vars_copybuf_free ()
 
bool ANIM_driver_vars_can_paste ()
 
bool ANIM_driver_vars_copy (ReportList *reports, FCurve *fcu)
 
bool ANIM_driver_vars_paste (ReportList *reports, FCurve *fcu, bool replace)
 
void ANIM_copy_as_driver (ID *target_id, const char *target_path, const char *var_name)
 
static const EnumPropertyItemdriver_mapping_type_itemf (bContext *C, PointerRNA *, PropertyRNA *, bool *r_free)
 
static bool add_driver_button_poll (bContext *C)
 
static int add_driver_button_none (bContext *C, wmOperator *op, short mapping_type)
 
static int add_driver_button_menu_exec (bContext *C, wmOperator *op)
 
static int add_driver_button_menu_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
static void UNUSED_FUNCTION ANIM_OT_driver_button_add_menu (wmOperatorType *ot)
 
static int add_driver_button_invoke (bContext *C, wmOperator *op, const wmEvent *)
 
void ANIM_OT_driver_button_add (wmOperatorType *ot)
 
static int remove_driver_button_exec (bContext *C, wmOperator *op)
 
void ANIM_OT_driver_button_remove (wmOperatorType *ot)
 
static int edit_driver_button_exec (bContext *C, wmOperator *op)
 
void ANIM_OT_driver_button_edit (wmOperatorType *ot)
 
static int copy_driver_button_exec (bContext *C, wmOperator *op)
 
void ANIM_OT_copy_driver_button (wmOperatorType *ot)
 
static int paste_driver_button_exec (bContext *C, wmOperator *op)
 
void ANIM_OT_paste_driver_button (wmOperatorType *ot)
 

Variables

static FCurvechanneldriver_copypaste_buf = nullptr
 
static ListBase driver_vars_copybuf = {nullptr, nullptr}
 
const EnumPropertyItem prop_driver_create_mapping_types []
 

Function Documentation

◆ add_driver_button_invoke()

◆ add_driver_button_menu_exec()

◆ add_driver_button_menu_invoke()

static int add_driver_button_menu_invoke ( bContext * C,
wmOperator * op,
const wmEvent *  )
static

◆ add_driver_button_none()

◆ add_driver_button_poll()

◆ add_driver_with_target()

◆ alloc_driver_fcurve()

◆ ANIM_add_driver()

◆ ANIM_add_driver_with_target()

int ANIM_add_driver_with_target ( ReportList * reports,
ID * dst_id,
const char dst_path[],
int dst_index,
ID * src_id,
const char src_path[],
int src_index,
short flag,
int driver_type,
short mapping_type )

Main Driver Management API calls.

Add a new driver for the specified property on the given ID block, and make it be driven by the specified target.

This is intended to be used in conjunction with a modal "eyedropper" for picking the variable that is going to be used to drive this one.

Parameters
flageCreateDriverFlags
driver_typeeDriver_Types
mapping_typeeCreateDriver_MappingTypes

Definition at line 285 of file drivers.cc.

References add_driver_with_target(), ANIM_add_driver(), BKE_reportf(), CREATEDRIVER_MAPPING_1_1, CREATEDRIVER_MAPPING_1_N, CREATEDRIVER_MAPPING_N_N, CREATEDRIVER_MAPPING_NONE, CREATEDRIVER_WITH_DEFAULT_DVAR, flag, len, ID::name, ptr, RNA_id_pointer_create(), RNA_path_resolve_property(), RNA_property_array_check(), RNA_property_array_length(), and RPT_ERROR.

Referenced by driverdropper_sample().

◆ ANIM_copy_as_driver()

void ANIM_copy_as_driver ( ID * target_id,
const char * target_path,
const char * var_name )

◆ ANIM_copy_driver()

bool ANIM_copy_driver ( ReportList * reports,
ID * id,
const char rna_path[],
int array_index,
short flag )

Main Driver Management API calls.

Make a copy of the driver for the specified property on the given ID block.

Definition at line 580 of file drivers.cc.

References ANIM_drivers_copybuf_free(), BKE_fcurve_copy(), BKE_reportf(), channeldriver_copypaste_buf, FCurve::driver, DRIVER_FCURVE_LOOKUP_ONLY, ptr, RNA_id_pointer_create(), FCurve::rna_path, RNA_path_resolve_property(), RPT_ERROR, and verify_driver_fcurve().

Referenced by copy_driver_button_exec().

◆ ANIM_driver_can_paste()

bool ANIM_driver_can_paste ( )

Returns whether there is a driver in the copy/paste buffer to paste.

Definition at line 573 of file drivers.cc.

References channeldriver_copypaste_buf.

Referenced by ui_popup_context_menu_for_button().

◆ ANIM_driver_vars_can_paste()

bool ANIM_driver_vars_can_paste ( )

Checks if there are driver variables in the copy/paste buffer.

Definition at line 701 of file drivers.cc.

References BLI_listbase_is_empty(), and driver_vars_copybuf.

◆ ANIM_driver_vars_copy()

bool ANIM_driver_vars_copy ( ReportList * reports,
FCurve * fcu )

◆ ANIM_driver_vars_copybuf_free()

void ANIM_driver_vars_copybuf_free ( )

Clear copy-paste buffer for driver variable sets.

Note
This function frees any MEM_calloc'ed copy/paste buffer data.

Definition at line 685 of file drivers.cc.

References BLI_listbase_clear(), driver_free_variable(), driver_vars_copybuf, ListBase::first, and DriverVar::next.

Referenced by ANIM_copy_as_driver(), ANIM_driver_vars_copy(), and WM_exit_ex().

◆ ANIM_driver_vars_paste()

◆ ANIM_drivers_copybuf_free()

void ANIM_drivers_copybuf_free ( )

Clear copy-paste buffer for drivers.

Note
This function frees any MEM_calloc'ed copy/paste buffer data.

Definition at line 564 of file drivers.cc.

References BKE_fcurve_free(), and channeldriver_copypaste_buf.

Referenced by ANIM_copy_as_driver(), ANIM_copy_driver(), and WM_exit_ex().

◆ ANIM_OT_copy_driver_button()

◆ ANIM_OT_driver_button_add()

◆ ANIM_OT_driver_button_add_menu()

◆ ANIM_OT_driver_button_edit()

◆ ANIM_OT_driver_button_remove()

◆ ANIM_OT_paste_driver_button()

◆ ANIM_paste_driver()

bool ANIM_paste_driver ( ReportList * reports,
ID * id,
const char rna_path[],
int array_index,
short flag )

Main Driver Management API calls.

Add a new driver for the specified property on the given ID block or replace an existing one with the driver + driver-curve data from the buffer.

Definition at line 628 of file drivers.cc.

References FCurve::bezt, BKE_report(), BKE_reportf(), channeldriver_copypaste_buf, copy_fmodifiers(), FCurve::driver, DRIVER_FCURVE_EMPTY, FCurve::extend, fcurve_copy_driver(), FCurve::fpt, MEM_dupallocN, FCurve::modifiers, ptr, RNA_id_pointer_create(), RNA_path_resolve_property(), RPT_ERROR, FCurve::totvert, and verify_driver_fcurve().

Referenced by paste_driver_button_exec().

◆ ANIM_remove_driver()

bool ANIM_remove_driver ( ID * id,
const char rna_path[],
int array_index )

Main Driver Management API calls.

Remove the driver for the specified property on the given ID block.

Returns
Whether any driver was removed.

Definition at line 523 of file drivers.cc.

References BKE_animdata_from_id(), BKE_fcurve_free(), BKE_fcurve_iter_step(), BLI_remlink(), DRIVER_FCURVE_LOOKUP_ONLY, AnimData::drivers, ListBase::first, FCurve::next, and verify_driver_fcurve().

Referenced by blender::ed::outliner::do_outliner_drivers_editop(), graph_driver_delete_invalid_exec(), pyrna_struct_driver_remove(), and remove_driver_button_exec().

◆ copy_driver_button_exec()

◆ driver_mapping_type_itemf()

◆ edit_driver_button_exec()

static int edit_driver_button_exec ( bContext * C,
wmOperator * op )
static

◆ paste_driver_button_exec()

◆ remove_driver_button_exec()

◆ verify_driver_fcurve()

FCurve * verify_driver_fcurve ( ID * id,
const char rna_path[],
int array_index,
eDriverFCurveCreationMode creation_mode )

Get (or add relevant data to be able to do so) F-Curve from the driver stack, for the given Animation Data block. This assumes that all the destinations are valid.

Note
This low-level function shouldn't be used directly for most tools, although there are special cases where this approach is preferable.

Definition at line 50 of file drivers.cc.

References alloc_driver_fcurve(), BKE_animdata_ensure_id(), BKE_animdata_from_id(), BKE_fcurve_find(), BLI_addtail(), DRIVER_FCURVE_LOOKUP_ONLY, AnimData::drivers, and ELEM.

Referenced by add_driver_with_target(), ANIM_add_driver(), ANIM_copy_driver(), ANIM_paste_driver(), ANIM_remove_driver(), and ui_but_anim_expression_create().

Variable Documentation

◆ channeldriver_copypaste_buf

FCurve* channeldriver_copypaste_buf = nullptr
static

◆ driver_vars_copybuf

ListBase driver_vars_copybuf = {nullptr, nullptr}
static

◆ prop_driver_create_mapping_types

const EnumPropertyItem prop_driver_create_mapping_types[]

Mapping Types enum for operators.

Note
Used by ANIM_OT_driver_button_add and UI_OT_eyedropper_driver.

Definition at line 828 of file drivers.cc.

Referenced by ANIM_OT_driver_button_add_menu(), driver_mapping_type_itemf(), and UI_OT_eyedropper_driver().