* Small changes in many files:

-  Trying to fix linking problems in OSX;
-  Making module .Get functions behave like the ones in Blender 2.25 - 2.27
   (Guignot pointed the incompatibility);
-  Included more types to Blender.Types;
-  Found by luck and corrected two bugs that were making Blender crash;
-  Added/updated some simple functions.
This commit is contained in:
2003-06-12 04:51:50 +00:00
parent ed6885d728
commit 6cc45538ef
24 changed files with 579 additions and 479 deletions

View File

@@ -451,7 +451,7 @@ PyObject * RunPython(Text *text, PyObject *globaldict)
/*#ifdef BLENDER_SANDBOX_MODE /*#ifdef BLENDER_SANDBOX_MODE
// IGNORE THIS ALL FOR A WHILE, IT'S VERY INCOMPLETE AND WILL CHANGE // IGNORE THIS ALL FOR A WHILE, IT'S VERY INCOMPLETE AND WILL CHANGE
// CONSIDERABLY IN THE NEXT COMMIT. THE ifdef won't stay, either. // CONSIDERABLY, SOON. The #ifdef won't stay, either.
// The import statement is a security risk, so we don't allow it in // The import statement is a security risk, so we don't allow it in
// SANDBOX MODE. Instead, we import all needed modules ourselves and // SANDBOX MODE. Instead, we import all needed modules ourselves and

View File

@@ -94,7 +94,7 @@ static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
armature_iter = G.main->armature.first; armature_iter = G.main->armature.first;
/* Use the name to search for the armature requested. */ /* Use the name to search for the armature requested. */
if (name) { /* (name) - Search armature by name */ if (name) { /* (name) - Search armature by name */
wanted_armature = NULL; wanted_armature = NULL;
@@ -121,9 +121,9 @@ static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
else else
{ {
/* Return a list of all armatures in the scene */ /* Return a list of with armatures in the scene */
int index = 0; int index = 0;
PyObject *armlist, *pystr; PyObject *armlist, *pyobj;
armlist = PyList_New (BLI_countlist (&(G.main->armature))); armlist = PyList_New (BLI_countlist (&(G.main->armature)));
@@ -132,13 +132,13 @@ static PyObject *M_Armature_Get(PyObject *self, PyObject *args)
"couldn't create PyList")); "couldn't create PyList"));
while (armature_iter) { while (armature_iter) {
pystr = PyString_FromString (armature_iter->id.name+2); pyobj = M_ArmatureCreatePyObject (armature_iter);
if (!pystr) if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString")); "couldn't create PyString"));
PyList_SET_ITEM (armlist, index, pystr); PyList_SET_ITEM (armlist, index, pyobj);
armature_iter = armature_iter->id.next; armature_iter = armature_iter->id.next;
index++; index++;
@@ -345,12 +345,10 @@ static PyObject *ArmatureRepr (C_Armature *self)
/*****************************************************************************/ /*****************************************************************************/
static int ArmatureCmp (C_Armature *a, C_Armature *b) static int ArmatureCmp (C_Armature *a, C_Armature *b)
{ {
if (a<b) return -1; bArmature *pa = a->armature, *pb = b->armature;
else if (a==b) return 0; return (pa == pb) ? 0:-1;
else return 1;
} }
/*****************************************************************************/ /*****************************************************************************/
/* Function: M_ArmatureCreatePyObject */ /* Function: M_ArmatureCreatePyObject */
/* Description: This function will create a new BlenArmature from an */ /* Description: This function will create a new BlenArmature from an */

View File

@@ -137,7 +137,7 @@ static int ArmaturePrint (C_Armature *armature, FILE *fp, int flags);
/*****************************************************************************/ /*****************************************************************************/
/* Python TypeArmature structure definition: */ /* Python TypeArmature structure definition: */
/*****************************************************************************/ /*****************************************************************************/
static PyTypeObject Armature_Type = PyTypeObject Armature_Type =
{ {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /* ob_size */

View File

@@ -283,14 +283,14 @@ static int Buffer_ass_slice(PyObject *self, int begin, int end, PyObject *seq)
static void Buffer_dealloc(PyObject *self) static void Buffer_dealloc(PyObject *self)
{ {
Buffer *buf= (Buffer *) self; Buffer *buf = (Buffer *)self;
if (buf->parent) Py_DECREF(buf->parent); if (buf->parent) Py_DECREF (buf->parent);
else MEM_freeN(buf->buf.asvoid); else MEM_freeN (buf->buf.asvoid);
MEM_freeN(buf->dimensions); MEM_freeN (buf->dimensions);
PyMem_DEL(self); PyObject_DEL (self);
} }
static PyObject *Buffer_tolist(PyObject *self) static PyObject *Buffer_tolist(PyObject *self)

View File

@@ -138,7 +138,7 @@ static PyObject *Buffer_repr(PyObject *self);
PyTypeObject buffer_Type = { PyTypeObject buffer_Type = {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"Buffer", /*tp_name*/ "buffer", /*tp_name*/
sizeof(Buffer), /*tp_basicsize*/ sizeof(Buffer), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor) Buffer_dealloc, /*tp_dealloc*/ (destructor) Buffer_dealloc, /*tp_dealloc*/

View File

@@ -146,7 +146,7 @@ static int BonePrint (C_Bone *bone, FILE *fp, int flags);
/*****************************************************************************/ /*****************************************************************************/
/* Python TypeBone structure definition: */ /* Python TypeBone structure definition: */
/*****************************************************************************/ /*****************************************************************************/
static PyTypeObject Bone_Type = PyTypeObject Bone_Type =
{ {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /* ob_size */
@@ -680,9 +680,8 @@ static PyObject *BoneRepr (C_Bone *self)
/**************************************************************************/ /**************************************************************************/
static int BoneCmp (C_Bone *a, C_Bone *b) static int BoneCmp (C_Bone *a, C_Bone *b)
{ {
if (a<b) return -1; Bone *pa = a->bone, *pb = b->bone;
else if (a==b) return 0; return (pa == pb) ? 0:-1;
else return 1;
} }

View File

@@ -34,12 +34,6 @@
* \ingroup scripts * \ingroup scripts
* \brief Blender.Camera Module and Camera Data PyObject implementation. * \brief Blender.Camera Module and Camera Data PyObject implementation.
* *
* Note: Parameters between "<" and ">" are optional. But if one of them is
* given, all preceding ones must be given, too. Of course, this only relates
* to the Python functions and methods described here and only inside Python
* code. [ This will go to another file later, probably the main exppython
* doc file]. XXX Better: put optional args with their default value:
* (self, name = "MyName")
*/ */
#include <BKE_main.h> #include <BKE_main.h>
@@ -88,9 +82,12 @@ static PyObject *M_Camera_Get (PyObject *self, PyObject *args);
/* Blender.Camera.__doc__ */ /* Blender.Camera.__doc__ */
/*****************************************************************************/ /*****************************************************************************/
static char M_Camera_doc[] = static char M_Camera_doc[] =
"The Blender Camera module\n\n\ "The Blender Camera module\n\
This module provides access to **Camera Data** objects in Blender\n\n\ \n\
Example::\n\n\ This module provides access to **Camera Data** objects in Blender\n\
\n\
Example::\n\
\n\
from Blender import Camera, Object, Scene\n\ from Blender import Camera, Object, Scene\n\
c = Camera.New('ortho') # create new ortho camera data\n\ c = Camera.New('ortho') # create new ortho camera data\n\
c.lens = 35.0 # set lens value\n\ c.lens = 35.0 # set lens value\n\
@@ -101,14 +98,18 @@ Example::\n\n\
cur.setCurrentCamera(ob) # make this camera the active\n"; cur.setCurrentCamera(ob) # make this camera the active\n";
static char M_Camera_New_doc[] = static char M_Camera_New_doc[] =
"(type) - return a new Camera object of type \"type\", \ "Blender.Camera.New (type = 'persp', name = 'CamData'):\n\
which can be 'persp' or 'ortho'.\n\ \n\
() - return a new Camera object of type 'persp'."; (type) - Return a new Camera Data object of type \"type\",\n\
which can be 'persp' or 'ortho';\n\
() - Return a new Camera Data object of type 'persp'.";
static char M_Camera_Get_doc[] = static char M_Camera_Get_doc[] =
"(name) - return the camera with the name 'name', \ "Blender.Camera.Get (name = None):\n\
returns None if not found.\n If 'name' is not specified, \ \n\
it returns a list of all cameras in the\ncurrent scene."; (name) - Return the Camera Data object with the given 'name',\n\
None if not found;\n\
() - Return a list with all Camera Data objects in the current scene.";
/*****************************************************************************/ /*****************************************************************************/
/* Python method structure definition for Blender.Camera module: */ /* Python method structure definition for Blender.Camera module: */
@@ -120,6 +121,7 @@ struct PyMethodDef M_Camera_methods[] = {
{"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc}, {"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
{NULL, NULL, 0, NULL} {NULL, NULL, 0, NULL}
}; };
/*****************************************************************************/ /*****************************************************************************/
/* Python BPy_Camera methods declarations: */ /* Python BPy_Camera methods declarations: */
/*****************************************************************************/ /*****************************************************************************/
@@ -150,8 +152,8 @@ static PyMethodDef BPy_Camera_methods[] = {
{"getType", (PyCFunction)Camera_getType, METH_NOARGS, {"getType", (PyCFunction)Camera_getType, METH_NOARGS,
"() - Return Camera type - 'persp':0, 'ortho':1"}, "() - Return Camera type - 'persp':0, 'ortho':1"},
{"getMode", (PyCFunction)Camera_getMode, METH_NOARGS, {"getMode", (PyCFunction)Camera_getMode, METH_NOARGS,
"() - Return Camera mode flags (or'ed value) -\n\t" "() - Return Camera mode flags (or'ed value) -\n"
"'showLimits':1, 'showMist':2"}, " 'showLimits':1, 'showMist':2"},
{"getLens", (PyCFunction)Camera_getLens, METH_NOARGS, {"getLens", (PyCFunction)Camera_getLens, METH_NOARGS,
"() - Return Camera lens value"}, "() - Return Camera lens value"},
{"getClipStart", (PyCFunction)Camera_getClipStart, METH_NOARGS, {"getClipStart", (PyCFunction)Camera_getClipStart, METH_NOARGS,
@@ -161,19 +163,19 @@ static PyMethodDef BPy_Camera_methods[] = {
{"getDrawSize", (PyCFunction)Camera_getDrawSize, METH_NOARGS, {"getDrawSize", (PyCFunction)Camera_getDrawSize, METH_NOARGS,
"() - Return Camera draw size value"}, "() - Return Camera draw size value"},
{"setName", (PyCFunction)Camera_setName, METH_VARARGS, {"setName", (PyCFunction)Camera_setName, METH_VARARGS,
"(str) - Change Camera Data name"}, "(s) - Set Camera Data name"},
{"setType", (PyCFunction)Camera_setType, METH_VARARGS, {"setType", (PyCFunction)Camera_setType, METH_VARARGS,
"(str) - Change Camera type, which can be 'persp' or 'ortho'"}, "(s) - Set Camera type, which can be 'persp' or 'ortho'"},
{"setMode", (PyCFunction)Camera_setMode, METH_VARARGS, {"setMode", (PyCFunction)Camera_setMode, METH_VARARGS,
"([str[,str]]) - Set Camera mode flag(s): 'showLimits' and 'showMist'"}, "(<s<,s>>) - Set Camera mode flag(s): 'showLimits' and 'showMist'"},
{"setLens", (PyCFunction)Camera_setLens, METH_VARARGS, {"setLens", (PyCFunction)Camera_setLens, METH_VARARGS,
"(float) - Change Camera lens value"}, "(f) - Set Camera lens value"},
{"setClipStart", (PyCFunction)Camera_setClipStart, METH_VARARGS, {"setClipStart", (PyCFunction)Camera_setClipStart, METH_VARARGS,
"(float) - Change Camera clip start value"}, "(f) - Set Camera clip start value"},
{"setClipEnd", (PyCFunction)Camera_setClipEnd, METH_VARARGS, {"setClipEnd", (PyCFunction)Camera_setClipEnd, METH_VARARGS,
"(float) - Change Camera clip end value"}, "(f) - Set Camera clip end value"},
{"setDrawSize", (PyCFunction)Camera_setDrawSize, METH_VARARGS, {"setDrawSize", (PyCFunction)Camera_setDrawSize, METH_VARARGS,
"(float) - Change Camera draw size value"}, "(f) - Set Camera draw size value"},
{0} {0}
}; };
@@ -238,52 +240,50 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords)
char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */ char *type_str = "persp"; /* "persp" is type 0, "ortho" is type 1 */
char *name_str = "CamData"; char *name_str = "CamData";
static char *kwlist[] = {"type_str", "name_str", NULL}; static char *kwlist[] = {"type_str", "name_str", NULL};
BPy_Camera *pycam; /* for Camera Data object wrapper in Python */ PyObject *pycam; /* for Camera Data object wrapper in Python */
Camera *blcam; /* for actual Camera Data we create in Blender */ Camera *blcam; /* for actual Camera Data we create in Blender */
char buf[21]; char buf[21];
printf ("In Camera_New()\n"); printf ("In Camera_New()\n");
/* Parse the arguments passed in by the Python interpreter */
if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist, if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist,
&type_str, &name_str)) &type_str, &name_str))
/* We expected string(s) (or nothing) as argument, but we didn't get that. */ /* We expected string(s) (or nothing) as argument, but we didn't get that. */
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected zero, one or two strings as arguments")); "expected zero, one or two strings as arguments");
blcam = add_camera(); /* first create the Camera Data in Blender */ blcam = add_camera(); /* first create the Camera Data in Blender */
if (blcam) /* now create the wrapper obj in Python */ if (blcam) /* now create the wrapper obj in Python */
pycam = (BPy_Camera *)PyObject_NEW(BPy_Camera, &Camera_Type); pycam = Camera_CreatePyObject (blcam);
else else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Camera Data in Blender")); "couldn't create Camera Data in Blender");
/* let's return user count to zero, because ... */ /* let's return user count to zero, because ... */
blcam->id.us = 0; /* ... add_camera() right above incref'ed it */ blcam->id.us = 0; /* ... add_camera() incref'ed it */
/* XXX XXX Do this in other modules, too */ /* XXX XXX Do this in other modules, too */
if (pycam == NULL) if (pycam == NULL)
return (EXPP_ReturnPyObjError (PyExc_MemoryError, return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Camera Data object")); "couldn't create Camera PyObject");
pycam->camera = blcam; /* link Python camera wrapper to Blender Camera */
if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */ if (strcmp (type_str, "persp") == 0) /* default, no need to set, so */
/*blcam->type = (short)EXPP_CAM_TYPE_PERSP*/; /* we comment this line */ /*blcam->type = (short)EXPP_CAM_TYPE_PERSP*/; /* we comment this line */
else if (strcmp (type_str, "ortho") == 0) else if (strcmp (type_str, "ortho") == 0)
blcam->type = (short)EXPP_CAM_TYPE_ORTHO; blcam->type = (short)EXPP_CAM_TYPE_ORTHO;
else else
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return EXPP_ReturnPyObjError (PyExc_AttributeError,
"unknown camera type")); "unknown camera type");
if (strcmp(name_str, "CamData") == 0) if (strcmp (name_str, "CamData") == 0)
return (PyObject *)pycam; return pycam;
else { /* user gave us a name for the camera, use it */ else { /* user gave us a name for the camera, use it */
PyOS_snprintf(buf, sizeof(buf), "%s", name_str); PyOS_snprintf (buf, sizeof(buf), "%s", name_str);
rename_id(&blcam->id, buf); /* proper way in Blender */ rename_id (&blcam->id, buf); /* proper way in Blender */
} }
return (PyObject *)pycam; return pycam;
} }
/** /**
@@ -292,11 +292,11 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords)
* This is the .Get() function of the Blender.Camera submodule. It searches * This is the .Get() function of the Blender.Camera submodule. It searches
* the list of current Camera Data objects and returns a Python wrapper for * the list of current Camera Data objects and returns a Python wrapper for
* the one with the name provided by the user. If called with no arguments, * the one with the name provided by the user. If called with no arguments,
* it returns a list of all current Camera Data object names in Blender. * it returns a list with Python wrappers for all current Camera Data objects
* \param <name> - string: The name of an existing Blender Camera Data object.
* \return () - A list with the names of all current Camera Data objects;\n
* \return (name) - A Python wrapper for the Camera Data called 'name'
* in Blender. * in Blender.
* \param <name> - string: The name of an existing Blender Camera Data object.
* \return () - A list with wrappers for all current Camera Data objects;\n
* \return (name) - A wrapper for the Camera Data called 'name' in Blender.
*/ */
static PyObject *M_Camera_Get(PyObject *self, PyObject *args) static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
@@ -305,59 +305,62 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
Camera *cam_iter; Camera *cam_iter;
if (!PyArg_ParseTuple(args, "|s", &name)) if (!PyArg_ParseTuple(args, "|s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument (or nothing)")); "expected string argument (or nothing)");
cam_iter = G.main->camera.first; cam_iter = G.main->camera.first;
if (name) { /* (name) - Search camera by name */ if (name) { /* (name) - Search camera by name */
BPy_Camera *wanted_cam = NULL; PyObject *wanted_cam = NULL;
while (cam_iter && !wanted_cam) {
if (strcmp (name, cam_iter->id.name+2) == 0) {
wanted_cam = Camera_CreatePyObject (cam_iter);
break;
}
while ((cam_iter) && (wanted_cam == NULL)) {
if (strcmp (name, cam_iter->id.name+2) == 0) {
wanted_cam = (BPy_Camera *)PyObject_NEW(BPy_Camera, &Camera_Type);
if (wanted_cam) wanted_cam->camera = cam_iter;
}
cam_iter = cam_iter->id.next; cam_iter = cam_iter->id.next;
} }
if (wanted_cam == NULL) { /* Requested camera doesn't exist */ if (!wanted_cam) { /* Requested camera doesn't exist */
char error_msg[64]; char error_msg[64];
PyOS_snprintf(error_msg, sizeof(error_msg), PyOS_snprintf(error_msg, sizeof(error_msg),
"Camera \"%s\" not found", name); "Camera \"%s\" not found", name);
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); return EXPP_ReturnPyObjError (PyExc_NameError, error_msg);
} }
return (PyObject *)wanted_cam; return wanted_cam;
} }
else { /* () - return a list of all cameras in the scene */ else { /* () - return a list of wrappers for all cameras in the scene */
int index = 0; int index = 0;
PyObject *camlist, *pystr; PyObject *cam_pylist, *pyobj;
camlist = PyList_New (BLI_countlist (&(G.main->camera))); cam_pylist = PyList_New (BLI_countlist (&(G.main->camera)));
if (camlist == NULL) if (!cam_pylist)
return (PythonReturnErrorObject (PyExc_MemoryError, return PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList")); "couldn't create PyList");
while (cam_iter) { while (cam_iter) {
pystr = PyString_FromString (cam_iter->id.name+2); pyobj = Camera_CreatePyObject (cam_iter);
if (!pystr) if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError, return PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString")); "couldn't create Camera PyObject");
PyList_SET_ITEM (camlist, index, pystr); PyList_SET_ITEM (cam_pylist, index, pyobj);
cam_iter = cam_iter->id.next; cam_iter = cam_iter->id.next;
index++; index++;
} }
return (camlist); return cam_pylist;
} }
} }
/*@}*/ /*@}*/
/** /**
@@ -365,7 +368,7 @@ static PyObject *M_Camera_Get(PyObject *self, PyObject *args)
* *
* This function is used by Blender_Init() in Blender.c to register the * This function is used by Blender_Init() in Blender.c to register the
* Blender.Camera submodule in the main Blender module. * Blender.Camera submodule in the main Blender module.
* \return PyObject*: The initialized submodule. * \return The initialized submodule.
*/ */
PyObject *M_Camera_Init (void) PyObject *M_Camera_Init (void)
@@ -379,7 +382,7 @@ PyObject *M_Camera_Init (void)
submodule = Py_InitModule3("Blender.Camera", submodule = Py_InitModule3("Blender.Camera",
M_Camera_methods, M_Camera_doc); M_Camera_methods, M_Camera_doc);
return (submodule); return submodule;
} }
/* Three Python Camera_Type helper functions needed by the Object module: */ /* Three Python Camera_Type helper functions needed by the Object module: */
@@ -389,8 +392,8 @@ PyObject *M_Camera_Init (void)
* *
* This is also used in Object.c when defining the object.data member variable * This is also used in Object.c when defining the object.data member variable
* for an Object of type 'Camera'. * for an Object of type 'Camera'.
* \param cam - Camera*: A pointer to an existing Blender Camera Data object. * \param cam - A pointer to an existing Blender Camera Data object.
* \return PyObject*: The Camera Data wrapper created. * \return The Camera Data wrapper created.
*/ */
PyObject *Camera_CreatePyObject (Camera *cam) PyObject *Camera_CreatePyObject (Camera *cam)
@@ -401,7 +404,7 @@ PyObject *Camera_CreatePyObject (Camera *cam)
if (!pycam) if (!pycam)
return EXPP_ReturnPyObjError (PyExc_MemoryError, return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create BPy_Camera object"); "couldn't create BPy_Camera PyObject");
pycam->camera = cam; pycam->camera = cam;
@@ -413,8 +416,8 @@ PyObject *Camera_CreatePyObject (Camera *cam)
* *
* This is also used in Object.c when handling the object.data member variable * This is also used in Object.c when handling the object.data member variable
* for an object of type 'Camera'. * for an object of type 'Camera'.
* \param pyobj - PyObject*: A pointer to a Camera PyObject. * \param pyobj - A pointer to a Camera PyObject.
* \return int: True or false. * \return True or false.
*/ */
int Camera_CheckPyObject (PyObject *pyobj) int Camera_CheckPyObject (PyObject *pyobj)
@@ -427,8 +430,8 @@ int Camera_CheckPyObject (PyObject *pyobj)
* *
* This is also used in Object.c when handling the object.data member variable * This is also used in Object.c when handling the object.data member variable
* for an object of type 'Camera'. * for an object of type 'Camera'.
* \param pyobj - PyObject*: A pointer to a Camera PyObject. * \param pyobj - A pointer to a Camera PyObject.
* \return Camera*: A pointer to the wrapped Blender Camera Data object. * \return A pointer to the wrapped Blender Camera Data object.
*/ */
Camera *Camera_FromPyObject (PyObject *pyobj) Camera *Camera_FromPyObject (PyObject *pyobj)
@@ -461,8 +464,8 @@ static PyObject *Camera_getName(BPy_Camera *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.name attribute")); "couldn't get Camera.name attribute");
} }
/** /**
@@ -477,8 +480,8 @@ static PyObject *Camera_getType(BPy_Camera *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.type attribute")); "couldn't get Camera.type attribute");
} }
/** /**
@@ -493,8 +496,8 @@ static PyObject *Camera_getMode(BPy_Camera *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.Mode attribute")); "couldn't get Camera.Mode attribute");
} }
/** /**
@@ -509,8 +512,8 @@ static PyObject *Camera_getLens(BPy_Camera *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.lens attribute")); "couldn't get Camera.lens attribute");
} }
/** /**
@@ -525,8 +528,8 @@ static PyObject *Camera_getClipStart(BPy_Camera *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.clipStart attribute")); "couldn't get Camera.clipStart attribute");
} }
/** /**
@@ -540,8 +543,8 @@ static PyObject *Camera_getClipEnd(BPy_Camera *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.clipEnd attribute")); "couldn't get Camera.clipEnd attribute");
} }
/** /**
@@ -555,8 +558,8 @@ static PyObject *Camera_getDrawSize(BPy_Camera *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Camera.drawSize attribute")); "couldn't get Camera.drawSize attribute");
} }
/** /**
@@ -570,8 +573,8 @@ static PyObject *Camera_setName(BPy_Camera *self, PyObject *args)
char buf[21]; char buf[21];
if (!PyArg_ParseTuple(args, "s", &name)) if (!PyArg_ParseTuple(args, "s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument")); "expected string argument");
PyOS_snprintf(buf, sizeof(buf), "%s", name); PyOS_snprintf(buf, sizeof(buf), "%s", name);
@@ -591,16 +594,16 @@ static PyObject *Camera_setType(BPy_Camera *self, PyObject *args)
char *type; char *type;
if (!PyArg_ParseTuple(args, "s", &type)) if (!PyArg_ParseTuple(args, "s", &type))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument")); "expected string argument");
if (strcmp (type, "persp") == 0) if (strcmp (type, "persp") == 0)
self->camera->type = (short)EXPP_CAM_TYPE_PERSP; self->camera->type = (short)EXPP_CAM_TYPE_PERSP;
else if (strcmp (type, "ortho") == 0) else if (strcmp (type, "ortho") == 0)
self->camera->type = (short)EXPP_CAM_TYPE_ORTHO; self->camera->type = (short)EXPP_CAM_TYPE_ORTHO;
else else
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return EXPP_ReturnPyObjError (PyExc_AttributeError,
"unknown camera type")); "unknown camera type");
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -624,14 +627,14 @@ static PyObject *Camera_setIntType(BPy_Camera *self, PyObject *args)
short value; short value;
if (!PyArg_ParseTuple(args, "h", &value)) if (!PyArg_ParseTuple(args, "h", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument: 0 or 1")); "expected int argument: 0 or 1");
if (value == 0 || value == 1) if (value == 0 || value == 1)
self->camera->type = value; self->camera->type = value;
else else
return (EXPP_ReturnPyObjError (PyExc_ValueError, return EXPP_ReturnPyObjError (PyExc_ValueError,
"expected int argument: 0 or 1")); "expected int argument: 0 or 1");
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -654,8 +657,8 @@ static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args)
short flag = 0; short flag = 0;
if (!PyArg_ParseTuple(args, "|ss", &mode_str1, &mode_str2)) if (!PyArg_ParseTuple(args, "|ss", &mode_str1, &mode_str2))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected one or two strings as arguments")); "expected one or two strings as arguments");
if (mode_str1 != NULL) { if (mode_str1 != NULL) {
if (strcmp(mode_str1, "showLimits") == 0) if (strcmp(mode_str1, "showLimits") == 0)
@@ -663,8 +666,8 @@ static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args)
else if (strcmp(mode_str1, "showMist") == 0) else if (strcmp(mode_str1, "showMist") == 0)
flag |= (short)EXPP_CAM_MODE_SHOWMIST; flag |= (short)EXPP_CAM_MODE_SHOWMIST;
else else
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return EXPP_ReturnPyObjError (PyExc_AttributeError,
"first argument is an unknown camera flag")); "first argument is an unknown camera flag");
if (mode_str2 != NULL) { if (mode_str2 != NULL) {
if (strcmp(mode_str2, "showLimits") == 0) if (strcmp(mode_str2, "showLimits") == 0)
@@ -672,8 +675,8 @@ static PyObject *Camera_setMode(BPy_Camera *self, PyObject *args)
else if (strcmp(mode_str2, "showMist") == 0) else if (strcmp(mode_str2, "showMist") == 0)
flag |= (short)EXPP_CAM_MODE_SHOWMIST; flag |= (short)EXPP_CAM_MODE_SHOWMIST;
else else
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return EXPP_ReturnPyObjError (PyExc_AttributeError,
"second argument is an unknown camera flag")); "second argument is an unknown camera flag");
} }
} }
@@ -698,14 +701,14 @@ static PyObject *Camera_setIntMode(BPy_Camera *self, PyObject *args)
short value; short value;
if (!PyArg_ParseTuple(args, "h", &value)) if (!PyArg_ParseTuple(args, "h", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument in [0,3]")); "expected int argument in [0,3]");
if (value >= 0 && value <= 3) if (value >= 0 && value <= 3)
self->camera->flag = value; self->camera->flag = value;
else else
return (EXPP_ReturnPyObjError (PyExc_ValueError, return EXPP_ReturnPyObjError (PyExc_ValueError,
"expected int argument in [0,3]")); "expected int argument in [0,3]");
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -721,8 +724,8 @@ static PyObject *Camera_setLens(BPy_Camera *self, PyObject *args)
float value; float value;
if (!PyArg_ParseTuple(args, "f", &value)) if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument")); "expected float argument");
self->camera->lens = EXPP_ClampFloat (value, self->camera->lens = EXPP_ClampFloat (value,
EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX); EXPP_CAM_LENS_MIN, EXPP_CAM_LENS_MAX);
@@ -741,8 +744,8 @@ static PyObject *Camera_setClipStart(BPy_Camera *self, PyObject *args)
float value; float value;
if (!PyArg_ParseTuple(args, "f", &value)) if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument")); "expected float argument");
self->camera->clipsta = EXPP_ClampFloat (value, self->camera->clipsta = EXPP_ClampFloat (value,
EXPP_CAM_CLIPSTART_MIN, EXPP_CAM_CLIPSTART_MAX); EXPP_CAM_CLIPSTART_MIN, EXPP_CAM_CLIPSTART_MAX);
@@ -761,8 +764,8 @@ static PyObject *Camera_setClipEnd(BPy_Camera *self, PyObject *args)
float value; float value;
if (!PyArg_ParseTuple(args, "f", &value)) if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected float argument")); "expected float argument");
self->camera->clipend = EXPP_ClampFloat (value, self->camera->clipend = EXPP_ClampFloat (value,
EXPP_CAM_CLIPEND_MIN, EXPP_CAM_CLIPEND_MAX); EXPP_CAM_CLIPEND_MIN, EXPP_CAM_CLIPEND_MAX);
@@ -781,8 +784,8 @@ static PyObject *Camera_setDrawSize(BPy_Camera *self, PyObject *args)
float value; float value;
if (!PyArg_ParseTuple(args, "f", &value)) if (!PyArg_ParseTuple(args, "f", &value))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return EXPP_ReturnPyObjError (PyExc_TypeError,
"expected a float number as argument")); "expected a float number as argument");
self->camera->drawsize = EXPP_ClampFloat (value, self->camera->drawsize = EXPP_ClampFloat (value,
EXPP_CAM_DRAWSIZE_MIN, EXPP_CAM_DRAWSIZE_MAX); EXPP_CAM_DRAWSIZE_MIN, EXPP_CAM_DRAWSIZE_MAX);
@@ -854,8 +857,8 @@ static PyObject *Camera_GetAttr (BPy_Camera *self, char *name)
} }
if (!attr) if (!attr)
return (EXPP_ReturnPyObjError (PyExc_MemoryError, return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create PyObject")); "couldn't create PyObject");
if (attr != Py_None) return attr; /* member attribute found, return it */ if (attr != Py_None) return attr; /* member attribute found, return it */
@@ -909,23 +912,23 @@ static int Camera_SetAttr (BPy_Camera *self, char *name, PyObject *value)
if ((strcmp (name, "Types") == 0) || /* user tried to change a */ if ((strcmp (name, "Types") == 0) || /* user tried to change a */
(strcmp (name, "Modes") == 0)) /* constant dict type ... */ (strcmp (name, "Modes") == 0)) /* constant dict type ... */
return (EXPP_ReturnIntError (PyExc_AttributeError, return EXPP_ReturnIntError (PyExc_AttributeError,
"constant dictionary -- cannot be changed")); "constant dictionary -- cannot be changed");
else /* ... or no member with the given name was found */ else /* ... or no member with the given name was found */
return (EXPP_ReturnIntError (PyExc_KeyError, return EXPP_ReturnIntError (PyExc_KeyError,
"attribute not found")); "attribute not found");
} }
/* valtuple won't be returned to the caller, so we need to DECREF it */ /* valtuple won't be returned to the caller, so we need to DECREF it */
Py_DECREF(valtuple); Py_DECREF (valtuple);
if (error != Py_None) return -1; if (error != Py_None) return -1;
/* Py_None was incref'ed by the called Camera_set* function. We probably /* Py_None was incref'ed by the called Camera_set* function. We probably
* don't need to decref Py_None (!), but since Python/C API manual tells us * don't need to decref Py_None (!), but since Python/C API manual tells us
* to treat it like any other PyObject regarding ref counting ... */ * to treat it like any other PyObject regarding ref counting ... */
Py_DECREF(Py_None); Py_DECREF (Py_None);
return 0; /* normal exit */ return 0; /* normal exit */
} }

