[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45297] trunk/blender/source/blender: For BMesh functions that test flags, add enabled/disabled variants.

Nicholas Bishop nicholasbishop at gmail.com
Fri Mar 30 19:30:50 CEST 2012


Revision: 45297
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45297
Author:   nicholasbishop
Date:     2012-03-30 17:30:49 +0000 (Fri, 30 Mar 2012)
Log Message:
-----------
For BMesh functions that test flags, add enabled/disabled variants.

Modified Paths:
--------------
    trunk/blender/source/blender/bmesh/intern/bmesh_marking.c
    trunk/blender/source/blender/bmesh/intern/bmesh_marking.h
    trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
    trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
    trunk/blender/source/blender/bmesh/operators/bmo_bevel.c
    trunk/blender/source/blender/bmesh/operators/bmo_connect.c
    trunk/blender/source/blender/bmesh/operators/bmo_create.c
    trunk/blender/source/blender/bmesh/operators/bmo_dissolve.c
    trunk/blender/source/blender/bmesh/operators/bmo_dupe.c
    trunk/blender/source/blender/bmesh/operators/bmo_edgesplit.c
    trunk/blender/source/blender/bmesh/operators/bmo_extrude.c
    trunk/blender/source/blender/bmesh/operators/bmo_inset.c
    trunk/blender/source/blender/bmesh/operators/bmo_mirror.c
    trunk/blender/source/blender/bmesh/operators/bmo_primitive.c
    trunk/blender/source/blender/bmesh/operators/bmo_subdivide.c
    trunk/blender/source/blender/bmesh/operators/bmo_triangulate.c
    trunk/blender/source/blender/bmesh/operators/bmo_utils.c
    trunk/blender/source/blender/editors/mesh/editmesh_tools.c

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_marking.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_marking.c	2012-03-30 17:30:24 UTC (rev 45296)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_marking.c	2012-03-30 17:30:49 UTC (rev 45297)
@@ -437,36 +437,48 @@
 }
 
 /**
- * counts number of elements with flag set
+ * counts number of elements with flag enabled/disabled
  */
-int BM_mesh_count_flag(BMesh *bm, const char htype, const char hflag, int respecthide)
+static int bm_mesh_flag_count(BMesh *bm, const char htype, const char hflag,
+							  int respecthide, int test_for_enabled)
 {
 	BMElem *ele;
 	BMIter iter;
+	int test = (test_for_enabled ? hflag : 0);
 	int tot = 0;
 
 	if (htype & BM_VERT) {
 		for (ele = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL); ele; ele = BM_iter_step(&iter)) {
 			if (respecthide && BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) continue;
-			if (BM_elem_flag_test(ele, hflag)) tot++;
+			if (BM_elem_flag_test(ele, hflag) == test) tot++;
 		}
 	}
 	if (htype & BM_EDGE) {
 		for (ele = BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, NULL); ele; ele = BM_iter_step(&iter)) {
 			if (respecthide && BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) continue;
-			if (BM_elem_flag_test(ele, hflag)) tot++;
+			if (BM_elem_flag_test(ele, hflag) == test) tot++;
 		}
 	}
 	if (htype & BM_FACE) {
 		for (ele = BM_iter_new(&iter, bm, BM_FACES_OF_MESH, NULL); ele; ele = BM_iter_step(&iter)) {
 			if (respecthide && BM_elem_flag_test(ele, BM_ELEM_HIDDEN)) continue;
-			if (BM_elem_flag_test(ele, hflag)) tot++;
+			if (BM_elem_flag_test(ele, hflag) == test) tot++;
 		}
 	}
 
 	return tot;
 }
 
