3D View: add back transform tool
authorCampbell Barton <ideasman42@gmail.com>
Thu, 23 May 2019 15:35:48 +0000 (01:35 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 23 May 2019 15:38:07 +0000 (01:38 +1000)
Further changes are planned in T64928,
this is just the initial basic version.

release/scripts/presets/keyconfig/keymap_data/blender_default.py
release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
source/blender/editors/transform/transform_gizmo_3d.c
source/blender/editors/transform/transform_ops.c

index a326bedbaa0479615e83a9c9c3c1ca08c3ef8b73..a344d4c7d50cec6adc3c339239ac6e6312d2f8cb 100644 (file)
@@ -5060,6 +5060,7 @@ def km_popup_toolbar(_params):
         {"items": [
             op_tool("builtin.select", {"type": 'W', "value": 'PRESS'}),
             op_tool("builtin.select_lasso", {"type": 'L', "value": 'PRESS'}),
+            op_tool("builtin.transform", {"type": 'T', "value": 'PRESS'}),
             op_tool("builtin.measure", {"type": 'M', "value": 'PRESS'}),
         ]},
     )
@@ -5298,6 +5299,16 @@ def km_3d_view_tool_select_lasso(params):
     )
 
 
+def km_3d_view_tool_transform(params):
+    return (
+        "3D View Tool: Transform",
+        {"space_type": 'VIEW_3D', "region_type": 'WINDOW'},
+        {"items": [
+            ("transform.from_gizmo", {"type": params.tool_tweak, "value": 'ANY'}, None),
+        ]},
+    )
+
+
 def km_3d_view_tool_move(params):
     return (
         "3D View Tool: Move",
@@ -6178,6 +6189,7 @@ def generate_keymaps(params=None):
         km_3d_view_tool_select_box(params),
         km_3d_view_tool_select_circle(params),
         km_3d_view_tool_select_lasso(params),
+        km_3d_view_tool_transform(params),
         km_3d_view_tool_move(params),
         km_3d_view_tool_rotate(params),
         km_3d_view_tool_scale(params),
index f429904d3fb54cf48dbfd5122f59fa136df82ecc..db29a284a49898df1537cb323f0ea650dec15dfd 100644 (file)
@@ -292,6 +292,30 @@ class _defs_transform:
             draw_settings=draw_settings,
         )
 
+    @ToolDef.from_fn
+    def transform():
+        def draw_settings(context, layout, tool):
+            if not layout.use_property_split:
+                layout.label(text="Gizmos:")
+            tool_settings = context.tool_settings
+
+            props = tool.gizmo_group_properties("VIEW3D_GGT_xform_gizmo")
+            layout.prop(props, "drag_action")
+
+            _template_widget.VIEW3D_GGT_xform_gizmo.draw_settings_with_index(context, layout, 1)
+
+        return dict(
+            idname="builtin.transform",
+            label="Transform",
+            description=(
+                "Supports any combination of grab, rotate & scale at once"
+            ),
+            icon="ops.transform.transform",
+            widget="VIEW3D_GGT_xform_gizmo",
+            keymap="3D View Tool: Transform",
+            draw_settings=draw_settings,
+        )
+
 
 class _defs_view3d_select:
 
