Smart scan return cancelled if cancelled before stitching starts.

This commit is contained in:
Julian Stirling 2026-07-02 09:49:22 +01:00
parent d7421ccea5
commit 1aed597f9c
3 changed files with 14 additions and 4 deletions

View file

@ -43,6 +43,7 @@ from .stage import BacklashCompensation, BaseStage
T = TypeVar("T") T = TypeVar("T")
P = ParamSpec("P") P = ParamSpec("P")
MIN_IMAGES_TO_STITCH = 2
# This allows ActiveScanData to hold arbitrary workflow settings models during a scan. # This allows ActiveScanData to hold arbitrary workflow settings models during a scan.
AnyModel = Annotated[ AnyModel = Annotated[
@ -409,7 +410,10 @@ class SmartScanThing(OFMThing):
# This scan can't stitch. # This scan can't stitch.
return return
# Begin stitching once two images are captured # Begin stitching once two images are captured
if self.scan_data.image_count >= 2 and not self._preview_stitcher.running: if (
self.scan_data.image_count >= MIN_IMAGES_TO_STITCH
and not self._preview_stitcher.running
):
self._preview_stitcher.start() self._preview_stitcher.start()
@_scan_running @_scan_running
@ -449,9 +453,14 @@ class SmartScanThing(OFMThing):
self._main_scan_loop(workflow) self._main_scan_loop(workflow)
self._save_final_scan_data(scan_result="success") self._save_final_scan_data(scan_result="success")
except lt.exceptions.InvocationCancelledError: except lt.exceptions.InvocationCancelledError as e:
self.logger.info("Stopping scan because it was cancelled.") self.logger.info("Stopping scan because it was cancelled.")
self._save_final_scan_data(scan_result="cancelled by user") self._save_final_scan_data(scan_result="cancelled by user")
if self.scan_data.image_count < MIN_IMAGES_TO_STITCH:
# If too few images to stitch then, return to the centre and report
# cancelled
self._return_to_starting_position()
raise e
except Exception as e: except Exception as e:
err_name = type(e).__name__ err_name = type(e).__name__
if self._scan_data is not None: if self._scan_data is not None:
@ -760,6 +769,6 @@ class SmartScanThing(OFMThing):
# Use the scan list (the data read by the gallery) to find any scans that # Use the scan list (the data read by the gallery) to find any scans that
# need stitching. # need stitching.
for scan in self.get_data_for_gallery(): for scan in self.get_data_for_gallery():
if scan.dzi is None and scan.number_of_images >= 2: if scan.dzi is None and scan.number_of_images >= MIN_IMAGES_TO_STITCH:
self.logger.info(f"Stitching {scan.name}") self.logger.info(f"Stitching {scan.name}")
self.stitch_scan(scan_name=scan.name) self.stitch_scan(scan_name=scan.name)

View file

@ -66,6 +66,7 @@ mode.
submit-label="" submit-label=""
:can-terminate="true" :can-terminate="true"
@completed="$emit('completed')" @completed="$emit('completed')"
@finished="$emit('finished')"
@update:task-status="taskStatus = $event" @update:task-status="taskStatus = $event"
@update:progress="progress = $event" @update:progress="progress = $event"
@update:log="log = $event" @update:log="log = $event"

View file

@ -6,7 +6,7 @@
:task-url="taskUrl" :task-url="taskUrl"
:task-info-title="infoPaneTitle" :task-info-title="infoPaneTitle"
:task-info-stream="displayImageOnRight" :task-info-stream="displayImageOnRight"
@completed="onScanCompleted" @finished="onScanCompleted"
@close-task="closeTask" @close-task="closeTask"
@action-started-externally="startScanning" @action-started-externally="startScanning"
> >