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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/NLA.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: NLA.c,v 1.10 2006/01/11 19:40:06 ascotan Exp $
 
2
 * $Id: NLA.c,v 1.16 2006/07/22 14:22:03 campbellbarton Exp $
3
3
 *
4
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5
5
 *
32
32
 
33
33
#include "NLA.h" /*This must come first*/
34
34
 
 
35
#include "DNA_curve_types.h"
 
36
#include "DNA_scene_types.h"
35
37
#include "BKE_action.h"
 
38
#include "BKE_nla.h"
36
39
#include "BKE_global.h"
37
40
#include "BKE_main.h"
38
41
#include "BKE_library.h"
40
43
#include "Object.h"
41
44
#include "Ipo.h"
42
45
#include "gen_utils.h"
 
46
#include "blendef.h"
 
47
#include "MEM_guardedalloc.h"
 
48
 
 
49
#define ACTSTRIP_STRIDEAXIS_X         0
 
50
#define ACTSTRIP_STRIDEAXIS_Y         1
 
51
#define ACTSTRIP_STRIDEAXIS_Z         2
43
52
 
44
53
/*****************************************************************************/
45
54
/* Python API function prototypes for the NLA module.                    */
78
87
static PyObject *Action_getName( BPy_Action * self );
79
88
static PyObject *Action_setName( BPy_Action * self, PyObject * args );
80
89
static PyObject *Action_setActive( BPy_Action * self, PyObject * args );
 
90
static PyObject *Action_getFrameNumbers(BPy_Action *self);
81
91
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args );
 
92
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * args );
82
93
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args );
83
94
static PyObject *Action_getAllChannelIpos( BPy_Action * self );
84
95
 
93
104
         "(str) - rename Action"},
94
105
        {"setActive", ( PyCFunction ) Action_setActive, METH_VARARGS,
95
106
         "(str) -set this action as the active action for an object"},
 
107
        {"getFrameNumbers", (PyCFunction) Action_getFrameNumbers, METH_NOARGS,
 
108
        "() - get the frame numbers at which keys have been inserted"},
96
109
        {"getChannelIpo", ( PyCFunction ) Action_getChannelIpo, METH_VARARGS,
97
110
         "(str) -get the Ipo from a named action channel in this action"},
 
111
        {"verifyChannel", ( PyCFunction ) Action_verifyChannel, METH_VARARGS,
 
112
         "(str) -verify the channel in this action"},
98
113
        {"removeChannel", ( PyCFunction ) Action_removeChannel, METH_VARARGS,
99
114
         "(str) -remove the channel from the action"},
100
115
        {"getAllChannelIpos", ( PyCFunction ) Action_getAllChannelIpos,
138
153
        0,                      /* tp_members */
139
154
};
140
155
 
141
 
//-------------------------------------------------------------------------
142
 
static PyObject *M_NLA_NewAction( PyObject * self, PyObject * args )
 
156
/*-------------------------------------------------------------------------*/
 
157
static PyObject *M_NLA_NewAction( PyObject * self_unused, PyObject * args )
143
158
{
144
159
        char *name_str = "DefaultAction";
145
160
        BPy_Action *py_action = NULL;   /* for Action Data object wrapper in Python */
150
165
                                       "expected string or nothing" );
151
166
                return NULL;
152
167
        }
153
 
        //Create new action globally
 
168
        /* Create new action globally */
154
169
        bl_action = alloc_libblock( &G.main->action, ID_AC, name_str );
155
 
        bl_action->id.flag |= LIB_FAKEUSER;
156
 
        bl_action->id.us++;
 
170
        bl_action->id.flag |= LIB_FAKEUSER; /* no need to assign a user because alloc_libblock alredy assigns one */
 
171
        
157
172
 
158
 
        // now create the wrapper obj in Python
 
173
        /* now create the wrapper obj in Python */
159
174
        if( bl_action )
160
175
                py_action =
161
176
                        ( BPy_Action * ) PyObject_NEW( BPy_Action,
172
187
                return NULL;
173
188
        }
174
189
 
175
 
        py_action->action = bl_action;  // link Python action wrapper with Blender Action
 
190
        py_action->action = bl_action;  /* link Python action wrapper with Blender Action */
176
191
 
177
192
        Py_INCREF( py_action );
178
193
        return ( PyObject * ) py_action;
179
194
}
180
195
 
181
 
static PyObject *M_NLA_CopyAction( PyObject * self, PyObject * args )
 
196
static PyObject *M_NLA_CopyAction( PyObject * self_unused, PyObject * args )
182
197
{
183
198
        BPy_Action *py_action = NULL;
184
199
        bAction *copyAction = NULL;
192
207
        return Action_CreatePyObject( copyAction );
193
208
}
194
209
 
195
 
static PyObject *M_NLA_GetActions( PyObject * self )
 
210
static PyObject *M_NLA_GetActions( PyObject * self_unused )
196
211
{
197
212
        PyObject *dict = PyDict_New(  );
198
213
        bAction *action = NULL;
200
215
        for( action = G.main->action.first; action; action = action->id.next ) {
201
216
                PyObject *py_action = Action_CreatePyObject( action );
202
217
                if( py_action ) {
203
 
                        // Insert dict entry using the bone name as key
 
218
                        /* Insert dict entry using the bone name as key */
204
219
                        if( PyDict_SetItemString
205
220
                            ( dict, action->id.name + 2, py_action ) != 0 ) {
206
221
                                Py_DECREF( py_action );
220
235
        return dict;
221
236
}
222
237
 
223
 
/*****************************************************************************/
224
 
/* Function:    NLA_Init                                                 */
225
 
/*****************************************************************************/
226
 
PyObject *NLA_Init( void )
227
 
{
228
 
        PyObject *submodule;
229
 
 
230
 
        Action_Type.ob_type = &PyType_Type;
231
 
 
232
 
        submodule = Py_InitModule3( "Blender.Armature.NLA",
233
 
                                    M_NLA_methods, M_NLA_doc );
234
 
 
235
 
        return ( submodule );
236
 
}
237
 
 
238
 
//----------------------------------------------------------------------
 
238
 
 
239
/*----------------------------------------------------------------------*/
239
240
static PyObject *Action_getName( BPy_Action * self )
240
241
{
241
242
        PyObject *attr = NULL;
253
254
                                        "couldn't get Action.name attribute" ) );
254
255
}
255
256
 
256
 
//----------------------------------------------------------------------
 
257
/*----------------------------------------------------------------------*/
257
258
static PyObject *Action_setName( BPy_Action * self, PyObject * args )
258
259
{
259
260
        char *name;
 
261
        char buf[21];
260
262
 
261
263
        if( !self->action )
262
264
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
266
268
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
267
269
                                                "expected string argument" ) );
268
270
 
269
 
        //change name
270
 
        strcpy( self->action->id.name + 2, name );
271
 
 
272
 
        Py_INCREF( Py_None );
273
 
        return Py_None;
 
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
static PyObject *Action_getFrameNumbers(BPy_Action *self)
 
279
{
 
280
        bActionChannel *achan = NULL;
 
281
        IpoCurve *icu = NULL;
 
282
        BezTriple *bezt = NULL;
 
283
        int verts;
 
284
        PyObject *py_list = NULL;
 
285
        
 
286
        py_list = PyList_New(0);
 
287
        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);
 
