Skip to content

Commit

Permalink
Merge pull request #989 from alicevision/dev/autoLayout
Browse files Browse the repository at this point in the history
Automatically update layout when needed
  • Loading branch information
fabiencastan authored Jul 19, 2020
2 parents c101241 + 7ff3bca commit 746e739
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/LdrToHdrCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def findMetadata(d, keys, defaultValue):
k = key.lower()
if v is not None:
return v
for dk, dv in d.iteritems():
for dk, dv in d.items():
dkm = dk.lower().replace(" ", "")
if dkm == key.lower():
return dv
Expand Down
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/LdrToHdrMerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def findMetadata(d, keys, defaultValue):
k = key.lower()
if v is not None:
return v
for dk, dv in d.iteritems():
for dk, dv in d.items():
dkm = dk.lower().replace(" ", "")
if dkm == key.lower():
return dv
Expand Down
2 changes: 1 addition & 1 deletion meshroom/nodes/aliceVision/LdrToHdrSampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def findMetadata(d, keys, defaultValue):
k = key.lower()
if v is not None:
return v
for dk, dv in d.iteritems():
for dk, dv in d.items():
dkm = dk.lower().replace(" ", "")
if dkm == key.lower():
return dv
Expand Down
35 changes: 28 additions & 7 deletions meshroom/ui/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,30 +194,44 @@ def reset(self):
""" Perform auto-layout on the whole graph. """
self.autoLayout()

def boundingBox(self, nodes=None):
def positionBoundingBox(self, nodes=None):
"""
Return bounding box for a set of nodes as (x, y, width, height).
Args:
nodes (list of Node): the list of nodes or the whole graph if None
Returns:
tuple of int: the resulting bounding box (x, y, width, height)
list of int: the resulting bounding box (x, y, width, height)
"""
if nodes is None:
nodes = self.graph.nodes.values()
first = nodes[0]
bbox = [first.x, first.y, first.x + self._nodeWidth, first.y + self._nodeHeight]
bbox = [first.x, first.y, first.x, first.y]
for n in nodes:
bbox[0] = min(bbox[0], n.x)
bbox[1] = min(bbox[1], n.y)
bbox[2] = max(bbox[2], n.x + self._nodeWidth)
bbox[3] = max(bbox[3], n.y + self._nodeHeight)
bbox[2] = max(bbox[2], n.x)
bbox[3] = max(bbox[3], n.y)

bbox[2] -= bbox[0]
bbox[3] -= bbox[1]
return bbox

return tuple(bbox)
def boundingBox(self, nodes=None):
"""
Return bounding box for a set of nodes as (x, y, width, height).
Args:
nodes (list of Node): the list of nodes or the whole graph if None
Returns:
list of int: the resulting bounding box (x, y, width, height)
"""
bbox = self.positionBoundingBox(nodes)
bbox[2] += self._nodeWidth
bbox[3] += self._nodeHeight
return bbox

def setDepthMode(self, mode):
""" Set node depth mode to use. """
Expand Down Expand Up @@ -267,7 +281,14 @@ def setGraph(self, g):
# perform auto-layout if graph does not provide nodes positions
if Graph.IO.Features.NodesPositions not in self._graph.fileFeatures:
self._layout.reset()
self._undoStack.clear() # clear undo-stack after layout
# clear undo-stack after layout
self._undoStack.clear()
else:
bbox = self._layout.positionBoundingBox()
if bbox[2] == 0 and bbox[3] == 0:
self._layout.reset()
# clear undo-stack after layout
self._undoStack.clear()
self.graphChanged.emit()

def onGraphUpdated(self):
Expand Down

0 comments on commit 746e739

Please sign in to comment.