~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
2
 
 * $Id: NLA.c,v 1.16 2006/07/22 14:22:03 campbellbarton Exp $
 
2
 * $Id: NLA.c 14444 2008-04-16 22:40:48Z hos $
3
3
 *
4
 
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
 
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or
7
7
 * modify it under the terms of the GNU General Public License
8
8
 * as published by the Free Software Foundation; either version 2
9
 
 * of the License, or (at your option) any later version. The Blender
10
 
 * Foundation also sells licenses for use in proprietary software under
11
 
 * the Blender License.  See http://www.blender.org/BL/ for information
12
 
 * about this.
 
9
 * of the License, or (at your option) any later version.
13
10
 *
14
11
 * This program is distributed in the hope that it will be useful,
15
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
24
 *
28
25
 * Contributor(s): Joseph Gilbert
29
26
 *
30
 
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
 
27
 * ***** END GPL LICENSE BLOCK *****
31
28
*/
32
29
 
33
30
#include "NLA.h" /*This must come first*/
43
40
#include "Object.h"
44
41
#include "Ipo.h"
45
42
#include "gen_utils.h"
 
43
#include "gen_library.h"
46
44
#include "blendef.h"
47
45
#include "MEM_guardedalloc.h"
48
46
 
84
82
/*****************************************************************************/
85
83
/* Python BPy_Action methods declarations:                              */
86
84
/*****************************************************************************/
87
 
static PyObject *Action_getName( BPy_Action * self );
88
 
static PyObject *Action_setName( BPy_Action * self, PyObject * args );
89
85
static PyObject *Action_setActive( BPy_Action * self, PyObject * args );
90
86
static PyObject *Action_getFrameNumbers(BPy_Action *self);
91
 
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args );
92
 
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * args );
93
 
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args );
 
87
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * value );
 
88
static PyObject *Action_getChannelNames( BPy_Action * self );
 
89
static PyObject *Action_renameChannel( BPy_Action * self, PyObject * args );
 
90
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * value );
 
91
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * value );
94
92
static PyObject *Action_getAllChannelIpos( BPy_Action * self );
95
93
 
