Skip to content

Commit

Permalink
Add "label" as an internal attribute
Browse files Browse the repository at this point in the history
Setting the "label" internal attribute allows to give a custom
label to replace the node's default label.
  • Loading branch information
cbentejac committed Aug 1, 2022
1 parent 7d2e9ed commit 5fa9626
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions meshroom/core/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def _set_value(self, value):
# TODO: only update the graph if this attribute participates to a UID
if self.isInput:
self.requestGraphUpdate()
# TODO: only call update of the node if the attribute is internal
# Internal attributes are set as inputs
self.requestNodeUpdate()

self.valueChanged.emit()

def upgradeValue(self, exportedValue):
Expand All @@ -178,6 +182,12 @@ def requestGraphUpdate(self):
self.node.graph.markNodesDirty(self.node)
self.node.graph.update()

def requestNodeUpdate(self):
# Update specific node information that do not affect the rest of the graph
# (like internal attributes)
if self.node:
self.node.updateInternalAttributes()

@property
def isOutput(self):
return self._isOutput
Expand Down
7 changes: 7 additions & 0 deletions meshroom/core/desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ class Node(object):
value="",
semantic="multiline",
uid=[0],
),
StringParam(
name="label",
label="Label",
description="Custom label to replace the node's default label.",
value="",
uid=[0],
)
]
inputs = []
Expand Down
6 changes: 6 additions & 0 deletions meshroom/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,8 @@ def getLabel(self):
Returns:
str: the high-level label of this node
"""
if self._internalAttributes.get("label").value.strip():
return self._internalAttributes.get("label").value.strip()
return self.nameToLabel(self._name)

@Slot(str, result=str)
Expand Down Expand Up @@ -819,6 +821,9 @@ def updateInternals(self, cacheDir=None):
if self.internalFolder != folder:
self.internalFolderChanged.emit()

def updateInternalAttributes(self):
self.internalAttributesChanged.emit()

@property
def internalFolder(self):
return self._internalFolder.format(**self._cmdVars)
Expand Down Expand Up @@ -1052,6 +1057,7 @@ def canBeCanceled(self):
y = Property(float, lambda self: self._position.y, notify=positionChanged)
attributes = Property(BaseObject, getAttributes, constant=True)
internalAttributes = Property(BaseObject, getInternalAttributes, constant=True)
internalAttributesChanged = Signal()
internalFolderChanged = Signal()
internalFolder = Property(str, internalFolder.fget, notify=internalFolderChanged)
depthChanged = Signal()
Expand Down
5 changes: 5 additions & 0 deletions meshroom/ui/qml/GraphEditor/Node.qml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ Item {
root.x = root.node.x
root.y = root.node.y
}

onInternalAttributesChanged: {
nodeLabel.text = node ? node.label : ""
}
}

// Whether an attribute can be displayed as an attribute pin on the node
Expand Down Expand Up @@ -179,6 +183,7 @@ Item {

// Node Name
Label {
id: nodeLabel
Layout.fillWidth: true
text: node ? node.label : ""
padding: 4
Expand Down

0 comments on commit 5fa9626

Please sign in to comment.