Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/alicevision/meshroom.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCandice Bentéjac <candice.bentejac@gmail.com>2022-09-06 16:40:59 +0300
committerCandice Bentéjac <candice.bentejac@gmail.com>2022-09-06 16:40:59 +0300
commit9f1b866e78941cb5f5fb52e9319064468200b9f7 (patch)
treec90ee79c5f22819271c17fb92c7fdb17e90a9a26
parent6bb0ad45088e59c543ce2dd142fe1d79247dadb3 (diff)
Paste the selected nodes relatively to the mouse's position
The mouse's position is the top-left corner of a zone in which all the selected nodes will be pasted. The bottom-right corner of that zone is (x, y), with x the maximum of the selected nodes' position along the x-axis and y the maximum of the selected nodes' position along the y-axis. The nodes relative position to one another - if positions are provided - is preserved. If no node in the selection has a specified position, the nodes will be pasted from left to right alphabetically, with the top-left corner of the first node at the mouse's position.
-rw-r--r--meshroom/ui/graph.py40
1 files changed, 35 insertions, 5 deletions
diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py
index af5c49eb..14fd3c7e 100644
--- a/meshroom/ui/graph.py
+++ b/meshroom/ui/graph.py
@@ -824,18 +824,48 @@ class UIGraph(QObject):
if not d:
return
- finalPosition = None
- prevPosition = None
- positions = []
+ if isinstance(position, QPoint):
+ position = Position(position.x(), position.y())
+ # Get the position of the first node in a zone whose top-left corner is the mouse and the bottom-right
+ # corner the (x, y) coordinates, with x the maximum of all the nodes' position along the x-axis, and y the
+ # maximum of all the nodes' position along the y-axis. All nodes with a position will be placed relatively
+ # to the first node within that zone.
+ firstNodePos = None
+ minX = 0
+ minY = 0
for key in sorted(d):
nodeType = d[key].get("nodeType", None)
if not nodeType:
raise ValueError("Invalid node description: no provided node type for '{}'".format(key))
+ pos = d[key].get("position", None)
+ if pos:
+ if not firstNodePos:
+ firstNodePos = pos
+ minX = pos[0]
+ minY = pos[1]
+ else:
+ if minX > pos[0]:
+ minX = pos[0]
+ if minY > pos[1]:
+ minY = pos[1]
+
+ # Ensure there will not be an error if no node has a specified position
+ if not firstNodePos:
+ firstNodePos = [0, 0]
+
+ # Position of the first node within the zone
+ position = Position(position.x + firstNodePos[0] - minX, position.y + firstNodePos[1] - minY)
+
+ finalPosition = None
+ prevPosition = None
+ positions = []
+
+ for key in sorted(d):
currentPosition = d[key].get("position", None)
- if isinstance(position, QPoint) and not finalPosition:
- finalPosition = Position(position.x(), position.y())
+ if not finalPosition:
+ finalPosition = position
else:
if prevPosition and currentPosition:
# If the nodes both have a position, recreate the distance between them with a different