~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): Florian Ernst
  • Date: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* 
 
2
 * $Id: NLA.c,v 1.7 2004/10/07 19:25:39 stiv Exp $
2
3
 *
3
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
5
 *
34
35
#include <BKE_action.h>
35
36
#include <BKE_global.h>
36
37
#include <BKE_main.h>
 
38
 
 
39
#include "Ipo.h"
37
40
#include "Types.h"
38
41
 
39
42
/*****************************************************************************/
40
43
/* Python API function prototypes for the NLA module.                    */
41
44
/*****************************************************************************/
42
 
static PyObject *M_NLA_NewAction (PyObject * self, PyObject * args);
43
 
static PyObject *M_NLA_CopyAction (PyObject * self, PyObject * args);
44
 
static PyObject *M_NLA_GetActions(PyObject* self);
 
45
static PyObject *M_NLA_NewAction( PyObject * self, PyObject * args );
 
46
static PyObject *M_NLA_CopyAction( PyObject * self, PyObject * args );
 
47
static PyObject *M_NLA_GetActions( PyObject * self );
45
48
 
46
49
/*****************************************************************************/
47
 
/* The following string definitions are used for documentation strings.          */
 
50
/* The following string definitions are used for documentation strings.    */
48
51
/* In Python these will be written to the console when doing a           */
49
52
/* Blender.Armature.NLA.__doc__                                  */
50
53
/*****************************************************************************/
51
 
char M_NLA_doc[] = "The Blender NLA module -This module provides control over  Armature keyframing in Blender.";
52
 
char M_NLA_NewAction_doc[] = "(name) - Create new action for linking to an object.";
 
54
char M_NLA_doc[] =
 
55
        "The Blender NLA module -This module provides control over  Armature keyframing in Blender.";
 
56
char M_NLA_NewAction_doc[] =
 
57
        "(name) - Create new action for linking to an object.";
53
58
char M_NLA_CopyAction_doc[] = "(name) - Copy action and return copy.";
54
59
char M_NLA_GetActions_doc[] = "(name) - Returns a dictionary of actions.";
55
60
 
56
61
/*****************************************************************************/
57
 
/* Python method structure definition for Blender.Armature.NLA module:                   */
 
62
/* Python method structure definition for Blender.Armature.NLA module:   */
58
63
/*****************************************************************************/
59
64
struct PyMethodDef M_NLA_methods[] = {
60
 
  {"NewAction", (PyCFunction) M_NLA_NewAction, METH_VARARGS,
61
 
          M_NLA_NewAction_doc},
62
 
  {"CopyAction", (PyCFunction) M_NLA_CopyAction, METH_VARARGS,
63
 
          M_NLA_CopyAction_doc},
64
 
  {"GetActions", (PyCFunction) M_NLA_GetActions, METH_NOARGS,
65
 
          M_NLA_GetActions_doc},
66
 
  {NULL, NULL, 0, NULL}
 
65
        {"NewAction", ( PyCFunction ) M_NLA_NewAction, METH_VARARGS,
 
66
         M_NLA_NewAction_doc},
 
67
        {"CopyAction", ( PyCFunction ) M_NLA_CopyAction, METH_VARARGS,
 
68
         M_NLA_CopyAction_doc},
 
69
        {"GetActions", ( PyCFunction ) M_NLA_GetActions, METH_NOARGS,
 
70
         M_NLA_GetActions_doc},
 
71
        {NULL, NULL, 0, NULL}
67
72
};
68
73
/*****************************************************************************/
69
 
/* Python BPy_Action methods declarations:                                                                                                                                               */
 
74
/* Python BPy_Action methods declarations:                              */
70
75
/*****************************************************************************/
71
 
static PyObject *Action_getName (BPy_Action * self);
72
 
static PyObject *Action_setName (BPy_Action * self, PyObject * args);
73
 
static PyObject *Action_setActive (BPy_Action * self, PyObject * args);
74
 
static PyObject *Action_getChannelIpo(BPy_Action * self, PyObject * args);
75
 
static PyObject *Action_removeChannel(BPy_Action * self, PyObject * args);
76
 
static PyObject *Action_getAllChannelIpos(BPy_Action*self);
 
76
static PyObject *Action_getName( BPy_Action * self );
 
77
static PyObject *Action_setName( BPy_Action * self, PyObject * args );
 
78
static PyObject *Action_setActive( BPy_Action * self, PyObject * args );
 
79
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args );
 
80
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args );
 
81
static PyObject *Action_getAllChannelIpos( BPy_Action * self );
77
82
 
