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

Effect.c « api2_2x « python « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c49dd53257c0468278237670f54228f2bfa834a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
 * $Id$
 *
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version. The Blender
 * Foundation also sells licenses for use in proprietary software under
 * the Blender License.  See http://www.blender.org/BL/ for information
 * about this.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * This is a new part of Blender.
 *
 * Contributor(s): Jacques Guignot
 *
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 */
#include "Effect.h" /*This must come first */

#include "DNA_object_types.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "Particle.h"
#include "Wave.h"
#include "gen_utils.h"

/*****************************************************************************/
/* Python BPy_Effect methods table:                                            */
/*****************************************************************************/
static PyMethodDef BPy_Effect_methods[] = {
	{NULL, NULL, 0, NULL}
};

/*****************************************************************************/
/* Python Effect_Type structure definition:                                  */
/*****************************************************************************/
PyTypeObject Effect_Type = {
	PyObject_HEAD_INIT( NULL )
		0,		/* ob_size */
	"Effect",		/* tp_name */
	sizeof( BPy_Effect ),	/* tp_basicsize */
	0,			/* tp_itemsize */
	/* methods */
	( destructor ) EffectDeAlloc,	/* tp_dealloc */
	0,			/* tp_print */
	( getattrfunc ) EffectGetAttr,	/* tp_getattr */
	( setattrfunc ) EffectSetAttr,	/* tp_setattr */
	0,			/* tp_compare */
	( reprfunc ) EffectRepr,	/* tp_repr */
	0,			/* tp_as_number */
	0,			/* tp_as_sequence */
	0,			/* tp_as_mapping */
	0,			/* tp_as_hash */
	0, 0, 0, 0, 0, 0,
	0,			/* tp_doc */
	0, 0, 0, 0, 0, 0,
	BPy_Effect_methods,	/* tp_methods */
	0,			/* tp_members */
};

/*****************************************************************************/
/* Python method structure definition for Blender.Effect module:             */
/*****************************************************************************/




struct PyMethodDef M_Effect_methods[] = {
	{"New", ( PyCFunction ) M_Effect_New, METH_VARARGS, NULL},
	{"Get", M_Effect_Get, METH_VARARGS, NULL},
	{"get", M_Effect_Get, METH_VARARGS, NULL},
	{NULL, NULL, 0, NULL}
};

/*****************************************************************************/
/* Function:              M_Effect_New                                       */
/* Python equivalent:     Blender.Effect.New                                 */
/*****************************************************************************/
PyObject *M_Effect_New( PyObject * self, PyObject * args )
{
/*	BPy_Effect *pyeffect;
	Effect *bleffect = 0;
	int type = -1;
	char *btype = NULL;*/
	Py_INCREF( Py_None );
	return Py_None;
/*	if( !PyArg_ParseTuple( args, "s", &btype ) )
		return ( EXPP_ReturnPyObjError( PyExc_TypeError,
						"expected type argument(wave,build or particle)" ) );
	if( !strcmp( btype, "wave" ) )
		type = EFF_WAVE;
	if( !strcmp( btype, "particle" ) )
		type = EFF_PARTICLE;
	if( type == -1 )
		return ( EXPP_ReturnPyObjError( PyExc_TypeError,
						"unknown type " ) );


	bleffect = add_effect( type );
	if( bleffect == NULL )
		return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
						"couldn't create Effect Data in Blender" ) );

	pyeffect = ( BPy_Effect * ) PyObject_NEW( BPy_Effect, &Effect_Type );


	if( pyeffect == NULL )
		return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
						"couldn't create Effect Data object" ) );

	pyeffect->effect = bleffect;

	return ( PyObject * ) pyeffect;*/
}

