Skip to content

Commit 5246397

Browse files
[ui/core] GroupAttributes: Make the connection worl for tests (core scripting) and for undos
1 parent 43d4585 commit 5246397

File tree

6 files changed

+232
-2
lines changed

6 files changed

+232
-2
lines changed

meshroom/core/attribute.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@ def connectTo(self, otherAttribute: "Attribute") -> Optional["Edge"]:
536536
if not (graph := self.node.graph):
537537
return None
538538

539+
if isinstance(otherAttribute.root, Attribute):
540+
otherAttribute.root.disconnectEdge()
541+
539542
return graph.addEdge(self, otherAttribute)
540543

541544
def disconnectEdge(self):

meshroom/ui/commands.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ def __init__(self, attribute):
317317
self.fullName = attribute.getFullNameToNode()
318318
self.value = attribute.getExportValue()
319319
self.isGroup = isinstance(attribute, GroupAttribute)
320+
self.linkParam = attribute.getLinkParam().getFullNameToNode() if attribute.isLink else None
320321

321322
def __init__(self, graph, src, dst, parent=None):
322323
super().__init__(graph, parent)
@@ -355,7 +356,11 @@ def _applyStoredAttributes(self):
355356
attribute = graph.attribute(storedAttribute.fullName)
356357
graph.removeEdge(attribute)
357358
attribute.value = storedAttribute.value
358-
attribute._applyExpr()
359+
360+
if storedAttribute.linkParam:
361+
graph.addEdge(graph.attribute(storedAttribute.linkParam), attribute)
362+
363+
#attribute._applyExpr()
359364

360365
def _getSrcAttribute(self):
361366
return self.graph.attribute(self.srcAttr)

tests/nodes/test/color.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from meshroom.core import desc
2+
3+
class Color(desc.Node):
4+
5+
inputs = [
6+
desc.GroupAttribute(
7+
name="rgb",
8+
label="rgb",
9+
description="rgb",
10+
exposed=True,
11+
groupDesc=[
12+
desc.FloatParam(name="r", label="r", description="r", value=0.0),
13+
desc.FloatParam(name="g", label="g", description="g", value=0.0),
14+
desc.FloatParam(name="b", label="b", description="b", value=0.0)
15+
]
16+
)
17+
]
18+
19+
class NestedColor(desc.Node):
20+
21+
inputs = [
22+
desc.GroupAttribute(
23+
name="rgb",
24+
label="rgb",
25+
description="rgb",
26+
exposed=True,
27+
groupDesc=[
28+
desc.FloatParam(name="r", label="r", description="r", value=0.0),
29+
desc.FloatParam(name="g", label="g", description="g", value=0.0),
30+
desc.FloatParam(name="b", label="b", description="b", value=0.0),
31+
desc.GroupAttribute(label="test", name="test", description="",
32+
groupDesc=[
33+
desc.FloatParam(name="r", label="r", description="r", value=0.0),
34+
desc.FloatParam(name="g", label="g", description="g", value=0.0),
35+
desc.FloatParam(name="b", label="b", description="b", value=0.0),
36+
37+
])
38+
]
39+
)
40+
]

tests/nodes/test/position.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from meshroom.core import desc
2+
3+
4+
class Position(desc.Node):
5+
6+
inputs = [
7+
desc.GroupAttribute(
8+
name="xyz",
9+
label="xyz",
10+
description="xyz",
11+
exposed=True,
12+
groupDesc=[
13+
desc.FloatParam(name="x", label="x", description="x", value=0.0),
14+
desc.FloatParam(name="y", label="y", description="y", value=0.0),
15+
desc.FloatParam(name="z", label="z", description="z", value=0.0)
16+
]
17+
)
18+
]
19+
20+
class NestedPosition(desc.Node):
21+
22+
inputs = [
23+
desc.GroupAttribute(
24+
name="xyz",
25+
label="xyz",
26+
description="xyz",
27+
exposed=True,
28+
groupDesc=[
29+
desc.FloatParam(name="x", label="x", description="x", value=0.0),
30+
desc.FloatParam(name="y", label="y", description="y", value=0.0),
31+
desc.FloatParam(name="z", label="z", description="z", value=0.0),
32+
desc.GroupAttribute(label="test", name="test", description="",
33+
groupDesc=[
34+
desc.FloatParam(name="x", label="x", description="x", value=0.0),
35+
desc.FloatParam(name="y", label="y", description="y", value=0.0),
36+
desc.FloatParam(name="z", label="z", description="z", value=0.0),
37+
])
38+
]
39+
)
40+
]

tests/nodes/test/test copy.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from meshroom.core import desc
2+
3+
class NestedTest(desc.Node):
4+
5+
inputs = [
6+
desc.GroupAttribute(
7+
name="xyz",
8+
label="xyz",
9+
description="xyz",
10+
exposed=True,
11+
groupDesc=[
12+
desc.FloatParam(name="x", label="x", description="x", value=0.0),
13+
desc.FloatParam(name="y", label="z", description="z", value=0.0),
14+
desc.FloatParam(name="z", label="z", description="z", value=0.0),
15+
desc.GroupAttribute(label="test", name="test", description="",
16+
groupDesc=[
17+
desc.StringParam(name="x", label="x", description="x", value="test"),
18+
desc.FloatParam(name="y", label="z", description="z", value=0.0),
19+
desc.FloatParam(name="z", label="z", description="z", value=0.0),
20+
])
21+
]
22+
)
23+
]

tests/test_groupAttributes.py

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import tempfile
6+
import math
67

