Index: Bone.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Bone.c,v retrieving revision 1.22 diff -u -r1.22 Bone.c --- Bone.c 7 Oct 2004 19:25:39 -0000 1.22 +++ Bone.c 25 Oct 2004 15:02:56 -0000 @@ -81,7 +81,8 @@ static PyObject *Bone_hasParent( BPy_Bone * self ); static PyObject *Bone_getWeight( BPy_Bone * self ); static PyObject *Bone_getBoneclass( BPy_Bone * self ); -static PyObject *Bone_hasIK( BPy_Bone * self ); +static PyObject *Bone_hasIK( BPy_Bone * self ); // deprecated +static PyObject *Bone_getIK( BPy_Bone * self ); static PyObject *Bone_getChildren( BPy_Bone * self ); static PyObject *Bone_clearParent( BPy_Bone * self ); static PyObject *Bone_clearChildren( BPy_Bone * self ); @@ -99,6 +100,7 @@ static PyObject *Bone_setPose( BPy_Bone * self, PyObject * args ); static PyObject *Bone_setBoneclass( BPy_Bone * self, PyObject * args ); static PyObject *Bone_getRestMatrix( BPy_Bone * self, PyObject * args ); +static PyObject *Bone_setIK( BPy_Bone * self, PyObject * args ); //--------------- Python BPy_Bone methods table:-------------------------- static PyMethodDef BPy_Bone_methods[] = { @@ -124,7 +126,9 @@ "() - return Bone weight"}, {"getBoneclass", ( PyCFunction ) Bone_getBoneclass, METH_NOARGS, "() - return Bone boneclass"}, - {"hasIK", ( PyCFunction ) Bone_hasIK, METH_VARARGS, + {"hasIK", ( PyCFunction ) Bone_hasIK, METH_NOARGS, // deprecated + "() - get the Bone IKToParent flag."}, + {"getIK", ( PyCFunction ) Bone_getIK, METH_NOARGS, "() - get the Bone IKToParent flag."}, {"getParent", ( PyCFunction ) Bone_getParent, METH_NOARGS, "() - return the parent bone of this one if it exists." @@ -162,6 +166,8 @@ "() - set the Bone boneclass."}, {"getRestMatrix", ( PyCFunction ) Bone_getRestMatrix, METH_VARARGS, "() - return the rest matrix for this bone"}, + {"setIK", ( PyCFunction ) Bone_setIK, METH_VARARGS, + "() - set the Bone IKToParent flag."}, {NULL, NULL, 0, NULL} }; @@ -455,7 +461,7 @@ else if( strcmp( name, "boneclass" ) == 0 ) attr = Bone_getBoneclass( self ); else if( strcmp( name, "ik" ) == 0 ) - attr = Bone_hasIK( self ); + attr = Bone_getIK( self ); else if( strcmp( name, "__members__" ) == 0 ) { /* 9 entries */ attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s,s,s]", @@ -489,6 +495,8 @@ if( strcmp( name, "name" ) == 0 ) error = Bone_setName( self, valtuple ); + else if( strcmp( name, "ik" ) == 0 ) + error = Bone_setIK( self, valtuple ); else { /* Error */ Py_DECREF( valtuple ); @@ -1641,6 +1649,15 @@ //--------------- BPy_Bone.hasIK()------------------------------- static PyObject *Bone_hasIK( BPy_Bone * self ) { + PyErr_Warn( PyExc_DeprecationWarning, + "hasIK() is deprecated. Please use getIK() instead" ); + + return Bone_getIK( self ); +} + +//--------------- BPy_Bone.hasIK()------------------------------- +static PyObject *Bone_getIK( BPy_Bone * self ) +{ if( !self->bone ) { //test to see if linked to armature //use python vars if( self->flag & BONE_IK_TOPARENT ) { @@ -1662,6 +1679,70 @@ } return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, "couldn't get Bone.Boneclass attribute" ) ); +} + + +//--------------- BPy_Bone.setIK()------------------------------- +static PyObject *Bone_setIK( BPy_Bone * self, PyObject * args ) +{ + PyObject *attr = NULL; + int flag = -1; + + if( args && !PyArg_ParseTuple( args, "|i", &flag ) ) + return EXPP_ReturnPyObjError( PyExc_TypeError, + "expected an integer, 0 or 1" ); + + if( !self->bone ) { //test to see if linked to armature + //use python vars + + // has parent? + char *parent_str = ""; + if( !BLI_streq( self->parent, parent_str ) ) { + switch ( flag ) { + case 0: + self->flag &= ~BONE_IK_TOPARENT; + break; + case 1: + self->flag |= BONE_IK_TOPARENT; + + // adjust the bone's head + attr = Py_BuildValue( "(f,f,f)", 0.0f, 0.0f, 0.0f ); + Bone_setHead(self, attr); + + break; + default: + break; + } + } else { + PyErr_Warn( PyExc_Warning, "bone has no parent!" ); + } + + } else { + //use bone datastruct + + // has parent? + if( self->bone->parent ) { + switch ( flag ) { + case 0: + self->bone->flag &= ~BONE_IK_TOPARENT; + break; + case 1: + self->bone->flag |= BONE_IK_TOPARENT; + + // adjust the bone's head + attr = Py_BuildValue( "(f,f,f)", 0.0f, 0.0f, 0.0f ); + Bone_setHead(self, attr); + + break; + default: + break; + } + } else { + PyErr_Warn( PyExc_Warning, "Warning: bone has no parent!\n" ); + } + } + return EXPP_incr_ret( Py_None ); + } //--------------- BPy_Bone.getRestMatrix()-------------------------