~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Ipo.c

  • Committer: Bazaar Package Importer
  • Author(s): Lukas Fittl
  • Date: 2006-09-20 01:57:27 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060920015727-gmoqlxwstx9wwqs3
Tags: 2.42a-1ubuntu1
* Merge from Debian unstable (Closes: Malone #55903). Remaining changes:
  - debian/genpot: Add python scripts from Lee June <blender@eyou.com> to
    generate a reasonable PO template from the sources. Since gettext is used
    in a highly nonstandard way, xgettext does not work for this job.
  - debian/rules: Call the scripts, generate po/blender.pot, and clean it up
    in the clean target.
  - Add a proper header to the generated PO template.
* debian/control: Build depend on libavformat-dev >= 3:0.cvs20060823-3.1,
  otherwise this package will FTBFS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: Ipo.c,v 1.49 2006/01/05 19:25:38 khughes Exp $
 
2
 * $Id: Ipo.c,v 1.55 2006/07/02 21:37:06 khughes Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
41
41
#include "BIF_space.h"
42
42
#include "BSE_editipo.h"
43
43
#include "MEM_guardedalloc.h"
 
44
#include "DNA_key_types.h"
44
45
#include "mydevice.h"
45
46
#include "Ipocurve.h"
46
47
#include "gen_utils.h"
47
48
 
 
49
extern int ob_ar[];
 
50
extern int la_ar[];
 
51
extern int ma_ar[];
 
52
extern int ac_ar[];
 
53
extern int cam_ar[];
 
54
extern int co_ar[];
 
55
extern int cu_ar[];
 
56
extern int seq_ar[];
 
57
extern int te_ar[];
 
58
extern int wo_ar[];
 
59
 
 
60
PyObject *submodule;
 
61
 
48
62
/*****************************************************************************/
49
63
/* Python API function prototypes for the Ipo module.                        */
50
64
/*****************************************************************************/
61
75
char M_Ipo_New_doc[] = "";
62
76
char M_Ipo_Get_doc[] = "";
63
77
 
64
 
 
65
78
/*****************************************************************************/
66
79
/* Python method structure definition for Blender.Ipo module:             */
67
80
/*****************************************************************************/
79
92
/* Python BPy_Ipo methods declarations:                                     */
80
93
/*****************************************************************************/
81
94
static PyObject *Ipo_getName( BPy_Ipo * self );
82
 
static PyObject *Ipo_setName( BPy_Ipo * self, PyObject * args );
 
95
static PyObject *Ipo_oldsetName( BPy_Ipo * self, PyObject * args );
 
96
static int Ipo_setName( BPy_Ipo * self, PyObject * args );
83
97
static PyObject *Ipo_getBlocktype( BPy_Ipo * self );
84
 
static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args );
 
98
static PyObject *Ipo_oldsetBlocktype( BPy_Ipo * self, PyObject * args );
 
99
static int Ipo_setBlocktype( BPy_Ipo * self, PyObject * args );
85
100
static PyObject *Ipo_getRctf( BPy_Ipo * self );
86
 
static PyObject *Ipo_setRctf( BPy_Ipo * self, PyObject * args );
 
101
static PyObject *Ipo_oldsetRctf( BPy_Ipo * self, PyObject * args );
 
102
static int Ipo_setRctf( BPy_Ipo * self, PyObject * args );
87
103
 
88
104
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args );
89
105
static PyObject *Ipo_getCurves( BPy_Ipo * self );
 
106
static PyObject *Ipo_getCurveNames( BPy_Ipo * self );
90
107
static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args );
91
108
static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args );
92
109
static PyObject *Ipo_getNcurves( BPy_Ipo * self );
96
113
static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args );
97
114
static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args );
98
115
 
99
 
 
100
116
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args );
101
117
static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args );
102
118
 
 
119
static PyObject *Ipo_getChannel( BPy_Ipo * self );
 
120
static int Ipo_setChannel( BPy_Ipo * self, PyObject * args );
 
121
 
 
122
static int Ipo_length( BPy_Ipo * inst );
 
123
static PyObject *Ipo_getIpoCurveByName( BPy_Ipo * self, PyObject * key );
 
124
static int Ipo_setIpoCurveByName( BPy_Ipo * self, PyObject * key, 
 
125
                PyObject * value );
 
126
static int Ipo_contains( BPy_Ipo * self, PyObject * key );
 
127
 
103
128
/*****************************************************************************/
104
129
/* Python BPy_Ipo methods table:                                            */
105
130
/*****************************************************************************/
107
132
        /* name, method, flags, doc */
108
133
        {"getName", ( PyCFunction ) Ipo_getName, METH_NOARGS,
109
134
         "() - Return Ipo Data name"},
