Index: Object.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
retrieving revision 1.81
diff -u -b -r1.81 Object.c
--- Object.c	3 Jul 2004 05:17:01 -0000	1.81
+++ Object.c	19 Jul 2004 06:56:29 -0000
@@ -43,6 +43,7 @@
 #include <BKE_property.h>
 #include <BKE_mball.h>
 #include <BIF_editview.h>
+#include <stddef.h>
 
 
 /*****************************************************************************/
@@ -291,10 +292,10 @@
 /* PythonTypeObject callback function prototypes							 */
 /*****************************************************************************/
 static void		 Object_dealloc (BPy_Object *obj);
-static PyObject* Object_getAttr (BPy_Object *obj, char *name);
 static int		 Object_setAttr (BPy_Object *obj, char *name, PyObject *v);
 static PyObject* Object_repr	(BPy_Object *obj);
 static int		 Object_compare (BPy_Object *a, BPy_Object *b);
+static PyGetSetDef BPy_Object_getset[];
 
 /*****************************************************************************/
 /* Python TypeObject structure definition.									 */
@@ -309,7 +310,7 @@
   /* methods */
   (destructor)Object_dealloc,		/* tp_dealloc */
   0,								/* tp_print */
-  (getattrfunc)Object_getAttr,		/* tp_getattr */
+  NULL,		/* tp_getattr */
   (setattrfunc)Object_setAttr,		/* tp_setattr */
   (cmpfunc)Object_compare,			/* tp_compare */
   (reprfunc)Object_repr,			/* tp_repr */
@@ -322,6 +323,8 @@
   0,0,0,0,0,0,
   BPy_Object_methods,				/* tp_methods */
   0,								/* tp_members */
+  .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
+  .tp_getset = BPy_Object_getset,
 };
 
 /*****************************************************************************/
