add subtypes to bmesh operators (needed for python api to know how to convert return values).
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -91,15 +91,15 @@ BLI_INLINE void _bmo_elem_flag_toggle( BMesh *bm, BMFlagLayer *oflags, const
|
||||
|
||||
/* slot type arrays are terminated by the last member
|
||||
* having a slot type of 0 */
|
||||
enum {
|
||||
BMO_OP_SLOT_SENTINEL = 0,
|
||||
typedef enum eBMOpSlotType {
|
||||
/* BMO_OP_SLOT_SENTINEL = 0, */
|
||||
BMO_OP_SLOT_BOOL = 1,
|
||||
BMO_OP_SLOT_INT = 2,
|
||||
BMO_OP_SLOT_FLT = 3,
|
||||
|
||||
/* normally store pointers to object, scene,
|
||||
* _never_ store arrays corresponding to mesh elements with this */
|
||||
BMO_OP_SLOT_PTR = 4,
|
||||
BMO_OP_SLOT_PTR = 4, /* requres subtype BMO_OP_SLOT_SUBTYPE_PTR_xxx */
|
||||
BMO_OP_SLOT_MAT = 5,
|
||||
BMO_OP_SLOT_VEC = 8,
|
||||
|
||||
@@ -108,16 +108,39 @@ enum {
|
||||
*
|
||||
* it's very important this remain a power of two */
|
||||
BMO_OP_SLOT_ELEMENT_BUF = 9, /* list of verts/edges/faces */
|
||||
BMO_OP_SLOT_MAPPING = 10 /* simple hash map */
|
||||
};
|
||||
BMO_OP_SLOT_MAPPING = 10 /* simple hash map, requres subtype BMO_OP_SLOT_SUBTYPE_MAP_xxx */
|
||||
} eBMOpSlotType;
|
||||
#define BMO_OP_SLOT_TOTAL_TYPES 11
|
||||
|
||||
/* leave zero for invalid/unset */
|
||||
typedef enum eBMOpSlotSubType {
|
||||
/* BMO_OP_SLOT_MAPPING */
|
||||
#define BMO_OP_SLOT_SUBTYPE_MAP__FIRST BMO_OP_SLOT_SUBTYPE_MAP_EMPTY
|
||||
BMO_OP_SLOT_SUBTYPE_MAP_EMPTY = 1, /* use as a set(), unused value */
|
||||
BMO_OP_SLOT_SUBTYPE_MAP_ELEM = 2,
|
||||
BMO_OP_SLOT_SUBTYPE_MAP_FLOAT = 3,
|
||||
BMO_OP_SLOT_SUBTYPE_MAP_INT = 4,
|
||||
BMO_OP_SLOT_SUBTYPE_MAP_BOOL = 5,
|
||||
BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL = 6, /* python can't convert these */
|
||||
#define BMO_OP_SLOT_SUBTYPE_MAP__LAST BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL
|
||||
|
||||
/* BMO_OP_SLOT_PTR */
|
||||
#define BMO_OP_SLOT_SUBTYPE_PTR__FIRST BMO_OP_SLOT_SUBTYPE_PTR_BMESH
|
||||
BMO_OP_SLOT_SUBTYPE_PTR_BMESH = 10,
|
||||
BMO_OP_SLOT_SUBTYPE_PTR_SCENE = 11,
|
||||
BMO_OP_SLOT_SUBTYPE_PTR_OBJECT = 12,
|
||||
BMO_OP_SLOT_SUBTYPE_PTR_MESH = 13,
|
||||
#define BMO_OP_SLOT_SUBTYPE_PTR__LAST BMO_OP_SLOT_SUBTYPE_PTR_MESH
|
||||
|
||||
} eBMOpSlotSubType;
|
||||
|
||||
/* please ignore all these structures, don't touch them in tool code, except
|
||||
* for when your defining an operator with BMOpDefine.*/
|
||||
|
||||
typedef struct BMOpSlot {
|
||||
const char *slot_name; /* pointer to BMOpDefine.slot_args */
|
||||
int slot_type;
|
||||
eBMOpSlotType slot_type;
|
||||
eBMOpSlotSubType slot_subtype;
|
||||
int len;
|
||||
// int flag; /* UNUSED */
|
||||
// int index; /* index within slot array */ /* UNUSED */
|
||||
@@ -166,8 +189,9 @@ enum {
|
||||
#define MAX_SLOTNAME 32
|
||||
|
||||
typedef struct BMOSlotType {
|
||||
int type;
|
||||
char name[MAX_SLOTNAME];
|
||||
eBMOpSlotType type;
|
||||
eBMOpSlotSubType subtype;
|
||||
} BMOSlotType;
|
||||
|
||||
typedef struct BMOpDefine {
|
||||
|
@@ -127,7 +127,7 @@ void BMO_pop(BMesh *bm)
|
||||
|
||||
|
||||
/* use for both slot_types_in and slot_types_out */
|
||||
static void bmo_op_slots_init(BMOSlotType *slot_types, BMOpSlot *slot_args)
|
||||
static void bmo_op_slots_init(const BMOSlotType *slot_types, BMOpSlot *slot_args)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; slot_types[i].type; i++) {
|
||||
@@ -158,15 +158,15 @@ void BMO_op_init(BMesh *bm, BMOperator *op, const int flag, const char *opname)
|
||||
|
||||
memset(op, 0, sizeof(BMOperator));
|
||||
op->type = opcode;
|
||||
op->type_flag = opdefines[opcode]->type_flag;
|
||||
op->type_flag = bmo_opdefines[opcode]->type_flag;
|
||||
op->flag = flag;
|
||||
|
||||
/* initialize the operator slot types */
|
||||
bmo_op_slots_init(opdefines[opcode]->slot_types_in, op->slots_in);
|
||||
bmo_op_slots_init(opdefines[opcode]->slot_types_out, op->slots_out);
|
||||
bmo_op_slots_init(bmo_opdefines[opcode]->slot_types_in, op->slots_in);
|
||||
bmo_op_slots_init(bmo_opdefines[opcode]->slot_types_out, op->slots_out);
|
||||
|
||||
/* callback */
|
||||
op->exec = opdefines[opcode]->exec;
|
||||
op->exec = bmo_opdefines[opcode]->exec;
|
||||
|
||||
/* memarena, used for operator's slot buffers */
|
||||
op->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
|
||||
@@ -199,7 +199,7 @@ void BMO_op_exec(BMesh *bm, BMOperator *op)
|
||||
BMO_pop(bm);
|
||||
}
|
||||
|
||||
static void bmo_op_slots_free(BMOSlotType *slot_types, BMOpSlot *slot_args)
|
||||
static void bmo_op_slots_free(const BMOSlotType *slot_types, BMOpSlot *slot_args)
|
||||
{
|
||||
BMOpSlot *slot;
|
||||
unsigned int i;
|
||||
@@ -220,13 +220,13 @@ static void bmo_op_slots_free(BMOSlotType *slot_types, BMOpSlot *slot_args)
|
||||
*/
|
||||
void BMO_op_finish(BMesh *bm, BMOperator *op)
|
||||
{
|
||||
bmo_op_slots_free(opdefines[op->type]->slot_types_in, op->slots_in);
|
||||
bmo_op_slots_free(opdefines[op->type]->slot_types_out, op->slots_out);
|
||||
bmo_op_slots_free(bmo_opdefines[op->type]->slot_types_in, op->slots_in);
|
||||
bmo_op_slots_free(bmo_opdefines[op->type]->slot_types_out, op->slots_out);
|
||||
|
||||
BLI_memarena_free(op->arena);
|
||||
|
||||
#ifdef DEBUG
|
||||
BM_ELEM_INDEX_VALIDATE(bm, "post bmo", opdefines[op->type]->opname);
|
||||
BM_ELEM_INDEX_VALIDATE(bm, "post bmo", bmo_opdefines[op->type]->opname);
|
||||
#else
|
||||
(void)bm;
|
||||
#endif
|
||||
@@ -631,7 +631,7 @@ void *bmo_slot_buffer_grow(BMesh *bm, BMOperator *op, int slot_code, int totadd)
|
||||
if (slot->len >= slot->size) {
|
||||
slot->size = (slot->size + 1 + totadd) * 2;
|
||||
|
||||
allocsize = BMO_OPSLOT_TYPEINFO[opdefines[op->type]->slot_types[slot_code].type] * slot->size;
|
||||
allocsize = BMO_OPSLOT_TYPEINFO[bmo_opdefines[op->type]->slot_types[slot_code].type] * slot->size;
|
||||
|
||||
tmp = slot->data.buf;
|
||||
slot->data.buf = MEM_callocN(allocsize, "opslot dynamic array");
|
||||
@@ -646,7 +646,7 @@ void *bmo_slot_buffer_grow(BMesh *bm, BMOperator *op, int slot_code, int totadd)
|
||||
slot->len += totadd;
|
||||
slot->size = slot->len + 2;
|
||||
|
||||
allocsize = BMO_OPSLOT_TYPEINFO[opdefines[op->type]->slot_types[slot_code].type] * slot->len;
|
||||
allocsize = BMO_OPSLOT_TYPEINFO[bmo_opdefines[op->type]->slot_types[slot_code].type] * slot->len;
|
||||
|
||||
tmp = slot->data.buf;
|
||||
slot->data.buf = MEM_callocN(allocsize, "opslot dynamic array");
|
||||
@@ -1393,8 +1393,8 @@ static int bmo_opname_to_opcode(const char *opname)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < bmesh_total_ops; i++) {
|
||||
if (!strcmp(opname, opdefines[i]->opname)) {
|
||||
for (i = 0; i < bmo_opdefines_total; i++) {
|
||||
if (!strcmp(opname, bmo_opdefines[i]->opname)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -1463,7 +1463,7 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const int flag, const char *_fmt, v
|
||||
}
|
||||
|
||||
BMO_op_init(bm, op, flag, opname);
|
||||
// def = opdefines[i];
|
||||
// def = bmo_opdefines[i];
|
||||
|
||||
i = 0;
|
||||
state = 1; /* 0: not inside slot_code name, 1: inside slot_code name */
|
||||
|
@@ -89,8 +89,8 @@ enum {
|
||||
VPATH_SELECT_TOPOLOGICAL
|
||||
};
|
||||
|
||||
extern BMOpDefine *opdefines[];
|
||||
extern int bmesh_total_ops;
|
||||
extern const BMOpDefine *bmo_opdefines[];
|
||||
extern const int bmo_opdefines_total;
|
||||
|
||||
/*------specific operator helper functions-------*/
|
||||
void BM_mesh_esubdivide(BMesh *bm, const char edge_hflag,
|
||||
|
@@ -353,6 +353,10 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *
|
||||
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:
|
||||
{
|
||||
const int size = slot->len;
|
||||
@@ -501,15 +505,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 +523,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 +569,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 +598,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; */
|
||||
|
Reference in New Issue
Block a user