110
 
        {"setName", ( PyCFunction ) Ipo_setName, METH_VARARGS,
 
135
        {"setName", ( PyCFunction ) Ipo_oldsetName, METH_VARARGS,
111
136
         "(str) - Change Ipo Data name"},
112
137
        {"getBlocktype", ( PyCFunction ) Ipo_getBlocktype, METH_NOARGS,
113
138
         "() - Return Ipo blocktype"},
114
 
        {"setBlocktype", ( PyCFunction ) Ipo_setBlocktype, METH_VARARGS,
 
139
        {"setBlocktype", ( PyCFunction ) Ipo_oldsetBlocktype, METH_VARARGS,
115
140
         "(str) - Change Ipo blocktype"},
116
141
        {"getRctf", ( PyCFunction ) Ipo_getRctf, METH_NOARGS,
117
142
         "() - Return Ipo rctf"},
118
 
        {"setRctf", ( PyCFunction ) Ipo_setRctf, METH_VARARGS,
 
143
        {"setRctf", ( PyCFunction ) Ipo_oldsetRctf, METH_VARARGS,
119
144
         "(flt,flt,flt,flt) - Change Ipo rctf"},
120
145
        {"addCurve", ( PyCFunction ) Ipo_addCurve, METH_VARARGS,
121
146
         "() - Add a curve to Ipo"},
123
148
         "(str) - Delete curve from Ipo"},
124
149
        {"getNcurves", ( PyCFunction ) Ipo_getNcurves, METH_NOARGS,
125
150
         "() - Return number of Ipo curves"},
 
151
        {"getCurves", ( PyCFunction ) Ipo_getCurves, METH_NOARGS,
 
152
         "() - Return list of all defined Ipo curves"},
 
153
        {"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
 
154
         "(str|int) - Returns specified Ipo curve"},
126
155
        {"getNBezPoints", ( PyCFunction ) Ipo_getNBezPoints, METH_VARARGS,
127
156
         "(int) - Return number of Bez points on an Ipo curve"},
128
157
        {"delBezPoint", ( PyCFunction ) Ipo_DeleteBezPoints, METH_VARARGS,
137
166
         "(int,int) - deprecated: see ipocurve.bezierPoints[]"},
138
167
        {"setCurveBeztriple", ( PyCFunction ) Ipo_setCurveBeztriple, METH_VARARGS,
139
168
         "(int,int,list) - set a BezTriple"},
140
 
        {"getCurves", ( PyCFunction ) Ipo_getCurves, METH_NOARGS,
141
 
         "() - Return list of all defined Ipo curves"},
142
 
        {"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
143
 
         "(str|int) - Returns specified Ipo curve"},
144
169
        {NULL, NULL, 0, NULL}
145
170
};
146
171
 
147
172
/*****************************************************************************/
148
 
/* Python Ipo_Type callback function prototypes:                          */
149
 
/*****************************************************************************/
150
 
static void IpoDeAlloc( BPy_Ipo * self );
 
173
/* Python BPy_Ipo attributes get/set structure:                              */
 
174
/*****************************************************************************/
 
175
static PyGetSetDef BPy_Ipo_getseters[] = {
 
176
        {"name",
 
177
         (getter)Ipo_getName, (setter)Ipo_setName,
 
178
         "Ipo data name",
 
179
         NULL},
 
180
        {"curves",
 
181
         (getter)Ipo_getCurves, (setter)NULL,
 
182
         "Ipo curves",
 
183
         NULL},
 
184
        {"curveConsts",
 
185
         (getter)Ipo_getCurveNames, (setter)NULL,
 
186
         "Ipo curve constants (values depend on Ipo type)",
 
187
         NULL},
 
188
        {"channel",
 
189
         (getter)Ipo_getChannel, (setter)Ipo_setChannel,
 
190
         "Ipo texture channel (world, lamp, material Ipos only)",
 
191
         NULL},
 
192
 
 
193
        {"blocktype",
 
194
         (getter)Ipo_getBlocktype, (setter)NULL,
 
195
         "Ipo block type",
 
196
         NULL},
 
197
        {"rcft",
 
198
         (getter)Ipo_getRctf, (setter)Ipo_setRctf,
 
199
         "Ipo type",
 
200
         NULL},
 
201
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 
202
};
 
203
 
 
204
/*****************************************************************************/
 
205
/* Python Ipo_Type Mapping Methods table:                                    */
 
206
/*****************************************************************************/
 
207
static PyMappingMethods Ipo_as_mapping = {
 
208
        ( inquiry ) Ipo_length, /* mp_length        */
 
209
        ( binaryfunc ) Ipo_getIpoCurveByName,   /* mp_subscript     */
 
210
        ( objobjargproc ) Ipo_setIpoCurveByName,        /* mp_ass_subscript */
 
211
};
 
212
 
 
213
static PySequenceMethods Ipo_as_sequence = {
 
214
        ( inquiry ) 0,  /* sq_length */
 
215
        ( binaryfunc ) 0,       /* sq_concat */
 
216
        ( intargfunc ) 0,       /* sq_repeat */
 
217
        ( intargfunc ) 0,       /* sq_item */
 
218
        ( intintargfunc ) 0,    /* sq_slice */
 
219
        ( intobjargproc ) 0,    /* sq_ass_item */
 
220
        ( intintobjargproc ) 0, /* sq_ass_slice */
 
221
        ( objobjproc ) Ipo_contains,    /* sq_contains */
 
222
        ( binaryfunc ) 0,               /* sq_inplace_concat */
 
223
        ( intargfunc ) 0,               /* sq_inplace_repeat */
 
224
};
 
225
 
 
226
/*****************************************************************************/
 
227
/* Python Ipo_Type callback function prototypes:                             */
 
228
/*****************************************************************************/
 
229
static void Ipo_dealloc( BPy_Ipo * self );
151
230
//static int IpoPrint (BPy_Ipo *self, FILE *fp, int flags);
152
 
static int IpoSetAttr( BPy_Ipo * self, char *name, PyObject * v );
153
 
static PyObject *IpoGetAttr( BPy_Ipo * self, char *name );
154
 
static PyObject *IpoRepr( BPy_Ipo * self );
 
231
static PyObject *Ipo_repr( BPy_Ipo * self );
 
232
static PyObject *Ipo_getIter( BPy_Ipo * self );
 
233
static PyObject *Ipo_nextIter( BPy_Ipo * self );
 
234
 
 
235
/* #define CURVEATTRS */ /* uncomment to enable curves as Ipo attributes */ 
 
236
 
 
237
#ifdef CURVEATTRS
 
238
static PyGetSetDef BPy_Ipocurve_getseter = {
 
239
        "noname",
 
240
         (getter)NULL, (setter)NULL,
 
241
         "Ipo curve name",
 
242
         NULL
 
243
};
 
244
 
 
245
void generate_curveattrs( PyObject* dict, int blocktype )
 
246
{
 
247
        typedef char * (*namefunc)(int, ... );
 
248
        namefunc lookup_name;
 
249
        int size;
 
250
        int *vals = NULL;
 
251
        char name[32];
 
252
        PyObject*desc;
 
253
 
 
254
        switch ( blocktype ) {
 
255
        case ID_OB:
 
256
                lookup_name = (namefunc)getname_ob_ei;
 
257
                vals = ob_ar;
 
258
                size = OB_TOTIPO;
 
259
                break;
 
260
        case ID_MA:
 
261
                lookup_name = (namefunc)getname_mat_ei;
 
262
                vals = ma_ar;
 
263
                size = MA_TOTIPO;
 
264
                break;
 
265
        case ID_CA:
 
266
                lookup_name = (namefunc)getname_cam_ei;
 
267
                vals = cam_ar;
 
268
                size = CAM_TOTIPO;
 
269
                break;
 
270
        case ID_LA:
 
271
                lookup_name = (namefunc)getname_la_ei;
 
272
                vals = la_ar;
 
273
                size = LA_TOTIPO;
 
274
                break;
 
275
        case ID_TE:
 
276
                lookup_name = (namefunc)getname_tex_ei;
 
277
                vals = te_ar;
 
278
                size = TE_TOTIPO;
 
279
                break;
 
280
        case ID_WO:
 
281
                lookup_name = (namefunc)getname_world_ei;
 
282
                vals = wo_ar;
 
283
                size = WO_TOTIPO;
 
284
                break;
 
285
        case ID_PO:
 
286
                lookup_name = (namefunc)getname_ac_ei;
 
287
                vals = ac_ar;
 
288
                size = AC_TOTIPO;
 
289
                break;
 
290
        case ID_CO:
 
291
                lookup_name = (namefunc)getname_co_ei;
 
292
                vals = co_ar;
 
293
                size = CO_TOTIPO;
 
294
                break;
 
295
        case ID_CU:
 
296
                lookup_name = (namefunc)getname_cu_ei;
 
297
                vals = cu_ar;
 
298
                size = CU_TOTIPO;
 
299
                break;
 
300
        case ID_SEQ:
 
301
                lookup_name = (namefunc)getname_seq_ei;
 
302
                vals = seq_ar;
 
303
                size = SEQ_TOTIPO;
 
304
                break;
 
305
        }
 
306
 
 
307
        desc = PyDescr_NewGetSet( &Ipo_Type, &BPy_Ipocurve_getseter );
 
308
        while( size-- ) {
 
309
                strcpy( name, lookup_name( *vals ) ); 
 
310
                *name = tolower( *name );
 
311
                PyDict_SetItemString( dict, name, desc );
 
312
                ++vals;
 
313
        }
 
314
        Py_DECREF( desc );
 
315
}
 
316
 
 
317
static short lookup_curve_name( char *, int , int );
 
318
 
 
319
static PyObject *getattro( PyObject *self, PyObject *value )
 
320
{
 
321
        char *name = PyString_AS_STRING( value );
 
322
        Ipo *ipo = ((BPy_Ipo *)self)->ipo;
 
323
        int adrcode;
 
324
        IpoCurve *icu;
 
325
 
 
326
        if( !strcmp(name, "__class__") )
 
327
                return PyObject_GenericGetAttr( self, value );
 
328
 
 
329
        if( !strcmp(name, "__dict__") ) /* no effect */
 
330
        {
 
331
                PyObject *dict;
 
332
                dict = PyDict_Copy( self->ob_type->tp_dict );
 
333
                generate_curveattrs( dict, ipo->blocktype );
 
334
                return dict;
 
335
        }
 
336
 
 
337
        adrcode = lookup_curve_name( name, ipo->blocktype, 
 
338
                        ((BPy_Ipo *)self)->mtex );
 
339
 
 
340
        if( adrcode != -1 ) {
 
341
                for( icu = ipo->curve.first; icu; icu = icu->next )
 
342
                        if( icu->adrcode == adrcode )
 
343
                                return IpoCurve_CreatePyObject( icu );
 
344
                Py_RETURN_NONE;
 
345
        }
 
346
 
 
347
        return PyObject_GenericGetAttr( self, value );
 
348
}
 
349
#endif
155
350
 
156
351
/*****************************************************************************/
157
 
/* Python Ipo_Type structure definition:                                  */
 
352
/* Python Ipo_Type structure definition:                                     */
158
353
/*****************************************************************************/
159
354
PyTypeObject Ipo_Type = {
160
 
        PyObject_HEAD_INIT( NULL ) /* required macro */ 0,      /* ob_size */
161
 
        "Ipo",                  /* tp_name */
162
 
        sizeof( BPy_Ipo ),      /* tp_basicsize */
163
 
        0,                      /* tp_itemsize */
164
 
        /* methods */
165
 
        ( destructor ) IpoDeAlloc,      /* tp_dealloc */
166
 
        0,                      /* tp_print */
167
 
        ( getattrfunc ) IpoGetAttr,     /* tp_getattr */
168
 
        ( setattrfunc ) IpoSetAttr,     /* tp_setattr */
169
 
        0,                      /* tp_compare */
170
 
        ( reprfunc ) IpoRepr,   /* tp_repr */
171
 
        0,                      /* tp_as_number */
172
 
        0,                      /* tp_as_sequence */
173
 
        0,                      /* tp_as_mapping */
174
 
        0,                      /* tp_as_hash */
175
 
        0, 0, 0, 0, 0, 0,
176
 
        0,                      /* tp_doc */
177
 
        0, 0, 0, 0, 0, 0,
178
 
        BPy_Ipo_methods,        /* tp_methods */
179
 
        0,                      /* tp_members */
 
355
        PyObject_HEAD_INIT( NULL )  /* required py macro */
 
356
        0,                          /* ob_size */
 
357
        /*  For printing, in format "<module>.<name>" */
 
358
        "Blender Ipo",              /* char *tp_name; */
 
359
        sizeof( BPy_Ipo ),          /* int tp_basicsize; */
 
360
        0,                          /* tp_itemsize;  For allocation */
 
361
 
 
362
        /* Methods to implement standard operations */
 
363
 
 
364
        ( destructor ) Ipo_dealloc,/* destructor tp_dealloc; */
 
365
        NULL,                       /* printfunc tp_print; */
 
366
        NULL,                       /* getattrfunc tp_getattr; */
 
367
        NULL,                       /* setattrfunc tp_setattr; */
 
368
        NULL,                       /* cmpfunc tp_compare; */
 
369
        ( reprfunc ) Ipo_repr,     /* reprfunc tp_repr; */
 
370
 
 
371
        /* Method suites for standard classes */
 
372
 
 
373
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
374
        &Ipo_as_sequence,           /* PySequenceMethods *tp_as_sequence; */
 
375
        &Ipo_as_mapping,                /* PyMappingMethods *tp_as_mapping; */
 
376
 
 
377
        /* More standard operations (here for binary compatibility) */
 
378
 
 
379
        NULL,                       /* hashfunc tp_hash; */
 
380
        NULL,                       /* ternaryfunc tp_call; */
 
381
        NULL,                       /* reprfunc tp_str; */
 
382
#ifdef CURVEATTRS
 
383
        (getattrofunc)getattro,
 
384
#else
 
385
        NULL,                       /* getattrofunc tp_getattro; */
 
386
#endif
 
387
        NULL,                       /* setattrofunc tp_setattro; */
 
388
 
 
389
        /* Functions to access object as input/output buffer */
 
390
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
391
 
 
392
  /*** Flags to define presence of optional/expanded features ***/
 
393
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
394
 
 
395
        NULL,                       /*  char *tp_doc;  Documentation string */
 
396
  /*** Assigned meaning in release 2.0 ***/
 
397
        /* call function for all accessible objects */
 
398
        NULL,                       /* traverseproc tp_traverse; */
 
399
 
 
400
        /* delete references to contained objects */
 
401
        NULL,                       /* inquiry tp_clear; */
 
402
 
 
403
  /***  Assigned meaning in release 2.1 ***/
 
404
  /*** rich comparisons ***/
 
405
        NULL,                       /* richcmpfunc tp_richcompare; */
 
406
 
 
407
  /***  weak reference enabler ***/
 
408
        0,                          /* long tp_weaklistoffset; */
 
409
 
 
410
  /*** Added in release 2.2 ***/
 
411
        /*   Iterators */
 
412
        ( getiterfunc) Ipo_getIter, /* getiterfunc tp_iter; */
 
413
        ( iternextfunc ) Ipo_nextIter, /* iternextfunc tp_iternext; */
 
414
 
 
415
  /*** Attribute descriptor and subclassing stuff ***/
 
416
        BPy_Ipo_methods,            /* struct PyMethodDef *tp_methods; */
 
417
        NULL,                       /* struct PyMemberDef *tp_members; */
 
418
        BPy_Ipo_getseters,          /* struct PyGetSetDef *tp_getset; */
 
419
        NULL,                       /* struct _typeobject *tp_base; */
 
420
        NULL,                       /* PyObject *tp_dict; */
 
421
        NULL,                       /* descrgetfunc tp_descr_get; */
 
422
        NULL,                       /* descrsetfunc tp_descr_set; */
 
423
        0,                          /* long tp_dictoffset; */
 
424
        NULL,                       /* initproc tp_init; */
 
425
        NULL,                       /* allocfunc tp_alloc; */
 
426
        NULL,                       /* newfunc tp_new; */
 
427
        /*  Low-level free-memory routine */
 
428
        NULL,                       /* freefunc tp_free;  */
 
429
        /* For PyObject_IS_GC */
 
430
        NULL,                       /* inquiry tp_is_gc;  */
 
431
        NULL,                       /* PyObject *tp_bases; */
 
432
        /* method resolution order */
 
433
        NULL,                       /* PyObject *tp_mro;  */
 
434
        NULL,                       /* PyObject *tp_cache; */
 
435
        NULL,                       /* PyObject *tp_subclasses; */
 
436
        NULL,                       /* PyObject *tp_weaklist; */
 
437
        NULL
180
438
};
181
439
 
182
440
/*****************************************************************************/
 
441
/* internal utility routines                                                 */
 
442
/*****************************************************************************/
 
443
 
 
444
/*
 
445
 * Search through list of known Ipocurves for a particular name.
 
446
 *
 
447
 * str: name of curve we are searching for
 
448
 * blocktype: type of Ipo
 
449
 * channel: texture channel number, for World/Lamp/Material curves
 
450
 *
 
451
 * returns the adrcode for the named curve if it exists, -1 otherwise
 
452
 */
 
453
 
 
454
/* this is needed since getname_ob_ei() is different from the rest */
 
455
 
 
456
typedef char * (*namefunc)(int, ... );
 
457
 
 
458
static short lookup_curve_name( char *str, int blocktype, int channel )
 
459
{
 
460
        namefunc lookup_name;
 
461
        int *adrcodes = NULL;
 
462
        int size = 0;
 
463
 
 
464
        /* make sure channel type is ignored when it should be */
 
465
        if( blocktype != ID_WO && blocktype != ID_LA && blocktype != ID_MA )
 
466
                channel = -1;
 
467
 
 
468
        switch ( blocktype ) {
 
469
        case ID_OB:
 
470
                lookup_name = (namefunc)getname_ob_ei;
 
471
                adrcodes = ob_ar;
 
472
                size = OB_TOTIPO;
 
473
                break;
 
474
        case ID_MA:
 
475
                lookup_name = (namefunc)getname_mat_ei;
 
476
                adrcodes = ma_ar;
 
477
                size = MA_TOTIPO;
 
478
                break;
 
479
        case ID_CA:
 
480
                lookup_name = (namefunc)getname_cam_ei;
 
481
                adrcodes = cam_ar;
 
482
                size = CAM_TOTIPO;
 
483
                break;
 
484
        case ID_LA:
 
485
                lookup_name = (namefunc)getname_la_ei;
 
486
                adrcodes = la_ar;
 
487
                size = LA_TOTIPO;
 
488
                break;
 
489
        case ID_TE:
 
490
                lookup_name = (namefunc)getname_tex_ei;
 
491
                adrcodes = te_ar;
 
492
                size = TE_TOTIPO;
 
493
                break;
 
494
        case ID_WO:
 
495
                lookup_name = (namefunc)getname_world_ei;
 
496
                adrcodes = wo_ar;
 
497
                size = WO_TOTIPO;
 
498
                break;
 
499
        case ID_PO:
 
500
                lookup_name = (namefunc)getname_ac_ei;
 
501
                adrcodes = ac_ar;
 
502
                size = AC_TOTIPO;
 
503
                break;
 
504
        case ID_CO:
 
505
                lookup_name = (namefunc)getname_co_ei;
 
506
                adrcodes = co_ar;
 
507
                size = CO_TOTIPO;
 
508
                break;
 
509
        case ID_CU:
 
510
                lookup_name = (namefunc)getname_cu_ei;
 
511
                adrcodes = cu_ar;
 
512
                size = CU_TOTIPO;
 
513
                break;
 
514
        case ID_SEQ:
 
515
                lookup_name = (namefunc)getname_seq_ei;
 
516
                adrcodes = seq_ar;
 
517
                size = SEQ_TOTIPO;
 
518
                break;
 
519
        case ID_KE:     /* shouldn't happen */
 
520
        default:
 
521
                return -1;
 
522
        }
 
523
 
 
524
        while ( size-- ) {
 
525
                char *name = lookup_name ( *adrcodes );
 
526
 
 
527
                /* if not a texture channel, just return the adrcode */
 
528
                if( !strcmp( str, name ) ) {
 
529
                        if( channel == -1 || *adrcodes < MA_MAP1 )
 
530
                                return (short)*adrcodes;
 
531
 
 
532
                /* otherwise adjust adrcode to include current channel */
 
533
                        else {
 
534
                                int param = (short)*adrcodes & ~MA_MAP1;
 
535
                                param |= texchannel_to_adrcode( channel );
 
536
                                return (short)param;
 
537
                        }
 
538
                }
 
539
                ++adrcodes;
 
540
        }
 
541
        return -1;
 
542
}
 
543
 
 
544
static short lookup_curve_key( char *str, Ipo *ipo )
 
545
{
 
546
        Key *keyiter;
 
547
 
 
548
        /* find the ipo in the keylist */
 
549
        for( keyiter = G.main->key.first; keyiter; keyiter = keyiter->id.next ) {
 
550
                if( keyiter->ipo == ipo ) {
 
551
                        KeyBlock *block = keyiter->block.first;
 
552
 
 
553
                        /* look for a matching string, get the adrcode */
 
554
                        for( block = keyiter->block.first; block; block = block->next )
 
555
                                if( !strcmp( str, block->name ) )
 
556
                                        return block->adrcode;
 
557
 
 
558
                        /* no match; no addr code */
 
559
                        return -1;
 
560
                }
 
561
        }
 
562
 
 
563
        /* error if the ipo isn't in the list */
 
564
        return -2;
 
565
}
 
566
 
 
567
/*
 
568
 * Search through list of known Ipocurves for a particular adrcode.
 
569
 *
 
570
 * code: adrcode of curve we are searching for
 
571
 * blocktype: type of Ipo
 
572
 * channel: texture channel number, for World/Lamp/Material curves
 
573
 *
 
574
 * returns the adrcode for the named curve if it exists, -1 otherwise
 
575
 */
 
576
 
 
577
static short lookup_curve_adrcode( int code, int blocktype, int channel )
 
578
{
 
579
        int *adrcodes = NULL;
 
580
        int size = 0;
 
581
 
 
582
        switch ( blocktype ) {
 
583
        case ID_OB:
 
584
                adrcodes = ob_ar;
 
585
                size = OB_TOTIPO;
 
586
                break;
 
587
        case ID_MA:
 
588
                adrcodes = ma_ar;
 
589
                size = MA_TOTIPO;
 
590
                break;
 
591
        case ID_CA:
 
592
                adrcodes = cam_ar;
 
593
                size = CAM_TOTIPO;
 
594
                break;
 
595
        case ID_LA:
 
596
                adrcodes = la_ar;
 
597
                size = LA_TOTIPO;
 
598
                break;
 
599
        case ID_TE:
 
600
                adrcodes = te_ar;
 
601
                size = TE_TOTIPO;
 
602
                break;
 
603
        case ID_WO:
 
604
                adrcodes = wo_ar;
 
605
                size = WO_TOTIPO;
 
606
                break;
 
607
        case ID_PO:
 
608
                adrcodes = ac_ar;
 
609
                size = AC_TOTIPO;
 
610
                break;
 
611
        case ID_CO:
 
612
                adrcodes = co_ar;
 
613
                size = CO_TOTIPO;
 
614
                break;
 
615
        case ID_CU:
 
616
                adrcodes = cu_ar;
 
617
                size = CU_TOTIPO;
 
618
                break;
 
619
        case ID_SEQ:
 
620
                adrcodes = seq_ar;
 
621
                size = SEQ_TOTIPO;
 
622
                break;
 
623
        case ID_KE:
 
624
        default:
 
625
                return -1;
 
626
        }
 
627
 
 
628
        while ( size-- ) {
 
629
                if( *adrcodes == code ) {
 
630
 
 
631
                /* if not a texture channel, just return the adrcode */
 
632
                        if( channel == -1 || *adrcodes < MA_MAP1 )
 
633
                                return (short)*adrcodes;
 
634
 
 
635
                /* otherwise adjust adrcode to include current channel */
 
636
                        else {
 
637
                                int param = *adrcodes & ~MA_MAP1;
 
638
                                param |= texchannel_to_adrcode( channel );
 
639
                                return (short)param;
 
640
                        }
 
641
                }
 
642
                ++adrcodes;
 
643
        }
 
644
        return -1;
 
645
}
 
646
 
 
647
/*
 
648
 * Delete an IpoCurve from an Ipo
 
649
 */
 
650
 
 
651
static void del_ipocurve( Ipo * ipo, IpoCurve * icu ) {
 
652
        BLI_remlink( &( ipo->curve ), icu );
 
653
        if( icu->bezt )
 
654
                MEM_freeN( icu->bezt );
 
655
        if( icu->driver )
 
656
                MEM_freeN( icu->driver );
 
657
        MEM_freeN( icu );
 
658
 
 
659
        /* have to do this to avoid crashes in the IPO window */
 
660
        allspace( REMAKEIPO, 0 );
 
661
        EXPP_allqueue( REDRAWIPO, 0 );
 
662
}
 
663
 
 
664
/*****************************************************************************/
 
665
/* Python BPy_Ipo functions:                                                 */
 
666
/*****************************************************************************/
 
667
 
 
668
/*****************************************************************************/
183
669
/* Function:              M_Ipo_New                                          */
184
670
/* Python equivalent:     Blender.Ipo.New                                    */
185
671
/*****************************************************************************/
186
672
 
187
 
static PyObject *M_Ipo_New( PyObject * self, PyObject * args )
 
673
static PyObject *M_Ipo_New( PyObject * self_unused, PyObject * args )
188
674
{
189
 
        Ipo *add_ipo( char *name, int idcode );
190
675
        char *name = NULL, *code = NULL;
191
676
        int idcode = -1;
192
 
        BPy_Ipo *pyipo;
193
677
        Ipo *blipo;
194
678
 
195
679
        if( !PyArg_ParseTuple( args, "ss", &code, &name ) )
196
 
                return ( EXPP_ReturnPyObjError
197
 
                         ( PyExc_TypeError,
198
 
                           "expected string string arguments" ) );
 
680
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
681
                                "expected two string arguments" );
199
682
 
200
683
        if( !strcmp( code, "Object" ) )
201
684
                idcode = ID_OB;
202
 
        if( !strcmp( code, "Camera" ) )
 
685
        else if( !strcmp( code, "Camera" ) )
203
686
                idcode = ID_CA;
204
 
        if( !strcmp( code, "World" ) )
 
687
        else if( !strcmp( code, "World" ) )
205
688
                idcode = ID_WO;
206
 
        if( !strcmp( code, "Material" ) )
 
689
        else if( !strcmp( code, "Material" ) )
207
690
                idcode = ID_MA;
208
 
        if( !strcmp( code, "Texture" ) )
 
691
        else if( !strcmp( code, "Texture" ) )
209
692
                idcode = ID_TE;
210
 
        if( !strcmp( code, "Lamp" ) )
 
693
        else if( !strcmp( code, "Lamp" ) )
211
694
                idcode = ID_LA;
212
 
        if( !strcmp( code, "Action" ) )
 
695
        else if( !strcmp( code, "Action" ) )
213
696
                idcode = ID_PO;
214
 
        if( !strcmp( code, "Constraint" ) )
 
697
        else if( !strcmp( code, "Constraint" ) )
215
698
                idcode = ID_CO;
216
 
        if( !strcmp( code, "Sequence" ) )
 
699
        else if( !strcmp( code, "Sequence" ) )
217
700
                idcode = ID_SEQ;
218
 
        if( !strcmp( code, "Curve" ) )
 
701
        else if( !strcmp( code, "Curve" ) )
219
702
                idcode = ID_CU;
220
 
        if( !strcmp( code, "Key" ) )
 
703
        else if( !strcmp( code, "Key" ) )
221
704
                idcode = ID_KE;
222
 
 
223
 
        if( idcode == -1 )
224
 
                return ( EXPP_ReturnPyObjError
225
 
                         ( PyExc_TypeError, "Bad code" ) );
226
 
 
 
705
        else return EXPP_ReturnPyObjError( PyExc_ValueError,
 
706
                        "unknown Ipo code" );
227
707
 
228
708
        blipo = add_ipo( name, idcode );
229
709
 
231
711
                /* return user count to zero because add_ipo() inc'd it */
232
712
                blipo->id.us = 0;
233
713
                /* create python wrapper obj */
234
 
                pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
 
714
                return Ipo_CreatePyObject( blipo );
235
715
        } else
