Skip to content

Commit 6ae4f6c

Browse files
committed
[core] node rename : assert the node cannot be renamed in lock mode (+ other fixes suggested by copilot)
1 parent e0571a0 commit 6ae4f6c

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

meshroom/core/graph.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,19 +519,22 @@ def renameNode(self, node: Node, newName: str):
519519
520520
Args:
521521
node (Node): Node to rename.
522-
newName (str): New name of the node. Must be unique in the graph.
522+
newName (str): New name of the node.
523523
"""
524524
# Handle empty string
525525
if not newName:
526526
return
527+
if node.getLocked():
528+
logging.warning(f"Cannot rename node {node} because of the locked status")
529+
return
527530
usedNames = {n._name for n in self._nodes if n != node}
528531
# Make sure we rename to an available name
529532
if newName in usedNames:
530533
newName = self._createUniqueNodeName(newName, usedNames)
531534
# Rename in the dict model
532535
self._nodes.rename(node._name, newName)
533536
# Finally rename the node name property and notify Qt
534-
node._name = newName
537+
node._name = newName
535538
node.nodeNameChanged.emit()
536539

537540
def copyNode(self, srcNode: Node, withEdges: bool=False):

meshroom/core/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ def nameToLabel(self, name):
913913
Returns:
914914
str: the high-level label from the technical node name
915915
"""
916-
t, idx = name.split("_") if "_" in name else (name, "1")
916+
t, idx = name.rsplit("_", 1) if "_" in name else (name, "1")
917917
return f"{t}{idx if int(idx) > 1 else ''}"
918918

919919
def getDocumentation(self):

meshroom/ui/graph.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,13 +939,11 @@ def addNewNode(self, nodeType, position=None, **kwargs):
939939
def renameNode(self, node: Node, newName: str):
940940
""" Triggers the node renaming.
941941
942-
The name we send here doesn't need to be unique here because we will ensure this later in
943-
the RenameNodeCommand. In this function the last `_N` index is removed, then all special characters
944-
(everything except letters and numbers) are removed. Then a `_N` index will be added to
945-
ensure the node name unicity.
942+
In this function the last `_N` index is removed, then all special characters
943+
(everything except letters and numbers) are removed.
944+
The name uniqueness will be ensured later by adding a suffix (e.g. `_1`, `_2`, ...)
946945
947-
As we remove all special characters, only one underscore is allowed in the node name.
948-
Label can be used if multiple underscores are needed.
946+
Labels can be used to have special characters in the displayed name.
949947
950948
Args:
951949
node (Node): Node to rename.

meshroom/ui/qml/GraphEditor/Node.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Item {
9090
root.y = root.node.y
9191
}
9292
function onNameChanged() {
93-
// Make sure when the node name changes the node label is updated
93+
// HACK: Make sure when the node name changes the node label is updated
9494
root.nodeLabel = ""
9595
// Restore binding to root.node.label
9696
root.nodeLabel = Qt.binding(function() { return root.node.label; })

meshroom/ui/qml/GraphEditor/NodeEditor.qml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Panel {
3434
// Set the display node type only if it is not contained in the node name
3535
const nodeType = _reconstruction.selectedNode.nodeType
3636
root.displayNodeType = nodeName.startsWith(nodeType + "_") ? "" : nodeType
37-
}
37+
}
3838
}
3939

4040
Connections {
@@ -116,6 +116,7 @@ Panel {
116116
id: nodeNameField
117117
visible: root.node !== null
118118
text: root.displayNodeName
119+
// For some reason the validator doesn't always work
119120
validator: RegularExpressionValidator { regularExpression: /^[0-9A-Za-z]+$/ }
120121
font.bold: true
121122
readOnly: true

tests/test_graph.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,21 @@ def test_rename_nodes():
296296
ls0 = graph.addNewNode("Ls")
297297
ls1 = graph.addNewNode("Ls")
298298
ls2 = graph.addNewNode("Ls")
299-
299+
300300
# Test with empty string
301301
assert ls0.name == "Ls_1"
302302
graph.renameNode(ls0, "")
303303
assert ls0.name == "Ls_1"
304-
304+
305305
# Rename
306306
graph.renameNode(ls0, "nodels")
307307
assert ls0.name == "nodels"
308308
graph.renameNode(ls1, "nodels")
309309
assert ls1.name == "nodels_1"
310310
graph.renameNode(ls2, "nodels")
311311
assert ls2.name == "nodels_2"
312+
313+
# Check we cannot rename in locked mode
314+
ls0.setLocked(True)
315+
graph.renameNode(ls0, "lockedLs")
316+
assert ls0.name == "nodels"

0 commit comments

Comments
 (0)