Fix #32458: changing UV image in image editor not working when the active face
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 31 Aug 2012 15:01:40 +0000 (15:01 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 31 Aug 2012 15:01:40 +0000 (15:01 +0000)
was not selected. Now changed it so that the active face must also have its
UVs shown in the image editor to be used as the source of the image shown.

source/blender/bmesh/intern/bmesh_marking.c
source/blender/bmesh/intern/bmesh_marking.h
source/blender/editors/include/ED_mesh.h
source/blender/editors/mesh/editmesh_select.c
source/blender/editors/mesh/editmesh_utils.c
source/blender/editors/mesh/mesh_navmesh.c
source/blender/editors/space_image/space_image.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/uvedit/uvedit_draw.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/editors/uvedit/uvedit_unwrap_ops.c

index 58ccfa79a02d18a301418fa156001ff25ad5140a..c0439311104ecfabddb31a7778b604ca477b66fe 100644 (file)
@@ -527,9 +527,9 @@ void BM_active_face_set(BMesh *bm, BMFace *efa)
        bm->act_face = efa;
 }
 
-BMFace *BM_active_face_get(BMesh *bm, int sloppy)
+BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected)
 {
-       if (bm->act_face) {
+       if (bm->act_face && (!selected || BM_elem_flag_test(bm->act_face, BM_ELEM_SELECT))) {
                return bm->act_face;
        }
        else if (sloppy) {
@@ -546,6 +546,9 @@ BMFace *BM_active_face_get(BMesh *bm, int sloppy)
                                if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
                                        f = NULL;
                                }
+                               else if (selected && !BM_elem_flag_test(f, BM_ELEM_SELECT)) {
+                                       f = NULL;
+                               }
                                else {
                                        break;
                                }
@@ -768,7 +771,7 @@ void BM_select_history_validate(BMesh *bm)
 int BM_select_history_active_get(BMesh *bm, BMEditSelection *ese)
 {
        BMEditSelection *ese_last = bm->selected.last;
-       BMFace *efa = BM_active_face_get(bm, FALSE);
+       BMFace *efa = BM_active_face_get(bm, FALSE, FALSE);
 
        ese->next = ese->prev = NULL;
 
index 9b73ed2c390b2800068349925ff48708e88cae23..8d4397794d56e99f14c43aec00481ed713b86bee 100644 (file)
@@ -71,7 +71,7 @@ int BM_mesh_elem_hflag_count_disabled(BMesh *bm, const char htype, const char hf
 
 /* edit selection stuff */
 void    BM_active_face_set(BMesh *bm, BMFace *f);
-BMFace *BM_active_face_get(BMesh *bm, int sloppy);
+BMFace *BM_active_face_get(BMesh *bm, int sloppy, int selected);
 
 void    BM_editselection_center(BMEditSelection *ese, float r_center[3]);
 void    BM_editselection_normal(BMEditSelection *ese, float r_normal[3]);
index 35284b26d29ad064e219e937a921a8097a49717e..da4400635522f56523dc53f15b09977f0ef1f279 100644 (file)
@@ -135,7 +135,7 @@ struct UvElementMap *EDBM_uv_element_map_create(struct BMEditMesh *em, int selec
 void                 EDBM_uv_element_map_free(struct UvElementMap *vmap);
 
 int              EDBM_mtexpoly_check(struct BMEditMesh *em);
-struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy);
+struct MTexPoly *EDBM_mtexpoly_active_get(struct BMEditMesh *em, struct BMFace **r_act_efa, int sloppy, int selected);
 
 void              EDBM_uv_vert_map_free(struct UvVertMap *vmap);
 struct UvMapVert *EDBM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v);
index 765091a3d1d0cd55da214827ba4a2efda21ad33d..a9e8c253c82a38152778fda1d9b01b362f4b915b 100644 (file)
@@ -2221,7 +2221,7 @@ static void deselect_nth_active(BMEditMesh *em, BMVert **r_eve, BMEdge **r_eed,
                }
        }
        else if (em->selectmode & SCE_SELECT_FACE) {
-               f = BM_active_face_get(em->bm, TRUE);
+               f = BM_active_face_get(em->bm, TRUE, FALSE);
                if (f) {
                        *r_efa = f;
                        return;
index aaf1701d7235c005060be4094dafb7fae518be3a..a111c2ffafb5c7eef9c4f63cda42d176ea79bed0 100644 (file)
@@ -992,15 +992,15 @@ void EDBM_uv_element_map_free(UvElementMap *element_map)
 
 /* last_sel, use em->act_face otherwise get the last selected face in the editselections
  * at the moment, last_sel is mainly useful for making sure the space image dosnt flicker */
-MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy)
+MTexPoly *EDBM_mtexpoly_active_get(BMEditMesh *em, BMFace **r_act_efa, int sloppy, int selected)
 {
        BMFace *efa = NULL;
        
        if (!EDBM_mtexpoly_check(em))
                return NULL;
        
-       efa = BM_active_face_get(em->bm, sloppy);
-       
+       efa = BM_active_face_get(em->bm, sloppy, selected);
+
        if (efa) {
                if (r_act_efa) *r_act_efa = efa;
                return CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
index 14d20d684552d22551e716efe3bde5d55acf8a5e..88b1f191e3ab266bb3a031a3c234c5412491472a 100644 (file)
@@ -491,7 +491,7 @@ static int navmesh_face_copy_exec(bContext *C, wmOperator *op)
        BMEditMesh *em = BMEdit_FromObject(obedit);
 
        /* do work here */
-       BMFace *efa_act = BM_active_face_get(em->bm, FALSE);
+       BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE);
 
        if (efa_act) {
                if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) {
index d2639edb27603836d5123c5de3c08ccf63986464..9cceaf0aa8e715f24afa1fe5a2f4c05cb0b50c59 100644 (file)
@@ -392,11 +392,12 @@ static void image_refresh(const bContext *C, ScrArea *sa)
        else if (obedit && obedit->type == OB_MESH) {
                Mesh *me = (Mesh *)obedit->data;
                struct BMEditMesh *em = me->edit_btmesh;
-               int sloppy = 1; /* partially selected face is ok */
+               int sloppy = TRUE; /* partially selected face is ok */
+               int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */
 
                if (BKE_scene_use_new_shading_nodes(scene)) {
                        /* new shading system, get image from material */
-                       BMFace *efa = BM_active_face_get(em->bm, sloppy);
+                       BMFace *efa = BM_active_face_get(em->bm, sloppy, selected);
 
                        if (efa) {
                                Image *node_ima;
@@ -413,8 +414,8 @@ static void image_refresh(const bContext *C, ScrArea *sa)
                        if (em && EDBM_mtexpoly_check(em)) {
                                sima->image = NULL;
                                
-                               tf = EDBM_mtexpoly_active_get(em, NULL, TRUE); /* partially selected face is ok */
-                               
+                               tf = EDBM_mtexpoly_active_get(em, NULL, sloppy, selected);
+
                                if (tf) {
                                        /* don't need to check for pin here, see above */
                                        sima->image = tf->tpage;
index 8e9776e0e17554319a5c01c7475f239ab2168540..26fe908f034ee7d1064fa66fe01ff6ba1b7161cb 100644 (file)
@@ -3164,7 +3164,7 @@ static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d,
 
 {
        Mesh *me = ob->data;
-       BMFace *efa_act = BM_active_face_get(em->bm, FALSE); /* annoying but active faces is stored differently */
+       BMFace *efa_act = BM_active_face_get(em->bm, FALSE, FALSE); /* annoying but active faces is stored differently */
        BMEdge *eed_act = NULL;
        BMVert *eve_act = NULL;
        
index 1f78bc6bddf695eed4bed882fcd9b9b2db354769..e5888a1b50805f9f5935b66e16be90a8dec866d8 100644 (file)
@@ -455,8 +455,8 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
 
        StitchPreviewer *stitch_preview = uv_get_stitch_previewer();
 
-       activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE); /* will be set to NULL if hidden */
-       activef = BM_active_face_get(bm, FALSE);
+       activetf = EDBM_mtexpoly_active_get(em, &efa_act, FALSE, FALSE); /* will be set to NULL if hidden */
+       activef = BM_active_face_get(bm, FALSE, FALSE);
        ts = scene->toolsettings;
 
        drawfaces = draw_uvs_face_check(scene);
index b922647f3e6cabc6d3e120a629b1b9180f49767a..5008c35e46a523a61f2b5d9832797a3832b3df78 100644 (file)
@@ -174,6 +174,8 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im
        BMIter iter;
        MTexPoly *tf;
        int update = 0;
+       int sloppy = TRUE;
+       int selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION);
        
        /* skip assigning these procedural images... */
        if (ima && (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE))
@@ -190,8 +192,7 @@ void ED_uvedit_assign_image(Main *bmain, Scene *scene, Object *obedit, Image *im
 
        if (BKE_scene_use_new_shading_nodes(scene)) {
                /* new shading system, assign image in material */
-               int sloppy = 1;
-               BMFace *efa = BM_active_face_get(em->bm, sloppy);
+               BMFace *efa = BM_active_face_get(em->bm, sloppy, selected);
 
                if (efa)
                        ED_object_assign_active_image(bmain, obedit, efa->mat_nr + 1, ima);
index b49033904088878a2878c400b8c5f667f22f1535..c1fb3ee3807f86e49fdd8f2694bbdf43564da98e 100644 (file)
@@ -192,7 +192,10 @@ static ParamHandle *construct_param_handle(Scene *scene, BMEditMesh *em,
        handle = param_construct_begin();
 
        if (correct_aspect) {
-               efa = BM_active_face_get(em->bm, TRUE);
+               int sloppy = TRUE;
+               int selected = FALSE;
+
+               efa = BM_active_face_get(em->bm, sloppy, selected);
 
                if (efa) {
                        float aspx, aspy;
@@ -380,7 +383,10 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, BMEditMesh *e
        handle = param_construct_begin();
 
        if (correct_aspect) {
-               editFace = BM_active_face_get(em->bm, TRUE);
+               int sloppy = TRUE;
+               int selected = FALSE;
+
+               editFace = BM_active_face_get(em->bm, sloppy, selected);
 
                if (editFace) {
                        MTexPoly *tf;
@@ -1003,7 +1009,9 @@ static void uv_transform_properties(wmOperatorType *ot, int radius)
 
 static void correct_uv_aspect(BMEditMesh *em)
 {
-       BMFace *efa = BM_active_face_get(em->bm, TRUE);
+       int sloppy = TRUE;
+       int selected = FALSE;
+       BMFace *efa = BM_active_face_get(em->bm, sloppy, selected);
        BMLoop *l;
        BMIter iter, liter;
        MLoopUV *luv;