Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2019-06-16 13:32:50 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2019-06-16 14:16:05 +0300
commit3e086af79ceb38345eed1c76472eb6fc8cfc1196 (patch)
tree19630b47cc3459f49d8313acd2f3b4521f1769c9 /source/blender/editors/space_graph
parent985f33719ce9108d35d5f37b4c7c79d81f708a0d (diff)
Drivers: fix Variable Copy & Paste in the edit popover.
Without these buttons the functionality of the popover is incomplete compared to the Graph Editor panel. To support this the operators have to read the active F-Curve from the context, instead of directly scanning animation data. Expanding the context would also help Python operators.
Diffstat (limited to 'source/blender/editors/space_graph')
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c82
-rw-r--r--source/blender/editors/space_graph/graph_edit.c52
-rw-r--r--source/blender/editors/space_graph/graph_intern.h1
-rw-r--r--source/blender/editors/space_graph/graph_utils.c10
4 files changed, 55 insertions, 90 deletions
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index cdb5e672f4a..301fefaf989 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -904,7 +904,7 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
DriverVar *dvar;
PointerRNA driver_ptr;
- uiLayout *col, *row;
+ uiLayout *col, *row, *row_outer;
uiBlock *block;
uiBut *but;
@@ -1005,61 +1005,41 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
uiItemS(layout);
/* add/copy/paste driver variables */
- if (is_popover) {
- /* add driver variable - add blank */
- row = uiLayoutRow(layout, true);
- block = uiLayoutGetBlock(row);
- but = uiDefIconTextBut(
- block,
- UI_BTYPE_BUT,
- B_IPO_DEPCHANGE,
- ICON_ADD,
- IFACE_("Add Input Variable"),
- 0,
- 0,
- 10 * UI_UNIT_X,
- UI_UNIT_Y,
- NULL,
- 0.0,
- 0.0,
- 0,
- 0,
- TIP_("Add a Driver Variable to keep track an input used by the driver"));
- UI_but_func_set(but, driver_add_var_cb, driver, NULL);
+ row_outer = uiLayoutRow(layout, false);
+ /* add driver variable - add blank */
+ row = uiLayoutRow(row_outer, true);
+ block = uiLayoutGetBlock(row);
+ but = uiDefIconTextBut(
+ block,
+ UI_BTYPE_BUT,
+ B_IPO_DEPCHANGE,
+ ICON_ADD,
+ IFACE_("Add Input Variable"),
+ 0,
+ 0,
+ 10 * UI_UNIT_X,
+ UI_UNIT_Y,
+ NULL,
+ 0.0,
+ 0.0,
+ 0,
+ 0,
+ TIP_("Add a Driver Variable to keep track of an input used by the driver"));
+ UI_but_func_set(but, driver_add_var_cb, driver, NULL);
+
+ if (is_popover) {
/* add driver variable - add using eyedropper */
/* XXX: will this operator work like this? */
uiItemO(row, "", ICON_EYEDROPPER, "UI_OT_eyedropper_driver");
}
- else {
- /* add driver variable */
- row = uiLayoutRow(layout, false);
- block = uiLayoutGetBlock(row);
- but = uiDefIconTextBut(block,
- UI_BTYPE_BUT,
- B_IPO_DEPCHANGE,
- ICON_ADD,
- IFACE_("Add Input Variable"),
- 0,
- 0,
- 10 * UI_UNIT_X,
- UI_UNIT_Y,
- NULL,
- 0.0,
- 0.0,
- 0,
- 0,
- TIP_("Driver variables ensure that all dependencies will be accounted "
- "for, ensuring that drivers will update correctly"));
- UI_but_func_set(but, driver_add_var_cb, driver, NULL);
- /* copy/paste (as sub-row) */
- row = uiLayoutRow(row, true);
- block = uiLayoutGetBlock(row);
+ /* copy/paste (as sub-row) */
+ row = uiLayoutRow(row_outer, true);
+ block = uiLayoutGetBlock(row);
- uiItemO(row, "", ICON_COPYDOWN, "GRAPH_OT_driver_variables_copy");
- uiItemO(row, "", ICON_PASTEDOWN, "GRAPH_OT_driver_variables_paste");
- }
+ uiItemO(row, "", ICON_COPYDOWN, "GRAPH_OT_driver_variables_copy");
+ uiItemO(row, "", ICON_PASTEDOWN, "GRAPH_OT_driver_variables_paste");
/* loop over targets, drawing them */
for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
@@ -1280,6 +1260,10 @@ static void graph_panel_drivers_popover(const bContext *C, Panel *pa)
if (fcu && fcu->driver) {
ID *id = ptr.id.data;
+ PointerRNA ptr_fcurve;
+ RNA_pointer_create(id, &RNA_FCurve, fcu, &ptr_fcurve);
+ uiLayoutSetContextPointer(layout, "active_editable_fcurve", &ptr_fcurve);
+
/* Driven Property Settings */
uiItemL(layout, IFACE_("Driven Property:"), ICON_NONE);
graph_draw_driven_property_panel(pa->layout, id, fcu);
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index b68efdc0ea0..dc5837e3fd1 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -2995,29 +2995,15 @@ void GRAPH_OT_fmodifier_paste(wmOperatorType *ot)
static int graph_driver_vars_copy_exec(bContext *C, wmOperator *op)
{
- bAnimContext ac;
- bAnimListElem *ale;
bool ok = false;
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0) {
- return OPERATOR_CANCELLED;
- }
-
- /* clear buffer first */
- ANIM_driver_vars_copybuf_free();
-
- /* get the active F-Curve */
- ale = get_active_fcurve_channel(&ac);
+ PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", &RNA_FCurve);
/* if this exists, call the copy driver vars API function */
- if (ale && ale->data) {
- FCurve *fcu = (FCurve *)ale->data;
+ FCurve *fcu = (FCurve *)ptr.data;
+ if (fcu) {
ok = ANIM_driver_vars_copy(op->reports, fcu);
-
- /* free temp data now */
- MEM_freeN(ale);
}
/* successful or not? */
@@ -3034,11 +3020,11 @@ void GRAPH_OT_driver_variables_copy(wmOperatorType *ot)
/* identifiers */
ot->name = "Copy Driver Variables";
ot->idname = "GRAPH_OT_driver_variables_copy";
- ot->description = "Copy the driver variables of the active F-Curve";
+ ot->description = "Copy the driver variables of the active driver";
/* api callbacks */
ot->exec = graph_driver_vars_copy_exec;
- ot->poll = graphop_active_fcurve_poll;
+ ot->poll = graphop_active_editable_fcurve_ctx_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
@@ -3048,34 +3034,18 @@ void GRAPH_OT_driver_variables_copy(wmOperatorType *ot)
static int graph_driver_vars_paste_exec(bContext *C, wmOperator *op)
{
- bAnimContext ac;
-
- ListBase anim_data = {NULL, NULL};
- bAnimListElem *ale;
- int filter;
-
const bool replace = RNA_boolean_get(op->ptr, "replace");
bool ok = false;
- /* get editor data */
- if (ANIM_animdata_get_context(C, &ac) == 0) {
- return OPERATOR_CANCELLED;
- }
+ PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", &RNA_FCurve);
- /* filter data */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_ACTIVE | ANIMFILTER_FOREDIT |
- ANIMFILTER_NODUPLIS);
- ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+ /* if this exists, call the paste driver vars API function */
+ FCurve *fcu = (FCurve *)ptr.data;
- /* paste variables */
- for (ale = anim_data.first; ale; ale = ale->next) {
- FCurve *fcu = (FCurve *)ale->data;
- ok |= ANIM_driver_vars_paste(op->reports, fcu, replace);
+ if (fcu) {
+ ok = ANIM_driver_vars_paste(op->reports, fcu, replace);
}
- /* cleanup */
- ANIM_animdata_freelist(&anim_data);
-
/* successful or not? */
if (ok) {
/* rebuild depsgraph, now that there are extra deps here */
@@ -3100,7 +3070,7 @@ void GRAPH_OT_driver_variables_paste(wmOperatorType *ot)
/* api callbacks */
ot->exec = graph_driver_vars_paste_exec;
- ot->poll = graphop_active_fcurve_poll;
+ ot->poll = graphop_active_editable_fcurve_ctx_poll;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/editors/space_graph/graph_intern.h b/source/blender/editors/space_graph/graph_intern.h
index 6ec8e54dce9..168c38b66a4 100644
--- a/source/blender/editors/space_graph/graph_intern.h
+++ b/source/blender/editors/space_graph/graph_intern.h
@@ -168,6 +168,7 @@ struct bAnimListElem *get_active_fcurve_channel(struct bAnimContext *ac);
bool graphop_visible_keyframes_poll(struct bContext *C);
bool graphop_editable_keyframes_poll(struct bContext *C);
bool graphop_active_fcurve_poll(struct bContext *C);
+bool graphop_active_editable_fcurve_ctx_poll(struct bContext *C);
bool graphop_selected_fcurve_poll(struct bContext *C);
/* ***************************************** */
diff --git a/source/blender/editors/space_graph/graph_utils.c b/source/blender/editors/space_graph/graph_utils.c
index d582ac557fa..b95ab48189c 100644
--- a/source/blender/editors/space_graph/graph_utils.c
+++ b/source/blender/editors/space_graph/graph_utils.c
@@ -44,6 +44,8 @@
#include "ED_screen.h"
#include "UI_interface.h"
+#include "RNA_access.h"
+
#include "graph_intern.h" // own include
/* ************************************************************** */
@@ -278,6 +280,14 @@ bool graphop_active_fcurve_poll(bContext *C)
return has_fcurve;
}
+/* has active F-Curve in the context that's editable */
+bool graphop_active_editable_fcurve_ctx_poll(bContext *C)
+{
+ PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", &RNA_FCurve);
+
+ return ptr.data != NULL;
+}
+
/* has selected F-Curve that's editable */
bool graphop_selected_fcurve_poll(bContext *C)
{