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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * $Id: Key.c,v 1.12 2007/01/16 05:20:39 stiv Exp $
 
2
 * $Id: Key.c,v 1.17 2007/03/29 03:47:50 khughes Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
31
31
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
32
32
 */
33
33
 
 
34
#include "Key.h" /*This must come first*/
 
35
 
34
36
#include "DNA_scene_types.h"
35
37
 
36
38
#include <BLI_blenlib.h>
41
43
#include "BIF_space.h"
42
44
 
43
45
#include "Ipocurve.h"
44
 
#include "Key.h"
45
46
#include "NMesh.h" /* we create NMesh.NMVert objects */
46
47
#include "Ipo.h"
47
48
#include "BezTriple.h"
52
53
#include "blendef.h"
53
54
#include "constant.h"
54
55
#include "gen_utils.h"
 
56
#include "gen_library.h"
55
57
 
56
58
#define KEY_TYPE_MESH    0
57
59
#define KEY_TYPE_CURVE   1
60
62
/* macro from blenkernel/intern/key.c:98 */
61
63
#define GS(a)   (*((short *)(a)))
62
64
 
63
 
static void Key_dealloc( PyObject * self );
64
 
static void KeyBlock_dealloc( PyObject * self );
65
65
static int Key_compare( BPy_Key * a, BPy_Key * b );
66
66
static PyObject *Key_repr( BPy_Key * self );
67
67
 
68
 
static PyObject *Key_getBlocks( PyObject * self );
 
68
static PyObject *Key_getBlocks( BPy_Key * self );
69
69
static PyObject *Key_getType( BPy_Key * self );
70
70
static PyObject *Key_getRelative( BPy_Key * self );
71
 
static PyObject *Key_getIpo( PyObject * self );
72
 
static int Key_setIpo( PyObject * self, PyObject * args );
73
 
static PyObject *Key_getValue( PyObject * self );
 
71
static PyObject *Key_getIpo( BPy_Key * self );
 
72
static int Key_setIpo( BPy_Key * self, PyObject * args );
 
73
static PyObject *Key_getValue( BPy_Key * self );
74
74
static int Key_setRelative( BPy_Key * self, PyObject * value );
75
75
 
76
76
static struct PyMethodDef Key_methods[] = {
136
136
        sizeof( BPy_Key ),                              /*tp_basicsize */
137
137
        0,                                                              /*tp_itemsize */
138
138
        /* methods */
139
 
        ( destructor ) Key_dealloc,             /*tp_dealloc */
 
139
        NULL,                                                   /*tp_dealloc */
140
140
        ( printfunc ) 0,                                /*tp_print */
141
141
        ( getattrfunc ) 0,      /*tp_getattr */
142
142
        ( setattrfunc ) 0,                              /*tp_setattr */
150
150
 
151
151
        /* More standard operations (here for binary compatibility) */
152
152
 
153
 
        NULL,                       /* hashfunc tp_hash; */
 
153
        ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
154
154
        NULL,                       /* ternaryfunc tp_call; */
155
155
        NULL,                       /* reprfunc tp_str; */
156
156
        NULL,                       /* getattrofunc tp_getattro; */
213
213
        sizeof( BPy_KeyBlock ), /*tp_basicsize */
214
214
        0,                      /*tp_itemsize */
215
215
        /* methods */
216
 
        ( destructor ) KeyBlock_dealloc,        /*tp_dealloc */
 
216
        NULL,                           /*tp_dealloc */
217
217
        NULL,                           /*tp_print */
218
218
        NULL,                           /*tp_getattr */
219
219
        NULL,                           /*tp_setattr */
284
284
        NULL
285
285
};
286
286
 
287
 
static void Key_dealloc( PyObject * self )
288
 
{
289
 
        PyObject_DEL( self );
290
 
}
291
 
 
292
287
static PyObject *new_Key(Key * oldkey)
293
288
{
294
289
        BPy_Key *k = PyObject_NEW( BPy_Key, &Key_Type );
319
314
        return PyString_FromFormat( "[Key \"%s\"]", self->key->id.name + 2 );
320
315
}
321
316
 
322
 
static PyObject *Key_getIpo( PyObject * self )
 
