[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19183] branches/bmesh/blender/source/ blender: Printf-style method of calling operations now take a modified format string ,

Joseph Eagar joeedh at gmail.com
Wed Mar 4 09:21:11 CET 2009


Revision: 19183
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19183
Author:   joeedh
Date:     2009-03-04 09:21:10 +0100 (Wed, 04 Mar 2009)

Log Message:
-----------
Printf-style method of calling operations now take a modified format string,
like so:

[opname] [slotname]=%[format code]

Before it was relying on the input format codes being in the same proper
order as the slots, which seemed like a potential maintainance nightmare to
me.  Also the flags for creating buffers from bmop flags or header flags,
now support additional modifiers for combining vert/edge/face inputs.
E.g. %hfvef would accept all geometry with a header flag, and 
%fef would accept edges and faces with a certain bmop flag set.

Example from the UI code:

if (!EDBM_CallOpf(em, op, "del geom=%hf context=%d", BM_SELECT, DEL_ONLYFACES))
			return OPERATOR_CANCELLED;
			
(remember EDBM_CallOpf is the UI wrapper for this that does conversion, 
 error reporting, etc).  
 
 On todo is cleaning up/splitting bmesh_operators.h,
 since it's kindof a mesh right now.  I'm thinking of adding the slot
 names in comments next to the slot ids, but I definitely would have to
 clean up bmesh_operators.h first, or it'd just be too chaotic for me.
 BTW, the operator API should now have enough meta info to wrap with
 a scripting language, not that it matters since that's not happening till
 much much later.
 
 Also hopefully corrected some SConscripts, fix mostly provided by Elia Sarti,
 though I also copied some SConscripts from 2.5 (not sure if doing
 so was especially helpful).
 
 Finally, I refactored a few places to use the new operator calling api,
 as an example of how this is beneficial.

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/SConscript
    branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_polygon.c
    branches/bmesh/blender/source/blender/bmesh/operators/extrudeops.c
    branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
    branches/bmesh/blender/source/blender/editors/mesh/bmeshutils.c
    branches/bmesh/blender/source/blender/editors/mesh/editmesh_tools.c
    branches/bmesh/blender/source/blender/editors/mesh/mesh_intern.h
    branches/bmesh/blender/source/blender/windowmanager/SConscript