297
                                        }
 
298
                                        Py_DECREF(value);
 
299
                                        bezt++;
 
300
                                }
 
301
                        }
 
302
                }
 
303
        }
 
304
        PyList_Sort(py_list);
 
305
        return EXPP_incr_ret(py_list);
274
306
}
275
307
 
276
308
static PyObject *Action_setActive( BPy_Action * self, PyObject * args )
278
310
        BPy_Object *object;
279
311
 
280
312
        if( !self->action )
281
 
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
282
 
                                         "couldn't get attribute from a NULL action" ) );
 
313
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
314
                                         "couldn't get attribute from a NULL action" );
283
315
 
284
316
        if( !PyArg_ParseTuple( args, "O!", &Object_Type, &object ) )
285
 
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
286
 
                                                "expected python object argument" ) );
287
 
 
288
 
        if( object->object->type != OB_ARMATURE ) {
289
 
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
290
 
                                                "object not of type armature" ) );
291
 
        }
292
 
        //set the active action to object
 
317
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
318
                                                "expected python object argument" );
 
319
 
 
320
        if( object->object->type != OB_ARMATURE )
 
321
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
 
322
                                                "object not of type armature" );
 
323
 
 
324
        /* if object is already attached to an action, decrement user count */
 
325
        if( object->object->action )
 
326
                --object->object->action->id.us;
 
327
 
 
328
        /* set the active action to object */
293
329
        object->object->action = self->action;
 
330
        ++object->object->action->id.us;
294
331
 
295
 
        Py_INCREF( Py_None );
296
 
        return Py_None;
 
332
        Py_RETURN_NONE;
297
333
}
298
334
 
299
335
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args )
301
337
        char *chanName;
302
338
        bActionChannel *chan;
303
339
 
304
 
        if( !PyArg_ParseTuple( args, "s", &chanName ) ) {
305
 
                EXPP_ReturnPyObjError( PyExc_AttributeError,
 
340
        if( !PyArg_ParseTuple( args, "s", &chanName ) )
 
341
                return EXPP_ReturnPyObjError( PyExc_AttributeError,
306
342
                                       "string expected" );
307
 
                return NULL;
308
 
        }
309
343
 
310
344
        chan = get_action_channel( self->action, chanName );
311
 
        if( chan == NULL ) {
312
 
                EXPP_ReturnPyObjError( PyExc_AttributeError,
313
 
                                       "no channel with that name..." );
314
 
                return NULL;
 
345
        if( !chan )
 
346
                return EXPP_ReturnPyObjError( PyExc_ValueError,
 
347
                                       "no channel with that name" );
 
348
        
 
349
        if( !chan->ipo ) {
 
350
                Py_RETURN_NONE;
315
351
        }
316
 
        //return IPO
 
352
 
317
353
        return Ipo_CreatePyObject( chan->ipo );
318
354
}
319
355
 
 
356
/*----------------------------------------------------------------------*/
 
357
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * args )
 
358
{
 
359
        char *chanName;
 
360
        bActionChannel *chan;
 
361
 
 
362
        if( !self->action )
 
363
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
364
                                         "couldn't create channel for a NULL action" ) );
 
365
 
 
366
        if( !PyArg_ParseTuple( args, "s", &chanName ) )
 
367
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
368
                                                "expected string argument" ) );
 
369
 
 
370
        chan = verify_action_channel(self->action, chanName);
 
371
 
 
372
        Py_INCREF( Py_None );
 
373
        return Py_None;
 
374
}
 
375
 
 
376
 
320
377
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args )
321
378
{
322
379
        char *chanName;
334
391
                                       "no channel with that name..." );
335
392
                return NULL;
336
393
        }
337
 
        //release ipo
 
394
        /*release ipo*/
338
395
        if( chan->ipo )
339
396
                chan->ipo->id.us--;
340
397
 
341
 
        //remove channel
 
398
        /*remove channel*/
342
399
        BLI_freelinkN( &self->action->chanbase, chan );
343
400
 
344
401
        Py_INCREF( Py_None );
351
408
        bActionChannel *chan = NULL;
352
409
 
353
410
        for( chan = self->action->chanbase.first; chan; chan = chan->next ) {
354
 
                PyObject *ipo_attr = Ipo_CreatePyObject( chan->ipo );
 
411
                PyObject *ipo_attr;
 
412
                if( chan->ipo )
 
413
                        ipo_attr = Ipo_CreatePyObject( chan->ipo );
 
414
                else {
 
415
                        ipo_attr = Py_None;
 
416
                        Py_INCREF( ipo_attr );
 
417
                }
355
418
                if( ipo_attr ) {
356
 
                        // Insert dict entry using the bone name as key
 
419
                        /* Insert dict entry using the bone name as key*/
357
420
                        if( PyDict_SetItemString( dict, chan->name, ipo_attr )
358
421
                            != 0 ) {
359
422
                                Py_DECREF( ipo_attr );
373
436
        return dict;
374
437
}
375
438
 
376
 
//----------------------------------------------------------------------
 
439
/*----------------------------------------------------------------------*/
377
440
static void Action_dealloc( BPy_Action * self )
378
441
{
379
442
        PyObject_DEL( self );
380
443
}
381
444
 
382
 
//----------------------------------------------------------------------
 
445
/*----------------------------------------------------------------------*/
383
446
static PyObject *Action_getAttr( BPy_Action * self, char *name )
384
447
{
385
448
        PyObject *attr = Py_None;
401
464
        return Py_FindMethod( BPy_Action_methods, ( PyObject * ) self, name );
402
465
}
403
466
 
404
 
//----------------------------------------------------------------------
 
467
/*----------------------------------------------------------------------*/
405
468
static int Action_setAttr( BPy_Action * self, char *name, PyObject * value )
406
469
{
407
470
        PyObject *valtuple;
432
495
        return 0;               /* normal exit */
433
496
}
434
497
 
435
 
//----------------------------------------------------------------------
 
498
/*----------------------------------------------------------------------*/
436
499
static PyObject *Action_repr( BPy_Action * self )
437
500
{
438
501
        if( self->action )
442
505
                return PyString_FromString( "NULL" );
443
506
}
444
507
 
445
 
//----------------------------------------------------------------------
 
508
/*----------------------------------------------------------------------*/
446
509
PyObject *Action_CreatePyObject( struct bAction * act )
447
510
{
448
511
        BPy_Action *blen_action;
461
524
        return ( ( PyObject * ) blen_action );
462
525
}
463
526
 
464
 
//-------------------------------------------------------------------------------------------------------------------------------
 
527
/*----------------------------------------------------------------------*/
465
528
int Action_CheckPyObject( PyObject * py_obj )
466
529
{
467
530
        return ( py_obj->ob_type == &Action_Type );
468
531
}
469
532
 
470
 
//----------------------------------------------------------------------
 
533
/*----------------------------------------------------------------------*/
471
534
struct bAction *Action_FromPyObject( PyObject * py_obj )
472
535
{
473
536
        BPy_Action *blen_obj;
475
538
        blen_obj = ( BPy_Action * ) py_obj;
476
539
        return ( blen_obj->action );
477
540
}
 
541
 
 
542
/*****************************************************************************/
 
543
/* ActionStrip wrapper                                                       */
 
544
/*****************************************************************************/
 
545
 
 
546
/*****************************************************************************/
 
547
/* Python BPy_ActionStrip attributes:                                        */
 
548
/*****************************************************************************/
 
549
 
 
550
/*
 
551
 * return the action for the action strip
 
552
 */
 
553
 
 
554
static PyObject *ActionStrip_getAction( BPy_ActionStrip * self )
 
555
{
 
556
        if( !self->strip )
 
557
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
558
                                "This strip has been removed!" );
 
559
        
 
560
        return Action_CreatePyObject( self->strip->act );
 
561
}
 
562
 
 
563
/*
 
564
 * return the start frame of the action strip
 
565
 */
 
566
 
 
567
static PyObject *ActionStrip_getStripStart( BPy_ActionStrip * self )
 
568
{
 
569
        if( !self->strip )
 
570
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
571
                                "This strip has been removed!" );
 
572
        
 
573
        return PyFloat_FromDouble( self->strip->start );
 
574
}
 