317
static PyObject *Key_getIpo( BPy_Key * self )
323
318
{
324
 
        BPy_Key *k = ( BPy_Key * ) self;
325
319
        BPy_Ipo *new_ipo;
326
320
 
327
 
        if (k->key->ipo) {
 
321
        if (self->key->ipo) {
328
322
                new_ipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
329
 
                new_ipo->ipo = k->key->ipo;
 
323
                new_ipo->ipo = self->key->ipo;
330
324
                return (PyObject *) new_ipo;
331
325
        } else {
332
 
                return EXPP_incr_ret( Py_None );
 
326
                Py_RETURN_NONE;
333
327
        }
334
328
}
335
329
 
336
 
static int Key_setIpo( PyObject * self, PyObject * value )
 
330
static int Key_setIpo( BPy_Key * self, PyObject * value )
337
331
{
338
 
        Ipo *ipo = NULL;
339
 
        Ipo *oldipo = (( BPy_Key * )self)->key->ipo;
340
 
        ID *id;
341
 
 
342
 
        /* if parameter is not None, check for valid Ipo */
343
 
 
344
 
        if ( value != Py_None ) {
345
 
                if ( !Ipo_CheckPyObject( value ) )
346
 
                        return EXPP_ReturnIntError( PyExc_RuntimeError,
347
 
                                                "expected an Ipo object" );
348
 
 
349
 
                ipo = Ipo_FromPyObject( value );
350
 
 
351
 
                if( !ipo )
352
 
                        return EXPP_ReturnIntError( PyExc_RuntimeError,
353
 
                                                "null ipo!" );
354
 
 
355
 
                if( ipo->blocktype != ID_KE )
356
 
                        return EXPP_ReturnIntError( PyExc_TypeError,
357
 
                                                "Ipo is not a key data Ipo" );
358
 
        }
359
 
 
360
 
        /* if already linked to Ipo, delete link */
361
 
 
362
 
        if ( oldipo ) {
363
 
                id = &oldipo->id;
364
 
                if( id->us > 0 )
365
 
                        id->us--;
366
 
        }
367
 
 
368
 
        /* assign new Ipo and increment user count, or set to NULL if deleting */
369
 
 
370
 
        (( BPy_Key * )self)->key->ipo = ipo;
371
 
        if ( ipo ) {
372
 
                id = &ipo->id;
373
 
                id_us_plus(id);
374
 
        }
375
 
 
376
 
        return 0;
 
332
        return GenericLib_assignData(value, (void **) &self->key->ipo, 0, 1, ID_IP, ID_KE);
377
333
}
378
334
 
379
335
static PyObject *Key_getRelative( BPy_Key * self )
380
336
{
381
337
        if( self->key->type == KEY_RELATIVE )
382
 
                return EXPP_incr_ret(Py_True);
 
338
                Py_RETURN_TRUE;
383
339
        else
384
 
                return EXPP_incr_ret(Py_False);
 
340
                Py_RETURN_FALSE;
385
341
}
386
342
 
387
343
static int Key_setRelative( BPy_Key * self, PyObject * value )
418
374
        return PyInt_FromLong( type );
419
375
}
420
376
 
421
 
static PyObject *Key_getBlocks( PyObject * self )
 
377
static PyObject *Key_getBlocks( BPy_Key * self )
422
378
{
423
 
        BPy_Key *k = ( BPy_Key * ) self;
424
 
        Key *key = k->key;
 
379
        Key *key = self->key;
425
380
        KeyBlock *kb;
426
381
        PyObject *keyblock_object;
427
382
        PyObject *l = PyList_New( 0 );
428
383
 
429
384
        for (kb = key->block.first; kb; kb = kb->next) {
430
 
                
431
385
                keyblock_object =  KeyBlock_CreatePyObject( kb, key );
432
386
                PyList_Append( l, keyblock_object );
433
387
        }
435
389
        return l;
436
390
}
437
391
 
438
 
static PyObject *Key_getValue( PyObject * self )
 
392
static PyObject *Key_getValue( BPy_Key * self )
439
393
{
440
394
        BPy_Key *k = ( BPy_Key * ) self;
441
395
 
444
398
 
445
399
/* ------------ Key Block Functions -------------- */
446
400
 
447
 
static void KeyBlock_dealloc( PyObject * self )
448
 
{
449
 
        PyObject_DEL( self );
450
 
}
451
 
 
452
401
static PyObject *new_KeyBlock( KeyBlock * oldkeyBlock, Key *parentKey)
453
402
{
454
403
        BPy_KeyBlock *kb = PyObject_NEW( BPy_KeyBlock, &KeyBlock_Type );