Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Bishop <nicholasbishop@gmail.com>2012-03-30 21:30:49 +0400
committerNicholas Bishop <nicholasbishop@gmail.com>2012-03-30 21:30:49 +0400
commitc7aed8b2af38f7b99f9df9d8e18006421ccb900e (patch)
tree4a2cf6b8c48d1dc33d86f7307e28a7d553a3e905 /source/blender/bmesh/intern
parentbbbbe1b00ea9dc46a4d837239748bfeceeda65e7 (diff)
For BMesh functions that test flags, add enabled/disabled variants.
Diffstat (limited to 'source/blender/bmesh/intern')
-rw-r--r--source/blender/bmesh/intern/bmesh_marking.c22
-rw-r--r--source/blender/bmesh/intern/bmesh_marking.h3
-rw-r--r--source/blender/bmesh/intern/bmesh_operator_api.h41
-rw-r--r--source/blender/bmesh/intern/bmesh_operators.c109
4 files changed, 134 insertions, 41 deletions
diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c
index 0318fd94b92..2116acc337e 100644
--- a/source/blender/bmesh/intern/bmesh_marking.c
+++ b/source/blender/bmesh/intern/bmesh_marking.c
@@ -437,36 +437,48 @@ void BM_select_mode_set(BMesh *bm, int selectmode)
}
/**
- * 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
diff --git a/source/blender/bmesh/intern/bmesh_marking.h b/source/blender/bmesh/intern/bmesh_marking.h
index f0e81b1dd9f..a02931b0e88 100644
--- a/source/blender/bmesh/intern/bmesh_marking.h
+++ b/source/blender/bmesh/intern/bmesh_marking.h
@@ -60,7 +60,8 @@ void BM_mesh_select_mode_flush(BMesh *bm);
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);
diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h
index e2062bdf8f8..bb980a63861 100644
--- a/source/blender/bmesh/intern/bmesh_operator_api.h
+++ b/source/blender/bmesh/intern/bmesh_operator_api.h
@@ -182,9 +182,13 @@ void BMO_op_exec(BMesh *bm, BMOperator *op);
* 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-----------*/
/*
@@ -209,8 +213,10 @@ int BMO_mesh_flag_count(BMesh *bm, const char htype, const short oflag);
* 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,10 +299,15 @@ void BMO_mesh_flag_disable_all(BMesh *bm, BMOperator *op, const char htype, cons
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,
@@ -312,11 +323,19 @@ void BMO_slot_buffer_hflag_enable(BMesh *bm, BMOperator *op, const char *slotnam
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);
diff --git a/source/blender/bmesh/intern/bmesh_operators.c b/source/blender/bmesh/intern/bmesh_operators.c
index 58c38def33f..e09be79633e 100644
--- a/source/blender/bmesh/intern/bmesh_operators.c
+++ b/source/blender/bmesh/intern/bmesh_operators.c
@@ -451,32 +451,34 @@ void BMO_slot_vec_get(BMOperator *op, const char *slotname, float r_vec[3])
/*
* 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 @@ int BMO_mesh_flag_count(BMesh *bm, const char htype, const short oflag)
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 @@ static void BMO_slot_buffer_from_all(BMesh *bm, BMOperator *op, const char *slot
/**
* \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) {
+ int test = (test_for_enabled ? hflag : 0);
+
bmo_slot_buffer_alloc(op, slotname, totelement);
if (htype & BM_VERT) {
for (ele = BM_iter_new(&elements, bm, BM_VERTS_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) {
- if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && BM_elem_flag_test(ele, hflag)) {
+ if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) &&
+ BM_elem_flag_test(ele, hflag) == test) {
((BMElem **)output->data.p)[i] = ele;
i++;
}
@@ -703,7 +723,8 @@ void BMO_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname,
if (htype & BM_EDGE) {
for (ele = BM_iter_new(&elements, bm, BM_EDGES_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) {
- if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && BM_elem_flag_test(ele, hflag)) {
+ if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) &&
+ BM_elem_flag_test(ele, hflag) == test) {
((BMElem **)output->data.p)[i] = ele;
i++;
}
@@ -712,7 +733,8 @@ void BMO_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname,
if (htype & BM_FACE) {
for (ele = BM_iter_new(&elements, bm, BM_FACES_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) {
- if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) && BM_elem_flag_test(ele, hflag)) {
+ if (!BM_elem_flag_test(ele, BM_ELEM_HIDDEN) &&
+ BM_elem_flag_test(ele, hflag) == test) {
((BMElem **)output->data.p)[i] = ele;
i++;
}
@@ -724,6 +746,18 @@ void BMO_slot_buffer_from_hflag(BMesh *bm, BMOperator *op, const char *slotname,
}
}
+void BMO_slot_buffer_from_enabled_hflag(BMesh *bm, BMOperator *op, const char *slotname,
+ const char htype, const char hflag)
+{
+ bmo_slot_buffer_from_hflag(bm, op, slotname, htype, hflag, TRUE);
+}
+
+void BMO_slot_buffer_from_disabled_hflag(BMesh *bm, BMOperator *op, const char *slotname,
+ const char htype, const char hflag)
+{
+ bmo_slot_buffer_from_hflag(bm, op, slotname, htype, hflag, FALSE);
+}
+
/**
* Copies the values from another slot to the end of the output slot.
*/
@@ -762,18 +796,25 @@ void BMO_slot_buffer_append(BMOperator *output_op, const char *output_slot_name,
* Copies elements of a certain type, which have a certain flag set
* into an output slot for an operator.
*/
-void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
- const char htype, const short oflag)
+static void bmo_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
+ const char htype, const short oflag,
+ int test_for_enabled)
{
BMIter elements;
BMOpSlot *slot = BMO_slot_get(op, slotname);
- int totelement = BMO_mesh_flag_count(bm, htype, oflag), i = 0;
+ int totelement, i = 0;
+
+ if (test_for_enabled)
+ totelement = BMO_mesh_enabled_flag_count(bm, htype, oflag);
+ else
+ totelement = BMO_mesh_disabled_flag_count(bm, htype, oflag);
BLI_assert(slot->slottype == BMO_OP_SLOT_ELEMENT_BUF);
if (totelement) {
BMHeader *ele;
BMHeader **ele_array;
+ int test = (test_for_enabled ? oflag : 0);
bmo_slot_buffer_alloc(op, slotname, totelement);
@@ -781,7 +822,7 @@ void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
if (htype & BM_VERT) {
for (ele = BM_iter_new(&elements, bm, BM_VERTS_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) {
- if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag)) {
+ if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag) == test) {
ele_array[i] = ele;
i++;
}
@@ -790,7 +831,7 @@ void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
if (htype & BM_EDGE) {
for (ele = BM_iter_new(&elements, bm, BM_EDGES_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) {
- if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag)) {
+ if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag) == test) {
ele_array[i] = ele;
i++;
}
@@ -799,7 +840,7 @@ void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
if (htype & BM_FACE) {
for (ele = BM_iter_new(&elements, bm, BM_FACES_OF_MESH, bm); ele; ele = BM_iter_step(&elements)) {
- if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag)) {
+ if (BMO_elem_flag_test(bm, (BMElemF *)ele, oflag) == test) {
ele_array[i] = ele;
i++;
}
@@ -811,6 +852,18 @@ void BMO_slot_buffer_from_flag(BMesh *bm, BMOperator *op, const char *slotname,
}
}
+void BMO_slot_buffer_from_enabled_flag(BMesh *bm, BMOperator *op, const char *slotname,
+ const char htype, const short oflag)
+{
+ bmo_slot_buffer_from_flag(bm, op, slotname, htype, oflag, TRUE);
+}
+
+void BMO_slot_buffer_from_disabled_flag(BMesh *bm, BMOperator *op, const char *slotname,
+ const char htype, const short oflag)
+{
+ bmo_slot_buffer_from_flag(bm, op, slotname, htype, oflag, FALSE);
+}
+
/**
* \brief BMO_FLAG_BUFFER
*
@@ -1403,7 +1456,9 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const char *_fmt, va_list vlist)
state = 1;
break;
case 'f':
+ case 'F':
case 'h':
+ case 'H':
case 'a':
type = *fmt;
@@ -1430,13 +1485,19 @@ int BMO_op_vinitf(BMesh *bm, BMOperator *op, const char *_fmt, va_list vlist)
}
if (type == 'h') {
- BMO_slot_buffer_from_hflag(bm, op, slotname, htype, va_arg(vlist, int));
+ BMO_slot_buffer_from_enabled_hflag(bm, op, slotname, htype, va_arg(vlist, int));
+ }
+ else if (type == 'H') {
+ BMO_slot_buffer_from_disabled_hflag(bm, op, slotname, htype, va_arg(vlist, int));
}
else if (type == 'a') {
BMO_slot_buffer_from_all(bm, op, slotname, htype);
}
- else {
- BMO_slot_buffer_from_flag(bm, op, slotname, htype, va_arg(vlist, int));
+ else if (type == 'f') {
+ BMO_slot_buffer_from_enabled_flag(bm, op, slotname, htype, va_arg(vlist, int));
+ }
+ else if (type == 'F') {
+ BMO_slot_buffer_from_disabled_flag(bm, op, slotname, htype, va_arg(vlist, int));
}
}