Skip to content

Commit

Permalink
Merge pull request #242 from wilecoyote2015/master
Browse files Browse the repository at this point in the history
Fix building connections when duplicating / pasting nodes
  • Loading branch information
jchanvfx authored Mar 23, 2022
2 parents c2ad7ce + 4e22c54 commit bccd8d8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,22 +1392,33 @@ def _deserialize(self, data, relative_pos=False, pos=None, set_parent=True):
'output_ports': n_data['output_ports']
})

def get_node_by_id(nid):
# if nid referes to a node created during deserialization,
# it may have a new id. get the new id.
if nid in nodes:
print(f'{nid}, {nodes[nid].id}')
nid = nodes[nid].id
return self.model.nodes.get(nid)

# build the connections.
for connection in data.get('connections', []):
nid, pname = connection.get('in', ('', ''))
in_node = nodes.get(nid)
in_node = get_node_by_id(nid)
if not in_node:
continue
in_port = in_node.inputs().get(pname) if in_node else None

nid, pname = connection.get('out', ('', ''))
out_node = nodes.get(nid)
out_node = get_node_by_id(nid)
if not out_node:
continue
out_port = out_node.outputs().get(pname) if out_node else None

if in_port and out_port:
self._undo_stack.push(PortConnectedCmd(in_port, out_port))
# only connect if input port is not connected yet or input port can have multiple connections.
# important when duplicating nodes.
if not in_port.model.connected_ports or in_port.model.multi_connection:
self._undo_stack.push(PortConnectedCmd(in_port, out_port))

node_objs = list(nodes.values())
if relative_pos:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Qt.py>=1.2.0
qt.py==1.3.6
pyqt5==5.15.6

0 comments on commit bccd8d8

Please sign in to comment.