svn merge -r 13095:13148 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / src / buttons_object.c
index 662e0df093b0b1bab3b816b6e2650d35fd977d36..3883db39c74a3ead1618f0d1762e1440f83ad0e7 100644 (file)
@@ -192,15 +192,18 @@ static void constraint_active_func(void *ob_v, void *con_v)
 
 static void add_constraint_to_active(Object *ob, bConstraint *con)
 {
 
 static void add_constraint_to_active(Object *ob, bConstraint *con)
 {
-       ListBase *list;
+       ListBase *list= get_active_constraints(ob);
+       bPoseChannel *pchan= get_active_posechannel(ob);
        
        
-       list = get_active_constraints(ob);
        if (list) {
                unique_constraint_name(con, list);
                BLI_addtail(list, con);
                
        if (list) {
                unique_constraint_name(con, list);
                BLI_addtail(list, con);
                
+               if (proxylocked_constraints_owner(ob, pchan))
+                       con->flag |= CONSTRAINT_PROXY_LOCAL;
+               
                con->flag |= CONSTRAINT_ACTIVE;
                con->flag |= CONSTRAINT_ACTIVE;
-               for(con= con->prev; con; con= con->prev)
+               for (con= con->prev; con; con= con->prev)
                        con->flag &= ~CONSTRAINT_ACTIVE;
        }
 }
                        con->flag &= ~CONSTRAINT_ACTIVE;
        }
 }
