Tool System: use tools for node editor
authorCampbell Barton <ideasman42@gmail.com>
Tue, 27 Nov 2018 07:39:29 +0000 (18:39 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 27 Nov 2018 07:43:08 +0000 (18:43 +1100)
release/scripts/presets/keyconfig/keymap_data/blender_default.py
release/scripts/startup/bl_ui/space_node.py
release/scripts/startup/bl_ui/space_toolsystem_common.py
release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
source/blender/editors/space_node/space_node.c
source/blender/makesrna/intern/rna_workspace.c
source/blender/windowmanager/WM_toolsystem.h
source/blender/windowmanager/intern/wm_toolsystem.c

index 6b8e459..706eade 100644 (file)
@@ -5050,6 +5050,46 @@ def km_image_editor_tool_uv_select_lasso(params):
     )
 
 
+def km_node_editor_tool_select(params):
+    return (
+        "Node Tool: Select",
+        {"space_type": 'NODE_EDITOR', "region_type": 'WINDOW'},
+        {"items": (
+            ("node.select", {"type": params.select_mouse, "value": 'PRESS'},
+             {"properties": [("extend", False)]}),
+        ),
+        },
+    )
+
+
+def km_node_editor_tool_select_box(params):
+    return (
+        "Node Tool: Select Box",
+        {"space_type": 'NODE_EDITOR', "region_type": 'WINDOW'},
+        {"items": (
+            ("node.select_box", {"type": params.tool_mouse, "value": 'PRESS'},
+              {"properties": [("deselect", False), ("tweak", True)]}),
+            ("node.select_box", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
+              {"properties": [("deselect", True), ("tweak", True)]}),
+        ),
+        },
+    )
+
+
+def km_node_editor_tool_select_lasso(params):
+    return (
+        "Node Tool: Select Lasso",
+        {"space_type": 'NODE_EDITOR', "region_type": 'WINDOW'},
+        {"items": (
+            ("node.select_lasso", {"type": params.tool_mouse, "value": 'PRESS'},
+              {"properties": [("deselect", False)]}),
+            ("node.select_lasso", {"type": params.tool_mouse, "value": 'PRESS', "ctrl": True},
+              {"properties": [("deselect", True)]}),
+        ),
+        },
+    )
+
+
 def km_3d_view_tool_object_cursor(params):
     return (
         "3D View Tool: Object, Cursor",
@@ -5902,6 +5942,9 @@ def generate_keymaps(params=None):
         km_image_editor_tool_uv_select_box(params),
         km_image_editor_tool_uv_select_circle(params),
         km_image_editor_tool_uv_select_lasso(params),
+        km_node_editor_tool_select(params),
+        km_node_editor_tool_select_box(params),
+        km_node_editor_tool_select_lasso(params),
         km_3d_view_tool_object_cursor(params),
         km_3d_view_tool_object_select(params),
         km_3d_view_tool_object_select_box(params),
index 789fc1b..6ec264f 100644 (file)
@@ -553,18 +553,6 @@ class NODE_PT_grease_pencil_tools(GreasePencilToolsPanel, Panel):
     # toolbar, but which may not necessarily be open
 
 
-# Tool Shelf ------------------
-
-
-# Grease Pencil drawing tools
-class NODE_PT_tools_grease_pencil_draw(AnnotationDrawingToolsPanel, Panel):
-    bl_space_type = 'NODE_EDITOR'
-    bl_region_type = 'TOOLS'
-
-
-# -----------------------------
-
-
 def node_draw_tree_view(layout, context):
     pass
 
@@ -587,7 +575,6 @@ classes = (
     NODE_UL_interface_sockets,
     NODE_PT_grease_pencil,
     NODE_PT_grease_pencil_tools,
-    NODE_PT_tools_grease_pencil_draw,
 )
 
 
index 2ff5c96..9349f77 100644 (file)
@@ -293,6 +293,12 @@ class ToolSelectPanelHelper:
             if tool is not None:
                 tool.refresh_from_context()
                 return tool
+        elif space_type == 'NODE_EDITOR':
+            space_data = context.space_data
+            tool = context.workspace.tools.from_space_node(create=create)
+            if tool is not None:
+                tool.refresh_from_context()
+                return tool
         return None
 
     @staticmethod
index 1f2b4ca..cefc900 100644 (file)
@@ -1164,6 +1164,49 @@ class _defs_gpencil_weight:
         )
 
 
+class _defs_node_select:
+
+    @ToolDef.from_fn
+    def select():
+        def draw_settings(context, layout, tool):
+            pass
+        return dict(
+            text="Select",
+            icon="ops.generic.select",
+            widget=None,
+            keymap="Node Tool: Select",
+            draw_settings=draw_settings,
+        )
+
+    @ToolDef.from_fn
+    def box():
+        def draw_settings(context, layout, tool):
+            props = tool.operator_properties("node.select_box")
+            layout.prop(props, "deselect")
+            pass
+        return dict(
+            text="Select Box",
+            icon="ops.generic.select_box",
+            widget=None,
+            keymap="Node Tool: Select Box",
+            draw_settings=draw_settings,
+        )
+
+    @ToolDef.from_fn
+    def lasso():
+        def draw_settings(context, layout, tool):
+            props = tool.operator_properties("node.select_lasso")
+            layout.prop(props, "deselect")
+            pass
+        return dict(
+            text="Select Lasso",
+            icon="ops.generic.select_lasso",
+            widget=None,
+            keymap="Node Tool: Select Lasso",
+            draw_settings=draw_settings,
+        )
+
+
 class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel):
     bl_space_type = 'IMAGE_EDITOR'
     bl_region_type = 'TOOLS'