236
 
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
237
 
                                                "couldn't create Ipo Data in Blender" ) );
238
 
 
239
 
        if( pyipo == NULL )
240
 
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
241
 
                                                "couldn't create Ipo Data object" ) );
242
 
 
243
 
        pyipo->ipo = blipo;
244
 
 
245
 
        return ( PyObject * ) pyipo;
 
716
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
717
                                "couldn't create Ipo Data in Blender" );
246
718
}
247
719
 
248
720
/*****************************************************************************/
253
725
/*                        passed in, a list of all ipo data names in the  */
254
726
/*                        current scene is returned.                         */
255
727
/*****************************************************************************/
256
 
static PyObject *M_Ipo_Get( PyObject * self, PyObject * args )
 
728
static PyObject *M_Ipo_Get( PyObject * self_unused, PyObject * args )
257
729
{
258
730
        char *name = NULL;
259
731
        Ipo *ipo_iter;
260
732
        PyObject *ipolist, *pyobj;
261
 
        BPy_Ipo *wanted_ipo = NULL;
262
733
        char error_msg[64];
263
734
 
264
735
        if( !PyArg_ParseTuple( args, "|s", &name ) )
268
739
        ipo_iter = G.main->ipo.first;
269
740
 
270
741
        if( name ) {            /* (name) - Search ipo by name */
271
 
                while( ( ipo_iter ) && ( wanted_ipo == NULL ) ) {
272
 
                        if( strcmp( name, ipo_iter->id.name + 2 ) == 0 ) {
273
 
                                wanted_ipo =
274
 
                                        ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo,
275
 
                                                                    &Ipo_Type );
276
 
                                if( wanted_ipo )
277
 
                                        wanted_ipo->ipo = ipo_iter;
 
742
                while( ipo_iter ) {
 
743
                        if( !strcmp( name, ipo_iter->id.name + 2 ) ) {
 
744
                                return Ipo_CreatePyObject( ipo_iter );
278
745
                        }
279
746
                        ipo_iter = ipo_iter->id.next;
280
747
                }
281
748
 
282
 
                if( wanted_ipo == NULL ) {      /* Requested ipo doesn't exist */
283
 
                        PyOS_snprintf( error_msg, sizeof( error_msg ),
284
 
                                       "Ipo \"%s\" not found", name );
285
 
                        return ( EXPP_ReturnPyObjError
286
 
                                 ( PyExc_NameError, error_msg ) );
287
 
                }
288
 
 
289
 
                return ( PyObject * ) wanted_ipo;
 
749
                PyOS_snprintf( error_msg, sizeof( error_msg ),
 
750
                                   "Ipo \"%s\" not found", name );
 
751
                return EXPP_ReturnPyObjError( PyExc_NameError, error_msg );
290
752
        }
291
753
 
292
754
        else {                  /* () - return a list with all ipos in the scene */
294
756
 
295
757
                ipolist = PyList_New( BLI_countlist( &( G.main->ipo ) ) );
296
758
 
297
 
                if( ipolist == NULL )
298
 
                        return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
299
 
                                                        "couldn't create PyList" ) );
 
759
                if( !ipolist )
 
760
                        return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
761
                                        "couldn't create PyList" );
300
762
 
301
763
                while( ipo_iter ) {
302
764
                        pyobj = Ipo_CreatePyObject( ipo_iter );
303
765
 
304
766
                        if( !pyobj )
305
 
                                return ( EXPP_ReturnPyObjError
306
 
                                         ( PyExc_MemoryError,
307
 
                                           "couldn't create PyString" ) );
 
767
                                return NULL;
308
768
 
309
769
                        PyList_SET_ITEM( ipolist, index, pyobj );
310
770
 
312
772
                        index++;
313
773
                }
314
774
 
315
 
                return ( ipolist );
 
775
                return ipolist;
316
776
        }
317
777
}
318
778
 
 
779
/*
 
780
 * This should probably be deprecated too?  Or else documented in epydocs.
 
781
 * Seems very similar to Ipocurve.recalc().
 
782
 */
319
783
 
320
 
static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
 
784
/*****************************************************************************/
 
785
/* Function:              M_Ipo_Recalc                                       */
 
786
/* Python equivalent:     Blender.Ipo.Recalc                                 */
 
787
/* Description:           Receives (presumably) an IpoCurve object and       */
 
788
/*                        updates the curve after changes to control points. */
 
789
/*****************************************************************************/
 
