[Bf-committers] PythonAPI - IpoCurve.getName() for action-ipos

Anders Nilsson bf-committers@blender.org
02 Apr 2004 18:57:00 +0200


--=-AQC64DSB6dOPHMlrzZjQ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

This fix will make IpoCurve.getName() return curve-names for
action-IPO:s and not only object-IPO:s. I've seen action-names requested
for quite some time in the forums at blender.org so this justifies not
rewriting it fully to support all sort of IPO's but just object and
action.

Ideally someone should do a <char *get_curve_name(IpoCurve *curve)> that
does all the switching efficiently. That one might be used in more
places to obtain curve names.

Anders Nilsson (breakin)

--=-AQC64DSB6dOPHMlrzZjQ
Content-Disposition: attachment; filename=patch.txt
Content-Type: text/x-patch; name=patch.txt; charset=UTF-8
Content-Transfer-Encoding: 7bit

Index: source/blender/python/api2_2x/Ipocurve.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Ipocurve.c,v
retrieving revision 1.12
diff -u -r1.12 Ipocurve.c
--- source/blender/python/api2_2x/Ipocurve.c	29 Mar 2004 08:16:18 -0000	1.12
+++ source/blender/python/api2_2x/Ipocurve.c	2 Apr 2004 16:49:43 -0000
@@ -338,28 +338,51 @@
   return Py_None;
 }
 
-static PyObject *
-IpoCurve_getName (C_IpoCurve * self)
+static PyObject* IpoCurve_getName (C_IpoCurve *self)
 {
-  char *nametab[24] =
-    { "LocX", "LocY", "LocZ", "dLocX", "dLocY", "dLocZ", "RotX", "RotY",
-    "RotZ", "dRotX", "dRotY", "dRotZ", "SizeX", "SizeY", "SizeZ", "dSizeX",
-    "dSizeY",
-    "dSizeZ", "Layer", "Time", "ColR", "ColG", "ColB", "ColA"
-  };
-
-  if (self->ipocurve->blocktype != ID_OB)
-    return EXPP_ReturnPyObjError (PyExc_TypeError,
-				  "This function doesn't support this ipocurve type yet");
-
-  //      printf("IpoCurve_getName %d\n",self->ipocurve->vartype);
-  if (self->ipocurve->adrcode <= 0)
-    return PyString_FromString ("Index too small");
-  if (self->ipocurve->adrcode >= 25)
-    return PyString_FromString ("Index too big");
-
-  return PyString_FromString (nametab[self->ipocurve->adrcode - 1]);
+	const int objectType=self->ipocurve->blocktype;
+	const int trackType=self->ipocurve->adrcode;
+	
+	const char * ob_nametab[24] = {"LocX","LocY","LocZ","dLocX","dLocY","dLocZ",
+		"RotX","RotY","RotZ","dRotX","dRotY","dRotZ","SizeX","SizeY","SizeZ",
+		"dSizeX","dSizeY","dSizeZ","Layer","Time","ColR","ColG","ColB","ColA"};
+		
+	const char * ac_nametab[5] = {"QuatW", "QuatX", "QuatY", "QuatZ","TotIpo"};
+	
+	switch (objectType) {
+	case ID_OB: {
+		if (self->ipocurve->adrcode <=0 ) {
+			return PyString_FromString("Index too small");
+		} else if (self->ipocurve->adrcode >= 25 ) {
+			return PyString_FromString("Index too big");
+		} else {	
+			return PyString_FromString(ob_nametab[trackType-1]);
+		}
+	}
+	break;
+	
+	case ID_AC: {
+		switch (trackType) {
+		case 1: case 2: case 3: case 13: case 14: case 15:
+			return PyString_FromString(ob_nametab[trackType-1]);
+		break;
+		
+		case 25: case 26: case 27: case 28:
+			return PyString_FromString(ac_nametab[trackType-25]);
+			break;
+		case 10:
+			return PyString_FromString(ac_nametab[4]);
+			break;
+		default:
+			return PyString_FromString("Index out of range");
+		}
+	}
+	break;
 
+	default:
+		return EXPP_ReturnPyObjError (PyExc_TypeError,
+		"This function doesn't support this ipocurve type yet");
+	}
 }
 
 

--=-AQC64DSB6dOPHMlrzZjQ--