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:
authorCampbell Barton <ideasman42@gmail.com>2006-09-24 12:30:38 +0400
committerCampbell Barton <ideasman42@gmail.com>2006-09-24 12:30:38 +0400
commite8495d1fdd7623cbd42cac1b30406dc6dbc0ee06 (patch)
treedbd207a21edfb748c872d3672517f2f97e6f383c /source/blender/python/api2_2x/Modifier.c
parente136fe0acb5d9e5d39fddec7dba4f49f807ffc7c (diff)
Extra generic errors for Scene, Groups and Metaballs to raise errors when trying to do anything with a python objects thats had its data removed in Blender.
Added to existing scn.objects scn.objects.active (get/set the active object for the scene) scn.objects.selected - an iterator that only uses selected objects scn.objects.context - an iterator on objects in the user context (visible in the current 3d views layer and selected) These are the same type as scn.objects but .add() .remove() .new() .active etc raise errors. so scn.objects.selected.add() will raise an error. Made nested loops possible with scn.objects, metaball.elements and ob.modifiers, by initializing the iter value as NULL and creating copys of the pyobject when _getIter() is called if ->iter is not NULL. This is how pythons xrange() works.
Diffstat (limited to 'source/blender/python/api2_2x/Modifier.c')
-rw-r--r--source/blender/python/api2_2x/Modifier.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/source/blender/python/api2_2x/Modifier.c b/source/blender/python/api2_2x/Modifier.c
index 89faa8c86d9..9c597f2618c 100644
--- a/source/blender/python/api2_2x/Modifier.c
+++ b/source/blender/python/api2_2x/Modifier.c
@@ -27,6 +27,9 @@
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
+/* TODO, accessing a modifier sequence of a deleted object will crash blender at the moment, not sure how to fix this. */
+
+
#include "Modifier.h" /*This must come first*/
#include "DNA_object_types.h"
@@ -48,6 +51,10 @@
#include "Mathutils.h"
#include "gen_utils.h"
+/* checks for the scene being removed */
+#define MODIFIER_DEL_CHECK_PY(bpy_modifier) if (!(bpy_modifier->md)) return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "Modifier has been removed" ) )
+#define MODIFIER_DEL_CHECK_INT(bpy_modifier) if (!(bpy_modifier->md)) return ( EXPP_ReturnIntError( PyExc_RuntimeError, "Modifier has been removed" ) )
+
enum mod_constants {
/*Apply to all modifiers*/
EXPP_MOD_RENDER = 0,
@@ -252,10 +259,7 @@ PyTypeObject Modifier_Type = {
static PyObject *Modifier_getName( BPy_Modifier * self )
{
- if (self->md==NULL)
- return (EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This modifier has been removed!" ));
-
+ MODIFIER_DEL_CHECK_PY(self);
return PyString_FromString( self->md->name );
}
@@ -269,9 +273,7 @@ static int Modifier_setName( BPy_Modifier * self, PyObject * attr )
if( !name )
return EXPP_ReturnIntError( PyExc_TypeError, "expected string arg" );
- if (self->md==NULL)
- return (EXPP_ReturnIntError( PyExc_RuntimeError,
- "This modifier has been removed!" ));
+ MODIFIER_DEL_CHECK_INT(self);
BLI_strncpy( self->md->name, name, sizeof( self->md->name ) );
@@ -284,9 +286,7 @@ static int Modifier_setName( BPy_Modifier * self, PyObject * attr )
static PyObject *Modifier_getType( BPy_Modifier * self )
{
- if (self->md==NULL )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This modifier has been removed!" );
+ MODIFIER_DEL_CHECK_PY(self);
return PyInt_FromLong( self->md->type );
}
@@ -729,9 +729,7 @@ static PyObject *Modifier_getData( BPy_Modifier * self, PyObject * key )
return EXPP_ReturnPyObjError( PyExc_TypeError,
"expected an int arg as stored in Blender.Modifier.Settings" );
- if (self->md==NULL )
- return EXPP_ReturnPyObjError( PyExc_RuntimeError,
- "This modifier has been removed!" );
+ MODIFIER_DEL_CHECK_PY(self);
setting = PyInt_AsLong( key );
switch( setting ) {
@@ -784,9 +782,7 @@ static int Modifier_setData( BPy_Modifier * self, PyObject * key,
return EXPP_ReturnIntError( PyExc_TypeError,
"expected an int arg as stored in Blender.Modifier.Settings" );
- if (self->md==NULL )
- return EXPP_ReturnIntError( PyExc_RuntimeError,
- "This modifier has been removed!" );
+ MODIFIER_DEL_CHECK_INT(self);
key_int = PyInt_AsLong( key );
@@ -910,8 +906,12 @@ ModifierData *Modifier_FromPyObject( PyObject * pyobj )
static PyObject *Modifiers_getIter( BPy_Modifiers * self )
{
- self->iter = (ModifierData *)self->obj->modifiers.first;
- return EXPP_incr_ret ( (PyObject *) self );
+ if (!self->iter) {
+ self->iter = (ModifierData *)self->obj->modifiers.first;
+ return EXPP_incr_ret ( (PyObject *) self );
+ } else {
+ return ModSeq_CreatePyObject(self->obj, (ModifierData *)self->obj->modifiers.first);
+ }
}
/*
@@ -920,12 +920,13 @@ static PyObject *Modifiers_getIter( BPy_Modifiers * self )
static PyObject *Modifiers_nextIter( BPy_Modifiers * self )
{
- ModifierData *this = self->iter;
- if( this ) {
- self->iter = this->next;
- return Modifier_CreatePyObject( self->obj, this );
+ ModifierData *iter = self->iter;
+ if( iter ) {
+ self->iter = iter->next;
+ return Modifier_CreatePyObject( self->obj, iter );
}
-
+
+ self->iter= NULL; /* mark as not iterating */
return EXPP_ReturnPyObjError( PyExc_StopIteration,
"iterator at end" );
}
@@ -1195,7 +1196,7 @@ PyTypeObject Modifiers_Type = {
/* Description: This function will create a new BPy_Modifiers from an */
/* existing ListBase structure. */
/*****************************************************************************/
-PyObject *ModSeq_CreatePyObject( Object *obj )
+PyObject *ModSeq_CreatePyObject( Object *obj, ModifierData *iter )
{
BPy_Modifiers *pymod;
pymod = ( BPy_Modifiers * ) PyObject_NEW( BPy_Modifiers, &Modifiers_Type );
@@ -1203,6 +1204,7 @@ PyObject *ModSeq_CreatePyObject( Object *obj )
return EXPP_ReturnPyObjError( PyExc_MemoryError,
"couldn't create BPy_Modifiers object" );
pymod->obj = obj;
+ pymod->iter = iter;
return ( PyObject * ) pymod;
}