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

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/Ipocurve.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: Ipocurve.c,v 1.24 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, Nathan Letwory, Ken Hughes
28
29
 *
29
30
 * ***** END GPL/BL DUAL LICENSE BLOCK *****
30
31
 */
37
38
#include <BKE_library.h>
38
39
#include <BKE_ipo.h>
39
40
#include <BLI_blenlib.h>
 
41
#include <BSE_editipo.h>
 
42
#include <MEM_guardedalloc.h>
 
43
#include <DNA_ipo_types.h>
40
44
 
41
45
#include "constant.h"
42
46
#include "gen_utils.h"
43
 
#include "modules.h"
 
47
#include "BezTriple.h"
44
48
 
45
49
/*****************************************************************************/
46
50
/* Python API function prototypes for the IpoCurve module.                   */
47
51
/*****************************************************************************/
48
 
static PyObject *M_IpoCurve_New (PyObject * self, PyObject * args);
49
 
static PyObject *M_IpoCurve_Get (PyObject * self, PyObject * args);
 
52
static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args );
 
53
static PyObject *M_IpoCurve_Get( PyObject * self, PyObject * args );
50
54
 
51
55
/*****************************************************************************/
52
56
/* The following string definitions are used for documentation strings.      */
62
66
/*****************************************************************************/
63
67
 
64
68
struct PyMethodDef M_IpoCurve_methods[] = {
65
 
  {"New", (PyCFunction) M_IpoCurve_New, METH_VARARGS | METH_KEYWORDS,
66
 
   M_IpoCurve_New_doc},
67
 
  {"Get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
68
 
  {"get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
69
 
  {NULL, NULL, 0, NULL}
 
69
        {"New", ( PyCFunction ) M_IpoCurve_New, METH_VARARGS | METH_KEYWORDS,
 
70
         M_IpoCurve_New_doc},
 
71
        {"Get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
 
72
        {"get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
 
73
        {NULL, NULL, 0, NULL}
70
74
};
71
75
 
72
76
/*****************************************************************************/
73
77
/* Python C_IpoCurve methods declarations:                                   */
74
78
/*****************************************************************************/
75
 
static PyObject *IpoCurve_getName (C_IpoCurve * self);
76
 
static PyObject *IpoCurve_Recalc (C_IpoCurve * self);
77
 
static PyObject *IpoCurve_setName (C_IpoCurve * self, PyObject * args);
78
 
static PyObject *IpoCurve_addBezier (C_IpoCurve * self, PyObject * args);
79
 
static PyObject *IpoCurve_setInterpolation (C_IpoCurve * self,
80
 
                                            PyObject * args);
81
 
static PyObject *IpoCurve_getInterpolation (C_IpoCurve * self);
82
 
static PyObject *IpoCurve_setExtrapolation (C_IpoCurve * self,
83
 
                                            PyObject * args);
84
 
static PyObject *IpoCurve_getExtrapolation (C_IpoCurve * self);
85
 
static PyObject *IpoCurve_getPoints (C_IpoCurve * self);
 
79
static PyObject *IpoCurve_getName( C_IpoCurve * self );
 
80
static PyObject *IpoCurve_Recalc( C_IpoCurve * self );
 
81
static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args );
 
82
static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args );
 
83
static PyObject *IpoCurve_setInterpolation( C_IpoCurve * self,
 
84
                                            PyObject * args );
 
85
static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self );
 
86
static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self,
 
87
                                            PyObject * args );
 
88
static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self );
 
89
static PyObject *IpoCurve_getPoints( C_IpoCurve * self );
 
90
static int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value );
 
91
static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args );
86
92
 
87
93
/*****************************************************************************/
88
94
/* Python C_IpoCurve methods table:                                          */
89
95
/*****************************************************************************/
90
96
static PyMethodDef C_IpoCurve_methods[] = {
91
 
  /* name, method, flags, doc */
92
 
  {"getName", (PyCFunction) IpoCurve_getName, METH_NOARGS,
93
 
   "() - Return IpoCurve Data name"},
94
 
  {"Recalc", (PyCFunction) IpoCurve_Recalc, METH_NOARGS,
95
 
   "() - Return IpoCurve Data name"},
96
 
  {"update", (PyCFunction) IpoCurve_Recalc, METH_NOARGS,
97
 
   "() - Return IpoCurve Data name"},
98
 
  {"setName", (PyCFunction) IpoCurve_setName, METH_VARARGS,
99
 
   "(str) - Change IpoCurve Data name"},
100
 
  {"addBezier", (PyCFunction) IpoCurve_addBezier, METH_VARARGS,
101
 
   "(str) - Change IpoCurve Data name"},
102
 
  {"setInterpolation", (PyCFunction) IpoCurve_setInterpolation, METH_VARARGS,
103
 
   "(str) - Change IpoCurve Data name"},
104
 
  {"getInterpolation", (PyCFunction) IpoCurve_getInterpolation, METH_NOARGS,
105
 
   "(str) - Change IpoCurve Data name"},
106
 
  {"setExtrapolation", (PyCFunction) IpoCurve_setExtrapolation, METH_VARARGS,
107
 
   "(str) - Change IpoCurve Data name"},
108
 
  {"getExtrapolation", (PyCFunction) IpoCurve_getExtrapolation, METH_NOARGS,
109
 
   "(str) - Change IpoCurve Data name"},
110
 
  {"getPoints", (PyCFunction) IpoCurve_getPoints, METH_NOARGS,
111
 
   "(str) - Change IpoCurve Data name"},
112
 
  {NULL, NULL, 0, NULL}
 
97
        /* name, method, flags, doc */
 
98
        {"getName", ( PyCFunction ) IpoCurve_getName, METH_NOARGS,
 
99
         "() - Return IpoCurve name"},
 
100
        {"Recalc", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS,
 
101
         "() - deprecated method.  use recalc() instead"},
 
102
        {"recalc", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS,
 
103
         "() - Recomputes the curve after changes"},
 
104
        {"update", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS,
 
105
         "() - obsolete: use recalc method instead."},
 
106
        {"addBezier", ( PyCFunction ) IpoCurve_addBezier, METH_VARARGS,
 
107
         "(coordlist) -  Adds a Bezier point to a curve"},
 
108
        {"delBezier", ( PyCFunction ) IpoCurve_delBezier, METH_VARARGS,
 
109
         "(int) - delete Bezier point at specified index"},
 
110
        {"setInterpolation", ( PyCFunction ) IpoCurve_setInterpolation,
 
111
         METH_VARARGS, "(str) - Sets the interpolation type of the curve"},
 
112
        {"getInterpolation", ( PyCFunction ) IpoCurve_getInterpolation,
 
113
         METH_NOARGS, "() - Gets the interpolation type of the curve"},
 
114
        {"setExtrapolation", ( PyCFunction ) IpoCurve_setExtrapolation,
 
115
         METH_VARARGS, "(str) - Sets the extend mode of the curve"},
 
116
        {"getExtrapolation", ( PyCFunction ) IpoCurve_getExtrapolation,
 
117
         METH_NOARGS, "() - Gets the extend mode of the curve"},
 
118
        {"getPoints", ( PyCFunction ) IpoCurve_getPoints, METH_NOARGS,
 
119
         "() - Returns list of all bezTriples of the curve"},
 
120
        {"evaluate", ( PyCFunction ) IpoCurve_evaluate, METH_VARARGS,
 
121
         "(float) - Evaluate curve at given time"},
 
122
        {NULL, NULL, 0, NULL}
113
123
};
114
124
 