@@ -211,8 +214,7 @@ static void get_constraint_ipo_context(void *ob_v, char *actname)
 {
        Object *ob= ob_v;
        
 {
        Object *ob= ob_v;
        
-       /* todo; check object if it has ob-level action ipo */
-       
+       /* todo: check object if it has ob-level action ipo */
        if (ob->flag & OB_POSEMODE) {
                bPoseChannel *pchan;
                
        if (ob->flag & OB_POSEMODE) {
                bPoseChannel *pchan;
                
@@ -505,12 +507,15 @@ static void draw_constraint_spaceselect (uiBlock *block, bConstraint *con, short
 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco)
 {
        Object *ob= OBACT;
 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco)
 {
        Object *ob= OBACT;
+       bPoseChannel *pchan= get_active_posechannel(ob);
        bConstraintTypeInfo *cti;
        uiBut *but;
        char typestr[32];
        short height, width = 265;
        bConstraintTypeInfo *cti;
        uiBut *but;
        char typestr[32];
        short height, width = 265;
+       short proxy_protected;
        int rb_col;
 
        int rb_col;
 
+       /* get constraint typeinfo */
        cti= constraint_get_typeinfo(con);
        if (cti == NULL) {
                /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
        cti= constraint_get_typeinfo(con);
        if (cti == NULL) {
                /* exception for 'Null' constraint - it doesn't have constraint typeinfo! */
@@ -522,6 +527,13 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
        else
                strcpy(typestr, cti->name);
                
        else
                strcpy(typestr, cti->name);
                
+       /* determine whether constraint is proxy protected or not */
+       if (proxylocked_constraints_owner(ob, pchan)) {
+               proxy_protected= (con->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
+       }
+       else
+               proxy_protected= 0;
+               
        /* unless button has own callback, it adds this callback to button */
        uiBlockSetFunc(block, constraint_active_func, ob, con);
 
        /* unless button has own callback, it adds this callback to button */
        uiBlockSetFunc(block, constraint_active_func, ob, con);
 
@@ -536,17 +548,8 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
        /* open/close */
        uiDefIconButBitS(block, ICONTOG, CONSTRAINT_EXPAND, B_CONSTRAINT_TEST, ICON_DISCLOSURE_TRI_RIGHT, *xco-10, *yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
        
        /* open/close */
        uiDefIconButBitS(block, ICONTOG, CONSTRAINT_EXPAND, B_CONSTRAINT_TEST, ICON_DISCLOSURE_TRI_RIGHT, *xco-10, *yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
        
-       /* up/down */
-       uiBlockBeginAlign(block);
-       uiBlockSetEmboss(block, UI_EMBOSS);
-       but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, *xco+width-50, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint up in constraint stack");
-       uiButSetFunc(but, constraint_moveUp, ob, con);
-       
-       but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, *xco+width-50+18, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
-       uiButSetFunc(but, constraint_moveDown, ob, con);
-       uiBlockEndAlign(block);
-       
-       if (con->flag & CONSTRAINT_EXPAND) {
+       /* name */      
+       if ((con->flag & CONSTRAINT_EXPAND) && (proxy_protected==0)) {
                if (con->flag & CONSTRAINT_DISABLE)
                        uiBlockSetCol(block, TH_REDALERT);
                
                if (con->flag & CONSTRAINT_DISABLE)
                        uiBlockSetCol(block, TH_REDALERT);
                
@@ -570,14 +573,60 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
 
        uiBlockSetCol(block, TH_AUTO);  
        
 
        uiBlockSetCol(block, TH_AUTO);  
        
-       uiBlockSetEmboss(block, UI_EMBOSSN);
+       /* proxy-protected constraints cannot be edited, so hide up/down + close buttons */
+       if (proxy_protected) {
+               uiBlockSetEmboss(block, UI_EMBOSSN);
+               
+               /* draw a ghost icon (for proxy) and also a lock beside it, to show that constraint is "proxy locked" */
+               uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_GHOST, *xco+244, *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
+               uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, ICON_LOCKED, *xco+262, *yco, 19, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Proxy Protected");
+               
+               uiBlockSetEmboss(block, UI_EMBOSS);
+       }
+       else {
+               short prev_proxylock;
+               
+               /* Up/Down buttons: 
+                *      Proxy-constraints are not allowed to occur after local (non-proxy) constraints
+                *      as that poses problems when restoring them, so disable the "up" button where
+                *      it may cause this situation.
+                */
+               if (proxylocked_constraints_owner(ob, pchan)) {
+                       if (con->prev) {
+                               prev_proxylock= (con->prev->flag & CONSTRAINT_PROXY_LOCAL) ? 0 : 1;
+                       }
+                       else
+                               prev_proxylock= 0;
+               }
+               else
+                       prev_proxylock= 0;
+                
+               uiBlockBeginAlign(block);
+                       uiBlockSetEmboss(block, UI_EMBOSS);
+                       
+                       if (prev_proxylock == 0) {
+                               but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, *xco+width-50, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint up in constraint stack");
+                               uiButSetFunc(but, constraint_moveUp, ob, con);
+                       }
+                       
+                       but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, *xco+width-50+18, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move constraint down in constraint stack");
+                       uiButSetFunc(but, constraint_moveDown, ob, con);
+               uiBlockEndAlign(block);
+               
+               
+               /* Close 'button' - emboss calls here disable drawing of 'button' behind X */
+               uiBlockSetEmboss(block, UI_EMBOSSN);
+               
+                       but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, *xco+262, *yco, 19, 19, list, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
+                       uiButSetFunc(but, del_constraint_func, ob, con);
+               
+               uiBlockSetEmboss(block, UI_EMBOSS);
+       }
+       
+       /* Set but-locks for protected settings (magic numbers are used here!) */
+       if (proxy_protected)
+               uiSetButLock(1, "Cannot edit Proxy-Protected Constraint");
        
        
-       but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, *xco+262, *yco, 19, 19, list, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
-       uiButSetFunc(but, del_constraint_func, ob, con);
-
-       uiBlockSetEmboss(block, UI_EMBOSS);
-
-
        /* Draw constraint data */
        if ((con->flag & CONSTRAINT_EXPAND) == 0) {
                (*yco) -= 21;
        /* Draw constraint data */
        if ((con->flag & CONSTRAINT_EXPAND) == 0) {
                (*yco) -= 21;
@@ -616,7 +665,7 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
                                                
                                                /* target label */
                                                sprintf(tarstr, "Target %02d:", tarnum);
                                                
                                                /* 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)) {
                                                
                                                /* target space-selector - per target */
                                                if (is_armature_target(ct->tar)) {
@@ -774,10 +823,10 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
                                /* 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)");
                                /* 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)");
                                        
                                        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;
                                uiBlockEndAlign(block);
                        }
                        break;
@@ -1651,6 +1700,9 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s
        else {
                (*yco)-=3;
        }
        else {
                (*yco)-=3;
        }
+       
+       /* clear any locks set up for proxies/lib-linking */
+       uiClearButLock();
 }
 
 static uiBlock *add_constraintmenu(void *arg_unused)
 }
 
 static uiBlock *add_constraintmenu(void *arg_unused)