Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically update layout when needed #989

Merged
merged 2 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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