115
125
/*****************************************************************************/
116
126
/* Python IpoCurve_Type callback function prototypes:                        */
117
127
/*****************************************************************************/
118
 
static void IpoCurveDeAlloc (C_IpoCurve * self);
 
128
static void IpoCurveDeAlloc( C_IpoCurve * self );
119
129
//static int IpoCurvePrint (C_IpoCurve *self, FILE *fp, int flags);
120
 
static int IpoCurveSetAttr (C_IpoCurve * self, char *name, PyObject * v);
121
 
static PyObject *IpoCurveGetAttr (C_IpoCurve * self, char *name);
122
 
static PyObject *IpoCurveRepr (C_IpoCurve * self);
 
130
static int IpoCurveSetAttr( C_IpoCurve * self, char *name, PyObject * v );
 
131
static PyObject *IpoCurveGetAttr( C_IpoCurve * self, char *name );
 
132
static PyObject *IpoCurveRepr( C_IpoCurve * self );
123
133
 
124
134
/*****************************************************************************/
125
135
/* Python IpoCurve_Type structure definition:                                */
126
136
/*****************************************************************************/
127
137
PyTypeObject IpoCurve_Type = {
128
 
  PyObject_HEAD_INIT (NULL)     /* required macro */
129
 
    0,                          /* ob_size */
130
 
  "IpoCurve",                   /* tp_name */
131
 
  sizeof (C_IpoCurve),          /* tp_basicsize */
132
 
  0,                            /* tp_itemsize */
133
 
  /* methods */
134
 
  (destructor) IpoCurveDeAlloc, /* tp_dealloc */
135
 
  0,                            /* tp_print */
136
 
  (getattrfunc) IpoCurveGetAttr,        /* tp_getattr */
137
 
  (setattrfunc) IpoCurveSetAttr,        /* tp_setattr */
138
 
  0,                            /* tp_compare */
139
 
  (reprfunc) IpoCurveRepr,      /* tp_repr */
140
 
  0,                            /* tp_as_number */
141
 
  0,                            /* tp_as_sequence */
142
 
  0,                            /* tp_as_mapping */
143
 
  0,                            /* tp_as_hash */
144
 
  0, 0, 0, 0, 0, 0,
145
 
  0,                            /* tp_doc */
146
 
  0, 0, 0, 0, 0, 0,
147
 
  C_IpoCurve_methods,           /* tp_methods */
148
 
  0,                            /* tp_members */
 
138
        PyObject_HEAD_INIT( NULL )                  /* required macro */ 
 
139
        0,      /* ob_size */
 
140
        "IpoCurve",             /* tp_name */
 
141
        sizeof( C_IpoCurve ),   /* tp_basicsize */
 
142
        0,                      /* tp_itemsize */
 
143
        /* methods */
 
144
        ( destructor ) IpoCurveDeAlloc, /* tp_dealloc */
 
145
        0,                      /* tp_print */
 
146
        ( getattrfunc ) IpoCurveGetAttr,        /* tp_getattr */
 
147
        ( setattrfunc ) IpoCurveSetAttr,        /* tp_setattr */
 
148
        0,                      /* tp_compare */
 
149
        ( reprfunc ) IpoCurveRepr,      /* tp_repr */
 
150
        0,                      /* tp_as_number */
 
151
        0,                      /* tp_as_sequence */
 
152
        0,                      /* tp_as_mapping */
 
153
        0,                      /* tp_as_hash */
 
154
        0, 0, 0, 0, 0, 0,
 
155
        0,                      /* tp_doc */
 
156
        0, 0, 0, 0, 0, 0,
 
157
        C_IpoCurve_methods,     /* tp_methods */
 
158
        0,                      /* tp_members */
149
159
};
150
160
 
151
161
/*****************************************************************************/
152
 
/* Function:              M_IpoCurve_New                                          */
153
 
/* Python equivalent:     Blender.IpoCurve.New                                    */
 
