diff options
author | Joshua Leung <aligorith@gmail.com> | 2009-11-25 15:00:31 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2009-11-25 15:00:31 +0300 |
commit | 6c881a7a6d9a5168ebbc5aa5339ed4324aef2154 (patch) | |
tree | 0e030b38e800a18929231ef368fe5ea15a7c900c /source/blender/makesrna | |
parent | 4c5b43052035a5aa3b34b77acb558f06147f0292 (diff) |
AnimSys - Transform Locks + RNA:
The Animation System now respects the Transform Locks too (i.e. lock x-location, etc.) when writing settings. This means that it is no longer necessary to set up "constant drivers" to make sure some values don't get accidentally animated.
Internally, added a new callback for properties in RNA, which is responsible for checking if the item at some array-index is editable. This needs to be manually called for each place which uses rna to set settings for arrays (see the code changes in anim_sys.c for changes how to do this; the same thing needs to be done in the UI code too, and probably in py-api too)
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_define.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 20 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_internal_types.h | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_object.c | 70 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_pose.c | 70 |
8 files changed, 177 insertions, 2 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index f8d9b4d333b..d35e5632053 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -640,6 +640,7 @@ int RNA_property_enum_identifier(struct bContext *C, PointerRNA *ptr, PropertyRN StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop); int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop); +int RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index); int RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop); int RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop); diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h index 5ed0fb5194d..37abe44f128 100644 --- a/source/blender/makesrna/RNA_define.h +++ b/source/blender/makesrna/RNA_define.h @@ -155,6 +155,7 @@ void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive); void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *updatefunc); void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable); +void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable); void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength); void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set); diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 526178d7b26..3d4e128c3ac 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -1763,7 +1763,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr rna_print_c_string(f, prop->description); fprintf(f, ",\n\t"); fprintf(f, "%d,\n", prop->icon); fprintf(f, "\t%s, %s|%s, %s, %d, {%d, %d, %d}, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength); - fprintf(f, "\t%s, %d, %s,\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable)); + fprintf(f, "\t%s, %d, %s, %s,\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable)); if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop); else fprintf(f, "\t0, 0"); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index ce2e256004e..669810bb39b 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -982,6 +982,26 @@ int RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop) return (flag & PROP_EDITABLE) && (!id || !id->lib || (flag & PROP_LIB_EXCEPTION)); } +/* same as RNA_property_editable(), except this checks individual items in an array */ +int RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index) +{ + ID *id; + int flag; + + prop= rna_ensure_property(prop); + + /* if there is no function to do this for a given index, + * just resort to doing this on the whole array + */ + if (prop->itemeditable == NULL) + return RNA_property_editable(ptr, prop); + + flag= prop->itemeditable(ptr, index); + id= ptr->id.data; + + return (flag & PROP_EDITABLE) && (!id || !id->lib || (flag & PROP_LIB_EXCEPTION)); +} + int RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop) { int flag; diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 891911d5765..9bf5afdac48 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -1732,6 +1732,16 @@ void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable) if(editable) prop->editable= (EditableFunc)editable; } +void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable) +{ + if(!DefRNA.preprocess) { + fprintf(stderr, "RNA_def_property_editable_array_func: only during preprocessing.\n"); + return; + } + + if(editable) prop->itemeditable= (ItemEditableFunc)editable; +} + void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func) { if(!DefRNA.preprocess) { diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h index 46ed1fa055f..8a35f831c96 100644 --- a/source/blender/makesrna/intern/rna_internal_types.h +++ b/source/blender/makesrna/intern/rna_internal_types.h @@ -55,6 +55,7 @@ struct GHash; typedef void (*UpdateFunc)(struct bContext *C, struct PointerRNA *ptr); typedef int (*EditableFunc)(struct PointerRNA *ptr); +typedef int (*ItemEditableFunc)(struct PointerRNA *ptr, int index); typedef struct IDProperty* (*IDPropertiesFunc)(struct PointerRNA *ptr, int create); typedef struct StructRNA *(*StructRefineFunc)(struct PointerRNA *ptr); typedef char *(*StructPathFunc)(struct PointerRNA *ptr); @@ -152,8 +153,10 @@ struct PropertyRNA { UpdateFunc update; int noteflag; - /* callback for testing if editable/evaluated */ + /* callback for testing if editable */ EditableFunc editable; + /* callback for testing if array-item editable (if applicable) */ + ItemEditableFunc itemeditable; /* raw access */ int rawoffset; diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index d42e862052f..148f9614dcb 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -577,6 +577,71 @@ static void rna_Object_dimensions_set(PointerRNA *ptr, const float *value) } } +static int rna_Object_location_editable(PointerRNA *ptr, int index) +{ + Object *ob= (Object *)ptr->data; + + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (ob->protectflag & OB_LOCK_LOCX)) + return 0; + else if ((index == 1) && (ob->protectflag & OB_LOCK_LOCY)) + return 0; + else if ((index == 2) && (ob->protectflag & OB_LOCK_LOCZ)) + return 0; + else + return PROP_EDITABLE; +} + +static int rna_Object_scale_editable(PointerRNA *ptr, int index) +{ + Object *ob= (Object *)ptr->data; + + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (ob->protectflag & OB_LOCK_SCALEX)) + return 0; + else if ((index == 1) && (ob->protectflag & OB_LOCK_SCALEY)) + return 0; + else if ((index == 2) && (ob->protectflag & OB_LOCK_SCALEZ)) + return 0; + else + return PROP_EDITABLE; +} + +static int rna_Object_rotation_euler_editable(PointerRNA *ptr, int index) +{ + Object *ob= (Object *)ptr->data; + + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (ob->protectflag & OB_LOCK_ROTX)) + return 0; + else if ((index == 1) && (ob->protectflag & OB_LOCK_ROTY)) + return 0; + else if ((index == 2) && (ob->protectflag & OB_LOCK_ROTZ)) + return 0; + else + return PROP_EDITABLE; +} + +static int rna_Object_rotation_4d_editable(PointerRNA *ptr, int index) +{ + Object *ob= (Object *)ptr->data; + + /* only consider locks if locking components individually... */ + if (ob->protectflag & OB_LOCK_ROT4D) { + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (ob->protectflag & OB_LOCK_ROTW)) + return 0; + else if ((index == 1) && (ob->protectflag & OB_LOCK_ROTX)) + return 0; + else if ((index == 2) && (ob->protectflag & OB_LOCK_ROTY)) + return 0; + else if ((index == 3) && (ob->protectflag & OB_LOCK_ROTZ)) + return 0; + } + + return PROP_EDITABLE; +} + static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr) { @@ -1397,11 +1462,13 @@ static void rna_def_object(BlenderRNA *brna) /* transform */ prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION); RNA_def_property_float_sdna(prop, NULL, "loc"); + RNA_def_property_editable_array_func(prop, "rna_Object_location_editable"); RNA_def_property_ui_text(prop, "Location", "Location of the object."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update"); prop= RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION); RNA_def_property_float_sdna(prop, NULL, "quat"); + RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable"); RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update"); @@ -1411,11 +1478,13 @@ static void rna_def_object(BlenderRNA *brna) prop= RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE); RNA_def_property_array(prop, 4); // TODO: maybe we'll need to define the 'default value' getter too... RNA_def_property_float_funcs(prop, "rna_Object_rotation_axis_angle_get", "rna_Object_rotation_axis_angle_set", NULL); + RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable"); RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update"); prop= RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER); RNA_def_property_float_sdna(prop, NULL, "rot"); + RNA_def_property_editable_array_func(prop, "rna_Object_rotation_euler_editable"); RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update"); @@ -1428,6 +1497,7 @@ static void rna_def_object(BlenderRNA *brna) prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ); RNA_def_property_float_sdna(prop, NULL, "size"); + RNA_def_property_editable_array_func(prop, "rna_Object_scale_editable"); RNA_def_property_ui_text(prop, "Scale", "Scaling of the object."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Object_update"); diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index ed1bb373b6e..8d43d72c02e 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -445,6 +445,71 @@ static int rna_PoseChannel_constraints_remove(bPoseChannel *pchan, bContext *C, return remove_constraint_index(&pchan->constraints, index); } +static int rna_PoseChannel_location_editable(PointerRNA *ptr, int index) +{ + bPoseChannel *pchan= (bPoseChannel*)ptr->data; + + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (pchan->protectflag & OB_LOCK_LOCX)) + return 0; + else if ((index == 1) && (pchan->protectflag & OB_LOCK_LOCY)) + return 0; + else if ((index == 2) && (pchan->protectflag & OB_LOCK_LOCZ)) + return 0; + else + return PROP_EDITABLE; +} + +static int rna_PoseChannel_scale_editable(PointerRNA *ptr, int index) +{ + bPoseChannel *pchan= (bPoseChannel*)ptr->data; + + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (pchan->protectflag & OB_LOCK_SCALEX)) + return 0; + else if ((index == 1) && (pchan->protectflag & OB_LOCK_SCALEY)) + return 0; + else if ((index == 2) && (pchan->protectflag & OB_LOCK_SCALEZ)) + return 0; + else + return PROP_EDITABLE; +} + +static int rna_PoseChannel_rotation_euler_editable(PointerRNA *ptr, int index) +{ + bPoseChannel *pchan= (bPoseChannel*)ptr->data; + + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTX)) + return 0; + else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTY)) + return 0; + else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTZ)) + return 0; + else + return PROP_EDITABLE; +} + +static int rna_PoseChannel_rotation_4d_editable(PointerRNA *ptr, int index) +{ + bPoseChannel *pchan= (bPoseChannel*)ptr->data; + + /* only consider locks if locking components individually... */ + if (pchan->protectflag & OB_LOCK_ROT4D) { + /* only if the axis in question is locked, not editable... */ + if ((index == 0) && (pchan->protectflag & OB_LOCK_ROTW)) + return 0; + else if ((index == 1) && (pchan->protectflag & OB_LOCK_ROTX)) + return 0; + else if ((index == 2) && (pchan->protectflag & OB_LOCK_ROTY)) + return 0; + else if ((index == 3) && (pchan->protectflag & OB_LOCK_ROTZ)) + return 0; + } + + return PROP_EDITABLE; +} + #else static void rna_def_bone_group(BlenderRNA *brna) @@ -634,16 +699,19 @@ static void rna_def_pose_channel(BlenderRNA *brna) /* Transformation settings */ prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION); RNA_def_property_float_sdna(prop, NULL, "loc"); + RNA_def_property_editable_array_func(prop, "rna_PoseChannel_location_editable"); RNA_def_property_ui_text(prop, "Location", ""); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); prop= RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ); RNA_def_property_float_sdna(prop, NULL, "size"); + RNA_def_property_editable_array_func(prop, "rna_PoseChannel_scale_editable"); RNA_def_property_ui_text(prop, "Scale", ""); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); prop= RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION); RNA_def_property_float_sdna(prop, NULL, "quat"); + RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable"); RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); @@ -653,11 +721,13 @@ static void rna_def_pose_channel(BlenderRNA *brna) prop= RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE); RNA_def_property_array(prop, 4); // TODO: maybe we'll need to define the 'default value' getter too... RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_axis_angle_get", "rna_PoseChannel_rotation_axis_angle_set", NULL); + RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable"); RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); prop= RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER); RNA_def_property_float_sdna(prop, NULL, "eul"); + RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_euler_editable"); RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers."); RNA_def_property_update(prop, NC_OBJECT|ND_TRANSFORM, "rna_Pose_update"); |