Modified: branches/bmesh/blender/source/blender/SConscript
===================================================================
--- branches/bmesh/blender/source/blender/SConscript	2009-03-03 14:31:10 UTC (rev 19182)
+++ branches/bmesh/blender/source/blender/SConscript	2009-03-04 08:21:10 UTC (rev 19183)
@@ -3,7 +3,7 @@
 import sys
 
 SConscript(['avi/SConscript',
-			'bmesh/SConscript',
+            'bmesh/SConscript',
             'blenkernel/SConscript',
             'blenlib/SConscript',
             'blenloader/SConscript',

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-03-03 14:31:10 UTC (rev 19182)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-03-04 08:21:10 UTC (rev 19183)
@@ -51,10 +51,17 @@
 	MemArena *arena;
 }BMOperator;
 
+#define MAX_SLOTNAME	32
+
+typedef struct slottype {
+	int type;
+	char name[MAX_SLOTNAME];
+} slottype;
+
 /*need to refactor code to use this*/
 typedef struct BMOpDefine {
 	char *name;
-	int slottypes[BMOP_MAX_SLOTS];
+	slottype slottypes[BMOP_MAX_SLOTS];
 	void (*exec)(BMesh *bm, BMOperator *op);
 	int totslot;
 	int flag;
@@ -326,7 +333,9 @@
 	       int flag, int numcuts, int seltype);
 void BM_extrudefaceflag(BMesh *bm, int flag);
 
-/*these next two return 1 if they did anything, or zero otherwise.*/
+/*these next two return 1 if they did anything, or zero otherwise.
+  they're kindof a hackish way to integrate with fkey, until
+  such time as fkey is completely bmeshafied.*/
 int BM_DissolveFaces(struct EditMesh *em, int flag);
 /*this doesn't display errors to the user, btw*/
 int BM_ConnectVerts(struct EditMesh *em, int flag);

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2009-03-03 14:31:10 UTC (rev 19182)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_mods.c	2009-03-04 08:21:10 UTC (rev 19183)
@@ -103,10 +103,11 @@
 		  increasing valence to four.  this may be hackish. . .*/
 		loop = e->loop;
 		if (loop->v == v) loop = (BMLoop*) loop->head.next;
-		BM_Split_Face(bm, loop->f, v, loop->v, NULL, NULL, 0);
+		if (!BM_Split_Face(bm, loop->f, v, loop->v, NULL, NULL, 0))
+			return 0;
 
 		BM_Dissolve_Disk(bm, v);
-		return;
+		return 1;
 	} else if (keepedge == NULL && len == 2) {
 		/*handle two-valence*/
 		f = v->edge->loop->f;
@@ -114,6 +115,8 @@
 		/*collapse the vertex*/
 		BM_Collapse_Vert(bm, v->edge, v, 1.0, 0);
 		BM_Join_Faces(bm, f, f2, NULL, 0, 0);
+
+		return 1;
 	}
 
 	if(keepedge){
@@ -143,11 +146,14 @@
 		/*get remaining two faces*/
 		f = v->edge->loop->f;
 		f2 = ((BMLoop*)v->edge->loop->radial.next->data)->f;
+
 		/*collapse the vertex*/
 		BM_Collapse_Vert(bm, baseedge, v, 1.0, 0);
-
-		/*join two remaining faces*/
-		BM_Join_Faces(bm, f, f2, NULL, 0, 0);
+		
+		if (f != f2) {
+			/*join two remaining faces*/
+			if (!BM_Join_Faces(bm, f, f2, NULL, 0, 0)) return 0;
+		}
 	}
 
 	return 1;

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-03-03 14:31:10 UTC (rev 19182)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_opdefines.c	2009-03-04 08:21:10 UTC (rev 19183)
@@ -5,8 +5,8 @@
 
 BMOpDefine def_connectverts = {
 	"connectvert",
-	{BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_PNT_BUF},
+	{{BMOP_OPSLOT_PNT_BUF, "verts"},
+	{BMOP_OPSLOT_PNT_BUF, "edgeout"}},
 	connectverts_exec,
 	BM_CONVERTS_TOTSLOT,
 	0
@@ -14,9 +14,9 @@
 
 BMOpDefine def_extrudefaceregion = {
 	"extrudefaceregion",
-	{BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_MAPPING,
-	 BMOP_OPSLOT_PNT_BUF},
+	{{BMOP_OPSLOT_PNT_BUF, "edgefacein"},
+	{BMOP_OPSLOT_MAPPING, "exclude"},
+	{BMOP_OPSLOT_PNT_BUF, "geomout"}},
 	extrude_edge_context_exec,
 	BMOP_EXFACE_TOTSLOT,
 	0
@@ -32,7 +32,7 @@
 
 BMOpDefine def_dissolvevertsop = {
 	"dissolveverts",
-	{BMOP_OPSLOT_PNT_BUF},
+	{{BMOP_OPSLOT_PNT_BUF, "verts"}},
 	dissolveverts_exec,
 	BMOP_DISVERTS_TOTSLOT,
 	0
@@ -40,8 +40,8 @@
 
 BMOpDefine def_dissolvefacesop = {
 	"dissolvefaces",
-	{BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_PNT_BUF},
+	{{BMOP_OPSLOT_PNT_BUF, "faces"},
+	{BMOP_OPSLOT_PNT_BUF, "regionnout"}},
 	dissolvefaces_exec,
 	BMOP_DISFACES_TOTSLOT,
 	0
@@ -50,9 +50,9 @@
 
 BMOpDefine def_triangop = {
 	"triangulate",
-	{BMOP_OPSLOT_PNT_BUF, 
-	 BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_PNT_BUF},
+	{{BMOP_OPSLOT_PNT_BUF, "faces"},
+	{BMOP_OPSLOT_PNT_BUF, "edgeout"},
+	{BMOP_OPSLOT_PNT_BUF, "faceout"}},
 	triangulate_exec,
 	BMOP_TRIANG_TOTSLOT,
 	0
@@ -60,15 +60,15 @@
 
 BMOpDefine def_subdop = {
 	"esubd",
-	{BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_INT,
-	 BMOP_OPSLOT_INT,
-	 BMOP_OPSLOT_FLT,
-	 BMOP_OPSLOT_MAPPING,
-	 BMOP_OPSLOT_MAPPING,
-	 BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_PNT_BUF,
-	 },
+	{{BMOP_OPSLOT_PNT_BUF, "edges"},
+	{BMOP_OPSLOT_INT, "numcuts"},
+	{BMOP_OPSLOT_INT, "flag"},
+	{BMOP_OPSLOT_FLT, "radius"},
+	{BMOP_OPSLOT_MAPPING, "custompatterns"},
+	{BMOP_OPSLOT_MAPPING, "edgepercents"},
+	{BMOP_OPSLOT_PNT_BUF, "outinner"},
+	{BMOP_OPSLOT_PNT_BUF, "outsplit"},
+	},
 	esubdivide_exec,
 	BMOP_ESUBDIVIDE_TOTSLOT,
 	0
@@ -76,7 +76,7 @@
 
 BMOpDefine def_edit2bmesh = {
 	"editmesh_to_bmesh",
-	{BMOP_OPSLOT_PNT},
+	{{BMOP_OPSLOT_PNT, "emout"}},
 	edit2bmesh_exec,
 	BMOP_TO_EDITMESH_TOTSLOT,
 	0
@@ -84,7 +84,7 @@
 
 BMOpDefine def_bmesh2edit = {
 	"bmesh_to_editmesh",
-	{BMOP_OPSLOT_PNT},
+	{{BMOP_OPSLOT_PNT, "em"}},
 	bmesh2edit_exec,
 	BMOP_FROM_EDITMESH_TOTSLOT,
 	0
@@ -92,7 +92,7 @@
 
 BMOpDefine def_delop = {
 	"del",
-	{BMOP_OPSLOT_PNT_BUF, BMOP_OPSLOT_INT},
+	{{BMOP_OPSLOT_PNT_BUF, "geom"}, {BMOP_OPSLOT_INT, "context"}},
 	delop_exec,
 	BMOP_DEL_TOTSLOT,
 	0
@@ -100,8 +100,10 @@
 
 BMOpDefine def_dupeop = {
 	"dupe",
-	{BMOP_OPSLOT_PNT_BUF, BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_PNT_BUF, BMOP_OPSLOT_MAPPING},
+	{{BMOP_OPSLOT_PNT_BUF, "geom"},
+	{BMOP_OPSLOT_PNT_BUF, "origout"},
+	{BMOP_OPSLOT_PNT_BUF, "newout"},
+	{BMOP_OPSLOT_MAPPING, "boundarymap"}},
 	dupeop_exec,
 	BMOP_DUPE_TOTSLOT,
 	0
@@ -109,8 +111,9 @@
 
 BMOpDefine def_splitop = {
 	"split",
-	{BMOP_OPSLOT_PNT_BUF,
-	 BMOP_OPSLOT_PNT_BUF, BMOP_OPSLOT_MAPPING},
+	{{BMOP_OPSLOT_PNT_BUF, "geom"},
+	{BMOP_OPSLOT_PNT_BUF, "geomout"},
+	{BMOP_OPSLOT_MAPPING, "boundarymap"}},
 	splitop_exec,
 	BMOP_SPLIT_TOTSLOT,
 	0

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-03-03 14:31:10 UTC (rev 19182)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-03-04 08:21:10 UTC (rev 19183)
@@ -93,7 +93,7 @@
 	
 	/*initialize the operator slot types*/
 	for(i = 0; i < opdefines[opcode]->totslot; i++) {
-		op->slots[i].slottype = opdefines[opcode]->slottypes[i];
+		op->slots[i].slottype = opdefines[opcode]->slottypes[i].type;
 		op->slots[i].index = i;
 	}
 
@@ -369,8 +369,8 @@
 			slot->size = (slot->size+1+totadd)*2;
 
 			tmp = slot->data.buf;
-			slot->data.buf = MEM_callocN(BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->size, "opslot dynamic array");
-			memcpy(slot->data.buf, tmp, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->size);
+			slot->data.buf = MEM_callocN(BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode].type] * slot->size, "opslot dynamic array");
+			memcpy(slot->data.buf, tmp, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode].type] * slot->size);
 			MEM_freeN(tmp);
 		}
 
@@ -380,8 +380,8 @@
 		slot->len += totadd;
 		slot->size = slot->len+2;
 		tmp = slot->data.buf;
-		slot->data.buf = MEM_callocN(BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->len, "opslot dynamic array");
-		memcpy(slot->data.buf, tmp, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * slot->len);
+		slot->data.buf = MEM_callocN(BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode].type] * slot->len, "opslot dynamic array");
+		memcpy(slot->data.buf, tmp, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode].type] * slot->len);
 	}
 
 	return slot->data.buf;
@@ -493,7 +493,7 @@
 	
 	op->slots[slotcode].len = len;
 	if(len)
-		op->slots[slotcode].data.buf = BLI_memarena_alloc(op->arena, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode]] * len);
+		op->slots[slotcode].data.buf = BLI_memarena_alloc(op->arena, BMOP_OPSLOT_TYPEINFO[opdefines[op->type]->slottypes[slotcode].type] * len);
 	return op->slots[slotcode].data.buf;
 }
 
