From 15d77f17a40398a63f95e16607deb81257c02698 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 10 Sep 2009 11:04:53 +0000 Subject: [PATCH] 2.5: UV Edit * 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 | 20 ++++++--- .../blender/editors/transform/transform_ops.c | 25 ++++++++++- source/blender/editors/uvedit/uvedit_ops.c | 45 ------------------- .../editors/uvedit/uvedit_unwrap_ops.c | 33 ++++++++++++-- source/blender/makesrna/intern/rna_access.c | 2 +- 5 files changed, 67 insertions(+), 58 deletions(-) diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 1f568be3e10..f049566d640 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -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) + if (RNA_struct_find_property(op->ptr, "value")) { - RNA_float_set_array(op->ptr, "value", t->auto_values); - } - else - { - 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; diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 08d22faf7e7..4ae0bca3284 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -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; diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index a44421e8145..9051300e117 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -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); diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index c18c9f8e022..b20d390fb4d 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -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) { diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 417ace6a455..e4bda24cf20 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -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; } }