96
94
/*****************************************************************************/
98
96
/*****************************************************************************/
99
97
static PyMethodDef BPy_Action_methods[] = {
100
98
        /* name, method, flags, doc */
101
 
        {"getName", ( PyCFunction ) Action_getName, METH_NOARGS,
 
99
        {"getName", ( PyCFunction ) GenericLib_getName, METH_NOARGS,
102
100
         "() - return Action name"},
103
 
        {"setName", ( PyCFunction ) Action_setName, METH_VARARGS,
 
101
        {"setName", ( PyCFunction ) GenericLib_setName_with_method, METH_VARARGS,
104
102
         "(str) - rename Action"},
105
103
        {"setActive", ( PyCFunction ) Action_setActive, METH_VARARGS,
106
104
         "(str) -set this action as the active action for an object"},
107
105
        {"getFrameNumbers", (PyCFunction) Action_getFrameNumbers, METH_NOARGS,
108
106
        "() - get the frame numbers at which keys have been inserted"},
109
 
        {"getChannelIpo", ( PyCFunction ) Action_getChannelIpo, METH_VARARGS,
 
107
        {"getChannelIpo", ( PyCFunction ) Action_getChannelIpo, METH_O,
110
108
         "(str) -get the Ipo from a named action channel in this action"},
111
 
        {"verifyChannel", ( PyCFunction ) Action_verifyChannel, METH_VARARGS,
 
109
        {"getChannelNames", ( PyCFunction ) Action_getChannelNames, METH_NOARGS,
 
110
         "() -get the channel names for this action"},
 
111
         {"renameChannel", ( PyCFunction ) Action_renameChannel, METH_VARARGS,
 
112
                 "(from, to) -rename the channel from string to string"},
 
113
        {"verifyChannel", ( PyCFunction ) Action_verifyChannel, METH_O,
112
114
         "(str) -verify the channel in this action"},
113
 
        {"removeChannel", ( PyCFunction ) Action_removeChannel, METH_VARARGS,
 
115
        {"removeChannel", ( PyCFunction ) Action_removeChannel, METH_O,
114
116
         "(str) -remove the channel from the action"},
115
117
        {"getAllChannelIpos", ( PyCFunction ) Action_getAllChannelIpos,
116
118
         METH_NOARGS,
121
123
/*****************************************************************************/
122
124
/* Python TypeAction callback function prototypes:                          */
123
125
/*****************************************************************************/
124
 
static void Action_dealloc( BPy_Action * bone );
125
 
static PyObject *Action_getAttr( BPy_Action * bone, char *name );
126
 
static int Action_setAttr( BPy_Action * bone, char *name, PyObject * v );
 
126
static int Action_compare( BPy_Action * a, BPy_Action * b );
127
127
static PyObject *Action_repr( BPy_Action * bone );
128
128
 
129
 
/*****************************************************************************/
130
 
/* Python TypeAction structure definition:                               */
131
 
/*****************************************************************************/
132
 
PyTypeObject Action_Type = {
133
 
        PyObject_HEAD_INIT( NULL ) 
134
 
        0,      /* ob_size */
135
 
        "Blender Action",       /* tp_name */
136
 
        sizeof( BPy_Action ),   /* tp_basicsize */
137
 
        0,                      /* tp_itemsize */
138
 
        /* methods */
139
 
        ( destructor ) Action_dealloc,  /* tp_dealloc */
140
 
        0,                      /* tp_print */
141
 
        ( getattrfunc ) Action_getAttr, /* tp_getattr */
142
 
        ( setattrfunc ) Action_setAttr, /* tp_setattr */
143
 
        0,                      /* tp_compare */
144
 
        ( reprfunc ) Action_repr,       /* tp_repr */
145
 
        0,                      /* tp_as_number */
146
 
        0,                      /* tp_as_sequence */
147
 
        0,                      /* tp_as_mapping */
148
 
        0,                      /* tp_as_hash */
149
 
        0, 0, 0, 0, 0, 0,
150
 
        0,                      /* tp_doc */
151
 
        0, 0, 0, 0, 0, 0,
152
 
        BPy_Action_methods,     /* tp_methods */
153
 
        0,                      /* tp_members */
154
 
};
155
 
 
156
129
/*-------------------------------------------------------------------------*/
157
130
static PyObject *M_NLA_NewAction( PyObject * self_unused, PyObject * args )
158
131
{
235
208
        return dict;
236
209
}
237
210
 
238
 
 
239
 
/*----------------------------------------------------------------------*/
240
 
static PyObject *Action_getName( BPy_Action * self )
241
 
{
242
 
        PyObject *attr = NULL;
243
 
 
244
 
        if( !self->action )
245
 
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
246
 
                                         "couldn't get attribute from a NULL action" ) );
247
 
 
248
 
        attr = PyString_FromString( self->action->id.name + 2 );
249
 
 
250
 
        if( attr )
251
 
                return attr;
252
 
 
253
 
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
254
 
                                        "couldn't get Action.name attribute" ) );
255
 
}
256
 
 
257
 
/*----------------------------------------------------------------------*/
258
 
static PyObject *Action_setName( BPy_Action * self, PyObject * args )
259
 
{
260
 
        char *name;
261
 
        char buf[21];
262
 
 
263
 
        if( !self->action )
264
 
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
265
 
                                         "couldn't get attribute from a NULL action" ) );
266
 
 
267
 
        if( !PyArg_ParseTuple( args, "s", &name ) )
268
 
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
269
 
                                                "expected string argument" ) );
270
 
 
271
 
        /*change name*/
272
 
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
273
 
        rename_id( &self->action->id, buf);
274
 
 
275
 
        Py_RETURN_NONE;