162
/* Function:       M_IpoCurve_New                                          */
 
163
/* Python equivalent:     Blender.IpoCurve.New                   */
154
164
/*****************************************************************************/
155
 
static PyObject *
156
 
M_IpoCurve_New (PyObject * self, PyObject * args)
 
165
static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args )
157
166
{
158
 
 
159
 
 
160
 
  return 0;
 
167
        return 0;
161
168
}
162
169
 
163
170
/*****************************************************************************/
164
171
/* Function:              Ipo_Init                                           */
165
172
/*****************************************************************************/
166
 
PyObject *
167
 
IpoCurve_Init (void)
 
173
PyObject *IpoCurve_Init( void )
168
174
{
169
 
  PyObject *submodule;
170
 
 
171
 
  IpoCurve_Type.ob_type = &PyType_Type;
172
 
 
173
 
  submodule =
174
 
    Py_InitModule3 ("Blender.IpoCurve", M_IpoCurve_methods, M_IpoCurve_doc);
175
 
 
176
 
  return (submodule);
 
175
        PyObject *submodule;
 
176
 
 
177
        IpoCurve_Type.ob_type = &PyType_Type;
 
178
 
 
179
        submodule =
 
180
                Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
 
181
                                M_IpoCurve_doc );
 
182
 
 
183
        return ( submodule );
177
184
}
178
185
 
179
186
/*****************************************************************************/
184
191
/*                           passed in, a list of all ipo data names in the  */
185
192
/*                        current scene is returned.                         */
186
193
/*****************************************************************************/
187
 
static PyObject *
188
 
M_IpoCurve_Get (PyObject * self, PyObject * args)
 
194
static PyObject *M_IpoCurve_Get( PyObject * self, PyObject * args )
189
195
{
190
 
  return 0;
 
196
        Py_INCREF( Py_None );
 
197
        return Py_None;
191
198
}
192
199
 
193
200
/*****************************************************************************/
194
201
/* Python C_IpoCurve methods:                                                */
195
202
/*****************************************************************************/
196
203
 
197
 
static PyObject *
198
 
IpoCurve_setInterpolation (C_IpoCurve * self, PyObject * args)
199
 
{
200
 
  char *interpolationtype = 0;
201
 
  int id = -1;
202
 
  if (!PyArg_ParseTuple (args, "s", &interpolationtype))
203
 
    return (EXPP_ReturnPyObjError
204
 
            (PyExc_TypeError, "expected string argument"));
205
 
  if (!strcmp (interpolationtype, "Bezier"))
206
 
    id = IPO_BEZ;
207
 
  if (!strcmp (interpolationtype, "Constant"))
208
 
    id = IPO_CONST;
209
 
  if (!strcmp (interpolationtype, "Linear"))
210
 
    id = IPO_LIN;
211
 
  if (id == -1)
212
 
    return (EXPP_ReturnPyObjError
213
 
            (PyExc_TypeError, "bad interpolation type"));
214
 
 
215
 
  self->ipocurve->ipo = id;
216
 
  Py_INCREF (Py_None);
217
 
  return Py_None;
218
 
}
219
 
 
220
 
static PyObject *
221
 
IpoCurve_getInterpolation (C_IpoCurve * self)
222
 
{
223
 
  char *str = 0;
224
 
  IpoCurve *icu = self->ipocurve;
225
 
  if (icu->ipo == IPO_BEZ)
226
 
    str = "Bezier";
227
 
  if (icu->ipo == IPO_CONST)
228
 
    str = "Constant";
229
 
  if (icu->ipo == IPO_LIN)
230
 
    str = "Linear";
231
 
 
232
 
  if (!str)
233
 
    return (EXPP_ReturnPyObjError
234
 
            (PyExc_TypeError, "unknown interpolation type"));
235
 
  return PyString_FromString (str);
236
 
}
237
 
 
238
 
static PyObject *
239
 
IpoCurve_setExtrapolation (C_IpoCurve * self, PyObject * args)
240
 
{
241
 
 
242
 
  char *extrapolationtype = 0;
243
 
  int id = -1;
244
 
  if (!PyArg_ParseTuple (args, "s", &extrapolationtype))
245
 
    return (EXPP_ReturnPyObjError
246
 
            (PyExc_TypeError, "expected string argument"));
247
 
  if (!strcmp (extrapolationtype, "Constant"))
248
 
    id = 0;
249
 
  if (!strcmp (extrapolationtype, "Extrapolation"))
250
 
    id = 1;
251
 
  if (!strcmp (extrapolationtype, "Cyclic"))
252
 
    id = 2;
253
 
  if (!strcmp (extrapolationtype, "Cyclic_extrapolation"))
254
 
    id = 3;
255
 
 
256
 
  if (id == -1)
257
 
    return (EXPP_ReturnPyObjError
258
 
            (PyExc_TypeError, "bad interpolation type"));
259
 
  self->ipocurve->extrap = id;
260
 
  Py_INCREF (Py_None);
261
 
  return Py_None;
262
 
}
263
 
 
264
 
static PyObject *
265
 
IpoCurve_getExtrapolation (C_IpoCurve * self)
266
 
{
267
 
  char *str = 0;
268
 
  IpoCurve *icu = self->ipocurve;
269
 
  if (icu->extrap == 0)
270
 
    str = "Constant";
271
 
  if (icu->extrap == 1)
272
 
    str = "Extrapolation";
273
 
  if (icu->extrap == 2)
274
 
    str = "Cyclic";
275
 
  if (icu->extrap == 3)
276
 
    str = "Cyclic_extrapolation";
277
 
 
278
 
  return PyString_FromString (str);
279
 
}
280
 
 
281
 
static PyObject *
282
 
IpoCurve_addBezier (C_IpoCurve * self, PyObject * args)
283
 
