Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-11-11 22:58:30 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-11-11 22:58:30 +0300
commit53250f85dbecdc4cdd6eded772972b137f3f8c6c (patch)
tree2deea82dca566fd752753d34b7df3e38ba4d0216 /source/blender/makesrna
parent047ee04418a5a785177258dd965f94571d553b57 (diff)
object.constraints.add()/remove()/active, same for PoseChannel
modified internal api for minimal rna wrapper functions. TODO - missing updates for pose channels - typecheck for pose/object constraints
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/rna_internal.h1
-rw-r--r--source/blender/makesrna/intern/rna_object.c35
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c48
-rw-r--r--source/blender/makesrna/intern/rna_pose.c40
-rw-r--r--source/blender/makesrna/intern/rna_pose_api.c58
-rw-r--r--source/blender/makesrna/intern/rna_scene.c4
6 files changed, 183 insertions, 3 deletions
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index d90b4f17c85..64af7e07fd5 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -213,6 +213,7 @@ void RNA_api_main(struct StructRNA *srna);
void RNA_api_material(StructRNA *srna);
void RNA_api_mesh(struct StructRNA *srna);
void RNA_api_object(struct StructRNA *srna);
+void RNA_api_pose_channel(struct StructRNA *srna);
void RNA_api_scene(struct StructRNA *srna);
void RNA_api_text(struct StructRNA *srna);
void RNA_api_ui_layout(struct StructRNA *srna);
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 63a7d68a0cd..652d018c345 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -86,6 +86,7 @@ EnumPropertyItem object_type_items[] = {
#include "BLI_math.h"
#include "DNA_key_types.h"
+#include "DNA_constraint_types.h"
#include "BKE_armature.h"
#include "BKE_bullet.h"
@@ -859,6 +860,30 @@ static PointerRNA rna_Object_collision_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_CollisionSettings, ob->pd);
}
+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;
+ }
+
+ 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;
+ }
+}
+
#else
static void rna_def_vertex_group(BlenderRNA *brna)
@@ -1428,6 +1453,16 @@ static void rna_def_object(BlenderRNA *brna)
prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Constraint");
RNA_def_property_ui_text(prop, "Constraints", "Constraints of the object.");
+ RNA_def_property_collection_funcs(prop, 0, 0, 0, 0, 0, 0, 0, "constraints__add", "constraints__remove");
+
+ { /* Collection active property */
+ PropertyRNA *prop_act= RNA_def_property(srna, "constraints__active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop_act, "Constraint");
+ RNA_def_property_pointer_funcs(prop_act, "rna_Object_active_constraint_get", "rna_Object_active_constraint_set", NULL);
+ RNA_def_property_flag(prop_act, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop_act, "Active Constraint", "Active Object constraint.");
+ RNA_def_property_collection_active(prop, prop_act);
+ }
prop= RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Modifier");
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 8fcc4e49986..6435102d8e4 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -33,6 +33,7 @@
#include "RNA_define.h"
#include "RNA_types.h"
+#include "RNA_enum_types.h"
#include "DNA_object_types.h"
@@ -50,6 +51,7 @@
#include "BKE_mesh.h"
#include "BKE_DerivedMesh.h"
+#include "BKE_constraint.h"
#include "BKE_customdata.h"
#include "BKE_anim.h"
#include "BKE_depsgraph.h"
@@ -64,6 +66,7 @@
#include "DNA_meshdata_types.h"
#include "DNA_curve_types.h"
#include "DNA_modifier_types.h"
+#include "DNA_constraint_types.h"
#include "MEM_guardedalloc.h"
@@ -349,6 +352,30 @@ static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int
}
*/
+static bConstraint *rna_Object_constraints_add(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);
+}
+
+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);
+
+ ED_object_constraint_set_active(object, NULL);
+ WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT, object);
+
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
#else
void RNA_api_object(StructRNA *srna)
@@ -424,6 +451,27 @@ void RNA_api_object(StructRNA *srna)
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
parm= RNA_def_boolean(func, "is_visible", 0, "", "Object visibility.");
RNA_def_function_return(func, parm);
+
+ /* Constraint collection */
+ func= RNA_def_function(srna, "constraints__add", "rna_Object_constraints_add");
+ 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, "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, "constraints__remove", "rna_Object_constraints_remove");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ 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.");
+ 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);
}
#endif
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index 5d2c281fb62..7199bdaa2f6 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -414,6 +414,32 @@ static void rna_pose_pgroup_name_set(PointerRNA *ptr, const char *value, char *r
}
#endif
+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;
+ }
+
+ 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;
+ }
+}
+
#else
static void rna_def_bone_group(BlenderRNA *brna)
@@ -512,7 +538,17 @@ static void rna_def_pose_channel(BlenderRNA *brna)
/* Bone Constraints */
prop= RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Constraint");
- RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel.");
+ RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel.");
+ RNA_def_property_collection_funcs(prop, 0, 0, 0, 0, 0, 0, 0, "constraints__add", "constraints__remove");
+
+ { /* Collection active property */
+ PropertyRNA *prop_act= RNA_def_property(srna, "constraints__active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop_act, "Constraint");
+ RNA_def_property_pointer_funcs(prop_act, "rna_PoseChannel_active_constraint_get", "rna_PoseChannel_active_constraint_set", NULL);
+ RNA_def_property_flag(prop_act, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop_act, "Active Constraint", "Active PoseChannel constraint.");
+ RNA_def_property_collection_active(prop, prop_act);
+ }
/* Name + Selection Status */
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
@@ -791,6 +827,8 @@ static void rna_def_pose_channel(BlenderRNA *brna)
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Lock Scale", "Lock editing of scale in the interface.");
RNA_def_property_update(prop, NC_OBJECT|ND_POSE, "rna_Pose_update");
+
+ RNA_api_pose_channel(srna);
}
static void rna_def_pose_itasc(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_pose_api.c b/source/blender/makesrna/intern/rna_pose_api.c
index 40bb131b3f9..ae83b728dd6 100644
--- a/source/blender/makesrna/intern/rna_pose_api.c
+++ b/source/blender/makesrna/intern/rna_pose_api.c
@@ -33,6 +33,7 @@
#include "RNA_define.h"
#include "RNA_types.h"
+#include "RNA_enum_types.h"
#include "DNA_object_types.h"
@@ -43,14 +44,71 @@
/* #include "DNA_anim_types.h" */
#include "DNA_action_types.h" /* bPose */
+#include "BKE_constraint.h" /* bPose */
+
+static bConstraint *rna_PoseChannel_constraints_add(bPoseChannel *pchan, bContext *C, int type)
+{
+ //WM_event_add_notifier(C, NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object);
+ // TODO, pass object also
+ // TODO, new pose bones don't have updated draw flags
+ return add_pose_constraint(NULL, pchan, NULL, type);
+}
+
+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;
+ }
+}
+
#else
void RNA_api_pose(StructRNA *srna)
{
/* FunctionRNA *func; */
/* PropertyRNA *parm; */
+}
+
+void RNA_api_pose_channel(StructRNA *srna)
+{
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+
+ /* Constraint collection */
+ func= RNA_def_function(srna, "constraints__add", "rna_PoseChannel_constraints_add");
+ 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, "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, "constraints__remove", "rna_PoseChannel_constraints_remove");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ 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.");
+ 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);
}
+
#endif
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 943d559133f..4805d6e8156 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2229,7 +2229,7 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_struct_type(prop_act, "ObjectBase");
RNA_def_property_pointer_sdna(prop_act, NULL, "basact");
RNA_def_property_flag(prop_act, PROP_EDITABLE);
- RNA_def_property_ui_text(prop_act, "Active Base", "Active object in the scene.");
+ RNA_def_property_ui_text(prop_act, "Active Base", "Active object base in the scene.");
RNA_def_property_update(prop_act, NC_SCENE|ND_OB_ACTIVE, NULL);
RNA_def_property_collection_active(prop, prop_act);
}
@@ -2245,7 +2245,7 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_struct_type(prop_act, "Object");
RNA_def_property_pointer_funcs(prop_act, "rna_Scene_active_object_get", "rna_Scene_active_object_set", NULL);
RNA_def_property_flag(prop_act, PROP_EDITABLE);
- RNA_def_property_ui_text(prop_act, "Object", "Object to use as projector transform.");
+ RNA_def_property_ui_text(prop_act, "Active Object", "Active object for this scene.");
/* Could call: ED_base_object_activate(C, scene->basact);
* but would be a bad level call and it seems the notifier is enough */
RNA_def_property_update(prop_act, NC_SCENE|ND_OB_ACTIVE, NULL);