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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Ipo.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: Ipo.c,v 1.40 2005/05/24 15:14:32 stiv Exp $
2
3
 *
3
4
 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
4
5
 *
24
25
 *
25
26
 * This is a new part of Blender.
26
27
 *
27
 
 * Contributor(s): Jacques Guignot
 
28
 * Contributor(s): Jacques Guignot RIP 2005, Nathan Letwory, 
 
29
 *  Stephen Swaney, Ken Hughes
28
30
 *
29
31
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
32
 */
35
37
#include <BKE_global.h>
36
38
#include <BKE_object.h>
37
39
#include <BKE_library.h>
 
40
#include <BSE_editipo.h>
38
41
#include <BLI_blenlib.h>
 
42
#include <BIF_space.h>
 
43
#include <BSE_editipo.h>
 
44
#include <mydevice.h>
 
45
#include <DNA_curve_types.h>
 
46
#include <MEM_guardedalloc.h>
39
47
 
 
48
#include "Ipocurve.h"
40
49
#include "constant.h"
41
50
#include "gen_utils.h"
42
 
#include "modules.h"
43
 
 
44
 
 
45
 
/* forward declarations */
46
 
void GetIpoCurveName (IpoCurve * icu, char *s);
47
 
void getname_mat_ei (int nr, char *str);
48
 
void getname_world_ei (int nr, char *str);
49
 
void getname_cam_ei (int nr, char *str);
50
 
void getname_ob_ei (int nr, char *str);
51
51
 
52
52
/*****************************************************************************/
53
53
/* Python API function prototypes for the Ipo module.                        */
54
54
/*****************************************************************************/
55
 
static PyObject *M_Ipo_New (PyObject * self, PyObject * args);
56
 
static PyObject *M_Ipo_Get (PyObject * self, PyObject * args);
57
 
static PyObject *M_Ipo_Recalc (PyObject * self, PyObject * args);
 
55
static PyObject *M_Ipo_New( PyObject * self, PyObject * args );
 
56
static PyObject *M_Ipo_Get( PyObject * self, PyObject * args );
 
57
static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args );
58
58
 
59
59
/*****************************************************************************/
60
60
/* The following string definitions are used for documentation strings.      */
71
71
/*****************************************************************************/
72
72
 
73
73
struct PyMethodDef M_Ipo_methods[] = {
74
 
  {"New", (PyCFunction) M_Ipo_New, METH_VARARGS | METH_KEYWORDS,
75
 
   M_Ipo_New_doc},
76
 
  {"Get", M_Ipo_Get, METH_VARARGS, M_Ipo_Get_doc},
77
 
  {"get", M_Ipo_Get, METH_VARARGS, M_Ipo_Get_doc},
78
 
  {"Recalc", M_Ipo_Recalc, METH_VARARGS, M_Ipo_Get_doc},
79
 
  {NULL, NULL, 0, NULL}
 
74
        {"New", ( PyCFunction ) M_Ipo_New, METH_VARARGS | METH_KEYWORDS,
 
75
         M_Ipo_New_doc},
 
76
        {"Get", M_Ipo_Get, METH_VARARGS, M_Ipo_Get_doc},
 
77
        {"get", M_Ipo_Get, METH_VARARGS, M_Ipo_Get_doc},
 
78
        {"Recalc", M_Ipo_Recalc, METH_VARARGS, M_Ipo_Get_doc},
 
79
        {NULL, NULL, 0, NULL}
80
80
};
81
81
 
82
82
/*****************************************************************************/
83
83
/* Python BPy_Ipo methods declarations:                                     */
84
84
/*****************************************************************************/
85
 
static PyObject *Ipo_getName (BPy_Ipo * self);
86
 
static PyObject *Ipo_setName (BPy_Ipo * self, PyObject * args);
87
 
static PyObject *Ipo_getBlocktype (BPy_Ipo * self);
88
 
static PyObject *Ipo_setBlocktype (BPy_Ipo * self, PyObject * args);
89
 
static PyObject *Ipo_getRctf (BPy_Ipo * self);
90
 
static PyObject *Ipo_setRctf (BPy_Ipo * self, PyObject * args);
91
 
 
92
 
static PyObject *Ipo_getCurve (BPy_Ipo * self, PyObject * args);
93
 
static PyObject *Ipo_getCurves (BPy_Ipo * self);
94
 
static PyObject *Ipo_addCurve (BPy_Ipo * self, PyObject * args);
95
 
static PyObject *Ipo_getNcurves (BPy_Ipo * self);
96
 
static PyObject *Ipo_getNBezPoints (BPy_Ipo * self, PyObject * args);
97
 
static PyObject *Ipo_DeleteBezPoints (BPy_Ipo * self, PyObject * args);
98
 
static PyObject *Ipo_getCurveBP (BPy_Ipo * self, PyObject * args);
99
 
static PyObject *Ipo_getCurvecurval (BPy_Ipo * self, PyObject * args);
100
 
static PyObject *Ipo_EvaluateCurveOn (BPy_Ipo * self, PyObject * args);
101
 
 
102
 
 
103
 
static PyObject *Ipo_setCurveBeztriple (BPy_Ipo * self, PyObject * args);
104
 
static PyObject *Ipo_getCurveBeztriple (BPy_Ipo * self, PyObject * args);
 
85
static PyObject *Ipo_getName( BPy_Ipo * self );
 
86
static PyObject *Ipo_setName( BPy_Ipo * self, PyObject * args );
 
87
static PyObject *Ipo_getBlocktype( BPy_Ipo * self );
 
88
static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args );
 
89
static PyObject *Ipo_getRctf( BPy_Ipo * self );
 
90
static PyObject *Ipo_setRctf( BPy_Ipo * self, PyObject * args );
 
91
 
 
92
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args );
 
93
static PyObject *Ipo_getCurves( BPy_Ipo * self );
 
94
static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args );
 
95
static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args );
 
96
static PyObject *Ipo_getNcurves( BPy_Ipo * self );
 
97
static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args );
 
98
static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args );
 
99
static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args );
 
100
static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args );
 
101
static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args );
 
102
 
 
103
 
 
104
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args );
 
105
static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args );
105
106
 
106
107
/*****************************************************************************/
107
108
/* Python BPy_Ipo methods table:                                            */
108
109
/*****************************************************************************/
109
110
static PyMethodDef BPy_Ipo_methods[] = {
110
 
  /* name, method, flags, doc */
111
 
  {"getName", (PyCFunction) Ipo_getName, METH_NOARGS,
112
 
   "() - Return Ipo Data name"},
113
 
  {"setName", (PyCFunction) Ipo_setName, METH_VARARGS,
114
 
   "(str) - Change Ipo Data name"},
115
 
  {"getBlocktype", (PyCFunction) Ipo_getBlocktype, METH_NOARGS,
116
 
   "() - Return Ipo blocktype -"},
117
 
  {"setBlocktype", (PyCFunction) Ipo_setBlocktype, METH_VARARGS,
118
 
   "(str) - Change Ipo blocktype"},
119
 
  {"getRctf", (PyCFunction) Ipo_getRctf, METH_NOARGS,
120
 
   "() - Return Ipo rctf - "},
121
 
  {"setRctf", (PyCFunction) Ipo_setRctf, METH_VARARGS,
122
 
   "(str) - Change Ipo rctf"},
123
 
  {"addCurve", (PyCFunction) Ipo_addCurve, METH_VARARGS,
124
 
   "() - Return Ipo ncurves"},
125
 
  {"getNcurves", (PyCFunction) Ipo_getNcurves, METH_NOARGS,
126
 
   "() - Return Ipo ncurves"},
127
 
  {"getNBezPoints", (PyCFunction) Ipo_getNBezPoints, METH_VARARGS,
128
 
   "() - Return curve number of Bez points"},
129
 
  {"delBezPoint", (PyCFunction) Ipo_DeleteBezPoints, METH_VARARGS,
130
 
   "() - Return curve number of Bez points"},
131
 
  {"getCurveBP", (PyCFunction) Ipo_getCurveBP, METH_VARARGS,
132
 
   "() - Return Ipo ncurves"},
133
 
  {"EvaluateCurveOn", (PyCFunction) Ipo_EvaluateCurveOn, METH_VARARGS,
134
 
   "() - Return curve value at given time"},
135
 
  {"getCurveCurval", (PyCFunction) Ipo_getCurvecurval, METH_VARARGS,
136
 
   "() - Return curval"},
137
 
  {"getCurveBeztriple", (PyCFunction) Ipo_getCurveBeztriple, METH_VARARGS,
138
 
   "() - Return Ipo ncurves"},
139
 
  {"setCurveBeztriple", (PyCFunction) Ipo_setCurveBeztriple, METH_VARARGS,
140
 
   "() - Return curval"},
141
 
  {"getCurves", (PyCFunction) Ipo_getCurves, METH_NOARGS,
142
 
   "() - Return curval"},
143
 
  {"getCurve", (PyCFunction) Ipo_getCurve, METH_VARARGS,
144
 
   "() - Return curval"},
145
 
  {NULL, NULL, 0, NULL}
 
111
        /* name, method, flags, doc */
 
112
        {"getName", ( PyCFunction ) Ipo_getName, METH_NOARGS,
 
113
         "() - Return Ipo Data name"},
 
114
        {"setName", ( PyCFunction ) Ipo_setName, METH_VARARGS,
 
115
         "(str) - Change Ipo Data name"},
 
116
        {"getBlocktype", ( PyCFunction ) Ipo_getBlocktype, METH_NOARGS,
 
117
         "() - Return Ipo blocktype -"},
 
118
        {"setBlocktype", ( PyCFunction ) Ipo_setBlocktype, METH_VARARGS,
 
119
         "(str) - Change Ipo blocktype"},
 
120
        {"getRctf", ( PyCFunction ) Ipo_getRctf, METH_NOARGS,
 
121
         "() - Return Ipo rctf - "},
 
122
        {"setRctf", ( PyCFunction ) Ipo_setRctf, METH_VARARGS,
 
123
         "(str) - Change Ipo rctf"},
 
124
        {"addCurve", ( PyCFunction ) Ipo_addCurve, METH_VARARGS,
 
125
         "() - Return Ipo ncurves"},
 
126
        {"delCurve", ( PyCFunction ) Ipo_delCurve, METH_VARARGS,
 
127
         "() - Delete Ipo curves"},
 
128
        {"getNcurves", ( PyCFunction ) Ipo_getNcurves, METH_NOARGS,
 
129
         "() - Return Ipo ncurves"},
 
130
        {"getNBezPoints", ( PyCFunction ) Ipo_getNBezPoints, METH_VARARGS,
 
131
         "() - Return curve number of Bez points"},
 
132
        {"delBezPoint", ( PyCFunction ) Ipo_DeleteBezPoints, METH_VARARGS,
 
133
         "() - Return curve number of Bez points"},
 
134
        {"getCurveBP", ( PyCFunction ) Ipo_getCurveBP, METH_VARARGS,
 
135
         "() - Return Ipo ncurves"},
 
136
        {"EvaluateCurveOn", ( PyCFunction ) Ipo_EvaluateCurveOn, METH_VARARGS,
 
137
         "() - Return curve value at given time"},
 
138
        {"getCurveCurval", ( PyCFunction ) Ipo_getCurvecurval, METH_VARARGS,
 
139
         "() - Return curval"},
 
140
        {"getCurveBeztriple", ( PyCFunction ) Ipo_getCurveBeztriple,
 
141
         METH_VARARGS,
 
142
         "() - Return Ipo ncurves"},
 
143
        {"setCurveBeztriple", ( PyCFunction ) Ipo_setCurveBeztriple,
 
144
         METH_VARARGS,
 
145
         "() - Return curval"},
 
146
        {"getCurves", ( PyCFunction ) Ipo_getCurves, METH_NOARGS,
 
147
         "() - Return curval"},
 
148
        {"getCurve", ( PyCFunction ) Ipo_getCurve, METH_VARARGS,
 
149
         "() - Return curval"},
 
150
        {NULL, NULL, 0, NULL}
146
151
};
147
152
 
