[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26637] trunk/blender/source/blender/ blenkernel: Constraints API: ID-Loopers

Joshua Leung aligorith at gmail.com
Sat Feb 6 12:28:23 CET 2010


Revision: 26637
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26637
Author:   aligorith
Date:     2010-02-06 12:28:22 +0100 (Sat, 06 Feb 2010)

Log Message:
-----------
Constraints API: ID-Loopers

Added a system for running a callback on all the ID-blocks referenced by constraints (like for modifiers). Also, added an API function which calls these on the constraints present in the given list.

These could be used for:
- the proxies + action/pyconstraint fix that campbell committed
- simplification of file loading code

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_constraint.h
    trunk/blender/source/blender/blenkernel/intern/constraint.c

Modified: trunk/blender/source/blender/blenkernel/BKE_constraint.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_constraint.h	2010-02-06 10:50:34 UTC (rev 26636)
+++ trunk/blender/source/blender/blenkernel/BKE_constraint.h	2010-02-06 11:28:22 UTC (rev 26637)
@@ -30,6 +30,7 @@
 #ifndef BKE_CONSTRAINT_H
 #define BKE_CONSTRAINT_H
 
+struct ID;
 struct bConstraint;
 struct bConstraintTarget;
 struct ListBase;
@@ -57,6 +58,11 @@
 
 /* ---------------------------------------------------------------------------- */
 
+/* Callback format for performing operations on ID-pointers for Constraints */
+typedef void (*ConstraintIDFunc)(struct bConstraint *con, struct ID **idpoin, void *userdata);
+
+/* ....... */
+
 /* Constraint Type-Info (shorthand in code = cti):
  *  This struct provides function pointers for runtime, so that functions can be
  *  written more generally (with fewer/no special exceptions for various constraints).
@@ -80,6 +86,8 @@
 	void (*free_data)(struct bConstraint *con);
 		/* adjust pointer to other ID-data using ID_NEW(), but not to targets (optional) */
 	void (*relink_data)(struct bConstraint *con);
+		/* run the provided callback function on all the ID-blocks linked to the constraint */
+	void (*id_looper)(struct bConstraint *con, ConstraintIDFunc func, void *userdata);
 		/* copy any special data that is allocated separately (optional) */
 	void (*copy_data)(struct bConstraint *con, struct bConstraint *src);
 		/* set settings for data that will be used for bConstraint.data (memory already allocated using MEM_callocN) */
@@ -116,6 +124,7 @@
 void free_constraints(struct ListBase *list);
 void copy_constraints(struct ListBase *dst, const struct ListBase *src);
 void relink_constraints(struct ListBase *list);
+void id_loop_constraints(struct ListBase *list, ConstraintIDFunc func, void *userdata);
 void free_constraint_data(struct bConstraint *con);
 
 /* Constraint API function prototypes */

Modified: trunk/blender/source/blender/blenkernel/intern/constraint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-02-06 10:50:34 UTC (rev 26636)
+++ trunk/blender/source/blender/blenkernel/intern/constraint.c	2010-02-06 11:28:22 UTC (rev 26637)
@@ -648,6 +648,7 @@
 	"bConstrNameConstraint", /* struct name */
 	constrname_free, /* free data */
 	constrname_relink, /* relink data */
+	constrname_id_looper, /* id looper */
 	constrname_copy, /* copy data */
 	constrname_new_data, /* new data */
 	constrname_get_tars, /* get constraint targets */
@@ -774,6 +775,14 @@
 	unit_m4(data->invmat);
 }
 
+static void childof_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bChildOfConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int childof_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -858,6 +867,7 @@
 	"bChildOfConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	childof_id_looper, /* id looper */
 	NULL, /* copy data */
 	childof_new_data, /* new data */
 	childof_get_tars, /* get constraint targets */
@@ -876,6 +886,14 @@
 	data->reserved2 = UP_Z;
 }	
 
+static void trackto_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bTrackToConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int trackto_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -1037,6 +1055,7 @@
 	"bTrackToConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	trackto_id_looper, /* id looper */
 	NULL, /* copy data */
 	trackto_new_data, /* new data */
 	trackto_get_tars, /* get constraint targets */
@@ -1058,6 +1077,17 @@
 	data->flag= CONSTRAINT_IK_TIP|CONSTRAINT_IK_STRETCH|CONSTRAINT_IK_POS;
 }
 
+static void kinematic_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bKinematicConstraint *data= con->data;
+	
+	/* chain target */
+	func(con, (ID**)&data->tar, userdata);
+	
+	/* poletarget */
+	func(con, (ID**)&data->poletar, userdata);
+}
+
 static int kinematic_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -1120,6 +1150,7 @@
 	"bKinematicConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	kinematic_id_looper, /* id looper */
 	NULL, /* copy data */
 	kinematic_new_data, /* new data */
 	kinematic_get_tars, /* get constraint targets */
@@ -1140,6 +1171,14 @@
 	data->followflag = 0;
 }
 
