Skip to content

Commit

Permalink
Update positioning of steps within the workflow panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsorby committed Oct 8, 2023
1 parent 16316f1 commit 838450d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 39 deletions.
10 changes: 6 additions & 4 deletions src/mapclient/core/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ def _log_event(self, event):
]
}

response = requests.post(self._base_url, json=event_data)

if not response.ok:
logger.info(f"Event response: {event['name']} - {response.status_code}")
try:
response = requests.post(self._base_url, json=event_data)
if not response.ok:
logger.info(f"Event response: {event['name']} - {response.status_code}")
except requests.ConnectionError:
logger.info(f"Event logging failed: {event['name']}")


metrics_logger = MetricsLogger()
Expand Down
8 changes: 4 additions & 4 deletions src/mapclient/core/workflow/workflowutils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from PySide6 import QtCore


def convert_to_parameterised_position(bounding_rect, raw_position):
return QtCore.QPointF(raw_position.x() / bounding_rect.right(), raw_position.y() / bounding_rect.bottom())
def convert_to_parameterised_position(bounding_rect, raw_position, offset):
return QtCore.QPointF(raw_position.x() / (bounding_rect.width() - offset.x()), raw_position.y() / (bounding_rect.height() - offset.y()))


def revert_parameterised_position(bounding_rect, parameterised_position):
return QtCore.QPointF(bounding_rect.right() * parameterised_position.x(), bounding_rect.bottom() * parameterised_position.y())
def revert_parameterised_position(bounding_rect, parameterised_position, offset):
return QtCore.QPointF((bounding_rect.width() - offset.x()) * parameterised_position.x(), (bounding_rect.height() - offset.y()) * parameterised_position.y())
21 changes: 12 additions & 9 deletions src/mapclient/view/workflow/workflowgraphicsitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Node(Item):
def __init__(self, metastep):
Item.__init__(self)

self._margin = 2.0
self._metastep = metastep
icon = self._metastep.getStep().getIcon()
if not icon:
Expand Down Expand Up @@ -380,7 +381,7 @@ def setPos(self, pos, modify_parameterised=True):
super(Node, self).setPos(pos)
scene = self.scene()
if modify_parameterised:
self._parameterised_pos = convert_to_parameterised_position(scene.sceneRect(), pos)
self._parameterised_pos = convert_to_parameterised_position(scene.sceneRect(), pos, self.offset())
self._metastep.setPos(pos)

def set_parameterised_pos(self, parameterised_pos):
Expand Down Expand Up @@ -425,15 +426,17 @@ def showStepName(self, show):
def metaItem(self):
return self._metastep

def offset(self):
return QtCore.QPointF(self._pixmap.width(), self._pixmap.height())

def boundingRect(self):
adjust = 2.0
return QtCore.QRectF(-adjust, -adjust,
self._pixmap.width() + 2 * adjust,
self._pixmap.height() + 2 * adjust)
return QtCore.QRectF(-self._margin, -self._margin,
self._pixmap.width() + 2 * self._margin,
self._pixmap.height() + 2 * self._margin)

def paint(self, painter, option, widget):
if option.state & QtWidgets.QStyle.State_Selected: # or self.selected:
painter.setBrush(QtCore.Qt.darkGray)
if option.state & QtWidgets.QStyle.StateFlag.State_Selected: # or self.selected:
painter.setBrush(QtCore.Qt.GlobalColor.darkGray)
painter.drawRoundedRect(self.boundingRect(), 5, 5)

# super(Node, self).paint(painter, option, widget)
Expand All @@ -444,8 +447,8 @@ def paint(self, painter, option, widget):

def itemChange(self, change, value):
if change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemPositionChange and self.scene():
return self.scene().ensureItemInScene(self, value)
elif change == QtWidgets.QGraphicsItem.ItemPositionHasChanged:
return self.scene().ensure_item_in_scene(self, value)
elif change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemPositionHasChanged:
for port_item in self._step_port_items:
port_item.itemChange(change, value)

Expand Down
39 changes: 20 additions & 19 deletions src/mapclient/view/workflow/workflowgraphicsscene.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,31 @@ def updateModel(self):

self._previousSelection = self.selectedItems()

def ensureItemInScene(self, item, newPos):
def ensure_item_in_scene(self, item, new_pos):
if self._is_ready:
bRect = item.boundingRect()
xp1 = bRect.x() + newPos.x()
yp1 = bRect.y() + newPos.y()
xp2 = bRect.x() + bRect.width() + newPos.x()
yp2 = bRect.y() + bRect.height() + newPos.y()
xp1 = bRect.x() + new_pos.x()
yp1 = bRect.y() + new_pos.y()
xp2 = xp1 + bRect.width()
yp2 = yp1 + bRect.height()
bRect.setCoords(xp1, yp1, xp2, yp2)
offset = item.offset()
rect = self.sceneRect()
if not rect.contains(bRect):
x1 = max(bRect.left(), rect.left()) + 2.0 # plus bounding rectangle adjust
x2 = min(bRect.x() + bRect.width(), rect.x() + rect.width()) - bRect.width() + 2.0
y1 = max(bRect.top(), rect.top()) + 2.0 # plus bounding rectangle adjust
y2 = min(bRect.bottom(), rect.bottom()) - bRect.height() + 2.0
if newPos.x() != x1:
newPos.setX(x1)
elif newPos.x() != x2:
newPos.setX(x2)
if newPos.y() != y1:
newPos.setY(y1)
elif newPos.y() != y2:
newPos.setY(y2)

return newPos
x1 = max(bRect.left(), rect.left())
y1 = max(bRect.top(), rect.top())
x2 = min(bRect.right(), rect.right()) - offset.x()
y2 = min(bRect.bottom(), rect.bottom()) - offset.y()
if new_pos.x() <= x1:
new_pos.setX(x1)
elif new_pos.x() >= x2:
new_pos.setX(x2)
if new_pos.y() <= y1:
new_pos.setY(y1)
elif new_pos.y() >= y2:
new_pos.setY(y2)

return new_pos

def clear(self):
QtWidgets.QGraphicsScene.clear(self)
Expand Down
6 changes: 3 additions & 3 deletions src/mapclient/view/workflow/workflowgraphicsview.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from PySide6 import QtCore, QtWidgets, QtGui

from mapclient.core.workflow.workflowutils import convert_to_parameterised_position, revert_parameterised_position
from mapclient.core.workflow.workflowutils import revert_parameterised_position
from mapclient.mountpoints.workflowstep import workflowStepFactory
from mapclient.core.workflow.workflowscene import MetaStep
from mapclient.view.utils import is_light_mode
Expand Down Expand Up @@ -245,7 +245,7 @@ def paste_steps(self, stream, event_position=None):
node = self.create_node(scene, name)

self._undoStack.push(CommandAdd(scene, node))
self._undoStack.push(CommandMove(node, position, scene.ensureItemInScene(node, position)))
self._undoStack.push(CommandMove(node, position, scene.ensure_item_in_scene(node, position)))

node.setSelected(True)

Expand Down Expand Up @@ -511,7 +511,7 @@ def _reposition_steps(self):
scene_rect = self.sceneRect()
for item in self.items():
if isinstance(item, Node):
new_position = revert_parameterised_position(scene_rect, item.parameterised_pos())
new_position = revert_parameterised_position(scene_rect, item.parameterised_pos(), item.offset())
item.setPos(new_position, False)

def merge_macros(self):
Expand Down

0 comments on commit 838450d

Please sign in to comment.