From 2aa6d4fc1105197c3f153b6ec3bb73942aa6ad18 Mon Sep 17 00:00:00 2001 From: Joseph Gilbert Date: Fri, 13 Jan 2006 15:27:23 +0000 Subject: [PATCH] *bone.children fix - fixes bone.children to return direct bone children - added bone.getAllChildren() to allow previous behavior --- source/blender/python/api2_2x/Bone.c | 77 +++++++++++++------ source/blender/python/api2_2x/doc/Armature.py | 9 ++- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/source/blender/python/api2_2x/Bone.c b/source/blender/python/api2_2x/Bone.c index 04e7b16d978..95344e7a960 100644 --- a/source/blender/python/api2_2x/Bone.c +++ b/source/blender/python/api2_2x/Bone.c @@ -796,6 +796,28 @@ PyTypeObject EditBone_Type = { }; //------------------METHOD IMPLEMENTATIONS-------------------------------- +//------------------------(internal) PyBone_ChildrenAsList +static int PyBone_ChildrenAsList(PyObject *list, ListBase *bones){ + Bone *bone = NULL; + PyObject *py_bone = NULL; + + for (bone = bones->first; bone; bone = bone->next){ + py_bone = PyBone_FromBone(bone); + if (py_bone == NULL) + return 0; + + if(PyList_Append(list, py_bone) == -1){ + goto RuntimeError; + } + if (bone->childbase.first) + PyBone_ChildrenAsList(list, &bone->childbase); + } + return 1; + +RuntimeError: + return EXPP_intError(PyExc_RuntimeError, "%s%s", + sBoneError, "Internal error trying to wrap blender bones!"); +} //-------------------------Bone.hasParent() PyObject *Bone_hasParent(BPy_Bone *self) { @@ -812,6 +834,20 @@ PyObject *Bone_hasChildren(BPy_Bone *self) else return EXPP_incr_ret(Py_False); } +//-------------------------Bone.getAllChildren() +PyObject *Bone_getAllChildren(BPy_Bone *self) +{ + PyObject *list = NULL; + + if (self->bone->childbase.first){ + list = PyList_New(0); + if (!PyBone_ChildrenAsList(list, &self->bone->childbase)) + return NULL; + return EXPP_incr_ret(list); + }else{ + return EXPP_incr_ret(Py_None); + } +} //------------------ATTRIBUTE IMPLEMENTATIONS----------------------------- //------------------------Bone.name (get) static PyObject *Bone_getName(BPy_Bone *self, void *closure) @@ -965,42 +1001,31 @@ static int Bone_setParent(BPy_Bone *self, PyObject *value, void *closure) return EXPP_intError(PyExc_ValueError, "%s%s", sBoneError, "You must first call .makeEditable() to edit the armature"); } -//------------------------(internal) PyBone_ChildrenAsList -static int PyBone_ChildrenAsList(PyObject *list, ListBase *bones){ - Bone *bone = NULL; - PyObject *py_bone = NULL; - - for (bone = bones->first; bone; bone = bone->next){ - py_bone = PyBone_FromBone(bone); - if (py_bone == NULL) - return 0; - - if(PyList_Append(list, py_bone) == -1){ - goto RuntimeError; - } - if (bone->childbase.first) - PyBone_ChildrenAsList(list, &bone->childbase); - } - return 1; - -RuntimeError: - return EXPP_intError(PyExc_RuntimeError, "%s%s", - sBoneError, "Internal error trying to wrap blender bones!"); -} - //------------------------Bone.children (get) static PyObject *Bone_getChildren(BPy_Bone *self, void *closure) { PyObject *list = NULL; + Bone *bone = NULL; + PyObject *py_bone = NULL; if (self->bone->childbase.first){ list = PyList_New(0); - if (!PyBone_ChildrenAsList(list, &self->bone->childbase)) - return NULL; + for (bone = self->bone->childbase.first; bone; bone = bone->next){ + py_bone = PyBone_FromBone(bone); + if (py_bone == NULL) + return 0; + if(PyList_Append(list, py_bone) == -1){ + goto RuntimeError; + } + } return EXPP_incr_ret(list); }else{ return EXPP_incr_ret(Py_None); } + +RuntimeError: + return EXPP_objError(PyExc_RuntimeError, "%s%s", + sBoneError, "Internal error trying to wrap blender bones!"); } //------------------------Bone.children (set) static int Bone_setChildren(BPy_Bone *self, PyObject *value, void *closure) @@ -1040,6 +1065,8 @@ static PyMethodDef BPy_Bone_methods[] = { "() - True/False - Bone has a parent"}, {"hasChildren", (PyCFunction) Bone_hasChildren, METH_NOARGS, "() - True/False - Bone has 1 or more children"}, + {"getAllChildren", (PyCFunction) Bone_getAllChildren, METH_NOARGS, + "() - All the children for this bone - including children's children"}, {NULL} }; //------------------------tp_getset diff --git a/source/blender/python/api2_2x/doc/Armature.py b/source/blender/python/api2_2x/doc/Armature.py index 1be56121532..a8ce2e3c1eb 100644 --- a/source/blender/python/api2_2x/doc/Armature.py +++ b/source/blender/python/api2_2x/doc/Armature.py @@ -212,7 +212,7 @@ class Bone: @type matrix: Matrix Object @ivar parent: The parent Bone. @type parent: Bone Object - @ivar children: The children bones. + @ivar children: The children directly attached to this bone. @type children: List of Bone Objects @ivar weight: The bone's weight. @type weight: Float @@ -246,6 +246,13 @@ class Bone: @rtype: Bool """ + def getAllChildren(): + """ + Gets all the children under this bone including the children's children. + @rtype: List of Bone object + @return: all bones under this one + """ + class Editbone: """ The Editbone Object