示例#1
0
/* callback to remove target variable from active driver */
static void driver_delete_var_cb(bContext *UNUSED(C), void *driver_v, void *dvar_v)
{
	ChannelDriver *driver = (ChannelDriver *)driver_v;
	DriverVar *dvar = (DriverVar *)dvar_v;
	
	/* remove the active variable */
	driver_free_variable_ex(driver, dvar);
}
示例#2
0
/* Paste the variables in the buffer to the given FCurve */
bool ANIM_driver_vars_paste(ReportList *reports, FCurve *fcu, bool replace)
{
	ChannelDriver *driver = (fcu) ? fcu->driver : NULL;
	ListBase tmp_list = {NULL, NULL};
	
	/* sanity checks */
	if (BLI_listbase_is_empty(&driver_vars_copybuf)) {
		BKE_report(reports, RPT_ERROR, "No driver variables in clipboard to paste");
		return false;
	}
	
	if (ELEM(NULL, fcu, fcu->driver)) {
		BKE_report(reports, RPT_ERROR, "Cannot paste driver variables without a driver");
		return false;
	}
	
	/* 1) Make a new copy of the variables in the buffer - these will get pasted later... */
	driver_variables_copy(&tmp_list, &driver_vars_copybuf);
	
	/* 2) Prepare destination array */
	if (replace) {
		DriverVar *dvar, *dvarn;
		
		/* Free all existing vars first - We aren't retaining anything */
		for (dvar = driver->variables.first; dvar; dvar = dvarn) {
			dvarn = dvar->next;
			driver_free_variable_ex(driver, dvar);
		}
		
		BLI_listbase_clear(&driver->variables);
	}
	
	/* 3) Add new vars */
	if (driver->variables.last) {
		DriverVar *last = driver->variables.last;
		DriverVar *first = tmp_list.first;
		
		last->next = first;
		first->prev = last;
		
		driver->variables.last = tmp_list.last;
	}
	else {
		driver->variables.first = tmp_list.first;
		driver->variables.last = tmp_list.last;
	}
	
#ifdef WITH_PYTHON
	/* since driver variables are cached, the expression needs re-compiling too */
	if (driver->type == DRIVER_TYPE_PYTHON)
		driver->flag |= DRIVER_FLAG_RENAMEVAR;
#endif
	
	return true;
}