78
from meshroom.core.graph import Graph, loadGraph
89
from meshroom.core.node import CompatibilityNode
@@ -40,6 +41,9 @@ def test_saveLoadGroupConnections():
4041
# Ensure the nodes are not CompatibilityNodes
4142
for node in graph.nodes:
4243
assert not isinstance(node, CompatibilityNode)
44+
45+
46+
4347

4448

4549
def test_groupAttributesFlatChildren():
@@ -100,4 +104,119 @@ def test_groupAttributesDepthLevels():
100104

101105
intAttr = node.attribute("exposedInt")
102106
assert not isinstance(intAttr, GroupAttribute)
103-
assert intAttr.depth == 0
107+
assert intAttr.depth == 0
108+
109+
def test_saveLoadGroupDirectConnections():
110+
"""
111+
112+
"""
113+
graph = Graph("Connections between GroupAttributes")
114+
115+
# Create two "GroupAttributes" nodes with their default parameters
116+
nodeA = graph.addNewNode("GroupAttributes")
117+
nodeB = graph.addNewNode("GroupAttributes")
118+
119+
# Connect attributes within groups at different depth levels
120+
graph.addEdges(
121+
(nodeA.firstGroup, nodeB.firstGroup),
122+
(nodeA.firstGroup, nodeB.firstGroup),
123+
)
124+
125+
# Save the graph in a file
126+
graphFile = os.path.join(tempfile.mkdtemp(), "test_io_group_connections.mg")
127+
graph.save(graphFile)
128+
129+
# Reload the graph
130+
graph = loadGraph(graphFile)
131+
132+
assert graph.node("GroupAttributes_2").firstGroup.getLinkParam() == graph.node("GroupAttributes_1").firstGroup
133+
134+
135+
def test_groupAttributes_with_same_structure_should_allow_connection():
136+
137+
# Given
138+
graph = Graph()
139+
nestedPosition = graph.addNewNode("NestedPosition")
140+
nestedColor = graph.addNewNode("NestedColor")
141+
142+
# When
143+
acceptedConnection = nestedPosition.xyz.isCompatibleWith(nestedColor.rgb)
144+
145+
# Then
146+
assert acceptedConnection == True
147+
148+
def test_groupAttributes_with_different_structure_should_not_allow_connection():
149+
150+
# Given
151+
graph = Graph()
152+
nestedPosition = graph.addNewNode("NestedPosition")
153+
nestedTest = graph.addNewNode("NestedTest")
154+
155+
# When
156+
acceptedConnection = nestedPosition.xyz.isCompatibleWith(nestedTest.xyz)
157+
158+
# Then
159+
assert acceptedConnection == False
160+
161+
def test_groupAttributes_connection_should_connect_all_subAttributes():
162+
# Given
163+
graph = Graph()
164+
165+
nestedColor = graph.addNewNode("NestedColor")
166+
nestedPosition = graph.addNewNode("NestedPosition")
167+
168+
assert nestedPosition.xyz.isLink == False
169+
assert nestedPosition.xyz.x.isLink == False
170+
assert nestedPosition.xyz.y.isLink == False
171+
assert nestedPosition.xyz.z.isLink == False
172+
assert nestedPosition.xyz.test.isLink == False
173+
assert nestedPosition.xyz.test.x.isLink == False
174+
assert nestedPosition.xyz.test.y.isLink == False
175+
assert nestedPosition.xyz.test.z.isLink == False
176+
177+
# When
178+
nestedColor.rgb.connectTo(nestedPosition.xyz)
179+
180+
# Then
181+
assert nestedPosition.xyz.isLink == True
182+
assert nestedPosition.xyz.x.isLink == True
183+
assert nestedPosition.xyz.y.isLink == True
184+
assert nestedPosition.xyz.z.isLink == True
185+
assert nestedPosition.xyz.test.isLink == True
186+
assert nestedPosition.xyz.test.x.isLink == True
187+
assert nestedPosition.xyz.test.y.isLink == True
188+
assert nestedPosition.xyz.test.z.isLink == True
189+
190+
def test_connecting_a_subAttribute_should_disconnect_the_parent_groupAttribute():
191+
# Given
192+
graph = Graph()
193+
194+
nestedColor = graph.addNewNode("NestedColor")
195+
nestedPosition = graph.addNewNode("NestedPosition")
196+
197+
nestedColor.rgb.connectTo(nestedPosition.xyz)
198+
199+
assert nestedPosition.xyz.isLink == True
200+
assert nestedPosition.xyz.x.isLink == True
201+
assert nestedPosition.xyz.y.isLink == True
202+
assert nestedPosition.xyz.z.isLink == True
203+
assert nestedPosition.xyz.test.isLink == True
204+
assert nestedPosition.xyz.test.x.isLink == True
205+
assert nestedPosition.xyz.test.y.isLink == True
206+
assert nestedPosition.xyz.test.z.isLink == True
207+
208+
# When
209+
r = nestedColor.rgb.r
210+
z = nestedPosition.xyz.test.z
211+
r.connectTo(z)
212+
213+
# Then
214+
215+
assert nestedPosition.xyz.isLink == False # Disconnected because sub GroupAttribute has been disconnected
216+
assert nestedPosition.xyz.x.isLink == True
217+
assert nestedPosition.xyz.y.isLink == True
218+
assert nestedPosition.xyz.z.isLink == True
219+
assert nestedPosition.xyz.test.isLink == False # Disconnected because nestedPosition.xyz.test.z has been reconnected
220+
assert nestedPosition.xyz.test.x.isLink == True
221+
assert nestedPosition.xyz.test.y.isLink == True
222+
assert nestedPosition.xyz.test.z.isLink == True

0 commit comments

Comments
 (0)