575
 
 
576
/*
 
577
 * set the start frame of the action strip
 
578
 */
 
579
 
 
580
static int ActionStrip_setStripStart( BPy_ActionStrip * self, PyObject * value )
 
581
{
 
582
        int retval;
 
583
 
 
584
        if( !self->strip )
 
585
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
586
                                "This strip has been removed!" );
 
587
 
 
588
        retval = EXPP_setFloatClamped( value, &self->strip->start,
 
589
                        -1000.0, self->strip->end-1 );
 
590
        if( !retval ) {
 
591
                float max = self->strip->end - self->strip->start;
 
592
                if( self->strip->blendin > max )
 
593
                        self->strip->blendin = max;
 
594
                if( self->strip->blendout > max )
 
595
                        self->strip->blendout = max;
 
596
        }
 
597
        return retval;
 
598
}
 
599
 
 
600
/*
 
601
 * return the ending frame of the action strip
 
602
 */
 
603
 
 
604
static PyObject *ActionStrip_getStripEnd( BPy_ActionStrip * self )
 
605
{
 
606
        if( !self->strip )
 
607
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
608
                                "This strip has been removed!" );
 
609
        
 
610
        return PyFloat_FromDouble( self->strip->end );
 
611
}
 
612
 
 
613
/*
 
614
 * set the ending frame of the action strip
 
615
 */
 
616
 
 
617
static int ActionStrip_setStripEnd( BPy_ActionStrip * self, PyObject * value )
 
618
{
 
619
        int retval;
 
620
 
 
621
        if( !self->strip )
 
622
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
623
                                "This strip has been removed!" );
 
624
 
 
625
        retval = EXPP_setFloatClamped( value, &self->strip->end,
 
626
                        self->strip->start+1, MAXFRAMEF );
 
627
        if( !retval ) {
 
628
                float max = self->strip->end - self->strip->start;
 
629
                if( self->strip->blendin > max )
 
630
                        self->strip->blendin = max;
 
631
                if( self->strip->blendout > max )
 
632
                        self->strip->blendout = max;
 
633
        }
 
634
        return retval;
 
635
}
 
636
 
 
637
/*
 
638
 * return the start frame of the action
 
639
 */
 
640
 
 
641
static PyObject *ActionStrip_getActionStart( BPy_ActionStrip * self )
 
642
{
 
643
        if( !self->strip )
 
644
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
645
                                "This strip has been removed!" );
 
646
        
 
647
        return PyFloat_FromDouble( self->strip->actstart );
 
648
}
 
649
 
 
650
/*
 
651
 * set the start frame of the action
 
652
 */
 
653
 
 
654
static int ActionStrip_setActionStart( BPy_ActionStrip * self, PyObject * value )
 
655
{
 
656
        if( !self->strip )
 
657
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
658
                                "This strip has been removed!" );
 
659
 
 
660
        return EXPP_setFloatClamped( value, &self->strip->actstart,
 
661
                        -1000.0, self->strip->actend-1 );
 
662
}
 
663
 
 
664
/*
 
665
 * return the ending frame of the action
 
666
 */
 
667
 
 
668
static PyObject *ActionStrip_getActionEnd( BPy_ActionStrip * self )
 
669
{
 
670
        if( !self->strip )
 
671
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
672
                                "This strip has been removed!" );
 
673
        
 
674
        return PyFloat_FromDouble( self->strip->actend );
 
675
}
 
676
 
 
677
/*
 
678
 * set the ending frame of the action
 
679
 */
 
680
 
 
681
static int ActionStrip_setActionEnd( BPy_ActionStrip * self, PyObject * value )
 
682
{
 
683
        if( !self->strip )
 
684
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
685
                                "This strip has been removed!" );
 
686
 
 
687
        return EXPP_setFloatClamped( value, &self->strip->actend,
 
688
                        self->strip->actstart+1, MAXFRAMEF );
 
689
}
 
690
 
 
691
/*
 
692
 * return the repeat value of the action strip
 
693
 */
 
694
 
 
695
static PyObject *ActionStrip_getRepeat( BPy_ActionStrip * self )
 
696
{
 
697
        if( !self->strip )
 
698
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
699
                                "This strip has been removed!" );
 
700
        
 
701
        return PyFloat_FromDouble( self->strip->repeat );
 
702
}
 
703
 
 
704
/*
 
705
 * set the repeat value of the action strip
 
706
 */
 
707
 
 
708
static int ActionStrip_setRepeat( BPy_ActionStrip * self, PyObject * value )
 
709
{
 
710
        if( !self->strip )
 
711
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
712
                                "This strip has been removed!" );
 
713
 
 
714
        return EXPP_setFloatClamped( value, &self->strip->repeat,
 
715
                        0.001, 1000.0f );
 
716
}
 
717
 
 
718
/*
 
719
 * return the blend in of the action strip
 
720
 */
 
721
 
 
722
static PyObject *ActionStrip_getBlendIn( BPy_ActionStrip * self )
 
723
{
 
724
        if( !self->strip )
 
725
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
726
                                "This strip has been removed!" );
 
727
        
 
728
        return PyFloat_FromDouble( self->strip->blendin );
 
729
}
 
730
 
 
731
/*
 
732
 * set the blend in value of the action strip
 
733
 */
 
734
 
 
735
static int ActionStrip_setBlendIn( BPy_ActionStrip * self, PyObject * value )
 
736
{
 
737
        if( !self->strip )
 
738
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
739
                                "This strip has been removed!" );
 
740
 
 
741
        return EXPP_setFloatClamped( value, &self->strip->blendin,
 
742
                        0.0, self->strip->end - self->strip->start );
 
743
}
 
744
 
 
745
/*
 
746
 * return the blend out of the action strip
 
747
 */
 
748
 
 
749
static PyObject *ActionStrip_getBlendOut( BPy_ActionStrip * self )
 
750
{
 
751
        if( !self->strip )
 
752
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
753
                                "This strip has been removed!" );
 
754
        
 
755
        return PyFloat_FromDouble( self->strip->blendout );
 
756
}
 
757
 
 
758
/*
 
759
 * set the blend out value of the action strip
 
760
 */
 
761
 
 
762
static int ActionStrip_setBlendOut( BPy_ActionStrip * self, PyObject * value )
 
763
{
 
764
        if( !self->strip )
 
765
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
766
                                "This strip has been removed!" );
 
767
 
 
768
        return EXPP_setFloatClamped( value, &self->strip->blendout,
 
769
                        0.0, self->strip->end - self->strip->start );
 