/*****************************************************************************/
/* Function:              M_Effect_Get                                       */
/* Python equivalent:     Blender.Effect.Get                                 */
/*****************************************************************************/
PyObject *M_Effect_Get( PyObject * self, PyObject * args )
{
	/*arguments : string object name
	   int : position of effect in the obj's effect list  */
	char *name = NULL;
	Object *object_iter;
	Effect *eff;
	BPy_Effect *wanted_eff;
	int num = -1, i;

	if( !PyArg_ParseTuple( args, "|si", &name, &num ) )
		return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
						"expected string int argument" ) );

	object_iter = G.main->object.first;

	if( !object_iter )
		return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
						"Scene contains no object" ) );

	if( name ) { /* (name, num = -1) - try to find the given object */

		while( object_iter ) {

			if( !strcmp( name, object_iter->id.name + 2 ) ) {

				eff = object_iter->effect.first; /*can be NULL: None will be returned*/

				if (num >= 0) { /* return effect in given num position if available */

					for( i = 0; i < num; i++ ) {
						if (!eff) break;
						eff = eff->next;
					}

					if (eff) {
						wanted_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
						wanted_eff->effect = eff;
						return ( PyObject * ) wanted_eff;
					} else { /* didn't find any effect in the given position */
						Py_INCREF(Py_None);
						return Py_None;
					}
				}

				else {/*return a list with all effects linked to the given object*/
							/* this was pointed by Stephen Swaney */
					PyObject *effectlist = PyList_New( 0 );

					while (eff) {
						BPy_Effect *found_eff = (BPy_Effect *)PyObject_NEW(BPy_Effect,
							&Effect_Type);
						found_eff->effect = eff;
						PyList_Append( effectlist, ( PyObject * ) found_eff );
						Py_DECREF((PyObject *)found_eff); /* PyList_Append incref'ed it */
						eff = eff->next;
					}
					return effectlist;
				}
			}
			
			object_iter = object_iter->id.next;
		}

		if (!object_iter)
			return EXPP_ReturnPyObjError (PyExc_AttributeError,
				"no such object");
	}
	
	else { /* () - return a list with all effects currently in Blender */
		PyObject *effectlist = PyList_New( 0 );

		while( object_iter ) {
			if( object_iter->effect.first != NULL ) {
				eff = object_iter->effect.first;
				while( eff ) {
					BPy_Effect *found_eff =
						( BPy_Effect * )
						PyObject_NEW( BPy_Effect,
							      &Effect_Type );
					found_eff->effect = eff;
					PyList_Append( effectlist,
						       ( PyObject * )
						       found_eff );
					Py_DECREF((PyObject *)found_eff);
					eff = eff->next;
				}
			}
			object_iter = object_iter->id.next;
		}
		return effectlist;
	}
	Py_INCREF( Py_None );
	return Py_None;
}

/*****************************************************************************/
/* Function:              Effect_Init                                        */
/*****************************************************************************/


PyObject *Wave_Init( void );
PyObject *Particle_Init( void );

PyObject *Effect_Init( void )
{
	PyObject *submodule, *dict;

	Effect_Type.ob_type = &PyType_Type;

	submodule = Py_InitModule3( "Blender.Effect", M_Effect_methods, 0 );
	dict = PyModule_GetDict( submodule );
	PyDict_SetItemString( dict, "Wave", Wave_Init(  ) );
	PyDict_SetItemString( dict, "Particle", Particle_Init(  ) );
	return ( submodule );
}

/*****************************************************************************/
/* Python BPy_Effect methods:                                       */
/*****************************************************************************/

PyObject *Effect_getType( BPy_Effect * self )
{
	PyObject *attr = PyInt_FromLong( ( long ) self->effect->type );
	if( attr )
		return attr;
	return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
					"couldn't get mode attribute" ) );
}


PyObject *Effect_setType( BPy_Effect * self, PyObject * args )
{
	int value;
	if( !PyArg_ParseTuple( args, "i", &value ) )
		return ( EXPP_ReturnPyObjError( PyExc_TypeError,
						"expected an int as argument" ) );
	self->effect->type = (short)value;
	Py_INCREF( Py_None );
	return Py_None;
}

