This was a problem with the BezTriple type.
Write access to BezTriple via 'pt' member did not work.

Preferred method to access BPy type members, especially for
write access, is via get*/set* methods.

BezTriple.setPoints() will accept x,y coordinates as either
a tuple or a list.

Updated BezTriple section of Ipo module doc.
This commit is contained in:
Stephen Swaney 2004-04-07 22:42:02 +00:00
parent a93a6966b7
commit 9cabf31ebc
2 changed files with 44 additions and 14 deletions

@ -1,5 +1,5 @@
/*
*
* $Id$
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
@ -206,27 +206,45 @@ BezTriple_setPoints (C_BezTriple * self, PyObject * args)
int i;
struct BezTriple *bezt = self->beztriple;
PyObject *popo = 0;
if (!PyArg_ParseTuple (args, "O", &popo))
return (EXPP_ReturnPyObjError
(PyExc_TypeError, "expected tuple argument"));
(PyExc_TypeError, "expected sequence argument"));
if (PySequence_Check (popo) == 0)
{
puts ("error in BezTriple_setPoints");
puts ("error in BezTriple_setPoints - expected sequence");
Py_INCREF (Py_None);
return Py_None;
}
{
/*
some debug stuff
this will become an overloaded args check
*/
int size = PySequence_Size (popo);
printf ("\n dbg: sequence size is %d\n", size);
}
for (i = 0; i < 2; i++)
{
PyObject *o = PySequence_GetItem( popo, i );
if( !o )
printf("\n bad o. o no!\n");
PyObject *o = PySequence_GetItem (popo, i);
if (!o)
printf ("\n bad o. o no!\n");
/* bezt->vec[1][i] = PyFloat_AsDouble (PyTuple_GetItem (popo, i));*/
bezt->vec[1][i] = PyFloat_AsDouble ( o );
/* bezt->vec[1][i] = PyFloat_AsDouble (PyTuple_GetItem (popo, i)); */
bezt->vec[1][i] = PyFloat_AsDouble (o);
bezt->vec[0][i] = bezt->vec[1][i] - 1;
bezt->vec[2][i] = bezt->vec[1][i] + 1;
}
/* experimental fussing with handles - ipo.c: calchandles_ipocurve */
if (bezt->vec[0][0] > bezt->vec[1][0])
bezt->vec[0][0] = bezt->vec[1][0];
if (bezt->vec[2][0] < bezt->vec[1][0])
bezt->vec[2][0] = bezt->vec[1][0];
Py_INCREF (Py_None);
return Py_None;
@ -259,9 +277,21 @@ BezTripleGetAttr (C_BezTriple * self, char *name)
static int
BezTripleSetAttr (C_BezTriple * self, char *name, PyObject * value)
{
#if 0
/*
this does not work at the moment: Wed Apr 7 2004
when the necessary code to make pt act like a sequence is
available, it will be reenabled
*/
if (strcmp (name, "pt") == 0)
BezTriple_setPoints (self, value);
return 0; /* normal exit */
#endif
return (EXPP_ReturnIntError (PyExc_AttributeError,
"cannot set a read-only attribute"));
}
/*****************************************************************************/

@ -260,22 +260,22 @@ class BezTriple:
"""
The BezTriple object
====================
This object gives access to generic data from all beztriple objects in Blender.
@cvar name: The Curve Data name.
@cvar bezierPoints : The list of the Bezier points.
This object gives access to generic data from all beztriple objects in Blender. If an attribute is listed as being 'read-only' that means you cannot write to it. Use the set*() methods instead.
@cvar pt : a list of the [x,y] coordinates for knot point of this BezTriple. read-only.
@cvar vec : a list of the 3 points [ handle, knot, handle ] that comprise a BezTriple. See the getTriple() method for an example of the format. read-only.
"""
def getPoints():
"""
Returns the xy coordinates of the Bezier point.
Returns the xy coordinates of the Bezier knot point.
@rtype: list of floats
@return: list of the x and y coordinates of the Bezier point.
"""
def setPoints(newval):
"""
Sets the point xy coordinates.
@type newval: tuple of (at least) 2 floats
Sets the point xy coordinates of the Bezier knot point.
@type newval: tuple of 2 floats
@param newval: the x and y coordinates of the new Bezier point.
@rtype: PyNone
@return: PyNone