| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2004-09-18 18:47:03 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-25 16:21:11 +00:00
										 |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | #include "Armature.h" //This must come first
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_main.h"
 | 
					
						
							|  |  |  | #include "BKE_global.h"
 | 
					
						
							|  |  |  | #include "BKE_armature.h"
 | 
					
						
							|  |  |  | #include "BKE_library.h"
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | #include "BKE_depsgraph.h"
 | 
					
						
							|  |  |  | #include "BKE_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2005-07-18 03:50:37 +00:00
										 |  |  | #include "BLI_blenlib.h"
 | 
					
						
							|  |  |  | #include "BLI_arithb.h"
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | #include "Bone.h"
 | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | #include "NLA.h"
 | 
					
						
							| 
									
										
										
										
											2004-03-31 07:40:08 +00:00
										 |  |  | #include "gen_utils.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | #include "DNA_object_types.h" //This must come before BIF_editarmature.h...
 | 
					
						
							|  |  |  | #include "BIF_editarmature.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 16:34:08 +00:00
										 |  |  | //------------------EXTERNAL PROTOTYPES--------------------
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | extern void make_boneList(ListBase* list, ListBase *bones, EditBone *parent); | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | extern void editbones_to_armature (ListBase *list, Object *ob); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //------------------------ERROR CODES---------------------------------
 | 
					
						
							|  |  |  | //This is here just to make me happy and to have more consistant error strings :)
 | 
					
						
							|  |  |  | static const char sBoneDictError[] = "ArmatureType.bones - Error: "; | 
					
						
							|  |  |  | static const char sBoneDictBadArgs[] = "ArmatureType.bones - Bad Arguments: "; | 
					
						
							|  |  |  | static const char sArmatureError[] = "ArmatureType - Error: "; | 
					
						
							|  |  |  | static const char sArmatureBadArgs[] = "ArmatureType - Bad Arguments: "; | 
					
						
							|  |  |  | static const char sModuleError[] = "Blender.Armature - Error: "; | 
					
						
							|  |  |  | static const char sModuleBadArgs[] = "Blender.Armature - Bad Arguments: "; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //################## BonesDict_Type (internal) ########################
 | 
					
						
							|  |  |  | /*This is an internal psuedo-dictionary type that allows for manipulation
 | 
					
						
							|  |  |  | * of bones inside of an armature. It is a subobject of armature. | 
					
						
							|  |  |  | * i.e. Armature.bones['key']*/ | 
					
						
							|  |  |  | //#####################################################################
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //------------------METHOD IMPLEMENTATIONS-----------------------------
 | 
					
						
							|  |  |  | //------------------------Armature.bones.items()
 | 
					
						
							|  |  |  | //Returns a list of key:value pairs like dict.items()
 | 
					
						
							| 
									
										
										
										
											2006-04-16 15:28:50 +00:00
										 |  |  | static PyObject* BonesDict_items(BPy_BonesDict *self) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (self->editmode_flag){ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return PyDict_Items(self->editbonesMap);  | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	}else{ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return PyDict_Items(self->bonesMap);  | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.bones.keys()
 | 
					
						
							|  |  |  | //Returns a list of keys like dict.keys()
 | 
					
						
							| 
									
										
										
										
											2006-04-16 15:28:50 +00:00
										 |  |  | static PyObject* BonesDict_keys(BPy_BonesDict *self) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (self->editmode_flag){ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return PyDict_Keys(self->editbonesMap); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	}else{ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return PyDict_Keys(self->bonesMap); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.bones.values()
 | 
					
						
							|  |  |  | //Returns a list of values like dict.values()
 | 
					
						
							| 
									
										
										
										
											2006-04-16 15:28:50 +00:00
										 |  |  | static PyObject* BonesDict_values(BPy_BonesDict *self) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (self->editmode_flag){ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return PyDict_Values(self->editbonesMap); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	}else{ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return PyDict_Values(self->bonesMap); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------ATTRIBUTE IMPLEMENTATION---------------------------
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | //------------------TYPE_OBECT IMPLEMENTATION-----------------------
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------tp_doc
 | 
					
						
							|  |  |  | //The __doc__ string for this object
 | 
					
						
							|  |  |  | static char BPy_BonesDict_doc[] = "This is an internal subobject of armature\
 | 
					
						
							|  |  |  | designed to act as a Py_Bone dictionary."; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //------------------------tp_methods
 | 
					
						
							|  |  |  | //This contains a list of all methods the object contains
 | 
					
						
							|  |  |  | static PyMethodDef BPy_BonesDict_methods[] = { | 
					
						
							|  |  |  | 	{"items", (PyCFunction) BonesDict_items, METH_NOARGS,  | 
					
						
							|  |  |  | 		"() - Returns the key:value pairs from the dictionary"}, | 
					
						
							|  |  |  | 	{"keys", (PyCFunction) BonesDict_keys, METH_NOARGS,  | 
					
						
							|  |  |  | 		"() - Returns the keys the dictionary"}, | 
					
						
							|  |  |  | 	{"values", (PyCFunction) BonesDict_values, METH_NOARGS,  | 
					
						
							|  |  |  | 		"() - Returns the values from the dictionary"}, | 
					
						
							| 
									
										
										
										
											2006-01-12 21:21:41 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2004-03-31 07:40:08 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | //-----------------(internal)
 | 
					
						
							|  |  |  | static int BoneMapping_Init(PyObject *dictionary, ListBase *bones){ | 
					
						
							|  |  |  | 	Bone *bone = NULL; | 
					
						
							|  |  |  | 	PyObject *py_bone = NULL; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	for (bone = bones->first; bone; bone = bone->next){ | 
					
						
							|  |  |  | 		py_bone = PyBone_FromBone(bone); | 
					
						
							|  |  |  | 		if (!py_bone) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		if(PyDict_SetItem(dictionary,  | 
					
						
							|  |  |  | 			PyString_FromString(bone->name), py_bone) == -1){ | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		Py_DECREF(py_bone); | 
					
						
							|  |  |  | 		if (bone->childbase.first)  | 
					
						
							|  |  |  | 			BoneMapping_Init(dictionary, &bone->childbase); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //-----------------(internal)
 | 
					
						
							|  |  |  | static int EditBoneMapping_Init(PyObject *dictionary, ListBase *editbones){ | 
					
						
							|  |  |  | 	EditBone *editbone = NULL; | 
					
						
							|  |  |  | 	PyObject *py_editbone = NULL; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	for (editbone = editbones->first; editbone; editbone = editbone->next){ | 
					
						
							|  |  |  | 		py_editbone = PyEditBone_FromEditBone(editbone); | 
					
						
							|  |  |  | 		if (!py_editbone) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		if(PyDict_SetItem(dictionary,  | 
					
						
							|  |  |  | 			PyString_FromString(editbone->name), py_editbone) == -1){ | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		Py_DECREF(py_editbone); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //----------------- BonesDict_InitBones
 | 
					
						
							|  |  |  | static int BonesDict_InitBones(BPy_BonesDict *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyDict_Clear(self->bonesMap); | 
					
						
							|  |  |  | 	if (BoneMapping_Init(self->bonesMap, self->bones) == -1) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | //----------------- BonesDict_InitEditBones
 | 
					
						
							|  |  |  | static int BonesDict_InitEditBones(BPy_BonesDict *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyDict_Clear(self->editbonesMap); | 
					
						
							|  |  |  | 	if (EditBoneMapping_Init(self->editbonesMap, &self->editbones) == -1) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------tp_repr
 | 
					
						
							|  |  |  | //This is the string representation of the object
 | 
					
						
							|  |  |  | static PyObject *BonesDict_repr(BPy_BonesDict *self) | 
					
						
							| 
									
										
										
										
											2004-04-05 04:17:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-07-14 14:48:45 +00:00
										 |  |  | 	char str[2048]; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	PyObject *key, *value; | 
					
						
							|  |  |  | 	int pos = 0; | 
					
						
							| 
									
										
										
										
											2005-12-23 22:16:33 +00:00
										 |  |  | 	char *p = str; | 
					
						
							| 
									
										
										
										
											2006-07-14 14:48:45 +00:00
										 |  |  | 	char *keys, *vals; | 
					
						
							| 
									
										
										
										
											2005-12-23 22:16:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	p += sprintf(str, "[Bone Dict: {"); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (self->editmode_flag){ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		while (PyDict_Next(self->editbonesMap, &pos, &key, &value)) { | 
					
						
							| 
									
										
										
										
											2006-07-14 14:48:45 +00:00
										 |  |  | 			keys = PyString_AsString(key); | 
					
						
							|  |  |  | 			vals = PyString_AsString(value->ob_type->tp_repr(value)); | 
					
						
							|  |  |  | 			if( strlen(str) + strlen(keys) + strlen(vals) < sizeof(str)-20 ) | 
					
						
							|  |  |  | 				p += sprintf(p, "%s : %s, ", keys, vals ); | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				p += sprintf(p, "...." ); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	}else{ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		while (PyDict_Next(self->bonesMap, &pos, &key, &value)) { | 
					
						
							| 
									
										
										
										
											2006-07-14 14:48:45 +00:00
										 |  |  | 			keys = PyString_AsString(key); | 
					
						
							|  |  |  | 			vals = PyString_AsString(value->ob_type->tp_repr(value)); | 
					
						
							|  |  |  | 			if( strlen(str) + strlen(keys) + strlen(vals) < sizeof(str)-20 ) | 
					
						
							|  |  |  | 				p += sprintf(p, "%s : %s, ", keys, vals ); | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				p += sprintf(p, "...." ); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-04-05 04:17:01 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-07-14 14:48:45 +00:00
										 |  |  | 	sprintf(p, "}]"); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return PyString_FromString(str); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------tp_dealloc
 | 
					
						
							|  |  |  | //This tells how to 'tear-down' our object when ref count hits 0
 | 
					
						
							|  |  |  | static void BonesDict_dealloc(BPy_BonesDict * self) | 
					
						
							| 
									
										
										
										
											2004-04-04 08:34:43 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	Py_DECREF(self->bonesMap); | 
					
						
							|  |  |  | 	Py_DECREF(self->editbonesMap); | 
					
						
							|  |  |  | 	BLI_freelistN(&self->editbones);  | 
					
						
							|  |  |  | 	BonesDict_Type.tp_free(self); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------mp_length
 | 
					
						
							|  |  |  | //This gets the size of the dictionary
 | 
					
						
							| 
									
										
										
										
											2006-04-16 15:28:50 +00:00
										 |  |  | static int BonesDict_len(BPy_BonesDict *self) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (self->editmode_flag){ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return BLI_countlist(&self->editbones); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	}else{ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return BLI_countlist(self->bones); | 
					
						
							| 
									
										
										
										
											2004-04-04 08:34:43 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //-----------------------mp_subscript
 | 
					
						
							|  |  |  | //This defines getting a bone from the dictionary - x = Bones['key']
 | 
					
						
							| 
									
										
										
										
											2006-04-16 15:28:50 +00:00
										 |  |  | static PyObject *BonesDict_GetItem(BPy_BonesDict *self, PyObject* key) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | {  | 
					
						
							|  |  |  | 	PyObject *value = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (self->editmode_flag){ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		value = PyDict_GetItem(self->editbonesMap, key); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	}else{ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		value = PyDict_GetItem(self->bonesMap, key); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-01-12 21:21:41 +00:00
										 |  |  | 	if(value == NULL){  /* item not found in dict. throw exception */ | 
					
						
							|  |  |  | 		char buffer[128]; | 
					
						
							|  |  |  | 		char* key_str; | 
					
						
							|  |  |  | 		key_str = PyString_AsString( key ); | 
					
						
							|  |  |  | 		if( !key_str ){  /* key not a py string */ | 
					
						
							|  |  |  | 			key_str = "";  /* use empty string for printing */ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  | 		PyOS_snprintf( buffer, sizeof(buffer), | 
					
						
							| 
									
										
										
										
											2006-01-14 19:05:33 +00:00
										 |  |  | 					   "bone %s not found", key_str); | 
					
						
							| 
									
										
										
										
											2006-01-12 21:21:41 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  |         return EXPP_ReturnPyObjError(PyExc_KeyError, buffer ); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return EXPP_incr_ret(value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //-----------------------mp_ass_subscript
 | 
					
						
							|  |  |  | //This does dict assignment - Bones['key'] = value
 | 
					
						
							| 
									
										
										
										
											2006-04-16 15:28:50 +00:00
										 |  |  | static int BonesDict_SetItem(BPy_BonesDict *self, PyObject *key, PyObject *value) | 
					
						
							| 
									
										
										
										
											2004-04-04 08:34:43 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	BPy_EditBone *editbone_for_deletion; | 
					
						
							|  |  |  | 	struct EditBone *editbone = NULL; | 
					
						
							|  |  |  | 	char *key_str = ""; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	if (self->editmode_flag){ | 
					
						
							|  |  |  | 		//Get the key name
 | 
					
						
							|  |  |  | 		if(key && PyString_Check(key)){ | 
					
						
							|  |  |  | 			key_str = PyString_AsString(key); | 
					
						
							|  |  |  | 		}else{ | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 			goto AttributeError; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		//parse value for assignment
 | 
					
						
							|  |  |  | 		if (value && EditBoneObject_Check(value)){ | 
					
						
							|  |  |  | 			//create a new editbone
 | 
					
						
							|  |  |  | 			editbone = MEM_callocN(sizeof(EditBone), "eBone"); | 
					
						
							|  |  |  | 			BLI_strncpy(editbone->name, key_str, 32); | 
					
						
							| 
									
										
										
										
											2007-01-16 09:18:01 +00:00
										 |  |  | 			unique_editbone_name(NULL, editbone->name); | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 			editbone->dist = ((BPy_EditBone*)value)->dist; | 
					
						
							|  |  |  | 			editbone->ease1 = ((BPy_EditBone*)value)->ease1; | 
					
						
							|  |  |  | 			editbone->ease2 = ((BPy_EditBone*)value)->ease2; | 
					
						
							|  |  |  | 			editbone->flag = ((BPy_EditBone*)value)->flag; | 
					
						
							|  |  |  | 			editbone->parent = ((BPy_EditBone*)value)->parent; | 
					
						
							|  |  |  | 			editbone->rad_head = ((BPy_EditBone*)value)->rad_head; | 
					
						
							|  |  |  | 			editbone->rad_tail = ((BPy_EditBone*)value)->rad_tail; | 
					
						
							|  |  |  | 			editbone->roll = ((BPy_EditBone*)value)->roll; | 
					
						
							|  |  |  | 			editbone->segments = ((BPy_EditBone*)value)->segments; | 
					
						
							|  |  |  | 			editbone->weight = ((BPy_EditBone*)value)->weight; | 
					
						
							|  |  |  | 			editbone->xwidth = ((BPy_EditBone*)value)->xwidth; | 
					
						
							|  |  |  | 			editbone->zwidth = ((BPy_EditBone*)value)->zwidth; | 
					
						
							|  |  |  | 			VECCOPY(editbone->head, ((BPy_EditBone*)value)->head); | 
					
						
							|  |  |  | 			VECCOPY(editbone->tail, ((BPy_EditBone*)value)->tail); | 
					
						
							| 
									
										
										
										
											2006-03-06 02:07:39 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			// FIXME, should be exposed via python. this avoids creating bones with no layers.
 | 
					
						
							|  |  |  | 			editbone->layer= 1; | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 			//set object pointer
 | 
					
						
							|  |  |  | 			((BPy_EditBone*)value)->editbone = editbone; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//fix the bone's head position if flags indicate that it is 'connected'
 | 
					
						
							|  |  |  | 			if (editbone->flag & BONE_CONNECTED){ | 
					
						
							|  |  |  | 				if(!editbone->parent){ | 
					
						
							|  |  |  | 					((BPy_EditBone*)value)->editbone = NULL; | 
					
						
							|  |  |  | 					MEM_freeN(editbone); | 
					
						
							|  |  |  | 					goto AttributeError3; | 
					
						
							|  |  |  | 				}else{ | 
					
						
							|  |  |  | 					VECCOPY(editbone->head, editbone->parent->tail); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//set in editbonelist
 | 
					
						
							|  |  |  | 			BLI_addtail(&self->editbones, editbone); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//set the new editbone in the mapping
 | 
					
						
							|  |  |  | 			if(PyDict_SetItemString(self->editbonesMap, key_str, value) == -1){ | 
					
						
							|  |  |  | 				((BPy_EditBone*)value)->editbone = NULL; | 
					
						
							|  |  |  | 				BLI_freelinkN(&self->editbones, editbone); | 
					
						
							|  |  |  | 				goto RuntimeError; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}else if(!value){ | 
					
						
							|  |  |  | 			//they are trying to delete the bone using 'del'
 | 
					
						
							|  |  |  | 			if(PyDict_GetItem(self->editbonesMap, key) != NULL){ | 
					
						
							|  |  |  | 				/*first kill the datastruct then remove the item from the dict
 | 
					
						
							|  |  |  | 				and wait for GC to pick it up. | 
					
						
							|  |  |  | 				We have to delete the datastruct here because the tp_dealloc | 
					
						
							|  |  |  | 				doesn't handle it*/ | 
					
						
							|  |  |  | 				editbone_for_deletion = (BPy_EditBone*)PyDict_GetItem(self->editbonesMap, key); | 
					
						
							|  |  |  | 				/*this is ugly but you have to set the parent to NULL for else 
 | 
					
						
							|  |  |  | 				editbones_to_armature will crash looking for this bone*/ | 
					
						
							|  |  |  | 				for (editbone = self->editbones.first; editbone; editbone = editbone->next){ | 
					
						
							| 
									
										
										
										
											2006-08-17 21:36:56 +00:00
										 |  |  | 					if (editbone->parent == editbone_for_deletion->editbone) { | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 						editbone->parent = NULL; | 
					
						
							| 
									
										
										
										
											2006-08-17 21:36:56 +00:00
										 |  |  | 						 /* remove the connected flag or else the 'root' ball
 | 
					
						
							|  |  |  | 						  * doesn't get drawn */ | 
					
						
							|  |  |  | 						editbone->flag &= ~BONE_CONNECTED; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				BLI_freelinkN(&self->editbones, editbone_for_deletion->editbone); | 
					
						
							|  |  |  | 				if(PyDict_DelItem(self->editbonesMap, key) == -1) | 
					
						
							|  |  |  | 					goto RuntimeError; | 
					
						
							|  |  |  | 			}else{ | 
					
						
							|  |  |  | 				goto KeyError; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	}else{ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		goto AttributeError2; | 
					
						
							| 
									
										
										
										
											2004-04-04 08:34:43 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | KeyError: | 
					
						
							|  |  |  | return EXPP_intError(PyExc_KeyError, "%s%s%s%s",  | 
					
						
							|  |  |  | 	    sBoneDictError,  "The key: ", key_str, " is not present in this dictionary!"); | 
					
						
							|  |  |  | RuntimeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_RuntimeError, "%s%s",  | 
					
						
							|  |  |  | 		sBoneDictError,  "Unable to access dictionary!"); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		sBoneDictBadArgs,  "Expects EditboneType Object"); | 
					
						
							|  |  |  | AttributeError2: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sBoneDictBadArgs,  "You must call makeEditable() first"); | 
					
						
							|  |  |  | AttributeError3: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sBoneDictBadArgs,  "The 'connected' flag is set but the bone has no parent!"); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-01-12 21:21:41 +00:00
										 |  |  | //------------------TYPE_OBJECT DEFINITION--------------------------
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //Mapping Protocol
 | 
					
						
							|  |  |  | static PyMappingMethods BonesDict_MapMethods = { | 
					
						
							|  |  |  | 	(inquiry) BonesDict_len,					//mp_length
 | 
					
						
							|  |  |  | 	(binaryfunc)BonesDict_GetItem,		//mp_subscript
 | 
					
						
							|  |  |  | 	(objobjargproc)BonesDict_SetItem,	//mp_ass_subscript
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | //BonesDict TypeObject
 | 
					
						
							|  |  |  | PyTypeObject BonesDict_Type = { | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	PyObject_HEAD_INIT(NULL)			//tp_head
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_internal
 | 
					
						
							|  |  |  | 	"BonesDict",								//tp_name
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	sizeof(BPy_BonesDict),					//tp_basicsize
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_itemsize
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	(destructor)BonesDict_dealloc,		//tp_dealloc
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_print
 | 
					
						
							|  |  |  | 	0,												//tp_getattr
 | 
					
						
							|  |  |  | 	0,												//tp_setattr
 | 
					
						
							|  |  |  | 	0,												//tp_compare
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	(reprfunc) BonesDict_repr,				//tp_repr
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_as_number
 | 
					
						
							|  |  |  | 	0,												//tp_as_sequence
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	&BonesDict_MapMethods,				//tp_as_mapping
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_hash
 | 
					
						
							|  |  |  | 	0,												//tp_call
 | 
					
						
							|  |  |  | 	0,												//tp_str
 | 
					
						
							|  |  |  | 	0,												//tp_getattro
 | 
					
						
							|  |  |  | 	0,												//tp_setattro
 | 
					
						
							|  |  |  | 	0,												//tp_as_buffer
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT,					//tp_flags
 | 
					
						
							|  |  |  | 	BPy_BonesDict_doc,						//tp_doc
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_traverse
 | 
					
						
							|  |  |  | 	0,												//tp_clear
 | 
					
						
							|  |  |  | 	0,												//tp_richcompare
 | 
					
						
							|  |  |  | 	0,												//tp_weaklistoffset
 | 
					
						
							|  |  |  | 	0,												//tp_iter
 | 
					
						
							|  |  |  | 	0,												//tp_iternext
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	BPy_BonesDict_methods,				//tp_methods
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_members
 | 
					
						
							|  |  |  | 	0,												//tp_getset
 | 
					
						
							|  |  |  | 	0,												//tp_base
 | 
					
						
							|  |  |  | 	0,												//tp_dict
 | 
					
						
							|  |  |  | 	0,												//tp_descr_get
 | 
					
						
							|  |  |  | 	0,												//tp_descr_set
 | 
					
						
							|  |  |  | 	0,												//tp_dictoffset
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	0, 				                                //tp_init
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_alloc
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	0,												//tp_new
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,												//tp_free
 | 
					
						
							|  |  |  | 	0,												//tp_is_gc
 | 
					
						
							|  |  |  | 	0,												//tp_bases
 | 
					
						
							|  |  |  | 	0,												//tp_mro
 | 
					
						
							|  |  |  | 	0,												//tp_cache
 | 
					
						
							|  |  |  | 	0,												//tp_subclasses
 | 
					
						
							|  |  |  | 	0,												//tp_weaklist
 | 
					
						
							|  |  |  | 	0												//tp_del
 | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | //-----------------------PyBonesDict_FromPyArmature
 | 
					
						
							|  |  |  | static PyObject *PyBonesDict_FromPyArmature(BPy_Armature *py_armature) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BPy_BonesDict *py_BonesDict = NULL; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	//create py object
 | 
					
						
							|  |  |  | 	py_BonesDict = (BPy_BonesDict *)BonesDict_Type.tp_alloc(&BonesDict_Type, 0);  | 
					
						
							|  |  |  | 	if (!py_BonesDict) | 
					
						
							|  |  |  | 		goto RuntimeError; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	//create internal dictionaries
 | 
					
						
							|  |  |  | 	py_BonesDict->bonesMap = PyDict_New(); | 
					
						
							|  |  |  | 	py_BonesDict->editbonesMap = PyDict_New(); | 
					
						
							|  |  |  | 	if (!py_BonesDict->bonesMap || !py_BonesDict->editbonesMap) | 
					
						
							|  |  |  | 		goto RuntimeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//set listbase pointer
 | 
					
						
							|  |  |  | 	py_BonesDict->bones = &py_armature->armature->bonebase; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//now that everything is setup - init the mappings
 | 
					
						
							|  |  |  | 	if (!BonesDict_InitBones(py_BonesDict)) | 
					
						
							|  |  |  | 		goto RuntimeError; | 
					
						
							|  |  |  | 	if (!BonesDict_InitEditBones(py_BonesDict)) | 
					
						
							|  |  |  | 		goto RuntimeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//set editmode flag
 | 
					
						
							|  |  |  | 	py_BonesDict->editmode_flag = 0;  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (PyObject*)py_BonesDict; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | RuntimeError: | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	return EXPP_objError(PyExc_RuntimeError, "%s%s",  | 
					
						
							|  |  |  | 		sBoneDictError, "Failed to create class"); | 
					
						
							| 
									
										
										
										
											2004-04-19 06:57:41 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //######################### Armature_Type #############################
 | 
					
						
							|  |  |  | /*This type represents a thin wrapper around bArmature data types
 | 
					
						
							|  |  |  | * internal to blender. It contains the psuedo-dictionary BonesDict | 
					
						
							|  |  |  | * as an assistant in manipulating it's own bone collection*/ | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | //#################################################################
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //------------------METHOD IMPLEMENTATION------------------------------
 | 
					
						
							|  |  |  | //------------------------Armature.makeEditable()
 | 
					
						
							|  |  |  | static PyObject *Armature_makeEditable(BPy_Armature *self) | 
					
						
							| 
									
										
										
										
											2004-04-04 08:34:43 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	if (self->armature->flag & ARM_EDITMODE) | 
					
						
							|  |  |  | 		goto AttributeError; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	make_boneList(&self->Bones->editbones, self->Bones->bones, NULL); | 
					
						
							|  |  |  | 	if (!BonesDict_InitEditBones(self->Bones)) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	self->Bones->editmode_flag = 1; | 
					
						
							|  |  |  | 	return EXPP_incr_ret(Py_None); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_objError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "The armature cannot be placed manually in editmode before you call makeEditable()!"); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-08-15 11:24:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | //------------------------Armature.update()
 | 
					
						
							|  |  |  | //This is a bit ugly because you need an object link to do this
 | 
					
						
							|  |  |  | static PyObject *Armature_update(BPy_Armature *self) | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	Object *obj = NULL; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	for (obj = G.main->object.first; obj; obj = obj->id.next){ | 
					
						
							|  |  |  | 		if (obj->data == self->armature) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	if (obj){ | 
					
						
							|  |  |  | 		editbones_to_armature (&self->Bones->editbones, obj); | 
					
						
							|  |  |  | 		if (!BonesDict_InitBones(self->Bones)) | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		self->Bones->editmode_flag = 0; | 
					
						
							| 
									
										
										
										
											2006-01-04 15:07:15 +00:00
										 |  |  | 		BLI_freelistN(&self->Bones->editbones); | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	}else{ | 
					
						
							|  |  |  | 		goto AttributeError; | 
					
						
							| 
									
										
										
										
											2004-03-31 07:40:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return EXPP_incr_ret(Py_None); | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_objError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "The armature must be linked to an object before you can save changes!"); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-08-15 11:24:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //------------------------Armature.__copy__()
 | 
					
						
							|  |  |  | static PyObject *Armature_copy(BPy_Armature *self) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *py_armature = NULL; | 
					
						
							|  |  |  | 	bArmature *bl_armature; | 
					
						
							|  |  |  | 	bl_armature= copy_armature(self->armature); | 
					
						
							|  |  |  | 	bl_armature->id.us= 0; | 
					
						
							| 
									
										
										
										
											2007-02-21 23:14:01 +00:00
										 |  |  | 	py_armature= Armature_CreatePyObject( bl_armature ); | 
					
						
							| 
									
										
										
										
											2006-08-15 11:24:08 +00:00
										 |  |  | 	return py_armature; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------ATTRIBUTE IMPLEMENTATION---------------------------
 | 
					
						
							| 
									
										
										
										
											2005-11-21 22:21:46 +00:00
										 |  |  | //------------------------Armature.autoIK (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getAutoIK(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->flag & ARM_AUTO_IK) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:12:46 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 22:21:46 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:12:46 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 22:21:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.autoIK (setter)
 | 
					
						
							|  |  |  | static int Armature_setAutoIK(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->flag |= ARM_AUTO_IK; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->flag &= ~ARM_AUTO_IK; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-12-07 19:36:01 +00:00
										 |  |  | //------------------------Armature.layers (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getLayers(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int layers, bit = 0, val = 0; | 
					
						
							|  |  |  | 	PyObject *item = NULL, *laylist = PyList_New( 0 ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !laylist ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_MemoryError, | 
					
						
							|  |  |  | 			"couldn't create pylist!" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	layers = self->armature->layer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while( bit < 20 ) { | 
					
						
							|  |  |  | 		val = 1 << bit; | 
					
						
							|  |  |  | 		if( layers & val ) { | 
					
						
							|  |  |  | 			item = Py_BuildValue( "i", bit + 1 ); | 
					
						
							|  |  |  | 			PyList_Append( laylist, item ); | 
					
						
							|  |  |  | 			Py_DECREF( item ); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		bit++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return laylist; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.layer (setter)
 | 
					
						
							|  |  |  | static int Armature_setLayers(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyList_Check(value)){ | 
					
						
							|  |  |  | 			int layers = 0, len_list = 0; | 
					
						
							|  |  |  | 			int val; | 
					
						
							|  |  |  | 			PyObject *item = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			len_list = PyList_Size(value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if( len_list == 0 ) | 
					
						
							|  |  |  | 				return EXPP_ReturnIntError( PyExc_AttributeError, | 
					
						
							|  |  |  | 				  "list can't be empty, at least one layer must be set" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			while( len_list ) { | 
					
						
							|  |  |  | 				--len_list; | 
					
						
							|  |  |  | 				item = PyList_GetItem( value, len_list ); | 
					
						
							|  |  |  | 				if( !PyInt_Check( item ) ) | 
					
						
							|  |  |  | 					return EXPP_ReturnIntError( PyExc_AttributeError, | 
					
						
							|  |  |  | 							"list must contain only integer numbers" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				val = ( int ) PyInt_AsLong( item ); | 
					
						
							|  |  |  | 				if( val < 1 || val > 20 ) | 
					
						
							|  |  |  | 					return EXPP_ReturnIntError( PyExc_AttributeError, | 
					
						
							|  |  |  | 						  "layer values must be in the range [1, 20]" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				layers |= 1 << ( val - 1 ); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* update any bases pointing to our object */ | 
					
						
							| 
									
										
										
										
											2006-04-24 15:09:07 +00:00
										 |  |  | 			self->armature->layer = (short)layers; | 
					
						
							| 
									
										
										
										
											2005-12-07 19:36:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_ReturnIntError( PyExc_TypeError, | 
					
						
							|  |  |  | 			"expected a list of integers" ); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-12-17 02:16:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //------------------------Armature.users (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getUsers( BPy_Armature * self ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong( self->armature->id.us ); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //------------------------Armature.fakeUser (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getFakeUser( BPy_Armature * self ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->id.flag & LIB_FAKEUSER) | 
					
						
							|  |  |  | 		Py_RETURN_TRUE; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		Py_RETURN_FALSE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.fakeUser (setter)
 | 
					
						
							|  |  |  | static int Armature_setFakeUser( BPy_Armature * self, PyObject * value ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return SetIdFakeUser(&self->armature->id, value); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-21 22:21:46 +00:00
										 |  |  | //------------------------Armature.mirrorEdit (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getMirrorEdit(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->flag & ARM_MIRROR_EDIT) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 22:21:46 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 22:21:46 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.mirrorEdit (setter)
 | 
					
						
							|  |  |  | static int Armature_setMirrorEdit(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->flag |= ARM_MIRROR_EDIT; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->flag &= ~ARM_MIRROR_EDIT; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-21 21:26:09 +00:00
										 |  |  | //------------------------Armature.drawType (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getDrawType(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->drawtype == ARM_OCTA){ | 
					
						
							|  |  |  | 		return EXPP_GetModuleConstant("Blender.Armature", "OCTAHEDRON") ; | 
					
						
							|  |  |  | 	}else if (self->armature->drawtype == ARM_LINE){ | 
					
						
							|  |  |  | 		return EXPP_GetModuleConstant("Blender.Armature", "STICK") ; | 
					
						
							|  |  |  | 	}else if (self->armature->drawtype == ARM_B_BONE){ | 
					
						
							|  |  |  | 		return EXPP_GetModuleConstant("Blender.Armature", "BBONE") ; | 
					
						
							|  |  |  | 	}else if (self->armature->drawtype == ARM_ENVELOPE){ | 
					
						
							|  |  |  | 		return EXPP_GetModuleConstant("Blender.Armature", "ENVELOPE") ; | 
					
						
							|  |  |  | 	}else{ | 
					
						
							|  |  |  | 		goto RuntimeError; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RuntimeError: | 
					
						
							|  |  |  | 	return EXPP_objError(PyExc_RuntimeError, "%s%s%s",  | 
					
						
							|  |  |  | 		sArmatureError, "drawType: ", "Internal failure!"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.drawType (setter)
 | 
					
						
							|  |  |  | static int Armature_setDrawType(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *val = NULL, *name = NULL; | 
					
						
							|  |  |  | 	long numeric_value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(BPy_Constant_Check(value)){ | 
					
						
							|  |  |  | 			name = PyDict_GetItemString(((BPy_constant*)value)->dict, "name"); | 
					
						
							|  |  |  | 			if (!STREQ2(PyString_AsString(name), "OCTAHEDRON", "STICK") && | 
					
						
							|  |  |  | 				!STREQ2(PyString_AsString(name), "BBONE", "ENVELOPE")) | 
					
						
							|  |  |  | 				goto ValueError; | 
					
						
							|  |  |  | 			val = PyDict_GetItemString(((BPy_constant*)value)->dict, "value"); | 
					
						
							|  |  |  | 			if (PyInt_Check(val)){ | 
					
						
							|  |  |  | 				numeric_value = PyInt_AS_LONG(val); | 
					
						
							|  |  |  | 				self->armature->drawtype = (int)numeric_value; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects module constant"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ValueError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Argument must be the constant OCTAHEDRON, STICK, BBONE, or ENVELOPE"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-21 20:54:29 +00:00
										 |  |  | //------------------------Armature.ghostStep (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getStep(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong((long)self->armature->ghostsize); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.ghostStep (setter)
 | 
					
						
							|  |  |  | static int Armature_setStep(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long numerical_value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyInt_Check(value)){ | 
					
						
							|  |  |  | 			numerical_value = PyInt_AS_LONG(value); | 
					
						
							|  |  |  | 			if (numerical_value > 20.0f || numerical_value < 1.0f) | 
					
						
							|  |  |  | 				goto ValueError; | 
					
						
							|  |  |  | 			self->armature->ghostsize = (short)numerical_value; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects Integer"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ValueError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Argument must fall within 1-20"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.ghost (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getGhost(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyInt_FromLong((long)self->armature->ghostep); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.ghost (setter)
 | 
					
						
							|  |  |  | static int Armature_setGhost(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long numerical_value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyInt_Check(value)){ | 
					
						
							|  |  |  | 			numerical_value = PyInt_AS_LONG(value); | 
					
						
							|  |  |  | 			if (numerical_value > 30.0f || numerical_value < 0.0f) | 
					
						
							|  |  |  | 				goto ValueError; | 
					
						
							|  |  |  | 			self->armature->ghostep = (short)numerical_value; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects Integer"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ValueError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Argument must fall within 0-30"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.drawNames (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getDrawNames(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->flag & ARM_DRAWNAMES) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:54:29 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:54:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.drawNames (setter)
 | 
					
						
							|  |  |  | static int Armature_setDrawNames(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->flag |= ARM_DRAWNAMES; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->flag &= ~ARM_DRAWNAMES; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.drawAxes (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getDrawAxes(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->flag & ARM_DRAWAXES) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:54:29 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:54:29 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.drawAxes (setter)
 | 
					
						
							|  |  |  | static int Armature_setDrawAxes(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->flag |= ARM_DRAWAXES; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->flag &= ~ARM_DRAWAXES; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | //------------------------Armature.delayDeform (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getDelayDeform(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->flag & ARM_DELAYDEFORM) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.delayDeform (setter)
 | 
					
						
							|  |  |  | static int Armature_setDelayDeform(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->flag |= ARM_DELAYDEFORM; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->flag &= ~ARM_DELAYDEFORM; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.restPosition (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getRestPosition(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->flag & ARM_RESTPOS) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.restPosition (setter)
 | 
					
						
							|  |  |  | static int Armature_setRestPosition(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->flag |= ARM_RESTPOS; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->flag &= ~ARM_RESTPOS; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.envelopes (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getEnvelopes(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->deformflag & ARM_DEF_ENVELOPE) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.envelopes (setter)
 | 
					
						
							|  |  |  | static int Armature_setEnvelopes(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->deformflag |= ARM_DEF_ENVELOPE; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->deformflag &= ~ARM_DEF_ENVELOPE; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.vertexGroups (getter)
 | 
					
						
							|  |  |  | static PyObject *Armature_getVertexGroups(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (self->armature->deformflag & ARM_DEF_VGROUP) | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_True); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-11-22 19:23:26 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_False); | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | //------------------------Armature.vertexGroups (setter)
 | 
					
						
							|  |  |  | static int Armature_setVertexGroups(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyBool_Check(value)){ | 
					
						
							|  |  |  | 			if (value == Py_True){ | 
					
						
							|  |  |  | 				self->armature->deformflag |= ARM_DEF_VGROUP; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			}else if (value == Py_False){ | 
					
						
							|  |  |  | 				self->armature->deformflag &= ~ARM_DEF_VGROUP; | 
					
						
							|  |  |  | 				return 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	goto AttributeError; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects True or False"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------Armature.name (getter)
 | 
					
						
							|  |  |  | //Gets the name of the armature
 | 
					
						
							|  |  |  | static PyObject *Armature_getName(BPy_Armature *self, void *closure) | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  |     return PyString_FromString(self->armature->id.name +2); //*new*
 | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------Armature.name (setter)
 | 
					
						
							|  |  |  | //Sets the name of the armature
 | 
					
						
							|  |  |  | static int Armature_setName(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-12-27 05:04:20 +00:00
										 |  |  | 	char *name; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(value){ | 
					
						
							|  |  |  | 		if(PyString_Check(value)){ | 
					
						
							|  |  |  | 			name = PyString_AsString(value); | 
					
						
							| 
									
										
										
										
											2006-12-27 05:04:20 +00:00
										 |  |  | 			rename_id(&self->armature->id, name); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 			return 0;  | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	goto AttributeError; | 
					
						
							| 
									
										
										
										
											2004-04-04 08:34:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, "Expects string"); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-02-23 14:51:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //------------------------Armature.name (getter)
 | 
					
						
							|  |  |  | //Gets the name of the armature
 | 
					
						
							|  |  |  | static PyObject *Armature_getLib(BPy_Armature *self, void *closure) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return EXPP_GetIdLib((ID *)self->armature); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------Armature.bones (getter)
 | 
					
						
							|  |  |  | //Gets the name of the armature
 | 
					
						
							|  |  |  | static PyObject *Armature_getBoneDict(BPy_Armature *self, void *closure) | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  |     return EXPP_incr_ret((PyObject*)self->Bones); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------Armature.bones (setter)
 | 
					
						
							|  |  |  | //Sets the name of the armature
 | 
					
						
							|  |  |  | /*TODO*/ | 
					
						
							|  |  |  | /*Copy Bones through x = y*/ | 
					
						
							|  |  |  | static int Armature_setBoneDict(BPy_Armature *self, PyObject *value, void *closure) | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	goto AttributeError; | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s",  | 
					
						
							|  |  |  | 		sArmatureError, "You are not allowed to change the .Bones attribute"); | 
					
						
							| 
									
										
										
										
											2003-05-29 04:00:35 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------TYPE_OBECT IMPLEMENTATION--------------------------
 | 
					
						
							|  |  |  | //------------------------tp_doc
 | 
					
						
							|  |  |  | //The __doc__ string for this object
 | 
					
						
							|  |  |  | static char BPy_Armature_doc[] = "This object wraps a Blender Armature object."; | 
					
						
							|  |  |  | //------------------------tp_methods
 | 
					
						
							|  |  |  | //This contains a list of all methods the object contains
 | 
					
						
							|  |  |  | static PyMethodDef BPy_Armature_methods[] = { | 
					
						
							|  |  |  | 	{"makeEditable", (PyCFunction) Armature_makeEditable, METH_NOARGS,  | 
					
						
							|  |  |  | 		"() - Unlocks the ability to modify armature bones"}, | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	{"update", (PyCFunction) Armature_update, METH_NOARGS,  | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		"() - Rebuilds the armature based on changes to bones since the last call to makeEditable"}, | 
					
						
							| 
									
										
										
										
											2006-08-15 11:24:08 +00:00
										 |  |  | 	{"__copy__", (PyCFunction) Armature_copy, METH_NOARGS,  | 
					
						
							|  |  |  | 		"() - Return a copy of the armature."}, | 
					
						
							| 
									
										
										
										
											2006-01-12 21:21:41 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | //------------------------tp_getset
 | 
					
						
							|  |  |  | //This contains methods for attributes that require checking
 | 
					
						
							|  |  |  | static PyGetSetDef BPy_Armature_getset[] = { | 
					
						
							|  |  |  | 	{"name", (getter)Armature_getName, (setter)Armature_setName,  | 
					
						
							|  |  |  | 		"The armature's name", NULL}, | 
					
						
							| 
									
										
										
										
											2007-02-23 14:51:20 +00:00
										 |  |  | 	{"lib", (getter)Armature_getLib, (setter)NULL,  | 
					
						
							|  |  |  | 		"The armature's library or None", NULL}, | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	{"bones", (getter)Armature_getBoneDict, (setter)Armature_setBoneDict,  | 
					
						
							|  |  |  | 		"The armature's Bone dictionary", NULL}, | 
					
						
							| 
									
										
										
										
											2005-11-21 20:22:08 +00:00
										 |  |  | 	{"vertexGroups", (getter)Armature_getVertexGroups, (setter)Armature_setVertexGroups,  | 
					
						
							|  |  |  | 		"Enable/Disable vertex group defined deformation", NULL}, | 
					
						
							|  |  |  | 	{"envelopes", (getter)Armature_getEnvelopes, (setter)Armature_setEnvelopes,  | 
					
						
							|  |  |  | 		"Enable/Disable bone envelope defined deformation", NULL}, | 
					
						
							|  |  |  | 	{"restPosition", (getter)Armature_getRestPosition, (setter)Armature_setRestPosition,  | 
					
						
							|  |  |  | 		"Show armature rest position - disables posing", NULL}, | 
					
						
							|  |  |  | 	{"delayDeform", (getter)Armature_getDelayDeform, (setter)Armature_setDelayDeform,  | 
					
						
							|  |  |  | 		"Don't deform children when manipulating bones in pose mode", NULL}, | 
					
						
							| 
									
										
										
										
											2005-11-21 20:54:29 +00:00
										 |  |  | 	{"drawAxes", (getter)Armature_getDrawAxes, (setter)Armature_setDrawAxes,  | 
					
						
							|  |  |  | 		"Enable/Disable  drawing  the bone axes", NULL}, | 
					
						
							|  |  |  | 	{"drawNames", (getter)Armature_getDrawNames, (setter)Armature_setDrawNames,  | 
					
						
							|  |  |  | 		"Enable/Disable  drawing the bone names", NULL}, | 
					
						
							|  |  |  | 	{"ghost", (getter)Armature_getGhost, (setter)Armature_setGhost,  | 
					
						
							|  |  |  | 		"Draw a number of ghosts around the current frame for current Action", NULL}, | 
					
						
							|  |  |  | 	{"ghostStep", (getter)Armature_getStep, (setter)Armature_setStep,  | 
					
						
							|  |  |  | 		"The number of frames between ghost instances", NULL}, | 
					
						
							| 
									
										
										
										
											2005-11-21 21:26:09 +00:00
										 |  |  | 	{"drawType", (getter)Armature_getDrawType, (setter)Armature_setDrawType,  | 
					
						
							|  |  |  | 		"The type of drawing currently applied to the armature", NULL}, | 
					
						
							| 
									
										
										
										
											2005-11-21 22:21:46 +00:00
										 |  |  | 	{"mirrorEdit", (getter)Armature_getMirrorEdit, (setter)Armature_setMirrorEdit,  | 
					
						
							|  |  |  | 		"Enable/Disable X-axis mirrored editing", NULL}, | 
					
						
							|  |  |  | 	{"autoIK", (getter)Armature_getAutoIK, (setter)Armature_setAutoIK,  | 
					
						
							|  |  |  | 		"Adds temporal IK chains while grabbing bones", NULL}, | 
					
						
							| 
									
										
										
										
											2005-12-07 19:36:01 +00:00
										 |  |  | 	{"layers", (getter)Armature_getLayers, (setter)Armature_setLayers,  | 
					
						
							|  |  |  | 		"List of layers for the armature", NULL}, | 
					
						
							| 
									
										
										
										
											2006-12-17 02:16:29 +00:00
										 |  |  | 	{"users", (getter)Armature_getUsers, (setter)NULL,  | 
					
						
							|  |  |  | 		"The number of object users", NULL}, | 
					
						
							|  |  |  | 	{"fakeUser", (getter)Armature_getFakeUser, (setter)Armature_setFakeUser,  | 
					
						
							|  |  |  | 		"The fake user status of this object", NULL}, | 
					
						
							| 
									
										
										
										
											2006-04-16 15:28:50 +00:00
										 |  |  | 	{NULL, NULL, NULL, NULL, NULL} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | //------------------------tp_new
 | 
					
						
							|  |  |  | //This methods creates a new object (note it does not initialize it - only the building)
 | 
					
						
							|  |  |  | //This can be called through python by myObject.__new__() however, tp_init is not called
 | 
					
						
							|  |  |  | static PyObject *Armature_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	BPy_Armature *py_armature = NULL; | 
					
						
							|  |  |  | 	bArmature *bl_armature; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	bl_armature = add_armature(); | 
					
						
							|  |  |  | 	if(bl_armature) { | 
					
						
							|  |  |  | 		bl_armature->id.us = 0; // return count to 0 - add_armature() inc'd it 
 | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		py_armature = (BPy_Armature*)type->tp_alloc(type, 0); //*new*
 | 
					
						
							|  |  |  | 		if (py_armature == NULL) | 
					
						
							|  |  |  | 			goto RuntimeError; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		py_armature->armature = bl_armature; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		//create armature.bones
 | 
					
						
							|  |  |  | 		py_armature->Bones = (BPy_BonesDict*)PyBonesDict_FromPyArmature(py_armature); | 
					
						
							|  |  |  | 		if (!py_armature->Bones) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 			goto RuntimeError; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		goto RuntimeError; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return (PyObject*)py_armature;  | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | RuntimeError: | 
					
						
							|  |  |  | 	return EXPP_objError(PyExc_RuntimeError, "%s%s%s",  | 
					
						
							|  |  |  | 		sArmatureError, " __new__: ", "couldn't create Armature Data in Blender"); | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------tp_init
 | 
					
						
							|  |  |  | //This methods does initialization of the new object
 | 
					
						
							|  |  |  | //This method will get called in python by 'myObject(argument, keyword=value)'
 | 
					
						
							|  |  |  | //tp_new will be automatically called before this
 | 
					
						
							|  |  |  | static int Armature_init(BPy_Armature *self, PyObject *args, PyObject *kwds) | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	char buf[21]; | 
					
						
							|  |  |  | 	char *name = "myArmature"; | 
					
						
							|  |  |  | 	static char *kwlist[] = {"name", NULL}; | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	if(!PyArg_ParseTupleAndKeywords(args, kwds, "|s", kwlist, &name)){ | 
					
						
							|  |  |  | 		goto AttributeError; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	//rename the armature if a name is supplied
 | 
					
						
							|  |  |  | 	if(!BLI_streq(name, "myArmature")){ | 
					
						
							|  |  |  | 		PyOS_snprintf(buf, sizeof(buf), "%s", name); | 
					
						
							|  |  |  | 		rename_id(&self->armature->id, buf); | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_intError(PyExc_AttributeError, "%s%s%s",  | 
					
						
							|  |  |  | 		sArmatureBadArgs, " __init__: ", "Expects string(name)"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function:	Armature_compare						 */ | 
					
						
							|  |  |  | /* Description: This is a callback function for the BPy_Armature type. It	 */ | 
					
						
							|  |  |  | /*		compares two Armature_Type objects. Only the "==" and "!="  */ | 
					
						
							|  |  |  | /*		comparisons are meaninful. Returns 0 for equality and -1 if  */ | 
					
						
							|  |  |  | /*		they don't point to the same Blender Object struct.	 */ | 
					
						
							|  |  |  | /*		In Python it becomes 1 if they are equal, 0 otherwise.	 */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | static int Armature_compare( BPy_Armature * a, BPy_Armature * b ) | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | 	return ( a->armature == b->armature ) ? 0 : -1; | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------------tp_repr
 | 
					
						
							|  |  |  | //This is the string representation of the object
 | 
					
						
							|  |  |  | static PyObject *Armature_repr(BPy_Armature *self) | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return PyString_FromFormat( "[Armature: \"%s\"]", self->armature->id.name + 2 ); //*new*
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | //------------------------tp_dealloc
 | 
					
						
							|  |  |  | //This tells how to 'tear-down' our object when ref count hits 0
 | 
					
						
							|  |  |  | ///tp_dealloc
 | 
					
						
							|  |  |  | static void Armature_dealloc(BPy_Armature * self) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-01-25 15:19:28 +00:00
										 |  |  | 	if (self->weaklist != NULL) | 
					
						
							|  |  |  |         PyObject_ClearWeakRefs((PyObject *) self); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	Py_DECREF(self->Bones); | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	Armature_Type.tp_free(self); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return; | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //------------------TYPE_OBECT DEFINITION--------------------------
 | 
					
						
							|  |  |  | PyTypeObject Armature_Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(NULL)		//tp_head
 | 
					
						
							|  |  |  | 	0,								//tp_internal
 | 
					
						
							|  |  |  | 	"Armature",						//tp_name
 | 
					
						
							|  |  |  | 	sizeof(BPy_Armature),			//tp_basicsize
 | 
					
						
							|  |  |  | 	0,								//tp_itemsize
 | 
					
						
							|  |  |  | 	(destructor)Armature_dealloc,	//tp_dealloc
 | 
					
						
							|  |  |  | 	0,								//tp_print
 | 
					
						
							|  |  |  | 	0,								//tp_getattr
 | 
					
						
							|  |  |  | 	0,								//tp_setattr
 | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | 	(cmpfunc) Armature_compare,		//tp_compare
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	(reprfunc) Armature_repr,		//tp_repr
 | 
					
						
							|  |  |  | 	0,								//tp_as_number
 | 
					
						
							|  |  |  | 	0,								//tp_as_sequence
 | 
					
						
							|  |  |  | 	0,								//tp_as_mapping
 | 
					
						
							|  |  |  | 	0,								//tp_hash
 | 
					
						
							|  |  |  | 	0,								//tp_call
 | 
					
						
							|  |  |  | 	0,								//tp_str
 | 
					
						
							|  |  |  | 	0,								//tp_getattro
 | 
					
						
							|  |  |  | 	0,								//tp_setattro
 | 
					
						
							|  |  |  | 	0,								//tp_as_buffer
 | 
					
						
							| 
									
										
										
										
											2007-01-25 15:19:28 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT| Py_TPFLAGS_HAVE_WEAKREFS,				//tp_flags
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	BPy_Armature_doc,				//tp_doc
 | 
					
						
							|  |  |  | 	0,								//tp_traverse
 | 
					
						
							|  |  |  | 	0,								//tp_clear
 | 
					
						
							| 
									
										
										
										
											2006-10-06 16:48:28 +00:00
										 |  |  | 	0, 								//tp_richcompare
 | 
					
						
							| 
									
										
										
										
											2007-01-25 15:19:28 +00:00
										 |  |  | 	offsetof(BPy_Armature, weaklist),	//tp_weaklistoffset
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	0,								//tp_iter
 | 
					
						
							|  |  |  | 	0,								//tp_iternext
 | 
					
						
							|  |  |  | 	BPy_Armature_methods,			//tp_methods
 | 
					
						
							|  |  |  | 	0,								//tp_members
 | 
					
						
							|  |  |  | 	BPy_Armature_getset,			//tp_getset
 | 
					
						
							|  |  |  | 	0,								//tp_base
 | 
					
						
							|  |  |  | 	0,								//tp_dict
 | 
					
						
							|  |  |  | 	0,								//tp_descr_get
 | 
					
						
							|  |  |  | 	0,								//tp_descr_set
 | 
					
						
							|  |  |  | 	0,								//tp_dictoffset
 | 
					
						
							|  |  |  | 	(initproc)Armature_init,		//tp_init
 | 
					
						
							|  |  |  | 	0,								//tp_alloc
 | 
					
						
							|  |  |  | 	(newfunc)Armature_new,			//tp_new
 | 
					
						
							|  |  |  | 	0,								//tp_free
 | 
					
						
							|  |  |  | 	0,								//tp_is_gc
 | 
					
						
							|  |  |  | 	0,								//tp_bases
 | 
					
						
							|  |  |  | 	0,								//tp_mro
 | 
					
						
							|  |  |  | 	0,								//tp_cache
 | 
					
						
							|  |  |  | 	0,								//tp_subclasses
 | 
					
						
							|  |  |  | 	0,								//tp_weaklist
 | 
					
						
							|  |  |  | 	0								//tp_del
 | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //-------------------MODULE METHODS IMPLEMENTATION------------------------
 | 
					
						
							|  |  |  | //----------------Blender.Armature.Get()
 | 
					
						
							|  |  |  | /* This function will return a Py_Armature when a single string is passed
 | 
					
						
							|  |  |  | * or else it will return a {key:value} dictionary when mutliple strings are passed | 
					
						
							|  |  |  | * or it will return a {key:value} dictionary of all armatures when nothing is passed*/ | 
					
						
							|  |  |  | static PyObject *M_Armature_Get(PyObject * self, PyObject * args) | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	PyObject *seq = NULL, *item = NULL, *dict = NULL, *py_armature = NULL; | 
					
						
							|  |  |  | 	char *name = "", buffer[24]; | 
					
						
							|  |  |  | 	int size = 0, i; | 
					
						
							|  |  |  | 	void *data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//GET ARGUMENTS - () ('s') ('s',..) (['s',..]) are exceptable
 | 
					
						
							|  |  |  | 	size = PySequence_Length(args); | 
					
						
							|  |  |  | 	if (size == 1) { | 
					
						
							|  |  |  | 		seq = PySequence_GetItem(args, 0); //*new*
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		if (!seq) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 			goto RuntimeError; | 
					
						
							|  |  |  | 		if(!PyString_Check(seq)){ | 
					
						
							|  |  |  | 			if (PySequence_Check(seq)) { | 
					
						
							|  |  |  | 				size = PySequence_Length(seq); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				Py_DECREF(seq); | 
					
						
							|  |  |  | 				goto AttributeError; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		seq = EXPP_incr_ret(args); //*take ownership*
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	//'seq' should be a list, empty tuple or string - check list for strings
 | 
					
						
							|  |  |  | 	if(!PyString_Check(seq)){ | 
					
						
							|  |  |  | 		for(i = 0; i < size; i++){ | 
					
						
							|  |  |  | 			item = PySequence_GetItem(seq, i); //*new*
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 			if (!item) { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 				Py_DECREF(seq); | 
					
						
							|  |  |  | 				goto RuntimeError; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(!PyString_Check(item)){ | 
					
						
							|  |  |  | 				EXPP_decr2(item, seq); | 
					
						
							|  |  |  | 				goto AttributeError; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			Py_DECREF(item); | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	//GET ARMATURES
 | 
					
						
							|  |  |  | 	if(size != 1){ | 
					
						
							|  |  |  | 		dict = PyDict_New(); //*new*
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		if(!dict){ | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 			Py_DECREF(seq); | 
					
						
							|  |  |  | 			goto RuntimeError; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(size == 0){	//GET ALL ARMATURES
 | 
					
						
							| 
									
										
										
										
											2005-12-04 20:39:56 +00:00
										 |  |  | 			data = G.main->armature.first; //get the first data ID from the armature library
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 			while (data){ | 
					
						
							| 
									
										
										
										
											2007-02-21 23:14:01 +00:00
										 |  |  | 				py_armature = Armature_CreatePyObject(data); //*new*
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 				sprintf(buffer, "%s", ((bArmature*)data)->id.name +2); | 
					
						
							|  |  |  | 				if(PyDict_SetItemString(dict, buffer, py_armature) == -1){ //add to dictionary
 | 
					
						
							|  |  |  | 					EXPP_decr3(seq, dict, py_armature); | 
					
						
							|  |  |  | 					goto RuntimeError; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 				Py_DECREF(py_armature); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 				data = ((ID*)data)->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			Py_DECREF(seq); | 
					
						
							|  |  |  | 		}else{	//GET ARMATURE LIST
 | 
					
						
							|  |  |  | 			for (i = 0; i < size; i++) { | 
					
						
							|  |  |  | 				item = PySequence_GetItem(seq, i); //*new*
 | 
					
						
							|  |  |  | 				name = PyString_AsString(item); | 
					
						
							|  |  |  | 				Py_DECREF(item); | 
					
						
							|  |  |  | 				data = find_id("AR", name); //get data from library
 | 
					
						
							|  |  |  | 				if (data != NULL){ | 
					
						
							| 
									
										
										
										
											2007-02-21 23:14:01 +00:00
										 |  |  | 					py_armature = Armature_CreatePyObject(data); //*new*
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 					if(PyDict_SetItemString(dict, name, py_armature) == -1){ //add to dictionary
 | 
					
						
							|  |  |  | 						EXPP_decr3(seq, dict, py_armature); | 
					
						
							|  |  |  | 						goto RuntimeError; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 					Py_DECREF(py_armature); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 				}else{ | 
					
						
							|  |  |  | 					if(PyDict_SetItemString(dict, name, Py_None) == -1){ //add to dictionary
 | 
					
						
							|  |  |  | 						EXPP_decr2(seq, dict); | 
					
						
							|  |  |  | 						goto RuntimeError; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 					Py_DECREF(Py_None); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			Py_DECREF(seq); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		return dict; | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	}else{	//GET SINGLE ARMATURE
 | 
					
						
							|  |  |  | 		if(!PyString_Check(seq)){ //This handles the bizarre case where (['s']) is passed
 | 
					
						
							|  |  |  | 			item = PySequence_GetItem(seq, 0); //*new*
 | 
					
						
							|  |  |  | 			name = PyString_AsString(item); | 
					
						
							|  |  |  | 			Py_DECREF(item); | 
					
						
							|  |  |  | 		}else{ | 
					
						
							|  |  |  | 			name = PyString_AsString(seq); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		Py_DECREF(seq); | 
					
						
							|  |  |  | 		data = find_id("AR", name); //get data from library
 | 
					
						
							|  |  |  | 		if (data != NULL){ | 
					
						
							| 
									
										
										
										
											2007-02-21 23:14:01 +00:00
										 |  |  | 			return Armature_CreatePyObject(data); //*new*
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		}else{ | 
					
						
							| 
									
										
										
										
											2006-12-22 21:23:27 +00:00
										 |  |  | 			char buffer[128]; | 
					
						
							|  |  |  | 			PyOS_snprintf( buffer, sizeof(buffer), | 
					
						
							|  |  |  | 						   "Armature \"%s\" not found", name); | 
					
						
							|  |  |  | 			return EXPP_ReturnPyObjError( PyExc_ValueError, | 
					
						
							|  |  |  | 										  buffer ); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | RuntimeError: | 
					
						
							|  |  |  | 	return EXPP_objError(PyExc_RuntimeError, "%s%s%s",  | 
					
						
							|  |  |  | 		sModuleError, "Get(): ", "Internal Error Ocurred"); | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | AttributeError: | 
					
						
							|  |  |  | 	return EXPP_objError(PyExc_AttributeError, "%s%s%s",  | 
					
						
							|  |  |  | 		sModuleBadArgs, "Get(): ", "- Expects (optional) string sequence"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-17 07:14:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | //----------------Blender.Armature.New()
 | 
					
						
							|  |  |  | static PyObject *M_Armature_New(PyObject * self, PyObject * args) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *name = "Armature"; | 
					
						
							|  |  |  | 	struct bArmature *armature; | 
					
						
							|  |  |  | 	BPy_Armature *obj; | 
					
						
							|  |  |  | 	char buf[21]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if( !PyArg_ParseTuple( args, "|s", &name ) ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_TypeError, | 
					
						
							|  |  |  | 					      "expected nothing or a string as argument" ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	armature= add_armature(); | 
					
						
							|  |  |  | 	armature->id.us = 0; | 
					
						
							| 
									
										
										
										
											2007-02-21 23:14:01 +00:00
										 |  |  | 	obj = (BPy_Armature *)Armature_CreatePyObject(armature); /*new*/ | 
					
						
							| 
									
										
										
										
											2006-08-17 07:14:29 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if( !obj ) | 
					
						
							|  |  |  | 		return EXPP_ReturnPyObjError( PyExc_RuntimeError, | 
					
						
							|  |  |  | 				       "PyObject_New() failed" );	 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	PyOS_snprintf( buf, sizeof( buf ), "%s", name ); | 
					
						
							|  |  |  | 	rename_id( &armature->id, buf ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	obj->armature = armature; | 
					
						
							|  |  |  | 	return (PyObject *)obj; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //-------------------MODULE METHODS DEFINITION-----------------------------
 | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | static char M_Armature_Get_doc[] = "(name) - return the armature with the name 'name', \
 | 
					
						
							|  |  |  |   returns None if not found.\n If 'name' is not specified, it returns a list of all \ | 
					
						
							|  |  |  |   armatures in the\ncurrent scene."; | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-17 07:14:29 +00:00
										 |  |  | static char M_Armature_New_doc[] = "(name) - return a new armature object."; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | struct PyMethodDef M_Armature_methods[] = { | 
					
						
							|  |  |  | 	{"Get", M_Armature_Get, METH_VARARGS, M_Armature_Get_doc}, | 
					
						
							| 
									
										
										
										
											2006-08-17 07:14:29 +00:00
										 |  |  | 	{"New", M_Armature_New, METH_VARARGS, M_Armature_New_doc}, | 
					
						
							| 
									
										
										
										
											2006-01-12 21:21:41 +00:00
										 |  |  | 	{NULL, NULL, 0, NULL} | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | //------------------VISIBLE PROTOTYPE IMPLEMENTATION-----------------------
 | 
					
						
							| 
									
										
										
										
											2007-01-25 15:19:28 +00:00
										 |  |  | //------------------------Armature_RebuildEditbones (internal)
 | 
					
						
							|  |  |  | PyObject * Armature_RebuildEditbones(PyObject *pyarmature) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Armature_makeEditable((BPy_Armature*)pyarmature); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | //------------------------Armature_RebuildBones (internal)
 | 
					
						
							|  |  |  | PyObject *Armature_RebuildBones(PyObject *pyarmature) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return Armature_update((BPy_Armature*)pyarmature); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //-----------------(internal)
 | 
					
						
							|  |  |  | //Converts a bArmature to a PyArmature
 | 
					
						
							| 
									
										
										
										
											2007-02-21 23:14:01 +00:00
										 |  |  | PyObject *Armature_CreatePyObject(struct bArmature *armature) | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	BPy_Armature *py_armature = NULL; | 
					
						
							| 
									
										
										
										
											2007-01-31 03:12:26 +00:00
										 |  |  | 	PyObject *maindict = NULL, *weakref = NULL; | 
					
						
							|  |  |  | 	PyObject *armlist = NULL;  /* list of armature weak refs */ | 
					
						
							|  |  |  | 	char *list_name = ARM_WEAKREF_LIST_NAME; | 
					
						
							| 
									
										
										
										
											2004-09-25 20:30:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	//create armature type
 | 
					
						
							| 
									
										
										
										
											2007-01-31 03:12:26 +00:00
										 |  |  | 	py_armature = (BPy_Armature*)Armature_Type.tp_alloc(&Armature_Type, 0); /*new*/ | 
					
						
							|  |  |  | 	if (!py_armature){ | 
					
						
							|  |  |  | 		printf("Oops - can't create py armature\n"); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		goto RuntimeError; | 
					
						
							| 
									
										
										
										
											2007-01-31 03:12:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	py_armature->weaklist = NULL; //init the weaklist
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	py_armature->armature = armature; | 
					
						
							| 
									
										
										
										
											2007-01-30 22:38:43 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	//create armature.bones
 | 
					
						
							|  |  |  | 	py_armature->Bones = (BPy_BonesDict*)PyBonesDict_FromPyArmature(py_armature); | 
					
						
							| 
									
										
										
										
											2007-01-31 03:12:26 +00:00
										 |  |  | 	if (!py_armature->Bones){ | 
					
						
							|  |  |  | 		printf("Oops - creating armature.bones\n"); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		goto RuntimeError; | 
					
						
							| 
									
										
										
										
											2007-01-31 03:12:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-25 15:19:28 +00:00
										 |  |  | 	//put a weakreference in __main__
 | 
					
						
							|  |  |  | 	maindict= PyModule_GetDict(PyImport_AddModule(	"__main__")); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-31 03:12:26 +00:00
										 |  |  | 	armlist = PyDict_GetItemString(maindict, list_name); | 
					
						
							|  |  |  | 	if( armlist){ | 
					
						
							|  |  |  | 		weakref = PyWeakref_NewProxy((PyObject*)py_armature, Py_None); | 
					
						
							|  |  |  | 		if (PyList_Append(armlist, weakref) == -1){ | 
					
						
							|  |  |  | 			printf("Oops - list-append failed\n"); | 
					
						
							|  |  |  | 			goto RuntimeError; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-01-30 22:38:43 +00:00
										 |  |  | 	return (PyObject *) py_armature; | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | RuntimeError: | 
					
						
							|  |  |  | 	return EXPP_objError(PyExc_RuntimeError, "%s%s%s",  | 
					
						
							| 
									
										
										
										
											2007-02-21 23:14:01 +00:00
										 |  |  | 		sModuleError, "Armature_CreatePyObject: ", "Internal Error Ocurred"); | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //-----------------(internal)
 | 
					
						
							|  |  |  | //Converts a PyArmature to a bArmature
 | 
					
						
							|  |  |  | struct bArmature *PyArmature_AsArmature(BPy_Armature *py_armature) | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	return (py_armature->armature); | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2007-01-22 11:26:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // This function returns true when the given PyObject
 | 
					
						
							|  |  |  | // is of the type Sound. Otherwise it will return false
 | 
					
						
							|  |  |  | int Armature_CheckPyObject( PyObject * pyobj ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return ( pyobj->ob_type == &Armature_Type); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct bArmature *Armature_FromPyObject( PyObject * py_obj ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return PyArmature_AsArmature((BPy_Armature*)py_obj); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | //-------------------MODULE INITIALIZATION--------------------------------
 | 
					
						
							|  |  |  | PyObject *Armature_Init(void) | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	PyObject *module, *dict; | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	//Initializes TypeObject.ob_type
 | 
					
						
							|  |  |  | 	if (PyType_Ready(&Armature_Type) < 0 ||	PyType_Ready(&BonesDict_Type) < 0 ||  | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 		PyType_Ready(&EditBone_Type) < 0 ||	PyType_Ready(&Bone_Type) < 0) { | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		return EXPP_incr_ret(Py_None); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	//Register the module
 | 
					
						
							|  |  |  | 	module = Py_InitModule3("Blender.Armature", M_Armature_methods,  | 
					
						
							|  |  |  | 		"The Blender Armature module");  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	//Add TYPEOBJECTS to the module
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	PyModule_AddObject(module, "Armature",  | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		EXPP_incr_ret((PyObject *)&Armature_Type)); //*steals*
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	PyModule_AddObject(module, "Bone",  | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 		EXPP_incr_ret((PyObject *)&Bone_Type)); //*steals*
 | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	PyModule_AddObject(module, "Editbone",  | 
					
						
							|  |  |  | 		EXPP_incr_ret((PyObject *)&EditBone_Type)); //*steals*
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//Add CONSTANTS to the module
 | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "CONNECTED",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("CONNECTED", BONE_CONNECTED))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "HINGE",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("HINGE", BONE_HINGE))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "NO_DEFORM",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("NO_DEFORM", BONE_NO_DEFORM))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "MULTIPLY",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("MULTIPLY", BONE_MULT_VG_ENV))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "HIDDEN_EDIT",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("HIDDEN_EDIT", BONE_HIDDEN_A))); | 
					
						
							| 
									
										
										
										
											2005-12-12 18:46:26 +00:00
										 |  |  | 	PyModule_AddObject(module, "ROOT_SELECTED",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("ROOT_SELECTED", BONE_ROOTSEL))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "BONE_SELECTED",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("BONE_SELECTED", BONE_SELECTED))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "TIP_SELECTED",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("TIP_SELECTED", BONE_TIPSEL))); | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-21 21:26:09 +00:00
										 |  |  | 	PyModule_AddObject(module, "OCTAHEDRON",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("OCTAHEDRON", ARM_OCTA))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "STICK",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("STICK", ARM_LINE))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "BBONE",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("BBONE", ARM_B_BONE))); | 
					
						
							|  |  |  | 	PyModule_AddObject(module, "ENVELOPE",  | 
					
						
							|  |  |  | 		EXPP_incr_ret(PyConstant_NewInt("ENVELOPE", ARM_ENVELOPE))); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-07 20:03:32 +00:00
										 |  |  | 	//Add SUBMODULES to the module
 | 
					
						
							|  |  |  | 	dict = PyModule_GetDict( module ); //borrowed
 | 
					
						
							|  |  |  | 	PyDict_SetItemString(dict, "NLA", NLA_Init()); //creates a *new* module
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return module; | 
					
						
							| 
									
										
										
										
											2004-05-11 08:26:44 +00:00
										 |  |  | } |