[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19635] branches/blender2.5/blender/source /blender/editors: 2.5 - Groundwork for Adding/Removing Drivers
Joshua Leung
aligorith at gmail.com
Fri Apr 10 15:08:13 CEST 2009
Revision: 19635
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19635
Author: aligorith
Date: 2009-04-10 15:08:12 +0200 (Fri, 10 Apr 2009)
Log Message:
-----------
2.5 - Groundwork for Adding/Removing Drivers
Drivers can now be Added/Removed from buttons using the D/Alt-D hotkeys, and also through the menu. Driver settings (i.e. the target) are not set by default. To set those, go to the Graph Editor (see notes).
Notes:
* Buildsystem maintainers - I've added a new file "editors/animation/drivers.c"
* Widget colours for the driven-setting indications are needed
* To see the new drivers, go into Graph Editor -> "Drivers" mode. Currently, there's a little bug there which prevents editing of the new drivers.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h
branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
branches/blender2.5/blender/source/blender/editors/interface/interface_anim.c
branches/blender2.5/blender/source/blender/editors/interface/interface_handlers.c
branches/blender2.5/blender/source/blender/editors/interface/interface_intern.h
branches/blender2.5/blender/source/blender/editors/interface/interface_widgets.c
Added Paths:
-----------
branches/blender2.5/blender/source/blender/editors/animation/drivers.c
Modified: branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c 2009-04-10 12:06:31 UTC (rev 19634)
+++ branches/blender2.5/blender/source/blender/editors/animation/anim_ops.c 2009-04-10 13:08:12 UTC (rev 19635)
@@ -386,6 +386,9 @@
WM_operatortype_append(ANIM_OT_delete_keyframe_button);
WM_operatortype_append(ANIM_OT_delete_keyframe_old); // xxx remove?
+ WM_operatortype_append(ANIM_OT_add_driver_button);
+ WM_operatortype_append(ANIM_OT_remove_driver_button);
+
WM_operatortype_append(ANIM_OT_keyingset_add_new);
WM_operatortype_append(ANIM_OT_keyingset_add_destination);
}
Added: branches/blender2.5/blender/source/blender/editors/animation/drivers.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/drivers.c (rev 0)
+++ branches/blender2.5/blender/source/blender/editors/animation/drivers.c 2009-04-10 13:08:12 UTC (rev 19635)
@@ -0,0 +1,289 @@
+/* Testing code for 2.5 animation system
+ * Copyright 2009, Joshua Leung
+ */
+
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+#include <math.h>
+#include <float.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_arithb.h"
+#include "BLI_dynstr.h"
+
+#include "DNA_anim_types.h"
+#include "DNA_action_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_key_types.h"
+#include "DNA_object_types.h"
+#include "DNA_material_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BKE_animsys.h"
+#include "BKE_action.h"
+#include "BKE_constraint.h"
+#include "BKE_fcurve.h"
+#include "BKE_utildefines.h"
+#include "BKE_context.h"
+#include "BKE_report.h"
+#include "BKE_key.h"
+#include "BKE_material.h"
+
+#include "ED_anim_api.h"
+#include "ED_keyframing.h"
+#include "ED_keyframes_edit.h"
+#include "ED_screen.h"
+#include "ED_util.h"
+
+#include "UI_interface.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_types.h"
+
+/* ************************************************** */
+/* Animation Data Validation */
+
+/* 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.
+ */
+FCurve *verify_driver_fcurve (ID *id, const char rna_path[], const int array_index, short add)
+{
+ AnimData *adt;
+ FCurve *fcu;
+
+ /* sanity checks */
+ if ELEM(NULL, id, rna_path)
+ return NULL;
+
+ /* init animdata if none available yet */
+ adt= BKE_animdata_from_id(id);
+ if ((adt == NULL) && (add))
+ adt= BKE_id_add_animdata(id);
+ if (adt == NULL) {
+ /* if still none (as not allowed to add, or ID doesn't have animdata for some reason) */
+ return NULL;
+ }
+
+ /* try to find f-curve matching for this setting
+ * - add if not found and allowed to add one
+ * TODO: add auto-grouping support? how this works will need to be resolved
+ */
+ fcu= list_find_fcurve(&adt->drivers, rna_path, array_index);
+
+ if ((fcu == NULL) && (add)) {
+ /* use default settings to make a F-Curve */
+ fcu= MEM_callocN(sizeof(FCurve), "FCurve");
+
+ fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED);
+
+ /* store path - make copy, and store that */
+ fcu->rna_path= BLI_strdupn(rna_path, strlen(rna_path));
+ fcu->array_index= array_index;
+
+ /* add some new driver data */
+ fcu->driver= MEM_callocN(sizeof(ChannelDriver), "ChannelDriver");
+
+ /* just add F-Curve to end of driver list */
+ BLI_addtail(&adt->drivers, fcu);
+ }
+
+ /* return the F-Curve */
+ return fcu;
+}
+
+/* ************************************************** */
+/* Driver Management API */
+
+/* Main Driver Management API calls:
+ * Add a new driver for the specified property on the given ID block
+ */
+short ANIM_add_driver (ID *id, const char rna_path[], int array_index, short flag)
+{
+ PointerRNA id_ptr, ptr;
+ PropertyRNA *prop;
+ FCurve *fcu;
+
+ /* validate pointer first - exit if failure */
+ RNA_id_pointer_create(id, &id_ptr);
+ if ((RNA_path_resolve(&id_ptr, rna_path, &ptr, &prop) == 0) || (prop == NULL)) {
+ printf("Insert Key: Could not add Driver, as RNA Path is invalid for the given ID (ID = %s, Path = %s)\n", id->name, rna_path);
+ return 0;
+ }
+
+ /* create F-Curve with Driver */
+ fcu= verify_driver_fcurve(id, rna_path, array_index, 1);
+
+ /* done */
+ return (fcu != NULL);
+}
+
+/* Main Driver Management API calls:
+ * Remove the driver for the specified property on the given ID block (if available)
+ */
+short ANIM_remove_driver (struct ID *id, const char rna_path[], int array_index, short flag)
+{
+ AnimData *adt;
+ FCurve *fcu;
+
+ /* get F-Curve
+ * Note: here is one of the places where we don't want new F-Curve + Driver added!
+ * so 'add' var must be 0
+ */
+ /* we don't check the validity of the path here yet, but it should be ok... */
+ fcu= verify_driver_fcurve(id, rna_path, array_index, 0);
+ adt= BKE_animdata_from_id(id);
+
+ /* only continue if we have an driver to remove */
+ if (adt && fcu) {
+ /* remove F-Curve from driver stack, then free it */
+ BLI_remlink(&adt->drivers, fcu);
+ free_fcurve(fcu);
+
+ /* done successfully */
+ return 1;
+ }
+
+ /* failed */
+ return 0;
+}
+
+
+/* ************************************************** */
+/* UI-Button Interface */
+
+/* Add Driver Button Operator ------------------------ */
+
+static int add_driver_button_exec (bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop= NULL;
+ char *path;
+ short success= 0;
+ int a, index, length, all= RNA_boolean_get(op->ptr, "all");
+
+ /* try to insert keyframe using property retrieved from UI */
+ memset(&ptr, 0, sizeof(PointerRNA));
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ if (ptr.data && prop && RNA_property_animateable(ptr.data, prop)) {
+ path= RNA_path_from_ID_to_property(&ptr, prop);
+
+ if (path) {
+ if (all) {
+ length= RNA_property_array_length(&ptr, prop);
+
+ if (length) index= 0;
+ else length= 1;
+ }
+ else
+ length= 1;
+
+ for (a=0; a<length; a++)
+ success+= ANIM_add_driver(ptr.id.data, path, index+a, 0);
+
+ MEM_freeN(path);
+ }
+ }
+
+ if (success) {
+ /* send updates */
+ ED_anim_dag_flush_update(C);
+
+ /* for now, only send ND_KEYS for KeyingSets */
+ WM_event_add_notifier(C, ND_KEYS, NULL); // XXX
+ }
+
+ return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void ANIM_OT_add_driver_button (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Add Driver";
+ ot->idname= "ANIM_OT_add_driver_button";
+
+ /* callbacks */
+ ot->exec= add_driver_button_exec;
+ //op->poll= ???
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "all", 1, "All", "Insert a keyframe for all element of the array.");
+}
+
+/* Remove Driver Button Operator ------------------------ */
+
+static int remove_driver_button_exec (bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop= NULL;
+ char *path;
+ short success= 0;
+ int a, index, length, all= RNA_boolean_get(op->ptr, "all");
+
+ /* try to insert keyframe using property retrieved from UI */
+ memset(&ptr, 0, sizeof(PointerRNA));
+ uiAnimContextProperty(C, &ptr, &prop, &index);
+
+ if (ptr.data && prop) {
+ path= RNA_path_from_ID_to_property(&ptr, prop);
+
+ if (path) {
+ if (all) {
+ length= RNA_property_array_length(&ptr, prop);
+
+ if(length) index= 0;
+ else length= 1;
+ }
+ else
+ length= 1;
+
+ for (a=0; a<length; a++)
+ success+= ANIM_remove_driver(ptr.id.data, path, index+a, 0);
+
+ MEM_freeN(path);
+ }
+ }
+
+
+ if (success) {
+ /* send updates */
+ ED_anim_dag_flush_update(C);
+
+ /* for now, only send ND_KEYS for KeyingSets */
+ WM_event_add_notifier(C, ND_KEYS, NULL); // XXX
+ }
+
+ return (success)? OPERATOR_FINISHED: OPERATOR_CANCELLED;
+}
+
+void ANIM_OT_remove_driver_button (wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Remove Driver";
+ ot->idname= "ANIM_OT_remove_driver_button";
+
+ /* callbacks */
+ ot->exec= remove_driver_button_exec;
+ //op->poll= ???
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "all", 1, "All", "Delete keyfames from all elements of the array.");
+}
+
+/* ************************************************** */
Modified: branches/blender2.5/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/animation/keyframing.c 2009-04-10 12:06:31 UTC (rev 19634)
+++ branches/blender2.5/blender/source/blender/editors/animation/keyframing.c 2009-04-10 13:08:12 UTC (rev 19635)
@@ -825,7 +825,7 @@
fcu= verify_fcurve(id, group, rna_path, array_index, 0);
adt= BKE_animdata_from_id(id);
- /* only continue if we have an ipo-curve to remove keyframes from */
+ /* only continue if we have an F-Curve to remove keyframes from */
if (adt && adt->action && fcu) {
bAction *act= adt->action;
short found = -1;
Modified: branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h 2009-04-10 12:06:31 UTC (rev 19634)
+++ branches/blender2.5/blender/source/blender/editors/include/ED_keyframing.h 2009-04-10 13:08:12 UTC (rev 19635)
@@ -95,10 +95,25 @@
void ANIM_OT_delete_keyframe_old(struct wmOperatorType *ot); // xxx rename and keep?
/* Keyframe managment operators for UI buttons. */
-
void ANIM_OT_insert_keyframe_button(struct wmOperatorType *ot);
void ANIM_OT_delete_keyframe_button(struct wmOperatorType *ot);
+/* ************ Drivers ********************** */
+
+/* Main Driver Management API calls:
+ * Add a new driver for the specified property on the given ID block
+ */
+short ANIM_add_driver (struct ID *id, const char rna_path[], int array_index, short flag);
+
+/* Main Driver Management API calls:
+ * Remove the driver for the specified property on the given ID block (if available)
+ */
+short ANIM_remove_driver (struct ID *id, const char rna_path[], int array_index, short flag);
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list