{
284
 
  short MEM_freeN (void *vmemh);
285
 
  void *MEM_mallocN (unsigned int len, char *str);
286
 
  float x, y;
287
 
  int npoints;
288
 
  IpoCurve *icu;
289
 
  BezTriple *bzt, *tmp;
290
 
  static char name[10] = "mlml";
291
 
  PyObject *popo = 0;
292
 
  if (!PyArg_ParseTuple (args, "O", &popo))
293
 
    return (EXPP_ReturnPyObjError
294
 
          (PyExc_TypeError, "expected tuple argument"));
295
 
 
296
 
  x = PyFloat_AsDouble (PyTuple_GetItem (popo, 0));
297
 
  y = PyFloat_AsDouble (PyTuple_GetItem (popo, 1));
298
 
  icu = self->ipocurve;
299
 
  npoints = icu->totvert;
300
 
  tmp = icu->bezt;
301
 
  icu->bezt = MEM_mallocN (sizeof (BezTriple) * (npoints + 1), name);
302
 
  if (tmp)
303
 
    {
304
 
      memmove (icu->bezt, tmp, sizeof (BezTriple) * npoints);
305
 
      MEM_freeN (tmp);
306
 
    }
307
 
  memmove (icu->bezt + npoints, icu->bezt, sizeof (BezTriple));
308
 
  icu->totvert++;
309
 
  bzt = icu->bezt + npoints;
310
 
  bzt->vec[0][0] = x - 1;
311
 
  bzt->vec[1][0] = x;
312
 
  bzt->vec[2][0] = x + 1;
313
 
  bzt->vec[0][1] = y - 1;
314
 
  bzt->vec[1][1] = y;
315
 
  bzt->vec[2][1] = y + 1;
316
 
  /* set handle type to Auto */
317
 
  bzt->h1 = HD_AUTO;
318
 
  bzt->h2 = HD_AUTO;
319
 
 
320
 
  Py_INCREF (Py_None);
321
 
  return Py_None;
322
 
}
323
 
 
324
 
 
325
 
static PyObject *
326
 
IpoCurve_setName (C_IpoCurve * self, PyObject * args)
327
 
{
328
 
  return 0;
329
 
}
330
 
 
331
 
 
332
 
static PyObject *
333
 
IpoCurve_Recalc (C_IpoCurve * self)
334
 
{
335
 
  IpoCurve *icu = self->ipocurve;
336
 
 
337
 
  /* testhandles_ipocurve (icu); */
338
 
  /* call calchandles_* instead of testhandles_*  */
339
 
  /* I'm not sure this is a complete solution but since we do not */
340
 
  /* deal with curve handles right now, it seems ok */
341
 
  calchandles_ipocurve (icu);
342
 
 
343
 
  Py_INCREF (Py_None);
344
 
  return Py_None;
345
 
}
346
 
 
347
 
static PyObject *
348
 
IpoCurve_getName (C_IpoCurve * self)
349
 
{
350
 
  const int objectType=self->ipocurve->blocktype;
351
 
  const int trackType=self->ipocurve->adrcode;
352
 
  
353
 
  const char * ob_nametab[24] = {"LocX","LocY","LocZ","dLocX","dLocY","dLocZ",
354
 
    "RotX","RotY","RotZ","dRotX","dRotY","dRotZ","SizeX","SizeY","SizeZ",
355
 
    "dSizeX","dSizeY","dSizeZ","Layer","Time","ColR","ColG","ColB","ColA"};
356
 
    
357
 
  const char * ac_nametab[5] = {"QuatW", "QuatX", "QuatY", "QuatZ"};
358
 
  
359
 
  switch (objectType) {
360
 
  case ID_OB: {
361
 
    if (self->ipocurve->adrcode <= 0 ) {
362
 
      return PyString_FromString("Index too small");
363
 
    } else if (self->ipocurve->adrcode >= 25 ) {
364
 
      return PyString_FromString("Index too big");
365
 
    } else {  
366
 
      return PyString_FromString(ob_nametab[trackType-1]);
367
 
    }
368
 
  }
369
 
  break;
370
 
  
371
 
  case ID_AC: {
372
 
    switch (trackType) {
373
 
    case 1: case 2: case 3: case 13: case 14: case 15:
374
 
      return PyString_FromString(ob_nametab[trackType-1]);
375
 
    break;
376
 
    
377
 
    case 25: case 26: case 27: case 28:
378
 
      return PyString_FromString(ac_nametab[trackType-25]);
379
 
      break;
380
 
    default:
381
 
      return PyString_FromString("Index out of range");
382
 
    }
383
 
  }
384
 
  break;
385
 
 
386
 
  default:
387
 
    return EXPP_ReturnPyObjError (PyExc_TypeError,
388
 
                    "This function doesn't support this ipocurve type yet");
389
 
  }
390
 
}
391
 
 
392
 
static void
393
 
IpoCurveDeAlloc (C_IpoCurve * self)
394
 
{
395
 
  PyObject_DEL (self);
396
 
}
397
 
 
398
 
static PyObject *
399
 
IpoCurve_getPoints (C_IpoCurve * self)
400
 