78
83
/*****************************************************************************/
79
84
/* Python BPy_Action methods table:                                      */
80
85
/*****************************************************************************/
81
86
static PyMethodDef BPy_Action_methods[] = {
82
 
  /* name, method, flags, doc */
83
 
  {"getName", (PyCFunction) Action_getName, METH_NOARGS,
84
 
   "() - return Action name"},
85
 
  {"setName", (PyCFunction) Action_setName, METH_VARARGS,
86
 
   "(str) - rename Action"},
87
 
  {"setActive", (PyCFunction) Action_setActive, METH_VARARGS,
88
 
   "(str) -set this action as the active action for an object"},
89
 
  {"getChannelIpo", (PyCFunction) Action_getChannelIpo, METH_VARARGS,
90
 
   "(str) -get the Ipo from a named action channel in this action"},
91
 
  {"removeChannel", (PyCFunction) Action_removeChannel, METH_VARARGS,
92
 
   "(str) -remove the channel from the action"},
93
 
  {"getAllChannelIpos", (PyCFunction)Action_getAllChannelIpos, METH_NOARGS,
94
 
        "() - Return a dict of (name:ipo)-keys containing each channel in the object's action"},
95
 
  {NULL, NULL, 0, NULL}
 
87
        /* name, method, flags, doc */
 
88
        {"getName", ( PyCFunction ) Action_getName, METH_NOARGS,
 
89
         "() - return Action name"},
 
90
        {"setName", ( PyCFunction ) Action_setName, METH_VARARGS,
 
91
         "(str) - rename Action"},
 
92
        {"setActive", ( PyCFunction ) Action_setActive, METH_VARARGS,
 
93
         "(str) -set this action as the active action for an object"},
 
94
        {"getChannelIpo", ( PyCFunction ) Action_getChannelIpo, METH_VARARGS,
 
95
         "(str) -get the Ipo from a named action channel in this action"},
 
96
        {"removeChannel", ( PyCFunction ) Action_removeChannel, METH_VARARGS,
 
97
         "(str) -remove the channel from the action"},
 
98
        {"getAllChannelIpos", ( PyCFunction ) Action_getAllChannelIpos,
 
99
         METH_NOARGS,
 
100
         "() - Return a dict of (name:ipo)-keys containing each channel in the object's action"},
 
101
        {NULL, NULL, 0, NULL}
96
102
};
97
103
 
98
104
/*****************************************************************************/
99
 
/* Python TypeAction callback function prototypes:                               */
 
105
/* Python TypeAction callback function prototypes:                          */
100
106
/*****************************************************************************/
101
 
static void Action_dealloc (BPy_Action * bone);
102
 
static PyObject *Action_getAttr (BPy_Action * bone, char *name);
103
 
static int Action_setAttr (BPy_Action * bone, char *name, PyObject * v);
104
 
static PyObject *Action_repr (BPy_Action * bone);
 
107
static void Action_dealloc( BPy_Action * bone );
 
108
static PyObject *Action_getAttr( BPy_Action * bone, char *name );
 
109
static int Action_setAttr( BPy_Action * bone, char *name, PyObject * v );
 
110
static PyObject *Action_repr( BPy_Action * bone );
105
111
 