148
153
/*****************************************************************************/
149
154
/* Python Ipo_Type callback function prototypes:                          */
150
155
/*****************************************************************************/
151
 
static void IpoDeAlloc (BPy_Ipo * self);
 
156
static void IpoDeAlloc( BPy_Ipo * self );
152
157
//static int IpoPrint (BPy_Ipo *self, FILE *fp, int flags);
153
 
static int IpoSetAttr (BPy_Ipo * self, char *name, PyObject * v);
154
 
static PyObject *IpoGetAttr (BPy_Ipo * self, char *name);
155
 
static PyObject *IpoRepr (BPy_Ipo * self);
 
158
static int IpoSetAttr( BPy_Ipo * self, char *name, PyObject * v );
 
159
static PyObject *IpoGetAttr( BPy_Ipo * self, char *name );
 
160
static PyObject *IpoRepr( BPy_Ipo * self );
156
161
 
157
162
/*****************************************************************************/
158
163
/* Python Ipo_Type structure definition:                                  */
159
164
/*****************************************************************************/
160
165
PyTypeObject Ipo_Type = {
161
 
  PyObject_HEAD_INIT (NULL) 0,  /* ob_size */
162
 
  "Ipo",                        /* tp_name */
163
 
  sizeof (BPy_Ipo),             /* tp_basicsize */
164
 
  0,                            /* tp_itemsize */
165
 
  /* methods */
166
 
  (destructor) IpoDeAlloc,      /* tp_dealloc */
167
 
  0,                            /* tp_print */
168
 
  (getattrfunc) IpoGetAttr,     /* tp_getattr */
169
 
  (setattrfunc) IpoSetAttr,     /* tp_setattr */
170
 
  0,                            /* tp_compare */
171
 
  (reprfunc) IpoRepr,           /* tp_repr */
172
 
  0,                            /* tp_as_number */
173
 
  0,                            /* tp_as_sequence */
174
 
  0,                            /* tp_as_mapping */
175
 
  0,                            /* tp_as_hash */
176
 
  0, 0, 0, 0, 0, 0,
177
 
  0,                            /* tp_doc */
178
 
  0, 0, 0, 0, 0, 0,
179
 
  BPy_Ipo_methods,              /* tp_methods */
180
 
  0,                            /* tp_members */
 
166
        PyObject_HEAD_INIT( NULL ) /* required macro */ 0,      /* ob_size */
 
167
        "Ipo",                  /* tp_name */
 
168
        sizeof( BPy_Ipo ),      /* tp_basicsize */
 
169
        0,                      /* tp_itemsize */
 
170
        /* methods */
 
171
        ( destructor ) IpoDeAlloc,      /* tp_dealloc */
 
172
        0,                      /* tp_print */
 
173
        ( getattrfunc ) IpoGetAttr,     /* tp_getattr */
 
174
        ( setattrfunc ) IpoSetAttr,     /* tp_setattr */
 
175
        0,                      /* tp_compare */
 
176
        ( reprfunc ) IpoRepr,   /* tp_repr */
 
177
        0,                      /* tp_as_number */
 
178
        0,                      /* tp_as_sequence */
 
179
        0,                      /* tp_as_mapping */
 
180
        0,                      /* tp_as_hash */
 
181
        0, 0, 0, 0, 0, 0,
 
182
        0,                      /* tp_doc */
 
183
        0, 0, 0, 0, 0, 0,
 
184
        BPy_Ipo_methods,        /* tp_methods */
 
185
        0,                      /* tp_members */
181
186
};
182
187
 
183
188
/*****************************************************************************/
185
190
/* Python equivalent:     Blender.Ipo.New                                    */
186
191
/*****************************************************************************/
187
192
 
188
 
static PyObject *
189
 
M_Ipo_New (PyObject * self, PyObject * args)
 
193
static PyObject *M_Ipo_New( PyObject * self, PyObject * args )
190
194
{
191
 
  Ipo *add_ipo (char *name, int idcode);
192
 
  char *name = NULL, *code = NULL;
193
 
  int idcode = -1;
194
 
  BPy_Ipo *pyipo;
195
 
  Ipo *blipo;
196
 
 
197
 
  if (!PyArg_ParseTuple (args, "ss", &code, &name))
198
 
    return (EXPP_ReturnPyObjError
199
 
            (PyExc_TypeError, "expected string string arguments"));
200
 
 
201
 
  if (!strcmp (code, "Object"))
202
 
    idcode = ID_OB;
203
 
  if (!strcmp (code, "Camera"))
204
 
    idcode = ID_CA;
205
 
  if (!strcmp (code, "World"))
206
 
    idcode = ID_WO;
207
 
  if (!strcmp (code, "Material"))
208
 
    idcode = ID_MA;
209
 
 
210
 
  if (idcode == -1)
211
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "Bad code"));
212
 
 
213
 
 
214
 
  blipo = add_ipo (name, idcode);
215
 
 
216
 
  if (blipo)
217
 
    {
218
 
      /* return user count to zero because add_ipo() inc'd it */
219
 
      blipo->id.us = 0;
220
 
      /* create python wrapper obj */
221
 
      pyipo = (BPy_Ipo *) PyObject_NEW (BPy_Ipo, &Ipo_Type);
222
 
    }
223
 
  else
224
 
    return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
225
 
                                   "couldn't create Ipo Data in Blender"));
226
 
 
227
 
  if (pyipo == NULL)
228
 
    return (EXPP_ReturnPyObjError (PyExc_MemoryError,
229
 
                                   "couldn't create Ipo Data object"));
230
 
 
231
 
  pyipo->ipo = blipo;
232
 
 
233
 
  return (PyObject *) pyipo;
 
195
        Ipo *add_ipo( char *name, int idcode );
 
196
        char *name = NULL, *code = NULL;
 
197
        int idcode = -1;
 
198
        BPy_Ipo *pyipo;
 
199
        Ipo *blipo;
 
200
 
 
201
        if( !PyArg_ParseTuple( args, "ss", &code, &name ) )
 
202
                return ( EXPP_ReturnPyObjError
 
203
                         ( PyExc_TypeError,
 
204
                           "expected string string arguments" ) );
 
205
 
 
206
        if( !strcmp( code, "Object" ) )
 
207
                idcode = ID_OB;
 
208
        if( !strcmp( code, "Camera" ) )
 
209
                idcode = ID_CA;
 
210
        if( !strcmp( code, "World" ) )
 
211
                idcode = ID_WO;
 
212
        if( !strcmp( code, "Material" ) )
 
213
                idcode = ID_MA;
 
214
        if( !strcmp( code, "Texture" ) )
 
215
                idcode = ID_TE;
 
216
        if( !strcmp( code, "Lamp" ) )
 
217
                idcode = ID_LA;
 
218
        if( !strcmp( code, "Action" ) )
 
219
                idcode = ID_AC;
 
220
        if( !strcmp( code, "Constraint" ) )
 
221
                idcode = IPO_CO;
 
222
        if( !strcmp( code, "Sequence" ) )
 
223
                idcode = ID_SEQ;
 
224
        if( !strcmp( code, "Curve" ) )
 
225
                idcode = ID_CU;
 
226
        if( !strcmp( code, "Key" ) )
 
227
                idcode = ID_KE;
 
228
 
 
229
        if( idcode == -1 )
 
230
                return ( EXPP_ReturnPyObjError
 
231
                         ( PyExc_TypeError, "Bad code" ) );
 
232
 
 
233
 
 
234
        blipo = add_ipo( name, idcode );
 
235
 
 
236
        if( blipo ) {
 
237
                /* return user count to zero because add_ipo() inc'd it */
 
238
                blipo->id.us = 0;
 
239
                /* create python wrapper obj */
 
240
                pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
 
241
        } else
 
242
                return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
 
243
                                                "couldn't create Ipo Data in Blender" ) );
 
244
 
 
245
        if( pyipo == NULL )
 
246
                return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
247
                                                "couldn't create Ipo Data object" ) );
 
248
 
 
249
        pyipo->ipo = blipo;
 
250
 
 
251
        return ( PyObject * ) pyipo;
234
252
}
235
253
 
236
254
/*****************************************************************************/
241
259
/*                        passed in, a list of all ipo data names in the  */
242
260
/*                        current scene is returned.                         */
243
261
/*****************************************************************************/
244
 
static PyObject *
245
 
M_Ipo_Get (PyObject * self, PyObject * args)
 
262
static PyObject *M_Ipo_Get( PyObject * self, PyObject * args )
246
263
{
247
 
  char *name = NULL;
248
 
  Ipo *ipo_iter;
249
 
  PyObject *ipolist, *pyobj;
250
 
  BPy_Ipo *wanted_ipo = NULL;
251
 
  char error_msg[64];
252
 
 
253
 
  if (!PyArg_ParseTuple (args, "|s", &name))
254
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError,
255
 
                                   "expected string argument (or nothing)"));
256
 
 
257
 
  ipo_iter = G.main->ipo.first;
258
 
 
259
 
  if (name)
260
 
    {                           /* (name) - Search ipo by name */
261
 
      while ((ipo_iter) && (wanted_ipo == NULL))
262
 
        {
263
 
          if (strcmp (name, ipo_iter->id.name + 2) == 0)
264
 
            {
265
 
              wanted_ipo = (BPy_Ipo *) PyObject_NEW (BPy_Ipo, &Ipo_Type);
266
 
              if (wanted_ipo)
267
 
                wanted_ipo->ipo = ipo_iter;
268
 
            }
269
 
          ipo_iter = ipo_iter->id.next;
270
 
        }
271
 
 
272
 
      if (wanted_ipo == NULL)
273
 
        {                       /* Requested ipo doesn't exist */
274
 
          PyOS_snprintf (error_msg, sizeof (error_msg),
275
 
                         "Ipo \"%s\" not found", name);
276
 
          return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
277
 
        }
278
 
 
279
 
      return (PyObject *) wanted_ipo;
280
 
    }
281
 
 
282
 
  else
