Merged changes in the trunk up to revision 52690.
Conflicts resolved: release/datafiles/startup.blend source/blender/blenlib/intern/bpath.c
This commit is contained in:
@@ -34,6 +34,7 @@ set(INC_SYS
|
||||
set(SRC
|
||||
bmesh_py_api.c
|
||||
bmesh_py_ops.c
|
||||
bmesh_py_ops_call.c
|
||||
bmesh_py_types.c
|
||||
bmesh_py_types_customdata.c
|
||||
bmesh_py_types_meshdata.c
|
||||
@@ -42,6 +43,7 @@ set(SRC
|
||||
|
||||
bmesh_py_api.h
|
||||
bmesh_py_ops.h
|
||||
bmesh_py_ops_call.h
|
||||
bmesh_py_types.h
|
||||
bmesh_py_types_customdata.h
|
||||
bmesh_py_types_meshdata.h
|
||||
|
||||
@@ -51,7 +51,6 @@
|
||||
|
||||
#include "bmesh_py_api.h" /* own include */
|
||||
|
||||
|
||||
PyDoc_STRVAR(bpy_bm_new_doc,
|
||||
".. method:: new()\n"
|
||||
"\n"
|
||||
@@ -73,6 +72,8 @@ PyDoc_STRVAR(bpy_bm_from_edit_mesh_doc,
|
||||
"\n"
|
||||
" Return a BMesh from this mesh, currently the mesh must already be in editmode.\n"
|
||||
"\n"
|
||||
" :arg mesh: The editmode mesh.\n"
|
||||
" :type mesh: :class:`bpy.types.Mesh`\n"
|
||||
" :return: the BMesh associated with this mesh.\n"
|
||||
" :rtype: :class:`bmesh.types.BMesh`\n"
|
||||
);
|
||||
@@ -96,9 +97,56 @@ static PyObject *bpy_bm_from_edit_mesh(PyObject *UNUSED(self), PyObject *value)
|
||||
return BPy_BMesh_CreatePyObject(bm, BPY_BMFLAG_IS_WRAPPED);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(bpy_bm_update_edit_mesh_doc,
|
||||
".. method:: update_edit_mesh(mesh, tessface=True)\n"
|
||||
"\n"
|
||||
" Update the mesh after changes to the BMesh in editmode, \n"
|
||||
" optionally recalculating n-gon tessellation.\n"
|
||||
"\n"
|
||||
" :arg mesh: The editmode mesh.\n"
|
||||
" :type mesh: :class:`bpy.types.Mesh`\n"
|
||||
" :arg tessface: Option to recalculate n-gon tessellation.\n"
|
||||
" :type tessface: boolean\n"
|
||||
);
|
||||
static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
PyObject *py_me;
|
||||
Mesh *me;
|
||||
int do_tessface = TRUE;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O|i:update_edit_mesh", &py_me, &do_tessface)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
me = PyC_RNA_AsPointer(py_me, "Mesh");
|
||||
|
||||
if (me == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (me->edit_btmesh == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"The mesh must be in editmode");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
{
|
||||
/* XXX, not great - infact this function could just not use the context at all
|
||||
* postpone that change until after release: BMESH_TODO - campbell */
|
||||
extern struct bContext *BPy_GetContext(void);
|
||||
extern void EDBM_update_generic(struct bContext *C, BMEditMesh *em, const short do_tessface);
|
||||
|
||||
struct bContext *C = BPy_GetContext();
|
||||
EDBM_update_generic(C, me->edit_btmesh, do_tessface);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static struct PyMethodDef BPy_BM_methods[] = {
|
||||
{"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},
|
||||
{"update_edit_mesh", (PyCFunction)bpy_bm_update_edit_mesh, METH_VARARGS, bpy_bm_update_edit_mesh_doc},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -38,39 +38,19 @@
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
#include "../mathutils/mathutils.h"
|
||||
|
||||
#include "bmesh.h"
|
||||
|
||||
#include "bmesh_py_ops_call.h"
|
||||
#include "bmesh_py_ops.h" /* own include */
|
||||
|
||||
#include "bmesh_py_types.h"
|
||||
|
||||
#include "bmesh_py_utils.h" /* own include */
|
||||
|
||||
static int bpy_bm_op_as_py_error(BMesh *bm)
|
||||
{
|
||||
if (BMO_error_occurred(bm)) {
|
||||
const char *errmsg;
|
||||
if (BMO_error_get(bm, &errmsg, NULL)) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"bmesh operator: %.200s",
|
||||
errmsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#include "bmesh_py_utils.h"
|
||||
|
||||
/* bmesh operator 'bmesh.ops.*' callable types
|
||||
* ******************************************* */
|
||||
PyTypeObject bmesh_op_Type;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
const char *opname;
|
||||
} BPy_BMeshOpFunc;
|
||||
|
||||
static PyObject *bpy_bmesh_op_CreatePyObject(const char *opname)
|
||||
{
|
||||
BPy_BMeshOpFunc *self = PyObject_New(BPy_BMeshOpFunc, &bmesh_op_Type);
|
||||
@@ -88,335 +68,6 @@ static PyObject *bpy_bmesh_op_repr(BPy_BMeshOpFunc *self)
|
||||
}
|
||||
|
||||
|
||||
static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
PyObject *ret;
|
||||
BPy_BMesh *py_bm;
|
||||
BMesh *bm;
|
||||
|
||||
BMOperator bmop;
|
||||
|
||||
if ((PyTuple_GET_SIZE(args) == 1) &&
|
||||
(py_bm = (BPy_BMesh *)PyTuple_GET_ITEM(args, 0)) &&
|
||||
(BPy_BMesh_Check(py_bm))
|
||||
)
|
||||
{
|
||||
BPY_BM_CHECK_OBJ(py_bm);
|
||||
bm = py_bm->bm;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"calling a bmesh operator expects a single BMesh (non keyword) "
|
||||
"as the first argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO - error check this!, though we do the error check on attribute access */
|
||||
/* TODO - make flags optional */
|
||||
BMO_op_init(bm, &bmop, BMO_FLAG_DEFAULTS, self->opname);
|
||||
|
||||
if (kw && PyDict_Size(kw) > 0) {
|
||||
/* setup properties, see bpy_rna.c: pyrna_py_to_prop()
|
||||
* which shares this logic for parsing properties */
|
||||
|
||||
PyObject *key, *value;
|
||||
Py_ssize_t pos = 0;
|
||||
while (PyDict_Next(kw, &pos, &key, &value)) {
|
||||
const char *slot_name = _PyUnicode_AsString(key);
|
||||
BMOpSlot *slot = BMO_slot_get(bmop.slots_in, slot_name);
|
||||
|
||||
if (slot == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" is invalid for this operator",
|
||||
self->opname, slot_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* now assign the value */
|
||||
switch (slot->slot_type) {
|
||||
case BMO_OP_SLOT_BOOL:
|
||||
{
|
||||
int param;
|
||||
|
||||
param = PyLong_AsLong(value);
|
||||
|
||||
if (param < 0) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected True/False or 0/1, not %.200s",
|
||||
self->opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
BMO_SLOT_AS_BOOL(slot) = param;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_INT:
|
||||
{
|
||||
int overflow;
|
||||
long param = PyLong_AsLongAndOverflow(value, &overflow);
|
||||
if (overflow || (param > INT_MAX) || (param < INT_MIN)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: keyword \"%.200s\" value not in 'int' range "
|
||||
"(" STRINGIFY(INT_MIN) ", " STRINGIFY(INT_MAX) ")",
|
||||
self->opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
else if (param == -1 && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected an int, not %.200s",
|
||||
self->opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
BMO_SLOT_AS_INT(slot) = (int)param;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_FLT:
|
||||
{
|
||||
float param = PyFloat_AsDouble(value);
|
||||
if (param == -1 && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected a float, not %.200s",
|
||||
self->opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
BMO_SLOT_AS_FLOAT(slot) = param;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_MAT:
|
||||
{
|
||||
/* XXX - BMesh operator design is crappy here, operator slot should define matrix size,
|
||||
* not the caller! */
|
||||
unsigned short size;
|
||||
if (!MatrixObject_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected a Matrix, not %.200s",
|
||||
self->opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
else if (BaseMath_ReadCallback((MatrixObject *)value) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
else if (((size = ((MatrixObject *)value)->num_col) != ((MatrixObject *)value)->num_row) ||
|
||||
(ELEM(size, 3, 4) == FALSE))
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix Matrix",
|
||||
self->opname, slot_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMO_slot_mat_set(&bmop, bmop.slots_in, slot_name, ((MatrixObject *)value)->matrix, size);
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_VEC:
|
||||
{
|
||||
/* passing slot name here is a bit non-descriptive */
|
||||
if (mathutils_array_parse(BMO_SLOT_AS_VECTOR(slot), 3, 3, value, slot_name) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_ELEMENT_BUF:
|
||||
{
|
||||
/* there are many ways we could interpret arguments, for now...
|
||||
* - verts/edges/faces from the mesh direct,
|
||||
* this way the operator takes every item.
|
||||
* - `TODO` a plain python sequence (list) of elements.
|
||||
* - `TODO` an iterator. eg.
|
||||
* face.verts
|
||||
* - `TODO` (type, flag) pair, eg.
|
||||
* ('VERT', {'TAG'})
|
||||
*/
|
||||
|
||||
#define BPY_BM_GENERIC_MESH_TEST(type_string) \
|
||||
if (((BPy_BMGeneric *)value)->bm != bm) { \
|
||||
PyErr_Format(PyExc_NotImplementedError, \
|
||||
"%.200s: keyword \"%.200s\" " type_string " are from another bmesh", \
|
||||
self->opname, slot_name, slot->slot_type); \
|
||||
return NULL; \
|
||||
} (void)0
|
||||
|
||||
if (BPy_BMVertSeq_Check(value)) {
|
||||
BPY_BM_GENERIC_MESH_TEST("verts");
|
||||
BMO_slot_buffer_from_all(bm, &bmop, bmop.slots_in, slot_name, BM_VERT);
|
||||
}
|
||||
else if (BPy_BMEdgeSeq_Check(value)) {
|
||||
BPY_BM_GENERIC_MESH_TEST("edges");
|
||||
BMO_slot_buffer_from_all(bm, &bmop, bmop.slots_in, slot_name, BM_EDGE);
|
||||
}
|
||||
else if (BPy_BMFaceSeq_Check(value)) {
|
||||
BPY_BM_GENERIC_MESH_TEST("faces");
|
||||
BMO_slot_buffer_from_all(bm, &bmop, bmop.slots_in, slot_name, BM_FACE);
|
||||
}
|
||||
else if (BPy_BMElemSeq_Check(value)) {
|
||||
BMIter iter;
|
||||
BMHeader *ele;
|
||||
int tot;
|
||||
unsigned int i;
|
||||
|
||||
BPY_BM_GENERIC_MESH_TEST("elements");
|
||||
|
||||
/* this will loop over all elements which is a shame but
|
||||
* we need to know this before alloc */
|
||||
/* calls bpy_bmelemseq_length() */
|
||||
tot = Py_TYPE(value)->tp_as_sequence->sq_length((PyObject *)self);
|
||||
|
||||
BMO_slot_buffer_alloc(&bmop, bmop.slots_in, slot_name, tot);
|
||||
|
||||
i = 0;
|
||||
BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) {
|
||||
slot->data.buf[i] = ele;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/* keep this last */
|
||||
else if (PySequence_Check(value)) {
|
||||
BMElem **elem_array = NULL;
|
||||
Py_ssize_t elem_array_len;
|
||||
|
||||
elem_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
|
||||
&elem_array_len, BM_VERT | BM_EDGE | BM_FACE,
|
||||
TRUE, TRUE, slot_name);
|
||||
|
||||
/* error is set above */
|
||||
if (elem_array == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BMO_slot_buffer_alloc(&bmop, bmop.slots_in, slot_name, elem_array_len);
|
||||
memcpy(slot->data.buf, elem_array, sizeof(void *) * elem_array_len);
|
||||
PyMem_FREE(elem_array);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
"a bmesh sequence, list, (htype, flag) pair, not %.200s",
|
||||
self->opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#undef BPY_BM_GENERIC_MESH_TEST
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* TODO --- many others */
|
||||
PyErr_Format(PyExc_NotImplementedError,
|
||||
"%.200s: keyword \"%.200s\" type %d not working yet!",
|
||||
self->opname, slot_name, slot->slot_type);
|
||||
return NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BMO_op_exec(bm, &bmop);
|
||||
|
||||
/* from here until the end of the function, no returns, just set 'ret' */
|
||||
if (UNLIKELY(bpy_bm_op_as_py_error(bm) == -1)) {
|
||||
ret = NULL; /* exception raised above */
|
||||
}
|
||||
else if (bmop.slots_out[0].slot_name == NULL) {
|
||||
ret = (Py_INCREF(Py_None), Py_None);
|
||||
}
|
||||
else {
|
||||
/* build return value */
|
||||
int i;
|
||||
ret = PyDict_New();
|
||||
|
||||
for (i = 0; bmop.slots_out[i].slot_name; i++) {
|
||||
// BMOpDefine *op_def = opdefines[bmop.type];
|
||||
// BMOSlotType *slot_type = op_def->slot_types_out[i];
|
||||
BMOpSlot *slot = &bmop.slots_out[i];
|
||||
PyObject *item = NULL;
|
||||
|
||||
/* keep switch in same order as above */
|
||||
switch (slot->slot_type) {
|
||||
case BMO_OP_SLOT_BOOL:
|
||||
item = PyBool_FromLong((BMO_SLOT_AS_BOOL(slot)));
|
||||
break;
|
||||
case BMO_OP_SLOT_INT:
|
||||
item = PyLong_FromLong(BMO_SLOT_AS_INT(slot));
|
||||
break;
|
||||
case BMO_OP_SLOT_FLT:
|
||||
item = PyFloat_FromDouble((double)BMO_SLOT_AS_FLOAT(slot));
|
||||
break;
|
||||
case BMO_OP_SLOT_MAT:
|
||||
item = Matrix_CreatePyObject((float *)BMO_SLOT_AS_MATRIX(slot), 4, 4, Py_NEW, NULL);
|
||||
break;
|
||||
case BMO_OP_SLOT_VEC:
|
||||
item = Vector_CreatePyObject(BMO_SLOT_AS_VECTOR(slot), slot->len, Py_NEW, NULL);
|
||||
break;
|
||||
case BMO_OP_SLOT_ELEMENT_BUF:
|
||||
{
|
||||
const int size = slot->len;
|
||||
void **buffer = BMO_SLOT_AS_BUFFER(slot);
|
||||
int j;
|
||||
|
||||
item = PyList_New(size);
|
||||
for (j = 0; j < size; j++) {
|
||||
BMHeader *ele = buffer[i];
|
||||
PyList_SET_ITEM(item, j, ele ? BPy_BMElem_CreatePyObject(bm, ele) : (Py_INCREF(Py_None), Py_None));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_MAPPING:
|
||||
{
|
||||
GHash *slot_hash = BMO_SLOT_AS_GHASH(slot);
|
||||
GHashIterator *hash_iter;
|
||||
item = PyDict_New();
|
||||
|
||||
for (hash_iter = BLI_ghashIterator_new(slot_hash);
|
||||
!BLI_ghashIterator_isDone(hash_iter);
|
||||
BLI_ghashIterator_step(hash_iter) )
|
||||
{
|
||||
BMHeader *ele_key = BLI_ghashIterator_getKey(hash_iter);
|
||||
BMHeader **ele_val = BLI_ghashIterator_getValue(hash_iter);
|
||||
|
||||
PyObject *py_key = ele_key ? BPy_BMElem_CreatePyObject(bm, ele_key) : (Py_INCREF(Py_None), Py_None);
|
||||
PyObject *py_val = *ele_val ? BPy_BMElem_CreatePyObject(bm, *ele_val) : (Py_INCREF(Py_None), Py_None);
|
||||
|
||||
PyDict_SetItem(ret, py_key, py_val);
|
||||
Py_DECREF(py_key);
|
||||
Py_DECREF(py_val);
|
||||
}
|
||||
BLI_ghashIterator_free(hash_iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
BLI_assert(item != NULL);
|
||||
if (item == NULL) {
|
||||
item = (Py_INCREF(Py_None), Py_None);
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* temp code, strip off '.out' while we keep this convention */
|
||||
{
|
||||
char slot_name_strip[MAX_SLOTNAME];
|
||||
char *ch = strchr(slot->slot_name, '.'); /* can't fail! */
|
||||
int tot = ch - slot->slot_name;
|
||||
BLI_assert(ch != NULL);
|
||||
memcpy(slot_name_strip, slot->slot_name, tot);
|
||||
slot_name_strip[tot] = '\0';
|
||||
PyDict_SetItemString(ret, slot_name_strip, item);
|
||||
}
|
||||
#else
|
||||
PyDict_SetItemString(ret, slot->slot_name, item);
|
||||
#endif
|
||||
Py_DECREF(item);
|
||||
}
|
||||
}
|
||||
|
||||
BMO_op_finish(bm, &bmop);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
PyTypeObject bmesh_op_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
@@ -440,7 +91,7 @@ PyTypeObject bmesh_op_Type = {
|
||||
/* More standard operations (here for binary compatibility) */
|
||||
|
||||
NULL, /* hashfunc tp_hash; */
|
||||
(ternaryfunc)pyrna_op_call, /* ternaryfunc tp_call; */
|
||||
(ternaryfunc)BPy_BMO_call, /* ternaryfunc tp_call; */
|
||||
NULL, /* reprfunc tp_str; */
|
||||
|
||||
/* will only use these if this is a subtype of a py class */
|
||||
@@ -501,15 +152,15 @@ PyTypeObject bmesh_op_Type = {
|
||||
/* bmesh fake module 'bmesh.ops'
|
||||
* ***************************** */
|
||||
|
||||
static PyObject *bpy_bmesh_fmod_getattro(PyObject *UNUSED(self), PyObject *pyname)
|
||||
static PyObject *bpy_bmesh_ops_fakemod_getattro(PyObject *UNUSED(self), PyObject *pyname)
|
||||
{
|
||||
const unsigned int tot = bmesh_total_ops;
|
||||
const unsigned int tot = bmo_opdefines_total;
|
||||
unsigned int i;
|
||||
const char *opname = _PyUnicode_AsString(pyname);
|
||||
|
||||
for (i = 0; i < tot; i++) {
|
||||
if (strcmp(opdefines[i]->opname, opname) == 0) {
|
||||
return bpy_bmesh_op_CreatePyObject(opdefines[i]->opname);
|
||||
if (strcmp(bmo_opdefines[i]->opname, opname) == 0) {
|
||||
return bpy_bmesh_op_CreatePyObject(opname);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,23 +170,23 @@ static PyObject *bpy_bmesh_fmod_getattro(PyObject *UNUSED(self), PyObject *pynam
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject *bpy_bmesh_fmod_dir(PyObject *UNUSED(self))
|
||||
static PyObject *bpy_bmesh_ops_fakemod_dir(PyObject *UNUSED(self))
|
||||
{
|
||||
const unsigned int tot = bmesh_total_ops;
|
||||
const unsigned int tot = bmo_opdefines_total;
|
||||
unsigned int i;
|
||||
PyObject *ret;
|
||||
|
||||
ret = PyList_New(bmesh_total_ops);
|
||||
ret = PyList_New(bmo_opdefines_total);
|
||||
|
||||
for (i = 0; i < tot; i++) {
|
||||
PyList_SET_ITEM(ret, i, PyUnicode_FromString(opdefines[i]->opname));
|
||||
PyList_SET_ITEM(ret, i, PyUnicode_FromString(bmo_opdefines[i]->opname));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct PyMethodDef bpy_bmesh_fmod_methods[] = {
|
||||
{"__dir__", (PyCFunction)bpy_bmesh_fmod_dir, METH_NOARGS, NULL},
|
||||
static struct PyMethodDef bpy_bmesh_ops_fakemod_methods[] = {
|
||||
{"__dir__", (PyCFunction)bpy_bmesh_ops_fakemod_dir, METH_NOARGS, NULL},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@@ -565,7 +216,7 @@ static PyTypeObject bmesh_ops_fakemod_Type = {
|
||||
NULL, /* reprfunc tp_str; */
|
||||
|
||||
/* will only use these if this is a subtype of a py class */
|
||||
bpy_bmesh_fmod_getattro, /* getattrofunc tp_getattro; */
|
||||
bpy_bmesh_ops_fakemod_getattro, /* getattrofunc tp_getattro; */
|
||||
NULL, /* setattrofunc tp_setattro; */
|
||||
|
||||
/* Functions to access object as input/output buffer */
|
||||
@@ -594,7 +245,7 @@ static PyTypeObject bmesh_ops_fakemod_Type = {
|
||||
NULL, /* iternextfunc tp_iternext; */
|
||||
|
||||
/*** Attribute descriptor and subclassing stuff ***/
|
||||
bpy_bmesh_fmod_methods, /* struct PyMethodDef *tp_methods; */
|
||||
bpy_bmesh_ops_fakemod_methods, /* struct PyMethodDef *tp_methods; */
|
||||
NULL, /* struct PyMemberDef *tp_members; */
|
||||
NULL, /* struct PyGetSetDef *tp_getset; */
|
||||
NULL, /* struct _typeobject *tp_base; */
|
||||
|
||||
783
source/blender/python/bmesh/bmesh_py_ops_call.c
Normal file
783
source/blender/python/bmesh/bmesh_py_ops_call.c
Normal file
@@ -0,0 +1,783 @@
|
||||
/*
|
||||
* ***** 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_ops_call.c
|
||||
* \ingroup pybmesh
|
||||
*
|
||||
* This file provides __call__ aka BPy_BMO_call for
|
||||
* the bmesh operatorand has been given its own file
|
||||
* because argument conversion is involved.
|
||||
*/
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "../mathutils/mathutils.h"
|
||||
|
||||
#include "bmesh.h"
|
||||
|
||||
#include "bmesh_py_ops.h"
|
||||
#include "bmesh_py_ops_call.h" /* own include */
|
||||
|
||||
#include "bmesh_py_types.h"
|
||||
#include "bmesh_py_utils.h"
|
||||
|
||||
static int bpy_bm_op_as_py_error(BMesh *bm)
|
||||
{
|
||||
if (BMO_error_occurred(bm)) {
|
||||
const char *errmsg;
|
||||
if (BMO_error_get(bm, &errmsg, NULL)) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"bmesh operator: %.200s",
|
||||
errmsg);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Utility function to check BMVert/BMEdge/BMFace's
|
||||
*
|
||||
* \param value
|
||||
* \param bm Check the \a value against this.
|
||||
* \param htype Test \a value matches this type.
|
||||
* \param descr Description text.
|
||||
*/
|
||||
static int bpy_slot_from_py_elem_check(BPy_BMElem *value, BMesh *bm, const char htype,
|
||||
/* for error messages */
|
||||
const char *opname, const char *slot_name, const char *descr)
|
||||
{
|
||||
if (!BPy_BMElem_Check(value) ||
|
||||
!(value->ele->head.htype & htype))
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" %.200s, expected a %.200s not *.200s",
|
||||
opname, slot_name, descr,
|
||||
BPy_BMElem_StringFromHType(htype),
|
||||
Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
else if (value->bm == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" %.200s invalidated element",
|
||||
opname, slot_name, descr);
|
||||
return -1;
|
||||
}
|
||||
else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" %.200s invalidated element",
|
||||
opname, slot_name, descr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Utility function to check BMVertSeq/BMEdgeSeq/BMFaceSeq's
|
||||
*
|
||||
* \param value Caller must check its a BMeshSeq
|
||||
* \param bm Check the \a value against this.
|
||||
* \param htype_py The type(s) of \a value.
|
||||
* \param htype_bmo The type(s) supported by the target slot.
|
||||
* \param descr Description text.
|
||||
*/
|
||||
static int bpy_slot_from_py_elemseq_check(BPy_BMGeneric *value, BMesh *bm,
|
||||
const char htype_py, const char htype_bmo,
|
||||
/* for error messages */
|
||||
const char *opname, const char *slot_name, const char *descr)
|
||||
{
|
||||
if (value->bm == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
|
||||
opname, slot_name, descr);
|
||||
return -1;
|
||||
}
|
||||
else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
|
||||
opname, slot_name, descr);
|
||||
return -1;
|
||||
}
|
||||
else if ((htype_py & htype_bmo) == 0) {
|
||||
char str_bmo[32];
|
||||
char str_py[32];
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" %.200s, expected "
|
||||
"a sequence of %.200s not %.200s",
|
||||
opname, slot_name, descr,
|
||||
BPy_BMElem_StringFromHType_ex(htype_bmo, str_bmo),
|
||||
BPy_BMElem_StringFromHType_ex(htype_py, str_py));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use for giving py args to an operator.
|
||||
*/
|
||||
static int bpy_slot_from_py(BMesh *bm, BMOperator *bmop, BMOpSlot *slot, PyObject *value,
|
||||
/* the are just for exception messages */
|
||||
const char *opname, const char *slot_name)
|
||||
{
|
||||
switch (slot->slot_type) {
|
||||
case BMO_OP_SLOT_BOOL:
|
||||
{
|
||||
int param;
|
||||
|
||||
param = PyLong_AsLong(value);
|
||||
|
||||
if (param < 0) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected True/False or 0/1, not %.200s",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
BMO_SLOT_AS_BOOL(slot) = param;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_INT:
|
||||
{
|
||||
int overflow;
|
||||
long param = PyLong_AsLongAndOverflow(value, &overflow);
|
||||
if (overflow || (param > INT_MAX) || (param < INT_MIN)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: keyword \"%.200s\" value not in 'int' range "
|
||||
"(" STRINGIFY(INT_MIN) ", " STRINGIFY(INT_MAX) ")",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
else if (param == -1 && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected an int, not %.200s",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
BMO_SLOT_AS_INT(slot) = (int)param;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_FLT:
|
||||
{
|
||||
float param = PyFloat_AsDouble(value);
|
||||
if (param == -1 && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected a float, not %.200s",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
BMO_SLOT_AS_FLOAT(slot) = param;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_MAT:
|
||||
{
|
||||
/* XXX - BMesh operator design is crappy here, operator slot should define matrix size,
|
||||
* not the caller! */
|
||||
unsigned short size;
|
||||
if (!MatrixObject_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected a Matrix, not %.200s",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
else if (BaseMath_ReadCallback((MatrixObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else if (((size = ((MatrixObject *)value)->num_col) != ((MatrixObject *)value)->num_row) ||
|
||||
(ELEM(size, 3, 4) == FALSE))
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix Matrix",
|
||||
opname, slot_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMO_slot_mat_set(bmop, bmop->slots_in, slot_name, ((MatrixObject *)value)->matrix, size);
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_VEC:
|
||||
{
|
||||
/* passing slot name here is a bit non-descriptive */
|
||||
if (mathutils_array_parse(BMO_SLOT_AS_VECTOR(slot), 3, 3, value, slot_name) == -1) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_ELEMENT_BUF:
|
||||
{
|
||||
if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) {
|
||||
if (bpy_slot_from_py_elem_check((BPy_BMElem *)value, bm, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
|
||||
opname, slot_name, "single element") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
BMO_slot_buffer_from_single(bmop, slot, &((BPy_BMElem *)value)->ele->head);
|
||||
}
|
||||
else {
|
||||
/* there are many ways we could interpret arguments, for now...
|
||||
* - verts/edges/faces from the mesh direct,
|
||||
* this way the operator takes every item.
|
||||
* - `TODO` a plain python sequence (list) of elements.
|
||||
* - `TODO` an iterator. eg.
|
||||
* face.verts
|
||||
* - `TODO` (type, flag) pair, eg.
|
||||
* ('VERT', {'TAG'})
|
||||
*/
|
||||
|
||||
if (BPy_BMVertSeq_Check(value)) {
|
||||
if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
|
||||
BM_VERT, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
|
||||
opname, slot_name, "element buffer") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_VERT);
|
||||
}
|
||||
else if (BPy_BMEdgeSeq_Check(value)) {
|
||||
if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
|
||||
BM_EDGE, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
|
||||
opname, slot_name, "element buffer") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_EDGE);
|
||||
}
|
||||
else if (BPy_BMFaceSeq_Check(value)) {
|
||||
if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
|
||||
BM_FACE, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
|
||||
opname, slot_name, "element buffer") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
BMO_slot_buffer_from_all(bm, bmop, bmop->slots_in, slot_name, BM_FACE);
|
||||
}
|
||||
|
||||
else if (BPy_BMElemSeq_Check(value)) {
|
||||
BMIter iter;
|
||||
BMHeader *ele;
|
||||
int tot;
|
||||
unsigned int i;
|
||||
|
||||
if (bpy_slot_from_py_elemseq_check((BPy_BMGeneric *)value, bm,
|
||||
bm_iter_itype_htype_map[((BPy_BMElemSeq *)value)->itype],
|
||||
(slot->slot_subtype.elem & BM_ALL_NOLOOP),
|
||||
opname, slot_name, "element buffer") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
/* this will loop over all elements which is a shame but
|
||||
* we need to know this before alloc */
|
||||
/* calls bpy_bmelemseq_length() */
|
||||
tot = Py_TYPE(value)->tp_as_sequence->sq_length(value);
|
||||
|
||||
BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, tot);
|
||||
|
||||
i = 0;
|
||||
BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) {
|
||||
slot->data.buf[i] = ele;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/* keep this last */
|
||||
else if (PySequence_Check(value)) {
|
||||
BMElem **elem_array = NULL;
|
||||
Py_ssize_t elem_array_len;
|
||||
|
||||
elem_array = BPy_BMElem_PySeq_As_Array(&bm, value, 0, PY_SSIZE_T_MAX,
|
||||
&elem_array_len, (slot->slot_subtype.elem & BM_ALL_NOLOOP),
|
||||
TRUE, TRUE, slot_name);
|
||||
|
||||
/* error is set above */
|
||||
if (elem_array == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMO_slot_buffer_alloc(bmop, bmop->slots_in, slot_name, elem_array_len);
|
||||
memcpy(slot->data.buf, elem_array, sizeof(void *) * elem_array_len);
|
||||
PyMem_FREE(elem_array);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
"a bmesh sequence, list, (htype, flag) pair, not %.200s",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_MAPPING:
|
||||
{
|
||||
/* first check types */
|
||||
if (slot->slot_subtype.map != BMO_OP_SLOT_SUBTYPE_MAP_EMPTY) {
|
||||
if (!PyDict_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
"a dict, not %.200s",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!PySet_Check(value)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
"a set, not %.200s",
|
||||
opname, slot_name, Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
switch (slot->slot_subtype.map) {
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_ELEM:
|
||||
{
|
||||
if (PyDict_Size(value) > 0) {
|
||||
PyObject *arg_key, *arg_value;
|
||||
Py_ssize_t arg_pos = 0;
|
||||
while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
|
||||
if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
|
||||
opname, slot_name, "invalid key in dict") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_value, bm, BM_ALL_NOLOOP,
|
||||
opname, slot_name, "invalid value in dict") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
BMO_slot_map_elem_insert(bmop, slot,
|
||||
((BPy_BMElem *)arg_key)->ele, ((BPy_BMElem *)arg_value)->ele);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_FLT:
|
||||
{
|
||||
if (PyDict_Size(value) > 0) {
|
||||
PyObject *arg_key, *arg_value;
|
||||
Py_ssize_t arg_pos = 0;
|
||||
while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
|
||||
float value_f;
|
||||
|
||||
if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
|
||||
opname, slot_name, "invalid key in dict") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
value_f = PyFloat_AsDouble(arg_value);
|
||||
|
||||
if (value_f == -1.0f && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
"a dict with float values, not %.200s",
|
||||
opname, slot_name, Py_TYPE(arg_value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMO_slot_map_float_insert(bmop, slot,
|
||||
((BPy_BMElem *)arg_key)->ele, value_f);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_INT:
|
||||
{
|
||||
if (PyDict_Size(value) > 0) {
|
||||
PyObject *arg_key, *arg_value;
|
||||
Py_ssize_t arg_pos = 0;
|
||||
while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
|
||||
int value_i;
|
||||
|
||||
if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
|
||||
opname, slot_name, "invalid key in dict") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
value_i = PyLong_AsLong(arg_value);
|
||||
|
||||
if (value_i == -1 && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
"a dict with int values, not %.200s",
|
||||
opname, slot_name, Py_TYPE(arg_value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMO_slot_map_int_insert(bmop, slot,
|
||||
((BPy_BMElem *)arg_key)->ele, value_i);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_BOOL:
|
||||
{
|
||||
if (PyDict_Size(value) > 0) {
|
||||
PyObject *arg_key, *arg_value;
|
||||
Py_ssize_t arg_pos = 0;
|
||||
while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
|
||||
int value_i;
|
||||
|
||||
if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
|
||||
opname, slot_name, "invalid key in dict") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
value_i = PyLong_AsLong(arg_value);
|
||||
|
||||
if (value_i == -1 && PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected "
|
||||
"a dict with bool values, not %.200s",
|
||||
opname, slot_name, Py_TYPE(arg_value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
BMO_slot_map_bool_insert(bmop, slot,
|
||||
((BPy_BMElem *)arg_key)->ele, value_i != 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY:
|
||||
{
|
||||
if (PySet_Size(value) > 0) {
|
||||
PyObject *arg_key;
|
||||
Py_ssize_t arg_pos = 0;
|
||||
Py_ssize_t arg_hash = 0;
|
||||
while (_PySet_NextEntry(value, &arg_pos, &arg_key, &arg_hash)) {
|
||||
|
||||
if (bpy_slot_from_py_elem_check((BPy_BMElem *)arg_key, bm, BM_ALL_NOLOOP,
|
||||
opname, slot_name, "invalid key in set") == -1)
|
||||
{
|
||||
return -1; /* error is set in bpy_slot_from_py_elem_check() */
|
||||
}
|
||||
|
||||
BMO_slot_map_empty_insert(bmop, slot,
|
||||
((BPy_BMElem *)arg_key)->ele);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL:
|
||||
{
|
||||
/* can't convert from these */
|
||||
PyErr_Format(PyExc_NotImplementedError,
|
||||
"This arguments mapping subtype %d is not supported", slot->slot_subtype);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
/* TODO --- many others */
|
||||
PyErr_Format(PyExc_NotImplementedError,
|
||||
"%.200s: keyword \"%.200s\" type %d not working yet!",
|
||||
opname, slot_name, slot->slot_type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* all is well */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use for getting return values from an operator thats already executed.
|
||||
*
|
||||
* \note Don't throw any exceptions and should always return a valid (PyObject *).
|
||||
*/
|
||||
static PyObject* bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
|
||||
{
|
||||
PyObject *item = NULL;
|
||||
|
||||
/* keep switch in same order as above */
|
||||
switch (slot->slot_type) {
|
||||
case BMO_OP_SLOT_BOOL:
|
||||
item = PyBool_FromLong((BMO_SLOT_AS_BOOL(slot)));
|
||||
break;
|
||||
case BMO_OP_SLOT_INT:
|
||||
item = PyLong_FromLong(BMO_SLOT_AS_INT(slot));
|
||||
break;
|
||||
case BMO_OP_SLOT_FLT:
|
||||
item = PyFloat_FromDouble((double)BMO_SLOT_AS_FLOAT(slot));
|
||||
break;
|
||||
case BMO_OP_SLOT_MAT:
|
||||
item = Matrix_CreatePyObject((float *)BMO_SLOT_AS_MATRIX(slot), 4, 4, Py_NEW, NULL);
|
||||
break;
|
||||
case BMO_OP_SLOT_VEC:
|
||||
item = Vector_CreatePyObject(BMO_SLOT_AS_VECTOR(slot), slot->len, Py_NEW, NULL);
|
||||
break;
|
||||
case BMO_OP_SLOT_PTR:
|
||||
BLI_assert(0); /* currently we don't have any pointer return values in use */
|
||||
item = (Py_INCREF(Py_None), Py_None);
|
||||
break;
|
||||
case BMO_OP_SLOT_ELEMENT_BUF:
|
||||
{
|
||||
if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) {
|
||||
BMHeader *ele = BMO_slot_buffer_get_single(slot);
|
||||
item = ele ? BPy_BMElem_CreatePyObject(bm, ele) : (Py_INCREF(Py_None), Py_None);
|
||||
}
|
||||
else {
|
||||
const int size = slot->len;
|
||||
void **buffer = BMO_SLOT_AS_BUFFER(slot);
|
||||
int j;
|
||||
|
||||
item = PyList_New(size);
|
||||
for (j = 0; j < size; j++) {
|
||||
BMHeader *ele = buffer[j];
|
||||
PyList_SET_ITEM(item, j, BPy_BMElem_CreatePyObject(bm, ele));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_MAPPING:
|
||||
{
|
||||
GHash *slot_hash = BMO_SLOT_AS_GHASH(slot);
|
||||
GHashIterator hash_iter;
|
||||
|
||||
switch (slot->slot_subtype.map) {
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_ELEM:
|
||||
{
|
||||
item = PyDict_New();
|
||||
if (slot_hash) {
|
||||
GHASH_ITER (hash_iter, slot_hash) {
|
||||
BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
|
||||
BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter);
|
||||
|
||||
PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
|
||||
PyObject *py_val = BPy_BMElem_CreatePyObject(bm, *(void **)BMO_OP_SLOT_MAPPING_DATA(ele_val));
|
||||
|
||||
PyDict_SetItem(item, py_key, py_val);
|
||||
Py_DECREF(py_key);
|
||||
Py_DECREF(py_val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_FLT:
|
||||
{
|
||||
item = PyDict_New();
|
||||
if (slot_hash) {
|
||||
GHASH_ITER (hash_iter, slot_hash) {
|
||||
BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
|
||||
BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter);
|
||||
|
||||
PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
|
||||
PyObject *py_val = PyFloat_FromDouble(*(float *)BMO_OP_SLOT_MAPPING_DATA(ele_val));
|
||||
|
||||
PyDict_SetItem(item, py_key, py_val);
|
||||
Py_DECREF(py_key);
|
||||
Py_DECREF(py_val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_INT:
|
||||
{
|
||||
item = PyDict_New();
|
||||
if (slot_hash) {
|
||||
GHASH_ITER (hash_iter, slot_hash) {
|
||||
BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
|
||||
BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter);
|
||||
|
||||
PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
|
||||
PyObject *py_val = PyLong_FromLong(*(int *)BMO_OP_SLOT_MAPPING_DATA(ele_val));
|
||||
|
||||
PyDict_SetItem(item, py_key, py_val);
|
||||
Py_DECREF(py_key);
|
||||
Py_DECREF(py_val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_BOOL:
|
||||
{
|
||||
item = PyDict_New();
|
||||
if (slot_hash) {
|
||||
GHASH_ITER (hash_iter, slot_hash) {
|
||||
BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
|
||||
BMOElemMapping *ele_val = BLI_ghashIterator_getValue(&hash_iter);
|
||||
|
||||
PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
|
||||
PyObject *py_val = PyBool_FromLong(*(int *)BMO_OP_SLOT_MAPPING_DATA(ele_val));
|
||||
|
||||
PyDict_SetItem(item, py_key, py_val);
|
||||
Py_DECREF(py_key);
|
||||
Py_DECREF(py_val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_EMPTY:
|
||||
{
|
||||
item = PySet_New(NULL);
|
||||
if (slot_hash) {
|
||||
GHASH_ITER (hash_iter, slot_hash) {
|
||||
BMHeader *ele_key = BLI_ghashIterator_getKey(&hash_iter);
|
||||
|
||||
PyObject *py_key = BPy_BMElem_CreatePyObject(bm, ele_key);
|
||||
|
||||
PySet_Add(item, py_key);
|
||||
|
||||
Py_DECREF(py_key);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL:
|
||||
/* can't convert from these */
|
||||
item = (Py_INCREF(Py_None), Py_None);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
BLI_assert(item != NULL);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the __call__ for bmesh.ops.xxx()
|
||||
*/
|
||||
PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
PyObject *ret;
|
||||
BPy_BMesh *py_bm;
|
||||
BMesh *bm;
|
||||
|
||||
BMOperator bmop;
|
||||
|
||||
if ((PyTuple_GET_SIZE(args) == 1) &&
|
||||
(py_bm = (BPy_BMesh *)PyTuple_GET_ITEM(args, 0)) &&
|
||||
(BPy_BMesh_Check(py_bm))
|
||||
)
|
||||
{
|
||||
BPY_BM_CHECK_OBJ(py_bm);
|
||||
bm = py_bm->bm;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"calling a bmesh operator expects a single BMesh (non keyword) "
|
||||
"as the first argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* TODO - error check this!, though we do the error check on attribute access */
|
||||
/* TODO - make flags optional */
|
||||
BMO_op_init(bm, &bmop, BMO_FLAG_DEFAULTS, self->opname);
|
||||
|
||||
if (kw && PyDict_Size(kw) > 0) {
|
||||
/* setup properties, see bpy_rna.c: pyrna_py_to_prop()
|
||||
* which shares this logic for parsing properties */
|
||||
|
||||
PyObject *key, *value;
|
||||
Py_ssize_t pos = 0;
|
||||
while (PyDict_Next(kw, &pos, &key, &value)) {
|
||||
const char *slot_name = _PyUnicode_AsString(key);
|
||||
BMOpSlot *slot;
|
||||
|
||||
if (!BMO_slot_exists(bmop.slots_in, slot_name)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" is invalid for this operator",
|
||||
self->opname, slot_name);
|
||||
BMO_op_finish(bm, &bmop);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
slot = BMO_slot_get(bmop.slots_in, slot_name);
|
||||
|
||||
/* now assign the value */
|
||||
if (bpy_slot_from_py(bm, &bmop, slot, value,
|
||||
self->opname, slot_name) == -1)
|
||||
{
|
||||
BMO_op_finish(bm, &bmop);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BMO_op_exec(bm, &bmop);
|
||||
|
||||
/* from here until the end of the function, no returns, just set 'ret' */
|
||||
if (UNLIKELY(bpy_bm_op_as_py_error(bm) == -1)) {
|
||||
ret = NULL; /* exception raised above */
|
||||
}
|
||||
else if (bmop.slots_out[0].slot_name == NULL) {
|
||||
ret = (Py_INCREF(Py_None), Py_None);
|
||||
}
|
||||
else {
|
||||
/* build return value */
|
||||
int i;
|
||||
ret = PyDict_New();
|
||||
|
||||
for (i = 0; bmop.slots_out[i].slot_name; i++) {
|
||||
// BMOpDefine *op_def = opdefines[bmop.type];
|
||||
// BMOSlotType *slot_type = op_def->slot_types_out[i];
|
||||
BMOpSlot *slot = &bmop.slots_out[i];
|
||||
PyObject *item;
|
||||
|
||||
/* this function doesn't throw exceptions */
|
||||
item = bpy_slot_to_py(bm, slot);
|
||||
if (item == NULL) {
|
||||
item = (Py_INCREF(Py_None), Py_None);
|
||||
}
|
||||
|
||||
#if 1
|
||||
/* temp code, strip off '.out' while we keep this convention */
|
||||
{
|
||||
char slot_name_strip[MAX_SLOTNAME];
|
||||
char *ch = strchr(slot->slot_name, '.'); /* can't fail! */
|
||||
int tot = ch - slot->slot_name;
|
||||
BLI_assert(ch != NULL);
|
||||
memcpy(slot_name_strip, slot->slot_name, tot);
|
||||
slot_name_strip[tot] = '\0';
|
||||
PyDict_SetItemString(ret, slot_name_strip, item);
|
||||
}
|
||||
#else
|
||||
PyDict_SetItemString(ret, slot->slot_name, item);
|
||||
#endif
|
||||
Py_DECREF(item);
|
||||
}
|
||||
}
|
||||
|
||||
BMO_op_finish(bm, &bmop);
|
||||
return ret;
|
||||
}
|
||||
41
source/blender/python/bmesh/bmesh_py_ops_call.h
Normal file
41
source/blender/python/bmesh/bmesh_py_ops_call.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* ***** 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_ops_call.h
|
||||
* \ingroup pybmesh
|
||||
*/
|
||||
|
||||
#ifndef __BMESH_PY_OPS_CALL_H__
|
||||
#define __BMESH_PY_OPS_CALL_H__
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required python macro */
|
||||
const char *opname;
|
||||
} BPy_BMeshOpFunc;
|
||||
|
||||
|
||||
PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw);
|
||||
|
||||
#endif /* __BMESH_PY_OPS_CALL_H__ */
|
||||
@@ -541,12 +541,30 @@ static PyObject *bpy_bmloop_link_loop_prev_get(BPy_BMLoop *self)
|
||||
return BPy_BMLoop_CreatePyObject(self->bm, self->l->prev);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(bpy_bmloop_link_loop_radial_next_doc,
|
||||
"The next loop around the edge (read-only).\n\n:type: :class:`BMLoop`"
|
||||
);
|
||||
static PyObject *bpy_bmloop_link_loop_radial_next_get(BPy_BMLoop *self)
|
||||
{
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_next);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(bpy_bmloop_link_loop_radial_prev_doc,
|
||||
"The previous loop around the edge (read-only).\n\n:type: :class:`BMLoop`"
|
||||
);
|
||||
static PyObject *bpy_bmloop_link_loop_radial_prev_get(BPy_BMLoop *self)
|
||||
{
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
return BPy_BMLoop_CreatePyObject(self->bm, self->l->radial_prev);
|
||||
}
|
||||
|
||||
/* ElemSeq
|
||||
* ^^^^^^^ */
|
||||
|
||||
/* note: use for bmvert/edge/face/loop seq's use these, not bmelemseq directly */
|
||||
PyDoc_STRVAR(bpy_bmelemseq_layers_doc,
|
||||
"blah blah (read-only).\n\n:type: :class:`BMLayerAccess`"
|
||||
"custom-data layers (read-only).\n\n:type: :class:`BMLayerAccess`"
|
||||
);
|
||||
static PyObject *bpy_bmelemseq_layers_get(BPy_BMElemSeq *self, void *htype)
|
||||
{
|
||||
@@ -555,6 +573,46 @@ static PyObject *bpy_bmelemseq_layers_get(BPy_BMElemSeq *self, void *htype)
|
||||
return BPy_BMLayerAccess_CreatePyObject(self->bm, GET_INT_FROM_POINTER(htype));
|
||||
}
|
||||
|
||||
/* FaceSeq
|
||||
* ^^^^^^^ */
|
||||
|
||||
PyDoc_STRVAR(bpy_bmfaceseq_active_doc,
|
||||
"active face.\n\n:type: :class:`BMFace` or None"
|
||||
);
|
||||
static PyObject *bpy_bmfaceseq_active_get(BPy_BMElemSeq *self, void *UNUSED(closure))
|
||||
{
|
||||
BMesh *bm = self->bm;
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
|
||||
if (bm->act_face) {
|
||||
return BPy_BMElem_CreatePyObject(bm, (BMHeader *)bm->act_face);
|
||||
}
|
||||
else {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
BMesh *bm = self->bm;
|
||||
if (value == Py_None) {
|
||||
bm->act_face = NULL;
|
||||
return 0;
|
||||
}
|
||||
else if (BPy_BMFace_Check(value)) {
|
||||
BPY_BM_CHECK_SOURCE_INT(value, bm, "faces.active = f");
|
||||
|
||||
bm->act_face = ((BPy_BMFace *)value)->f;
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"faces.active = f: expected BMFace or None, not %.200s",
|
||||
Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
static PyGetSetDef bpy_bmesh_getseters[] = {
|
||||
{(char *)"verts", (getter)bpy_bmvertseq_get, (setter)NULL, (char *)bpy_bmvertseq_doc, NULL},
|
||||
{(char *)"edges", (getter)bpy_bmedgeseq_get, (setter)NULL, (char *)bpy_bmedgeseq_doc, NULL},
|
||||
@@ -659,6 +717,8 @@ static PyGetSetDef bpy_bmloop_getseters[] = {
|
||||
{(char *)"link_loops", (getter)bpy_bmelemseq_elem_get, (setter)NULL, (char *)bpy_bmloops_link_loops_doc, (void *)BM_LOOPS_OF_LOOP},
|
||||
{(char *)"link_loop_next", (getter)bpy_bmloop_link_loop_next_get, (setter)NULL, (char *)bpy_bmloop_link_loop_next_doc, NULL},
|
||||
{(char *)"link_loop_prev", (getter)bpy_bmloop_link_loop_prev_get, (setter)NULL, (char *)bpy_bmloop_link_loop_prev_doc, NULL},
|
||||
{(char *)"link_loop_radial_next", (getter)bpy_bmloop_link_loop_radial_next_get, (setter)NULL, (char *)bpy_bmloop_link_loop_radial_next_doc, NULL},
|
||||
{(char *)"link_loop_radial_prev", (getter)bpy_bmloop_link_loop_radial_prev_get, (setter)NULL, (char *)bpy_bmloop_link_loop_radial_prev_doc, NULL},
|
||||
|
||||
/* readonly checks */
|
||||
{(char *)"is_valid", (getter)bpy_bm_is_valid_get, (setter)NULL, (char *)bpy_bm_is_valid_doc, NULL},
|
||||
@@ -668,7 +728,7 @@ static PyGetSetDef bpy_bmloop_getseters[] = {
|
||||
|
||||
static PyGetSetDef bpy_bmvertseq_getseters[] = {
|
||||
{(char *)"layers", (getter)bpy_bmelemseq_layers_get, (setter)NULL, (char *)bpy_bmelemseq_layers_doc, (void *)BM_VERT},
|
||||
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
|
||||
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
|
||||
};
|
||||
static PyGetSetDef bpy_bmedgeseq_getseters[] = {
|
||||
{(char *)"layers", (getter)bpy_bmelemseq_layers_get, (setter)NULL, (char *)bpy_bmelemseq_layers_doc, (void *)BM_EDGE},
|
||||
@@ -676,6 +736,8 @@ static PyGetSetDef bpy_bmedgeseq_getseters[] = {
|
||||
};
|
||||
static PyGetSetDef bpy_bmfaceseq_getseters[] = {
|
||||
{(char *)"layers", (getter)bpy_bmelemseq_layers_get, (setter)NULL, (char *)bpy_bmelemseq_layers_doc, (void *)BM_FACE},
|
||||
/* face only */
|
||||
{(char *)"active", (getter)bpy_bmfaceseq_active_get, (setter)bpy_bmfaceseq_active_set, (char *)bpy_bmfaceseq_active_doc, NULL},
|
||||
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
|
||||
};
|
||||
static PyGetSetDef bpy_bmloopseq_getseters[] = {
|
||||
@@ -1232,13 +1294,7 @@ static PyObject *bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *ar
|
||||
else {
|
||||
BMesh *bm = self->bm;
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_face);
|
||||
|
||||
if (py_face->bm != bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"BMVert.copy_from_face_interp(face): face is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "copy_from_face_interp()");
|
||||
|
||||
BM_vert_interp_from_face(bm, self->v, py_face->f);
|
||||
|
||||
@@ -1372,13 +1428,7 @@ static PyObject *bpy_bmedge_other_vert(BPy_BMEdge *self, BPy_BMVert *value)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(value);
|
||||
|
||||
if (self->bm != value->bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"BMEdge.other_vert(vert): vert is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "BMEdge.other_vert(vert)");
|
||||
|
||||
other = BM_edge_other_vert(self->e, value->v);
|
||||
|
||||
@@ -1432,13 +1482,7 @@ static PyObject *bpy_bmface_copy_from_face_interp(BPy_BMFace *self, PyObject *ar
|
||||
else {
|
||||
BMesh *bm = self->bm;
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_face);
|
||||
|
||||
if (py_face->bm != bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"BMFace.copy_from_face_interp(face): face is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "BMFace.copy_from_face_interp(face)");
|
||||
|
||||
BM_face_interp_from_face(bm, self->f, py_face->f);
|
||||
|
||||
@@ -1604,13 +1648,7 @@ static PyObject *bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *ar
|
||||
else {
|
||||
BMesh *bm = self->bm;
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_face);
|
||||
|
||||
if (py_face->bm != bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"BMLoop.copy_from_face_interp(face): face is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "BMLoop.copy_from_face_interp(face)");
|
||||
|
||||
BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires);
|
||||
|
||||
@@ -1708,7 +1746,7 @@ static PyObject *bpy_bmvertseq_new(BPy_BMElemSeq *self, PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
v = BM_vert_create(bm, co, NULL);
|
||||
v = BM_vert_create(bm, co, NULL, 0);
|
||||
|
||||
if (v == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
@@ -1777,7 +1815,7 @@ static PyObject *bpy_bmedgeseq_new(BPy_BMElemSeq *self, PyObject *args)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
e = BM_edge_create(bm, vert_array[0], vert_array[1], NULL, FALSE);
|
||||
e = BM_edge_create(bm, vert_array[0], vert_array[1], NULL, 0);
|
||||
|
||||
if (e == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
@@ -1863,10 +1901,10 @@ static PyObject *bpy_bmfaceseq_new(BPy_BMElemSeq *self, PyObject *args)
|
||||
|
||||
/* ensure edges */
|
||||
for (i = vert_seq_len - 1, i_next = 0; i_next < vert_seq_len; (i = i_next++)) {
|
||||
edge_array[i] = BM_edge_create(bm, vert_array[i], vert_array[i_next], NULL, TRUE);
|
||||
edge_array[i] = BM_edge_create(bm, vert_array[i], vert_array[i_next], NULL, BM_CREATE_NO_DOUBLE);
|
||||
}
|
||||
|
||||
f_new = BM_face_create(bm, vert_array, edge_array, vert_seq_len, FALSE);
|
||||
f_new = BM_face_create(bm, vert_array, edge_array, vert_seq_len, 0);
|
||||
|
||||
if (UNLIKELY(f_new == NULL)) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
@@ -1906,13 +1944,7 @@ static PyObject *bpy_bmvertseq_remove(BPy_BMElemSeq *self, BPy_BMVert *value)
|
||||
else {
|
||||
BMesh *bm = self->bm;
|
||||
|
||||
BPY_BM_CHECK_OBJ(value);
|
||||
|
||||
if (value->bm != bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"verts.remove(vert): vert is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(value, bm, "verts.remove(vert)");
|
||||
|
||||
BM_vert_kill(bm, value->v);
|
||||
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
||||
@@ -1936,13 +1968,7 @@ static PyObject *bpy_bmedgeseq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value)
|
||||
else {
|
||||
BMesh *bm = self->bm;
|
||||
|
||||
BPY_BM_CHECK_OBJ(value);
|
||||
|
||||
if (value->bm != bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"edges.remove(edge): edge is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(value, bm, "edges.remove(edges)");
|
||||
|
||||
BM_edge_kill(bm, value->e);
|
||||
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
||||
@@ -1966,13 +1992,7 @@ static PyObject *bpy_bmfaceseq_remove(BPy_BMElemSeq *self, BPy_BMFace *value)
|
||||
else {
|
||||
BMesh *bm = self->bm;
|
||||
|
||||
BPY_BM_CHECK_OBJ(value);
|
||||
|
||||
if (value->bm != bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"faces.remove(face): face is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(value, bm, "faces.remove(face)");
|
||||
|
||||
BM_face_kill(bm, value->f);
|
||||
bpy_bm_generic_invalidate((BPy_BMGeneric *)value);
|
||||
@@ -3032,7 +3052,8 @@ void BPy_BM_init_types(void)
|
||||
BPy_BMLoopSeq_Type.tp_methods = bpy_bmloopseq_methods;
|
||||
BPy_BMIter_Type.tp_methods = NULL;
|
||||
|
||||
|
||||
/*BPy_BMElem_Check() uses bpy_bm_elem_hash() to check types.
|
||||
* if this changes update the macro */
|
||||
BPy_BMesh_Type.tp_hash = bpy_bm_hash;
|
||||
BPy_BMVert_Type.tp_hash = bpy_bm_elem_hash;
|
||||
BPy_BMEdge_Type.tp_hash = bpy_bm_elem_hash;
|
||||
@@ -3400,6 +3421,21 @@ int bpy_bm_generic_valid_check(BPy_BMGeneric *self)
|
||||
}
|
||||
}
|
||||
|
||||
int bpy_bm_generic_valid_check_source(BPy_BMGeneric *self, BMesh *bm_source, const char *error_prefix)
|
||||
{
|
||||
int ret = bpy_bm_generic_valid_check(self);
|
||||
if (LIKELY(ret == 0)) {
|
||||
if (UNLIKELY(self->bm != bm_source)) {
|
||||
/* could give more info here */
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: BMesh data of type %.200s is from another mesh",
|
||||
error_prefix, Py_TYPE(self)->tp_name);
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bpy_bm_generic_invalidate(BPy_BMGeneric *self)
|
||||
{
|
||||
self->bm = NULL;
|
||||
|
||||
@@ -55,6 +55,8 @@ extern PyTypeObject BPy_BMIter_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)
|
||||
/* trick since we know they share a hash function */
|
||||
#define BPy_BMElem_Check(v) (Py_TYPE(v)->tp_hash == BPy_BMVert_Type.tp_hash)
|
||||
|
||||
/* cast from _any_ bmesh type - they all have BMesh first */
|
||||
typedef struct BPy_BMGeneric {
|
||||
@@ -156,9 +158,6 @@ PyObject *BPy_BMIter_CreatePyObject(BMesh *bm);
|
||||
|
||||
PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele); /* just checks type and creates v/e/f/l */
|
||||
|
||||
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,
|
||||
const char htype,
|
||||
const char do_unique_check, const char do_bm_check,
|
||||
@@ -169,9 +168,20 @@ 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);
|
||||
|
||||
void bpy_bm_generic_invalidate(BPy_BMGeneric *self);
|
||||
int bpy_bm_generic_valid_check(BPy_BMGeneric *self);
|
||||
int bpy_bm_generic_valid_check_source(BPy_BMGeneric *self, BMesh *bm_source, const char *error_prefix);
|
||||
|
||||
#define BPY_BM_CHECK_OBJ(obj) if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0
|
||||
#define BPY_BM_CHECK_INT(obj) if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return -1; } (void)0
|
||||
#define BPY_BM_CHECK_OBJ(obj) \
|
||||
if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0
|
||||
#define BPY_BM_CHECK_INT(obj) \
|
||||
if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return -1; } (void)0
|
||||
|
||||
/* macros like BPY_BM_CHECK_OBJ/BPY_BM_CHECK_INT that ensure we're from the right BMesh */
|
||||
#define BPY_BM_CHECK_SOURCE_OBJ(obj, bm, errmsg) \
|
||||
if (UNLIKELY(bpy_bm_generic_valid_check_source((BPy_BMGeneric *)obj, bm, errmsg) == -1)) { return NULL; } (void)0
|
||||
#define BPY_BM_CHECK_SOURCE_INT(obj, bm, errmsg) \
|
||||
if (UNLIKELY(bpy_bm_generic_valid_check_source((BPy_BMGeneric *)obj, bm, errmsg) == -1)) { return -1; } (void)0
|
||||
|
||||
#define BPY_BM_IS_VALID(obj) (LIKELY((obj)->bm != NULL))
|
||||
|
||||
|
||||
@@ -262,16 +262,10 @@ static PyObject *bpy_bmlayeritem_copy_from(BPy_BMLayerItem *self, BPy_BMLayerIte
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(self);
|
||||
BPY_BM_CHECK_OBJ(value);
|
||||
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "layer.copy_from()");
|
||||
|
||||
if (self->bm != value->bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"layer.copy_from(): layer is from another mesh");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
else if ((self->htype != value->htype) ||
|
||||
(self->type != value->type))
|
||||
if ((self->htype != value->htype) ||
|
||||
(self->type != value->type))
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"layer.copy_from(other): layer type mismatch");
|
||||
|
||||
@@ -114,13 +114,7 @@ static PyObject *bpy_bmeditselseq_add(BPy_BMEditSelSeq *self, BPy_BMElem *value)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(value);
|
||||
|
||||
if (self->bm != value->bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Element is not from this mesh");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "select_history.add()");
|
||||
|
||||
BM_select_history_store(self->bm, value->ele);
|
||||
|
||||
@@ -145,11 +139,9 @@ static PyObject *bpy_bmeditselseq_remove(BPy_BMEditSelSeq *self, BPy_BMElem *val
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(value);
|
||||
BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "select_history.remove()");
|
||||
|
||||
if ((self->bm != value->bm) ||
|
||||
(BM_select_history_remove(self->bm, value->ele) == FALSE))
|
||||
{
|
||||
if (BM_select_history_remove(self->bm, value->ele) == FALSE) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Element not found in selection history");
|
||||
return NULL;
|
||||
|
||||
@@ -557,16 +557,10 @@ static PyObject *bpy_bm_utils_face_vert_separate(PyObject *UNUSED(self), PyObjec
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BPY_BM_CHECK_OBJ(py_face);
|
||||
BPY_BM_CHECK_OBJ(py_vert);
|
||||
|
||||
bm = py_face->bm;
|
||||
|
||||
if (bm != py_vert->bm) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"mesh elements are from different meshes");
|
||||
return NULL;
|
||||
}
|
||||
BPY_BM_CHECK_OBJ(py_face);
|
||||
BPY_BM_CHECK_SOURCE_OBJ(py_vert, bm, "face_vert_separate()");
|
||||
|
||||
l = BM_face_vert_share_loop(py_face->f, py_vert->v);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user