[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13135] trunk/blender/source/blender: == Constraints - Code Cleanups ==
Joshua Leung
aligorith at gmail.com
Sat Jan 5 10:31:44 CET 2008
Revision: 13135
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13135
Author: aligorith
Date: 2008-01-05 10:31:43 +0100 (Sat, 05 Jan 2008)
Log Message:
-----------
== Constraints - Code Cleanups ==
* Tidied up coding style of code in editconstraint.c
- removed blank lines, made whitespace-use more consistent
* Shuffled code in editconstraint.c and BIF_editconstraint.h so that it was in a more orderly fashion
* Reduced code redundancy in test_constraints
- tests which can apply to general constraints (target existance, and clashes with the owner) are not copied out for each constraint that needs it
- ChildOf constraint now gets validated too (before it was missing such checks)
* Recoded the way PyConstraints build the menu for displaying scripts available for use. It now uses dynstr instead of guessing how much memory to allocate for each entry
Modified Paths:
--------------
trunk/blender/source/blender/include/BIF_editconstraint.h
trunk/blender/source/blender/src/buttons_object.c
trunk/blender/source/blender/src/editconstraint.c
Modified: trunk/blender/source/blender/include/BIF_editconstraint.h
===================================================================
--- trunk/blender/source/blender/include/BIF_editconstraint.h 2008-01-05 04:07:28 UTC (rev 13134)
+++ trunk/blender/source/blender/include/BIF_editconstraint.h 2008-01-05 09:31:43 UTC (rev 13135)
@@ -41,23 +41,18 @@
struct Text;
/* generic constraint editing functions */
-
-struct bConstraint *add_new_constraint(short type);
-
-void add_constraint_to_object(struct bConstraint *con, struct Object *ob);
-
struct ListBase *get_active_constraints(struct Object *ob);
struct bConstraint *get_active_constraint(struct Object *ob);
struct ListBase *get_active_constraint_channels (struct Object *ob, int forcevalid);
struct bConstraintChannel *get_active_constraint_channel(struct Object *ob);
-void object_test_constraints(struct Object *owner);
-
-void add_constraint(int only_IK);
+void add_constraint_to_object(struct bConstraint *con, struct Object *ob);
+struct bConstraint *add_new_constraint(short type);
+void add_constraint(short only_IK);
void ob_clear_constraints(void);
-
void rename_constraint(struct Object *ob, struct bConstraint *con, char *newname);
+void object_test_constraints(struct Object *owner);
/* a few special functions for PyConstraints */
char *buildmenu_pyconstraints(struct Text *con_text, int *pyconindex);
Modified: trunk/blender/source/blender/src/buttons_object.c
===================================================================
--- trunk/blender/source/blender/src/buttons_object.c 2008-01-05 04:07:28 UTC (rev 13134)
+++ trunk/blender/source/blender/src/buttons_object.c 2008-01-05 09:31:43 UTC (rev 13135)
@@ -663,7 +663,7 @@
/* target label */
sprintf(tarstr, "Target %02d:", tarnum);
- uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, *xco+45, *yco-(48+yoffset), 60, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
+ uiDefBut(block, LABEL, B_CONSTRAINT_TEST, tarstr, *xco+45, *yco-(48+yoffset), 80, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
/* target space-selector - per target */
if (is_armature_target(ct->tar)) {
@@ -821,10 +821,10 @@
/* Inverse options */
uiBlockBeginAlign(block);
but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Set Offset", *xco, *yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Calculate current Parent-Inverse Matrix (i.e. restore offset from parent)");
- uiButSetFunc(but, childof_const_setinv, data, NULL);
+ uiButSetFunc(but, childof_const_setinv, con, NULL);
but=uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Clear Offset", *xco+((width/2)+10), *yco-151, (width/2),18, NULL, 0, 24, 0, 0, "Clear Parent-Inverse Matrix (i.e. clear offset from parent)");
- uiButSetFunc(but, childof_const_clearinv, data, NULL);
+ uiButSetFunc(but, childof_const_clearinv, con, NULL);
uiBlockEndAlign(block);
}
break;
Modified: trunk/blender/source/blender/src/editconstraint.c
===================================================================
--- trunk/blender/source/blender/src/editconstraint.c 2008-01-05 04:07:28 UTC (rev 13134)
+++ trunk/blender/source/blender/src/editconstraint.c 2008-01-05 09:31:43 UTC (rev 13135)
@@ -25,7 +25,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): none yet.
+ * Contributor(s): Joshua Leung
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@@ -37,6 +37,7 @@
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
+#include "BLI_dynstr.h"
#include "DNA_action_types.h"
#include "DNA_armature_types.h"
@@ -73,55 +74,56 @@
#include "nla.h"
#include "mydevice.h"
+/* -------------- Get Active Constraint Data ---------------------- */
ListBase *get_active_constraint_channels (Object *ob, int forcevalid)
{
char ipstr[64];
- if (!ob)
+ if (ob == NULL)
return NULL;
/* See if we are a bone constraint */
if (ob->flag & OB_POSEMODE) {
bActionChannel *achan;
bPoseChannel *pchan;
-
+
pchan = get_active_posechannel(ob);
if (pchan) {
-
/* Make sure we have an action */
- if (!ob->action){
- if (!forcevalid)
+ if (ob->action == NULL) {
+ if (forcevalid == 0)
return NULL;
- ob->action=add_empty_action("Action");
+ ob->action= add_empty_action("Action");
}
/* Make sure we have an actionchannel */
achan = get_action_channel(ob->action, pchan->name);
- if (!achan){
- if (!forcevalid)
+ if (achan == NULL) {
+ if (forcevalid == 0)
return NULL;
- achan = MEM_callocN (sizeof(bActionChannel), "actionChannel");
-
- strcpy (achan->name, pchan->name);
- sprintf (ipstr, "%s.%s", ob->action->id.name+2, achan->name);
+ achan = MEM_callocN (sizeof(bActionChannel), "ActionChannel");
+
+ strcpy(achan->name, pchan->name);
+ sprintf(ipstr, "%s.%s", ob->action->id.name+2, achan->name);
ipstr[23]=0;
achan->ipo= add_ipo(ipstr, ID_AC);
- BLI_addtail (&ob->action->chanbase, achan);
+ BLI_addtail(&ob->action->chanbase, achan);
}
return &achan->constraintChannels;
}
- else return NULL;
+ else
+ return NULL;
}
/* else we return object constraints */
else {
- if(ob->ipoflag & OB_ACTION_OB) {
+ if (ob->ipoflag & OB_ACTION_OB) {
bActionChannel *achan = get_action_channel(ob->action, "Object");
- if(achan)
+ if (achan)
return &achan->constraintChannels;
else
return NULL;
@@ -133,14 +135,14 @@
/* if object in posemode, active bone constraints, else object constraints */
-ListBase *get_active_constraints(Object *ob)
+ListBase *get_active_constraints (Object *ob)
{
- if (!ob)
+ if (ob == NULL)
return NULL;
if (ob->flag & OB_POSEMODE) {
bPoseChannel *pchan;
-
+
pchan = get_active_posechannel(ob);
if (pchan)
return &pchan->constraints;
@@ -152,40 +154,46 @@
}
/* single constraint */
-bConstraint *get_active_constraint(Object *ob)
+bConstraint *get_active_constraint (Object *ob)
{
ListBase *lb= get_active_constraints(ob);
if (lb) {
bConstraint *con;
- for (con= lb->first; con; con=con->next)
+
+ for (con= lb->first; con; con=con->next) {
if (con->flag & CONSTRAINT_ACTIVE)
return con;
+ }
}
+
return NULL;
}
/* single channel, for ipo */
-bConstraintChannel *get_active_constraint_channel(Object *ob)
+bConstraintChannel *get_active_constraint_channel (Object *ob)
{
bConstraint *con;
bConstraintChannel *chan;
if (ob->flag & OB_POSEMODE) {
- if(ob->action) {
+ if (ob->action) {
bPoseChannel *pchan;
pchan = get_active_posechannel(ob);
if (pchan) {
- for (con= pchan->constraints.first; con; con= con->next)
+ for (con= pchan->constraints.first; con; con= con->next) {
if (con->flag & CONSTRAINT_ACTIVE)
break;
+ }
+
if (con) {
bActionChannel *achan = get_action_channel(ob->action, pchan->name);
if (achan) {
- for (chan= achan->constraintChannels.first; chan; chan= chan->next)
+ for (chan= achan->constraintChannels.first; chan; chan= chan->next) {
if (!strcmp(chan->name, con->name))
break;
+ }
return chan;
}
}
@@ -193,16 +201,20 @@
}
}
else {
- for(con= ob->constraints.first; con; con= con->next)
- if(con->flag & CONSTRAINT_ACTIVE)
+ for (con= ob->constraints.first; con; con= con->next) {
+ if (con->flag & CONSTRAINT_ACTIVE)
break;
- if(con) {
+ }
+
+ if (con) {
ListBase *lb= get_active_constraint_channels(ob, 0);
-
- if(lb) {
- for(chan= lb->first; chan; chan= chan->next)
- if(!strcmp(chan->name, con->name))
+
+ if (lb) {
+ for (chan= lb->first; chan; chan= chan->next) {
+ if (!strcmp(chan->name, con->name))
break;
+ }
+
return chan;
}
}
@@ -211,13 +223,15 @@
return NULL;
}
+/* -------------- Constraint Management (Add New, Remove, Rename) -------------------- */
-bConstraint *add_new_constraint(short type)
+/* Creates a new constraint, initialises its data, and returns it */
+bConstraint *add_new_constraint (short type)
{
bConstraint *con;
bConstraintTypeInfo *cti;
- con = MEM_callocN(sizeof(bConstraint), "constraint");
+ con = MEM_callocN(sizeof(bConstraint), "Constraint");
/* Set up a generic constraint datablock */
con->type = type;
@@ -238,7 +252,8 @@
return con;
}
-void add_constraint_to_object(bConstraint *con, Object *ob)
+/* Adds the given constraint to the Object-level set of constraints for the given Object */
+void add_constraint_to_object (bConstraint *con, Object *ob)
{
ListBase *list;
list = &ob->constraints;
@@ -256,361 +271,14 @@
}
}
-/* checks validity of object pointers, and NULLs,
- * if Bone doesnt exist it sets the CONSTRAINT_DISABLE flag
- */
-static void test_constraints (Object *owner, const char substring[])
-{
- bConstraint *curcon;
- ListBase *conlist= NULL;
- int type;
-
- if (owner==NULL) return;
-
- /* Check parents */
- if (strlen (substring)) {
- switch (owner->type) {
- case OB_ARMATURE:
- type = CONSTRAINT_OBTYPE_BONE;
- break;
- default:
- type = CONSTRAINT_OBTYPE_OBJECT;
- break;
- }
- }
- else
- type = CONSTRAINT_OBTYPE_OBJECT;
-
- /* Get the constraint list for this object */
- switch (type) {
- case CONSTRAINT_OBTYPE_OBJECT:
- conlist = &owner->constraints;
- break;
- case CONSTRAINT_OBTYPE_BONE:
- {
- Bone *bone;
- bPoseChannel *chan;
-
- bone = get_named_bone( ((bArmature *)owner->data ), substring );
- chan = get_pose_channel(owner->pose, substring);
- if (bone && chan) {
- conlist = &chan->constraints;
- }
- }
- break;
- }
-
- /* Check all constraints - is constraint valid? */
- if (conlist) {
- for (curcon = conlist->first; curcon; curcon=curcon->next) {
- curcon->flag &= ~CONSTRAINT_DISABLE;
-
- switch (curcon->type) {
- case CONSTRAINT_TYPE_PYTHON:
- {
- bPythonConstraint *data = curcon->data;
-
- /* is there are valid script? */
- if (!data->text) {
- curcon->flag |= CONSTRAINT_DISABLE;
- break;
- }
- else if (!BPY_is_pyconstraint(data->text)) {
- curcon->flag |= CONSTRAINT_DISABLE;
- break;
- }
-
- /* does the constraint require target input... also validates targets */
- BPY_pyconstraint_update(owner, curcon);
- }
- break;
- case CONSTRAINT_TYPE_ACTION:
- {
- bActionConstraint *data = curcon->data;
-
- if (!exist_object(data->tar)) {
- data->tar = NULL;
- curcon->flag |= CONSTRAINT_DISABLE;
- break;
- }
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list