[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44577] trunk/blender/source/blender: style cleanup

Campbell Barton ideasman42 at gmail.com
Thu Mar 1 17:04:45 CET 2012


Revision: 44577
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44577
Author:   campbellbarton
Date:     2012-03-01 16:04:37 +0000 (Thu, 01 Mar 2012)
Log Message:
-----------
style cleanup
* add extra argument to BMO_slot_map_to_flag() to filter by vert/edge/face
* made BMO_slot_map_* / BMO_slot_buffer_* functions stricter with type checking.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/bmesh_operator_api.h
    trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.c
    trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
    trunk/blender/source/blender/bmesh/intern/bmesh_structure.c
    trunk/blender/source/blender/bmesh/operators/bmo_extrude.c
    trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c
    trunk/blender/source/blender/editors/mesh/bmesh_select.c
    trunk/blender/source/blender/editors/mesh/bmesh_tools.c

Modified: trunk/blender/source/blender/bmesh/bmesh_operator_api.h
===================================================================
--- trunk/blender/source/blender/bmesh/bmesh_operator_api.h	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/bmesh/bmesh_operator_api.h	2012-03-01 16:04:37 UTC (rev 44577)
@@ -327,8 +327,8 @@
 
 /* flags all elements in a mapping.  note that the mapping must only have
  * bmesh elements in it.*/
-void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op,
-                          const char *slotname, const short oflag);
+void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slotname,
+                          const short oflag, const char hflag);
 
 /* this part of the API is used to iterate over element buffer or
  * mapping slots.

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.c	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operator_api_inline.c	2012-03-01 16:04:37 UTC (rev 44577)
@@ -88,7 +88,7 @@
 BM_INLINE void BMO_slot_map_ptr_insert(BMesh *bm, BMOperator *op, const char *slotname,
                                        void *element, void *val)
 {
-	BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(void*));
+	BMO_slot_map_insert(bm, op, slotname, element, &val, sizeof(void *));
 }
 
 BM_INLINE int BMO_slot_map_contains(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, void *element)
@@ -96,7 +96,12 @@
 	BMOpSlot *slot = BMO_slot_get(op, slotname);
 
 	/*sanity check*/
-	if (slot->slottype != BMO_OP_SLOT_MAPPING) return 0;
+	if (slot->slottype != BMO_OP_SLOT_MAPPING) {
+#ifdef DEBUG
+		printf("%s: invalid type %d\n", __func__, slot->slottype);
+#endif
+		return 0;
+	}
 	if (!slot->data.ghash) return 0;
 
 	return BLI_ghash_haskey(slot->data.ghash, element);
@@ -109,7 +114,12 @@
 	BMOpSlot *slot = BMO_slot_get(op, slotname);
 
 	/*sanity check*/
-	if (slot->slottype != BMO_OP_SLOT_MAPPING) return NULL;
+	if (slot->slottype != BMO_OP_SLOT_MAPPING) {
+#ifdef DEBUG
+		printf("%s: invalid type %d\n", __func__, slot->slottype);
+#endif
+		return NULL;
+	}
 	if (!slot->data.ghash) return NULL;
 
 	mapping = (BMOElemMapping *)BLI_ghash_lookup(slot->data.ghash, element);
@@ -140,7 +150,7 @@
 BM_INLINE void *BMO_slot_map_ptr_get(BMesh *bm, BMOperator *op, const char *slotname,
                                      void *element)
 {
-	void **val = (void**) BMO_slot_map_data_get(bm, op, slotname, element);
+	void **val = (void **) BMO_slot_map_data_get(bm, op, slotname, element);
 	if (val) return *val;
 
 	return NULL;

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators.c	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators.c	2012-03-01 16:04:37 UTC (rev 44577)
@@ -153,8 +153,8 @@
 	op->exec = opdefines[opcode]->exec;
 
 	/* memarena, used for operator's slot buffers */
-	op->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "bmesh operator");
-	BLI_memarena_use_calloc (op->arena);
+	op->arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
+	BLI_memarena_use_calloc(op->arena);
 }
 
 /**
@@ -267,7 +267,9 @@
 			BMOElemMapping *srcmap, *dstmap;
 
 			/* sanity check */