283
 
    {                           /* () - return a list with all ipos in the scene */
284
 
      int index = 0;
285
 
 
286
 
      ipolist = PyList_New (BLI_countlist (&(G.main->ipo)));
287
 
 
288
 
      if (ipolist == NULL)
289
 
        return (PythonReturnErrorObject (PyExc_MemoryError,
290
 
                                         "couldn't create PyList"));
291
 
 
292
 
      while (ipo_iter)
293
 
        {
294
 
          pyobj = Ipo_CreatePyObject (ipo_iter);
295
 
 
296
 
          if (!pyobj)
297
 
            return (PythonReturnErrorObject (PyExc_MemoryError,
298
 
                                             "couldn't create PyString"));
299
 
 
300
 
          PyList_SET_ITEM (ipolist, index, pyobj);
301
 
 
302
 
          ipo_iter = ipo_iter->id.next;
303
 
          index++;
304
 
        }
305
 
 
306
 
      return (ipolist);
307
 
    }
 
264
        char *name = NULL;
 
265
        Ipo *ipo_iter;
 
266
        PyObject *ipolist, *pyobj;
 
267
        BPy_Ipo *wanted_ipo = NULL;
 
268
        char error_msg[64];
 
269
 
 
270
        if( !PyArg_ParseTuple( args, "|s", &name ) )
 
271
                return ( EXPP_ReturnPyObjError( PyExc_TypeError,
 
272
                                                "expected string argument (or nothing)" ) );
 
273
 
 
274
        ipo_iter = G.main->ipo.first;
 
275
 
 
276
        if( name ) {            /* (name) - Search ipo by name */
 
277
                while( ( ipo_iter ) && ( wanted_ipo == NULL ) ) {
 
278
                        if( strcmp( name, ipo_iter->id.name + 2 ) == 0 ) {
 
279
                                wanted_ipo =
 
280
                                        ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo,
 
281
                                                                    &Ipo_Type );
 
282
                                if( wanted_ipo )
 
283
                                        wanted_ipo->ipo = ipo_iter;
 
284
                        }
 
285
                        ipo_iter = ipo_iter->id.next;
 
286
                }
 
287
 
 
288
                if( wanted_ipo == NULL ) {      /* Requested ipo doesn't exist */
 
289
                        PyOS_snprintf( error_msg, sizeof( error_msg ),
 
290
                                       "Ipo \"%s\" not found", name );
 
291
                        return ( EXPP_ReturnPyObjError
 
292
                                 ( PyExc_NameError, error_msg ) );
 
293
                }
 
294
 
 
295
                return ( PyObject * ) wanted_ipo;
 
296
        }
 
297
 
 
298
        else {                  /* () - return a list with all ipos in the scene */
 
299
                int index = 0;
 
300
 
 
301
                ipolist = PyList_New( BLI_countlist( &( G.main->ipo ) ) );
 
302
 
 
303
                if( ipolist == NULL )
 
304
                        return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
 
305
                                                        "couldn't create PyList" ) );
 
306
 
 
307
                while( ipo_iter ) {
 
308
                        pyobj = Ipo_CreatePyObject( ipo_iter );
 
309
 
 
310
                        if( !pyobj )
 
311
                                return ( EXPP_ReturnPyObjError
 
312
                                         ( PyExc_MemoryError,
 
313
                                           "couldn't create PyString" ) );
 
314
 
 
315
                        PyList_SET_ITEM( ipolist, index, pyobj );
 
316
 
 
317
                        ipo_iter = ipo_iter->id.next;
 
318
                        index++;
 
319
                }
 
320
 
 
321
                return ( ipolist );
 
322
        }
308
323
}
309
324
 
310
325
 
311
 
static PyObject *
312
 
M_Ipo_Recalc (PyObject * self, PyObject * args)
 
326
static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args )
313
327
{
314
 
  void testhandles_ipocurve (IpoCurve * icu);
315
 
  PyObject *a;
316
 
  IpoCurve *icu;
317
 
  if (!PyArg_ParseTuple (args, "O", &a))
318
 
    return (EXPP_ReturnPyObjError
319
 
            (PyExc_TypeError, "expected ipo argument)"));
320
 
  icu = IpoCurve_FromPyObject (a);
321
 
  testhandles_ipocurve (icu);
 
328
        void testhandles_ipocurve( IpoCurve * icu );
 
329
        PyObject *a;
 
330
        IpoCurve *icu;
 
331
        if( !PyArg_ParseTuple( args, "O", &a ) )
 
332
                return ( EXPP_ReturnPyObjError
 
333
                         ( PyExc_TypeError, "expected ipo argument)" ) );
 
334
        icu = IpoCurve_FromPyObject( a );
 
335
        testhandles_ipocurve( icu );
322
336
 
323
 
  Py_INCREF (Py_None);
324
 
  return Py_None;
 
337
        Py_INCREF( Py_None );
 
338
        return Py_None;
325
339
 
326
340
}
327
341
 
328
342
/*****************************************************************************/
329
343
/* Function:              Ipo_Init                                           */
330
344
/*****************************************************************************/
331
 
PyObject *
332
 
Ipo_Init (void)
 
345
PyObject *Ipo_Init( void )
333
346
{
334
 
  PyObject *submodule;
335
 
 
336
 
  Ipo_Type.ob_type = &PyType_Type;
337
 
 
338
 
  submodule = Py_InitModule3 ("Blender.Ipo", M_Ipo_methods, M_Ipo_doc);
339
 
 
340
 
  return (submodule);
 
347
        PyObject *submodule;
 
348
 
 
349
        Ipo_Type.ob_type = &PyType_Type;
 
350
 
 
351
        submodule = Py_InitModule3( "Blender.Ipo", M_Ipo_methods, M_Ipo_doc );
 
352
 
 
353
        return ( submodule );
341
354
}
342
355
 
343
356
/*****************************************************************************/
344
357
/* Python BPy_Ipo methods:                                                  */
345
358
/*****************************************************************************/
346
 
static PyObject *
347
 
Ipo_getName (BPy_Ipo * self)
348
 
{
349
 
  PyObject *attr = PyString_FromString (self->ipo->id.name + 2);
350
 
 
351
 
  if (attr)
352
 
    return attr;
353
 
  Py_INCREF (Py_None);
354
 
  return Py_None;
355
 
}
356
 
 
357
 
 
358
 
static PyObject *
359
 
Ipo_setName (BPy_Ipo * self, PyObject * args)
360
 
{
361
 
  char *name;
362
 
  char buf[21];
363
 
 
364
 
  if (!PyArg_ParseTuple (args, "s", &name))
365
 
    return (EXPP_ReturnPyObjError
366
 
            (PyExc_TypeError, "expected string argument"));
367
 
 
368
 
  PyOS_snprintf (buf, sizeof (buf), "%s", name);
369
 
 
370
 
  rename_id (&self->ipo->id, buf);
371
 
 
372
 
  Py_INCREF (Py_None);
373
 
  return Py_None;
374
 
}
375
 
 
376
 
static PyObject *
377
 
Ipo_getBlocktype (BPy_Ipo * self)
378
 
{
379
 
  PyObject *attr = PyInt_FromLong (self->ipo->blocktype);
380
 
  if (attr)
381
 
    return attr;
382
 
  return (EXPP_ReturnPyObjError
383
 
          (PyExc_RuntimeError, "couldn't get Ipo.blocktype attribute"));
384
 
}
385
 
 
386
 
 
387
 
static PyObject *
388
 
Ipo_setBlocktype (BPy_Ipo * self, PyObject * args)
389
 
{
390
 
  int blocktype = 0;
391
 
 
392
 
  if (!PyArg_ParseTuple (args, "i", &blocktype))
393
 
    return (EXPP_ReturnPyObjError
394
 
            (PyExc_TypeError, "expected string argument"));
395
 
 
396
 
  self->ipo->blocktype = (short) blocktype;
397
 
 
398
 
  Py_INCREF (Py_None);
399
 
  return Py_None;
400
 
}
401
 
 
402
 
 
403
 
static PyObject *
404
 
Ipo_getRctf (BPy_Ipo * self)
405
 
{
406
 
  PyObject *l = PyList_New (0);
407
 
  PyList_Append (l, PyFloat_FromDouble (self->ipo->cur.xmin));
408
 
  PyList_Append (l, PyFloat_FromDouble (self->ipo->cur.xmax));
409
 
  PyList_Append (l, PyFloat_FromDouble (self->ipo->cur.ymin));
410
 
  PyList_Append (l, PyFloat_FromDouble (self->ipo->cur.ymax));
411
 
  return l;
412
 
 
413
 
}
414
 
 
415
 
 
416
 
static PyObject *
417
 
Ipo_setRctf (BPy_Ipo * self, PyObject * args)
418
 
{
419
 
  float v[4];
420
 
  if (!PyArg_ParseTuple (args, "ffff", v, v + 1, v + 2, v + 3))
421
 
    return (EXPP_ReturnPyObjError
422
 
            (PyExc_TypeError, "expected 4 float argument"));
423
 
 
424
 
  self->ipo->cur.xmin = v[0];
425
 
  self->ipo->cur.xmax = v[1];
426
 
  self->ipo->cur.ymin = v[2];
427
 
  self->ipo->cur.ymax = v[3];
428
 
 
429
 
  Py_INCREF (Py_None);
430
 
  return Py_None;
431
 
}
432
 
 
433
 
static PyObject *
434
 
Ipo_getNcurves (BPy_Ipo * self)
435
 
{
436
 
  int i = 0;
437
 
 
438
 
  IpoCurve *icu;
439
 
  for (icu = self->ipo->curve.first; icu; icu = icu->next)
440
 
    {
441
 
      i++;
442
 
    }
443
 
 
444
 
  return (PyInt_FromLong (i));
445
 
}
446
 
 
447
 
 
448
 
static PyObject *
449
 
Ipo_addCurve (BPy_Ipo * self, PyObject * args)
450
 
