== Constraints - Code Cleanup ==
authorJoshua Leung <aligorith@gmail.com>
Wed, 20 Jun 2007 07:11:31 +0000 (07:11 +0000)
committerJoshua Leung <aligorith@gmail.com>
Wed, 20 Jun 2007 07:11:31 +0000 (07:11 +0000)
Simplified the code in two functions where checking for targets/subtargets could really have been done using Constraint API methods (constraint_has_target, get_constraint_target).

source/blender/blenkernel/intern/constraint.c
source/blender/src/editconstraint.c

index 9c03db824af47f51fccc5dd3453904f66bdbf0fc..4ca9d7e316ae8a6b9e5686f56b7698fa496ca3e7 100644 (file)
@@ -128,111 +128,13 @@ void relink_constraints (struct ListBase *list)
        bConstraint *con;
        
        for (con = list->first; con; con=con->next) {
-               switch (con->type) {
-                       case CONSTRAINT_TYPE_PYTHON:
-                       {
-                               bPythonConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_KINEMATIC:
-                       {
-                               bKinematicConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_TRACKTO:
-                       {
-                               bTrackToConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_MINMAX:
-                       {
-                               bMinMaxConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_LOCKTRACK:
-                       {
-                               bLockTrackConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_ACTION:
-                       {
-                               bActionConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_LOCLIKE:
-                       {
-                               bLocateLikeConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_ROTLIKE:
-                       {
-                               bRotateLikeConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_SIZELIKE:
-                       {
-                               bSizeLikeConstraint *data;
-                               data = con->data;
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_FOLLOWPATH:
-                       {
-                               bFollowPathConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_STRETCHTO:
-                       {
-                               bStretchToConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_RIGIDBODYJOINT:
-                       {
-                               bRigidBodyJointConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
-                       case CONSTRAINT_TYPE_CLAMPTO:
-                       {       
-                               bClampToConstraint *data;
-                               data = con->data;
-                               
-                               ID_NEW(data->tar);
-                       }
-                               break;
+               /* check if constraint has a target that needs relinking */
+               if (constraint_has_target(con)) {
+                       Object *tar;
+                       char *subtarget;
+                       
+                       tar = get_constraint_target(con, &subtarget);
+                       ID_NEW(tar);
                }
        }
 }
index 32cfde2eb86a802345889147a2bef6f1714b9c26..95391b37af7700c2e9cd9817ee198fba4fd8fc64 100644 (file)
@@ -250,86 +250,13 @@ char *get_con_subtarget_name(bConstraint *con, Object *target)
         * If the target for this constraint is target, return a pointer 
         * to the name for this constraints subtarget ... NULL otherwise
         */
-       switch (con->type) {
-               case CONSTRAINT_TYPE_PYTHON:
-               {
-                       bPythonConstraint *data = con->data;
-                       if (data->flag & PYCON_USETARGETS) {
-                               if (data->tar==target) return data->subtarget;
-                       }
-               }
-               break;
-               case CONSTRAINT_TYPE_ACTION:
-               {
-                       bActionConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_LOCLIKE:
-               {
-                       bLocateLikeConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_ROTLIKE:
-               {
-                       bRotateLikeConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_SIZELIKE:
-               {
-                       bSizeLikeConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_KINEMATIC:
-               {
-                       bKinematicConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_TRACKTO:
-               {
-                       bTrackToConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_MINMAX:
-               {
-                       bMinMaxConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_LOCKTRACK:
-               {
-                       bLockTrackConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_STRETCHTO:
-               {
-                       bStretchToConstraint *data = con->data;
-                       if (data->tar==target) return data->subtarget;
-               }
-               break;
-               case CONSTRAINT_TYPE_FOLLOWPATH: 
-                       /* wonder if this is relevent, since this constraint 
-                        * cannot have a subtarget - theeth 
-                        */
-               {
-                       /*
-                        * bFollowPathConstraint *data = con->data;
-                        */
-                       return NULL;
-               }
-               break;
-               case CONSTRAINT_TYPE_CLAMPTO:
-               {
-                       /* cannot have subtarget. if followpath is removed from here, remove this too... */
-                       return NULL; 
-               }
-               break;
+        
+       if (constraint_has_target(con)) {
+               Object *tar;
+               char *subtarget;
+               
+               tar = get_constraint_target(con, &subtarget);
+               if (tar==target) return subtarget;
        }
        
        return NULL;