Skip to content

Commit 233bbb7

Browse files
committed
[ui] Graph: Updating the way how color gets set on the selected nodes
Coloring the nodes now uses setAttribute command instead of relying on refrences to Nodes within the graph.
1 parent 418bd63 commit 233bbb7

File tree

4 files changed

+11
-65
lines changed

4 files changed

+11
-65
lines changed

meshroom/core/node.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,6 @@ def getColor(self):
556556
return self.internalAttribute("color").value.strip()
557557
return ""
558558

559-
def setColor(self, color: str):
560-
""" Sets the color of the Node.
561-
562-
Args:
563-
color (str): The hex of the color to set on the node.
564-
"""
565-
if self.hasInternalAttribute("color"):
566-
self.internalAttribute("color").value = color
567-
568559
def getInvalidationMessage(self):
569560
"""
570561
Returns:
@@ -976,7 +967,7 @@ def _onAttributeChanged(self, attr: Attribute):
976967
if attr.value is None:
977968
# Discard dynamic values depending on the graph processing.
978969
return
979-
970+
980971
if self.graph and self.graph.isLoading:
981972
# Do not trigger attribute callbacks during the graph loading.
982973
return
@@ -1365,7 +1356,7 @@ def hasSequenceOutputAttribute(self):
13651356
False otherwise.
13661357
"""
13671358
for attr in self._attributes:
1368-
if attr.enabled and attr.isOutput and (attr.desc.semantic == "sequence" or
1359+
if attr.enabled and attr.isOutput and (attr.desc.semantic == "sequence" or
13691360
attr.desc.semantic == "imageList"):
13701361
return True
13711362
return False
@@ -1395,7 +1386,7 @@ def has3DOutputAttribute(self):
13951386
internalAttributes = Property(BaseObject, getInternalAttributes, constant=True)
13961387
internalAttributesChanged = Signal()
13971388
label = Property(str, getLabel, notify=internalAttributesChanged)
1398-
color = Property(str, getColor, setColor, notify=internalAttributesChanged)
1389+
color = Property(str, getColor, notify=internalAttributesChanged)
13991390
invalidation = Property(str, getInvalidationMessage, notify=internalAttributesChanged)
14001391
comment = Property(str, getComment, notify=internalAttributesChanged)
14011392
internalFolderChanged = Signal()
@@ -1918,7 +1909,7 @@ def nodeFactory(nodeDict, name=None, template=False, uidConflict=False):
19181909
# do not perform that check for internal attributes because there is no point in
19191910
# raising compatibility issues if their number differs: in that case, it is only useful
19201911
# if some internal attributes do not exist or are invalid
1921-
if not template and (sorted([attr.name for attr in nodeDesc.inputs
1912+
if not template and (sorted([attr.name for attr in nodeDesc.inputs
19221913
if not isinstance(attr, desc.PushButtonParam)]) != sorted(inputs.keys()) or
19231914
sorted([attr.name for attr in nodeDesc.outputs if not attr.isDynamicValue]) !=
19241915
sorted(outputs.keys())):

meshroom/ui/commands.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -205,54 +205,6 @@ def undoImpl(self):
205205
self.graph.removeNode(duplicate)
206206

207207

208-
class UpdateNodeColorCommand(GraphCommand):
209-
""" Command representing the work for Coloring nodes in the Graph.
210-
"""
211-
212-
def __init__(self, graph, nodes, color, parent=None):
213-
""" Command Constructor.
214-
215-
Args:
216-
graph (meshroom.core.Graph): Current Graph instance.
217-
nodes (list<Node>): Array of nodes.
218-
color (str): Hex code for the color.
219-
220-
Keyword Args:
221-
parent (QObject): Parent QObject instance.
222-
"""
223-
super(UpdateNodeColorCommand, self).__init__(graph, parent)
224-
self._nodes = nodes
225-
self._color = color
226-
227-
# Existing colors
228-
# Map <Node: str>
229-
# Holds the existing color of the node which can be applied on the node back in case of an undo
230-
self._colorMap = {}
231-
232-
self.setText("Update Selected Node Color")
233-
234-
def redoImpl(self) -> bool:
235-
""" Redo implementation.
236-
"""
237-
for node in self._nodes:
238-
# Update the existing color for the node in the map
239-
self._colorMap[node] = node.color
240-
241-
# Now update the color of the node with the provided one
242-
node.color = self._color
243-
244-
return True
245-
246-
def undoImpl(self):
247-
""" Undo Implementation.
248-
"""
249-
with GraphModification(self.graph):
250-
# Revert the color for the nodes
251-
for node in self._nodes:
252-
# Get the color which was saved for the node
253-
node.color = self._colorMap.get(node)
254-
255-
256208
class PasteNodesCommand(GraphCommand):
257209
"""
258210
Handle node pasting in a Graph.

meshroom/ui/graph.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,15 +953,18 @@ def selectFollowing(self, node):
953953
self.selectNodes(self._graph.dfsOnDiscover(startNodes=[node], reverse=True, dependenciesOnly=True)[0])
954954

955955
@Slot(str)
956-
def updateNodeColor(self, color):
956+
def setSelectedNodesColor(self, color: str):
957957
""" Sets the Provided color on the selected Nodes.
958958
959959
Args:
960960
color (str): Hex code of the color to be set on the nodes.
961961
"""
962962
# Update the color attribute of the nodes which are currently selected
963-
with self.groupedGraphModification("Update Color for Select Nodes"):
964-
self.push(commands.UpdateNodeColorCommand(self._graph, list(self._selectedNodes), color))
963+
with self.groupedGraphModification("Set Nodes Color"):
964+
# For each of the selected nodes -> Check if the node has a color -> Apply the color if it has
965+
for node in self._selectedNodes:
966+
if node.hasInternalAttribute("color"):
967+
self.setAttribute(node.internalAttribute("color"), color)
965968

966969
@Slot(QObject, QObject)
967970
def boxSelect(self, selection, draggable):

meshroom/ui/qml/GraphEditor/GraphEditor.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ Item {
10651065

10661066
// When a Color is selected
10671067
onColorSelected: (color)=> {
1068-
uigraph.updateNodeColor(color)
1068+
uigraph.setSelectedNodesColor(color)
10691069
}
10701070
}
10711071
}

0 commit comments

Comments
 (0)