diff options
author | Joseph Eagar <joeedh@gmail.com> | 2009-03-02 07:08:24 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2009-03-02 07:08:24 +0300 |
commit | 1bc67f36d682bb4e5786dee7adfacdc844f1a539 (patch) | |
tree | e8814c4dddc24f6595bbcb2cab525d9ee548d7ed /source/blender/editors/mesh/bmeshutils.c | |
parent | 3faf2b6db7cbe42c3439cad09b7035a25fa5c6c2 (diff) |
Created a printf-style method of calling operators. I did this to cut down on duplicated
code, and also because calling operators was such a pain. The basic form of the format
is "opname %[code]", where each % matches to an argument.
The codes are fairly simple:
d - int
i - int
f - float
h[v/e/f] - all verts/edges/faces with a certain header flag.
f[v/e/f] - all verts/edges/faces with a certain flag.
For example:
EDBM_CallOpf(em, op, "dissolveverts %hv", BM_SELECT)
will call the dissolve verts operator.
The relevent functions are:
//calls a bmesh operator, doing necassary conversions and error reporting.
int EDBM_CallOpf(EditMesh *em, struct wmOperator *op, char *fmt, ...);
//execute an operator
int BMO_CallOpf(BMesh *bm, char *fmt, ...);
//initializes but doesn't execute an op.
int BMO_InitOpf(BMesh *bm, BMOperator *op, char *fmt, ...);
//vlist version of above.
int BMO_VInitOpf(BMesh *bm, BMOperator *op, char *fmt, va_list vlist);
Note this system is dependant on getting the slot codes from the argument
order. I'd like to make it better, possibly pass in slot names, but that'd
mean actually giving the slots names (which I can do, but wanted to discuss with
Briggs and others what I have now first).
Diffstat (limited to 'source/blender/editors/mesh/bmeshutils.c')
-rw-r--r-- | source/blender/editors/mesh/bmeshutils.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/source/blender/editors/mesh/bmeshutils.c b/source/blender/editors/mesh/bmeshutils.c index 76c10b75db5..2d3a3c9b193 100644 --- a/source/blender/editors/mesh/bmeshutils.c +++ b/source/blender/editors/mesh/bmeshutils.c @@ -26,6 +26,7 @@ * ***** END GPL LICENSE BLOCK ***** */ #include <stdlib.h> +#include <stdarg.h> #include <string.h> #include <math.h> #include <float.h> @@ -88,14 +89,38 @@ #include "mesh_intern.h" #include "bmesh.h" +int EDBM_CallOpf(EditMesh *em, wmOperator *op, char *fmt, ...) +{ + BMesh *bm = editmesh_to_bmesh(em); + BMOperator bmop; + va_list list; + + va_start(list, fmt); + + if (!BMO_VInitOpf(bm, &bmop, fmt, list)) { + BKE_report(op->reports, RPT_ERROR, + "Parse error in EDBM_CallOpf"); + va_end(list); + return 0; + } + + BMO_Exec_Op(bm, &bmop); + BMO_Finish_Op(bm, &bmop); + + va_end(list); + + return EDBM_Finish(bm, em, op); + return 1; +} + /*returns 0 on error, 1 on success*/ -int EDBM_Finish(BMesh *bm, EditMesh *em, wmOperator *op, bContext *c) { +int EDBM_Finish(BMesh *bm, EditMesh *em, wmOperator *op) { EditMesh *em2; char *errmsg; if (BMO_GetError(bm, &errmsg, NULL)) { BKE_report(op->reports, RPT_ERROR, errmsg); - BMO_ClearStack(bm); + BM_Free_Mesh(bm); return 0; } |