*bone.children fix
authorJoseph Gilbert <ascotan@gmail.com>
Fri, 13 Jan 2006 15:27:23 +0000 (15:27 +0000)
committerJoseph Gilbert <ascotan@gmail.com>
Fri, 13 Jan 2006 15:27:23 +0000 (15:27 +0000)
- fixes bone.children to return direct bone children
- added bone.getAllChildren() to allow previous behavior

source/blender/python/api2_2x/Bone.c
source/blender/python/api2_2x/doc/Armature.py

index 04e7b16d978cb3f37ff9a097780d7511046a9c1b..95344e7a960936877b517a6ac57d5c0049e13ca8 100644 (file)
@@ -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
index 1be561215321418b336e2e4a2b55e12b647191f6..a8ce2e3c1ebaf775712aa7767d342ac78f789637 100644 (file)
@@ -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