bmesh python api:

BMesh.select_history.remove/clear/validate functions.
This commit is contained in:
2012-03-13 02:59:42 +00:00
parent d25dc3b872
commit a69585573e
3 changed files with 66 additions and 15 deletions

View 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)

View 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);

View 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}
};
@@ -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;