Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / transform / transform_ops.c
index 4157b69fded1dfe4e84628c070c482a9584d2a45..36c444a0ca35dd1b28417cbb7b428273e3573561 100644 (file)
@@ -160,11 +160,12 @@ const EnumPropertyItem rna_enum_transform_mode_types[] =
 
 static int select_orientation_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene = CTX_data_scene(C);
        int orientation = RNA_enum_get(op->ptr, "orientation");
 
-       BIF_selectTransformOrientationValue(C, orientation);
+       BIF_selectTransformOrientationValue(scene, orientation);
 
-       WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
+       WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
 
        return OPERATOR_FINISHED;
 }
@@ -205,13 +206,10 @@ static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
 
 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
 {
-       View3D *v3d = CTX_wm_view3d(C);
-       int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
+       Scene *scene = CTX_data_scene(C);
+       BIF_removeTransformOrientationIndex(C, scene->orientation_index_custom);
 
-       BIF_removeTransformOrientationIndex(C, selected_index);
-
-       WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
-       WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
+       WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
 
        return OPERATOR_FINISHED;
 }
@@ -223,18 +221,12 @@ static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent
 
 static int delete_orientation_poll(bContext *C)
 {
-       int selected_index = -1;
-       View3D *v3d = CTX_wm_view3d(C);
+       Scene *scene = CTX_data_scene(C);
 
        if (ED_operator_areaactive(C) == 0)
                return 0;
 
-
-       if (v3d) {
-               selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
-       }
-
-       return selected_index >= 0;
+       return (scene->orientation_type >= V3D_MANIP_CUSTOM) && (scene->orientation_index_custom != -1);
 }
 
 static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
@@ -289,6 +281,9 @@ static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
        RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the new custom orientation");
        RNA_def_boolean(ot->srna, "use_view", false, "Use View",
                        "Use the current view instead of the active object to create the new orientation");
+
+       WM_operatortype_props_advanced_begin(ot);
+
        RNA_def_boolean(ot->srna, "use", false, "Use after creation", "Select orientation after its creation");
        RNA_def_boolean(ot->srna, "overwrite", false, "Overwrite previous",
                        "Overwrite previously created orientation with same name");
@@ -319,7 +314,8 @@ static void transformops_loopsel_hack(bContext *C, wmOperator *op)
 
                                /* still switch if we were originally in face select mode */
                                if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
-                                       BMEditMesh *em = BKE_editmesh_from_object(scene->obedit);
+                                       Object *obedit = CTX_data_edit_object(C);
+                                       BMEditMesh *em = BKE_editmesh_from_object(obedit);
                                        em->selectmode = ts->selectmode = selectmode_orig;
                                        EDBM_selectmode_set(em);
                                }
@@ -483,7 +479,10 @@ static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                return OPERATOR_CANCELLED;
        }
 
-       if (RNA_struct_property_is_set(op->ptr, "value")) {
+       /* When modal, allow 'value' to set initial offset. */
+       if ((event == NULL) &&
+           RNA_struct_property_is_set(op->ptr, "value"))
+       {
                return transform_exec(C, op);
        }
        else {
@@ -491,6 +490,15 @@ static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
                WM_event_add_modal_handler(C, op);
 
                op->flag |= OP_IS_MODAL_GRAB_CURSOR; // XXX maybe we want this with the manipulator only?
+
+               /* Use when modal input has some transformation to begin with. */
+               {
+                       TransInfo *t = op->customdata;
+                       if (UNLIKELY(!is_zero_v4(t->values_modal_offset))) {
+                               transformApply(C, t);
+                       }
+               }
+
                return OPERATOR_RUNNING_MODAL;
        }
 }
@@ -599,6 +607,8 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
 
        RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
 }
 
@@ -619,6 +629,8 @@ static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
 
        RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(
                ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CENTER);
 }
@@ -650,6 +662,8 @@ static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
 
        RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
 }
 
@@ -671,6 +685,8 @@ static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
        /* Maybe we could use float_vector_xyz here too? */
        RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
 }
 
@@ -691,6 +707,8 @@ static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
 
        RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(
                ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT | P_CENTER);
 }
@@ -715,6 +733,8 @@ static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
 
        RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
 }
 
@@ -735,6 +755,8 @@ static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
 
        RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
 }
 
@@ -755,6 +777,8 @@ static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
 
        RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
        // XXX Shear axis?
 }
@@ -776,6 +800,8 @@ static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
 
        RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_CENTER);
 }
 
@@ -798,6 +824,8 @@ static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
 
        RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness");
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
 }
 
@@ -819,6 +847,8 @@ static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
 
        RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
 }
 
@@ -863,6 +893,9 @@ static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
        RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
        RNA_def_boolean(ot->srna, "use_even", false, "Even",
                        "Make the edge loop match the shape of the adjacent edge loop");
+
+       WM_operatortype_props_advanced_begin(ot);
+
        RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
                        "When Even mode is active, flips between the two adjacent edge loops");
        RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
@@ -889,6 +922,9 @@ static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
        RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
        RNA_def_boolean(ot->srna, "use_even", false, "Even",
                        "Make the edge loop match the shape of the adjacent edge loop");
+
+       WM_operatortype_props_advanced_begin(ot);
+
        RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
                        "When Even mode is active, flips between the two adjacent edge loops");
        RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
@@ -914,6 +950,8 @@ static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
 
        RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_SNAP);
 }
 
@@ -955,6 +993,8 @@ static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
 
        RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_SNAP);
 }
 
@@ -975,6 +1015,8 @@ static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
 
        RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(ot, P_SNAP);
 }
 
@@ -1000,6 +1042,8 @@ static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
 
        RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
 
+       WM_operatortype_props_advanced_begin(ot);
+
        Transform_Properties(
                ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT | P_CENTER);
 }
@@ -1066,6 +1110,8 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
                        kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
                        RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_element");
 
+                       /* Will fall-through to texture-space transform. */
+                       kmi = WM_keymap_add_item(keymap, "OBJECT_OT_transform_axis_target", TKEY, KM_PRESS, KM_SHIFT, 0);
 
                        kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
                        RNA_boolean_set(kmi->ptr, "texture_space", true);