276
 
}
277
 
 
278
211
static PyObject *Action_getFrameNumbers(BPy_Action *self)
279
212
{
280
213
        bActionChannel *achan = NULL;
285
218
        
286
219
        py_list = PyList_New(0);
287
220
        for(achan = self->action->chanbase.first; achan; achan = achan->next){
288
 
                for (icu = achan->ipo->curve.first; icu; icu = icu->next){
289
 
                        bezt= icu->bezt;
290
 
                        if(bezt) {
291
 
                                verts = icu->totvert;
292
 
                                while(verts--) {
293
 
                                        PyObject *value;
294
 
                                        value = PyInt_FromLong((int)bezt->vec[1][0]);
295
 
                                        if ( PySequence_Contains(py_list, value) == 0){
296
 
                                                PyList_Append(py_list, value);
 
221
                if (achan->ipo) {
 
222
                        for (icu = achan->ipo->curve.first; icu; icu = icu->next){
 
223
                                bezt= icu->bezt;
 
224
                                if(bezt) {
 
225
                                        verts = icu->totvert;
 
226
                                        while(verts--) {
 
227
                                                PyObject *value;
 
228
                                                value = PyInt_FromLong((int)bezt->vec[1][0]);
 
229
                                                if ( PySequence_Contains(py_list, value) == 0){
 
230
                                                        PyList_Append(py_list, value);
 
231
                                                }
 
232
                                                Py_DECREF(value);
 
233
                                                bezt++;
297
234
                                        }
298
 
                                        Py_DECREF(value);
299
 
                                        bezt++;
300
235
                                }
301
236
                        }
302
237
                }
332
267
        Py_RETURN_NONE;
333
268
}
334
269
 
335
 
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args )
 
270
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * value )
336
271
{
337
 
        char *chanName;
 
272
        char *chanName = PyString_AsString(value);
338
273
        bActionChannel *chan;
339
274
 
340
 
        if( !PyArg_ParseTuple( args, "s", &chanName ) )
 
275
        if( !chanName )
341
276
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
342
277
                                       "string expected" );
343
278
 
353
288
        return Ipo_CreatePyObject( chan->ipo );
354
289
}
355
290
 
 
291
static PyObject *Action_getChannelNames( BPy_Action * self )
 
292
{
 
293
        PyObject *list = PyList_New( BLI_countlist(&(self->action->chanbase)) );
 
294
        bActionChannel *chan = NULL;
 
295
        int index=0;
 
296
        for( chan = self->action->chanbase.first; chan; chan = chan->next ) {
 
297
                PyList_SetItem( list, index, PyString_FromString(chan->name) );
 
298
                index++;
 
299
        }
 
300
        return list;
 
301
}
 
302
 
 
303
static PyObject *Action_renameChannel( BPy_Action * self, PyObject * args )
 
304
{
 
305
        char *chanFrom, *chanTo;
 
306
        bActionChannel *chan;
 
307
 
 
308
        if( !PyArg_ParseTuple( args, "ss", &chanFrom, &chanTo ) )
 
309
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
310
                                       "2 strings expected" );
 
311
        
 
312
        chan = get_action_channel( self->action, chanFrom );
 
313
        if( !chan )
 
314
                return EXPP_ReturnPyObjError( PyExc_ValueError,
 
315
                                "no channel with that name" );
 
316
        if (strlen(chanTo) > 31)
 
317
                return EXPP_ReturnPyObjError( PyExc_ValueError,
 
318
                                "new name greater then 31 characters long" );
 
319
        
 
320
        if (get_action_channel( self->action, chanTo ))
 
321
                return EXPP_ReturnPyObjError( PyExc_ValueError,
 
322
                                "channel target name alredy exists" );
 
323
        
 
324
        strcpy(chan->name, chanTo);
 
325
        
 
326
        Py_RETURN_NONE;
 
327
}
 
328
 
356
329
/*----------------------------------------------------------------------*/
357
 
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * args )
 
330
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * value )
358
331
{
359
 
        char *chanName;
 
332
        char *chanName = PyString_AsString(value);
360
333
        bActionChannel *chan;
361
334
 
362
335
        if( !self->action )
363
336
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
364
337
                                         "couldn't create channel for a NULL action" ) );
365
338
 
366
 
        if( !PyArg_ParseTuple( args, "s", &chanName ) )
 
339
        if( !chanName )
367
340
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
368
341
                                                "expected string argument" ) );
369
342
 
370
343
        chan = verify_action_channel(self->action, chanName);
371
344
 
372
 
        Py_INCREF( Py_None );
373
 
        return Py_None;
 
345
        Py_RETURN_NONE;
374
346
}
375
347
 
376
348
 
377
 
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args )
 