770
}
 
771
 
 
772
/*
 
773
 * return the blend mode of the action strip
 
774
 */
 
775
 
 
776
static PyObject *ActionStrip_getBlendMode( BPy_ActionStrip * self )
 
777
{
 
778
        if( !self->strip )
 
779
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
780
                                "This strip has been removed!" );
 
781
        
 
782
        return PyInt_FromLong( (long)self->strip->mode ) ;
 
783
}
 
784
 
 
785
/*
 
786
 * set the blend mode value of the action strip
 
787
 */
 
788
 
 
789
static int ActionStrip_setBlendMode( BPy_ActionStrip * self, PyObject * value )
 
790
{
 
791
        if( !self->strip )
 
792
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
793
                                "This strip has been removed!" );
 
794
 
 
795
        return EXPP_setIValueRange( value, &self->strip->mode,
 
796
                                0, ACTSTRIPMODE_ADD, 'h' );
 
797
}
 
798
 
 
799
/*
 
800
 * return the flag settings of the action strip
 
801
 */
 
802
 
 
803
#define ACTIONSTRIP_MASK (ACTSTRIP_SELECT | ACTSTRIP_USESTRIDE \
 
804
                | ACTSTRIP_HOLDLASTFRAME | ACTSTRIP_ACTIVE | ACTSTRIP_LOCK_ACTION)
 
805
 
 
806
static PyObject *ActionStrip_getFlag( BPy_ActionStrip * self )
 
807
{
 
808
        if( !self->strip )
 
809
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
810
                                "This strip has been removed!" );
 
811
        
 
812
        return PyInt_FromLong( (long)( self->strip->flag & ACTIONSTRIP_MASK ) ) ;
 
813
}
 
814
 
 
815
/*
 
816
 * set the flag settings out value of the action strip
 
817
 */
 
818
 
 
819
static int ActionStrip_setFlag( BPy_ActionStrip * self, PyObject * arg )
 
820
{
 
821
        PyObject *num = PyNumber_Int( arg );
 
822
        int value;
 
823
 
 
824
        if( !self->strip )
 
825
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
826
                                "This strip has been removed!" );
 
827
        if( !num )
 
828
                return EXPP_ReturnIntError( PyExc_TypeError,
 
829
                                "expected int argument" );
 
830
        value = PyInt_AS_LONG( num );
 
831
        Py_DECREF( num );
 
832
 
 
833
        if( ( value & ACTIONSTRIP_MASK ) != value ) {
 
834
                char errstr[128];
 
835
                sprintf ( errstr , "expected int bitmask of 0x%04x", ACTIONSTRIP_MASK );
 
836
                return EXPP_ReturnIntError( PyExc_TypeError, errstr );
 
837
        }
 
838
 
 
839
        self->strip->flag = (short)value;
 
840
        return 0;
 
841
}
 
842
 
 
843
/*
 
844
 * return the stride axis of the action strip
 
845
 */
 
846
 
 
847
static PyObject *ActionStrip_getStrideAxis( BPy_ActionStrip * self )
 
848
{
 
849
        if( !self->strip )
 
850
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
851
                                "This strip has been removed!" );
 
852
        
 
853
        return PyInt_FromLong( (long)self->strip->stride_axis ) ;
 
854
}
 
855
 
 
856
/*
 
857
 * set the stride axis of the action strip
 
858
 */
 
859
 
 
860
static int ActionStrip_setStrideAxis( BPy_ActionStrip * self, PyObject * value )
 
861
{
 
862
        if( !self->strip )
 
863
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
864
                                "This strip has been removed!" );
 
865
 
 
866
        return EXPP_setIValueRange( value, &self->strip->stride_axis,
 
867
                                ACTSTRIP_STRIDEAXIS_X, ACTSTRIP_STRIDEAXIS_Z, 'h' );
 
868
}
 
869
 
 
870
/*
 
871
 * return the stride length of the action strip
 
872
 */
 
873
 
 
874
static PyObject *ActionStrip_getStrideLength( BPy_ActionStrip * self )
 
875
{
 
876
        if( !self->strip )
 
877
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
878
                                "This strip has been removed!" );
 
879
        
 
880
        return PyFloat_FromDouble( (double)self->strip->stridelen ) ;
 
881
}
 
882
 
 
883
/*
 
884
 * set the stride length of the action strip
 
885
 */
 
886
 
 
887
static int ActionStrip_setStrideLength( BPy_ActionStrip * self, PyObject * value )
 
888
{
 
889
        if( !self->strip )
 
890
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
891
                                "This strip has been removed!" );
 
892
 
 
893
        return EXPP_setFloatClamped( value, &self->strip->stridelen,
 
894
                        0.0001, 1000.0 );
 
895
}
 
896
 
 
897
/*
 
898
 * return the stride bone name
 
899
 */
 
900
 
 
901
static PyObject *ActionStrip_getStrideBone( BPy_ActionStrip * self )
 
902
{
 
903
        if( !self->strip )
 
904
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
905
                                "This strip has been removed!" );
 
906
        
 
907
        return PyString_FromString( self->strip->stridechannel );
 
908
}
 
909
 
 
910
/*
 
911
 * set the stride bone name
 
912
 */
 
913
 
 
914
static int ActionStrip_setStrideBone( BPy_ActionStrip * self, PyObject * attr )
 
915
{
 
916
        char *name = PyString_AsString( attr );
 
917
        if( !name )
 
918
                return EXPP_ReturnIntError( PyExc_TypeError, "expected string arg" );
 
919
 
 
920
        if( !self->strip )
 
921
                return EXPP_ReturnIntError( PyExc_RuntimeError,
 
922
                                "This strip has been removed!" );
 
923
        
 
924
        BLI_strncpy( self->strip->stridechannel, name, 32 );
 
925
 
 
926
        return 0;
 
927
}
 
928
 
 
929
/*****************************************************************************/
 
930
/* Python BPy_Constraint attributes get/set structure:                       */
 
931
/*****************************************************************************/
 
932
static PyGetSetDef BPy_ActionStrip_getseters[] = {
 
933
        {"action",
 
934
        (getter)ActionStrip_getAction, (setter)NULL,
 
935
         "Action associated with the strip", NULL},
 
936
        {"stripStart",
 
937
        (getter)ActionStrip_getStripStart, (setter)ActionStrip_setStripStart,
 
938
         "Starting frame of the strip", NULL},
 
939
        {"stripEnd",
 
940
        (getter)ActionStrip_getStripEnd, (setter)ActionStrip_setStripEnd,
 
941
         "Ending frame of the strip", NULL},
 
942
        {"actionStart",
 
943
        (getter)ActionStrip_getActionStart, (setter)ActionStrip_setActionStart,
 
944
         "Starting frame of the action", NULL},
 
945
        {"actionEnd",
 
946
        (getter)ActionStrip_getActionEnd, (setter)ActionStrip_setActionEnd,
 
947
         "Ending frame of the action", NULL},
 
948
        {"repeat",
 
949
        (getter)ActionStrip_getRepeat, (setter)ActionStrip_setRepeat,
 
950
         "The number of times to repeat the action range", NULL},
 
951
        {"blendIn",
 
952
        (getter)ActionStrip_getBlendIn, (setter)ActionStrip_setBlendIn,
 
953
         "Number of frames of motion blending", NULL},
 
954
        {"blendOut",
 
955
        (getter)ActionStrip_getBlendOut, (setter)ActionStrip_setBlendOut,
 
956
         "Number of frames of ease-out", NULL},
 
957
        {"mode",
 
958
        (getter)ActionStrip_getBlendMode, (setter)ActionStrip_setBlendMode,
 
959
         "Setting of blending mode", NULL},
 
960
        {"flag",
 
961
        (getter)ActionStrip_getFlag, (setter)ActionStrip_setFlag,
 
962
         "Setting of blending flags", NULL},
 
963
        {"strideAxis",
 
964
        (getter)ActionStrip_getStrideAxis, (setter)ActionStrip_setStrideAxis,
 
965
         "Dominant axis for stride bone", NULL},
 
966
        {"strideLength",
 
967
        (getter)ActionStrip_getStrideLength, (setter)ActionStrip_setStrideLength,
 
968
         "Distance covered by one complete cycle of the action", NULL},
 
969
        {"strideBone",
 
970
        (getter)ActionStrip_getStrideBone, (setter)ActionStrip_setStrideBone,
 
971
         "Name of Bone used for stride", NULL},
 
972
        {NULL,NULL,NULL,NULL,NULL}  /* Sentinel */
 
973
};
 
