| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-04-16 22:40:48 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-04-16 22:40:48 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							| 
									
										
										
										
											2008-04-16 22:40:48 +00:00
										 |  |  |  * of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  |  * Contributor(s): Jacques Guignot, Nathan Letwory, Ken Hughes, Johnny Matthews | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-04-16 22:40:48 +00:00
										 |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "Ipocurve.h" /*This must come first*/
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | #include "Object.h"
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "BKE_global.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | #include "BKE_main.h"
 | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | #include "BKE_depsgraph.h"
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "BKE_ipo.h"
 | 
					
						
							| 
									
										
										
										
											2008-04-17 21:14:55 +00:00
										 |  |  | #include "BKE_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2008-09-14 04:32:17 +00:00
										 |  |  | #include "BIF_keyframing.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | #include "BIF_space.h"
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "BSE_editipo.h"
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | #include "DNA_ipo_types.h"
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | #include "DNA_key_types.h"
 | 
					
						
							| 
									
										
										
										
											2008-10-11 12:17:16 +00:00
										 |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2004-10-07 19:25:40 +00:00
										 |  |  | #include "BezTriple.h"
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "gen_utils.h"
 | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* The following string definitions are used for documentation strings.      */ | 
					
						
							|  |  |  | /* In Python these will be written to the console when doing a               */ | 
					
						
							|  |  |  | /* Blender.IpoCurve.__doc__                                                  */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | char M_IpoCurve_doc[] = ""; | 
					
						
							|  |  |  | char M_IpoCurve_New_doc[] = ""; | 
					
						
							|  |  |  | char M_IpoCurve_Get_doc[] = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python method structure definition for Blender.IpoCurve module:           */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct PyMethodDef M_IpoCurve_methods[] = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python C_IpoCurve methods declarations:                                   */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getName( C_IpoCurve * self ); | 
					
						
							|  |  |  | static PyObject *IpoCurve_Recalc( C_IpoCurve * self ); | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | static PyObject *IpoCurve_append( C_IpoCurve * self, PyObject * value ); | 
					
						
							|  |  |  | static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * value ); | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_setInterpolation( C_IpoCurve * self, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 					    PyObject * value ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static PyObject *IpoCurve_newgetInterp( C_IpoCurve * self ); | 
					
						
							|  |  |  | static int IpoCurve_newsetInterp( C_IpoCurve * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_setExtrapolation( C_IpoCurve * self, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 					    PyObject * value ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static PyObject *IpoCurve_newgetExtend( C_IpoCurve * self ); | 
					
						
							|  |  |  | static int IpoCurve_newsetExtend( C_IpoCurve * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getPoints( C_IpoCurve * self ); | 
					
						
							| 
									
										
										
										
											2008-10-11 12:17:16 +00:00
										 |  |  | static PyObject *IpoCurve_clean( C_IpoCurve * self, PyObject *value ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | static PyObject *IpoCurve_getDriver( C_IpoCurve * self ); | 
					
						
							|  |  |  | static int IpoCurve_setDriver( C_IpoCurve * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *IpoCurve_getDriverObject( C_IpoCurve * self); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | static PyObject *IpoCurve_getDriverExpression( C_IpoCurve * self); | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | static PyObject *IpoCurve_getFlag( C_IpoCurve * self, void *type); | 
					
						
							|  |  |  | static int IpoCurve_setFlag( C_IpoCurve * self, PyObject *value, void *type); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | static int IpoCurve_setDriverExpression( C_IpoCurve * self, PyObject * args ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static PyObject *IpoCurve_getCurval( C_IpoCurve * self, PyObject * args ); | 
					
						
							|  |  |  | static int IpoCurve_setCurval( C_IpoCurve * self, PyObject * key,  | 
					
						
							|  |  |  | 		PyObject * value ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python C_IpoCurve methods table:                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyMethodDef C_IpoCurve_methods[] = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* name, method, flags, doc */ | 
					
						
							|  |  |  | 	{"getName", ( PyCFunction ) IpoCurve_getName, METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2005-05-24 15:14:32 +00:00
										 |  |  | 	 "() - Return IpoCurve name"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"Recalc", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2005-05-24 15:14:32 +00:00
										 |  |  | 	 "() - deprecated method.  use recalc() instead"}, | 
					
						
							|  |  |  | 	{"recalc", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS, | 
					
						
							|  |  |  | 	 "() - Recomputes the curve after changes"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"update", ( PyCFunction ) IpoCurve_Recalc, METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	 "() - deprecated method: use recalc method instead."}, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	{"append", ( PyCFunction ) IpoCurve_append, METH_O, | 
					
						
							| 
									
										
										
										
											2005-05-24 15:14:32 +00:00
										 |  |  | 	 "(coordlist) -  Adds a Bezier point to a curve"}, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	{"addBezier", ( PyCFunction ) IpoCurve_addBezier, METH_O, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	 "() - deprecated method. use append() instead"}, | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | 	{"delBezier", ( PyCFunction ) IpoCurve_delBezier, METH_VARARGS, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	 "() - deprecated method. use \"del icu[index]\" instead"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"setInterpolation", ( PyCFunction ) IpoCurve_setInterpolation, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	 METH_O, "(str) - Sets the interpolation type of the curve"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"getInterpolation", ( PyCFunction ) IpoCurve_getInterpolation, | 
					
						
							| 
									
										
										
										
											2005-05-24 15:14:32 +00:00
										 |  |  | 	 METH_NOARGS, "() - Gets the interpolation type of the curve"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"setExtrapolation", ( PyCFunction ) IpoCurve_setExtrapolation, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	 METH_O, "(str) - Sets the extend mode of the curve"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"getExtrapolation", ( PyCFunction ) IpoCurve_getExtrapolation, | 
					
						
							| 
									
										
										
										
											2005-05-24 15:14:32 +00:00
										 |  |  | 	 METH_NOARGS, "() - Gets the extend mode of the curve"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"getPoints", ( PyCFunction ) IpoCurve_getPoints, METH_NOARGS, | 
					
						
							| 
									
										
										
										
											2005-05-24 15:14:32 +00:00
										 |  |  | 	 "() - Returns list of all bezTriples of the curve"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"evaluate", ( PyCFunction ) IpoCurve_evaluate, METH_VARARGS, | 
					
						
							|  |  |  | 	 "(float) - Evaluate curve at given time"}, | 
					
						
							| 
									
										
										
										
											2008-10-11 12:17:16 +00:00
										 |  |  | 	{"clean", ( PyCFunction ) IpoCurve_clean, METH_VARARGS, | 
					
						
							|  |  |  | 	 "(float) - Clean BezTriples using the given threshold value"}, | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * IpoCurve methods | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyGetSetDef C_IpoCurve_getseters[] = { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	{"name", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_getName, (setter)NULL, | 
					
						
							|  |  |  | 	 "the IpoCurve name", | 
					
						
							|  |  |  | 	NULL}, | 
					
						
							|  |  |  | 	{"bezierPoints", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_getPoints, (setter)NULL, | 
					
						
							|  |  |  | 	 "list of all bezTriples of the curve", | 
					
						
							|  |  |  | 	NULL}, | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	{"driver", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_getDriver, (setter)IpoCurve_setDriver, | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | 	 "The status of the driver 1-object, 2-py expression, 0-off", | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	 NULL}, | 
					
						
							|  |  |  | 	{"driverObject", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_getDriverObject, (setter)IpoCurve_setDriverObject, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	 "The object used to drive the IpoCurve", | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	 NULL}, | 
					
						
							|  |  |  | 	{"driverChannel", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_getDriverChannel, (setter)IpoCurve_setDriverChannel, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	 "The channel on the driver object used to drive the IpoCurve", | 
					
						
							|  |  |  | 	 NULL}, | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 	{"driverExpression", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_getDriverExpression, (setter)IpoCurve_setDriverExpression, | 
					
						
							|  |  |  | 	 "The python expression on the driver used to drive the IpoCurve", | 
					
						
							|  |  |  | 	 NULL}, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	{"interpolation", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_newgetInterp, (setter)IpoCurve_newsetInterp, | 
					
						
							|  |  |  | 	 "The interpolation mode of the curve", | 
					
						
							|  |  |  | 	 NULL}, | 
					
						
							|  |  |  | 	{"extend", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_newgetExtend, (setter)IpoCurve_newsetExtend, | 
					
						
							|  |  |  | 	 "The extend mode of the curve", | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	 NULL}, | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	{"sel", | 
					
						
							|  |  |  | 	 (getter)IpoCurve_getFlag, (setter)IpoCurve_setFlag, | 
					
						
							|  |  |  | 	 "the selection state of the curve", | 
					
						
							|  |  |  | 	 (void *)IPO_SELECT}, | 
					
						
							|  |  |  | 	  | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	 {NULL,NULL,NULL,NULL,NULL} | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python IpoCurve_Type Mapping Methods table:                               */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyMappingMethods IpoCurve_as_mapping = { | 
					
						
							|  |  |  | 	( inquiry ) 0,	/* mp_length */ | 
					
						
							|  |  |  | 	( binaryfunc ) IpoCurve_getCurval,	/* mp_subscript */ | 
					
						
							|  |  |  | 	( objobjargproc ) IpoCurve_setCurval,	/* mp_ass_subscript */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python IpoCurve_Type callback function prototypes:                        */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | static int IpoCurve_compare( C_IpoCurve * a, C_IpoCurve * b ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static PyObject *IpoCurve_repr( C_IpoCurve * self ); | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python IpoCurve_Type structure definition:                                */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyTypeObject IpoCurve_Type = { | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	PyObject_HEAD_INIT( NULL )          /* required macro */  | 
					
						
							|  |  |  | 	0,									/* ob_size */ | 
					
						
							|  |  |  | 	"IpoCurve",							/* tp_name */ | 
					
						
							|  |  |  | 	sizeof( C_IpoCurve ),				/* tp_basicsize */ | 
					
						
							|  |  |  | 	0,									/* tp_itemsize */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* methods */ | 
					
						
							| 
									
										
										
										
											2007-03-15 01:47:53 +00:00
										 |  |  | 	NULL,							    /* tp_dealloc */ | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	0,									/* tp_print */ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	( getattrfunc ) NULL,	            /* tp_getattr */ | 
					
						
							|  |  |  | 	( setattrfunc ) NULL,	            /* tp_setattr */ | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | 	( cmpfunc ) IpoCurve_compare,		/* tp_compare */ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	( reprfunc ) IpoCurve_repr,			/* tp_repr */ | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	/* Method suites for standard classes */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	NULL,                               /* PyNumberMethods *tp_as_number; */ | 
					
						
							|  |  |  | 	NULL,                               /* PySequenceMethods *tp_as_sequence; */ | 
					
						
							|  |  |  | 	&IpoCurve_as_mapping,               /* PyMappingMethods *tp_as_mapping; */ | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* More standard operations (here for binary compatibility) */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	NULL,                       		/* hashfunc tp_hash; */ | 
					
						
							|  |  |  | 	NULL,                       		/* ternaryfunc tp_call; */ | 
					
						
							|  |  |  | 	NULL,                       		/* reprfunc tp_str; */ | 
					
						
							|  |  |  | 	NULL,                       		/* getattrofunc tp_getattro; */ | 
					
						
							|  |  |  | 	NULL,                      			/* setattrofunc tp_setattro; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Functions to access object as input/output buffer */ | 
					
						
							|  |  |  | 	NULL,                       		/* PyBufferProcs *tp_as_buffer; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*** Flags to define presence of optional/expanded features ***/ | 
					
						
							|  |  |  | 	Py_TPFLAGS_DEFAULT,         		/* long tp_flags; */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	NULL,                       		/*  char *tp_doc;  */ | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  |   /*** Assigned meaning in release 2.0 ***/ | 
					
						
							|  |  |  | 	/* call function for all accessible objects */ | 
					
						
							|  |  |  | 	NULL,                       		/* traverseproc tp_traverse; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* delete references to contained objects */ | 
					
						
							|  |  |  | 	NULL,                       		/* inquiry tp_clear; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /***  Assigned meaning in release 2.1 ***/ | 
					
						
							|  |  |  |   /*** rich comparisons ***/ | 
					
						
							|  |  |  | 	NULL,                       		/* richcmpfunc tp_richcompare; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /***  weak reference enabler ***/ | 
					
						
							|  |  |  | 	0,                          		/* long tp_weaklistoffset; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*** Added in release 2.2 ***/ | 
					
						
							|  |  |  | 	/*   Iterators */ | 
					
						
							|  |  |  | 	NULL,                      			/* getiterfunc tp_iter; */ | 
					
						
							|  |  |  | 	NULL,                       		/* iternextfunc tp_iternext; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /*** Attribute descriptor and subclassing stuff ***/ | 
					
						
							|  |  |  | 	C_IpoCurve_methods,           		/* struct PyMethodDef *tp_methods; */ | 
					
						
							|  |  |  | 	NULL,                       		/* struct PyMemberDef *tp_members; */ | 
					
						
							|  |  |  | 	C_IpoCurve_getseters,         		/* struct PyGetSetDef *tp_getset; */ | 
					
						
							|  |  |  | 	NULL,                       		/* struct _typeobject *tp_base; */ | 
					
						
							|  |  |  | 	NULL,                       		/* PyObject *tp_dict; */ | 
					
						
							|  |  |  | 	NULL,                       		/* descrgetfunc tp_descr_get; */ | 
					
						
							|  |  |  | 	NULL,                       		/* descrsetfunc tp_descr_set; */ | 
					
						
							|  |  |  | 	0,                          		/* long tp_dictoffset; */ | 
					
						
							|  |  |  | 	NULL,                       		/* initproc tp_init; */ | 
					
						
							|  |  |  | 	NULL,                       		/* allocfunc tp_alloc; */ | 
					
						
							|  |  |  | 	NULL,                       		/* newfunc tp_new; */ | 
					
						
							|  |  |  | 	/*  Low-level free-memory routine */ | 
					
						
							|  |  |  | 	NULL,                       		/* freefunc tp_free;  */ | 
					
						
							|  |  |  | 	/* For PyObject_IS_GC */ | 
					
						
							|  |  |  | 	NULL,                       		/* inquiry tp_is_gc;  */ | 
					
						
							|  |  |  | 	NULL,                       		/* PyObject *tp_bases; */ | 
					
						
							|  |  |  | 	/* method resolution order */ | 
					
						
							|  |  |  | 	NULL,                       		/* PyObject *tp_mro;  */ | 
					
						
							|  |  |  | 	NULL,                       		/* PyObject *tp_cache; */ | 
					
						
							|  |  |  | 	NULL,                       		/* PyObject *tp_subclasses; */ | 
					
						
							|  |  |  | 	NULL,                       		/* PyObject *tp_weaklist; */ | 
					
						
							|  |  |  | 	NULL | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /* local utility functions                                                   */ | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Keys are handled differently than other Ipos, so go through contortions | 
					
						
							|  |  |  |  * to find their names. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *get_key_curvename( IpoCurve *ipocurve ) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	Key *key_iter; | 
					
						
							|  |  |  | 	char *empty = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* search for keys with an Ipo */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for( key_iter = G.main->key.first; key_iter; key_iter=key_iter->id.next) { | 
					
						
							|  |  |  | 		if( key_iter->ipo ) { | 
					
						
							|  |  |  | 			IpoCurve *icu = key_iter->ipo->curve.first; | 
					
						
							|  |  |  | 			/* search curves for a match */ | 
					
						
							|  |  |  | 			while( icu ) { | 
					
						
							|  |  |  | 				if( icu == ipocurve ) { | 
					
						
							|  |  |  | 					KeyBlock *block = key_iter->block.first; | 
					
						
							|  |  |  | 					/* search for matching adrcode */ | 
					
						
							|  |  |  | 					while( block ) { | 
					
						
							|  |  |  | 						if( block->adrcode == ipocurve->adrcode ) | 
					
						
							|  |  |  | 							return block->name; | 
					
						
							|  |  |  | 						block = block->next; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				icu = icu->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* shouldn't get here unless deleted in UI while BPy object alive */ | 
					
						
							|  |  |  | 	return empty; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * internal bpy func to get Ipo Curve Name, used by Ipo.c and | 
					
						
							|  |  |  |  * KX_BlenderSceneConverter.cpp. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * We are returning a pointer to string constants so there are | 
					
						
							|  |  |  |  * no issues with who owns pointers. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char *getIpoCurveName( IpoCurve * icu ) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	switch ( icu->blocktype ) { | 
					
						
							|  |  |  | 	case ID_MA: | 
					
						
							|  |  |  | 		return getname_mat_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_WO: | 
					
						
							|  |  |  | 		return getname_world_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_CA: | 
					
						
							|  |  |  | 		return getname_cam_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_OB: | 
					
						
							|  |  |  | 		return getname_ob_ei( icu->adrcode, 1 ); | 
					
						
							|  |  |  | 		/* solve: what if EffX/Y/Z are wanted? */ | 
					
						
							|  |  |  | 	case ID_TE: | 
					
						
							|  |  |  | 		return getname_tex_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_LA: | 
					
						
							|  |  |  | 		return getname_la_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_PO: | 
					
						
							|  |  |  | 		return getname_ac_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_CU: | 
					
						
							|  |  |  | 		return getname_cu_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_KE: | 
					
						
							|  |  |  | 		/* return "Key";	*/ | 
					
						
							|  |  |  | 		/* ipo curves have no names... that was only meant for drawing the buttons... (ton) */ | 
					
						
							|  |  |  | 		return get_key_curvename( icu ); | 
					
						
							|  |  |  | 	case ID_SEQ: | 
					
						
							|  |  |  | 		return getname_seq_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	case ID_CO: | 
					
						
							|  |  |  | 		return getname_co_ei( icu->adrcode ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * delete a bezTriple from a curve | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static void del_beztriple( IpoCurve *icu, int index ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int npoints = icu->totvert - 1; | 
					
						
							|  |  |  | 	BezTriple * tmp = icu->bezt; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * if delete empties list, then delete it, otherwise copy the remaining | 
					
						
							|  |  |  | 	 * points to a new list | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	if( !npoints ) { | 
					
						
							|  |  |  | 		icu->bezt = NULL; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		icu->bezt = | 
					
						
							|  |  |  | 			MEM_mallocN( sizeof( BezTriple ) * npoints, "bezt" ); | 
					
						
							|  |  |  | 		if( index > 0 ) | 
					
						
							|  |  |  | 			memmove( icu->bezt, tmp, index * sizeof( BezTriple ) ); | 
					
						
							|  |  |  | 		if( index < npoints ) | 
					
						
							|  |  |  | 			memmove( icu->bezt + index, tmp + index + 1, | 
					
						
							|  |  |  | 				 ( npoints - index ) * sizeof( BezTriple ) ); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	/* free old list, adjust vertex count */ | 
					
						
							|  |  |  | 	MEM_freeN( tmp ); | 
					
						
							|  |  |  | 	icu->totvert--; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* call calchandles_* instead of testhandles_*  */ | 
					
						
							|  |  |  | 	/* I'm not sure this is a complete solution but since we do not */ | 
					
						
							|  |  |  | 	/* deal with curve handles right now, it seems ok */ | 
					
						
							|  |  |  | 	calchandles_ipocurve( icu ); | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | /* Python C_IpoCurve methods:                                                */ | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_setInterpolation( C_IpoCurve * self, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 					    PyObject * value ) | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	char *interpolationtype = PyString_AsString(value); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	short id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	if( !interpolationtype ) | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected string argument" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !strcmp( interpolationtype, "Bezier" ) ) | 
					
						
							|  |  |  | 		id = IPO_BEZ; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	else if( !strcmp( interpolationtype, "Constant" ) ) | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		id = IPO_CONST; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	else if( !strcmp( interpolationtype, "Linear" ) ) | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		id = IPO_LIN; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"bad interpolation type" ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	self->ipocurve->ipo = id; | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-08-05 10:19:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getInterpolation( C_IpoCurve * self ) | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *str = 0; | 
					
						
							|  |  |  | 	IpoCurve *icu = self->ipocurve; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch( icu->ipo ) { | 
					
						
							|  |  |  | 	case IPO_BEZ: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		str = "Bezier"; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case IPO_CONST: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		str = "Constant"; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case IPO_LIN: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		str = "Linear"; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"unknown interpolation type" ); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return PyString_FromString( str ); | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-08-05 10:19:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static PyObject * IpoCurve_setExtrapolation( C_IpoCurve * self, | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 		PyObject * value ) | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	char *extrapolationtype = PyString_AsString(value); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	short id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	if( !extrapolationtype ) | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected string argument" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !strcmp( extrapolationtype, "Constant" ) ) | 
					
						
							|  |  |  | 		id = 0; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	else if( !strcmp( extrapolationtype, "Extrapolation" ) ) | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		id = 1; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	else if( !strcmp( extrapolationtype, "Cyclic" ) ) | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		id = 2; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	else if( !strcmp( extrapolationtype, "Cyclic_extrapolation" ) ) | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		id = 3; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"bad interpolation type" ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	self->ipocurve->extrap = id; | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-08-05 10:19:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getExtrapolation( C_IpoCurve * self ) | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	char *str; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	IpoCurve *icu = self->ipocurve; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch( icu->extrap ) { | 
					
						
							|  |  |  | 	case 0: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		str = "Constant"; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case 1: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		str = "Extrapolation"; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case 2: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		str = "Cyclic"; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case 3: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		str = "Cyclic_extrapolation"; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"bad extrapolation type" ); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return PyString_FromString( str ); | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-08-05 10:19:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * append a new BezTriple to curve | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | static PyObject *IpoCurve_append( C_IpoCurve * self, PyObject * value ) | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	float x, y; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	IpoCurve *icu = self->ipocurve; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* if args is a already a beztriple, tack onto end of list */ | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	if( BPy_BezTriple_Check ( value ) ) { | 
					
						
							|  |  |  | 		BPy_BezTriple *bobj = (BPy_BezTriple *)value; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		BezTriple *newb = MEM_callocN( (icu->totvert+1)*sizeof(BezTriple), | 
					
						
							|  |  |  | 				"BPyBeztriple" ); | 
					
						
							|  |  |  | 		if( icu->bezt ) { | 
					
						
							| 
									
										
										
										
											2006-08-20 11:02:31 +00:00
										 |  |  | 			memcpy( newb, icu->bezt, ( icu->totvert )*sizeof( BezTriple ) ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 			MEM_freeN( icu->bezt ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		icu->bezt = newb; | 
					
						
							|  |  |  | 		memcpy( &icu->bezt[icu->totvert], bobj->beztriple, | 
					
						
							|  |  |  | 				sizeof( BezTriple ) ); | 
					
						
							|  |  |  | 		icu->totvert++; | 
					
						
							|  |  |  | 		calchandles_ipocurve( icu ); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* otherwise try to get two floats and add to list */ | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		PyObject *xobj, *yobj; | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 		xobj = PyNumber_Float( PyTuple_GetItem( value, 0 ) ); | 
					
						
							|  |  |  | 		yobj = PyNumber_Float( PyTuple_GetItem( value, 1 ) ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if( !xobj || !yobj ) | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected tuple of floats" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		x = (float)PyFloat_AsDouble( xobj ); | 
					
						
							| 
									
										
										
										
											2007-04-05 04:34:41 +00:00
										 |  |  | 		Py_DECREF( xobj ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		y = (float)PyFloat_AsDouble( yobj ); | 
					
						
							| 
									
										
										
										
											2007-04-05 04:34:41 +00:00
										 |  |  | 		Py_DECREF( yobj ); | 
					
						
							| 
									
										
										
										
											2007-09-18 06:41:29 +00:00
										 |  |  | 		insert_vert_icu( icu, x, y, 0); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |    Function:  IpoCurve_delBezier | 
					
						
							|  |  |  |    Bpy:       Blender.Ipocurve.delBezier(0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |    Delete an BezTriple from an IPO curve. | 
					
						
							|  |  |  |    example: | 
					
						
							|  |  |  |        ipo = Blender.Ipo.Get('ObIpo') | 
					
						
							|  |  |  |        cu = ipo.getCurve('LocX') | 
					
						
							|  |  |  |        cu.delBezier(0) | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *IpoCurve_delBezier( C_IpoCurve * self, PyObject * args ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int index; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( args, "i", &index ) ) | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected int argument" ); | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* if index is negative, count from end of list */ | 
					
						
							|  |  |  | 	if( index < 0 ) | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		index += self->ipocurve->totvert; | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | 	/* check range of index */ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	if( index < 0 || index > self->ipocurve->totvert - 1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_IndexError, | 
					
						
							|  |  |  | 				"index outside of list" ); | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	del_beztriple( self->ipocurve, index ); | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_Recalc( C_IpoCurve * self ) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	IpoCurve *icu = self->ipocurve; | 
					
						
							| 
									
										
										
										
											2004-04-29 04:50:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* testhandles_ipocurve (icu); */ | 
					
						
							|  |  |  | 	/* call calchandles_* instead of testhandles_*  */ | 
					
						
							|  |  |  | 	/* I'm not sure this is a complete solution but since we do not */ | 
					
						
							|  |  |  | 	/* deal with curve handles right now, it seems ok */ | 
					
						
							|  |  |  | 	calchandles_ipocurve( icu ); | 
					
						
							| 
									
										
										
										
											2005-11-17 19:10:40 +00:00
										 |  |  | 	sort_time_ipocurve( icu ); | 
					
						
							| 
									
										
										
										
											2004-04-29 04:50:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_INCREF( Py_None ); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getName( C_IpoCurve * self ) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	switch ( self->ipocurve->blocktype ) { | 
					
						
							|  |  |  | 	case ID_OB: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_ob_ei( self->ipocurve->adrcode, 1 ) );	/* solve: what if EffX/Y/Z are wanted? */ | 
					
						
							|  |  |  | 	case ID_TE: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_tex_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							|  |  |  | 	case ID_LA: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_la_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							|  |  |  | 	case ID_MA: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_mat_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							|  |  |  | 	case ID_CA: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_cam_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							|  |  |  | 	case ID_WO: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_world_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							| 
									
										
										
										
											2005-10-10 18:05:30 +00:00
										 |  |  | 	case ID_PO: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return PyString_FromString( getname_ac_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							|  |  |  | 	case ID_CU: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_cu_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							|  |  |  | 	case ID_KE: | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		return PyString_FromString( get_key_curvename( self->ipocurve ) ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	case ID_SEQ: | 
					
						
							|  |  |  | 		return PyString_FromString( getname_seq_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							| 
									
										
										
										
											2005-10-10 18:05:30 +00:00
										 |  |  | 	case ID_CO: | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		return PyString_FromString( getname_co_ei | 
					
						
							|  |  |  | 					    ( self->ipocurve->adrcode ) ); | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 				"This function doesn't support this ipocurve type yet" ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_getPoints( C_IpoCurve * self ) | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	BezTriple *bezt; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *po; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	PyObject *list = PyList_New( self->ipocurve->totvert ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !list ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_MemoryError, | 
					
						
							|  |  |  | 				"PyList_New() failed" ); | 
					
						
							| 
									
										
										
										
											2004-03-29 08:16:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	for( bezt = self->ipocurve->bezt, i = 0; | 
					
						
							|  |  |  | 			i < self->ipocurve->totvert; i++, bezt++ ) { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		po = BezTriple_CreatePyObject( bezt ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		if( !po ) { | 
					
						
							|  |  |  | 			Py_DECREF( list ); | 
					
						
							| 
									
										
										
										
											2007-05-27 21:33:48 +00:00
										 |  |  | 			return NULL; /* This is okay since the error is alredy set */ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		PyList_SET_ITEM( list, i, po ); | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return list; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    IpoCurve_compare                                     		 */ | 
					
						
							|  |  |  | /* Description: This compares 2 python types, == or != only.			     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static int IpoCurve_compare( C_IpoCurve * a, C_IpoCurve * b ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ( a->ipocurve == b->ipocurve ) ? 0 : -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    IpoCurve_repr                                                */ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | /* Description: This is a callback function for the C_IpoCurve type. It      */ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /*              builds a meaningful string to represent ipocurve objects.    */ | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static PyObject *IpoCurve_repr( C_IpoCurve * self ) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	return PyString_FromFormat( "[IpoCurve \"%s\"]", | 
					
						
							|  |  |  | 			getIpoCurveName( self->ipocurve ) ); | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Three Python IpoCurve_Type helper functions needed by the Object module: */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | /* Function:    IpoCurve_CreatePyObject                                     */ | 
					
						
							|  |  |  | /* Description: This function will create a new C_IpoCurve from an existing  */ | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | /*              Blender ipo structure.                                       */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | PyObject *IpoCurve_CreatePyObject( IpoCurve * icu ) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	C_IpoCurve *pyipo; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	pyipo = ( C_IpoCurve * ) PyObject_NEW( C_IpoCurve, &IpoCurve_Type ); | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !pyipo ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_MemoryError, | 
					
						
							|  |  |  | 					      "couldn't create C_IpoCurve object" ); | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	pyipo->ipocurve = icu; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( PyObject * ) pyipo; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | /* Function:    IpoCurve_FromPyObject                                       */ | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | /* Description: This function returns the Blender ipo from the given         */ | 
					
						
							|  |  |  | /*              PyObject.                                                    */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | IpoCurve *IpoCurve_FromPyObject( PyObject * pyobj ) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( ( C_IpoCurve * ) pyobj )->ipocurve; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:29:55 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-06-06 19:42:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * get the value of an Ipocurve at a particular time | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *IpoCurve_getCurval( C_IpoCurve * self, PyObject * args ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float time; | 
					
						
							|  |  |  | 	PyObject *pyfloat = PyNumber_Float( args ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !pyfloat ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected float argument" ); | 
					
						
							|  |  |  | 	time = ( float )PyFloat_AS_DOUBLE( pyfloat ); | 
					
						
							|  |  |  | 	Py_DECREF( pyfloat ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return PyFloat_FromDouble( ( double ) eval_icu( self->ipocurve, time ) ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * set the value of an Ipocurve at a particular time | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int IpoCurve_setCurval( C_IpoCurve * self, PyObject * key,  | 
					
						
							|  |  |  | 		PyObject * value ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float time, curval; | 
					
						
							|  |  |  | 	PyObject *pyfloat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* make sure time, curval are both floats */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pyfloat = PyNumber_Float( key ); | 
					
						
							|  |  |  | 	if( !pyfloat ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected float key" ); | 
					
						
							|  |  |  | 	time = ( float )PyFloat_AS_DOUBLE( pyfloat ); | 
					
						
							|  |  |  | 	Py_DECREF( pyfloat ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pyfloat = PyNumber_Float( value ); | 
					
						
							|  |  |  | 	if( !pyfloat ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected float argument" ); | 
					
						
							|  |  |  | 	curval = ( float )PyFloat_AS_DOUBLE( pyfloat ); | 
					
						
							|  |  |  | 	Py_DECREF( pyfloat ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* insert a key at the specified time */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-18 06:41:29 +00:00
										 |  |  | 	insert_vert_icu( self->ipocurve, time, curval, 0); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	allspace(REMAKEIPO, 0); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-06 19:42:12 +00:00
										 |  |  | /***************************************************************************/ | 
					
						
							|  |  |  | /* Function:      IpoCurve_evaluate( time )                                */ | 
					
						
							|  |  |  | /* Description:   Evaluates IPO curve at the given time.                   */ | 
					
						
							|  |  |  | /***************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *IpoCurve_evaluate( C_IpoCurve * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-06-06 19:42:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	float time = 0; | 
					
						
							|  |  |  | 	double eval = 0; | 
					
						
							| 
									
										
										
										
											2004-06-06 19:42:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* expecting float */ | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( args, "f", &time ) ) | 
					
						
							|  |  |  | 		return ( EXPP_ReturnPyObjError | 
					
						
							|  |  |  | 			 ( PyExc_TypeError, "expected float argument" ) ); | 
					
						
							| 
									
										
										
										
											2004-06-06 19:42:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	eval = ( double ) eval_icu( self->ipocurve, time ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return PyFloat_FromDouble( eval ); | 
					
						
							| 
									
										
										
										
											2004-06-06 19:42:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-04-24 19:03:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-11 12:17:16 +00:00
										 |  |  | /***************************************************************************/ | 
					
						
							|  |  |  | /* Function:      IpoCurve_clean( thresh )                                */ | 
					
						
							|  |  |  | /* Description:   Cleans IPO curve with the (optional) threshold.         */ | 
					
						
							|  |  |  | /***************************************************************************/ | 
					
						
							|  |  |  | static PyObject *IpoCurve_clean( C_IpoCurve * self, PyObject * args ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	float thresh, othresh; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	thresh= othresh= G.scene->toolsettings->clean_thresh; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* expecting float */ | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( args, "|f", &thresh ) ) | 
					
						
							|  |  |  | 		return ( EXPP_ReturnPyObjError | 
					
						
							|  |  |  | 			 ( PyExc_TypeError, "expected float argument" ) ); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* set IPO-cleaning threshold based on value provided by user (temporarily) */ | 
					
						
							|  |  |  | 	G.scene->toolsettings->clean_thresh= thresh; | 
					
						
							|  |  |  | 	clean_ipo_curve( self->ipocurve ); | 
					
						
							|  |  |  | 	G.scene->toolsettings->clean_thresh= othresh; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | static PyObject *IpoCurve_getDriver( C_IpoCurve * self ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	if( !self->ipocurve->driver ) | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 		return PyInt_FromLong( 0 );	 | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		if (self->ipocurve->driver->type == IPO_DRIVER_TYPE_NORMAL) | 
					
						
							|  |  |  | 			return PyInt_FromLong( 1 ); | 
					
						
							|  |  |  | 		if (self->ipocurve->driver->type == IPO_DRIVER_TYPE_PYTHON) | 
					
						
							|  |  |  | 			return PyInt_FromLong( 2 ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"unknown driver type, internal error" ); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | 	sets the driver to | 
					
						
							|  |  |  | 	0: disabled | 
					
						
							|  |  |  | 	1: enabled (object) | 
					
						
							|  |  |  | 	2: enabled (python expression) | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | static int IpoCurve_setDriver( C_IpoCurve * self, PyObject * args ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	IpoCurve *ipo = self->ipocurve; | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 	int type; | 
					
						
							| 
									
										
										
										
											2007-07-01 05:41:23 +00:00
										 |  |  | 	if( !PyInt_Check( args ) ) | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 				"expected int argument 0 or 1 " ); | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	type = PyInt_AS_LONG( args ); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (type < 0 || type > 2) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 				"expected int argument 0, 1 or 2" ); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (type==0) { /* disable driver */ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		if( ipo->driver ) { | 
					
						
							|  |  |  | 			MEM_freeN( ipo->driver ); | 
					
						
							|  |  |  | 			ipo->driver = NULL;			 | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		if( !ipo->driver ) { /*add driver if its not there */ | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 			ipo->driver = MEM_callocN( sizeof(IpoDriver), "ipo driver" ); | 
					
						
							|  |  |  | 			ipo->driver->blocktype = ID_OB; | 
					
						
							|  |  |  | 			ipo->driver->adrcode = OB_LOC_X; | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		if (type==1 && ipo->driver->type != IPO_DRIVER_TYPE_NORMAL) { | 
					
						
							|  |  |  | 			ipo->driver->type = IPO_DRIVER_TYPE_NORMAL; | 
					
						
							|  |  |  | 			ipo->driver->ob = NULL; | 
					
						
							|  |  |  | 			ipo->driver->flag &= ~IPO_DRIVER_FLAG_INVALID; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 		} else if (type==2 && ipo->driver->type != IPO_DRIVER_TYPE_PYTHON) { | 
					
						
							|  |  |  | 			ipo->driver->type = IPO_DRIVER_TYPE_PYTHON; | 
					
						
							|  |  |  | 			/* we should probably set ipo->driver->ob, but theres no way to do it properly */ | 
					
						
							|  |  |  | 			ipo->driver->ob = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | static PyObject *IpoCurve_getDriverObject( C_IpoCurve * self ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	IpoCurve *ipo = self->ipocurve; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 	if( ipo->driver ) | 
					
						
							|  |  |  | 		return Object_CreatePyObject( ipo->driver->ob ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | static int IpoCurve_setDriverObject( C_IpoCurve * self, PyObject * arg ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	IpoCurve *ipo = self->ipocurve; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	if( !ipo->driver ) | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 		return EXPP_ReturnIntError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "This IpoCurve does not have an active driver" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!BPy_Object_Check(arg) ) | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		return EXPP_ReturnIntError( PyExc_RuntimeError, | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 					      "expected an object argument" ); | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 	ipo->driver->ob = ((BPy_Object *)arg)->object; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	DAG_scene_sort(G.scene);	 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject *IpoCurve_getDriverChannel( C_IpoCurve * self ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	if( !self->ipocurve->driver ) | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "This IpoCurve does not have an active driver" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	return PyInt_FromLong( self->ipocurve->driver->adrcode );	 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int IpoCurve_setDriverChannel( C_IpoCurve * self, PyObject * args ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 	IpoCurve *ipo = self->ipocurve; | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	short param; | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	if( !ipo->driver ) | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 		return EXPP_ReturnIntError( PyExc_RuntimeError, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 				"This IpoCurve does not have an active driver" ); | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-01 05:41:23 +00:00
										 |  |  | 	if( !PyInt_Check( args ) ) | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 				"expected int argument" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	param  = (short)PyInt_AS_LONG ( args ); | 
					
						
							|  |  |  | 	if( ( param >= OB_LOC_X && param <= OB_LOC_Z ) | 
					
						
							|  |  |  | 			|| ( param >= OB_ROT_X && param <= OB_ROT_Z ) | 
					
						
							|  |  |  | 			|| ( param >= OB_SIZE_X && param <= OB_SIZE_Z ) ) { | 
					
						
							|  |  |  | 		ipo->driver->adrcode = (short)PyInt_AS_LONG ( args ); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-12-06 05:42:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 	return EXPP_ReturnIntError( PyExc_ValueError, "invalid int argument" ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | static PyObject *IpoCurve_getDriverExpression( C_IpoCurve * self ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IpoCurve *ipo = self->ipocurve; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( ipo->driver && ipo->driver->type == IPO_DRIVER_TYPE_PYTHON ) | 
					
						
							|  |  |  | 		return PyString_FromString( ipo->driver->name ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int IpoCurve_setDriverExpression( C_IpoCurve * self, PyObject * arg ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	IpoCurve *ipo = self->ipocurve; | 
					
						
							|  |  |  | 	char *exp; /* python expression */ | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if( !ipo->driver ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"This IpoCurve does not have an active driver" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ipo->driver->type != IPO_DRIVER_TYPE_PYTHON) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 			"This IpoCurve is not a python expression set the driver attribute to 2" ); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(!PyString_Check(arg) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					      "expected a string argument" ); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	exp = PyString_AsString(arg); | 
					
						
							|  |  |  | 	if (strlen(exp)>127) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_ValueError, | 
					
						
							|  |  |  | 					      "string is too long, use 127 characters or less" ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | 	strcpy(ipo->driver->name, exp); | 
					
						
							| 
									
										
										
										
											2006-12-25 10:44:28 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | static PyObject *M_IpoCurve_ExtendDict( void ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *EM = PyConstant_New(  ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( EM ) { | 
					
						
							|  |  |  | 		BPy_constant *d = ( BPy_constant * ) EM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		PyConstant_Insert( d, "CONST", PyInt_FromLong( IPO_HORIZ ) ); | 
					
						
							|  |  |  | 		PyConstant_Insert( d, "EXTRAP", PyInt_FromLong( IPO_DIR ) ); | 
					
						
							|  |  |  | 		PyConstant_Insert( d, "CYCLIC", PyInt_FromLong( IPO_CYCL ) ); | 
					
						
							|  |  |  | 		PyConstant_Insert( d, "CYCLIC_EXTRAP", PyInt_FromLong( IPO_CYCLX ) ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return EM; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *M_IpoCurve_InterpDict( void ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *IM = PyConstant_New(  ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( IM ) { | 
					
						
							|  |  |  | 		BPy_constant *d = ( BPy_constant * ) IM; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		PyConstant_Insert( d, "CONST", PyInt_FromLong( IPO_CONST ) ); | 
					
						
							|  |  |  | 		PyConstant_Insert( d, "LINEAR", PyInt_FromLong( IPO_LIN ) ); | 
					
						
							|  |  |  | 		PyConstant_Insert( d, "BEZIER", PyInt_FromLong( IPO_BEZ ) ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return IM; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:              IpoCurve_Init                                      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyObject *IpoCurve_Init( void ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *submodule; | 
					
						
							|  |  |  | 	PyObject *ExtendTypes = M_IpoCurve_ExtendDict( ); | 
					
						
							|  |  |  | 	PyObject *InterpTypes = M_IpoCurve_InterpDict( ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( PyType_Ready( &IpoCurve_Type ) < 0) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	submodule = | 
					
						
							|  |  |  | 		Py_InitModule3( "Blender.IpoCurve", M_IpoCurve_methods, | 
					
						
							|  |  |  | 				M_IpoCurve_doc ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "LOC_X", OB_LOC_X ); | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "LOC_Y", OB_LOC_Y ); | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "LOC_Z", OB_LOC_Z );	 | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "ROT_X", OB_ROT_X ); | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "ROT_Y", OB_ROT_Y ); | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "ROT_Z", OB_ROT_Z );	 | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "SIZE_X", OB_SIZE_X ); | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "SIZE_Y", OB_SIZE_Y ); | 
					
						
							|  |  |  | 	PyModule_AddIntConstant( submodule, "SIZE_Z", OB_SIZE_Z );	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( ExtendTypes ) | 
					
						
							|  |  |  | 		PyModule_AddObject( submodule, "ExtendTypes", ExtendTypes ); | 
					
						
							|  |  |  | 	if( InterpTypes ) | 
					
						
							|  |  |  | 		PyModule_AddObject( submodule, "InterpTypes", InterpTypes ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return submodule; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *IpoCurve_newgetInterp( C_IpoCurve * self ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-06-29 08:59:26 +00:00
										 |  |  | 	return PyInt_FromLong( self->ipocurve->ipo );	 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int IpoCurve_newsetInterp( C_IpoCurve * self, PyObject * value ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return EXPP_setIValueRange( value, &self->ipocurve->ipo, | 
					
						
							|  |  |  | 			IPO_CONST, IPO_BEZ, 'h' ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *IpoCurve_newgetExtend( C_IpoCurve * self ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-06-29 08:59:26 +00:00
										 |  |  | 	return PyInt_FromLong( self->ipocurve->extrap );	 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int IpoCurve_newsetExtend( C_IpoCurve * self, PyObject * value ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return EXPP_setIValueRange( value, &self->ipocurve->extrap, | 
					
						
							|  |  |  | 			IPO_HORIZ, IPO_CYCLX, 'h' ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | static PyObject *IpoCurve_getFlag( C_IpoCurve * self, void *type ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-04-17 21:14:55 +00:00
										 |  |  | 	if (self->ipocurve->flag & GET_INT_FROM_POINTER(type)) | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | 		Py_RETURN_TRUE; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		Py_RETURN_FALSE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int IpoCurve_setFlag( C_IpoCurve * self, PyObject *value, void *type ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int param = PyObject_IsTrue( value ); | 
					
						
							| 
									
										
										
										
											2007-07-12 11:51:21 +00:00
										 |  |  | 	if( param == -1 ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 				"expected True/False or 0/1" ); | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (param) | 
					
						
							| 
									
										
										
										
											2008-04-17 21:14:55 +00:00
										 |  |  | 		self->ipocurve->flag |= GET_INT_FROM_POINTER(type); | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2008-04-17 21:14:55 +00:00
										 |  |  | 		self->ipocurve->flag &= ~GET_INT_FROM_POINTER(type); | 
					
						
							| 
									
										
										
										
											2007-01-13 04:53:41 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | /* #####DEPRECATED###### */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * value ) | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	float x, y; | 
					
						
							|  |  |  | 	int npoints; | 
					
						
							|  |  |  | 	IpoCurve *icu; | 
					
						
							|  |  |  | 	BezTriple *bzt, *tmp; | 
					
						
							|  |  |  | 	static char name[10] = "mlml"; | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( value, "ff", &x, &y ) ) | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 		return ( EXPP_ReturnPyObjError | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 			 ( PyExc_TypeError, "expected a tuple of 2 floats" ) ); | 
					
						
							| 
									
										
										
										
											2006-04-21 20:27:52 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	icu = self->ipocurve; | 
					
						
							|  |  |  | 	npoints = icu->totvert; | 
					
						
							|  |  |  | 	tmp = icu->bezt; | 
					
						
							|  |  |  | 	icu->bezt = MEM_mallocN( sizeof( BezTriple ) * ( npoints + 1 ), name ); | 
					
						
							|  |  |  | 	if( tmp ) { | 
					
						
							|  |  |  | 		memmove( icu->bezt, tmp, sizeof( BezTriple ) * npoints ); | 
					
						
							|  |  |  | 		MEM_freeN( tmp ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	memmove( icu->bezt + npoints, icu->bezt, sizeof( BezTriple ) ); | 
					
						
							|  |  |  | 	icu->totvert++; | 
					
						
							|  |  |  | 	bzt = icu->bezt + npoints; | 
					
						
							|  |  |  | 	bzt->vec[0][0] = x - 1; | 
					
						
							|  |  |  | 	bzt->vec[1][0] = x; | 
					
						
							|  |  |  | 	bzt->vec[2][0] = x + 1; | 
					
						
							|  |  |  | 	bzt->vec[0][1] = y - 1; | 
					
						
							|  |  |  | 	bzt->vec[1][1] = y; | 
					
						
							|  |  |  | 	bzt->vec[2][1] = y + 1; | 
					
						
							|  |  |  | 	/* set handle type to Auto */ | 
					
						
							|  |  |  | 	bzt->h1 = HD_AUTO; | 
					
						
							|  |  |  | 	bzt->h2 = HD_AUTO; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-16 12:24:41 +00:00
										 |  |  | 	Py_RETURN_NONE; | 
					
						
							| 
									
										
										
										
											2005-10-26 16:30:50 +00:00
										 |  |  | } |