790
static PyObject *M_Ipo_Recalc( PyObject * self_unused, PyObject * args )
321
791
{
322
 
        PyObject *obj;
323
 
        IpoCurve *icu;
 
792
        PyObject *pyobj;
324
793
 
325
 
        if( !PyArg_ParseTuple( args, "O!", &IpoCurve_Type, &obj ) )
 
794
        if( !PyArg_ParseTuple( args, "O!", &IpoCurve_Type, &pyobj ) )
326
795
                return EXPP_ReturnPyObjError( PyExc_TypeError,
327
796
                                "expected Ipo curve argument" );
328
797
 
329
 
        icu = IpoCurve_FromPyObject( obj );
330
 
        testhandles_ipocurve( icu );
331
 
 
332
 
        Py_INCREF( Py_None );
333
 
        return Py_None;
334
 
 
335
 
}
336
 
 
337
 
/*****************************************************************************/
338
 
/* Function:              Ipo_Init                                           */
339
 
/*****************************************************************************/
340
 
PyObject *Ipo_Init( void )
341
 
{
342
 
        PyObject *submodule;
343
 
 
344
 
        Ipo_Type.ob_type = &PyType_Type;
345
 
 
346
 
        submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
347
 
 
348
 
        return ( submodule );
349
 
}
350
 
 
351
 
/*****************************************************************************/
352
 
/* Python BPy_Ipo methods:                                                  */
353
 
/*****************************************************************************/
 
798
        testhandles_ipocurve( IpoCurve_FromPyObject( pyobj ) );
 
799
 
 
800
        Py_RETURN_NONE;
 
801
}
 
802
 
 
803
/*****************************************************************************/
 
804
/* Python BPy_Ipo methods:                                                   */
 
805
/*****************************************************************************/
 
806
 
354
807
static PyObject *Ipo_getName( BPy_Ipo * self )
355
808
{
356
809
        PyObject *attr = PyString_FromString( self->ipo->id.name + 2 );
357
810
 
358
811
        if( attr )
359
812
                return attr;
360
 
        Py_INCREF( Py_None );
361
 
        return Py_None;
 
813
 
 
814
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
815
                        "couldn't get Ipo.name attribute" );
362
816
}
363
817
 
364
 
 
365
 
static PyObject *Ipo_setName( BPy_Ipo * self, PyObject * args )
 
818
static int Ipo_setName( BPy_Ipo * self, PyObject * args )
366
819
{
367
820
        char *name;
368
821
        char buf[21];
369
822
 
370
 
        if( !PyArg_ParseTuple( args, "s", &name ) )
371
 
                return ( EXPP_ReturnPyObjError
372
 
                         ( PyExc_TypeError, "expected string argument" ) );
 
823
        name = PyString_AsString( args );
 
824
        if( !name )
 
825
                return EXPP_ReturnIntError( PyExc_TypeError,
 
826
                                "expected string argument" );
373
827
 
374
828
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
375
829
 
376
830
        rename_id( &self->ipo->id, buf );
377
831
 
378
 
        Py_INCREF( Py_None );
379
 
        return Py_None;
 
832
        return 0;
380
833
}
381
834
 
382
835
static PyObject *Ipo_getBlocktype( BPy_Ipo * self )
383
836
{
384
837
        PyObject *attr = PyInt_FromLong( self->ipo->blocktype );
 
838
 
385
839
        if( attr )
386
840
                return attr;
387
 
        return ( EXPP_ReturnPyObjError
388
 
                 ( PyExc_RuntimeError,
389
 
                   "couldn't get Ipo.blocktype attribute" ) );
 
841
 
 
842
        return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
843
                   "couldn't get Ipo.blocktype attribute" );
390
844
}
391
845
 
392
 
 
393
 
static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
 
846
static int Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
394
847
{
395
 
        int blocktype = 0;
396
 
 
397
 
        if( !PyArg_ParseTuple( args, "i", &blocktype ) )
398
 
                return ( EXPP_ReturnPyObjError
399
 
                         ( PyExc_TypeError, "expected string argument" ) );
400
 
 
401
 
        self->ipo->blocktype = ( short ) blocktype;
402
 
 
403
 
        Py_INCREF( Py_None );
404
 
        return Py_None;
 
848
        if( !PyInt_CheckExact( args ) )
 
849
                return EXPP_ReturnIntError( PyExc_TypeError,
 
850
                                "expected int argument" );
 
851
 
 
852
        self->ipo->blocktype = (short)PyInt_AS_LONG( args );
 
853
 
 
854
        return 0;
405
855
}
406
856
 
407
 
 
408
857
static PyObject *Ipo_getRctf( BPy_Ipo * self )
409
858
{
410
859
        PyObject *l = PyList_New( 0 );
413
862
        PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymin ) );
414
863
        PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymax ) );
415
864
        return l;
416
 
 
417
865
}
418
866
 
419
 
 
420
 
static PyObject *Ipo_setRctf( BPy_Ipo * self, PyObject * args )
 
867
static int Ipo_setRctf( BPy_Ipo * self, PyObject * args )
421
868
{
422
869
        float v[4];
 
870
 
423
871
        if( !PyArg_ParseTuple( args, "ffff", v, v + 1, v + 2, v + 3 ) )
424
 
                return ( EXPP_ReturnPyObjError
425
 
                         ( PyExc_TypeError, "expected 4 float argument" ) );
 
872
                return EXPP_ReturnIntError( PyExc_TypeError,
 
873
                                "expected a tuple of 4 floats" );
426
874
 
427
875
        self->ipo->cur.xmin = v[0];
428
876
        self->ipo->cur.xmax = v[1];
429
877
        self->ipo->cur.ymin = v[2];
430
878
        self->ipo->cur.ymax = v[3];
431
879
 
432
 
        Py_INCREF( Py_None );
433
 
        return Py_None;
 
880
        return 0;
434
881
}
435
882
 
 
883
/*
 
884
 * Get total number of Ipo curves for this Ipo.  NOTE:  this function
 
885
 * returns all curves for Ipos which have texture channels, unlike
 
886
 * Ipo_length().
 
887
 */
 
888
 
436
889
static PyObject *Ipo_getNcurves( BPy_Ipo * self )
437
890
{
 
891
        IpoCurve *icu;
438
892
        int i = 0;
439
893
 
440
 
        IpoCurve *icu;
441
894
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
442
895
                i++;
443
896
        }
444
897
 
445
 
        return ( PyInt_FromLong( i ) );
446
 
}
447
 
 
448
 
 
449
 
/*
450
 
  Lamp ipo Name to Channel
451
 
*/
452
 
 
453
 
static int Ipo_laIcuName( char *s, int *param )
454
 
{
455
 
        extern int la_ar[];
456
 
 
457
 
        int not_ok = 0;
458
 
        int i;
459
 
        char *lamp_names[LA_TOTIPO] =
460
 
                { "Energ", "R", "G", "B", "Dist", "SpoSi",
461
 
                "SpoBl", "Quad1", "Quad2", "HaInt",
462
 
                /* lamp texture names */
463
 
                "OfsX", "OfsY", "OfsZ", "SizeX", "SizeY",
464
 
                "SizeZ", "texR", "texG", "texB", "DefVar",
465
 
                "Col"
466
 
        };
467
 
 
468
 
        for( i = 0; i < LA_TOTIPO; i++ ) {
469
 
                if( !strcmp( s, lamp_names[i] ) ) {     /* found it! */
470
 
                        *param = la_ar[i];
471
 
                        return 1;
472
 
                }
473
 
        }
474
 
 
475
 
        return not_ok;
476
 
}
477
 
 
478
 
 
479
 
/* 
480
 
 World Ipo Name to Channel
481
 
*/
482
 
 
483
 
static int Ipo_woIcuName( char *s, int *param )
484
 
{
485
 
        extern int wo_ar[];     /* channel values from ipo.c */
486
 
        int not_ok = 0;
487
 
        int i;
488
 
        char *world_names[WO_TOTIPO] = { "HorR", "HorG", "HorB",
489
 
                "ZenR", "ZenG", "ZenB",
490
 
                "Expos",
491
 
                "Misi", "MisDi", "MisSta", "MisHi",
492
 
                "StarR", "StarB", "StarG",
493
 
                "StarDi", "StarSi",
494
 
                /* world textures names */
495
 
                "OfsX", "OfsY", "OfsZ",
496
 
                "SizeX", "SizeY", "SizeZ",
497
 
                "texR", "texG", "texB",
498
 
                "DefVar", "Col", "Nor", "Var",
499
 
        };
500
 
 
501
 
        for( i = 0; i < WO_TOTIPO; i++ ) {
502
 
                if( !strcmp( s, world_names[i] ) ) {    /* found it! */
503
 
                        *param = wo_ar[i];
504
 
                        return 1;
505
 
                }
506
 
        }
507
 
 
508
 
        return not_ok;
509
 
}
510
 
 
511
 
static int Ipo_maIcuName( char *s, int *param )
512
 
{
513
 
        extern int ma_ar[];
514
 
 
515
 
        int not_ok = 0;
516
 
        int i;
517
 
 
518
 
        char *material_names[MA_TOTIPO] = { "R", "G", "B",
519
 
                "SpecR", "SpecG", "SpecB",
520
 
                "MirR", "MirG", "MirB", "Ref", "Alpha",
521
 
                "Emit", "Amb", "Spec",
522
 
                "Hard", "SpTra", "Ior", "Mode",
523
 
                "HaSize", "Translu",
524
 
                "RayMir", "FresMir", "FresMirI",
525
 
                "FresTra", "FresTraI",
526
 
                "TraGlow",
527
 
                "OfsX", "OfsY", "OfsZ",
528
 
                "SizeX", "SizeY", "SizeZ",
529
 
                "texR", "texG", "texB",
530
 
                "DefVar", "Col", "Nor", "Var",
531
 
                "Disp"
532
 
        };
533
 
 
534
 
 
535
 
        for( i = 0; i < MA_TOTIPO; i++ ) {
536
 
                if( !strcmp( s, material_names[i] ) ) { /* found it! */
537
 
                        *param = ma_ar[i];
538
 
                        return 1;
539
 
                }
540
 
        }
541
 
 
542
 
        return not_ok;
543
 
}
544
 
 
545
 
static int Ipo_keIcuName( char *s, int *param )
546
 
{
547
 
        char key[10];
548
 
        int ok = 0;
549
 
        int nr = 0;
550
 
        if( !strcmp( s, "Speed" ) ) {
551
 
                *param = KEY_SPEED;
552
 
                ok = 1;
553
 
        }
554
 
        for( nr = 1; nr < 64; nr++ ) {
555
 
                sprintf( key, "Key %d", nr );
556
 
                if( !strcmp( s, key ) ) {
557
 
                        *param = nr;
558
 
                        ok = 1;
559
 
                        break;
560
 
                }
561
 
        }
562
 
 
563
 
        return ok;
564
 
}
565
 
 
566
 
static int Ipo_seqIcuName( char *s, int *param )
567
 
{
568
 
        int ok = 0;
569
 
        if( !strcmp( s, "Fac" ) ) {
570
 
                *param = SEQ_FAC1;
571
 
                ok = 1;
572
 
        }
573
 
 
574
 
        return ok;
575
 
}
576
 
 
577
 
static int Ipo_cuIcuName( char *s, int *param )
578
 
{
579
 
        int ok = 0;
580
 
        if( !strcmp( s, "Speed" ) ) {
581
 
                *param = CU_SPEED;
582
 
                ok = 1;
583
 
        }
584
 
 
585
 
        return ok;
586
 
}
587
 
 
588
 
static int Ipo_coIcuName( char *s, int *param )
589
 
{
590
 
        int ok = 0;
591
 
        if( !strcmp( s, "Inf" ) ) {
592
 
                *param = CO_ENFORCE;
593
 
                ok = 1;
594
 
        }
595
 
 
596
 
        return ok;
597
 
}
598
 
 
599
 
static int Ipo_acIcuName( char *s, int *param )
600
 
{
601
 
        int ok = 0;
602
 
        if( !strcmp( s, "LocX" ) ) {
603
 
                *param = AC_LOC_X;
604
 
                return 1;
605
 
        }
606
 
        if( !strcmp( s, "LocY" ) ) {
607
 
                *param = AC_LOC_Y;
608
 
                return 1;
609
 
        }
610
 
        if( !strcmp( s, "LocZ" ) ) {
611
 
                *param = AC_LOC_Z;
612
 
                return 1;
613
 
        }
614
 
        if( !strcmp( s, "SizeX" ) ) {
615
 
                *param = AC_SIZE_X;
616
 
                return 1;
617
 
        }
618
 
        if( !strcmp( s, "SizeY" ) ) {
619
 
                *param = AC_SIZE_Y;
620
 
                return 1;
621
 
        }
622
 
        if( !strcmp( s, "SizeZ" ) ) {
623
 
                *param = AC_SIZE_Z;
624
 
                return 1;
625
 
        }
626
 
        if( !strcmp( s, "QuatX" ) ) {
627
 
                *param = AC_QUAT_X;
628
 
                return 1;
629
 
        }
630
 
        if( !strcmp( s, "QuatY" ) ) {
631
 
                *param = AC_QUAT_Y;
632
 
                return 1;
633
 
        }
634
 
        if( !strcmp( s, "QuatZ" ) ) {
635
 
                *param = AC_QUAT_Z;
636
 
                return 1;
637
 
        }
638
 
        if( !strcmp( s, "QuatW" ) ) {
639
 
                *param = AC_QUAT_W;
640
 
                return 1;
641
 
        }
642
 
        return ok;
643
 
}
644
 
 
645
 
 
646
 