106
112
/*****************************************************************************/
107
113
/* Python TypeAction structure definition:                               */
108
114
/*****************************************************************************/
109
115
PyTypeObject Action_Type = {
110
 
  PyObject_HEAD_INIT (NULL) 0,    /* ob_size */
111
 
  "Blender Action",                                       /* tp_name */
112
 
  sizeof (BPy_Action),                            /* tp_basicsize */
113
 
  0,                                                                      /* tp_itemsize */
114
 
  /* methods */
115
 
  (destructor) Action_dealloc,            /* tp_dealloc */
116
 
  0,                                                                     /* tp_print */
117
 
  (getattrfunc) Action_getAttr,          /* tp_getattr */
118
 
  (setattrfunc) Action_setAttr,          /* tp_setattr */
119
 
  0,                                                         /* tp_compare */
120
 
  (reprfunc) Action_repr,                            /* tp_repr */
121
 
  0,                                                                     /* tp_as_number */
122
 
  0,                                                                     /* tp_as_sequence */
123
 
  0,                                                                     /* tp_as_mapping */
124
 
  0,                                                                     /* tp_as_hash */
125
 
  0, 0, 0, 0, 0, 0,
126
 
  0,                                                                     /* tp_doc */
127
 
  0, 0, 0, 0, 0, 0,
128
 
  BPy_Action_methods,                        /* tp_methods */
129
 
  0,                                                                     /* tp_members */
 
116
        PyObject_HEAD_INIT( NULL ) 
 
117
        0,      /* ob_size */
 
118
        "Blender Action",       /* tp_name */
 
119
        sizeof( BPy_Action ),   /* tp_basicsize */
 
120
        0,                      /* tp_itemsize */
 
121
        /* methods */
 
122
        ( destructor ) Action_dealloc,  /* tp_dealloc */
 
123
        0,                      /* tp_print */
 
124
        ( getattrfunc ) Action_getAttr, /* tp_getattr */
 
125
        ( setattrfunc ) Action_setAttr, /* tp_setattr */
 
126
        0,                      /* tp_compare */
 
127
        ( reprfunc ) Action_repr,       /* tp_repr */
 
128
        0,                      /* tp_as_number */
 
129
        0,                      /* tp_as_sequence */
 
130
        0,                      /* tp_as_mapping */
 
131
        0,                      /* tp_as_hash */
 
132
        0, 0, 0, 0, 0, 0,
 
133
        0,                      /* tp_doc */
 
134
        0, 0, 0, 0, 0, 0,
 
135
        BPy_Action_methods,     /* tp_methods */
 
136
        0,                      /* tp_members */
130
137
};
131
138
 
132
 
//-------------------------------------------------------------------------------------------------------------------------------
133
 
static PyObject *
134
 
M_NLA_NewAction (PyObject * self, PyObject * args)
 
139
//-------------------------------------------------------------------------
 
140
static PyObject *M_NLA_NewAction( PyObject * self, PyObject * args )
135
141
{
136
 
  char *name_str = "DefaultAction";
137
 
  BPy_Action *py_action = NULL; /* for Action Data object wrapper in Python */
138
 
  bAction *bl_action = NULL;            /* for actual Action Data we create in Blender */
139
 
 
140
 
  if (!PyArg_ParseTuple (args, "|s", &name_str)){
141
 
    EXPP_ReturnPyObjError (PyExc_AttributeError,
142
 
                                   "expected string or nothing");
143
 
        return NULL;
144
 
  }
145
 
 
146
 
  //Create new action globally
147
 
 bl_action = alloc_libblock(&G.main->action, ID_AC, name_str);
148
 
 bl_action->id.flag |= LIB_FAKEUSER;
149
 
 bl_action->id.us++;
150
 
 
151
 
  // now create the wrapper obj in Python
152
 
  if (bl_action)                                
153
 
    py_action = (BPy_Action *) PyObject_NEW (BPy_Action, &Action_Type);
154
 
  else{
155
 
    EXPP_ReturnPyObjError (PyExc_RuntimeError,
156
 
                                   "couldn't create Action Data in Blender");
157
 
        return NULL;
158
 
  }
159
 
 
160
 
  if (py_action == NULL){
161
 
    EXPP_ReturnPyObjError (PyExc_MemoryError,
162
 
                                   "couldn't create Action Data object");
163
 
        return NULL;
164
 
  }
165
 
 
166
 
  py_action->action = bl_action;        // link Python action wrapper with Blender Action
167
 
 
168
 
  Py_INCREF(py_action);
169
 
  return (PyObject *) py_action;
 
142
        char *name_str = "DefaultAction";
 
143
        BPy_Action *py_action = NULL;   /* for Action Data object wrapper in Python */
 
144
        bAction *bl_action = NULL;      /* for actual Action Data we create in Blender */
 
145
 
 
146
        if( !PyArg_ParseTuple( args, "|s", &name_str ) ) {
 
147
                EXPP_ReturnPyObjError( PyExc_AttributeError,
 
148
                                       "expected string or nothing" );
 
149
                return NULL;
 
150
        }
 
151
        //Create new action globally
 
152
        bl_action = alloc_libblock( &G.main->action, ID_AC, name_str );
 
153
        bl_action->id.flag |= LIB_FAKEUSER;
 
154
        bl_action->id.us++;
 
155
 
 
156
        // now create the wrapper obj in Python
 
157
        if( bl_action )
 
158
                py_action =
 
159
                        ( BPy_Action * ) PyObject_NEW( BPy_Action,
 
160
                                                       &Action_Type );
 
161
        else {
 
162
                EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
163
                                       "couldn't create Action Data in Blender" );
 
164
                return NULL;
 
165
        }
 