{
401
 
  struct BezTriple *bezt;
402
 
  PyObject *po;
403
 
 
404
 
  PyObject *list = PyList_New (0);
405
 
  int i;
406
 
 
407
 
  for (i = 0; i < self->ipocurve->totvert; i++)
408
 
    {
409
 
      bezt = self->ipocurve->bezt + i;
410
 
      po = BezTriple_CreatePyObject (bezt);
 
204
static PyObject *IpoCurve_setInterpolation( C_IpoCurve * self,
 
205
                                            PyObject * args )
 
206
{
 
207
        char *interpolationtype = 0;
 
208
        int id = -1;
 
209
        if( !PyArg_ParseTuple( args, "s", &interpolationtype ) )
 
210
                return ( EXPP_ReturnPyObjError
 
211
                         ( PyExc_TypeError, "expected string argument" ) );
 
212
        if( !strcmp( interpolationtype, "Bezier" ) )
 
213
                id = IPO_BEZ;
 
214
        if( !strcmp( interpolationtype, "Constant" ) )
 
215
                id = IPO_CONST;
 
216
        if( !strcmp( interpolationtype, "Linear" ) )
 
217
                id = IPO_LIN;
 
218
        if( id == -1 )
 
219
                return ( EXPP_ReturnPyObjError
 
220
                         ( PyExc_TypeError, "bad interpolation type" ) );
 
221
 
 
222
        self->ipocurve->ipo = id;
 
223
        Py_INCREF( Py_None );
 
224
        return Py_None;
 
225
}
 
226
 
 
227
static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self )
 
228
{
 
229
        char *str = 0;
 
230
        IpoCurve *icu = self->ipocurve;
 
231
        if( icu->ipo == IPO_BEZ )
 
232
                str = "Bezier";
 
233
        if( icu->ipo == IPO_CONST )
 
234
                str = "Constant";
 
235
        if( icu->ipo == IPO_LIN )
 
236
                str = "Linear";
 
237
 
 
238
        if( !str )
 
239
                return ( EXPP_ReturnPyObjError
 
240
                         ( PyExc_TypeError, "unknown interpolation type" ) );
 
241
        return PyString_FromString( str );
 
242
}
 
243
 
 
244
static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self,
 
245
                                            PyObject * args )
 
246
{
 
247
 
 
248
        char *extrapolationtype = 0;
 
249
        int id = -1;
 
250
        if( !PyArg_ParseTuple( args, "s", &extrapolationtype ) )
 
251
                return ( EXPP_ReturnPyObjError
 
252
                         ( PyExc_TypeError, "expected string argument" ) );
 
253
        if( !strcmp( extrapolationtype, "Constant" ) )
 
254
                id = 0;
 
255
        if( !strcmp( extrapolationtype, "Extrapolation" ) )
 
256
                id = 1;
 
257
        if( !strcmp( extrapolationtype, "Cyclic" ) )
 
258
                id = 2;
 
259
        if( !strcmp( extrapolationtype, "Cyclic_extrapolation" ) )
 
260
                id = 3;
 
261
 
 
262
        if( id == -1 )
 
263
                return ( EXPP_ReturnPyObjError
 
264
                         ( PyExc_TypeError, "bad interpolation type" ) );
 
265
        self->ipocurve->extrap = id;
 
266
        Py_INCREF( Py_None );
 
267
        return Py_None;
 
268
}
 
269
 
 
270
static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self )
 
271
{
 
272
        char *str = 0;
 
273
        IpoCurve *icu = self->ipocurve;
 
274
        if( icu->extrap == 0 )
 
275
                str = "Constant";
 
276
        if( icu->extrap == 1 )
 
277
                str = "Extrapolation";
 
278
        if( icu->extrap == 2 )
 
279
                str = "Cyclic";
 
280
        if( icu->extrap == 3 )
 
281
                str = "Cyclic_extrapolation";
 
282
 
 
283
        return PyString_FromString( str );
 
284
}
 
285
 
 
286
static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args )
 
287
{
 
288
        short MEM_freeN( void *vmemh );
 
289
        void *MEM_mallocN( unsigned int len, char *str );
 
290
        float x, y;
 
291
        int npoints;
 
292
        IpoCurve *icu;
 
293
        BezTriple *bzt, *tmp;
 
294
        static char name[10] = "mlml";
 
295
        PyObject *popo = 0;
 
296
        if( !PyArg_ParseTuple( args, "O", &popo ) )
 
297
                return ( EXPP_ReturnPyObjError
 
298
                         ( PyExc_TypeError, "expected tuple argument" ) );
 
299
 
 
300
        x = PyFloat_AsDouble( PyTuple_GetItem( popo, 0 ) );
 
301
        y = PyFloat_AsDouble( PyTuple_GetItem( popo, 1 ) );
 
302
        icu = self->ipocurve;
 
303
        npoints = icu->totvert;
 
304
        tmp = icu->bezt;
 
305
        icu->bezt = MEM_mallocN( sizeof( BezTriple ) * ( npoints + 1 ), name );
 
306
        if( tmp ) {
 
307
                memmove( icu->bezt, tmp, sizeof( BezTriple ) * npoints );
 
308
                MEM_freeN( tmp );
 
309
        }
 
310
        memmove( icu->bezt + npoints, icu->bezt, sizeof( BezTriple ) );
 
311
        icu->totvert++;
 
312
        bzt = icu->bezt + npoints;
 
313
        bzt->vec[0][0] = x - 1;
 
314
        bzt->vec[1][0] = x;
 
315
        bzt->vec[2][0] = x + 1;
 
316
        bzt->vec[0][1] = y - 1;
 
317
        bzt->vec[1][1] = y;
 
318
        bzt->vec[2][1] = y + 1;
 
319
        /* set handle type to Auto */
 
320
        bzt->h1 = HD_AUTO;
 
321
        bzt->h2 = HD_AUTO;
 
322
 
 
323
        Py_INCREF( Py_None );
 
324
        return Py_None;
 
325
}
 
326
 
 
327
/*
 
328
   Function:  IpoCurve_delBezier
 
329
   Bpy:       Blender.Ipocurve.delBezier(0)
 
330
 
 
331
   Delete an BezTriple from an IPO curve.
 
332
   example:
 
333
       ipo = Blender.Ipo.Get('ObIpo')
 
334
       cu = ipo.getCurve('LocX')
 
335
       cu.delBezier(0)
 
336
*/
 