349
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * value )
378
350
{
379
 
        char *chanName;
 
351
        char *chanName = PyString_AsString(value);
380
352
        bActionChannel *chan;
381
353
 
382
 
        if( !PyArg_ParseTuple( args, "s", &chanName ) ) {
383
 
                EXPP_ReturnPyObjError( PyExc_AttributeError,
384
 
                                       "string expected" );
385
 
                return NULL;
386
 
        }
 
354
        if( !chanName )
 
355
                return (EXPP_ReturnPyObjError( PyExc_AttributeError,
 
356
                                       "string expected" ));
 
357
 
387
358
 
388
359
        chan = get_action_channel( self->action, chanName );
389
360
        if( chan == NULL ) {
398
369
        /*remove channel*/
399
370
        BLI_freelinkN( &self->action->chanbase, chan );
400
371
 
401
 
        Py_INCREF( Py_None );
402
 
        return ( Py_None );
 
372
        Py_RETURN_NONE;
403
373
}
404
374
 
405
375
static PyObject *Action_getAllChannelIpos( BPy_Action * self )
437
407
}
438
408
 
439
409
/*----------------------------------------------------------------------*/
440
 
static void Action_dealloc( BPy_Action * self )
441
 
{
442
 
        PyObject_DEL( self );
443
 
}
444
 
 
445
 
/*----------------------------------------------------------------------*/
446
 
static PyObject *Action_getAttr( BPy_Action * self, char *name )
447
 
{
448
 
        PyObject *attr = Py_None;
449
 
 
450
 
        if( strcmp( name, "name" ) == 0 )
451
 
                attr = Action_getName( self );
452
 
        else if( strcmp( name, "__members__" ) == 0 ) {
453
 
                attr = Py_BuildValue( "[s]", "name" );
454
 
        }
455
 
 
456
 
        if( !attr )
457
 
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
458
 
                                                "couldn't create PyObject" ) );
459
 
 
460
 
        if( attr != Py_None )
461
 
                return attr;    /* member attribute found, return it */
462
 
 
463
 
        /* not an attribute, search the methods table */
464
 
        return Py_FindMethod( BPy_Action_methods, ( PyObject * ) self, name );
465
 
}
466
 
 
467
 
/*----------------------------------------------------------------------*/
468
 
static int Action_setAttr( BPy_Action * self, char *name, PyObject * value )
469
 