View File

@@ -33,9 +33,7 @@
#define EXPP_CAMERA_H #define EXPP_CAMERA_H
#include <Python.h> #include <Python.h>
#include <DNA_camera_types.h> #include <DNA_camera_types.h>
#include "constant.h" #include "constant.h"
#include "gen_utils.h" #include "gen_utils.h"

View File

@@ -45,20 +45,20 @@ static PyObject *M_Curve_New(PyObject *self, PyObject *args)
printf ("In Curve_New()\n"); printf ("In Curve_New()\n");
if (!PyArg_ParseTuple(args, "|s", &name)) if (!PyArg_ParseTuple(args, "|s", &name))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected string argument or no argument")); "expected string argument or no argument"));
blcurve = add_curve(OB_CURVE); /* first create the Curve Data in Blender */ blcurve = add_curve(OB_CURVE); /* first create the Curve Data in Blender */
if (blcurve == NULL) if (blcurve == NULL)
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Curve Data in Blender")); "couldn't create Curve Data in Blender"));
pycurve = (C_Curve *)PyObject_NEW(C_Curve, &Curve_Type); pycurve = (C_Curve *)PyObject_NEW(C_Curve, &Curve_Type);
if (pycurve == NULL) if (pycurve == NULL)
return (EXPP_ReturnPyObjError (PyExc_MemoryError, return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Curve Data object")); "couldn't create Curve Data object"));
pycurve->curve = blcurve; /* link Python curve wrapper to Blender Curve */ pycurve->curve = blcurve; /* link Python curve wrapper to Blender Curve */
if (name) if (name)
@@ -84,7 +84,7 @@ static PyObject *M_Curve_Get(PyObject *self, PyObject *args)
printf ("In Curve_Get()\n"); printf ("In Curve_Get()\n");
if (!PyArg_ParseTuple(args, "|s", &name))//expects nothing or a string if (!PyArg_ParseTuple(args, "|s", &name))//expects nothing or a string
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected string argument")); "expected string argument"));
if(name){//a name has been given if(name){//a name has been given
/* Use the name to search for the curve requested */ /* Use the name to search for the curve requested */
wanted_curv = NULL; wanted_curv = NULL;
@@ -93,8 +93,8 @@ static PyObject *M_Curve_Get(PyObject *self, PyObject *args)
while ((curv_iter) && (wanted_curv == NULL)) { while ((curv_iter) && (wanted_curv == NULL)) {
if (strcmp (name, curv_iter->id.name+2) == 0) { if (strcmp (name, curv_iter->id.name+2) == 0) {
wanted_curv = (C_Curve *)PyObject_NEW(C_Curve, &Curve_Type); wanted_curv = (C_Curve *)PyObject_NEW(C_Curve, &Curve_Type);
if (wanted_curv) wanted_curv->curve = curv_iter; if (wanted_curv) wanted_curv->curve = curv_iter;
} }
curv_iter = curv_iter->id.next; curv_iter = curv_iter->id.next;
@@ -109,33 +109,33 @@ static PyObject *M_Curve_Get(PyObject *self, PyObject *args)
return (PyObject*)wanted_curv; return (PyObject*)wanted_curv;
}//if(name) }/*if(name)*/
else{//no name has been given; return a list of all curves by name. else{/*no name has been given; return a list with all curves in the scene */
int index = 0; int index = 0;
PyObject *curvlist, *pystr; PyObject *curvlist, *pyobj;
curv_iter = G.main->curve.first; curv_iter = G.main->curve.first;
curvlist = PyList_New (BLI_countlist (&(G.main->curve))); curvlist = PyList_New (BLI_countlist (&(G.main->curve)));
if (curvlist == NULL) if (curvlist == NULL)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList")); "couldn't create PyList"));
while (curv_iter) { while (curv_iter) {
pystr = PyString_FromString (curv_iter->id.name+2); pyobj = CurveCreatePyObject (curv_iter);
if (!pystr) if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString")); "couldn't create PyString"));
PyList_SET_ITEM (curvlist, index, pystr); PyList_SET_ITEM (curvlist, index, pyobj);
curv_iter = curv_iter->id.next; curv_iter = curv_iter->id.next;
index++; index++;
} }
return (curvlist); return (curvlist);
}//else }/*else*/
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -168,7 +168,7 @@ static PyObject *Curve_getName(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.name attribute")); "couldn't get Curve.name attribute"));
} }
static PyObject *Curve_setName(C_Curve *self, PyObject *args) static PyObject *Curve_setName(C_Curve *self, PyObject *args)
@@ -178,7 +178,7 @@ static PyObject *Curve_setName(C_Curve *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s", &(name))) if (!PyArg_ParseTuple(args, "s", &(name)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected string argument")); "expected string argument"));
PyOS_snprintf(buf, sizeof(buf), "%s", name); PyOS_snprintf(buf, sizeof(buf), "%s", name);
rename_id(&self->curve->id, buf); /* proper way in Blender */ rename_id(&self->curve->id, buf); /* proper way in Blender */
@@ -193,7 +193,7 @@ static PyObject *Curve_getPathLen(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.pathlen attribute")); "couldn't get Curve.pathlen attribute"));
} }
@@ -201,8 +201,8 @@ static PyObject *Curve_setPathLen(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "i", &(self->curve->pathlen))) if (!PyArg_ParseTuple(args, "i", &(self->curve->pathlen)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int argument")); "expected int argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -216,7 +216,7 @@ static PyObject *Curve_getTotcol(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.totcol attribute")); "couldn't get Curve.totcol attribute"));
} }
@@ -224,8 +224,8 @@ static PyObject *Curve_setTotcol(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "i", &(self->curve->totcol))) if (!PyArg_ParseTuple(args, "i", &(self->curve->totcol)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int argument")); "expected int argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -239,7 +239,7 @@ static PyObject *Curve_getMode(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.flag attribute")); "couldn't get Curve.flag attribute"));
} }
@@ -247,8 +247,8 @@ static PyObject *Curve_setMode(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "i", &(self->curve->flag))) if (!PyArg_ParseTuple(args, "i", &(self->curve->flag)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int argument")); "expected int argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -262,7 +262,7 @@ static PyObject *Curve_getBevresol(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.bevresol attribute")); "couldn't get Curve.bevresol attribute"));
} }
@@ -270,8 +270,8 @@ static PyObject *Curve_setBevresol(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "i", &(self->curve->bevresol))) if (!PyArg_ParseTuple(args, "i", &(self->curve->bevresol)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int argument")); "expected int argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -285,7 +285,7 @@ static PyObject *Curve_getResolu(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.resolu attribute")); "couldn't get Curve.resolu attribute"));
} }
@@ -293,8 +293,8 @@ static PyObject *Curve_setResolu(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "i", &(self->curve->resolu))) if (!PyArg_ParseTuple(args, "i", &(self->curve->resolu)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int argument")); "expected int argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -309,7 +309,7 @@ static PyObject *Curve_getResolv(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.resolv attribute")); "couldn't get Curve.resolv attribute"));
} }
@@ -317,8 +317,8 @@ static PyObject *Curve_setResolv(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "i", &(self->curve->resolv))) if (!PyArg_ParseTuple(args, "i", &(self->curve->resolv)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int argument")); "expected int argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -333,7 +333,7 @@ static PyObject *Curve_getWidth(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.width attribute")); "couldn't get Curve.width attribute"));
} }
@@ -341,8 +341,8 @@ static PyObject *Curve_setWidth(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "f", &(self->curve->width))) if (!PyArg_ParseTuple(args, "f", &(self->curve->width)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected float argument")); "expected float argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -356,7 +356,7 @@ static PyObject *Curve_getExt1(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.ext1 attribute")); "couldn't get Curve.ext1 attribute"));
} }
@@ -364,8 +364,8 @@ static PyObject *Curve_setExt1(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "f", &(self->curve->ext1))) if (!PyArg_ParseTuple(args, "f", &(self->curve->ext1)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected float argument")); "expected float argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -380,7 +380,7 @@ static PyObject *Curve_getExt2(C_Curve *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Curve.ext2 attribute")); "couldn't get Curve.ext2 attribute"));
} }
@@ -388,8 +388,8 @@ static PyObject *Curve_setExt2(C_Curve *self, PyObject *args)
{ {
if (!PyArg_ParseTuple(args, "f", &(self->curve->ext2))) if (!PyArg_ParseTuple(args, "f", &(self->curve->ext2)))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected float argument")); "expected float argument"));
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -408,13 +408,13 @@ static PyObject *Curve_setControlPoint(C_Curve *self, PyObject *args)
if (ptrnurb->bp) if (ptrnurb->bp)
if (!PyArg_ParseTuple(args, "iiffff", &numcourbe,&numpoint,&x,&y,&z,&w)) if (!PyArg_ParseTuple(args, "iiffff", &numcourbe,&numpoint,&x,&y,&z,&w))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int int float float float float arguments")); "expected int int float float float float arguments"));
if (ptrnurb->bezt) if (ptrnurb->bezt)
if (!PyArg_ParseTuple(args, "iifffffffff", &numcourbe,&numpoint, if (!PyArg_ParseTuple(args, "iifffffffff", &numcourbe,&numpoint,
bez,bez+1,bez+2,bez+3,bez+4,bez+5,bez+6,bez+7,bez+8)) bez,bez+1,bez+2,bez+3,bez+4,bez+5,bez+6,bez+7,bez+8))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int int float float float float float float " "expected int int float float float float float float "
"float float float arguments")); "float float float arguments"));
for(i = 0;i< numcourbe;i++) for(i = 0;i< numcourbe;i++)
ptrnurb=ptrnurb->next; ptrnurb=ptrnurb->next;
@@ -428,8 +428,8 @@ static PyObject *Curve_setControlPoint(C_Curve *self, PyObject *args)
if (ptrnurb->bezt) if (ptrnurb->bezt)
{ {
for(i = 0;i<3;i++) for(i = 0;i<3;i++)
for(j = 0;j<3;j++) for(j = 0;j<3;j++)
ptrnurb->bezt[numpoint].vec[i][j] = bez[i*3+j]; ptrnurb->bezt[numpoint].vec[i][j] = bez[i*3+j];
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
@@ -445,7 +445,7 @@ static PyObject *Curve_getControlPoint(C_Curve *self, PyObject *args)
if (!PyArg_ParseTuple(args, "ii", &numcourbe,&numpoint)) if (!PyArg_ParseTuple(args, "ii", &numcourbe,&numpoint))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected int int arguments")); "expected int int arguments"));
//check args ??? //check args ???
if (!self->curve->nurb.first)return liste; if (!self->curve->nurb.first)return liste;
ptrnurb = self->curve->nurb.first; ptrnurb = self->curve->nurb.first;
@@ -455,16 +455,16 @@ static PyObject *Curve_getControlPoint(C_Curve *self, PyObject *args)
if (ptrnurb->bp) if (ptrnurb->bp)
{ {
for(i = 0;i< 4;i++) for(i = 0;i< 4;i++)
PyList_Append(liste, PyFloat_FromDouble( ptrnurb->bp[numpoint].vec[i])); PyList_Append(liste, PyFloat_FromDouble( ptrnurb->bp[numpoint].vec[i]));
} }
if (ptrnurb->bezt) if (ptrnurb->bezt)
{ {
liste = PyList_New(9); liste = PyList_New(9);
for(i = 0;i< 3;i++) for(i = 0;i< 3;i++)
for(j = 0;j< 3;j++) for(j = 0;j< 3;j++)
PyList_Append(liste, PyList_Append(liste,
PyFloat_FromDouble( ptrnurb->bezt[numpoint].vec[i][j])); PyFloat_FromDouble( ptrnurb->bezt[numpoint].vec[i][j]));
} }
return liste; return liste;
@@ -487,7 +487,7 @@ static PyObject *Curve_setLoc(C_Curve *self, PyObject *args)
if (!PyArg_ParseTuple(args, "fff",&x,&y,&z)) if (!PyArg_ParseTuple(args, "fff",&x,&y,&z))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected float float float arguments")); "expected float float float arguments"));
self->curve->loc[0] = x; self->curve->loc[0] = x;
self->curve->loc[1] = y; self->curve->loc[1] = y;
@@ -513,7 +513,7 @@ static PyObject *Curve_setRot(C_Curve *self, PyObject *args)
if (!PyArg_ParseTuple(args, "fff",&x,&y,&z)) if (!PyArg_ParseTuple(args, "fff",&x,&y,&z))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected float float float arguments")); "expected float float float arguments"));
self->curve->rot[0] = x; self->curve->rot[0] = x;
self->curve->rot[1] = y; self->curve->rot[1] = y;
@@ -538,7 +538,7 @@ static PyObject *Curve_setSize(C_Curve *self, PyObject *args)
if (!PyArg_ParseTuple(args, "fff",&x,&y,&z)) if (!PyArg_ParseTuple(args, "fff",&x,&y,&z))
return (EXPP_ReturnPyObjError (PyExc_AttributeError, return (EXPP_ReturnPyObjError (PyExc_AttributeError,
"expected float float float arguments")); "expected float float float arguments"));
self->curve->size[0] = x; self->curve->size[0] = x;
self->curve->size[1] = y; self->curve->size[1] = y;
@@ -598,7 +598,7 @@ static PyObject *CurveGetAttr (C_Curve *self, char *name)//getattr
if (!attr) if (!attr)
return (EXPP_ReturnPyObjError (PyExc_MemoryError, return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create PyObject")); "couldn't create PyObject"));
if (attr != Py_None) return attr; /* member attribute found, return it */ if (attr != Py_None) return attr; /* member attribute found, return it */

View File

@@ -198,7 +198,7 @@ struct Curve* CurveFromPyObject (PyObject *py_obj);
/*****************************************************************************/ /*****************************************************************************/
/* Python Curve_Type structure definition: */ /* Python Curve_Type structure definition: */
/*****************************************************************************/ /*****************************************************************************/
static PyTypeObject Curve_Type = PyTypeObject Curve_Type =
{ {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /* ob_size */

View File

@@ -38,16 +38,16 @@
static void Button_dealloc(PyObject *self) static void Button_dealloc(PyObject *self)
{ {
Button *but= (Button*) self; Button *but = (Button*)self;
if(but->type==3) MEM_freeN(but->val.asstr); if(but->type == 3) MEM_freeN (but->val.asstr);
PyMem_DEL(self); PyObject_DEL (self);
} }
static PyObject *Button_getattr(PyObject *self, char *name) static PyObject *Button_getattr(PyObject *self, char *name)
{ {
Button *but= (Button*) self; Button *but = (Button*)self;
if(strcmp(name, "val") == 0) { if(strcmp(name, "val") == 0) {
if (but->type==1) if (but->type==1)

View File

@@ -37,28 +37,28 @@
/*****************************************************************************/ /*****************************************************************************/
static PyObject *M_Ipo_New(PyObject *self, PyObject *args) static PyObject *M_Ipo_New(PyObject *self, PyObject *args)
{ {
Ipo *add_ipo(char *name, int idcode); Ipo *add_ipo(char *name, int idcode);
char*name = NULL; char*name = NULL;
int code = 0; int code = 0;
C_Ipo *pyipo; C_Ipo *pyipo;
Ipo *blipo; Ipo *blipo;
if (!PyArg_ParseTuple(args, "si", &name,&code)) if (!PyArg_ParseTuple(args, "si", &name,&code))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string int arguments")); "expected string int arguments"));
blipo = add_ipo(name,code); blipo = add_ipo(name,code);
if (blipo) if (blipo)
pyipo = (C_Ipo *)PyObject_NEW(C_Ipo, &Ipo_Type); pyipo = (C_Ipo *)PyObject_NEW(C_Ipo, &Ipo_Type);
else else
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Ipo Data in Blender")); "couldn't create Ipo Data in Blender"));
if (pyipo == NULL) if (pyipo == NULL)
return (EXPP_ReturnPyObjError (PyExc_MemoryError, return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Ipo Data object")); "couldn't create Ipo Data object"));
pyipo->ipo = blipo; pyipo->ipo = blipo;
@@ -77,57 +77,57 @@ static PyObject *M_Ipo_Get(PyObject *self, PyObject *args)
{ {
char *name = NULL; char *name = NULL;
Ipo *ipo_iter; Ipo *ipo_iter;
PyObject *ipolist, *pystr; PyObject *ipolist, *pyobj;
C_Ipo *wanted_ipo = NULL; C_Ipo *wanted_ipo = NULL;
char error_msg[64]; char error_msg[64];
if (!PyArg_ParseTuple(args, "|s", &name)) if (!PyArg_ParseTuple(args, "|s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument (or nothing)")); "expected string argument (or nothing)"));
ipo_iter = G.main->ipo.first; ipo_iter = G.main->ipo.first;
if (name) { /* (name) - Search ipo by name */ if (name) { /* (name) - Search ipo by name */
while ((ipo_iter) && (wanted_ipo == NULL)) { while ((ipo_iter) && (wanted_ipo == NULL)) {
if (strcmp (name, ipo_iter->id.name+2) == 0) { if (strcmp (name, ipo_iter->id.name+2) == 0) {
wanted_ipo = (C_Ipo *)PyObject_NEW(C_Ipo, &Ipo_Type); wanted_ipo = (C_Ipo *)PyObject_NEW(C_Ipo, &Ipo_Type);
if (wanted_ipo) wanted_ipo->ipo = ipo_iter; if (wanted_ipo) wanted_ipo->ipo = ipo_iter;
} }
ipo_iter = ipo_iter->id.next; ipo_iter = ipo_iter->id.next;
} }
if (wanted_ipo == NULL) { /* Requested ipo doesn't exist */ if (wanted_ipo == NULL) { /* Requested ipo doesn't exist */
PyOS_snprintf(error_msg, sizeof(error_msg), PyOS_snprintf(error_msg, sizeof(error_msg),
"Ipo \"%s\" not found", name); "Ipo \"%s\" not found", name);
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg)); return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
} }
return (PyObject *)wanted_ipo; return (PyObject *)wanted_ipo;
} }
else { /* () - return a list of all ipos in the scene */ else { /* () - return a list with all ipos in the scene */
int index = 0; int index = 0;
ipolist = PyList_New (BLI_countlist (&(G.main->ipo))); ipolist = PyList_New (BLI_countlist (&(G.main->ipo)));
if (ipolist == NULL) if (ipolist == NULL)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList")); "couldn't create PyList"));
while (ipo_iter) { while (ipo_iter) {
pystr = PyString_FromString (ipo_iter->id.name+2); pyobj = Ipo_CreatePyObject (ipo_iter);
if (!pystr) if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString")); "couldn't create PyString"));
PyList_SET_ITEM (ipolist, index, pystr); PyList_SET_ITEM (ipolist, index, pyobj);
ipo_iter = ipo_iter->id.next; ipo_iter = ipo_iter->id.next;
index++; index++;
} }
return (ipolist); return (ipolist);
} }
} }
@@ -138,9 +138,10 @@ PyObject *M_Ipo_Init (void)
{ {
PyObject *submodule; PyObject *submodule;
Ipo_Type.ob_type = &PyType_Type;
printf ("In M_Ipo_Init()\n"); printf ("In M_Ipo_Init()\n");
submodule = Py_InitModule3("Blender.Ipo", submodule = Py_InitModule3("Blender.Ipo", M_Ipo_methods, M_Ipo_doc);
M_Ipo_methods, M_Ipo_doc);
return (submodule); return (submodule);
} }
@@ -155,7 +156,7 @@ static PyObject *Ipo_getName(C_Ipo *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Ipo.name attribute")); "couldn't get Ipo.name attribute"));
} }
static PyObject *Ipo_setName(C_Ipo *self, PyObject *args) static PyObject *Ipo_setName(C_Ipo *self, PyObject *args)
{ {
@@ -164,7 +165,7 @@ static PyObject *Ipo_setName(C_Ipo *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s", &name)) if (!PyArg_ParseTuple(args, "s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument")); "expected string argument"));
PyOS_snprintf(buf, sizeof(buf), "%s", name); PyOS_snprintf(buf, sizeof(buf), "%s", name);
@@ -181,7 +182,7 @@ static PyObject *Ipo_getBlocktype(C_Ipo *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Ipo.blocktype attribute")); "couldn't get Ipo.blocktype attribute"));
} }
@@ -191,9 +192,9 @@ static PyObject *Ipo_setBlocktype(C_Ipo *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i", &blocktype)) if (!PyArg_ParseTuple(args, "i", &blocktype))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument")); "expected string argument"));
self->ipo->blocktype = (short)blocktype; self->ipo->blocktype = (short)blocktype;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -206,7 +207,7 @@ static PyObject *Ipo_getShowkey(C_Ipo *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Ipo.showkey attribute")); "couldn't get Ipo.showkey attribute"));
} }
@@ -216,9 +217,9 @@ static PyObject *Ipo_setShowkey(C_Ipo *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i", &showkey)) if (!PyArg_ParseTuple(args, "i", &showkey))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument")); "expected string argument"));
self->ipo->showkey = (short)showkey; self->ipo->showkey = (short)showkey;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -231,7 +232,7 @@ static PyObject *Ipo_getPad(C_Ipo *self)
if (attr) return attr; if (attr) return attr;
return (EXPP_ReturnPyObjError (PyExc_RuntimeError, return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't get Ipo.pad attribute")); "couldn't get Ipo.pad attribute"));
} }
@@ -241,9 +242,9 @@ static PyObject *Ipo_setPad(C_Ipo *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i", &pad)) if (!PyArg_ParseTuple(args, "i", &pad))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument")); "expected string argument"));
self->ipo->pad = pad; self->ipo->pad = pad;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -251,7 +252,7 @@ static PyObject *Ipo_setPad(C_Ipo *self, PyObject *args)
static PyObject *Ipo_getRctf(C_Ipo *self) static PyObject *Ipo_getRctf(C_Ipo *self)
{ {
PyObject* l = PyList_New(0); PyObject* l = PyList_New(0);
PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.xmin)); PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.xmin));
PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.xmax)); PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.xmax));
PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.ymin)); PyList_Append( l, PyFloat_FromDouble(self->ipo->cur.ymin));
@@ -263,15 +264,15 @@ static PyObject *Ipo_getRctf(C_Ipo *self)
static PyObject *Ipo_setRctf(C_Ipo *self, PyObject *args) static PyObject *Ipo_setRctf(C_Ipo *self, PyObject *args)
{ {
float v[4]; float v[4];
if (!PyArg_ParseTuple(args, "ffff",v,v+1,v+2,v+3)) if (!PyArg_ParseTuple(args, "ffff",v,v+1,v+2,v+3))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected 4 float argument")); "expected 4 float argument"));
self->ipo->cur.xmin = v[0]; self->ipo->cur.xmin = v[0];
self->ipo->cur.xmax = v[1]; self->ipo->cur.xmax = v[1];
self->ipo->cur.ymin = v[2]; self->ipo->cur.ymin = v[2];
self->ipo->cur.ymax = v[3]; self->ipo->cur.ymax = v[3];
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -279,12 +280,12 @@ static PyObject *Ipo_setRctf(C_Ipo *self, PyObject *args)
static PyObject *Ipo_getNcurves(C_Ipo *self) static PyObject *Ipo_getNcurves(C_Ipo *self)
{ {
int i = 0; int i = 0;
IpoCurve *icu; IpoCurve *icu;
for (icu=self->ipo->curve.first; icu; icu=icu->next){ for (icu=self->ipo->curve.first; icu; icu=icu->next){
i++; i++;
} }
return (PyInt_FromLong(i) ); return (PyInt_FromLong(i) );
} }
@@ -292,91 +293,91 @@ static PyObject *Ipo_getNcurves(C_Ipo *self)
static PyObject *Ipo_getCurveBP(C_Ipo *self, PyObject *args) static PyObject *Ipo_getCurveBP(C_Ipo *self, PyObject *args)
{ {
struct BPoint *ptrbpoint; struct BPoint *ptrbpoint;
int num = 0,i; int num = 0,i;
IpoCurve *icu; IpoCurve *icu;
PyObject* l; PyObject* l;
if (!PyArg_ParseTuple(args, "i",&num)) if (!PyArg_ParseTuple(args, "i",&num))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument")); "expected int argument"));
icu =self->ipo->curve.first; icu =self->ipo->curve.first;
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve"));
for(i = 0;i<num;i++) for(i = 0;i<num;i++)
{ {
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number"));
icu=icu->next; icu=icu->next;
} }
ptrbpoint = icu->bp; ptrbpoint = icu->bp;
if(!ptrbpoint)return EXPP_ReturnPyObjError(PyExc_TypeError,"No base point"); if(!ptrbpoint)return EXPP_ReturnPyObjError(PyExc_TypeError,"No base point");
l = PyList_New(0); l = PyList_New(0);
for(i=0;i<4;i++) for(i=0;i<4;i++)
PyList_Append( l, PyFloat_FromDouble(ptrbpoint->vec[i])); PyList_Append( l, PyFloat_FromDouble(ptrbpoint->vec[i]));
return l; return l;
} }
static PyObject *Ipo_getCurveBeztriple(C_Ipo *self, PyObject *args) static PyObject *Ipo_getCurveBeztriple(C_Ipo *self, PyObject *args)
{ {
struct BezTriple *ptrbt; struct BezTriple *ptrbt;
int num = 0,pos,i,j; int num = 0,pos,i,j;
IpoCurve *icu; IpoCurve *icu;
PyObject* l = PyList_New(0); PyObject* l = PyList_New(0);
if (!PyArg_ParseTuple(args, "ii",&num,&pos)) if (!PyArg_ParseTuple(args, "ii",&num,&pos))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument")); "expected int argument"));
icu =self->ipo->curve.first; icu =self->ipo->curve.first;
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve"));
for(i = 0;i<num;i++) for(i = 0;i<num;i++)
{ {
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number"));
icu=icu->next; icu=icu->next;
} }
if (pos >= icu->totvert) if (pos >= icu->totvert)
return EXPP_ReturnPyObjError(PyExc_TypeError,"Bad bezt number"); return EXPP_ReturnPyObjError(PyExc_TypeError,"Bad bezt number");
ptrbt = icu->bezt + pos; ptrbt = icu->bezt + pos;
if(!ptrbt) if(!ptrbt)
return EXPP_ReturnPyObjError(PyExc_TypeError,"No bez triple"); return EXPP_ReturnPyObjError(PyExc_TypeError,"No bez triple");
for(i=0;i<3;i++) for(i=0;i<3;i++)
for(j=0;j<3;j++) for(j=0;j<3;j++)
PyList_Append( l, PyFloat_FromDouble(ptrbt->vec[i][j])); PyList_Append( l, PyFloat_FromDouble(ptrbt->vec[i][j]));
return l; return l;
} }
static PyObject *Ipo_setCurveBeztriple(C_Ipo *self, PyObject *args) static PyObject *Ipo_setCurveBeztriple(C_Ipo *self, PyObject *args)
{ {
struct BezTriple *ptrbt; struct BezTriple *ptrbt;
int num = 0,pos,i; int num = 0,pos,i;
IpoCurve *icu; IpoCurve *icu;
PyObject *listargs=0; PyObject *listargs=0;
if (!PyArg_ParseTuple(args, "iiO",&num,&pos,&listargs)) if (!PyArg_ParseTuple(args, "iiO",&num,&pos,&listargs))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument")); "expected int argument"));
icu =self->ipo->curve.first; icu =self->ipo->curve.first;
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve"));
for(i = 0;i<num;i++) for(i = 0;i<num;i++)
{ {
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number"));
icu=icu->next; icu=icu->next;
} }
if (pos >= icu->totvert) if (pos >= icu->totvert)
return EXPP_ReturnPyObjError(PyExc_TypeError,"Bad bezt number"); return EXPP_ReturnPyObjError(PyExc_TypeError,"Bad bezt number");
ptrbt = icu->bezt + pos; ptrbt = icu->bezt + pos;
if(!ptrbt) if(!ptrbt)
return EXPP_ReturnPyObjError(PyExc_TypeError,"No bez triple"); return EXPP_ReturnPyObjError(PyExc_TypeError,"No bez triple");
for(i=0;i<9;i++) for(i=0;i<9;i++)
{ {
PyObject * xx = PyList_GetItem(listargs,i); PyObject * xx = PyList_GetItem(listargs,i);
ptrbt->vec[i/3][i%3] = PyFloat_AsDouble(xx); ptrbt->vec[i/3][i%3] = PyFloat_AsDouble(xx);
} }
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -387,21 +388,21 @@ static PyObject *Ipo_setCurveBeztriple(C_Ipo *self, PyObject *args)
static PyObject *Ipo_getCurvecurval(C_Ipo *self, PyObject *args) static PyObject *Ipo_getCurvecurval(C_Ipo *self, PyObject *args)
{ {
int num = 0,i; int num = 0,i;
IpoCurve *icu; IpoCurve *icu;
if (!PyArg_ParseTuple(args, "i",&num)) if (!PyArg_ParseTuple(args, "i",&num))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument")); "expected int argument"));
icu =self->ipo->curve.first; icu =self->ipo->curve.first;
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"No IPO curve"));
for(i = 0;i<num;i++) for(i = 0;i<num;i++)
{ {
if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number")); if(!icu) return (EXPP_ReturnPyObjError (PyExc_TypeError,"Bad ipo number"));
icu=icu->next; icu=icu->next;
} }
return PyFloat_FromDouble(icu->curval); return PyFloat_FromDouble(icu->curval);
} }
@@ -449,12 +450,53 @@ static int IpoPrint(C_Ipo *self, FILE *fp, int flags)
} }
/*****************************************************************************/ /*****************************************************************************/
/* Function: IpoRepr */ /* Function: IpoRepr */
/* Description: This is a callback function for the C_Ipo type. It */ /* Description: This is a callback function for the C_Ipo type. It */
/* builds a meaninful string to represent ipo objects. */ /* builds a meaninful string to represent ipo objects. */
/*****************************************************************************/ /*****************************************************************************/
static PyObject *IpoRepr (C_Ipo *self) static PyObject *IpoRepr (C_Ipo *self)
{ {
return PyString_FromString(self->ipo->id.name+2); return PyString_FromString(self->ipo->id.name+2);
} }
/* Three Python Ipo_Type helper functions needed by the Object module: */
/*****************************************************************************/
/* Function: Ipo_CreatePyObject */
/* Description: This function will create a new C_Ipo from an existing */
/* Blender ipo structure. */
/*****************************************************************************/
PyObject *Ipo_CreatePyObject (Ipo *ipo)
{
C_Ipo *pyipo;
pyipo = (C_Ipo *)PyObject_NEW (C_Ipo, &Ipo_Type);
if (!pyipo)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create C_Ipo object");
pyipo->ipo = ipo;
return (PyObject *)pyipo;
}
/*****************************************************************************/
/* Function: Ipo_CheckPyObject */
/* Description: This function returns true when the given PyObject is of the */
/* type Ipo. Otherwise it will return false. */
/*****************************************************************************/
int Ipo_CheckPyObject (PyObject *pyobj)
{
return (pyobj->ob_type == &Ipo_Type);
}
/*****************************************************************************/
/* Function: Ipo_FromPyObject */
/* Description: This function returns the Blender ipo from the given */
/* PyObject. */
/*****************************************************************************/
Ipo *Ipo_FromPyObject (PyObject *pyobj)
{
return ((C_Ipo *)pyobj)->ipo;
}

