added tipRadius and headRadius bone properties
authorCampbell Barton <ideasman42@gmail.com>
Sat, 26 Aug 2006 05:40:58 +0000 (05:40 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 26 Aug 2006 05:40:58 +0000 (05:40 +0000)
source/blender/python/api2_2x/Bone.c
source/blender/python/api2_2x/Bone.h
source/blender/python/api2_2x/doc/Armature.py

index c18beb17b081ee95b6c6dd8d4c7b777cda13ad63..bed859a5a78dc7a0ef8e16a06c46bf783b07a132 100644 (file)
@@ -639,6 +639,76 @@ static int EditBone_setLength(BPy_EditBone *self, PyObject *value, void *closure
        printf("Sorry this isn't implemented yet.... :/");
        return 1;
 }
+
+
+//------------------------Bone.headRadius (get)
+static PyObject *EditBone_getHeadRadius(BPy_EditBone *self, void *closure)
+{
+       if (self->editbone)
+               if (self->editbone->parent && self->editbone->flag & BONE_CONNECTED)
+                       return PyFloat_FromDouble(self->editbone->parent->rad_tail);
+               else
+                       return PyFloat_FromDouble(self->editbone->rad_head);
+       else
+               if (self->parent && self->flag & BONE_CONNECTED)
+                       return PyFloat_FromDouble(self->parent->rad_tail);
+               else
+                       return PyFloat_FromDouble(self->rad_head);
+}
+//------------------------Bone.headRadius (set)
+static int EditBone_setHeadRadius(BPy_EditBone *self, PyObject *value, void *closure)
+{  
+       float radius;
+       if (!PyArg_Parse(value, "f", &radius))
+               goto AttributeError;
+       CLAMP(radius, 0.0f, 10000.0f);
+
+       if (self->editbone)
+               if (self->editbone->parent && self->editbone->flag & BONE_CONNECTED)
+                       self->editbone->parent->rad_tail= radius;
+               else
+                       self->editbone->rad_head= radius;
+       else
+               if (self->parent && self->flag & BONE_CONNECTED)
+                       self->parent->rad_tail= radius;
+               else
+                       self->rad_head= radius;
+       return 0;
+
+AttributeError:
+       return EXPP_intError(PyExc_AttributeError, "%s%s%s",
+               sEditBoneError, ".headRadius: ", "expects a float");
+}
+
+
+//------------------------Bone.tailRadius (get)
+static PyObject *EditBone_getTailRadius(BPy_EditBone *self, void *closure)
+{
+       if (self->editbone)
+               return PyFloat_FromDouble(self->editbone->rad_tail);
+       else
+               return PyFloat_FromDouble(self->rad_tail);
+}
+//------------------------Bone.tailRadius (set)
+static int EditBone_setTailRadius(BPy_EditBone *self, PyObject *value, void *closure)
+{  
+       float radius;
+       if (!PyArg_Parse(value, "f", &radius))
+               goto AttributeError;
+       CLAMP(radius, 0.0f, 10000.0f);
+
+       if (self->editbone)
+               self->editbone->rad_tail = radius;
+       else
+               self->rad_tail = radius;
+       return 0;
+
+AttributeError:
+       return EXPP_intError(PyExc_AttributeError, "%s%s%s",
+               sEditBoneError, ".tailRadius: ", "expects a float");
+}
+
+
 //------------------TYPE_OBECT IMPLEMENTATION--------------------------
 //------------------------tp_methods
 //This contains a list of all methods the object contains
@@ -674,6 +744,10 @@ static PyGetSetDef BPy_EditBone_getset[] = {
                "The parent bone of this bone", NULL},
        {"length", (getter)EditBone_getLength, (setter)EditBone_setLength, 
                "The length of this bone", NULL},
+       {"tailRadius", (getter)EditBone_getTailRadius, (setter)EditBone_setTailRadius, 
+               "Set the radius of this bones tip", NULL},
+       {"headRadius", (getter)EditBone_getHeadRadius, (setter)EditBone_setHeadRadius, 
+               "Set the radius of this bones head", NULL},
        {NULL, NULL, NULL, NULL,NULL}
 };
 
@@ -1056,6 +1130,56 @@ static int Bone_setLength(BPy_Bone *self, PyObject *value, void *closure)
   return EXPP_intError(PyExc_ValueError, "%s%s", 
                sBoneError, "You must first call .makeEditable() to edit the armature");
 }
