Revision: 23830
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23830
Author:   aligorith
Date:     2009-10-14 13:57:26 +0200 (Wed, 14 Oct 2009)

Log Message:
-----------
Drivers UI - Converting to Layout Engine

* Converted Drivers UI to mostly use the Layout Engine
* All the buttons that perform actions are not operators yet (the code for that 
would be quite icky still)

* I've added some (commented out) calls for the property definitions of Driver 
properties to perform Depsgraph updates. I've left these commented out until we 
have the option to turn off auto-updates, since with driver editing, that could 
be very dangerous.

* Drivers can now (in theory) use any ID-block, using the Any-ID template added 
earlier. However, be warned that the stupid depsgraph won't be able to cope 
with most of these cases.


TODO: 
- more fancy widgets for RNA-Path and Index will come later

Modified Paths:
--------------
    trunk/blender/source/blender/editors/animation/anim_channels_defines.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/space_graph/graph_buttons.c
    trunk/blender/source/blender/makesrna/intern/rna_fcurve.c

Modified: trunk/blender/source/blender/editors/animation/anim_channels_defines.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_channels_defines.c      
2009-10-14 11:17:59 UTC (rev 23829)
+++ trunk/blender/source/blender/editors/animation/anim_channels_defines.c      
2009-10-14 11:57:26 UTC (rev 23830)
@@ -2189,7 +2189,7 @@
 
 /* ------------------ */
 
-/* callback for widget settings - send notifiers */
+/* callback for (normal) widget settings - send notifiers */
 static void achannel_setting_widget_cb(bContext *C, void *poin, void *poin2)
 {
        WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN_EDIT, NULL);

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c        
2009-10-14 11:17:59 UTC (rev 23829)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c        
2009-10-14 11:57:26 UTC (rev 23830)
@@ -438,7 +438,6 @@
                uiItemL(row, "ID-Block:", 0);
        
        /* ID-Type Selector - just have a menu of icons */
-       // XXX should value really be 0?
        uiItemFullR(row, "", 0, ptr, propType, 0, 0, UI_ITEM_R_ICON_ONLY);
        
        /* ID-Block Selector - just use pointer widget... */

Modified: trunk/blender/source/blender/editors/space_graph/graph_buttons.c
===================================================================
--- trunk/blender/source/blender/editors/space_graph/graph_buttons.c    
2009-10-14 11:17:59 UTC (rev 23829)
+++ trunk/blender/source/blender/editors/space_graph/graph_buttons.c    
2009-10-14 11:57:26 UTC (rev 23830)
@@ -193,7 +193,7 @@
        }
        
        /* default for now */
-       WM_event_add_notifier(C, NC_SCENE, scene);
+       WM_event_add_notifier(C, NC_SCENE, scene); // XXX does this always work?
 }
 
 /* callback to remove the active driver */
@@ -251,21 +251,6 @@
        return graph_panel_context(C, NULL, NULL);
 }
 
-static void test_obpoin_but(struct bContext *C, char *name, ID **idpp)
-{
-       ID *id;
-       
-       id= CTX_data_main(C)->object.first;
-       while(id) {
-               if( strcmp(name, id->name+2)==0 ) {
-                       *idpp= id;
-                       id_lib_extern(id);      /* checks lib data, sets 
correct flag for saving then */
-                       return;
-               }
-               id= id->next;
-       }
-       *idpp= NULL;
-}
 
 /* driver settings for active F-Curve (only for 'Drivers' mode) */
 static void graph_panel_drivers(const bContext *C, Panel *pa)
@@ -275,91 +260,98 @@
        ChannelDriver *driver;
        DriverTarget *dtar;
        
-       PointerRNA rna_ptr;
+       PointerRNA driver_ptr;
+       uiLayout *col;
        uiBlock *block;
        uiBut *but;
-       int yco=85, i=0;
-
-       if(!graph_panel_context(C, &ale, &fcu))
+       
+       /* Get settings from context */
+       if (!graph_panel_context(C, &ale, &fcu))
                return;
-
        driver= fcu->driver;
        
-       block= uiLayoutAbsoluteBlock(pa->layout);
+       /* set event handler for panel */
+       block= uiLayoutGetBlock(pa->layout); // xxx?
        uiBlockSetHandleFunc(block, do_graph_region_driver_buttons, NULL);
        
