예제 #1
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;
}
예제 #2
0
파일: drivers.c 프로젝트: dfelinto/blender
/* Copy the given driver's variables to the buffer */
bool ANIM_driver_vars_copy(ReportList *reports, FCurve *fcu)
{
  /* sanity checks */
  if (ELEM(NULL, fcu, fcu->driver)) {
    BKE_report(reports, RPT_ERROR, "No driver to copy variables from");
    return false;
  }

  if (BLI_listbase_is_empty(&fcu->driver->variables)) {
    BKE_report(reports, RPT_ERROR, "Driver has no variables to copy");
    return false;
  }

  /* clear buffer */
  ANIM_driver_vars_copybuf_free();

  /* copy over the variables */
  driver_variables_copy(&driver_vars_copybuf, &fcu->driver->variables);

  return (BLI_listbase_is_empty(&driver_vars_copybuf) == false);
}