[Bf-blender-cvs] [c38ebf93e35] master: Added "Delete Invalid Drivers" operator

Sybren A. Stüvel noreply at git.blender.org
Wed Jan 17 12:13:11 CET 2018


Commit: c38ebf93e356a97b3013b075e1d98268df891809
Author: Sybren A. Stüvel
Date:   Wed Jan 17 12:12:37 2018 +0100
Branches: master
https://developer.blender.org/rBc38ebf93e356a97b3013b075e1d98268df891809

Added "Delete Invalid Drivers" operator

This operator is available in the graph editor in the Drivers mode, and
allows quick cleanup of drivers marked as 'invalid'.

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

M	release/scripts/startup/bl_ui/space_graph.py
M	source/blender/editors/space_graph/graph_edit.c
M	source/blender/editors/space_graph/graph_intern.h
M	source/blender/editors/space_graph/graph_ops.c

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

diff --git a/release/scripts/startup/bl_ui/space_graph.py b/release/scripts/startup/bl_ui/space_graph.py
index 4938512070e..e2407f1f2b2 100644
--- a/release/scripts/startup/bl_ui/space_graph.py
+++ b/release/scripts/startup/bl_ui/space_graph.py
@@ -201,6 +201,8 @@ class GRAPH_MT_channel(Menu):
         layout.operator_context = 'INVOKE_REGION_CHANNELS'
 
         layout.operator("anim.channels_delete")
+        if context.space_data.mode == 'DRIVERS':
+            layout.operator("graph.driver_delete_invalid")
 
         layout.separator()
         layout.operator("anim.channels_group")
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index 839fce48b1c..396dd93ebd9 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -2746,3 +2746,92 @@ void GRAPH_OT_driver_variables_paste(wmOperatorType *ot)
 }
 
 /* ************************************************************************** */
+typedef struct InvalidDriverInfo {
+	struct InvalidDriverInfo *next, *prev;
+	ID *id;
+	FCurve *fcu;
+} InvalidDriverInfo;
+
+static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
+{
+	bAnimContext ac;
+	ListBase anim_data = {NULL, NULL};
+	ListBase to_delete = {NULL, NULL};
+	bAnimListElem *ale;
+	InvalidDriverInfo *idi;
+	int filter;
+	bool ok = false;
+	unsigned int deleted = 0;
+
+	/* get editor data */
+	if (ANIM_animdata_get_context(C, &ac) == 0)
+		return OPERATOR_CANCELLED;
+
+	/* NOTE: we might need a scene update to evaluate the driver flags */
+
+	/* filter data */
+	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE);
+	ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
+
+	/* find invalid drivers */
+	for (ale = anim_data.first; ale; ale = ale->next) {
+		FCurve *fcu = (FCurve *)ale->data;
+		if (ELEM(NULL, fcu, fcu->driver)) {
+			continue;
+		}
+		if (!(fcu->driver->flag & DRIVER_FLAG_INVALID)) {
+			continue;
+		}
+
+		/* remember in a separate list so we don't iterate over the same collection we modify */
+		idi = MEM_callocN(sizeof(InvalidDriverInfo), "invalid driver info");
+		BLI_assert(idi != NULL);
+		idi->id = ale->id;
+		idi->fcu = fcu;
+		BLI_addtail(&to_delete, idi);
+	}
+
+	/* delete invalid drivers */
+	for (idi = to_delete.first; idi; idi = idi->next) {
+		ok |= ANIM_remove_driver(op->reports, idi->id, idi->fcu->rna_path, idi->fcu->array_index, 0);
+		if (!ok) {
+			break;
+		}
+		deleted += 1;
+	}
+
+	/* cleanup */
+	BLI_freelistN(&to_delete);
+	ANIM_animdata_freelist(&anim_data);
+
+	if (deleted > 0) {
+		/* notify the world of any changes */
+		DAG_relations_tag_update(CTX_data_main(C));
+		WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL);
+		WM_reportf(RPT_INFO, "Deleted %u drivers", deleted);
+	} else {
+		WM_report(RPT_INFO, "No drivers deleted");
+	}
+
+	/* successful or not? */
+	if (!ok) {
+		return OPERATOR_CANCELLED;
+	}
+
+	return OPERATOR_FINISHED;
+}
+
+void GRAPH_OT_driver_delete_invalid(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Delete Invalid Drivers";
+	ot->idname = "GRAPH_OT_driver_delete_invalid";
+	ot->description = "Deletes all visible drivers considered invalid";
+
+	/* api callbacks */
+	ot->exec = graph_driver_delete_invalid_exec;
+	ot->poll = graphop_visible_keyframes_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 534b712fd5e..6c375b23352 100644
--- a/source/blender/editors/space_graph/graph_intern.h
+++ b/source/blender/editors/space_graph/graph_intern.h
@@ -152,6 +152,7 @@ void GRAPH_OT_fmodifier_paste(struct wmOperatorType *ot);
 
 void GRAPH_OT_driver_variables_copy(struct wmOperatorType *ot);
 void GRAPH_OT_driver_variables_paste(struct wmOperatorType *ot);
+void GRAPH_OT_driver_delete_invalid(struct wmOperatorType *ot);
 
 /* ----------- */
 
diff --git a/source/blender/editors/space_graph/graph_ops.c b/source/blender/editors/space_graph/graph_ops.c
index 62275abcd02..57d8f45905d 100644
--- a/source/blender/editors/space_graph/graph_ops.c
+++ b/source/blender/editors/space_graph/graph_ops.c
@@ -468,6 +468,7 @@ void graphedit_operatortypes(void)
 	/* Drivers */
 	WM_operatortype_append(GRAPH_OT_driver_variables_copy);
 	WM_operatortype_append(GRAPH_OT_driver_variables_paste);
+	WM_operatortype_append(GRAPH_OT_driver_delete_invalid);
 }
 
 void ED_operatormacros_graph(void)



More information about the Bf-blender-cvs mailing list