[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18620] branches/bmesh/blender/source/ blender/bmesh: added operator slot iterators

Joseph Eagar joeedh at gmail.com
Thu Jan 22 13:29:14 CET 2009


Revision: 18620
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18620
Author:   joeedh
Date:     2009-01-22 13:29:08 +0100 (Thu, 22 Jan 2009)

Log Message:
-----------
added operator slot iterators

Modified Paths:
--------------
    branches/bmesh/blender/source/blender/bmesh/bmesh.h
    branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
    branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
    branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c
    branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
    branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh.h	2009-01-22 10:53:22 UTC (rev 18619)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh.h	2009-01-22 12:29:08 UTC (rev 18620)
@@ -107,7 +107,7 @@
 	void *data;
 } BMNode;
 
-struct Scene;
+struct bmop_error;
 typedef struct BMesh {
 	ListBase verts, edges, polys;
 	struct BLI_mempool *vpool;
@@ -126,6 +126,7 @@
 	struct BLI_mempool *flagpool;					/*memory pool for dynamically allocated flag layers*/
 	int stackdepth;									/*current depth of operator stack*/
 	int totflags, walkers;							/*total number of tool flag layers*/
+	ListBase errorstack; /*privately used by the operator error reporting system*/
 } BMesh;
 
 typedef struct BMVert {	

Modified: branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-01-22 10:53:22 UTC (rev 18619)
+++ branches/bmesh/blender/source/blender/bmesh/bmesh_operators.h	2009-01-22 12:29:08 UTC (rev 18620)
@@ -30,6 +30,30 @@
 	} data;
 }BMOpSlot;
 
+/*these macros are used for iterating over slot buffers.
+  for example:
+  int i;
+
+  for (ptr=BMOS_IterNewP(i, slot); ptr; ptr=BMOS_IterStepP(i, slot)) {
+  }
+
+  int ival;
+  for (ival=BMOS_IterNewI(i, slot); !BMOS_IterDoneI(i, slot); ival=BMOS_IterStepI(i, slot) {
+  }
+*/
+/*remember, the ',' operator executes all expressions seperated by ','
+  (left to right) but uses the value of the right-most one.*/
+#define BMOS_IterNewP(stateint, slot)	(stateint = 0, slot->len>0 ? *(void**)slot->data.p : NULL)
+#define BMOS_IterStepP(stateint, slot)	(stateint++,stateint>=slot->len ? NULL : ((void**)slot->data.buf)[stateint])
+
+#define BMOS_IterNewF(stateint, slot)	(stateint = 0, slot->len>0 ? *(float*)slot->data.p : NULL)
+#define BMOS_IterDoneF(stateint, slot)	(stateint >= slot->len)
+#define BMOS_IterStepF(stateint, slot)	(stateint++,stateint>=slot->len ? NULL : ((float*)slot->data.buf)[stateint])
+
+#define BMOS_IterNewI(stateint, slot)	(stateint = 0, slot->len>0 ? *(int*)slot->data.p : NULL)
+#define BMOS_IterDoneI(stateint, slot)	(stateint >= slot->len)
+#define BMOS_IterStepI(stateint, slot)	(stateint++,stateint>=slot->len ? NULL : ((int*)slot->data.buf)[stateint])
+
 /*operators represent logical, executable mesh modules.*/
 #define BMOP_MAX_SLOTS			16		/*way more than probably needed*/
 
@@ -73,6 +97,26 @@
 void BMO_Flag_Buffer(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag);
 void BMO_HeaderFlag_To_Slot(struct BMesh *bm, struct BMOperator *op, int slotcode, int flag, int type);
 
+/*if msg is null, then the default message for the errorcode is used*/
+void BMOP_RaiseError(BMesh *bm, int errcode, char *msg);
+/*returns error code or 0 if no error*/
+int BMOP_GetError(BMesh *bm, char **msg);
+/*returns 1 if there was an error*/
+int BMOP_CheckError(BMesh *bm);
+int BMOP_PopError(BMesh *bm, char **msg);
+
+/*------ error code defines -------*/
+
+/*error messages*/
+#define BMERR_SELF_INTERSECTING	1
+
+static char *bmop_error_messages[] = {
+	0,
+	"Self intersection error",
+};
+
+#define BMERR_TOTAL (sizeof(error_messages) / sizeof(void*) - 1)
+
 /*------------begin operator defines (see bmesh_opdefines.c too)------------*/
 /*split op*/
 #define BMOP_SPLIT				0