337
 
 
338
static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args )
 
339
{
 
340
        //short MEM_freeN( void *vmemh );
 
341
        //void *MEM_mallocN( unsigned int len, char *str );
 
342
        int npoints;
 
343
        int index;
 
344
        IpoCurve *icu;
 
345
        BezTriple *tmp;
 
346
 
 
347
        if( !PyArg_ParseTuple( args, "i", &index ) )
 
348
                return ( EXPP_ReturnPyObjError
 
349
                         ( PyExc_TypeError, "expected int argument" ) );
 
350
 
 
351
        icu = self->ipocurve;
 
352
        npoints = icu->totvert - 1;
 
353
 
 
354
        /* if index is negative, count from end of list */
 
355
        if( index < 0 )
 
356
                index += icu->totvert;
 
357
        /* check range of index */
 
358
        if( index < 0 || index > npoints )
 
359
                return ( EXPP_ReturnPyObjError
 
360
                         ( PyExc_ValueError, "index outside of list" ) );
 
361
 
 
362
        tmp = icu->bezt;
 
363
 
 
364
        /*
 
365
           if delete empties list, then delete it, otherwise copy the remaining
 
366
           points to a new list
 
367
         */
 
368
 
 
369
        if( npoints == 0 ) {
 
370
                icu->bezt = NULL;
 
371
        } else {
 
372
                icu->bezt =
 
373
                        MEM_mallocN( sizeof( BezTriple ) * npoints, "bezt" );
 
374
                if( index > 0 )
 
375
                        memmove( icu->bezt, tmp, index * sizeof( BezTriple ) );
 
376
                if( index < npoints )
 
377
                        memmove( icu->bezt + index, tmp + index + 1,
 
378
                                 ( npoints - index ) * sizeof( BezTriple ) );
 
379
        }
 
380
 
 
381
        /* free old list, adjust vertex count */
 
382
        MEM_freeN( tmp );
 
383
        icu->totvert--;
 
384
 
 
385
        /* call calchandles_* instead of testhandles_*  */
 
386
        /* I'm not sure this is a complete solution but since we do not */
 
387
        /* deal with curve handles right now, it seems ok */
 
388
        calchandles_ipocurve( icu );
 
389
 
 
390
        Py_INCREF( Py_None );
 
391
        return Py_None;
 
392
}
 
393
 
 
394
 
 
395
static PyObject *IpoCurve_Recalc( C_IpoCurve * self )
 
396
{
 
397
        IpoCurve *icu = self->ipocurve;
 
398
 
 
399
        /* testhandles_ipocurve (icu); */
 
400
        /* call calchandles_* instead of testhandles_*  */
 
401
        /* I'm not sure this is a complete solution but since we do not */
 
402
        /* deal with curve handles right now, it seems ok */
 
403
        calchandles_ipocurve( icu );
 
404
 
 
405
        Py_INCREF( Py_None );
 
406
        return Py_None;
 
407
}
 
408
 
 
409
static PyObject *IpoCurve_getName( C_IpoCurve * self )
 
410
{
 
411
        switch ( self->ipocurve->blocktype ) {
 
412
        case ID_OB:
 
413
                return PyString_FromString( getname_ob_ei( self->ipocurve->adrcode, 1 ) );      /* solve: what if EffX/Y/Z are wanted? */
 
414
        case ID_TE:
 
415
                return PyString_FromString( getname_tex_ei
 
416
                                            ( self->ipocurve->adrcode ) );
 
417
        case ID_LA:
 
418
                return PyString_FromString( getname_la_ei
 
419
                                            ( self->ipocurve->adrcode ) );
 
420
        case ID_MA:
 
421
                return PyString_FromString( getname_mat_ei
 
422
                                            ( self->ipocurve->adrcode ) );
 
423
        case ID_CA:
 
424
                return PyString_FromString( getname_cam_ei
 
425
                                            ( self->ipocurve->adrcode ) );
 
426
        case ID_WO:
 
427
                return PyString_FromString( getname_world_ei
 
428
                                            ( self->ipocurve->adrcode ) );
 
429
        case ID_AC:
 
430
                return PyString_FromString( getname_ac_ei
 
431
                                            ( self->ipocurve->adrcode ) );
 
432
        case ID_CU:
 
433
                return PyString_FromString( getname_cu_ei
 
434
                                            ( self->ipocurve->adrcode ) );
 
435
        case ID_KE:
 
436
                return PyString_FromString( getname_key_ei
 
437
                                            ( self->ipocurve->adrcode ) );
 
438
        case ID_SEQ:
 
439
                return PyString_FromString( getname_seq_ei
 
440
                                            ( self->ipocurve->adrcode ) );
 
441
        case IPO_CO:
 
442
                return PyString_FromString( getname_co_ei
 
443
                                            ( self->ipocurve->adrcode ) );
 
444
        default:
 
445
                return EXPP_ReturnPyObjError( PyExc_TypeError,
 
446
                                              "This function doesn't support this ipocurve type yet" );
 
447
        }
 
448
 
 
449
        return PyString_FromString( "" );
 
450
}
 
451
 
 
452
static void IpoCurveDeAlloc( C_IpoCurve * self )
 
453
{
 
454
        PyObject_DEL( self );
 
455
}
 
456
 
 
457
static PyObject *IpoCurve_getPoints( C_IpoCurve * self )
 