+int BM_mesh_enabled_flag_count(BMesh *bm, const char htype, const char hflag, int respecthide)
+{
+	return bm_mesh_flag_count(bm, htype, hflag, respecthide, TRUE);
+}
+
+int BM_mesh_disabled_flag_count(BMesh *bm, const char htype, const char hflag, int respecthide)
+{
+	return bm_mesh_flag_count(bm, htype, hflag, respecthide, FALSE);
+}
+
 /**
  * \note use BM_elem_flag_test(ele, BM_ELEM_SELECT) to test selection
  * \note by design, this will not touch the editselection history stuff

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_marking.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_marking.h	2012-03-30 17:30:24 UTC (rev 45296)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_marking.h	2012-03-30 17:30:49 UTC (rev 45297)
@@ -60,7 +60,8 @@
 void BM_mesh_deselect_flush(BMesh *bm);
 void BM_mesh_select_flush(BMesh *bm);
 
-int BM_mesh_count_flag(BMesh *bm, const char htype, const char hflag, int respecthide);
+int BM_mesh_enabled_flag_count(BMesh *bm, const char htype, const char hflag, int respecthide);
+int BM_mesh_disabled_flag_count(BMesh *bm, const char htype, const char hflag, int respecthide);
 
 /* edit selection stuff */
 void    BM_active_face_set(BMesh *em, BMFace *f);

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h	2012-03-30 17:30:24 UTC (rev 45296)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operator_api.h	2012-03-30 17:30:49 UTC (rev 45297)
@@ -182,10 +182,14 @@
  * after it finishes executing in BMO_op_exec).*/
 void BMO_op_finish(BMesh *bm, BMOperator *op);
 
-/* count the number of elements with a specific flag.
+/* count the number of elements with the specified flag enabled.
  * type can be a bitmask of BM_FACE, BM_EDGE, or BM_FACE. */
-int BMO_mesh_flag_count(BMesh *bm, const char htype, const short oflag);
+int BMO_mesh_enabled_flag_count(BMesh *bm, const char htype, const short oflag);
 
+/* count the number of elements with the specified flag disabled.
+ * type can be a bitmask of BM_FACE, BM_EDGE, or BM_FACE. */
+int BMO_mesh_disabled_flag_count(BMesh *bm, const char htype, const short oflag);
+
 /*---------formatted operator initialization/execution-----------*/
 /*
  * this system is used to execute or initialize an operator,
@@ -209,8 +213,10 @@
  *             so e.g. %hf will do faces, %hfe will do faces and edges,
  *             %hv will do verts, etc.  must pass in at least one
  *             element type letter.
+ *    %H[f/e/v] - same as %h, but tests if the flag is disabled
  *    %f[f/e/v] - same as %h, except it deals with tool flags instead of
  *                 header flags.
+ *    %F[f/e/v] - same as %f, but tests if the flag is disabled
  *    %a[f/e/v] - pass all elements (of types specified by f/e/v) to the
  *                 slot.
  *    %e        - pass in a single element.
@@ -293,11 +299,16 @@
 void BMO_slot_buffer_append(BMOperator *output_op, const char *output_op_slot,
 							BMOperator *other_op, const char *other_op_slot);
 
-/* puts every element of type type (which is a bitmask) with tool flag flag,
- * into a slot. */
-void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
-                               const char htype, const short oflag);
+/* puts every element of type 'type' (which is a bitmask) with tool
+ * flag 'flag', into a slot. */
+void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, const char *slotname,
+									   const char htype, const short oflag);
 
+/* puts every element of type 'type' (which is a bitmask) without tool
+ * flag 'flag', into a slot. */
+void BMO_slot_buffer_from_disabled_flag(BMesh *bm, BMOperator *op, const char *slotname,
+										const char htype, const short oflag);
+
 /* tool-flags all elements inside an element slot array with flag flag. */
 void BMO_slot_buffer_flag_enable(BMesh *bm, BMOperator *op, const char *slotname,
                                  const char htype, const short oflag);
@@ -312,12 +323,20 @@
 void BMO_slot_buffer_hflag_disable(BMesh *bm, BMOperator *op, const char *slotname,
                                    const char htype, const char hflag, const char do_flush);
 
-/* puts every element of type type (which is a bitmask) with header flag
- * flag, into a slot.  note: ignores hidden elements (e.g. elements with
- * header flag BM_ELEM_HIDDEN set).*/
-void BMO_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname,
-                                const char htype, const char hflag);
+/* puts every element of type 'type' (which is a bitmask) with header
+ * flag 'flag', into a slot.  note: ignores hidden elements
+ * (e.g. elements with header flag BM_ELEM_HIDDEN set).*/
+void BMO_slot_buffer_from_enabled_hflag(BMesh *bm, BMOperator *op,
+										const char *slotname,
+										const char htype, const char hflag);
 
