Skip to content

Commit fc729d7

Browse files
committed
topological sort exclude BackDropNode
1 parent 383cba2 commit fc729d7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

NodeGraphQt/base/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def _layout_graph_up(graph):
320320

321321
# topological_sort
322322

323+
323324
def get_input_nodes(node):
324325
"""
325326
Get input nodes of node.
@@ -477,6 +478,14 @@ def dfs(start_node):
477478
return sorted_nodes
478479

479480

481+
def __remove_BackdropNode(nodes):
482+
from .node import BackdropNode
483+
for node in nodes[:]:
484+
if isinstance(node, BackdropNode):
485+
nodes.remove(node)
486+
return nodes
487+
488+
480489
def topological_sort_by_down(start_nodes=[], all_nodes=[]):
481490
"""
482491
Topological sort method by down stream direction.
@@ -488,6 +497,10 @@ def topological_sort_by_down(start_nodes=[], all_nodes=[]):
488497
Returns:
489498
list[NodeGraphQt.BaseNode]: sorted nodes.
490499
"""
500+
if start_nodes:
501+
start_nodes = __remove_BackdropNode(start_nodes)
502+
if all_nodes:
503+
all_nodes = __remove_BackdropNode(all_nodes)
491504

492505
if not start_nodes:
493506
start_nodes = [n for n in all_nodes if not _has_input_node(n)]
@@ -512,6 +525,10 @@ def topological_sort_by_up(start_nodes=[], all_nodes=[]):
512525
Returns:
513526
list[NodeGraphQt.BaseNode]: sorted nodes.
514527
"""
528+
if start_nodes:
529+
start_nodes = __remove_BackdropNode(start_nodes)
530+
if all_nodes:
531+
all_nodes = __remove_BackdropNode(all_nodes)
515532

516533
if not start_nodes:
517534
start_nodes = [n for n in all_nodes if not _has_output_node(n)]
@@ -652,6 +669,10 @@ def auto_layout_up(start_nodes=[], all_nodes=[]):
652669
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the end nodes of the graph.
653670
all_nodes (list[NodeGraphQt.BaseNode])(Optional): if 'start_nodes' is None the function can calculate start nodes from 'all_nodes'.
654671
"""
672+
if start_nodes:
673+
start_nodes = __remove_BackdropNode(start_nodes)
674+
if all_nodes:
675+
all_nodes = __remove_BackdropNode(all_nodes)
655676

656677
if not start_nodes:
657678
start_nodes = [n for n in all_nodes if not _has_output_node(n)]
@@ -693,6 +714,10 @@ def auto_layout_down(start_nodes=[], all_nodes=[]):
693714
start_nodes (list[NodeGraphQt.BaseNode])(Optional): the start update nodes of the graph.
694715
all_nodes (list[NodeGraphQt.BaseNode])(Optional): if 'start_nodes' is None the function can calculate start nodes from 'all_nodes'.
695716
"""
717+
if start_nodes:
718+
start_nodes = __remove_BackdropNode(start_nodes)
719+
if all_nodes:
720+
all_nodes = __remove_BackdropNode(all_nodes)
696721

697722
if not start_nodes:
698723
start_nodes = [n for n in all_nodes if not _has_input_node(n)]

example_auto_nodes/node_base/subgraph_node.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .auto_node import AutoNode
22
from NodeGraphQt import SubGraph
33
import json
4-
from NodeGraphQt import topological_sort_by_down
4+
from NodeGraphQt import topological_sort_by_down, BackdropNode
55

66

77
class SubGraphNode(AutoNode, SubGraph):
@@ -220,6 +220,8 @@ def create_from_nodes(self, nodes):
220220
connected = []
221221

222222
for node in nodes:
223+
if isinstance(node, BackdropNode):
224+
continue
223225
for port in node.input_ports():
224226
for pipe in port.view.connected_pipes:
225227
if pipe.output_port.isVisible():

0 commit comments

Comments
 (0)