458
{
 
459
        struct BezTriple *bezt;
 
460
        PyObject *po;
 
461
 
 
462
        PyObject *list = PyList_New( 0 );
 
463
        int i;
 
464
 
 
465
        for( i = 0; i < self->ipocurve->totvert; i++ ) {
 
466
                bezt = self->ipocurve->bezt + i;
 
467
                po = BezTriple_CreatePyObject( bezt );
411
468
#if 0
412
 
      if (BezTriple_CheckPyObject (po))
413
 
        printf ("po is ok\n");
414
 
      else
415
 
        printf ("po is hosed\n");
 
469
                if( BezTriple_CheckPyObject( po ) )
 
470
                        printf( "po is ok\n" );
 
471
                else
 
472
                        printf( "po is hosed\n" );
416
473
#endif
417
 
      PyList_Append (list, po);
418
 
      /*
419
 
         PyList_Append( list, BezTriple_CreatePyObject(bezt));
420
 
       */
421
 
    }
422
 
  return list;
 
474
                PyList_Append( list, po );
 
475
                /*
 
476
                   PyList_Append( list, BezTriple_CreatePyObject(bezt));
 
477
                 */
 
478
        }
 
479
        return list;
423
480
}
424
481
 
425
482
 
426
 
int
427
 
IpoCurve_setPoints (C_IpoCurve * self, PyObject * value)
 
483
int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value )
428
484
{
429
 
  struct BezTriple *bezt;
430
 
  PyObject *l = PyList_New (0);
431
 
  int i;
432
 
  for (i = 0; i < self->ipocurve->totvert; i++)
433
 
    {
434
 
      bezt = self->ipocurve->bezt + i;
435
 
      PyList_Append (l, BezTriple_CreatePyObject (bezt));
436
 
    }
437
 
  return 0;
 
485
        struct BezTriple *bezt;
 
486
        PyObject *l = PyList_New( 0 );
 
487
        int i;
 
488
        for( i = 0; i < self->ipocurve->totvert; i++ ) {
 
489
                bezt = self->ipocurve->bezt + i;
 
490
                PyList_Append( l, BezTriple_CreatePyObject( bezt ) );
 
491
        }
 
492
        return 0;
438
493
}
439
494
 
440
495
 
441
496
/*****************************************************************************/
442
 
/* Function:    IpoCurveGetAttr                                                   */
443
 
/* Description: This is a callback function for the C_IpoCurve type. It is        */
444
 
/*              the function that accesses C_IpoCurve "member variables" and      */
 
497
/* Function:    IpoCurveGetAttr                                         */
 
498
/* Description: This is a callback function for the C_IpoCurve type. It is   */
 
499
/*              the function that accesses C_IpoCurve "member variables" and */
445
500
/*              methods.                                                     */
446
501
/*****************************************************************************/
447
 
static PyObject *
448
 
IpoCurveGetAttr (C_IpoCurve * self, char *name)
449
 
{
450
 
  if (strcmp (name, "bezierPoints") == 0)
451
 
    return IpoCurve_getPoints (self);
452
 
  if (strcmp (name, "name") == 0)
453
 
    return IpoCurve_getName (self);
454
 
  return Py_FindMethod (C_IpoCurve_methods, (PyObject *) self, name);
455
 
}
456
 
 
457
 
/*****************************************************************************/
458
 
/* Function:    IpoCurveSetAttr                                                */
459
 
/* Description: This is a callback function for the C_IpoCurve type. It is the */
460
 
/*              function that sets IpoCurve Data attributes (member variables).*/
461
 
/*****************************************************************************/
462
 
static int
463
 
IpoCurveSetAttr (C_IpoCurve * self, char *name, PyObject * value)
464
 
{
465
 
  if (strcmp (name, "bezierPoints") == 0)
466
 
    return IpoCurve_setPoints (self, value);
467
 
  return 0;                     /* normal exit */
468
 
}
469
 
 
470
 
/*****************************************************************************/
471
 
/* Function:    IpoCurveRepr                                                      */
472
 
/* Description: This is a callback function for the C_IpoCurve type. It           */
 
502
static PyObject *IpoCurveGetAttr( C_IpoCurve * self, char *name )
 
503
{
 
504
        if( strcmp( name, "bezierPoints" ) == 0 )
 
505
                return IpoCurve_getPoints( self );
 
506
        if( strcmp( name, "name" ) == 0 )
 
507
                return IpoCurve_getName( self );
 
508
        return Py_FindMethod( C_IpoCurve_methods, ( PyObject * ) self, name );
 
509
}
 
510
 
 
511
/*****************************************************************************/
 
512
/* Function:    IpoCurveSetAttr                                    */
 
513
/* Description: This is a callback function for the C_IpoCurve type. It  */
 
514
/*               sets IpoCurve Data attributes (member variables).*/
 
515
/*****************************************************************************/
 
516
static int IpoCurveSetAttr( C_IpoCurve * self, char *name, PyObject * value )
 
517
{
 
518
        if( strcmp( name, "bezierPoints" ) == 0 )
 
519
                return IpoCurve_setPoints( self, value );
 
520
        return 0;               /* normal exit */
 
521
}
 
522
 
 
523
/*****************************************************************************/
 
524
/* Function:    IpoCurveRepr                                             */
 
525
/* Description: This is a callback function for the C_IpoCurve type. It      */
473
526
/*              builds a meaninful string to represent ipo objects.          */
474
527
/*****************************************************************************/
475
 
static PyObject *
476
 
IpoCurveRepr (C_IpoCurve * self)
 
528
static PyObject *IpoCurveRepr( C_IpoCurve * self )
477
529
{
478
 
  void GetIpoCurveName (IpoCurve * icu, char *s);
479
 
  char s[100], s1[100];
480
 
  GetIpoCurveName (self->ipocurve, s1);
481
 
  sprintf (s, "IpoCurve %s \n", s1);
482
 
  return PyString_FromString (s);
 
530
        char s[100];
 
531
        sprintf( s, "[IpoCurve \"%s\"]\n", getIpoCurveName( self->ipocurve ) );
 
532
        return PyString_FromString( s );
483
533
}
484
534
 