@@ -882,11 +882,27 @@
 
 #define nextc(fmt) ((fmt)[0] != 0 ? (fmt)[1] : 0)
 
+static int bmesh_name_to_slotcode(BMOpDefine *def, char *name)
+{
+	int i;
+
+	for (i=0; i<def->totslot; i++) {
+		if (!strcmp(name, def->slottypes[i].name)) return i;
+	}
+
+	return -1;
+}
+
 int BMO_VInitOpf(BMesh *bm, BMOperator *op, char *fmt, va_list vlist)
 {
-	int i, n=strlen(fmt), slotcode = -1, ret, type;
-	char *opname;
+	int i, n=strlen(fmt), stop, slotcode = -1, ret, type, state, c;
+	char *opname, *ofmt;
+	BMOpDefine *def;
+
+	/*we muck around in here, so dup it*/
+	fmt = ofmt = strdup(fmt);
 	
+	/*find operator name*/
 	i = strcspn(fmt, " \t");
 
 	opname = fmt;
@@ -899,52 +915,95 @@
 	}
 
 	if (i == bmesh_total_ops) return 0;
+	
 	BMO_Init_Op(op, i);
+	def = opdefines[i];
 	
 	i = 0;
+	state = 1; //0: not inside slotcode name, 1: inside slotcode name
+	c = 0;
+	
 	while (*fmt) {
-		switch (*fmt) {
-		case ' ':
-		case '\t':
-			break;
-		case '%':
-			slotcode += 1;
-			break;
-		case 'i':
-		case 'd':
-			BMO_Set_Int(op, slotcode, va_arg(vlist, int));
-			break;
-		case 'f':
-		case 'h':
-			type = *fmt;
+		if (state) {
+			/*jump past leading whitespace*/
+			i = strspn(fmt, " \t");
+			fmt += i;
+			
+			/*ignore trailing whitespace*/
+			if (!fmt[i])
+				break;
 
-			if (nextc(fmt) == ' ' || nextc(fmt) == '\t') {
-				BMO_Set_Float(op,slotcode,va_arg(vlist,float));
-			} else {
-				switch (nextc(fmt)) {
-					case 'f': ret = BM_FACE; break;
-					case 'e': ret = BM_EDGE; break;
-					case 'v': ret = BM_VERT; break;
-					default: goto error;
+			/*find end of slot name.  currently this is
+			  a little flexible, allowing "slot=%f", 
+			  "slot %f", "slot%f", and "slot\t%f". */
+			i = strcspn(fmt, "= \t%");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list