IpoWindow, Action curve update.
authorTon Roosendaal <ton@blender.org>
Mon, 3 Oct 2005 13:03:25 +0000 (13:03 +0000)
committerTon Roosendaal <ton@blender.org>
Mon, 3 Oct 2005 13:03:25 +0000 (13:03 +0000)
When no Ipo existed yet for an Action Channel (Bone), you could not add
curves with CTRL+click or Drivers. This was due to antique action code
state... it's still messy, no time for big cleanup here yet. At least
this works now. :)

(Also: removed test prints of previous commit)

source/blender/include/BIF_editaction.h
source/blender/render/intern/source/initrender.c
source/blender/src/buttons_editing.c
source/blender/src/drawipo.c
source/blender/src/editaction.c
source/blender/src/editipo.c

index c2443d24ea9d64ad47d23acadbf0a13dc43dd114..495b7a620c204411f8141a0c652466b4358d528a 100644 (file)
@@ -96,6 +96,8 @@ struct bAction *add_empty_action(void);
 void winqreadactionspace(struct ScrArea *sa, void *spacedata, struct BWinEvent *evt);
 struct bAction *bake_action_with_client (struct bAction *act, struct Object *arm, float tolerance);
 
+void verify_active_action_channel(struct Object *ob);
+
 void remake_action_ipos(struct bAction *act);
 
 
index 143d4867d0889dcd1556e2ec221d4f3174c1b767..f79b86f018b6cd7a70e5903e653f3755da8921a9 100644 (file)
@@ -692,7 +692,6 @@ static void initparts(void)
                                pa->x+= 2;
                                pa->y+= 2;
                        }
-                       printf("part %d %d\n", pa->x, pa->y);
                        BLI_addtail(&R.parts, pa);
                }
                else MEM_freeN(pa);
@@ -720,7 +719,6 @@ static void addparttorect(Part *pa)
        int y, heigth, len, copylen;
 
        /* calc the right offset in rects, zbuffer cannot exist... */
-       printf("add part %d %d\n", pa->x, pa->y);
        if(pa->rect==NULL) return;
        
        rtp= pa->rect;
index 7ae055490f2c5f2824331a340085a8aabd1c9603..e2eb2b7efc3cf32f85d0fd9fd381ea497c7fea90 100644 (file)
@@ -1375,7 +1375,7 @@ static void editing_panel_modifiers(Object *ob)
        uiDefBlockBut(block, modifiers_add_menu, ob, "Add Modifier", 0, 190, 130, 20, "Add a new modifier");
 
        sprintf(str, "To: %s", ob->id.name+2);
-       uiDefBut(block, LABEL, 1, str,  140, 190, 140, 20, NULL, 0.0, 0.0, 0, 0, "Object whose modifier stack is being edited");
+       uiDefBut(block, LABEL, 1, str,  140, 190, 150, 20, NULL, 0.0, 0.0, 0, 0, "Object whose modifier stack is being edited");
 
        xco = 0;
        yco = 160;
index 3890af122bf85ee7719af37b06204592d6078a76..83b01a08307d318a68fabb3e232d57f9486d42c3 100644 (file)
@@ -1685,7 +1685,7 @@ void do_ipobuts(unsigned short event)
                ei= get_active_editipo();
                if(ei) {
                        if(ei->icu==NULL) {
-                               ei->icu= get_ipocurve(G.sipo->from, G.sipo->blocktype, ei->adrcode, 0);
+                               ei->icu= get_ipocurve(G.sipo->from, G.sipo->blocktype, ei->adrcode, NULL);
                                ei->flag |= IPO_SELECT;
                                ei->icu->flag= ei->flag;
                        }
index 722e2f72cacb7ec7bf3bb3fd6842b95dad1c2507..faead395413708ebe2f813baae2cf7ed98c1903a 100644 (file)
@@ -766,6 +766,41 @@ bActionChannel* get_hilighted_action_channel(bAction* action)
 
 }
 