166
 
 
167
        if( py_action == NULL ) {
 
168
                EXPP_ReturnPyObjError( PyExc_MemoryError,
 
169
                                       "couldn't create Action Data object" );
 
170
                return NULL;
 
171
        }
 
172
 
 
173
        py_action->action = bl_action;  // link Python action wrapper with Blender Action
 
174
 
 
175
        Py_INCREF( py_action );
 
176
        return ( PyObject * ) py_action;
170
177
}
171
178
 
172
 
static PyObject *
173
 
M_NLA_CopyAction(PyObject* self, PyObject * args)
 
179
static PyObject *M_NLA_CopyAction( PyObject * self, PyObject * args )
174
180
{
175
181
        BPy_Action *py_action = NULL;
176
182
        bAction *copyAction = NULL;
177
183
 
178
 
        if (!PyArg_ParseTuple (args, "O!", &Action_Type, &py_action)){
179
 
                EXPP_ReturnPyObjError (PyExc_AttributeError,
180
 
                                   "expected python action type");
 
184
        if( !PyArg_ParseTuple( args, "O!", &Action_Type, &py_action ) ) {
 
185
                EXPP_ReturnPyObjError( PyExc_AttributeError,
 
186
                                       "expected python action type" );
181
187
                return NULL;
182
 
  }
183
 
        copyAction =  copy_action(py_action->action);
184
 
        return Action_CreatePyObject (copyAction);
 
188
        }
 
189
        copyAction = copy_action( py_action->action );
 
190
        return Action_CreatePyObject( copyAction );
185
191
}
186
192
 
187
 
static PyObject *
188
 
M_NLA_GetActions(PyObject* self)
 
193
static PyObject *M_NLA_GetActions( PyObject * self )
189
194
{
190
 
        PyObject *dict=PyDict_New ();
 
195
        PyObject *dict = PyDict_New(  );
191
196
        bAction *action = NULL;
192
197
 
193
 
        for(action = G.main->action.first; action; action = action->id.next){
194
 
        PyObject * py_action = Action_CreatePyObject (action);
195
 
                if (py_action) {
 
198
        for( action = G.main->action.first; action; action = action->id.next ) {
 
199
                PyObject *py_action = Action_CreatePyObject( action );
 
200
                if( py_action ) {
196
201
                        // Insert dict entry using the bone name as key
197
 
                        if (PyDict_SetItemString (dict, action->id.name + 2, py_action) !=0) {
198
 
                                Py_DECREF (py_action);
199
 
                                Py_DECREF ( dict );
200
 
                                
201
 
                                return EXPP_ReturnPyObjError (PyExc_RuntimeError,
202
 
                                                "NLA_GetActions: couldn't set dict item");
 
202
                        if( PyDict_SetItemString
 
203
                            ( dict, action->id.name + 2, py_action ) != 0 ) {
 
204
                                Py_DECREF( py_action );
 
205
                                Py_DECREF( dict );
 
206
 
 
207
                                return EXPP_ReturnPyObjError
 
208
                                        ( PyExc_RuntimeError,
 
209
                                          "NLA_GetActions: couldn't set dict item" );
203
210
                        }
204
 
                        Py_DECREF (py_action);
 
211
                        Py_DECREF( py_action );
205
212
                } else {
206
 
                        Py_DECREF ( dict );
207
 
                        return (PythonReturnErrorObject (PyExc_RuntimeError,
208
 
                                "NLA_GetActions: could not create Action object"));
 
213
                        Py_DECREF( dict );
 
214
                        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
215
                                                        "NLA_GetActions: could not create Action object" ) );
209
216
                }
210
 
        }       
 
217
        }
211
218
        return dict;
212
219
}
213
220
 
214
221
/*****************************************************************************/
215
222
/* Function:    NLA_Init                                                 */
216
223
/*****************************************************************************/
217
 
PyObject *
218
 
NLA_Init (void)
219
 
{
220
 
  PyObject *submodule;
221
 
 
222
 
  Action_Type.ob_type = &PyType_Type;
223
 
 
224
 
  submodule = Py_InitModule3 ("Blender.Armature.NLA",
225
 
                              M_NLA_methods, M_NLA_doc);
226
 
 
227
 
  return (submodule);
228
 
}
229
 
 
230
 
//-------------------------------------------------------------------------------------------------------------------------------
231
 
static PyObject *
232
 
Action_getName (BPy_Action * self)
233
 