{
451
 
  IpoCurve *get_ipocurve (ID * from, short type, int adrcode, Ipo * useipo);
452
 
  void allspace (unsigned short event, short val);
453
 
  void allqueue (unsigned short event, short val);
454
 
  int param = 0, ok = 0;
455
 
  char *s = 0;
456
 
  IpoCurve *icu;
457
 
  Link *link;
458
 
  struct Object *object = NULL;
459
 
 
460
 
  if (!PyArg_ParseTuple (args, "s", &s))
461
 
    return (EXPP_ReturnPyObjError
462
 
            (PyExc_TypeError, "expected string argument"));
463
 
 
464
 
  /* insertkey demande un pointeur sur l'objet pour lequel on veut ajouter 
465
 
     une courbe IPO */
466
 
  link = G.main->object.first;
467
 
  while (link)
468
 
    {
469
 
      object = (Object *) link;
470
 
      if (object->ipo == self->ipo)
471
 
        break;
472
 
      link = link->next;
473
 
    }
474
 
  /* todo : what kind of object....
475
 
     #define GS(a)        (*((short *)(a)))
476
 
     printf("object %p\n",object);
477
 
     printf("type %d\n",GS(object->id.name));
478
 
   */
479
 
 
480
 
  if (!strcmp (s, "LocX"))
481
 
    {
482
 
      param = OB_LOC_X;
483
 
      ok = 1;
484
 
    }
485
 
  if (!strcmp (s, "LocY"))
486
 
    {
487
 
      param = OB_LOC_Y;
488
 
      ok = 1;
489
 
    }
490
 
  if (!strcmp (s, "LocZ"))
491
 
    {
492
 
      param = OB_LOC_Z;
493
 
      ok = 1;
494
 
    }
495
 
  if (!strcmp (s, "RotX"))
496
 
    {
497
 
      param = OB_ROT_X;
498
 
      ok = 1;
499
 
    }
500
 
  if (!strcmp (s, "RotY"))
501
 
    {
502
 
      param = OB_ROT_Y;
503
 
      ok = 1;
504
 
    }
505
 
  if (!strcmp (s, "RotZ"))
506
 
    {
507
 
      param = OB_ROT_Z;
508
 
      ok = 1;
509
 
    }
510
 
  if (!strcmp (s, "SizeX"))
511
 
    {
512
 
      param = OB_SIZE_X;
513
 
      ok = 1;
514
 
    }
515
 
  if (!strcmp (s, "SizeY"))
516
 
    {
517
 
      param = OB_SIZE_Y;
518
 
      ok = 1;
519
 
    }
520
 
  if (!strcmp (s, "SizeZ"))
521
 
    {
522
 
      param = OB_SIZE_Z;
523
 
      ok = 1;
524
 
    }
525
 
 
526
 
  if (!strcmp (s, "DLocX"))
527
 
    {
528
 
      param = OB_DLOC_X;
529
 
      ok = 1;
530
 
    }
531
 
  if (!strcmp (s, "DLocY"))
532
 
    {
533
 
      param = OB_DLOC_Y;
534
 
      ok = 1;
535
 
    }
536
 
  if (!strcmp (s, "DLocZ"))
537
 
    {
538
 
      param = OB_DLOC_Z;
539
 
      ok = 1;
540
 
    }
541
 
  if (!strcmp (s, "DRotX"))
542
 
    {
543
 
      param = OB_DROT_X;
544
 
      ok = 1;
545
 
    }
546
 
  if (!strcmp (s, "DRotY"))
547
 
    {
548
 
      param = OB_DROT_Y;
549
 
      ok = 1;
550
 
    }
551
 
  if (!strcmp (s, "DRotZ"))
552
 
    {
553
 
      param = OB_DROT_Z;
554
 
      ok = 1;
555
 
    }
556
 
  if (!strcmp (s, "DSizeX"))
557
 
    {
558
 
      param = OB_DSIZE_X;
559
 
      ok = 1;
560
 
    }
561
 
  if (!strcmp (s, "DSizeY"))
562
 
    {
563
 
      param = OB_DSIZE_Y;
564
 
      ok = 1;
565
 
    }
566
 
  if (!strcmp (s, "DSizeZ"))
567
 
    {
568
 
      param = OB_DSIZE_Z;
569
 
      ok = 1;
570
 
    }
571
 
 
572
 
  if (!strcmp (s, "Layer"))
573
 
    {
574
 
      param = OB_LAY;
575
 
      ok = 1;
576
 
    }
577
 
  if (!strcmp (s, "Time"))
578
 
    {
579
 
      param = OB_TIME;
580
 
      ok = 1;
581
 
    }
582
 
 
583
 
  if (!strcmp (s, "ColR"))
584
 
    {
585
 
      param = OB_COL_R;
586
 
      ok = 1;
587
 
    }
588
 
  if (!strcmp (s, "ColG"))
589
 
    {
590
 
      param = OB_COL_G;
591
 
      ok = 1;
592
 
    }
593
 
  if (!strcmp (s, "ColB"))
594
 
    {
595
 
      param = OB_COL_B;
596
 
      ok = 1;
597
 
    }
598
 
  if (!strcmp (s, "ColA"))
599
 
    {
600
 
      param = OB_COL_A;
601
 
      ok = 1;
602
 
    }
603
 
  if (!ok)
604
 
    return (EXPP_ReturnPyObjError (PyExc_ValueError, "Not a valid param."));
605
 
 
606
 
  /* add a new curve to the ipo.  we pass in self->ipo so a new one does 
607
 
     not get created */ 
608
 
  icu = get_ipocurve (&(object->id), ID_OB, param, self->ipo );
609
 
 
610
 
 
611
 
#define REMAKEIPO               1
612
 
#define REDRAWIPO                       0x4023
613
 
  allspace (REMAKEIPO, 0);
614
 
  allqueue (REDRAWIPO, 0);
615
 
 
616
 
  return IpoCurve_CreatePyObject (icu);
617
 
}
618
 
 
619
 
 
620
 
 
621
 
static PyObject *
622
 
Ipo_getCurve (BPy_Ipo * self, PyObject * args)
623
 
{
624
 
  //int num = 0 , i = 0;
625
 
  char *str;
626
 
  IpoCurve *icu = 0;
627
 
  if (!PyArg_ParseTuple (args, "s", &str))
628
 
    return (EXPP_ReturnPyObjError
629
 
            (PyExc_TypeError, "expected string argument"));
630
 
  for (icu = self->ipo->curve.first; icu; icu = icu->next)
631
 
    {
632
 
      char str1[80];
633
 
      GetIpoCurveName (icu, str1);
634
 
      if (!strcmp (str1, str))
635
 
        return IpoCurve_CreatePyObject (icu);
636
 
    }
637
 
 
638
 
  Py_INCREF (Py_None);
639
 
  return Py_None;
640
 
}
641
 
 
642
 
 
643
 
void
644
 
GetIpoCurveName (IpoCurve * icu, char *s)
645
 
{
646
 
  switch (icu->blocktype)
647
 
    {
648
 
    case ID_MA:
649
 
      {
650
 
        getname_mat_ei (icu->adrcode, s);
651
 
        break;
652
 
      }
653
 
    case ID_WO:
654
 
      {
655
 
        getname_world_ei (icu->adrcode, s);
656
 
        break;
657
 
      }
658
 
    case ID_CA:
659
 
      {
660
 
        getname_cam_ei (icu->adrcode, s);
661
 
        break;
662
 
      }
663
 
    case ID_OB:
664
 
      {
665
 
        getname_ob_ei (icu->adrcode, s);
666
 
        break;
667
 
      }
668
 
    }
669
 
}
670
 
 
671
 
 
672
 
static PyObject *
673
 
Ipo_getCurves (BPy_Ipo * self)
674
 
{
675
 
  PyObject *attr = PyList_New (0);
676
 
  IpoCurve *icu;
677
 
  for (icu = self->ipo->curve.first; icu; icu = icu->next)
678
 
    {
679
 
      PyList_Append (attr, IpoCurve_CreatePyObject (icu));
680
 
    }
681
 
  return attr;
682
 
}
683
 
 
684
 
 
685
 
static PyObject *
686
 
Ipo_getNBezPoints (BPy_Ipo * self, PyObject * args)
687
 
{
688
 
  int num = 0, i = 0;
689
 
  IpoCurve *icu = 0;
690
 
  if (!PyArg_ParseTuple (args, "i", &num))
691
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument"));
692
 
  icu = self->ipo->curve.first;
693
 
  if (!icu)
694
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "No IPO curve"));
695
 
  for (i = 0; i < num; i++)
696
 
    {
697
 
      if (!icu)
698
 
        return (EXPP_ReturnPyObjError (PyExc_TypeError, "Bad curve number"));
699
 
      icu = icu->next;
700
 
 
701
 
    }
702
 
  return (PyInt_FromLong (icu->totvert));
703
 
}
704
 
 
705
 
static PyObject *
706
 
Ipo_DeleteBezPoints (BPy_Ipo * self, PyObject * args)
707
 
{
708
 
  int num = 0, i = 0;
709
 
  IpoCurve *icu = 0;
710
 
  if (!PyArg_ParseTuple (args, "i", &num))
711
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument"));
712
 
  icu = self->ipo->curve.first;
713
 
  if (!icu)
714
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "No IPO curve"));
715
 
  for (i = 0; i < num; i++)
716
 
    {
717
 
      if (!icu)
718
 
        return (EXPP_ReturnPyObjError (PyExc_TypeError, "Bad curve number"));
719
 
      icu = icu->next;
720
 
 
721
 
    }
722
 
  icu->totvert--;
723
 
  return (PyInt_FromLong (icu->totvert));
724
 
}
725
 
 
726
 
 
727
 
static PyObject *
728
 
Ipo_getCurveBP (BPy_Ipo * self, PyObject * args)
729
 
{
730
 
  struct BPoint *ptrbpoint;
731
 
  int num = 0, i;
732
 
  IpoCurve *icu;
733
 
  PyObject *l;
734
 
 
735
 
  if (!PyArg_ParseTuple (args, "i", &num))
736
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument"));
737
 
  icu = self->ipo->curve.first;
738
 
  if (!icu)
739
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "No IPO curve"));
740
 
  for (i = 0; i < num; i++)
741
 
    {
742
 
      if (!icu)
743
 
        return (EXPP_ReturnPyObjError (PyExc_TypeError, "Bad curve number"));
744
 
      icu = icu->next;
745
 
 
746
 
    }
747
 
  ptrbpoint = icu->bp;
748
 
  if (!ptrbpoint)
749
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "No base point");
750
 
 
751
 
  l = PyList_New (0);
752
 
  for (i = 0; i < 4; i++)
753
 
    PyList_Append (l, PyFloat_FromDouble (ptrbpoint->vec[i]));
754
 
  return l;
755
 
}
756
 
 
757
 
static PyObject *
758
 
Ipo_getCurveBeztriple (BPy_Ipo * self, PyObject * args)
759
 
{
760
 
  struct BezTriple *ptrbt;
761
 
  int num = 0, pos, i, j;
762
 
  IpoCurve *icu;
763
 
  PyObject *l = PyList_New (0);
764
 
 
765
 
  if (!PyArg_ParseTuple (args, "ii", &num, &pos))
766
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument"));
767
 
  icu = self->ipo->curve.first;
768
 
  if (!icu)
769
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "No IPO curve"));
770
 
  for (i = 0; i < num; i++)
771
 
    {
772
 
      if (!icu)
773
 
        return (EXPP_ReturnPyObjError (PyExc_TypeError, "Bad ipo number"));
774
 
      icu = icu->next;
775
 
    }
776
 
  if (pos >= icu->totvert)
777
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "Bad bezt number");
778
 
 
779
 
  ptrbt = icu->bezt + pos;
780
 
  if (!ptrbt)
781
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "No bez triple");
782
 
 
783
 
  for (i = 0; i < 3; i++)
784
 
    for (j = 0; j < 3; j++)
785
 
      PyList_Append (l, PyFloat_FromDouble (ptrbt->vec[i][j]));
786
 
  return l;
787
 
}
788
 
 
789
 
 
790
 
static PyObject *
791
 
Ipo_setCurveBeztriple (BPy_Ipo * self, PyObject * args)
792
 
