Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWillian Padovani Germano <wpgermano@gmail.com>2006-04-30 20:22:31 +0400
committerWillian Padovani Germano <wpgermano@gmail.com>2006-04-30 20:22:31 +0400
commit89dab4397d9eb2b9970ba28edeaf95c578dcaab4 (patch)
tree267c2faf6a9f2475630df2894a5e24832bc9ace4 /source/blender/src/drawipo.c
parent3b84767824d4f9666dfc5eea1fcf134d7643fb27 (diff)
Pydrivers: Ipo Drivers controlled by Python expressions
wiki with info: http://mediawiki.blender.org/index.php/BlenderDev/PyDrivers (there are two sample .blends in the patch tracker entry, last link in the wiki page) Notes: In usiblender.c I just made Python exit before the main library gets freed. I found a situation with pydrivers where py's gc tried to del objects on exit and their ID's were not valid anymore (so sigsegv). Ton needs to check the depsgraph part. For now pydrivers can reference their own object, something normal ipodrivers can't. This seems to work fine and is quite useful, but if tests prove the restriction is necessary, we just need to uncomment a piece of code in EXPP_interface.c, marked with "XXX". Thanks Ton for the ipodrivers code and adding the hooks for the py part and Martin for the "Button Python Evaluation" patch from which I started this one. Anyone interested, please check the wiki, the .blends (they have README's) and tell me about any issue.
Diffstat (limited to 'source/blender/src/drawipo.c')
-rw-r--r--source/blender/src/drawipo.c51
1 files changed, 44 insertions, 7 deletions
diff --git a/source/blender/src/drawipo.c b/source/blender/src/drawipo.c
index 642a7a0602e..ffbc8a67f9d 100644
--- a/source/blender/src/drawipo.c
+++ b/source/blender/src/drawipo.c
@@ -84,6 +84,8 @@
#include "BSE_editipo_types.h"
#include "BSE_editnla_types.h"
+#include "BPY_extern.h"
+
#include "mydevice.h"
#include "blendef.h"
#include "butspace.h" // shouldnt be...
@@ -1561,6 +1563,7 @@ static void draw_key(SpaceIpo *sipo, int visible)
#define B_IPO_DRIVER 3405
#define B_IPO_REDR 3406
#define B_IPO_DEPCHANGE 3407
+#define B_IPO_DRIVERTYPE 3408
static float hspeed= 0;
@@ -1755,7 +1758,12 @@ void do_ipobuts(unsigned short event)
ei= get_active_editipo();
if(ei) {
if(ei->icu->driver) {
- if(G.sipo->blocktype==ID_KE || G.sipo->blocktype==ID_AC)
+ if (ei->icu->driver->type == IPO_DRIVER_TYPE_PYTHON) {
+ /* eval user's expression once for validity */
+ BPY_pydriver_eval(ei->icu->driver);
+ DAG_scene_sort(G.scene);
+ }
+ else if(G.sipo->blocktype==ID_KE || G.sipo->blocktype==ID_AC)
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
else
DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
@@ -1814,14 +1822,39 @@ void do_ipobuts(unsigned short event)
BIF_undo_push("Add/Remove Ipo driver");
}
break;
+ case B_IPO_DRIVERTYPE:
+ ei= get_active_editipo();
+ if(ei) {
+ if(ei->icu->driver) {
+ IpoDriver *driver= ei->icu->driver;
+
+ if(driver->type == IPO_DRIVER_TYPE_PYTHON) {
+ /* pydriver expression shouldn't reference own ob,
+ * so we need to store ob ptr to check against it */
+ driver->ob= ob;
+ }
+ else {
+ driver->ob= NULL;
+ driver->blocktype= ID_OB;
+ driver->adrcode= OB_LOC_X;
+ driver->flag &= ~IPO_DRIVER_FLAG_INVALID;
+ }
+ }
+ allqueue(REDRAWVIEW3D, 0);
+ allqueue(REDRAWIPO, 0);
+ allqueue(REDRAWBUTSEDIT, 0);
+ DAG_scene_sort(G.scene);
+
+ BIF_undo_push("Change Ipo driver type");
+ }
+ break;
case B_IPO_DEPCHANGE:
ei= get_active_editipo();
if(ei) {
if(ei->icu->driver) {
IpoDriver *driver= ei->icu->driver;
- if(driver->flag & IPO_DRIVER_PYTHON) {
- driver->ob= NULL;
+ if(driver->type == IPO_DRIVER_TYPE_PYTHON) {
}
else {
if(driver->ob) {
@@ -1918,14 +1951,18 @@ static void ipo_panel_properties(short cntrl) // IPO_HANDLER_PROPERTIES
if(ei->icu && ei->icu->driver) {
IpoDriver *driver= ei->icu->driver;
-
+
uiDefBut(block, BUT, B_IPO_DRIVER, "Remove", 210,265,100,20, NULL, 0.0f, 0.0f, 0, 0, "Remove Driver for this Ipo Channel");
uiBlockBeginAlign(block);
- uiDefIconButBitS(block, TOG, IPO_DRIVER_PYTHON, B_IPO_DEPCHANGE, ICON_PYTHON, 10,240,25,20, &driver->flag, 0, 0, 0, 0, "Use a one-line Python Expression as Driver");
-
- if(driver->flag & IPO_DRIVER_PYTHON) {
+ uiDefIconButS(block, TOG, B_IPO_DRIVERTYPE, ICON_PYTHON, 10,240,25,20, &driver->type, (float)IPO_DRIVER_TYPE_NORMAL, (float)IPO_DRIVER_TYPE_PYTHON, 0, 0, "Use a one-line Python Expression as Driver");
+
+ if(driver->type == IPO_DRIVER_TYPE_PYTHON) {
uiDefBut(block, TEX, B_IPO_REDR, "", 35,240,275,20, driver->name, 0, 127, 0, 0, "Python Expression");
+ if(driver->flag & IPO_DRIVER_FLAG_INVALID) {
+ uiDefBut(block, LABEL, 0, "Error: invalid Python expression",
+ 5,215,230,19, NULL, 0, 0, 0, 0, "");
+ }
uiBlockEndAlign(block);
}
else {