Merged changes in the trunk up to revision 45133.

Conflicts resolved:
source/blender/blenloader/intern/readfile.c
source/blender/blenloader/intern/writefile.c
source/blender/bmesh/intern/bmesh_construct.c
source/blender/bmesh/intern/bmesh_mesh_conv.c
source/blender/bmesh/intern/bmesh_mesh_conv.h
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/resources.c
source/blender/editors/mesh/bmesh_select.c
source/blender/editors/mesh/bmesh_tools.c
source/blender/editors/space_view3d/drawobject.c
source/blender/render/intern/source/shadeoutput.c
This commit is contained in:
2012-03-25 08:20:19 +00:00
1200 changed files with 77004 additions and 63870 deletions

View File

@@ -33,13 +33,17 @@ set(INC_SYS
set(SRC
bmesh_py_api.c
bmesh_py_select.c
bmesh_py_types.c
bmesh_py_types_customdata.c
bmesh_py_types_meshdata.c
bmesh_py_types_select.c
bmesh_py_utils.c
bmesh_py_api.h
bmesh_py_select.h
bmesh_py_types.h
bmesh_py_types_customdata.h
bmesh_py_types_meshdata.h
bmesh_py_types_select.h
bmesh_py_utils.h
)

View File

@@ -31,127 +31,73 @@
#include <Python.h>
#include "BLI_utildefines.h"
#include "bmesh.h"
#include "bmesh_py_types.h"
#include "bmesh_py_utils.h"
#include "bmesh_py_select.h"
#include "bmesh_py_types_select.h"
#include "bmesh_py_types_customdata.h"
#include "bmesh_py_types_meshdata.h"
#include "BLI_utildefines.h"
#include "bmesh_py_utils.h"
#include "BKE_tessmesh.h"
#include "BKE_depsgraph.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "../generic/py_capi_utils.h"
#include "bmesh_py_api.h" /* own include */
PyDoc_STRVAR(bpy_bm_new_doc,
".. method:: new()\n"
"\n"
" :return: Retyrn a new, empty mesh.\n"
" :rtype: :class:`BMesh`\n"
" :return: Return a new, empty BMesh.\n"
" :rtype: :class:`bmesh.types.BMesh`\n"
);
static PyObject *bpy_bm_new(PyObject *UNUSED(self))
{
BPy_BMesh *py_bmesh;
BMesh *bm;
bm = BM_mesh_create(NULL, &bm_mesh_allocsize_default);
bm = BM_mesh_create(&bm_mesh_allocsize_default);
py_bmesh = (BPy_BMesh *)BPy_BMesh_CreatePyObject(bm);
py_bmesh->py_owns = TRUE;
return (PyObject *)py_bmesh;
return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_NOP);
}
PyDoc_STRVAR(bpy_bm_from_mesh_doc,
".. method:: from_mesh(mesh)\n"
PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc,
".. method:: from_edit_mesh(mesh)\n"
"\n"
" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
"\n"
" :return: the BMesh assosiated with this mesh.\n"
" :rtype: :class:`bmesh.types.BMesh`\n"
);
static PyObject *bpy_bm_from_mesh(PyObject *UNUSED(self), PyObject *value)
static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value)
{
BPy_BMesh *py_bmesh;
BMesh *bm;
Mesh *me = PyC_RNA_AsPointer(value, "Mesh");
int py_owns;
if (me == NULL) {
return NULL;
}
/* temp! */
if (!me->edit_btmesh) {
bm = BM_mesh_create(NULL, &bm_mesh_allocsize_default);
BM_mesh_to_bmesh(bm, me, 0, 0); /* BMESH_TODO add args */
py_owns = TRUE;
}
else {
bm = me->edit_btmesh->bm;
py_owns = FALSE;
}
py_bmesh = (BPy_BMesh *)BPy_BMesh_CreatePyObject(bm);
py_bmesh->py_owns = py_owns;
return (PyObject *)py_bmesh;
}
PyDoc_STRVAR(bpy_bm_to_mesh_doc,
".. method:: to_mesh(mesh, bmesh)\n"
"\n"
" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
"\n"
" :return: the BMesh assosiated with this mesh.\n"
" :rtype: :class:`bmesh.types.BMesh`\n"
);
static PyObject *bpy_bm_to_mesh(PyObject *UNUSED(self), PyObject *args)
{
PyObject *py_mesh;
BPy_BMesh *py_bmesh;
Mesh *me;
BMesh *bm;
if (!PyArg_ParseTuple(args, "OO!:to_mesh", &py_mesh, &BPy_BMesh_Type, &py_bmesh) ||
!(me = PyC_RNA_AsPointer(py_mesh, "Mesh")))
{
if (me->edit_btmesh == NULL) {
PyErr_SetString(PyExc_ValueError,
"The mesh must be in editmode");
return NULL;
}
BPY_BM_CHECK_OBJ(py_bmesh);
bm = me->edit_btmesh->bm;
if (me->edit_btmesh) {
PyErr_Format(PyExc_ValueError,
"to_mesh(): Mesh '%s' is in editmode", me->id.name + 2);
return NULL;
}
bm = py_bmesh->bm;
BM_mesh_from_bmesh(bm, me, FALSE);
/* we could have the user do this but if they forget blender can easy crash
* since the references arrays for the objects derived meshes are now invalid */
DAG_id_tag_update(&me->id, OB_RECALC_DATA);
Py_RETURN_NONE;
return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED);
}
static struct PyMethodDef BPy_BM_methods[] = {
/* THESE NAMES MAY CHANGE! */
{"new", (PyCFunction)bpy_bm_new, METH_NOARGS, bpy_bm_new_doc},
{"from_mesh", (PyCFunction)bpy_bm_from_mesh, METH_O, bpy_bm_from_mesh_doc},
{"to_mesh", (PyCFunction)bpy_bm_to_mesh, METH_VARARGS, bpy_bm_to_mesh_doc},
{"new", (PyCFunction)bpy_bm_new, METH_NOARGS, bpy_bm_new_doc},
{"from_edit_mesh", (PyCFunction)bpy_bm_from_edit_mesh, METH_O, bpy_bm_from_edit_mesh_doc},
{NULL, NULL, 0, NULL}
};
@@ -163,6 +109,9 @@ PyDoc_STRVAR(BPy_BM_doc,
"\n"
"* :mod:`bmesh.utils`\n"
"* :mod:`bmesh.types`\n"
"\n"
"\n"
".. include:: include__bmesh.rst\n"
);
static struct PyModuleDef BPy_BM_module_def = {
PyModuleDef_HEAD_INIT,
@@ -183,17 +132,18 @@ PyObject *BPyInit_bmesh(void)
PyObject *sys_modules = PySys_GetObject("modules"); /* not pretty */
BPy_BM_init_types();
BPy_BM_init_select_types();
BPy_BM_init_types_select();
BPy_BM_init_types_customdata();
BPy_BM_init_types_meshdata();
mod = PyModule_Create(&BPy_BM_module_def);
/* bmesh.types */
PyModule_AddObject(mod, "types", (submodule=BPyInit_bmesh_types()));
PyModule_AddObject(mod, "types", (submodule = BPyInit_bmesh_types()));
PyDict_SetItemString(sys_modules, "bmesh.types", submodule);
Py_INCREF(submodule);
PyModule_AddObject(mod, "utils", (submodule=BPyInit_bmesh_utils()));
PyModule_AddObject(mod, "utils", (submodule = BPyInit_bmesh_utils()));
PyDict_SetItemString(sys_modules, "bmesh.utils", submodule);
Py_INCREF(submodule);

File diff suppressed because it is too large Load Diff

View File

@@ -35,7 +35,13 @@ extern PyTypeObject BPy_BMVert_Type;
extern PyTypeObject BPy_BMEdge_Type;
extern PyTypeObject BPy_BMFace_Type;
extern PyTypeObject BPy_BMLoop_Type;
extern PyTypeObject BPy_BMElemSeq_Type;
extern PyTypeObject BPy_BMVertSeq_Type;
extern PyTypeObject BPy_BMEdgeSeq_Type;
extern PyTypeObject BPy_BMFaceSeq_Type;
extern PyTypeObject BPy_BMLoopSeq_Type;
extern PyTypeObject BPy_BMIter_Type;
#define BPy_BMesh_Check(v) (Py_TYPE(v) == &BPy_BMesh_Type)
@@ -44,6 +50,10 @@ extern PyTypeObject BPy_BMIter_Type;
#define BPy_BMFace_Check(v) (Py_TYPE(v) == &BPy_BMFace_Type)
#define BPy_BMLoop_Check(v) (Py_TYPE(v) == &BPy_BMLoop_Type)
#define BPy_BMElemSeq_Check(v) (Py_TYPE(v) == &BPy_BMElemSeq_Type)
#define BPy_BMVertSeq_Check(v) (Py_TYPE(v) == &BPy_BMVertSeq_Type)
#define BPy_BMEdgeSeq_Check(v) (Py_TYPE(v) == &BPy_BMEdgeSeq_Type)
#define BPy_BMFaceSeq_Check(v) (Py_TYPE(v) == &BPy_BMFaceSeq_Type)
#define BPy_BMLoopSeq_Check(v) (Py_TYPE(v) == &BPy_BMLoopSeq_Type)
#define BPy_BMIter_Check(v) (Py_TYPE(v) == &BPy_BMIter_Type)
/* cast from _any_ bmesh type - they all have BMesh first */
@@ -62,7 +72,7 @@ typedef struct BPy_BMElem {
typedef struct BPy_BMesh {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
char py_owns;
int flag;
} BPy_BMesh;
/* element types */
@@ -93,6 +103,13 @@ typedef struct BPy_BMLoop {
/* iterators */
/* used for ...
* - BPy_BMElemSeq_Type
* - BPy_BMVertSeq_Type
* - BPy_BMEdgeSeq_Type
* - BPy_BMFaceSeq_Type
* - BPy_BMLoopSeq_Type
*/
typedef struct BPy_BMElemSeq {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
@@ -120,12 +137,21 @@ void BPy_BM_init_types(void);
PyObject *BPyInit_bmesh_types(void);
PyObject *BPy_BMesh_CreatePyObject(BMesh *bm);
enum {
BPY_BMFLAG_NOP = 0, /* do nothing */
BPY_BMFLAG_IS_WRAPPED = 1 /* the mesh is owned by editmode */
};
PyObject *BPy_BMesh_CreatePyObject(BMesh *bm, int flag);
PyObject *BPy_BMVert_CreatePyObject(BMesh *bm, BMVert *v);
PyObject *BPy_BMEdge_CreatePyObject(BMesh *bm, BMEdge *e);
PyObject *BPy_BMFace_CreatePyObject(BMesh *bm, BMFace *f);
PyObject *BPy_BMLoop_CreatePyObject(BMesh *bm, BMLoop *l);
PyObject *BPy_BMElemSeq_CreatePyObject(BMesh *bm, BPy_BMElem *py_ele, const char itype);
PyObject *BPy_BMVertSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMEdgeSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMFaceSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMLoopSeq_CreatePyObject(BMesh *bm);
PyObject *BPy_BMIter_CreatePyObject(BMesh *bm);
PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele); /* just checks type and creates v/e/f/l */
@@ -134,11 +160,14 @@ int bpy_bm_generic_valid_check(BPy_BMGeneric *self);
void bpy_bm_generic_invalidate(BPy_BMGeneric *self);
void *BPy_BMElem_PySeq_As_Array(BMesh **r_bm, PyObject *seq, Py_ssize_t min, Py_ssize_t max, Py_ssize_t *r_size,
PyTypeObject *type,
const char htype,
const char do_unique_check, const char do_bm_check,
const char *error_prefix);
PyObject *BPy_BMElem_Array_As_Tuple(BMesh *bm, BMHeader **elem, Py_ssize_t elem_len);
int BPy_BMElem_CheckHType(PyTypeObject *type, const char htype);
char *BPy_BMElem_StringFromHType_ex(const char htype, char ret[32]);
char *BPy_BMElem_StringFromHType(const char htype);
#define BPY_BM_CHECK_OBJ(obj) if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0

View File

@@ -0,0 +1,952 @@
/*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2012 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bmesh_py_types_customdata.c
* \ingroup pybmesh
*
* This file defines the types for 'BMesh.verts/edges/faces/loops.layers'
* customdata layer access.
*/
#include <Python.h>
#include "BLI_string.h"
#include "BLI_math_vector.h"
#include "bmesh.h"
#include "bmesh_py_types.h"
#include "bmesh_py_types_customdata.h"
#include "bmesh_py_types_meshdata.h"
#include "../mathutils/mathutils.h"
#include "BKE_customdata.h"
#include "DNA_meshdata_types.h"
static CustomData *bpy_bm_customdata_get(BMesh *bm, char htype)
{
switch (htype) {
case BM_VERT: return &bm->vdata;
case BM_EDGE: return &bm->edata;
case BM_FACE: return &bm->pdata;
case BM_LOOP: return &bm->ldata;
}
BLI_assert(0);
return NULL;
}
static CustomDataLayer *bpy_bmlayeritem_get(BPy_BMLayerItem *self)
{
CustomData *data = bpy_bm_customdata_get(self->bm, self->htype);
return &data->layers[CustomData_get_layer_index_n(data, self->type, self->index)];
}
/* py-type definitions
* ******************* */
/* getseters
* ========= */
/* used for many different types */
PyDoc_STRVAR(bpy_bmlayeraccess_collection__float_doc,
"Generic float custom-data layer.\n\ntype: :class:`BMLayerCollection`"
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__int_doc,
"Generic int custom-data layer.\n\ntype: :class:`BMLayerCollection`"
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__string_doc,
"Generic string custom-data layer (exposed as bytes, 255 max length).\n\ntype: :class:`BMLayerCollection`"
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__deform_doc,
"Vertex deform weight :class:`BMDeformVert` (TODO).\n\ntype: :class:`BMLayerCollection`" // TYPE DOESN'T EXIST YET
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__shape_doc,
"Vertex shapekey absolute location (as a 3D Vector).\n\n:type: :class:`BMLayerCollection`"
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__bevel_weight_doc,
"Bevel weight float in [0 - 1].\n\n:type: :class:`BMLayerCollection`"
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__crease_doc,
"Edge crease for subsurf - float in [0 - 1].\n\n:type: :class:`BMLayerCollection`"
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__tex_doc,
"Accessor for :class:`BMTexPoly` layer (TODO).\n\ntype: :class:`BMLayerCollection`" // TYPE DOESN'T EXIST YET
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__uv_doc,
"Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n\ntype: :class:`BMLayerCollection`"
);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__color_doc,
"Accessor for vertex color layer.\n\ntype: :class:`BMLayerCollection`"
);
static PyObject *bpy_bmlayeraccess_collection_get(BPy_BMLayerAccess *self, void *flag)
{
const int type = (int)GET_INT_FROM_POINTER(flag);
BPY_BM_CHECK_OBJ(self);
return BPy_BMLayerCollection_CreatePyObject(self->bm, self->htype, type);
}
PyDoc_STRVAR(bpy_bmlayercollection_active_doc,
"This meshes vert sequence (read-only).\n\n:type: :class:`BMVertSeq`"
);
static PyObject *bpy_bmlayercollection_active_get(BPy_BMLayerItem *self, void *UNUSED(flag))
{
CustomData *data;
int index;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_active_layer_index(data, self->type);
if (index != -1) {
return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
}
else {
Py_RETURN_NONE;
}
}
PyDoc_STRVAR(bpy_bmlayercollection_name_doc,
"The layers unique name (read-only).\n\n:type: string"
);
static PyObject *bpy_bmlayeritem_name_get(BPy_BMLayerItem *self, void *UNUSED(flag))
{
CustomDataLayer *layer;
BPY_BM_CHECK_OBJ(self);
layer = bpy_bmlayeritem_get(self);
return PyUnicode_FromString(layer->name);
}
static PyGetSetDef bpy_bmlayeraccess_vert_getseters[] = {
{(char *)"deform", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__deform_doc, (void *)CD_MDEFORMVERT},
{(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
{(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
{(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
{(char *)"shape", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__shape_doc, (void *)CD_SHAPEKEY},
{(char *)"bevel_weight", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__bevel_weight_doc, (void *)CD_BWEIGHT},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeraccess_edge_getseters[] = {
{(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
{(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
{(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
{(char *)"bevel_weight", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__bevel_weight_doc, (void *)CD_BWEIGHT},
{(char *)"crease", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__crease_doc, (void *)CD_CREASE},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeraccess_face_getseters[] = {
{(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
{(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
{(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
{(char *)"tex", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__tex_doc, (void *)CD_MTEXPOLY},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeraccess_loop_getseters[] = {
{(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
{(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
{(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
{(char *)"uv", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__uv_doc, (void *)CD_MLOOPUV},
{(char *)"color", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__color_doc, (void *)CD_MLOOPCOL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayercollection_getseters[] = {
/* BMESH_TODO, make writeable */
{(char *)"active", (getter)bpy_bmlayercollection_active_get, (setter)NULL, (char *)bpy_bmlayercollection_active_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyGetSetDef bpy_bmlayeritem_getseters[] = {
/* BMESH_TODO, make writeable */
{(char *)"name", (getter)bpy_bmlayeritem_name_get, (setter)NULL, (char *)bpy_bmlayercollection_name_doc, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
/* Methods
* ======= */
/* BMLayerCollection
* ----------------- */
PyDoc_STRVAR(bpy_bmlayercollection_keys_doc,
".. method:: keys()\n"
"\n"
" Return the identifiers of collection members\n"
" (matching pythons dict.keys() functionality).\n"
"\n"
" :return: the identifiers for each member of this collection.\n"
" :rtype: list of strings\n"
);
static PyObject *bpy_bmlayercollection_keys(BPy_BMLayerCollection *self)
{
PyObject *ret;
PyObject *item;
int index;
CustomData *data;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_layer_index(data, self->type);
ret = PyList_New(0);
if (index != -1) {
int tot = CustomData_number_of_layers(data, self->type);
for ( ; tot-- > 0; index++) {
item = PyUnicode_FromString(data->layers[index].name);
PyList_Append(ret, item);
Py_DECREF(item);
}
}
return ret;
}
PyDoc_STRVAR(bpy_bmlayercollection_values_doc,
".. method:: items()\n"
"\n"
" Return the identifiers of collection members\n"
" (matching pythons dict.items() functionality).\n"
"\n"
" :return: (key, value) pairs for each member of this collection.\n"
" :rtype: list of tuples\n"
);
static PyObject *bpy_bmlayercollection_values(BPy_BMLayerCollection *self)
{
PyObject *ret;
PyObject *item;
int index;
CustomData *data;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_layer_index(data, self->type);
ret = PyList_New(0);
if (index != -1) {
int tot = CustomData_number_of_layers(data, self->type);
for ( ; tot-- > 0; index++) {
item = PyTuple_New(2);
PyTuple_SET_ITEM(item, 0, PyUnicode_FromString(data->layers[index].name));
PyTuple_SET_ITEM(item, 1, BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index));
PyList_Append(ret, item);
Py_DECREF(item);
}
}
return ret;
}
PyDoc_STRVAR(bpy_bmlayercollection_items_doc,
".. method:: values()\n"
"\n"
" Return the values of collection\n"
" (matching pythons dict.values() functionality).\n"
"\n"
" :return: the members of this collection.\n"
" :rtype: list\n"
);
static PyObject *bpy_bmlayercollection_items(BPy_BMLayerCollection *self)
{
PyObject *ret;
PyObject *item;
int index;
CustomData *data;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_layer_index(data, self->type);
ret = PyList_New(0);
if (index != -1) {
int tot = CustomData_number_of_layers(data, self->type);
for ( ; tot-- > 0; index++) {
item = BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
PyList_Append(ret, item);
Py_DECREF(item);
}
}
return ret;
}
PyDoc_STRVAR(bpy_bmlayercollection_get_doc,
".. method:: get(key, default=None)\n"
"\n"
" Returns the value of the layer matching the key or default\n"
" when not found (matches pythons dictionary function of the same name).\n"
"\n"
" :arg key: The key associated with the layer.\n"
" :type key: string\n"
" :arg default: Optional argument for the value to return if\n"
" *key* is not found.\n"
" :type default: Undefined\n"
);
static PyObject *bpy_bmlayercollection_get(BPy_BMLayerCollection *self, PyObject *args)
{
const char *key;
PyObject *def = Py_None;
BPY_BM_CHECK_OBJ(self);
if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) {
return NULL;
}
else {
CustomData *data;
int index;
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_named_layer_index(data, self->type, key);
if (index != -1) {
return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
}
}
return Py_INCREF(def), def;
}
static struct PyMethodDef bpy_bmelemseq_methods[] = {
{"keys", (PyCFunction)bpy_bmlayercollection_keys, METH_NOARGS, bpy_bmlayercollection_keys_doc},
{"values", (PyCFunction)bpy_bmlayercollection_values, METH_NOARGS, bpy_bmlayercollection_values_doc},
{"items", (PyCFunction)bpy_bmlayercollection_items, METH_NOARGS, bpy_bmlayercollection_items_doc},
{"get", (PyCFunction)bpy_bmlayercollection_get, METH_VARARGS, bpy_bmlayercollection_get_doc},
/* for later! */
#if 0
{"new", (PyCFunction)bpy_bmlayercollection_new, METH_O, bpy_bmlayercollection_new_doc},
{"remove", (PyCFunction)bpy_bmlayercollection_new, METH_O, bpy_bmlayercollection_remove_doc},
#endif
{NULL, NULL, 0, NULL}
};
/* Sequences
* ========= */
static Py_ssize_t bpy_bmlayercollection_length(BPy_BMLayerCollection *self)
{
CustomData *data;
BPY_BM_CHECK_INT(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
return CustomData_number_of_layers(data, self->type);
}
static PyObject *bpy_bmlayercollection_subscript_str(BPy_BMLayerCollection *self, const char *keyname)
{
CustomData *data;
int index;
BPY_BM_CHECK_OBJ(self);
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_named_layer_index(data, self->type, keyname);
if (index != -1) {
return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index);
}
else {
PyErr_Format(PyExc_KeyError,
"BMLayerCollection[key]: key \"%.200s\" not found", keyname);
return NULL;
}
}
static PyObject *bpy_bmlayercollection_subscript_int(BPy_BMLayerCollection *self, int keynum)
{
Py_ssize_t len;
BPY_BM_CHECK_OBJ(self);
len = bpy_bmlayercollection_length(self);
if (keynum < 0) keynum += len;
if (keynum >= 0) {
if (keynum < len) {
return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, keynum);
}
}
PyErr_Format(PyExc_IndexError,
"BMLayerCollection[index]: index %d out of range", keynum);
return NULL;
}
static PyObject *bpy_bmlayercollection_subscript_slice(BPy_BMLayerCollection *self, Py_ssize_t start, Py_ssize_t stop)
{
Py_ssize_t len = bpy_bmlayercollection_length(self);
int count = 0;
PyObject *tuple;
BPY_BM_CHECK_OBJ(self);
if (start >= start) start = len - 1;
if (stop >= stop) stop = len - 1;
tuple = PyTuple_New(stop - start);
for (count = start; count < stop; count++) {
PyTuple_SET_ITEM(tuple, count - start, BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, count));
}
return tuple;
}
static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, PyObject *key)
{
/* don't need error check here */
if (PyUnicode_Check(key)) {
return bpy_bmlayercollection_subscript_str(self, _PyUnicode_AsString(key));
}
else if (PyIndex_Check(key)) {
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
return NULL;
return bpy_bmlayercollection_subscript_int(self, i);
}
else if (PySlice_Check(key)) {
PySliceObject *key_slice = (PySliceObject *)key;
Py_ssize_t step = 1;
if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) {
return NULL;
}
else if (step != 1) {
PyErr_SetString(PyExc_TypeError,
"BMLayerCollection[slice]: slice steps not supported");
return NULL;
}
else if (key_slice->start == Py_None && key_slice->stop == Py_None) {
return bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MAX);
}
else {
Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX;
/* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */
if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) return NULL;
if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) return NULL;
if (start < 0 || stop < 0) {
/* only get the length for negative values */
Py_ssize_t len = bpy_bmlayercollection_length(self);
if (start < 0) start += len;
if (stop < 0) start += len;
}
if (stop - start <= 0) {
return PyTuple_New(0);
}
else {
return bpy_bmlayercollection_subscript_slice(self, start, stop);
}
}
}
else {
PyErr_SetString(PyExc_AttributeError,
"BMLayerCollection[key]: invalid key, key must be an int");
return NULL;
}
}
static int bpy_bmlayercollection_contains(BPy_BMLayerCollection *self, PyObject *value)
{
const char *keyname = _PyUnicode_AsString(value);
CustomData *data;
int index;
BPY_BM_CHECK_INT(self);
if (keyname == NULL) {
PyErr_SetString(PyExc_TypeError,
"BMLayerCollection.__contains__: expected a string");
return -1;
}
data = bpy_bm_customdata_get(self->bm, self->htype);
index = CustomData_get_named_layer_index(data, self->type, keyname);
return (index != -1) ? 1 : 0;
}
static PySequenceMethods bpy_bmlayercollection_as_sequence = {
(lenfunc)bpy_bmlayercollection_length, /* sq_length */
NULL, /* sq_concat */
NULL, /* sq_repeat */
(ssizeargfunc)bpy_bmlayercollection_subscript_int, /* sq_item */ /* Only set this so PySequence_Check() returns True */
NULL, /* sq_slice */
(ssizeobjargproc)NULL, /* sq_ass_item */
NULL, /* *was* sq_ass_slice */
(objobjproc)bpy_bmlayercollection_contains, /* sq_contains */
(binaryfunc) NULL, /* sq_inplace_concat */
(ssizeargfunc) NULL, /* sq_inplace_repeat */
};
static PyMappingMethods bpy_bmlayercollection_as_mapping = {
(lenfunc)bpy_bmlayercollection_length, /* mp_length */
(binaryfunc)bpy_bmlayercollection_subscript, /* mp_subscript */
(objobjargproc)NULL, /* mp_ass_subscript */
};
/* Iterator
* -------- */
static PyObject *bpy_bmlayercollection_iter(BPy_BMLayerCollection *self)
{
/* fake it with a list iterator */
PyObject *ret;
PyObject *iter = NULL;
BPY_BM_CHECK_OBJ(self);
ret = bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MIN);
if (ret) {
iter = PyObject_GetIter(ret);
Py_DECREF(ret);
}
return iter;
}
PyDoc_STRVAR(bpy_bmlayeraccess_type_doc,
"Exposes custom-data layer attributes."
);
PyDoc_STRVAR(bpy_bmlayercollection_type_doc,
"Gives access to a collection of custom-data layers of the same type and behaves like python dictionaries, "
"except for the ability to do list like index access."
);
PyDoc_STRVAR(bpy_bmlayeritem_type_doc,
"Exposes a single custom data layer, "
"their main purpose is for use as item accessors to custom-data when used with vert/edge/face/loop data."
);
PyTypeObject BPy_BMLayerAccessVert_Type = {{{0}}}; /* bm.verts.layers */
PyTypeObject BPy_BMLayerAccessEdge_Type = {{{0}}}; /* bm.edges.layers */
PyTypeObject BPy_BMLayerAccessFace_Type = {{{0}}}; /* bm.faces.layers */
PyTypeObject BPy_BMLayerAccessLoop_Type = {{{0}}}; /* bm.loops.layers */
PyTypeObject BPy_BMLayerCollection_Type = {{{0}}}; /* bm.loops.layers.uv */
PyTypeObject BPy_BMLayerItem_Type = {{{0}}}; /* bm.loops.layers.uv["UVMap"] */
PyObject *BPy_BMLayerAccess_CreatePyObject(BMesh *bm, const char htype)
{
BPy_BMLayerAccess *self;
PyTypeObject *type;
switch (htype) {
case BM_VERT: type = &BPy_BMLayerAccessVert_Type; break;
case BM_EDGE: type = &BPy_BMLayerAccessEdge_Type; break;
case BM_FACE: type = &BPy_BMLayerAccessFace_Type; break;
case BM_LOOP: type = &BPy_BMLayerAccessLoop_Type; break;
default:
{
BLI_assert(0);
type = NULL;
break;
}
}
self = PyObject_New(BPy_BMLayerAccess, type);
self->bm = bm;
self->htype = htype;
return (PyObject *)self;
}
PyObject *BPy_BMLayerCollection_CreatePyObject(BMesh *bm, const char htype, int type)
{
BPy_BMLayerCollection *self = PyObject_New(BPy_BMLayerCollection, &BPy_BMLayerCollection_Type);
self->bm = bm;
self->htype = htype;
self->type = type;
return (PyObject *)self;
}
PyObject *BPy_BMLayerItem_CreatePyObject(BMesh *bm, const char htype, int type, int index)
{
BPy_BMLayerItem *self = PyObject_New(BPy_BMLayerItem, &BPy_BMLayerItem_Type);
self->bm = bm;
self->htype = htype;
self->type = type;
self->index = index;
return (PyObject *)self;
}
void BPy_BM_init_types_customdata(void)
{
BPy_BMLayerAccessVert_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
BPy_BMLayerAccessEdge_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
BPy_BMLayerAccessFace_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
BPy_BMLayerAccessLoop_Type.tp_basicsize = sizeof(BPy_BMLayerAccess);
BPy_BMLayerCollection_Type.tp_basicsize = sizeof(BPy_BMLayerCollection);
BPy_BMLayerItem_Type.tp_basicsize = sizeof(BPy_BMLayerItem);
BPy_BMLayerAccessVert_Type.tp_name = "BMLayerAccessVert";
BPy_BMLayerAccessEdge_Type.tp_name = "BMLayerAccessEdge";
BPy_BMLayerAccessFace_Type.tp_name = "BMLayerAccessFace";
BPy_BMLayerAccessLoop_Type.tp_name = "BMLayerAccessLoop";
BPy_BMLayerCollection_Type.tp_name = "BMLayerCollection";
BPy_BMLayerItem_Type.tp_name = "BMLayerItem";
/* todo */
BPy_BMLayerAccessVert_Type.tp_doc = bpy_bmlayeraccess_type_doc;
BPy_BMLayerAccessEdge_Type.tp_doc = bpy_bmlayeraccess_type_doc;
BPy_BMLayerAccessFace_Type.tp_doc = bpy_bmlayeraccess_type_doc;
BPy_BMLayerAccessLoop_Type.tp_doc = bpy_bmlayeraccess_type_doc;
BPy_BMLayerCollection_Type.tp_doc = bpy_bmlayercollection_type_doc;
BPy_BMLayerItem_Type.tp_doc = bpy_bmlayeritem_type_doc;
BPy_BMLayerAccessVert_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerAccessEdge_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerAccessFace_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerAccessLoop_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerCollection_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerItem_Type.tp_repr = (reprfunc)NULL;
BPy_BMLayerAccessVert_Type.tp_getset = bpy_bmlayeraccess_vert_getseters;
BPy_BMLayerAccessEdge_Type.tp_getset = bpy_bmlayeraccess_edge_getseters;
BPy_BMLayerAccessFace_Type.tp_getset = bpy_bmlayeraccess_face_getseters;
BPy_BMLayerAccessLoop_Type.tp_getset = bpy_bmlayeraccess_loop_getseters;
BPy_BMLayerCollection_Type.tp_getset = bpy_bmlayercollection_getseters;
BPy_BMLayerItem_Type.tp_getset = bpy_bmlayeritem_getseters;
// BPy_BMLayerAccess_Type.tp_methods = bpy_bmeditselseq_methods;
BPy_BMLayerCollection_Type.tp_methods = bpy_bmelemseq_methods;
BPy_BMLayerCollection_Type.tp_as_sequence = &bpy_bmlayercollection_as_sequence;
BPy_BMLayerCollection_Type.tp_as_mapping = &bpy_bmlayercollection_as_mapping;
BPy_BMLayerCollection_Type.tp_iter = (getiterfunc)bpy_bmlayercollection_iter;
BPy_BMLayerAccessVert_Type.tp_dealloc = NULL;
BPy_BMLayerAccessEdge_Type.tp_dealloc = NULL;
BPy_BMLayerAccessFace_Type.tp_dealloc = NULL;
BPy_BMLayerAccessLoop_Type.tp_dealloc = NULL;
BPy_BMLayerCollection_Type.tp_dealloc = NULL;
BPy_BMLayerItem_Type.tp_dealloc = NULL;
BPy_BMLayerAccessVert_Type.tp_flags = Py_TPFLAGS_DEFAULT;
BPy_BMLayerAccessEdge_Type.tp_flags = Py_TPFLAGS_DEFAULT;
BPy_BMLayerAccessFace_Type.tp_flags = Py_TPFLAGS_DEFAULT;
BPy_BMLayerAccessLoop_Type.tp_flags = Py_TPFLAGS_DEFAULT;
BPy_BMLayerCollection_Type.tp_flags = Py_TPFLAGS_DEFAULT;
BPy_BMLayerItem_Type.tp_flags = Py_TPFLAGS_DEFAULT;
PyType_Ready(&BPy_BMLayerAccessVert_Type);
PyType_Ready(&BPy_BMLayerAccessEdge_Type);
PyType_Ready(&BPy_BMLayerAccessFace_Type);
PyType_Ready(&BPy_BMLayerAccessLoop_Type);
PyType_Ready(&BPy_BMLayerCollection_Type);
PyType_Ready(&BPy_BMLayerItem_Type);
}
/* Per Element Get/Set
* ******************* */
/**
* helper function for get/set, NULL return means the error is set
*/
static void *bpy_bmlayeritem_ptr_get(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
{
void *value;
BMElem *ele = py_ele->ele;
CustomData *data;
/* error checking */
if (UNLIKELY(!BPy_BMLayerItem_Check(py_layer))) {
PyErr_SetString(PyExc_AttributeError,
"BMElem[key]: invalid key, must be a BMLayerItem");
return NULL;
}
else if (UNLIKELY(py_ele->bm != py_layer->bm)) {
PyErr_SetString(PyExc_ValueError,
"BMElem[layer]: layer is from another mesh");
return NULL;
}
else if (UNLIKELY(ele->head.htype != py_layer->htype)) {
char namestr_1[32], namestr_2[32];
PyErr_Format(PyExc_ValueError,
"Layer/Element type mismatch, expected %.200s got layer type %.200s",
BPy_BMElem_StringFromHType_ex(ele->head.htype, namestr_1),
BPy_BMElem_StringFromHType_ex(py_layer->htype, namestr_2));
return NULL;
}
data = bpy_bm_customdata_get(py_layer->bm, py_layer->htype);
value = CustomData_bmesh_get_n(data, ele->head.data, py_layer->type, py_layer->index);
if (UNLIKELY(value == NULL)) {
/* this should be fairly unlikely but possible if layers move about after we get them */
PyErr_SetString(PyExc_KeyError,
"BMElem[key]: layer not found");
return NULL;
}
else {
return value;
}
}
/**
*\brief BMElem.__getitem__()
*
* assume all error checks are done, eg:
*
* uv = vert[uv_layer]
*/
PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
{
void *value = bpy_bmlayeritem_ptr_get(py_ele, py_layer);
PyObject *ret;
if (UNLIKELY(value == NULL)) {
return NULL;
}
switch (py_layer->type) {
case CD_MDEFORMVERT:
{
ret = Py_NotImplemented; /* TODO */
Py_INCREF(ret);
break;
}
case CD_PROP_FLT:
{
ret = PyFloat_FromDouble(*(float *)value);
break;
}
case CD_PROP_INT:
{
ret = PyLong_FromSsize_t((Py_ssize_t)(*(int *)value));
break;
}
case CD_PROP_STR:
{
MStringProperty *mstring = value;
ret = PyBytes_FromStringAndSize(mstring->s, BLI_strnlen(mstring->s, sizeof(mstring->s)));
break;
}
case CD_MTEXPOLY:
{
ret = Py_NotImplemented; /* TODO */
Py_INCREF(ret);
break;
}
case CD_MLOOPUV:
{
ret = BPy_BMLoopUV_CreatePyObject(value);
break;
}
case CD_MLOOPCOL:
{
ret = BPy_BMLoopColor_CreatePyObject(value);
break;
}
case CD_SHAPEKEY:
{
ret = Vector_CreatePyObject((float *)value, 3, Py_WRAP, NULL);
break;
}
case CD_BWEIGHT:
{
ret = PyFloat_FromDouble(*(float *)value);
break;
}
case CD_CREASE:
{
ret = PyFloat_FromDouble(*(float *)value);
break;
}
default:
{
ret = Py_NotImplemented; /* TODO */
Py_INCREF(ret);
break;
}
}
return ret;
}
int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *py_value)
{
int ret = 0;
void *value = bpy_bmlayeritem_ptr_get(py_ele, py_layer);
if (UNLIKELY(value == NULL)) {
return -1;
}
switch (py_layer->type) {
case CD_MDEFORMVERT:
{
PyErr_SetString(PyExc_AttributeError, "readonly"); /* could make this writeable later */
ret = -1;
break;
}
case CD_PROP_FLT:
{
float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(float *)value = tmp_val;
}
break;
}
case CD_PROP_INT:
{
int tmp_val = PyLong_AsSsize_t(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected an int, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(int *)value = tmp_val;
}
break;
}
case CD_PROP_STR:
{
MStringProperty *mstring = value;
const char *tmp_val = PyBytes_AsString(py_value);
if (UNLIKELY(tmp_val == NULL)) {
PyErr_Format(PyExc_TypeError, "expected bytes, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
BLI_strncpy(mstring->s, tmp_val, sizeof(mstring->s));
}
break;
}
case CD_MTEXPOLY:
{
PyErr_SetString(PyExc_AttributeError, "readonly"); /* could make this writeable later */
ret = -1;
break;
}
case CD_MLOOPUV:
{
ret = BPy_BMLoopUV_AssignPyObject(value, py_value);
break;
}
case CD_MLOOPCOL:
{
ret = BPy_BMLoopColor_AssignPyObject(value, py_value);
break;
}
case CD_SHAPEKEY:
{
float tmp_val[3];
if (UNLIKELY(mathutils_array_parse(tmp_val, 3, 3, py_value, "BMVert[shape] = value") == -1)) {
ret = -1;
}
else {
copy_v3_v3((float *)value, tmp_val);
}
break;
}
case CD_BWEIGHT:
{
float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(float *)value = CLAMPIS(tmp_val, 0.0f, 1.0f);
}
break;
}
case CD_CREASE:
{
float tmp_val = PyFloat_AsDouble(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
PyErr_Format(PyExc_TypeError, "expected a float, not a %.200s", Py_TYPE(py_value)->tp_name);
ret = -1;
}
else {
*(float *)value = CLAMPIS(tmp_val, 0.0f, 1.0f);
}
break;
}
default:
{
PyErr_SetString(PyExc_AttributeError, "readonly / unsupported type");
ret = -1;
break;
}
}
return ret;
}

View File

@@ -0,0 +1,81 @@
/*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2012 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bmesh_py_types_customdata.h
* \ingroup pybmesh
*/
#ifndef __BMESH_PY_TYPES_CUSTOMDATA_H__
#define __BMESH_PY_TYPES_CUSTOMDATA_H__
/* all use BPy_BMLayerAccess struct */
extern PyTypeObject BPy_BMLayerAccessVert_Type;
extern PyTypeObject BPy_BMLayerAccessEdge_Type;
extern PyTypeObject BPy_BMLayerAccessFace_Type;
extern PyTypeObject BPy_BMLayerAccessLoop_Type;
extern PyTypeObject BPy_BMLayerCollection_Type;
extern PyTypeObject BPy_BMLayerItem_Type;
#define BPy_BMLayerAccess_Check(v) (Py_TYPE(v) == &BPy_BMLayerAccess_Type)
#define BPy_BMLayerCollection_Check(v) (Py_TYPE(v) == &BPy_BMLayerCollection_Type)
#define BPy_BMLayerItem_Check(v) (Py_TYPE(v) == &BPy_BMLayerItem_Type)
/* all layers for vert/edge/face/loop */
typedef struct BPy_BMLayerAccess {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
char htype;
} BPy_BMLayerAccess;
/* access different layer types deform/uv/vertexcolor */
typedef struct BPy_BMLayerCollection {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
char htype;
int type; /* customdata type - CD_XXX */
} BPy_BMLayerCollection;
/* access a specific layer directly */
typedef struct BPy_BMLayerItem {
PyObject_VAR_HEAD
struct BMesh *bm; /* keep first */
char htype;
int type; /* customdata type - CD_XXX */
int index; /* index of this layer type */
} BPy_BMLayerItem;
PyObject *BPy_BMLayerAccess_CreatePyObject(BMesh *bm, const char htype);
PyObject *BPy_BMLayerCollection_CreatePyObject(BMesh *bm, const char htype, int type);
PyObject *BPy_BMLayerItem_CreatePyObject(BMesh *bm, const char htype, int type, int index);
void BPy_BM_init_types_customdata(void);
/* __getitem__ / __setitem__ */
PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer);
int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObject *value);
#endif /* __BMESH_PY_TYPES_CUSTOMDATA_H__ */

View File

@@ -0,0 +1,260 @@
/*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2012 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bmesh_py_types_meshdata.c
* \ingroup pybmesh
*
* This file defines customdata types which can't be accessed as primitive
* python types such as MDeformVert, MLoopUV, MTexPoly
*/
#include <Python.h>
#include "../mathutils/mathutils.h"
#include "DNA_meshdata_types.h"
#include "BLI_utildefines.h"
#include "BLI_math_vector.h"
/* Mesh Loop UV
* ************ */
#define BPy_BMLoopUV_Check(v) (Py_TYPE(v) == &BPy_BMLoopUV_Type)
typedef struct BPy_BMLoopUV {
PyObject_VAR_HEAD
MLoopUV *data;
} BPy_BMLoopUV;
PyDoc_STRVAR(bpy_bmloopuv_uv_doc,
"Loops UV (as a 2D Vector).\n\n:type: :class:`mathutils.Vector`"
);
static PyObject *bpy_bmloopuv_uv_get(BPy_BMLoopUV *self, void *UNUSED(closure))
{
return Vector_CreatePyObject(self->data->uv, 2, Py_WRAP, NULL);
}
static int bpy_bmloopuv_uv_set(BPy_BMLoopUV *self, PyObject *value, void *UNUSED(closure))
{
float tvec[2];
if (mathutils_array_parse(tvec, 2, 2, value, "BMLoopUV.uv") != -1) {
copy_v2_v2(self->data->uv, tvec);
return 0;
}
else {
return -1;
}
}
PyDoc_STRVAR(bpy_bmloopuv_flag__pin_uv_doc,
"UV pin state.\n\n:type: boolean"
);
PyDoc_STRVAR(bpy_bmloopuv_flag__select_doc,
"UV select state.\n\n:type: boolean"
);
PyDoc_STRVAR(bpy_bmloopuv_flag__select_edge_doc,
"UV edge select state.\n\n:type: boolean"
);
static PyObject *bpy_bmloopuv_flag_get(BPy_BMLoopUV *self, void *flag_p)
{
const int flag = GET_INT_FROM_POINTER(flag_p);
return PyBool_FromLong(self->data->flag & flag);
}
static int bpy_bmloopuv_flag_set(BPy_BMLoopUV *self, PyObject *value, void *flag_p)
{
const int flag = GET_INT_FROM_POINTER(flag_p);
switch (PyLong_AsLong(value)) {
case TRUE:
self->data->flag |= flag;
return 0;
case FALSE:
self->data->flag &= ~flag;
return 0;
default:
PyErr_SetString(PyExc_TypeError,
"expected a boolean type 0/1");
return -1;
}
}
static PyGetSetDef bpy_bmloopuv_getseters[] = {
/* attributes match rna_def_mloopuv */
{(char *)"uv", (getter)bpy_bmloopuv_uv_get, (setter)bpy_bmloopuv_uv_set, (char *)bpy_bmloopuv_uv_doc, NULL},
{(char *)"pin_uv", (getter)bpy_bmloopuv_flag_get, (setter)bpy_bmloopuv_flag_set, (char *)bpy_bmloopuv_flag__pin_uv_doc, (void *)MLOOPUV_PINNED},
{(char *)"select", (getter)bpy_bmloopuv_flag_get, (setter)bpy_bmloopuv_flag_set, (char *)bpy_bmloopuv_flag__select_doc, (void *)MLOOPUV_VERTSEL},
{(char *)"select_edge", (getter)bpy_bmloopuv_flag_get, (setter)bpy_bmloopuv_flag_set, (char *)bpy_bmloopuv_flag__select_edge_doc, (void *)MLOOPUV_EDGESEL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
PyTypeObject BPy_BMLoopUV_Type = {{{0}}}; /* bm.loops.layers.uv.active */
static void bm_init_types_bmloopuv(void)
{
BPy_BMLoopUV_Type.tp_basicsize = sizeof(BPy_BMLoopUV);
BPy_BMLoopUV_Type.tp_name = "BMLoopUV";
BPy_BMLoopUV_Type.tp_doc = NULL; // todo
BPy_BMLoopUV_Type.tp_getset = bpy_bmloopuv_getseters;
BPy_BMLoopUV_Type.tp_flags = Py_TPFLAGS_DEFAULT;
PyType_Ready(&BPy_BMLoopUV_Type);
}
int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *mloopuv, PyObject *value)
{
if (UNLIKELY(!BPy_BMLoopUV_Check(value))) {
PyErr_Format(PyExc_TypeError, "expected BMLoopUV, not a %.200s", Py_TYPE(value)->tp_name);
return -1;
}
else {
*((MLoopUV *)mloopuv) = *((MLoopUV *)((BPy_BMLoopUV *)value)->data);
return 0;
}
}
PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *mloopuv)
{
BPy_BMLoopUV *self = PyObject_New(BPy_BMLoopUV, &BPy_BMLoopUV_Type);
self->data = mloopuv;
return (PyObject *)self;
}
/* --- End Mesh Loop UV --- */
/* Mesh Loop Color
* *************** */
/* This simply provices a color wrapper for
* color which uses mathutils callbacks for mathutils.Color
*/
#define MLOOPCOL_FROM_CAPSULE(color_capsule) \
((MLoopCol *)PyCapsule_GetPointer(color_capsule, NULL))
static void mloopcol_to_float(const MLoopCol *mloopcol, float col_r[3])
{
rgb_uchar_to_float(col_r, (unsigned char *)&mloopcol->r);
}
static void mloopcol_from_float(MLoopCol *mloopcol, const float col[3])
{
rgb_float_to_uchar((unsigned char *)&mloopcol->r, col);
}
static unsigned char mathutils_bmloopcol_cb_index = -1;
static int mathutils_bmloopcol_check(BaseMathObject *UNUSED(bmo))
{
/* always ok */
return 0;
}
static int mathutils_bmloopcol_get(BaseMathObject *bmo, int UNUSED(subtype))
{
MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
mloopcol_to_float(mloopcol, bmo->data);
return 0;
}
static int mathutils_bmloopcol_set(BaseMathObject *bmo, int UNUSED(subtype))
{
MLoopCol *mloopcol = MLOOPCOL_FROM_CAPSULE(bmo->cb_user);
mloopcol_from_float(mloopcol, bmo->data);
return 0;
}
static int mathutils_bmloopcol_get_index(BaseMathObject *bmo, int subtype, int UNUSED(index))
{
/* lazy, avoid repeteing the case statement */
if (mathutils_bmloopcol_get(bmo, subtype) == -1)
return -1;
return 0;
}
static int mathutils_bmloopcol_set_index(BaseMathObject *bmo, int subtype, int index)
{
const float f = bmo->data[index];
/* lazy, avoid repeteing the case statement */
if (mathutils_bmloopcol_get(bmo, subtype) == -1)
return -1;
bmo->data[index] = f;
return mathutils_bmloopcol_set(bmo, subtype);
}
Mathutils_Callback mathutils_bmloopcol_cb = {
mathutils_bmloopcol_check,
mathutils_bmloopcol_get,
mathutils_bmloopcol_set,
mathutils_bmloopcol_get_index,
mathutils_bmloopcol_set_index
};
static void bm_init_types_bmloopcol(void)
{
/* pass */
mathutils_bmloopcol_cb_index = Mathutils_RegisterCallback(&mathutils_bmloopcol_cb);
}
int BPy_BMLoopColor_AssignPyObject(struct MLoopCol *mloopcol, PyObject *value)
{
float tvec[3];
if (mathutils_array_parse(tvec, 3, 3, value, "BMLoopCol") != -1) {
mloopcol_from_float(mloopcol, tvec);
return 0;
}
else {
return -1;
}
}
PyObject *BPy_BMLoopColor_CreatePyObject(struct MLoopCol *data)
{
PyObject *color_capsule;
color_capsule = PyCapsule_New(data, NULL, NULL);
return Color_CreatePyObject_cb(color_capsule, mathutils_bmloopcol_cb_index, 0);
}
#undef MLOOPCOL_FROM_CAPSULE
/* --- End Mesh Loop Color --- */
/* call to init all types */
void BPy_BM_init_types_meshdata(void)
{
bm_init_types_bmloopuv();
bm_init_types_bmloopcol();
}

View File

@@ -0,0 +1,52 @@
/*
* ***** BEGIN GPL 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.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2012 Blender Foundation.
* All rights reserved.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bmesh_py_types_meshdata.h
* \ingroup pybmesh
*/
#ifndef __BMESH_PY_TYPES_MESHDATA_H__
#define __BMESH_PY_TYPES_MESHDATA_H__
extern PyTypeObject BPy_BMLoopUV_Type;
#define BPy_BMLoopUV_Check(v) (Py_TYPE(v) == &BPy_BMLoopUV_Type)
typedef struct BPy_BMGenericMeshData {
PyObject_VAR_HEAD
void *data;
} BPy_BMGenericMeshData;
struct MLoopUV;
int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *data, PyObject *value);
PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *data);
int BPy_BMLoopColor_AssignPyObject(struct MLoopUV *data, PyObject *value);
PyObject *BPy_BMLoopColor_CreatePyObject(struct MLoopUV *data);
void BPy_BM_init_types_meshdata(void);
#endif /* __BMESH_PY_TYPES_MESHDATA_H__ */

View File

@@ -23,22 +23,25 @@
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bmesh_py_select.c
/** \file blender/python/bmesh/bmesh_py_types_select.c
* \ingroup pybmesh
*
* This file defines the types for 'BMesh.select_history'
* sequence and iterator.
*
* select_history is very loosely based on pytons set() type,
* since items can only exist once. however they do have an order.
*/
#include <Python.h>
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "bmesh.h"
#include "bmesh_py_types.h"
#include "bmesh_py_select.h"
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "bmesh_py_types_select.h"
#include "BKE_tessmesh.h"
@@ -69,8 +72,98 @@ static PyGetSetDef bpy_bmeditselseq_getseters[] = {
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
PyDoc_STRVAR(bpy_bmeditselseq_validate_doc,
".. method:: validate()\n"
"\n"
" Ensures all elements in the selection history are selected.\n"
);
static PyObject *bpy_bmeditselseq_validate(BPy_BMEditSelSeq *self)
{
BPY_BM_CHECK_OBJ(self);
BM_select_history_validate(self->bm);
Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmeditselseq_clear_doc,
".. method:: clear()\n"
"\n"
" Empties the selection history.\n"
);
static PyObject *bpy_bmeditselseq_clear(BPy_BMEditSelSeq *self)
{
BPY_BM_CHECK_OBJ(self);
BM_select_history_clear(self->bm);
Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmeditselseq_add_doc,
".. method:: add(element)\n"
"\n"
" Add an element to the selection history (no action taken if its already added).\n"
);
static PyObject *bpy_bmeditselseq_add(BPy_BMEditSelSeq *self, BPy_BMElem *value)
{
BPY_BM_CHECK_OBJ(self);
if ((BPy_BMVert_Check(value) ||
BPy_BMEdge_Check(value) ||
BPy_BMFace_Check(value)) == FALSE)
{
PyErr_Format(PyExc_TypeError,
"Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
return NULL;
}
BPY_BM_CHECK_OBJ(value);
if (self->bm != value->bm) {
PyErr_SetString(PyExc_ValueError,
"Element is not from this mesh");
return NULL;
}
BM_select_history_store(self->bm, value->ele);
Py_RETURN_NONE;
}
PyDoc_STRVAR(bpy_bmeditselseq_remove_doc,
".. method:: remove(element)\n"
"\n"
" Remove an element from the selection history.\n"
);
static PyObject *bpy_bmeditselseq_remove(BPy_BMEditSelSeq *self, BPy_BMElem *value)
{
BPY_BM_CHECK_OBJ(self);
if ((BPy_BMVert_Check(value) ||
BPy_BMEdge_Check(value) ||
BPy_BMFace_Check(value)) == FALSE)
{
PyErr_Format(PyExc_TypeError,
"Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
return NULL;
}
BPY_BM_CHECK_OBJ(value);
if ((self->bm != value->bm) ||
(BM_select_history_remove(self->bm, value->ele) == FALSE))
{
PyErr_SetString(PyExc_ValueError,
"Element not found in selection history");
return NULL;
}
Py_RETURN_NONE;
}
static struct PyMethodDef bpy_bmeditselseq_methods[] = {
// {"select_flush_mode", (PyCFunction)bpy_bmesh_select_flush_mode, METH_NOARGS, bpy_bmesh_select_flush_mode_doc},
{"validate", (PyCFunction)bpy_bmeditselseq_validate, METH_NOARGS, bpy_bmeditselseq_validate_doc},
{"clear", (PyCFunction)bpy_bmeditselseq_clear, METH_NOARGS, bpy_bmeditselseq_clear_doc},
{"add", (PyCFunction)bpy_bmeditselseq_add, METH_O, bpy_bmeditselseq_add_doc},
{"remove", (PyCFunction)bpy_bmeditselseq_remove, METH_O, bpy_bmeditselseq_remove_doc},
{NULL, NULL, 0, NULL}
};
@@ -103,7 +196,7 @@ static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keyn
}
else {
PyErr_Format(PyExc_IndexError,
"BMElemSeq[index]: index %d out of range", keynum);
"BMElemSeq[index]: index %d out of range", keynum);
return NULL;
}
}
@@ -154,7 +247,7 @@ static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, Py_ssi
static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *key)
{
/* dont need error check here */
/* don't need error check here */
if (PyIndex_Check(key)) {
Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
@@ -213,15 +306,7 @@ static int bpy_bmeditselseq_contains(BPy_BMEditSelSeq *self, PyObject *value)
value_bm_ele = (BPy_BMElem *)value;
if (value_bm_ele->bm == self->bm) {
BMEditSelection *ese_test;
BMElem *ele;
ele = value_bm_ele->ele;
for (ese_test = self->bm->selected.first; ese_test; ese_test = ese_test->next) {
if (ele == ese_test->ele) {
return 1;
}
}
return BM_select_history_check(self->bm, value_bm_ele->ele);
}
return 0;
@@ -274,7 +359,7 @@ static PyObject *bpy_bmeditseliter_next(BPy_BMEditSelIter *self)
}
}
PyTypeObject BPy_BMEditSelSeq_Type = {{{0}}};
PyTypeObject BPy_BMEditSelSeq_Type = {{{0}}};
PyTypeObject BPy_BMEditSelIter_Type = {{{0}}};
@@ -294,7 +379,7 @@ PyObject *BPy_BMEditSelIter_CreatePyObject(BMesh *bm)
return (PyObject *)self;
}
void BPy_BM_init_select_types(void)
void BPy_BM_init_types_select(void)
{
BPy_BMEditSelSeq_Type.tp_basicsize = sizeof(BPy_BMEditSelSeq);
BPy_BMEditSelIter_Type.tp_basicsize = sizeof(BPy_BMEditSelIter);
@@ -332,3 +417,38 @@ void BPy_BM_init_select_types(void)
PyType_Ready(&BPy_BMEditSelSeq_Type);
PyType_Ready(&BPy_BMEditSelIter_Type);
}
/* utility function */
/**
* \note doesnt actually check selection.
*/
int BPy_BMEditSel_Assign(BPy_BMesh *self, PyObject *value)
{
BMesh *bm;
Py_ssize_t value_len;
Py_ssize_t i;
BMElem **value_array = NULL;
BPY_BM_CHECK_INT(self);
bm = self->bm;
value_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
&value_len, BM_VERT | BM_EDGE | BM_FACE,
TRUE, TRUE, "BMesh.select_history = value");
if (value_array == NULL) {
return -1;
}
BM_select_history_clear(bm);
for (i = 0; i < value_len; i++) {
BM_select_history_store_notest(bm, value_array[i]);
}
PyMem_FREE(value_array);
return 0;
}

View File

@@ -23,12 +23,14 @@
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/bmesh/bmesh_py_select.h
/** \file blender/python/bmesh/bmesh_py_types_select.h
* \ingroup pybmesh
*/
#ifndef __BMESH_PY_SELECT_H__
#define __BMESH_PY_SELECT_H__
#ifndef __BMESH_PY_TYPES_SELECT_H__
#define __BMESH_PY_TYPES_SELECT_H__
struct BPy_BMesh;
extern PyTypeObject BPy_BMEditSelSeq_Type;
extern PyTypeObject BPy_BMEditSelIter_Type;
@@ -47,9 +49,10 @@ typedef struct BPy_BMEditSelIter {
struct BMEditSelection *ese;
} BPy_BMEditSelIter;
void BPy_BM_init_select_types(void);
void BPy_BM_init_types_select(void);
PyObject *BPy_BMEditSel_CreatePyObject(BMesh *bm);
PyObject *BPy_BMEditSelIter_CreatePyObject(BMesh *bm);
int BPy_BMEditSel_Assign(struct BPy_BMesh *self, PyObject *value);
#endif /* __BMESH_PY_SELECT_H__ */

View File

@@ -32,14 +32,14 @@
#include <Python.h>
#include "bmesh.h"
#include "bmesh_py_types.h"
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
#include "bmesh.h"
#include "bmesh_py_types.h"
#include "bmesh_py_utils.h" /* own include */
@@ -49,11 +49,11 @@ PyDoc_STRVAR(bpy_bm_utils_vert_collapse_edge_doc,
" Collapse a vertex into an edge.\n"
"\n"
" :arg vert: The vert that will be collapsed.\n"
" :type vert: :class:`BMVert`\n"
" :type vert: :class:`bmesh.types.BMVert`\n"
" :arg edge: The edge to collapse into.\n"
" :type edge: :class:`BMEdge`\n"
" :type edge: :class:`bmesh.types.BMEdge`\n"
" :return: The resulting edge from the collapse operation.\n"
" :rtype: :class:`BMEdge`\n"
" :rtype: :class:`bmesh.types.BMEdge`\n"
);
static PyObject *bpy_bm_utils_vert_collapse_edge(PyObject *UNUSED(self), PyObject *args)
{
@@ -109,13 +109,13 @@ PyDoc_STRVAR(bpy_bm_utils_vert_collapse_faces_doc,
" Split an edge, return the newly created data.\n"
"\n"
" :arg vert: The vert that will be collapsed.\n"
" :type vert: :class:`BMVert`\n"
" :type vert: :class:`bmesh.types.BMVert`\n"
" :arg edge: The edge to collapse into.\n"
" :type edge: :class:`BMEdge`\n"
" :type edge: :class:`bmesh.types.BMEdge`\n"
" :arg fac: The factor to use when merging customdata [0 - 1].\n"
" :type fac: float\n"
" :return: The resulting edge from the collapse operation.\n"
" :rtype: :class:`BMEdge`\n"
" :rtype: :class:`bmesh.types.BMEdge`\n"
);
static PyObject *bpy_bm_utils_vert_collapse_faces(PyObject *UNUSED(self), PyObject *args)
{
@@ -175,7 +175,7 @@ PyDoc_STRVAR(bpy_bm_utils_vert_dissolve_doc,
" Dissolve this vertex (will be removed).\n"
"\n"
" :arg vert: The vert to be dissolved.\n"
" :type vert: :class:`BMVert`\n"
" :type vert: :class:`bmesh.types.BMVert`\n"
" :return: True when the vertex dissolve is successful.\n"
" :rtype: boolean\n"
);
@@ -204,11 +204,11 @@ PyDoc_STRVAR(bpy_bm_utils_vert_separate_doc,
" Separate this vertex at every edge.\n"
"\n"
" :arg vert: The vert to be separated.\n"
" :type vert: :class:`BMVert`\n"
" :type vert: :class:`bmesh.types.BMVert`\n"
" :arg edges: The edges to separated.\n"
" :type edges: :class:`BMEdge`\n"
" :type edges: :class:`bmesh.types.BMEdge`\n"
" :return: The newly separated verts (including the vertex passed).\n"
" :rtype: tuple of :class:`BMVert`\n"
" :rtype: tuple of :class:`bmesh.types.BMVert`\n"
);
static PyObject *bpy_bm_utils_vert_separate(PyObject *UNUSED(self), PyObject *args)
{
@@ -238,7 +238,7 @@ static PyObject *bpy_bm_utils_vert_separate(PyObject *UNUSED(self), PyObject *ar
bm = py_vert->bm;
edge_array = BPy_BMElem_PySeq_As_Array(&bm, edge_seq, 0, PY_SSIZE_T_MAX,
&edge_array_len, &BPy_BMEdge_Type,
&edge_array_len, BM_EDGE,
TRUE, TRUE, "vert_separate(...)");
if (edge_array == NULL) {
@@ -266,9 +266,9 @@ PyDoc_STRVAR(bpy_bm_utils_edge_split_doc,
" Split an edge, return the newly created data.\n"
"\n"
" :arg edge: The edge to split.\n"
" :type edge: :class:`BMEdge`\n"
" :type edge: :class:`bmesh.types.BMEdge`\n"
" :arg vert: One of the verts on the edge, defines the split direction.\n"
" :type vert: :class:`BMVert`\n"
" :type vert: :class:`bmesh.types.BMVert`\n"
" :arg fac: The point on the edge where the new vert will be created [0 - 1].\n"
" :type fac: float\n"
" :return: The newly created (edge, vert) pair.\n"
@@ -329,11 +329,11 @@ PyDoc_STRVAR(bpy_bm_utils_edge_rotate_doc,
" If rotating the edge fails, None will be returned.\n"
"\n"
" :arg edge: The edge to rotate.\n"
" :type edge: :class:`BMEdge`\n"
" :type edge: :class:`bmesh.types.BMEdge`\n"
" :arg ccw: When True the edge will be rotated counter clockwise.\n"
" :type ccw: boolean\n"
" :return: The newly rotated edge.\n"
" :rtype: :class:`BMEdge`\n"
" :rtype: :class:`bmesh.types.BMEdge`\n"
);
static PyObject *bpy_bm_utils_edge_rotate(PyObject *UNUSED(self), PyObject *args)
{
@@ -371,13 +371,13 @@ PyDoc_STRVAR(bpy_bm_utils_face_split_doc,
" Split an edge, return the newly created data.\n"
"\n"
" :arg face: The face to cut.\n"
" :type face: :class:`BMFace`\n"
" :type face: :class:`bmesh.types.BMFace`\n"
" :arg vert_a: First vertex to cut in the face (face must contain the vert).\n"
" :type vert_a: :class:`BMVert`\n"
" :type vert_a: :class:`bmesh.types.BMVert`\n"
" :arg vert_b: Second vertex to cut in the face (face must contain the vert).\n"
" :type vert_b: :class:`BMVert`\n"
" :type vert_b: :class:`bmesh.types.BMVert`\n"
" :arg edge_example: Optional edge argument, newly created edge will copy settings from this one.\n"
" :type edge_example: :class:`BMEdge`\n"
" :type edge_example: :class:`bmesh.types.BMEdge`\n"
);
static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args)
{
@@ -448,9 +448,9 @@ PyDoc_STRVAR(bpy_bm_utils_face_join_doc,
" Joins a sequence of faces.\n"
"\n"
" :arg faces: Sequence of faces.\n"
" :type faces: :class:`BMFace`\n"
" :type faces: :class:`bmesh.types.BMFace`\n"
" :return: The newly created face or None on failure.\n"
" :rtype: :class:`BMFace`\n"
" :rtype: :class:`bmesh.types.BMFace`\n"
);
static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *value)
{
@@ -460,7 +460,7 @@ static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *value)
BMFace *f_new;
face_array = BPy_BMElem_PySeq_As_Array(&bm, value, 2, PY_SSIZE_T_MAX,
&face_seq_len, &BPy_BMFace_Type,
&face_seq_len, BM_FACE,
TRUE, TRUE, "face_join(...)");
if (face_array == NULL) {
@@ -488,11 +488,11 @@ PyDoc_STRVAR(bpy_bm_utils_face_vert_separate_doc,
" Rip a vertex in a face away and add a new vertex.\n"
"\n"
" :arg face: The face to separate.\n"
" :type face: :class:`BMFace`\n"
" :type face: :class:`bmesh.types.BMFace`\n"
" :arg vert: A vertex in the face to separate.\n"
" :type vert: :class:`BMVert`\n"
" :type vert: :class:`bmesh.types.BMVert`\n"
" :return vert: The newly created vertex or None of failure.\n"
" :rtype vert: :class:`BMVert`\n"
" :rtype vert: :class:`bmesh.types.BMVert`\n"
"\n"
" .. note::\n"
"\n"
@@ -550,7 +550,7 @@ PyDoc_STRVAR(bpy_bm_utils_face_flip_doc,
" Flip the faces direction.\n"
"\n"
" :arg face: Face to flip.\n"
" :type face: :class:`BMFace`\n"
" :type face: :class:`bmesh.types.BMFace`\n"
);
static PyObject *bpy_bm_utils_face_flip(PyObject *UNUSED(self), BPy_BMFace *value)
{
@@ -576,9 +576,9 @@ PyDoc_STRVAR(bpy_bm_utils_loop_separate_doc,
" Rip a vertex in a face away and add a new vertex.\n"
"\n"
" :arg loop: The to separate.\n"
" :type loop: :class:`BMFace`\n"
" :type loop: :class:`bmesh.types.BMFace`\n"
" :return vert: The newly created vertex or None of failure.\n"
" :rtype vert: :class:`BMVert`\n"
" :rtype vert: :class:`bmesh.types.BMVert`\n"
);
static PyObject *bpy_bm_utils_loop_separate(PyObject *UNUSED(self), BPy_BMLoop *value)
{

View File

@@ -80,10 +80,10 @@ static PyObject *Buffer_repr(Buffer *self);
static PyObject *Buffer_to_list(Buffer *self)
{
int i, len= self->dimensions[0];
PyObject *list= PyList_New(len);
int i, len = self->dimensions[0];
PyObject *list = PyList_New(len);
for (i=0; i<len; i++) {
for (i = 0; i < len; i++) {
PyList_SET_ITEM(list, i, Buffer_item(self, i));
}
@@ -95,17 +95,17 @@ static PyObject *Buffer_to_list_recursive(Buffer *self)
PyObject *list;
if (self->ndimensions > 1) {
int i, len= self->dimensions[0];
list= PyList_New(len);
int i, len = self->dimensions[0];
list = PyList_New(len);
for (i=0; i<len; i++) {
Buffer *sub= (Buffer *)Buffer_item(self, i);
for (i = 0; i < len; i++) {
Buffer *sub = (Buffer *)Buffer_item(self, i);
PyList_SET_ITEM(list, i, Buffer_to_list_recursive(sub));
Py_DECREF(sub);
}
}
else {
list= Buffer_to_list(self);
list = Buffer_to_list(self);
}
return list;
@@ -113,10 +113,10 @@ static PyObject *Buffer_to_list_recursive(Buffer *self)
static PyObject *Buffer_dimensions(Buffer *self, void *UNUSED(arg))
{
PyObject *list= PyList_New(self->ndimensions);
PyObject *list = PyList_New(self->ndimensions);
int i;
for (i= 0; i<self->ndimensions; i++) {
for (i = 0; i < self->ndimensions; i++) {
PyList_SET_ITEM(list, i, PyLong_FromLong(self->dimensions[i]));
}
@@ -239,16 +239,16 @@ static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \
int BGL_typeSize(int type)
{
switch (type) {
case GL_BYTE:
return sizeof(char);
case GL_SHORT:
return sizeof(short);
case GL_INT:
return sizeof(int);
case GL_FLOAT:
return sizeof(float);
case GL_DOUBLE:
return sizeof(double);
case GL_BYTE:
return sizeof(char);
case GL_SHORT:
return sizeof(short);
case GL_INT:
return sizeof(int);
case GL_FLOAT:
return sizeof(float);
case GL_DOUBLE:
return sizeof(double);
}
return -1;
}
@@ -256,30 +256,31 @@ int BGL_typeSize(int type)
Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuffer)
{
Buffer *buffer;
void *buf= NULL;
void *buf = NULL;
int i, size, length;
length= 1;
for (i=0; i<ndimensions; i++)
length*= dimensions[i];
size= BGL_typeSize(type);
buf= MEM_mallocN(length*size, "Buffer buffer");
buffer= (Buffer *) PyObject_NEW(Buffer, &BGL_bufferType);
buffer->parent= NULL;
buffer->ndimensions= ndimensions;
buffer->dimensions= MEM_mallocN(ndimensions*sizeof(int), "Buffer dimensions");
memcpy(buffer->dimensions, dimensions, ndimensions*sizeof(int));
buffer->type= type;
buffer->buf.asvoid= buf;
length = 1;
for (i = 0; i < ndimensions; i++) {
length *= dimensions[i];
}
size = BGL_typeSize(type);
buf = MEM_mallocN(length * size, "Buffer buffer");
buffer = (Buffer *)PyObject_NEW(Buffer, &BGL_bufferType);
buffer->parent = NULL;
buffer->ndimensions = ndimensions;
buffer->dimensions = MEM_mallocN(ndimensions * sizeof(int), "Buffer dimensions");
memcpy(buffer->dimensions, dimensions, ndimensions * sizeof(int));
buffer->type = type;
buffer->buf.asvoid = buf;
if (initbuffer) {
memcpy(buffer->buf.asvoid, initbuffer, length*size);
memcpy(buffer->buf.asvoid, initbuffer, length * size);
}
else {
memset(buffer->buf.asvoid, 0, length*size);
memset(buffer->buf.asvoid, 0, length * size);
}
return buffer;
}
@@ -288,10 +289,10 @@ Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuf
#define MAX_DIMENSIONS 256
static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
{
PyObject *length_ob= NULL, *init= NULL;
PyObject *length_ob = NULL, *init = NULL;
Buffer *buffer;
int dimensions[MAX_DIMENSIONS];
int type;
Py_ssize_t i, ndimensions = 0;
@@ -312,15 +313,15 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
}
if (PyLong_Check(length_ob)) {
ndimensions= 1;
if (((dimensions[0]= PyLong_AsLong(length_ob)) < 1)) {
ndimensions = 1;
if (((dimensions[0] = PyLong_AsLong(length_ob)) < 1)) {
PyErr_SetString(PyExc_AttributeError,
"dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
return NULL;
}
}
else if (PySequence_Check(length_ob)) {
ndimensions= PySequence_Size(length_ob);
ndimensions = PySequence_Size(length_ob);
if (ndimensions > MAX_DIMENSIONS) {
PyErr_SetString(PyExc_AttributeError,
"too many dimensions, max is "STRINGIFY(MAX_DIMENSIONS));
@@ -331,11 +332,13 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
"sequence must have at least one dimension");
return NULL;
}
for (i=0; i<ndimensions; i++) {
PyObject *ob= PySequence_GetItem(length_ob, i);
for (i = 0; i < ndimensions; i++) {
PyObject *ob = PySequence_GetItem(length_ob, i);
if (!PyLong_Check(ob)) dimensions[i]= 1;
else dimensions[i]= PyLong_AsLong(ob);
if (!PyLong_Check(ob))
dimensions[i] = 1;
else
dimensions[i] = PyLong_AsLong(ob);
Py_DECREF(ob);
if (dimensions[i] < 1) {
@@ -351,16 +354,16 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
"or an int, not a %.200s", Py_TYPE(length_ob)->tp_name);
return NULL;
}
buffer= BGL_MakeBuffer(type, ndimensions, dimensions, NULL);
buffer = BGL_MakeBuffer(type, ndimensions, dimensions, NULL);
if (init && ndimensions) {
if (Buffer_ass_slice(buffer, 0, dimensions[0], init)) {
Py_DECREF(buffer);
return NULL;
}
}
return (PyObject *) buffer;
return (PyObject *)buffer;
}
/*@ Buffer sequence methods */
@@ -377,12 +380,12 @@ static PyObject *Buffer_item(Buffer *self, int i)
return NULL;
}
if (self->ndimensions==1) {
if (self->ndimensions == 1) {
switch (self->type) {
case GL_BYTE: return Py_BuildValue("b", self->buf.asbyte[i]);
case GL_SHORT: return Py_BuildValue("h", self->buf.asshort[i]);
case GL_INT: return Py_BuildValue("i", self->buf.asint[i]);
case GL_FLOAT: return PyFloat_FromDouble(self->buf.asfloat[i]);
case GL_BYTE: return Py_BuildValue("b", self->buf.asbyte[i]);
case GL_SHORT: return Py_BuildValue("h", self->buf.asshort[i]);
case GL_INT: return Py_BuildValue("i", self->buf.asint[i]);
case GL_FLOAT: return PyFloat_FromDouble(self->buf.asfloat[i]);
case GL_DOUBLE: return Py_BuildValue("d", self->buf.asdouble[i]);
}
}
@@ -390,26 +393,24 @@ static PyObject *Buffer_item(Buffer *self, int i)
Buffer *newbuf;
int j, length, size;
length= 1;
for (j=1; j < self->ndimensions; j++) {
length = 1;
for (j = 1; j < self->ndimensions; j++) {
length *= self->dimensions[j];
}
size= BGL_typeSize(self->type);
size = BGL_typeSize(self->type);
newbuf= (Buffer *) PyObject_NEW(Buffer, &BGL_bufferType);
newbuf = (Buffer *)PyObject_NEW(Buffer, &BGL_bufferType);
Py_INCREF(self);
newbuf->parent= (PyObject *)self;
newbuf->parent = (PyObject *)self;
newbuf->ndimensions= self->ndimensions - 1;
newbuf->type= self->type;
newbuf->buf.asvoid= self->buf.asbyte + i*length*size;
newbuf->dimensions= MEM_mallocN(newbuf->ndimensions*sizeof(int),
"Buffer dimensions");
memcpy(newbuf->dimensions, self->dimensions+1,
newbuf->ndimensions*sizeof(int));
newbuf->ndimensions = self->ndimensions - 1;
newbuf->type = self->type;
newbuf->buf.asvoid = self->buf.asbyte + i * length * size;
newbuf->dimensions = MEM_mallocN(newbuf->ndimensions * sizeof(int), "Buffer dimensions");
memcpy(newbuf->dimensions, self->dimensions + 1, newbuf->ndimensions * sizeof(int));
return (PyObject *) newbuf;
return (PyObject *)newbuf;
}
return NULL;
@@ -420,13 +421,13 @@ static PyObject *Buffer_slice(Buffer *self, int begin, int end)
PyObject *list;
int count;
if (begin < 0) begin= 0;
if (end > self->dimensions[0]) end= self->dimensions[0];
if (begin > end) begin= end;
if (begin < 0) begin = 0;
if (end > self->dimensions[0]) end = self->dimensions[0];
if (begin > end) begin = end;
list= PyList_New(end-begin);
list = PyList_New(end - begin);
for (count= begin; count<end; count++) {
for (count = begin; count < end; count++) {
PyList_SET_ITEM(list, count-begin, Buffer_item(self, count));
}
return list;
@@ -440,11 +441,11 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
return -1;
}
if (self->ndimensions!=1) {
Buffer *row= (Buffer *)Buffer_item(self, i);
if (self->ndimensions != 1) {
Buffer *row = (Buffer *)Buffer_item(self, i);
if (row) {
int ret= Buffer_ass_slice(row, 0, self->dimensions[1], v);
int ret = Buffer_ass_slice(row, 0, self->dimensions[1], v);
Py_DECREF(row);
return ret;
}
@@ -454,29 +455,23 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
}
switch (self->type) {
case GL_BYTE:
return PyArg_Parse(v, "b:Expected ints", &self->buf.asbyte[i]) ? 0:-1;
case GL_SHORT:
return PyArg_Parse(v, "h:Expected ints", &self->buf.asshort[i]) ? 0:-1;
case GL_INT:
return PyArg_Parse(v, "i:Expected ints", &self->buf.asint[i]) ? 0:-1;
case GL_FLOAT:
return PyArg_Parse(v, "f:Expected floats", &self->buf.asfloat[i]) ? 0:-1;
case GL_DOUBLE:
return PyArg_Parse(v, "d:Expected floats", &self->buf.asdouble[i]) ? 0:-1;
default:
return 0; /* should never happen */
case GL_BYTE: return PyArg_Parse(v, "b:Expected ints", &self->buf.asbyte[i]) ? 0 : -1;
case GL_SHORT: return PyArg_Parse(v, "h:Expected ints", &self->buf.asshort[i]) ? 0 : -1;
case GL_INT: return PyArg_Parse(v, "i:Expected ints", &self->buf.asint[i]) ? 0 : -1;
case GL_FLOAT: return PyArg_Parse(v, "f:Expected floats", &self->buf.asfloat[i]) ? 0 : -1;
case GL_DOUBLE: return PyArg_Parse(v, "d:Expected floats", &self->buf.asdouble[i]) ? 0 : -1;
default: return 0; /* should never happen */
}
}
static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
{
PyObject *item;
int count, err=0;
int count, err = 0;
if (begin < 0) begin= 0;
if (end > self->dimensions[0]) end= self->dimensions[0];
if (begin > end) begin= end;
if (begin < 0) begin = 0;
if (end > self->dimensions[0]) end = self->dimensions[0];
if (begin > end) begin = end;
if (!PySequence_Check(seq)) {
PyErr_Format(PyExc_TypeError,
@@ -487,23 +482,25 @@ static int Buffer_ass_slice(Buffer *self, int begin, int end, PyObject *seq)
}
/* re-use count var */
if ((count= PySequence_Size(seq)) != (end - begin)) {
if ((count = PySequence_Size(seq)) != (end - begin)) {
PyErr_Format(PyExc_TypeError,
"buffer[:] = value, size mismatch in assignment. "
"Expected: %d (given: %d)", count, end - begin);
return -1;
}
for (count= begin; count < end; count++) {
item= PySequence_GetItem(seq, count - begin);
for (count = begin; count < end; count++) {
item = PySequence_GetItem(seq, count - begin);
if (item) {
err= Buffer_ass_item(self, count, item);
err = Buffer_ass_item(self, count, item);
Py_DECREF(item);
}
else {
err= -1;
err = -1;
}
if (err) {
break;
}
if (err) break;
}
return err;
}
@@ -580,8 +577,12 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value)
static void Buffer_dealloc(Buffer *self)
{
if (self->parent) Py_DECREF(self->parent);
else MEM_freeN (self->buf.asvoid);
if (self->parent) {
Py_DECREF(self->parent);
}
else {
MEM_freeN(self->buf.asvoid);
}
MEM_freeN(self->dimensions);
@@ -591,19 +592,20 @@ static void Buffer_dealloc(Buffer *self)
static PyObject *Buffer_repr(Buffer *self)
{
PyObject *list= Buffer_to_list_recursive(self);
PyObject *list = Buffer_to_list_recursive(self);
PyObject *repr;
const char *typestr= "UNKNOWN";
const char *typestr;
switch (self->type) {
case GL_BYTE: typestr= "GL_BYTE"; break;
case GL_SHORT: typestr= "GL_SHORT"; break;
case GL_INT: typestr= "GL_BYTE"; break;
case GL_FLOAT: typestr= "GL_FLOAT"; break;
case GL_DOUBLE: typestr= "GL_DOUBLE"; break;
case GL_BYTE: typestr = "GL_BYTE"; break;
case GL_SHORT: typestr = "GL_SHORT"; break;
case GL_INT: typestr = "GL_BYTE"; break;
case GL_FLOAT: typestr = "GL_FLOAT"; break;
case GL_DOUBLE: typestr = "GL_DOUBLE"; break;
default: typestr = "UNKNOWN"; break;
}
repr= PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list);
repr = PyUnicode_FromFormat("Buffer(%s, %R)", typestr, list);
Py_DECREF(list);
return repr;
@@ -1296,21 +1298,20 @@ static struct PyModuleDef BGL_module_def = {
PyObject *BPyInit_bgl(void)
{
PyObject *submodule, *dict, *item;
submodule= PyModule_Create(&BGL_module_def);
dict= PyModule_GetDict(submodule);
submodule = PyModule_Create(&BGL_module_def);
dict = PyModule_GetDict(submodule);
if (PyType_Ready(&BGL_bufferType) < 0)
return NULL; /* should never happen */
PyModule_AddObject(submodule, "Buffer", (PyObject *)&BGL_bufferType);
Py_INCREF((PyObject *)&BGL_bufferType);
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, item=PyLong_FromLong((int)x)); Py_DECREF(item)
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, item = PyLong_FromLong((int)x)); Py_DECREF(item)
/* So, for example:
* EXPP_ADDCONST(GL_CURRENT_BIT) becomes
* PyDict_SetItemString(dict, "GL_CURRENT_BIT", item=PyLong_FromLong(GL_CURRENT_BIT)); Py_DECREF(item) */
* PyDict_SetItemString(dict, "GL_CURRENT_BIT", item = PyLong_FromLong(GL_CURRENT_BIT)); Py_DECREF(item) */
EXPP_ADDCONST(GL_CURRENT_BIT);
EXPP_ADDCONST(GL_POINT_BIT);
@@ -1795,4 +1796,3 @@ PyObject *BPyInit_bgl(void)
return submodule;
}

View File

@@ -44,10 +44,10 @@ PyObject *BPyInit_bgl(void);
/*@ Create a buffer object */
/*@ dimensions is an array of ndimensions integers representing the size of each dimension */
/*@ initbuffer if not NULL holds a contiguous buffer with the correct format from which the buffer will be initialized */
struct _Buffer *BGL_MakeBuffer( int type, int ndimensions, int *dimensions, void *initbuffer );
struct _Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuffer);
/*@ Return the size of buffer element, type must be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE */
/*@ returns -1 otherwise */
int BGL_typeSize( int type );
int BGL_typeSize(int type);
/*@ Buffer Object */
/*@ For Python access to OpenGL functions requiring a pointer. */
@@ -312,23 +312,23 @@ extern PyTypeObject BGL_bufferType;
#define ret_ret_void return Py_INCREF(Py_None), Py_None
#define ret_def_GLint int ret_int
#define ret_set_GLint ret_int=
#define ret_set_GLint ret_int =
#define ret_ret_GLint return PyLong_FromLong(ret_int)
#define ret_def_GLuint unsigned int ret_uint
#define ret_set_GLuint ret_uint=
#define ret_set_GLuint ret_uint =
#define ret_ret_GLuint return PyLong_FromLong((long) ret_uint)
#define ret_def_GLenum unsigned int ret_uint
#define ret_set_GLenum ret_uint=
#define ret_set_GLenum ret_uint =
#define ret_ret_GLenum return PyLong_FromLong((long) ret_uint)
#define ret_def_GLboolean unsigned char ret_bool
#define ret_set_GLboolean ret_bool=
#define ret_set_GLboolean ret_bool =
#define ret_ret_GLboolean return PyLong_FromLong((long) ret_bool)
#define ret_def_GLstring const unsigned char *ret_str;
#define ret_set_GLstring ret_str=
#define ret_set_GLstring ret_str =
#define ret_ret_GLstring \
if (ret_str) { \

View File

@@ -182,7 +182,7 @@ static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
BLF_width_and_height(fontid, text, &r_width, &r_height);
ret= PyTuple_New(2);
ret = PyTuple_New(2);
PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(r_width));
PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(r_height));
return ret;
@@ -356,7 +356,7 @@ PyDoc_STRVAR(py_blf_load_doc,
);
static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args)
{
char* filename;
char *filename;
if (!PyArg_ParseTuple(args, "s:blf.load", &filename))
return NULL;
@@ -374,7 +374,7 @@ PyDoc_STRVAR(py_blf_unload_doc,
);
static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args)
{
char* filename;
char *filename;
if (!PyArg_ParseTuple(args, "s:blf.unload", &filename))
return NULL;

View File

@@ -101,7 +101,7 @@ void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
PyObject *bpy_text_import(Text *text)
{
char *buf = NULL;
char modulename[MAX_ID_NAME+2];
char modulename[MAX_ID_NAME + 2];
int len;
if (!text->compiled) {

View File

@@ -74,21 +74,21 @@ static PyObject *idprop_py_from_idp_int(IDProperty *prop)
static PyObject *idprop_py_from_idp_float(IDProperty *prop)
{
return PyFloat_FromDouble((double)(*(float*)(&prop->data.val)));
return PyFloat_FromDouble((double)(*(float *)(&prop->data.val)));
}
static PyObject *idprop_py_from_idp_double(IDProperty *prop)
{
return PyFloat_FromDouble((*(double*)(&prop->data.val)));
return PyFloat_FromDouble((*(double *)(&prop->data.val)));
}
static PyObject *idprop_py_from_idp_group(ID *id, IDProperty *prop, IDProperty *parent)
{
BPy_IDProperty *group= PyObject_New(BPy_IDProperty, &BPy_IDGroup_Type);
BPy_IDProperty *group = PyObject_New(BPy_IDProperty, &BPy_IDGroup_Type);
group->id = id;
group->prop = prop;
group->parent = parent; /* can be NULL */
return (PyObject*) group;
return (PyObject*)group;
}
static PyObject *idprop_py_from_idp_array(ID *id, IDProperty *prop)
@@ -96,13 +96,13 @@ static PyObject *idprop_py_from_idp_array(ID *id, IDProperty *prop)
BPy_IDProperty *array = PyObject_New(BPy_IDProperty, &BPy_IDArray_Type);
array->id = id;
array->prop = prop;
return (PyObject*) array;
return (PyObject*)array;
}
static PyObject *idprop_py_from_idp_idparray(ID *id, IDProperty *prop)
{
PyObject *seq = PyList_New(prop->len), *wrap;
IDProperty *array= IDP_IDPArray(prop);
IDProperty *array = IDP_IDPArray(prop);
int i;
if (!seq) {
@@ -112,8 +112,8 @@ static PyObject *idprop_py_from_idp_idparray(ID *id, IDProperty *prop)
return NULL;
}
for (i=0; i<prop->len; i++) {
wrap= BPy_IDGroup_WrapData(id, array++, prop);
for (i = 0; i < prop->len; i++) {
wrap = BPy_IDGroup_WrapData(id, array++, prop);
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
return NULL;
@@ -134,28 +134,20 @@ static Py_hash_t BPy_IDGroup_hash(BPy_IDProperty *self)
static PyObject *BPy_IDGroup_repr(BPy_IDProperty *self)
{
return PyUnicode_FromFormat( "<bpy id property from \"%s\">", self->id->name);
return PyUnicode_FromFormat("<bpy id property from \"%s\">", self->id->name);
}
PyObject *BPy_IDGroup_WrapData(ID *id, IDProperty *prop, IDProperty *parent)
{
switch (prop->type) {
case IDP_STRING:
return idprop_py_from_idp_string(prop);
case IDP_INT:
return idprop_py_from_idp_int(prop);
case IDP_FLOAT:
return idprop_py_from_idp_float(prop);
case IDP_DOUBLE:
return idprop_py_from_idp_double(prop);
case IDP_GROUP:
return idprop_py_from_idp_group(id, prop, parent);
case IDP_ARRAY:
return idprop_py_from_idp_array(id, prop);
case IDP_IDPARRAY: /* this could be better a internal type */
return idprop_py_from_idp_idparray(id, prop);
default:
Py_RETURN_NONE;
case IDP_STRING: return idprop_py_from_idp_string(prop);
case IDP_INT: return idprop_py_from_idp_int(prop);
case IDP_FLOAT: return idprop_py_from_idp_float(prop);
case IDP_DOUBLE: return idprop_py_from_idp_double(prop);
case IDP_GROUP: return idprop_py_from_idp_group(id, prop, parent);
case IDP_ARRAY: return idprop_py_from_idp_array(id, prop);
case IDP_IDPARRAY: return idprop_py_from_idp_idparray(id, prop); /* this could be better a internal type */
default: Py_RETURN_NONE;
}
}
@@ -174,10 +166,10 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
#ifdef USE_STRING_COERCE
{
int alloc_len;
PyObject *value_coerce= NULL;
PyObject *value_coerce = NULL;
st= (char *)PyC_UnicodeAsByte(value, &value_coerce);
alloc_len= strlen(st) + 1;
st = (char *)PyC_UnicodeAsByte(value, &value_coerce);
alloc_len = strlen(st) + 1;
st = _PyUnicode_AsString(value);
IDP_ResizeArray(prop, alloc_len);
@@ -195,8 +187,8 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
case IDP_INT:
{
int ivalue= PyLong_AsSsize_t(value);
if (ivalue==-1 && PyErr_Occurred()) {
int ivalue = PyLong_AsSsize_t(value);
if (ivalue == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected an int type");
return -1;
}
@@ -205,22 +197,22 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
}
case IDP_FLOAT:
{
float fvalue= (float)PyFloat_AsDouble(value);
if (fvalue==-1 && PyErr_Occurred()) {
float fvalue = (float)PyFloat_AsDouble(value);
if (fvalue == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
*(float*)&self->prop->data.val = fvalue;
*(float *)&self->prop->data.val = fvalue;
break;
}
case IDP_DOUBLE:
{
double dvalue= PyFloat_AsDouble(value);
if (dvalue==-1 && PyErr_Occurred()) {
double dvalue = PyFloat_AsDouble(value);
if (dvalue == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
*(double*)&self->prop->data.val = dvalue;
*(double *)&self->prop->data.val = dvalue;
break;
}
default:
@@ -289,16 +281,16 @@ static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
return NULL;
}
name= _PyUnicode_AsString(item);
name = _PyUnicode_AsString(item);
if (name == NULL) {
PyErr_SetString(PyExc_TypeError, "only strings are allowed as keys of ID properties");
return NULL;
}
idprop= IDP_GetPropertyFromGroup(self->prop, name);
idprop = IDP_GetPropertyFromGroup(self->prop, name);
if (idprop==NULL) {
if (idprop == NULL) {
PyErr_SetString(PyExc_KeyError, "key not in subgroup dict");
return NULL;
}
@@ -306,21 +298,21 @@ static PyObject *BPy_IDGroup_Map_GetItem(BPy_IDProperty *self, PyObject *item)
return BPy_IDGroup_WrapData(self->id, idprop, self->prop);
}
/*returns NULL on success, error string on failure*/
/* returns NULL on success, error string on failure */
static int idp_sequence_type(PyObject *seq)
{
PyObject *item;
int type= IDP_INT;
int type = IDP_INT;
Py_ssize_t i, len = PySequence_Size(seq);
for (i=0; i < len; i++) {
for (i = 0; i < len; i++) {
item = PySequence_GetItem(seq, i);
if (PyFloat_Check(item)) {
if (type == IDP_IDPARRAY) { /* mixed dict/int */
Py_DECREF(item);
return -1;
}
type= IDP_DOUBLE;
type = IDP_DOUBLE;
}
else if (PyLong_Check(item)) {
if (type == IDP_IDPARRAY) { /* mixed dict/int */
@@ -333,7 +325,7 @@ static int idp_sequence_type(PyObject *seq)
Py_DECREF(item);
return -1;
}
type= IDP_IDPARRAY;
type = IDP_IDPARRAY;
}
else {
Py_XDECREF(item);
@@ -353,7 +345,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
IDProperty *prop = NULL;
IDPropertyTemplate val = {0};
const char *name= "";
const char *name = "";
if (name_obj) {
Py_ssize_t name_size;
@@ -373,7 +365,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
}
else if (PyUnicode_Check(ob)) {
#ifdef USE_STRING_COERCE
PyObject *value_coerce= NULL;
PyObject *value_coerce = NULL;
val.string.str = (char *)PyC_UnicodeAsByte(ob, &value_coerce);
val.string.subtype = IDP_STRING_SUB_UTF8;
prop = IDP_New(IDP_STRING, &val, name);
@@ -384,19 +376,19 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
#endif
}
else if (PyBytes_Check(ob)) {
val.string.str= PyBytes_AS_STRING(ob);
val.string.len= PyBytes_GET_SIZE(ob);
val.string.subtype= IDP_STRING_SUB_BYTE;
val.string.str = PyBytes_AS_STRING(ob);
val.string.len = PyBytes_GET_SIZE(ob);
val.string.subtype = IDP_STRING_SUB_BYTE;
prop = IDP_New(IDP_STRING, &val, name);
//prop = IDP_NewString(PyBytes_AS_STRING(ob), name, PyBytes_GET_SIZE(ob));
//prop->subtype= IDP_STRING_SUB_BYTE;
//prop->subtype = IDP_STRING_SUB_BYTE;
}
else if (PySequence_Check(ob)) {
PyObject *item;
int i;
if ((val.array.type= idp_sequence_type(ob)) == -1)
if ((val.array.type = idp_sequence_type(ob)) == -1)
return "only floats, ints and dicts are allowed in ID property arrays";
/* validate sequence and derive type.
@@ -406,34 +398,34 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
val.array.len = PySequence_Size(ob);
switch (val.array.type) {
case IDP_DOUBLE:
prop = IDP_New(IDP_ARRAY, &val, name);
for (i=0; i<val.array.len; i++) {
item = PySequence_GetItem(ob, i);
((double*)IDP_Array(prop))[i] = (float)PyFloat_AsDouble(item);
Py_DECREF(item);
}
break;
case IDP_INT:
prop = IDP_New(IDP_ARRAY, &val, name);
for (i=0; i<val.array.len; i++) {
item = PySequence_GetItem(ob, i);
((int*)IDP_Array(prop))[i] = (int)PyLong_AsSsize_t(item);
Py_DECREF(item);
}
break;
case IDP_IDPARRAY:
prop= IDP_NewIDPArray(name);
for (i=0; i<val.array.len; i++) {
const char *error;
item = PySequence_GetItem(ob, i);
error= BPy_IDProperty_Map_ValidateAndCreate(NULL, prop, item);
Py_DECREF(item);
case IDP_DOUBLE:
prop = IDP_New(IDP_ARRAY, &val, name);
for (i = 0; i < val.array.len; i++) {
item = PySequence_GetItem(ob, i);
((double *)IDP_Array(prop))[i] = (float)PyFloat_AsDouble(item);
Py_DECREF(item);
}
break;
case IDP_INT:
prop = IDP_New(IDP_ARRAY, &val, name);
for (i = 0; i < val.array.len; i++) {
item = PySequence_GetItem(ob, i);
((int *)IDP_Array(prop))[i] = (int)PyLong_AsSsize_t(item);
Py_DECREF(item);
}
break;
case IDP_IDPARRAY:
prop = IDP_NewIDPArray(name);
for (i = 0; i < val.array.len; i++) {
const char *error;
item = PySequence_GetItem(ob, i);
error = BPy_IDProperty_Map_ValidateAndCreate(NULL, prop, item);
Py_DECREF(item);
if (error)
return error;
}
break;
if (error)
return error;
}
break;
}
}
else if (PyMapping_Check(ob)) {
@@ -447,7 +439,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
* we can delete it easily enough.*/
prop = IDP_New(IDP_GROUP, &val, name);
len = PyMapping_Length(ob);
for (i=0; i<len; i++) {
for (i = 0; i < len; i++) {
key = PySequence_GetItem(keys, i);
pval = PySequence_GetItem(vals, i);
if (!PyUnicode_Check(key)) {
@@ -476,7 +468,7 @@ const char *BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty
}
else return "invalid property value";
if (group->type==IDP_IDPARRAY) {
if (group->type == IDP_IDPARRAY) {
IDP_AppendArray(group, prop);
// IDP_FreeProperty(item); // IDP_AppendArray does a shallow copy (memcpy), only free memory
MEM_freeN(prop);
@@ -518,7 +510,7 @@ int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
err = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val);
if (err) {
PyErr_SetString(PyExc_KeyError, err );
PyErr_SetString(PyExc_KeyError, err);
return -1;
}
@@ -538,107 +530,107 @@ static PyObject *BPy_IDGroup_iter(BPy_IDProperty *self)
iter->mode = IDPROP_ITER_KEYS;
iter->cur = self->prop->data.group.first;
Py_XINCREF(iter);
return (PyObject*) iter;
return (PyObject*)iter;
}
/* for simple, non nested types this is the same as BPy_IDGroup_WrapData */
static PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
{
switch (prop->type) {
case IDP_STRING:
return idprop_py_from_idp_string(prop);
case IDP_INT:
return idprop_py_from_idp_int(prop);
case IDP_FLOAT:
return idprop_py_from_idp_float(prop);
case IDP_DOUBLE:
return idprop_py_from_idp_double(prop);
case IDP_ARRAY:
{
PyObject *seq = PyList_New(prop->len);
int i;
if (!seq) {
PyErr_Format(PyExc_RuntimeError,
"%s: IDP_ARRAY: PyList_New(%d) failed",
__func__, prop->len);
return NULL;
}
switch (prop->subtype) {
case IDP_FLOAT:
{
float *array= (float*)IDP_Array(prop);
for (i=0; i<prop->len; i++) {
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
}
break;
}
case IDP_DOUBLE:
{
double *array= (double*)IDP_Array(prop);
for (i=0; i<prop->len; i++) {
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
}
break;
}
case IDP_STRING:
return idprop_py_from_idp_string(prop);
case IDP_INT:
return idprop_py_from_idp_int(prop);
case IDP_FLOAT:
return idprop_py_from_idp_float(prop);
case IDP_DOUBLE:
return idprop_py_from_idp_double(prop);
case IDP_ARRAY:
{
int *array= (int*)IDP_Array(prop);
for (i=0; i<prop->len; i++) {
PyList_SET_ITEM(seq, i, PyLong_FromLong(array[i]));
PyObject *seq = PyList_New(prop->len);
int i;
if (!seq) {
PyErr_Format(PyExc_RuntimeError,
"%s: IDP_ARRAY: PyList_New(%d) failed",
__func__, prop->len);
return NULL;
}
break;
}
default:
PyErr_Format(PyExc_RuntimeError,
"%s: invalid/corrupt array type '%d'!",
__func__, prop->subtype);
Py_DECREF(seq);
return NULL;
switch (prop->subtype) {
case IDP_FLOAT:
{
float *array = (float *)IDP_Array(prop);
for (i = 0; i < prop->len; i++) {
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
}
break;
}
case IDP_DOUBLE:
{
double *array = (double *)IDP_Array(prop);
for (i = 0; i < prop->len; i++) {
PyList_SET_ITEM(seq, i, PyFloat_FromDouble(array[i]));
}
break;
}
case IDP_INT:
{
int *array = (int *)IDP_Array(prop);
for (i = 0; i < prop->len; i++) {
PyList_SET_ITEM(seq, i, PyLong_FromLong(array[i]));
}
break;
}
default:
PyErr_Format(PyExc_RuntimeError,
"%s: invalid/corrupt array type '%d'!",
__func__, prop->subtype);
Py_DECREF(seq);
return NULL;
}
return seq;
}
case IDP_IDPARRAY:
{
PyObject *seq = PyList_New(prop->len), *wrap;
IDProperty *array = IDP_IDPArray(prop);
int i;
return seq;
}
case IDP_IDPARRAY:
{
PyObject *seq = PyList_New(prop->len), *wrap;
IDProperty *array= IDP_IDPArray(prop);
int i;
if (!seq) {
PyErr_Format(PyExc_RuntimeError,
"%s: IDP_IDPARRAY: PyList_New(%d) failed",
__func__, prop->len);
return NULL;
}
for (i=0; i<prop->len; i++) {
wrap= BPy_IDGroup_MapDataToPy(array++);
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
if (!seq) {
PyErr_Format(PyExc_RuntimeError,
"%s: IDP_IDPARRAY: PyList_New(%d) failed",
__func__, prop->len);
return NULL;
}
PyList_SET_ITEM(seq, i, wrap);
for (i = 0; i < prop->len; i++) {
wrap = BPy_IDGroup_MapDataToPy(array++);
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
return NULL;
PyList_SET_ITEM(seq, i, wrap);
}
return seq;
}
return seq;
}
case IDP_GROUP:
{
PyObject *dict = PyDict_New(), *wrap;
IDProperty *loop;
case IDP_GROUP:
{
PyObject *dict = PyDict_New(), *wrap;
IDProperty *loop;
for (loop=prop->data.group.first; loop; loop=loop->next) {
wrap = BPy_IDGroup_MapDataToPy(loop);
for (loop = prop->data.group.first; loop; loop = loop->next) {
wrap = BPy_IDGroup_MapDataToPy(loop);
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
return NULL;
if (!wrap) /* BPy_IDGroup_MapDataToPy sets the error */
return NULL;
PyDict_SetItemString(dict, loop->name, wrap);
Py_DECREF(wrap);
PyDict_SetItemString(dict, loop->name, wrap);
Py_DECREF(wrap);
}
return dict;
}
return dict;
}
}
PyErr_Format(PyExc_RuntimeError,
@@ -660,7 +652,7 @@ static PyObject *BPy_IDGroup_Pop(BPy_IDProperty *self, PyObject *value)
return NULL;
}
idprop= IDP_GetPropertyFromGroup(self->prop, name);
idprop = IDP_GetPropertyFromGroup(self->prop, name);
if (idprop) {
pyform = BPy_IDGroup_MapDataToPy(idprop);
@@ -687,7 +679,7 @@ static PyObject *BPy_IDGroup_IterItems(BPy_IDProperty *self)
iter->mode = IDPROP_ITER_ITEMS;
iter->cur = self->prop->data.group.first;
Py_XINCREF(iter);
return (PyObject*) iter;
return (PyObject*)iter;
}
/* utility function */
@@ -698,7 +690,7 @@ static void BPy_IDGroup_CorrectListLen(IDProperty *prop, PyObject *seq, int len,
printf("%s: ID Property Error found and corrected!\n", func);
/*fill rest of list with valid references to None*/
for (j=len; j<prop->len; j++) {
for (j = len; j < prop->len; j++) {
Py_INCREF(Py_None);
PyList_SET_ITEM(seq, j, Py_None);
}
@@ -713,11 +705,13 @@ PyObject *BPy_Wrap_GetKeys(IDProperty *prop)
IDProperty *loop;
int i;
for (i=0, loop=prop->data.group.first; loop && (i < prop->len); loop=loop->next, i++)
for (i = 0, loop = prop->data.group.first; loop && (i < prop->len); loop = loop->next, i++)
PyList_SET_ITEM(list, i, PyUnicode_FromString(loop->name));
/* if the id prop is corrupt, count the remaining */
for (; loop; loop=loop->next, i++) {}
for ( ; loop; loop = loop->next, i++) {
/* pass */
}
if (i != prop->len) { /* if the loop didnt finish, we know the length is wrong */
BPy_IDGroup_CorrectListLen(prop, list, i, __func__);
@@ -735,7 +729,7 @@ PyObject *BPy_Wrap_GetValues(ID *id, IDProperty *prop)
IDProperty *loop;
int i;
for (i=0, loop=prop->data.group.first; loop; loop=loop->next, i++) {
for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) {
PyList_SET_ITEM(list, i, BPy_IDGroup_WrapData(id, loop, prop));
}
@@ -755,8 +749,8 @@ PyObject *BPy_Wrap_GetItems(ID *id, IDProperty *prop)
IDProperty *loop;
int i;
for (i=0, loop=prop->data.group.first; loop; loop=loop->next, i++) {
PyObject *item= PyTuple_New(2);
for (i = 0, loop = prop->data.group.first; loop; loop = loop->next, i++) {
PyObject *item = PyTuple_New(2);
PyTuple_SET_ITEM(item, 0, PyUnicode_FromString(loop->name));
PyTuple_SET_ITEM(item, 1, BPy_IDGroup_WrapData(id, loop, prop));
PyList_SET_ITEM(seq, i, item);
@@ -805,7 +799,7 @@ static int BPy_IDGroup_Contains(BPy_IDProperty *self, PyObject *value)
static PyObject *BPy_IDGroup_Update(BPy_IDProperty *self, PyObject *value)
{
PyObject *pkey, *pval;
Py_ssize_t i=0;
Py_ssize_t i = 0;
if (!PyDict_Check(value)) {
PyErr_Format(PyExc_TypeError,
@@ -829,18 +823,18 @@ static PyObject *BPy_IDGroup_to_dict(BPy_IDProperty *self)
/* Matches python dict.get(key, [default]) */
static PyObject* BPy_IDGroup_Get(BPy_IDProperty *self, PyObject *args)
static PyObject *BPy_IDGroup_Get(BPy_IDProperty *self, PyObject *args)
{
IDProperty *idprop;
char *key;
PyObject* def = Py_None;
PyObject *def = Py_None;
if (!PyArg_ParseTuple(args, "s|O:get", &key, &def))
return NULL;
idprop= IDP_GetPropertyFromGroup(self->prop, key);
idprop = IDP_GetPropertyFromGroup(self->prop, key);
if (idprop) {
PyObject* pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop);
PyObject *pyobj = BPy_IDGroup_WrapData(self->id, idprop, self->prop);
if (pyobj)
return pyobj;
}
@@ -955,17 +949,17 @@ static PyTypeObject *idp_array_py_type(BPy_IDArray *self, short *is_double)
{
switch (self->prop->subtype) {
case IDP_FLOAT:
*is_double= 0;
*is_double = 0;
return &PyFloat_Type;
case IDP_DOUBLE:
*is_double= 1;
*is_double = 1;
return &PyFloat_Type;
case IDP_INT:
*is_double= 0;
*is_double = 0;
return &PyLong_Type;
}
*is_double= 0;
*is_double = 0;
return NULL;
}
@@ -977,12 +971,9 @@ static PyObject *BPy_IDArray_repr(BPy_IDArray *self)
static PyObject *BPy_IDArray_GetType(BPy_IDArray *self)
{
switch (self->prop->subtype) {
case IDP_FLOAT:
return PyUnicode_FromString("f");
case IDP_DOUBLE:
return PyUnicode_FromString("d");
case IDP_INT:
return PyUnicode_FromString("i");
case IDP_FLOAT: return PyUnicode_FromString("f");
case IDP_DOUBLE: return PyUnicode_FromString("d");
case IDP_INT: return PyUnicode_FromString("i");
}
PyErr_Format(PyExc_RuntimeError,
@@ -1023,11 +1014,11 @@ static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, int index)
switch (self->prop->subtype) {
case IDP_FLOAT:
return PyFloat_FromDouble(((float*)IDP_Array(self->prop))[index]);
return PyFloat_FromDouble(((float *)IDP_Array(self->prop))[index]);
case IDP_DOUBLE:
return PyFloat_FromDouble(((double*)IDP_Array(self->prop))[index]);
return PyFloat_FromDouble(((double *)IDP_Array(self->prop))[index]);
case IDP_INT:
return PyLong_FromLong((long)((int*)IDP_Array(self->prop))[index]);
return PyLong_FromLong((long)((int *)IDP_Array(self->prop))[index]);
}
PyErr_Format(PyExc_RuntimeError,
@@ -1050,29 +1041,29 @@ static int BPy_IDArray_SetItem(BPy_IDArray *self, int index, PyObject *value)
switch (self->prop->subtype) {
case IDP_FLOAT:
f= (float)PyFloat_AsDouble(value);
if (f==-1 && PyErr_Occurred()) {
f = (float)PyFloat_AsDouble(value);
if (f == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
((float*)IDP_Array(self->prop))[index] = f;
((float *)IDP_Array(self->prop))[index] = f;
break;
case IDP_DOUBLE:
d= PyFloat_AsDouble(value);
if (d==-1 && PyErr_Occurred()) {
d = PyFloat_AsDouble(value);
if (d == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
((double*)IDP_Array(self->prop))[index] = d;
((double *)IDP_Array(self->prop))[index] = d;
break;
case IDP_INT:
i= PyLong_AsSsize_t(value);
if (i==-1 && PyErr_Occurred()) {
i = PyLong_AsSsize_t(value);
if (i == -1 && PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected an int type");
return -1;
}
((int*)IDP_Array(self->prop))[index] = i;
((int *)IDP_Array(self->prop))[index] = i;
break;
}
return 0;
@@ -1097,21 +1088,21 @@ static PySequenceMethods BPy_IDArray_Seq = {
/* sequence slice (get): idparr[a:b] */
static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
{
IDProperty *prop= self->prop;
IDProperty *prop = self->prop;
PyObject *tuple;
int count;
CLAMP(begin, 0, prop->len);
if (end<0) end= prop->len+end+1;
if (end < 0) end = prop->len + end + 1;
CLAMP(end, 0, prop->len);
begin= MIN2(begin, end);
begin = MIN2(begin, end);
tuple= PyTuple_New(end - begin);
tuple = PyTuple_New(end - begin);
switch (prop->subtype) {
case IDP_FLOAT:
{
float *array= (float*)IDP_Array(prop);
float *array = (float *)IDP_Array(prop);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count]));
}
@@ -1119,7 +1110,7 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
}
case IDP_DOUBLE:
{
double *array= (double*)IDP_Array(prop);
double *array = (double *)IDP_Array(prop);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, PyFloat_FromDouble(array[count]));
}
@@ -1127,7 +1118,7 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
}
case IDP_INT:
{
int *array= (int*)IDP_Array(prop);
int *array = (int *)IDP_Array(prop);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin, PyLong_FromLong(array[count]));
}
@@ -1140,10 +1131,10 @@ static PyObject *BPy_IDArray_slice(BPy_IDArray *self, int begin, int end)
/* sequence slice (set): idparr[a:b] = value */
static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject *seq)
{
IDProperty *prop= self->prop;
short is_double= 0;
const PyTypeObject *py_type= idp_array_py_type(self, &is_double);
const size_t elem_size= is_double ? sizeof(double) : sizeof(float);
IDProperty *prop = self->prop;
short is_double = 0;
const PyTypeObject *py_type = idp_array_py_type(self, &is_double);
const size_t elem_size = is_double ? sizeof(double) : sizeof(float);
size_t alloc_len;
size_t size;
void *vec;
@@ -1153,9 +1144,9 @@ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject
begin = MIN2(begin, end);
size = (end - begin);
alloc_len= size * elem_size;
alloc_len = size * elem_size;
vec= MEM_mallocN(alloc_len, "array assignment"); /* NOTE: we count on int/float being the same size here */
vec = MEM_mallocN(alloc_len, "array assignment"); /* NOTE: we count on int/float being the same size here */
if (PyC_AsArray(vec, seq, size, py_type, is_double, "slice assignment: ") == -1) {
MEM_freeN(vec);
return -1;
@@ -1167,7 +1158,7 @@ static int BPy_IDArray_ass_slice(BPy_IDArray *self, int begin, int end, PyObject
return 0;
}
static PyObject *BPy_IDArray_subscript(BPy_IDArray* self, PyObject* item)
static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item)
{
if (PyIndex_Check(item)) {
Py_ssize_t i;
@@ -1203,7 +1194,7 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray* self, PyObject* item)
}
}
static int BPy_IDArray_ass_subscript(BPy_IDArray* self, PyObject* item, PyObject* value)
static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject *value)
{
if (PyIndex_Check(item)) {
Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
@@ -1331,12 +1322,14 @@ static PyObject *IDGroup_Iter_repr(BPy_IDGroup_Iter *self)
static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self)
{
IDProperty *cur=NULL;
PyObject *ret;
if (self->cur) {
PyObject *ret;
IDProperty *cur;
cur = self->cur;
self->cur = self->cur->next;
if (self->mode == IDPROP_ITER_ITEMS) {
ret = PyTuple_New(2);
PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(cur->name));
@@ -1357,7 +1350,7 @@ PyTypeObject BPy_IDGroup_Iter_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
/* For printing, in format "<module>.<name>" */
"Blender IDGroup_Iter", /* char *tp_name; */
sizeof( BPy_IDGroup_Iter ), /* int tp_basicsize; */
sizeof(BPy_IDGroup_Iter), /* int tp_basicsize; */
0, /* tp_itemsize; For allocation */
/* Methods to implement standard operations */
@@ -1367,7 +1360,7 @@ PyTypeObject BPy_IDGroup_Iter_Type = {
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* cmpfunc tp_compare; */
( reprfunc ) IDGroup_Iter_repr, /* reprfunc tp_repr; */
(reprfunc) IDGroup_Iter_repr, /* reprfunc tp_repr; */
/* Method suites for standard classes */

View File

@@ -67,28 +67,28 @@ int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length,
/* for each type */
if (type == &PyFloat_Type) {
if (is_double) {
double *array_double= array;
for (i=0; i<length; i++) {
double *array_double = array;
for (i = 0; i < length; i++) {
array_double[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
}
}
else {
float *array_float= array;
for (i=0; i<length; i++) {
float *array_float = array;
for (i = 0; i < length; i++) {
array_float[i] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value_fast, i));
}
}
}
else if (type == &PyLong_Type) {
/* could use is_double for 'long int' but no use now */
int *array_int= array;
for (i=0; i<length; i++) {
int *array_int = array;
for (i = 0; i < length; i++) {
array_int[i] = PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i));
}
}
else if (type == &PyBool_Type) {
int *array_bool= array;
for (i=0; i<length; i++) {
int *array_bool = array;
for (i = 0; i < length; i++) {
array_bool[i] = (PyLong_AsSsize_t(PySequence_Fast_GET_ITEM(value_fast, i)) != 0);
}
}
@@ -117,7 +117,7 @@ int PyC_AsArray(void *array, PyObject *value, const Py_ssize_t length,
void PyC_ObSpit(const char *name, PyObject *var)
{
fprintf(stderr, "<%s> : ", name);
if (var==NULL) {
if (var == NULL) {
fprintf(stderr, "<NIL>");
}
else {
@@ -156,10 +156,10 @@ void PyC_FileAndNum(const char **filename, int *lineno)
{
PyFrameObject *frame;
if (filename) *filename= NULL;
if (filename) *filename = NULL;
if (lineno) *lineno = -1;
if (!(frame= PyThreadState_GET()->frame)) {
if (!(frame = PyThreadState_GET()->frame)) {
return;
}
@@ -172,16 +172,16 @@ void PyC_FileAndNum(const char **filename, int *lineno)
if (filename && *filename == NULL) {
/* try an alternative method to get the filename - module based
* references below are all borrowed (double checked) */
PyObject *mod_name= PyDict_GetItemString(PyEval_GetGlobals(), "__name__");
PyObject *mod_name = PyDict_GetItemString(PyEval_GetGlobals(), "__name__");
if (mod_name) {
PyObject *mod= PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
PyObject *mod = PyDict_GetItem(PyImport_GetModuleDict(), mod_name);
if (mod) {
*filename= PyModule_GetFilename(mod);
*filename = PyModule_GetFilename(mod);
}
/* unlikely, fallback */
if (*filename == NULL) {
*filename= _PyUnicode_AsString(mod_name);
*filename = _PyUnicode_AsString(mod_name);
}
}
}
@@ -204,13 +204,13 @@ void PyC_FileAndNum_Safe(const char **filename, int *lineno)
PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...)
{
Py_ssize_t i;
PyObject *item= o;
PyObject *item = o;
char *attr;
va_list vargs;
va_start(vargs, n);
for (i=0; i<n; i++) {
for (i = 0; i < n; i++) {
attr = va_arg(vargs, char *);
item = PyObject_GetAttrString(item, attr);
@@ -238,7 +238,7 @@ PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *for
va_list args;
va_start(args, format);
error_value_prefix= PyUnicode_FromFormatV(format, args); /* can fail and be NULL */
error_value_prefix = PyUnicode_FromFormatV(format, args); /* can fail and be NULL */
va_end(args);
if (PyErr_Occurred()) {
@@ -271,22 +271,22 @@ PyObject *PyC_Err_Format_Prefix(PyObject *exception_type_prefix, const char *for
PyObject *PyC_ExceptionBuffer(void)
{
PyObject *traceback_mod= NULL;
PyObject *format_tb_func= NULL;
PyObject *ret= NULL;
PyObject *traceback_mod = NULL;
PyObject *format_tb_func = NULL;
PyObject *ret = NULL;
if (! (traceback_mod= PyImport_ImportModule("traceback")) ) {
if (!(traceback_mod = PyImport_ImportModule("traceback"))) {
goto error_cleanup;
}
else if (! (format_tb_func= PyObject_GetAttrString(traceback_mod, "format_exc"))) {
else if (!(format_tb_func = PyObject_GetAttrString(traceback_mod, "format_exc"))) {
goto error_cleanup;
}
ret= PyObject_CallObject(format_tb_func, NULL);
ret = PyObject_CallObject(format_tb_func, NULL);
if (ret == Py_None) {
Py_DECREF(ret);
ret= NULL;
ret = NULL;
}
error_cleanup:
@@ -303,8 +303,8 @@ PyObject *PyC_ExceptionBuffer(void)
PyObject *stderr_backup = PySys_GetObject("stderr"); /* borrowed */
PyObject *string_io = NULL;
PyObject *string_io_buf = NULL;
PyObject *string_io_mod= NULL;
PyObject *string_io_getvalue= NULL;
PyObject *string_io_mod = NULL;
PyObject *string_io_getvalue = NULL;
PyObject *error_type, *error_value, *error_traceback;
@@ -319,17 +319,17 @@ PyObject *PyC_ExceptionBuffer(void)
* string_io = io.StringIO()
*/
if (! (string_io_mod= PyImport_ImportModule("io")) ) {
if (!(string_io_mod = PyImport_ImportModule("io"))) {
goto error_cleanup;
}
else if (! (string_io = PyObject_CallMethod(string_io_mod, (char *)"StringIO", NULL))) {
else if (!(string_io = PyObject_CallMethod(string_io_mod, (char *)"StringIO", NULL))) {
goto error_cleanup;
}
else if (! (string_io_getvalue= PyObject_GetAttrString(string_io, "getvalue"))) {
else if (!(string_io_getvalue = PyObject_GetAttrString(string_io, "getvalue"))) {
goto error_cleanup;
}
Py_INCREF(stdout_backup); // since these were borrowed we dont want them freed when replaced.
Py_INCREF(stdout_backup); // since these were borrowed we don't want them freed when replaced.
Py_INCREF(stderr_backup);
PySys_SetObject("stdout", string_io); // both of these are freed when restoring
@@ -374,7 +374,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
{
const char *result;
result= _PyUnicode_AsString(py_str);
result = _PyUnicode_AsString(py_str);
if (result) {
/* 99% of the time this is enough but we better support non unicode
@@ -387,7 +387,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
if (PyBytes_Check(py_str)) {
return PyBytes_AS_STRING(py_str);
}
else if ((*coerce= PyUnicode_EncodeFSDefault(py_str))) {
else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
return PyBytes_AS_STRING(*coerce);
}
else {
@@ -399,7 +399,7 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
{
PyObject *result= PyUnicode_FromStringAndSize(str, size);
PyObject *result = PyUnicode_FromStringAndSize(str, size);
if (result) {
/* 99% of the time this is enough but we better support non unicode
* chars since blender doesnt limit this */
@@ -408,7 +408,7 @@ PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
else {
PyErr_Clear();
/* this means paths will always be accessible once converted, on all OS's */
result= PyUnicode_DecodeFSDefaultAndSize(str, size);
result = PyUnicode_DecodeFSDefaultAndSize(str, size);
return result;
}
}
@@ -432,13 +432,15 @@ PyObject *PyC_UnicodeFromByte(const char *str)
****************************************************************************/
PyObject *PyC_DefaultNameSpace(const char *filename)
{
PyInterpreterState *interp= PyThreadState_GET()->interp;
PyObject *mod_main= PyModule_New("__main__");
PyInterpreterState *interp = PyThreadState_GET()->interp;
PyObject *mod_main = PyModule_New("__main__");
PyDict_SetItemString(interp->modules, "__main__", mod_main);
Py_DECREF(mod_main); /* sys.modules owns now */
PyModule_AddStringConstant(mod_main, "__name__", "__main__");
if (filename)
PyModule_AddStringConstant(mod_main, "__file__", filename); /* __file__ only for nice UI'ness */
if (filename) {
/* __file__ mainly for nice UI'ness */
PyModule_AddObject(mod_main, "__file__", PyUnicode_DecodeFSDefault(filename));
}
PyModule_AddObject(mod_main, "__builtins__", interp->builtins);
Py_INCREF(interp->builtins); /* AddObject steals a reference */
return PyModule_GetDict(mod_main);
@@ -447,14 +449,14 @@ PyObject *PyC_DefaultNameSpace(const char *filename)
/* restore MUST be called after this */
void PyC_MainModule_Backup(PyObject **main_mod)
{
PyInterpreterState *interp= PyThreadState_GET()->interp;
*main_mod= PyDict_GetItemString(interp->modules, "__main__");
Py_XINCREF(*main_mod); /* dont free */
PyInterpreterState *interp = PyThreadState_GET()->interp;
*main_mod = PyDict_GetItemString(interp->modules, "__main__");
Py_XINCREF(*main_mod); /* don't free */
}
void PyC_MainModule_Restore(PyObject *main_mod)
{
PyInterpreterState *interp= PyThreadState_GET()->interp;
PyInterpreterState *interp = PyThreadState_GET()->interp;
PyDict_SetItemString(interp->modules, "__main__", main_mod);
Py_XDECREF(main_mod);
}
@@ -462,7 +464,7 @@ void PyC_MainModule_Restore(PyObject *main_mod)
/* must be called before Py_Initialize, expects output of BLI_get_folder(BLENDER_PYTHON, NULL) */
void PyC_SetHomePath(const char *py_path_bundle)
{
if (py_path_bundle==NULL) {
if (py_path_bundle == NULL) {
/* Common enough to have bundled *nix python but complain on OSX/Win */
#if defined(__APPLE__) || defined(_WIN32)
fprintf(stderr, "Warning! bundled python not found and is expected on this platform. "
@@ -506,34 +508,34 @@ void PyC_SetHomePath(const char *py_path_bundle)
/* Would be nice if python had this built in */
void PyC_RunQuicky(const char *filepath, int n, ...)
{
FILE *fp= fopen(filepath, "r");
FILE *fp = fopen(filepath, "r");
if (fp) {
PyGILState_STATE gilstate= PyGILState_Ensure();
PyGILState_STATE gilstate = PyGILState_Ensure();
va_list vargs;
int *sizes= PyMem_MALLOC(sizeof(int) * (n / 2));
int *sizes = PyMem_MALLOC(sizeof(int) * (n / 2));
int i;
PyObject *py_dict = PyC_DefaultNameSpace(filepath);
PyObject *values= PyList_New(n / 2); /* namespace owns this, dont free */
PyObject *values = PyList_New(n / 2); /* namespace owns this, don't free */
PyObject *py_result, *ret;
PyObject *struct_mod= PyImport_ImportModule("struct");
PyObject *calcsize= PyObject_GetAttrString(struct_mod, "calcsize"); /* struct.calcsize */
PyObject *pack= PyObject_GetAttrString(struct_mod, "pack"); /* struct.pack */
PyObject *unpack= PyObject_GetAttrString(struct_mod, "unpack"); /* struct.unpack */
PyObject *struct_mod = PyImport_ImportModule("struct");
PyObject *calcsize = PyObject_GetAttrString(struct_mod, "calcsize"); /* struct.calcsize */
PyObject *pack = PyObject_GetAttrString(struct_mod, "pack"); /* struct.pack */
PyObject *unpack = PyObject_GetAttrString(struct_mod, "unpack"); /* struct.unpack */
Py_DECREF(struct_mod);
va_start(vargs, n);
for (i=0; i * 2<n; i++) {
for (i = 0; i * 2 < n; i++) {
char *format = va_arg(vargs, char *);
void *ptr = va_arg(vargs, void *);
ret= PyObject_CallFunction(calcsize, (char *)"s", format);
ret = PyObject_CallFunction(calcsize, (char *)"s", format);
if (ret) {
sizes[i]= PyLong_AsSsize_t(ret);
@@ -554,7 +556,7 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
else {
if (PyTuple_GET_SIZE(ret) == 1) {
/* convenience, convert single tuples into single values */
PyObject *tmp= PyTuple_GET_ITEM(ret, 0);
PyObject *tmp = PyTuple_GET_ITEM(ret, 0);
Py_INCREF(tmp);
Py_DECREF(ret);
ret = tmp;
@@ -576,29 +578,29 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
/* we could skip this but then only slice assignment would work
* better not be so strict */
values= PyDict_GetItemString(py_dict, "values");
values = PyDict_GetItemString(py_dict, "values");
if (values && PyList_Check(values)) {
/* dont use the result */
/* don't use the result */
Py_DECREF(py_result);
py_result= NULL;
py_result = NULL;
/* now get the values back */
va_start(vargs, n);
for (i=0; i*2 <n; i++) {
for (i = 0; i * 2 < n; i++) {
char *format = va_arg(vargs, char *);
void *ptr = va_arg(vargs, void *);
PyObject *item;
PyObject *item_new;
/* prepend the string formatting and remake the tuple */
item= PyList_GET_ITEM(values, i);
item = PyList_GET_ITEM(values, i);
if (PyTuple_CheckExact(item)) {
int ofs= PyTuple_GET_SIZE(item);
item_new= PyTuple_New(ofs + 1);
int ofs = PyTuple_GET_SIZE(item);
item_new = PyTuple_New(ofs + 1);
while (ofs--) {
PyObject *member= PyTuple_GET_ITEM(item, ofs);
PyObject *member = PyTuple_GET_ITEM(item, ofs);
PyTuple_SET_ITEM(item_new, ofs + 1, member);
Py_INCREF(member);
}
@@ -606,7 +608,7 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
PyTuple_SET_ITEM(item_new, 0, PyUnicode_FromString(format));
}
else {
item_new= Py_BuildValue("sO", format, item);
item_new = Py_BuildValue("sO", format, item);
}
ret = PyObject_Call(pack, item_new, NULL);
@@ -650,8 +652,8 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
/* generic function to avoid depending on RNA */
void *PyC_RNA_AsPointer(PyObject *value, const char *type_name)
{
PyObject* as_pointer;
PyObject* pointer;
PyObject *as_pointer;
PyObject *pointer;
if (!strcmp(Py_TYPE(value)->tp_name, type_name) &&
(as_pointer = PyObject_GetAttrString(value, "as_pointer")) != NULL &&
@@ -705,8 +707,8 @@ char *PyC_FlagSet_AsString(PyC_FlagSet *item)
int PyC_FlagSet_ValueFromID_int(PyC_FlagSet *item, const char *identifier, int *value)
{
for( ; item->identifier; item++) {
if(strcmp(item->identifier, identifier) == 0) {
for ( ; item->identifier; item++) {
if (strcmp(item->identifier, identifier) == 0) {
*value = item->value;
return 1;
}

View File

@@ -73,12 +73,17 @@ PyDoc_STRVAR(bpy_script_paths_doc,
static PyObject *bpy_script_paths(PyObject *UNUSED(self))
{
PyObject *ret = PyTuple_New(2);
PyObject *item;
char *path;
path = BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL);
PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
item = PyUnicode_DecodeFSDefault(path ? path : "");
BLI_assert(item != NULL);
PyTuple_SET_ITEM(ret, 0, item);
path = BLI_get_folder(BLENDER_USER_SCRIPTS, NULL);
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:""));
item = PyUnicode_DecodeFSDefault(path ? path : "");
BLI_assert(item != NULL);
PyTuple_SET_ITEM(ret, 1, item);
return ret;
}
@@ -202,7 +207,7 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj
path = BLI_get_folder_version(folder_id, (major * 100) + minor, FALSE);
return PyUnicode_DecodeFSDefault(path);
return PyUnicode_DecodeFSDefault(path ? path : "");
}
static PyMethodDef meth_bpy_script_paths =

View File

@@ -47,6 +47,8 @@ static PyStructSequence_Field app_cb_info_fields[] = {
{(char *)"render_pre", (char *)"Callback list - on render (before)"},
{(char *)"render_post", (char *)"Callback list - on render (after)"},
{(char *)"render_stats", (char *)"Callback list - on printing render statistics"},
{(char *)"render_complete", (char *)"Callback list - on completion of render job"},
{(char *)"render_cancel", (char *)"Callback list - on cancelling a render job"},
{(char *)"load_pre", (char *)"Callback list - on loading a new blend file (before)"},
{(char *)"load_post", (char *)"Callback list - on loading a new blend file (after)"},
{(char *)"save_pre", (char *)"Callback list - on saving a blend file (before)"},
@@ -254,10 +256,10 @@ void BPY_app_handlers_reset(const short do_all)
for (i = PyList_GET_SIZE(ls) - 1; i >= 0; i--) {
if ( (PyFunction_Check((item = PyList_GET_ITEM(ls, i)))) &&
(dict_ptr = _PyObject_GetDictPtr(item)) &&
(*dict_ptr) &&
(PyDict_GetItem(*dict_ptr, perm_id_str) != NULL))
if ((PyFunction_Check((item = PyList_GET_ITEM(ls, i)))) &&
(dict_ptr = _PyObject_GetDictPtr(item)) &&
(*dict_ptr) &&
(PyDict_GetItem(*dict_ptr, perm_id_str) != NULL))
{
/* keep */
}
@@ -277,13 +279,12 @@ void BPY_app_handlers_reset(const short do_all)
void bpy_app_generic_callback(struct Main *UNUSED(main), struct ID *id, void *arg)
{
PyObject *cb_list = py_cb_array[GET_INT_FROM_POINTER(arg)];
Py_ssize_t cb_list_len;
if ((cb_list_len = PyList_GET_SIZE(cb_list)) > 0) {
if (PyList_GET_SIZE(cb_list) > 0) {
PyGILState_STATE gilstate = PyGILState_Ensure();
PyObject* args = PyTuple_New(1); // save python creating each call
PyObject* func;
PyObject* ret;
PyObject *args = PyTuple_New(1); // save python creating each call
PyObject *func;
PyObject *ret;
Py_ssize_t pos;
/* setup arguments */
@@ -297,8 +298,9 @@ void bpy_app_generic_callback(struct Main *UNUSED(main), struct ID *id, void *ar
Py_INCREF(Py_None);
}
// Iterate the list and run the callbacks
for (pos = 0; pos < cb_list_len; pos++) {
/* Iterate the list and run the callbacks
* note: don't store the list size since the scripts may remove themselves */
for (pos = 0; pos < PyList_GET_SIZE(cb_list); pos++) {
func = PyList_GET_ITEM(cb_list, pos);
ret = PyObject_Call(func, args, NULL);
if (ret == NULL) {

View File

@@ -70,7 +70,7 @@ int bpy_pydriver_create_dict(void)
mod = PyImport_ImportModule("math");
if (mod) {
PyDict_Merge(d, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
PyDict_Merge(d, PyModule_GetDict(mod), 0); /* 0 - don't overwrite existing values */
Py_DECREF(mod);
}
@@ -159,14 +159,14 @@ static void pydriver_error(ChannelDriver *driver)
/* This evals py driver expressions, 'expr' is a Python expression that
* should evaluate to a float number, which is returned.
*
* (old)note: PyGILState_Ensure() isnt always called because python can call
* (old)note: PyGILState_Ensure() isn't always called because python can call
* the bake operator which intern starts a thread which calls scene update
* which does a driver update. to avoid a deadlock check PYC_INTERPRETER_ACTIVE
* if PyGILState_Ensure() is needed - see [#27683]
*
* (new)note: checking if python is running is not threadsafe [#28114]
* now release the GIL on python operator execution instead, using
* PyEval_SaveThread() / PyEval_RestoreThread() so we dont lock up blender.
* PyEval_SaveThread() / PyEval_RestoreThread() so we don't lock up blender.
*/
float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
{

View File

@@ -52,6 +52,7 @@
#include "DNA_text_types.h"
#include "BLI_path_util.h"
#include "BLI_fileops.h"
#include "BLI_math_base.h"
#include "BLI_string.h"
#include "BLI_string_utf8.h"
@@ -96,7 +97,7 @@ void bpy_context_update(bContext *C)
{
BPy_SetContext(C);
bpy_import_main_set(CTX_data_main(C));
BPY_modules_update(C); /* can give really bad results if this isnt here */
BPY_modules_update(C); /* can give really bad results if this isn't here */
}
void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
@@ -238,7 +239,7 @@ void BPY_python_start(int argc, const char **argv)
Py_Initialize();
// PySys_SetArgv(argc, argv); // broken in py3, not a huge deal
/* sigh, why do python guys not have a char** version anymore? :( */
/* sigh, why do python guys not have a (char **) version anymore? */
{
int i;
PyObject *py_argv = PyList_New(argc);
@@ -388,7 +389,7 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
}
else {
FILE *fp = fopen(fn, "r");
FILE *fp = BLI_fopen(fn, "r");
if (fp) {
py_dict = PyC_DefaultNameSpace(fn);
@@ -497,7 +498,7 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
mod = PyImport_ImportModule("math");
if (mod) {
PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - don't overwrite existing values */
Py_DECREF(mod);
}
else { /* highly unlikely but possibly */
@@ -705,7 +706,7 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
#ifdef WITH_PYTHON_MODULE
#include "BLI_fileops.h"
/* TODO, reloading the module isnt functional at the moment. */
/* TODO, reloading the module isn't functional at the moment. */
static void bpy_module_free(void *mod);
extern int main_python_enter(int argc, const char **argv);
@@ -782,7 +783,7 @@ PyInit_bpy(void)
* we may end up having to rename this module so there is no naming conflict here eg:
* 'from blender import bpy'
*
* 3) we dont know the filename at this point, workaround by assigning a dummy value
* 3) we don't know the filename at this point, workaround by assigning a dummy value
* which calls back when its freed so the real loading can take place.
*/

View File

@@ -62,7 +62,7 @@ static void atexit_func_call(const char *func_name, PyObject *atexit_func_arg)
PyObject *ret;
PyTuple_SET_ITEM(args, 0, atexit_func_arg);
Py_INCREF(atexit_func_arg); /* only incref so we dont dec'ref along with 'args' */
Py_INCREF(atexit_func_arg); /* only incref so we don't dec'ref along with 'args' */
ret = PyObject_CallObject(atexit_func, args);

View File

@@ -62,7 +62,7 @@
#endif
typedef struct {
PyObject_HEAD /* required python macro */
PyObject_HEAD /* required python macro */
/* collection iterator specific parts */
char relpath[FILE_MAX];
char abspath[FILE_MAX]; /* absolute path */
@@ -186,7 +186,7 @@ static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *
{
static const char *kwlist[] = {"filepath", "link", "relative", NULL};
BPy_Library *ret;
const char* filename = NULL;
const char *filename = NULL;
int is_rel = 0, is_link = 0;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ii:load", (char **)kwlist, &filename, &is_link, &is_rel))
@@ -199,8 +199,8 @@ static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *
BLI_path_abs(ret->abspath, G.main->name);
ret->blo_handle = NULL;
ret->flag= (is_link ? FILE_LINK : 0) |
(is_rel ? FILE_RELPATH : 0);
ret->flag = ((is_link ? FILE_LINK : 0) |
(is_rel ? FILE_RELPATH : 0));
ret->dict = PyDict_New();
@@ -431,7 +431,7 @@ int bpy_lib_init(PyObject *mod_par)
PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL));
/* some compilers dont like accessing this directly, delay assignment */
/* some compilers don't like accessing this directly, delay assignment */
bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr;
if (PyType_Ready(&bpy_lib_Type) < 0)

View File

@@ -225,7 +225,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
ReportList *reports;
reports = MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these dont move into global reports */
BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these don't move into global reports */
#ifdef BPY_RELEASE_GIL
/* release GIL, since a thread could be started from an operator

View File

@@ -155,10 +155,10 @@ static void printf_func_error(PyObject *py_func)
/* use py style error */
fprintf(stderr, "File \"%s\", line %d, in %s\n",
_PyUnicode_AsString(f_code->co_filename),
f_code->co_firstlineno,
_PyUnicode_AsString(((PyFunctionObject *)py_func)->func_name)
);
_PyUnicode_AsString(f_code->co_filename),
f_code->co_firstlineno,
_PyUnicode_AsString(((PyFunctionObject *)py_func)->func_name)
);
}
/* operators and classes use this so it can store the args given but defer
@@ -372,7 +372,7 @@ static int bpy_struct_id_used(StructRNA *srna, char *identifier)
/* Function that sets RNA, NOTE - self is NULL when called from python,
* but being abused from C so we can pass the srna along.
* This isnt incorrect since its a python object - but be careful */
* This isn't incorrect since its a python object - but be careful */
PyDoc_STRVAR(BPy_BoolProperty_doc,
".. function:: BoolProperty(name=\"\", "
"description=\"\", "
@@ -1033,14 +1033,14 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
item = PySequence_Fast_GET_ITEM(seq_fast, i);
if ( (PyTuple_CheckExact(item)) &&
(item_size = PyTuple_GET_SIZE(item)) &&
(item_size == 3 || item_size == 4) &&
(tmp.identifier = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
(tmp.name = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
(tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
/* TODO, number isnt ensured to be unique from the script author */
(item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1))
if ((PyTuple_CheckExact(item)) &&
(item_size = PyTuple_GET_SIZE(item)) &&
(item_size == 3 || item_size == 4) &&
(tmp.identifier = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
(tmp.name = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
(tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
/* TODO, number isn't ensured to be unique from the script author */
(item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1))
{
if (is_enum_flag) {
if (item_size < 4) {
@@ -1260,7 +1260,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
}
/* items can be a list or a callable */
if (PyFunction_Check(items)) { /* dont use PyCallable_Check because we need the function code for errors */
if (PyFunction_Check(items)) { /* don't use PyCallable_Check because we need the function code for errors */
PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(items);
if (f_code->co_argcount != 2) {
PyErr_Format(PyExc_ValueError,

View File

@@ -85,7 +85,7 @@
#define USE_MATHUTILS
#define USE_STRING_COERCE
static PyObject* pyrna_struct_Subtype(PointerRNA *ptr);
static PyObject *pyrna_struct_Subtype(PointerRNA *ptr);
static PyObject *pyrna_prop_collection_values(BPy_PropertyRNA *self);
#define BPY_DOC_ID_PROP_TYPE_NOTE \
@@ -372,7 +372,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po
static short pyrna_rotation_euler_order_get(PointerRNA *ptr, PropertyRNA **prop_eul_order, short order_fallback);
/* bpyrna vector/euler/quat callbacks */
static int mathutils_rna_array_cb_index = -1; /* index for our callbacks */
static unsigned char mathutils_rna_array_cb_index = -1; /* index for our callbacks */
/* subtype not used much yet */
#define MATHUTILS_CB_SUBTYPE_EUL 0
@@ -517,7 +517,7 @@ static Mathutils_Callback mathutils_rna_array_cb = {
/* bpyrna matrix callbacks */
static int mathutils_rna_matrix_cb_index = -1; /* index for our callbacks */
static unsigned char mathutils_rna_matrix_cb_index = -1; /* index for our callbacks */
static int mathutils_rna_matrix_get(BaseMathObject *bmo, int UNUSED(subtype))
{
@@ -756,15 +756,15 @@ int pyrna_enum_value_from_id(EnumPropertyItem *item, const char *identifier, int
static int pyrna_struct_compare(BPy_StructRNA *a, BPy_StructRNA *b)
{
return ( (a->ptr.data == b->ptr.data) &&
(a->ptr.type == b->ptr.type)) ? 0 : -1;
return (((a->ptr.data == b->ptr.data) &&
(a->ptr.type == b->ptr.type)) ? 0 : -1);
}
static int pyrna_prop_compare(BPy_PropertyRNA *a, BPy_PropertyRNA *b)
{
return ( (a->prop == b->prop) &&
return (((a->prop == b->prop) &&
(a->ptr.data == b->ptr.data) &&
(a->ptr.type == b->ptr.type) ) ? 0 : -1;
(a->ptr.type == b->ptr.type)) ? 0 : -1);
}
static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op)
@@ -776,21 +776,21 @@ static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op)
ok = pyrna_struct_compare((BPy_StructRNA *)a, (BPy_StructRNA *)b);
switch (op) {
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
}
return Py_INCREF(res), res;
@@ -805,21 +805,21 @@ static PyObject *pyrna_prop_richcmp(PyObject *a, PyObject *b, int op)
ok = pyrna_prop_compare((BPy_PropertyRNA *)a, (BPy_PropertyRNA *)b);
switch (op) {
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
}
return Py_INCREF(res), res;
@@ -912,7 +912,7 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self)
int len = -1;
char *c = type_fmt;
while ((*c++= tolower(*type_id++))) {}
while ((*c++ = tolower(*type_id++))) {}
if (type == PROP_COLLECTION) {
len = pyrna_prop_collection_length(self);
@@ -1694,9 +1694,9 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
* if this causes problems in the future it should be removed.
*/
if ((ptr_type == &RNA_AnyType) &&
(BPy_StructRNA_Check(value)) &&
(RNA_struct_is_a(((BPy_StructRNA *)value)->ptr.type, &RNA_Operator))
) {
(BPy_StructRNA_Check(value)) &&
(RNA_struct_is_a(((BPy_StructRNA *)value)->ptr.type, &RNA_Operator)))
{
value = PyObject_GetAttrString(value, "properties");
value_new = value;
}
@@ -2640,7 +2640,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop,
RNA_property_float_get_array(ptr, prop, values);
for (count = start; count < stop; count++) {
fval = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, count-start));
fval = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, count - start));
CLAMP(fval, min, max);
values[count] = fval;
}
@@ -2660,7 +2660,7 @@ static int prop_subscript_ass_array_slice(PointerRNA *ptr, PropertyRNA *prop,
RNA_property_boolean_get_array(ptr, prop, values);
for (count = start; count < stop; count++)
values[count] = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count-start));
values[count] = PyLong_AsLong(PySequence_Fast_GET_ITEM(value, count - start));
if (PyErr_Occurred()) ret = -1;
else RNA_property_boolean_set_array(ptr, prop, values);
@@ -3282,25 +3282,42 @@ static PyObject *pyrna_struct_type_recast(BPy_StructRNA *self)
return pyrna_struct_CreatePyObject(&r_ptr);
}
static void pyrna_dir_members_py__add_keys(PyObject *list, PyObject *dict)
{
PyObject *list_tmp;
list_tmp = PyDict_Keys(dict);
PyList_SetSlice(list, INT_MAX, INT_MAX, list_tmp);
Py_DECREF(list_tmp);
}
static void pyrna_dir_members_py(PyObject *list, PyObject *self)
{
PyObject *dict;
PyObject **dict_ptr;
PyObject *list_tmp;
dict_ptr = _PyObject_GetDictPtr((PyObject *)self);
if (dict_ptr && (dict = *dict_ptr)) {
list_tmp = PyDict_Keys(dict);
PyList_SetSlice(list, INT_MAX, INT_MAX, list_tmp);
Py_DECREF(list_tmp);
pyrna_dir_members_py__add_keys(list, dict);
}
dict = ((PyTypeObject *)Py_TYPE(self))->tp_dict;
if (dict) {
list_tmp = PyDict_Keys(dict);
PyList_SetSlice(list, INT_MAX, INT_MAX, list_tmp);
Py_DECREF(list_tmp);
pyrna_dir_members_py__add_keys(list, dict);
}
/* since this is least common case, handle it last */
if (BPy_PropertyRNA_Check(self)) {
BPy_PropertyRNA *self_prop = (BPy_PropertyRNA *)self;
PointerRNA r_ptr;
if (RNA_property_collection_type_get(&self_prop->ptr, self_prop->prop, &r_ptr)) {
PyObject *cls = pyrna_struct_Subtype(&r_ptr); /* borrows */
dict = ((PyTypeObject *)cls)->tp_dict;
pyrna_dir_members_py__add_keys(list, dict);
Py_DECREF(cls);
}
}
}
@@ -3770,8 +3787,10 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyErr_Clear();
cls = pyrna_struct_Subtype(&r_ptr); /* borrows */
cls = pyrna_struct_Subtype(&r_ptr);
ret = PyObject_GenericGetAttr(cls, pyname);
Py_DECREF(cls);
/* restore the original error */
if (ret == NULL) {
PyErr_Restore(error_type, error_value, error_traceback);
@@ -3919,6 +3938,12 @@ static PyGetSetDef pyrna_struct_getseters[] = {
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
static PyObject *pyrna_func_doc_get(BPy_FunctionRNA *self, void *closure);
static PyGetSetDef pyrna_func_getseters[] = {
{(char *)"__doc__", (getter)pyrna_func_doc_get, (setter)NULL, NULL, NULL},
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
};
PyDoc_STRVAR(pyrna_prop_collection_keys_doc,
".. method:: keys()\n"
@@ -3927,7 +3952,7 @@ PyDoc_STRVAR(pyrna_prop_collection_keys_doc,
" (matching pythons dict.keys() functionality).\n"
"\n"
" :return: the identifiers for each member of this collection.\n"
" :rtype: list of stings\n"
" :rtype: list of strings\n"
);
static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self)
{
@@ -4034,7 +4059,7 @@ static PyObject *pyrna_struct_get(BPy_StructRNA *self, PyObject *args)
IDProperty *group, *idprop;
const char *key;
PyObject* def = Py_None;
PyObject *def = Py_None;
PYRNA_STRUCT_CHECK_OBJ(self);
@@ -4092,7 +4117,7 @@ static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args
PointerRNA newptr;
PyObject *key_ob;
PyObject* def = Py_None;
PyObject *def = Py_None;
PYRNA_PROP_CHECK_OBJ(self);
@@ -4166,16 +4191,16 @@ static PyObject *pyrna_prop_collection_find(BPy_PropertyRNA *self, PyObject *key
return PyLong_FromSsize_t(index);
}
static void foreach_attr_type( BPy_PropertyRNA *self, const char *attr,
/* values to assign */
RawPropertyType *raw_type, int *attr_tot, int *attr_signed)
static void foreach_attr_type(BPy_PropertyRNA *self, const char *attr,
/* values to assign */
RawPropertyType *raw_type, int *attr_tot, int *attr_signed)
{
PropertyRNA *prop;
*raw_type = PROP_RAW_UNSET;
*attr_tot = 0;
*attr_signed = FALSE;
/* note: this is fail with zero length lists, so dont let this get caled in that case */
/* note: this is fail with zero length lists, so don't let this get caled in that case */
RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
prop = RNA_struct_find_property(&itemptr, attr);
*raw_type = RNA_property_raw_type(prop);
@@ -4190,8 +4215,8 @@ static void foreach_attr_type( BPy_PropertyRNA *self, const char *attr,
static int foreach_parse_args(
BPy_PropertyRNA *self, PyObject *args,
/*values to assign */
const char **attr, PyObject **seq, int *tot, int *size,
/* values to assign */
const char **attr, PyObject **seq, int *tot, int *size,
RawPropertyType *raw_type, int *attr_tot, int *attr_signed
)
{
@@ -4236,7 +4261,7 @@ static int foreach_parse_args(
#endif
}
/* check 'attr_tot' otherwise we dont know if any values were set
/* check 'attr_tot' otherwise we don't know if any values were set
* this isn't ideal because it means running on an empty list may fail silently when its not compatible. */
if (*size == 0 && *attr_tot != 0) {
PyErr_SetString(PyExc_AttributeError, "attribute does not support foreach method");
@@ -4250,21 +4275,21 @@ static int foreach_compat_buffer(RawPropertyType raw_type, int attr_signed, cons
char f = format ? *format:'B'; /* B is assumed when not set */
switch (raw_type) {
case PROP_RAW_CHAR:
if (attr_signed) return (f == 'b') ? 1:0;
else return (f == 'B') ? 1:0;
case PROP_RAW_SHORT:
if (attr_signed) return (f == 'h') ? 1:0;
else return (f == 'H') ? 1:0;
case PROP_RAW_INT:
if (attr_signed) return (f == 'i') ? 1:0;
else return (f == 'I') ? 1:0;
case PROP_RAW_FLOAT:
return (f == 'f') ? 1:0;
case PROP_RAW_DOUBLE:
return (f == 'd') ? 1:0;
case PROP_RAW_UNSET:
return 0;
case PROP_RAW_CHAR:
if (attr_signed) return (f == 'b') ? 1:0;
else return (f == 'B') ? 1:0;
case PROP_RAW_SHORT:
if (attr_signed) return (f == 'h') ? 1:0;
else return (f == 'H') ? 1:0;
case PROP_RAW_INT:
if (attr_signed) return (f == 'i') ? 1:0;
else return (f == 'I') ? 1:0;
case PROP_RAW_FLOAT:
return (f == 'f') ? 1:0;
case PROP_RAW_DOUBLE:
return (f == 'd') ? 1:0;
case PROP_RAW_UNSET:
return 0;
}
return 0;
@@ -4314,25 +4339,25 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
for ( ; i < tot; i++) {
item = PySequence_GetItem(seq, i);
switch (raw_type) {
case PROP_RAW_CHAR:
((char *)array)[i] = (char)PyLong_AsLong(item);
break;
case PROP_RAW_SHORT:
((short *)array)[i] = (short)PyLong_AsLong(item);
break;
case PROP_RAW_INT:
((int *)array)[i] = (int)PyLong_AsLong(item);
break;
case PROP_RAW_FLOAT:
((float *)array)[i] = (float)PyFloat_AsDouble(item);
break;
case PROP_RAW_DOUBLE:
((double *)array)[i] = (double)PyFloat_AsDouble(item);
break;
case PROP_RAW_UNSET:
/* should never happen */
BLI_assert(!"Invalid array type - set");
break;
case PROP_RAW_CHAR:
((char *)array)[i] = (char)PyLong_AsLong(item);
break;
case PROP_RAW_SHORT:
((short *)array)[i] = (short)PyLong_AsLong(item);
break;
case PROP_RAW_INT:
((int *)array)[i] = (int)PyLong_AsLong(item);
break;
case PROP_RAW_FLOAT:
((float *)array)[i] = (float)PyFloat_AsDouble(item);
break;
case PROP_RAW_DOUBLE:
((double *)array)[i] = (double)PyFloat_AsDouble(item);
break;
case PROP_RAW_UNSET:
/* should never happen */
BLI_assert(!"Invalid array type - set");
break;
}
Py_DECREF(item);
@@ -4369,27 +4394,27 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
for ( ; i < tot; i++) {
switch (raw_type) {
case PROP_RAW_CHAR:
item = PyLong_FromSsize_t((Py_ssize_t) ((char *)array)[i]);
break;
case PROP_RAW_SHORT:
item = PyLong_FromSsize_t((Py_ssize_t) ((short *)array)[i]);
break;
case PROP_RAW_INT:
item = PyLong_FromSsize_t((Py_ssize_t) ((int *)array)[i]);
break;
case PROP_RAW_FLOAT:
item = PyFloat_FromDouble((double) ((float *)array)[i]);
break;
case PROP_RAW_DOUBLE:
item = PyFloat_FromDouble((double) ((double *)array)[i]);
break;
default: /* PROP_RAW_UNSET */
/* should never happen */
BLI_assert(!"Invalid array type - get");
item = Py_None;
Py_INCREF(item);
break;
case PROP_RAW_CHAR:
item = PyLong_FromSsize_t((Py_ssize_t) ((char *)array)[i]);
break;
case PROP_RAW_SHORT:
item = PyLong_FromSsize_t((Py_ssize_t) ((short *)array)[i]);
break;
case PROP_RAW_INT:
item = PyLong_FromSsize_t((Py_ssize_t) ((int *)array)[i]);
break;
case PROP_RAW_FLOAT:
item = PyFloat_FromDouble((double) ((float *)array)[i]);
break;
case PROP_RAW_DOUBLE:
item = PyFloat_FromDouble((double) ((double *)array)[i]);
break;
default: /* PROP_RAW_UNSET */
/* should never happen */
BLI_assert(!"Invalid array type - get");
item = Py_None;
Py_INCREF(item);
break;
}
PySequence_SetItem(seq, i, item);
@@ -4524,7 +4549,7 @@ static struct PyMethodDef pyrna_struct_methods[] = {
{"type_recast", (PyCFunction)pyrna_struct_type_recast, METH_NOARGS, pyrna_struct_type_recast_doc},
{"__dir__", (PyCFunction)pyrna_struct_dir, METH_NOARGS, NULL},
/* experemental */
/* experimental */
{"callback_add", (PyCFunction)pyrna_callback_add, METH_VARARGS, NULL},
{"callback_remove", (PyCFunction)pyrna_callback_remove, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
@@ -4993,7 +5018,7 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
/* Check if we gave args that don't exist in the function
* printing the error is slow but it should only happen when developing.
* the if below is quick, checking if it passed less keyword args then we gave.
* (Dont overwrite the error if we have one, otherwise can skip important messages and confuse with args)
* (Don't overwrite the error if we have one, otherwise can skip important messages and confuse with args)
*/
if (err == 0 && kw && (pykw_len > kw_tot)) {
PyObject *key, *value;
@@ -5131,6 +5156,22 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject
Py_RETURN_NONE;
}
static PyObject *pyrna_func_doc_get(BPy_FunctionRNA *self, void *UNUSED(closure))
{
PyObject *ret;
char *args;
args = RNA_function_as_string_keywords(NULL, self->func, NULL, TRUE, TRUE);
ret = PyUnicode_FromFormat("%.200s.%.200s(%.200s)\n%s",
RNA_struct_identifier(self->ptr.type),
RNA_function_identifier(self->func),
args, RNA_function_ui_description(self->func));
MEM_freeN(args);
return ret;
}
/* subclasses of pyrna_struct_Type which support idprop definitions use this as a metaclass */
/* note: tp_base member is set to &PyType_Type on init */
@@ -5707,7 +5748,7 @@ PyTypeObject pyrna_func_Type = {
/*** Attribute descriptor and subclassing stuff ***/
NULL, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
NULL, /* struct PyGetSetDef *tp_getset; */
pyrna_func_getseters, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
@@ -5922,10 +5963,10 @@ static void pyrna_subtype_set_rna(PyObject *newclass, StructRNA *srna)
/* done with rna instance */
}
static PyObject* pyrna_srna_Subtype(StructRNA *srna);
static PyObject *pyrna_srna_Subtype(StructRNA *srna);
/* return a borrowed reference */
static PyObject* pyrna_srna_PyBase(StructRNA *srna) //, PyObject *bpy_types_dict)
static PyObject *pyrna_srna_PyBase(StructRNA *srna) //, PyObject *bpy_types_dict)
{
/* Assume RNA_struct_py_type_get(srna) was already checked */
StructRNA *base;
@@ -5952,7 +5993,7 @@ static PyObject* pyrna_srna_PyBase(StructRNA *srna) //, PyObject *bpy_types_dict
* return a borrowed reference */
static PyObject *bpy_types_dict = NULL;
static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
static PyObject *pyrna_srna_ExternalType(StructRNA *srna)
{
const char *idname = RNA_struct_identifier(srna);
PyObject *newclass;
@@ -6002,7 +6043,7 @@ static PyObject* pyrna_srna_ExternalType(StructRNA *srna)
return newclass;
}
static PyObject* pyrna_srna_Subtype(StructRNA *srna)
static PyObject *pyrna_srna_Subtype(StructRNA *srna)
{
PyObject *newclass = NULL;
@@ -6035,8 +6076,8 @@ static PyObject* pyrna_srna_Subtype(StructRNA *srna)
// if (!descr) descr = "(no docs)";
// "__doc__", descr
if ( RNA_struct_idprops_check(srna) &&
!PyObject_IsSubclass(py_base, (PyObject *)&pyrna_struct_meta_idprop_Type))
if (RNA_struct_idprops_check(srna) &&
!PyObject_IsSubclass(py_base, (PyObject *)&pyrna_struct_meta_idprop_Type))
{
metaclass = (PyObject *)&pyrna_struct_meta_idprop_Type;
}
@@ -6045,7 +6086,7 @@ static PyObject* pyrna_srna_Subtype(StructRNA *srna)
}
/* always use O not N when calling, N causes refcount errors */
newclass = PyObject_CallFunction(metaclass, (char *)"s(O){sss()}",
newclass = PyObject_CallFunction(metaclass, (char *)"s(O) {sss()}",
idname, py_base, "__module__","bpy.types", "__slots__");
/* newclass will now have 2 ref's, ???, probably 1 is internal since decrefing here segfaults */
@@ -6082,7 +6123,7 @@ static StructRNA *srna_from_ptr(PointerRNA *ptr)
}
/* always returns a new ref, be sure to decref when done */
static PyObject* pyrna_struct_Subtype(PointerRNA *ptr)
static PyObject *pyrna_struct_Subtype(PointerRNA *ptr)
{
return pyrna_srna_Subtype(srna_from_ptr(ptr));
}
@@ -6588,10 +6629,10 @@ static int pyrna_deferred_register_class_recursive(StructRNA *srna, PyTypeObject
*
* So only scan base classes which are not subclasses if blender types.
* This best fits having 'mix-in' classes for operators and render engines.
* */
*/
if (py_superclass != &PyBaseObject_Type &&
!PyObject_IsSubclass((PyObject *)py_superclass, (PyObject *)&pyrna_struct_Type)
) {
!PyObject_IsSubclass((PyObject *)py_superclass, (PyObject *)&pyrna_struct_Type))
{
ret = pyrna_deferred_register_class_recursive(srna, py_superclass);
if (ret != 0) {
@@ -6606,7 +6647,7 @@ static int pyrna_deferred_register_class_recursive(StructRNA *srna, PyTypeObject
int pyrna_deferred_register_class(StructRNA *srna, PyObject *py_class)
{
/* Panels and Menus dont need this
/* Panels and Menus don't need this
* save some time and skip the checks here */
if (!RNA_struct_idprops_register_check(srna))
return 0;
@@ -6704,7 +6745,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
func_arg_count = rna_function_arg_count(func);
if (func_arg_count >= 0) { /* -1 if we dont care*/
if (func_arg_count >= 0) { /* -1 if we don't care*/
arg_count = ((PyCodeObject *)PyFunction_GET_CODE(item))->co_argcount;
/* note, the number of args we check for and the number of args we give to
@@ -7016,8 +7057,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
if (err == -1) {
PyC_Err_Format_Prefix(PyExc_RuntimeError,
"class %.200s, function %.200s: incompatible return value ",
RNA_struct_identifier(ptr->type), RNA_function_identifier(func)
);
RNA_struct_identifier(ptr->type), RNA_function_identifier(func));
}
}
else if (ret_len > 1) {
@@ -7065,10 +7105,10 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
if (err != 0) {
ReportList *reports;
/* alert the user, else they wont know unless they see the console. */
if ( (!is_static) &&
(ptr->data) &&
(RNA_struct_is_a(ptr->type, &RNA_Operator)) &&
(is_valid_wm == (CTX_wm_manager(C) != NULL)))
if ((!is_static) &&
(ptr->data) &&
(RNA_struct_is_a(ptr->type, &RNA_Operator)) &&
(is_valid_wm == (CTX_wm_manager(C) != NULL)))
{
wmOperator *op = ptr->data;
reports = op->reports;
@@ -7106,7 +7146,7 @@ static void bpy_class_free(void *pyob_ptr)
PyErr_Clear();
#if 0 /* needs further investigation, too annoying so quiet for now */
if (G.f&G_DEBUG) {
if (G.f & G_DEBUG) {
if (self->ob_refcnt > 1) {
PyC_ObSpit("zombie class - ref should be 1", self);
}

View File

@@ -550,21 +550,21 @@ int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data,
{
int ret;
switch (RNA_property_type(prop)) {
case PROP_FLOAT:
ret = py_to_array(py, ptr, prop, param_data, py_float_check, "float", sizeof(float),
py_to_float, (RNA_SetArrayFunc)RNA_property_float_set_array, error_prefix);
break;
case PROP_INT:
ret = py_to_array(py, ptr, prop, param_data, py_int_check, "int", sizeof(int),
py_to_int, (RNA_SetArrayFunc)RNA_property_int_set_array, error_prefix);
break;
case PROP_BOOLEAN:
ret = py_to_array(py, ptr, prop, param_data, py_bool_check, "boolean", sizeof(int),
py_to_bool, (RNA_SetArrayFunc)RNA_property_boolean_set_array, error_prefix);
break;
default:
PyErr_SetString(PyExc_TypeError, "not an array type");
ret = -1;
case PROP_FLOAT:
ret = py_to_array(py, ptr, prop, param_data, py_float_check, "float", sizeof(float),
py_to_float, (RNA_SetArrayFunc)RNA_property_float_set_array, error_prefix);
break;
case PROP_INT:
ret = py_to_array(py, ptr, prop, param_data, py_int_check, "int", sizeof(int),
py_to_int, (RNA_SetArrayFunc)RNA_property_int_set_array, error_prefix);
break;
case PROP_BOOLEAN:
ret = py_to_array(py, ptr, prop, param_data, py_bool_check, "boolean", sizeof(int),
py_to_bool, (RNA_SetArrayFunc)RNA_property_boolean_set_array, error_prefix);
break;
default:
PyErr_SetString(PyExc_TypeError, "not an array type");
ret = -1;
}
return ret;
@@ -575,21 +575,21 @@ int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, in
{
int ret;
switch (RNA_property_type(prop)) {
case PROP_FLOAT:
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
py_float_check, "float", py_to_float, float_set_index, error_prefix);
break;
case PROP_INT:
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
py_int_check, "int", py_to_int, int_set_index, error_prefix);
break;
case PROP_BOOLEAN:
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
py_bool_check, "boolean", py_to_bool, bool_set_index, error_prefix);
break;
default:
PyErr_SetString(PyExc_TypeError, "not an array type");
ret = -1;
case PROP_FLOAT:
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
py_float_check, "float", py_to_float, float_set_index, error_prefix);
break;
case PROP_INT:
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
py_int_check, "int", py_to_int, int_set_index, error_prefix);
break;
case PROP_BOOLEAN:
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
py_bool_check, "boolean", py_to_bool, bool_set_index, error_prefix);
break;
default:
PyErr_SetString(PyExc_TypeError, "not an array type");
ret = -1;
}
return ret;
@@ -600,18 +600,18 @@ PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index)
PyObject *item;
switch (RNA_property_type(prop)) {
case PROP_FLOAT:
item = PyFloat_FromDouble(RNA_property_float_get_index(ptr, prop, index));
break;
case PROP_BOOLEAN:
item = PyBool_FromLong(RNA_property_boolean_get_index(ptr, prop, index));
break;
case PROP_INT:
item = PyLong_FromSsize_t(RNA_property_int_get_index(ptr, prop, index));
break;
default:
PyErr_SetString(PyExc_TypeError, "not an array type");
item = NULL;
case PROP_FLOAT:
item = PyFloat_FromDouble(RNA_property_float_get_index(ptr, prop, index));
break;
case PROP_BOOLEAN:
item = PyBool_FromLong(RNA_property_boolean_get_index(ptr, prop, index));
break;
case PROP_INT:
item = PyLong_FromSsize_t(RNA_property_int_get_index(ptr, prop, index));
break;
default:
PyErr_SetString(PyExc_TypeError, "not an array type");
item = NULL;
}
return item;

View File

@@ -137,7 +137,7 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args)
ED_region_draw_cb_exit(((ARegion *)self->ptr.data)->type, handle);
}
/* dont allow reuse */
/* don't allow reuse */
PyCapsule_SetName(py_handle, RNA_CAPSULE_ID_INVALID);
Py_RETURN_NONE;

View File

@@ -54,7 +54,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
/* new style errors. `err' is an instance */
if (! (v = PyObject_GetAttrString(err, "msg")))
if (!(v = PyObject_GetAttrString(err, "msg")))
goto finally;
*message = v;
@@ -62,7 +62,7 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
goto finally;
if (v == Py_None)
*filename = NULL;
else if (! (*filename = _PyUnicode_AsString(v)))
else if (!(*filename = _PyUnicode_AsString(v)))
goto finally;
Py_DECREF(v);
@@ -131,8 +131,8 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset)
if (parse_syntax_error(value, &message, &filename, lineno, offset, &text)) {
/* python adds a '/', prefix, so check for both */
if ((BLI_path_cmp(filename, filepath) == 0) ||
((filename[0] == '\\' || filename[0] == '/') && BLI_path_cmp(filename + 1, filepath) == 0)
) {
((filename[0] == '\\' || filename[0] == '/') && BLI_path_cmp(filename + 1, filepath) == 0))
{
/* good */
}
else {

View File

@@ -77,7 +77,7 @@ static struct PyModuleDef gpumodule = {
PyMODINIT_FUNC
PyInit_gpu(void)
{
PyObject* m;
PyObject *m;
m = PyModule_Create(&gpumodule);
if (m == NULL)
@@ -155,14 +155,14 @@ PyDoc_STRVAR(GPU_export_shader_doc,
" :return: Dictionary defining the shader, uniforms and attributes.\n"
" :rtype: Dict"
);
static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObject *kwds)
static PyObject *GPU_export_shader(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
{
PyObject* pyscene;
PyObject* pymat;
PyObject* result;
PyObject* dict;
PyObject* val;
PyObject* seq;
PyObject *pyscene;
PyObject *pymat;
PyObject *result;
PyObject *dict;
PyObject *val;
PyObject *seq;
int i;
Scene *scene;
@@ -174,7 +174,7 @@ static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObj
static const char *kwlist[] = {"scene", "material", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:export_shader", (char**)(kwlist), &pyscene, &pymat))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:export_shader", (char **)(kwlist), &pyscene, &pymat))
return NULL;
scene = (Scene *)PyC_RNA_AsPointer(pyscene, "Scene");
@@ -202,7 +202,7 @@ static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObj
PY_DICT_ADD_STRING(result,shader,vertex);
}
seq = PyList_New(BLI_countlist(&shader->uniforms));
for (i=0, uniform=shader->uniforms.first; uniform; uniform=uniform->next, i++) {
for (i = 0, uniform = shader->uniforms.first; uniform; uniform = uniform->next, i++) {
dict = PyDict_New();
PY_DICT_ADD_STRING(dict,uniform,varname);
PY_DICT_ADD_LONG(dict,uniform,datatype);
@@ -230,7 +230,7 @@ static PyObject* GPU_export_shader(PyObject* UNUSED(self), PyObject *args, PyObj
Py_DECREF(seq);
seq = PyList_New(BLI_countlist(&shader->attributes));
for (i=0, attribute=shader->attributes.first; attribute; attribute=attribute->next, i++) {
for (i = 0, attribute = shader->attributes.first; attribute; attribute = attribute->next, i++) {
dict = PyDict_New();
PY_DICT_ADD_STRING(dict,attribute,varname);
PY_DICT_ADD_LONG(dict,attribute,datatype);
@@ -260,9 +260,9 @@ static PyMethodDef meth_export_shader[] = {
{"export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS, GPU_export_shader_doc}
};
PyObject* GPU_initPython(void)
PyObject *GPU_initPython(void)
{
PyObject* module = PyInit_gpu();
PyObject *module = PyInit_gpu();
PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));
PyDict_SetItemString(PyImport_GetModuleDict(), "gpu", module);

View File

@@ -32,5 +32,5 @@
/**
* Initalizes the gpu Python module.
*/
PyObject* GPU_initPython(void);
PyObject *GPU_initPython(void);

View File

@@ -52,8 +52,8 @@ static int mathutils_array_parse_fast(float *array,
i = size;
do {
i--;
if ( ((array[i] = PyFloat_AsDouble((item = PySequence_Fast_GET_ITEM(value_fast, i)))) == -1.0f) &&
PyErr_Occurred())
if (((array[i] = PyFloat_AsDouble((item = PySequence_Fast_GET_ITEM(value_fast, i)))) == -1.0f) &&
PyErr_Occurred())
{
PyErr_Format(PyExc_TypeError,
"%.200s: sequence index %d expected a number, "
@@ -75,10 +75,10 @@ int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *
#if 1 /* approx 6x speedup for mathutils types */
if ( (size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
(size = EulerObject_Check(value) ? 3 : 0) ||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
(size = ColorObject_Check(value) ? 3 : 0))
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
(size = EulerObject_Check(value) ? 3 : 0) ||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
(size = ColorObject_Check(value) ? 3 : 0))
{
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
return -1;
@@ -139,10 +139,10 @@ int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, c
#if 1 /* approx 6x speedup for mathutils types */
if ( (size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
(size = EulerObject_Check(value) ? 3 : 0) ||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
(size = ColorObject_Check(value) ? 3 : 0))
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
(size = EulerObject_Check(value) ? 3 : 0) ||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
(size = ColorObject_Check(value) ? 3 : 0))
{
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
return -1;
@@ -284,18 +284,21 @@ PyObject *mathutils_dynstr_to_py(struct DynStr *ds)
/* Mathutils Callbacks */
/* for mathutils internal use only, eventually should re-alloc but to start with we only have a few users */
static Mathutils_Callback *mathutils_callbacks[8] = {NULL};
#define MATHUTILS_TOT_CB 8
static Mathutils_Callback *mathutils_callbacks[MATHUTILS_TOT_CB] = {NULL};
int Mathutils_RegisterCallback(Mathutils_Callback *cb)
unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb)
{
int i;
unsigned char i;
/* find the first free slot */
for (i = 0; mathutils_callbacks[i]; i++) {
if (mathutils_callbacks[i] == cb) /* already registered? */
return i;
}
BLI_assert(i < MATHUTILS_TOT_CB);
mathutils_callbacks[i] = cb;
return i;
}

View File

@@ -67,8 +67,8 @@ typedef struct {
#include "mathutils_geometry.h"
#include "mathutils_noise.h"
PyObject *BaseMathObject_owner_get( BaseMathObject * self, void * );
PyObject *BaseMathObject_is_wrapped_get( BaseMathObject *self, void * );
PyObject *BaseMathObject_owner_get(BaseMathObject * self, void *);
PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *);
int BaseMathObject_traverse(BaseMathObject *self, visitproc visit, void *arg);
int BaseMathObject_clear(BaseMathObject *self);
@@ -98,7 +98,7 @@ struct Mathutils_Callback {
BaseMathSetIndexFunc set_index;
};
int Mathutils_RegisterCallback(Mathutils_Callback *cb);
unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb);
int _BaseMathObject_ReadCallback(BaseMathObject *self);
int _BaseMathObject_WriteCallback(BaseMathObject *self);

View File

@@ -159,21 +159,21 @@ static PyObject *Color_richcmpr(PyObject *a, PyObject *b, int op)
}
switch (op) {
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
}
return Py_INCREF(res), res;
@@ -218,7 +218,7 @@ static int Color_ass_item(ColorObject *self, int i, PyObject *value)
return -1;
}
if (i < 0) i= COLOR_SIZE - i;
if (i < 0) i = COLOR_SIZE - i;
if (i < 0 || i >= COLOR_SIZE) {
PyErr_SetString(PyExc_IndexError, "color[attribute] = x: "
@@ -504,7 +504,7 @@ static PyObject *Color_mul(PyObject *v1, PyObject *v2)
/* make sure v1 is always the vector */
if (color1 && color2) {
/* col * col, dont support yet! */
/* col * col, don't support yet! */
}
else if (color1) {
if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* COLOR * FLOAT */
@@ -885,14 +885,15 @@ PyObject *Color_CreatePyObject(float *col, int type, PyTypeObject *base_type)
return (PyObject *)self;
}
PyObject *Color_CreatePyObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
PyObject *Color_CreatePyObject_cb(PyObject *cb_user,
unsigned char cb_type, unsigned char cb_subtype)
{
ColorObject *self = (ColorObject *)Color_CreatePyObject(NULL, Py_NEW, NULL);
if (self) {
Py_INCREF(cb_user);
self->cb_user = cb_user;
self->cb_type = (unsigned char)cb_type;
self->cb_subtype = (unsigned char)cb_subtype;
self->cb_user = cb_user;
self->cb_type = cb_type;
self->cb_subtype = cb_subtype;
PyObject_GC_Track(self);
}

View File

@@ -48,7 +48,8 @@ typedef struct {
* blender (stored in blend_data). This is an either/or struct not both*/
//prototypes
PyObject *Color_CreatePyObject( float *col, int type, PyTypeObject *base_type);
PyObject *Color_CreatePyObject_cb(PyObject *cb_user, int cb_type, int cb_subtype);
PyObject *Color_CreatePyObject(float *col, int type, PyTypeObject *base_type);
PyObject *Color_CreatePyObject_cb(PyObject *cb_user,
unsigned char cb_type, unsigned char cb_subtype);
#endif /* __MATHUTILS_COLOR_H__ */

View File

@@ -349,21 +349,21 @@ static PyObject *Euler_richcmpr(PyObject *a, PyObject *b, int op)
}
switch (op) {
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
}
return Py_INCREF(res), res;
@@ -732,14 +732,15 @@ PyObject *Euler_CreatePyObject(float *eul, short order, int type, PyTypeObject *
return (PyObject *)self;
}
PyObject *Euler_CreatePyObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype)
PyObject *Euler_CreatePyObject_cb(PyObject *cb_user, short order,
unsigned char cb_type, unsigned char cb_subtype)
{
EulerObject *self = (EulerObject *)Euler_CreatePyObject(NULL, order, Py_NEW, NULL);
if (self) {
Py_INCREF(cb_user);
self->cb_user = cb_user;
self->cb_type = (unsigned char)cb_type;
self->cb_subtype = (unsigned char)cb_subtype;
self->cb_user = cb_user;
self->cb_type = cb_type;
self->cb_subtype = cb_subtype;
PyObject_GC_Track(self);
}

View File

@@ -50,8 +50,9 @@ typedef struct {
* blender (stored in blend_data). This is an either/or struct not both */
//prototypes
PyObject *Euler_CreatePyObject( float *eul, short order, int type, PyTypeObject *base_type);
PyObject *Euler_CreatePyObject_cb(PyObject *cb_user, short order, int cb_type, int cb_subtype);
PyObject *Euler_CreatePyObject(float *eul, short order, int type, PyTypeObject *base_type);
PyObject *Euler_CreatePyObject_cb(PyObject *cb_user, short order,
unsigned char cb_type, unsigned char cb_subtype);
short euler_order_from_string(const char *str, const char *error_prefix);

View File

@@ -78,7 +78,7 @@ static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col
* matrix row callbacks
* this is so you can do matrix[i][j] = val OR matrix.row[i][j] = val */
int mathutils_matrix_row_cb_index = -1;
unsigned char mathutils_matrix_row_cb_index = -1;
static int mathutils_matrix_row_check(BaseMathObject *bmo)
{
@@ -162,7 +162,7 @@ Mathutils_Callback mathutils_matrix_row_cb = {
* matrix row callbacks
* this is so you can do matrix.col[i][j] = val */
int mathutils_matrix_col_cb_index = -1;
unsigned char mathutils_matrix_col_cb_index = -1;
static int mathutils_matrix_col_check(BaseMathObject *bmo)
{
@@ -255,7 +255,7 @@ Mathutils_Callback mathutils_matrix_col_cb = {
* this is so you can do matrix.translation = val
* note, this is _exactly like matrix.col except the 4th component is always omitted */
int mathutils_matrix_translation_cb_index = -1;
unsigned char mathutils_matrix_translation_cb_index = -1;
static int mathutils_matrix_translation_check(BaseMathObject *bmo)
{
@@ -780,7 +780,7 @@ PyDoc_STRVAR(C_Matrix_Shear_doc,
" :arg size: The size of the shear matrix to construct [2, 4].\n"
" :type size: int\n"
" :arg factor: The factor of shear to apply. For a 3 or 4 *size* matrix\n"
" pass a pair of floats corrasponding with the *plane* axis.\n"
" pass a pair of floats corresponding with the *plane* axis.\n"
" :type factor: float or float pair\n"
" :return: A new shear matrix.\n"
" :rtype: :class:`Matrix`\n"
@@ -1601,28 +1601,28 @@ static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op)
if (BaseMath_ReadCallback(matA) == -1 || BaseMath_ReadCallback(matB) == -1)
return NULL;
ok = ( (matA->num_row == matB->num_row) &&
(matA->num_col == matB->num_col) &&
EXPP_VectorsAreEqual(matA->matrix, matB->matrix, (matA->num_col * matA->num_row), 1)
) ? 0 : -1;
ok = ((matA->num_row == matB->num_row) &&
(matA->num_col == matB->num_col) &&
EXPP_VectorsAreEqual(matA->matrix, matB->matrix, (matA->num_col * matA->num_row), 1)
) ? 0 : -1;
}
switch (op) {
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
}
return Py_INCREF(res), res;
@@ -1739,8 +1739,7 @@ static PyObject *Matrix_slice(MatrixObject *self, int begin, int end)
tuple = PyTuple_New(end - begin);
for (count = begin; count < end; count++) {
PyTuple_SET_ITEM(tuple, count - begin,
Vector_CreatePyObject_cb((PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, count));
Vector_CreatePyObject_cb((PyObject *)self, self->num_col, mathutils_matrix_row_cb_index, count));
}
return tuple;
@@ -1850,8 +1849,7 @@ static PyObject *Matrix_sub(PyObject *m1, PyObject *m2)
PyErr_Format(PyExc_TypeError,
"Matrix subtraction: (%s - %s) "
"invalid type for this operation",
Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name
);
Py_TYPE(m1)->tp_name, Py_TYPE(m2)->tp_name);
return NULL;
}
@@ -2400,14 +2398,14 @@ PyObject *Matrix_CreatePyObject(float *mat,
PyObject *Matrix_CreatePyObject_cb(PyObject *cb_user,
const unsigned short num_col, const unsigned short num_row,
int cb_type, int cb_subtype)
unsigned char cb_type, unsigned char cb_subtype)
{
MatrixObject *self = (MatrixObject *)Matrix_CreatePyObject(NULL, num_col, num_row, Py_NEW, NULL);
if (self) {
Py_INCREF(cb_user);
self->cb_user = cb_user;
self->cb_type = (unsigned char)cb_type;
self->cb_subtype = (unsigned char)cb_subtype;
self->cb_user = cb_user;
self->cb_type = cb_type;
self->cb_subtype = cb_subtype;
PyObject_GC_Track(self);
}
return (PyObject *) self;

View File

@@ -71,11 +71,11 @@ PyObject *Matrix_CreatePyObject(float *mat,
int type, PyTypeObject *base_type);
PyObject *Matrix_CreatePyObject_cb(PyObject *user,
const unsigned short num_col, const unsigned short num_row,
int cb_type, int cb_subtype);
unsigned char cb_type, unsigned char cb_subtype);
extern int mathutils_matrix_row_cb_index; /* default */
extern int mathutils_matrix_col_cb_index;
extern int mathutils_matrix_translation_cb_index;
extern unsigned char mathutils_matrix_row_cb_index; /* default */
extern unsigned char mathutils_matrix_col_cb_index;
extern unsigned char mathutils_matrix_translation_cb_index;
extern struct Mathutils_Callback mathutils_matrix_row_cb; /* default */
extern struct Mathutils_Callback mathutils_matrix_col_cb;

View File

@@ -527,21 +527,21 @@ static PyObject *Quaternion_richcmpr(PyObject *a, PyObject *b, int op)
}
switch (op) {
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_NE:
ok = !ok; /* pass through */
case Py_EQ:
res = ok ? Py_False : Py_True;
break;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
case Py_LT:
case Py_LE:
case Py_GT:
case Py_GE:
res = Py_NotImplemented;
break;
default:
PyErr_BadArgument();
return NULL;
}
return Py_INCREF(res), res;
@@ -558,7 +558,7 @@ static int Quaternion_len(QuaternionObject *UNUSED(self))
//sequence accessor (get)
static PyObject *Quaternion_item(QuaternionObject *self, int i)
{
if (i < 0) i = QUAT_SIZE-i;
if (i < 0) i = QUAT_SIZE - i;
if (i < 0 || i >= QUAT_SIZE) {
PyErr_SetString(PyExc_IndexError,
@@ -585,7 +585,7 @@ static int Quaternion_ass_item(QuaternionObject *self, int i, PyObject *ob)
return -1;
}
if (i < 0) i = QUAT_SIZE-i;
if (i < 0) i = QUAT_SIZE - i;
if (i < 0 || i >= QUAT_SIZE) {
PyErr_SetString(PyExc_IndexError,
@@ -805,12 +805,12 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2)
return NULL;
}
if (quat1 && quat2) { /* QUAT*QUAT (cross product) */
if (quat1 && quat2) { /* QUAT * QUAT (cross product) */
mul_qt_qtqt(quat, quat1->quat, quat2->quat);
return Quaternion_CreatePyObject(quat, Py_NEW, Py_TYPE(q1));
}
/* the only case this can happen (for a supported type is "FLOAT*QUAT") */
else if (quat2) { /* FLOAT*QUAT */
/* the only case this can happen (for a supported type is "FLOAT * QUAT") */
else if (quat2) { /* FLOAT * QUAT */
if (((scalar = PyFloat_AsDouble(q1)) == -1.0f && PyErr_Occurred()) == 0) {
return quat_mul_float(quat2, scalar);
}
@@ -1101,21 +1101,22 @@ static PyObject *quat__apply_to_copy(PyNoArgsFunction quat_func, QuaternionObjec
}
}
/* axis vector suffers from precission errors, use this function to ensure */
/* axis vector suffers from precision errors, use this function to ensure */
static void quat__axis_angle_sanitize(float axis[3], float *angle)
{
if (axis) {
if ( !finite(axis[0]) ||
!finite(axis[1]) ||
!finite(axis[2]))
if (is_zero_v3(axis) ||
!finite(axis[0]) ||
!finite(axis[1]) ||
!finite(axis[2]))
{
axis[0] = 1.0f;
axis[1] = 0.0f;
axis[2] = 0.0f;
}
else if ( EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
EXPP_FloatsAreEqual(axis[1], 0.0f, 10) &&
EXPP_FloatsAreEqual(axis[2], 0.0f, 10))
else if (EXPP_FloatsAreEqual(axis[0], 0.0f, 10) &&
EXPP_FloatsAreEqual(axis[1], 0.0f, 10) &&
EXPP_FloatsAreEqual(axis[2], 0.0f, 10))
{
axis[0] = 1.0f;
}
@@ -1268,14 +1269,15 @@ PyObject *Quaternion_CreatePyObject(float *quat, int type, PyTypeObject *base_ty
return (PyObject *) self;
}
PyObject *Quaternion_CreatePyObject_cb(PyObject *cb_user, int cb_type, int cb_subtype)
PyObject *Quaternion_CreatePyObject_cb(PyObject *cb_user,
unsigned char cb_type, unsigned char cb_subtype)
{
QuaternionObject *self = (QuaternionObject *)Quaternion_CreatePyObject(NULL, Py_NEW, NULL);
if (self) {
Py_INCREF(cb_user);
self->cb_user = cb_user;
self->cb_type = (unsigned char)cb_type;
self->cb_subtype = (unsigned char)cb_subtype;
self->cb_user = cb_user;
self->cb_type = cb_type;
self->cb_subtype = cb_subtype;
PyObject_GC_Track(self);
}

View File

@@ -48,7 +48,8 @@ typedef struct {
* blender (stored in blend_data). This is an either/or struct not both */
//prototypes
PyObject *Quaternion_CreatePyObject( float *quat, int type, PyTypeObject *base_type);
PyObject *Quaternion_CreatePyObject_cb(PyObject *cb_user, int cb_type, int cb_subtype);
PyObject *Quaternion_CreatePyObject(float *quat, int type, PyTypeObject *base_type);
PyObject *Quaternion_CreatePyObject_cb(PyObject *cb_user,
unsigned char cb_type, unsigned char cb_subtype);
#endif /* __MATHUTILS_QUATERNION_H__ */

View File

@@ -247,7 +247,7 @@ static PyObject *C_Vector_Linspace(PyObject *cls, PyObject *args)
return NULL;
}
step = (end - start)/(float)(size-1);
step = (end - start) / (float)(size - 1);
vec = PyMem_Malloc(size * sizeof(float));
@@ -734,19 +734,19 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args)
}
else if (strlen(strack) == 1) {
switch (strack[0]) {
case '-':
case 'X':
track = 0;
break;
case 'Y':
track = 1;
break;
case 'Z':
track = 2;
break;
default:
PyErr_SetString(PyExc_ValueError, axis_err_msg);
return NULL;
case '-':
case 'X':
track = 0;
break;
case 'Y':
track = 1;
break;
case 'Z':
track = 2;
break;
default:
PyErr_SetString(PyExc_ValueError, axis_err_msg);
return NULL;
}
}
else {
@@ -759,18 +759,18 @@ static PyObject *Vector_to_track_quat(VectorObject *self, PyObject *args)
const char *axis_err_msg = "only X, Y or Z for up axis";
if (strlen(sup) == 1) {
switch (*sup) {
case 'X':
up = 0;
break;
case 'Y':
up = 1;
break;
case 'Z':
up = 2;
break;
default:
PyErr_SetString(PyExc_ValueError, axis_err_msg);
return NULL;
case 'X':
up = 0;
break;
case 'Y':
up = 1;
break;
case 'Z':
up = 2;
break;
default:
PyErr_SetString(PyExc_ValueError, axis_err_msg);
return NULL;
}
}
else {
@@ -920,7 +920,7 @@ PyDoc_STRVAR(Vector_angle_doc,
" :return: angle in radians or fallback when given\n"
" :rtype: float\n"
"\n"
" .. note:: Zero length vectors raise an :exc:`AttributeError`.\n"
" .. note:: Zero length vectors raise an :exc:`ValueError`.\n"
);
static PyObject *Vector_angle(VectorObject *self, PyObject *args)
{
@@ -971,6 +971,62 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args)
return PyFloat_FromDouble(saacos(dot / (sqrt(dot_self) * sqrt(dot_other))));
}
PyDoc_STRVAR(Vector_angle_signed_doc,
".. function:: angle_signed(other, fallback)\n"
"\n"
" Return the signed angle between two 2D vectors (clockwise is positive).\n"
"\n"
" :arg other: another vector to compare the angle with\n"
" :type other: :class:`Vector`\n"
" :arg fallback: return this value when the angle cant be calculated\n"
" (zero length vector)\n"
" :type fallback: any\n"
" :return: angle in radians or fallback when given\n"
" :rtype: float\n"
"\n"
" .. note:: Zero length vectors raise an :exc:`ValueError`.\n"
);
static PyObject *Vector_angle_signed(VectorObject *self, PyObject *args)
{
float tvec[2];
PyObject *value;
PyObject *fallback = NULL;
if (!PyArg_ParseTuple(args, "O|O:angle_signed", &value, &fallback))
return NULL;
if (BaseMath_ReadCallback(self) == -1)
return NULL;
if (mathutils_array_parse(tvec, 2, 2, value, "Vector.angle_signed(other), invalid 'other' arg") == -1)
return NULL;
if (self->size != 2) {
PyErr_SetString(PyExc_ValueError,
"Vector must be 2D");
return NULL;
}
if (is_zero_v2(self->vec) || is_zero_v2(tvec)) {
/* avoid exception */
if (fallback) {
Py_INCREF(fallback);
return fallback;
}
else {
PyErr_SetString(PyExc_ValueError,
"Vector.angle_signed(other): "
"zero length vectors have no valid angle");
return NULL;
}
}
return PyFloat_FromDouble(angle_signed_v2v2(self->vec, tvec));
}
PyDoc_STRVAR(Vector_rotation_difference_doc,
".. function:: rotation_difference(other)\n"
"\n"
@@ -1203,10 +1259,10 @@ static int Vector_len(VectorObject *self)
/* sequence accessor (get): vector[index] */
static PyObject *vector_item_internal(VectorObject *self, int i, const int is_attr)
{
if (i < 0) i = self->size-i;
if (i < 0) i = self->size - i;
if (i < 0 || i >= self->size) {
if (is_attr) {
if (is_attr) {
PyErr_Format(PyExc_AttributeError,
"Vector.%c: unavailable on %dd vector",
*(((char *)"xyzw") + i), self->size);
@@ -1239,7 +1295,7 @@ static int vector_ass_item_internal(VectorObject *self, int i, PyObject *value,
return -1;
}
if (i < 0) i = self->size-i;
if (i < 0) i = self->size - i;
if (i < 0 || i >= self->size) {
if (is_attr) {
@@ -2190,9 +2246,9 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure
size_from = axis_from;
}
else if ( (PyErr_Clear()), /* run but ignore the result */
(size_from = mathutils_array_parse(vec_assign, 2, 4, value,
"mathutils.Vector.**** = swizzle assignment")) == -1)
else if ((PyErr_Clear()), /* run but ignore the result */
(size_from = mathutils_array_parse(vec_assign, 2, 4, value,
"mathutils.Vector.**** = swizzle assignment")) == -1)
{
return -1;
}
@@ -2595,11 +2651,11 @@ while len(axises) >= 2:
if len(axises)>2:
for axis_2 in axises:
axis_2_pos = axis_pos[axis_2]
axis_dict[axis_0 + axis_1 + axis_2] = '((%s|SWIZZLE_VALID_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<<(SWIZZLE_BITS_PER_AXIS*2)))' % (axis_0_pos, axis_1_pos, axis_2_pos)
axis_dict[axis_0 + axis_1 + axis_2] = '((%s|SWIZZLE_VALID_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<<(SWIZZLE_BITS_PER_AXIS * 2)))' % (axis_0_pos, axis_1_pos, axis_2_pos)
if len(axises)>3:
for axis_3 in axises:
axis_3_pos = axis_pos[axis_3]
axis_dict[axis_0 + axis_1 + axis_2 + axis_3] = '((%s|SWIZZLE_VALID_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<<(SWIZZLE_BITS_PER_AXIS*2)) | ((%s|SWIZZLE_VALID_AXIS)<<(SWIZZLE_BITS_PER_AXIS*3))) ' % (axis_0_pos, axis_1_pos, axis_2_pos, axis_3_pos)
axis_dict[axis_0 + axis_1 + axis_2 + axis_3] = '((%s|SWIZZLE_VALID_AXIS) | ((%s|SWIZZLE_VALID_AXIS)<<SWIZZLE_BITS_PER_AXIS) | ((%s|SWIZZLE_VALID_AXIS) << (SWIZZLE_BITS_PER_AXIS * 2)) | ((%s|SWIZZLE_VALID_AXIS)<<(SWIZZLE_BITS_PER_AXIS * 3))) ' % (axis_0_pos, axis_1_pos, axis_2_pos, axis_3_pos)
axises = axises[:-1]
@@ -2611,7 +2667,7 @@ unique = set()
for key, val in items:
num = eval(val)
set_str = 'Vector_setSwizzle' if (len(set(key)) == len(key)) else 'NULL'
print '\t{"%s", %s(getter)Vector_getSwizzle, (setter)%s, NULL, SET_INT_IN_POINTER(%s)}, // %s' % (key, (' '*(4-len(key))), set_str, axis_dict[key], num)
print '\t{"%s", %s(getter)Vector_getSwizzle, (setter)%s, NULL, SET_INT_IN_POINTER(%s)}, // %s' % (key, (' '*(4 - len(key))), set_str, axis_dict[key], num)
unique.add(num)
if len(unique) != len(items):
@@ -2705,6 +2761,7 @@ static struct PyMethodDef Vector_methods[] = {
{"cross", (PyCFunction) Vector_cross, METH_O, Vector_cross_doc},
{"dot", (PyCFunction) Vector_dot, METH_O, Vector_dot_doc},
{"angle", (PyCFunction) Vector_angle, METH_VARARGS, Vector_angle_doc},
{"angle_signed", (PyCFunction) Vector_angle_signed, METH_VARARGS, Vector_angle_signed_doc},
{"rotation_difference", (PyCFunction) Vector_rotation_difference, METH_O, Vector_rotation_difference_doc},
{"project", (PyCFunction) Vector_project, METH_O, Vector_project_doc},
{"lerp", (PyCFunction) Vector_lerp, METH_VARARGS, Vector_lerp_doc},
@@ -2856,15 +2913,15 @@ PyObject *Vector_CreatePyObject(float *vec, const int size, const int type, PyTy
return (PyObject *) self;
}
PyObject *Vector_CreatePyObject_cb(PyObject *cb_user, int size, int cb_type, int cb_subtype)
PyObject *Vector_CreatePyObject_cb(PyObject *cb_user, int size, unsigned char cb_type, unsigned char cb_subtype)
{
float dummy[4] = {0.0, 0.0, 0.0, 0.0}; /* dummy init vector, callbacks will be used on access */
VectorObject *self = (VectorObject *)Vector_CreatePyObject(dummy, size, Py_NEW, NULL);
if (self) {
Py_INCREF(cb_user);
self->cb_user = cb_user;
self->cb_type = (unsigned char)cb_type;
self->cb_subtype = (unsigned char)cb_subtype;
self->cb_user = cb_user;
self->cb_type = cb_type;
self->cb_subtype = cb_subtype;
PyObject_GC_Track(self);
}

View File

@@ -46,7 +46,8 @@ typedef struct {
/*prototypes*/
PyObject *Vector_CreatePyObject(float *vec, const int size, const int type, PyTypeObject *base_type);
PyObject *Vector_CreatePyObject_cb(PyObject *user, int size, int callback_type, int subtype);
PyObject *Vector_CreatePyObject_cb(PyObject *user, int size,
unsigned char cb_type, unsigned char subtype);
PyObject *Vector_CreatePyObject_alloc(float *vec, const int size, PyTypeObject *base_type);
#endif /* __MATHUTILS_VECTOR_H__ */

View File

@@ -99,11 +99,11 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject *
return NULL;
}
if ( BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1 ||
BaseMath_ReadCallback(ray) == -1 ||
BaseMath_ReadCallback(ray_off) == -1)
if (BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1 ||
BaseMath_ReadCallback(ray) == -1 ||
BaseMath_ReadCallback(ray_off) == -1)
{
return NULL;
}
@@ -199,10 +199,10 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject
return NULL;
}
if ( BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1 ||
BaseMath_ReadCallback(vec4) == -1)
if (BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1 ||
BaseMath_ReadCallback(vec4) == -1)
{
return NULL;
}
@@ -298,9 +298,9 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject *args)
return NULL;
}
if ( BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1)
if (BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1)
{
return NULL;
}
@@ -327,10 +327,10 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject *args)
return NULL;
}
if ( BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1 ||
BaseMath_ReadCallback(vec4) == -1)
if (BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1 ||
BaseMath_ReadCallback(vec4) == -1)
{
return NULL;
}
@@ -374,9 +374,9 @@ static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject *args)
return NULL;
}
if ( BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1)
if (BaseMath_ReadCallback(vec1) == -1 ||
BaseMath_ReadCallback(vec2) == -1 ||
BaseMath_ReadCallback(vec3) == -1)
{
return NULL;
}
@@ -424,10 +424,10 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj
return NULL;
}
if ( BaseMath_ReadCallback(line_a1) == -1 ||
BaseMath_ReadCallback(line_a2) == -1 ||
BaseMath_ReadCallback(line_b1) == -1 ||
BaseMath_ReadCallback(line_b2) == -1)
if (BaseMath_ReadCallback(line_a1) == -1 ||
BaseMath_ReadCallback(line_a2) == -1 ||
BaseMath_ReadCallback(line_b1) == -1 ||
BaseMath_ReadCallback(line_b2) == -1)
{
return NULL;
}
@@ -474,10 +474,10 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec
return NULL;
}
if ( BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(plane_co) == -1 ||
BaseMath_ReadCallback(plane_no) == -1)
if (BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(plane_co) == -1 ||
BaseMath_ReadCallback(plane_no) == -1)
{
return NULL;
}
@@ -530,10 +530,10 @@ static PyObject *M_Geometry_intersect_plane_plane(PyObject *UNUSED(self), PyObje
return NULL;
}
if ( BaseMath_ReadCallback(plane_a_co) == -1 ||
BaseMath_ReadCallback(plane_a_no) == -1 ||
BaseMath_ReadCallback(plane_b_co) == -1 ||
BaseMath_ReadCallback(plane_b_no) == -1)
if (BaseMath_ReadCallback(plane_a_co) == -1 ||
BaseMath_ReadCallback(plane_a_no) == -1 ||
BaseMath_ReadCallback(plane_b_co) == -1 ||
BaseMath_ReadCallback(plane_b_no) == -1)
{
return NULL;
}
@@ -592,9 +592,9 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje
return NULL;
}
if ( BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(sphere_co) == -1)
if (BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(sphere_co) == -1)
{
return NULL;
}
@@ -613,17 +613,17 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje
PyObject *ret = PyTuple_New(2);
switch (isect_line_sphere_v3(line_a->vec, line_b->vec, sphere_co->vec, sphere_radius, isect_a, isect_b)) {
case 1:
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
use_b = FALSE;
break;
case 2:
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b = FALSE;
break;
default:
use_a = FALSE;
use_b = FALSE;
case 1:
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
use_b = FALSE;
break;
case 2:
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b = FALSE;
break;
default:
use_a = FALSE;
use_b = FALSE;
}
if (use_a) { PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(isect_a, 3, Py_NEW, NULL)); }
@@ -672,9 +672,9 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO
return NULL;
}
if ( BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(sphere_co) == -1)
if (BaseMath_ReadCallback(line_a) == -1 ||
BaseMath_ReadCallback(line_b) == -1 ||
BaseMath_ReadCallback(sphere_co) == -1)
{
return NULL;
}
@@ -686,17 +686,17 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO
PyObject *ret = PyTuple_New(2);
switch (isect_line_sphere_v2(line_a->vec, line_b->vec, sphere_co->vec, sphere_radius, isect_a, isect_b)) {
case 1:
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
use_b = FALSE;
break;
case 2:
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b = FALSE;
break;
default:
use_a = FALSE;
use_b = FALSE;
case 1:
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
use_b = FALSE;
break;
case 2:
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_a = FALSE;
if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a->vec, line_b->vec)) >= 0.0f) && (lambda <= 1.0f)))) use_b = FALSE;
break;
default:
use_a = FALSE;
use_b = FALSE;
}
if (use_a) { PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(isect_a, 2, Py_NEW, NULL)); }
@@ -737,9 +737,9 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec
return NULL;
}
if ( BaseMath_ReadCallback(pt) == -1 ||
BaseMath_ReadCallback(line_1) == -1 ||
BaseMath_ReadCallback(line_2) == -1)
if (BaseMath_ReadCallback(pt) == -1 ||
BaseMath_ReadCallback(line_1) == -1 ||
BaseMath_ReadCallback(line_2) == -1)
{
return NULL;
}
@@ -791,10 +791,10 @@ static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObj
return NULL;
}
if ( BaseMath_ReadCallback(pt_vec) == -1 ||
BaseMath_ReadCallback(tri_p1) == -1 ||
BaseMath_ReadCallback(tri_p2) == -1 ||
BaseMath_ReadCallback(tri_p3) == -1)
if (BaseMath_ReadCallback(pt_vec) == -1 ||
BaseMath_ReadCallback(tri_p1) == -1 ||
BaseMath_ReadCallback(tri_p2) == -1 ||
BaseMath_ReadCallback(tri_p3) == -1)
{
return NULL;
}
@@ -834,11 +834,11 @@ static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyOb
return NULL;
}
if ( BaseMath_ReadCallback(pt_vec) == -1 ||
BaseMath_ReadCallback(quad_p1) == -1 ||
BaseMath_ReadCallback(quad_p2) == -1 ||
BaseMath_ReadCallback(quad_p3) == -1 ||
BaseMath_ReadCallback(quad_p4) == -1)
if (BaseMath_ReadCallback(pt_vec) == -1 ||
BaseMath_ReadCallback(quad_p1) == -1 ||
BaseMath_ReadCallback(quad_p2) == -1 ||
BaseMath_ReadCallback(quad_p3) == -1 ||
BaseMath_ReadCallback(quad_p4) == -1)
{
return NULL;
}
@@ -872,9 +872,9 @@ static PyObject *M_Geometry_distance_point_to_plane(PyObject *UNUSED(self), PyOb
return NULL;
}
if ( BaseMath_ReadCallback(pt) == -1 ||
BaseMath_ReadCallback(plene_co) == -1 ||
BaseMath_ReadCallback(plane_no) == -1)
if (BaseMath_ReadCallback(pt) == -1 ||
BaseMath_ReadCallback(plene_co) == -1 ||
BaseMath_ReadCallback(plane_no) == -1)
{
return NULL;
}
@@ -923,13 +923,13 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje
return NULL;
}
if ( vec_pt->size != 3 ||
vec_t1_src->size != 3 ||
vec_t2_src->size != 3 ||
vec_t3_src->size != 3 ||
vec_t1_tar->size != 3 ||
vec_t2_tar->size != 3 ||
vec_t3_tar->size != 3)
if (vec_pt->size != 3 ||
vec_t1_src->size != 3 ||
vec_t2_src->size != 3 ||
vec_t3_src->size != 3 ||
vec_t1_tar->size != 3 ||
vec_t2_tar->size != 3 ||
vec_t3_tar->size != 3)
{
PyErr_SetString(PyExc_ValueError,
"One of more of the vector arguments wasn't a 3D vector");
@@ -993,10 +993,10 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject
return NULL;
}
if ( BaseMath_ReadCallback(vec_k1) == -1 ||
BaseMath_ReadCallback(vec_h1) == -1 ||
BaseMath_ReadCallback(vec_k2) == -1 ||
BaseMath_ReadCallback(vec_h2) == -1)
if (BaseMath_ReadCallback(vec_k1) == -1 ||
BaseMath_ReadCallback(vec_h1) == -1 ||
BaseMath_ReadCallback(vec_k2) == -1 ||
BaseMath_ReadCallback(vec_h2) == -1)
{
return NULL;
}
@@ -1023,8 +1023,8 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject
}
PyDoc_STRVAR(M_Geometry_tesselate_polygon_doc,
".. function:: tesselate_polygon(veclist_list)\n"
PyDoc_STRVAR(M_Geometry_tessellate_polygon_doc,
".. function:: tessellate_polygon(veclist_list)\n"
"\n"
" Takes a list of polylines (each point a vector) and returns the point indices for a polyline filled with triangles.\n"
"\n"
@@ -1032,7 +1032,7 @@ PyDoc_STRVAR(M_Geometry_tesselate_polygon_doc,
" :rtype: list\n"
);
/* PolyFill function, uses Blenders scanfill to fill multiple poly lines */
static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *polyLineSeq)
static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(self), PyObject *polyLineSeq)
{
PyObject *tri_list; /*return this list of tri's */
PyObject *polyLine, *polyVec;
@@ -1063,7 +1063,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
}
len_polypoints = PySequence_Size(polyLine);
if (len_polypoints > 0) { /* dont bother adding edges as polylines */
if (len_polypoints > 0) { /* don't bother adding edges as polylines */
#if 0
if (EXPP_check_sequence_consistency(polyLine, &vector_Type) != 1) {
freedisplist(&dispbase);
@@ -1141,7 +1141,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject *
freedisplist(&dispbase);
}
else {
/* no points, do this so scripts dont barf */
/* no points, do this so scripts don't barf */
freedisplist(&dispbase); /* possible some dl was allocated */
tri_list = PyList_New(0);
}
@@ -1280,7 +1280,7 @@ static PyMethodDef M_Geometry_methods[] = {
{"barycentric_transform", (PyCFunction) M_Geometry_barycentric_transform, METH_VARARGS, M_Geometry_barycentric_transform_doc},
#ifndef MATH_STANDALONE
{"interpolate_bezier", (PyCFunction) M_Geometry_interpolate_bezier, METH_VARARGS, M_Geometry_interpolate_bezier_doc},
{"tesselate_polygon", (PyCFunction) M_Geometry_tesselate_polygon, METH_O, M_Geometry_tesselate_polygon_doc},
{"tessellate_polygon", (PyCFunction) M_Geometry_tessellate_polygon, METH_O, M_Geometry_tessellate_polygon_doc},
{"box_pack_2d", (PyCFunction) M_Geometry_box_pack_2d, METH_O, M_Geometry_box_pack_2d_doc},
#endif
{NULL, NULL, 0, NULL}

View File

@@ -199,7 +199,7 @@ static float frand(void)
/* Fills an array of length size with random numbers in the range (-1, 1)*/
static void rand_vn(float *array_tar, const int size)
{
float *array_pt = array_tar + (size-1);
float *array_pt = array_tar + (size - 1);
int i = size;
while (i--) { *(array_pt--) = 2.0f * frand() - 1.0f; }
}
@@ -335,7 +335,7 @@ PyDoc_STRVAR(M_Noise_random_vector_doc,
static PyObject *M_Noise_random_vector(PyObject *UNUSED(self), PyObject *args)
{
float vec[4]= {0.0f, 0.0f, 0.0f, 0.0f};
int size= 3;
int size = 3;
if (!PyArg_ParseTuple(args, "|i:random_vector", &size))
return NULL;
@@ -484,7 +484,7 @@ static PyObject *M_Noise_turbulence_vector(PyObject *UNUSED(self), PyObject *arg
PyObject *value;
float vec[3], r_vec[3];
int oct, hd, nb = 1;
float as =0.5f, fs = 2.0f;
float as = 0.5f, fs = 2.0f;
if (!PyArg_ParseTuple(args, "Oii|iff:turbulence_vector", &value, &oct, &hd, &nb, &as, &fs))
return NULL;

View File

@@ -40,7 +40,7 @@ defs = """
"""
print '\tmod = PyModule_New("dummy");'
print '\tPyModule_AddObject( submodule, "key", mod );'
print '\tPyModule_AddObject(submodule, "key", mod);'
for d in defs.split('\n'):
@@ -58,7 +58,7 @@ for d in defs.split('\n'):
val = w[0]
py_val = w[0]
print '\tPyModule_AddObject( mod, "%s", PyLong_FromSize_t(%s) );' % (val, py_val)
print '\tPyModule_AddObject(mod, "%s", PyLong_FromSize_t(%s));' % (val, py_val)