2.5: UV Edit
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 10 Sep 2009 11:04:53 +0000 (11:04 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Thu, 10 Sep 2009 11:04:53 +0000 (11:04 +0000)
* Make mirror operator and menus work.
* Added TFM_OT_mirror transform operator specific for mirror.
* Assign image from image space when unwrapping in 3d view.

source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_ops.c
source/blender/editors/uvedit/uvedit_ops.c
source/blender/editors/uvedit/uvedit_unwrap_ops.c
source/blender/makesrna/intern/rna_access.c

index 1f568be3e10a3213fc6dd7ae58c1e39e58ac4da3..f049566d6407bb75187d68121debdabd2e8f3da1 100644 (file)
@@ -1257,13 +1257,16 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        int constraint_axis[3] = {0, 0, 0};
        int proportional = 0;
 
-       if (t->flag & T_AUTOVALUES)
-       {
-               RNA_float_set_array(op->ptr, "value", t->auto_values);
-       }
-       else
+       if (RNA_struct_find_property(op->ptr, "value"))
        {
-               RNA_float_set_array(op->ptr, "value", t->values);
+               if (t->flag & T_AUTOVALUES)
+               {
+                       RNA_float_set_array(op->ptr, "value", t->auto_values);
+               }
+               else
+               {
+                       RNA_float_set_array(op->ptr, "value", t->values);
+               }
        }
 
        /* XXX convert stupid flag to enum */
@@ -4145,7 +4148,10 @@ int Mirror(TransInfo *t, short mval[2])
 
                recalcData(t);
 
-               ED_area_headerprint(t->sa, "Select a mirror axis (X, Y, Z)");
+               if(t->flag & T_2D_EDIT)
+                       ED_area_headerprint(t->sa, "Select a mirror axis (X, Y)");
+               else
+                       ED_area_headerprint(t->sa, "Select a mirror axis (X, Y, Z)");
        }
 
        return 1;
index 08d22faf7e71f4face0bc9cdfdec23e678fdd7fd..4ae0bca32844f440498b469eb1c9b160739b1c29 100644 (file)
@@ -98,6 +98,7 @@ char OP_WARP[] = "TFM_OT_warp";
 char OP_SHRINK_FATTEN[] = "TFM_OT_shrink_fatten";
 char OP_TILT[] = "TFM_OT_tilt";
 char OP_TRACKBALL[] = "TFM_OT_trackball";
+char OP_MIRROR[] = "TFM_OT_mirror";
 
 
 TransformModeItem transform_modes[] =
@@ -111,6 +112,7 @@ TransformModeItem transform_modes[] =
        {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN},
        {OP_TILT, TFM_TILT},
        {OP_TRACKBALL, TFM_TRACKBALL},
+       {OP_MIRROR, TFM_MIRROR},
        {NULL, 0}
 };
 
@@ -528,6 +530,25 @@ void TFM_OT_tosphere(struct wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 }
 