974
 
 
975
/*****************************************************************************/
 
976
/* Python BPy_ActionStrip methods:                                           */
 
977
/*****************************************************************************/
 
978
 
 
979
/*
 
980
 * restore the values of ActionStart and ActionEnd to their defaults
 
981
 */
 
982
 
 
983
static PyObject *ActionStrip_resetLimits( BPy_ActionStrip *self )
 
984
{
 
985
        bActionStrip *strip = self->strip;
 
986
 
 
987
        if( !strip )
 
988
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
989
                                "This strip has been removed!" );
 
990
        
 
991
        calc_action_range( strip->act, &strip->actstart, &strip->actend, 1 );
 
992
 
 
993
        Py_RETURN_NONE;
 
994
}
 
995
 
 
996
/*
 
997
 * reset the strip size
 
998
 */
 
999
 
 
1000
static PyObject *ActionStrip_resetStripSize( BPy_ActionStrip *self )
 
1001
{
 
1002
        float mapping;
 
1003
        bActionStrip *strip = self->strip;
 
1004
 
 
1005
        if( !strip )
 
1006
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1007
                                "This strip has been removed!" );
 
1008
        
 
1009
        mapping = (strip->actend - strip->actstart) / (strip->end - strip->start);
 
1010
        strip->end = strip->start + mapping*(strip->end - strip->start);
 
1011
 
 
1012
        Py_RETURN_NONE;
 
1013
}
 
1014
 
 
1015
/*
 
1016
 * snap to start and end to nearest frames
 
1017
 */
 
1018
 
 
1019
static PyObject *ActionStrip_snapToFrame( BPy_ActionStrip *self )
 
1020
{
 
1021
        bActionStrip *strip = self->strip;
 
1022
 
 
1023
        if( !strip )
 
1024
                return EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1025
                                "This strip has been removed!" );
 
1026
        
 
1027
        strip->start= floor(strip->start+0.5);
 
1028
        strip->end= floor(strip->end+0.5);
 
1029
 
 
1030
        Py_RETURN_NONE;
 
1031
}
 
1032
 
 
1033
/*****************************************************************************/
 
1034
/* Python BPy_ActionStrip methods table:                                    */
 
1035
/*****************************************************************************/
 
1036
static PyMethodDef BPy_ActionStrip_methods[] = {
 
1037
        /* name, method, flags, doc */
 
1038
        {"resetActionLimits", ( PyCFunction ) ActionStrip_resetLimits, METH_NOARGS,
 
1039
         "Restores the values of ActionStart and ActionEnd to their defaults"},
 
1040
        {"resetStripSize", ( PyCFunction ) ActionStrip_resetStripSize, METH_NOARGS,
 
1041
         "Resets the Action Strip size to its creation values"},
 
1042
        {"snapToFrame", ( PyCFunction ) ActionStrip_snapToFrame, METH_NOARGS,
 
1043
         "Snaps the ends of the action strip to the nearest whole numbered frame"},
 
1044
        {NULL, NULL, 0, NULL}
 
1045
};
 
1046
 
 
1047
/*****************************************************************************/
 
1048
/* Python ActionStrip_Type structure definition:                            */
 
1049
/*****************************************************************************/
 
1050
PyTypeObject ActionStrip_Type = {
 
1051
        PyObject_HEAD_INIT( NULL )  /* required py macro */
 
1052
        0,                          /* ob_size */
 
1053
        /*  For printing, in format "<module>.<name>" */
 
1054
        "Blender.ActionStrip",     /* char *tp_name; */
 
1055
        sizeof( BPy_ActionStrip ), /* int tp_basicsize; */
 
1056
        0,                          /* tp_itemsize;  For allocation */
 
1057
 
 
1058
        /* Methods to implement standard operations */
 
1059
 
 
1060
        ( destructor ) Action_dealloc,/* destructor tp_dealloc; */
 
1061
        NULL,                       /* printfunc tp_print; */
 
1062
        NULL,                       /* getattrfunc tp_getattr; */
 
1063
        NULL,                       /* setattrfunc tp_setattr; */
 
1064
        NULL,                       /* cmpfunc tp_compare; */
 
1065
        ( reprfunc ) NULL,          /* reprfunc tp_repr; */
 
1066
 
 
1067
        /* Method suites for standard classes */
 
1068
 
 
1069
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
1070
        NULL,                       /* PySequenceMethods *tp_as_sequence; */
 
1071
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
1072
 
 
1073
        /* More standard operations (here for binary compatibility) */
 
1074
 
 
1075
        NULL,                       /* hashfunc tp_hash; */
 
1076
        NULL,                       /* ternaryfunc tp_call; */
 
1077
        NULL,                       /* reprfunc tp_str; */
 
1078
        NULL,                       /* getattrofunc tp_getattro; */
 
1079
        NULL,                       /* setattrofunc tp_setattro; */
 
1080
 
 
1081
        /* Functions to access object as input/output buffer */
 
1082
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
1083
 
 
1084
  /*** Flags to define presence of optional/expanded features ***/
 
1085
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
1086
 
 
1087
        NULL,                       /*  char *tp_doc;  Documentation string */
 
1088
  /*** Assigned meaning in release 2.0 ***/
 
1089
        /* call function for all accessible objects */
 
1090
        NULL,                       /* traverseproc tp_traverse; */
 
1091
 
 
1092
        /* delete references to contained objects */
 
1093
        NULL,                       /* inquiry tp_clear; */
 
1094
 
 
1095
  /***  Assigned meaning in release 2.1 ***/
 
1096
  /*** rich comparisons ***/
 
1097
        NULL,                       /* richcmpfunc tp_richcompare; */
 
1098
 
 
1099
  /***  weak reference enabler ***/
 
1100
        0,                          /* long tp_weaklistoffset; */
 
1101
 
 
1102
  /*** Added in release 2.2 ***/
 
1103
        /*   Iterators */
 
1104
        NULL,                        /* getiterfunc tp_iter; */
 
1105
    NULL,                        /* iternextfunc tp_iternext; */
 
1106
 
 
1107
  /*** Attribute descriptor and subclassing stuff ***/
 
1108
        BPy_ActionStrip_methods,    /* struct PyMethodDef *tp_methods; */
 
1109
        NULL,                       /* struct PyMemberDef *tp_members; */
 
1110
        BPy_ActionStrip_getseters,  /* struct PyGetSetDef *tp_getset; */
 
1111
        NULL,                       /* struct _typeobject *tp_base; */
 
1112
        NULL,                       /* PyObject *tp_dict; */
 
1113
        NULL,                       /* descrgetfunc tp_descr_get; */
 
1114
        NULL,                       /* descrsetfunc tp_descr_set; */
 
1115
        0,                          /* long tp_dictoffset; */
 
1116
        NULL,                       /* initproc tp_init; */
 
1117
        NULL,                       /* allocfunc tp_alloc; */
 
1118
        NULL,                       /* newfunc tp_new; */
 
1119
        /*  Low-level free-memory routine */
 
1120
        NULL,                       /* freefunc tp_free;  */
 
1121
        /* For PyObject_IS_GC */
 
1122
        NULL,                       /* inquiry tp_is_gc;  */
 
1123
        NULL,                       /* PyObject *tp_bases; */
 
1124
        /* method resolution order */
 
1125
        NULL,                       /* PyObject *tp_mro;  */
 
1126
        NULL,                       /* PyObject *tp_cache; */
 
1127
        NULL,                       /* PyObject *tp_subclasses; */
 
1128
        NULL,                       /* PyObject *tp_weaklist; */
 
1129
        NULL
 
1130
};
 