{
470
 
        PyObject *valtuple;
471
 
        PyObject *error = NULL;
472
 
 
473
 
        valtuple = Py_BuildValue( "(O)", value );       /* the set* functions expect a tuple */
474
 
 
475
 
        if( !valtuple )
476
 
                return EXPP_ReturnIntError( PyExc_MemoryError,
477
 
                                            "ActionSetAttr: couldn't create tuple" );
478
 
 
479
 
        if( strcmp( name, "name" ) == 0 )
480
 
                error = Action_setName( self, valtuple );
481
 
        else {                  /* Error */
482
 
                Py_DECREF( valtuple );
483
 
 
484
 
                /* ... member with the given name was found */
485
 
                return ( EXPP_ReturnIntError
486
 
                         ( PyExc_KeyError, "attribute not found" ) );
487
 
        }
488
 
 
489
 
        Py_DECREF( valtuple );
490
 
 
491
 
        if( error != Py_None )
492
 
                return -1;
493
 
 
494
 
        Py_DECREF( Py_None );   /* was incref'ed by the called Action_set* function */
495
 
        return 0;               /* normal exit */
 
410
static int Action_compare( BPy_Action * a, BPy_Action * b )
 
411
{
 
412
        return ( a->action == b->action ) ? 0 : -1;
496
413
}
497
414
 
498
415
/*----------------------------------------------------------------------*/
510
427
{
511
428
        BPy_Action *blen_action;
512
429
 
513
 
        if(!act)
514
 
                return EXPP_incr_ret(Py_None);
 
430
        if(!act) Py_RETURN_NONE;
515
431
 
516
432
        blen_action =
517
433
                ( BPy_Action * ) PyObject_NEW( BPy_Action, &Action_Type );
525
441
}
526
442
 
527
443
/*----------------------------------------------------------------------*/
528
 
int Action_CheckPyObject( PyObject * py_obj )
529
 
{
530
 
        return ( py_obj->ob_type == &Action_Type );
531
 
}
532
 
 
533
 
/*----------------------------------------------------------------------*/
534
444
struct bAction *Action_FromPyObject( PyObject * py_obj )
535
445
{
536
446
        BPy_Action *blen_obj;
540
450
}
541
451
 
542
452
/*****************************************************************************/
 
453
/* Python attributes get/set structure:                                      */
 
454
/*****************************************************************************/
 
455
static PyGetSetDef BPy_Action_getseters[] = {
 
456
        GENERIC_LIB_GETSETATTR,
 
457
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 
458
};
 
459
 
 
460
/*****************************************************************************/
 
461
/* Python TypeAction structure definition:                                                              */
 
462
/*****************************************************************************/
 
463
PyTypeObject Action_Type = {
 
464
        PyObject_HEAD_INIT( NULL ) 
 
465
        0,      /* ob_size */
 
466
        "Blender Action",       /* tp_name */
 
467
        sizeof( BPy_Action ),   /* tp_basicsize */
 
468
        0,                      /* tp_itemsize */
 
469
        /* methods */
 
470
        NULL,   /* tp_dealloc */
 
471
        NULL,   /* tp_print */
 
472
        NULL,   /* tp_getattr */
 
473
        NULL,   /* tp_setattr */
 
474
        ( cmpfunc ) Action_compare,             /* tp_compare */
 
475
        ( reprfunc ) Action_repr,       /* tp_repr */
 
476
        /* Method suites for standard classes */
 
477
 
 
478
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
479
        NULL,                       /* PySequenceMethods *tp_as_sequence; */
 
480
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
481
 
 
482
        /* More standard operations (here for binary compatibility) */
 
483
 
 
484
        ( hashfunc ) GenericLib_hash,   /* hashfunc tp_hash; */
 
485
        NULL,                       /* ternaryfunc tp_call; */
 
486
        NULL,                       /* reprfunc tp_str; */
 
487
        NULL,                       /* getattrofunc tp_getattro; */
 
488
        NULL,                       /* setattrofunc tp_setattro; */
 
489
 
 
490
        /* Functions to access object as input/output buffer */
 
491
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
492
 
 
493
  /*** Flags to define presence of optional/expanded features ***/
 
494
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
495
 
 
496
        NULL,                       /*  char *tp_doc;  Documentation string */
 
497
  /*** Assigned meaning in release 2.0 ***/
 
498
        /* call function for all accessible objects */
 
499
        NULL,                       /* traverseproc tp_traverse; */
 
500
 
 
501
        /* delete references to contained objects */
 
502
        NULL,                       /* inquiry tp_clear; */
 
503
 
 
504
  /***  Assigned meaning in release 2.1 ***/
 
505
  /*** rich comparisons ***/
 
506
        NULL,                       /* richcmpfunc tp_richcompare; */
 
507
 
 
508
  /***  weak reference enabler ***/
 
509
        0,                          /* long tp_weaklistoffset; */
 
510
 
 
511
  /*** Added in release 2.2 ***/
 
512
        /*   Iterators */
 
513
        NULL,                       /* getiterfunc tp_iter; */
 
514
        NULL,                       /* iternextfunc tp_iternext; */
 
515
 
 
516
  /*** Attribute descriptor and subclassing stuff ***/
 
517
        BPy_Action_methods,           /* struct PyMethodDef *tp_methods; */
 
518
        NULL,                       /* struct PyMemberDef *tp_members; */
 
519
        BPy_Action_getseters,         /* struct PyGetSetDef *tp_getset; */
 
520
        NULL,                       /* struct _typeobject *tp_base; */
 
521
        NULL,                       /* PyObject *tp_dict; */
 
522
        NULL,                       /* descrgetfunc tp_descr_get; */
 
523
        NULL,                       /* descrsetfunc tp_descr_set; */
 
524
        0,                          /* long tp_dictoffset; */
 
525
        NULL,                       /* initproc tp_init; */
 
526
        NULL,                       /* allocfunc tp_alloc; */
 
527
        NULL,                       /* newfunc tp_new; */
 
528
        /*  Low-level free-memory routine */
 
529
        NULL,                       /* freefunc tp_free;  */
 
530
        /* For PyObject_IS_GC */
 
531
        NULL,                       /* inquiry tp_is_gc;  */
 
532
        NULL,                       /* PyObject *tp_bases; */
 
533
        /* method resolution order */
 
534
        NULL,                       /* PyObject *tp_mro;  */
 
535
        NULL,                       /* PyObject *tp_cache; */
 
536
        NULL,                       /* PyObject *tp_subclasses; */
 
537
        NULL,                       /* PyObject *tp_weaklist; */
 
538
        NULL
 
539
};
 
540
 
 
541
 
 
542
 
 
543
/*****************************************************************************/
543
544
/* ActionStrip wrapper                                                       */
544
545
/*****************************************************************************/
545
546
 
712
713
                                "This strip has been removed!" );
