mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
fix(image_roi): position can be set from rpc
This commit is contained in:
@ -602,6 +602,16 @@ class BaseROI(RPCBase):
|
|||||||
ndarray: Pixel data inside the ROI, or (data, coords) if *returnMappedCoords* is True.
|
ndarray: Pixel data inside the ROI, or (data, coords) if *returnMappedCoords* is True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@rpc_call
|
||||||
|
def set_position(self, x: "float", y: "float"):
|
||||||
|
"""
|
||||||
|
Sets the position of the ROI.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x (float): The x-coordinate of the new position.
|
||||||
|
y (float): The y-coordinate of the new position.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class CircularROI(RPCBase):
|
class CircularROI(RPCBase):
|
||||||
"""Circular Region of Interest with center/diameter tracking and auto-labeling."""
|
"""Circular Region of Interest with center/diameter tracking and auto-labeling."""
|
||||||
@ -701,6 +711,16 @@ class CircularROI(RPCBase):
|
|||||||
ndarray: Pixel data inside the ROI, or (data, coords) if *returnMappedCoords* is True.
|
ndarray: Pixel data inside the ROI, or (data, coords) if *returnMappedCoords* is True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@rpc_call
|
||||||
|
def set_position(self, x: "float", y: "float"):
|
||||||
|
"""
|
||||||
|
Sets the position of the ROI.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x (float): The x-coordinate of the new position.
|
||||||
|
y (float): The y-coordinate of the new position.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class Curve(RPCBase):
|
class Curve(RPCBase):
|
||||||
@rpc_call
|
@rpc_call
|
||||||
@ -2652,6 +2672,16 @@ class RectangularROI(RPCBase):
|
|||||||
ndarray: Pixel data inside the ROI, or (data, coords) if *returnMappedCoords* is True.
|
ndarray: Pixel data inside the ROI, or (data, coords) if *returnMappedCoords* is True.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@rpc_call
|
||||||
|
def set_position(self, x: "float", y: "float"):
|
||||||
|
"""
|
||||||
|
Sets the position of the ROI.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x (float): The x-coordinate of the new position.
|
||||||
|
y (float): The y-coordinate of the new position.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class ResetButton(RPCBase):
|
class ResetButton(RPCBase):
|
||||||
"""A button that resets the scan queue."""
|
"""A button that resets the scan queue."""
|
||||||
|
@ -113,6 +113,7 @@ class BaseROI(BECConnector):
|
|||||||
"line_width.setter",
|
"line_width.setter",
|
||||||
"get_coordinates",
|
"get_coordinates",
|
||||||
"get_data_from_image",
|
"get_data_from_image",
|
||||||
|
"set_position",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -333,6 +334,16 @@ class BaseROI(BECConnector):
|
|||||||
def add_scale_handle(self):
|
def add_scale_handle(self):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def set_position(self, x: float, y: float):
|
||||||
|
"""
|
||||||
|
Sets the position of the ROI.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
x (float): The x-coordinate of the new position.
|
||||||
|
y (float): The y-coordinate of the new position.
|
||||||
|
"""
|
||||||
|
self.setPos(x, y)
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
handles = self.handles
|
handles = self.handles
|
||||||
for i in range(len(handles)):
|
for i in range(len(handles)):
|
||||||
|
@ -188,3 +188,20 @@ def test_roi_controller_get_roi_methods(qtbot, mocked_client):
|
|||||||
assert controller.get_roi(1) == r2
|
assert controller.get_roi(1) == r2
|
||||||
assert controller.get_roi(99) is None
|
assert controller.get_roi(99) is None
|
||||||
assert controller.get_roi_by_name("notfound") is None
|
assert controller.get_roi_by_name("notfound") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_roi_set_position(bec_image_widget_with_roi):
|
||||||
|
"""Test that set_position updates the ROI position and coordinates."""
|
||||||
|
widget, roi, _ = bec_image_widget_with_roi
|
||||||
|
# Save original coordinates
|
||||||
|
orig_coords = roi.get_coordinates(typed=False)
|
||||||
|
# Move ROI by a known offset
|
||||||
|
roi.set_position(10, 15)
|
||||||
|
new_coords = roi.get_coordinates(typed=False)
|
||||||
|
# The new position should reflect the set_position call
|
||||||
|
assert new_coords != orig_coords
|
||||||
|
# The first coordinate should match the new position
|
||||||
|
if hasattr(roi, "pos"):
|
||||||
|
pos = roi.pos()
|
||||||
|
assert int(pos.x()) == 10
|
||||||
|
assert int(pos.y()) == 15
|
||||||
|
Reference in New Issue
Block a user