| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | /* 
 | 
					
						
							| 
									
										
										
										
											2004-09-18 18:47:03 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +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): Joseph Gilbert | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "NLA.h" /*This must come first*/
 | 
					
						
							| 
									
										
										
										
											2004-10-07 19:25:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "BKE_action.h"
 | 
					
						
							|  |  |  | #include "BKE_global.h"
 | 
					
						
							|  |  |  | #include "BKE_main.h"
 | 
					
						
							|  |  |  | #include "BKE_library.h"
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							|  |  |  | #include "Object.h"
 | 
					
						
							| 
									
										
										
										
											2004-10-07 19:25:40 +00:00
										 |  |  | #include "Ipo.h"
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "gen_utils.h"
 | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python API function prototypes for the NLA module.			 */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NLA_NewAction( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *M_NLA_CopyAction( PyObject * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *M_NLA_GetActions( PyObject * self ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | /* The following string definitions are used for documentation strings.	   */ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | /* In Python these will be written to the console when doing a		 */ | 
					
						
							|  |  |  | /* Blender.Armature.NLA.__doc__					 */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | char M_NLA_doc[] = | 
					
						
							|  |  |  | 	"The Blender NLA module -This module provides control over  Armature keyframing in Blender."; | 
					
						
							|  |  |  | char M_NLA_NewAction_doc[] = | 
					
						
							|  |  |  | 	"(name) - Create new action for linking to an object."; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | char M_NLA_CopyAction_doc[] = "(name) - Copy action and return copy."; | 
					
						
							|  |  |  | char M_NLA_GetActions_doc[] = "(name) - Returns a dictionary of actions."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | /* Python method structure definition for Blender.Armature.NLA module:	 */ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | struct PyMethodDef M_NLA_methods[] = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	{"NewAction", ( PyCFunction ) M_NLA_NewAction, METH_VARARGS, | 
					
						
							|  |  |  | 	 M_NLA_NewAction_doc}, | 
					
						
							|  |  |  | 	{"CopyAction", ( PyCFunction ) M_NLA_CopyAction, METH_VARARGS, | 
					
						
							|  |  |  | 	 M_NLA_CopyAction_doc}, | 
					
						
							|  |  |  | 	{"GetActions", ( PyCFunction ) M_NLA_GetActions, METH_NOARGS, | 
					
						
							|  |  |  | 	 M_NLA_GetActions_doc}, | 
					
						
							|  |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | /* Python BPy_Action methods declarations:				*/ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *Action_getName( BPy_Action * self ); | 
					
						
							|  |  |  | static PyObject *Action_setName( BPy_Action * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *Action_setActive( BPy_Action * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args ); | 
					
						
							|  |  |  | static PyObject *Action_getAllChannelIpos( BPy_Action * self ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python BPy_Action methods table:					 */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static PyMethodDef BPy_Action_methods[] = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* name, method, flags, doc */ | 
					
						
							|  |  |  | 	{"getName", ( PyCFunction ) Action_getName, METH_NOARGS, | 
					
						
							|  |  |  | 	 "() - return Action name"}, | 
					
						
							|  |  |  | 	{"setName", ( PyCFunction ) Action_setName, METH_VARARGS, | 
					
						
							|  |  |  | 	 "(str) - rename Action"}, | 
					
						
							|  |  |  | 	{"setActive", ( PyCFunction ) Action_setActive, METH_VARARGS, | 
					
						
							|  |  |  | 	 "(str) -set this action as the active action for an object"}, | 
					
						
							|  |  |  | 	{"getChannelIpo", ( PyCFunction ) Action_getChannelIpo, METH_VARARGS, | 
					
						
							|  |  |  | 	 "(str) -get the Ipo from a named action channel in this action"}, | 
					
						
							|  |  |  | 	{"removeChannel", ( PyCFunction ) Action_removeChannel, METH_VARARGS, | 
					
						
							|  |  |  | 	 "(str) -remove the channel from the action"}, | 
					
						
							|  |  |  | 	{"getAllChannelIpos", ( PyCFunction ) Action_getAllChannelIpos, | 
					
						
							|  |  |  | 	 METH_NOARGS, | 
					
						
							|  |  |  | 	 "() - Return a dict of (name:ipo)-keys containing each channel in the object's action"}, | 
					
						
							|  |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | /* Python TypeAction callback function prototypes:			    */ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static void Action_dealloc( BPy_Action * bone ); | 
					
						
							|  |  |  | static PyObject *Action_getAttr( BPy_Action * bone, char *name ); | 
					
						
							|  |  |  | static int Action_setAttr( BPy_Action * bone, char *name, PyObject * v ); | 
					
						
							|  |  |  | static PyObject *Action_repr( BPy_Action * bone ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Python TypeAction structure definition:				 */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyTypeObject Action_Type = { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject_HEAD_INIT( NULL )  | 
					
						
							|  |  |  | 	0,	/* ob_size */ | 
					
						
							|  |  |  | 	"Blender Action",	/* tp_name */ | 
					
						
							|  |  |  | 	sizeof( BPy_Action ),	/* tp_basicsize */ | 
					
						
							|  |  |  | 	0,			/* tp_itemsize */ | 
					
						
							|  |  |  | 	/* methods */ | 
					
						
							|  |  |  | 	( destructor ) Action_dealloc,	/* tp_dealloc */ | 
					
						
							|  |  |  | 	0,			/* tp_print */ | 
					
						
							|  |  |  | 	( getattrfunc ) Action_getAttr,	/* tp_getattr */ | 
					
						
							|  |  |  | 	( setattrfunc ) Action_setAttr,	/* tp_setattr */ | 
					
						
							|  |  |  | 	0,			/* tp_compare */ | 
					
						
							|  |  |  | 	( reprfunc ) Action_repr,	/* tp_repr */ | 
					
						
							|  |  |  | 	0,			/* tp_as_number */ | 
					
						
							|  |  |  | 	0,			/* tp_as_sequence */ | 
					
						
							|  |  |  | 	0,			/* tp_as_mapping */ | 
					
						
							|  |  |  | 	0,			/* tp_as_hash */ | 
					
						
							|  |  |  | 	0, 0, 0, 0, 0, 0, | 
					
						
							|  |  |  | 	0,			/* tp_doc */ | 
					
						
							|  |  |  | 	0, 0, 0, 0, 0, 0, | 
					
						
							|  |  |  | 	BPy_Action_methods,	/* tp_methods */ | 
					
						
							|  |  |  | 	0,			/* tp_members */ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | //-------------------------------------------------------------------------
 | 
					
						
							|  |  |  | static PyObject *M_NLA_NewAction( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *name_str = "DefaultAction"; | 
					
						
							|  |  |  | 	BPy_Action *py_action = NULL;	/* for Action Data object wrapper in Python */ | 
					
						
							|  |  |  | 	bAction *bl_action = NULL;	/* for actual Action Data we create in Blender */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( args, "|s", &name_str ) ) { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 				       "expected string or nothing" ); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	//Create new action globally
 | 
					
						
							|  |  |  | 	bl_action = alloc_libblock( &G.main->action, ID_AC, name_str ); | 
					
						
							|  |  |  | 	bl_action->id.flag |= LIB_FAKEUSER; | 
					
						
							|  |  |  | 	bl_action->id.us++; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// now create the wrapper obj in Python
 | 
					
						
							|  |  |  | 	if( bl_action ) | 
					
						
							|  |  |  | 		py_action = | 
					
						
							|  |  |  | 			( BPy_Action * ) PyObject_NEW( BPy_Action, | 
					
						
							|  |  |  | 						       &Action_Type ); | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 				       "couldn't create Action Data in Blender" ); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( py_action == NULL ) { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_MemoryError, | 
					
						
							|  |  |  | 				       "couldn't create Action Data object" ); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	py_action->action = bl_action;	// link Python action wrapper with Blender Action
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_INCREF( py_action ); | 
					
						
							|  |  |  | 	return ( PyObject * ) py_action; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NLA_CopyAction( PyObject * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BPy_Action *py_action = NULL; | 
					
						
							|  |  |  | 	bAction *copyAction = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "O!", &Action_Type, &py_action ) ) { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 				       "expected python action type" ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	copyAction = copy_action( py_action->action ); | 
					
						
							|  |  |  | 	return Action_CreatePyObject( copyAction ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *M_NLA_GetActions( PyObject * self ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *dict = PyDict_New(  ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 	bAction *action = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( action = G.main->action.first; action; action = action->id.next ) { | 
					
						
							|  |  |  | 		PyObject *py_action = Action_CreatePyObject( action ); | 
					
						
							|  |  |  | 		if( py_action ) { | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 			// Insert dict entry using the bone name as key
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( PyDict_SetItemString | 
					
						
							|  |  |  | 			    ( dict, action->id.name + 2, py_action ) != 0 ) { | 
					
						
							|  |  |  | 				Py_DECREF( py_action ); | 
					
						
							|  |  |  | 				Py_DECREF( dict ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError | 
					
						
							|  |  |  | 					( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					  "NLA_GetActions: couldn't set dict item" ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			Py_DECREF( py_action ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			Py_DECREF( dict ); | 
					
						
							|  |  |  | 			return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 							"NLA_GetActions: could not create Action object" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 	return dict; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:	NLA_Init						 */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | PyObject *NLA_Init( void ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *submodule; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Action_Type.ob_type = &PyType_Type; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	submodule = Py_InitModule3( "Blender.Armature.NLA", | 
					
						
							|  |  |  | 				    M_NLA_methods, M_NLA_doc ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( submodule ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | static PyObject *Action_getName( BPy_Action * self ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *attr = NULL; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !self->action ) | 
					
						
							|  |  |  | 		( EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					 "couldn't get attribute from a NULL action" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	attr = PyString_FromString( self->action->id.name + 2 ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( attr ) | 
					
						
							|  |  |  | 		return attr; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					"couldn't get Action.name attribute" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | static PyObject *Action_setName( BPy_Action * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	char *name; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !self->action ) | 
					
						
							|  |  |  | 		( EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					 "couldn't get attribute from a NULL action" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "s", &name ) ) | 
					
						
							|  |  |  | 		return ( EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						"expected string argument" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	//change name
 | 
					
						
							|  |  |  | 	strcpy( self->action->id.name + 2, name ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_INCREF( Py_None ); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *Action_setActive( BPy_Action * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_Object *object; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !self->action ) | 
					
						
							|  |  |  | 		( EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					 "couldn't get attribute from a NULL action" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "O!", &Object_Type, &object ) ) | 
					
						
							|  |  |  | 		return ( EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						"expected python object argument" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( object->object->type != OB_ARMATURE ) { | 
					
						
							|  |  |  | 		return ( EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						"object not of type armature" ) ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	//set the active action to object
 | 
					
						
							|  |  |  | 	object->object->action = self->action; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_INCREF( Py_None ); | 
					
						
							|  |  |  | 	return Py_None; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *Action_getChannelIpo( BPy_Action * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *chanName; | 
					
						
							|  |  |  | 	bActionChannel *chan; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "s", &chanName ) ) { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 				       "string expected" ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	chan = get_named_actionchannel( self->action, chanName ); | 
					
						
							|  |  |  | 	if( chan == NULL ) { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 				       "no channel with that name..." ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	//return IPO
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return Ipo_CreatePyObject( chan->ipo ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *Action_removeChannel( BPy_Action * self, PyObject * args ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char *chanName; | 
					
						
							|  |  |  | 	bActionChannel *chan; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !PyArg_ParseTuple( args, "s", &chanName ) ) { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 				       "string expected" ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	chan = get_named_actionchannel( self->action, chanName ); | 
					
						
							|  |  |  | 	if( chan == NULL ) { | 
					
						
							|  |  |  | 		EXPP_ReturnPyObjError( PyExc_AttributeError, | 
					
						
							|  |  |  | 				       "no channel with that name..." ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	//release ipo
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( chan->ipo ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		chan->ipo->id.us--; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//remove channel
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BLI_freelinkN( &self->action->chanbase, chan ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_INCREF( Py_None ); | 
					
						
							|  |  |  | 	return ( Py_None ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | static PyObject *Action_getAllChannelIpos( BPy_Action * self ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *dict = PyDict_New(  ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 	bActionChannel *chan = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	for( chan = self->action->chanbase.first; chan; chan = chan->next ) { | 
					
						
							|  |  |  | 		PyObject *ipo_attr = Ipo_CreatePyObject( chan->ipo ); | 
					
						
							|  |  |  | 		if( ipo_attr ) { | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 			// Insert dict entry using the bone name as key
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			if( PyDict_SetItemString( dict, chan->name, ipo_attr ) | 
					
						
							|  |  |  | 			    != 0 ) { | 
					
						
							|  |  |  | 				Py_DECREF( ipo_attr ); | 
					
						
							|  |  |  | 				Py_DECREF( dict ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				return EXPP_ReturnPyObjError | 
					
						
							|  |  |  | 					( PyExc_RuntimeError, | 
					
						
							|  |  |  | 					  "Action_getAllChannelIpos: couldn't set dict item" ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			Py_DECREF( ipo_attr ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 			Py_DECREF( dict ); | 
					
						
							|  |  |  | 			return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 							"Action_getAllChannelIpos: could not create Ipo object" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 	return dict; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | static void Action_dealloc( BPy_Action * self ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject_DEL( self ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | static PyObject *Action_getAttr( BPy_Action * self, char *name ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *attr = Py_None; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( strcmp( name, "name" ) == 0 ) | 
					
						
							|  |  |  | 		attr = Action_getName( self ); | 
					
						
							|  |  |  | 	else if( strcmp( name, "__members__" ) == 0 ) { | 
					
						
							|  |  |  | 		attr = Py_BuildValue( "[s]", "name" ); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !attr ) | 
					
						
							|  |  |  | 		return ( EXPP_ReturnPyObjError( PyExc_MemoryError, | 
					
						
							|  |  |  | 						"couldn't create PyObject" ) ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( attr != Py_None ) | 
					
						
							|  |  |  | 		return attr;	/* member attribute found, return it */ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	/* not an attribute, search the methods table */ | 
					
						
							|  |  |  | 	return Py_FindMethod( BPy_Action_methods, ( PyObject * ) self, name ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | static int Action_setAttr( BPy_Action * self, char *name, PyObject * value ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	PyObject *valtuple; | 
					
						
							|  |  |  | 	PyObject *error = NULL; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	valtuple = Py_BuildValue( "(O)", value );	/* the set* functions expect a tuple */ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( !valtuple ) | 
					
						
							|  |  |  | 		return EXPP_ReturnIntError( PyExc_MemoryError, | 
					
						
							|  |  |  | 					    "ActionSetAttr: couldn't create tuple" ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( strcmp( name, "name" ) == 0 ) | 
					
						
							|  |  |  | 		error = Action_setName( self, valtuple ); | 
					
						
							|  |  |  | 	else {			/* Error */ | 
					
						
							|  |  |  | 		Py_DECREF( valtuple ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		/* ... member with the given name was found */ | 
					
						
							|  |  |  | 		return ( EXPP_ReturnIntError | 
					
						
							|  |  |  | 			 ( PyExc_KeyError, "attribute not found" ) ); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_DECREF( valtuple ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( error != Py_None ) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	Py_DECREF( Py_None );	/* was incref'ed by the called Action_set* function */ | 
					
						
							|  |  |  | 	return 0;		/* normal exit */ | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | static PyObject *Action_repr( BPy_Action * self ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( self->action ) | 
					
						
							|  |  |  | 		return PyString_FromFormat( "[Action \"%s\"]", | 
					
						
							|  |  |  | 					    self->action->id.name + 2 ); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		return PyString_FromString( "NULL" ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | PyObject *Action_CreatePyObject( struct bAction * act ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_Action *blen_action; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	blen_action = | 
					
						
							|  |  |  | 		( BPy_Action * ) PyObject_NEW( BPy_Action, &Action_Type ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	if( blen_action == NULL ) { | 
					
						
							|  |  |  | 		return ( NULL ); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	blen_action->action = act; | 
					
						
							|  |  |  | 	return ( ( PyObject * ) blen_action ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | //-------------------------------------------------------------------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | int Action_CheckPyObject( PyObject * py_obj ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	return ( py_obj->ob_type == &Action_Type ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //----------------------------------------------------------------------
 | 
					
						
							|  |  |  | struct bAction *Action_FromPyObject( PyObject * py_obj ) | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	BPy_Action *blen_obj; | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	blen_obj = ( BPy_Action * ) py_obj; | 
					
						
							|  |  |  | 	return ( blen_obj->action ); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } |