Skip to content

Commit 766c56e

Browse files
author
Fabien Servant
committed
Enable connecting multiple list Attributes
1 parent 912a71d commit 766c56e

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

meshroom/ui/graph.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,11 +1231,37 @@ def clearDataFrom(self, nodes: list[Node]):
12311231
@Slot(Attribute, Attribute)
12321232
def addEdge(self, src, dst):
12331233
if isinstance(src, ListAttribute) and not isinstance(dst, ListAttribute):
1234+
# Source is a list, Destination is not a list
1235+
# Connect first attribute of the list to the destination
12341236
self._addEdge(src.at(0), dst)
12351237
elif isinstance(dst, ListAttribute) and not isinstance(src, ListAttribute):
1238+
# Source is not a list, Destination is a list
1239+
# Append the source to the destination's list attributes
12361240
with self.groupedGraphModification(f"Insert and Add Edge on {dst.fullName}"):
12371241
self.appendAttribute(dst)
12381242
self._addEdge(src, dst.at(-1))
1243+
elif isinstance(src, ListAttribute) and isinstance(dst, ListAttribute):
1244+
# Both Source and Destination attributes are listAttributes
1245+
with self.groupedGraphModification(f"Insert and Add Edges on {dst.fullName}"):
1246+
1247+
if dst.isLink:
1248+
# Destination link is only a *view* on the listAttributes provided
1249+
# by the connected node. Therefore there is no meaning modifying the
1250+
# ListAttribute. We will therefore remove the existing link and create
1251+
# links for each attributes of the list. The listAttribute will be owned
1252+
# by the destination node and contains *views* on source individual attributes
1253+
existingEdge = self._graph.edge(dst)
1254+
existingSrc = existingEdge.src # the previously connected ListAttribute
1255+
self.push(commands.RemoveEdgeCommand(self._graph, existingEdge))
1256+
for j in range(len(existingSrc)):
1257+
self.appendAttribute(dst)
1258+
self._addEdge(existingSrc.at(j), dst.at(-1))
1259+
1260+
# Add connections betweens the element of the source listAttribute
1261+
# and newly created items of the destination listAttribute
1262+
for i in range(len(src)):
1263+
self.appendAttribute(dst)
1264+
self._addEdge(src.at(i), dst.at(-1))
12391265
else:
12401266
self._addEdge(src, dst)
12411267

meshroom/ui/qml/GraphEditor/AttributePin.qml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,11 @@ RowLayout {
130130
|| drag.source.objectName != inputDragTarget.objectName // Not an edge connector
131131
|| !validIncomingConnection // Connection is not allowed
132132
|| drag.source.nodeItem === inputDragTarget.nodeItem // Connection between attributes of the same node
133-
|| drag.source.isList && childrenRepeater.count // Source/target are lists but target already has children
134133
|| drag.source.connectorType === "input" // Refuse to connect an "input pin" on another one (input attr can be connected to input attr, but not the graphical pin)
135134
) {
136135
// Refuse attributes connection
137136
drag.accepted = false
138-
} else if (inputDragTarget.attribute.isLink) { // Already connected attribute
137+
} else if (inputDragTarget.attribute.isLink && !(drag.source.isList && root.isList)) { // Already connected attribute (not list-to-list, which is additive)
139138
root.edgeAboutToBeRemoved(inputDragTarget.attribute)
140139
}
141140
inputDropArea.acceptableDrop = drag.accepted
@@ -367,12 +366,11 @@ RowLayout {
367366
|| !validIncomingConnection // Connection is not allowed
368367
|| drag.source.nodeItem === outputDragTarget.nodeItem // Connection between attributes of the same node
369368
|| (!drag.source.isList && outputDragTarget.isList) // Connection between a list and a simple attribute
370-
|| (drag.source.isList && childrenRepeater.count) // Source/target are lists but target already has children
371369
|| drag.source.connectorType === "output" // Refuse to connect an output pin on another one
372370
) {
373371
// Refuse attributes connection
374372
drag.accepted = false
375-
} else if (drag.source.attribute.isLink) { // Already connected attribute
373+
} else if (drag.source.attribute.isLink && !(drag.source.isList && root.isList)) { // Already connected attribute (not list-to-list, which is additive)
376374
root.edgeAboutToBeRemoved(drag.source.attribute)
377375
}
378376
outputDropArea.acceptableDrop = drag.accepted

0 commit comments

Comments
 (0)