{
234
 
  PyObject *attr = NULL;
235
 
 
236
 
  if (!self->action)
237
 
    (EXPP_ReturnPyObjError (PyExc_RuntimeError,
238
 
                            "couldn't get attribute from a NULL action"));
239
 
 
240
 
  attr = PyString_FromString (self->action->id.name+2);
241
 
 
242
 
  if (attr)
243
 
    return attr;
244
 
 
245
 
  return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
246
 
                                 "couldn't get Action.name attribute"));
247
 
}
248
 
//-------------------------------------------------------------------------------------------------------------------------------
249
 
static PyObject *
250
 
Action_setName (BPy_Action * self, PyObject * args)
251
 
{
252
 
  char *name;
253
 
 
254
 
  if (!self->action)
255
 
    (EXPP_ReturnPyObjError (PyExc_RuntimeError,
256
 
                            "couldn't get attribute from a NULL action"));
257
 
 
258
 
  if (!PyArg_ParseTuple (args, "s", &name))
259
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
260
 
                                   "expected string argument"));
261
 
 
262
 
  //change name
263
 
  strcpy(self->action->id.name+2, name);
264
 
 
265
 
  Py_INCREF (Py_None);
266
 
  return Py_None;
267
 
}
268
 
 
269
 
static PyObject *
270
 
Action_setActive(BPy_Action * self, PyObject * args)
271
 
{
272
 
  BPy_Object *object;
273
 
 
274
 
  if (!self->action)
275
 
    (EXPP_ReturnPyObjError (PyExc_RuntimeError,
276
 
                            "couldn't get attribute from a NULL action"));
277
 
 
278
 
  if (!PyArg_ParseTuple (args, "O!", &Object_Type, &object))
279
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
280
 
                                   "expected python object argument"));
281
 
 
282
 
  if(object->object->type != OB_ARMATURE) {
283
 
    return (EXPP_ReturnPyObjError (PyExc_AttributeError,
284
 
                                   "object not of type armature"));
285
 
  }
286
 
 
287
 
  //set the active action to object
288
 
  object->object->action = self->action;
289
 
 
290
 
  Py_INCREF (Py_None);
291
 
  return Py_None;
292
 
}
293
 
 
294
 
static PyObject *
295
 
Action_getChannelIpo(BPy_Action * self, PyObject * args)
 
224
PyObject *NLA_Init( void )
 
225
{
 
226
        PyObject *submodule;
 
227
 
 
228
        Action_Type.ob_type = &PyType_Type;
 
229
 
 
230
        submodule = Py_InitModule3( "Blender.Armature.NLA",
 
231
                                    M_NLA_methods, M_NLA_doc );
 
232
 
 
233
        return ( submodule );
 
234
}
 
235
 
 
236
//----------------------------------------------------------------------
 
237
static PyObject *Action_getName( BPy_Action * self )
 
238
{
 
239
        PyObject *attr = NULL;
 
240
 
 
241
        if( !self->action )
 
242
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
243
                                         "couldn't get attribute from a NULL action" ) );
 
244
 
 
245
        attr = PyString_FromString( self->action->id.name + 2 );
 
246
 
 
247
        if( attr )
 
248
                return attr;
 
249
 
 
250
        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
251
                                        "couldn't get Action.name attribute" ) );
 
252
}
 
253
 
 
254
//----------------------------------------------------------------------
 
255
static PyObject *Action_setName( BPy_Action * self, PyObject * args )
 
256
{
 
257
        char *name;
 
258
 
 
259
        if( !self->action )
 
260
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
261
                                         "couldn't get attribute from a NULL action" ) );
 
262
 
 
263
        if( !PyArg_ParseTuple( args, "s", &name ) )
 
264
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
265
                                                "expected string argument" ) );
 
266
 
 
267
        //change name
 
268
        strcpy( self->action->id.name + 2, name );
 
269
 
 
270
        Py_INCREF( Py_None );
 
271
        return Py_None;
 
272
}
 
273
 
 
274
static PyObject *Action_setActive( BPy_Action * self, PyObject * args )
 
275
{
 
276
        BPy_Object *object;
 
277
 
 
278
        if( !self->action )
 
279
                ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
280
                                         "couldn't get attribute from a NULL action" ) );
 
281
 
 
282
        if( !PyArg_ParseTuple( args, "O!", &Object_Type, &object ) )
 
283
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
284
                                                "expected python object argument" ) );
 
285
 
 
286
        if( object->object->type != OB_ARMATURE ) {
 
287
                return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
 
288
                                                "object not of type armature" ) );
 
289
        }
 
290
        //set the active action to object
 
291
        object->object->action = self->action;
 