+void TFM_OT_mirror(struct wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name   = "Mirror";
+       ot->description= "Mirror selected vertices around one or more axes.";
+       ot->idname = OP_MIRROR;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
+
+       /* api callbacks */
+       ot->invoke = transform_invoke;
+       ot->exec   = transform_exec;
+       ot->modal  = transform_modal;
+       ot->cancel  = transform_cancel;
+       ot->poll   = ED_operator_areaactive;
+
+       Properties_Proportional(ot);
+       Properties_Constraints(ot);
+}
+
 void TFM_OT_transform(struct wmOperatorType *ot)
 {
        static EnumPropertyItem transform_mode_types[] = {
@@ -595,6 +616,7 @@ void transform_operatortypes(void)
        WM_operatortype_append(TFM_OT_shrink_fatten);
        WM_operatortype_append(TFM_OT_tilt);
        WM_operatortype_append(TFM_OT_trackball);
+       WM_operatortype_append(TFM_OT_mirror);
 
        WM_operatortype_append(TFM_OT_select_orientation);
 }
@@ -699,8 +721,7 @@ void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *key
 
                        km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
 
-                       km = WM_keymap_add_item(keymap, "TFM_OT_transform", MKEY, KM_PRESS, 0, 0);
-                       RNA_int_set(km->ptr, "mode", TFM_MIRROR);
+                       km = WM_keymap_add_item(keymap, "TFM_OT_mirror", MKEY, KM_PRESS, 0, 0);
                        break;
                default:
                        break;
index a44421e8145ccbe2819aeb983a58abee957c72b4..9051300e117cd4bf570ea35067616d4b11610c67 100644 (file)
@@ -942,50 +942,6 @@ static void select_linked(Scene *scene, Image *ima, EditMesh *em, float limit[2]
        EM_free_uv_vert_map(vmap);
 }
 
-/* ******************** mirror operator **************** */
-
-static int mirror_exec(bContext *C, wmOperator *op)
-{
-       float mat[3][3];
-       int axis;
-       
-       Mat3One(mat);
-       axis= RNA_enum_get(op->ptr, "axis");
-
-       if(axis == 'x') {
-               /* XXX initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
-               BIF_setSingleAxisConstraint(mat[0], " on X axis");
-               Transform(); */
-       }
-       else {
-               /* XXX initTransform(TFM_MIRROR, CTX_NO_PET|CTX_AUTOCONFIRM);
-               BIF_setSingleAxisConstraint(mat[1], " on Y axis");
-               Transform(); */
-       }
-
-       return OPERATOR_FINISHED;
-}
-
-void UV_OT_mirror(wmOperatorType *ot)
-{
-       static EnumPropertyItem axis_items[] = {
-               {'x', "MIRROR_X", 0, "Mirror X", "Mirror UVs over X axis."},
-               {'y', "MIRROR_Y", 0, "Mirror Y", "Mirror UVs over Y axis."},
-               {0, NULL, 0, NULL, NULL}};
-
-       /* identifiers */
-       ot->name= "Mirror";
-       ot->idname= "UV_OT_mirror";
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-       
-       /* api callbacks */
-       ot->exec= mirror_exec;
-       ot->poll= ED_operator_uvedit;
-
-       /* properties */
-       RNA_def_enum(ot->srna, "axis", axis_items, 'x', "Axis", "Axis to mirror UV locations over.");
-}
-
 /* ******************** align operator **************** */
 
 static void weld_align_uv(bContext *C, int tool)
@@ -3092,7 +3048,6 @@ void ED_operatortypes_uvedit(void)
        WM_operatortype_append(UV_OT_snap_selection);
 
        WM_operatortype_append(UV_OT_align);
-       WM_operatortype_append(UV_OT_mirror);
        WM_operatortype_append(UV_OT_stitch);
        WM_operatortype_append(UV_OT_weld);
        WM_operatortype_append(UV_OT_pin);
index c18c9f8e022ad25794393b003a089335d40cddb7..b20d390fb4d0f0099f1374ef967173efb759bdcc 100644 (file)
@@ -44,6 +44,7 @@
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
+#include "BKE_image.h"
 #include "BKE_mesh.h"
 #include "BKE_utildefines.h"
 
@@ -75,6 +76,11 @@ static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit)
        EditMesh *em= BKE_mesh_get_editmesh((Mesh*)obedit->data);
        EditFace *efa;
        MTFace *tf;
+       Image *ima;
+       bScreen *sc;
+       ScrArea *sa;
+       SpaceLink *slink;
+       SpaceImage *sima;
 
        if(ED_uvedit_test(obedit)) {
                BKE_mesh_end_editmesh(obedit->data, em);
@@ -88,10 +94,31 @@ static int ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit)
                BKE_mesh_end_editmesh(obedit->data, em);
                return 0;
        }
+
+       ima= CTX_data_edit_image(C);
+
+       if(!ima) {
+               /* no image in context in the 3d view, we find first image window .. */
+               sc= CTX_wm_screen(C);
+
+               for(sa=sc->areabase.first; sa; sa=sa->next) {
+                       slink= sa->spacedata.first;
+                       if(slink->spacetype == SPACE_IMAGE) {
+                               sima= (SpaceImage*)slink;
+
+                               ima= sima->image;
+                               if(ima) {
+                                       if(ima->type==IMA_TYPE_R_RESULT || ima->type==IMA_TYPE_COMPOSITE)
+                                               ima= NULL;
+                                       else
+                                               break;
+                               }
+                       }
+               }
+       }
        
-       // XXX this image is not in context in 3d view .. only
-       // way to get would be to find the first image window?
-       ED_uvedit_assign_image(scene, obedit, CTX_data_edit_image(C), NULL);
+       if(ima)
+               ED_uvedit_assign_image(scene, obedit, ima, NULL);
        
        /* select new UV's */
        for(efa=em->faces.first; efa; efa=efa->next) {
index 417ace6a455a25fe172dffe49f215dd843f67122..e4bda24cf20171b919d3819771472404c4df39bc 100644 (file)
@@ -2748,7 +2748,7 @@ int RNA_property_is_set(PointerRNA *ptr, const char *name)
                return (rna_idproperty_find(ptr, name) != NULL);
        }
        else {
-               printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name);
+               // printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name);
                return 0;
        }
 }