UV Sticky mode is not respected with Border select
Open, ConfirmedPublic

Description

Blender Version
2.78a

Short description of error
Sticky mode is not used with border select in UV editor.

If you click on UV:But with border select:
Anthony Edlin (krash) triaged this task as "Confirmed" priority.Nov 29 2016, 2:13 AM

Can confirm this is current behavior. Also circle select and lasso select also don't follow sticky mode. Not sure if this is desired behavior or not. Shouldn't be that hard to add to those operators, could mark todo for someone that wants an easier task.

Campbell Barton (campbellbarton) changed Type from Bug to To Do.

As noted this doesn't work, but more a case of not being implemented then a software error.

Nice TODO for new developer - move to quick hacks.

I'd like to try this, if no one has made a claim!

Sure go for it, you can assign me I'll help test and review once you have a patch.

Also Selection Mode is not respected by Border Select. Edge and Island mode is not usable with Border Select.

Hi is this task done !
I would like to take this task .

Hi darshan, sorry things have been very busy in my life. Yeah you are more then free to take it off my hands.

ya sure you can help me in this task !!

index 193b006cf0..27525f7755 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -2842,6 +2842,65 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object

 /* ******************** border select operator **************** */

+bool uv_touched_vetex(int hitv[4], int v, int sticky, int hitlen) {
+       int  i = 0;
+
+       for (i = 0; i<hitlen; i++) {
+               if (hitv[i] == v) {
+                       if (sticky == SI_STICKY_VERTEX)
+                               return true;
+               }
+       }
+
+       return false;
+}
+
+void uv_get_hit_vertex(BMLoop *l, MLoopUV *luv, MLoopUV *luv_next, MTexPoly *tf,
+                                       BMFace *efa,const bool cd_loop_uv_offset, NearestHit *hit ,int index) {
+
+       memset(hit, 0, sizeof(hit));
+
+       hit->l = l;
+       hit->luv = luv;
+       hit->luv_next = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset);
+       hit->tf = tf;
+       hit->efa = efa;
+       hit->lindex = index;
+       return;
+}
+
+void uv_select_sticky_border(BMEditMesh *em, Scene *scene, Image *ima, int v, NearestHit *hit, int sticky) {
+       BMFace *efa;
+       BMIter iter, liter;
+       BMLoop *l;
+       MTexPoly *tf;
+       int *hitv = NULL;
+       int hitlen = 0, i = 0;
+
+       const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+       const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
+
+       if (hit->efa == NULL || sticky == SI_STICKY_DISABLE)
+               return;
+
+       hitv = BLI_array_alloca(hitv, hit->efa->len);
+       copy_vn_i(hitv, hit->efa->len, 0xFFFFFFFF);
+       hitv[hit->lindex] = BM_elem_index_get(hit->l->v);
+       hitlen = hit->efa->len;
+       printf("%d    %d\n", hit->efa->len, hitlen);
+       BM_ITER_MESH(efa, &iter, em->bm, BM_FACES_OF_MESH) {
+               tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
+               if (!uvedit_face_visible_test(scene, ima, efa, tf))
+                       continue;
+               BM_ITER_ELEM_INDEX(l, &liter, efa, BM_LOOPS_OF_FACE, i) {
+                       if (uv_touched_vetex(hitv, BM_elem_index_get(l->v), sticky, hit->efa->len)) {
+                               uvedit_uv_select_enable(em, scene, l, false, cd_loop_uv_offset);
+                       }
+               }
+       }
+
+}
+
 static int uv_border_select_exec(bContext *C, wmOperator *op)
 {
        SpaceImage *sima = CTX_wm_space_image(C);
@@ -2855,8 +2914,10 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
        BMLoop *l;
        BMIter iter, liter;
        MTexPoly *tf;
-       MLoopUV *luv;
+       MLoopUV *luv ,*luv_next;
+       NearestHit hit;
        rctf rectf;
+       int sticky,i=0;
        bool changed, pinned, select, extend;
        const bool use_face_center = (ts->uv_flag & UV_SYNC_SELECTION) ?
                                    (ts->selectmode == SCE_SELECT_FACE) :
@@ -2874,6 +2935,8 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
        pinned = RNA_boolean_get(op->ptr, "pinned");
        extend = RNA_boolean_get(op->ptr, "extend");

+       sticky = (sima) ? sima->sticky : 1;
+
        if (!extend)
                uv_select_all_perform(scene, ima, em, SEL_DESELECT);

@@ -2911,19 +2974,28 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
                        tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
                        if (!uvedit_face_visible_test(scene, ima, efa, tf))
                                continue;
-                       BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+                       BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
                                luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+                               luv_next = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset);

                                if (!pinned || (ts->uv_flag & UV_SYNC_SELECTION)) {

                                        /* UV_SYNC_SELECTION - can't do pinned selection */
                                        if (BLI_rctf_isect_pt_v(&rectf, luv->uv)) {
                                                uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
+                                               if (sticky == SI_STICKY_VERTEX) {
+                                                       uv_get_hit_vertex(l, luv, luv_next, tf, efa, cd_loop_uv_offset, &hit, i);
+                                                       uv_select_sticky_border(em, scene, ima, BM_elem_index_get(l->v), &hit, sticky);
+                                               }
                                        }
                                }
                                else if (pinned) {
                                        if ((luv->flag & MLOOPUV_PINNED) && BLI_rctf_isect_pt_v(&rectf, luv->uv)) {
                                                uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
+                                               if (sticky == SI_STICKY_VERTEX) {
+                                                       uv_get_hit_vertex(l, luv, luv_next, tf, efa, cd_loop_uv_offset, &hit, i);
+                                                       uv_select_sticky_border(em, scene, ima, BM_elem_index_get(l->v), &hit, sticky);
+                                               }
                                        }
                                }
                        }

This is the patch i have created for border selection .Using this the sticky mode(veres selection ) for border selection is same as mouse selection.

Please make differential with this patch to make reviewing it a little easier

https://developer.blender.org/differential/diff/create/

https://developer.blender.org/D2526
this is the differential i have created .

uv_select_sticky_border is called in a loop, this isnt needed since you can use LOOPS_OF_VERT iterator to find all face corners attached to the vertex.

I have updated the diff
Here is the link https://developer.blender.org/D2596