-       /* general actions */
-       but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Update Dependencies", 10, 
200, 180, 22, NULL, 0.0, 0.0, 0, 0, "Force updates of dependencies");
-       uiButSetFunc(but, driver_update_flags_cb, fcu, NULL);
+       /* general actions - management */
+       col= uiLayoutColumn(pa->layout, 0);
+       block= uiLayoutGetBlock(col);
+               but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Update 
Dependencies", 0, 0, 10*UI_UNIT_X, 22, NULL, 0.0, 0.0, 0, 0, "Force updates of 
dependencies");
+               uiButSetFunc(but, driver_update_flags_cb, fcu, NULL);
+               
+               but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Remove Driver", 0, 
0, 10*UI_UNIT_X, 18, NULL, 0.0, 0.0, 0, 0, "Remove this driver");
+               uiButSetFunc(but, driver_remove_cb, ale, NULL);
+               
+       /* driver-level settings - type, expressions, and errors */
+       RNA_pointer_create(ale->id, &RNA_Driver, driver, &driver_ptr);
        
-       but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Remove Driver", 200, 200, 
110, 18, NULL, 0.0, 0.0, 0, 0, "Remove this driver");
-       uiButSetFunc(but, driver_remove_cb, ale, NULL);
-       
-       /* type */
-       uiDefBut(block, LABEL, 1, "Type:",                                      
10, 170, 60, 20, NULL, 0.0, 0.0, 0, 0, "");
-       uiDefButI(block, MENU, B_IPO_DEPCHANGE,
-                                       "Driver Type%t|Normal%x0|Scripted 
Expression%x1|Rotational Difference%x2", 
-                                       70,170,240,20, &driver->type, 0, 0, 0, 
0, "Driver type");
-       
-       /* show expression box if doing scripted drivers */
-       if (driver->type == DRIVER_TYPE_PYTHON) {
-               uiDefBut(block, TEX, B_REDR, "Expr: ", 10,150,300,20, 
driver->expression, 0, 255, 0, 0, "One-liner Python Expression to use as 
Scripted Expression");
+       col= uiLayoutColumn(pa->layout, 1);
+       block= uiLayoutGetBlock(col);
+               uiItemR(col, NULL, 0, &driver_ptr, "type", 0);
                
-               /* errors */
-               if (driver->flag & DRIVER_FLAG_INVALID) {
-                       uiDefIconBut(block, LABEL, 1, ICON_ERROR, 10, 130, 48, 
48, NULL, 0, 0, 0, 0, ""); // a bit larger
-                       uiDefBut(block, LABEL, 0, "Error: invalid Python 
expression",
-                                       50,110,230,19, NULL, 0, 0, 0, 0, "");
+               /* show expression box if doing scripted drivers, and/or error 
messages when invalid drivers exist */
+               if (driver->type == DRIVER_TYPE_PYTHON) {
+                       /* expression */
+                       uiItemR(col, "Expr:", 0, &driver_ptr, "expression", 0);
+                       
+                       /* errors? */
+                       if (driver->flag & DRIVER_FLAG_INVALID)
+                               uiItemL(col, "ERROR: invalid Python 
expression", ICON_ERROR);
                }
-       }
-       else {
-               /* errors */
-               if (driver->flag & DRIVER_FLAG_INVALID) {
-                       uiDefIconBut(block, LABEL, 1, ICON_ERROR, 10, 130, 48, 
48, NULL, 0, 0, 0, 0, ""); // a bit larger
-                       uiDefBut(block, LABEL, 0, "Error: invalid target 
channel(s)",
-                                       50,130,230,19, NULL, 0, 0, 0, 0, "");
+               else {
+                       /* errors? */
+                       if (driver->flag & DRIVER_FLAG_INVALID)
+                               uiItemL(col, "ERROR: invalid target 
channel(s)", ICON_ERROR);
                }
-       }
        
-       but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Add Variable", 10, 110, 
300, 20, NULL, 0.0, 0.0, 0, 0, "Add a new target variable for this Driver");
-       uiButSetFunc(but, driver_add_var_cb, driver, NULL);
+       /* add driver target variables */
+       col= uiLayoutColumn(pa->layout, 0);
+       block= uiLayoutGetBlock(col);
+               but= uiDefBut(block, BUT, B_IPO_DEPCHANGE, "Add Variable", 0, 
0, 10*UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "Add a new target variable 
for this Driver");
+               uiButSetFunc(but, driver_add_var_cb, driver, NULL);
        
        /* loop over targets, drawing them */
        for (dtar= driver->targets.first; dtar; dtar= dtar->next) {
-               short height = (dtar->id) ? 80 : 60;
+               PointerRNA dtar_ptr;
+               uiLayout *box, *row;
                
-               /* panel behind buttons */
-               uiDefBut(block, ROUNDBOX, B_REDR, "", 5, yco-height+25, 310, 
height, NULL, 5.0, 0.0, 12.0, 0, "");
+               /* panel holding the buttons */
+               box= uiLayoutBox(pa->layout);
                
-               /* variable name */
-               uiDefButC(block, TEX, B_REDR, "Name: ", 10,yco,280,20, 
dtar->name, 0, 63, 0, 0, "Name of target variable (No spaces or dots are 
allowed. Also, must not start with a symbol or digit).");
+               /* first row context info for driver */
+               RNA_pointer_create(ale->id, &RNA_DriverTarget, dtar, &dtar_ptr);
                
-               /* remove button */
-               but= uiDefIconBut(block, BUT, B_REDR, ICON_X, 290, yco, 20, 20, 
NULL, 0.0, 0.0, 0.0, 0.0, "Delete target variable.");
-               uiButSetFunc(but, driver_delete_var_cb, driver, dtar);
+               row= uiLayoutRow(box, 0);
+               block= uiLayoutGetBlock(row);
+                       /* variable name */
+                       uiItemR(row, "", 0, &dtar_ptr, "name", 0);
+                       
+                       /* remove button */
+                       but= uiDefIconBut(block, BUT, B_REDR, ICON_X, 290, 0, 
UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Delete target variable.");
+                       uiButSetFunc(but, driver_delete_var_cb, driver, dtar);
                
                
-               /* Target Object */
-               uiDefBut(block, LABEL, 1, "Value:",     10, yco-30, 60, 20, 
NULL, 0.0, 0.0, 0, 0, "");
-               uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_REDR, "Ob: ", 
70, yco-30, 240, 20, &dtar->id, "Object to use as Driver target");
+               /* Target ID */
+               row= uiLayoutRow(box, 0);
+                       uiTemplateAnyID(row, (bContext *)C, &dtar_ptr, "id", 
"id_type", "Value: ");
                
-               // XXX should we hide these technical details?
+               /* Target Property */
+               // TODO: make this less technical...
                if (dtar->id) {
-                       uiBlockBeginAlign(block);
-                               /* RNA Path */
-                               RNA_pointer_create(ale->id, &RNA_DriverTarget, 
dtar, &rna_ptr);
-                               uiDefButR(block, TEX, 0, "Path: ", 10, yco-50, 
250, 20, &rna_ptr, "rna_path", 0, 0, 0, -1, -1, "RNA Path (from Driver Object) 
to property used as Driver.");
-                                       
-                               /* Array Index */
-                               uiDefButI(block, NUM, B_REDR, "", 
260,yco-50,50,20, &dtar->array_index, 0, INT_MAX, 0, 0, "Index to the specific 
property used as Driver if applicable.");
-                       uiBlockEndAlign(block);
+                       col= uiLayoutColumn(box, 1);
+                       block= uiLayoutGetBlock(col);
+                               /* rna path */
+                               // TODO: this needs path constructor widget
+                               uiItemR(col, "Path", 0, &dtar_ptr, "rna_path", 
0);
+                               
+                               /* array index */
+                               // TODO: this needs selector which limits it to 
ok values
+                               uiItemR(col, "Index", 0, &dtar_ptr, 
"array_index", 0);
                }
-               
-               /* adjust y-coordinate for next target */
-               yco -= height;
-               i++;
        }
-
+       
+       /* cleanup */
        MEM_freeN(ale);
 }
 
@@ -373,8 +365,8 @@
        switch (event) {
                case B_REDR:
                case B_FMODIFIER_REDRAW: // XXX this should send depsgraph 
updates too
-                       ED_area_tag_redraw(CTX_wm_area(C));
-                       return; /* no notifier! */
+                       WM_event_add_notifier(C, NC_ANIMATION, NULL); // XXX 
need a notifier specially for F-Modifiers
+                       break;
        }
 }
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_fcurve.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_fcurve.c   2009-10-14 
11:17:59 UTC (rev 23829)
+++ trunk/blender/source/blender/makesrna/intern/rna_fcurve.c   2009-10-14 
11:57:26 UTC (rev 23830)
@@ -32,6 +32,7 @@
 #include "rna_internal.h"
 
 #include "DNA_anim_types.h"
+#include "DNA_object_types.h"
 #include "DNA_scene_types.h"
 
 #include "MEM_guardedalloc.h"
@@ -52,8 +53,6 @@
 
 #ifdef RNA_RUNTIME
 
-/* --------- */
-
 static StructRNA *rna_FModifierType_refine(struct PointerRNA *ptr)
 {
        FModifier *fcm= (FModifier *)ptr->data;
@@ -82,6 +81,21 @@
 
 /* ****************************** */
 
+#include "BKE_depsgraph.h"
+
+static void rna_ChannelDriver_update_data(bContext *C, PointerRNA *ptr)
+{
+       ID *id= ptr->id.data;
+       
+       // TODO: this really needs an update guard...
+       DAG_scene_sort(CTX_data_scene(C));
+       DAG_id_flush_update(id, OB_RECALC_DATA);
+       
+       WM_event_add_notifier(C, NC_SCENE, id);
+}
+
+/* ----------- */
+
 static StructRNA *rna_DriverTarget_id_typef(PointerRNA *ptr)
 {

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to