1131
 
 
1132
static PyObject *M_ActionStrip_FlagsDict( void )
 
1133
{
 
1134
        PyObject *S = PyConstant_New(  );
 
1135
        
 
1136
        if( S ) {
 
1137
                BPy_constant *d = ( BPy_constant * ) S;
 
1138
                PyConstant_Insert( d, "SELECT",
 
1139
                                PyInt_FromLong( ACTSTRIP_SELECT ) );
 
1140
                PyConstant_Insert( d, "STRIDE_PATH",
 
1141
                                PyInt_FromLong( ACTSTRIP_USESTRIDE ) );
 
1142
                PyConstant_Insert( d, "HOLD",
 
1143
                                PyInt_FromLong( ACTSTRIP_HOLDLASTFRAME ) );
 
1144
                PyConstant_Insert( d, "ACTIVE",
 
1145
                                PyInt_FromLong( ACTSTRIP_ACTIVE ) );
 
1146
                PyConstant_Insert( d, "LOCK_ACTION",
 
1147
                                PyInt_FromLong( ACTSTRIP_LOCK_ACTION ) );
 
1148
        }
 
1149
        return S;
 
1150
}
 
1151
 
 
1152
static PyObject *M_ActionStrip_AxisDict( void )
 
1153
{
 
1154
        PyObject *S = PyConstant_New(  );
 
1155
        
 
1156
        if( S ) {
 
1157
                BPy_constant *d = ( BPy_constant * ) S;
 
1158
                PyConstant_Insert( d, "STRIDEAXIS_X",
 
1159
                                PyInt_FromLong( ACTSTRIP_STRIDEAXIS_X ) );
 
1160
                PyConstant_Insert( d, "STRIDEAXIS_Y",
 
1161
                                PyInt_FromLong( ACTSTRIP_STRIDEAXIS_Y ) );
 
1162
                PyConstant_Insert( d, "STRIDEAXIS_Z",
 
1163
                                PyInt_FromLong( ACTSTRIP_STRIDEAXIS_Z ) );
 
1164
        }
 
1165
        return S;
 
1166
}
 
1167
 
 
1168
static PyObject *M_ActionStrip_ModeDict( void )
 
1169
{
 
1170
        PyObject *S = PyConstant_New(  );
 
1171
        
 
1172
        if( S ) {
 
1173
                BPy_constant *d = ( BPy_constant * ) S;
 
1174
                PyConstant_Insert( d, "MODE_ADD",
 
1175
                                PyInt_FromLong( ACTSTRIPMODE_ADD ) );
 
1176
        }
 
1177
        return S;
 
1178
}
 
1179
 
 
1180
PyObject *ActionStrip_CreatePyObject( struct bActionStrip *strip )
 
1181
{
 
1182
        BPy_ActionStrip *pyobj;
 
1183
        pyobj = ( BPy_ActionStrip * ) PyObject_NEW( BPy_ActionStrip,
 
1184
                        &ActionStrip_Type );
 
1185
        if( !pyobj )
 
1186
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
1187
                                              "couldn't create BPy_ActionStrip object" );
 
1188
        pyobj->strip = strip;
 
1189
        return ( PyObject * ) pyobj;
 
1190
}
 
1191
 
 
1192
/*****************************************************************************/
 
1193
/* ActionStrip Sequence wrapper                                              */
 
1194
/*****************************************************************************/
 
1195
 
 
1196
/*
 
1197
 * Initialize the iterator
 
1198
 */
 
1199
 
 
1200
static PyObject *ActionStrips_getIter( BPy_ActionStrips * self )
 
1201
{
 
1202
        self->iter = (bActionStrip *)self->ob->nlastrips.first;
 
1203
        return EXPP_incr_ret ( (PyObject *) self );
 
1204
}
 
1205
 
 
1206
/*
 
1207
 * Get the next action strip
 
1208
 */
 
1209
 
 
1210
static PyObject *ActionStrips_nextIter( BPy_ActionStrips * self )
 
1211
{
 
1212
        bActionStrip *strip = self->iter;
 
1213
        if( strip ) {
 
1214
                self->iter = strip->next;
 
1215
                return ActionStrip_CreatePyObject( strip );
 
1216
        }
 
1217
 
 
1218
        return EXPP_ReturnPyObjError( PyExc_StopIteration,
 
1219
                        "iterator at end" );
 
1220
}
 
1221
 
 
1222
/* return the number of action strips */
 
1223
 
 
1224
static int ActionStrips_length( BPy_ActionStrips * self )
 
1225
{
 
1226
        return BLI_countlist( &self->ob->nlastrips );
 
1227
}
 
1228
 
 
1229
/* return an action strip */
 
1230
 
 
1231
static PyObject *ActionStrips_item( BPy_ActionStrips * self, int i )
 
1232
{
 
1233
        bActionStrip *strip = NULL;
 
1234
 
 
1235
        /* if index is negative, start counting from the end of the list */
 
1236
        if( i < 0 )
 
1237
                i += ActionStrips_length( self );
 
1238
 
 
1239
        /* skip through the list until we get the strip or end of list */
 
1240
 
 
1241
        strip = self->ob->nlastrips.first;
 
1242
 
 
1243
        while( i && strip ) {
 
1244
                --i;
 
1245
                strip = strip->next;
 
1246
        }
 
1247
 
 
1248
        if( strip )
 
1249
                return ActionStrip_CreatePyObject( strip );
 
1250
        else
 
1251
                return EXPP_ReturnPyObjError( PyExc_IndexError,
 
1252
                                "array index out of range" );
 
1253
}
 
1254
 
 
1255
/*****************************************************************************/
 
1256
/* Python BPy_ActionStrips sequence table:                                  */
 
1257
/*****************************************************************************/
 
