Bugfixes:
authorJoshua Leung <aligorith@gmail.com>
Thu, 22 Oct 2009 23:23:09 +0000 (23:23 +0000)
committerJoshua Leung <aligorith@gmail.com>
Thu, 22 Oct 2009 23:23:09 +0000 (23:23 +0000)
* The python 'math' library is now included in the py-namespace used to evaluate button expressions. So it is now possible to do 'radians(somevalue)' to get a rotation value that Blender can understand...

* Shapekey path getting function now uses the appropriate wrapper for grabbing the pointer to the ID block for the ShapeKey

* Made the Graph Editor's minimum zoom size finer...

source/blender/editors/space_graph/space_graph.c
source/blender/makesrna/intern/rna_key.c
source/blender/python/intern/bpy_interface.c

index b4b06844d1392a5bfa003f502d6933ef7d3e4422..342afab753468bdafe3649bb774ec2f0b23af214 100644 (file)
@@ -151,8 +151,8 @@ static SpaceLink *graph_new(const bContext *C)
        
        ar->v2d.cur= ar->v2d.tot;
        
-       ar->v2d.min[0]= 0.01f;
-       ar->v2d.min[1]= 0.01f;
+       ar->v2d.min[0]= 0.001f;
+       ar->v2d.min[1]= 0.001f;
        
        ar->v2d.max[0]= MAXFRAMEF;
        ar->v2d.max[1]= 50000.0f;
index 433e5a7e4a30caa8a211e74cd0cc55f77b939c57..ca36da5d03b85161e48b50d607f322c06e5dcdde 100644 (file)
 #include "WM_api.h"
 #include "WM_types.h"
 
+static Key *rna_ShapeKey_find_key(ID *id)
+{
+       switch(GS(id->name)) {
+               case ID_CU: return ((Curve*)id)->key;
+               case ID_KE: return (Key*)id;
+               case ID_LT: return ((Lattice*)id)->key;
+               case ID_ME: return ((Mesh*)id)->key;
+               default: return NULL;
+       }
+}
+
 void rna_ShapeKey_name_set(PointerRNA *ptr, const char *value)
 {
        KeyBlock *kb= ptr->data;
@@ -63,7 +74,7 @@ void rna_ShapeKey_name_set(PointerRNA *ptr, const char *value)
        
        /* make sure the name is truly unique */
        if (ptr->id.data) {
-               Key *key= ptr->id.data;
+               Key *key= rna_ShapeKey_find_key(ptr->id.data);
                BLI_uniquename(&key->block, kb, "Key", '.', offsetof(KeyBlock, name), 32);
        }
        
@@ -86,17 +97,6 @@ static void rna_ShapeKey_value_range(PointerRNA *ptr, float *min, float *max)
        *max= data->slidermax;
 }
 
-static Key *rna_ShapeKey_find_key(ID *id)
-{
-       switch(GS(id->name)) {
-               case ID_CU: return ((Curve*)id)->key;
-               case ID_KE: return (Key*)id;
-               case ID_LT: return ((Lattice*)id)->key;
-               case ID_ME: return ((Mesh*)id)->key;
-               default: return NULL;
-       }
-}
-
 static PointerRNA rna_ShapeKey_relative_key_get(PointerRNA *ptr)
 {
        Key *key= rna_ShapeKey_find_key(ptr->id.data);
index 9e76c1d03aa145b45493a04c54cb3c79076a0a88..095bfab45c4055dab7b033030c9fe02afd842661 100644 (file)
@@ -884,7 +884,7 @@ float BPY_pydriver_eval (ChannelDriver *driver)
 int BPY_button_eval(bContext *C, char *expr, double *value)
 {
        PyGILState_STATE gilstate;
-       PyObject *dict, *retval;
+       PyObject *dict, *mod, *retval;
        int error_ret = 0;
        
        if (!value || !expr || expr[0]=='\0') return -1;
@@ -892,6 +892,20 @@ int BPY_button_eval(bContext *C, char *expr, double *value)
        bpy_context_set(C, &gilstate);
        
        dict= CreateGlobalDictionary(C);
+       
+       /* import some modules: builtins,math*/
+       PyDict_SetItemString(dict, "__builtins__", PyEval_GetBuiltins());
+
+       mod = PyImport_ImportModule("math");
+       if (mod) {
+               PyDict_Merge(dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
+               
+               /* Only keep for backwards compat! - just import all math into root, they are standard */
+               PyDict_SetItemString(dict, "math", mod);
+               PyDict_SetItemString(dict, "m", mod);
+               Py_DECREF(mod);
+       } 
+       
        retval = PyRun_String(expr, Py_eval_input, dict, dict);
        
        if (retval == NULL) {