The following updates have been contributed by Willian P. Germano:

* Implemented BPY_end_python function.
* Implemented error handling. This results in rerunning a script after an
  error has occurred. No need to restart blender anymore.
* Camera module supports dir()
* variable assignment now calls the Python equivalent function - this has
  type checking and should be safer now.
* Implemented the Lamp module. Used the Camera module as a template.
* Implemented the Image module.
* Added EXPP_ClampFloat and EXPP_intError functions to gen_utils.[ch]
* Implemented 'constant' object.
This commit is contained in:
Michel Selten 2003-04-08 19:54:14 +00:00
parent 0850182872
commit ec669df6ee
13 changed files with 3585 additions and 209 deletions

@ -24,7 +24,7 @@
*
* This is a new part of Blender.
*
* Contributor(s): Michel Selten
* Contributor(s): Michel Selten, Willian P. Germano
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
@ -96,12 +96,12 @@ void BPY_start_python(void)
}
/*****************************************************************************/
/* Description: */
/* Notes: Not implemented yet */
/* Description: This function will terminate the Python interpreter */
/*****************************************************************************/
void BPY_end_python(void)
{
printf ("In BPY_end_python\n");
Py_Finalize();
return;
}
@ -145,6 +145,15 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
/* dict = newGlobalDictionary(); */
ret = RunPython (st->text, dict);
/* If errors have occurred, set the error filename to the name of the
script.
*/
if (!ret)
{
sprintf(g_script_error.filename, "%s", st->text->id.name+2);
return NULL;
}
return dict;
}
@ -307,6 +316,17 @@ PyObject * RunPython(Text *text, PyObject *globaldict)
buf = txt_to_buf(text);
ret = PyRun_String (buf, Py_file_input, globaldict, globaldict);
if (!ret)
{
/* an exception was raised, handle it here */
PyErr_Print(); /* this function also clears the error
indicator */
}
else
{
PyErr_Clear(); /* seems necessary, at least now */
}
MEM_freeN (buf);
return ret;
}