@@ -1243,6 +1286,59 @@ class IMAGE_PT_tools_active(ToolSelectPanelHelper, Panel):
     }
 
 
+class NODE_PT_tools_active(ToolSelectPanelHelper, Panel):
+    bl_space_type = 'NODE_EDITOR'
+    bl_region_type = 'TOOLS'
+    bl_label = "Tools"  # not visible
+    bl_options = {'HIDE_HEADER'}
+
+    # Satisfy the 'ToolSelectPanelHelper' API.
+    keymap_prefix = "Node Editor Tool:"
+
+    @classmethod
+    def tools_from_context(cls, context, mode=None):
+        if mode is None:
+            if context.space_data is None:
+                mode = None
+            else:
+                mode = context.space_data.tree_type
+        for tools in (cls._tools[None], cls._tools.get(mode, ())):
+            for item in tools:
+                if not (type(item) is ToolDef) and callable(item):
+                    yield from item(context)
+                else:
+                    yield item
+
+    @classmethod
+    def tools_all(cls):
+        yield from cls._tools.items()
+
+    _tools_select = (
+        (
+            _defs_node_select.select,
+            _defs_node_select.box,
+            _defs_node_select.lasso,
+        ),
+    )
+
+    _tools_annotate = (
+        (
+            _defs_annotate.scribble,
+            _defs_annotate.line,
+            _defs_annotate.poly,
+            _defs_annotate.eraser,
+        ),
+    )
+
+    _tools = {
+        None: [
+            *_tools_select,
+            None,
+            *_tools_annotate,
+        ],
+    }
+
+
 class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
     bl_space_type = 'VIEW_3D'
     bl_region_type = 'TOOLS'
@@ -1507,6 +1603,7 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
 
 classes = (
     IMAGE_PT_tools_active,
+    NODE_PT_tools_active,
     VIEW3D_PT_tools_active,
 )
 
index 85820ec..8af5fe1 100644 (file)
@@ -1014,10 +1014,12 @@ void ED_spacetype_node(void)
        /* regions: toolbar */
        art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tools region");
        art->regionid = RGN_TYPE_TOOLS;
-       art->prefsizex = 160; /* XXX */
+       art->prefsizex = 58; /* XXX */
        art->prefsizey = 50; /* XXX */
        art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
        art->listener = node_region_listener;
+       art->message_subscribe = ED_region_generic_tools_region_message_subscribe;
+       art->snap_size = ED_region_generic_tools_region_snap_size;
        art->init = node_toolbar_region_init;
        art->draw = node_toolbar_region_draw;
        BLI_addhead(&st->regiontypes, art);
index 59b1086..a79dc05 100644 (file)
@@ -132,6 +132,12 @@ static bToolRef *rna_WorkSpace_tools_from_space_image_mode(
        return rna_WorkSpace_tools_from_tkey(workspace, &(bToolKey){ .space_type = SPACE_IMAGE, .mode = mode}, create);
 }
 
+static bToolRef *rna_WorkSpace_tools_from_space_node(
+        WorkSpace *workspace, bool create)
+{
+       return rna_WorkSpace_tools_from_tkey(workspace, &(bToolKey){ .space_type = SPACE_NODE, .mode = 0}, create);
+}
+
 const EnumPropertyItem *rna_WorkSpace_tools_mode_itemf(
         bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
 {
@@ -301,6 +307,13 @@ static void rna_def_workspace_tools(BlenderRNA *brna, PropertyRNA *cprop)
        /* return type */
        parm = RNA_def_pointer(func, "result", "WorkspaceTool", "", "");
        RNA_def_function_return(func, parm);
+
+       func = RNA_def_function(srna, "from_space_node", "rna_WorkSpace_tools_from_space_node");
+       RNA_def_function_ui_description(func, "");
+       RNA_def_boolean(func, "create", false, "Create", "");
+       /* return type */
+       parm = RNA_def_pointer(func, "result", "WorkspaceTool", "", "");
+       RNA_def_function_return(func, parm);
 }
 
 static void rna_def_workspace(BlenderRNA *brna)
index 7410bf4..9b056dd 100644 (file)
@@ -46,9 +46,9 @@ struct WorkSpace;
 /* wm_toolsystem.c  */
 
 #define WM_TOOLSYSTEM_SPACE_MASK ( \
-       (1 << SPACE_VIEW3D) | \
-       (1 << SPACE_IMAGE) \
-)
+       (1 << SPACE_IMAGE) | \
+       (1 << SPACE_NODE) | \
+       (1 << SPACE_VIEW3D) )
 
 /* Values that define a categoey of active tool. */
 typedef struct bToolKey { int space_type; int mode; } bToolKey;
index d1173fc..6857e05 100644 (file)
@@ -613,6 +613,11 @@ int WM_toolsystem_mode_from_spacetype(
                        mode = sima->mode;
                        break;
                }
+               case SPACE_NODE:
+               {
+                       mode = 0;
+                       break;
+               }
        }
        return mode;
 }