+/* puts every element of type 'type' (which is a bitmask) without
+ * header flag 'flag', into a slot.  note: ignores hidden elements
+ * (e.g. elements with header flag BM_ELEM_HIDDEN set).*/
+void BMO_slot_buffer_from_disabled_hflag(BMesh *bm, BMOperator *op,
+										 const char *slotname,
+										 const char htype, const char hflag);
+
 /* counts number of elements inside a slot array. */
 int BMO_slot_buffer_count(BMesh *bm, BMOperator *op, const char *slotname);
 int BMO_slot_map_count(BMesh *bm, BMOperator *op, const char *slotname);

Modified: trunk/blender/source/blender/bmesh/intern/bmesh_operators.c
===================================================================
--- trunk/blender/source/blender/bmesh/intern/bmesh_operators.c	2012-03-30 17:30:24 UTC (rev 45296)
+++ trunk/blender/source/blender/bmesh/intern/bmesh_operators.c	2012-03-30 17:30:49 UTC (rev 45297)
@@ -451,32 +451,34 @@
 /*
  * BMO_COUNTFLAG
  *
- * Counts the number of elements of a certain type that
- * have a specific flag set.
+ * Counts the number of elements of a certain type that have a
+ * specific flag enabled (or disabled if test_for_enabled is false).
  *
  */
 
-int BMO_mesh_flag_count(BMesh *bm, const char htype, const short oflag)
+static int bmo_mesh_flag_count(BMesh *bm, const char htype, const short oflag,
+							   int test_for_enabled)
 {
 	BMIter elements;
 	int count = 0;
 	BMElemF *ele_f;
+	int test = (test_for_enabled ? oflag : 0);
 
 	if (htype & BM_VERT) {
 		for (ele_f = BM_iter_new(&elements, bm, BM_VERTS_OF_MESH, bm); ele_f; ele_f = BM_iter_step(&elements)) {
-			if (BMO_elem_flag_test(bm, ele_f, oflag))
+			if (BMO_elem_flag_test(bm, ele_f, oflag) == test)
 				count++;
 		}
 	}
 	if (htype & BM_EDGE) {
 		for (ele_f = BM_iter_new(&elements, bm, BM_EDGES_OF_MESH, bm); ele_f; ele_f = BM_iter_step(&elements)) {
-			if (BMO_elem_flag_test(bm, ele_f, oflag))
+			if (BMO_elem_flag_test(bm, ele_f, oflag) == test)
 				count++;
 		}
 	}
 	if (htype & BM_FACE) {
 		for (ele_f = BM_iter_new(&elements, bm, BM_FACES_OF_MESH, bm); ele_f; ele_f = BM_iter_step(&elements)) {
-			if (BMO_elem_flag_test(bm, ele_f, oflag))
+			if (BMO_elem_flag_test(bm, ele_f, oflag) == test)
 				count++;
 		}
 	}
@@ -484,6 +486,17 @@
 	return count;
 }
 
+
+int BMO_mesh_enabled_flag_count(BMesh *bm, const char htype, const short oflag)
+{
+	return bmo_mesh_flag_count(bm, htype, oflag, TRUE);
+}
+
+int BMO_mesh_disabled_flag_count(BMesh *bm, const char htype, const short oflag)
+{
+	return bmo_mesh_flag_count(bm, htype, oflag, FALSE);
+}
+
 void BMO_mesh_flag_disable_all(BMesh *bm, BMOperator *UNUSED(op), const char htype, const short oflag)
 {
 	const char iter_types[3] = {BM_VERTS_OF_MESH,
@@ -676,25 +689,32 @@
 /**
  * \brief BMO_HEADERFLAG_TO_SLOT
  *
- * Copies elements of a certain type, which have a certain header flag set
- * into a slot for an operator.
+ * Copies elements of a certain type, which have a certain header flag
+ * enabled/disabled into a slot for an operator.
  */
-void BMO_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname,
-                                const char htype, const char hflag)
+static void bmo_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname,
+									   const char htype, const char hflag,
+									   int test_for_enabled)
 {
 	BMIter elements;
 	BMElem *ele;
 	BMOpSlot *output = BMO_slot_get(op, slotname);
 	int totelement = 0, i = 0;
-	
-	totelement = BM_mesh_count_flag(bm, htype, hflag, TRUE);
 
+	if (test_for_enabled)
+		totelement = BM_mesh_enabled_flag_count(bm, htype, hflag, TRUE);
+	else
+		totelement = BM_mesh_disabled_flag_count(bm, htype, hflag, TRUE);
+
 	if (totelement) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list