16 #include "../mathutils/mathutils.h"
24 #include "../generic/py_capi_utils.h"
25 #include "../generic/python_utildefines.h"
35 PyErr_Format(PyExc_RuntimeError,
"bmesh operator: %.200s", errmsg);
56 const char *slot_name,
60 PyErr_Format(PyExc_TypeError,
61 "%.200s: keyword \"%.200s\" %.200s, expected a %.200s not *.200s",
66 Py_TYPE(value)->tp_name);
70 PyErr_Format(PyExc_TypeError,
71 "%.200s: keyword \"%.200s\" %.200s invalidated element",
77 if (value->
bm !=
bm) {
78 PyErr_Format(PyExc_TypeError,
79 "%.200s: keyword \"%.200s\" %.200s invalidated element",
100 const char htype_bmo,
103 const char *slot_name,
107 PyErr_Format(PyExc_TypeError,
108 "%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
114 if (value->
bm !=
bm) {
115 PyErr_Format(PyExc_TypeError,
116 "%.200s: keyword \"%.200s\" %.200s, invalidated sequence",
122 if ((htype_py & htype_bmo) == 0) {
125 PyErr_Format(PyExc_TypeError,
126 "%.200s: keyword \"%.200s\" %.200s, expected "
127 "a sequence of %.200s not %.200s",
148 const char *slot_name)
155 PyErr_Format(PyExc_TypeError,
156 "%.200s: keyword \"%.200s\" expected True/False or 0/1, not %.200s",
159 Py_TYPE(value)->tp_name);
171 const char *enum_str = PyUnicode_AsUTF8(value);
173 if (enum_str ==
NULL) {
174 PyErr_Format(PyExc_TypeError,
175 "%.200s: keyword \"%.200s\" expected a string, not %.200s",
178 Py_TYPE(value)->tp_name);
199 const int param = PyC_Long_AsI32(value);
201 if (param == -1 && PyErr_Occurred()) {
202 PyErr_Format(PyExc_TypeError,
203 "%.200s: keyword \"%.200s\" expected an int, not %.200s",
206 Py_TYPE(value)->tp_name);
215 const float param = PyFloat_AsDouble(value);
216 if (param == -1 && PyErr_Occurred()) {
217 PyErr_Format(PyExc_TypeError,
218 "%.200s: keyword \"%.200s\" expected a float, not %.200s",
221 Py_TYPE(value)->tp_name);
238 PyErr_Format(PyExc_TypeError,
239 "%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix",
262 "single element") == -1) {
286 "element buffer") == -1) {
299 "element buffer") == -1) {
312 "element buffer") == -1) {
331 "element buffer") == -1) {
338 tot = Py_TYPE(value)->tp_as_sequence->sq_length(value);
349 else if (PySequence_Check(value)) {
351 Py_ssize_t elem_array_len;
364 if (elem_array ==
NULL) {
369 memcpy(slot->
data.
buf, elem_array,
sizeof(
void *) * elem_array_len);
370 PyMem_FREE(elem_array);
373 PyErr_Format(PyExc_TypeError,
374 "%.200s: keyword \"%.200s\" expected "
375 "a bmesh sequence, list, (htype, flag) pair, not %.200s",
378 Py_TYPE(value)->tp_name);
387 if (!PyDict_Check(value)) {
388 PyErr_Format(PyExc_TypeError,
389 "%.200s: keyword \"%.200s\" expected "
390 "a dict, not %.200s",
393 Py_TYPE(value)->tp_name);
398 if (!PySet_Check(value)) {
399 PyErr_Format(PyExc_TypeError,
400 "%.200s: keyword \"%.200s\" expected "
404 Py_TYPE(value)->tp_name);
411 if (PyDict_Size(value) > 0) {
412 PyObject *arg_key, *arg_value;
413 Py_ssize_t arg_pos = 0;
414 while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
420 "invalid key in dict") == -1) {
429 "invalid value in dict") == -1) {
440 if (PyDict_Size(value) > 0) {
441 PyObject *arg_key, *arg_value;
442 Py_ssize_t arg_pos = 0;
443 while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
451 "invalid key in dict") == -1) {
455 value_f = PyFloat_AsDouble(arg_value);
457 if (value_f == -1.0f && PyErr_Occurred()) {
458 PyErr_Format(PyExc_TypeError,
459 "%.200s: keyword \"%.200s\" expected "
460 "a dict with float values, not %.200s",
463 Py_TYPE(arg_value)->tp_name);
473 if (PyDict_Size(value) > 0) {
474 PyObject *arg_key, *arg_value;
475 Py_ssize_t arg_pos = 0;
476 while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
484 "invalid key in dict") == -1) {
488 value_i = PyC_Long_AsI32(arg_value);
490 if (value_i == -1 && PyErr_Occurred()) {
491 PyErr_Format(PyExc_TypeError,
492 "%.200s: keyword \"%.200s\" expected "
493 "a dict with int values, not %.200s",
496 Py_TYPE(arg_value)->tp_name);
506 if (PyDict_Size(value) > 0) {
507 PyObject *arg_key, *arg_value;
508 Py_ssize_t arg_pos = 0;
509 while (PyDict_Next(value, &arg_pos, &arg_key, &arg_value)) {
517 "invalid key in dict") == -1) {
521 value_i = PyC_Long_AsI32(arg_value);
523 if (value_i == -1 && PyErr_Occurred()) {
524 PyErr_Format(PyExc_TypeError,
525 "%.200s: keyword \"%.200s\" expected "
526 "a dict with bool values, not %.200s",
529 Py_TYPE(arg_value)->tp_name);
539 if (PySet_Size(value) > 0) {
541 Py_ssize_t arg_pos = 0;
542 Py_ssize_t arg_hash = 0;
543 while (_PySet_NextEntry(value, &arg_pos, &arg_key, &arg_hash)) {
550 "invalid key in set") == -1) {
561 PyErr_Format(PyExc_NotImplementedError,
562 "This arguments mapping subtype %d is not supported",
571 PyErr_Format(PyExc_NotImplementedError,
572 "%.200s: keyword \"%.200s\" type %d not working yet!",
590 PyObject *item =
NULL;
611 item = Py_INCREF_RET(Py_None);
623 item = PyList_New(
size);
624 for (j = 0; j <
size; j++) {
637 item = _PyDict_NewPresized(slot_hash ?
BLI_ghash_len(slot_hash) : 0);
646 PyDict_SetItem(item, py_key, py_val);
654 item = _PyDict_NewPresized(slot_hash ?
BLI_ghash_len(slot_hash) : 0);
661 PyObject *py_val = PyFloat_FromDouble(*(
float *)&ele_val);
663 PyDict_SetItem(item, py_key, py_val);
671 item = _PyDict_NewPresized(slot_hash ?
BLI_ghash_len(slot_hash) : 0);
678 PyObject *py_val = PyLong_FromLong(*(
int *)&ele_val);
680 PyDict_SetItem(item, py_key, py_val);
688 item = _PyDict_NewPresized(slot_hash ?
BLI_ghash_len(slot_hash) : 0);
695 PyObject *py_val = PyBool_FromLong(*(
bool *)&ele_val);
697 PyDict_SetItem(item, py_key, py_val);
705 item = PySet_New(
NULL);
712 PySet_Add(item, py_key);
721 item = Py_INCREF_RET(Py_None);
740 if ((PyTuple_GET_SIZE(args) == 1) && (py_bm = (
BPy_BMesh *)PyTuple_GET_ITEM(args, 0)) &&
746 PyErr_SetString(PyExc_ValueError,
"bmesh created with 'use_operators=False'");
754 PyErr_SetString(PyExc_TypeError,
755 "bmesh operators expect a single BMesh positional argument, all other args "
764 if (kw && PyDict_Size(kw) > 0) {
768 PyObject *key, *value;
770 while (PyDict_Next(kw, &
pos, &key, &value)) {
771 const char *slot_name = PyUnicode_AsUTF8(key);
775 PyErr_Format(PyExc_TypeError,
776 "%.200s: keyword \"%.200s\" is invalid for this operator",
800 ret = Py_INCREF_RET(Py_None);
816 item = Py_INCREF_RET(Py_None);
823 const char *ch = strchr(slot->
slot_name,
'.');
826 memcpy(slot_name_strip, slot->
slot_name, tot);
827 slot_name_strip[tot] =
'\0';
828 PyDict_SetItemString(
ret, slot_name_strip, item);
BLI_INLINE void * BLI_ghashIterator_getKey(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
#define GHASH_ITER(gh_iter_, ghash_)
unsigned int BLI_ghash_len(const GHash *gh) ATTR_WARN_UNUSED_RESULT
void BMO_error_clear(BMesh *bm)
bool BMO_error_occurred_at_level(BMesh *bm, eBMOpErrorLevel level)
void bool BMO_error_get(BMesh *bm, const char **r_msg, BMOperator **r_op, eBMOpErrorLevel *r_level)
const char bm_iter_itype_htype_map[BM_ITYPE_MAX]
ATTR_WARN_UNUSED_RESULT BMesh const char itype
ATTR_WARN_UNUSED_RESULT BMesh * bm
void * BMO_slot_buffer_alloc(BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, int len)
#define BMO_SLOT_AS_VECTOR(slot)
void BMO_slot_mat_set(BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, const float *mat, int size)
#define BMO_SLOT_AS_FLOAT(slot)
@ BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE
@ BMO_OP_SLOT_ELEMENT_BUF
void * BMO_slot_buffer_get_single(BMOpSlot *slot)
void BMO_slot_buffer_from_single(BMOperator *op, BMOpSlot *slot, BMHeader *ele)
void BMO_op_exec(BMesh *bm, BMOperator *op)
BMESH OPSTACK EXEC OP.
#define BMO_SLOT_AS_BUFFER(slot)
@ BMO_OP_SLOT_SUBTYPE_MAP_ELEM
@ BMO_OP_SLOT_SUBTYPE_MAP_BOOL
@ BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL
@ BMO_OP_SLOT_SUBTYPE_MAP_INT
@ BMO_OP_SLOT_SUBTYPE_MAP_EMPTY
@ BMO_OP_SLOT_SUBTYPE_MAP_FLT
@ BMO_OP_SLOT_SUBTYPE_INT_FLAG
@ BMO_OP_SLOT_SUBTYPE_INT_ENUM
#define BMO_SLOT_AS_GHASH(slot)
void BMO_op_init(BMesh *bm, BMOperator *op, int flag, const char *opname)
BMESH OPSTACK INIT OP.
#define BMO_SLOT_AS_BOOL(slot)
#define BMO_SLOT_AS_MATRIX(slot)
void BMO_op_finish(BMesh *bm, BMOperator *op)
BMESH OPSTACK FINISH OP.
BMOpSlot * BMO_slot_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK GET SLOT.
void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype)
BMO_ALL_TO_SLOT.
#define BMO_FLAG_DEFAULTS
bool BMO_slot_exists(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *identifier)
BMESH OPSTACK HAS SLOT.
#define BMO_SLOT_AS_INT(slot)
BLI_INLINE void BMO_slot_map_int_insert(BMOperator *op, BMOpSlot *slot, void *element, const int val)
BLI_INLINE void BMO_slot_map_elem_insert(BMOperator *op, BMOpSlot *slot, const void *element, void *val)
BLI_INLINE void BMO_slot_map_float_insert(BMOperator *op, BMOpSlot *slot, void *element, const float val)
BLI_INLINE void BMO_slot_map_empty_insert(BMOperator *op, BMOpSlot *slot, const void *element)
BLI_INLINE void BMO_slot_map_bool_insert(BMOperator *op, BMOpSlot *slot, void *element, const bool val)
BLI_STATIC_ASSERT(sizeof(PyC_FlagSet)==sizeof(BMO_FlagSet), "size mismatch")
PyObject * BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw)
static PyObject * bpy_slot_to_py(BMesh *bm, BMOpSlot *slot)
static int bpy_bm_op_as_py_error(BMesh *bm)
static int bpy_slot_from_py_elemseq_check(BPy_BMGeneric *value, BMesh *bm, const char htype_py, const char htype_bmo, const char *opname, const char *slot_name, const char *descr)
Utility function to check BMVertSeq/BMEdgeSeq/BMFaceSeq's.
static int bpy_slot_from_py_elem_check(BPy_BMElem *value, BMesh *bm, const char htype, const char *opname, const char *slot_name, const char *descr)
Utility function to check BMVert/BMEdge/BMFace's.
static int bpy_slot_from_py(BMesh *bm, BMOperator *bmop, BMOpSlot *slot, PyObject *value, const char *opname, const char *slot_name)
PyObject * BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele)
char * BPy_BMElem_StringFromHType_ex(const char htype, char ret[32])
char * BPy_BMElem_StringFromHType(const char htype)
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 bool do_unique_check, const bool do_bm_check, const char *error_prefix)
#define BPY_BM_CHECK_OBJ(obj)
#define BPy_BMVertSeq_Check(v)
#define BPy_BMFaceSeq_Check(v)
#define BPy_BMElemSeq_Check(v)
#define BPy_BMElem_Check(v)
#define BPy_BMesh_Check(v)
#define BPy_BMEdgeSeq_Check(v)
#define BM_ITER_BPY_BM_SEQ(ele, iter, bpy_bmelemseq)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
ccl_global float * buffer
int mathutils_array_parse(float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
int Matrix_ParseAny(PyObject *o, void *p)
PyObject * Matrix_CreatePyObject(const float *mat, const ushort col_num, const ushort row_num, PyTypeObject *base_type)
PyObject * Vector_CreatePyObject(const float *vec, const int vec_num, PyTypeObject *base_type)
int PyC_FlagSet_ValueFromID(const PyC_FlagSet *item, const char *identifier, int *r_value, const char *error_prefix)
int PyC_Long_AsBool(PyObject *value)
int PyC_FlagSet_ToBitfield(const PyC_FlagSet *items, PyObject *value, int *r_value, const char *error_prefix)
eBMOpSlotSubType_Union slot_subtype
struct BMOpSlot::@145::@146 enum_data
union BMOpSlot::@145 data
struct BMOpSlot slots_out[BMO_OP_MAX_SLOTS]
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
PyObject_VAR_HEAD struct BMesh * bm
PyObject_VAR_HEAD struct BMesh * bm
PyObject_VAR_HEAD struct BMesh * bm
eBMOpSlotSubType_Int intg
eBMOpSlotSubType_Elem elem