[Bf-blender-cvs] [1e6a5eb0879] blender2.8: Implement BMesh Operator string enumerators and docs generation.
Andrew Hale
noreply at git.blender.org
Mon Aug 27 16:18:34 CEST 2018
Commit: 1e6a5eb0879119808fde8f002eed5ac7909944ec
Author: Andrew Hale
Date: Mon Aug 27 15:51:27 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB1e6a5eb0879119808fde8f002eed5ac7909944ec
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
===================================================================
M doc/python_api/rst_from_bmesh_opdefines.py
M source/blender/bmesh/intern/bmesh_opdefines.c
M source/blender/bmesh/intern/bmesh_operator_api.h
M source/blender/bmesh/intern/bmesh_operators.c
M source/blender/python/bmesh/bmesh_py_ops.c
M source/blender/python/bmesh/bmesh_py_ops_call.c
===================================================================
diff --git a/doc/python_api/rst_from_bmesh_opdefines.py b/doc/python_api/rst_from_bmesh_opdefines.py
index d3e4b2a0cfd..8357d063429 100644
--- a/doc/python_api/rst_from_bmesh_opdefines.py
+++ b/doc/python_api/rst_from_bmesh_opdefines.py
@@ -31,6 +31,7 @@
# - campbell
import os
+import re
CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.normpath(os.path.join(CURRENT_DIR, "..", ".."))))
@@ -75,7 +76,8 @@ def main():
for l in fsrc:
l = l[:-1]
# weak but ok
- if ("BMOpDefine" in l and l.split()[1] == "BMOpDefine") and "bmo_opdefines[]" not in l:
+ if ((("BMOpDefine" in l and l.split()[1] == "BMOpDefine") and "bmo_opdefines[]" not in l) or
+ ("static BMO_FlagSet " in l)):
is_block = True
block_ctx = []
blocks.append((comment_ctx, block_ctx))
@@ -92,9 +94,12 @@ def main():
if cpp_comment != -1:
l = l[:cpp_comment]
+ # remove sentinel from enums
+ l = l.replace("{0, NULL}", "")
+
block_ctx.append(l)
- if l.strip() == "};":
+ if l.strip().endswith("};"):
is_block = False
comment_ctx = None
@@ -136,6 +141,9 @@ def main():
"BMO_OP_SLOT_SUBTYPE_PTR_MESH",
"BMO_OP_SLOT_SUBTYPE_PTR_BMESH",
+ "BMO_OP_SLOT_SUBTYPE_INT_ENUM",
+ "BMO_OP_SLOT_SUBTYPE_INT_FLAG",
+
"BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE",
"BM_VERT",
@@ -160,6 +168,7 @@ def main():
for comment, b in blocks:
# magic, translate into python
b[0] = b[0].replace("static BMOpDefine ", "")
+ is_enum = False
for i, l in enumerate(b):
l = l.strip()
@@ -178,11 +187,35 @@ def main():
# exec func. eg: bmo_rotate_edges_exec,
if l.startswith("bmo_") and l.endswith("_exec,"):
l = "None,"
+
+ # enums
+ if l.startswith("static BMO_FlagSet "):
+ is_enum = True
+
b[i] = l
# for l in b:
# print(l)
+ if is_enum:
+ text = "".join(b)
+ text = text.replace("static BMO_FlagSet ", "")
+ text = text.replace("[]", "")
+ text = text.strip(";")
+ text = text.replace("(", "[").replace(")", "]")
+ text = text.replace("\"", "'")
+
+ k, v = text.split("=", 1)
+
+ v = repr(re.findall(r"'([^']*)'", v))
+
+ k = k.strip()
+ v = v.strip()
+
+ vars_dict[k] = v
+
+ continue
+
text = "\n".join(b)
global_namespace = {
"__file__": "generated",
@@ -225,6 +258,7 @@ def main():
# -- wash the comment
comment_washed = []
+ comment = [] if comment is None else comment
for i, l in enumerate(comment):
assert((l.strip() == "") or
(l in {"/*", " *"}) or
@@ -246,7 +280,9 @@ def main():
args_wash = []
for i in args_index:
arg = args[i]
- if len(arg) == 3:
+ if len(arg) == 4:
+ name, tp, tp_sub, enums = arg
+ elif len(arg) == 3:
name, tp, tp_sub = arg
elif len(arg) == 2:
name, tp = arg
@@ -282,7 +318,12 @@ def main():
if tp == BMO_OP_SLOT_FLT:
tp_str = "float"
elif tp == BMO_OP_SLOT_INT:
- tp_str = "int"
+ if tp_sub == BMO_OP_SLOT_SUBTYPE_INT_ENUM:
+ tp_str = "enum in " + enums + ", default " + enums.split(",", 1)[0].strip("[")
+ elif tp_sub == BMO_OP_SLOT_SUBTYPE_INT_FLAG:
+ tp_str = "set of flags from " + enums + ", default {}"
+ else:
+ tp_str = "int"
elif tp == BMO_OP_SLOT_BOOL:
tp_str = "bool"
elif tp == BMO_OP_SLOT_MAT:
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index ef9c510aea1..c054089480f 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -59,6 +59,8 @@
#include "bmesh.h"
#include "intern/bmesh_operators_private.h"
+#include "DNA_modifier_types.h"
+
/* The formatting of these bmesh operators is parsed by
* 'doc/python_api/rst_from_bmesh_opdefines.py'
* for use in python docs, so reStructuredText may be used
@@ -95,6 +97,32 @@
* note that '//' comments are ignored.
*/
+/* enums shared between multiple operators */
+
+static BMO_FlagSet bmo_enum_axis_xyz[] = {
+ {0, "X"},
+ {1, "Y"},
+ {2, "Z"},
+ {0, NULL},
+};
+
+static BMO_FlagSet bmo_enum_falloff_type[] = {
+ {SUBD_FALLOFF_SMOOTH, "SMOOTH"},
+ {SUBD_FALLOFF_SPHERE, "SPHERE"},
+ {SUBD_FALLOFF_ROOT, "ROOT"},
+ {SUBD_FALLOFF_SHARP, "SHARP"},
+ {SUBD_FALLOFF_LIN, "LINEAR"},
+ {SUBD_FALLOFF_INVSQUARE, "INVERSE_SQUARE"},
+ {0, NULL},
+};
+
+static BMO_FlagSet bmo_enum_compare_types[] = {
+ {SIM_CMP_EQ, "EQUAL"},
+ {SIM_CMP_GT, "GREATER_THAN"},
+ {SIM_CMP_LT, "LESS_THAN"},
+ {0, NULL},
+};
+
/*
* Vertex Smooth.
*
@@ -290,7 +318,7 @@ static BMOpDefine bmo_mirror_def = {
{{"geom", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT | BM_EDGE | BM_FACE}}, /* input geometry */
{"matrix", BMO_OP_SLOT_MAT}, /* matrix defining the mirror transformation */
{"merge_dist", BMO_OP_SLOT_FLT}, /* maximum distance for merging. does no merging if 0. */
- {"axis", BMO_OP_SLOT_INT}, /* the axis to use, 0, 1, or 2 for x, y, z */
+ {"axis", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM}, bmo_enum_axis_xyz}, /* the axis to use. */
{"mirror_u", BMO_OP_SLOT_BOOL}, /* mirror UVs across the u axis */
{"mirror_v", BMO_OP_SLOT_BOOL}, /* mirror UVs across the v axis */
{{'\0'}},
@@ -1110,6 +1138,15 @@ static BMOpDefine bmo_dissolve_faces_def = {
BMO_OPTYPE_FLAG_SELECT_VALIDATE),
};
+static BMO_FlagSet bmo_enum_dissolve_limit_flags[] = {
+ {BMO_DELIM_NORMAL, "NORMAL"},
+ {BMO_DELIM_MATERIAL, "MATERIAL"},
+ {BMO_DELIM_SEAM, "SEAM"},
+ {BMO_DELIM_SHARP, "SHARP"},
+ {BMO_DELIM_UV, "UV"},
+ {0, NULL}
+};
+
/*
* Limited Dissolve.
*
@@ -1122,7 +1159,7 @@ static BMOpDefine bmo_dissolve_limit_def = {
{"use_dissolve_boundaries", BMO_OP_SLOT_BOOL},
{"verts", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT}},
{"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}},
- {"delimit", BMO_OP_SLOT_INT},
+ {"delimit", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_FLAG}, bmo_enum_dissolve_limit_flags},
{{'\0'}},
},
/* slots_out */
@@ -1156,6 +1193,20 @@ static BMOpDefine bmo_dissolve_degenerate_def = {
BMO_OPTYPE_FLAG_SELECT_VALIDATE),
};
+static BMO_FlagSet bmo_enum_triangulate_quad_method[] = {
+ {MOD_TRIANGULATE_QUAD_BEAUTY, "BEAUTY"},
+ {MOD_TRIANGULATE_QUAD_FIXED, "FIXED"},
+ {MOD_TRIANGULATE_QUAD_ALTERNATE, "ALTERNATE"},
+ {MOD_TRIANGULATE_QUAD_SHORTEDGE, "SHORT_EDGE"},
+ {0, NULL},
+};
+
+static BMO_FlagSet bmo_enum_triangulate_ngon_method[] = {
+ {MOD_TRIANGULATE_NGON_BEAUTY, "BEAUTY"},
+ {MOD_TRIANGULATE_NGON_EARCLIP, "EAR_CLIP"},
+ {0, NULL},
+};
+
/*
* Triangulate.
*/
@@ -1163,8 +1214,8 @@ static BMOpDefine bmo_triangulate_def = {
"triangulate",
/* slots_in */
{{"faces", BMO_OP_SLOT_ELEMENT_BUF, {BM_FACE}},
- {"quad_method", BMO_OP_SLOT_INT},
- {"ngon_method", BMO_OP_SLOT_INT},
+ {"quad_method", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM}, bmo_enum_triangulate_quad_method},
+ {"ngon_method", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM}, bmo_enum_triangulate_ngon_method},
{{'\0'}},
},
/* slots_out */
@@ -1200,6 +1251,14 @@ static BMOpDefine bmo_unsubdivide_def = {
BMO_OPTYPE_FLAG_SELECT_VALIDATE),
};
+static BMO_FlagSet bmo_enum_subdivide_edges_quad_corner_type[] = {
+ {SUBD_CORNER_STRAIGHT_CUT, "STRAIGHT_CUT"},
+ {SUBD_CORNER_INNERVERT, "INNER_VERT"},
+ {SUBD_CORNER_PATH, "PATH"},
+ {SUBD_CORNER_FAN, "FAN"},
+ {0, NULL},
+};
+
/*
* Subdivide Edges.
*
@@ -1211,15 +1270,14 @@ static BMOpDefine bmo_subdivide_edges_def = {
/* slots_in */
{{"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}},
{"smooth", BMO_OP_SLOT_FLT},
- {"smooth_falloff", BMO_OP_SLOT_INT}, /* SUBD_FALLOFF_ROOT and friends */
+ {"smooth_falloff", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM}, bmo_enum_falloff_type}, /* smooth falloff type */
{"fractal", BMO_OP_SLOT_FLT},
{"along_normal", BMO_OP_SLOT_FLT},
{"cuts", BMO_OP_SLOT_INT},
{"seed", BMO_OP_SLOT_INT},
{"custom_patterns", BMO_OP_SLOT_MAPPING, {(int)BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL}}, /* uses custom pointers */
{"edge_percents", BMO_OP_SLOT_MAPPING, {(int)BMO_OP_SLOT_SUBTYPE_MAP_FLT}},
-
- {"quad_corner_type", BMO_OP_SLOT_INT}, /* quad corner type, see bmesh_operators.h */
+ {"quad_corner_type", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM}, bmo_enum_subdivide_edges_quad_corner_type}, /* quad corner type */
{"use_grid_fill", BMO_OP_SLOT_BOOL}, /* fill in fully-selected faces with a grid */
{"use_single_edge", BMO_OP_SLOT_BOOL}, /* tessellate the case of one edge selected in a quad or triangle */
{"use_only_quads", BMO_OP_SLOT_BOOL}, /* only subdivide quads (for loopcut) */
@@ -1241,6 +1299,13 @@ static BMOpDefine bmo_subdivide_edges_def = {
BMO_OPTYPE_FLAG_SELECT_VALIDATE),
};
+static BMO_FlagSet bmo_enum_subdivide_edgering_interp_mode[] = {
+ {SUBD_RING_INTERP_LINEAR, "LINEAR"},
+ {SUBD_RING_INTERP_PATH, "PATH"},
+ {SUBD_RING_INTERP_SURF, "SURFACE"},
+ {0, NULL},
+};
+
/*
* Subdivide Edge-Ring.
*
@@ -1250,10 +1315,10 @@ static BMOpDefine bmo_subdivide_edgering_def = {
"subdivide_edgering",
/* slots_in */
{{"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, /* input vertices */
- {"interp_mode", BMO_OP_SLOT_INT},
+ {"interp_mode", BMO_OP_SLOT_INT, {(int)BMO_OP_SLOT_SUBTYPE_INT_ENUM}, bmo_enum_subdivide_edgering_interp_mode}, /* interpolation method */
{"smooth", BMO_OP_SLOT_FLT},
{"cuts", BMO_OP_SLOT_INT},
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list