View File

@@ -152,9 +152,9 @@ static PyObject *IpoRepr (C_Ipo *self);
/*****************************************************************************/ /*****************************************************************************/
/* Python Ipo_Type structure definition: */ /* Python Ipo_Type structure definition: */
/*****************************************************************************/ /*****************************************************************************/
static PyTypeObject Ipo_Type = PyTypeObject Ipo_Type =
{ {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(NULL)
0, /* ob_size */ 0, /* ob_size */
"Ipo", /* tp_name */ "Ipo", /* tp_name */
sizeof (C_Ipo), /* tp_basicsize */ sizeof (C_Ipo), /* tp_basicsize */

View File

@@ -99,22 +99,22 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
char *name = NULL; char *name = NULL;
Lamp *lamp_iter; Lamp *lamp_iter;
if (!PyArg_ParseTuple(args, "|s", &name)) if (!PyArg_ParseTuple(args, "|s", &name))
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected string argument (or nothing)")); "expected string argument (or nothing)"));
lamp_iter = G.main->lamp.first; lamp_iter = G.main->lamp.first;
if (name) { /* (name) - Search lamp by name */ if (name) { /* (name) - Search lamp by name */
C_Lamp *wanted_lamp = NULL; C_Lamp *wanted_lamp = NULL;
while ((lamp_iter) && (wanted_lamp == NULL)) { while ((lamp_iter) && (wanted_lamp == NULL)) {
if (strcmp (name, lamp_iter->id.name+2) == 0) if (strcmp (name, lamp_iter->id.name+2) == 0)
wanted_lamp = (C_Lamp *)Lamp_CreatePyObject(lamp_iter); wanted_lamp = (C_Lamp *)Lamp_CreatePyObject(lamp_iter);
lamp_iter = lamp_iter->id.next; lamp_iter = lamp_iter->id.next;
} }
if (wanted_lamp == NULL) { /* Requested lamp doesn't exist */ if (wanted_lamp == NULL) { /* Requested lamp doesn't exist */
@@ -125,11 +125,11 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
} }
return (PyObject *)wanted_lamp; return (PyObject *)wanted_lamp;
} }
else { /* () - return a list of all lamps in the scene */ else { /* () - return a list of all lamps in the scene */
int index = 0; int index = 0;
PyObject *lamplist, *pystr; PyObject *lamplist, *pyobj;
lamplist = PyList_New (BLI_countlist (&(G.main->lamp))); lamplist = PyList_New (BLI_countlist (&(G.main->lamp)));
@@ -137,46 +137,46 @@ static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList")); "couldn't create PyList"));
while (lamp_iter) { while (lamp_iter) {
pystr = PyString_FromString (lamp_iter->id.name+2); pyobj = Lamp_CreatePyObject (lamp_iter);
if (!pystr) if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString")); "couldn't create PyString"));
PyList_SET_ITEM (lamplist, index, pystr); PyList_SET_ITEM (lamplist, index, pyobj);
lamp_iter = lamp_iter->id.next; lamp_iter = lamp_iter->id.next;
index++; index++;
} }
return (lamplist); return lamplist;
} }
} }
static PyObject *M_Lamp_TypesDict (void) static PyObject *M_Lamp_TypesDict (void)
{ /* create the Blender.Lamp.Types constant dict */ { /* create the Blender.Lamp.Types constant dict */
PyObject *Types = M_constant_New(); PyObject *Types = M_constant_New();
if (Types) { if (Types) {
C_constant *c = (C_constant *)Types; C_constant *c = (C_constant *)Types;
constant_insert (c, "Lamp", PyInt_FromLong (EXPP_LAMP_TYPE_LAMP)); constant_insert (c, "Lamp", PyInt_FromLong (EXPP_LAMP_TYPE_LAMP));
constant_insert (c, "Sun", PyInt_FromLong (EXPP_LAMP_TYPE_SUN)); constant_insert (c, "Sun", PyInt_FromLong (EXPP_LAMP_TYPE_SUN));
constant_insert (c, "Spot", PyInt_FromLong (EXPP_LAMP_TYPE_SPOT)); constant_insert (c, "Spot", PyInt_FromLong (EXPP_LAMP_TYPE_SPOT));
constant_insert (c, "Hemi", PyInt_FromLong (EXPP_LAMP_TYPE_HEMI)); constant_insert (c, "Hemi", PyInt_FromLong (EXPP_LAMP_TYPE_HEMI));
} }
return Types; return Types;
} }
static PyObject *M_Lamp_ModesDict (void) static PyObject *M_Lamp_ModesDict (void)
{ /* create the Blender.Lamp.Modes constant dict */ { /* create the Blender.Lamp.Modes constant dict */
PyObject *Modes = M_constant_New(); PyObject *Modes = M_constant_New();
if (Modes) { if (Modes) {
C_constant *c = (C_constant *)Modes; C_constant *c = (C_constant *)Modes;
constant_insert (c, "Shadows", PyInt_FromLong (EXPP_LAMP_MODE_SHADOWS)); constant_insert (c, "Shadows", PyInt_FromLong (EXPP_LAMP_MODE_SHADOWS));
constant_insert (c, "Halo", PyInt_FromLong (EXPP_LAMP_MODE_HALO)); constant_insert (c, "Halo", PyInt_FromLong (EXPP_LAMP_MODE_HALO));
@@ -186,8 +186,8 @@ static PyObject *M_Lamp_ModesDict (void)
constant_insert (c, "Sphere", PyInt_FromLong (EXPP_LAMP_MODE_SPHERE)); constant_insert (c, "Sphere", PyInt_FromLong (EXPP_LAMP_MODE_SPHERE));
constant_insert (c, "Square", PyInt_FromLong (EXPP_LAMP_MODE_SQUARE)); constant_insert (c, "Square", PyInt_FromLong (EXPP_LAMP_MODE_SQUARE));
constant_insert (c, "OnlyShadow", constant_insert (c, "OnlyShadow",
PyInt_FromLong (EXPP_LAMP_MODE_ONLYSHADOW)); PyInt_FromLong (EXPP_LAMP_MODE_ONLYSHADOW));
} }
return Modes; return Modes;
} }
@@ -202,13 +202,13 @@ PyObject *M_Lamp_Init (void)
Lamp_Type.ob_type = &PyType_Type; Lamp_Type.ob_type = &PyType_Type;
Types = M_Lamp_TypesDict (); Types = M_Lamp_TypesDict ();
Modes = M_Lamp_ModesDict (); Modes = M_Lamp_ModesDict ();
submodule = Py_InitModule3("Blender.Lamp", M_Lamp_methods, M_Lamp_doc); submodule = Py_InitModule3("Blender.Lamp", M_Lamp_methods, M_Lamp_doc);
if (Types) PyModule_AddObject(submodule, "Types", Types); if (Types) PyModule_AddObject(submodule, "Types", Types);
if (Modes) PyModule_AddObject(submodule, "Modes", Modes); if (Modes) PyModule_AddObject(submodule, "Modes", Modes);
return (submodule); return (submodule);
} }
@@ -222,24 +222,24 @@ PyObject *M_Lamp_Init (void)
/*****************************************************************************/ /*****************************************************************************/
PyObject *Lamp_CreatePyObject (Lamp *lamp) PyObject *Lamp_CreatePyObject (Lamp *lamp)
{ {
C_Lamp *pylamp; C_Lamp *pylamp;
float *rgb[3]; float *rgb[3];
pylamp = (C_Lamp *)PyObject_NEW (C_Lamp, &Lamp_Type); pylamp = (C_Lamp *)PyObject_NEW (C_Lamp, &Lamp_Type);
if (!pylamp) if (!pylamp)
return EXPP_ReturnPyObjError (PyExc_MemoryError, return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create C_Lamp object"); "couldn't create C_Lamp object");
pylamp->lamp = lamp; pylamp->lamp = lamp;
rgb[0] = &lamp->r; rgb[0] = &lamp->r;
rgb[1] = &lamp->g; rgb[1] = &lamp->g;
rgb[2] = &lamp->b; rgb[2] = &lamp->b;
pylamp->color = (C_rgbTuple *)rgbTuple_New(rgb); pylamp->color = (C_rgbTuple *)rgbTuple_New(rgb);
return (PyObject *)pylamp; return (PyObject *)pylamp;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -249,7 +249,7 @@ PyObject *Lamp_CreatePyObject (Lamp *lamp)
/*****************************************************************************/ /*****************************************************************************/
int Lamp_CheckPyObject (PyObject *pyobj) int Lamp_CheckPyObject (PyObject *pyobj)
{ {
return (pyobj->ob_type == &Lamp_Type); return (pyobj->ob_type == &Lamp_Type);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -259,7 +259,7 @@ int Lamp_CheckPyObject (PyObject *pyobj)
/*****************************************************************************/ /*****************************************************************************/
Lamp *Lamp_FromPyObject (PyObject *pyobj) Lamp *Lamp_FromPyObject (PyObject *pyobj)
{ {
return ((C_Lamp *)pyobj)->lamp; return ((C_Lamp *)pyobj)->lamp;
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -437,7 +437,7 @@ static PyObject *Lamp_getQuad2(C_Lamp *self)
static PyObject *Lamp_getCol(C_Lamp *self) static PyObject *Lamp_getCol(C_Lamp *self)
{ {
return rgbTuple_getCol(self->color); return rgbTuple_getCol(self->color);
} }
static PyObject *Lamp_setName(C_Lamp *self, PyObject *args) static PyObject *Lamp_setName(C_Lamp *self, PyObject *args)
@@ -568,8 +568,8 @@ static PyObject *Lamp_setSamples(C_Lamp *self, PyObject *args)
return (EXPP_ReturnPyObjError (PyExc_TypeError, return (EXPP_ReturnPyObjError (PyExc_TypeError,
"expected int argument in [1,16]")); "expected int argument in [1,16]"));
self->lamp->samp = EXPP_ClampInt (value, self->lamp->samp = EXPP_ClampInt (value,
EXPP_LAMP_SAMPLES_MIN, EXPP_LAMP_SAMPLES_MAX); EXPP_LAMP_SAMPLES_MIN, EXPP_LAMP_SAMPLES_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -584,7 +584,7 @@ static PyObject *Lamp_setBufferSize(C_Lamp *self, PyObject *args)
"expected int argument in [512, 5120]")); "expected int argument in [512, 5120]"));
self->lamp->bufsize = EXPP_ClampInt (value, self->lamp->bufsize = EXPP_ClampInt (value,
EXPP_LAMP_BUFFERSIZE_MIN, EXPP_LAMP_BUFFERSIZE_MAX); EXPP_LAMP_BUFFERSIZE_MIN, EXPP_LAMP_BUFFERSIZE_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -599,7 +599,7 @@ static PyObject *Lamp_setHaloStep(C_Lamp *self, PyObject *args)
"expected int argument in [0,12]")); "expected int argument in [0,12]"));
self->lamp->shadhalostep = EXPP_ClampInt (value, self->lamp->shadhalostep = EXPP_ClampInt (value,
EXPP_LAMP_HALOSTEP_MIN, EXPP_LAMP_HALOSTEP_MAX); EXPP_LAMP_HALOSTEP_MIN, EXPP_LAMP_HALOSTEP_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -614,7 +614,7 @@ static PyObject *Lamp_setEnergy(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->energy = EXPP_ClampFloat (value, self->lamp->energy = EXPP_ClampFloat (value,
EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX); EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -629,7 +629,7 @@ static PyObject *Lamp_setDist(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->dist = EXPP_ClampFloat (value, self->lamp->dist = EXPP_ClampFloat (value,
EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX); EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -644,7 +644,7 @@ static PyObject *Lamp_setSpotSize(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->spotsize = EXPP_ClampFloat (value, self->lamp->spotsize = EXPP_ClampFloat (value,
EXPP_LAMP_SPOTSIZE_MIN, EXPP_LAMP_SPOTSIZE_MAX); EXPP_LAMP_SPOTSIZE_MIN, EXPP_LAMP_SPOTSIZE_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -659,7 +659,7 @@ static PyObject *Lamp_setSpotBlend(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->spotblend = EXPP_ClampFloat (value, self->lamp->spotblend = EXPP_ClampFloat (value,
EXPP_LAMP_SPOTBLEND_MIN, EXPP_LAMP_SPOTBLEND_MAX); EXPP_LAMP_SPOTBLEND_MIN, EXPP_LAMP_SPOTBLEND_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -674,7 +674,7 @@ static PyObject *Lamp_setClipStart(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->clipsta = EXPP_ClampFloat (value, self->lamp->clipsta = EXPP_ClampFloat (value,
EXPP_LAMP_CLIPSTART_MIN, EXPP_LAMP_CLIPSTART_MAX); EXPP_LAMP_CLIPSTART_MIN, EXPP_LAMP_CLIPSTART_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -689,7 +689,7 @@ static PyObject *Lamp_setClipEnd(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->clipend = EXPP_ClampFloat (value, self->lamp->clipend = EXPP_ClampFloat (value,
EXPP_LAMP_CLIPEND_MIN, EXPP_LAMP_CLIPEND_MAX); EXPP_LAMP_CLIPEND_MIN, EXPP_LAMP_CLIPEND_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -704,7 +704,7 @@ static PyObject *Lamp_setBias(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->bias = EXPP_ClampFloat (value, self->lamp->bias = EXPP_ClampFloat (value,
EXPP_LAMP_BIAS_MIN, EXPP_LAMP_BIAS_MAX); EXPP_LAMP_BIAS_MIN, EXPP_LAMP_BIAS_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -719,7 +719,7 @@ static PyObject *Lamp_setSoftness(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->soft = EXPP_ClampFloat (value, self->lamp->soft = EXPP_ClampFloat (value,
EXPP_LAMP_SOFTNESS_MIN, EXPP_LAMP_SOFTNESS_MAX); EXPP_LAMP_SOFTNESS_MIN, EXPP_LAMP_SOFTNESS_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -734,7 +734,7 @@ static PyObject *Lamp_setHaloInt(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->haint = EXPP_ClampFloat (value, self->lamp->haint = EXPP_ClampFloat (value,
EXPP_LAMP_HALOINT_MIN, EXPP_LAMP_HALOINT_MAX); EXPP_LAMP_HALOINT_MIN, EXPP_LAMP_HALOINT_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -749,7 +749,7 @@ static PyObject *Lamp_setQuad1(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->att1 = EXPP_ClampFloat (value, self->lamp->att1 = EXPP_ClampFloat (value,
EXPP_LAMP_QUAD1_MIN, EXPP_LAMP_QUAD1_MAX); EXPP_LAMP_QUAD1_MIN, EXPP_LAMP_QUAD1_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
@@ -764,14 +764,14 @@ static PyObject *Lamp_setQuad2(C_Lamp *self, PyObject *args)
"expected float argument")); "expected float argument"));
self->lamp->att2 = EXPP_ClampFloat (value, self->lamp->att2 = EXPP_ClampFloat (value,
EXPP_LAMP_QUAD2_MIN, EXPP_LAMP_QUAD2_MAX); EXPP_LAMP_QUAD2_MIN, EXPP_LAMP_QUAD2_MAX);
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key, static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key,
PyObject *args) PyObject *args)
{ /* for compatibility with old bpython */ { /* for compatibility with old bpython */
float value; float value;
@@ -780,7 +780,7 @@ static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key,
"expected float argument in [0.0, 1.0]")); "expected float argument in [0.0, 1.0]"));
value = EXPP_ClampFloat (value, EXPP_LAMP_COL_MIN, value = EXPP_ClampFloat (value, EXPP_LAMP_COL_MIN,
EXPP_LAMP_COL_MAX); EXPP_LAMP_COL_MAX);
if (!strcmp(key, "R")) if (!strcmp(key, "R"))
self->lamp->r = value; self->lamp->r = value;
@@ -789,13 +789,13 @@ static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key,
else if (!strcmp(key, "B")) else if (!strcmp(key, "B"))
self->lamp->b = value; self->lamp->b = value;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }
static PyObject *Lamp_setCol(C_Lamp *self, PyObject *args) static PyObject *Lamp_setCol(C_Lamp *self, PyObject *args)
{ {
return rgbTuple_setCol(self->color, args); return rgbTuple_setCol(self->color, args);
} }
/*****************************************************************************/ /*****************************************************************************/
@@ -836,8 +836,8 @@ static PyObject *LampGetAttr (C_Lamp *self, char *name)
attr = PyFloat_FromDouble(self->lamp->g); attr = PyFloat_FromDouble(self->lamp->g);
else if (strcmp(name, "B") == 0) else if (strcmp(name, "B") == 0)
attr = PyFloat_FromDouble(self->lamp->b); attr = PyFloat_FromDouble(self->lamp->b);
else if (strcmp(name, "col") == 0) else if (strcmp(name, "col") == 0)
attr = Lamp_getCol(self); attr = Lamp_getCol(self);
else if (strcmp(name, "energy") == 0) else if (strcmp(name, "energy") == 0)
attr = PyFloat_FromDouble(self->lamp->energy); attr = PyFloat_FromDouble(self->lamp->energy);
else if (strcmp(name, "dist") == 0) else if (strcmp(name, "dist") == 0)
@@ -992,8 +992,8 @@ static int LampSetAttr (C_Lamp *self, char *name, PyObject *value)
/*****************************************************************************/ /*****************************************************************************/
static int LampCompare (C_Lamp *a, C_Lamp *b) static int LampCompare (C_Lamp *a, C_Lamp *b)
{ {
Lamp *pa = a->lamp, *pb = b->lamp; Lamp *pa = a->lamp, *pb = b->lamp;
return (pa == pb) ? 0:-1; return (pa == pb) ? 0:-1;
} }
/*****************************************************************************/ /*****************************************************************************/

View File

@@ -111,7 +111,7 @@ static PyObject *M_Metaball_Get(PyObject *self, PyObject *args)
else { /* () - return a list of all mballs in the scene */ else { /* () - return a list of all mballs in the scene */
int index = 0; int index = 0;
PyObject *mballlist, *pystr; PyObject *mballlist, *pyobj;
mballlist = PyList_New (BLI_countlist (&(G.main->mball))); mballlist = PyList_New (BLI_countlist (&(G.main->mball)));
@@ -120,13 +120,13 @@ static PyObject *M_Metaball_Get(PyObject *self, PyObject *args)
"couldn't create PyList")); "couldn't create PyList"));
while (mball_iter) { while (mball_iter) {
pystr = PyString_FromString (mball_iter->id.name+2); pyobj = Metaball_CreatePyObject (mball_iter);
if (!pystr) if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString")); "couldn't create PyString"));
PyList_SET_ITEM (mballlist, index, pystr); PyList_SET_ITEM (mballlist, index, pyobj);
mball_iter = mball_iter->id.next; mball_iter = mball_iter->id.next;
index++; index++;
@@ -1039,3 +1039,44 @@ static PyObject *MetaballRepr (C_Metaball *self)
return PyString_FromString(self->metaball->id.name+2); return PyString_FromString(self->metaball->id.name+2);
} }
/* Three Python Metaball_Type helper functions needed by the Object module: */
/*****************************************************************************/
/* Function: Metaball_CreatePyObject */
/* Description: This function will create a new C_Metaball from an existing */
/* Blender metaball structure. */
/*****************************************************************************/
PyObject *Metaball_CreatePyObject (MetaBall *metaball)
{
C_Metaball *pymetaball;
pymetaball = (C_Metaball *)PyObject_NEW (C_Metaball, &Metaball_Type);
if (!pymetaball)
return EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create C_Metaball object");
pymetaball->metaball = metaball;
return (PyObject *)pymetaball;
}
/*****************************************************************************/
/* Function: Metaball_CheckPyObject */
/* Description: This function returns true when the given PyObject is of the */
/* type Metaball. Otherwise it will return false. */
/*****************************************************************************/
int Metaball_CheckPyObject (PyObject *pyobj)
{
return (pyobj->ob_type == &Metaball_Type);
}
/*****************************************************************************/
/* Function: Metaball_FromPyObject */
/* Description: This function returns the Blender metaball from the given */
/* PyObject. */
/*****************************************************************************/
MetaBall *Metaball_FromPyObject (PyObject *pyobj)
{
return ((C_Metaball *)pyobj)->metaball;
}

View File

@@ -278,7 +278,7 @@ static PyObject *MetaballRepr (C_Metaball *self);
/*****************************************************************************/ /*****************************************************************************/
/* Python Metaball_Type structure definition: */ /* Python Metaball_Type structure definition: */
/*****************************************************************************/ /*****************************************************************************/
static PyTypeObject Metaball_Type = PyTypeObject Metaball_Type =
{ {
PyObject_HEAD_INIT(&PyType_Type) PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */ 0, /* ob_size */

View File

@@ -46,7 +46,7 @@ void mesh_update(Mesh *mesh)
static void NMCol_dealloc(PyObject *self) static void NMCol_dealloc(PyObject *self)
{ {
PyMem_DEL(self); /* XXX PyObject_Del ?*/ PyObject_DEL(self); /* XXX PyObject_Del ?*/
} }
static C_NMCol *newcol (char r, char g, char b, char a) static C_NMCol *newcol (char r, char g, char b, char a)
@@ -144,7 +144,7 @@ static void NMFace_dealloc (PyObject *self)
Py_DECREF(mf->col); Py_DECREF(mf->col);
Py_XDECREF(mf->image); Py_XDECREF(mf->image);
PyMem_DEL(self); PyObject_DEL(self);
} }
static C_NMFace *new_NMFace(PyObject *vertexlist) static C_NMFace *new_NMFace(PyObject *vertexlist)
@@ -393,7 +393,7 @@ static PyObject *M_NMesh_Vert(PyObject *self, PyObject *args)
static void NMVert_dealloc(PyObject *self) static void NMVert_dealloc(PyObject *self)
{ {
PyMem_DEL(self); PyObject_DEL(self);
} }
static PyObject *NMVert_getattr(PyObject *self, char *name) static PyObject *NMVert_getattr(PyObject *self, char *name)
@@ -545,7 +545,7 @@ static void NMesh_dealloc(PyObject *self)
Py_DECREF(me->verts); Py_DECREF(me->verts);
Py_DECREF(me->faces); Py_DECREF(me->faces);
PyMem_DEL(self); PyObject_DEL(self);
} }
static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args) static PyObject *NMesh_getSelectedFaces(PyObject *self, PyObject *args)

View File

@@ -73,7 +73,7 @@ PyTypeObject NMFace_Type;
PyTypeObject NMVert_Type; PyTypeObject NMVert_Type;
PyTypeObject NMCol_Type; PyTypeObject NMCol_Type;
PyTypeObject Image_Type; extern PyTypeObject Image_Type;
/* Globals */ /* Globals */

View File

@@ -567,13 +567,13 @@ static PyObject *Object_getData (C_Object *self)
//#obj_id = MAKE_ID2 (id->name[0], id->name[1]); //#obj_id = MAKE_ID2 (id->name[0], id->name[1]);
switch (self->object->type)//#obj_id) switch (self->object->type)//#obj_id)
{ {
case ID_AR: case OB_ARMATURE://#ID_AR:
data_object = M_ArmatureCreatePyObject (self->object->data); data_object = M_ArmatureCreatePyObject (self->object->data);
break; break;
case OB_CAMERA://#ID_CA: case OB_CAMERA://#ID_CA:
data_object = Camera_CreatePyObject (self->object->data); data_object = Camera_CreatePyObject (self->object->data);
break; break;
case ID_CU: case OB_CURVE://#ID_CU:
data_object = CurveCreatePyObject (self->object->data); data_object = CurveCreatePyObject (self->object->data);
break; break;
case ID_IM: case ID_IM:
@@ -581,12 +581,13 @@ static PyObject *Object_getData (C_Object *self)
break; break;
case ID_IP: case ID_IP:
break; break;
case ID_LA: case OB_LAMP://#ID_LA:
data_object = Lamp_CreatePyObject (self->object->data); data_object = Lamp_CreatePyObject (self->object->data);
break; break;
case ID_MA: case ID_MA:
break; break;
case ID_ME: case OB_MESH://#ID_ME:
data_object = NMesh_CreatePyObject (self->object->data);
break; break;
case ID_OB: case ID_OB:
data_object = M_ObjectCreatePyObject (self->object->data); data_object = M_ObjectCreatePyObject (self->object->data);
@@ -1291,7 +1292,7 @@ static PyObject* ObjectGetAttr (C_Object *obj, char *name)
if (StringEqual (name, "drawMode")) if (StringEqual (name, "drawMode"))
return (Py_BuildValue ("b", object->dtx)); return (Py_BuildValue ("b", object->dtx));
/* not an attribute, search the methods table */ /* not an attribute, search the methods table */
return Py_FindMethod(C_Object_methods, (PyObject *)obj, name); return Py_FindMethod(C_Object_methods, (PyObject *)obj, name);
} }

View File

@@ -295,30 +295,30 @@ static PyObject *M_Scene_Get(PyObject *self, PyObject *args)
return wanted_scene; return wanted_scene;
} }
else { /* () - return a list of all scenes in Blender */ else { /* () - return a list with wrappers for all scenes in Blender */
int index = 0; int index = 0;
PyObject *scenelist, *pystr; PyObject *sce_pylist, *pyobj;
scenelist = PyList_New (BLI_countlist (&(G.main->scene))); sce_pylist = PyList_New (BLI_countlist (&(G.main->scene)));
if (scenelist == NULL) if (sce_pylist == NULL)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyList")); "couldn't create PyList"));
while (scene_iter) { while (scene_iter) {
pystr = PyString_FromString (scene_iter->id.name+2); pyobj = Scene_CreatePyObject (scene_iter);
if (!pystr) if (!pyobj)
return (PythonReturnErrorObject (PyExc_MemoryError, return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString")); "couldn't create PyString"));
PyList_SET_ITEM (scenelist, index, pystr); PyList_SET_ITEM (sce_pylist, index, pyobj);
scene_iter = scene_iter->id.next; scene_iter = scene_iter->id.next;
index++; index++;
} }
return scenelist; return sce_pylist;
} }
} }

View File

@@ -51,7 +51,7 @@
#define EXPP_TEXT_MODE_FOLLOW TXT_FOLLOW #define EXPP_TEXT_MODE_FOLLOW TXT_FOLLOW
/*****************************************************************************/ /*****************************************************************************/
/* Python API function prototypes for the Text module. */ /* Python API function prototypes for the Text module. */
/*****************************************************************************/ /*****************************************************************************/
static PyObject *M_Text_New (PyObject *self, PyObject *args, static PyObject *M_Text_New (PyObject *self, PyObject *args,
PyObject *keywords); PyObject *keywords);
@@ -62,7 +62,7 @@ static PyObject *M_Text_unlink (PyObject *self, PyObject *args);
/*****************************************************************************/ /*****************************************************************************/
/* The following string definitions are used for documentation strings. */ /* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */ /* In Python these will be written to the console when doing a */
/* Blender.Text.__doc__ */ /* Blender.Text.__doc__ */
/*****************************************************************************/ /*****************************************************************************/
static char M_Text_doc[] = static char M_Text_doc[] =
"The Blender Text module\n\n"; "The Blender Text module\n\n";
@@ -83,7 +83,7 @@ static char M_Text_unlink_doc[] =
"(text) - remove text object 'text' from the text window"; "(text) - remove text object 'text' from the text window";
/*****************************************************************************/ /*****************************************************************************/
/* Python method structure definition for Blender.Text module: */ /* Python method structure definition for Blender.Text module: */
/*****************************************************************************/ /*****************************************************************************/
struct PyMethodDef M_Text_methods[] = { struct PyMethodDef M_Text_methods[] = {
{"New",(PyCFunction)M_Text_New, METH_VARARGS|METH_KEYWORDS, {"New",(PyCFunction)M_Text_New, METH_VARARGS|METH_KEYWORDS,
@@ -96,15 +96,16 @@ struct PyMethodDef M_Text_methods[] = {
}; };
/*****************************************************************************/ /*****************************************************************************/
/* Python C_Text structure definition: */ /* Python C_Text structure definition: */
/*****************************************************************************/ /*****************************************************************************/
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD
Text *text; Text *text;
} C_Text; } C_Text;
/*****************************************************************************/ /*****************************************************************************/
/* Python C_Text methods declarations: */ /* Python C_Text methods declarations: */
/*****************************************************************************/ /*****************************************************************************/
static PyObject *Text_getName(C_Text *self); static PyObject *Text_getName(C_Text *self);
static PyObject *Text_getFilename(C_Text *self); static PyObject *Text_getFilename(C_Text *self);
@@ -116,7 +117,7 @@ static PyObject *Text_set(C_Text *self, PyObject *args);
static PyObject *Text_asLines(C_Text *self, PyObject *args); static PyObject *Text_asLines(C_Text *self, PyObject *args);
/*****************************************************************************/ /*****************************************************************************/
/* Python C_Text methods table: */ /* Python C_Text methods table: */
/*****************************************************************************/ /*****************************************************************************/
static PyMethodDef C_Text_methods[] = { static PyMethodDef C_Text_methods[] = {
/* name, method, flags, doc */ /* name, method, flags, doc */
@@ -140,7 +141,7 @@ static PyMethodDef C_Text_methods[] = {
}; };
/*****************************************************************************/ /*****************************************************************************/
/* Python Text_Type callback function prototypes: */ /* Python Text_Type callback function prototypes: */
/*****************************************************************************/ /*****************************************************************************/
static void TextDeAlloc (C_Text *self); static void TextDeAlloc (C_Text *self);
static int TextPrint (C_Text *self, FILE *fp, int flags); static int TextPrint (C_Text *self, FILE *fp, int flags);
@@ -150,7 +151,7 @@ static int TextCompare (C_Text *a, C_Text *b);
static PyObject *TextRepr (C_Text *self); static PyObject *TextRepr (C_Text *self);
/*****************************************************************************/ /*****************************************************************************/
/* Python Text_Type structure definition: */ /* Python Text_Type structure definition: */
/*****************************************************************************/ /*****************************************************************************/
PyTypeObject Text_Type = PyTypeObject Text_Type =
{ {

View File

@@ -40,35 +40,50 @@ PyObject *M_Types_Init (void)
{ {
PyObject *submodule, *dict; PyObject *submodule, *dict;
submodule = Py_InitModule3("Blender.Types", Null_methods, M_Types_doc); /* These are only set when some object initializes them. But unless we
* do it now, we get two easy ways to crash Blender. Maybe we'd better
* have an Init function for all these internal types that more than one
* module can use. We could call it after setting the Blender dictionary */
vector_Type.ob_type = &PyType_Type;
rgbTuple_Type.ob_type = &PyType_Type;
constant_Type.ob_type = &PyType_Type;
dict = PyModule_GetDict(submodule); submodule = Py_InitModule3 ("Blender.Types", Null_methods, M_Types_doc);
dict = PyModule_GetDict(submodule);
/* The Blender Object Type */ /* The Blender Object Type */
PyDict_SetItemString(dict, "ObjectType", (PyObject *)&Object_Type); PyDict_SetItemString(dict, "ObjectType", (PyObject *)&Object_Type);
/* Blender Object Data Types */ /* Blender Object Data Types */
PyDict_SetItemString(dict, "NMeshType", (PyObject *)&NMesh_Type); PyDict_SetItemString(dict, "NMeshType", (PyObject *)&NMesh_Type);
PyDict_SetItemString(dict, "NMFaceType", (PyObject *)&NMFace_Type); PyDict_SetItemString(dict, "NMFaceType", (PyObject *)&NMFace_Type);
PyDict_SetItemString(dict, "NMVertType", (PyObject *)&NMVert_Type); PyDict_SetItemString(dict, "NMVertType", (PyObject *)&NMVert_Type);
PyDict_SetItemString(dict, "NMColType", (PyObject *)&NMCol_Type); PyDict_SetItemString(dict, "NMColType", (PyObject *)&NMCol_Type);
PyDict_SetItemString(dict, "CameraType", (PyObject *)&Camera_Type); PyDict_SetItemString(dict, "ArmatureType", (PyObject *)&Armature_Type);
PyDict_SetItemString(dict, "ImageType", (PyObject *)&Image_Type); PyDict_SetItemString(dict, "BoneType", (PyObject *)&Bone_Type);
PyDict_SetItemString(dict, "LampType", (PyObject *)&Lamp_Type);
PyDict_SetItemString(dict, "TextType", (PyObject *)&Text_Type);
PyDict_SetItemString(dict, "ButtonType", (PyObject *)&Button_Type); PyDict_SetItemString(dict, "CurveType", (PyObject *)&Curve_Type);
PyDict_SetItemString(dict, "MaterialType",(PyObject *)&Material_Type); PyDict_SetItemString(dict, "IpoType", (PyObject *)&Ipo_Type);
PyDict_SetItemString(dict, "MetaballType", (PyObject *)&Metaball_Type);
PyDict_SetItemString(dict, "CameraType", (PyObject *)&Camera_Type);
PyDict_SetItemString(dict, "ImageType", (PyObject *)&Image_Type);
PyDict_SetItemString(dict, "LampType", (PyObject *)&Lamp_Type);
PyDict_SetItemString(dict, "TextType", (PyObject *)&Text_Type);
PyDict_SetItemString(dict, "MaterialType", (PyObject *)&Material_Type);
PyDict_SetItemString(dict, "ButtonType", (PyObject *)&Button_Type);
/* External helper Types available to the main ones above */ /* External helper Types available to the main ones above */
PyDict_SetItemString(dict, "vectorType", (PyObject *)&vector_Type); PyDict_SetItemString(dict, "vectorType", (PyObject *)&vector_Type);
PyDict_SetItemString(dict, "bufferType", (PyObject *)&buffer_Type); PyDict_SetItemString(dict, "bufferType", (PyObject *)&buffer_Type);
PyDict_SetItemString(dict, "constantType", (PyObject *)&constant_Type); PyDict_SetItemString(dict, "constantType", (PyObject *)&constant_Type);
PyDict_SetItemString(dict, "rgbTupleType", (PyObject *)&rgbTuple_Type); PyDict_SetItemString(dict, "rgbTupleType", (PyObject *)&rgbTuple_Type);
return (submodule); return submodule;
} }

View File

@@ -39,6 +39,8 @@ extern PyTypeObject Button_Type, Material_Type;
extern PyTypeObject Object_Type; extern PyTypeObject Object_Type;
extern PyTypeObject NMesh_Type, NMFace_Type, NMVert_Type, NMCol_Type; extern PyTypeObject NMesh_Type, NMFace_Type, NMVert_Type, NMCol_Type;
extern PyTypeObject Camera_Type, Lamp_Type, Image_Type, Text_Type; extern PyTypeObject Camera_Type, Lamp_Type, Image_Type, Text_Type;
extern PyTypeObject Armature_Type, Bone_Type;
extern PyTypeObject Curve_Type, Ipo_Type, Metaball_Type;
extern PyTypeObject vector_Type, buffer_Type, rgbTuple_Type, extern PyTypeObject vector_Type, buffer_Type, rgbTuple_Type,
constant_Type; constant_Type;

View File

@@ -39,7 +39,7 @@
static void Vector_dealloc(VectorObject *self) static void Vector_dealloc(VectorObject *self)
{ {
PyMem_DEL(self); PyObject_DEL (self);
} }
static PyObject *Vector_getattr(VectorObject *self, char *name) static PyObject *Vector_getattr(VectorObject *self, char *name)
@@ -195,7 +195,7 @@ PyTypeObject vector_Type =
{ {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"Vector", /*tp_name*/ "vector", /*tp_name*/
sizeof(VectorObject), /*tp_basicsize*/ sizeof(VectorObject), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
/* methods */ /* methods */
@@ -213,7 +213,7 @@ PyObject *newVectorObject(float *vec, int size)
{ {
VectorObject *self; VectorObject *self;
vector_Type.ob_type = &PyType_Type; vector_Type.ob_type = &PyType_Type;
self= PyObject_NEW(VectorObject, &vector_Type); self= PyObject_NEW(VectorObject, &vector_Type);