* Removed datablock.[ch]
* Object.Get("") should work. * Many variables from module Object are implemented. * Updated build environment to generate more warnings (-Wall) Michel
This commit is contained in:
@@ -33,10 +33,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_global.h>
|
||||
#include <BSE_headerbuttons.h>
|
||||
#include <DNA_ID.h>
|
||||
#include <DNA_object_types.h>
|
||||
#include <DNA_scene_types.h>
|
||||
/* #include <DNA_screen_types.h> */
|
||||
#include <DNA_userdef_types.h>
|
||||
#include <BKE_ipo.h>
|
||||
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
@@ -218,6 +221,7 @@ PyObject *Blender_Redraw(PyObject *self, PyObject *args)
|
||||
|
||||
return Windowmodule_Redraw(self, Py_BuildValue("(i)", wintype));
|
||||
*/
|
||||
return (Py_None);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
@@ -32,6 +32,13 @@
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_main.h>
|
||||
#include <DNA_ika_types.h>
|
||||
#include <DNA_object_types.h>
|
||||
|
||||
#include "gen_utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python API function prototypes for the Blender module. */
|
||||
/*****************************************************************************/
|
||||
@@ -57,6 +64,44 @@ char Object_GetSelected_doc[] =
|
||||
"() - Returns a list of selected Objects in the active layer(s)\n\
|
||||
The active object is the first in the list, if visible";
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BlenderObject structure definition. */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
struct Object *object;
|
||||
} BlenObject;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* PythonTypeObject callback function prototypes */
|
||||
/*****************************************************************************/
|
||||
void ObjectDeAlloc (BlenObject *obj);
|
||||
PyObject* ObjectGetAttr (BlenObject *obj, char *name);
|
||||
int ObjectSetAttr (BlenObject *obj, char *name, PyObject *v);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python TypeObject structure definition. */
|
||||
/*****************************************************************************/
|
||||
static PyTypeObject object_type =
|
||||
{
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /* ob_size */
|
||||
"Object", /* tp_name */
|
||||
sizeof (BlenObject), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)ObjectDeAlloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
(getattrfunc)ObjectGetAttr, /* tp_getattr */
|
||||
(setattrfunc)ObjectSetAttr, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
0, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_as_hash */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python method structure definition. */
|
||||
/*****************************************************************************/
|
||||
@@ -66,7 +111,6 @@ struct PyMethodDef Object_methods[] = {
|
||||
{"get", Object_Get, METH_VARARGS, Object_Get_doc},
|
||||
{"getSelected", Object_GetSelected, METH_VARARGS, Object_GetSelected_doc},
|
||||
{NULL, NULL}
|
||||
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -85,9 +129,52 @@ PyObject *Object_New(PyObject *self, PyObject *args)
|
||||
/*****************************************************************************/
|
||||
PyObject *Object_Get(PyObject *self, PyObject *args)
|
||||
{
|
||||
char * name;
|
||||
PyObject * arg;
|
||||
struct Object * obj_iter;
|
||||
BlenObject * blen_object;
|
||||
|
||||
printf ("In Object_Get()\n");
|
||||
|
||||
return (Py_None);
|
||||
if (!PyArg_ParseTuple(args, "O", &arg))
|
||||
{
|
||||
/* We expected a string as an argument, but we didn't get one. */
|
||||
return (PythonReturnErrorObject (PyExc_AttributeError,
|
||||
"expected string argument"));
|
||||
}
|
||||
|
||||
if (!PyString_Check (arg))
|
||||
{
|
||||
return (PythonReturnErrorObject (PyExc_AttributeError,
|
||||
"expected string argument"));
|
||||
}
|
||||
name = PyString_AsString (arg);
|
||||
|
||||
/* Use the name to search for the object requested. */
|
||||
/* Should this lookup be a new function in blenkernel/intern/object.c? */
|
||||
blen_object = NULL;
|
||||
obj_iter = G.main->object.first;
|
||||
while ((obj_iter) && (blen_object == NULL))
|
||||
{
|
||||
if (StringEqual (name, GetIdName (&(obj_iter->id))))
|
||||
{
|
||||
blen_object = (BlenObject*)PyObject_NEW
|
||||
(BlenObject,
|
||||
&object_type);
|
||||
|
||||
blen_object->object = obj_iter;
|
||||
}
|
||||
obj_iter = obj_iter->id.next;
|
||||
}
|
||||
|
||||
if (blen_object == NULL)
|
||||
{
|
||||
/* No object exists with the name specified in the argument name. */
|
||||
return (PythonReturnErrorObject (PyExc_AttributeError,
|
||||
"expected string argument"));
|
||||
}
|
||||
|
||||
return ((PyObject*)blen_object);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -107,12 +194,339 @@ PyObject *Object_GetSelected (PyObject *self, PyObject *args)
|
||||
PyObject *initObject (void)
|
||||
{
|
||||
PyObject * module;
|
||||
PyObject * dict;
|
||||
|
||||
printf ("In initObject()\n");
|
||||
|
||||
module = Py_InitModule("Blender.Object", Object_methods);
|
||||
module = Py_InitModule("Object", Object_methods);
|
||||
|
||||
return (module);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ObjectCreatePyObject */
|
||||
/* Description: This function will create a new BlenObject from an existing */
|
||||
/* Object structure. */
|
||||
/*****************************************************************************/
|
||||
PyObject* ObjectCreatePyObject (struct Object *obj)
|
||||
{
|
||||
BlenObject * blen_object;
|
||||
|
||||
printf ("In ObjectCreatePyObject\n");
|
||||
|
||||
blen_object = (BlenObject*)PyObject_NEW
|
||||
(BlenObject,
|
||||
&object_type);
|
||||
|
||||
blen_object->object = obj;
|
||||
return ((PyObject*)blen_object);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ObjectDeAlloc */
|
||||
/* Description: This is a callback function for the BlenObject type. It is */
|
||||
/* the destructor function. */
|
||||
/*****************************************************************************/
|
||||
void ObjectDeAlloc (BlenObject *obj)
|
||||
{
|
||||
PyObject_DEL (obj);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ObjectGetAttr */
|
||||
/* Description: This is a callback function for the BlenObject type. It is */
|
||||
/* the function that retrieves any value from Blender and */
|
||||
/* passes it to Python. */
|
||||
/*****************************************************************************/
|
||||
PyObject* ObjectGetAttr (BlenObject *obj, char *name)
|
||||
{
|
||||
struct Object * object;
|
||||
struct Ika * ika;
|
||||
|
||||
object = obj->object;
|
||||
if (StringEqual (name, "LocX"))
|
||||
return (PyFloat_FromDouble(object->loc[0]));
|
||||
if (StringEqual (name, "LocY"))
|
||||
return (PyFloat_FromDouble(object->loc[1]));
|
||||
if (StringEqual (name, "LocZ"))
|
||||
return (PyFloat_FromDouble(object->loc[2]));
|
||||
if (StringEqual (name, "loc"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "dLocX"))
|
||||
return (PyFloat_FromDouble(object->dloc[0]));
|
||||
if (StringEqual (name, "dLocY"))
|
||||
return (PyFloat_FromDouble(object->dloc[1]));
|
||||
if (StringEqual (name, "dLocZ"))
|
||||
return (PyFloat_FromDouble(object->dloc[2]));
|
||||
if (StringEqual (name, "dloc"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "RotX"))
|
||||
return (PyFloat_FromDouble(object->rot[0]));
|
||||
if (StringEqual (name, "RotY"))
|
||||
return (PyFloat_FromDouble(object->rot[1]));
|
||||
if (StringEqual (name, "RotZ"))
|
||||
return (PyFloat_FromDouble(object->rot[2]));
|
||||
if (StringEqual (name, "rot"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "dRotX"))
|
||||
return (PyFloat_FromDouble(object->drot[0]));
|
||||
if (StringEqual (name, "dRotY"))
|
||||
return (PyFloat_FromDouble(object->drot[1]));
|
||||
if (StringEqual (name, "dRotZ"))
|
||||
return (PyFloat_FromDouble(object->drot[2]));
|
||||
if (StringEqual (name, "drot"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "SizeX"))
|
||||
return (PyFloat_FromDouble(object->size[0]));
|
||||
if (StringEqual (name, "SizeY"))
|
||||
return (PyFloat_FromDouble(object->size[1]));
|
||||
if (StringEqual (name, "SizeZ"))
|
||||
return (PyFloat_FromDouble(object->size[2]));
|
||||
if (StringEqual (name, "size"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "dSizeX"))
|
||||
return (PyFloat_FromDouble(object->dsize[0]));
|
||||
if (StringEqual (name, "dSizeY"))
|
||||
return (PyFloat_FromDouble(object->dsize[1]));
|
||||
if (StringEqual (name, "dSizeZ"))
|
||||
return (PyFloat_FromDouble(object->dsize[2]));
|
||||
if (StringEqual (name, "dsize"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (strncmp (name,"Eff", 3) == 0)
|
||||
{
|
||||
if ( (object->type == OB_IKA) && (object->data != NULL) )
|
||||
{
|
||||
ika = object->data;
|
||||
switch (name[3])
|
||||
{
|
||||
case 'X':
|
||||
return (PyFloat_FromDouble (ika->effg[0]));
|
||||
case 'Y':
|
||||
return (PyFloat_FromDouble (ika->effg[1]));
|
||||
case 'Z':
|
||||
return (PyFloat_FromDouble (ika->effg[2]));
|
||||
default:
|
||||
/* Do we need to display a sensible error message here? */
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
if (StringEqual (name, "Layer"))
|
||||
return (PyInt_FromLong(object->lay));
|
||||
if (StringEqual (name, "parent"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "track"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "data"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "ipo"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "mat"))
|
||||
{
|
||||
printf ("This is not implemented yet. (matrix)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "matrix"))
|
||||
{
|
||||
printf ("This is not implemented yet. (matrix)\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "colbits"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "drawType"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
if (StringEqual (name, "drawMode"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
printf ("Unknown variable.\n");
|
||||
return (Py_None);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function: ObjectSetAttr */
|
||||
/* Description: This is a callback function for the BlenObject type. It is */
|
||||
/* the function that retrieves any value from Python and sets */
|
||||
/* it accordingly in Blender. */
|
||||
/*****************************************************************************/
|
||||
int ObjectSetAttr (BlenObject *obj, char *name, PyObject *value)
|
||||
{
|
||||
struct Object * object;
|
||||
struct Ika * ika;
|
||||
|
||||
object = obj->object;
|
||||
if (StringEqual (name, "LocX"))
|
||||
return (!PyArg_Parse (value, "f", &(object->loc[0])));
|
||||
if (StringEqual (name, "LocY"))
|
||||
return (!PyArg_Parse (value, "f", &(object->loc[1])));
|
||||
if (StringEqual (name, "LocZ"))
|
||||
return (!PyArg_Parse (value, "f", &(object->loc[2])));
|
||||
if (StringEqual (name, "loc"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (0);
|
||||
}
|
||||
if (StringEqual (name, "dLocX"))
|
||||
return (!PyArg_Parse (value, "f", &(object->dloc[0])));
|
||||
if (StringEqual (name, "dLocY"))
|
||||
return (!PyArg_Parse (value, "f", &(object->dloc[1])));
|
||||
if (StringEqual (name, "dLocZ"))
|
||||
return (!PyArg_Parse (value, "f", &(object->dloc[2])));
|
||||
if (StringEqual (name, "dloc"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (0);
|
||||
}
|
||||
if (StringEqual (name, "RotX"))
|
||||
return (!PyArg_Parse (value, "f", &(object->rot[0])));
|
||||
if (StringEqual (name, "RotY"))
|
||||
return (!PyArg_Parse (value, "f", &(object->rot[1])));
|
||||
if (StringEqual (name, "RotZ"))
|
||||
return (!PyArg_Parse (value, "f", &(object->rot[2])));
|
||||
if (StringEqual (name, "rot"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (0);
|
||||
}
|
||||
if (StringEqual (name, "dRotX"))
|
||||
return (!PyArg_Parse (value, "f", &(object->drot[0])));
|
||||
if (StringEqual (name, "dRotY"))
|
||||
return (!PyArg_Parse (value, "f", &(object->drot[1])));
|
||||
if (StringEqual (name, "dRotZ"))
|
||||
return (!PyArg_Parse (value, "f", &(object->drot[2])));
|
||||
if (StringEqual (name, "drot"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (0);
|
||||
}
|
||||
if (StringEqual (name, "SizeX"))
|
||||
return (!PyArg_Parse (value, "f", &(object->size[0])));
|
||||
if (StringEqual (name, "SizeY"))
|
||||
return (!PyArg_Parse (value, "f", &(object->size[1])));
|
||||
if (StringEqual (name, "SizeZ"))
|
||||
return (!PyArg_Parse (value, "f", &(object->size[2])));
|
||||
if (StringEqual (name, "size"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (0);
|
||||
}
|
||||
if (StringEqual (name, "dSizeX"))
|
||||
return (!PyArg_Parse (value, "f", &(object->dsize[0])));
|
||||
if (StringEqual (name, "dSizeY"))
|
||||
return (!PyArg_Parse (value, "f", &(object->dsize[1])));
|
||||
if (StringEqual (name, "dSizeZ"))
|
||||
return (!PyArg_Parse (value, "f", &(object->dsize[2])));
|
||||
if (StringEqual (name, "dsize"))
|
||||
{
|
||||
printf ("This is not implemented yet. (vector)\n");
|
||||
return (0);
|
||||
}
|
||||
if (strncmp (name,"Eff", 3) == 0)
|
||||
{
|
||||
if ( (object->type == OB_IKA) && (object->data != NULL) )
|
||||
{
|
||||
ika = object->data;
|
||||
switch (name[3])
|
||||
{
|
||||
case 'X':
|
||||
return (!PyArg_Parse (value, "f", &(ika->effg[0])));
|
||||
case 'Y':
|
||||
return (!PyArg_Parse (value, "f", &(ika->effg[1])));
|
||||
case 'Z':
|
||||
return (!PyArg_Parse (value, "f", &(ika->effg[2])));
|
||||
default:
|
||||
/* Do we need to display a sensible error message here? */
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
if (StringEqual (name, "Layer"))
|
||||
return (!PyArg_Parse (value, "i", &(object->lay)));
|
||||
if (StringEqual (name, "parent"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "track"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "data"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "ipo"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "mat"))
|
||||
{
|
||||
printf ("This is not implemented yet. (matrix)\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "matrix"))
|
||||
{
|
||||
printf ("This is not implemented yet. (matrix)\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "colbits"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "drawType"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (1);
|
||||
}
|
||||
if (StringEqual (name, "drawMode"))
|
||||
{
|
||||
printf ("This is not implemented yet.\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
printf ("Unknown variable.\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@@ -1,311 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* ***** 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): Michel Selten
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_main.h>
|
||||
#include <DNA_ID.h>
|
||||
|
||||
#include "datablock.h"
|
||||
#include "gen_utils.h"
|
||||
#include "modules.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Function prototypes */
|
||||
/*****************************************************************************/
|
||||
void DataBlock_dealloc (PyObject *self);
|
||||
PyObject * DataBlock_getattr (PyObject *self, char *name);
|
||||
int DataBlock_setattr (PyObject *self, char *name, PyObject *ob);
|
||||
PyObject * DataBlock_repr (PyObject *self);
|
||||
|
||||
PyTypeObject DataBlock_Type =
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /* ob_size */
|
||||
"Block", /* tp_name */
|
||||
sizeof (DataBlock), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
(destructor) DataBlock_dealloc, /* tp_dealloc */
|
||||
(printfunc) NULL, /* tp_print */
|
||||
(getattrfunc) DataBlock_getattr, /* tp_getattr */
|
||||
(setattrfunc) DataBlock_setattr, /* tp_setattr */
|
||||
(cmpfunc) NULL, /* tp_compare */
|
||||
(reprfunc) DataBlock_repr /* tp_repr */
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: This function creates a Python datablock descriptor object */
|
||||
/* from the specified data pointer. This pointer must point to */
|
||||
/* a structure with a valid ID header. */
|
||||
/*****************************************************************************/
|
||||
PyObject * DataBlockFromID (ID * data)
|
||||
{
|
||||
DataBlock * new_block;
|
||||
int obj_id;
|
||||
|
||||
if (!data)
|
||||
{
|
||||
return ( PythonIncRef (Py_None) );
|
||||
}
|
||||
|
||||
/* First get the object type. */
|
||||
obj_id = MAKE_ID2(data->name[0], data->name[1]);
|
||||
|
||||
switch (obj_id)
|
||||
{
|
||||
case ID_OB:
|
||||
/* Create a new datablock of type: Object */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Object";
|
||||
new_block->type_list= &(G.main->object);
|
||||
new_block->properties= NULL; /* Object_Properties; */
|
||||
break;
|
||||
case ID_ME:
|
||||
/* Create a new datablock of type: Mesh */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Mesh";
|
||||
new_block->type_list= &(G.main->mesh);
|
||||
new_block->properties= NULL; /* Mesh_Properties; */
|
||||
break;
|
||||
case ID_LA:
|
||||
/* Create a new datablock of type: Lamp */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Lamp";
|
||||
new_block->type_list= &(G.main->lamp);
|
||||
new_block->properties= NULL; /* Lamp_Properties; */
|
||||
break;
|
||||
case ID_CA:
|
||||
/* Create a new datablock of type: Camera */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Camera";
|
||||
new_block->type_list= &(G.main->camera);
|
||||
new_block->properties= NULL; /* Camera_Properties; */
|
||||
break;
|
||||
case ID_MA:
|
||||
/* Create a new datablock of type: Material */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Material";
|
||||
new_block->type_list= &(G.main->mat);
|
||||
new_block->properties= NULL; /* Material_Properties; */
|
||||
break;
|
||||
case ID_WO:
|
||||
/* Create a new datablock of type: World */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "World";
|
||||
new_block->type_list= &(G.main->world);
|
||||
new_block->properties= NULL; /* World_Properties; */
|
||||
break;
|
||||
case ID_IP:
|
||||
/* Create a new datablock of type: Ipo */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Ipo";
|
||||
new_block->type_list= &(G.main->ipo);
|
||||
new_block->properties= NULL; /* Ipo_Properties; */
|
||||
break;
|
||||
case ID_IM:
|
||||
/* Create a new datablock of type: Image */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Image";
|
||||
new_block->type_list= &(G.main->image);
|
||||
new_block->properties= NULL; /* Image_Properties; */
|
||||
break;
|
||||
case ID_TXT:
|
||||
/* Create a new datablock of type: Text */
|
||||
new_block= PyObject_NEW(DataBlock, &DataBlock_Type);
|
||||
new_block->type= "Text";
|
||||
new_block->type_list= &(G.main->text);
|
||||
new_block->properties= NULL; /* Text_Properties; */
|
||||
break;
|
||||
default:
|
||||
return ( PythonReturnErrorObject (PyExc_SystemError,
|
||||
"Unable to create block for data") );
|
||||
}
|
||||
new_block->data = (void*)data;
|
||||
|
||||
return ( (PyObject *) new_block );
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Private functions */
|
||||
/*****************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: Deallocates a Python Datablock object. */
|
||||
/*****************************************************************************/
|
||||
void DataBlock_dealloc (PyObject *self)
|
||||
{
|
||||
PyMem_DEL (self);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: */
|
||||
/*****************************************************************************/
|
||||
PyObject * DataBlock_getattr (PyObject *self, char *name)
|
||||
{
|
||||
int obj_id;
|
||||
PyObject * ret = NULL;
|
||||
DataBlock * block = (DataBlock*) self;
|
||||
|
||||
if (!block)
|
||||
{
|
||||
return (PythonReturnErrorObject (PyExc_RuntimeError,
|
||||
"Block was deleted!"));
|
||||
}
|
||||
|
||||
/* Check for common attributes. */
|
||||
if (StringEqual (name, "name") )
|
||||
{
|
||||
return (PyString_FromString ((((ID*)block->data)->name)+2));
|
||||
}
|
||||
if (StringEqual (name, "block_type") )
|
||||
{
|
||||
return(PyString_FromString (block->type));
|
||||
}
|
||||
if (StringEqual (name, "users") )
|
||||
{
|
||||
return (PyInt_FromLong (((ID*)block->data)->us));
|
||||
}
|
||||
|
||||
/* The following datablock types have methods: */
|
||||
obj_id = MAKE_ID2 (((ID*)block->data)->name[0],
|
||||
((ID*)block->data)->name[1]);
|
||||
switch (obj_id)
|
||||
{
|
||||
case ID_OB:
|
||||
ret = Py_FindMethod (Object_methods, self, name);
|
||||
break;
|
||||
case ID_IP:
|
||||
ret = Py_None;
|
||||
/* ret = Py_FindMethod (Ipo_methods, self, name); */
|
||||
break;
|
||||
case ID_CA:
|
||||
ret = Py_None;
|
||||
/* ret = Py_FindMethod (Camera_methods, self, name); */
|
||||
break;
|
||||
case ID_MA:
|
||||
ret = Py_None;
|
||||
/* ret = Py_FindMethod (Material_methods, self, name); */
|
||||
break;
|
||||
case ID_LA:
|
||||
ret = Py_None;
|
||||
/* ret = Py_FindMethod (Lamp_methods, self, name); */
|
||||
break;
|
||||
case ID_TXT:
|
||||
ret = Py_None;
|
||||
/* ret = Py_FindMethod (Text_methods, self, name); */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
/* No method found, clear the error message. */
|
||||
PyErr_Clear ();
|
||||
|
||||
/* Try to find the common datablock methods. */
|
||||
/* ret = Py_FindMethod (commonDataBlock_methods, self, name); */
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
/* No method found, clear the error message. */
|
||||
PyErr_Clear ();
|
||||
|
||||
/* Try to find attributes from property list */
|
||||
/* ret = datablock_getattr (block->properties,
|
||||
block->type, name, block->data); */
|
||||
ret = Py_None;
|
||||
}
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: */
|
||||
/*****************************************************************************/
|
||||
int DataBlock_setattr (PyObject *self, char *name, PyObject *ob)
|
||||
{
|
||||
DataBlock * block = (DataBlock*) self;
|
||||
|
||||
if (!block)
|
||||
{
|
||||
PythonReturnErrorObject (PyExc_RuntimeError, "Block was deleted!");
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (StringEqual (name, "name"))
|
||||
{
|
||||
if (!PyArg_Parse (ob, "s", &name))
|
||||
{
|
||||
/* TODO: Do we need to display some sort of error message here? */
|
||||
return (-1);
|
||||
}
|
||||
|
||||
new_id (block->type_list, (ID*)block->data, name);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* return (datablock_setattr (block->properties, block->type, name,
|
||||
block->data, ob)); */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Description: This function prints a sensible string when doing a */
|
||||
/* 'print abc' from Python. Where abc is one of the Blender */
|
||||
/* objects. */
|
||||
/*****************************************************************************/
|
||||
PyObject * DataBlock_repr (PyObject *self)
|
||||
{
|
||||
DataBlock * data_block;
|
||||
ID * id;
|
||||
static char s[256];
|
||||
|
||||
data_block = (DataBlock *)self;
|
||||
if (data_block->data)
|
||||
{
|
||||
/* The object is still available, print the type and name. */
|
||||
id = (ID*)data_block->data;
|
||||
sprintf (s, "[%.32s %.32s]", data_block->type, id->name+2);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The object has been deleted, print the type and <deleted>. */
|
||||
sprintf (s, "[%.32s <deleted>]", data_block->type);
|
||||
}
|
||||
|
||||
return Py_BuildValue("s", s);
|
||||
}
|
||||
|
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* ***** 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): Michel Selten
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <DNA_ID.h>
|
||||
#include <DNA_listBase.h>
|
||||
|
||||
#define DBP_TYPE_NON 0 /* No item */
|
||||
#define DBP_TYPE_CHA 1 /* Char item */
|
||||
#define DBP_TYPE_SHO 2 /* Short item */
|
||||
#define DBP_TYPE_INT 3 /* Int item */
|
||||
#define DBP_TYPE_FLO 4 /* Float item */
|
||||
#define DBP_TYPE_VEC 5 /* Float vector object */
|
||||
#define DBP_TYPE_FUN 6 /* funcPtrToObj hold function to convert ptr->ob */
|
||||
/* funcObjToPtr holds function to convert ob->ptr */
|
||||
|
||||
#define DBP_HANDLING_NONE 0 /* No special handling required */
|
||||
#define DBP_HANDLING_FUNC 1 /* Extra1 is used to retrieve ptr */
|
||||
#define DBP_HANDLING_NENM 2 /* Extra1 holds named enum to resolve */
|
||||
/* values from/to. */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char * public_name;
|
||||
char * struct_name;
|
||||
int type;
|
||||
int stype;
|
||||
float min; /* Minimum allowed value */
|
||||
float max; /* Maximum allowed value */
|
||||
int idx[4];
|
||||
int dlist[4];
|
||||
int handling;
|
||||
void * extra1;
|
||||
void * funcPtrToObj;
|
||||
void * funcObjToPtr;
|
||||
} DataBlockProperty;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
void * data;
|
||||
char * type;
|
||||
ListBase * type_list;
|
||||
DataBlockProperty * properties;
|
||||
} DataBlock;
|
||||
|
||||
PyObject * DataBlockFromID (ID * data);
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include <string.h>
|
||||
#include <Python.h>
|
||||
|
||||
#include <DNA_ID.h>
|
||||
#include <DNA_scriptlink_types.h>
|
||||
|
||||
int StringEqual (char * string1, char * string2)
|
||||
@@ -40,10 +41,15 @@ int StringEqual (char * string1, char * string2)
|
||||
return (strcmp(string1, string2)==0);
|
||||
}
|
||||
|
||||
char * GetIdName (ID *id)
|
||||
{
|
||||
return ((id->name)+2);
|
||||
}
|
||||
|
||||
PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg)
|
||||
{
|
||||
PyErr_SetString (type, error_msg);
|
||||
return NULL;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
PyObject * PythonIncRef (PyObject *object)
|
||||
|
@@ -29,7 +29,12 @@
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <DNA_ID.h>
|
||||
|
||||
int StringEqual (char * string1, char * string2);
|
||||
char * GetIdName (ID *id);
|
||||
PyObject * PythonReturnErrorObject (PyObject * type, char * error_msg);
|
||||
PyObject * PythonIncRef (PyObject *object);
|
||||
char * event_to_name(short event);
|
||||
|
@@ -31,7 +31,15 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <BKE_global.h>
|
||||
#include <BKE_main.h>
|
||||
#include <DNA_ID.h>
|
||||
#include <DNA_camera_types.h>
|
||||
#include <DNA_lamp_types.h>
|
||||
#include <DNA_material_types.h>
|
||||
#include <DNA_object_types.h>
|
||||
#include <DNA_scene_types.h>
|
||||
#include <DNA_world_types.h>
|
||||
|
||||
#include "datablock.h"
|
||||
#include "gen_utils.h"
|
||||
@@ -48,6 +56,7 @@ void setScriptLinks(ID *id, short event)
|
||||
PyObject *link;
|
||||
int obj_id;
|
||||
|
||||
printf ("In setScriptLinks (id=?, event=%d)\n", event);
|
||||
if (!g_blenderdict)
|
||||
{
|
||||
/* Not initialized yet. This can happen at first file load. */
|
||||
@@ -62,7 +71,45 @@ void setScriptLinks(ID *id, short event)
|
||||
}
|
||||
else
|
||||
{
|
||||
link = DataBlockFromID(id);
|
||||
link = Py_None;
|
||||
switch (obj_id)
|
||||
{
|
||||
case ID_OB:
|
||||
/* Create a new datablock of type: Object */
|
||||
/*
|
||||
link = ObjectCreatePyObject (G.main->object);
|
||||
*/
|
||||
break;
|
||||
case ID_ME:
|
||||
/* Create a new datablock of type: Mesh */
|
||||
break;
|
||||
case ID_LA:
|
||||
/* Create a new datablock of type: Lamp */
|
||||
break;
|
||||
case ID_CA:
|
||||
/* Create a new datablock of type: Camera */
|
||||
break;
|
||||
case ID_MA:
|
||||
/* Create a new datablock of type: Material */
|
||||
break;
|
||||
case ID_WO:
|
||||
/* Create a new datablock of type: World */
|
||||
break;
|
||||
case ID_IP:
|
||||
/* Create a new datablock of type: Ipo */
|
||||
break;
|
||||
case ID_IM:
|
||||
/* Create a new datablock of type: Image */
|
||||
break;
|
||||
case ID_TXT:
|
||||
/* Create a new datablock of type: Text */
|
||||
break;
|
||||
default:
|
||||
PythonReturnErrorObject (PyExc_SystemError,
|
||||
"Unable to create block for data");
|
||||
return;
|
||||
}
|
||||
/* link = DataBlockFromID(id); */
|
||||
}
|
||||
|
||||
if (!link)
|
||||
|
@@ -30,13 +30,13 @@
|
||||
*/
|
||||
#include <Python.h>
|
||||
|
||||
#include <DNA_object_types.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Global variables */
|
||||
/*****************************************************************************/
|
||||
PyObject *g_blenderdict;
|
||||
|
||||
extern struct PyMethodDef Object_methods[];
|
||||
|
||||
void initBlender (void);
|
||||
PyObject* initObject (void);
|
||||
|
||||
PyObject* ObjectCreatePyObject (struct Object *obj);
|
||||
|
Reference in New Issue
Block a user