713
714
 
714
715
        return EXPP_setFloatClamped( value, &self->strip->repeat,
715
 
                        0.001, 1000.0f );
 
716
                        0.001f, 1000.0f );
716
717
}
717
718
 
718
719
/*
801
802
 */
802
803
 
803
804
#define ACTIONSTRIP_MASK (ACTSTRIP_SELECT | ACTSTRIP_USESTRIDE \
804
 
                | ACTSTRIP_HOLDLASTFRAME | ACTSTRIP_ACTIVE | ACTSTRIP_LOCK_ACTION)
 
805
                | ACTSTRIP_HOLDLASTFRAME | ACTSTRIP_ACTIVE | ACTSTRIP_LOCK_ACTION \
 
806
                | ACTSTRIP_MUTE)
805
807
 
806
808
static PyObject *ActionStrip_getFlag( BPy_ActionStrip * self )
807
809
{
891
893
                                "This strip has been removed!" );
892
894
 
893
895
        return EXPP_setFloatClamped( value, &self->strip->stridelen,
894
 
                        0.0001, 1000.0 );
 
896
                        0.0001f, 1000.0 );
895
897
}
896
898
 
897
899
/*
907
909
        return PyString_FromString( self->strip->stridechannel );
908
910
}
909
911
 
 
912
static PyObject *ActionStrip_getGroupTarget( BPy_ActionStrip * self )
 
913
{
 
914
        if( !self->strip )
 
915
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
916
                                "This strip has been removed!" );
 
917
                                
 
918
        if (self->strip->object) {
 
919
                return Object_CreatePyObject( self->strip->object );
 
920
        } else {
 
921
                Py_RETURN_NONE;
 
922
        }
 
923
}
 
924
 
910
925
/*
911
926
 * set the stride bone name
912
927
 */
926
941
        return 0;
927
942
}
928
943
 
 
944
static int ActionStrip_setGroupTarget( BPy_ActionStrip * self, PyObject * args )
 
945
{
 
946
        if( !self->strip )
 
947
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
948
                                "This strip has been removed!" );
 
949
 
 
950
        if( (PyObject *)args == Py_None )
 
951
                self->strip->object = NULL;
 
952
        else if( BPy_Object_Check( args ) )
 
953
                self->strip->object = ((BPy_Object *)args)->object;
 
954
        else
 
955
                return EXPP_ReturnIntError( PyExc_TypeError,
 
956
                                "expected an object or None" );
 
957
        return 0;
 
958
}
 
959
 
929
960
/*****************************************************************************/
930
961
/* Python BPy_Constraint attributes get/set structure:                       */
931
962
/*****************************************************************************/
969
1000
        {"strideBone",
970
1001
        (getter)ActionStrip_getStrideBone, (setter)ActionStrip_setStrideBone,
971
1002
         "Name of Bone used for stride", NULL},
 
1003
        {"groupTarget",
 
1004
        (getter)ActionStrip_getGroupTarget, (setter)ActionStrip_setGroupTarget,
 
1005
         "Name of target armature within group", NULL}, 
972
1006
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
973
1007
};
974
1008
 
1024
1058
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1025
1059
                                "This strip has been removed!" );
1026
1060
        
1027
 
        strip->start= floor(strip->start+0.5);
1028
 
        strip->end= floor(strip->end+0.5);
 
1061
        strip->start= (float)floor(strip->start+0.5);
 
1062
        strip->end= (float)floor(strip->end+0.5);
1029
1063
 
1030
1064
        Py_RETURN_NONE;
1031
1065
}
1057
1091
 
1058
1092
        /* Methods to implement standard operations */
1059
1093
 