292
 
 
293
        Py_INCREF( Py_None );
 
294
        return Py_None;
 
295
}
 
296
 
 
297
static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args )
296
298
{
297
299
        char *chanName;
298
300
        bActionChannel *chan;
299
301
 
300
 
        if(!PyArg_ParseTuple(args, "s", &chanName)){
301
 
                EXPP_ReturnPyObjError(PyExc_AttributeError, "string expected");
302
 
                return NULL;
303
 
        }
304
 
 
305
 
        chan = get_named_actionchannel(self->action,chanName);
306
 
        if(chan == NULL){
307
 
                EXPP_ReturnPyObjError(PyExc_AttributeError, "no channel with that name...");
308
 
                return NULL;
309
 
        }
310
 
 
 
302
        if( !PyArg_ParseTuple( args, "s", &chanName ) ) {
 
303
                EXPP_ReturnPyObjError( PyExc_AttributeError,
 
304
                                       "string expected" );
 
305
                return NULL;
 
306
        }
 
307
 
 
308
        chan = get_named_actionchannel( self->action, chanName );
 
309
        if( chan == NULL ) {
 
310
                EXPP_ReturnPyObjError( PyExc_AttributeError,
 
311
                                       "no channel with that name..." );
 
312
                return NULL;
 
313
        }
311
314
        //return IPO
312
 
    return Ipo_CreatePyObject (chan->ipo);
 
315
        return Ipo_CreatePyObject( chan->ipo );
313
316
}
314
317
 
315
 
static PyObject *
316
 
Action_removeChannel(BPy_Action * self, PyObject * args)
 
318
static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args )
317
319
{
318
320
        char *chanName;
319
321
        bActionChannel *chan;
320
322
 
321
 
        if(!PyArg_ParseTuple(args, "s", &chanName)){
322
 
                EXPP_ReturnPyObjError(PyExc_AttributeError, "string expected");
323
 
                return NULL;
324
 
        }
325
 
 
326
 
        chan = get_named_actionchannel(self->action,chanName);
327
 
        if(chan == NULL){
328
 
                EXPP_ReturnPyObjError(PyExc_AttributeError, "no channel with that name...");
329
 
                return NULL;
330
 
        }
331
 
 
 
323
        if( !PyArg_ParseTuple( args, "s", &chanName ) ) {
 
324
                EXPP_ReturnPyObjError( PyExc_AttributeError,
 
325
                                       "string expected" );
 
326
                return NULL;
 
327
        }
 
328
 
 
329
        chan = get_named_actionchannel( self->action, chanName );
 
330
        if( chan == NULL ) {
 
331
                EXPP_ReturnPyObjError( PyExc_AttributeError,
 
332
                                       "no channel with that name..." );
 
333
                return NULL;
 
334
        }
332
335
        //release ipo
333
 
        if(chan->ipo)
 
336
        if( chan->ipo )
334
337
                chan->ipo->id.us--;
335
338
 
336
339
        //remove channel
337
 
        BLI_freelinkN (&self->action->chanbase, chan);
 
340
        BLI_freelinkN( &self->action->chanbase, chan );
338
341
 
339
 
        Py_INCREF (Py_None);
340
 
        return (Py_None);
 
342
        Py_INCREF( Py_None );
 
343
        return ( Py_None );
341
344
}
342
345
 
343
 
static PyObject *Action_getAllChannelIpos (BPy_Action *self)
 
346
static PyObject *Action_getAllChannelIpos( BPy_Action * self )
344
347
{
345
 
        PyObject *dict=PyDict_New ();
 
348
        PyObject *dict = PyDict_New(  );
346
349
        bActionChannel *chan = NULL;
347
350
 
348
 
        for(chan = self->action->chanbase.first; chan; chan = chan->next){
349
 
        PyObject * ipo_attr = Ipo_CreatePyObject (chan->ipo);
350
 
                if (ipo_attr) {
 
351
        for( chan = self->action->chanbase.first; chan; chan = chan->next ) {
 
352
                PyObject *ipo_attr = Ipo_CreatePyObject( chan->ipo );
 
353
                if( ipo_attr ) {
351
354
                        // Insert dict entry using the bone name as key
352
 
                        if (PyDict_SetItemString (dict, chan->name, ipo_attr) !=0) {
353
 
                                Py_DECREF ( ipo_attr );
354
 
                                Py_DECREF ( dict );
355
 
                                
356
 
                                return EXPP_ReturnPyObjError (PyExc_RuntimeError,
357
 
                                                "Action_getAllChannelIpos: couldn't set dict item");
 
355
                        if( PyDict_SetItemString( dict, chan->name, ipo_attr )
 
356
                            != 0 ) {
 
357
                                Py_DECREF( ipo_attr );
 
358
                                Py_DECREF( dict );
 
359
 
 
360
                                return EXPP_ReturnPyObjError
 
361
                                        ( PyExc_RuntimeError,
 
362
                                          "Action_getAllChannelIpos: couldn't set dict item" );
358
363
                        }
359
 
                        Py_DECREF (ipo_attr);
 
364
                        Py_DECREF( ipo_attr );
360
365
                } else {
361
 
                        Py_DECREF ( dict );
362
 
                        return (PythonReturnErrorObject (PyExc_RuntimeError,
363
 
                                "Action_getAllChannelIpos: could not create Ipo object"));
 
366
                        Py_DECREF( dict );
 
367
                        return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
368
                                                        "Action_getAllChannelIpos: could not create Ipo object" ) );
364
369
                }
365
 
        }       
 
370
        }
366
371
        return dict;
367
372
}
368
373
 