{
793
 
  struct BezTriple *ptrbt;
794
 
  int num = 0, pos, i;
795
 
  IpoCurve *icu;
796
 
  PyObject *listargs = 0;
797
 
 
798
 
  if (!PyArg_ParseTuple (args, "iiO", &num, &pos, &listargs))
799
 
    return (EXPP_ReturnPyObjError
800
 
            (PyExc_TypeError, "expected int int object argument"));
801
 
  if (!PyTuple_Check (listargs))
802
 
    return (EXPP_ReturnPyObjError
803
 
            (PyExc_TypeError, "3rd arg should be a tuple"));
804
 
  icu = self->ipo->curve.first;
805
 
  if (!icu)
806
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "No IPO curve"));
807
 
  for (i = 0; i < num; i++)
808
 
    {
809
 
      if (!icu)
810
 
        return (EXPP_ReturnPyObjError (PyExc_TypeError, "Bad ipo number"));
811
 
      icu = icu->next;
812
 
    }
813
 
  if (pos >= icu->totvert)
814
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "Bad bezt number");
815
 
 
816
 
  ptrbt = icu->bezt + pos;
817
 
  if (!ptrbt)
818
 
    return EXPP_ReturnPyObjError (PyExc_TypeError, "No bez triple");
819
 
 
820
 
  for (i = 0; i < 9; i++)
821
 
    {
822
 
      PyObject *xx = PyTuple_GetItem (listargs, i);
823
 
      ptrbt->vec[i / 3][i % 3] = PyFloat_AsDouble (xx);
824
 
    }
825
 
 
826
 
  Py_INCREF (Py_None);
827
 
  return Py_None;
828
 
}
829
 
 
830
 
 
831
 
static PyObject *
832
 
Ipo_EvaluateCurveOn (BPy_Ipo * self, PyObject * args)
833
 
{
834
 
  float eval_icu (IpoCurve * icu, float ipotime);
835
 
 
836
 
  int num = 0, i;
837
 
  IpoCurve *icu;
838
 
  float time = 0;
839
 
 
840
 
  if (!PyArg_ParseTuple (args, "if", &num, &time))
841
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument"));
842
 
 
843
 
  icu = self->ipo->curve.first;
844
 
  if (!icu)
845
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "No IPO curve"));
846
 
 
847
 
  for (i = 0; i < num; i++)
848
 
    {
849
 
      if (!icu)
850
 
        return (EXPP_ReturnPyObjError (PyExc_TypeError, "Bad ipo number"));
851
 
      icu = icu->next;
852
 
 
853
 
    }
854
 
  return PyFloat_FromDouble (eval_icu (icu, time));
855
 
}
856
 
 
857
 
 
858
 
static PyObject *
859
 
Ipo_getCurvecurval (BPy_Ipo * self, PyObject * args)
860
 
{
861
 
  int numcurve = 0, i;
862
 
  IpoCurve *icu;
863
 
  char *stringname = 0;
864
 
 
865
 
  icu = self->ipo->curve.first;
866
 
  if (!icu)
867
 
    return (EXPP_ReturnPyObjError (PyExc_TypeError, "No IPO curve"));
868
 
 
869
 
  if (PyNumber_Check (PySequence_GetItem (args, 0)))    // args is an integer
870
 
    {
871
 
      if (!PyArg_ParseTuple (args, "i", &numcurve))
872
 
        return (EXPP_ReturnPyObjError
873
 
                (PyExc_TypeError, "expected int or string argument"));
874
 
      for (i = 0; i < numcurve; i++)
875
 
        {
876
 
          if (!icu)
877
 
            return (EXPP_ReturnPyObjError
878
 
                    (PyExc_TypeError, "Bad ipo number"));
879
 
          icu = icu->next;
880
 
        }
881
 
    }
882
 
 
883
 
  else                          // args is a string
884
 
    {
885
 
      if (!PyArg_ParseTuple (args, "s", &stringname))
886
 
        return (EXPP_ReturnPyObjError
887
 
                (PyExc_TypeError, "expected int or string argument"));
888
 
      while (icu)
889
 
        {
890
 
          char str1[10];
891
 
          GetIpoCurveName (icu, str1);
892
 
          if (!strcmp (str1, stringname))
893
 
            break;
894
 
          icu = icu->next;
895
 
        }
896
 
    }
897
 
 
898
 
  if (icu)
899
 
    return PyFloat_FromDouble (icu->curval);
900
 
  Py_INCREF (Py_None);
901
 
  return Py_None;
 
359
static PyObject *Ipo_getName( BPy_Ipo * self )
 
360
{
 
361
        PyObject *attr = PyString_FromString( self->ipo->id.name + 2 );
 
362
 
 
363
        if( attr )
 
364
                return attr;
 
365
        Py_INCREF( Py_None );
 
366
        return Py_None;
 
367
}
 
368
 
 
369
 
 
370
static PyObject *Ipo_setName( BPy_Ipo * self, PyObject * args )
 
371
{
 
372
        char *name;
 
373
        char buf[21];
 
374
 
 
375
        if( !PyArg_ParseTuple( args, "s", &name ) )
 
376
                return ( EXPP_ReturnPyObjError
 
377
                         ( PyExc_TypeError, "expected string argument" ) );
 
378
 
 
379
        PyOS_snprintf( buf, sizeof( buf ), "%s", name );
 
380
 
 
381
        rename_id( &self->ipo->id, buf );
 
382
 
 
383
        Py_INCREF( Py_None );
 
384
        return Py_None;
 
385
}
 
386
 
 
387
static PyObject *Ipo_getBlocktype( BPy_Ipo * self )
 
388
{
 
389
        PyObject *attr = PyInt_FromLong( self->ipo->blocktype );
 
390
        if( attr )
 
391
                return attr;
 
392
        return ( EXPP_ReturnPyObjError
 
393
                 ( PyExc_RuntimeError,
 
394
                   "couldn't get Ipo.blocktype attribute" ) );
 
395
}
 
396
 
 
397
 
 
398
static PyObject *Ipo_setBlocktype( BPy_Ipo * self, PyObject * args )
 
399
{
 
400
        int blocktype = 0;
 
401
 
 
402
        if( !PyArg_ParseTuple( args, "i", &blocktype ) )
 
403
                return ( EXPP_ReturnPyObjError
 
404
                         ( PyExc_TypeError, "expected string argument" ) );
 
405
 
 
406
        self->ipo->blocktype = ( short ) blocktype;
 
407
 
 
408
        Py_INCREF( Py_None );
 
409
        return Py_None;
 
410
}
 
411
 
 
412
 
 
413
static PyObject *Ipo_getRctf( BPy_Ipo * self )
 
414
{
 
415
        PyObject *l = PyList_New( 0 );
 
416
        PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.xmin ) );
 
417
        PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.xmax ) );
 
418
        PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymin ) );
 
419
        PyList_Append( l, PyFloat_FromDouble( self->ipo->cur.ymax ) );
 
420
        return l;
 
421
 
 
422
}
 
423
 
 
424
 
 
425
static PyObject *Ipo_setRctf( BPy_Ipo * self, PyObject * args )
 
426
{
 
427
        float v[4];
 
428
        if( !PyArg_ParseTuple( args, "ffff", v, v + 1, v + 2, v + 3 ) )
 
429
                return ( EXPP_ReturnPyObjError
 
430
                         ( PyExc_TypeError, "expected 4 float argument" ) );
 
431
 
 
432
        self->ipo->cur.xmin = v[0];
 
433
        self->ipo->cur.xmax = v[1];
 
434
        self->ipo->cur.ymin = v[2];
 
435
        self->ipo->cur.ymax = v[3];
 
436
 
 
437
        Py_INCREF( Py_None );
 
438
        return Py_None;
 
439
}
 
440
 
 
441
static PyObject *Ipo_getNcurves( BPy_Ipo * self )
 
442
{
 
443
        int i = 0;
 
444
 
 
445
        IpoCurve *icu;
 
446
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
 
447
                i++;
 
448
        }
 
449
 
 
450
        return ( PyInt_FromLong( i ) );
 
451
}
 
452
 
 
453
 
 
454
/*
 
455
  Lamp ipo Name to Channel
 
456
*/
 
457
 
 
458
static int Ipo_laIcuName( char *s, int *param )
 
459
{
 
460
        extern int la_ar[];
 
461
 
 
462
        int not_ok = 0;
 
463
        int i;
 
464
        char *lamp_names[LA_TOTIPO] =
 
465
                { "Energ", "R", "G", "B", "Dist", "SpoSi",
 
466
                "SpoBl", "Quad1", "Quad2", "HaInt",
 
467
                /* lamp texture names */
 
468
                "OfsX", "OfsY", "OfsZ", "SizeX", "SizeY",
 
469
                "SizeZ", "texR", "texG", "texB", "DefVar",
 
470
                "Col"
 
471
        };
 
472
 
 
473
        for( i = 0; i < LA_TOTIPO; i++ ) {
 
474
                if( !strcmp( s, lamp_names[i] ) ) {     /* found it! */
 
475
                        *param = la_ar[i];
 
476
                        return 1;
 
477
                }
 
478
        }
 
479
 
 
480
        return not_ok;
 
481
}
 
482
 
 
483
 
 
484
/* 
 
485
 World Ipo Name to Channel
 
486
*/
 
487
 
 
488
static int Ipo_woIcuName( char *s, int *param )
 
489
{
 
490
        extern int wo_ar[];     /* channel values from ipo.c */
 
491
        int not_ok = 0;
 
492
        int i;
 
493
        char *world_names[WO_TOTIPO] = { "HorR", "HorG", "HorB",
 
494
                "ZenR", "ZenG", "ZenB",
 
495
                "Expos",
 
496
                "Misi", "MisDi", "MisSta", "MisHi",
 
497
                "StarR", "StarB", "StarG",
 
498
                "StarDi", "StarSi",
 
499
                /* world textures names */
 
500
                "OfsX", "OfsY", "OfsZ",
 
501
                "SizeX", "SizeY", "SizeZ",
 
502
                "texR", "texG", "texB",
 
503
                "DefVar", "Col", "Nor", "Var",
 
504
        };
 
505
 
 
506
        for( i = 0; i < WO_TOTIPO; i++ ) {
 
507
                if( !strcmp( s, world_names[i] ) ) {    /* found it! */
 
508
                        *param = wo_ar[i];
 
509
                        return 1;
 
510
                }
 
511
        }
 
512
 
 
513
        return not_ok;
 
514
}
 
515
 
 
516
static int Ipo_maIcuName( char *s, int *param )
 
517
{
 
518
        extern int ma_ar[];
 
519
 
 
520
        int not_ok = 0;
 
521
        int i;
 
522
 
 
523
        char *material_names[MA_TOTIPO] = { "R", "G", "B",
 
524
                "SpecR", "SpecG", "SpecB",
 
525
                "MirR", "MirG", "MirB", "Ref", "Alpha",
 
526
                "Emit", "Amb", "Spec",
 
527
                "Hard", "SpTra", "Ior", "Mode",
 
528
                "HaSize", "Translu",
 
529
                "RayMir", "FresMir", "FresMirI",
 
530
                "FresTra", "FresTraI",
 
531
                "TraGlow",
 
532
                "OfsX", "OfsY", "OfsZ",
 
533
                "SizeX", "SizeY", "SizeZ",
 
534
                "texR", "texG", "texB",
 
535
                "DefVar", "Col", "Nor", "Var",
 
536
                "Disp"
 
537
        };
 
538
 
 
539
 
 
540
        for( i = 0; i < MA_TOTIPO; i++ ) {
 
541
                if( !strcmp( s, material_names[i] ) ) { /* found it! */
 
542
                        *param = ma_ar[i];
 
543
                        return 1;
 
544
                }
 
545
        }
 
546
 
 
547
        return not_ok;
 
548
}
 