-			if (!source_slot->data.ghash) return;
+			if (!source_slot->data.ghash) {
+				return;
+			}
 			
 			if (!dest_slot->data.ghash) {
 				dest_slot->data.ghash = BLI_ghash_new(BLI_ghashutil_ptrhash,
@@ -534,12 +536,8 @@
 {
 	BMOElemMapping *mapping;
 	BMOpSlot *slot = BMO_slot_get(op, slotname);
+	BLI_assert(slot->slottype == BMO_OP_SLOT_MAPPING);
 
-	/*sanity check*/
-	if (slot->slottype != BMO_OP_SLOT_MAPPING) {
-		return;
-	}
-
 	mapping = (BMOElemMapping *) BLI_memarena_alloc(op->arena, sizeof(*mapping) + len);
 
 	mapping->element = (BMHeader *) element;
@@ -595,8 +593,8 @@
 }
 #endif
 
-void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op,
-                          const char *slotname, const short oflag)
+void BMO_slot_map_to_flag(BMesh *bm, BMOperator *op, const char *slotname,
+                          const short oflag, const char htype)
 {
 	GHashIterator it;
 	BMOpSlot *slot = BMO_slot_get(op, slotname);
@@ -605,12 +603,13 @@
 	BLI_assert(slot->slottype == BMO_OP_SLOT_MAPPING);
 
 	/* sanity check */
-	if (slot->slottype != BMO_OP_SLOT_MAPPING) return;
 	if (!slot->data.ghash) return;
 
 	BLI_ghashIterator_init(&it, slot->data.ghash);
 	for ( ; (ele_f = BLI_ghashIterator_getKey(&it)); BLI_ghashIterator_step(&it)) {
-		BMO_elem_flag_enable(bm, ele_f, oflag);
+		if (ele_f->head.htype & htype) {
+			BMO_elem_flag_enable(bm, ele_f, oflag);
+		}
 	}
 }
 
@@ -865,7 +864,7 @@
 	BMHeader **data =  slot->data.p;
 	int i;
 
-	BLI_assert(slot->slottype > BMO_OP_SLOT_VEC);
+	BLI_assert(slot->slottype == BMO_OP_SLOT_ELEMENT_BUF);
 
 	for (i = 0; i < slot->len; i++) {
 		if (!(htype & data[i]->htype))
@@ -886,7 +885,9 @@
 	BMOpSlot *slot = BMO_slot_get(op, slotname);
 	BMHeader **data =  slot->data.p;
 	int i;
-	
+
+	BLI_assert(slot->slottype == BMO_OP_SLOT_ELEMENT_BUF);
+
 	for (i = 0; i < slot->len; i++) {
 		if (!(htype & data[i]->htype))
 			continue;

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_structure.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_structure.c	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_structure.c	2012-03-01 16:04:37 UTC (rev 44577)
@@ -234,7 +234,7 @@
 	BMEdge *e_iter, *e_first;
 	
 	if (v1->e) {
-		e_first = e_iter= v1->e;
+		e_first = e_iter = v1->e;
 
 		do {
 			if (bmesh_verts_in_edge(v1, v2, e_iter)) {

Modified: trunk/blender/source/blender/bmesh/operators/bmo_extrude.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_extrude.c	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/bmesh/operators/bmo_extrude.c	2012-03-01 16:04:37 UTC (rev 44577)
@@ -29,9 +29,11 @@
 
 #include "bmesh_operators_private.h" /* own include */
 
-#define EXT_INPUT 1
-#define EXT_KEEP  2
-#define EXT_DEL   4
+enum {
+	EXT_INPUT   = 1,
+	EXT_KEEP    = 2,
+	EXT_DEL     = 4
+};
 
 #define VERT_MARK 1
 #define EDGE_MARK 1
@@ -192,7 +194,7 @@
 	BMLoop *l, *l2;
 	BMVert *verts[4], *v, *v2;
 	BMFace *f;
-	int rlen, found, fwd, delorig = 0;
+	int found, fwd, delorig = FALSE;
 
 	/* initialize our sub-operators */
 	BMO_op_init(bm, &dupeop, "dupe");
@@ -204,21 +206,27 @@
 	if (!BMO_slot_bool_get(op, "alwayskeeporig")) {
 		BM_ITER(e, &iter, bm, BM_EDGES_OF_MESH, NULL) {
 
+			int edge_face_tot;
+
 			if (!BMO_elem_flag_test(bm, e, EXT_INPUT)) {
 				continue;
 			}
 
-			found = FALSE;
-			f = BM_iter_new(&fiter, bm, BM_FACES_OF_EDGE, e);
-			for (rlen = 0; f; f = BM_iter_step(&fiter), rlen++) {
+			found = FALSE; /* found a face that isn't input? */
+			edge_face_tot = 0; /* edge/face count */
+
+			BM_ITER(f, &fiter, bm, BM_FACES_OF_EDGE, e) {
 				if (!BMO_elem_flag_test(bm, f, EXT_INPUT)) {
 					found = TRUE;
-					delorig = 1;
+					delorig = TRUE;
 					break;
 				}
+
+				edge_face_tot++;
 			}
 
-			if ((found == FALSE) && (rlen > 1)) {
+			if ((edge_face_tot > 1) && (found == FALSE)) {
+				/* edge has a face user, that face isnt extrude input */
 				BMO_elem_flag_enable(bm, e, EXT_DEL);
 			}
 		}
@@ -256,7 +264,7 @@
 		}
 	}
 
-	if (delorig) {
+	if (delorig == TRUE) {
 		BMO_op_initf(bm, &delop, "del geom=%fvef context=%i",
 		             EXT_DEL, DEL_ONLYTAGGED);
 	}
@@ -267,11 +275,13 @@
 	if (bm->act_face && BMO_elem_flag_test(bm, bm->act_face, EXT_INPUT))
 		bm->act_face = BMO_slot_map_ptr_get(bm, &dupeop, "facemap", bm->act_face);
 
-	if (delorig) BMO_op_exec(bm, &delop);
+	if (delorig) {
+		BMO_op_exec(bm, &delop);
+	}
 	
 	/* if not delorig, reverse loops of original face */
 	if (!delorig) {
-		for (f = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); f; f = BM_iter_step(&iter)) {
+		BM_ITER(f, &iter, bm, BM_FACES_OF_MESH, NULL) {
 			if (BMO_elem_flag_test(bm, f, EXT_INPUT)) {
 				BM_face_normal_flip(bm, f);
 			}

Modified: trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c
===================================================================
--- trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c	2012-03-01 16:04:37 UTC (rev 44577)
@@ -755,10 +755,10 @@
 	params.off[2] = (float)BLI_drand() * 200.0f;
 	
 	BMO_slot_map_to_flag(bmesh, op, "custompatterns",
-	                     FACE_CUSTOMFILL);
+	                     FACE_CUSTOMFILL, BM_FACE);
 
 	BMO_slot_map_to_flag(bmesh, op, "edgepercents",
-	                     EDGE_PERCENT);
+	                     EDGE_PERCENT, BM_EDGE);
 
 	for (face = BM_iter_new(&fiter, bmesh, BM_FACES_OF_MESH, NULL);
 	     face;

Modified: trunk/blender/source/blender/editors/mesh/bmesh_select.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/bmesh_select.c	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/editors/mesh/bmesh_select.c	2012-03-01 16:04:37 UTC (rev 44577)
@@ -1087,7 +1087,7 @@
 	RNA_def_boolean(ot->srna, "ring", 0, "Select Ring", "Select ring");
 }
 
-void MESH_OT_edgering_select (wmOperatorType *ot)
+void MESH_OT_edgering_select(wmOperatorType *ot)
 {
 	/* description */
 	ot->name = "Edge Ring Select";

Modified: trunk/blender/source/blender/editors/mesh/bmesh_tools.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/bmesh_tools.c	2012-03-01 13:13:08 UTC (rev 44576)
+++ trunk/blender/source/blender/editors/mesh/bmesh_tools.c	2012-03-01 16:04:37 UTC (rev 44577)
@@ -3346,7 +3346,7 @@
 	if (type == 0)
 		retval = mesh_separate_selected(bmain, scene, base, op);
 	else if (type == 1)
-		retval = mesh_separate_material (bmain, scene, base, op);
+		retval = mesh_separate_material(bmain, scene, base, op);
 	else if (type == 2)
 		retval = mesh_separate_loose(bmain, scene, base, op);
 	   




More information about the Bf-blender-cvs mailing list