@@ -1685,6 +1709,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
 
     # for reuse
     _tools_transform = (
+        _defs_transform.transform,
         _defs_transform.translate,
         _defs_transform.rotate,
         (
index e43379dc35828eeddafd5fa2b608357553868d0a..16dcd053f9d89d6aae0efade6be408c226ca513a 100644 (file)
@@ -1661,7 +1661,12 @@ static void WIDGETGROUP_gizmo_setup(const bContext *C, wmGizmoGroup *gzgroup)
     else if (tref && STREQ(tref->idname, "builtin.scale")) {
       ggd->twtype |= V3D_GIZMO_SHOW_OBJECT_SCALE;
     }
+    else if (tref && STREQ(tref->idname, "builtin.transform")) {
+      ggd->twtype = V3D_GIZMO_SHOW_OBJECT_TRANSLATE | V3D_GIZMO_SHOW_OBJECT_ROTATE |
+                    V3D_GIZMO_SHOW_OBJECT_SCALE;
+    }
     else {
+      /* This is also correct logic for 'builtin.transform', no special check needed. */
       /* Setup all gizmos, they can be toggled via 'ToolSettings.gizmo_flag' */
       ggd->twtype = V3D_GIZMO_SHOW_OBJECT_TRANSLATE | V3D_GIZMO_SHOW_OBJECT_ROTATE |
                     V3D_GIZMO_SHOW_OBJECT_SCALE;
@@ -1990,6 +1995,20 @@ void VIEW3D_GGT_xform_gizmo(wmGizmoGroupType *gzgt)
   gzgt->message_subscribe = WIDGETGROUP_gizmo_message_subscribe;
   gzgt->draw_prepare = WIDGETGROUP_gizmo_draw_prepare;
   gzgt->invoke_prepare = WIDGETGROUP_gizmo_invoke_prepare;
+
+  static const EnumPropertyItem rna_enum_gizmo_items[] = {
+      {V3D_GIZMO_SHOW_OBJECT_TRANSLATE, "TRANSLATE", 0, "Move", ""},
+      {V3D_GIZMO_SHOW_OBJECT_ROTATE, "ROTATE", 0, "Rotate", ""},
+      {V3D_GIZMO_SHOW_OBJECT_SCALE, "SCALE", 0, "Scale", ""},
+      {0, "NONE", 0, "None", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
+  RNA_def_enum(gzgt->srna,
+               "drag_action",
+               rna_enum_gizmo_items,
+               V3D_GIZMO_SHOW_OBJECT_TRANSLATE,
+               "Drag Action",
+               "");
 }
 
 /** Only poll, flag & gzmap_params differ. */
index cdd0896ab660612f62436a87ac2fe87210c4a792..f028f2dc506568ca52e11d5640423e773e26ed13 100644 (file)
@@ -1210,6 +1210,60 @@ static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
                            P_ALIGN_SNAP | P_GPENCIL_EDIT | P_CENTER);
 }
 
+static int transform_from_gizmo_invoke(bContext *C,
+                                       wmOperator *UNUSED(op),
+                                       const wmEvent *UNUSED(event))
+{
+  bToolRef *tref = WM_toolsystem_ref_from_context(C);
+  if (tref) {
+    ARegion *ar = CTX_wm_region(C);
+    wmGizmoMap *gzmap = ar->gizmo_map;
+    wmGizmoGroup *gzgroup = gzmap ? WM_gizmomap_group_find(gzmap, "VIEW3D_GGT_xform_gizmo") : NULL;
+    if (gzgroup != NULL) {
+      PointerRNA gzg_ptr;
+      WM_toolsystem_ref_properties_ensure_from_gizmo_group(tref, gzgroup->type, &gzg_ptr);
+      const int drag_action = RNA_enum_get(&gzg_ptr, "drag_action");
+      const char *op_id = NULL;
+      switch (drag_action) {
+        case V3D_GIZMO_SHOW_OBJECT_TRANSLATE:
+          op_id = "TRANSFORM_OT_translate";
+          break;
+        case V3D_GIZMO_SHOW_OBJECT_ROTATE:
+          op_id = "TRANSFORM_OT_rotate";
+          break;
+        case V3D_GIZMO_SHOW_OBJECT_SCALE:
+          op_id = "TRANSFORM_OT_resize";
+          break;
+        default:
+          break;
+      }
+      if (op_id) {
+        wmOperatorType *ot = WM_operatortype_find(op_id, true);
+        PointerRNA op_ptr;
+        WM_operator_properties_create_ptr(&op_ptr, ot);
+        RNA_boolean_set(&op_ptr, "release_confirm", true);
+        WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_ptr);
+        WM_operator_properties_free(&op_ptr);
+        return OPERATOR_FINISHED;
+      }
+    }
+  }
+  return OPERATOR_PASS_THROUGH;
+}
+
+/* Use with 'TRANSFORM_GGT_gizmo'. */
+static void TRANSFORM_OT_from_gizmo(struct wmOperatorType *ot)
+{
+  /* identifiers */
+  ot->name = "Transform From Gizmo";
+  ot->description = "Transform selected items by mode type";
+  ot->idname = "TRANSFORM_OT_from_gizmo";
+  ot->flag = 0;
+
+  /* api callbacks */
+  ot->invoke = transform_from_gizmo_invoke;
+}
+
 void transform_operatortypes(void)
 {
   TransformModeItem *tmode;
@@ -1223,6 +1277,8 @@ void transform_operatortypes(void)
   WM_operatortype_append(TRANSFORM_OT_select_orientation);
   WM_operatortype_append(TRANSFORM_OT_create_orientation);
   WM_operatortype_append(TRANSFORM_OT_delete_orientation);
+
+  WM_operatortype_append(TRANSFORM_OT_from_gizmo);
 }
 
 void ED_keymap_transform(wmKeyConfig *keyconf)