369
 
//-------------------------------------------------------------------------------------------------------------------------------
370
 
static void
371
 
Action_dealloc (BPy_Action * self)
372
 
{
373
 
    PyObject_DEL (self);
374
 
}
375
 
//-------------------------------------------------------------------------------------------------------------------------------
376
 
static PyObject *
377
 
Action_getAttr (BPy_Action * self, char *name)
378
 
{
379
 
  PyObject *attr = Py_None;
380
 
 
381
 
  if (strcmp (name, "name") == 0)
382
 
    attr = Action_getName (self);
383
 
  else if (strcmp (name, "__members__") == 0)  {
384
 
      attr = Py_BuildValue ("[s]",
385
 
                            "name");
386
 
    }
387
 
 
388
 
  if (!attr)
389
 
    return (EXPP_ReturnPyObjError (PyExc_MemoryError,
390
 
                                   "couldn't create PyObject"));
391
 
 
392
 
  if (attr != Py_None)
393
 
    return attr;                /* member attribute found, return it */
394
 
 
395
 
  /* not an attribute, search the methods table */
396
 
  return Py_FindMethod (BPy_Action_methods, (PyObject *) self, name);
397
 
}
398
 
 
399
 
//-------------------------------------------------------------------------------------------------------------------------------
400
 
static int
401
 
Action_setAttr (BPy_Action * self, char *name, PyObject * value)
402
 
{
403
 
  PyObject *valtuple;
404
 
  PyObject *error = NULL;
405
 
 
406
 
  valtuple = Py_BuildValue ("(O)", value);      /* the set* functions expect a tuple */
407
 
 
408
 
  if (!valtuple)
409
 
    return EXPP_ReturnIntError (PyExc_MemoryError,
410
 
                                "ActionSetAttr: couldn't create tuple");
411
 
 
412
 
  if (strcmp (name, "name") == 0)
413
 
    error = Action_setName (self, valtuple);
414
 
  else
415
 
    {                           /* Error */
416
 
      Py_DECREF (valtuple);
417
 
 
418
 
      /* ... member with the given name was found */
419
 
      return (EXPP_ReturnIntError (PyExc_KeyError, "attribute not found"));
420
 
    }
421
 
 
422
 
  Py_DECREF (valtuple);
423
 
 
424
 
  if (error != Py_None)
425
 
    return -1;
426
 
 
427
 
  Py_DECREF (Py_None);          /* was incref'ed by the called Action_set* function */
428
 
  return 0;                     /* normal exit */
429
 
}
430
 
//-------------------------------------------------------------------------------------------------------------------------------
431
 
static PyObject *
432
 
Action_repr (BPy_Action * self)
433
 
{
434
 
  if (self->action)
435
 
    return PyString_FromFormat ("[Action \"%s\"]", self->action->id.name + 2);
436
 
  else
437
 
    return PyString_FromString ("NULL");
438
 
}
439
 
//-------------------------------------------------------------------------------------------------------------------------------
440
 
PyObject *
441
 
Action_CreatePyObject (struct bAction * act)
442
 
{
443
 
  BPy_Action *blen_action;
444
 
 
445
 
  blen_action = (BPy_Action *) PyObject_NEW (BPy_Action, &Action_Type);
446
 
 
447
 
  if (blen_action == NULL)
448
 
    {
449
 
      return (NULL);
450
 
    }
451
 
  blen_action->action   = act;
452
 
  return ((PyObject *) blen_action);
453
 
}
454
 
