diff --git a/source/blender/editors/animation/drivers.cc b/source/blender/editors/animation/drivers.cc index 63754a82b58..87970a7b31a 100644 --- a/source/blender/editors/animation/drivers.cc +++ b/source/blender/editors/animation/drivers.cc @@ -520,49 +520,39 @@ int ANIM_add_driver( return done_tot; } -bool ANIM_remove_driver( - ReportList * /*reports*/, ID *id, const char rna_path[], int array_index, short /*flag*/) +bool ANIM_remove_driver(ID *id, const char rna_path[], int array_index) { - AnimData *adt; - FCurve *fcu; - bool success = false; - - /* we don't check the validity of the path here yet, but it should be ok... */ - adt = BKE_animdata_from_id(id); - - if (adt) { - if (array_index == -1) { - /* step through all drivers, removing all of those with the same base path */ - FCurve *fcu_iter = static_cast(adt->drivers.first); - - while ((fcu = BKE_fcurve_iter_step(fcu_iter, rna_path)) != nullptr) { - /* Store the next fcurve for looping. */ - fcu_iter = fcu->next; - - /* remove F-Curve from driver stack, then free it */ - BLI_remlink(&adt->drivers, fcu); - BKE_fcurve_free(fcu); - - /* done successfully */ - success = true; - } - } - else { - /* find the matching driver and remove it only - * NOTE: here is one of the places where we don't want new F-Curve + Driver added! - * so 'add' var must be 0 - */ - fcu = verify_driver_fcurve(id, rna_path, array_index, DRIVER_FCURVE_LOOKUP_ONLY); - if (fcu) { - BLI_remlink(&adt->drivers, fcu); - BKE_fcurve_free(fcu); - - success = true; - } - } + AnimData *adt = BKE_animdata_from_id(id); + if (!adt) { + return false; } - return success; + if (array_index >= 0) { + /* Simple case: Find the matching driver and remove it. */ + FCurve *fcu = verify_driver_fcurve(id, rna_path, array_index, DRIVER_FCURVE_LOOKUP_ONLY); + if (!fcu) { + return false; + } + + BLI_remlink(&adt->drivers, fcu); + BKE_fcurve_free(fcu); + return true; + } + + /* Step through all drivers, removing all of those with the same RNA path. */ + bool any_driver_removed = false; + FCurve *fcu_iter = static_cast(adt->drivers.first); + FCurve *fcu; + while ((fcu = BKE_fcurve_iter_step(fcu_iter, rna_path)) != nullptr) { + /* Store the next fcurve for looping. */ + fcu_iter = fcu->next; + + BLI_remlink(&adt->drivers, fcu); + BKE_fcurve_free(fcu); + + any_driver_removed = true; + } + return any_driver_removed; } /* ************************************************** */ @@ -1101,7 +1091,7 @@ static int remove_driver_button_exec(bContext *C, wmOperator *op) if (ptr.owner_id && ptr.data && prop) { if (const std::optional path = RNA_path_from_ID_to_property(&ptr, prop)) { - changed = ANIM_remove_driver(op->reports, ptr.owner_id, path->c_str(), index, 0); + changed = ANIM_remove_driver(ptr.owner_id, path->c_str(), index); } } diff --git a/source/blender/editors/include/ED_keyframing.hh b/source/blender/editors/include/ED_keyframing.hh index ea84b9b9f66..021921dcdd9 100644 --- a/source/blender/editors/include/ED_keyframing.hh +++ b/source/blender/editors/include/ED_keyframing.hh @@ -353,10 +353,11 @@ int ANIM_add_driver( /** * \brief Main Driver Management API calls. * - * Remove the driver for the specified property on the given ID block (if available). + * Remove the driver for the specified property on the given ID block. + * + * \return Whether any driver was removed. */ -bool ANIM_remove_driver( - ReportList *reports, ID *id, const char rna_path[], int array_index, short flag); +bool ANIM_remove_driver(ID *id, const char rna_path[], int array_index); /* -------- */ diff --git a/source/blender/editors/space_graph/graph_edit.cc b/source/blender/editors/space_graph/graph_edit.cc index a40ab96fe6f..e4881f0e0c4 100644 --- a/source/blender/editors/space_graph/graph_edit.cc +++ b/source/blender/editors/space_graph/graph_edit.cc @@ -3295,7 +3295,7 @@ void GRAPH_OT_driver_variables_paste(wmOperatorType *ot) /** \name Delete Invalid Drivers Operator * \{ */ -static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op) +static int graph_driver_delete_invalid_exec(bContext *C, wmOperator * /*op*/) { bAnimContext ac; ListBase anim_data = {nullptr, nullptr}; @@ -3326,7 +3326,7 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op) continue; } - ok |= ANIM_remove_driver(op->reports, ale->id, fcu->rna_path, fcu->array_index, 0); + ok |= ANIM_remove_driver(ale->id, fcu->rna_path, fcu->array_index); if (!ok) { break; } diff --git a/source/blender/editors/space_outliner/outliner_edit.cc b/source/blender/editors/space_outliner/outliner_edit.cc index 331cafd2ea9..0ef30b4189c 100644 --- a/source/blender/editors/space_outliner/outliner_edit.cc +++ b/source/blender/editors/space_outliner/outliner_edit.cc @@ -1832,8 +1832,7 @@ static void do_outliner_drivers_editop(SpaceOutliner *space_outliner, break; } case DRIVERS_EDITMODE_REMOVE: { - /* remove driver matching the information obtained (only if valid) */ - ANIM_remove_driver(reports, id, path, array_index, dflags); + ANIM_remove_driver(id, path, array_index); break; } } diff --git a/source/blender/python/intern/bpy_rna_anim.cc b/source/blender/python/intern/bpy_rna_anim.cc index 3eb877d73d6..ad77f89c82a 100644 --- a/source/blender/python/intern/bpy_rna_anim.cc +++ b/source/blender/python/intern/bpy_rna_anim.cc @@ -669,7 +669,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args) BKE_reports_init(&reports, RPT_STORE); - result = ANIM_remove_driver(&reports, (ID *)self->ptr.owner_id, path_full, index, 0); + result = ANIM_remove_driver(self->ptr.owner_id, path_full, index); if (path != path_full) { MEM_freeN((void *)path_full);