+
+//------------------------Bone.headRadius (get)
+static PyObject *Bone_getHeadRadius(BPy_Bone *self, void *closure)
+{
+
+       if (self->bone->parent && self->bone->flag & BONE_CONNECTED)
+               return PyFloat_FromDouble(self->bone->parent->rad_tail);
+       else
+               return PyFloat_FromDouble(self->bone->rad_head);
+}
+//------------------------Bone.headRadius (set)
+static int Bone_setHeadRadius(BPy_Bone *self, PyObject *value, void *closure)
+{  
+       float radius;
+       if (!PyArg_Parse(value, "f", &radius))
+               goto AttributeError;
+       CLAMP(radius, 0.0f, 10000.0f);
+
+       if (self->bone->parent && self->bone->flag & BONE_CONNECTED)
+               self->bone->parent->rad_tail= radius;
+       else
+               self->bone->rad_head= radius;
+       return 0;
+
+AttributeError:
+       return EXPP_intError(PyExc_AttributeError, "%s%s%s",
+               sEditBoneError, ".headRadius: ", "expects a float");
+}
+
+//------------------------Bone.tailRadius (get)
+static PyObject *Bone_getTailRadius(BPy_Bone *self, void *closure)
+{
+       return PyFloat_FromDouble(self->bone->rad_tail);
+}
+
+//------------------------Bone.headRadius (set)
+static int Bone_setTailRadius(BPy_Bone *self, PyObject *value, void *closure)
+{  
+       float radius;
+       if (!PyArg_Parse(value, "f", &radius))
+               goto AttributeError;
+       CLAMP(radius, 0.0f, 10000.0f);
+       self->bone->rad_tail= radius;
+       return 0;
+
+AttributeError:
+       return EXPP_intError(PyExc_AttributeError, "%s%s%s",
+               sEditBoneError, ".headRadius: ", "expects a float");
+}
+
 //------------------TYPE_OBECT IMPLEMENTATION--------------------------
 //------------------------tp_methods
 //This contains a list of all methods the object contains
@@ -1095,6 +1219,10 @@ static PyGetSetDef BPy_Bone_getset[] = {
                "The child bones of this bone", NULL},
        {"length", (getter)Bone_getLength, (setter)Bone_setLength, 
                "The length of this bone", NULL},
+       {"tailRadius", (getter)Bone_getTailRadius, (setter)Bone_setTailRadius, 
+               "Set the radius of this bones tip", NULL},
+       {"headRadius", (getter)Bone_getHeadRadius, (setter)Bone_setHeadRadius, 
+               "Set the radius of this bones head", NULL},
        {NULL, NULL, NULL, NULL,NULL}
 };
 //------------------------tp_repr
index 8c10aeb307525aa7256b73a882c052c36a7457ef..c3f5de81714606d8f499a1943052172d22c09f2e 100644 (file)
 #include <Python.h>
 #include "DNA_armature_types.h"
 
-//-------------------TYPE CHECKS---------------------------------
+/*-------------------TYPE CHECKS---------------------------------*/
 #define BoneObject_Check(v) ((v)->ob_type == &Bone_Type)
 #define EditBoneObject_Check(v) ((v)->ob_type == &EditBone_Type)
-//-------------------TYPEOBJECT----------------------------------
+/*-------------------TYPEOBJECT----------------------------------*/
 extern PyTypeObject EditBone_Type;
 extern PyTypeObject Bone_Type;
-//-------------------STRUCT DEFINITION----------------------------
+/*-------------------STRUCT DEFINITION----------------------------*/
 
 typedef struct {
        PyObject_HEAD
@@ -66,7 +66,7 @@ typedef struct {
        float rad_tail;
        short segments;
 } BPy_EditBone;
-//-------------------VISIBLE PROTOTYPES-------------------------
+/*-------------------VISIBLE PROTOTYPES-------------------------*/
 PyObject *PyBone_FromBone(struct Bone *bone);
 struct Bone *PyBone_AsBone(BPy_Bone *py_Bone);
 PyObject *PyEditBone_FromBone(Bone *bone);
index 587cadd74ad1cb08a0f49afd59ce56492162ed45..791d18e2566aa0da031c65c61b5219e1842d7ab2 100644 (file)
@@ -277,6 +277,10 @@ class Bone:
   @type deformDist: Float
   @ivar length: The length of the bone. This cannot be set.
   @type length: Float
+  @ivar headRadius: The radius of this bones head (used for envalope bones)
+  @type headRadius: Float
+  @ivar tailRadius: The radius of this bones head (used for envalope bones)
+  @type tailRadius: Float
   """
 
   def hasParent():
@@ -334,6 +338,10 @@ class Editbone:
   @type deformDist: Float
   @ivar length: The length of the bone. This cannot be set.
   @type length: Float
+  @ivar headRadius: The radius of this bones head (used for envalope bones)
+  @type headRadius: Float
+  @ivar tailRadius: The radius of this bones head (used for envalope bones)
+  @type tailRadius: Float
   """
 
   def hasParent():