1258
static PySequenceMethods ActionStrips_as_sequence = {
 
1259
        ( inquiry ) ActionStrips_length,        /* sq_length */
 
1260
        ( binaryfunc ) 0,       /* sq_concat */
 
1261
        ( intargfunc ) 0,       /* sq_repeat */
 
1262
        ( intargfunc ) ActionStrips_item,       /* sq_item */
 
1263
        ( intintargfunc ) 0,    /* sq_slice */
 
1264
        ( intobjargproc ) 0,    /* sq_ass_item */
 
1265
        ( intintobjargproc ) 0, /* sq_ass_slice */
 
1266
        ( objobjproc ) 0,       /* sq_contains */
 
1267
        ( binaryfunc ) 0,               /* sq_inplace_concat */
 
1268
        ( intargfunc ) 0,               /* sq_inplace_repeat */
 
1269
};
 
1270
 
 
1271
 
 
1272
/*****************************************************************************/
 
1273
/* Python BPy_ActionStrip methods:                                           */
 
1274
/*****************************************************************************/
 
1275
 
 
1276
/*
 
1277
 * helper function to check for a valid action strip argument
 
1278
 */
 
1279
 
 
1280
static bActionStrip *locate_strip( BPy_ActionStrips *self, PyObject * args )
 
1281
{
 
1282
        BPy_ActionStrip *pyobj;
 
1283
        bActionStrip *strip = NULL;
 
1284
 
 
1285
        /* check that argument is a constraint */
 
1286
        if( !PyArg_ParseTuple( args, "O!", &ActionStrip_Type, &pyobj ) ) {
 
1287
                EXPP_ReturnPyObjError( PyExc_TypeError,
 
1288
                                "expected an action strip as an argument" );
 
1289
                return NULL;
 
1290
        }
 
1291
 
 
1292
        if( !pyobj->strip ) {
 
1293
                EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
1294
                                "This strip has been removed!" );
 
1295
                return NULL;
 
1296
        }
 
1297
 
 
1298
        /* find the action strip in the NLA */
 
1299
        for( strip = self->ob->nlastrips.first; strip; strip = strip->next )
 
1300
                if( strip == pyobj->strip )
 
1301
                        return strip;
 
1302
 
 
1303
        /* return exception if we can't find the strip */
 
1304
        EXPP_ReturnPyObjError( PyExc_AttributeError,
 
1305
                        "action strip does not belong to this object" );
 
1306
        return NULL;
 
1307
}
 
1308
 
 
1309
/*
 
1310
 * remove an action strip from the NLA
 
1311
 */
 
1312
 
 
1313
static PyObject *ActionStrips_remove( BPy_ActionStrips *self, PyObject * args )
 
1314
{
 
1315
        BPy_ActionStrip *pyobj;
 
1316
        bActionStrip *strip = locate_strip( self, args );
 
1317
 
 
1318
        /* return exception if we can't find the strip */
 
1319
        if( !strip )
 
1320
                return (PyObject *)NULL;
 
1321
 
 
1322
        /* do the actual removal */
 
1323
        free_actionstrip(strip);
 
1324
        BLI_remlink(&self->ob->nlastrips, strip);
 
1325
        MEM_freeN(strip);
 
1326
 
 
1327
        pyobj->strip = NULL;
 
1328
        Py_RETURN_NONE;
 
1329
}
 
1330
 
 
1331
/*
 
1332
 * move an action strip up in the strip list
 
1333
 */
 
1334
 
 
1335
static PyObject *ActionStrips_moveUp( BPy_ActionStrips *self, PyObject * args )
 
1336
{
 
1337
        bActionStrip *strip = locate_strip( self, args );
 
1338
 
 
1339
        /* return exception if we can't find the strip */
 
1340
        if( !strip )
 
1341
                return (PyObject *)NULL;
 
1342
 
 
1343
        /* if strip is not already the first, move it up */
 
1344
        if( strip != self->ob->nlastrips.first ) {
 
1345
                BLI_remlink(&self->ob->nlastrips, strip);
 
1346
                BLI_insertlink(&self->ob->nlastrips, strip->prev->prev, strip);
 
1347
        }
 
1348
 
 
1349
        Py_RETURN_NONE;
 
1350
}
 
1351
 
 
1352
/*
 
1353
 * move an action strip down in the strip list
 
1354
 */
 
1355
 
 
1356
static PyObject *ActionStrips_moveDown( BPy_ActionStrips *self, PyObject * args )
 
1357
{
 
1358
        bActionStrip *strip = locate_strip( self, args );
 
1359
 
 
1360
        /* return exception if we can't find the strip */
 
1361
        if( !strip )
 
1362
                return (PyObject *)NULL;
 
1363
 
 
1364
        /* if strip is not already the last, move it down */
 
1365
        if( strip != self->ob->nlastrips.last ) {
 
1366
                BLI_remlink(&self->ob->nlastrips, strip);
 
1367
                BLI_insertlink(&self->ob->nlastrips, strip->next, strip);
 
1368
        }
 
1369
 
 
1370
        Py_RETURN_NONE;
 
1371
}
 
1372
 
 
1373
static PyObject *ActionStrips_append( BPy_ActionStrips *self, PyObject * args )
 
1374
{
 
1375
        BPy_Action *pyobj;
 
1376
        Object *ob;
 
1377
        bActionStrip *strip;
 
1378
        bAction *act;
 
1379
 
 
1380
        /* check that argument is an action */
 
1381
        if( !PyArg_ParseTuple( args, "O!", &Action_Type, &pyobj ) )
 
1382
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1383
                                "expected an action as an argument" );
 
1384
 
 
1385
        ob = self->ob;
 
1386
        act = pyobj->action;
 
1387
 
 
1388
        /* Initialize the new action block */
 
1389
        strip = MEM_callocN( sizeof(bActionStrip), "bActionStrip" );
 
1390
 
 
1391
    strip->act = act;
 
1392
    calc_action_range( strip->act, &strip->actstart, &strip->actend, 1 );
 
1393
    strip->start = G.scene->r.cfra;
 
1394
    strip->end = strip->start + ( strip->actend - strip->actstart );
 
1395
        /* simple prevention of zero strips */
 
1396
    if( strip->start > strip->end-2 )
 
1397
        strip->end = strip->start+100;
 
1398
 
 
1399
    strip->flag = ACTSTRIP_LOCK_ACTION;
 
1400
    find_stridechannel(ob, strip);
 
1401
 
 
1402
    strip->repeat = 1.0;
 
1403
    act->id.us++;
 
1404
 
 
1405
    BLI_addtail(&ob->nlastrips, strip);
 
1406
 
 
1407
        Py_RETURN_NONE;
 
1408
}
 
1409
 
 
1410
/*****************************************************************************/
 
1411
/* Python BPy_ActionStrips methods table:                                    */
 
1412
/*****************************************************************************/
 
1413
static PyMethodDef BPy_ActionStrips_methods[] = {
 
1414
        /* name, method, flags, doc */
 
1415
        {"append", ( PyCFunction ) ActionStrips_append, METH_VARARGS,
 
1416
         "(action) - append a new actionstrip using existing action"},
 
1417
        {"remove", ( PyCFunction ) ActionStrips_remove, METH_VARARGS,
 
1418
         "(strip) - remove an existing strip from this actionstrips"},
 
1419
        {"moveUp", ( PyCFunction ) ActionStrips_moveUp, METH_VARARGS,
 
1420
         "(strip) - move an existing strip up in the actionstrips"},
 
1421
        {"moveDown", ( PyCFunction ) ActionStrips_moveDown, METH_VARARGS,
 
1422
         "(strip) - move an existing strip down in the actionstrips"},
 
1423
        {NULL, NULL, 0, NULL}
 
1424
};
 