PyObject *Effect_getFlag( BPy_Effect * self )
{
	PyObject *attr = PyInt_FromLong( ( long ) self->effect->flag );
	if( attr )
		return attr;
	return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
					"couldn't get mode attribute" ) );
}


PyObject *Effect_setFlag( BPy_Effect * self, PyObject * args )
{
	int value;
	if( !PyArg_ParseTuple( args, "i", &value ) )
		return ( EXPP_ReturnPyObjError( PyExc_TypeError,
						"expected an int as argument" ) );
	self->effect->flag = (short)value;
	Py_INCREF( Py_None );
	return Py_None;
}





/*****************************************************************************/
/* Function:    EffectDeAlloc                                                */
/* Description: This is a callback function for the BPy_Effect type. It is   */
/*              the destructor function.                                     */
/*****************************************************************************/
void EffectDeAlloc( BPy_Effect * self )
{
	PyObject_DEL( self );
}

/*****************************************************************************/
/* Function:    EffectGetAttr                                                */
/* Description: This is a callback function for the BPy_Effect type. It is   */
/*              the function that accesses BPy_Effect "member variables" and */
/*              methods.                                                     */
/*****************************************************************************/


PyObject *EffectGetAttr( BPy_Effect * self, char *name )
{
	switch ( self->effect->type ) {
	case EFF_WAVE:
		return WaveGetAttr( ( BPy_Wave * ) self, name );
	case EFF_PARTICLE:
		return ParticleGetAttr( ( BPy_Particle * ) self, name );
	}

	return Py_FindMethod( BPy_Effect_methods, ( PyObject * ) self, name );
}

/*****************************************************************************/
/* Function:    EffectSetAttr                                                */
/* Description: This is a callback function for the BPy_Effect type. It   */
/*              sets Effect Data attributes (member variables). */
/*****************************************************************************/


int EffectSetAttr( BPy_Effect * self, char *name, PyObject * value )
{
	switch ( self->effect->type ) {
	case EFF_WAVE:
		return WaveSetAttr( ( BPy_Wave * ) self, name, value );
	case EFF_PARTICLE:
		return ParticleSetAttr( ( BPy_Particle * ) self, name, value );
	}
	return 0;		/* normal exit */
}

/*****************************************************************************/
/* Function:    EffectPrint                                                  */
/* Description: This is a callback function for the BPy_Effect type. It      */
/*              builds a meaninful string to 'print' effcte objects.         */
/*****************************************************************************/
/*
int EffectPrint(BPy_Effect *self, FILE *fp, int flags) 
{ 
if (self->effect->type == EFF_PARTICLE)puts("Effect Particle");
if (self->effect->type == EFF_WAVE)puts("Effect Wave");
 
  return 0;
}
*/
/*****************************************************************************/
/* Function:    EffectRepr                                                   */
/* Description: This is a callback function for the BPy_Effect type. It      */
/*              builds a meaninful string to represent effcte objects.       */
/*****************************************************************************/

PyObject *EffectRepr( BPy_Effect * self )
{
	char *str = "";
	if( self->effect->type == EFF_PARTICLE )
		str = "Effect Particle";
	if( self->effect->type == EFF_WAVE )
		str = "Effect Wave";
	return PyString_FromString( str );
}

PyObject *EffectCreatePyObject( struct Effect * effect )
{
	BPy_Effect *blen_object;

	blen_object =
		( BPy_Effect * ) PyObject_NEW( BPy_Effect, &Effect_Type );

	if( blen_object == NULL ) {
		return ( NULL );
	}
	blen_object->effect = effect;
	return ( ( PyObject * ) blen_object );

}

int EffectCheckPyObject( PyObject * py_obj )
{
	return ( py_obj->ob_type == &Effect_Type );
}


struct Effect *EffectFromPyObject( PyObject * py_obj )
{
	BPy_Effect *blen_obj;

	blen_obj = ( BPy_Effect * ) py_obj;
	return ( ( Effect * ) blen_obj->effect );

}