549
 
 
550
static int Ipo_keIcuName( char *s, int *param )
 
551
{
 
552
        char key[10];
 
553
        int ok = 0;
 
554
        int nr = 0;
 
555
        if( !strcmp( s, "Speed" ) ) {
 
556
                *param = KEY_SPEED;
 
557
                ok = 1;
 
558
        }
 
559
        for( nr = 1; nr < 64; nr++ ) {
 
560
                sprintf( key, "Key %d", nr );
 
561
                if( !strcmp( s, key ) ) {
 
562
                        *param = nr;
 
563
                        ok = 1;
 
564
                        break;
 
565
                }
 
566
        }
 
567
 
 
568
        return ok;
 
569
}
 
570
 
 
571
static int Ipo_seqIcuName( char *s, int *param )
 
572
{
 
573
        int ok = 0;
 
574
        if( !strcmp( s, "Fac" ) ) {
 
575
                *param = SEQ_FAC1;
 
576
                ok = 1;
 
577
        }
 
578
 
 
579
        return ok;
 
580
}
 
581
 
 
582
static int Ipo_cuIcuName( char *s, int *param )
 
583
{
 
584
        int ok = 0;
 
585
        if( !strcmp( s, "Speed" ) ) {
 
586
                *param = CU_SPEED;
 
587
                ok = 1;
 
588
        }
 
589
 
 
590
        return ok;
 
591
}
 
592
 
 
593
static int Ipo_coIcuName( char *s, int *param )
 
594
{
 
595
        int ok = 0;
 
596
        if( !strcmp( s, "Inf" ) ) {
 
597
                *param = CO_ENFORCE;
 
598
                ok = 1;
 
599
        }
 
600
 
 
601
        return ok;
 
602
}
 
603
 
 
604
static int Ipo_acIcuName( char *s, int *param )
 
605
{
 
606
        int ok = 0;
 
607
        if( !strcmp( s, "LocX" ) ) {
 
608
                *param = AC_LOC_X;
 
609
                return 1;
 
610
        }
 
611
        if( !strcmp( s, "LocY" ) ) {
 
612
                *param = AC_LOC_Y;
 
613
                return 1;
 
614
        }
 
615
        if( !strcmp( s, "LocZ" ) ) {
 
616
                *param = AC_LOC_Z;
 
617
                return 1;
 
618
        }
 
619
        if( !strcmp( s, "SizeX" ) ) {
 
620
                *param = AC_SIZE_X;
 
621
                return 1;
 
622
        }
 
623
        if( !strcmp( s, "SizeY" ) ) {
 
624
                *param = AC_SIZE_Y;
 
625
                return 1;
 
626
        }
 
627
        if( !strcmp( s, "SizeZ" ) ) {
 
628
                *param = AC_SIZE_Z;
 
629
                return 1;
 
630
        }
 
631
        if( !strcmp( s, "QuatX" ) ) {
 
632
                *param = AC_QUAT_X;
 
633
                return 1;
 
634
        }
 
635
        if( !strcmp( s, "QuatY" ) ) {
 
636
                *param = AC_QUAT_Y;
 
637
                return 1;
 
638
        }
 
639
        if( !strcmp( s, "QuatZ" ) ) {
 
640
                *param = AC_QUAT_Z;
 
641
                return 1;
 
642
        }
 
643
        if( !strcmp( s, "QuatW" ) ) {
 
644
                *param = AC_QUAT_W;
 
645
                return 1;
 
646
        }
 
647
        return ok;
 
648
}
 
649
 
 
650
 
 
651
/*
 
652
  Camera ipo name to channel
 
653
*/
 
654
 
 
655
static int Ipo_caIcuName( char *s, int *param )
 
656
{
 
657
        /* for Camera ipos CAM_TOTNAM == CAM_TOTIPO 
 
658
           and cam_ic_names[] holds the complete set of names, so we use that.
 
659
         */
 
660
        extern int cam_ar[];
 
661
        extern char *cam_ic_names[];
 
662
 
 
663
        int not_ok = 0;
 
664
        int i;
 
665
 
 
666
        for( i = 0; i < CAM_TOTIPO; i++ ) {
 
667
                if( !strcmp( s, cam_ic_names[i] ) ) {   /* found it! */
 
668
                        *param = cam_ar[i];
 
669
                        return 1;
 
670
                }
 
671
        }
 
672
 
 
673
        return not_ok;
 
674
}
 
675
 
 
676
 
 
677
/*
 
678
  texture ipo name to channel
 
679
*/
 
680
 
 
681
static int Ipo_texIcuName( char *s, int *param )
 
682
{
 
683
        /* this is another case where TE_TOTIPO == TE_TOTNAM.
 
684
           te_ic_names[] has all our names so use that.
 
685
        */
 
686
        extern int te_ar[];
 
687
        extern char *tex_ic_names[];
 
688
        int not_ok = 0;
 
689
        int i;
 
690
 
 
691
        for( i = 0; i < TE_TOTIPO; i++){
 
692
                if( !strcmp( s, tex_ic_names[i] ) ){
 
693
                        *param = te_ar[i];
 
694
                        return 1;
 
695
                }
 
696
        }
 
697
 
 
698
        return not_ok;
 
699
}
 
700
 
 
701
static int Ipo_obIcuName( char *s, int *param )
 
702
{
 
703
        int ok = 0;
 
704
        if( !strcmp( s, "LocX" ) ) {
 
705
                *param = OB_LOC_X;
 
706
                return 1;
 
707
        }
 
708
        if( !strcmp( s, "LocY" ) ) {
 
709
                *param = OB_LOC_Y;
 
710
                return 1;
 
711
        }
 
712
        if( !strcmp( s, "LocZ" ) ) {
 
713
                *param = OB_LOC_Z;
 
714
                return 1;
 
715
        }
 
716
        if( !strcmp( s, "RotX" ) ) {
 
717
                *param = OB_ROT_X;
 
718
                return 1;
 
719
        }
 
720
        if( !strcmp( s, "RotY" ) ) {
 
721
                *param = OB_ROT_Y;
 
722
                return 1;
 
723
        }
 
724
        if( !strcmp( s, "RotZ" ) ) {
 
725
                *param = OB_ROT_Z;
 
726
                return 1;
 
727
        }
 
728
        if( !strcmp( s, "SizeX" ) ) {
 
729
                *param = OB_SIZE_X;
 
730
                return 1;
 
731
        }
 
732
        if( !strcmp( s, "SizeY" ) ) {
 
733
                *param = OB_SIZE_Y;
 
734
                return 1;
 
735
        }
 
736
        if( !strcmp( s, "SizeZ" ) ) {
 
737
                *param = OB_SIZE_Z;
 
738
                return 1;
 
739
        }
 
740
 
 
741
        if( !strcmp( s, "dLocX" ) ) {
 
742
                *param = OB_DLOC_X;
 
743
                return 1;
 
744
        }
 
745
        if( !strcmp( s, "dLocY" ) ) {
 
746
                *param = OB_DLOC_Y;
 
747
                return 1;
 
748
        }
 
749
        if( !strcmp( s, "dLocZ" ) ) {
 
750
                *param = OB_DLOC_Z;
 
751
                return 1;
 
752
        }
 
753
        if( !strcmp( s, "dRotX" ) ) {
 
754
                *param = OB_DROT_X;
 
755
                return 1;
 
756
        }
 
757
        if( !strcmp( s, "dRotY" ) ) {
 
758
                *param = OB_DROT_Y;
 
759
                return 1;
 
760
        }
 
761
        if( !strcmp( s, "dRotZ" ) ) {
 
762
                *param = OB_DROT_Z;
 
763
                return 1;
 
764
        }
 
765
        if( !strcmp( s, "dSizeX" ) ) {
 
766
                *param = OB_DSIZE_X;
 
767
                return 1;
 
768
        }
 
769
        if( !strcmp( s, "dSizeY" ) ) {
 
770
                *param = OB_DSIZE_Y;
 
771
                return 1;
 
772
        }
 
773
        if( !strcmp( s, "dSizeZ" ) ) {
 
774
                *param = OB_DSIZE_Z;
 
775
                return 1;
 
776
        }
 
777
 
 
778
        if( !strcmp( s, "Layer" ) ) {
 
779
                *param = OB_LAY;
 
780
                return 1;
 
781
        }
 
782
        if( !strcmp( s, "Time" ) ) {
 
783
                *param = OB_TIME;
 
784
                return 1;
 
785
        }
 
786
 
 
787
        if( !strcmp( s, "ColR" ) ) {
 
788
                *param = OB_COL_R;
 
789
                return 1;
 
790
        }
 
791
        if( !strcmp( s, "ColG" ) ) {
 
792
                *param = OB_COL_G;
 
793
                return 1;
 
794
        }
 
795
        if( !strcmp( s, "ColB" ) ) {
 
796
                *param = OB_COL_B;
 
797
                return 1;
 
798
        }
 
799
        if( !strcmp( s, "ColA" ) ) {
 
800
                *param = OB_COL_A;
 
801
                return 1;
 
802
        }
 
803
        if( !strcmp( s, "FStreng" ) ) {
 
804
                *param = OB_PD_FSTR;
 
805
                return 1;
 
806
        }
 
807
        if( !strcmp( s, "FFall" ) ) {
 
808
                *param = OB_PD_FFALL;
 
809
                return 1;
 
810
        }
 
811
        if( !strcmp( s, "Damping" ) ) {
 
812
                *param = OB_PD_SDAMP;
 
813
                return 1;
 
814
        }
 
815
        if( !strcmp( s, "RDamp" ) ) {
 
816
                *param = OB_PD_RDAMP;
 
817
                return 1;
 
818
        }
 
819
        if( !strcmp( s, "Perm" ) ) {
 
820
                *param = OB_PD_PERM;
 
821
                return 1;
 
822
        }
 
823
 
 
824
        return ok;
 
825
}
 
826
 
 
827
 
 
828
/* 
 
829
   Function:  Ipo_addCurve
 
830
   Bpy:       Blender.Ipo.addCurve( 'curname')
 
831
 
 
832
   add a new curve to an existing IPO.
 
833
   example:
 
834
   ipo = Blender.Ipo.New('Object','ObIpo')
 
835
   cu = ipo.addCurve('LocX')
 
836
*/
 
837
 
 
838
static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args )
 
