diff options
author | Andrew Hale <TrumanBlending@gmail.com> | 2018-08-27 16:51:27 +0300 |
---|---|---|
committer | Andrew Hale <TrumanBlending@gmail.com> | 2018-08-27 17:15:54 +0300 |
commit | 1e6a5eb0879119808fde8f002eed5ac7909944ec (patch) | |
tree | 599f852c269a9194606aa0b8754dfa4c885fd969 /source/blender/python/bmesh/bmesh_py_ops_call.c | |
parent | 09e1e2b8ce48f7692b0b3f4425a7bcd7d0bec476 (diff) |
Implement BMesh Operator string enumerators and docs generation.
Partial implementation of T56496 for review.
Reviewers: campbellbarton
Reviewed By: campbellbarton
Differential Revision: https://developer.blender.org/D3635
Diffstat (limited to 'source/blender/python/bmesh/bmesh_py_ops_call.c')
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_ops_call.c | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c index 4dce0dc2a22..74d899ba3f8 100644 --- a/source/blender/python/bmesh/bmesh_py_ops_call.c +++ b/source/blender/python/bmesh/bmesh_py_ops_call.c @@ -46,6 +46,8 @@ #include "../generic/python_utildefines.h" #include "../generic/py_capi_utils.h" +BLI_STATIC_ASSERT(sizeof(PyC_FlagSet) == sizeof(BMO_FlagSet), "size mismatch"); + static int bpy_bm_op_as_py_error(BMesh *bm) { if (BMO_error_occurred(bm)) { @@ -169,16 +171,46 @@ static int bpy_slot_from_py( } case BMO_OP_SLOT_INT: { - const int param = PyC_Long_AsI32(value); + if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_ENUM) { + int enum_val = -1; + PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_flags; + const char *enum_str = _PyUnicode_AsString(value); - 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; + if (enum_str == NULL) { + PyErr_Format(PyExc_TypeError, + "%.200s: keyword \"%.200s\" expected a string, not %.200s", + opname, slot_name, Py_TYPE(value)->tp_name); + return -1; + } + + if (PyC_FlagSet_ValueFromID(items, enum_str, &enum_val, slot_name) == -1) { + return -1; + } + + BMO_SLOT_AS_INT(slot) = enum_val; + } + else if (slot->slot_subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_FLAG) { + int flag = 0; + PyC_FlagSet *items = (PyC_FlagSet *)slot->data.enum_flags; + + if (PyC_FlagSet_ToBitfield(items, value, &flag, slot_name) == -1) { + return -1; + } + + BMO_SLOT_AS_INT(slot) = flag; } else { - BMO_SLOT_AS_INT(slot) = param; + const int param = PyC_Long_AsI32(value); + + 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) = param; + } } break; } |