37
38
/* Python BPy_Effect methods table: */
38
39
/*****************************************************************************/
39
40
static PyMethodDef BPy_Effect_methods[] = {
43
44
/*****************************************************************************/
44
45
/* Python Effect_Type structure definition: */
45
46
/*****************************************************************************/
46
PyTypeObject Effect_Type =
48
PyObject_HEAD_INIT(NULL)
50
"Effect", /* tp_name */
51
sizeof (BPy_Effect), /* tp_basicsize */
54
(destructor)EffectDeAlloc, /* tp_dealloc */
56
(getattrfunc)EffectGetAttr, /* tp_getattr */
57
(setattrfunc)EffectSetAttr, /* tp_setattr */
59
(reprfunc)EffectRepr, /* tp_repr */
61
0, /* tp_as_sequence */
62
0, /* tp_as_mapping */
67
BPy_Effect_methods, /* tp_methods */
47
PyTypeObject Effect_Type = {
48
PyObject_HEAD_INIT( NULL )
50
"Effect", /* tp_name */
51
sizeof( BPy_Effect ), /* tp_basicsize */
54
( destructor ) EffectDeAlloc, /* tp_dealloc */
56
( getattrfunc ) EffectGetAttr, /* tp_getattr */
57
( setattrfunc ) EffectSetAttr, /* tp_setattr */
59
( reprfunc ) EffectRepr, /* tp_repr */
61
0, /* tp_as_sequence */
62
0, /* tp_as_mapping */
67
BPy_Effect_methods, /* tp_methods */
71
71
/*****************************************************************************/
78
78
struct PyMethodDef M_Effect_methods[] = {
79
{"New",(PyCFunction)M_Effect_New, METH_VARARGS,NULL},
80
{"Get", M_Effect_Get, METH_VARARGS,NULL},
81
{"get", M_Effect_Get, METH_VARARGS, NULL},
79
{"New", ( PyCFunction ) M_Effect_New, METH_VARARGS, NULL},
80
{"Get", M_Effect_Get, METH_VARARGS, NULL},
81
{"get", M_Effect_Get, METH_VARARGS, NULL},
85
85
/*****************************************************************************/
86
86
/* Function: M_Effect_New */
87
87
/* Python equivalent: Blender.Effect.New */
88
88
/*****************************************************************************/
89
PyObject *M_Effect_New(PyObject *self, PyObject *args)
89
PyObject *M_Effect_New( PyObject * self, PyObject * args )
97
if (!PyArg_ParseTuple(args, "s",&btype))
98
return (EXPP_ReturnPyObjError (PyExc_TypeError,
99
"expected type argument(wave,build or particle)"));
100
if (!strcmp( btype,"wave"))type = EFF_WAVE;
101
if (!strcmp( btype,"build"))type = EFF_BUILD;
102
if (!strcmp( btype,"particle"))type = EFF_PARTICLE;
104
return (EXPP_ReturnPyObjError (PyExc_TypeError,
108
bleffect = add_effect(type);
109
if (bleffect == NULL)
110
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
111
"couldn't create Effect Data in Blender"));
113
pyeffect = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
116
if (pyeffect == NULL) return (EXPP_ReturnPyObjError (PyExc_MemoryError,
117
"couldn't create Effect Data object"));
119
pyeffect->effect = bleffect;
121
return (PyObject *)pyeffect;
97
if( !PyArg_ParseTuple( args, "s", &btype ) )
98
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
99
"expected type argument(wave,build or particle)" ) );
100
if( !strcmp( btype, "wave" ) )
102
if( !strcmp( btype, "build" ) )
104
if( !strcmp( btype, "particle" ) )
107
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
111
bleffect = add_effect( type );
112
if( bleffect == NULL )
113
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
114
"couldn't create Effect Data in Blender" ) );
116
pyeffect = ( BPy_Effect * ) PyObject_NEW( BPy_Effect, &Effect_Type );
119
if( pyeffect == NULL )
120
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
121
"couldn't create Effect Data object" ) );
123
pyeffect->effect = bleffect;
125
return ( PyObject * ) pyeffect;
124
128
/*****************************************************************************/
125
129
/* Function: M_Effect_Get */
126
130
/* Python equivalent: Blender.Effect.Get */
127
131
/*****************************************************************************/
128
PyObject *M_Effect_Get(PyObject *self, PyObject *args)
132
PyObject *M_Effect_Get( PyObject * self, PyObject * args )
130
/*arguments : string object name
131
int : position of effect in the obj's effect list */
135
BPy_Effect *wanted_eff;
137
if (!PyArg_ParseTuple(args, "|si", &name, &num ))
138
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
139
"expected string int argument"));
140
object_iter = G.main->object.first;
141
if (!object_iter)return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
142
"Scene contains no object"));
146
if (strcmp(name,object_iter->id.name+2))
148
object_iter = object_iter->id.next;
153
if (object_iter->effect.first != NULL){
154
eff = object_iter->effect.first;
155
for(i = 0;i<num;i++)eff = eff->next;
156
wanted_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
157
wanted_eff->effect = eff;
158
return (PyObject*)wanted_eff;
134
/*arguments : string object name
135
int : position of effect in the obj's effect list */
139
BPy_Effect *wanted_eff;
142
if( !PyArg_ParseTuple( args, "|si", &name, &num ) )
143
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
144
"expected string int argument" ) );
146
object_iter = G.main->object.first;
149
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
150
"Scene contains no object" ) );
152
if( name ) { /* (name, num = -1) - try to find the given object */
154
while( object_iter ) {
156
if( !strcmp( name, object_iter->id.name + 2 ) ) {
158
eff = object_iter->effect.first; /*can be NULL: None will be returned*/
160
if (num >= 0) { /* return effect in given num position if available */
162
for( i = 0; i < num; i++ ) {
168
wanted_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
169
wanted_eff->effect = eff;
170
return ( PyObject * ) wanted_eff;
171
} else { /* didn't find any effect in the given position */
160
object_iter = object_iter->id.next;
164
PyObject * effectlist = PyList_New (0);
167
if (object_iter->effect.first != NULL){
168
eff = object_iter->effect.first;
170
BPy_Effect *found_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
177
else {/*return a list with all effects linked to the given object*/
178
/* this was pointed by Stephen Swaney */
179
PyObject *effectlist = PyList_New( 0 );
182
BPy_Effect *found_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect,
171
184
found_eff->effect = eff;
172
PyList_Append (effectlist , (PyObject *)found_eff);
185
PyList_Append( effectlist, ( PyObject * ) found_eff );
186
Py_DECREF((PyObject *)found_eff); /* PyList_Append incref'ed it */
176
object_iter = object_iter->id.next;
193
object_iter = object_iter->id.next;
197
return EXPP_ReturnPyObjError (PyExc_AttributeError,
201
else { /* () - return a list with all effects currently in Blender */
202
PyObject *effectlist = PyList_New( 0 );
204
while( object_iter ) {
205
if( object_iter->effect.first != NULL ) {
206
eff = object_iter->effect.first;
208
BPy_Effect *found_eff =
210
PyObject_NEW( BPy_Effect,
212
found_eff->effect = eff;
213
PyList_Append( effectlist,
216
Py_DECREF((PyObject *)found_eff);
220
object_iter = object_iter->id.next;
178
222
return effectlist;
224
Py_INCREF( Py_None );
184
228
/*****************************************************************************/
186
230
/*****************************************************************************/
189
PyObject *Build_Init (void);
190
PyObject *Wave_Init (void);
191
PyObject *Particle_Init (void);
193
PyObject *Effect_Init (void)
195
PyObject *submodule, *dict;
197
Effect_Type.ob_type = &PyType_Type;
199
submodule = Py_InitModule3("Blender.Effect",M_Effect_methods, 0 );
200
dict = PyModule_GetDict (submodule);
201
PyDict_SetItemString (dict, "Wave", Wave_Init());
202
PyDict_SetItemString (dict, "Build", Build_Init());
203
PyDict_SetItemString (dict, "Particle", Particle_Init());
207
/*****************************************************************************/
208
/* Python BPy_Effect methods: */
209
/*****************************************************************************/
211
PyObject *Effect_getType(BPy_Effect *self)
213
PyObject *attr = PyInt_FromLong((long)self->effect->type);
214
if (attr) return attr;
215
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,\
216
"couldn't get mode attribute"));
220
PyObject *Effect_setType(BPy_Effect *self, PyObject *args)
223
if (!PyArg_ParseTuple(args, "i", &value))
224
return (EXPP_ReturnPyObjError (PyExc_TypeError,\
225
"expected an int as argument"));
226
self->effect->type = value;
231
PyObject *Effect_getFlag(BPy_Effect *self)
233
PyObject *attr = PyInt_FromLong((long)self->effect->flag);
234
if (attr) return attr;
235
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,\
236
"couldn't get mode attribute"));
240
PyObject *Effect_setFlag(BPy_Effect *self, PyObject *args)
243
if (!PyArg_ParseTuple(args, "i", &value))
244
return (EXPP_ReturnPyObjError (PyExc_TypeError,\
245
"expected an int as argument"));
246
self->effect->flag = value;
233
PyObject *Build_Init( void );
234
PyObject *Wave_Init( void );
235
PyObject *Particle_Init( void );
237
PyObject *Effect_Init( void )
239
PyObject *submodule, *dict;
241
Effect_Type.ob_type = &PyType_Type;
243
submodule = Py_InitModule3( "Blender.Effect", M_Effect_methods, 0 );
244
dict = PyModule_GetDict( submodule );
245
PyDict_SetItemString( dict, "Wave", Wave_Init( ) );
246
PyDict_SetItemString( dict, "Build", Build_Init( ) );
247
PyDict_SetItemString( dict, "Particle", Particle_Init( ) );
248
return ( submodule );
251
/*****************************************************************************/
252
/* Python BPy_Effect methods: */
253
/*****************************************************************************/
255
PyObject *Effect_getType( BPy_Effect * self )
257
PyObject *attr = PyInt_FromLong( ( long ) self->effect->type );
260
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
261
"couldn't get mode attribute" ) );
265
PyObject *Effect_setType( BPy_Effect * self, PyObject * args )
268
if( !PyArg_ParseTuple( args, "i", &value ) )
269
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
270
"expected an int as argument" ) );
271
self->effect->type = value;
272
Py_INCREF( Py_None );
276
PyObject *Effect_getFlag( BPy_Effect * self )
278
PyObject *attr = PyInt_FromLong( ( long ) self->effect->flag );
281
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
282
"couldn't get mode attribute" ) );
286
PyObject *Effect_setFlag( BPy_Effect * self, PyObject * args )
289
if( !PyArg_ParseTuple( args, "i", &value ) )
290
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
291
"expected an int as argument" ) );
292
self->effect->flag = value;
293
Py_INCREF( Py_None );
255
301
/*****************************************************************************/
256
302
/* Function: EffectDeAlloc */
257
/* Description: This is a callback function for the BPy_Effect type. It is */
303
/* Description: This is a callback function for the BPy_Effect type. It is */
258
304
/* the destructor function. */
259
305
/*****************************************************************************/
260
void EffectDeAlloc (BPy_Effect *self)
306
void EffectDeAlloc( BPy_Effect * self )
308
PyObject_DEL( self );
265
311
/*****************************************************************************/
266
312
/* Function: EffectGetAttr */
267
/* Description: This is a callback function for the BPy_Effect type. It is */
268
/* the function that accesses BPy_Effect "member variables" and */
313
/* Description: This is a callback function for the BPy_Effect type. It is */
314
/* the function that accesses BPy_Effect "member variables" and */
270
316
/*****************************************************************************/
273
PyObject *EffectGetAttr (BPy_Effect *self, char *name)
319
PyObject *EffectGetAttr( BPy_Effect * self, char *name )
275
switch(self->effect->type)
277
case EFF_BUILD : return BuildGetAttr( (BPy_Build*)self, name);
278
case EFF_WAVE : return WaveGetAttr ((BPy_Wave*)self, name);
279
case EFF_PARTICLE : return ParticleGetAttr ((BPy_Particle*)self, name);
321
switch ( self->effect->type ) {
323
return BuildGetAttr( ( BPy_Build * ) self, name );
325
return WaveGetAttr( ( BPy_Wave * ) self, name );
327
return ParticleGetAttr( ( BPy_Particle * ) self, name );
282
return Py_FindMethod(BPy_Effect_methods, (PyObject *)self, name);
330
return Py_FindMethod( BPy_Effect_methods, ( PyObject * ) self, name );
285
333
/*****************************************************************************/
286
334
/* Function: EffectSetAttr */
287
/* Description: This is a callback function for the BPy_Effect type. It is the */
288
/* function that sets Effect Data attributes (member variables).*/
335
/* Description: This is a callback function for the BPy_Effect type. It */
336
/* sets Effect Data attributes (member variables). */
289
337
/*****************************************************************************/
292
int EffectSetAttr (BPy_Effect *self, char *name, PyObject *value)
340
int EffectSetAttr( BPy_Effect * self, char *name, PyObject * value )
294
switch(self->effect->type)
296
case EFF_BUILD : return BuildSetAttr( (BPy_Build*)self, name,value);
297
case EFF_WAVE : return WaveSetAttr ((BPy_Wave*)self, name,value);
298
case EFF_PARTICLE : return ParticleSetAttr ((BPy_Particle*)self, name,value);
300
return 0; /* normal exit */
342
switch ( self->effect->type ) {
344
return BuildSetAttr( ( BPy_Build * ) self, name, value );
346
return WaveSetAttr( ( BPy_Wave * ) self, name, value );
348
return ParticleSetAttr( ( BPy_Particle * ) self, name, value );
350
return 0; /* normal exit */
303
353
/*****************************************************************************/
304
354
/* Function: EffectPrint */
305
/* Description: This is a callback function for the BPy_Effect type. It */
355
/* Description: This is a callback function for the BPy_Effect type. It */
306
356
/* builds a meaninful string to 'print' effcte objects. */
307
357
/*****************************************************************************/
318
368
/*****************************************************************************/
319
369
/* Function: EffectRepr */
320
/* Description: This is a callback function for the BPy_Effect type. It */
370
/* Description: This is a callback function for the BPy_Effect type. It */
321
371
/* builds a meaninful string to represent effcte objects. */
322
372
/*****************************************************************************/
324
PyObject *EffectRepr (BPy_Effect *self)
327
if (self->effect->type == EFF_BUILD)str = "Effect Build";
328
if (self->effect->type == EFF_PARTICLE)str = "Effect Particle";
329
if (self->effect->type == EFF_WAVE)str = "Effect Wave";
330
return PyString_FromString(str);
333
PyObject* EffectCreatePyObject (struct Effect *effect)
335
BPy_Effect * blen_object;
337
blen_object = (BPy_Effect*)PyObject_NEW (BPy_Effect, &Effect_Type);
339
if (blen_object == NULL)
343
blen_object->effect = effect;
344
return ((PyObject*)blen_object);
348
int EffectCheckPyObject (PyObject *py_obj)
350
return (py_obj->ob_type == &Effect_Type);
354
struct Effect* EffectFromPyObject (PyObject *py_obj)
356
BPy_Effect * blen_obj;
358
blen_obj = (BPy_Effect*)py_obj;
359
return ((Effect*)blen_obj->effect);
374
PyObject *EffectRepr( BPy_Effect * self )
377
if( self->effect->type == EFF_BUILD )
378
str = "Effect Build";
379
if( self->effect->type == EFF_PARTICLE )
380
str = "Effect Particle";
381
if( self->effect->type == EFF_WAVE )
383
return PyString_FromString( str );
386
PyObject *EffectCreatePyObject( struct Effect * effect )
388
BPy_Effect *blen_object;
391
( BPy_Effect * ) PyObject_NEW( BPy_Effect, &Effect_Type );
393
if( blen_object == NULL ) {
396
blen_object->effect = effect;
397
return ( ( PyObject * ) blen_object );
401
int EffectCheckPyObject( PyObject * py_obj )
403
return ( py_obj->ob_type == &Effect_Type );
407
struct Effect *EffectFromPyObject( PyObject * py_obj )
409
BPy_Effect *blen_obj;
411
blen_obj = ( BPy_Effect * ) py_obj;
412
return ( ( Effect * ) blen_obj->effect );