/*
647
 
  Camera ipo name to channel
648
 
*/
649
 
 
650
 
static int Ipo_caIcuName( char *s, int *param )
651
 
{
652
 
        /* for Camera ipos CAM_TOTNAM == CAM_TOTIPO 
653
 
           and cam_ic_names[] holds the complete set of names, so we use that.
654
 
         */
655
 
        extern int cam_ar[];
656
 
        extern char *cam_ic_names[];
657
 
 
658
 
        int not_ok = 0;
659
 
        int i;
660
 
 
661
 
        for( i = 0; i < CAM_TOTIPO; i++ ) {
662
 
                if( !strcmp( s, cam_ic_names[i] ) ) {   /* found it! */
663
 
                        *param = cam_ar[i];
664
 
                        return 1;
665
 
                }
666
 
        }
667
 
 
668
 
        return not_ok;
669
 
}
670
 
 
671
 
 
672
 
/*
673
 
  texture ipo name to channel
674
 
*/
675
 
 
676
 
static int Ipo_texIcuName( char *s, int *param )
677
 
{
678
 
        /* this is another case where TE_TOTIPO == TE_TOTNAM.
679
 
           te_ic_names[] has all our names so use that.
680
 
        */
681
 
        extern int te_ar[];
682
 
        extern char *tex_ic_names[];
683
 
        int not_ok = 0;
684
 
        int i;
685
 
 
686
 
        for( i = 0; i < TE_TOTIPO; i++){
687
 
                if( !strcmp( s, tex_ic_names[i] ) ){
688
 
                        *param = te_ar[i];
689
 
                        return 1;
690
 
                }
691
 
        }
692
 
 
693
 
        return not_ok;
694
 
}
695
 
 
696
 
static int Ipo_obIcuName( char *s, int *param )
697
 
{
698
 
        int ok = 0;
699
 
        if( !strcmp( s, "LocX" ) ) {
700
 
                *param = OB_LOC_X;
701
 
                return 1;
702
 
        }
703
 
        if( !strcmp( s, "LocY" ) ) {
704
 
                *param = OB_LOC_Y;
705
 
                return 1;
706
 
        }
707
 
        if( !strcmp( s, "LocZ" ) ) {
708
 
                *param = OB_LOC_Z;
709
 
                return 1;
710
 
        }
711
 
        if( !strcmp( s, "RotX" ) ) {
712
 
                *param = OB_ROT_X;
713
 
                return 1;
714
 
        }
715
 
        if( !strcmp( s, "RotY" ) ) {
716
 
                *param = OB_ROT_Y;
717
 
                return 1;
718
 
        }
719
 
        if( !strcmp( s, "RotZ" ) ) {
720
 
                *param = OB_ROT_Z;
721
 
                return 1;
722
 
        }
723
 
        if( !strcmp( s, "SizeX" ) ) {
724
 
                *param = OB_SIZE_X;
725
 
                return 1;
726
 
        }
727
 
        if( !strcmp( s, "SizeY" ) ) {
728
 
                *param = OB_SIZE_Y;
729
 
                return 1;
730
 
        }
731
 
        if( !strcmp( s, "SizeZ" ) ) {
732
 
                *param = OB_SIZE_Z;
733
 
                return 1;
734
 
        }
735
 
 
736
 
        if( !strcmp( s, "dLocX" ) ) {
737
 
                *param = OB_DLOC_X;
738
 
                return 1;
739
 
        }
740
 
        if( !strcmp( s, "dLocY" ) ) {
741
 
                *param = OB_DLOC_Y;
742
 
                return 1;
743
 
        }
744
 
        if( !strcmp( s, "dLocZ" ) ) {
745
 
                *param = OB_DLOC_Z;
746
 
                return 1;
747
 
        }
748
 
        if( !strcmp( s, "dRotX" ) ) {
749
 
                *param = OB_DROT_X;
750
 
                return 1;
751
 
        }
752
 
        if( !strcmp( s, "dRotY" ) ) {
753
 
                *param = OB_DROT_Y;
754
 
                return 1;
755
 
        }
756
 
        if( !strcmp( s, "dRotZ" ) ) {
757
 
                *param = OB_DROT_Z;
758
 
                return 1;
759
 
        }
760
 
        if( !strcmp( s, "dSizeX" ) ) {
761
 
                *param = OB_DSIZE_X;
762
 
                return 1;
763
 
        }
764
 
        if( !strcmp( s, "dSizeY" ) ) {
765
 
                *param = OB_DSIZE_Y;
766
 
                return 1;
767
 
        }
768
 
        if( !strcmp( s, "dSizeZ" ) ) {
769
 
                *param = OB_DSIZE_Z;
770
 
                return 1;
771
 
        }
772
 
 
773
 
        if( !strcmp( s, "Layer" ) ) {
774
 
                *param = OB_LAY;
775
 
                return 1;
776
 
        }
777
 
        if( !strcmp( s, "Time" ) ) {
778
 
                *param = OB_TIME;
779
 
                return 1;
780
 
        }
781
 
 
782
 
        if( !strcmp( s, "ColR" ) ) {
783
 
                *param = OB_COL_R;
784
 
                return 1;
785
 
        }
786
 
        if( !strcmp( s, "ColG" ) ) {
787
 
                *param = OB_COL_G;
788
 
                return 1;
789
 
        }
790
 
        if( !strcmp( s, "ColB" ) ) {
791
 
                *param = OB_COL_B;
792
 
                return 1;
793
 
        }
794
 
        if( !strcmp( s, "ColA" ) ) {
795
 
                *param = OB_COL_A;
796
 
                return 1;
797
 
        }
798
 
        if( !strcmp( s, "FStreng" ) ) {
799
 
                *param = OB_PD_FSTR;
800
 
                return 1;
801
 
        }
802
 
        if( !strcmp( s, "FFall" ) ) {
803
 
                *param = OB_PD_FFALL;
804
 
                return 1;
805
 
        }
806
 
        if( !strcmp( s, "Damping" ) ) {
807
 
                *param = OB_PD_SDAMP;
808
 
                return 1;
809
 
        }
810
 
        if( !strcmp( s, "RDamp" ) ) {
811
 
                *param = OB_PD_RDAMP;
812
 
                return 1;
813
 
        }
814
 
        if( !strcmp( s, "Perm" ) ) {
815
 
                *param = OB_PD_PERM;
816
 
                return 1;
817
 
        }
818
 
 
819
 
        return ok;
820
 
}
821
 
 
 
898
        return PyInt_FromLong( (long)i );
 
899
}
822
900
 
823
901
/* 
824
902
   Function:  Ipo_addCurve
832
910
 
833
911
static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
834
912
{
835
 
        int param = 0;          /* numeric curve name constant */
836
 
        int ok;
 
913
        short param;            /* numeric curve name constant */
837
914
        char *cur_name = 0;     /* input arg: curve name */
838
915
        Ipo *ipo = 0;
839
916
        IpoCurve *icu = 0;
859
936
                                ( PyExc_RuntimeError, "Ipo not found" );
860
937
 
861
938
        /*
862
 
           depending on the block type, 
863
 
           check if the input arg curve name is valid 
864
 
           and set param to numeric value.
 
939
         * Check if the input arg curve name is valid depending on the block
 
940
         * type, and set param to numeric value.  Invalid names will return
 
941
         * param = -1.
865
942
         */
866
 
        switch ( ipo->blocktype ) {
867
 
        case ID_OB:
868
 
                ok = Ipo_obIcuName( cur_name, &param );
869
 
                break;
870
 
        case ID_CA:
871
 
                ok = Ipo_caIcuName( cur_name, &param );
872
 
                break;
873
 
        case ID_LA:
874
 
                ok = Ipo_laIcuName( cur_name, &param );
875
 
                break;
876
 
        case ID_TE:
877
 
                ok = Ipo_texIcuName( cur_name, &param );
878
 
                break;
879
 
        case ID_WO:
880
 
                ok = Ipo_woIcuName( cur_name, &param );
881
 
                break;
882
 
        case ID_MA:
883
 
                ok = Ipo_maIcuName( cur_name, &param );
884
 
                break;
885
 
        case ID_PO:
886
 
                ok = Ipo_acIcuName( cur_name, &param );
887
 
                break;
888
 
        case ID_CO:
889
 
                ok = Ipo_coIcuName( cur_name, &param );
890
 
                break;
891
 
        case ID_CU:
892
 
                ok = Ipo_cuIcuName( cur_name, &param );
893
 
                break;
894
 
        case ID_KE:
895
 
                ok = Ipo_keIcuName( cur_name, &param );
896
 
                break;
897
 
        case ID_SEQ:
898
 
                ok = Ipo_seqIcuName( cur_name, &param );
899
 
                break;
900
 
        default:
901
 
                ok = 0;
 
943
 
 
944
        if( ipo->blocktype != ID_KE ) {
 
945
                param = lookup_curve_name( cur_name, ipo->blocktype, self->mtex );
 
946
        } else {
 
947
                param = lookup_curve_key( cur_name, ipo );
 
948
                if( param == -2 )
 
949
                        return EXPP_ReturnPyObjError( PyExc_RuntimeError, 
 
950
                                        "unable to find matching key data for Ipo" );
902
951
        }
903
952
 
904
 
        if( !ok )               /* curve type was invalid */
905
 
                return EXPP_ReturnPyObjError
906
 
                        ( PyExc_NameError, "curve name was invalid" );
 
953
        if( param == -1 )
 
954
                return EXPP_ReturnPyObjError( PyExc_NameError,
 
955
                                "curve name is not valid" );
907
956
 
908
957
        /* see if the curve already exists */
909
958
        for( icu = ipo->curve.first; icu; icu = icu->next )
912
961
                                        "Ipo curve already exists" );
913
962
 
914
963
        /* create the new ipo curve */
915
 
        icu = MEM_callocN(sizeof(IpoCurve), "Python added ipocurve");
916
 
        icu->blocktype= ipo->blocktype;
917
 
        icu->adrcode= (short)param;
 
964
        icu = MEM_callocN( sizeof(IpoCurve), "Python added ipocurve");
 
965
        icu->blocktype = ipo->blocktype;
 
966
        icu->adrcode = param;
918
967
        icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
919
968
        set_icu_vars( icu );
920
969
        BLI_addtail( &(ipo->curve), icu);
921
 
        
 
970
 
922
971
        allspace( REMAKEIPO, 0 );
923
972
        EXPP_allqueue( REDRAWIPO, 0 );
924
973
 
942
991
        char *strname;
943
992
 
944
993
        if( !PyArg_ParseTuple( args, "s", &strname ) )
945
 
                return ( EXPP_ReturnPyObjError
946
 
                         ( PyExc_TypeError, "string argument" ) );
 
994
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
995
                                "expected string argument" );
947
996
 
948
997
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
949
 
                char *str1 = getIpoCurveName( icu );
950
 
                if( !strcmp( str1, strname ) ) {
951
 
                        BLI_remlink( &( self->ipo->curve ), icu );
952
 
                        if( icu->bezt )
953
 
                                MEM_freeN( icu->bezt );
954
 
                        MEM_freeN( icu );
955
 
 
956
 
                        allspace( REMAKEIPO, 0 );
957
 
                        EXPP_allqueue( REDRAWIPO, 0 );
958
 
 
959
 
                        Py_INCREF( Py_None );
960
 
                        return Py_None;
 
998
                if( !strcmp( strname, getIpoCurveName( icu ) ) ) {
 
999
                        del_ipocurve( self->ipo, icu );
 
1000
                Py_RETURN_NONE;
961
1001
                }
962
1002
        }
963
1003
 
964
 
        return ( EXPP_ReturnPyObjError
965
 
                 ( PyExc_RuntimeError, "IpoCurve not found" ) );
 
1004
        return EXPP_ReturnPyObjError( PyExc_ValueError, "IpoCurve not found" );
966
1005
}
967
 
 
968
 
 
 
1006
/*
 
1007
 */
969
1008
 