Modified: branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-01-22 10:53:22 UTC (rev 18619)
+++ branches/bmesh/blender/source/blender/bmesh/intern/bmesh_operators.c	2009-01-22 12:29:08 UTC (rev 18620)
@@ -2,6 +2,7 @@
 
 #include "BLI_memarena.h"
 #include "BLI_mempool.h"
+#include "BLI_blenlib.h"
 
 #include "BKE_utildefines.h"
 
@@ -31,6 +32,46 @@
 	sizeof(void*)	/* pointer buffer */
 };
 
+/*error system*/
+typedef struct bmop_error {
+	struct bmop_error *next, *prev;
+	int errorcode;
+	char *msg;
+} bmop_error;
+
+void BMOP_RaiseError(BMesh *bm, int errcode, char *msg)
+{
+	bmop_error *err = MEM_callocN(sizeof(bmop_error), "bmop_error");
+	err->errorcode = errcode;
+	err->msg = msg;
+	BLI_addhead(&bm->errorstack, err);
+}
+
+/*returns error code or 0 if no error*/
+int BMOP_GetError(BMesh *bm, char **msg)
+{
+	bmop_error *err = bm->errorstack.first;
+	if (!err) return 0;
+	
+	if (msg) *msg = err->msg;
+
+	return err->errorcode;
+}
+
+int BMOP_CheckError(BMesh *bm)
+{
+	return bm->errorstack.first != NULL;
+}
+
+int BMOP_PopError(BMesh *bm, char **msg) 
+{
+	int errorcode = BMOP_GetError(bm, msg);
+	if (errorcode)
+		BLI_remlink(&bm->errorstack, &bm->errorstack.first);
+
+	return errorcode;
+}
+
 /*
  * BMESH OPSTACK PUSH
  *

Modified: branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c	2009-01-22 10:53:22 UTC (rev 18619)
+++ branches/bmesh/blender/source/blender/bmesh/operators/dissolveops.c	2009-01-22 12:29:08 UTC (rev 18620)
@@ -43,8 +43,7 @@
 	}
 	*/
 
-	for (i=0; i<vinput->len; i++) {
-		vert = ((BMVert**)vinput->data.p)[i];
+	for (vert=BMOS_IterNewP(i, vinput); vert; vert = BMOS_IterStepP(i, vinput)) {
 		BM_Dissolve_Disk(bmesh, vert);
 	}
 }
\ No newline at end of file

Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2009-01-22 10:53:22 UTC (rev 18619)
+++ branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c	2009-01-22 12:29:08 UTC (rev 18620)
@@ -250,8 +250,7 @@
 	einput = BMO_GetSlot(op, BMOP_ESUBDIVIDE_EDGES);
 
 	/*first go through and split edges*/
-	for (i=0; i<einput->len; i++) {
-		edge = ((BMEdge**)einput->data.p)[i];
+	for (edge=BMOS_IterNewP(i, einput); edge; edge = BMOS_IterStepP(i, einput)) {
 		v1 = BM_Split_Edge(bmesh, edge->v1, edge, &nedge, 0.5, 1);
 		BMO_SetFlag(bmesh, v1, SUBD_SPLIT);
 		BMO_SetFlag(bmesh, nedge, SUBD_SPLIT);

Modified: branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c
===================================================================
--- branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c	2009-01-22 10:53:22 UTC (rev 18619)
+++ branches/bmesh/blender/source/blender/bmesh/operators/triangulateop.c	2009-01-22 12:29:08 UTC (rev 18620)
@@ -19,10 +19,8 @@
 	int i, count = 0;
 	
 	finput = BMO_GetSlot(op, BMOP_ESUBDIVIDE_EDGES);
-
-	for (i=0; i<finput->len; i++) {
-		face = ((BMFace**)finput->data.p)[i];
-
+	
+	for (face=BMOS_IterNewP(i, finput); face; face=BMOS_IterStepP(i, finput)) {
 		/*HACK! need to discuss with Briggs why the function takes an 
 		  externally-allocated array of vert coordinates in the first place.*/
 		if (face->len > 400) projverts = MEM_callocN(sizeof(float)*3*face->len, "projverts");





More information about the Bf-blender-cvs mailing list