Fix #32355: select vertex path not working when vertices are selected with e.g.

border select. There was a fix before bmesh where it would require exactly two
vertices to be selected, but this was not ported over, and it also wasn't quite
correct.

This case should also work: click on two vertices, selected the path between
them, and then click on a 3rd vertex and select path, to extend the path further
from the 2nd to the 3rd vertex.

Now both use cases should work.
This commit is contained in:
Brecht Van Lommel
2012-08-21 13:19:31 +00:00
parent 4bcae5fb07
commit be4ac3a860

View File

@@ -2122,23 +2122,49 @@ static int edbm_select_vertex_path_exec(bContext *C, wmOperator *op)
Object *ob = CTX_data_edit_object(C);
BMEditMesh *em = BMEdit_FromObject(ob);
BMOperator bmop;
BMIter iter;
BMVert *eve = NULL, *svert = NULL, *evert = NULL;
BMEditSelection *sv, *ev;
/* get the type from RNA */
int type = RNA_enum_get(op->ptr, "type");
/* first try to find vertices in edit selection */
sv = em->bm->selected.last;
if (sv != NULL)
if (sv != NULL) {
ev = sv->prev;
else return OPERATOR_CANCELLED;
if (ev == NULL)
return OPERATOR_CANCELLED;
if ((sv->htype != BM_VERT) || (ev->htype != BM_VERT))
if (ev && (sv->htype == BM_VERT) && (ev->htype == BM_VERT)) {
svert = (BMVert *)sv->ele;
evert = (BMVert *)ev->ele;
}
}
/* if those are not found, because vertices where selected by e.g.
border or circle select, find two selected vertices */
if (svert == NULL) {
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
if (!BM_elem_flag_test(eve, BM_ELEM_SELECT) || BM_elem_flag_test(eve, BM_ELEM_HIDDEN))
continue;
if (svert == NULL) svert = eve;
else if (evert == NULL) evert = eve;
else {
/* more than two vertices are selected,
show warning message and cancel operator */
svert = evert = NULL;
break;
}
}
}
if (svert == NULL || evert == NULL) {
BKE_report(op->reports, RPT_WARNING, "Path Selection requires that two vertices be selected");
return OPERATOR_CANCELLED;
}
/* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */
EDBM_op_init(em, &bmop, op, "shortest_path startv=%e endv=%e type=%i", sv->ele, ev->ele, type);
EDBM_op_init(em, &bmop, op, "shortest_path startv=%e endv=%e type=%i", svert, evert, type);
/* execute the operator */
BMO_op_exec(em->bm, &bmop);