970
1009
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
971
1010
{
972
 
    char *str, *str1;
973
1011
    IpoCurve *icu = NULL;
974
 
    int adrcode;
975
 
    PyObject *thing;
976
 
 
977
 
    if( !PyArg_ParseTuple( args, "O", &thing ) )
978
 
        return EXPP_ReturnPyObjError(PyExc_TypeError, 
979
 
                                                        "expected string or int argument" );
980
 
 
981
 
    if(PyString_Check(thing)){
982
 
        str = PyString_AsString(thing);
 
1012
    short adrcode;
 
1013
    PyObject *value = NULL;
 
1014
 
 
1015
    if( !PyArg_ParseTuple( args, "|O", &value ) )
 
1016
                goto typeError;
 
1017
 
 
1018
    /* if no name give, get all the Ipocurves */
 
1019
        if( !value )
 
1020
                return Ipo_getCurves( self );
 
1021
 
 
1022
        /* if arg is a string or int, look up the adrcode */
 
1023
    if( PyString_Check( value ) ) {
 
1024
                char *str = PyString_AsString( value );
983
1025
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
984
 
            str1 = getIpoCurveName( icu );
985
 
            if( !strcmp( str1, str ) )
 
1026
            if( !strcmp( str, getIpoCurveName( icu ) ) )
986
1027
                return IpoCurve_CreatePyObject( icu );
987
1028
        }
988
 
    } else if (PyInt_Check(thing)){
989
 
        adrcode = (short)PyInt_AsLong(thing);
 
1029
        Py_RETURN_NONE;
 
1030
        }
 
1031
    else if( PyInt_Check( value ) ) {
 
1032
        adrcode = ( short )PyInt_AsLong( value );
990
1033
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
991
 
            if(icu->adrcode == adrcode)
 
1034
            if( icu->adrcode == adrcode )
992
1035
                 return IpoCurve_CreatePyObject( icu );
993
 
        }
994
 
    } else
995
 
        return EXPP_ReturnPyObjError(PyExc_TypeError, 
996
 
                                                        "expected string or int argument" );
997
 
    Py_INCREF( Py_None );
998
 
    return Py_None;
 
1036
                }
 
1037
        Py_RETURN_NONE;
 
1038
        }
 
1039
 
 
1040
typeError:
 
1041
        return EXPP_ReturnPyObjError(PyExc_TypeError,
 
1042
                        "expected string or int argument" );
999
1043
1000
1044
 
1001
1045
static PyObject *Ipo_getCurves( BPy_Ipo * self )
1002
1046
{
1003
1047
        PyObject *attr = PyList_New( 0 );
1004
1048
        IpoCurve *icu;
1005
 
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
 
1049
 
 
1050
        for( icu = self->ipo->curve.first; icu; icu = icu->next )
1006
1051
                PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
1007
 
        }
1008
 
        return attr;
1009
 
}
1010
 
 
 
1052
 
 
1053
        return attr;
 
1054
}
 
1055
 
 
1056
/*
 
1057
 * return a list of valid curve name constants for the Ipo
 
1058
 */
 
1059
 
 
1060
static PyObject *Ipo_getCurveNames( BPy_Ipo * self )
 
1061
{
 
1062
        namefunc lookup_name;
 
1063
        int size;
 
1064
        PyObject *dict;
 
1065
        int *vals = NULL;
 
1066
        char name[32];
 
1067
        PyObject *attr = Py_None;
 
1068
 
 
1069
        /* determine what type of Ipo we are */
 
1070
 
 
1071
        switch ( self->ipo->blocktype ) {
 
1072
        case ID_OB:
 
1073
                lookup_name = (namefunc)getname_ob_ei;
 
1074
                vals = ob_ar;
 
1075
                size = OB_TOTIPO;
 
1076
                strcpy( name, "OB_" );
 
1077
                break;
 
1078
        case ID_MA:
 
1079
                lookup_name = (namefunc)getname_mat_ei;
 
1080
                vals = ma_ar;
 
1081
                size = MA_TOTIPO;
 
1082
                strcpy( name, "MA_" );
 
1083
                break;
 
1084
        case ID_CA:
 
1085
                lookup_name = (namefunc)getname_cam_ei;
 
1086
                vals = cam_ar;
 
1087
                size = CAM_TOTIPO;
 
1088
                strcpy( name, "CA_" );
 
1089
                break;
 
1090
        case ID_LA:
 
1091
                lookup_name = (namefunc)getname_la_ei;
 
1092
                vals = la_ar;
 
1093
                size = LA_TOTIPO;
 
1094
                strcpy( name, "LA_" );
 
1095
                break;
 
1096
        case ID_TE:
 
1097
                lookup_name = (namefunc)getname_tex_ei;
 
1098
                vals = te_ar;
 
1099
                size = TE_TOTIPO;
 
1100
                strcpy( name, "TE_" );
 
1101
                break;
 
1102
        case ID_WO:
 
1103
                lookup_name = (namefunc)getname_world_ei;
 
1104
                vals = wo_ar;
 
1105
                size = WO_TOTIPO;
 
1106
                strcpy( name, "WO_" );
 
1107
                break;
 
1108
        case ID_PO:
 
1109
                lookup_name = (namefunc)getname_ac_ei;
 
1110
                vals = ac_ar;
 
1111
                size = AC_TOTIPO;
 
1112
                strcpy( name, "PO_" );
 
1113
                break;
 
1114
        case ID_CO:
 
1115
                lookup_name = (namefunc)getname_co_ei;
 
1116
                vals = co_ar;
 
1117
                size = CO_TOTIPO;
 
1118
                strcpy( name, "CO_" );
 
1119
                break;
 
1120
        case ID_CU:
 
1121
                lookup_name = (namefunc)getname_cu_ei;
 
1122
                vals = cu_ar;
 
1123
                size = CU_TOTIPO;
 
1124
                strcpy( name, "CU_" );
 
1125
                break;
 
1126
        case ID_SEQ:
 
1127
                lookup_name = (namefunc)getname_seq_ei;
 
1128
                vals = seq_ar;
 
1129
                size = SEQ_TOTIPO;
 
1130
                strcpy( name, "SQ_" );
 
1131
                break;
 
1132
        case ID_KE:
 
1133
                {
 
1134
                        Key *key;
 
1135
 
 
1136
                        /* find the ipo in the keylist */
 
1137
                        for( key = G.main->key.first; key; key = key->id.next ) {
 
1138
                                if( key->ipo == self->ipo ) {
 
1139
                                        KeyBlock *block = key->block.first;
 
1140
                                        attr = PyList_New( 0 );
 
1141
 
 
1142
                                        /* add each name to the list */
 
1143
                                        for( block = key->block.first; block; block = block->next )
 
1144
                                                PyList_Append( attr,
 
1145
                                                                PyString_FromString( block->name ) );
 
1146
 
 
1147
                                        return attr;
 
1148
                                }
 
1149
                        }
 
1150
 
 
1151
                        /* error if the ipo isn't in the list */
 
1152
                return EXPP_ReturnPyObjError( PyExc_RuntimeError, 
 
1153
                                        "unable to find matching key data for Ipo" );
 
1154
                }
 
1155
        default:
 
1156
                Py_DECREF( attr );
 
1157
        return EXPP_ReturnPyObjError( PyExc_RuntimeError, 
 
1158
                                                        "unknown Ipo type" );
 
1159
        }
 
1160
 
 
1161
        /*
 
1162
         * go through the list of adrcodes to find names, then add to dictionary
 
1163
         * with string as key and adrcode as value
 
1164
         */
 
1165
 
 
1166
        dict = PyModule_GetDict( submodule );
 
1167
        attr = PyConstant_New();
 
1168
 
 
1169
        while( size-- ) {
 
1170
                char *ptr = name+3;
 
1171
                strcpy( name+3, lookup_name( *vals ) ); 
 
1172
                while( *ptr ) {
 
1173
                        *ptr = (char)toupper( *ptr );
 
1174
                        ++ptr;
 
1175
                }
 
1176
                PyConstant_Insert( (BPy_constant *)attr, name, 
 
1177
                                PyInt_FromLong( *vals ) );
 
1178
                ++vals;
 
1179
        }
 
1180
        return attr;
 
1181
}
 
1182
 
 
1183
void generate_curveconsts( PyObject* module )
 
1184
{
 
1185
        namefunc lookup_name = NULL;
 
1186
        int size = 0;
 
1187
        int *vals = NULL;
 
1188
        char name[32];
 
1189
 
 
1190
        unsigned int i = 0;
 
1191
        static short curvelist[] = {
 
1192
                ID_OB, ID_MA, ID_CA, ID_LA, ID_TE, ID_WO, ID_PO, ID_CO, ID_CU, ID_SEQ
 
1193
        };
 
1194
 
 
1195
        for( i = 0; i < sizeof(curvelist)/sizeof(short); ++i ) {
 
1196
                switch ( curvelist[i] ) {
 
1197
                case ID_OB:
 
1198
                        lookup_name = (namefunc)getname_ob_ei;
 
1199
                        vals = ob_ar;
 
1200
                        size = OB_TOTIPO;
 
1201
                        strcpy( name, "OB_" );
 
1202
                        break;
 
1203
                case ID_MA:
 
1204
                        lookup_name = (namefunc)getname_mat_ei;
 
1205
                        vals = ma_ar;
 
1206
                        size = MA_TOTIPO;
 
1207
                        strcpy( name, "MA_" );
 
1208
                        break;
 
1209
                case ID_CA:
 
1210
                        lookup_name = (namefunc)getname_cam_ei;
 
1211
                        vals = cam_ar;
 
1212
                        size = CAM_TOTIPO;
 
1213
                        strcpy( name, "CA_" );
 
1214
                        break;
 
1215
                case ID_LA:
 
1216
                        lookup_name = (namefunc)getname_la_ei;
 
1217
                        vals = la_ar;
 
1218
                        size = LA_TOTIPO;
 
1219
                        strcpy( name, "LA_" );
 
1220
                        break;
 
1221
                case ID_TE:
 
1222
                        lookup_name = (namefunc)getname_tex_ei;
 
1223
                        vals = te_ar;
 
1224
                        size = TE_TOTIPO;
 
1225
                        strcpy( name, "TE_" );
 
1226
                        break;
 
1227
                case ID_WO:
 
1228
                        lookup_name = (namefunc)getname_world_ei;
 
1229
                        vals = wo_ar;
 
1230
                        size = WO_TOTIPO;
 
1231
                        strcpy( name, "WO_" );
 
1232
                        break;
 
1233
                case ID_PO:
 
1234
                        lookup_name = (namefunc)getname_ac_ei;
 
1235
                        vals = ac_ar;
 
1236
                        size = AC_TOTIPO;
 
1237
                        strcpy( name, "PO_" );
 
1238
                        break;
 
1239
                case ID_CO:
 
1240
                        lookup_name = (namefunc)getname_co_ei;
 
1241
                        vals = co_ar;
 
1242
                        size = CO_TOTIPO;
 
1243
                        strcpy( name, "CO_" );
 
1244
                        break;
 
1245
                case ID_CU:
 
1246
                        lookup_name = (namefunc)getname_cu_ei;
 
1247
                        vals = cu_ar;
 
1248
                        size = CU_TOTIPO;
 
1249
                        strcpy( name, "CU_" );
 
1250
                        break;
 
1251
                case ID_SEQ:
 
1252
                        lookup_name = (namefunc)getname_seq_ei;
 
1253
                        vals = seq_ar;
 
1254
                        size = SEQ_TOTIPO;
 
1255
                        strcpy( name, "SQ_" );
 
1256
                        break;
 
1257
                }
 
1258
 
 
1259
                while( size-- ) {
 
1260
                        char *ptr = name+3;
 
1261
                        strcpy( name+3, lookup_name( *vals ) ); 
 
1262
                        while( *ptr ) {
 
1263
                                *ptr = (char)toupper( *ptr );
 
1264
                                ++ptr;
 
1265
                        }
 
1266
                        PyModule_AddIntConstant( module, name, *vals );
 
1267
                        ++vals;
 
1268
                }
 
1269
        }
 
1270
}
 
1271
 
 
1272
 
 
1273
/*
 
1274
 * get the current texture channel number, if defined
 
1275
 */
 
1276
 
 
1277
static PyObject *Ipo_getChannel( BPy_Ipo * self )
 
1278
{
 
1279
        if( self->mtex != -1 )
 
1280
                return Py_BuildValue( "h", self->mtex );
 
1281
        Py_RETURN_NONE;
 
1282
}
 
1283
 
 
1284
/*
 
1285
 * set the current texture channel number, if defined
 
1286
 */
 
1287
 
 
1288
static int Ipo_setChannel( BPy_Ipo * self, PyObject * value )
 
