diff --git a/src/mx_bluesky/beamlines/i24/web_gui_plans/oav_plans.py b/src/mx_bluesky/beamlines/i24/web_gui_plans/oav_plans.py index 30d84e3a2..7989db677 100644 --- a/src/mx_bluesky/beamlines/i24/web_gui_plans/oav_plans.py +++ b/src/mx_bluesky/beamlines/i24/web_gui_plans/oav_plans.py @@ -83,3 +83,18 @@ def focus_on_oav_view( magnitude = -magnitude yield from bps.abs_set(pmac.z, magnitude, wait=True) + + +def move_on_oav_view_click( + position: tuple[int, int], oav=inject("oav"), pmac: PMAC = inject("pmac") +) -> MsgGenerator: + x = position[0] + y = position[1] + + x_microns_per_pixel = yield from bps.rd(oav.microns_per_pixel_x) + y_microns_per_pixel = yield from bps.rd(oav.microns_per_pixel_y) + + x_mm = (x * x_microns_per_pixel) / 1000 + y_mm = (y * y_microns_per_pixel) / 1000 + + yield from bps.mv(pmac.x, x_mm, pmac.y, y_mm, wait=True) diff --git a/tests/unit_tests/beamlines/i24/web_gui/test_oav_plans.py b/tests/unit_tests/beamlines/i24/web_gui/test_oav_plans.py index 45703ce2f..34e6ea8b9 100644 --- a/tests/unit_tests/beamlines/i24/web_gui/test_oav_plans.py +++ b/tests/unit_tests/beamlines/i24/web_gui/test_oav_plans.py @@ -9,6 +9,7 @@ focus_on_oav_view, move_block_on_arrow_click, move_nudge_on_arrow_click, + move_on_oav_view_click, move_window_on_arrow_click, ) @@ -103,3 +104,30 @@ async def test_focus_on_oav_view( ): run_engine(focus_on_oav_view(FocusDirection(direction), MoveSize(move_size), pmac)) assert await pmac.z.user_readback.get_value() == expected_value + + +@pytest.mark.parametrize( + "coordinates, expected_x, expected_y", + [ + ((568, 321), 0.568, 0.321), + ((123, 789), 0.123, 0.789), + ], +) +def test_move_on_oav_view_click( + coordinates, expected_x, expected_y, oav, pmac, run_engine +): + def fake_rd(_signal): + return 1.0 + yield + + with ( + patch( + "mx_bluesky.beamlines.i24.web_gui_plans.oav_plans.bps.mv", + ) as mock_bps_mv, + patch( + "mx_bluesky.beamlines.i24.web_gui_plans.oav_plans.bps.rd", + side_effect=fake_rd, + ), + ): + run_engine(move_on_oav_view_click(coordinates, oav, pmac)) + mock_bps_mv.assert_any_call(pmac.x, expected_x, pmac.y, expected_y, wait=True) diff --git a/uv.lock b/uv.lock index 44a964d1d..7c42ef633 100644 --- a/uv.lock +++ b/uv.lock @@ -802,8 +802,8 @@ wheels = [ [[package]] name = "dls-dodal" -version = "2.2.1.dev6+g856994d96" -source = { git = "https://github.com/DiamondLightSource/dodal.git?rev=main#856994d968e25d7ce8f66a75bde1468ba3367b57" } +version = "2.2.1.dev8+g690e423a9" +source = { git = "https://github.com/DiamondLightSource/dodal.git?rev=main#690e423a9c5d2cb0b34211c0e617442b505dee39" } dependencies = [ { name = "aiofiles", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" }, { name = "aiohttp", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },