feat: auto-centering row with apply-after-mount, grid button raster-only

Auto Centering moves out of the experiment tabs to its own row between
Manual sample and Exp. Config., with an apply-after-mount checkbox that
re-runs it on every detected sample mount (guarded against firing on GUI
startup). Draw a Grid now only shows on the Raster scan tab.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
duan_jandClaude Fable 5 committed 2026-08-20 16:21:21 +02:00
1 parent 36a4a5fbb8
commit 623f803ceb
2 files changed
+100 -15

No files matched your search

@@ -12,6 +12,7 @@ from aarecommon.math.coordinate import Coordinate, SmargonCoordinate
from aarecommon.math.diffraction_geometry import DiffractionGeometry
from aarecommon.models.models import SampleGeometryModel
from aare.gui.panels.data_collection_settings import DataCollectionSettings
from aare.gui.panels.raster_data_collection import RasterDataCollectionPanel
from aare.gui.panels.rotation_data_collection import RotationDataCollectionPanel
from aare.gui.scan_logic.raster_grid_manager import RasterGridManager
@@ -171,8 +172,8 @@ def test_user_override_persists_across_samples(panel, diffraction):
@pytest.fixture
def raster_panel(qapp, diffraction):
geom = SampleGeometryModel(
def geom():
return SampleGeometryModel(
beam_location_pxl=Coordinate(x=500, y=500),
pixel_in_mm=0.001,
aerotech=Coordinate(x=0, y=0, z=0),
@@ -181,6 +182,10 @@ def raster_panel(qapp, diffraction):
omega_deg=0.0,
beam_size_mm=Coordinate(x=0.01, y=0.01),
)
@pytest.fixture
def raster_panel(qapp, diffraction, geom):
mgr = RasterGridManager(geom)
return RasterDataCollectionPanel(raster_mgr=mgr, diffraction=diffraction)
@@ -212,3 +217,53 @@ def test_grid_size_field_shares_panel_toggle(raster_panel):
_edit(raster_panel.high_res_enter, "2.50")
assert raster_panel._source == DbOverrideLineEdit.SOURCE_MINE
assert raster_panel.width_enter.source() == DbOverrideLineEdit.SOURCE_MINE
# ---------------------------------------------------------------------------
# DataCollectionSettings: per-tab grid button + auto-center after mount
# ---------------------------------------------------------------------------
@pytest.fixture
def settings_panel(qapp, diffraction, geom):
return DataCollectionSettings(geom, RasterGridManager(geom), diffraction)
def test_grid_button_only_on_raster_tab(settings_panel):
assert not settings_panel.bounding_box.isHidden() # Raster is the default tab
for idx in (1, 2, 3):
settings_panel._tab_bar.setCurrentIndex(idx)
assert settings_panel.bounding_box.isHidden()
settings_panel._tab_bar.setCurrentIndex(0)
assert not settings_panel.bounding_box.isHidden()
def test_auto_center_fires_on_mount_only_when_armed(settings_panel):
clicks = []
settings_panel.find_tip.clicked.connect(lambda: clicks.append(1))
settings_panel.auto_center_after_mount.setChecked(True)
# First status with a sample already mounted = GUI (re)start: hardware
# must not move, only the id is recorded.
settings_panel._track_sample(1)
assert not clicks
# Real mount after an unmount fires the centering.
settings_panel._track_sample(None)
settings_panel._track_sample(2)
assert len(clicks) == 1
# Direct sample exchange (no unmount tick in between) also fires.
settings_panel._track_sample(3)
assert len(clicks) == 2
# Remounting the SAME sample counts as a fresh mount.
settings_panel._track_sample(None)
settings_panel._track_sample(3)
assert len(clicks) == 3
# Disarmed: mounts no longer trigger.
settings_panel.auto_center_after_mount.setChecked(False)
settings_panel._track_sample(None)
settings_panel._track_sample(4)
assert len(clicks) == 3