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 $
4
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
* ***** BEGIN GPL LICENSE BLOCK *****
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
9
* of the License, or (at your option) any later version.
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
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 );
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,
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 );
129
/*****************************************************************************/
130
/* Python TypeAction structure definition: */
131
/*****************************************************************************/
132
PyTypeObject Action_Type = {
133
PyObject_HEAD_INIT( NULL )
135
"Blender Action", /* tp_name */
136
sizeof( BPy_Action ), /* tp_basicsize */
139
( destructor ) Action_dealloc, /* tp_dealloc */
141
( getattrfunc ) Action_getAttr, /* tp_getattr */
142
( setattrfunc ) Action_setAttr, /* tp_setattr */
144
( reprfunc ) Action_repr, /* tp_repr */
145
0, /* tp_as_number */
146
0, /* tp_as_sequence */
147
0, /* tp_as_mapping */
152
BPy_Action_methods, /* tp_methods */
156
129
/*-------------------------------------------------------------------------*/
157
130
static PyObject *M_NLA_NewAction( PyObject * self_unused, PyObject * args )
239
/*----------------------------------------------------------------------*/
240
static PyObject *Action_getName( BPy_Action * self )
242
PyObject *attr = NULL;
245
( EXPP_ReturnPyObjError( PyExc_RuntimeError,
246
"couldn't get attribute from a NULL action" ) );
248
attr = PyString_FromString( self->action->id.name + 2 );
253
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
254
"couldn't get Action.name attribute" ) );
257
/*----------------------------------------------------------------------*/
258
static PyObject *Action_setName( BPy_Action * self, PyObject * args )
264
( EXPP_ReturnPyObjError( PyExc_RuntimeError,
265
"couldn't get attribute from a NULL action" ) );
267
if( !PyArg_ParseTuple( args, "s", &name ) )
268
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
269
"expected string argument" ) );
272
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
273
rename_id( &self->action->id, buf);
278
211
static PyObject *Action_getFrameNumbers(BPy_Action *self)
280
213
bActionChannel *achan = NULL;
353
288
return Ipo_CreatePyObject( chan->ipo );
291
static PyObject *Action_getChannelNames( BPy_Action * self )
293
PyObject *list = PyList_New( BLI_countlist(&(self->action->chanbase)) );
294
bActionChannel *chan = NULL;
296
for( chan = self->action->chanbase.first; chan; chan = chan->next ) {
297
PyList_SetItem( list, index, PyString_FromString(chan->name) );
303
static PyObject *Action_renameChannel( BPy_Action * self, PyObject * args )
305
char *chanFrom, *chanTo;
306
bActionChannel *chan;
308
if( !PyArg_ParseTuple( args, "ss", &chanFrom, &chanTo ) )
309
return EXPP_ReturnPyObjError( PyExc_AttributeError,
310
"2 strings expected" );
312
chan = get_action_channel( self->action, chanFrom );
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" );
320
if (get_action_channel( self->action, chanTo ))
321
return EXPP_ReturnPyObjError( PyExc_ValueError,
322
"channel target name alredy exists" );
324
strcpy(chan->name, chanTo);
356
329
/*----------------------------------------------------------------------*/
357
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * args )
330
static PyObject *Action_verifyChannel( BPy_Action * self, PyObject * value )
332
char *chanName = PyString_AsString(value);
360
333
bActionChannel *chan;
362
335
if( !self->action )
363
336
( EXPP_ReturnPyObjError( PyExc_RuntimeError,
364
337
"couldn't create channel for a NULL action" ) );
366
if( !PyArg_ParseTuple( args, "s", &chanName ) )
367
340
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
368
341
"expected string argument" ) );
370
343
chan = verify_action_channel(self->action, chanName);
372
Py_INCREF( Py_None );
377
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args )
349
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * value )
351
char *chanName = PyString_AsString(value);
380
352
bActionChannel *chan;
382
if( !PyArg_ParseTuple( args, "s", &chanName ) ) {
383
EXPP_ReturnPyObjError( PyExc_AttributeError,
355
return (EXPP_ReturnPyObjError( PyExc_AttributeError,
356
"string expected" ));
388
359
chan = get_action_channel( self->action, chanName );
389
360
if( chan == NULL ) {
439
409
/*----------------------------------------------------------------------*/
440
static void Action_dealloc( BPy_Action * self )
442
PyObject_DEL( self );
445
/*----------------------------------------------------------------------*/
446
static PyObject *Action_getAttr( BPy_Action * self, char *name )
448
PyObject *attr = Py_None;
450
if( strcmp( name, "name" ) == 0 )
451
attr = Action_getName( self );
452
else if( strcmp( name, "__members__" ) == 0 ) {
453
attr = Py_BuildValue( "[s]", "name" );
457
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
458
"couldn't create PyObject" ) );
460
if( attr != Py_None )
461
return attr; /* member attribute found, return it */
463
/* not an attribute, search the methods table */
464
return Py_FindMethod( BPy_Action_methods, ( PyObject * ) self, name );
467
/*----------------------------------------------------------------------*/
468
static int Action_setAttr( BPy_Action * self, char *name, PyObject * value )
471
PyObject *error = NULL;
473
valtuple = Py_BuildValue( "(O)", value ); /* the set* functions expect a tuple */
476
return EXPP_ReturnIntError( PyExc_MemoryError,
477
"ActionSetAttr: couldn't create tuple" );
479
if( strcmp( name, "name" ) == 0 )
480
error = Action_setName( self, valtuple );
482
Py_DECREF( valtuple );
484
/* ... member with the given name was found */
485
return ( EXPP_ReturnIntError
486
( PyExc_KeyError, "attribute not found" ) );
489
Py_DECREF( valtuple );
491
if( error != Py_None )
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 )
412
return ( a->action == b->action ) ? 0 : -1;
498
415
/*----------------------------------------------------------------------*/
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 */
460
/*****************************************************************************/
461
/* Python TypeAction structure definition: */
462
/*****************************************************************************/
463
PyTypeObject Action_Type = {
464
PyObject_HEAD_INIT( NULL )
466
"Blender Action", /* tp_name */
467
sizeof( BPy_Action ), /* tp_basicsize */
470
NULL, /* tp_dealloc */
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 */
478
NULL, /* PyNumberMethods *tp_as_number; */
479
NULL, /* PySequenceMethods *tp_as_sequence; */
480
NULL, /* PyMappingMethods *tp_as_mapping; */
482
/* More standard operations (here for binary compatibility) */
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; */
490
/* Functions to access object as input/output buffer */
491
NULL, /* PyBufferProcs *tp_as_buffer; */
493
/*** Flags to define presence of optional/expanded features ***/
494
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
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; */
501
/* delete references to contained objects */
502
NULL, /* inquiry tp_clear; */
504
/*** Assigned meaning in release 2.1 ***/
505
/*** rich comparisons ***/
506
NULL, /* richcmpfunc tp_richcompare; */
508
/*** weak reference enabler ***/
509
0, /* long tp_weaklistoffset; */
511
/*** Added in release 2.2 ***/
513
NULL, /* getiterfunc tp_iter; */
514
NULL, /* iternextfunc tp_iternext; */
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; */
543
/*****************************************************************************/
543
544
/* ActionStrip wrapper */
544
545
/*****************************************************************************/
944
static int ActionStrip_setGroupTarget( BPy_ActionStrip * self, PyObject * args )
947
return EXPP_ReturnIntError( PyExc_RuntimeError,
948
"This strip has been removed!" );
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;
955
return EXPP_ReturnIntError( PyExc_TypeError,
956
"expected an object or None" );
929
960
/*****************************************************************************/
930
961
/* Python BPy_Constraint attributes get/set structure: */
931
962
/*****************************************************************************/