//-------------------------------------------------------------------------------------------------------------------------------
455
 
int
456
 
Action_CheckPyObject (PyObject * py_obj)
457
 
{
458
 
  return (py_obj->ob_type == &Action_Type);
459
 
}
460
 
//-------------------------------------------------------------------------------------------------------------------------------
461
 
struct bAction *
462
 
Action_FromPyObject (PyObject * py_obj)
463
 
{
464
 
  BPy_Action *blen_obj;
465
 
 
466
 
  blen_obj = (BPy_Action *) py_obj;
467
 
  return (blen_obj->action);
 
374
//----------------------------------------------------------------------
 
375
static void Action_dealloc( BPy_Action * self )
 
376
{
 
377
        PyObject_DEL( self );
 
378
}
 
379
 
 
380
//----------------------------------------------------------------------
 
381
static PyObject *Action_getAttr( BPy_Action * self, char *name )
 
382
{
 
383
        PyObject *attr = Py_None;
 
384
 
 
385
        if( strcmp( name, "name" ) == 0 )
 
386
                attr = Action_getName( self );
 
387
        else if( strcmp( name, "__members__" ) == 0 ) {
 
388
                attr = Py_BuildValue( "[s]", "name" );
 
389
        }
 
390
 
 
391
        if( !attr )
 
392
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
393
                                                "couldn't create PyObject" ) );
 
394
 
 
395
        if( attr != Py_None )
 
396
                return attr;    /* member attribute found, return it */
 
397
 
 
398
        /* not an attribute, search the methods table */
 
399
        return Py_FindMethod( BPy_Action_methods, ( PyObject * ) self, name );
 
400
}
 
401
 
 
402
//----------------------------------------------------------------------
 
403
static int Action_setAttr( BPy_Action * self, char *name, PyObject * value )
 
404
{
 
405
        PyObject *valtuple;
 
406
        PyObject *error = NULL;
 
407
 
 
408
        valtuple = Py_BuildValue( "(O)", value );       /* the set* functions expect a tuple */
 
409
 
 
410
        if( !valtuple )
 
411
                return EXPP_ReturnIntError( PyExc_MemoryError,
 
412
                                            "ActionSetAttr: couldn't create tuple" );
 
413
 
 
414
        if( strcmp( name, "name" ) == 0 )
 
415
                error = Action_setName( self, valtuple );
 
416
        else {                  /* Error */
 
417
                Py_DECREF( valtuple );
 
418
 
 
419
                /* ... member with the given name was found */
 
420
                return ( EXPP_ReturnIntError
 
421
                         ( PyExc_KeyError, "attribute not found" ) );
 
422
        }
 
423
 
 
424
        Py_DECREF( valtuple );
 
425
 
 
426
        if( error != Py_None )
 
427
                return -1;
 
428
 
 
429
        Py_DECREF( Py_None );   /* was incref'ed by the called Action_set* function */
 
430
        return 0;               /* normal exit */
 
431
}
 
432
 
 
433
//----------------------------------------------------------------------
 
434
static PyObject *Action_repr( BPy_Action * self )
 
435
{
 
436
        if( self->action )
 
437
                return PyString_FromFormat( "[Action \"%s\"]",
 
438
                                            self->action->id.name + 2 );
 
439
        else
 
440
                return PyString_FromString( "NULL" );
 
441
}
 
442
 
 
443
//----------------------------------------------------------------------
 
444
PyObject *Action_CreatePyObject( struct bAction * act )
 
445
{
 
446
        BPy_Action *blen_action;
 
447
 
 
448
        blen_action =
 
449
                ( BPy_Action * ) PyObject_NEW( BPy_Action, &Action_Type );
 
450
 
 
451
        if( blen_action == NULL ) {
 
452
                return ( NULL );
 
453
        }
 
454
        blen_action->action = act;
 
455
        return ( ( PyObject * ) blen_action );
 
456
}
 
457
 
 
458
//-------------------------------------------------------------------------------------------------------------------------------
 
459
int Action_CheckPyObject( PyObject * py_obj )
 
460
{
 
461
        return ( py_obj->ob_type == &Action_Type );
 
462
}
 
463
 
 
464
//----------------------------------------------------------------------
 
465
struct bAction *Action_FromPyObject( PyObject * py_obj )
 
466
{
 
467
        BPy_Action *blen_obj;
 
468
 
 
469
        blen_obj = ( BPy_Action * ) py_obj;
 
470
        return ( blen_obj->action );
468
471
}