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
This commit is contained in:
2018-08-27 15:51:27 +02:00
parent 09e1e2b8ce
commit 1e6a5eb087
6 changed files with 286 additions and 34 deletions

View File

@@ -75,10 +75,14 @@ static char *bmp_slots_as_args(const BMOSlotType slot_types[BMO_OP_MAX_SLOTS], c
{
DynStr *dyn_str = BLI_dynstr_new();
char *ret;
bool quoted;
bool set;
int i = 0;
while (*slot_types[i].name) {
quoted = false;
set = false;
/* cut off '.out' by using a string size arg */
const int name_len = is_out ?
(strchr(slot_types[i].name, '.') - slot_types[i].name) :
@@ -86,7 +90,19 @@ static char *bmp_slots_as_args(const BMOSlotType slot_types[BMO_OP_MAX_SLOTS], c
const char *value = "<Unknown>";
switch (slot_types[i].type) {
case BMO_OP_SLOT_BOOL: value = "False"; break;
case BMO_OP_SLOT_INT: value = "0"; break;
case BMO_OP_SLOT_INT:
if (slot_types[i].subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_ENUM) {
value = slot_types[i].enum_flags[0].identifier;
quoted = true;
}
else if (slot_types[i].subtype.intg == BMO_OP_SLOT_SUBTYPE_INT_FLAG) {
value = "";
set = true;
}
else {
value = "0";
}
break;
case BMO_OP_SLOT_FLT: value = "0.0"; break;
case BMO_OP_SLOT_PTR: value = "None"; break;
case BMO_OP_SLOT_MAT: value = "Matrix()"; break;
@@ -95,7 +111,11 @@ static char *bmp_slots_as_args(const BMOSlotType slot_types[BMO_OP_MAX_SLOTS], c
(slot_types[i].subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) ? "None" : "[]"; break;
case BMO_OP_SLOT_MAPPING: value = "{}"; break;
}
BLI_dynstr_appendf(dyn_str, i ? ", %.*s=%s" : "%.*s=%s", name_len, slot_types[i].name, value);
BLI_dynstr_appendf(dyn_str, i ? ", %.*s=%s%s%s%s%s" : "%.*s=%s%s%s%s%s",
name_len, slot_types[i].name,
set ? "{" : "", quoted ? "'" : "",
value,
quoted ? "'" : "", set ? "}" : "");
i++;
}

View File

@@ -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;
}