bmesh python api:
BMesh.select_history.remove/clear/validate functions.
This commit is contained in:
@@ -701,15 +701,17 @@ int BM_select_history_check(BMesh *bm, const BMElem *ele)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BM_select_history_remove(BMesh *bm, BMElem *ele)
|
int BM_select_history_remove(BMesh *bm, BMElem *ele)
|
||||||
{
|
{
|
||||||
BMEditSelection *ese;
|
BMEditSelection *ese;
|
||||||
for (ese = bm->selected.first; ese; ese = ese->next) {
|
for (ese = bm->selected.first; ese; ese = ese->next) {
|
||||||
if (ese->ele == ele) {
|
if (ese->ele == ele) {
|
||||||
BLI_freelinkN(&(bm->selected), ese);
|
BLI_freelinkN(&(bm->selected), ese);
|
||||||
break;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BM_select_history_clear(BMesh *bm)
|
void BM_select_history_clear(BMesh *bm)
|
||||||
|
|||||||
@@ -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);
|
void BM_editselection_plane(BMesh *bm, float r_plane[3], BMEditSelection *ese);
|
||||||
|
|
||||||
int BM_select_history_check(BMesh *bm, const BMElem *ele);
|
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_store(BMesh *bm, BMElem *ele);
|
||||||
void BM_select_history_validate(BMesh *bm);
|
void BM_select_history_validate(BMesh *bm);
|
||||||
void BM_select_history_clear(BMesh *em);
|
void BM_select_history_clear(BMesh *em);
|
||||||
|
|||||||
@@ -69,8 +69,65 @@ static PyGetSetDef bpy_bmeditselseq_getseters[] = {
|
|||||||
{NULL, NULL, NULL, NULL, NULL} /* Sentinel */
|
{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[] = {
|
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}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -213,15 +270,7 @@ static int bpy_bmeditselseq_contains(BPy_BMEditSelSeq *self, PyObject *value)
|
|||||||
|
|
||||||
value_bm_ele = (BPy_BMElem *)value;
|
value_bm_ele = (BPy_BMElem *)value;
|
||||||
if (value_bm_ele->bm == self->bm) {
|
if (value_bm_ele->bm == self->bm) {
|
||||||
BMEditSelection *ese_test;
|
return BM_select_history_check(self->bm, value_bm_ele->ele);
|
||||||
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 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user