Skip to content

Commit ee14941

Browse files
author
nicolas-lambert-tc
committed
[ui] Explicitely indicate opened templates in graph editor
1 parent efe48f5 commit ee14941

4 files changed

Lines changed: 81 additions & 1 deletion

File tree

meshroom/core/graph.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def __init__(self, name: str = "", parent: BaseObject = None):
228228
self._relativeCacheDir: str = ""
229229
self._cacheDir: str = ""
230230
self._filepath: str = ""
231+
self._templateFilepath: str = ""
231232
self._fileDateVersion = 0
232233
self.header = {}
233234

@@ -1553,6 +1554,7 @@ def _setFilepath(self, filepath):
15531554
if self._filepath == newFilepath:
15541555
return
15551556
self._filepath = newFilepath
1557+
self._setTemplateFilepath("")
15561558
# For now:
15571559
# * cache folder is located next to the graph file
15581560
# * graph name if the basename of the graph file
@@ -1565,10 +1567,22 @@ def _setFilepath(self, filepath):
15651567

15661568
def _unsetFilepath(self):
15671569
self._filepath = ""
1570+
self._setTemplateFilepath("")
15681571
self.name = ""
15691572
self.cacheDir = ""
15701573
self.filepathChanged.emit()
15711574

1575+
@Slot(str)
1576+
def setTemplateFilepath(self, filepath):
1577+
self._setTemplateFilepath(filepath)
1578+
1579+
def _setTemplateFilepath(self, filepath):
1580+
newFilepath = Path(filepath).as_posix() if filepath else ""
1581+
if self._templateFilepath == newFilepath:
1582+
return
1583+
self._templateFilepath = newFilepath
1584+
self.templateFilepathChanged.emit()
1585+
15721586
def updateInternals(self, startNodes=None, force=False):
15731587
nodes, edges = self.dfsOnFinish(startNodes=startNodes)
15741588
for node in nodes:
@@ -1811,6 +1825,8 @@ def setVerbose(self, v):
18111825
edges = Property(BaseObject, edges.fget, constant=True)
18121826
filepathChanged = Signal()
18131827
filepath = Property(str, lambda self: self._filepath, notify=filepathChanged)
1828+
templateFilepathChanged = Signal()
1829+
templateFilepath = Property(str, lambda self: self._templateFilepath, notify=templateFilepathChanged)
18141830
isSaving = Property(bool, isSaving.fget, constant=True)
18151831
fileReleaseVersion = Property(str, lambda self: self.header.get(GraphIO.Keys.ReleaseVersion, "0.0"),
18161832
notify=filepathChanged)

meshroom/ui/qml/Application.qml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,23 @@ Page {
15091509
}
15101510
}
15111511
}
1512+
// TemplateBadge
1513+
MaterialToolButton {
1514+
1515+
readonly property string templateFilePath: {
1516+
const coreGraph = _currentScene ? _currentScene.graph : null
1517+
const templatePath = coreGraph ? coreGraph.templateFilepath : ""
1518+
return templatePath
1519+
}
1520+
1521+
text: MaterialIcons.library_books
1522+
visible: Boolean(templateFilePath)
1523+
font.pointSize: 11
1524+
padding: 2
1525+
checked: true
1526+
ToolTip.text: `Current graph is a template: ${templateFilePath}`
1527+
ToolTip.visible: hovered
1528+
}
15121529
}
15131530

15141531
GraphEditor {

meshroom/ui/qml/GraphEditor/GraphEditor.qml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,50 @@ Item {
388388
}
389389
}
390390

391+
Canvas {
392+
id: templateBackgroundStripes
393+
394+
anchors.fill: parent
395+
visible: Boolean(root.graph && root.graph.templateFilepath)
396+
opacity: 0.03
397+
398+
readonly property color stripeColor: activePalette.highlight
399+
readonly property int stripeWidth: 21
400+
readonly property int stripeGap: 42
401+
402+
onPaint: {
403+
const ctx = getContext("2d")
404+
ctx.clearRect(0, 0, width, height)
405+
406+
if (!visible) {
407+
return
408+
}
409+
410+
ctx.save()
411+
ctx.strokeStyle = stripeColor
412+
ctx.lineWidth = stripeWidth
413+
414+
const diagonal = Math.sqrt(width * width + height * height)
415+
const step = stripeWidth + stripeGap
416+
ctx.translate(width * 0.5, height * 0.5)
417+
ctx.rotate(-Math.PI / 4)
418+
419+
for (let x = -diagonal; x <= diagonal; x += step) {
420+
ctx.beginPath()
421+
ctx.moveTo(x, -diagonal)
422+
ctx.lineTo(x, diagonal)
423+
ctx.stroke()
424+
}
425+
426+
ctx.restore()
427+
}
428+
429+
onVisibleChanged: requestPaint()
430+
onWidthChanged: requestPaint()
431+
onHeightChanged: requestPaint()
432+
onStripeColorChanged: requestPaint()
433+
}
434+
391435
Item {
392436
id: draggable
393437
transformOrigin: Item.TopLeft

meshroom/ui/scene.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,10 @@ def load(self, url):
503503
@Slot(QUrl, result=bool)
504504
def loadTemplate(self, url):
505505
localFile = self._urlToLocalFile(url)
506-
return self._loadWithErrorReport(self._initFromTemplateWithCopyOutputs, localFile)
506+
loaded = self._loadWithErrorReport(self._initFromTemplateWithCopyOutputs, localFile)
507+
if loaded:
508+
self.graph.setTemplateFilepath(localFile)
509+
return loaded
507510

508511
@staticmethod
509512
def _urlToLocalFile(url) -> str:

0 commit comments

Comments
 (0)