+/* sets action->achan to active channel, also adds if needed */
+void verify_active_action_channel(Object *ob)
+{
+       if(ob) {
+               bPoseChannel *pchan;
+               bActionChannel *achan;
+               
+               if(ob->action==NULL) return;
+               
+               pchan= get_active_posechannel(ob);
+               if(pchan) {
+                       /* See if this action channel exists already */ 
+                       for (achan=ob->action->chanbase.first; achan; achan=achan->next){
+                               if (!strcmp (pchan->name, achan->name))
+                                       break;
+                       }
+                       
+                       if (!achan){
+                               achan = MEM_callocN (sizeof(bActionChannel), "actionChannel");
+                               strcpy (achan->name, pchan->name);
+                               BLI_addtail (&ob->action->chanbase, achan);
+                       }
+                       
+                       ob->action->achan= achan;
+                       ob->action->pchan= pchan;
+                       
+                       for (achan=ob->action->chanbase.first; achan; achan=achan->next)
+                               achan->flag &= ~(ACHAN_SELECTED|ACHAN_HILIGHTED);
+                       
+                       ob->action->achan->flag |= ACHAN_SELECTED|ACHAN_HILIGHTED;
+
+               }
+       }               
+}
+
 void set_exprap_action(int mode)
 {
        if(G.saction->action && G.saction->action->id.lib) return;
index 0025d723d77aa0bb7019d9ef4a683f41314a94f6..db0bdcf6a49e2679cdf22458489316f3c7355c61 100644 (file)
@@ -338,10 +338,13 @@ static void set_active_editipo(EditIpo *actei)
 
 EditIpo *get_active_editipo(void)
 {
-       EditIpo *ei= G.sipo->editipo;
+       EditIpo *ei;
        int a;
        
-       for(a=0; a<G.sipo->totipo; a++, ei++)
+       if(G.sipo==NULL)
+               return NULL;
+       
+       for(a=0, ei=G.sipo->editipo; a<G.sipo->totipo; a++, ei++)
                if(ei->flag & IPO_ACTIVE)
                        return ei;
        
@@ -635,16 +638,14 @@ Ipo *get_ipo_to_edit(ID **from)
        }
        else if(G.sipo->blocktype==ID_AC) {
                bActionChannel *chan;
-               if (ob && ob->action){
+               if (ob && ob->action) {
                        *from= (ID *) ob->action;
                        chan= get_hilighted_action_channel(ob->action);
                        if (chan)
                                return chan->ipo;
-                       else{
-                               *from = NULL;
+                       else
                                return NULL;
-                       }
-               }
+               } 
 
        }
        else if(G.sipo->blocktype==ID_WO) {
@@ -1909,12 +1910,22 @@ Ipo *get_ipo(ID *from, short type, int make)
        }
        else if( type==ID_AC) {
                act= (bAction *)from;
-               if (!act->achan) return NULL;
                if (act->id.lib) return NULL;
+               
+               /* weak... the *from pointer has action, ipo doesnt give more context info yet */
+               verify_active_action_channel(OBACT);
+               
+               if (act->achan==NULL)
+                       return NULL;
+               
                ipo= act->achan->ipo;
 
-               /* This should never happen */
-               if(make && ipo==NULL) ipo= act->achan->ipo= add_ipo("AcIpo", ID_AC);
+               if(make && ipo==NULL) {
+                       ipo= act->achan->ipo= add_ipo(act->achan->name, ID_AC);
+                       allspace(REMAKEIPO, 0);
+                       allqueue(REDRAWIPO, 0);
+                       allqueue(REDRAWACTION, 0);
+               }
        }
        else if( type==ID_MA) {
                ma= (Material *)from;
@@ -1998,13 +2009,11 @@ IpoCurve *get_ipocurve(ID *from, short type, int adrcode, Ipo *useipo)
        /* also test if ipo and ipocurve exist */
 
        if (useipo==NULL) {
-
                if (G.sipo==NULL || G.sipo->pin==0){
                        ipo= get_ipo(from, type, 1);    /* 1= make */
                }
                else
                        ipo = G.sipo->ipo;
-
                
                if(G.sipo) {
                        if (G.sipo->pin==0) G.sipo->ipo= ipo;