[Bf-blender-cvs] [4605e57b0f6] blender2.8: Drivers Workflow (T55145): Improvements to "Add Driver" workflow

Joshua Leung noreply at git.blender.org
Mon Jun 11 07:44:18 CEST 2018


Commit: 4605e57b0f60fef282afeae3756211fe6ac1c572
Author: Joshua Leung
Date:   Mon Jun 11 17:35:13 2018 +1200
Branches: blender2.8
https://developer.blender.org/rB4605e57b0f60fef282afeae3756211fe6ac1c572

Drivers Workflow (T55145): Improvements to "Add Driver" workflow

This commit implements a new behaviour for the "Add Driver" functionality
(invoked from the RMB menu on a property, or by pressing Ctrl-D).

Instead of spawning a context menu asking you to pick the way
you want to create a driver, it will now just create a driver on the
property under the mouse and then show the "Edit Drivers" popover so
that you can immediately start editing the properties of this driver.
This way, the whole process is more visual and feels less blocking /
constrained, with less upfront decisions needed immediately.

Notes:
* The new behaviour is equivalent to choosing the "Manually Create (Single)"
  and then doing a "Edit Driver" on the property
* Renamed the old "ANIM_OT_driver_button_add" operator to
  "ANIM_OT_driver_button_add_menu". It will probably go away
  in the near future, but it's better to keep it around for a
  while longer still until the new workflow settles down.

===================================================================

M	source/blender/editors/animation/drivers.c
M	source/blender/editors/interface/interface_handlers.c

===================================================================

diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index 03639b0ad77..28933f0e135 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -806,7 +806,7 @@ static const EnumPropertyItem *driver_mapping_type_itemsf(bContext *C, PointerRN
 }
 
 
-/* Add Driver Button Operator ------------------------ */
+/* Add Driver (With Menu) Button Operator ------------------------ */
 
 static int add_driver_button_poll(bContext *C)
 {
@@ -855,7 +855,7 @@ static int add_driver_button_none(bContext *C, wmOperator *op, short mapping_typ
 	}
 }
 
-static int add_driver_button_exec(bContext *C, wmOperator *op)
+static int add_driver_button_menu_exec(bContext *C, wmOperator *op)
 {
 	short mapping_type = RNA_enum_get(op->ptr, "mapping_type");
 	if (ELEM(mapping_type, CREATEDRIVER_MAPPING_NONE, CREATEDRIVER_MAPPING_NONE_ALL)) {
@@ -874,13 +874,13 @@ static int add_driver_button_exec(bContext *C, wmOperator *op)
 }
 
 /* Show menu or create drivers */
-static int add_driver_button_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+static int add_driver_button_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 {
 	PropertyRNA *prop;
 
 	if ((prop = RNA_struct_find_property(op->ptr, "mapping_type")) && RNA_property_is_set(op->ptr, prop)) {
 		/* Mapping Type is Set - Directly go into creating drivers */
-		return add_driver_button_exec(C, op);
+		return add_driver_button_menu_exec(C, op);
 	}
 	else {
 		/* Show menu */
@@ -890,19 +890,16 @@ static int add_driver_button_invoke(bContext *C, wmOperator *op, const wmEvent *
 	}
 }
 
-void ANIM_OT_driver_button_add(wmOperatorType *ot)
+void ANIM_OT_driver_button_add_menu(wmOperatorType *ot)
 {
 	/* identifiers */
-	ot->name = "Add Driver";
-	ot->idname = "ANIM_OT_driver_button_add";
+	ot->name = "Add Driver Menu";
+	ot->idname = "ANIM_OT_driver_button_add_menu";
 	ot->description = "Add driver(s) for the property(s) represented by the highlighted button";
 
 	/* callbacks */
-	/* NOTE: No exec, as we need all these to use the current context info
-	 * (especially the eyedropper, which is interactive)
-	 */
-	ot->invoke = add_driver_button_invoke;
-	ot->exec = add_driver_button_exec;
+	ot->invoke = add_driver_button_menu_invoke;
+	ot->exec = add_driver_button_menu_exec;
 	ot->poll = add_driver_button_poll;
 
 	/* flags */
@@ -914,6 +911,59 @@ void ANIM_OT_driver_button_add(wmOperatorType *ot)
 	RNA_def_enum_funcs(ot->prop, driver_mapping_type_itemsf);
 }
 
+/* Add Driver Button Operator ------------------------ */
+
+static int add_driver_button_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+	PointerRNA ptr = {{NULL}};
+	PropertyRNA *prop = NULL;
+	int index;
+
+	/* try to find driver using property retrieved from UI */
+	UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+	if (ptr.id.data && ptr.data && prop && RNA_property_animateable(&ptr, prop)) {
+		/* 1) Create a new "empty" driver for this property */
+		char *path = BKE_animdata_driver_path_hack(C, &ptr, prop, NULL);
+		short flags = CREATEDRIVER_WITH_DEFAULT_DVAR;
+		short success = 0;
+
+		if (path) {
+			success += ANIM_add_driver(op->reports, ptr.id.data, path, index, flags, DRIVER_TYPE_PYTHON);
+			MEM_freeN(path);
+		}
+
+		if (success) {
+			/* send updates */
+			UI_context_update_anim_flag(C);
+			DEG_relations_tag_update(CTX_data_main(C));
+			WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL);
+		}
+
+		/* 2) Show editing panel for setting up this driver */
+		/* TODO: Use a different one from the editing popever, so we can have the single/all toggle? */
+		UI_popover_panel_invoke(C, SPACE_IPO, RGN_TYPE_UI, "GRAPH_PT_drivers_popover", true, op->reports);
+	}
+
+	return OPERATOR_INTERFACE;
+}
+
+void ANIM_OT_driver_button_add(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Add Driver";
+	ot->idname = "ANIM_OT_driver_button_add";
+	ot->description = "Add driver for the property under the cursor";
+
+	/* callbacks */
+	/* NOTE: No exec, as we need all these to use the current context info */
+	ot->invoke = add_driver_button_invoke;
+	ot->poll = add_driver_button_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
+}
+
 /* Remove Driver Button Operator ------------------------ */
 
 static int remove_driver_button_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index b05dbe9c3b0..43eadc1ee32 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -6792,16 +6792,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
 		else if (is_anim) {
 			uiItemS(layout);
 
-			if (is_array_component) {
-				uiItemMenuEnumO(layout, C, "ANIM_OT_driver_button_add", "mapping_type",
-				                CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add Drivers"),
-				                ICON_DRIVER);
-			}
-			else {
-				uiItemMenuEnumO(layout, C, "ANIM_OT_driver_button_add", "mapping_type",
-				                CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add Driver"),
-				                ICON_DRIVER);
-			}
+			uiItemO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Add Driver"),
+			        ICON_DRIVER, "ANIM_OT_driver_button_add");
 
 			if (ANIM_driver_can_paste()) {
 				uiItemO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Paste Driver"),



More information about the Bf-blender-cvs mailing list