485
535
/* Three Python IpoCurve_Type helper functions needed by the Object module: */
486
536
 
487
537
/*****************************************************************************/
488
 
/* Function:    IpoCurve_CreatePyObject                                           */
489
 
/* Description: This function will create a new C_IpoCurve from an existing       */
 
538
/* Function:    IpoCurve_CreatePyObject                                     */
 
539
/* Description: This function will create a new C_IpoCurve from an existing  */
490
540
/*              Blender ipo structure.                                       */
491
541
/*****************************************************************************/
492
 
PyObject *
493
 
IpoCurve_CreatePyObject (IpoCurve * ipo)
 
542
PyObject *IpoCurve_CreatePyObject( IpoCurve * ipo )
494
543
{
495
 
  C_IpoCurve *pyipo;
496
 
 
497
 
  pyipo = (C_IpoCurve *) PyObject_NEW (C_IpoCurve, &IpoCurve_Type);
498
 
 
499
 
  if (!pyipo)
500
 
    return EXPP_ReturnPyObjError (PyExc_MemoryError,
501
 
                                  "couldn't create C_IpoCurve object");
502
 
 
503
 
  pyipo->ipocurve = ipo;
504
 
 
505
 
  return (PyObject *) pyipo;
 
544
        C_IpoCurve *pyipo;
 
545
 
 
546
        pyipo = ( C_IpoCurve * ) PyObject_NEW( C_IpoCurve, &IpoCurve_Type );
 
547
 
 
548
        if( !pyipo )
 
549
                return EXPP_ReturnPyObjError( PyExc_MemoryError,
 
550
                                              "couldn't create C_IpoCurve object" );
 
551
 
 
552
        pyipo->ipocurve = ipo;
 
553
 
 
554
        return ( PyObject * ) pyipo;
506
555
}
507
556
 
508
557
/*****************************************************************************/
509
 
/* Function:    IpoCurve_CheckPyObject                                            */
 
558
/* Function:    IpoCurve_CheckPyObject                                      */
510
559
/* Description: This function returns true when the given PyObject is of the */
511
 
/*              type IpoCurve. Otherwise it will return false.                    */
 
560
/*              type IpoCurve. Otherwise it will return false.               */
512
561
/*****************************************************************************/
513
 
int
514
 
IpoCurve_CheckPyObject (PyObject * pyobj)
 
562
int IpoCurve_CheckPyObject( PyObject * pyobj )
515
563
{
516
 
  return (pyobj->ob_type == &IpoCurve_Type);
 
564
        return ( pyobj->ob_type == &IpoCurve_Type );
517
565
}
518
566
 
519
567
/*****************************************************************************/
520
 
/* Function:    IpoCurve_FromPyObject                                             */
 
568
/* Function:    IpoCurve_FromPyObject                                       */
521
569
/* Description: This function returns the Blender ipo from the given         */
522
570
/*              PyObject.                                                    */
523
571
/*****************************************************************************/
524
 
IpoCurve *
525
 
IpoCurve_FromPyObject (PyObject * pyobj)
526
 
{
527
 
  return ((C_IpoCurve *) pyobj)->ipocurve;
 
572
IpoCurve *IpoCurve_FromPyObject( PyObject * pyobj )
 
573
{
 
574
        return ( ( C_IpoCurve * ) pyobj )->ipocurve;
 
575
}
 
576
 
 
577
/***************************************************************************/
 
578
/* Function:      IpoCurve_evaluate( time )                                */
 
579
/* Description:   Evaluates IPO curve at the given time.                   */
 
580
/***************************************************************************/
 
581
 
 
582
static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args )
 
583
{
 
584
 
 
585
        float time = 0;
 
586
        double eval = 0;
 
587
 
 
588
        /* expecting float */
 
589
        if( !PyArg_ParseTuple( args, "f", &time ) )
 
590
                return ( EXPP_ReturnPyObjError
 
591
                         ( PyExc_TypeError, "expected float argument" ) );
 
592
 
 
593
        eval = ( double ) eval_icu( self->ipocurve, time );
 
594
 
 
595
        return PyFloat_FromDouble( eval );
 
596
 
 
597
}
 
598
 
 
599
/*
 
600
  internal bpy func to get Ipo Curve Name.
 
601
  We are returning a pointer to string constants so there are
 
602
  no issues with who owns pointers.
 
603
*/
 
604
 
 
605
char *getIpoCurveName( IpoCurve * icu )
 
606
{
 
607
        switch ( icu->blocktype ) {
 
608
        case ID_MA:
 
609
                return getname_mat_ei( icu->adrcode );
 
610
        case ID_WO:
 
611
                return getname_world_ei( icu->adrcode );
 
612
        case ID_CA:
 
613
                return getname_cam_ei( icu->adrcode );
 
614
        case ID_OB:
 
615
                return getname_ob_ei( icu->adrcode, 1 );
 
616
                /* solve: what if EffX/Y/Z are wanted? */
 
617
        case ID_TE:
 
618
                return getname_tex_ei( icu->adrcode );
 
619
        case ID_LA:
 
620
                return getname_la_ei( icu->adrcode );
 
621
        case ID_AC:
 
622
                return getname_ac_ei( icu->adrcode );
 
623
        case ID_CU:
 
624
                return getname_cu_ei( icu->adrcode );
 
625
        case ID_KE:
 
626
                return getname_key_ei( icu->adrcode );
 
627
        case ID_SEQ:
 
628
                return getname_seq_ei( icu->adrcode );
 
629
        case IPO_CO:
 
630
                return getname_co_ei( icu->adrcode );
 
631
        }
 
632
        return NULL;
528
633
}