| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. The Blender | 
					
						
							|  |  |  |  * Foundation also sells licenses for use in proprietary software under | 
					
						
							|  |  |  |  * the Blender License.  See http://www.blender.org/BL/ for information
 | 
					
						
							|  |  |  |  * about this. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Jacques Guignot | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Ipo.h"
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:              M_Ipo_New                                          */ | 
					
						
							|  |  |  | /* Python equivalent:     Blender.Ipo.New                                    */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | static PyObject *M_Ipo_New(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  | 	Ipo *add_ipo(char *name, int idcode); | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | 	char*name = NULL,*code=NULL; | 
					
						
							|  |  |  | 	int idcode = -1; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |   C_Ipo    *pyipo; | 
					
						
							|  |  |  |   Ipo      *blipo; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "ss", &code,&name)) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError,"expected string int arguments")); | 
					
						
							|  |  |  | 		if (!strcmp(code,"Object"))idcode = ID_OB; | 
					
						
							|  |  |  | 		if (!strcmp(code,"Camera"))idcode = ID_CA; | 
					
						
							|  |  |  | 		if (!strcmp(code,"World"))idcode = ID_WO; | 
					
						
							|  |  |  | 		if (!strcmp(code,"Material"))idcode = ID_MA; | 
					
						
							|  |  |  | 		if (idcode == -1) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad code")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  |   blipo = add_ipo(name,idcode); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (blipo)  | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  | 		pyipo = (C_Ipo *)PyObject_NEW(C_Ipo, &Ipo_Type); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_RuntimeError, | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  | 																	 "couldn't create Ipo Data in Blender")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (pyipo == NULL) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  | 																	 "couldn't create Ipo Data object")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   pyipo->ipo = blipo;  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return (PyObject *)pyipo; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:              M_Ipo_Get                                       */ | 
					
						
							|  |  |  | /* Python equivalent:     Blender.Ipo.Get                                 */ | 
					
						
							|  |  |  | /* Description:           Receives a string and returns the ipo data obj  */ | 
					
						
							|  |  |  | /*                        whose name matches the string.  If no argument is  */ | 
					
						
							|  |  |  | /*                        passed in, a list of all ipo data names in the  */ | 
					
						
							|  |  |  | /*                        current scene is returned.                         */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *M_Ipo_Get(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char   *name = NULL; | 
					
						
							|  |  |  |   Ipo *ipo_iter; | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   PyObject *ipolist, *pyobj; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |   C_Ipo *wanted_ipo = NULL; | 
					
						
							|  |  |  |   char error_msg[64]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "|s", &name)) | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |                 "expected string argument (or nothing)")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ipo_iter = G.main->ipo.first; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   if (name) { /* (name) - Search ipo by name */ | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |     while ((ipo_iter) && (wanted_ipo == NULL)) { | 
					
						
							|  |  |  |       if (strcmp (name, ipo_iter->id.name+2) == 0) { | 
					
						
							|  |  |  |         wanted_ipo = (C_Ipo *)PyObject_NEW(C_Ipo, &Ipo_Type); | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         if (wanted_ipo) wanted_ipo->ipo = ipo_iter; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |       ipo_iter = ipo_iter->id.next; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (wanted_ipo == NULL) { /* Requested ipo doesn't exist */ | 
					
						
							|  |  |  |       PyOS_snprintf(error_msg, sizeof(error_msg), | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |                             "Ipo \"%s\" not found", name); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |       return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return (PyObject *)wanted_ipo; | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   else { /* () - return a list with all ipos in the scene */ | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |     int index = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ipolist = PyList_New (BLI_countlist (&(G.main->ipo))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (ipolist == NULL) | 
					
						
							|  |  |  |       return (PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |                         "couldn't create PyList")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     while (ipo_iter) { | 
					
						
							|  |  |  |       pyobj = Ipo_CreatePyObject (ipo_iter); | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |  			if (!pyobj) | 
					
						
							|  |  |  |         return (PythonReturnErrorObject (PyExc_MemoryError, | 
					
						
							|  |  |  |                   "couldn't create PyString")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |       PyList_SET_ITEM (ipolist, index, pyobj); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |       ipo_iter = ipo_iter->id.next; | 
					
						
							|  |  |  |       index++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |     return (ipolist); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * M_Ipo_Recalc(PyObject *self, PyObject *args) | 
					
						
							|  |  |  | {	 | 
					
						
							|  |  |  | 	void testhandles_ipocurve(IpoCurve *icu); | 
					
						
							| 
									
										
										
										
											2003-08-01 19:47:01 +00:00
										 |  |  |  PyObject  *a; | 
					
						
							|  |  |  | IpoCurve *icu;  | 
					
						
							|  |  |  | if (!PyArg_ParseTuple(args, "O", &a)) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError,"expected ipo argument)")); | 
					
						
							|  |  |  | icu = IpoCurve_FromPyObject(a); | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  |  testhandles_ipocurve(icu);  | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | /* Function:              Ipo_Init                                           */ | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-06-28 07:38:21 +00:00
										 |  |  | PyObject *Ipo_Init (void) | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   PyObject  *submodule; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |   Ipo_Type.ob_type = &PyType_Type; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   submodule = Py_InitModule3("Blender.Ipo", M_Ipo_methods, M_Ipo_doc); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return (submodule); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python C_Ipo methods:                                                  */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *Ipo_getName(C_Ipo *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *attr = PyString_FromString(self->ipo->id.name+2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (attr) return attr; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | static PyObject *Ipo_setName(C_Ipo *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   char *name; | 
					
						
							|  |  |  |   char buf[21]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "s", &name)) | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError,   "expected string argument")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   PyOS_snprintf(buf, sizeof(buf), "%s", name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   rename_id(&self->ipo->id, buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_getBlocktype(C_Ipo *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *attr = PyInt_FromLong(self->ipo->blocktype); | 
					
						
							|  |  |  |   if (attr) return attr; | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  |   return (EXPP_ReturnPyObjError (PyExc_RuntimeError,"couldn't get Ipo.blocktype attribute")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_setBlocktype(C_Ipo *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int blocktype = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "i", &blocktype)) | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected string argument")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         self->ipo->blocktype = (short)blocktype; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_getRctf(C_Ipo *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         PyObject* l = PyList_New(0); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |   PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.xmin)); | 
					
						
							|  |  |  |   PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.xmax)); | 
					
						
							|  |  |  |   PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.ymin)); | 
					
						
							|  |  |  |   PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.ymax)); | 
					
						
							|  |  |  |   return l; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_setRctf(C_Ipo *self, PyObject *args) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         float v[4]; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |   if (!PyArg_ParseTuple(args, "ffff",v,v+1,v+2,v+3)) | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected 4 float argument")); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         self->ipo->cur.xmin  = v[0]; | 
					
						
							|  |  |  |         self->ipo->cur.xmax  = v[1]; | 
					
						
							|  |  |  |         self->ipo->cur.ymin  = v[2]; | 
					
						
							|  |  |  |         self->ipo->cur.ymax  = v[3]; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_getNcurves(C_Ipo *self) | 
					
						
							|  |  |  | {  | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         int i = 0; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         IpoCurve *icu; | 
					
						
							|  |  |  |         for (icu=self->ipo->curve.first; icu; icu=icu->next){ | 
					
						
							|  |  |  |                 i++; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return (PyInt_FromLong(i) ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_addCurve(C_Ipo *self, PyObject *args) | 
					
						
							|  |  |  | {  | 
					
						
							|  |  |  | 	void *MEM_callocN(unsigned int len, char *str); | 
					
						
							| 
									
										
										
										
											2003-07-21 17:35:19 +00:00
										 |  |  |     IpoCurve *ptr; | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | 	int i = 0,typenumber = -1; | 
					
						
							|  |  |  | 	char*type = 0; | 
					
						
							|  |  |  | 	static char *name="mmm";	 | 
					
						
							|  |  |  | 	char * nametab[24] = {"LocX","LocY","LocZ","dLocX","dLocY","dLocZ","RotX","RotY","RotZ","dRotX","dRotY","dRotZ","SizeX","SizeY","SizeZ","dSizeX","dSizeY","dSizeZ","Layer","Time","ColR","ColG","ColB","ColA"}; | 
					
						
							| 
									
										
										
										
											2003-07-21 17:35:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | 	if (!PyArg_ParseTuple(args, "s",&type)) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected string argument")); | 
					
						
							|  |  |  | 	for(i = 0;i<24;i++) | 
					
						
							|  |  |  | 		if(!strcmp(nametab[i],type)) | 
					
						
							|  |  |  | 			typenumber=i+1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (typenumber == -1) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_TypeError, "unknown type")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-21 17:35:19 +00:00
										 |  |  | 	ptr = (IpoCurve*)MEM_callocN(sizeof(IpoCurve),name); | 
					
						
							| 
									
										
										
										
											2003-07-21 00:08:30 +00:00
										 |  |  | 	ptr->blocktype = 16975; | 
					
						
							|  |  |  | 	ptr->totvert = 0; | 
					
						
							|  |  |  | 	ptr->adrcode = typenumber; | 
					
						
							|  |  |  | 	ptr->ipo = 2; | 
					
						
							|  |  |  | 	ptr->flag = 7; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 	BLI_addhead(&(self->ipo->curve),ptr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return IpoCurve_CreatePyObject (ptr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  | static PyObject *Ipo_getCurves(C_Ipo *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject *attr = PyList_New(0); | 
					
						
							|  |  |  |   IpoCurve *icu; | 
					
						
							|  |  |  |         for (icu=self->ipo->curve.first; icu; icu=icu->next){ | 
					
						
							|  |  |  |         PyList_Append(attr, IpoCurve_CreatePyObject(icu)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 	return attr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_getNBezPoints(C_Ipo *self, PyObject *args) | 
					
						
							|  |  |  | {  | 
					
						
							|  |  |  | 	int num = 0 , i = 0; | 
					
						
							|  |  |  | 	IpoCurve *icu = 0; | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "i",&num)) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument")); | 
					
						
							|  |  |  | 	icu =self->ipo->curve.first; | 
					
						
							|  |  |  |  if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); | 
					
						
							|  |  |  |  for(i = 0;i<num;i++) | 
					
						
							|  |  |  | 	 { | 
					
						
							|  |  |  | 		 if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad curve number")); | 
					
						
							|  |  |  | 		 icu=icu->next; | 
					
						
							|  |  |  |                   | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  |  return (PyInt_FromLong(icu->totvert) ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_DeleteBezPoints(C_Ipo *self, PyObject *args) | 
					
						
							|  |  |  | {  | 
					
						
							|  |  |  | 	int num = 0 , i = 0; | 
					
						
							|  |  |  | 	IpoCurve *icu = 0; | 
					
						
							|  |  |  | 	if (!PyArg_ParseTuple(args, "i",&num)) | 
					
						
							|  |  |  | 		return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument")); | 
					
						
							|  |  |  | 	icu =self->ipo->curve.first; | 
					
						
							|  |  |  |  if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); | 
					
						
							|  |  |  |  for(i = 0;i<num;i++) | 
					
						
							|  |  |  | 	 { | 
					
						
							|  |  |  | 		 if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad curve number")); | 
					
						
							|  |  |  | 		 icu=icu->next; | 
					
						
							|  |  |  |                   | 
					
						
							|  |  |  | 	 } | 
					
						
							|  |  |  |  icu->totvert--; | 
					
						
							|  |  |  |  return (PyInt_FromLong(icu->totvert) ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | static PyObject *Ipo_getCurveBP(C_Ipo *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  | {        | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  | 	struct BPoint *ptrbpoint; | 
					
						
							|  |  |  | 	int num = 0,i; | 
					
						
							|  |  |  | 	IpoCurve *icu; | 
					
						
							|  |  |  | 	PyObject* l; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "i",&num)) | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, "expected int argument")); | 
					
						
							|  |  |  | 	icu =self->ipo->curve.first; | 
					
						
							|  |  |  | 	if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); | 
					
						
							|  |  |  | 	for(i = 0;i<num;i++) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad curve number")); | 
					
						
							|  |  |  | 			icu=icu->next; | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  |                  | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  | 	ptrbpoint = icu->bp; | 
					
						
							|  |  |  | 	if(!ptrbpoint)return EXPP_ReturnPyObjError(PyExc_TypeError,"No base point"); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-10 00:22:17 +00:00
										 |  |  | 	l = PyList_New(0); | 
					
						
							|  |  |  | 	for(i=0;i<4;i++) | 
					
						
							|  |  |  | 		PyList_Append( l, PyFloat_FromDouble(ptrbpoint->vec[i])); | 
					
						
							|  |  |  | 	return l; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_getCurveBeztriple(C_Ipo *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  | {        | 
					
						
							|  |  |  |         struct BezTriple *ptrbt; | 
					
						
							|  |  |  |         int num = 0,pos,i,j; | 
					
						
							|  |  |  |         IpoCurve *icu; | 
					
						
							|  |  |  |         PyObject* l = PyList_New(0); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "ii",&num,&pos)) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError, | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |                                                                                                                                          "expected int argument")); | 
					
						
							|  |  |  |         icu =self->ipo->curve.first; | 
					
						
							|  |  |  |         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); | 
					
						
							|  |  |  |         for(i = 0;i<num;i++) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); | 
					
						
							|  |  |  |                         icu=icu->next; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |         if (pos >= icu->totvert) | 
					
						
							|  |  |  |                 return EXPP_ReturnPyObjError(PyExc_TypeError,"Bad bezt number"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ptrbt = icu->bezt + pos; | 
					
						
							|  |  |  |         if(!ptrbt) | 
					
						
							|  |  |  |                 return EXPP_ReturnPyObjError(PyExc_TypeError,"No bez triple"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for(i=0;i<3;i++) | 
					
						
							|  |  |  |                 for(j=0;j<3;j++) | 
					
						
							|  |  |  |                         PyList_Append( l, PyFloat_FromDouble(ptrbt->vec[i][j])); | 
					
						
							|  |  |  |         return l; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject *Ipo_setCurveBeztriple(C_Ipo *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  | {        | 
					
						
							|  |  |  |         struct BezTriple *ptrbt; | 
					
						
							|  |  |  |         int num = 0,pos,i; | 
					
						
							|  |  |  |         IpoCurve *icu; | 
					
						
							|  |  |  |         PyObject *listargs=0; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "iiO",&num,&pos,&listargs)) | 
					
						
							| 
									
										
										
										
											2003-08-01 19:47:01 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError,"expected int int object argument")); | 
					
						
							|  |  |  |         if(!PyTuple_Check(listargs))  | 
					
						
							|  |  |  | return (EXPP_ReturnPyObjError (PyExc_TypeError,"3rd arg should be a tuple")); | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         icu =self->ipo->curve.first; | 
					
						
							|  |  |  |         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); | 
					
						
							|  |  |  |         for(i = 0;i<num;i++) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); | 
					
						
							|  |  |  |                         icu=icu->next; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |         if (pos >= icu->totvert) | 
					
						
							|  |  |  |                 return EXPP_ReturnPyObjError(PyExc_TypeError,"Bad bezt number"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ptrbt = icu->bezt + pos; | 
					
						
							|  |  |  |         if(!ptrbt) | 
					
						
							|  |  |  |                 return EXPP_ReturnPyObjError(PyExc_TypeError,"No bez triple"); | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         for(i=0;i<9;i++) | 
					
						
							|  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2003-08-01 19:47:01 +00:00
										 |  |  |                         PyObject * xx = PyTuple_GetItem(listargs,i); | 
					
						
							|  |  |  | 												printf("%f\n", PyFloat_AsDouble(xx)); | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |                         ptrbt->vec[i/3][i%3] = PyFloat_AsDouble(xx); | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Py_INCREF(Py_None); | 
					
						
							|  |  |  |   return Py_None; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-08-01 19:47:01 +00:00
										 |  |  | static PyObject *Ipo_EvaluateCurveOn(C_Ipo *self, PyObject *args) | 
					
						
							|  |  |  | {   | 
					
						
							|  |  |  | 	float eval_icu(IpoCurve *icu, float ipotime) ; | 
					
						
							|  |  |  |       | 
					
						
							|  |  |  |         int num = 0,i; | 
					
						
							|  |  |  |         IpoCurve *icu; | 
					
						
							|  |  |  | 				float time = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "if",&num,&time)) | 
					
						
							|  |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError,"expected int argument")); | 
					
						
							|  |  |  |         icu =self->ipo->curve.first; | 
					
						
							|  |  |  |         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); | 
					
						
							|  |  |  |         for(i = 0;i<num;i++) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); | 
					
						
							|  |  |  |                         icu=icu->next; | 
					
						
							|  |  |  |                   | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |         return PyFloat_FromDouble(eval_icu(icu,time)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | static PyObject *Ipo_getCurvecurval(C_Ipo *self, PyObject *args) | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  | {        | 
					
						
							|  |  |  |         int num = 0,i; | 
					
						
							|  |  |  |         IpoCurve *icu; | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!PyArg_ParseTuple(args, "i",&num)) | 
					
						
							| 
									
										
										
										
											2003-08-01 19:47:01 +00:00
										 |  |  |     return (EXPP_ReturnPyObjError (PyExc_TypeError,"expected int argument")); | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         icu =self->ipo->curve.first; | 
					
						
							|  |  |  |         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); | 
					
						
							|  |  |  |         for(i = 0;i<num;i++) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                         if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); | 
					
						
							|  |  |  |                         icu=icu->next; | 
					
						
							|  |  |  |                   | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  |         return PyFloat_FromDouble(icu->curval); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    IpoDeAlloc                                                   */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Ipo type. It is        */ | 
					
						
							|  |  |  | /*              the destructor function.                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static void IpoDeAlloc (C_Ipo *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PyObject_DEL (self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    IpoGetAttr                                                   */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Ipo type. It is        */ | 
					
						
							|  |  |  | /*              the function that accesses C_Ipo "member variables" and      */ | 
					
						
							|  |  |  | /*              methods.                                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *IpoGetAttr (C_Ipo *self, char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-07-19 08:32:01 +00:00
										 |  |  | if (strcmp (name, "curves") == 0)return Ipo_getCurves (self); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  |   return Py_FindMethod(C_Ipo_methods, (PyObject *)self, name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    IpoSetAttr                                                */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Ipo type. It is the */ | 
					
						
							|  |  |  | /*              function that sets Ipo Data attributes (member variables).*/ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static int IpoSetAttr (C_Ipo *self, char *name, PyObject *value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return 0; /* normal exit */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  | /* Function:    IpoRepr                                                      */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the C_Ipo type. It           */ | 
					
						
							|  |  |  | /*              builds a meaninful string to represent ipo objects.          */ | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyObject *IpoRepr (C_Ipo *self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-07-04 16:06:39 +00:00
										 |  |  |   return PyString_FromFormat("[Ipo \"%s\"]", self->ipo->id.name+2); | 
					
						
							| 
									
										
										
										
											2003-06-05 18:03:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-06-12 04:51:50 +00:00
										 |  |  | /* Three Python Ipo_Type helper functions needed by the Object module: */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    Ipo_CreatePyObject                                           */ | 
					
						
							|  |  |  | /* Description: This function will create a new C_Ipo from an existing       */ | 
					
						
							|  |  |  | /*              Blender ipo structure.                                       */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyObject *Ipo_CreatePyObject (Ipo *ipo) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	C_Ipo *pyipo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pyipo = (C_Ipo *)PyObject_NEW (C_Ipo, &Ipo_Type); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!pyipo) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError (PyExc_MemoryError, | 
					
						
							|  |  |  | 						"couldn't create C_Ipo object"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pyipo->ipo = ipo; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (PyObject *)pyipo; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    Ipo_CheckPyObject                                            */ | 
					
						
							|  |  |  | /* Description: This function returns true when the given PyObject is of the */ | 
					
						
							|  |  |  | /*              type Ipo. Otherwise it will return false.                    */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | int Ipo_CheckPyObject (PyObject *pyobj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (pyobj->ob_type == &Ipo_Type); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:    Ipo_FromPyObject                                             */ | 
					
						
							|  |  |  | /* Description: This function returns the Blender ipo from the given         */ | 
					
						
							|  |  |  | /*              PyObject.                                                    */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | Ipo *Ipo_FromPyObject (PyObject *pyobj) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ((C_Ipo *)pyobj)->ipo; | 
					
						
							|  |  |  | } |