839
{
 
840
        int param = 0;          /* numeric curve name constant */
 
841
        int ok = 0;
 
842
        int ipofound = 0;
 
843
        char *cur_name = 0;     /* input arg: curve name */
 
844
        Ipo *ipo = 0;
 
845
        IpoCurve *icu = 0;
 
846
        Link *link;
 
847
 
 
848
        if( !PyArg_ParseTuple( args, "s", &cur_name ) )
 
849
                return ( EXPP_ReturnPyObjError
 
850
                         ( PyExc_TypeError, "expected string argument" ) );
 
851
 
 
852
 
 
853
        /* chase down the ipo list looking for ours */
 
854
        link = G.main->ipo.first;
 
855
 
 
856
        while( link ) {
 
857
                ipo = ( Ipo * ) link;
 
858
                if( ipo == self->ipo ) {
 
859
                        ipofound = 1;
 
860
                        break;
 
861
                }
 
862
                link = link->next;
 
863
        }
 
864
 
 
865
        if( ipo && ipofound ) {
 
866
                /* ok.  continue */
 
867
        } else {                /* runtime error here:  our ipo not found */
 
868
                return ( EXPP_ReturnPyObjError
 
869
                         ( PyExc_RuntimeError, "Ipo not found" ) );
 
870
        }
 
871
 
 
872
 
 
873
        /*
 
874
           depending on the block type, 
 
875
           check if the input arg curve name is valid 
 
876
           and set param to numeric value.
 
877
         */
 
878
        switch ( ipo->blocktype ) {
 
879
        case ID_OB:
 
880
                ok = Ipo_obIcuName( cur_name, &param );
 
881
                break;
 
882
        case ID_CA:
 
883
                ok = Ipo_caIcuName( cur_name, &param );
 
884
                break;
 
885
        case ID_LA:
 
886
                ok = Ipo_laIcuName( cur_name, &param );
 
887
                break;
 
888
        case ID_TE:
 
889
                ok = Ipo_texIcuName( cur_name, &param );
 
890
                break;
 
891
        case ID_WO:
 
892
                ok = Ipo_woIcuName( cur_name, &param );
 
893
                break;
 
894
        case ID_MA:
 
895
                ok = Ipo_maIcuName( cur_name, &param );
 
896
                break;
 
897
        case ID_AC:
 
898
                ok = Ipo_acIcuName( cur_name, &param );
 
899
                break;
 
900
        case IPO_CO:
 
901
                ok = Ipo_coIcuName( cur_name, &param );
 
902
                break;
 
903
        case ID_CU:
 
904
                ok = Ipo_cuIcuName( cur_name, &param );
 
905
                break;
 
906
        case ID_KE:
 
907
                ok = Ipo_keIcuName( cur_name, &param );
 
908
                break;
 
909
        case ID_SEQ:
 
910
                ok = Ipo_seqIcuName( cur_name, &param );
 
911
                break;
 
912
        default:
 
913
                ok = 0;
 
914
        }
 
915
 
 
916
        if( !ok )               /* curve type was invalid */
 
917
                return EXPP_ReturnPyObjError
 
918
                        ( PyExc_NameError, "curve name was invalid" );
 
919
 
 
920
        /* ask blender to create the new ipo curve */
 
921
        icu = get_ipocurve( NULL, ipo->blocktype, param, self->ipo );
 
922
 
 
923
        if( icu == 0 )          /* could not create curve */
 
924
                return EXPP_ReturnPyObjError
 
925
                        ( PyExc_RuntimeError,
 
926
                          "blender could not create ipo curve" );
 
927
 
 
928
        allspace( REMAKEIPO, 0 );
 
929
        EXPP_allqueue( REDRAWIPO, 0 );
 
930
 
 
931
        /* create a bpy wrapper for the new ipo curve */
 
932
        return IpoCurve_CreatePyObject( icu );
 
933
}
 
934
 
 
935
/* 
 
936
   Function:  Ipo_delCurve
 
937
   Bpy:       Blender.Ipo.delCurve(curtype)
 
938
 
 
939
   delete an existing curve from IPO.
 
940
   example:
 
941
       ipo = Blender.Ipo.New('Object','ObIpo')
 
942
       cu = ipo.delCurve('LocX')
 
943
*/
 
944
 
 
945
static PyObject *Ipo_delCurve( BPy_Ipo * self, PyObject * args )
 
946
{
 
947
        IpoCurve *icu;
 
948
        char *strname;
 
949
 
 
950
        if( !PyArg_ParseTuple( args, "s", &strname ) )
 
951
                return ( EXPP_ReturnPyObjError
 
952
                         ( PyExc_TypeError, "string argument" ) );
 
953
 
 
954
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
 
955
                char *str1 = getIpoCurveName( icu );
 
956
                if( !strcmp( str1, strname ) ) {
 
957
                        BLI_remlink( &( self->ipo->curve ), icu );
 
958
                        if( icu->bezt )
 
959
                                MEM_freeN( icu->bezt );
 
960
                        MEM_freeN( icu );
 
961
                        del_ipoCurve( icu );
 
962
                        Py_INCREF( Py_None );
 
963
                        return Py_None;
 
964
                }
 
965
        }
 
966
 
 
967
        return ( EXPP_ReturnPyObjError
 
968
                 ( PyExc_RuntimeError, "IpoCurve not found" ) );
 
969
}
 
970
 
 
971
 
 
972
 
 
973
static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args )
 
974
{
 
975
        char *str, *str1;
 
976
        IpoCurve *icu = 0;
 
977
 
 
978
        if( !PyArg_ParseTuple( args, "s", &str ) )
 
979
                return ( EXPP_ReturnPyObjError
 
980
                         ( PyExc_TypeError, "expected string argument" ) );
 
981
 
 
982
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
 
983
                str1 = getIpoCurveName( icu );
 
984
                if( !strcmp( str1, str ) )
 
985
                        return IpoCurve_CreatePyObject( icu );
 
986
        }
 
987
 
 
988
        Py_INCREF( Py_None );
 
989
        return Py_None;
 
990
}
 
991
 
 
992
static PyObject *Ipo_getCurves( BPy_Ipo * self )
 
993
{
 
994
        PyObject *attr = PyList_New( 0 );
 
995
        IpoCurve *icu;
 
996
        for( icu = self->ipo->curve.first; icu; icu = icu->next ) {
 
997
                PyList_Append( attr, IpoCurve_CreatePyObject( icu ) );
 
998
        }
 
999
        return attr;
 
1000
}
 
1001
 
 
1002
 
 
1003
static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args )
 
1004
{
 
1005
        int num = 0, i = 0;
 
1006
        IpoCurve *icu = 0;
 
1007
        if( !PyArg_ParseTuple( args, "i", &num ) )
 
1008
                return ( EXPP_ReturnPyObjError
 
1009
                         ( PyExc_TypeError, "expected int argument" ) );
 
1010
        icu = self->ipo->curve.first;
 
1011
        if( !icu )
 
1012
                return ( EXPP_ReturnPyObjError
 
1013
                         ( PyExc_TypeError, "No IPO curve" ) );
 
1014
        for( i = 0; i < num; i++ ) {
 
1015
                if( !icu )
 
1016
                        return ( EXPP_ReturnPyObjError
 
1017
                                 ( PyExc_TypeError, "Bad curve number" ) );
 
1018
                icu = icu->next;
 
1019
 
 
1020
        }
 
1021
        return ( PyInt_FromLong( icu->totvert ) );
 
1022
}
 
1023
 
 
1024
static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args )
 
1025
{
 
1026
        int num = 0, i = 0;
 
1027
        IpoCurve *icu = 0;
 
1028
        if( !PyArg_ParseTuple( args, "i", &num ) )
 
1029
                return ( EXPP_ReturnPyObjError
 
1030
                         ( PyExc_TypeError, "expected int argument" ) );
 
1031
        icu = self->ipo->curve.first;
 
1032
        if( !icu )
 
1033
                return ( EXPP_ReturnPyObjError
 
1034
                         ( PyExc_TypeError, "No IPO curve" ) );
 
1035
        for( i = 0; i < num; i++ ) {
 
1036
                if( !icu )
 
1037
                        return ( EXPP_ReturnPyObjError
 
1038
                                 ( PyExc_TypeError, "Bad curve number" ) );
 
1039
                icu = icu->next;
 
1040
 
 
1041
        }
 
1042
        icu->totvert--;
 
1043
        return ( PyInt_FromLong( icu->totvert ) );
 
1044
}
 
1045
 
 
1046
 
 
1047
/*
 
1048
 * Ipo_getCurveBP()
 
1049
 * this method is UNSUPPORTED.
 
1050
 * Calling this method throws a TypeError Exception.
 
1051
 *
 
1052
 * it looks like the original intent was to return the first point
 
1053
 * of a BPoint Ipo curve.  However, BPoint ipos are not currently
 
1054
 * implemented.
 
1055
 */
 
1056
 
 
1057
static PyObject *Ipo_getCurveBP( BPy_Ipo * self, PyObject * args )
 
1058
{
 
1059
 
 
1060
        /* unsupported method */
 
1061
        return EXPP_ReturnPyObjError( PyExc_NotImplementedError,
 
1062
                                      "bpoint ipos are not supported" );
 
1063
 
 
1064
#if 0
 
1065
 
 
1066
        struct BPoint *ptrbpoint;
 
1067
        int num = 0, i;
 
1068
        IpoCurve *icu;
 
1069
        PyObject *l;
 
1070
 
 
1071
        if( !PyArg_ParseTuple( args, "i", &num ) )
 
1072
                return ( EXPP_ReturnPyObjError
 
1073
                         ( PyExc_TypeError, "expected int argument" ) );
 
1074
        icu = self->ipo->curve.first;
 
1075
        if( !icu )
 
1076
                return ( EXPP_ReturnPyObjError
 
1077
                         ( PyExc_TypeError, "No IPO curve" ) );
 
1078
        for( i = 0; i < num; i++ ) {
 
1079
                if( !icu )
 
1080
                        return ( EXPP_ReturnPyObjError
 
1081
                                 ( PyExc_TypeError, "Bad curve number" ) );
 
1082
                icu = icu->next;
 
1083
 
 
1084
        }
 
1085
        ptrbpoint = icu->bp;
 
1086
        if( !ptrbpoint )
 
1087
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1088
                                              "No base point" );
 
1089
 
 
1090
        l = PyList_New( 0 );
 
1091
        for( i = 0; i < 4; i++ )
 
1092
                PyList_Append( l, PyFloat_FromDouble( ptrbpoint->vec[i] ) );
 
1093
        return l;
 
1094
#endif
 
1095
}
 
1096
 
 
1097
static PyObject *Ipo_getCurveBeztriple( BPy_Ipo * self, PyObject * args )
 
1098
{
 
1099
        struct BezTriple *ptrbt;
 
1100
        int num = 0, pos, i, j;
 
1101
        IpoCurve *icu;
 
1102
        PyObject *l = PyList_New( 0 );
 
1103
 
 
1104
        if( !PyArg_ParseTuple( args, "ii", &num, &pos ) )
 
1105
                return ( EXPP_ReturnPyObjError
 
1106
                         ( PyExc_TypeError, "expected int argument" ) );
 
1107
        icu = self->ipo->curve.first;
 
1108
        if( !icu )
 
1109
                return ( EXPP_ReturnPyObjError
 
1110
                         ( PyExc_TypeError, "No IPO curve" ) );
 
1111
        for( i = 0; i < num; i++ ) {
 
1112
                if( !icu )
 
1113
                        return ( EXPP_ReturnPyObjError
 
1114
                                 ( PyExc_TypeError, "Bad ipo number" ) );
 
1115
                icu = icu->next;
 
1116
        }
 
1117
        if( pos >= icu->totvert )
 
1118
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1119
                                              "Bad bezt number" );
 