@ -241,6 +241,8 @@ void initBlender (void)
dict = PyModule_GetDict (module);
g_blenderdict = dict;
PyDict_SetItemString (dict, "Object", initObject());
PyDict_SetItemString (dict, "Camera", initCamera());
PyDict_SetItemString (dict, "Camera", M_Camera_Init());
PyDict_SetItemString (dict, "Lamp", M_Lamp_Init());
PyDict_SetItemString (dict, "Image", M_Image_Init());
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,228 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef EXPP_CAMERA_H
#define EXPP_CAMERA_H
#include <Python.h>
#include <stdio.h>
#include <BKE_main.h>
#include <BKE_global.h>
#include <BKE_object.h>
#include <BKE_library.h>
#include <DNA_camera_types.h>
#include "constant.h"
#include "gen_utils.h"
#include "modules.h"
/*****************************************************************************/
/* Python C_Camera defaults: */
/*****************************************************************************/
/* Camera types */
#define EXPP_CAM_TYPE_PERSP 0
#define EXPP_CAM_TYPE_ORTHO 1
/* Camera mode flags */
#define EXPP_CAM_MODE_SHOWLIMITS 1
#define EXPP_CAM_MODE_SHOWMIST 2
/* Camera default and MIN, MAX values */
#define EXPP_CAM_TYPE EXPP_CAM_TYPE_PERSP
#define EXPP_CAM_MODE 0
#define EXPP_CAM_LENS 35.0
#define EXPP_CAM_LENS_MIN 1.0
#define EXPP_CAM_LENS_MAX 250.0
#define EXPP_CAM_CLIPSTART 0.10
#define EXPP_CAM_CLIPSTART_MIN 0.00
#define EXPP_CAM_CLIPSTART_MAX 100.00
#define EXPP_CAM_CLIPEND 100.0
#define EXPP_CAM_CLIPEND_MIN 1.0
#define EXPP_CAM_CLIPEND_MAX 5000.0
#define EXPP_CAM_DRAWSIZE 0.5
#define EXPP_CAM_DRAWSIZE_MIN 0.1
#define EXPP_CAM_DRAWSIZE_MAX 10.0
/*****************************************************************************/
/* Python API function prototypes for the Camera module. */
/*****************************************************************************/
static PyObject *M_Camera_New (PyObject *self, PyObject *args,
PyObject *keywords);
static PyObject *M_Camera_Get (PyObject *self, PyObject *args);
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.Camera.__doc__ */
/*****************************************************************************/
char M_Camera_doc[] =
"The Blender Camera module\n\n\
This module provides access to **Camera Data** objects in Blender\n\n\
Example::\n\n\
from Blender import Camera, Object, Scene\n\
c = Camera.New('ortho') # create new ortho camera data\n\
c.lens = 35.0 # set lens value\n\
cur = Scene.getCurrent() # get current Scene\n\
ob = Object.New('Camera') # make camera object\n\
ob.link(c) # link camera data with this object\n\
cur.link(ob) # link object into scene\n\
cur.setCurrentCamera(ob) # make this camera the active\n";
char M_Camera_New_doc[] =
"(type) - return a new Camera object of type \"type\", \
which can be 'persp' or 'ortho'.\n\
() - return a new Camera object of type 'persp'.";
char M_Camera_Get_doc[] =
"(name) - return the camera with the name 'name', \
returns None if not found.\n If 'name' is not specified, \
it returns a list of all cameras in the\ncurrent scene.";
/*****************************************************************************/
/* Python method structure definition for Blender.Camera module: */
/*****************************************************************************/
struct PyMethodDef M_Camera_methods[] = {
{"New",(PyCFunction)M_Camera_New, METH_VARARGS|METH_KEYWORDS,
M_Camera_New_doc},
{"Get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
{"get", M_Camera_Get, METH_VARARGS, M_Camera_Get_doc},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python C_Camera structure definition: */
/*****************************************************************************/
typedef struct {
PyObject_HEAD
PyObject *dict;
Camera *camera;
int linked;
} C_Camera;
/*****************************************************************************/
/* Python C_Camera methods declarations: */
/*****************************************************************************/
static PyObject *Camera_getName(C_Camera *self);
static PyObject *Camera_getType(C_Camera *self);
static PyObject *Camera_getMode(C_Camera *self);
static PyObject *Camera_getLens(C_Camera *self);
static PyObject *Camera_getClipStart(C_Camera *self);
static PyObject *Camera_getClipEnd(C_Camera *self);
static PyObject *Camera_getDrawSize(C_Camera *self);
static PyObject *Camera_rename(C_Camera *self, PyObject *args);
static PyObject *Camera_setType(C_Camera *self, PyObject *args);
static PyObject *Camera_setIntType(C_Camera *self, PyObject *args);
static PyObject *Camera_setMode(C_Camera *self, PyObject *args);
static PyObject *Camera_setIntMode(C_Camera *self, PyObject *args);
static PyObject *Camera_setLens(C_Camera *self, PyObject *args);
static PyObject *Camera_setClipStart(C_Camera *self, PyObject *args);
static PyObject *Camera_setClipEnd(C_Camera *self, PyObject *args);
static PyObject *Camera_setDrawSize(C_Camera *self, PyObject *args);
/*****************************************************************************/
/* Python C_Camera methods table: */
/*****************************************************************************/
static PyMethodDef C_Camera_methods[] = {
/* name, method, flags, doc */
{"getName", (PyCFunction)Camera_getName, METH_NOARGS,
"() - Return Camera Data name"},
{"getType", (PyCFunction)Camera_getType, METH_NOARGS,
"() - Return Camera type - 'persp':0, 'ortho':1"},
{"getMode", (PyCFunction)Camera_getMode, METH_NOARGS,
"() - Return Camera mode flags (or'ed value) -\n\t\
'showLimits':1, 'showMist':2"},
{"getLens", (PyCFunction)Camera_getLens, METH_NOARGS,
"() - Return Camera lens value"},
{"getClipStart", (PyCFunction)Camera_getClipStart, METH_NOARGS,
"() - Return Camera clip start value"},
{"getClipEnd", (PyCFunction)Camera_getClipEnd, METH_NOARGS,
"() - Return Camera clip end value"},
{"getDrawSize", (PyCFunction)Camera_getDrawSize, METH_NOARGS,
"() - Return Camera draw size value"},
{"rename", (PyCFunction)Camera_rename, METH_VARARGS,
"(str) - Change Camera Data name"},
{"setType", (PyCFunction)Camera_setType, METH_VARARGS,
"(str) - Change Camera type, which can be 'persp' or 'ortho'"},
{"setMode", (PyCFunction)Camera_setMode, METH_VARARGS,
"([str[,str]]) - Set Camera mode flag(s): 'showLimits' and 'showMist'"},
{"setLens", (PyCFunction)Camera_setLens, METH_VARARGS,
"(float) - Change Camera lens value"},
{"setClipStart", (PyCFunction)Camera_setClipStart, METH_VARARGS,
"(float) - Change Camera clip start value"},
{"setClipEnd", (PyCFunction)Camera_setClipEnd, METH_VARARGS,
"(float) - Change Camera clip end value"},
{"setDrawSize", (PyCFunction)Camera_setDrawSize, METH_VARARGS,
"(float) - Change Camera draw size value"},
{0}
};
/*****************************************************************************/
/* Python Camera_Type callback function prototypes: */
/*****************************************************************************/
static void CameraDeAlloc (C_Camera *cam);
static int CameraPrint (C_Camera *cam, FILE *fp, int flags);
static int CameraSetAttr (C_Camera *cam, char *name, PyObject *v);
static PyObject *CameraGetAttr (C_Camera *cam, char *name);
static PyObject *CameraRepr (C_Camera *cam);
/*****************************************************************************/
/* Python Camera_Type structure definition: */
/*****************************************************************************/
static PyTypeObject Camera_Type =
{
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
"Camera", /* tp_name */
sizeof (C_Camera), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)CameraDeAlloc, /* tp_dealloc */
(printfunc)CameraPrint, /* tp_print */
(getattrfunc)CameraGetAttr, /* tp_getattr */
(setattrfunc)CameraSetAttr, /* tp_setattr */
0, /* tp_compare */
(reprfunc)CameraRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_hash */
0,0,0,0,0,0,
0, /* tp_doc */
0,0,0,0,0,0,
C_Camera_methods, /* tp_methods */
0, /* tp_members */
};
#endif /* EXPP_CAMERA_H */

@ -0,0 +1,425 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "Image.h"
/*****************************************************************************/
/* Function: M_Image_New */
/* Python equivalent: Blender.Image.New */
/*****************************************************************************/
static PyObject *M_Image_New(PyObject *self, PyObject *args, PyObject *keywords)
{
printf ("In Image_New() - unimplemented in 2.25\n");
Py_INCREF(Py_None);
return Py_None;
}
/*****************************************************************************/
/* Function: M_Image_Get */
/* Python equivalent: Blender.Image.Get */
/*****************************************************************************/
static PyObject *M_Image_Get(PyObject *self, PyObject *args)
{
char *name;
Image *img_iter;
C_Image *wanted_img;
printf ("In Image_Get()\n");
if (!PyArg_ParseTuple(args, "s", &name))
{
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected string argument"));
}
/* Use the name to search for the image requested. */
wanted_img = NULL;
img_iter = G.main->image.first;
while ((img_iter) && (wanted_img == NULL)) {
if (strcmp (name, GetIdName (&(img_iter->id))) == 0)
wanted_img = (C_Image *)ImageCreatePyObject(img_iter);
img_iter = img_iter->id.next;
}
if (wanted_img == NULL) {
/* No image exists with the name specified in the argument name. */
char error_msg[64];
PyOS_snprintf(error_msg, sizeof(error_msg),
"Image \"%s\" not found", name);
return (PythonReturnErrorObject (PyExc_NameError, error_msg));
}
return ((PyObject*)wanted_img);
}
static PyObject *M_Image_Load(PyObject *self, PyObject *args)
{
char *fname;
Image *img_ptr;
C_Image *img;
printf ("In Image_Load()\n");
if (!PyArg_ParseTuple(args, "s", &fname))
{
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected string argument"));
}
img_ptr = add_image(fname);
if (!img_ptr)
return (PythonReturnErrorObject (PyExc_IOError,
"couldn't load image"));
img = (C_Image *)ImageCreatePyObject(img_ptr);
return (PyObject *)img;
}
/*****************************************************************************/
/* Function: M_Image_Init */
/*****************************************************************************/
PyObject *M_Image_Init (void)
{
PyObject *module;
printf ("In M_Image_Init()\n");
module = Py_InitModule3("Image", M_Image_methods, M_Image_doc);
return (module);
}
/*****************************************************************************/
/* Python C_Image methods: */
/*****************************************************************************/
static PyObject *Image_getName(C_Image *self)
{
PyObject *attr;
attr = PyDict_GetItemString(self->dict, "name");
if (attr) {
Py_INCREF(attr);
return attr;
}
return (PythonReturnErrorObject (PyExc_RuntimeError,
"couldn't get Image.name attribute"));
}
static PyObject *Image_getFilename(C_Image *self)
{
PyObject *attr;
attr = PyDict_GetItemString(self->dict, "filename");
if (attr) {
Py_INCREF(attr);
return attr;
}
return (PythonReturnErrorObject (PyExc_RuntimeError,
"couldn't get Image.filename attribute"));
}
static PyObject *Image_rename(C_Image *self, PyObject *args)
{
char *name_str;
char buf[21];
ID *tmp_id;
PyObject *name;
if (!PyArg_ParseTuple(args, "s", &name_str))
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected string argument"));
PyOS_snprintf(buf, sizeof(buf), "%s", name_str);
/* update the Blender Image, too */
tmp_id = &self->image->id;
rename_id(tmp_id, buf);
PyOS_snprintf(buf, sizeof(buf), "%s", tmp_id->name+2);/* may have changed */
name = PyString_FromString(buf);
if (!name)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyString Object"));
if (PyDict_SetItemString(self->dict, "name", name) != 0) {
Py_DECREF(name);
return (PythonReturnErrorObject (PyExc_RuntimeError,
"couldn't set Image.name attribute"));
}
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *Image_setXRep(C_Image *self, PyObject *args)
{
short value;
PyObject *rep;
if (!PyArg_ParseTuple(args, "h", &value))
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected int argument in [1,16]"));
if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
rep = PyInt_FromLong(value);
else
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected int argument in [1,16]"));
if (!rep)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyInt Object"));
if (PyDict_SetItemString(self->dict, "xrep", rep) != 0) {
Py_DECREF(rep);
return (PythonReturnErrorObject (PyExc_RuntimeError,
"could not set Image.xrep attribute"));
}
/* update the Blender Image, too */
self->image->xrep = value;
Py_INCREF(Py_None);
return Py_None;
}
static PyObject *Image_setYRep(C_Image *self, PyObject *args)
{
short value;
PyObject *rep;
if (!PyArg_ParseTuple(args, "h", &value))
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected int argument in [1,16]"));
if (value >= EXPP_IMAGE_REP_MIN || value <= EXPP_IMAGE_REP_MAX)
rep = PyInt_FromLong(value);
else
return (PythonReturnErrorObject (PyExc_AttributeError,
"expected int argument in [1,16]"));
if (!rep)
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create PyInt Object"));
if (PyDict_SetItemString(self->dict, "yrep", rep) != 0) {
Py_DECREF(rep);
return (PythonReturnErrorObject (PyExc_RuntimeError,
"could not set Image.yrep attribute"));
}
/* update the Blender Image, too */
self->image->yrep = value;
Py_INCREF(Py_None);
return Py_None;
}
/*****************************************************************************/
/* Function: ImageCreatePyObject */
/* Description: This function will create a new C_Image. If the Image */
/* struct passed to it is not NULL, it'll use its attributes. */
/*****************************************************************************/
PyObject *ImageCreatePyObject (Image *blenderImage)
{
PyObject *name, *filename, *xrep, *yrep;
C_Image *img;
printf ("In ImageCreatePyObject\n");
img = (C_Image *)PyObject_NEW(C_Image, &Image_Type);
if (img == NULL)
return NULL;
img->dict = PyDict_New();
if (img->dict == NULL) {
Py_DECREF((PyObject *)img);
return NULL;
}
/*branch currently unused*/
if (blenderImage == NULL) { /* Not linked to an Image Object yet */
name = PyString_FromString("DATA");
filename = PyString_FromString("");
xrep = PyInt_FromLong(EXPP_IMAGE_REP); /* rep default is 1, of course */
yrep = PyInt_FromLong(EXPP_IMAGE_REP);
}
else { /* Image Object available, get its attributes directly */
name = PyString_FromString(blenderImage->id.name+2);
filename = PyString_FromString(blenderImage->name);
xrep = PyInt_FromLong(blenderImage->xrep);
yrep = PyInt_FromLong(blenderImage->yrep);
}
if (name == NULL || filename == NULL ||
xrep == NULL || yrep == NULL)
goto fail;
if ((PyDict_SetItemString(img->dict, "name", name) != 0) ||
(PyDict_SetItemString(img->dict, "filename", filename) != 0) ||
(PyDict_SetItemString(img->dict, "xrep", xrep) != 0) ||
(PyDict_SetItemString(img->dict, "yrep", yrep) != 0) ||
(PyDict_SetItemString(img->dict, "__members__",
PyDict_Keys(img->dict)) != 0))
goto fail;
img->image = blenderImage; /* it's NULL when creating only image "data" */
return ((PyObject*)img);
fail:
Py_XDECREF(name);
Py_XDECREF(filename);
Py_XDECREF(xrep);
Py_XDECREF(yrep);
Py_DECREF(img->dict);
Py_DECREF((PyObject *)img);
return NULL;
}
/*****************************************************************************/
/* Function: ImageDeAlloc */
/* Description: This is a callback function for the C_Image type. It is */
/* the destructor function. */
/*****************************************************************************/
static void ImageDeAlloc (C_Image *self)
{
Py_DECREF(self->dict);
PyObject_DEL (self);
}
/*****************************************************************************/
/* Function: ImageGetAttr */
/* Description: This is a callback function for the C_Image type. It is */
/* the function that accesses C_Image member variables and */
/* methods. */
/*****************************************************************************/
static PyObject* ImageGetAttr (C_Image *img, char *name)
{/* first try the attributes dictionary */
if (img->dict) {
PyObject *v = PyDict_GetItemString(img->dict, name);
if (v) {
Py_INCREF(v); /* was a borrowed ref */
return v;
}
}
/* not an attribute, search the methods table */
return Py_FindMethod(C_Image_methods, (PyObject *)img, name);
}
/*****************************************************************************/
/* Function: ImageSetAttr */
/* Description: This is a callback function for the C_Image type. It is the */
/* function that changes Image Data members values. If this */
/* data is linked to a Blender Image, it also gets updated. */
/*****************************************************************************/
static int ImageSetAttr (C_Image *self, char *name, PyObject *value)
{
PyObject *valtuple;
PyObject *error = NULL;
if (self->dict == NULL) return -1;
/* We're playing a trick on the Python API users here. Even if they use
* Image.member = val instead of Image.setMember(value), we end up using the
* function anyway, since it already has error checking, clamps to the right
* interval and updates the Blender Image structure when necessary. */
valtuple = PyTuple_New(1); /* the set* functions expect a tuple */
if (!valtuple)
return EXPP_intError(PyExc_MemoryError,
"ImageSetAttr: couldn't create PyTuple");
if (PyTuple_SetItem(valtuple, 0, value) != 0) {
Py_DECREF(value); /* PyTuple_SetItem incref's value even when it fails */
Py_DECREF(valtuple);
return EXPP_intError(PyExc_RuntimeError,
"ImageSetAttr: couldn't fill tuple");
}
if (strcmp (name, "name") == 0)
error = Image_rename (self, valtuple);
else if (strcmp (name, "xrep") == 0)
error = Image_setXRep (self, valtuple);
else if (strcmp (name, "yrep") == 0)
error = Image_setYRep (self, valtuple);
else { /* Error: no such member in the Image Data structure */
Py_DECREF(value);
Py_DECREF(valtuple);
return (EXPP_intError (PyExc_KeyError,
"attribute not found or immutable"));
}
if (error == Py_None) return 0; /* normal exit */
Py_DECREF(value);
Py_DECREF(valtuple);
return -1;
}
/*****************************************************************************/
/* Function: ImagePrint */
/* Description: This is a callback function for the C_Image type. It */
/* builds a meaninful string to 'print' image objects. */
/*****************************************************************************/
static int ImagePrint(C_Image *self, FILE *fp, int flags)
{
char *name;
name = PyString_AsString(Image_getName(self));
fprintf(fp, "[Image \"%s\"]", name);
return 0;
}
/*****************************************************************************/
/* Function: ImageRepr */
/* Description: This is a callback function for the C_Image type. It */
/* builds a meaninful string to represent image objects. */
/*****************************************************************************/
static PyObject *ImageRepr (C_Image *self)
{
char buf[64];
char *name;
name = PyString_AsString(Image_getName(self));
PyOS_snprintf(buf, sizeof(buf), "[Image \"%s\"]", name);
return PyString_FromString(buf);
}

@ -0,0 +1,167 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef EXPP_IMAGE_H
#define EXPP_IMAGE_H
#include <Python.h>
#include <stdio.h>
#include <BKE_main.h>
#include <BKE_global.h>
#include <BKE_library.h>
#include <BKE_image.h>
#include <DNA_image_types.h>
#include "gen_utils.h"
#include "modules.h"
/*****************************************************************************/
/* Python C_Image defaults: */
/*****************************************************************************/
#define EXPP_IMAGE_REP 1
#define EXPP_IMAGE_REP_MIN 1
#define EXPP_IMAGE_REP_MAX 16
/*****************************************************************************/
/* Python API function prototypes for the Image module. */
/*****************************************************************************/
static PyObject *M_Image_New (PyObject *self, PyObject *args,
PyObject *keywords);
static PyObject *M_Image_Get (PyObject *self, PyObject *args);
static PyObject *M_Image_Load (PyObject *self, PyObject *args);
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.Image.__doc__ */
/*****************************************************************************/
char M_Image_doc[] =
"The Blender Image module\n\n";
char M_Image_New_doc[] =
"() - return a new Image object -- unimplemented";
char M_Image_Get_doc[] =
"(name) - return the camera with the name 'name', \
returns None if not found.\n If 'name' is not specified, \
it returns a list of all cameras in the\ncurrent scene.";
char M_Image_Load_doc[] =
"(filename) - return image from file filename as Image Object, \
returns None if not found.\n";
/*****************************************************************************/
/* Python method structure definition for Blender.Image module: */
/*****************************************************************************/
struct PyMethodDef M_Image_methods[] = {
{"New",(PyCFunction)M_Image_New, METH_VARARGS|METH_KEYWORDS,
M_Image_New_doc},
{"Get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
{"get", M_Image_Get, METH_VARARGS, M_Image_Get_doc},
{"Load", M_Image_Load, METH_VARARGS, M_Image_Load_doc},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python C_Image structure definition: */
/*****************************************************************************/
typedef struct {
PyObject_HEAD
PyObject *dict;
Image *image;
} C_Image;
/*****************************************************************************/
/* Python C_Image methods declarations: */
/*****************************************************************************/
static PyObject *Image_getName(C_Image *self);
static PyObject *Image_getFilename(C_Image *self);
static PyObject *Image_rename(C_Image *self, PyObject *args);
static PyObject *Image_setXRep(C_Image *self, PyObject *args);
static PyObject *Image_setYRep(C_Image *self, PyObject *args);
/*****************************************************************************/
/* Python C_Image methods table: */
/*****************************************************************************/
static PyMethodDef C_Image_methods[] = {
/* name, method, flags, doc */
{"getName", (PyCFunction)Image_getName, METH_NOARGS,
"() - Return Image Data name"},
{"getFilename", (PyCFunction)Image_getFilename, METH_VARARGS,
"() - Return Image Data filename"},
{"rename", (PyCFunction)Image_rename, METH_VARARGS,
"(str) - Change Image Data name"},
{"setXRep", (PyCFunction)Image_setXRep, METH_VARARGS,
"(int) - Change Image Data x repetition value"},
{"setYRep", (PyCFunction)Image_setYRep, METH_VARARGS,
"(int) - Change Image Data y repetition value"},
{0}
};
/*****************************************************************************/
/* Python Image_Type callback function prototypes: */
/*****************************************************************************/
static void ImageDeAlloc (C_Image *cam);
static int ImagePrint (C_Image *cam, FILE *fp, int flags);
static int ImageSetAttr (C_Image *cam, char *name, PyObject *v);
static PyObject *ImageGetAttr (C_Image *cam, char *name);
static PyObject *ImageRepr (C_Image *cam);
/*****************************************************************************/
/* Python Image_Type structure definition: */
/*****************************************************************************/
static PyTypeObject Image_Type =
{
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
"Image", /* tp_name */
sizeof (C_Image), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)ImageDeAlloc, /* tp_dealloc */
(printfunc)ImagePrint, /* tp_print */
(getattrfunc)ImageGetAttr, /* tp_getattr */
(setattrfunc)ImageSetAttr, /* tp_setattr */
0, /* tp_compare */
(reprfunc)ImageRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_hash */
0,0,0,0,0,0,
0, /* tp_doc */
0,0,0,0,0,0,
C_Image_methods, /* tp_methods */
0, /* tp_members */
};
#endif /* EXPP_IMAGE_H */

File diff suppressed because it is too large Load Diff

@ -0,0 +1,312 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef EXPP_LAMP_H
#define EXPP_LAMP_H
#include <Python.h>
#include <stdio.h>
#include <BKE_main.h>
#include <BKE_global.h>
#include <BKE_object.h>
#include <BKE_library.h>
#include <DNA_lamp_types.h>
#include "constant.h"
#include "gen_utils.h"
#include "modules.h"
/*****************************************************************************/
/* Python C_Lamp defaults: */
/*****************************************************************************/
#define EXPP_LAMP_MAX 256
/* Lamp types */
#define EXPP_LAMP_TYPE_LAMP 0
#define EXPP_LAMP_TYPE_SUN 1
#define EXPP_LAMP_TYPE_SPOT 2
#define EXPP_LAMP_TYPE_HEMI 3
/* Lamp mode flags */
#define EXPP_LAMP_MODE_SHADOWS 1
#define EXPP_LAMP_MODE_HALO 2
#define EXPP_LAMP_MODE_LAYER 4
#define EXPP_LAMP_MODE_QUAD 8
#define EXPP_LAMP_MODE_NEGATIVE 16
#define EXPP_LAMP_MODE_ONLYSHADOW 32
#define EXPP_LAMP_MODE_SPHERE 64
#define EXPP_LAMP_MODE_SQUARE 128
#define EXPP_LAMP_MODE_TEXTURE 256
#define EXPP_LAMP_MODE_OSATEX 512
#define EXPP_LAMP_MODE_DEEPSHADOW 1024
/* Lamp default and MIN, MAX values */
#define EXPP_LAMP_TYPE EXPP_LAMP_TYPE_LAMP
#define EXPP_LAMP_MODE EXPP_LAMP_MODE_SHADOWS
#define EXPP_LAMP_SAMPLES 3
#define EXPP_LAMP_SAMPLES_MIN 1
#define EXPP_LAMP_SAMPLES_MAX 16
#define EXPP_LAMP_BUFFERSIZE 512
#define EXPP_LAMP_ENERGY 1.0
#define EXPP_LAMP_ENERGY_MIN 0.0
#define EXPP_LAMP_ENERGY_MAX 10.0
#define EXPP_LAMP_DIST 20.0
#define EXPP_LAMP_DIST_MIN 0.1
#define EXPP_LAMP_DIST_MAX 5000.0
#define EXPP_LAMP_SPOTSIZE 45.0
#define EXPP_LAMP_SPOTSIZE_MIN 1.0
#define EXPP_LAMP_SPOTSIZE_MAX 180.0
#define EXPP_LAMP_SPOTBLEND 0.15
#define EXPP_LAMP_SPOTBLEND_MIN 0.00
#define EXPP_LAMP_SPOTBLEND_MAX 1.00
#define EXPP_LAMP_CLIPSTART 0.5
#define EXPP_LAMP_CLIPSTART_MIN 0.1
#define EXPP_LAMP_CLIPSTART_MAX 1000.0
#define EXPP_LAMP_CLIPEND 40.0
#define EXPP_LAMP_CLIPEND_MIN 1.0
#define EXPP_LAMP_CLIPEND_MAX 5000.0
#define EXPP_LAMP_BIAS 1.00
#define EXPP_LAMP_BIAS_MIN 0.01
#define EXPP_LAMP_BIAS_MAX 5.00
#define EXPP_LAMP_SOFTNESS 3.0
#define EXPP_LAMP_SOFTNESS_MIN 1.0
#define EXPP_LAMP_SOFTNESS_MAX 100.0
#define EXPP_LAMP_HALOINT 1.0
#define EXPP_LAMP_HALOINT_MIN 0.0
#define EXPP_LAMP_HALOINT_MAX 5.0
#define EXPP_LAMP_HALOSTEP 0
#define EXPP_LAMP_HALOSTEP_MIN 0
#define EXPP_LAMP_HALOSTEP_MAX 12
#define EXPP_LAMP_QUAD1 0.0 /* Not implemented yet ( and not in 2.25) */
#define EXPP_LAMP_QUAD1_MIN 0.0
#define EXPP_LAMP_QUAD1_MAX 1.0
#define EXPP_LAMP_QUAD2 1.0
#define EXPP_LAMP_QUAD2_MIN 0.0
#define EXPP_LAMP_QUAD2_MAX 1.0
/*****************************************************************************/
/* Python API function prototypes for the Lamp module. */
/*****************************************************************************/
static PyObject *M_Lamp_New (PyObject *self, PyObject *args, PyObject *keywords);
static PyObject *M_Lamp_Get (PyObject *self, PyObject *args);
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.Lamp.__doc__ */
/*****************************************************************************/
char M_Lamp_doc[] =
"The Blender Lamp module\n\n\
This module provides control over **Lamp Data** objects in Blender.\n\n\
Example::\n\n\
from Blender import Lamp\n\
l = Lamp.New('Spot')\n\
l.setMode('square', 'shadow')\n\
ob = Object.New('Lamp')\n\
ob.link(l)\n";
char M_Lamp_New_doc[] =
"(type, name) - return a new Lamp datablock of type 'type'\n\
and optional name 'name'.";
char M_Lamp_Get_doc[] =
"(name) - return the lamp with the name 'name', \
returns None if not found.\n If 'name' is not specified, \
it returns a list of all lamps in the\ncurrent scene.";
/*****************************************************************************/
/* Python method structure definition for Blender.Lamp module: */
/*****************************************************************************/
struct PyMethodDef M_Lamp_methods[] = {
{"New",(PyCFunction)M_Lamp_New, METH_VARARGS|METH_KEYWORDS,
M_Lamp_New_doc},
{"Get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
{"get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
{NULL, NULL, 0, NULL}
};
/*****************************************************************************/
/* Python C_Lamp structure definition: */
/*****************************************************************************/
typedef struct {
PyObject_HEAD
PyObject *dict;
Lamp *lamp;
int linked;
} C_Lamp;
/*****************************************************************************/
/* Python C_Lamp methods declarations: */
/*****************************************************************************/
static PyObject *Lamp_getName(C_Lamp *self);
static PyObject *Lamp_getType(C_Lamp *self);
static PyObject *Lamp_getMode(C_Lamp *self);
static PyObject *Lamp_getSamples(C_Lamp *self);
static PyObject *Lamp_getBufferSize(C_Lamp *self);
static PyObject *Lamp_getHaloStep(C_Lamp *self);
static PyObject *Lamp_getEnergy(C_Lamp *self);
static PyObject *Lamp_getDist(C_Lamp *self);
static PyObject *Lamp_getSpotSize(C_Lamp *self);
static PyObject *Lamp_getSpotBlend(C_Lamp *self);
static PyObject *Lamp_getClipStart(C_Lamp *self);
static PyObject *Lamp_getClipEnd(C_Lamp *self);
static PyObject *Lamp_getBias(C_Lamp *self);
static PyObject *Lamp_getSoftness(C_Lamp *self);
static PyObject *Lamp_getHaloInt(C_Lamp *self);
static PyObject *Lamp_rename(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setType(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setIntType(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setMode(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setIntMode(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setSamples(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setBufferSize(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setHaloStep(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setEnergy(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setDist(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setSpotSize(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setSpotBlend(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setClipStart(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setClipEnd(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setBias(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setSoftness(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setHaloInt(C_Lamp *self, PyObject *args);
static PyObject *Lamp_setColorComponent(C_Lamp *self, char *key,
PyObject *args);
/*****************************************************************************/
/* Python C_Lamp methods table: */
/*****************************************************************************/
static PyMethodDef C_Lamp_methods[] = {
/* name, method, flags, doc */
{"getName", (PyCFunction)Lamp_getName, METH_NOARGS,
"() - return Lamp name"},
{"getType", (PyCFunction)Lamp_getType, METH_NOARGS,
"() - return Lamp type -\n\t\
'Lamp':0, 'Sun':1, 'Spot':2, 'Hemi':3"},
{"getMode", (PyCFunction)Lamp_getMode, METH_NOARGS,
"() - return Lamp mode flags (or'ed value)"},
{"getSamples", (PyCFunction)Lamp_getSamples, METH_NOARGS,
"() - return Lamp samples value"},
{"getBufferSize", (PyCFunction)Lamp_getBufferSize, METH_NOARGS,
"() - return Lamp buffer size value"},
{"getHaloStep", (PyCFunction)Lamp_getHaloStep, METH_NOARGS,
"() - return Lamp halo step value"},
{"getEnergy", (PyCFunction)Lamp_getEnergy, METH_NOARGS,
"() - return Lamp energy value"},
{"getDist", (PyCFunction)Lamp_getDist, METH_NOARGS,
"() - return Lamp clipping distance value"},
{"getSpotSize", (PyCFunction)Lamp_getSpotSize, METH_NOARGS,
"() - return Lamp spot size value"},
{"getSpotBlend", (PyCFunction)Lamp_getSpotBlend, METH_NOARGS,
"() - return Lamp spot blend value"},
{"getClipStart", (PyCFunction)Lamp_getClipStart, METH_NOARGS,
"() - return Lamp clip start value"},
{"getClipEnd", (PyCFunction)Lamp_getClipEnd, METH_NOARGS,
"() - return Lamp clip end value"},
{"getBias", (PyCFunction)Lamp_getBias, METH_NOARGS,
"() - return Lamp bias value"},
{"getSoftness", (PyCFunction)Lamp_getSoftness, METH_NOARGS,
"() - return Lamp softness value"},
{"getHaloInt", (PyCFunction)Lamp_getHaloInt, METH_NOARGS,
"() - return Lamp halo intensity value"},
{"rename", (PyCFunction)Lamp_rename, METH_VARARGS,
"(str) - rename Lamp"},
{"setType", (PyCFunction)Lamp_setType, METH_VARARGS,
"(str) - change Lamp type, which can be 'persp' or 'ortho'"},
{"setMode", (PyCFunction)Lamp_setMode, METH_VARARGS,
"([up to eight str's]) - Set Lamp mode flag(s)"},
{"setSamples", (PyCFunction)Lamp_setSamples, METH_VARARGS,
"(int) - change Lamp samples value"},
{"setBufferSize", (PyCFunction)Lamp_setBufferSize, METH_VARARGS,
"(int) - change Lamp buffer size value"},
{"setHaloStep", (PyCFunction)Lamp_setHaloStep, METH_VARARGS,
"(int) - change Lamp halo step value"},
{"setEnergy", (PyCFunction)Lamp_setEnergy, METH_VARARGS,
"(float) - change Lamp energy value"},
{"setSpotSize", (PyCFunction)Lamp_setSpotSize, METH_VARARGS,
"(float) - change Lamp spot size value"},
{"setSpotBlend", (PyCFunction)Lamp_setHaloStep, METH_VARARGS,
"(float) - change Lamp spot blend value"},
{"setClipStart", (PyCFunction)Lamp_setClipStart, METH_VARARGS,
"(float) - change Lamp clip start value"},
{"setClipEnd", (PyCFunction)Lamp_setClipEnd, METH_VARARGS,
"(float) - change Lamp clip end value"},
{"setBias", (PyCFunction)Lamp_setBias, METH_VARARGS,
"(float) - change Lamp draw size value"},
{"setSoftness", (PyCFunction)Lamp_setSoftness, METH_VARARGS,
"(float) - change Lamp softness value"},
{"setHaloInt", (PyCFunction)Lamp_setHaloInt, METH_VARARGS,
"(float) - change Lamp halo intensity value"},
{0}
};
/*****************************************************************************/
/* Python TypeLamp callback function prototypes: */
/*****************************************************************************/
static void LampDeAlloc (C_Lamp *lamp);
static PyObject *LampGetAttr (C_Lamp *lamp, char *name);
static int LampSetAttr (C_Lamp *lamp, char *name, PyObject *v);
static PyObject *LampRepr (C_Lamp *lamp);
static int LampPrint (C_Lamp *lamp, FILE *fp, int flags);
/*****************************************************************************/
/* Python TypeLamp structure definition: */
/*****************************************************************************/
static PyTypeObject Lamp_Type =
{
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
"Lamp", /* tp_name */
sizeof (C_Lamp), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)LampDeAlloc, /* tp_dealloc */
(printfunc)LampPrint, /* tp_print */
(getattrfunc)LampGetAttr, /* tp_getattr */
(setattrfunc)LampSetAttr, /* tp_setattr */
0, /* tp_compare */
(reprfunc)LampRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_hash */
0,0,0,0,0,0,
0, /* tp_doc */
0,0,0,0,0,0,
C_Lamp_methods, /* tp_methods */
0, /* tp_members */
};
#endif /* EXPP_LAMP_H */

@ -0,0 +1,212 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "constant.h"
/* This file is heavily based on the old bpython Constant object code in
Blender */
/*****************************************************************************/
/* Python constant_Type callback function prototypes: */
/*****************************************************************************/
static void constantDeAlloc (C_constant *cam);
static PyObject *constantGetAttr (C_constant *cam, char *name);
static PyObject *constantRepr (C_constant *cam);
static int constantLength(C_constant *self);
static PyObject *constantSubscript(C_constant *self, PyObject *key);
static int constantAssSubscript(C_constant *self, PyObject *who,
PyObject *cares);
/*****************************************************************************/
/* Python constant_Type Mapping Methods table: */
/*****************************************************************************/
static PyMappingMethods constantAsMapping =
{
(inquiry)constantLength, /* mp_length */
(binaryfunc)constantSubscript, /* mp_subscript */
(objobjargproc)constantAssSubscript, /* mp_ass_subscript */
};
/*****************************************************************************/
/* Python constant_Type structure definition: */
/*****************************************************************************/
PyTypeObject constant_Type =
{
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
"constant", /* tp_name */
sizeof (C_constant), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)constantDeAlloc, /* tp_dealloc */
0, /* tp_print */
(getattrfunc)constantGetAttr, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
(reprfunc)constantRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
&constantAsMapping, /* tp_as_mapping */
0, /* tp_as_hash */
0,0,0,0,0,0,
0, /* tp_doc */
0,0,0,0,0,0,
0, /* tp_methods */
0, /* tp_members */
};
/*****************************************************************************/
/* Function: constant_New */
/*****************************************************************************/
static PyObject *new_const(void);
PyObject *constant_New(void) /* can't be static, we call it in other files */
{
return new_const();
}
static PyObject *new_const(void)
{ /* ... but this function needs to be static */
C_constant *constant;
printf ("In constant_New()\n");
constant = (C_constant *)PyObject_NEW(C_constant, &constant_Type);
if (constant == NULL)
{
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create constant object"));
}
if ((constant->dict = PyDict_New()) == NULL)
{
return (PythonReturnErrorObject (PyExc_MemoryError,
"couldn't create constant object's dictionary"));
}
return (PyObject *)constant;
}
/*****************************************************************************/
/* Python C_constant methods: */
/*****************************************************************************/
void constant_insert(C_constant *self, char *key, PyObject *value)
{
if (self->dict)
{
PyDict_SetItemString(self->dict, key, value);
}
}
/*****************************************************************************/
/* Function: constantDeAlloc */
/* Description: This is a callback function for the C_constant type. It is */
/* the destructor function. */
/*****************************************************************************/
static void constantDeAlloc (C_constant *self)
{
Py_DECREF(self->dict);
PyObject_DEL (self);
}
/*****************************************************************************/
/* Function: constantGetAttr */
/* Description: This is a callback function for the C_constant type. It is */
/* the function that accesses C_constant member variables and */
/* methods. */
/*****************************************************************************/
static PyObject* constantGetAttr (C_constant *self, char *name)
{
if (self->dict)
{
PyObject *v;
if (!strcmp(name, "__members__"))
{
return PyDict_Keys(self->dict);
}
v = PyDict_GetItemString(self->dict, name);
if (v)
{
Py_INCREF(v); /* was a borrowed ref */
return v;
}
return (PythonReturnErrorObject (PyExc_AttributeError,
"attribute not found"));
}
return (PythonReturnErrorObject (PyExc_RuntimeError,
"constant object lacks a dictionary"));
}
/*****************************************************************************/
/* Section: Sequence Mapping */
/* These functions provide code to access constant objects as */
/* mappings. */
/*****************************************************************************/
static int constantLength(C_constant *self)
{
return 0;
}
static PyObject *constantSubscript(C_constant *self, PyObject *key)
{
if (self->dict)
{
PyObject *v = PyDict_GetItem(self->dict, key);
if (v)
{
Py_INCREF(v);
return v;
}
}
return NULL;
}
static int constantAssSubscript(C_constant *self, PyObject *who,
PyObject *cares)
{
/* no user assignments allowed */
return 0;
}
/*****************************************************************************/
/* Function: constantRepr */
/* Description: This is a callback function for the C_constant type. It */
/* builds a meaninful string to represent constant objects. */
/*****************************************************************************/
static PyObject *constantRepr (C_constant *self)
{
PyObject *repr = PyObject_Repr(self->dict);
return repr;
}

@ -0,0 +1,61 @@
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Willian P. Germano
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef EXPP_constant_H
#define EXPP_constant_H
#include <Python.h>
#include <stdio.h>
#include "gen_utils.h"
/* Objects of <type 'constant'> are instanced inside many other Blender Python
* objects, so this header file must contain only 'public' declarations */
/*****************************************************************************/
/* Python API function prototypes for the constant module. */
/*****************************************************************************/
PyObject *constant_New (void);
/*****************************************************************************/
/* Python C_constant structure definition: */
/*****************************************************************************/
typedef struct {
PyObject_HEAD
PyObject *dict;
} C_constant;
/*****************************************************************************/
/* Python C_constant methods declarations: */
/*****************************************************************************/
void constant_insert(C_constant *self, char *name, PyObject *args);
#endif /* EXPP_constant_H */

@ -39,6 +39,17 @@
#include <DNA_object_types.h>
#include <DNA_scriptlink_types.h>
/*****************************************************************************/
/* Description: This function clamps a float to the given interval */
/* [min, max]. */
/*****************************************************************************/
float EXPP_ClampFloat (float value, float min, float max)
{
if (value < min) return min;
else if (value > max) return max;
return value;
}
/*****************************************************************************/
/* Description: This function returns true if both given strings are equal, */
/* otherwise it returns false. */
@ -58,7 +69,7 @@ char * GetIdName (ID *id)
}
/*****************************************************************************/
/* Description: This function sets an internal string with the given type */
/* Description: These functions set an internal string with the given type */
/* and error_msg arguments. */
/*****************************************************************************/
PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg)
@ -67,6 +78,12 @@ PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg)
return (NULL);
}
int EXPP_intError (PyObject *type, char *error_msg)
{
PyErr_SetString (type, error_msg);
return -1;
}
/*****************************************************************************/
/* Description: This function increments the reference count of the given */
/* Python object. */

@ -38,6 +38,8 @@ char * GetIdName (ID *id);
PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg);
PyObject * PythonIncRef (PyObject *object);
char * event_to_name(short event);
float EXPP_ClampFloat(float value, float min, float max);
int EXPP_intError(PyObject *type, char *error_msg);
/* The following functions may need to be moved to the respective BKE or */
/* DNA modules. */

@ -31,6 +31,9 @@
#include <Python.h>
#include <DNA_object_types.h>
#include <DNA_camera_types.h>
#include <DNA_lamp_types.h>
#include <DNA_image_types.h>
/*****************************************************************************/
/* Global variables */
@ -40,5 +43,9 @@ PyObject *g_blenderdict;
void initBlender (void);
PyObject* initObject (void);
PyObject* ObjectCreatePyObject (struct Object *obj);
PyObject* initCamera (void);
PyObject* M_Camera_Init (void);
PyObject* CameraCreatePyObject (struct Camera *cam);
PyObject* M_Lamp_Init (void);
PyObject* LampCreatePyObject (struct Lamp *lamp);
PyObject* M_Image_Init (void);
PyObject* ImageCreatePyObject (struct Image *img);