@@ -576,7 +579,8 @@
 {
 	PyObject	* module;
 
-	Object_Type.ob_type = &PyType_Type;
+	if (PyType_Ready(&Object_Type) < 0)
+		return NULL;
 
 	module = Py_InitModule3("Blender.Object", M_Object_methods, M_Object_doc);
 
@@ -1986,6 +1990,11 @@
 {
 	BPy_Object	  * blen_object;
 
+	if (obj == NULL)
+	{
+		return (NULL);
+	}
+
 	blen_object = (BPy_Object*)PyObject_NEW (BPy_Object, &Object_Type);
 
 	if (blen_object == NULL)
@@ -2055,138 +2064,64 @@
 	PyObject_DEL (obj);
 }
 
-/*****************************************************************************/
-/* Function:	Object_getAttr												 */
-/* Description: This is a callback function for the BlenObject type. It is	 */
-/*				the function that retrieves any value from Blender and		 */
-/*				passes it to Python.										 */
-/*****************************************************************************/
-static PyObject* Object_getAttr (BPy_Object *obj, char *name)
-{
-	struct Object	* object;
-	struct Ika		* ika;
+/* Attribute functions */
+#define OBJECT_ATTR_GET_AXIS(attr)					\
+static PyObject* Object_get_##attr(PyObject *self, void *axis_gen)	\
+{									\
+	BPy_Object *obj = (BPy_Object*) self;				\
+	int axis = axis_gen;						\
+	struct Object *object = obj->object;				\
+									\
+	return PyFloat_FromDouble(object->attr[axis]);			\
+}
+
+#define OBJECT_ATTR_GET3(attr)						\
+static PyObject* Object_get3_##attr(PyObject *self, void *unused)	\
+{									\
+	BPy_Object *obj = (BPy_Object*) self;				\
+	struct Object *object = obj->object;				\
+									\
+	return Py_BuildValue ("fff",					\
+	    object->attr[0], object->attr[1], object->attr[2]);		\
+}
+OBJECT_ATTR_GET_AXIS(loc)
+OBJECT_ATTR_GET_AXIS(dloc)
+OBJECT_ATTR_GET3(dloc)
+OBJECT_ATTR_GET_AXIS(rot)
+OBJECT_ATTR_GET3(rot)
+OBJECT_ATTR_GET_AXIS(drot)
+OBJECT_ATTR_GET3(drot)
+OBJECT_ATTR_GET_AXIS(size)
+OBJECT_ATTR_GET_AXIS(dsize)
+OBJECT_ATTR_GET3(dsize)
+#define OBJECT_ATTR_GET_INT(attr)					\
+static PyObject* Object_get_##attr(PyObject *self, void *unused)	\
+{									\
+	BPy_Object *obj = (BPy_Object*) self;				\
+	struct Object *object = obj->object;				\
+									\
+	return PyInt_FromLong(object->attr);				\
+}
+OBJECT_ATTR_GET_INT(lay)
+OBJECT_ATTR_GET_INT(colbits)
+static PyObject* Object_get_eff(PyObject *self, void *axis_gen)
+{
+	BPy_Object *obj = (BPy_Object*) self;
+	struct Object *object = obj->object;
+	int axis = (int)axis_gen;
 
-	object = obj->object;
-	if (StringEqual (name, "LocX"))
-		return (PyFloat_FromDouble(object->loc[0]));
-	if (StringEqual (name, "LocY"))
-		return (PyFloat_FromDouble(object->loc[1]));
-	if (StringEqual (name, "LocZ"))
-		return (PyFloat_FromDouble(object->loc[2]));
-	if (StringEqual (name, "loc"))
-		return (Py_BuildValue ("fff", object->loc[0], object->loc[1],
-							   object->loc[2]));
-	if (StringEqual (name, "dLocX"))
-		return (PyFloat_FromDouble(object->dloc[0]));
-	if (StringEqual (name, "dLocY"))
-		return (PyFloat_FromDouble(object->dloc[1]));
-	if (StringEqual (name, "dLocZ"))
-		return (PyFloat_FromDouble(object->dloc[2]));
-	if (StringEqual (name, "dloc"))
-		return (Py_BuildValue ("fff", object->dloc[0], object->dloc[1],
-							   object->dloc[2]));
-	if (StringEqual (name, "RotX"))
-		return (PyFloat_FromDouble(object->rot[0]));
-	if (StringEqual (name, "RotY"))
-		return (PyFloat_FromDouble(object->rot[1]));
-	if (StringEqual (name, "RotZ"))
-		return (PyFloat_FromDouble(object->rot[2]));
-	if (StringEqual (name, "rot"))
-		return (Py_BuildValue ("fff", object->rot[0], object->rot[1],
-							   object->rot[2]));
-	if (StringEqual (name, "dRotX"))
-		return (PyFloat_FromDouble(object->drot[0]));
-	if (StringEqual (name, "dRotY"))
-		return (PyFloat_FromDouble(object->drot[1]));
-	if (StringEqual (name, "dRotZ"))
-		return (PyFloat_FromDouble(object->drot[2]));
-	if (StringEqual (name, "drot"))
-		return (Py_BuildValue ("fff", object->drot[0], object->drot[1],
-							   object->drot[2]));
-	if (StringEqual (name, "SizeX"))
-		return (PyFloat_FromDouble(object->size[0]));
-	if (StringEqual (name, "SizeY"))
-		return (PyFloat_FromDouble(object->size[1]));
-	if (StringEqual (name, "SizeZ"))
-		return (PyFloat_FromDouble(object->size[2]));
-	if (StringEqual (name, "size"))
-		return (Py_BuildValue ("fff", object->size[0], object->size[1],
-							   object->size[2]));
-	if (StringEqual (name, "dSizeX"))
-		return (PyFloat_FromDouble(object->dsize[0]));
-	if (StringEqual (name, "dSizeY"))
-		return (PyFloat_FromDouble(object->dsize[1]));
-	if (StringEqual (name, "dSizeZ"))
-		return (PyFloat_FromDouble(object->dsize[2]));
-	if (StringEqual (name, "dsize"))
-		return (Py_BuildValue ("fff", object->dsize[0], object->dsize[1],
-							   object->dsize[2]));
-	if (strncmp (name,"Eff", 3) == 0)
-	{
 		if ( (object->type == OB_IKA) && (object->data != NULL) )
 		{
-			ika = object->data;
-			switch (name[3])
-			{
-				case 'X':
-					return (PyFloat_FromDouble (ika->effg[0]));
-				case 'Y':
-					return (PyFloat_FromDouble (ika->effg[1]));
-				case 'Z':
-					return (PyFloat_FromDouble (ika->effg[2]));
-				default:
-				/* Do we need to display a sensible error message here? */
-					return (NULL);
-			}
+		struct Ika *ika = object->data;
+		return (PyFloat_FromDouble (ika->effg[axis]));
 		}
-		return (NULL);
-	}
-	if (StringEqual (name, "Layer"))
-	  return (PyInt_FromLong(object->lay));
-	if (StringEqual (name, "parent"))
-	{
-		if (object->parent)
-			return (Object_CreatePyObject (object->parent));
 		else 
-	{
-	  Py_INCREF (Py_None);
-	  return (Py_None);
-	}
-	}
-
-	if (StringEqual (name, "track"))
-	  return (Object_CreatePyObject (object->track));
-	if (StringEqual (name, "data"))
-	  return (Object_getData (obj));
-	if (StringEqual (name, "ipo"))
-	{
-		if (object->ipo == NULL)
-		{
-			/* There's no ipo linked to the object, return Py_None. */
-			Py_INCREF (Py_None);
-			return (Py_None);
-		}
-		return (Ipo_CreatePyObject (object->ipo));
-	}
-	if (StringEqual (name, "mat") || StringEqual (name, "matrix"))
-		return (Object_getMatrix (obj, Py_BuildValue("(s)","localspace")));
-	if (StringEqual (name, "matrixWorld"))
-		return (Object_getMatrix (obj, Py_BuildValue("(s)","worldspace")));
-	if (StringEqual (name, "matrixLocal"))
-		return (Object_getMatrix (obj, Py_BuildValue("(s)","localspace")));
-	if (StringEqual (name, "colbits"))
-		return (Py_BuildValue ("h", object->colbits));
-	if (StringEqual (name, "drawType"))
-		return (Py_BuildValue ("b", object->dt));
-	if (StringEqual (name, "drawMode"))
-		return (Py_BuildValue ("b", object->dtx));
-	if (StringEqual (name, "name"))
-		return (Py_BuildValue ("s", object->id.name+2));
-	if (StringEqual (name, "sel"))
-		return (Object_isSelected (obj));
-  
-	/* not an attribute, search the methods table */
-	return Py_FindMethod(BPy_Object_methods, (PyObject *)obj, name);
+		return EXPP_incr_ret (Py_None);
+}
+static PyObject* Object_get_matrix(PyObject *self, void *which)
+{
+	BPy_Object *obj = (BPy_Object*) self;
+	return (Object_getMatrix (obj, Py_BuildValue("(s)",which)));
 }
 
 /*****************************************************************************/
@@ -2429,3 +2364,50 @@
 {
   return PyString_FromFormat("[Object \"%s\"]", self->object->id.name+2);
 }
+
+/* Moved this down here, as it's horribly tedious to copy prototypes */
+static PyGetSetDef BPy_Object_getset[] =
+{
+  {"LocX", Object_get_loc, NULL, "Location along X-axis", 0},
+  {"LocY", Object_get_loc, NULL, "Location along Y-axis", 1},
+  {"LocZ", Object_get_loc, NULL, "Location along Z-axis", 2},
+  {"loc", Object_getLocation, NULL, "Location [x,y,z]", NULL},
+  {"dLocX", Object_get_dloc, NULL, "Delta location along X-axis", 0},
+  {"dLocY", Object_get_dloc, NULL, "Delta location along Y-axis", 1},
+  {"dLocZ", Object_get_dloc, NULL, "Delta location along Z-axis", 2},
+  {"dloc", Object_get3_dloc, NULL, "Delta location [x,y,z]", NULL},
+  {"RotX", Object_get_rot, NULL, "Rotation around X-axis", 0},
+  {"RotY", Object_get_rot, NULL, "Rotation around Y-axis", 1},
+  {"RotZ", Object_get_rot, NULL, "Rotation around Z-axis", 2},
+  {"rot", Object_get3_rot, NULL, "Rotation [x,y,z]", NULL},
+  {"dRotX", Object_get_drot, NULL, "Delta rotation around X-axis", 0},
+  {"dRotY", Object_get_drot, NULL, "Delta rotation around Y-axis", 1},
+  {"dRotZ", Object_get_drot, NULL, "Delta rotation around Z-axis", 2},
+  {"drot", Object_get3_drot, NULL, "Delta rotation [x,y,z]", NULL},
+  {"SizeX", Object_get_size, NULL, "Scaling in X-axis", 0},
+  {"SizeY", Object_get_size, NULL, "Scaling in Y-axis", 1},
+  {"SizeZ", Object_get_size, NULL, "Scaling in Z-axis", 2},
+  {"size", Object_getSize, NULL, "Scaling [x,y,z]", NULL},
+  {"dSizeX", Object_get_dsize, NULL, "Delta scaling in X-axis", 0},
+  {"dSizeY", Object_get_dsize, NULL, "Delta scaling in Y-axis", 1},
+  {"dSizeZ", Object_get_dsize, NULL, "Delta scaling in Z-axis", 2},
+  {"dsize", Object_get3_dsize, NULL, "Delta scaling [x,y,z]", NULL},
+  {"EffX", Object_get_eff, NULL, "Effector for X-axis", 0},
+  {"EffY", Object_get_eff, NULL, "Effector for Y-axis", 1},
+  {"EffZ", Object_get_eff, NULL, "Effector for Z-axis", 2},
+  {"layer", Object_get_lay, NULL, "Object layers", NULL},
+  {"parent", Object_getParent, NULL, "parent Object", NULL},
+  {"track", Object_getTracked, NULL, "Object being tracked", NULL},
+  {"data", Object_getData, NULL, "ObData", NULL},
+  {"ipo", Object_getIpo, NULL, "Object Ipo", NULL},
+  {"mat", Object_get_matrix, NULL, "localspace matrix", "localspace"},
+  {"matrixLocal", Object_get_matrix, NULL, "localspace matrix", "localspace"},
+  {"matrixWorld", Object_get_matrix, NULL, "worldspace matrix", "worldspace"},
+  {"colbits", Object_get_colbits, NULL, "Bitmask for Object Materials vs Data Materials", NULL},
+  {"drawType", Object_getDrawType, NULL, "drawing type", NULL},
+  {"drawMode", Object_getDrawMode, NULL, "drawing mode", NULL},
+  {"name", Object_getName, NULL, "Object name", NULL},
+  {"sel", Object_isSelected, NULL, "whether object is selected", NULL},
+  {NULL}
+};
+
