From 567ee32f14304a462e59bde2de92b10861ad7c86 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 16 Nov 2009 11:11:16 +0000 Subject: - fcurve modifiers.new()/remove()/active - renamed .add() to .new() for rna collection functions since they dont add an existing item. - remove 'name' as an argument from the new driver target function, better to keep the api minimal and let scripters use the data api for editing values after. - added some api functions to keep rna api from becoming a mess. --- source/blender/makesrna/intern/rna_armature.c | 5 +- source/blender/makesrna/intern/rna_fcurve.c | 93 ++++++++++++++++++++++----- source/blender/makesrna/intern/rna_group.c | 7 +- source/blender/makesrna/intern/rna_object.c | 40 +++--------- source/blender/makesrna/intern/rna_pose.c | 42 +++--------- source/blender/makesrna/intern/rna_scene.c | 8 +-- 6 files changed, 103 insertions(+), 92 deletions(-) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index 45710f11a4e..f1164cda675 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -633,11 +633,11 @@ static void rna_def_armature_bones(BlenderRNA *brna, PropertyRNA *cprop) // FunctionRNA *func; // PropertyRNA *parm; + RNA_def_property_srna(cprop, "ArmatureBones"); srna= RNA_def_struct(brna, "ArmatureBones", NULL); RNA_def_struct_sdna(srna, "bArmature"); RNA_def_struct_ui_text(srna, "Armature Bones", "Collection of armature bones."); - RNA_def_property_srna(cprop, "ArmatureBones"); prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Bone"); @@ -659,12 +659,11 @@ static void rna_def_armature_edit_bones(BlenderRNA *brna, PropertyRNA *cprop) // FunctionRNA *func; // PropertyRNA *parm; + RNA_def_property_srna(cprop, "ArmatureEditBones"); srna= RNA_def_struct(brna, "ArmatureEditBones", NULL); RNA_def_struct_sdna(srna, "bArmature"); RNA_def_struct_ui_text(srna, "Armature EditBones", "Collection of armature edit bones."); - RNA_def_property_srna(cprop, "ArmatureEditBones"); - prop= RNA_def_property(srna, "edit_bones", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "EditBone"); RNA_def_property_pointer_sdna(prop, NULL, "act_edbone"); diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index 84353cb273f..c83781a518a 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -190,18 +190,9 @@ static void rna_FCurve_RnaPath_set(PointerRNA *ptr, const char *value) fcu->rna_path= NULL; } -DriverTarget *rna_Driver_add_target(ChannelDriver *driver, char *name) +DriverTarget *rna_Driver_new_target(ChannelDriver *driver) { - DriverTarget *dtar= driver_add_new_target(driver); - - /* set the name if given */ - if (name && name[0]) { - BLI_strncpy(dtar->name, name, 64); - BLI_uniquename(&driver->targets, dtar, "var", '_', offsetof(DriverTarget, name), 64); - } - - /* return this target for the users to play with */ - return dtar; + return driver_add_new_target(driver); } void rna_Driver_remove_target(ChannelDriver *driver, DriverTarget *dtar) @@ -210,8 +201,31 @@ void rna_Driver_remove_target(ChannelDriver *driver, DriverTarget *dtar) driver_free_target(driver, dtar); } -#else +static PointerRNA rna_FCurve_active_modifier_get(PointerRNA *ptr) +{ + FCurve *fcu= (FCurve*)ptr->data; + FModifier *fcm= find_active_fmodifier(&fcu->modifiers); + return rna_pointer_inherit_refine(ptr, &RNA_FModifier, fcm); +} + +static void rna_FCurve_active_modifier_set(PointerRNA *ptr, PointerRNA value) +{ + FCurve *fcu= (FCurve*)ptr->data; + set_active_fmodifier(&fcu->modifiers, (FModifier *)value.data); +} + +static FModifier *rna_FCurve_modifiers_new(FCurve *fcu, bContext *C, int type) +{ + return add_fmodifier(&fcu->modifiers, type); +} + +static int rna_FCurve_modifiers_remove(FCurve *fcu, bContext *C, int index) +{ + return remove_fmodifier_index(&fcu->modifiers, index); +} + +#else static void rna_def_fmodifier_generator(BlenderRNA *brna) { @@ -623,21 +637,18 @@ static void rna_def_channeldriver_targets(BlenderRNA *brna, PropertyRNA *cprop) FunctionRNA *func; PropertyRNA *parm; + RNA_def_property_srna(cprop, "ChannelDriverTargets"); srna= RNA_def_struct(brna, "ChannelDriverTargets", NULL); RNA_def_struct_sdna(srna, "ChannelDriver"); RNA_def_struct_ui_text(srna, "ChannelDriver Targets", "Collection of channel driver Targets."); - RNA_def_property_srna(cprop, "ChannelDriverTargets"); - /* add target */ - func= RNA_def_function(srna, "add", "rna_Driver_add_target"); + func= RNA_def_function(srna, "new", "rna_Driver_new_target"); RNA_def_function_ui_description(func, "Add a new target for the driver."); /* return type */ parm= RNA_def_pointer(func, "target", "DriverTarget", "", "Newly created Driver Target."); RNA_def_function_return(func, parm); - /* optional name parameter */ - parm= RNA_def_string(func, "name", "", 64, "Name", "Name to use in scripted expressions/functions. (No spaces or dots are allowed. Also, must not start with a symbol or digit)"); /* remove target */ func= RNA_def_function(srna, "remove", "rna_Driver_remove_target"); @@ -708,6 +719,52 @@ static void rna_def_fpoint(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Point", "Point coordinates"); } +/* channeldriver.targets.* */ +static void rna_def_fcurve_modifiers(BlenderRNA *brna, PropertyRNA *cprop) +{ + /* add target */ + StructRNA *srna; + PropertyRNA *prop; + + FunctionRNA *func; + PropertyRNA *parm; + + RNA_def_property_srna(cprop, "FCurveModifiers"); + srna= RNA_def_struct(brna, "FCurveModifiers", NULL); + RNA_def_struct_sdna(srna, "FCurve"); + RNA_def_struct_ui_text(srna, "FCurve Modifiers", "Collection of fcurve modifiers."); + + + /* Collection active property */ + prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "FModifier"); + RNA_def_property_pointer_funcs(prop, "rna_FCurve_active_modifier_get", "rna_FCurve_active_modifier_set", NULL); + RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Active fcurve modifier", "Active fcurve modifier."); + + + /* Constraint collection */ + func= RNA_def_function(srna, "new", "rna_FCurve_modifiers_new"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Add a constraint to this object"); + /* return type */ + parm= RNA_def_pointer(func, "fmodifier", "FModifier", "", "New fmodifier."); + RNA_def_function_return(func, parm); + /* object to add */ + parm= RNA_def_enum(func, "type", fmodifier_type_items, 1, "", "Constraint type to add."); + RNA_def_property_flag(parm, PROP_REQUIRED); + + func= RNA_def_function(srna, "remove", "rna_FCurve_modifiers_remove"); + RNA_def_function_flag(func, FUNC_USE_CONTEXT); + RNA_def_function_ui_description(func, "Remove a modifier from this fcurve."); + /* return type */ + parm= RNA_def_boolean(func, "success", 0, "Success", "Removed the constraint successfully."); + 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); +} + static void rna_def_fcurve(BlenderRNA *brna) { StructRNA *srna; @@ -769,6 +826,8 @@ static void rna_def_fcurve(BlenderRNA *brna) prop= RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "FModifier"); RNA_def_property_ui_text(prop, "Modifiers", "Modifiers affecting the shape of the F-Curve."); + + rna_def_fcurve_modifiers(brna, prop); } /* *********************** */ diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c index a1b5bf85bf7..7cd0bac402a 100644 --- a/source/blender/makesrna/intern/rna_group.c +++ b/source/blender/makesrna/intern/rna_group.c @@ -72,11 +72,10 @@ static void rna_def_group_objects(BlenderRNA *brna, PropertyRNA *cprop) FunctionRNA *func; PropertyRNA *parm; - srna= RNA_def_struct(brna, "GroupObjectCollection", NULL); + RNA_def_property_srna(cprop, "GroupObjects"); + srna= RNA_def_struct(brna, "GroupObjects", NULL); RNA_def_struct_sdna(srna, "Group"); - RNA_def_struct_ui_text(srna, "GroupObjects", "Collection of group objects."); - - RNA_def_property_srna(cprop, "GroupObjectCollection"); + RNA_def_struct_ui_text(srna, "Group Objects", "Collection of group objects."); /* add object */ func= RNA_def_function(srna, "link", "rna_Group_objects_link"); diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index b1a647c5add..8f5a9520502 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -865,29 +865,17 @@ static PointerRNA rna_Object_collision_get(PointerRNA *ptr) static PointerRNA rna_Object_active_constraint_get(PointerRNA *ptr) { Object *ob= (Object*)ptr->id.data; - bConstraint *con; - for(con= ob->constraints.first; con; con= con->next) { - if(con->flag & CONSTRAINT_ACTIVE) - break; - } - + bConstraint *con= find_active_constraint(&ob->constraints); return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con); } static void rna_Object_active_constraint_set(PointerRNA *ptr, PointerRNA value) { Object *ob= (Object*)ptr->id.data; - bConstraint *con; - for(con= ob->constraints.first; con; con= con->next) { - if(value.data==con) - con->flag |= CONSTRAINT_ACTIVE; - else - con->flag &= ~CONSTRAINT_ACTIVE; - } + set_active_constraint(&ob->constraints, (bConstraint *)value.data); } - -static bConstraint *rna_Object_constraints_add(Object *object, bContext *C, int type) +static bConstraint *rna_Object_constraints_new(Object *object, bContext *C, int type) { WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); return add_ob_constraint(object, NULL, type); @@ -895,20 +883,13 @@ static bConstraint *rna_Object_constraints_add(Object *object, bContext *C, int static int rna_Object_constraints_remove(Object *object, bContext *C, int index) { - bConstraint *con= BLI_findlink(&object->constraints, index); - - if(con) { - free_constraint_data(con); - BLI_freelinkN(&object->constraints, con); - + int ok = remove_constraint_index(&object->constraints, index); + if(ok) { ED_object_constraint_set_active(object, NULL); WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, object); - - return 1; - } - else { - return 0; } + + return ok; } #else @@ -1187,12 +1168,11 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop) FunctionRNA *func; PropertyRNA *parm; + RNA_def_property_srna(cprop, "ObjectConstraints"); srna= RNA_def_struct(brna, "ObjectConstraints", NULL); RNA_def_struct_sdna(srna, "Object"); RNA_def_struct_ui_text(srna, "Object Constraints", "Collection of object constraints."); - RNA_def_property_srna(cprop, "ObjectConstraints"); - /* Collection active property */ prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); @@ -1203,9 +1183,9 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop) /* Constraint collection */ - func= RNA_def_function(srna, "add", "rna_Object_constraints_add"); + func= RNA_def_function(srna, "new", "rna_Object_constraints_new"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); - RNA_def_function_ui_description(func, "Add a constraint to this object"); + 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); diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index 5efc4eb3fc0..a0685a00fe0 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -419,30 +419,17 @@ static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *r static PointerRNA rna_PoseChannel_active_constraint_get(PointerRNA *ptr) { bPoseChannel *pchan= (bPoseChannel*)ptr->data; - - bConstraint *con; - for(con= pchan->constraints.first; con; con= con->next) { - if(con->flag & CONSTRAINT_ACTIVE) - break; - } - + bConstraint *con= find_active_constraint(&pchan->constraints); return rna_pointer_inherit_refine(ptr, &RNA_Constraint, con); } static void rna_PoseChannel_active_constraint_set(PointerRNA *ptr, PointerRNA value) { bPoseChannel *pchan= (bPoseChannel*)ptr->data; - - bConstraint *con; - for(con= pchan->constraints.first; con; con= con->next) { - if(value.data==con) - con->flag |= CONSTRAINT_ACTIVE; - else - con->flag &= ~CONSTRAINT_ACTIVE; - } + set_active_constraint(&pchan->constraints, (bConstraint *)value.data); } -static bConstraint *rna_PoseChannel_constraints_add(bPoseChannel *pchan, bContext *C, int type) +static bConstraint *rna_PoseChannel_constraints_new(bPoseChannel *pchan, bContext *C, int type) { //WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object); // TODO, pass object also @@ -452,20 +439,10 @@ static bConstraint *rna_PoseChannel_constraints_add(bPoseChannel *pchan, bContex static int rna_PoseChannel_constraints_remove(bPoseChannel *pchan, bContext *C, int index) { - bConstraint *con= BLI_findlink(&pchan->constraints, index); - - if(con) { - free_constraint_data(con); - BLI_freelinkN(&pchan->constraints, con); - - //ED_object_constraint_set_active(object, NULL); - //WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, object); - - return 1; - } - else { - return 0; - } + // TODO + //ED_object_constraint_set_active(object, NULL); + //WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, object); + return remove_constraint_index(&pchan->constraints, index); } #else @@ -549,12 +526,11 @@ static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cpro FunctionRNA *func; PropertyRNA *parm; + RNA_def_property_srna(cprop, "PoseChannelConstraints"); srna= RNA_def_struct(brna, "PoseChannelConstraints", NULL); RNA_def_struct_sdna(srna, "bPoseChannel"); RNA_def_struct_ui_text(srna, "PoseChannel Constraints", "Collection of object constraints."); - RNA_def_property_srna(cprop, "PoseChannelConstraints"); - /* Collection active property */ prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Constraint"); @@ -564,7 +540,7 @@ static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cpro /* Constraint collection */ - func= RNA_def_function(srna, "add", "rna_PoseChannel_constraints_add"); + func= RNA_def_function(srna, "new", "rna_PoseChannel_constraints_new"); RNA_def_function_flag(func, FUNC_USE_CONTEXT); RNA_def_function_ui_description(func, "Add a constraint to this object"); /* return type */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 4f681c45e2d..6bb8001ffb0 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -2178,13 +2178,12 @@ static void rna_def_scene_objects(BlenderRNA *brna, PropertyRNA *cprop) FunctionRNA *func; PropertyRNA *parm; - + + RNA_def_property_srna(cprop, "SceneObjects"); srna= RNA_def_struct(brna, "SceneObjects", NULL); RNA_def_struct_sdna(srna, "Object"); RNA_def_struct_ui_text(srna, "Scene Objects", "Collection of scene objects."); - RNA_def_property_srna(cprop, "SceneObjects"); - #if 0 /* add object */ func= RNA_def_function(srna, "link", "rna_Scene_objects_link"); @@ -2229,12 +2228,11 @@ static void rna_def_scene_bases(BlenderRNA *brna, PropertyRNA *cprop) // FunctionRNA *func; // PropertyRNA *parm; + RNA_def_property_srna(cprop, "SceneBases"); srna= RNA_def_struct(brna, "SceneBases", NULL); RNA_def_struct_sdna(srna, "Scene"); RNA_def_struct_ui_text(srna, "Scene Bases", "Collection of scene bases."); - RNA_def_property_srna(cprop, "SceneBases"); - prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "ObjectBase"); RNA_def_property_pointer_sdna(prop, NULL, "basact"); -- cgit v1.2.3