1425
 
 
1426
/*****************************************************************************/
 
1427
/* Python ActionStrips_Type structure definition:                            */
 
1428
/*****************************************************************************/
 
1429
PyTypeObject ActionStrips_Type = {
 
1430
        PyObject_HEAD_INIT( NULL )  /* required py macro */
 
1431
        0,                          /* ob_size */
 
1432
        /*  For printing, in format "<module>.<name>" */
 
1433
        "Blender.ActionStrips",     /* char *tp_name; */
 
1434
        sizeof( BPy_ActionStrips ), /* int tp_basicsize; */
 
1435
        0,                          /* tp_itemsize;  For allocation */
 
1436
 
 
1437
        /* Methods to implement standard operations */
 
1438
 
 
1439
        ( destructor ) Action_dealloc,/* destructor tp_dealloc; */
 
1440
        NULL,                       /* printfunc tp_print; */
 
1441
        NULL,                       /* getattrfunc tp_getattr; */
 
1442
        NULL,                       /* setattrfunc tp_setattr; */
 
1443
        NULL,                       /* cmpfunc tp_compare; */
 
1444
        ( reprfunc ) NULL,          /* reprfunc tp_repr; */
 
1445
 
 
1446
        /* Method suites for standard classes */
 
1447
 
 
1448
        NULL,                       /* PyNumberMethods *tp_as_number; */
 
1449
        &ActionStrips_as_sequence,  /* PySequenceMethods *tp_as_sequence; */
 
1450
        NULL,                       /* PyMappingMethods *tp_as_mapping; */
 
1451
 
 
1452
        /* More standard operations (here for binary compatibility) */
 
1453
 
 
1454
        NULL,                       /* hashfunc tp_hash; */
 
1455
        NULL,                       /* ternaryfunc tp_call; */
 
1456
        NULL,                       /* reprfunc tp_str; */
 
1457
        NULL,                       /* getattrofunc tp_getattro; */
 
1458
        NULL,                       /* setattrofunc tp_setattro; */
 
1459
 
 
1460
        /* Functions to access object as input/output buffer */
 
1461
        NULL,                       /* PyBufferProcs *tp_as_buffer; */
 
1462
 
 
1463
  /*** Flags to define presence of optional/expanded features ***/
 
1464
        Py_TPFLAGS_DEFAULT,         /* long tp_flags; */
 
1465
 
 
1466
        NULL,                       /*  char *tp_doc;  Documentation string */
 
1467
  /*** Assigned meaning in release 2.0 ***/
 
1468
        /* call function for all accessible objects */
 
1469
        NULL,                       /* traverseproc tp_traverse; */
 
1470
 
 
1471
        /* delete references to contained objects */
 
1472
        NULL,                       /* inquiry tp_clear; */
 
1473
 
 
1474
  /***  Assigned meaning in release 2.1 ***/
 
1475
  /*** rich comparisons ***/
 
1476
        NULL,                       /* richcmpfunc tp_richcompare; */
 
1477
 
 
1478
  /***  weak reference enabler ***/
 
1479
        0,                          /* long tp_weaklistoffset; */
 
1480
 
 
1481
  /*** Added in release 2.2 ***/
 
1482
        /*   Iterators */
 
1483
        ( getiterfunc )ActionStrips_getIter, /* getiterfunc tp_iter; */
 
1484
    ( iternextfunc )ActionStrips_nextIter, /* iternextfunc tp_iternext; */
 
1485
 
 
1486
  /*** Attribute descriptor and subclassing stuff ***/
 
1487
        BPy_ActionStrips_methods,   /* struct PyMethodDef *tp_methods; */
 
1488
        NULL,                       /* struct PyMemberDef *tp_members; */
 
1489
        NULL,                       /* struct PyGetSetDef *tp_getset; */
 
1490
        NULL,                       /* struct _typeobject *tp_base; */
 
1491
        NULL,                       /* PyObject *tp_dict; */
 
1492
        NULL,                       /* descrgetfunc tp_descr_get; */
 
1493
        NULL,                       /* descrsetfunc tp_descr_set; */
 
1494
        0,                          /* long tp_dictoffset; */
 
1495
        NULL,                       /* initproc tp_init; */
 
1496
        NULL,                       /* allocfunc tp_alloc; */
 
1497
        NULL,                       /* newfunc tp_new; */
 
1498
        /*  Low-level free-memory routine */
 
1499
        NULL,                       /* freefunc tp_free;  */
 
1500
        /* For PyObject_IS_GC */
 
1501
        NULL,                       /* inquiry tp_is_gc;  */
 
1502
        NULL,                       /* PyObject *tp_bases; */
 
1503
        /* method resolution order */
 
1504
        NULL,                       /* PyObject *tp_mro;  */
 
1505
        NULL,                       /* PyObject *tp_cache; */
 
1506
        NULL,                       /* PyObject *tp_subclasses; */
 
1507
        NULL,                       /* PyObject *tp_weaklist; */
 
1508
        NULL
 
1509
};
 
1510
 
 
1511
PyObject *ActionStrips_CreatePyObject( Object *ob )
 
1512
{
 
1513
        BPy_ActionStrips *pyseq;
 
1514
        pyseq = ( BPy_ActionStrips * ) PyObject_NEW( BPy_ActionStrips,
 
1515
                        &ActionStrips_Type );
 
1516
        if( !pyseq )
 
1517
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
1518
                                              "couldn't create BPy_ActionStrips object" );
 
1519
        pyseq->ob = ob;
 
1520
        return ( PyObject * ) pyseq;
 
1521
}
 
1522
 
 
1523
/*****************************************************************************/
 
1524
/* Function:    NLA_Init                                                     */
 
1525
/*****************************************************************************/
 
1526
PyObject *NLA_Init( void )
 
1527
{
 
1528
        PyObject *FlagsDict = M_ActionStrip_FlagsDict( );
 
1529
        PyObject *AxisDict = M_ActionStrip_AxisDict( );
 
1530
        PyObject *ModeDict = M_ActionStrip_ModeDict( );
 
1531
        PyObject *submodule;
 
1532
 
 
1533
        if( PyType_Ready( &Action_Type ) < 0
 
1534
                        || PyType_Ready( &ActionStrip_Type ) < 0
 
1535
                        || PyType_Ready( &ActionStrips_Type ) < 0 )
 
1536
                return NULL;
 
1537
 
 
1538
        submodule = Py_InitModule3( "Blender.Armature.NLA",
 
1539
                                    M_NLA_methods, M_NLA_doc );
 
1540
 
 
1541
        if( FlagsDict )
 
1542
                PyModule_AddObject( submodule, "Flags", FlagsDict );
 
1543
        if( AxisDict )
 
1544
                PyModule_AddObject( submodule, "StrideAxes", AxisDict );
 
1545
        if( ModeDict )
 
1546
                PyModule_AddObject( submodule, "Modes", ModeDict );
 
1547
 
 
1548
        return submodule;
 
1549
}