[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11267] branches/pyapi_devel/source/ blender/python/api2_2x: * Object, made softbodies a seperate type rather then having its variables mised up with object .
Campbell Barton
cbarton at metavr.com
Fri Jul 13 18:37:27 CEST 2007
Revision: 11267
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11267
Author: campbellbarton
Date: 2007-07-13 18:37:27 +0200 (Fri, 13 Jul 2007)
Log Message:
-----------
* Object, made softbodies a seperate type rather then having its variables mised up with object.
This makes sense in that not all objects have this data and its a seperate type internaly.
ob.softBody.mass = 0.5 # for instance
* Draw, callback bugfix from trunk
* Lamp - use radians for lamp angle
Modified Paths:
--------------
branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c
branches/pyapi_devel/source/blender/python/api2_2x/Draw.c
branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
branches/pyapi_devel/source/blender/python/api2_2x/Object.c
branches/pyapi_devel/source/blender/python/api2_2x/Object.h
branches/pyapi_devel/source/blender/python/api2_2x/Scene.c
Added Paths:
-----------
branches/pyapi_devel/source/blender/python/api2_2x/object_softbody.c
branches/pyapi_devel/source/blender/python/api2_2x/object_softbody.h
Modified: branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c 2007-07-13 16:10:34 UTC (rev 11266)
+++ branches/pyapi_devel/source/blender/python/api2_2x/BezTriple.c 2007-07-13 16:37:27 UTC (rev 11267)
@@ -350,7 +350,12 @@
static int BezTriple_setHide( BPy_BezTriple * self, PyObject *value )
{
- if( PyObject_IsTrue( value ) )
+ int pybool = PyObject_IsTrue( value );
+ if (pybool==-1)
+ return EXPP_ReturnIntError( PyExc_TypeError,
+ "expected 1/0 or true/false" );
+
+ if(pybool)
self->beztriple->hide = IPO_BEZ;
else
self->beztriple->hide = 0;
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Draw.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Draw.c 2007-07-13 16:10:34 UTC (rev 11266)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Draw.c 2007-07-13 16:37:27 UTC (rev 11267)
@@ -103,10 +103,10 @@
static void spacescript_do_pywin_buttons( SpaceScript * sc,
unsigned short event );
-static PyObject *Method_Exit( PyObject * self, PyObject * args );
+static PyObject *Method_Exit( PyObject * self );
static PyObject *Method_Register( PyObject * self, PyObject * args );
static PyObject *Method_Redraw( PyObject * self, PyObject * args );
-static PyObject *Method_Draw( PyObject * self, PyObject * args );
+static PyObject *Method_Draw( PyObject * self );
static PyObject *Method_Create( PyObject * self, PyObject * args );
static PyObject *Method_UIBlock( PyObject * self, PyObject * args );
@@ -134,12 +134,19 @@
/* CLEVER NUMBUT */
static PyObject *Method_PupBlock( PyObject * self, PyObject * args );
+PyObject * pycallback_weakref_dealloc(PyObject *self, PyObject *weakref);
+/* python callable */
+PyObject * pycallback_weakref_dealloc__pyfunc;
+
static uiBlock *Get_uiBlock( void );
static void py_slider_update( void *butv, void *data2_unused );
/* hack to get 1 block for the UIBlock, only ever 1 at a time */
static uiBlock *uiblock=NULL;
+/* store weakref's to callbacks here */
+static PyObject *callback_list;
+
static char Draw_doc[] = "The Blender.Draw submodule";
static char Method_UIBlock_doc[] = "(drawfunc, x,y) - Popup dialog where buttons can be drawn (expemental)";
@@ -389,11 +396,11 @@
MethodDef( PupStrInput ),
MethodDef( PupBlock ),
MethodDef( Image ),
- MethodDef( Exit ),
+ {"Exit", (PyCFunction)Method_Exit, METH_NOARGS, Method_Exit_doc},
MethodDef( Redraw ),
- MethodDef( Draw ),
+ {"Draw", (PyCFunction)Method_Draw, METH_NOARGS, Method_Draw_doc},
MethodDef( Register ),
- {"PushButton", Method_Button, METH_VARARGS, Method_Button_doc},
+ {"PushButton", (PyCFunction)Method_Button, METH_VARARGS, Method_Button_doc},
MethodDef( BeginAlign ),
MethodDef( EndAlign),
{NULL, NULL, 0, NULL}
@@ -591,11 +598,7 @@
static Button *newbutton( void )
{
- Button *but = NULL;
-
- but = ( Button * ) PyObject_NEW( Button, &Button_Type );
-
- return but;
+ return ( Button * ) PyObject_NEW( Button, &Button_Type );
}
/* GUI interface routines */
@@ -710,7 +713,10 @@
if (event == UI_BUT_EVENT) {
/* check that event is in free range for script button events;
- * read the comment before check_button_event() below to understand */
+ * read the comment before check_button_event() below to understand
+ *
+ * This will never run from UIBlock so no need to check if uiblock==NULL
+ * And only sub EXPP_BUTTON_EVENTS_OFFSET in that case */
if (val >= EXPP_BUTTON_EVENTS_OFFSET && val < 0x4000)
spacescript_do_pywin_buttons(sc, val - EXPP_BUTTON_EVENTS_OFFSET);
return;
@@ -738,7 +744,7 @@
static void exec_but_callback(void *pyobj, void *data)
{
PyObject *result;
- PyObject * pyvalue;
+ PyObject *pyvalue = NULL;
uiBut *but = (uiBut *)data;
PyObject *arg;
PyObject *callback = (PyObject *)pyobj;
@@ -748,6 +754,14 @@
if (callback==NULL || callback == Py_None)
return;
+ if (callback) {
+ if (!PySequence_Contains(callback_list, callback)) {
+ printf("Error, the callback is out of scope.\n\tmake the callback global to resolve this.\n");
+ return;
+ }
+ callback = PyWeakref_GetObject(callback);
+ }
+
/* Button types support
case MENU:
case TEX:
@@ -814,13 +828,34 @@
Py_XDECREF( result );
}
+PyObject * pycallback_weakref_dealloc(PyObject *self, PyObject *weakref)
+{
+ int i = PySequence_Index(callback_list, weakref);
+ if (i==-1) {
+ printf("callback weakref internal error, weakref not in list\n\tthis should never happen.\n");
+ return NULL;
+ }
+ PySequence_DelItem(callback_list, i);
+ Py_RETURN_NONE;
+}
static void set_pycallback(uiBut *ubut, PyObject *callback)
{
+ PyObject *weakref;
if (!callback || !PyCallable_Check(callback)) return;
- uiButSetFunc(ubut, exec_but_callback, callback, ubut);
+
+ /* This works in most cases except where there are local functions
+ * that are deallocated so we must use weakrefs, will complain rather then crashing */
+ /*uiButSetFunc(ubut, exec_but_callback, callback, ubut);*/
+
+ weakref = PyWeakref_NewRef(callback, pycallback_weakref_dealloc__pyfunc);
+ PyList_Append(callback_list, weakref);
+ Py_DECREF(weakref);
+
+ /*printf("adding weakref, totlength %i\n", PyList_Size(callback_list));*/
+ uiButSetFunc(ubut, exec_but_callback, weakref, ubut);
}
-static PyObject *Method_Exit( PyObject * self, PyObject * args )
+static PyObject *Method_Exit( PyObject * self )
{
SpaceScript *sc;
Script *script;
@@ -832,10 +867,6 @@
else
Py_RETURN_NONE;
- if( !PyArg_ParseTuple( args, "" ) )
- return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected empty argument list" );
-
exit_pydraw( sc, 0 );
script = sc->script;
@@ -950,7 +981,7 @@
Py_RETURN_NONE;
}
-static PyObject *Method_Draw( PyObject * self, PyObject * args )
+static PyObject *Method_Draw( PyObject * self )
{
/*@ If forced drawing is disable queue a redraw event instead */
if( EXPP_disable_force_draw ) {
@@ -958,10 +989,6 @@
Py_RETURN_NONE;
}
- if( !PyArg_ParseTuple( args, "" ) )
- return EXPP_ReturnPyObjError( PyExc_AttributeError,
- "expected empty argument list" );
-
scrarea_do_windraw( curarea );
screen_swapbuffers( );
@@ -1200,13 +1227,13 @@
disable_where_script( 1 );
spacescript_do_pywin_buttons( curarea->spacedata.first,
- (unsigned short)uiButGetRetVal( but ) );
+ (unsigned short)uiButGetRetVal( but ) - EXPP_BUTTON_EVENTS_OFFSET);
/* XXX useless right now, investigate better before a bcon 5 */
ret = M_Window_Redraw( 0, ref );
Py_DECREF(ref);
- if (ret) { Py_DECREF(ret); }
+ Py_XDECREF(ret);
disable_where_script( 0 );
@@ -1232,6 +1259,9 @@
UI_METHOD_ERRORCHECK;
+ if(realtime && uiblock)
+ realtime = 0; /* realtime dosnt work with UIBlock */
+
but = newbutton( );
if( PyFloat_Check( inio ) ) {
@@ -1461,9 +1491,9 @@
if (!range) range= 1.0f; /* avoid any odd errors */
/* set the precission to display*/
- if (range>=100.0f) precission=1.0f;
- else if (range>=10.0f) precission=2.0f;
- else if (range>=1.0f) precission=3.0f;
+ if (range>=1000.0f) precission=1.0f;
+ else if (range>=100.0f) precission=2.0f;
+ else if (range>=10.0f) precission=3.0f;
else precission=4.0f;
but->type = BFLOAT_TYPE;
@@ -1966,17 +1996,26 @@
}
+static PyMethodDef bpycallback_weakref_dealloc[] = {
+ {"pycallback_weakref_dealloc", pycallback_weakref_dealloc, METH_O, ""}
+};
+
PyObject *Draw_Init( void )
{
PyObject *submodule, *dict;
-
+
+ /* Weakref management - used for callbacks so we can
+ * tell when a callback has been removed that a UI button referenced */
+ callback_list = PyList_New(0);
+ pycallback_weakref_dealloc__pyfunc = PyCFunction_New(bpycallback_weakref_dealloc, NULL);
+
if( PyType_Ready( &Button_Type) < 0)
Py_RETURN_NONE;
submodule = Py_InitModule3( "Blender.Draw", Draw_methods, Draw_doc );
dict = PyModule_GetDict( submodule );
-
+
#define EXPP_ADDCONST(x) \
EXPP_dict_set_item_str(dict, #x, PyInt_FromLong(x))
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c 2007-07-13 16:10:34 UTC (rev 11266)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Lamp.c 2007-07-13 16:37:27 UTC (rev 11267)
@@ -167,7 +167,7 @@
param = la->dist;
break;
case EXPP_LAMP_ATTR_SPOTSIZE:
- param = la->spotsize;
+ param = la->spotsize / (180.0/M_PI);
break;
case EXPP_LAMP_ATTR_SPOTBLEND:
param = la->spotblend;
@@ -237,6 +237,7 @@
float *param;
Lamp *la = self->lamp;
float min, max;
+ int ret;
switch( (int)type ) {
case EXPP_LAMP_ATTR_ENERGY:
@@ -319,8 +320,14 @@
return EXPP_ReturnIntError( PyExc_RuntimeError,
"undefined type in setFloatAttrClamp" );
}
+
+ ret= EXPP_setFloatClamped( value, param, min, max );
- return EXPP_setFloatClamped( value, param, min, max );
+ /* convert bach to degrees */
+ if (ret != -1 && (int)type == EXPP_LAMP_ATTR_SPOTSIZE)
+ la->spotsize *= (180.0/M_PI);
+
+ return ret;
}
/*
Modified: branches/pyapi_devel/source/blender/python/api2_2x/Object.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/Object.c 2007-07-13 16:10:34 UTC (rev 11266)
+++ branches/pyapi_devel/source/blender/python/api2_2x/Object.c 2007-07-13 16:37:27 UTC (rev 11267)
@@ -119,6 +119,7 @@
#include "BIF_editkey.h"
#include "IDProp.h"
#include "bpy_list.h"
+#include "object_softbody.h"
/* Defines for insertIpoKey */
@@ -188,94 +189,8 @@
EXPP_OBJ_ATTR_PI_SBIFACETHICK,
EXPP_OBJ_ATTR_PI_SBOFACETHICK,
- EXPP_OBJ_ATTR_SB_NODEMASS, /* these need to stay together */
- EXPP_OBJ_ATTR_SB_GRAV, /* and in order */
- EXPP_OBJ_ATTR_SB_MEDIAFRICT,
- EXPP_OBJ_ATTR_SB_RKLIMIT,
- EXPP_OBJ_ATTR_SB_PHYSICSSPEED,
- EXPP_OBJ_ATTR_SB_GOALSPRING,
- EXPP_OBJ_ATTR_SB_GOALFRICT,
- EXPP_OBJ_ATTR_SB_MINGOAL,
- EXPP_OBJ_ATTR_SB_MAXGOAL,
- EXPP_OBJ_ATTR_SB_DEFGOAL,
- EXPP_OBJ_ATTR_SB_INSPRING,
- EXPP_OBJ_ATTR_SB_INFRICT,
-
};
-#define EXPP_OBJECT_DRAWSIZEMIN 0.01f
-#define EXPP_OBJECT_DRAWSIZEMAX 10.0f
-
-/* clamping and range values for particle interaction settings */
-#define EXPP_OBJECT_PIDAMP_MIN 0.0f
-#define EXPP_OBJECT_PIDAMP_MAX 1.0f
-#define EXPP_OBJECT_PIRDAMP_MIN 0.0f
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list