[Bf-blender-cvs] [293c4768220] functions: initial support for reordering group inputs

Jacques Lucke noreply at git.blender.org
Thu Dec 5 19:55:39 CET 2019


Commit: 293c47682205f791272498cc77b8dbaeb4745368
Author: Jacques Lucke
Date:   Thu Dec 5 13:58:38 2019 +0100
Branches: functions
https://developer.blender.org/rB293c47682205f791272498cc77b8dbaeb4745368

initial support for reordering group inputs

===================================================================

M	release/scripts/startup/nodes/function_nodes/groups.py
M	source/blender/blenkernel/intern/inlined_node_tree.cc

===================================================================

diff --git a/release/scripts/startup/nodes/function_nodes/groups.py b/release/scripts/startup/nodes/function_nodes/groups.py
index 8241fa61c82..cf231c18a0e 100644
--- a/release/scripts/startup/nodes/function_nodes/groups.py
+++ b/release/scripts/startup/nodes/function_nodes/groups.py
@@ -201,13 +201,73 @@ class GroupInterfacePanel(bpy.types.Panel, NodeSidebarPanel):
 
         col = layout.column(align=True)
         col.label(text="Inputs:")
-        for node in tree.get_input_nodes():
-            layout.label(text=node.input_name)
+        box = col.box().column(align=True)
+        for i, node in enumerate(tree.get_input_nodes()):
+            row = box.row(align=True)
+            row.prop(node, "input_name", text="")
+
+            props = row.operator("fn.move_group_interface", text="", icon="TRIA_UP")
+            props.is_input = True
+            props.from_index = i
+            props.offset = -1
+
+            props = row.operator("fn.move_group_interface", text="", icon="TRIA_DOWN")
+            props.is_input = True
+            props.from_index = i
+            props.offset = 1
 
         col = layout.column(align=True)
         col.label(text="Outputs:")
-        for node in tree.get_output_nodes():
-            layout.label(text=node.output_name)
+        box = col.box().column(align=True)
+        for i, node in enumerate(tree.get_output_nodes()):
+            row = box.row(align=True)
+            row.prop(node, "output_name", text="")
+
+            props = row.operator("fn.move_group_interface", text="", icon="TRIA_UP")
+            props.is_input = False
+            props.from_index = i
+            props.offset = -1
+
+            props = row.operator("fn.move_group_interface", text="", icon="TRIA_DOWN")
+            props.is_input = False
+            props.from_index = i
+            props.offset = 1
+
+
+class MoveGroupInterface(bpy.types.Operator):
+    bl_idname = "fn.move_group_interface"
+    bl_label = "Move Group Interface"
+
+    is_input: BoolProperty()
+    from_index: IntProperty()
+    offset: IntProperty()
+
+    def execute(self, context):
+        tree = context.space_data.node_tree
+
+        if self.is_input:
+            nodes = tree.get_input_nodes()
+        else:
+            nodes = tree.get_output_nodes()
+        
+        from_index = self.from_index
+        to_index = min(max(self.from_index + self.offset, 0), len(nodes) - 1)
+
+        nodes[from_index], nodes[to_index] = nodes[to_index], nodes[from_index]
+
+        with skip_syncing():
+            for i, node in enumerate(nodes):
+                node.sort_index = i
+        tree.sync()
+
+        return {"FINISHED"}
+
+
+def update_sort_indices(tree):
+    for i, node in enumerate(tree.get_input_nodes()):
+        node.sort_index = i
+    for i, node in enumerate(tree.get_output_nodes()):
+        node.sort_index = i
 
 
 class ManageGroupPieMenu(bpy.types.Menu, PieMenuHelper):
@@ -319,6 +379,8 @@ class CreateGroupInputForSocket(bpy.types.Operator):
             new_node = tree.nodes.new(type="fn_GroupInputNode")
             new_node.sort_index = 1000
             new_node.input_name = socket.name
+            update_sort_indices(tree)
+            
             if isinstance(socket, DataSocket):
                 new_node.interface_type = "DATA"
                 new_node.data_type = socket.data_type
@@ -357,6 +419,8 @@ class CreateGroupOutputForSocket(bpy.types.Operator):
         with skip_syncing():
             new_node = tree.nodes.new(type="fn_GroupOutputNode")
             new_node.sort_index = 1000
+            update_sort_indices(tree)
+
             new_node.output_name = socket.name
             if isinstance(socket, DataSocket):
                 new_node.interface_type = "DATA"
diff --git a/source/blender/blenkernel/intern/inlined_node_tree.cc b/source/blender/blenkernel/intern/inlined_node_tree.cc
index 66256f71090..83c0c375be2 100644
--- a/source/blender/blenkernel/intern/inlined_node_tree.cc
+++ b/source/blender/blenkernel/intern/inlined_node_tree.cc
@@ -22,6 +22,9 @@ static bool cmp_group_interface_nodes(const VNode *a, const VNode *b)
   if (a_index < b_index) {
     return true;
   }
+  if (a_index > b_index) {
+    return false;
+  }
 
   /* TODO: Match sorting with Python. */
   return BLI_strcasecmp(a->name().data(), b->name().data()) == -1;
@@ -423,9 +426,12 @@ std::string InlinedNodeTree::to_dot() const
           dot_group_input_node.set_attribute("bgcolor", "white");
           dot_group_input_node.set_attribute("style", "filled");
 
-          dot_group_inputs.add_new(group_input,
-                                   BLI::DotExport::Utils::NodeWithSocketsWrapper(
-                                       dot_group_input_node, "Group Input", {}, {"Value"}));
+          std::string group_input_name = group_input->vsocket().name();
+
+          dot_group_inputs.add_new(
+              group_input,
+              BLI::DotExport::Utils::NodeWithSocketsWrapper(
+                  dot_group_input_node, "Group Input", {}, {group_input_name}));
 
           BLI::DotExport::Cluster *cluster = get_cluster_for_parent(
               digraph, dot_clusters, group_input->parent());



More information about the Bf-blender-cvs mailing list