Registra spento sul frame gia' registrato, nuovo grab dopo il reset

Refs #123

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 22:04:20 +01:00
parent c904800e94
commit 8ef61a1285
2 changed files with 27 additions and 3 deletions
@@ -32,6 +32,7 @@ function visionExecute() {
preview: false, // result on screen is an analysis only, not saved preview: false, // result on screen is an analysis only, not saved
saved: false, // «Registra» done: the saved result replaces the preview saved: false, // «Registra» done: the saved result replaces the preview
lastBlob: null, // last frame shown, the one «Registra» saves lastBlob: null, // last frame shown, the one «Registra» saves
recordedBlob: null, // #123: frame saved by the last successful «Registra»: not recordable twice
paused: false, // operator paused the in-line loop paused: false, // operator paused the in-line loop
registering: false, // «Registra» in progress: the loop stands still registering: false, // «Registra» in progress: the loop stands still
leaving: false, // page is being left: no more requests leaving: false, // page is being left: no more requests
@@ -43,8 +44,10 @@ function visionExecute() {
// #120: «Rimisura»/nuovo ciclo (task-result-reset): il pezzo va registrato di nuovo, anche senza camera // #120: «Rimisura»/nuovo ciclo (task-result-reset): il pezzo va registrato di nuovo, anche senza camera
window.addEventListener('task-result-reset', () => { window.addEventListener('task-result-reset', () => {
this.saved = false; this.saved = false;
this.preview = !!this.result; // #123: il frame gia' registrato non e' piu' un'anteprima ne' si registra due volte
this.kick(); this.preview = !!this.result && this.lastBlob !== this.recordedBlob;
// #123: camera impulsiva = frame nuovo subito (come all'apertura); in linea riparte il ciclo
if (this.hasCamera && !this.inLinea) this.grab(); else this.kick();
}); });
if (!this.hasCamera) return; if (!this.hasCamera) return;
document.addEventListener('visibilitychange', () => { if (!document.hidden) this.kick(); }); document.addEventListener('visibilitychange', () => { if (!document.hidden) this.kick(); });
@@ -58,7 +61,7 @@ function visionExecute() {
get hasCamera() { return !!(window.__visionCfg || {}).cameraAvailable; }, get hasCamera() { return !!(window.__visionCfg || {}).cameraAvailable; },
get inLinea() { return this.hasCamera && (window.__visionCfg || {}).modo === 'in_linea'; }, get inLinea() { return this.hasCamera && (window.__visionCfg || {}).modo === 'in_linea'; },
// «Registra» needs a frame on screen that is not saved yet // «Registra» needs a frame on screen that is not saved yet
get canRecord() { return !!this.lastBlob && !this.saved && !this.registering; }, get canRecord() { return !!this.lastBlob && this.lastBlob !== this.recordedBlob && !this.saved && !this.registering; }, // #123: non sul frame gia' registrato
shouldRun() { shouldRun() {
return this.inLinea && !this.paused && !this.saved && !this.registering return this.inLinea && !this.paused && !this.saved && !this.registering
@@ -145,6 +148,7 @@ function visionExecute() {
if (!this.error && this.result && this.result.vision_result_id) { if (!this.error && this.result && this.result.vision_result_id) {
this.preview = false; this.preview = false;
this.saved = true; this.saved = true;
this.recordedBlob = blob; // #123: questo frame e' registrato, Registra resta spento finche' non ne arriva uno nuovo
this._emitRecorded(); // #120: la pagina conta le quote registrate this._emitRecorded(); // #120: la pagina conta le quote registrate
} }
} finally { } finally {
@@ -175,6 +175,26 @@ c5.acquire = async function () { this.result = { vision_result_id: 7, measuremen
h(); h();
check('#120 task-result-reset: saved = false', c5.saved === false); check('#120 task-result-reset: saved = false', c5.saved === false);
// #123: dopo Registra + task-result-reset Registra e' spento sul frame registrato, anteprima spenta, impulsiva = grab
win.__visionCfg = { cameraAvailable: true, modo: 'impulsiva', subtasks: [] };
const c9 = ctx.visionExecute();
let grabs = 0;
c9.grab = async function () { grabs++; };
c9.lastBlob = { name: 'f1' };
c9.acquire = async function () { this.result = { vision_result_id: 11, measurements: okMs }; };
check('#123 prima di Registra: canRecord', c9.canRecord === true);
await c9.record();
check('#123 dopo Registra: canRecord falso (saved)', c9.canRecord === false && c9.recordedBlob === c9.lastBlob);
c9.$nextTick = () => {}; // #123: nel test nessun grab di apertura
c9.init(); // registra l'ascolto di task-result-reset
grabs = 0;
(listeners['task-result-reset'] || []).slice(-1)[0]();
check('#123 reset sul frame registrato: canRecord falso', c9.canRecord === false && c9.saved === false);
check('#123 reset sul frame registrato: niente badge anteprima', c9.preview === false);
check('#123 reset in impulsiva: un solo grab', grabs === 1, String(grabs));
c9.lastBlob = { name: 'f2' };
check('#123 frame nuovo: canRecord vero', c9.canRecord === true);
// #119 #122: saveName = titolo del task (nome proposto da <tmf-viewer save-name>), 'immagine' se manca // #119 #122: saveName = titolo del task (nome proposto da <tmf-viewer save-name>), 'immagine' se manca
win.__visionCfg = { taskName: 'Roto3', subtasks: [] }; win.__visionCfg = { taskName: 'Roto3', subtasks: [] };
check('#122 saveName = nome del task', ctx.visionExecute().saveName === 'Roto3'); check('#122 saveName = nome del task', ctx.visionExecute().saveName === 'Roto3');