+static void followpath_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bFollowPathConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int followpath_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -1283,6 +1322,7 @@
 	"bFollowPathConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	followpath_id_looper, /* id looper */
 	NULL, /* copy data */
 	followpath_new_data, /* new data */
 	followpath_get_tars, /* get constraint targets */
@@ -1331,6 +1371,7 @@
 	"bLocLimitConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	NULL, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
 	NULL, /* get constraint targets */
@@ -1388,6 +1429,7 @@
 	"bRotLimitConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	NULL, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
 	NULL, /* get constraint targets */
@@ -1447,6 +1489,7 @@
 	"bSizeLimitConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	NULL, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
 	NULL, /* get constraint targets */
@@ -1464,6 +1507,14 @@
 	data->flag = LOCLIKE_X|LOCLIKE_Y|LOCLIKE_Z;
 }
 
+static void loclike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bLocateLikeConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int loclike_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -1529,6 +1580,7 @@
 	"bLocateLikeConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	loclike_id_looper, /* id looper */
 	NULL, /* copy data */
 	loclike_new_data, /* new data */
 	loclike_get_tars, /* get constraint targets */
@@ -1546,6 +1598,14 @@
 	data->flag = ROTLIKE_X|ROTLIKE_Y|ROTLIKE_Z;
 }
 
+static void rotlike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bChildOfConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int rotlike_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -1631,6 +1691,7 @@
 	"bRotateLikeConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	rotlike_id_looper, /* id looper */
 	NULL, /* copy data */
 	rotlike_new_data, /* new data */
 	rotlike_get_tars, /* get constraint targets */
@@ -1648,6 +1709,14 @@
 	data->flag = SIZELIKE_X|SIZELIKE_Y|SIZELIKE_Z;
 }
 
+static void sizelike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bSizeLikeConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int sizelike_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -1719,6 +1788,7 @@
 	"bSizeLikeConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	sizelike_id_looper, /* id looper */
 	NULL, /* copy data */
 	sizelike_new_data, /* new data */
 	sizelike_get_tars, /* get constraint targets */
@@ -1729,6 +1799,14 @@
 
 /* ----------- Copy Transforms ------------- */
 
+static void translike_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bTransLikeConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int translike_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -1772,6 +1850,7 @@
 	"bTransLikeConstraint", /* struct name */
 	NULL, /* free data */
 	NULL, /* relink data */
+	translike_id_looper, /* id looper */
 	NULL, /* copy data */
 	NULL, /* new data */
 	translike_get_tars, /* get constraint targets */
@@ -1833,6 +1912,19 @@
 	return 0;
 }
 
+static void pycon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bPythonConstraint *data= con->data;
+	bConstraintTarget *ct;
+	
+	/* targets */
+	for (ct= data->targets.first; ct; ct= ct->next)
+		func(con, (ID**)&ct->tar, userdata);
+		
+	/* script */
+	func(con, (ID**)&data->text, userdata);
+}
+
 /* Whether this approach is maintained remains to be seen (aligorith) */
 static void pycon_get_tarmat (bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float ctime)
 {
@@ -1894,6 +1986,7 @@
 	"bPythonConstraint", /* struct name */
 	pycon_free, /* free data */
 	pycon_relink, /* relink data */
+	pycon_id_looper, /* id looper */
 	pycon_copy, /* copy data */
 	pycon_new_data, /* new data */
 	pycon_get_tars, /* get constraint targets */
@@ -1921,11 +2014,22 @@
 /* only for setting the ID as extern */
 static void actcon_copy_data (bConstraint *con, bConstraint *srccon)
 {
-	bActionConstraint *src= srccon->data;
+	//bActionConstraint *src= srccon->data;
 	bActionConstraint *dst= con->data;
 	id_lib_extern((ID *)dst->act); /* would be better solved with something like modifiers_foreachIDLink */
 }
 
+static void actcon_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bActionConstraint *data= con->data;
+	
+	/* target */
+	func(con, (ID**)&data->tar, userdata);
+	
+	/* action */
+	func(con, (ID**)&data->act, userdata);
+}
+
 static int actcon_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -2065,6 +2169,7 @@
 	"bActionConstraint", /* struct name */
 	NULL, /* free data */
 	actcon_relink, /* relink data */
+	actcon_id_looper, /* id looper */
 	actcon_copy_data, /* copy data */
 	actcon_new_data, /* new data */
 	actcon_get_tars, /* get constraint targets */
@@ -2083,6 +2188,14 @@
 	data->lockflag = LOCK_Z;
 }	
 
+static void locktrack_id_looper (bConstraint *con, ConstraintIDFunc func, void *userdata)
+{
+	bLockTrackConstraint *data= con->data;
+	
+	/* target only */
+	func(con, (ID**)&data->tar, userdata);
+}
+
 static int locktrack_get_tars (bConstraint *con, ListBase *list)
 {
 	if (con && list) {
@@ -2418,6 +2531,7 @@

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list