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-07-31 18:42:03 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2019-08-04 13:58:15 +0300
commit47335b4e61db11e1ee2e38f421dc86fa3c3dd375 (patch)
treeffc2ccfed4d77158ce42a6f7151693f39e7160b3 /source/blender/editors/interface/interface_ops.c
parenta2fe386153ee976bf5b687257f117ca4efb1ef8f (diff)
Add a new Copy As Driver context menu option for properties.
It is a very common need to create drivers that set the value of a property to the value of some other property, but it currently requires multiple actions: Copy Data Path on the input property, adding a driver to the output property, selecting the input ID reference, and pasting the path. This adds a new Copy As Driver context menu option, which creates a complete driver in the clipboard that reads the current property, so all that remains is to paste it to the output property. It is also possible to paste just the new driver variable into an existing driver to combine multiple inputs. Reviewers: brecht, billreynish Differential Revision: https://developer.blender.org/D5382
Diffstat (limited to 'source/blender/editors/interface/interface_ops.c')
-rw-r--r--source/blender/editors/interface/interface_ops.c81
1 files changed, 77 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index f2b2a478ba9..f5a894d7620 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -65,6 +65,9 @@
#include "ED_object.h"
#include "ED_paint.h"
+/* for Copy As Driver */
+#include "ED_keyframing.h"
+
/* only for UI_OT_editsource */
#include "ED_screen.h"
#include "BKE_main.h"
@@ -153,23 +156,92 @@ static void UI_OT_copy_data_path_button(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-static bool copy_python_command_button_poll(bContext *C)
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Copy As Driver Operator
+ * \{ */
+
+static bool copy_as_driver_button_poll(bContext *C)
{
- uiBut *but = UI_context_active_but_get(C);
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ char *path;
+ int index;
- if (but && (but->optype != NULL)) {
- return 1;
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ if (ptr.id.data && ptr.data && prop &&
+ ELEM(RNA_property_type(prop), PROP_BOOLEAN, PROP_INT, PROP_FLOAT, PROP_ENUM)) {
+ path = RNA_path_from_ID_to_property(&ptr, prop);
+
+ if (path) {
+ MEM_freeN(path);
+ return 1;
+ }
}
return 0;
}
+static int copy_as_driver_button_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ /* try to create driver using property retrieved from UI */
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ if (ptr.id.data && ptr.data && prop) {
+ int dim = RNA_property_array_dimension(&ptr, prop, NULL);
+ char *path = RNA_path_from_ID_to_property_index(&ptr, prop, dim, index);
+
+ if (path) {
+ ANIM_copy_as_driver(ptr.id.data, path, RNA_property_identifier(prop));
+ MEM_freeN(path);
+ return OPERATOR_FINISHED;
+ }
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+static void UI_OT_copy_as_driver_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Copy As New Driver";
+ ot->idname = "UI_OT_copy_as_driver_button";
+ ot->description =
+ "Create a new driver with this property as input, and copy it to the "
+ "clipboard. Use Paste Driver to add it to the target property, or Paste "
+ "Driver Variables to extend an existing driver";
+
+ /* callbacks */
+ ot->exec = copy_as_driver_button_exec;
+ ot->poll = copy_as_driver_button_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER;
+}
+
/** \} */
/* -------------------------------------------------------------------- */
/** \name Copy Python Command Operator
* \{ */
+static bool copy_python_command_button_poll(bContext *C)
+{
+ uiBut *but = UI_context_active_but_get(C);
+
+ if (but && (but->optype != NULL)) {
+ return 1;
+ }
+
+ return 0;
+}
+
static int copy_python_command_button_exec(bContext *C, wmOperator *UNUSED(op))
{
uiBut *but = UI_context_active_but_get(C);
@@ -1668,6 +1740,7 @@ static void UI_OT_drop_color(wmOperatorType *ot)
void ED_operatortypes_ui(void)
{
WM_operatortype_append(UI_OT_copy_data_path_button);
+ WM_operatortype_append(UI_OT_copy_as_driver_button);
WM_operatortype_append(UI_OT_copy_python_command_button);
WM_operatortype_append(UI_OT_reset_default_button);
WM_operatortype_append(UI_OT_assign_default_button);