This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/python/api2_2x/Build.c

315 lines
10 KiB
C
Raw Normal View History

2003-06-21 11:44:10 +00:00
/*
*
* ***** 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): Jacques Guignot
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "Build.h"
#include "Effect.h"
/*****************************************************************************/
/* Python Build_Type structure definition: */
/*****************************************************************************/
PyTypeObject Build_Type =
{
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"Build", /* tp_name */
sizeof (BPy_Build), /* tp_basicsize */
2003-06-21 11:44:10 +00:00
0, /* tp_itemsize */
/* methods */
(destructor)BuildDeAlloc, /* tp_dealloc */
0, /* tp_print */
2003-06-21 11:44:10 +00:00
(getattrfunc)BuildGetAttr, /* tp_getattr */
(setattrfunc)BuildSetAttr, /* tp_setattr */
0, /* tp_compare */
(reprfunc)BuildRepr, /* 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,
BPy_Build_methods, /* tp_methods */
2003-06-21 11:44:10 +00:00
0, /* tp_members */
};
/*****************************************************************************/
/* Function: M_Build_New */
/* Python equivalent: Blender.Effect.Build.New */
/*****************************************************************************/
PyObject *M_Build_New(PyObject *self, PyObject *args)
{
int type = EFF_BUILD;
BPy_Effect *pyeffect;
2003-06-21 11:44:10 +00:00
Effect *bleffect = 0;
bleffect = add_effect(type);
if (bleffect == NULL)
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Effect Data in Blender"));
pyeffect = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
2003-06-21 11:44:10 +00:00
if (pyeffect == NULL) return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Effect Data object"));
pyeffect->effect = bleffect;
return (PyObject *)pyeffect;
return 0;
}
/*****************************************************************************/
/* Function: M_Build_Get */
/* Python equivalent: Blender.Effect.Build.Get */
/*****************************************************************************/
PyObject *M_Build_Get(PyObject *self, PyObject *args)
{
/*arguments : string object name
int : position of effect in the obj's effect list */
char *name = 0;
Object *object_iter;
Effect *eff;
BPy_Build *wanted_eff;
2003-06-21 11:44:10 +00:00
int num,i;
if (!PyArg_ParseTuple(args, "si", &name, &num ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected string int argument"));
object_iter = G.main->object.first;
if (!object_iter)return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"Scene contains no object"));
while (object_iter)
{
if (strcmp(name,object_iter->id.name+2))
{
object_iter = object_iter->id.next;
continue;
}
if (object_iter->effect.first != NULL)
{
eff = object_iter->effect.first;
for(i = 0;i<num;i++)
{
if (eff->type != EFF_BUILD)continue;
eff = eff->next;
if (!eff)
return(EXPP_ReturnPyObjError(PyExc_AttributeError,"object not created"));
2003-06-21 11:44:10 +00:00
}
wanted_eff = (BPy_Build *)PyObject_NEW(BPy_Build, &Build_Type);
2003-06-21 11:44:10 +00:00
wanted_eff->build = eff;
return (PyObject*)wanted_eff;
}
object_iter = object_iter->id.next;
}
Py_INCREF(Py_None);
return Py_None;
}
struct PyMethodDef M_Build_methods[] = {
{"New",(PyCFunction)M_Build_New, METH_VARARGS, M_Build_New_doc},
{"Get", M_Build_Get, METH_VARARGS, M_Build_Get_doc},
{"get", M_Build_Get, METH_VARARGS,M_Build_Get_doc},
{NULL, NULL, 0, NULL}
};
2003-06-21 11:44:10 +00:00
/*****************************************************************************/
/* Function: Build_Init */
2003-06-21 11:44:10 +00:00
/*****************************************************************************/
PyObject *Build_Init (void)
2003-06-21 11:44:10 +00:00
{
PyObject *submodule;
2003-06-21 11:44:10 +00:00
Build_Type.ob_type = &PyType_Type;
submodule = Py_InitModule3("Blender.Build",M_Build_methods,M_Build_doc );
2003-06-21 11:44:10 +00:00
return (submodule);
}
/*****************************************************************************/
/* Python BPy_Build methods: */
2003-06-21 11:44:10 +00:00
/*****************************************************************************/
PyObject *Build_getLen(BPy_Build *self)
2003-06-21 11:44:10 +00:00
{
BuildEff*ptr = (BuildEff*)self->build;
return PyFloat_FromDouble(ptr->len);
}
PyObject *Build_setLen(BPy_Build *self,PyObject *args)
2003-06-21 11:44:10 +00:00
{
BuildEff*ptr = (BuildEff*)self->build;
float val = 0;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr->len = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Build_getSfra(BPy_Build *self)
2003-06-21 11:44:10 +00:00
{
BuildEff*ptr = (BuildEff*)self->build;
return PyFloat_FromDouble(ptr->sfra);
}
PyObject *Build_setSfra(BPy_Build *self,PyObject *args)
2003-06-21 11:44:10 +00:00
{
BuildEff*ptr = (BuildEff*)self->build;
float val = 0;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,"expected float argument"));
ptr->sfra = val;
Py_INCREF(Py_None);
return Py_None;
}
/*****************************************************************************/
/* Function: BuildDeAlloc */
/* Description: This is a callback function for the BPy_Build type. It is */
2003-06-21 11:44:10 +00:00
/* the destructor function. */
/*****************************************************************************/
void BuildDeAlloc (BPy_Build *self)
2003-06-21 11:44:10 +00:00
{
BuildEff*ptr = (BuildEff*)self;
PyObject_DEL (ptr);
}
/*****************************************************************************/
/* Function: BuildGetAttr */
/* Description: This is a callback function for the BPy_Build type. It is */
/* the function that accesses BPy_Build "member variables" and */
2003-06-21 11:44:10 +00:00
/* methods. */
/*****************************************************************************/
PyObject *BuildGetAttr (BPy_Build *self, char *name)
2003-06-21 11:44:10 +00:00
{
if (!strcmp(name,"sfra"))return Build_getSfra( self);
if (!strcmp(name,"len"))return Build_getLen( self);
return Py_FindMethod(BPy_Build_methods, (PyObject *)self, name);
2003-06-21 11:44:10 +00:00
}
/*****************************************************************************/
/* Function: BuildSetAttr */
/* Description: This is a callback function for the BPy_Build type. It is the */
2003-06-21 11:44:10 +00:00
/* function that sets Build Data attributes (member variables). */
/*****************************************************************************/
int BuildSetAttr (BPy_Build *self, char *name, PyObject *value)
2003-06-21 11:44:10 +00:00
{
PyObject *valtuple;
PyObject *error = NULL;
valtuple = Py_BuildValue("(N)", value);
if (!valtuple)
return EXPP_ReturnIntError(PyExc_MemoryError,
"CameraSetAttr: couldn't create PyTuple");
if (!strcmp (name, "sfra")) error = Build_setSfra (self, valtuple);
else if (!strcmp (name, "len")) error = Build_setLen (self, valtuple);
else {
Py_DECREF(valtuple);
return (EXPP_ReturnIntError (PyExc_KeyError,
"attribute not found"));
}
/* Py_DECREF(valtuple);*/
if (error != Py_None) return -1;
Py_DECREF(Py_None);
return 0;
}
/*****************************************************************************/
/* Function: BuildPrint */
/* Description: This is a callback function for the BPy_Build type. It */
2003-06-21 11:44:10 +00:00
/* builds a meaninful string to 'print' build objects. */
/*****************************************************************************/
/*
int BuildPrint(BPy_Build *self, FILE *fp, int flags)
2003-06-21 11:44:10 +00:00
{
return 0;
}
*/
2003-06-21 11:44:10 +00:00
/*****************************************************************************/
/* Function: BuildRepr */
/* Description: This is a callback function for the BPy_Build type. It */
2003-06-21 11:44:10 +00:00
/* builds a meaninful string to represent build objects. */
/*****************************************************************************/
PyObject *BuildRepr (BPy_Build *self)
2003-06-21 11:44:10 +00:00
{
return PyString_FromString("Build effect");
2003-06-21 11:44:10 +00:00
}
PyObject* BuildCreatePyObject (struct Effect *build)
{
BPy_Build * blen_object;
2003-06-21 11:44:10 +00:00
blen_object = (BPy_Build*)PyObject_NEW (BPy_Build, &Build_Type);
2003-06-21 11:44:10 +00:00
if (blen_object == NULL)
{
return (NULL);
}
blen_object->build = build;
return ((PyObject*)blen_object);
}
int BuildCheckPyObject (PyObject *py_obj)
{
return (py_obj->ob_type == &Build_Type);
}
struct Build* BuildFromPyObject (PyObject *py_obj)
{
BPy_Build * blen_obj;
2003-06-21 11:44:10 +00:00
blen_obj = (BPy_Build*)py_obj;
2003-06-21 11:44:10 +00:00
return ((struct Build*)blen_obj->build);
}