1289
{
 
1290
        if( self->mtex != -1 )
 
1291
                return EXPP_setIValueRange( value, &self->mtex, 0, 9, 'h' );
 
1292
        return 0;
 
1293
}
 
1294
 
 
1295
/*****************************************************************************/
 
1296
/* Function:    Ipo_dealloc                                                  */
 
1297
/* Description: This is a callback function for the BPy_Ipo type. It is      */
 
1298
/*              the destructor function.                                     */
 
1299
/*****************************************************************************/
 
1300
static void Ipo_dealloc( BPy_Ipo * self )
 
1301
{
 
1302
        PyObject_DEL( self );
 
1303
}
 
1304
 
 
1305
/*****************************************************************************/
 
1306
/* Function:    Ipo_repr                                                     */
 
1307
/* Description: This is a callback function for the BPy_Ipo type. It         */
 
1308
/*              builds a meaningful string to represent ipo objects.         */
 
1309
/*****************************************************************************/
 
1310
static PyObject *Ipo_repr( BPy_Ipo * self )
 
1311
{
 
1312
        char *param;
 
1313
 
 
1314
        switch ( self->ipo->blocktype ) {
 
1315
        case ID_OB:
 
1316
                param = "Object"; break;
 
1317
        case ID_CA:
 
1318
                param = "Camera"; break;
 
1319
        case ID_LA:
 
1320
                param = "Lamp"; break;
 
1321
        case ID_TE:
 
1322
                param = "Texture"; break;
 
1323
        case ID_WO:
 
1324
                param = "World"; break;
 
1325
        case ID_MA:
 
1326
                param = "Material"; break;
 
1327
        case ID_PO:
 
1328
                param = "Action"; break;
 
1329
        case ID_CO:
 
1330
                param = "Constriant"; break;
 
1331
        case ID_CU:
 
1332
                param = "Curve"; break;
 
1333
        case ID_SEQ:
 
1334
                param = "Sequence"; break;
 
1335
        case ID_KE:
 
1336
                param = "Key"; break;
 
1337
        default:
 
1338
        return EXPP_ReturnPyObjError( PyExc_RuntimeError, 
 
1339
                                                        "unknown Ipo type" );
 
1340
        }
 
1341
        return PyString_FromFormat( "[Ipo \"%s\" (%s)]", self->ipo->id.name + 2,
 
1342
                                    param );
 
1343
}
 
1344
 
 
1345
/* Three Python Ipo_Type helper functions needed by the Object module: */
 
1346
 
 
1347
/*****************************************************************************/
 
1348
/* Function:    Ipo_CreatePyObject                                           */
 
1349
/* Description: This function will create a new BPy_Ipo from an existing     */
 
1350
/*              Blender ipo structure.                                       */
 
1351
/*****************************************************************************/
 
1352
PyObject *Ipo_CreatePyObject( Ipo * ipo )
 
1353
{
 
1354
        BPy_Ipo *pyipo;
 
1355
        pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
 
1356
        if( !pyipo )
 
1357
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
1358
                                              "couldn't create BPy_Ipo object" );
 
1359
        pyipo->ipo = ipo;
 
1360
        pyipo->iter = 0;
 
1361
        if( pyipo->ipo->blocktype == ID_WO || pyipo->ipo->blocktype == ID_LA ||
 
1362
                        pyipo->ipo->blocktype == ID_MA )
 
1363
                pyipo->mtex = 0;
 
1364
        else
 
1365
                pyipo->mtex = -1;
 
1366
        return ( PyObject * ) pyipo;
 
1367
}
 
1368
 
 
1369
/*****************************************************************************/
 
1370
/* Function:    Ipo_CheckPyObject                                            */
 
1371
/* Description: This function returns true when the given PyObject is of the */
 
1372
/*              type Ipo. Otherwise it will return false.                    */
 
1373
/*****************************************************************************/
 
1374
int Ipo_CheckPyObject( PyObject * pyobj )
 
1375
{
 
1376
        return ( pyobj->ob_type == &Ipo_Type );
 
1377
}
 
1378
 
 
1379
/*****************************************************************************/
 
1380
/* Function:    Ipo_FromPyObject                                             */
 
1381
/* Description: This function returns the Blender ipo from the given         */
 
1382
/*              PyObject.                                                    */
 
1383
/*****************************************************************************/
 
1384
Ipo *Ipo_FromPyObject( PyObject * pyobj )
 
1385
{
 
1386
        return ( ( BPy_Ipo * ) pyobj )->ipo;
 
1387
}
 
1388
 
 
1389
/*****************************************************************************/
 
1390
/* Function:    Ipo_length                                                   */
 
1391
/* Description: This function counts the number of curves accessible for the */
 
1392
/*              PyObject.                                                    */
 
1393
/*****************************************************************************/
 
1394
static int Ipo_length( BPy_Ipo * self )
 
1395
{
 
1396
        IpoCurve *icu;
 
1397
        int len = 0;
 
1398
 
 
1399
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
 
1400
                if( self->mtex == -1 || icu->adrcode < MA_MAP1 ||
 
1401
                                icu->adrcode & texchannel_to_adrcode( self->mtex ) )
 
1402
                        ++len;
 
1403
        }
 
1404
        return len;
 
1405
}
 
1406
 
 
1407
/*
 
1408
 * "mapping" operator getter: return an IpoCurve it we can find it
 
1409
 */
 
1410
 
 
1411
static PyObject *Ipo_getIpoCurveByName( BPy_Ipo * self, PyObject * key )
 
1412
{
 
1413
    IpoCurve *icu = NULL;
 
1414
    int adrcode;
 
1415
 
 
1416
        /* if Ipo is not ShapeKey and arg is an int, look up the adrcode */
 
1417
        if( self->ipo->blocktype != ID_KE && PyNumber_Check( key ) )
 
1418
                adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
 
1419
                                self->ipo->blocktype, self->mtex );
 
1420
        /* if Ipo is ShapeKey and arg is string, look up the adrcode */
 
1421
        else if( self->ipo->blocktype == ID_KE && PyString_Check( key ) ) {
 
1422
                adrcode = lookup_curve_key( PyString_AS_STRING( key ), self->ipo );
 
1423
                if( adrcode == -2 )
 
1424
                        return EXPP_ReturnPyObjError( PyExc_RuntimeError, 
 
1425
                                        "unable to find matching key data for Ipo" );
 
1426
        }
 
1427
        else
 
1428
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1429
                                "expected int or string key" );
 
1430
 
 
1431
        /* if no adrcode found, value error */
 
1432
        if( adrcode == -1 )
 
1433
                return EXPP_ReturnPyObjError( PyExc_KeyError, "invalid curve key" );
 
1434
 
 
1435
        /* search for a matching adrcode */
 
1436
        for( icu = self->ipo->curve.first; icu; icu = icu->next )
 
1437
                if( icu->adrcode == adrcode )
 
1438
                        return IpoCurve_CreatePyObject( icu );
 
1439
 
 
1440
        /* no curve found */
 
1441
    Py_RETURN_NONE;
 
1442
}
 
1443
 
 
1444
/*
 
1445
 * "mapping" operator setter: create or delete an IpoCurve it we can find it
 
1446
 */
 
1447
 
 
1448
static int Ipo_setIpoCurveByName( BPy_Ipo * self, PyObject * key, 
 
1449
                PyObject * arg )
 
1450
{
 
1451
        IpoCurve *icu;
 
1452
        Ipo *ipo = self->ipo;
 
1453
        short adrcode;
 
1454
 
 
1455
        /* "del ipo[const]" will send NULL here; give an error */
 
1456
        if( !arg )
 
1457
                return EXPP_ReturnIntError( PyExc_NotImplementedError,
 
1458
                                "del operator not supported" );
 
1459
 
 
1460
        /* "del ipo[const]" will send NULL here; give an error */
 
1461
        if( self->ipo->blocktype == ID_KE )
 
1462
                return EXPP_ReturnIntError( PyExc_TypeError,
 
1463
                                "creation or deletion of Shape Keys not supported" );
 
1464
 
 
1465
        /* check for int argument */
 
1466
        if( !PyNumber_Check( key ) )
 
1467
                return EXPP_ReturnIntError( PyExc_TypeError, "expected int key" );
 
1468
 
 
1469
        /* look up the key, return error if not found */
 
1470
        adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
 
1471
                        self->ipo->blocktype, self->mtex );
 
1472
 
 
1473
        if( adrcode == -1 )
 
1474
                return EXPP_ReturnIntError( PyExc_KeyError,
 
1475
                                "invalid curve specified" );
 
1476
 
 
1477
        /* if arg is None, delete the curve */
 
1478
        if( arg == Py_None ) {
 
1479
                for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
 
1480
                        if( icu->adrcode == adrcode ) {
 
1481
                                del_ipocurve( ipo, icu );
 
1482
                                return 0;
 
1483
                        }
 
1484
                }
 
1485
 
 
1486
                return EXPP_ReturnIntError( PyExc_ValueError, "IpoCurve not found" );
 
1487
        } else {
 
1488
 
 
1489
        /* create the new ipo curve */
 
1490
                float time, curval;
 
1491
                PyObject *tmp, *flt=NULL, *val=NULL;
 
1492
 
 
1493
                /* error if not a sequence or sequence with other than 2 values */
 
1494
                if( PySequence_Size( arg ) != 2 )
 
1495
                        goto AttrError;
 
1496
 
 
1497
                /* get the time and curval */
 
1498
                tmp = PySequence_ITEM( arg, 0 );
 
1499
                flt = PyNumber_Float( tmp );
 
1500
                Py_DECREF( tmp );
 
1501
                tmp = PySequence_ITEM( arg, 1 );
 
1502
                val = PyNumber_Float( tmp );
 
1503
                Py_DECREF( tmp );
 
1504
 
 
1505
                if( !flt || !val )
 
1506
                        goto AttrError;
 
1507
 
 
1508
                time = (float)PyFloat_AS_DOUBLE( flt );
 
1509
                curval = (float)PyFloat_AS_DOUBLE( val );
 
1510
                Py_DECREF( flt );
 
1511
                Py_DECREF( val );
 
1512
 
 
1513
                /* if curve already exist, delete the original */
 
1514
                for( icu = ipo->curve.first; icu; icu = icu->next )
 
1515
                        if( icu->adrcode == adrcode ) {
 
1516
                                del_ipocurve( ipo, icu );
 
1517
                                break;
 
1518
                        }
 
1519
 
 
1520
                /* create the new curve, then add the key */
 
1521
                icu = MEM_callocN( sizeof(IpoCurve), "Python added ipocurve");
 
1522
                icu->blocktype = ipo->blocktype;
 
1523
                icu->adrcode = adrcode;
 
1524
                icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
 
1525
                set_icu_vars( icu );
 
1526
                BLI_addtail( &(ipo->curve), icu);
 
1527
                insert_vert_ipo( icu, time, curval );
 
1528
 
 
1529
                allspace( REMAKEIPO, 0 );
 
1530
                EXPP_allqueue( REDRAWIPO, 0 );
 
1531
 
 
1532
                return 0; 
 
1533
 
 
1534
AttrError:
 
1535
                Py_XDECREF( val );
 
1536
                Py_XDECREF( flt );
 
1537
                return EXPP_ReturnIntError( PyExc_AttributeError,
 
1538
                                "expected sequence of two floats" );
 
1539
        }
 
1540
 
1541
 
 
1542
/*
 
1543
 * sequence __contains__ method (implements "x in ipo")
 
1544
 */
 
1545
 
 
1546
static int Ipo_contains( BPy_Ipo *self, PyObject *key )
 
1547
{
 
1548
    IpoCurve *icu = NULL;
 
1549
    int adrcode;
 
1550
 
 
1551
        /* take a Ipo curve name: key must be a int */ 
 
1552
 
 
1553
        if( self->ipo->blocktype != ID_KE && PyNumber_Check( key ) ) {
 
1554
                adrcode = lookup_curve_adrcode( PyInt_AsLong( key ),
 
1555
                        self->ipo->blocktype, self->mtex );
 
1556
 
 
1557
                /* if we found an adrcode for the key, search the ipo's curve */
 
1558
                if( adrcode != -1 ) {
 
1559
                        for( icu = self->ipo->curve.first; icu; icu = icu->next )
 
1560
                                if( icu->adrcode == adrcode )
 
1561
                                        return 1;
 
1562
                }
 
1563
        } else if( self->ipo->blocktype == ID_KE && PyString_Check( key ) ) {
 
1564
                adrcode = lookup_curve_key( PyString_AS_STRING( key ), self->ipo );
 
1565
 
 
1566
                /* if we found an adrcode for the key, search the ipo's curve */
 
1567
                if( adrcode >= 0 ) {
 
1568
                        for( icu = self->ipo->curve.first; icu; icu = icu->next )
 
1569
                                if( icu->adrcode == adrcode )
 
1570
                                        return 1;
 
1571
                }
 
1572
        } 
 
1573
 
 
1574
        /* no curve found */
 
1575
    return 0;
 
1576
}
 
