diff options
author | Joseph Gilbert <ascotan@gmail.com> | 2006-01-13 18:27:23 +0300 |
---|---|---|
committer | Joseph Gilbert <ascotan@gmail.com> | 2006-01-13 18:27:23 +0300 |
commit | 2aa6d4fc1105197c3f153b6ec3bb73942aa6ad18 (patch) | |
tree | eb58b4791831d6d6f21e850ef4522bae2474178e /source/blender/python/api2_2x/Bone.c | |
parent | 1752c034416950cf94e3f973ffd26c4da2cd3ede (diff) |
*bone.children fix
- fixes bone.children to return direct bone children
- added bone.getAllChildren() to allow previous behavior
Diffstat (limited to 'source/blender/python/api2_2x/Bone.c')
-rw-r--r-- | source/blender/python/api2_2x/Bone.c | 77 |
1 files changed, 52 insertions, 25 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 |