From adae794233e168aa4046b560c43db6b48725cc08 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 24 Aug 2010 06:40:28 +0000 Subject: py/rna remove functions now all work in a similar way. - some remove() functions took an int argument rather then the item to remove. - disallow None argument. - raise an error if the item isnt in the collection. --- source/blender/makesrna/intern/rna_object.c | 37 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'source/blender/makesrna/intern/rna_object.c') diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 7cfff23b1c6..f4449f4ebd0 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -1014,21 +1014,22 @@ static void rna_Object_active_constraint_set(PointerRNA *ptr, PointerRNA value) constraints_set_active(&ob->constraints, (bConstraint *)value.data); } -static bConstraint *rna_Object_constraint_new(Object *object, int type) +static bConstraint *rna_Object_constraints_new(Object *object, int type) { WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); return add_ob_constraint(object, NULL, type); } -static int rna_Object_constraint_remove(Object *object, int index) +static void rna_Object_constraints_remove(Object *object, ReportList *reports, bConstraint *con) { - int ok = remove_constraint_index(&object->constraints, index); - if(ok) { - ED_object_constraint_set_active(object, NULL); - WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT, object); + if(BLI_findindex(&object->constraints, con) == -1) { + BKE_reportf(reports, RPT_ERROR, "Constraint '%s' not found in object '%s'.", con->name, object->id.name+2); + return; } - return ok; + remove_constraint(&object->constraints, con); + ED_object_constraint_set_active(object, NULL); + WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT, object); } static ModifierData *rna_Object_modifier_new(Object *object, bContext *C, ReportList *reports, char *name, int type) @@ -1380,23 +1381,21 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop) /* Constraint collection */ - func= RNA_def_function(srna, "new", "rna_Object_constraint_new"); + func= RNA_def_function(srna, "new", "rna_Object_constraints_new"); RNA_def_function_ui_description(func, "Add a new constraint to this object"); - /* return type */ - parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint."); - RNA_def_function_return(func, parm); /* object to add */ parm= RNA_def_enum(func, "type", constraint_type_items, 1, "", "Constraint type to add."); RNA_def_property_flag(parm, PROP_REQUIRED); - - func= RNA_def_function(srna, "remove", "rna_Object_constraint_remove"); - RNA_def_function_ui_description(func, "Remove a constraint from this object."); /* return type */ - parm= RNA_def_boolean(func, "success", 0, "Success", "Removed the constraint successfully."); + parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint."); RNA_def_function_return(func, parm); - /* object to add */ - parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX); - RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "remove", "rna_Object_constraints_remove"); + RNA_def_function_ui_description(func, "Remove a constraint from this object."); + RNA_def_function_flag(func, FUNC_USE_REPORTS); + /* constraint to remove */ + parm= RNA_def_pointer(func, "constraint", "Constraint", "", "Removed constraint."); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); } /* object.modifiers */ @@ -1444,7 +1443,7 @@ static void rna_def_object_modifiers(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_function_ui_description(func, "Remove an existing modifier from the object."); /* target to remove*/ parm= RNA_def_pointer(func, "modifier", "Modifier", "", "Modifier to remove."); - RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); } /* object.particle_systems */ -- cgit v1.2.3