1577
 
 
1578
/*
 
1579
 * Initialize the interator index
 
1580
 */
 
1581
 
 
1582
static PyObject *Ipo_getIter( BPy_Ipo * self )
 
1583
{
 
1584
        self->iter = 0;
 
1585
        return EXPP_incr_ret ( (PyObject *) self );
 
1586
}
 
1587
 
 
1588
/*
 
1589
 * Get the next Ipo curve
 
1590
 */
 
1591
 
 
1592
static PyObject *Ipo_nextIter( BPy_Ipo * self )
 
1593
{
 
1594
        int i;
 
1595
        IpoCurve *icu = self->ipo->curve.first;
 
1596
 
 
1597
        ++self->iter;
 
1598
 
 
1599
                /*
 
1600
                 * count curves only if 
 
1601
                 * (a) Ipo has no texture channels
 
1602
                 * (b) Ipo has texture channels, but curve is not that type
 
1603
                 * (c) Ipo has texture channels, and curve is that type, and it is
 
1604
                 *    in the active texture channel
 
1605
                 */
 
1606
        for( i = 0; icu; icu = icu->next ) {
 
1607
                if( self->mtex == -1 || icu->adrcode < MA_MAP1 ||
 
1608
                                icu->adrcode & texchannel_to_adrcode( self->mtex ) ) {
 
1609
                        ++i;
 
1610
 
 
1611
                        /* if indices match, return the curve */
 
1612
                        if( i == self->iter )
 
1613
                                return IpoCurve_CreatePyObject( icu );
 
1614
                }
 
1615
        }
 
1616
 
 
1617
        /* ran out of curves */
 
1618
        return EXPP_ReturnPyObjError( PyExc_StopIteration,
 
1619
                        "iterator at end" );
 
1620
}
 
1621
 
 
1622
/*****************************************************************************/
 
1623
/* Function:              Ipo_Init                                           */
 
1624
/*****************************************************************************/
 
1625
PyObject *Ipo_Init( void )
 
1626
{
 
1627
        // PyObject *submodule;
 
1628
 
 
1629
        if( PyType_Ready( &Ipo_Type ) < 0 )
 
1630
                return NULL;
 
1631
 
 
1632
        submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
 
1633
        generate_curveconsts( submodule );
 
1634
 
 
1635
        return submodule;
 
1636
}
 
1637
 
 
1638
/*
 
1639
 * The following methods should be deprecated when there are equivalent
 
1640
 * methods in Ipocurve (if there aren't already).
 
1641
 */
1011
1642
 
1012
1643
static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
1013
1644
{
1014
 
        int num = 0, i = 0;
1015
 
        IpoCurve *icu = 0;
 
1645
        int num = 0;
 
1646
        IpoCurve *icu = NULL;
 
1647
 
1016
1648
        if( !PyArg_ParseTuple( args, "i", &num ) )
1017
 
                return ( EXPP_ReturnPyObjError
1018
 
                         ( PyExc_TypeError, "expected int argument" ) );
 
1649
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1650
                                "expected int argument" );
 
1651
 
1019
1652
        icu = self->ipo->curve.first;
1020
 
        if( !icu )
1021
 
                return ( EXPP_ReturnPyObjError
1022
 
                         ( PyExc_TypeError, "No IPO curve" ) );
1023
 
        for( i = 0; i < num; i++ ) {
1024
 
                if( !icu )
1025
 
                        return ( EXPP_ReturnPyObjError
1026
 
                                 ( PyExc_TypeError, "Bad curve number" ) );
 
1653
        while( icu && num > 0 ) {
1027
1654
                icu = icu->next;
1028
 
 
 
1655
                --num;
1029
1656
        }
1030
 
        return ( PyInt_FromLong( icu->totvert ) );
 
1657
 
 
1658
        if( num < 0 && !icu )
 
1659
                return EXPP_ReturnPyObjError( PyExc_IndexError,
 
1660
                                "index out of range" );
 
1661
 
 
1662
        return PyInt_FromLong( icu->totvert );
1031
1663
}
1032
1664
 
1033
1665
static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
1052
1684
        return ( PyInt_FromLong( icu->totvert ) );
1053
1685
}
1054
1686
 
1055
 
 
1056
1687
/*
1057
1688
 * Ipo_getCurveBP()
1058
1689
 * this method is UNSUPPORTED.
1063
1694
 * implemented.
1064
1695
 */
1065
1696
 
1066
 
static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
 
1697
static PyObject *Ipo_getCurveBP( BPy_Ipo * self_unused, PyObject * args_unused )
1067
1698
{
1068
 
 
1069
 
        /* unsupported method */
1070
1699
        return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
1071
1700
                                      "bpoint ipos are not supported" );
1072
 
 
1073
 
#if 0
1074
 
 
1075
 
        struct BPoint *ptrbpoint;
1076
 
        int num = 0, i;
1077
 
        IpoCurve *icu;
1078
 
        PyObject *l;
1079
 
 
1080
 
        if( !PyArg_ParseTuple( args, "i", &num ) )
1081
 
                return ( EXPP_ReturnPyObjError
1082
 
                         ( PyExc_TypeError, "expected int argument" ) );
1083
 
        icu = self->ipo->curve.first;
1084
 
        if( !icu )
1085
 
                return ( EXPP_ReturnPyObjError
1086
 
                         ( PyExc_TypeError, "No IPO curve" ) );
1087
 
        for( i = 0; i < num; i++ ) {
1088
 
                if( !icu )
1089
 
                        return ( EXPP_ReturnPyObjError
1090
 
                                 ( PyExc_TypeError, "Bad curve number" ) );
1091
 
                icu = icu->next;
1092
 
 
1093
 
        }
1094
 
        ptrbpoint = icu->bp;
1095
 
        if( !ptrbpoint )
1096
 
                return EXPP_ReturnPyObjError( PyExc_TypeError,
1097
 
                                              "No base point" );
1098
 
 
1099
 
        l = PyList_New( 0 );
1100
 
        for( i = 0; i < 4; i++ )
1101
 
                PyList_Append( l, PyFloat_FromDouble( ptrbpoint->vec[i] ) );
1102
 
        return l;
1103
 
#endif
1104
1701
}
1105
1702
 
1106
1703
static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args )
1140
1737
        return l;
1141
1738
}
1142
1739
 
1143
 
 
1144
1740
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
1145
1741
{
1146
1742
        struct BezTriple *ptrbt;
1183
1779
        return Py_None;
1184
1780
}
1185
1781
 
1186
 
 
1187
1782
static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
1188
1783
{
1189
 
        float eval_icu( IpoCurve * icu, float ipotime );
1190
 
 
1191
1784
        int num = 0, i;
1192
1785
        IpoCurve *icu;
1193
1786
        float time = 0;
1211
1804
        return PyFloat_FromDouble( eval_icu( icu, time ) );
1212
1805
}
1213
1806
 
1214
 
 
1215
1807
static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
1216
1808
{
1217
1809
        int numcurve = 0, i;
1223
1815
                return ( EXPP_ReturnPyObjError
1224
1816
                         ( PyExc_TypeError, "No IPO curve" ) );
1225
1817
 
1226
 
        if( PyNumber_Check( PySequence_GetItem( args, 0 ) ) )   // args is an integer
 
1818
        if( PyNumber_Check( PyTuple_GetItem( args, 0 ) ) )      // args is an integer
1227
1819
        {
1228
1820
                if( !PyArg_ParseTuple( args, "i", &numcurve ) )
1229
1821
                        return ( EXPP_ReturnPyObjError
1258
1850
        return Py_None;
1259
1851
}
1260
1852
 
1261
 
 
1262
 
/*****************************************************************************/
1263
 
/* Function:    IpoDeAlloc                                                   */
1264
 
/* Description: This is a callback function for the BPy_Ipo type. It is        */
1265
 
/*              the destructor function.                                     */
1266
 
/*****************************************************************************/
1267
 
static void IpoDeAlloc( BPy_Ipo * self )
1268
 
{
1269
 
        PyObject_DEL( self );
1270
 
}
1271
 
 
1272
 
/*****************************************************************************/
1273
 
/* Function:    IpoGetAttr                                                   */
1274
 
/* Description: This is a callback function for the BPy_Ipo type. It is        */
1275
 
/*              the function that accesses BPy_Ipo "member variables" and      */
1276
 
/*              methods.                                                     */
1277
 
/*****************************************************************************/
1278
 
static PyObject *IpoGetAttr( BPy_Ipo * self, char *name )
1279
 
{
1280
 
        if( strcmp( name, "curves" ) == 0 )
1281
 
                return Ipo_getCurves( self );
1282
 
        return Py_FindMethod( BPy_Ipo_methods, ( PyObject * ) self, name );
1283
 
}
1284
 
 
1285
 
/*****************************************************************************/
1286
 
/* Function:    IpoSetAttr                                                */
1287
 
/* Description: This is a callback function for the BPy_Ipo type. It is the */
1288
 
/*              function that sets Ipo Data attributes (member variables).*/
1289
 
/*****************************************************************************/
1290
 
static int IpoSetAttr( BPy_Ipo * self, char *name, PyObject * value )
1291
 
{
1292
 
        return 0;               /* normal exit */
1293
 
}
1294
 
 
1295
 
/*****************************************************************************/
1296
 
/* Function:    IpoRepr                                                      */
1297
 
/* Description: This is a callback function for the BPy_Ipo type. It           */
1298
 
/*              builds a meaninful string to represent ipo objects.          */
1299
 
/*****************************************************************************/
1300
 
static PyObject *IpoRepr( BPy_Ipo * self )
1301
 
{
1302
 
        return PyString_FromFormat( "[Ipo \"%s\" %d]", self->ipo->id.name + 2,
1303
 
                                    self->ipo->blocktype );
1304
 
}
1305
 
 
1306
 
/* Three Python Ipo_Type helper functions needed by the Object module: */
1307
 
 
1308
 
/*****************************************************************************/
1309
 
/* Function:    Ipo_CreatePyObject                                           */
1310
 
/* Description: This function will create a new BPy_Ipo from an existing       */
1311
 
/*              Blender ipo structure.                                       */
1312
 
/*****************************************************************************/
1313
 
PyObject *Ipo_CreatePyObject( Ipo * ipo )
1314
 
{
1315
 
        BPy_Ipo *pyipo;
1316
 
        pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
1317
 
        if( !pyipo )
1318
 
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
1319
 
                                              "couldn't create BPy_Ipo object" );
1320
 
        pyipo->ipo = ipo;
1321
 
        return ( PyObject * ) pyipo;
1322
 
}
1323
 
 
1324
 
/*****************************************************************************/
1325
 
/* Function:    Ipo_CheckPyObject                                            */
1326
 
/* Description: This function returns true when the given PyObject is of the */
1327
 
/*              type Ipo. Otherwise it will return false.                    */
1328
 
/*****************************************************************************/
1329
 
int Ipo_CheckPyObject( PyObject * pyobj )
1330
 
{
1331
 
        return ( pyobj->ob_type == &Ipo_Type );
1332
 
}
1333
 
 
1334
 
/*****************************************************************************/
1335
 
/* Function:    Ipo_FromPyObject                                             */
1336
 
/* Description: This function returns the Blender ipo from the given         */
1337
 
/*              PyObject.                                                    */
1338
 
/*****************************************************************************/
1339
 
Ipo *Ipo_FromPyObject( PyObject * pyobj )
1340
 
{
1341
 
        return ( ( BPy_Ipo * ) pyobj )->ipo;
 
1853
/*
 
1854
 * The following methods should be deprecated when methods are pruned out.
 
1855
 */
 
1856
 
 
1857
static PyObject *Ipo_oldsetRctf( BPy_Ipo * self, PyObject * args )
 
1858
{
 
1859
        return EXPP_setterWrapperTuple( (void *)self, args,
 
1860
                        (setter)Ipo_setRctf );
 
1861
}
 
1862
 
 
1863
static PyObject *Ipo_oldsetName( BPy_Ipo * self, PyObject * args )
 
1864
{
 
1865
        return EXPP_setterWrapperTuple( (void *)self, args,
 
1866
                        (setter)Ipo_setName );
 
1867
}
 
1868
 
 
1869
static PyObject *Ipo_oldsetBlocktype( BPy_Ipo * self, PyObject * args )
 
1870
{
 
1871
        return EXPP_setterWrapperTuple( (void *)self, args,
 
1872
                        (setter)Ipo_setBlocktype );
1342
1873
}