62
66
/*****************************************************************************/
64
68
struct PyMethodDef M_IpoCurve_methods[] = {
65
{"New", (PyCFunction) M_IpoCurve_New, METH_VARARGS | METH_KEYWORDS,
67
{"Get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
68
{"get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
69
{"New", ( PyCFunction ) M_IpoCurve_New, METH_VARARGS | METH_KEYWORDS,
71
{"Get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
72
{"get", M_IpoCurve_Get, METH_VARARGS, M_IpoCurve_Get_doc},
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,
81
static PyObject *IpoCurve_getInterpolation (C_IpoCurve * self);
82
static PyObject *IpoCurve_setExtrapolation (C_IpoCurve * self,
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,
85
static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self );
86
static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self,
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 );
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}
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 );
124
134
/*****************************************************************************/
125
135
/* Python IpoCurve_Type structure definition: */
126
136
/*****************************************************************************/
127
137
PyTypeObject IpoCurve_Type = {
128
PyObject_HEAD_INIT (NULL) /* required macro */
130
"IpoCurve", /* tp_name */
131
sizeof (C_IpoCurve), /* tp_basicsize */
134
(destructor) IpoCurveDeAlloc, /* tp_dealloc */
136
(getattrfunc) IpoCurveGetAttr, /* tp_getattr */
137
(setattrfunc) IpoCurveSetAttr, /* tp_setattr */
139
(reprfunc) IpoCurveRepr, /* tp_repr */
140
0, /* tp_as_number */
141
0, /* tp_as_sequence */
142
0, /* tp_as_mapping */
147
C_IpoCurve_methods, /* tp_methods */
138
PyObject_HEAD_INIT( NULL ) /* required macro */
140
"IpoCurve", /* tp_name */
141
sizeof( C_IpoCurve ), /* tp_basicsize */
144
( destructor ) IpoCurveDeAlloc, /* tp_dealloc */
146
( getattrfunc ) IpoCurveGetAttr, /* tp_getattr */
147
( setattrfunc ) IpoCurveSetAttr, /* tp_setattr */
149
( reprfunc ) IpoCurveRepr, /* tp_repr */
150
0, /* tp_as_number */
151
0, /* tp_as_sequence */
152
0, /* tp_as_mapping */
157
C_IpoCurve_methods, /* tp_methods */
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
/*****************************************************************************/
156
M_IpoCurve_New (PyObject * self, PyObject * args)
165
static PyObject *M_IpoCurve_New( PyObject * self, PyObject * args )
163
170
/*****************************************************************************/
164
171
/* Function: Ipo_Init */
165
172
/*****************************************************************************/
173
PyObject *IpoCurve_Init( void )
171
IpoCurve_Type.ob_type = &PyType_Type;
174
Py_InitModule3 ("Blender.IpoCurve", M_IpoCurve_methods, M_IpoCurve_doc);
177
IpoCurve_Type.ob_type = &PyType_Type;
180
Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods,
183
return ( submodule );
179
186
/*****************************************************************************/
184
191
/* passed in, a list of all ipo data names in the */
185
192
/* current scene is returned. */
186
193
/*****************************************************************************/
188
M_IpoCurve_Get (PyObject * self, PyObject * args)
194
static PyObject *M_IpoCurve_Get( PyObject * self, PyObject * args )
196
Py_INCREF( Py_None );
193
200
/*****************************************************************************/
194
201
/* Python C_IpoCurve methods: */
195
202
/*****************************************************************************/
198
IpoCurve_setInterpolation (C_IpoCurve * self, PyObject * args)
200
char *interpolationtype = 0;
202
if (!PyArg_ParseTuple (args, "s", &interpolationtype))
203
return (EXPP_ReturnPyObjError
204
(PyExc_TypeError, "expected string argument"));
205
if (!strcmp (interpolationtype, "Bezier"))
207
if (!strcmp (interpolationtype, "Constant"))
209
if (!strcmp (interpolationtype, "Linear"))
212
return (EXPP_ReturnPyObjError
213
(PyExc_TypeError, "bad interpolation type"));
215
self->ipocurve->ipo = id;
221
IpoCurve_getInterpolation (C_IpoCurve * self)
224
IpoCurve *icu = self->ipocurve;
225
if (icu->ipo == IPO_BEZ)
227
if (icu->ipo == IPO_CONST)
229
if (icu->ipo == IPO_LIN)
233
return (EXPP_ReturnPyObjError
234
(PyExc_TypeError, "unknown interpolation type"));
235
return PyString_FromString (str);
239
IpoCurve_setExtrapolation (C_IpoCurve * self, PyObject * args)
242
char *extrapolationtype = 0;
244
if (!PyArg_ParseTuple (args, "s", &extrapolationtype))
245
return (EXPP_ReturnPyObjError
246
(PyExc_TypeError, "expected string argument"));
247
if (!strcmp (extrapolationtype, "Constant"))
249
if (!strcmp (extrapolationtype, "Extrapolation"))
251
if (!strcmp (extrapolationtype, "Cyclic"))
253
if (!strcmp (extrapolationtype, "Cyclic_extrapolation"))
257
return (EXPP_ReturnPyObjError
258
(PyExc_TypeError, "bad interpolation type"));
259
self->ipocurve->extrap = id;
265
IpoCurve_getExtrapolation (C_IpoCurve * self)
268
IpoCurve *icu = self->ipocurve;
269
if (icu->extrap == 0)
271
if (icu->extrap == 1)
272
str = "Extrapolation";
273
if (icu->extrap == 2)
275
if (icu->extrap == 3)
276
str = "Cyclic_extrapolation";
278
return PyString_FromString (str);
282
IpoCurve_addBezier (C_IpoCurve * self, PyObject * args)
284
short MEM_freeN (void *vmemh);
285
void *MEM_mallocN (unsigned int len, char *str);
289
BezTriple *bzt, *tmp;
290
static char name[10] = "mlml";
292
if (!PyArg_ParseTuple (args, "O", &popo))
293
return (EXPP_ReturnPyObjError
294
(PyExc_TypeError, "expected tuple argument"));
296
x = PyFloat_AsDouble (PyTuple_GetItem (popo, 0));
297
y = PyFloat_AsDouble (PyTuple_GetItem (popo, 1));
298
icu = self->ipocurve;
299
npoints = icu->totvert;
301
icu->bezt = MEM_mallocN (sizeof (BezTriple) * (npoints + 1), name);
304
memmove (icu->bezt, tmp, sizeof (BezTriple) * npoints);
307
memmove (icu->bezt + npoints, icu->bezt, sizeof (BezTriple));
309
bzt = icu->bezt + npoints;
310
bzt->vec[0][0] = x - 1;
312
bzt->vec[2][0] = x + 1;
313
bzt->vec[0][1] = y - 1;
315
bzt->vec[2][1] = y + 1;
316
/* set handle type to Auto */
326
IpoCurve_setName (C_IpoCurve * self, PyObject * args)
333
IpoCurve_Recalc (C_IpoCurve * self)
335
IpoCurve *icu = self->ipocurve;
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);
348
IpoCurve_getName (C_IpoCurve * self)
350
const int objectType=self->ipocurve->blocktype;
351
const int trackType=self->ipocurve->adrcode;
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"};
357
const char * ac_nametab[5] = {"QuatW", "QuatX", "QuatY", "QuatZ"};
359
switch (objectType) {
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");
366
return PyString_FromString(ob_nametab[trackType-1]);
373
case 1: case 2: case 3: case 13: case 14: case 15:
374
return PyString_FromString(ob_nametab[trackType-1]);
377
case 25: case 26: case 27: case 28:
378
return PyString_FromString(ac_nametab[trackType-25]);
381
return PyString_FromString("Index out of range");
387
return EXPP_ReturnPyObjError (PyExc_TypeError,
388
"This function doesn't support this ipocurve type yet");
393
IpoCurveDeAlloc (C_IpoCurve * self)
399
IpoCurve_getPoints (C_IpoCurve * self)
401
struct BezTriple *bezt;
404
PyObject *list = PyList_New (0);
407
for (i = 0; i < self->ipocurve->totvert; i++)
409
bezt = self->ipocurve->bezt + i;
410
po = BezTriple_CreatePyObject (bezt);
204
static PyObject *IpoCurve_setInterpolation( C_IpoCurve * self,
207
char *interpolationtype = 0;
209
if( !PyArg_ParseTuple( args, "s", &interpolationtype ) )
210
return ( EXPP_ReturnPyObjError
211
( PyExc_TypeError, "expected string argument" ) );
212
if( !strcmp( interpolationtype, "Bezier" ) )
214
if( !strcmp( interpolationtype, "Constant" ) )
216
if( !strcmp( interpolationtype, "Linear" ) )
219
return ( EXPP_ReturnPyObjError
220
( PyExc_TypeError, "bad interpolation type" ) );
222
self->ipocurve->ipo = id;
223
Py_INCREF( Py_None );
227
static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self )
230
IpoCurve *icu = self->ipocurve;
231
if( icu->ipo == IPO_BEZ )
233
if( icu->ipo == IPO_CONST )
235
if( icu->ipo == IPO_LIN )
239
return ( EXPP_ReturnPyObjError
240
( PyExc_TypeError, "unknown interpolation type" ) );
241
return PyString_FromString( str );
244
static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self,
248
char *extrapolationtype = 0;
250
if( !PyArg_ParseTuple( args, "s", &extrapolationtype ) )
251
return ( EXPP_ReturnPyObjError
252
( PyExc_TypeError, "expected string argument" ) );
253
if( !strcmp( extrapolationtype, "Constant" ) )
255
if( !strcmp( extrapolationtype, "Extrapolation" ) )
257
if( !strcmp( extrapolationtype, "Cyclic" ) )
259
if( !strcmp( extrapolationtype, "Cyclic_extrapolation" ) )
263
return ( EXPP_ReturnPyObjError
264
( PyExc_TypeError, "bad interpolation type" ) );
265
self->ipocurve->extrap = id;
266
Py_INCREF( Py_None );
270
static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self )
273
IpoCurve *icu = self->ipocurve;
274
if( icu->extrap == 0 )
276
if( icu->extrap == 1 )
277
str = "Extrapolation";
278
if( icu->extrap == 2 )
280
if( icu->extrap == 3 )
281
str = "Cyclic_extrapolation";
283
return PyString_FromString( str );
286
static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args )
288
short MEM_freeN( void *vmemh );
289
void *MEM_mallocN( unsigned int len, char *str );
293
BezTriple *bzt, *tmp;
294
static char name[10] = "mlml";
296
if( !PyArg_ParseTuple( args, "O", &popo ) )
297
return ( EXPP_ReturnPyObjError
298
( PyExc_TypeError, "expected tuple argument" ) );
300
x = PyFloat_AsDouble( PyTuple_GetItem( popo, 0 ) );
301
y = PyFloat_AsDouble( PyTuple_GetItem( popo, 1 ) );
302
icu = self->ipocurve;
303
npoints = icu->totvert;
305
icu->bezt = MEM_mallocN( sizeof( BezTriple ) * ( npoints + 1 ), name );
307
memmove( icu->bezt, tmp, sizeof( BezTriple ) * npoints );
310
memmove( icu->bezt + npoints, icu->bezt, sizeof( BezTriple ) );
312
bzt = icu->bezt + npoints;
313
bzt->vec[0][0] = x - 1;
315
bzt->vec[2][0] = x + 1;
316
bzt->vec[0][1] = y - 1;
318
bzt->vec[2][1] = y + 1;
319
/* set handle type to Auto */
323
Py_INCREF( Py_None );
328
Function: IpoCurve_delBezier
329
Bpy: Blender.Ipocurve.delBezier(0)
331
Delete an BezTriple from an IPO curve.
333
ipo = Blender.Ipo.Get('ObIpo')
334
cu = ipo.getCurve('LocX')
338
static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args )
340
//short MEM_freeN( void *vmemh );
341
//void *MEM_mallocN( unsigned int len, char *str );
347
if( !PyArg_ParseTuple( args, "i", &index ) )
348
return ( EXPP_ReturnPyObjError
349
( PyExc_TypeError, "expected int argument" ) );
351
icu = self->ipocurve;
352
npoints = icu->totvert - 1;
354
/* if index is negative, count from end of list */
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" ) );
365
if delete empties list, then delete it, otherwise copy the remaining
373
MEM_mallocN( sizeof( BezTriple ) * npoints, "bezt" );
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 ) );
381
/* free old list, adjust vertex count */
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 );
390
Py_INCREF( Py_None );
395
static PyObject *IpoCurve_Recalc( C_IpoCurve * self )
397
IpoCurve *icu = self->ipocurve;
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 );
405
Py_INCREF( Py_None );
409
static PyObject *IpoCurve_getName( C_IpoCurve * self )
411
switch ( self->ipocurve->blocktype ) {
413
return PyString_FromString( getname_ob_ei( self->ipocurve->adrcode, 1 ) ); /* solve: what if EffX/Y/Z are wanted? */
415
return PyString_FromString( getname_tex_ei
416
( self->ipocurve->adrcode ) );
418
return PyString_FromString( getname_la_ei
419
( self->ipocurve->adrcode ) );
421
return PyString_FromString( getname_mat_ei
422
( self->ipocurve->adrcode ) );
424
return PyString_FromString( getname_cam_ei
425
( self->ipocurve->adrcode ) );
427
return PyString_FromString( getname_world_ei
428
( self->ipocurve->adrcode ) );
430
return PyString_FromString( getname_ac_ei
431
( self->ipocurve->adrcode ) );
433
return PyString_FromString( getname_cu_ei
434
( self->ipocurve->adrcode ) );
436
return PyString_FromString( getname_key_ei
437
( self->ipocurve->adrcode ) );
439
return PyString_FromString( getname_seq_ei
440
( self->ipocurve->adrcode ) );
442
return PyString_FromString( getname_co_ei
443
( self->ipocurve->adrcode ) );
445
return EXPP_ReturnPyObjError( PyExc_TypeError,
446
"This function doesn't support this ipocurve type yet" );
449
return PyString_FromString( "" );
452
static void IpoCurveDeAlloc( C_IpoCurve * self )
454
PyObject_DEL( self );
457
static PyObject *IpoCurve_getPoints( C_IpoCurve * self )
459
struct BezTriple *bezt;
462
PyObject *list = PyList_New( 0 );
465
for( i = 0; i < self->ipocurve->totvert; i++ ) {
466
bezt = self->ipocurve->bezt + i;
467
po = BezTriple_CreatePyObject( bezt );
412
if (BezTriple_CheckPyObject (po))
413
printf ("po is ok\n");
415
printf ("po is hosed\n");
469
if( BezTriple_CheckPyObject( po ) )
470
printf( "po is ok\n" );
472
printf( "po is hosed\n" );
417
PyList_Append (list, po);
419
PyList_Append( list, BezTriple_CreatePyObject(bezt));
474
PyList_Append( list, po );
476
PyList_Append( list, BezTriple_CreatePyObject(bezt));
427
IpoCurve_setPoints (C_IpoCurve * self, PyObject * value)
483
int IpoCurve_setPoints( C_IpoCurve * self, PyObject * value )
429
struct BezTriple *bezt;
430
PyObject *l = PyList_New (0);
432
for (i = 0; i < self->ipocurve->totvert; i++)
434
bezt = self->ipocurve->bezt + i;
435
PyList_Append (l, BezTriple_CreatePyObject (bezt));
485
struct BezTriple *bezt;
486
PyObject *l = PyList_New( 0 );
488
for( i = 0; i < self->ipocurve->totvert; i++ ) {
489
bezt = self->ipocurve->bezt + i;
490
PyList_Append( l, BezTriple_CreatePyObject( bezt ) );
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 */
446
501
/*****************************************************************************/
448
IpoCurveGetAttr (C_IpoCurve * self, char *name)
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);
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
/*****************************************************************************/
463
IpoCurveSetAttr (C_IpoCurve * self, char *name, PyObject * value)
465
if (strcmp (name, "bezierPoints") == 0)
466
return IpoCurve_setPoints (self, value);
467
return 0; /* normal exit */
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 )
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 );
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 )
518
if( strcmp( name, "bezierPoints" ) == 0 )
519
return IpoCurve_setPoints( self, value );
520
return 0; /* normal exit */
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
/*****************************************************************************/
476
IpoCurveRepr (C_IpoCurve * self)
528
static PyObject *IpoCurveRepr( C_IpoCurve * self )
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);
531
sprintf( s, "[IpoCurve \"%s\"]\n", getIpoCurveName( self->ipocurve ) );
532
return PyString_FromString( s );
485
535
/* Three Python IpoCurve_Type helper functions needed by the Object module: */
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
/*****************************************************************************/
493
IpoCurve_CreatePyObject (IpoCurve * ipo)
542
PyObject *IpoCurve_CreatePyObject( IpoCurve * ipo )
497
pyipo = (C_IpoCurve *) PyObject_NEW (C_IpoCurve, &IpoCurve_Type);
500
return EXPP_ReturnPyObjError (PyExc_MemoryError,
501
"couldn't create C_IpoCurve object");
503
pyipo->ipocurve = ipo;
505
return (PyObject *) pyipo;
546
pyipo = ( C_IpoCurve * ) PyObject_NEW( C_IpoCurve, &IpoCurve_Type );
549
return EXPP_ReturnPyObjError( PyExc_MemoryError,
550
"couldn't create C_IpoCurve object" );
552
pyipo->ipocurve = ipo;
554
return ( PyObject * ) pyipo;
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
/*****************************************************************************/
514
IpoCurve_CheckPyObject (PyObject * pyobj)
562
int IpoCurve_CheckPyObject( PyObject * pyobj )
516
return (pyobj->ob_type == &IpoCurve_Type);
564
return ( pyobj->ob_type == &IpoCurve_Type );
519
567
/*****************************************************************************/
520
/* Function: IpoCurve_FromPyObject */
568
/* Function: IpoCurve_FromPyObject */
521
569
/* Description: This function returns the Blender ipo from the given */
523
571
/*****************************************************************************/
525
IpoCurve_FromPyObject (PyObject * pyobj)
527
return ((C_IpoCurve *) pyobj)->ipocurve;
572
IpoCurve *IpoCurve_FromPyObject( PyObject * pyobj )
574
return ( ( C_IpoCurve * ) pyobj )->ipocurve;
577
/***************************************************************************/
578
/* Function: IpoCurve_evaluate( time ) */
579
/* Description: Evaluates IPO curve at the given time. */
580
/***************************************************************************/
582
static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args )
588
/* expecting float */
589
if( !PyArg_ParseTuple( args, "f", &time ) )
590
return ( EXPP_ReturnPyObjError
591
( PyExc_TypeError, "expected float argument" ) );
593
eval = ( double ) eval_icu( self->ipocurve, time );
595
return PyFloat_FromDouble( eval );
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.
605
char *getIpoCurveName( IpoCurve * icu )
607
switch ( icu->blocktype ) {
609
return getname_mat_ei( icu->adrcode );
611
return getname_world_ei( icu->adrcode );
613
return getname_cam_ei( icu->adrcode );
615
return getname_ob_ei( icu->adrcode, 1 );
616
/* solve: what if EffX/Y/Z are wanted? */
618
return getname_tex_ei( icu->adrcode );
620
return getname_la_ei( icu->adrcode );
622
return getname_ac_ei( icu->adrcode );
624
return getname_cu_ei( icu->adrcode );
626
return getname_key_ei( icu->adrcode );
628
return getname_seq_ei( icu->adrcode );
630
return getname_co_ei( icu->adrcode );