From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.
// 2.65.10 bex ANIM_add_driver
//
// this is a list of functions executed from ANIM_add_driver(){}
//
// they are not complete
//	# 	= no sub functions
//	*	= duplicate
//	no tab 	= no check
 
/*
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2009 Blender Foundation
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * ***** END GPL LICENSE BLOCK *****
 */
 
// source/blender/editors/animation/drivers.c
short ANIM_add_driver(ReportList *reports, ID *id, const char rna_path[], int array_index, short flag, int type){
 
	RNA_id_pointer_create(id, &id_ptr);
	RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop)
	BKE_reportf(reports, RPT_ERROR, "Could not add driver, as RNA path is invalid for the given ID (ID = %s, path = %s)",id->name, rna_path);
	RNA_property_array_length(&ptr, prop);
	verify_driver_fcurve(id, rna_path, array_index, 1);			// source/blender/editors/animation/drivers.c
		ELEM(NULL, id, rna_path)
		BKE_animdata_from_id(id);					// source/blender/blenkernel/intern/anim_sys.c
			id_type_can_have_animdata(id)				// source/blender/blenkernel/intern/anim_sys.c
				GS(id->name)
		BKE_id_add_animdata(id);					// source/blender/blenkernel/intern/anim_sys.c
			id_type_can_have_animdata(id)
			MEM_callocN(sizeof(AnimData), "AnimData");
		list_find_fcurve(&adt->drivers, rna_path, array_index);		// source/blender/blenkernel/intern/fcurve.c
			ELEM(NULL, list, rna_path)
			strcmp(fcu->rna_path, rna_path)
		MEM_callocN(sizeof(FCurve), "FCurve");
		BLI_strdupn(rna_path, strlen(rna_path));
		MEM_callocN(sizeof(ChannelDriver), "ChannelDriver");
		add_fmodifier(&fcu->modifiers, FMODIFIER_TYPE_GENERATOR);
		BLI_addtail(&adt->drivers, fcu);
			#	.
	RNA_property_type(prop);
	RNA_property_array_length(&ptr, prop);
	sizeof(driver->expression);
	RNA_property_boolean_get(&ptr, prop);
	RNA_property_boolean_get_index(&ptr, prop, array_index);
	BLI_strncpy(expression, (val) ? "True" : "False", maxlen);
	RNA_property_int_get(&ptr, prop);
	RNA_property_int_get_index(&ptr, prop, array_index);
	BLI_snprintf(expression, maxlen, "%d", val);
	RNA_property_float_get(&ptr, prop);
	RNA_property_float_get_index(&ptr, prop, array_index);
	BLI_snprintf(expression, maxlen, "%.3f", fval);
	driver_add_new_variable(driver);					// source/blender/blenkernel/intern/fcurve.c
		MEM_callocN(sizeof(DriverVar), "DriverVar");
		BLI_addtail(&driver->variables, dvar);
			*
		strcpy(dvar->name, "var");
		BLI_uniquename(&driver->variables, dvar, "var", '_', offsetof(DriverVar, name), sizeof(dvar->name));
		driver_change_variable_type(dvar, DVAR_TYPE_SINGLE_PROP);
			get_dvar_typeinfo(type);				// source/blender/blenkernel/intern/fcurve.c
				#
			ELEM(NULL, dvar, dvti)
	driver_change_variable_type(dvar, DVAR_TYPE_TRANSFORM_CHAN);		// source/blender/blenkernel/intern/fcurve.c
		*
}