1060
 
        ( destructor ) Action_dealloc,/* destructor tp_dealloc; */
 
1094
        NULL,                                           /* destructor tp_dealloc; */
1061
1095
        NULL,                       /* printfunc tp_print; */
1062
1096
        NULL,                       /* getattrfunc tp_getattr; */
1063
1097
        NULL,                       /* setattrfunc tp_setattr; */
1145
1179
                                PyInt_FromLong( ACTSTRIP_ACTIVE ) );
1146
1180
                PyConstant_Insert( d, "LOCK_ACTION",
1147
1181
                                PyInt_FromLong( ACTSTRIP_LOCK_ACTION ) );
 
1182
                PyConstant_Insert( d, "MUTE",
 
1183
                                PyInt_FromLong( ACTSTRIP_MUTE ) );
1148
1184
        }
1149
1185
        return S;
1150
1186
}
1277
1313
 * helper function to check for a valid action strip argument
1278
1314
 */
1279
1315
 
1280
 
static bActionStrip *locate_strip( BPy_ActionStrips *self, PyObject * args )
 
1316
static bActionStrip *locate_strip( BPy_ActionStrips *self, 
 
1317
                PyObject *args, BPy_ActionStrip **stripobj )
1281
1318
{
 
1319
        bActionStrip *strip = NULL;
1282
1320
        BPy_ActionStrip *pyobj;
1283
 
        bActionStrip *strip = NULL;
1284
1321
 
1285
1322
        /* check that argument is a constraint */
1286
1323
        if( !PyArg_ParseTuple( args, "O!", &ActionStrip_Type, &pyobj ) ) {
1295
1332
                return NULL;
1296
1333
        }
1297
1334
 
 
1335
        /* if caller needs the object, return it */
 
1336
        if( stripobj )
 
1337
                *stripobj = pyobj;
 
1338
 
1298
1339
        /* find the action strip in the NLA */
1299
1340
        for( strip = self->ob->nlastrips.first; strip; strip = strip->next )
1300
1341
                if( strip == pyobj->strip )
1313
1354
static PyObject *ActionStrips_remove( BPy_ActionStrips *self, PyObject * args )
1314
1355
{
1315
1356
        BPy_ActionStrip *pyobj;
1316
 
        bActionStrip *strip = locate_strip( self, args );
 
1357
        bActionStrip *strip = locate_strip( self, args, &pyobj );
1317
1358
 
1318
1359
        /* return exception if we can't find the strip */
1319
1360
        if( !strip )
1334
1375
 
1335
1376
static PyObject *ActionStrips_moveUp( BPy_ActionStrips *self, PyObject * args )
1336
1377
{
1337
 
        bActionStrip *strip = locate_strip( self, args );
 
1378
        bActionStrip *strip = locate_strip( self, args, NULL );
1338
1379
 
1339
1380
        /* return exception if we can't find the strip */
1340
1381
        if( !strip )
1355
1396
 
1356
1397
static PyObject *ActionStrips_moveDown( BPy_ActionStrips *self, PyObject * args )
1357
1398
{
1358
 
        bActionStrip *strip = locate_strip( self, args );
 
1399
        bActionStrip *strip = locate_strip( self, args, NULL );
1359
1400
 
1360
1401
        /* return exception if we can't find the strip */
1361
1402
        if( !strip )
1390
1431
 
1391
1432
    strip->act = act;
1392
1433
    calc_action_range( strip->act, &strip->actstart, &strip->actend, 1 );
1393
 
    strip->start = G.scene->r.cfra;
 
1434
    strip->start = (float)G.scene->r.cfra;
1394
1435
    strip->end = strip->start + ( strip->actend - strip->actstart );
1395
1436
        /* simple prevention of zero strips */
1396
1437
    if( strip->start > strip->end-2 )
1436
1477
 
1437
1478
        /* Methods to implement standard operations */
1438
1479
 
1439
 
        ( destructor ) Action_dealloc,/* destructor tp_dealloc; */
 
1480
        NULL,                                           /* destructor tp_dealloc; */
1440
1481
        NULL,                       /* printfunc tp_print; */
1441
1482
        NULL,                       /* getattrfunc tp_getattr; */
1442
1483
        NULL,                       /* setattrfunc tp_setattr; */