1120
 
 
1121
        ptrbt = icu->bezt + pos;
 
1122
        if( !ptrbt )
 
1123
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1124
                                              "No bez triple" );
 
1125
 
 
1126
        for( i = 0; i < 3; i++ )
 
1127
                for( j = 0; j < 3; j++ )
 
1128
                        PyList_Append( l,
 
1129
                                       PyFloat_FromDouble( ptrbt->
 
1130
                                                           vec[i][j] ) );
 
1131
        return l;
 
1132
}
 
1133
 
 
1134
 
 
1135
static PyObject *Ipo_setCurveBeztriple( BPy_Ipo * self, PyObject * args )
 
1136
{
 
1137
        struct BezTriple *ptrbt;
 
1138
        int num = 0, pos, i;
 
1139
        IpoCurve *icu;
 
1140
        PyObject *listargs = 0;
 
1141
 
 
1142
        if( !PyArg_ParseTuple( args, "iiO", &num, &pos, &listargs ) )
 
1143
                return ( EXPP_ReturnPyObjError
 
1144
                         ( PyExc_TypeError,
 
1145
                           "expected int int object argument" ) );
 
1146
        if( !PyTuple_Check( listargs ) )
 
1147
                return ( EXPP_ReturnPyObjError
 
1148
                         ( PyExc_TypeError, "3rd arg should be a tuple" ) );
 
1149
        icu = self->ipo->curve.first;
 
1150
        if( !icu )
 
1151
                return ( EXPP_ReturnPyObjError
 
1152
                         ( PyExc_TypeError, "No IPO curve" ) );
 
1153
        for( i = 0; i < num; i++ ) {
 
1154
                if( !icu )
 
1155
                        return ( EXPP_ReturnPyObjError
 
1156
                                 ( PyExc_TypeError, "Bad ipo number" ) );
 
1157
                icu = icu->next;
 
1158
        }
 
1159
        if( pos >= icu->totvert )
 
1160
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1161
                                              "Bad bezt number" );
 
1162
 
 
1163
        ptrbt = icu->bezt + pos;
 
1164
        if( !ptrbt )
 
1165
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
1166
                                              "No bez triple" );
 
1167
 
 
1168
        for( i = 0; i < 9; i++ ) {
 
1169
                PyObject *xx = PyTuple_GetItem( listargs, i );
 
1170
                ptrbt->vec[i / 3][i % 3] = PyFloat_AsDouble( xx );
 
1171
        }
 
1172
 
 
1173
        Py_INCREF( Py_None );
 
1174
        return Py_None;
 
1175
}
 
1176
 
 
1177
 
 
1178
static PyObject *Ipo_EvaluateCurveOn( BPy_Ipo * self, PyObject * args )
 
1179
{
 
1180
        float eval_icu( IpoCurve * icu, float ipotime );
 
1181
 
 
1182
        int num = 0, i;
 
1183
        IpoCurve *icu;
 
1184
        float time = 0;
 
1185
 
 
1186
        if( !PyArg_ParseTuple( args, "if", &num, &time ) )
 
1187
                return ( EXPP_ReturnPyObjError
 
1188
                         ( PyExc_TypeError, "expected int argument" ) );
 
1189
 
 
1190
        icu = self->ipo->curve.first;
 
1191
        if( !icu )
 
1192
                return ( EXPP_ReturnPyObjError
 
1193
                         ( PyExc_TypeError, "No IPO curve" ) );
 
1194
 
 
1195
        for( i = 0; i < num; i++ ) {
 
1196
                if( !icu )
 
1197
                        return ( EXPP_ReturnPyObjError
 
1198
                                 ( PyExc_TypeError, "Bad ipo number" ) );
 
1199
                icu = icu->next;
 
1200
 
 
1201
        }
 
1202
        return PyFloat_FromDouble( eval_icu( icu, time ) );
 
1203
}
 
1204
 
 
1205
 
 
1206
static PyObject *Ipo_getCurvecurval( BPy_Ipo * self, PyObject * args )
 
1207
{
 
1208
        int numcurve = 0, i;
 
1209
        IpoCurve *icu;
 
1210
        char *stringname = 0, *str1 = 0;
 
1211
 
 
1212
        icu = self->ipo->curve.first;
 
1213
        if( !icu )
 
1214
                return ( EXPP_ReturnPyObjError
 
1215
                         ( PyExc_TypeError, "No IPO curve" ) );
 
1216
 
 
1217
        if( PyNumber_Check( PySequence_GetItem( args, 0 ) ) )   // args is an integer
 
1218
        {
 
1219
                if( !PyArg_ParseTuple( args, "i", &numcurve ) )
 
1220
                        return ( EXPP_ReturnPyObjError
 
1221
                                 ( PyExc_TypeError,
 
1222
                                   "expected int or string argument" ) );
 
1223
                for( i = 0; i < numcurve; i++ ) {
 
1224
                        if( !icu )
 
1225
                                return ( EXPP_ReturnPyObjError
 
1226
                                         ( PyExc_TypeError,
 
1227
                                           "Bad ipo number" ) );
 
1228
                        icu = icu->next;
 
1229
                }
 
1230
        }
 
1231
 
 
1232
        else                    // args is a string
 
1233
        {
 
1234
                if( !PyArg_ParseTuple( args, "s", &stringname ) )
 
1235
                        return ( EXPP_ReturnPyObjError
 
1236
                                 ( PyExc_TypeError,
 
1237
                                   "expected int or string argument" ) );
 
1238
                while( icu ) {
 
1239
                        str1 = getIpoCurveName( icu );
 
1240
                        if( !strcmp( str1, stringname ) )
 
1241
                                break;
 
1242
                        icu = icu->next;
 
1243
                }
 
1244
        }
 
1245
 
 
1246
        if( icu )
 
1247
                return PyFloat_FromDouble( icu->curval );
 
1248
        Py_INCREF( Py_None );
 
1249
        return Py_None;
902
1250
}
903
1251
 
904
1252
 
907
1255
/* Description: This is a callback function for the BPy_Ipo type. It is        */
908
1256
/*              the destructor function.                                     */
909
1257
/*****************************************************************************/
910
 
static void
911
 
IpoDeAlloc (BPy_Ipo * self)
 
1258
static void IpoDeAlloc( BPy_Ipo * self )
912
1259
{
913
 
  PyObject_DEL (self);
 
1260
        PyObject_DEL( self );
914
1261
}
915
1262
 
916
1263
/*****************************************************************************/
919
1266
/*              the function that accesses BPy_Ipo "member variables" and      */
920
1267
/*              methods.                                                     */
921
1268
/*****************************************************************************/
922
 
static PyObject *
923
 
IpoGetAttr (BPy_Ipo * self, char *name)
 
1269
static PyObject *IpoGetAttr( BPy_Ipo * self, char *name )
924
1270
{
925
 
  if (strcmp (name, "curves") == 0)
926
 
    return Ipo_getCurves (self);
927
 
  return Py_FindMethod (BPy_Ipo_methods, (PyObject *) self, name);
 
1271
        if( strcmp( name, "curves" ) == 0 )
 
1272
                return Ipo_getCurves( self );
 
1273
        return Py_FindMethod( BPy_Ipo_methods, ( PyObject * ) self, name );
928
1274
}
929
1275
 
930
1276
/*****************************************************************************/
932
1278
/* Description: This is a callback function for the BPy_Ipo type. It is the */
933
1279
/*              function that sets Ipo Data attributes (member variables).*/
934
1280
/*****************************************************************************/
935
 
static int
936
 
IpoSetAttr (BPy_Ipo * self, char *name, PyObject * value)
 
1281
static int IpoSetAttr( BPy_Ipo * self, char *name, PyObject * value )
937
1282
{
938
 
  return 0;                     /* normal exit */
 
1283
        return 0;               /* normal exit */
939
1284
}
940
1285
 
941
1286
/*****************************************************************************/
943
1288
/* Description: This is a callback function for the BPy_Ipo type. It           */
944
1289
/*              builds a meaninful string to represent ipo objects.          */
945
1290
/*****************************************************************************/
946
 
static PyObject *
947
 
IpoRepr (BPy_Ipo * self)
 
1291
static PyObject *IpoRepr( BPy_Ipo * self )
948
1292
{
949
 
  return PyString_FromFormat ("[Ipo \"%s\" %d]", self->ipo->id.name + 2,
950
 
                              self->ipo->blocktype);
 
1293
        return PyString_FromFormat( "[Ipo \"%s\" %d]", self->ipo->id.name + 2,
 
1294
                                    self->ipo->blocktype );
951
1295
}
952
1296
 
953
1297
/* Three Python Ipo_Type helper functions needed by the Object module: */
957
1301
/* Description: This function will create a new BPy_Ipo from an existing       */
958
1302
/*              Blender ipo structure.                                       */
959
1303
/*****************************************************************************/
960
 
PyObject *
961
 
Ipo_CreatePyObject (Ipo * ipo)
 
1304
PyObject *Ipo_CreatePyObject( Ipo * ipo )
962
1305
{
963
 
  BPy_Ipo *pyipo;
964
 
  pyipo = (BPy_Ipo *) PyObject_NEW (BPy_Ipo, &Ipo_Type);
965
 
  if (!pyipo)
966
 
    return EXPP_ReturnPyObjError (PyExc_MemoryError,
967
 
                                  "couldn't create BPy_Ipo object");
968
 
  pyipo->ipo = ipo;
969
 
  return (PyObject *) pyipo;
 
1306
        BPy_Ipo *pyipo;
 
1307
        pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type );
 
1308
        if( !pyipo )
 
1309
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
1310
                                              "couldn't create BPy_Ipo object" );
 
1311
        pyipo->ipo = ipo;
 
1312
        return ( PyObject * ) pyipo;
970
1313
}
971
1314
 
972
1315
/*****************************************************************************/
974
1317
/* Description: This function returns true when the given PyObject is of the */
975
1318
/*              type Ipo. Otherwise it will return false.                    */
976
1319
/*****************************************************************************/
977
 
int
978
 
Ipo_CheckPyObject (PyObject * pyobj)
 
1320
int Ipo_CheckPyObject( PyObject * pyobj )
979
1321
{
980
 
  return (pyobj->ob_type == &Ipo_Type);
 
1322
        return ( pyobj->ob_type == &Ipo_Type );
981
1323
}
982
1324
 
983
1325
/*****************************************************************************/
985
1327
/* Description: This function returns the Blender ipo from the given         */
986
1328
/*              PyObject.                                                    */
987
1329
/*****************************************************************************/
988
 
Ipo *
989
 
Ipo_FromPyObject (PyObject * pyobj)
 
1330
Ipo *Ipo_FromPyObject( PyObject * pyobj )
990
1331
{
991
 
  return ((BPy_Ipo *) pyobj)->ipo;
 
1332
        return ( ( BPy_Ipo * ) pyobj )->ipo;
992
1333
}