bmesh python api:
authorCampbell Barton <ideasman42@gmail.com>
Tue, 13 Mar 2012 02:59:42 +0000 (02:59 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 13 Mar 2012 02:59:42 +0000 (02:59 +0000)
BMesh.select_history.remove/clear/validate functions.

source/blender/bmesh/intern/bmesh_marking.c
source/blender/bmesh/intern/bmesh_marking.h
source/blender/python/bmesh/bmesh_py_select.c

index f05a75e74bf4df0cb784c6cf8ee6d4b487e581b7..4108d00fe7af141826b8cf5998015e02396269a2 100644 (file)
@@ -701,15 +701,17 @@ int BM_select_history_check(BMesh *bm, const BMElem *ele)
        return FALSE;
 }
 
-void BM_select_history_remove(BMesh *bm, BMElem *ele)
+int BM_select_history_remove(BMesh *bm, BMElem *ele)
 {
        BMEditSelection *ese;
        for (ese = bm->selected.first; ese; ese = ese->next) {
                if (ese->ele == ele) {
                        BLI_freelinkN(&(bm->selected), ese);
-                       break;
+                       return TRUE;
                }
        }
+
+       return FALSE;
 }
 
 void BM_select_history_clear(BMesh *bm)
index 598cc02126aba4b255b03db1a87fce18584cb8c6..8e4a4ab7d660c162e98fd0c90613324238ba40dc 100644 (file)
@@ -70,7 +70,7 @@ void BM_editselection_normal(float r_normal[3], BMEditSelection *ese);
 void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese);
 
 int  BM_select_history_check(BMesh *bm, const BMElem *ele);
-void BM_select_history_remove(BMesh *bm, BMElem *ele);
+int  BM_select_history_remove(BMesh *bm, BMElem *ele);
 void BM_select_history_store(BMesh *bm, BMElem *ele);
 void BM_select_history_validate(BMesh *bm);
 void BM_select_history_clear(BMesh *em);
index c5c66c0aaaa258777bdac896af1a5b5293dd15de..cd6145709e075fb9ecd405f9c66d5ed10c061b34 100644 (file)
@@ -69,8 +69,65 @@ static PyGetSetDef bpy_bmeditselseq_getseters[] = {
     {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
 };
 
+PyDoc_STRVAR(bpy_bmeditselseq_validate_doc,
+".. method:: validate()\n"
+"\n"
+"   Ensures all elements in the selection history are selected.\n"
+);
+static PyObject *bpy_bmeditselseq_validate(BPy_BMEditSelSeq *self)
+{
+       BPY_BM_CHECK_OBJ(self);
+       BM_select_history_validate(self->bm);
+       Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(bpy_bmeditselseq_clear_doc,
+".. method:: clear()\n"
+"\n"
+"   Empties the selection history.\n"
+);
+static PyObject *bpy_bmeditselseq_clear(BPy_BMEditSelSeq *self)
+{
+       BPY_BM_CHECK_OBJ(self);
+       BM_select_history_clear(self->bm);
+       Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(bpy_bmeditselseq_remove_doc,
+".. method:: remove(element)\n"
+"\n"
+"   Remove an element from the selection history.\n"
+);
+static PyObject *bpy_bmeditselseq_remove(BPy_BMEditSelSeq *self, BPy_BMElem *value)
+{
+       BPY_BM_CHECK_OBJ(self);
+
+       if ((BPy_BMVert_Check(value) ||
+            BPy_BMEdge_Check(value) ||
+            BPy_BMFace_Check(value)) == FALSE)
+       {
+               PyErr_Format(PyExc_TypeError,
+                            "Expected a BMVert/BMedge/BMFace not a %.200s", Py_TYPE(value)->tp_name);
+               return NULL;
+       }
+
+       BPY_BM_CHECK_OBJ(value);
+
+       if ((self->bm != value->bm) ||
+           (BM_select_history_remove(self->bm, value->ele) == FALSE))
+       {
+               PyErr_SetString(PyExc_ValueError,
+                               "Element not found in selection history");
+               return NULL;
+       }
+
+       Py_RETURN_NONE;
+}
+
 static struct PyMethodDef bpy_bmeditselseq_methods[] = {
-    // {"select_flush_mode", (PyCFunction)bpy_bmesh_select_flush_mode, METH_NOARGS, bpy_bmesh_select_flush_mode_doc},
+    {"validate", (PyCFunction)bpy_bmeditselseq_validate, METH_NOARGS, bpy_bmeditselseq_validate_doc},
+    {"clear",    (PyCFunction)bpy_bmeditselseq_clear,    METH_NOARGS, bpy_bmeditselseq_clear_doc},
+    {"remove",   (PyCFunction)bpy_bmeditselseq_remove,   METH_O,      bpy_bmeditselseq_remove_doc},
     {NULL, NULL, 0, NULL}
 };
 
@@ -103,7 +160,7 @@ static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keyn
        }
        else {
                PyErr_Format(PyExc_IndexError,
-                                "BMElemSeq[index]: index %d out of range", keynum);
+                            "BMElemSeq[index]: index %d out of range", keynum);
                return NULL;
        }
 }
@@ -213,15 +270,7 @@ static int bpy_bmeditselseq_contains(BPy_BMEditSelSeq *self, PyObject *value)
 
        value_bm_ele = (BPy_BMElem *)value;
        if (value_bm_ele->bm == self->bm) {
-               BMEditSelection *ese_test;
-               BMElem *ele;
-
-               ele = value_bm_ele->ele;
-               for (ese_test = self->bm->selected.first; ese_test; ese_test = ese_test->next) {
-                       if (ele == ese_test->ele) {
-                               return 1;
-                       }
-               }
+               return BM_select_history_check(self->bm, value_bm_ele->ele);
        }
 
        return 0;
@@ -274,7 +323,7 @@ static PyObject *bpy_bmeditseliter_next(BPy_BMEditSelIter *self)
        }
 }
 
-PyTypeObject BPy_BMEditSelSeq_Type     = {{{0}}};
+PyTypeObject BPy_BMEditSelSeq_Type  = {{{0}}};
 PyTypeObject BPy_BMEditSelIter_Type = {{{0}}};