Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d6cee498ad | |||
| 828471d27a | |||
| cf64a247be | |||
| 813b66d0c5 | |||
| 8c6d6c1630 | |||
| 1afaaa0bae | |||
| cb66371a5b | |||
| 390d6210d0 |
@@ -0,0 +1,53 @@
|
|||||||
|
<#
|
||||||
|
Cosa fa: avvia TieMeasureFlow DA SORGENTE su una macchina di sviluppo Windows, senza la build
|
||||||
|
Nuitka (che richiede ~20 minuti): stessi quattro server e stesse porte dell'exe (8780 web,
|
||||||
|
8000 backend, 8100 visione, 8765 camera), stessa cartella dati %PROGRAMDATA%\Tielogic\TieMeasureFlow.
|
||||||
|
Prima dell'avvio: ambiente Python 3.13 in build\venv313 (uv sync, solo con -Sincronizza o se manca),
|
||||||
|
tailwind.css e traduzioni .mo ricompilati, DLL di WeasyPrint in build\gtk (scaricate con
|
||||||
|
pdf\prendi-gtk.ps1 se mancano).
|
||||||
|
|
||||||
|
Come si usa (dalla radice del repo):
|
||||||
|
powershell -ExecutionPolicy Bypass -File packaging\windows\sviluppo.ps1 [-Sincronizza] [-Ascolto 0.0.0.0] [-EscludiCamere OECS]
|
||||||
|
Dopo una modifica: Ctrl+C e rilancio (pochi secondi). Template e JS non richiedono altro;
|
||||||
|
classi Tailwind nuove e msgid nuovi vengono ricompilati a ogni avvio.
|
||||||
|
|
||||||
|
Dipende da: uv, npx (Node), la licenza tiemeasureflow di QUESTA macchina in
|
||||||
|
%PROGRAMDATA%\Tielogic\licenze\tiemeasureflow.json (impronta: avvio.py --impronta).
|
||||||
|
#>
|
||||||
|
param(
|
||||||
|
[switch]$Sincronizza, # forza uv sync (dipendenze cambiate)
|
||||||
|
[string]$Ascolto = '127.0.0.1', # indirizzo di ascolto della UI web ($Host e' riservato in PowerShell)
|
||||||
|
[string]$EscludiCamere = '' # backend nativi da saltare (TieVision-Core#339): OECS se c'e' il runtime OECS ma in fiera si usa GenTL
|
||||||
|
)
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
$radice = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
|
||||||
|
$env:UV_PROJECT_ENVIRONMENT = Join-Path $radice 'build\venv313' # stesso ambiente della build
|
||||||
|
$py = Join-Path $env:UV_PROJECT_ENVIRONMENT 'Scripts\python.exe'
|
||||||
|
|
||||||
|
if ($Sincronizza -or -not (Test-Path $py)) {
|
||||||
|
uv sync --python 3.13 --frozen --extra server --extra client --extra vision-worker --group windows
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "uv sync fallito" }
|
||||||
|
}
|
||||||
|
|
||||||
|
# CSS e traduzioni: non sono nel repo, come in build.ps1
|
||||||
|
$flask = Join-Path $radice 'src\frontend\flask_app'
|
||||||
|
Push-Location $flask
|
||||||
|
try {
|
||||||
|
npx --yes tailwindcss@3.4.19 -i static/css/input.css -o static/css/tailwind.css --minify
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "Tailwind fallito" }
|
||||||
|
& (Join-Path $env:UV_PROJECT_ENVIRONMENT 'Scripts\pybabel.exe') -q compile -d translations
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "pybabel compile fallito" }
|
||||||
|
} finally { Pop-Location }
|
||||||
|
|
||||||
|
# DLL di WeasyPrint fuori dalla radice (gtk\ nella radice non e' ignorata da git): build\gtk
|
||||||
|
$gtk = Join-Path $radice 'build\gtk'
|
||||||
|
if (-not (Test-Path (Join-Path $gtk '*.dll'))) {
|
||||||
|
powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $PSScriptRoot 'pdf\prendi-gtk.ps1') -Destinazione $gtk
|
||||||
|
if ($LASTEXITCODE -ne 0) { throw "prendi-gtk.ps1 fallito" }
|
||||||
|
}
|
||||||
|
$env:WEASYPRINT_DLL_DIRECTORIES = $gtk
|
||||||
|
|
||||||
|
if ($EscludiCamere) { $env:VS_CAMERA_ESCLUDI = $EscludiCamere } # #339: stesso percorso camera del PC fiera
|
||||||
|
Set-Location $radice
|
||||||
|
& $py (Join-Path $PSScriptRoot 'avvio.py') --senza-browser --senza-finestre --host $Ascolto # errori in console, niente MessageBox
|
||||||
|
exit $LASTEXITCODE
|
||||||
+354
-98
@@ -8,6 +8,10 @@ Parla con le rotte dello stesso servizio: /camera/sources, /camera/anteprima,
|
|||||||
/camera/parametri, /camera/parametri/salva, /camera/calibration, /camera/calibrate.
|
/camera/parametri, /camera/parametri/salva, /camera/calibration, /camera/calibrate.
|
||||||
#84: calibrazione densa, un solo dato dell'operatore (lato dello scacco in mm).
|
#84: calibrazione densa, un solo dato dell'operatore (lato dello scacco in mm).
|
||||||
#87: anteprima, parametri camera, stile TMF.
|
#87: anteprima, parametri camera, stile TMF.
|
||||||
|
#91: due tab, «Acquisizione» e «Calibrazione», nella stessa pagina; l'anteprima resta
|
||||||
|
visibile in entrambe. Calibrazioni salvate con nome in un archivio unico
|
||||||
|
(/camera/calibrazioni, /camera/calibrazione-attiva); il calcolo non salva piu':
|
||||||
|
si salva dal calcolo_id con un nome.
|
||||||
Dipende da: niente. E' una stringa, cosi' il pacchetto compilato non ha file dati.
|
Dipende da: niente. E' una stringa, cosi' il pacchetto compilato non ha file dati.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -75,16 +79,45 @@ PAGINA = r"""<!doctype html>
|
|||||||
.parametro .campo input[type=text] { width: 110px; text-align: right; flex: none; }
|
.parametro .campo input[type=text] { width: 110px; text-align: right; flex: none; }
|
||||||
.parametro .unita { font-size: .82rem; color: var(--secondario); min-width: 2.2em; }
|
.parametro .unita { font-size: .82rem; color: var(--secondario); min-width: 2.2em; }
|
||||||
.parametro .limiti { font-size: .75rem; color: var(--secondario); }
|
.parametro .limiti { font-size: .75rem; color: var(--secondario); }
|
||||||
|
/* #91: tab Acquisizione | Calibrazione */
|
||||||
|
.tabs { display: flex; gap: 6px; margin: 0 0 14px; border-bottom: 1px solid var(--bordo); }
|
||||||
|
.tabs button { background: transparent; color: var(--secondario); border-radius: 6px 6px 0 0; border-bottom: 3px solid transparent;
|
||||||
|
flex: 0 1 auto; padding: 8px 18px; }
|
||||||
|
.tabs button[aria-selected=true] { color: var(--testo); background: var(--pannello); border-bottom-color: var(--accento); font-weight: 600; }
|
||||||
|
/* #91: calibrazione con nome, elenco delle salvate */
|
||||||
|
.scorri { overflow-x: auto; margin-top: 8px; }
|
||||||
|
.elenco { width: 100%; }
|
||||||
|
.elenco th { text-align: left; font-size: .78rem; font-weight: 600; color: var(--secondario); padding: 2px 12px 4px 0; white-space: nowrap; }
|
||||||
|
.elenco td { padding: 5px 12px 5px 0; border-top: 1px solid var(--bordo); vertical-align: top; }
|
||||||
|
.elenco td:first-child { color: var(--testo); }
|
||||||
|
.elenco .azioni { white-space: nowrap; }
|
||||||
|
.elenco button { padding: 3px 9px; font-size: .82rem; margin-right: 4px; }
|
||||||
|
.segno { display: inline-block; font-size: .72rem; padding: 0 6px; border-radius: 9px; background: var(--ok); color: #052e16; margin-left: 6px; }
|
||||||
|
.segno.diversa { background: var(--avviso); color: #422006; }
|
||||||
|
.origine label { display: inline-block; margin: 0 14px 4px 0; color: var(--testo); font-size: .92rem; }
|
||||||
|
input[type=radio] { accent-color: var(--accento); }
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.griglia { grid-template-columns: minmax(0, 1fr); }
|
.griglia { grid-template-columns: minmax(0, 1fr); }
|
||||||
.cornice img { max-height: 60vh; }
|
.cornice img { max-height: 60vh; }
|
||||||
}
|
}
|
||||||
|
@media (max-width: 500px) { /* #91: utilizzabile anche stretta (400 px) */
|
||||||
|
main { padding: 8px; }
|
||||||
|
.scheda { padding: 10px; }
|
||||||
|
.tabs button { flex: 1 1 0; padding: 8px 6px; }
|
||||||
|
.parametro .campo input[type=text] { width: 88px; }
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main>
|
<main>
|
||||||
<h1>Acquisizione camera</h1>
|
<h1>Acquisizione camera</h1>
|
||||||
|
|
||||||
|
<!-- #91: due tab; la colonna dell'anteprima resta visibile in entrambe -->
|
||||||
|
<div class="tabs" role="tablist" aria-label="Sezioni della pagina">
|
||||||
|
<button id="tabAcq" type="button" role="tab" aria-selected="true" aria-controls="pannelloAcq">Acquisizione</button>
|
||||||
|
<button id="tabCal" type="button" role="tab" aria-selected="false" aria-controls="pannelloCal" tabindex="-1">Calibrazione</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="griglia">
|
<div class="griglia">
|
||||||
<div class="colonna">
|
<div class="colonna">
|
||||||
<!-- #87: sezione Anteprima -->
|
<!-- #87: sezione Anteprima -->
|
||||||
@@ -132,7 +165,7 @@ PAGINA = r"""<!doctype html>
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="colonna">
|
<div class="colonna" id="pannelloAcq" role="tabpanel" aria-labelledby="tabAcq">
|
||||||
<!-- #87: sezione Sorgente -->
|
<!-- #87: sezione Sorgente -->
|
||||||
<section class="scheda" id="sezioneSorgente">
|
<section class="scheda" id="sezioneSorgente">
|
||||||
<h2>Sorgente</h2>
|
<h2>Sorgente</h2>
|
||||||
@@ -151,43 +184,51 @@ PAGINA = r"""<!doctype html>
|
|||||||
</div>
|
</div>
|
||||||
<div id="msgParametri" class="messaggio"></div>
|
<div id="msgParametri" class="messaggio"></div>
|
||||||
</section>
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- #91: tab Calibrazione (colonna destra al posto di Sorgente e Parametri) -->
|
||||||
|
<div class="colonna" id="pannelloCal" role="tabpanel" aria-labelledby="tabCal" hidden>
|
||||||
<section class="scheda" id="sezioneCalibrazione">
|
<section class="scheda" id="sezioneCalibrazione">
|
||||||
<h2>Calibrazione</h2>
|
<h2>Calibrazione</h2>
|
||||||
<div class="riga">
|
<div class="stato" style="margin:0 0 10px">Sorgente: <strong id="calSorgente">-</strong> (si cambia nella tab Acquisizione)</div>
|
||||||
|
<div class="origine">
|
||||||
|
<label for="origSorgente"><input id="origSorgente" name="origine" type="radio" value="sorgente" checked> Sorgente selezionata</label>
|
||||||
|
<label for="origFile"><input id="origFile" name="origine" type="radio" value="file"> Immagine da file</label>
|
||||||
|
</div>
|
||||||
|
<div class="riga" style="margin-top:4px">
|
||||||
|
<button id="scegliFile" class="secondario">Scegli immagine...</button>
|
||||||
|
<input id="file" type="file" accept="image/*" hidden>
|
||||||
|
<span id="nomeFile" class="nota" style="margin:0 0 6px">nessuna immagine scelta</span>
|
||||||
|
</div>
|
||||||
|
<div class="riga" style="margin-top:10px">
|
||||||
<div><label for="quadrato">Lato dello scacco (mm)</label><input id="quadrato" type="text" inputmode="decimal" value="2" size="8"></div>
|
<div><label for="quadrato">Lato dello scacco (mm)</label><input id="quadrato" type="text" inputmode="decimal" value="2" size="8"></div>
|
||||||
|
<button id="acquisisci" title="Acquisisci e calibra">Calcola</button>
|
||||||
</div>
|
</div>
|
||||||
<p class="nota">
|
<p class="nota">
|
||||||
Servono una scacchiera che riempie tutto il campo della camera, piana, ferma e ben illuminata, e il lato di uno scacco.
|
Servono una scacchiera che riempie tutto il campo della camera, piana, ferma e ben illuminata, e il lato di uno scacco.
|
||||||
La griglia si trova da sola; il risultato corregge anche la distorsione dell'ottica.
|
La griglia si trova da sola; il risultato corregge anche la distorsione dell'ottica.
|
||||||
Durante il calcolo l'anteprima si sospende.</p>
|
Calcolando dalla sorgente l'anteprima si sospende e poi riprende.</p>
|
||||||
<div class="riga" style="margin-top:10px">
|
|
||||||
<button id="acquisisci">Acquisisci e calibra</button>
|
|
||||||
<button id="scegliFile" class="secondario">Scegli immagine...</button>
|
|
||||||
<input id="file" type="file" accept="image/*" hidden>
|
|
||||||
<span id="nomeFile" class="nota" style="margin:0 0 6px">nessuna immagine scelta</span>
|
|
||||||
<button id="carica" class="secondario">Carica immagine e calibra</button>
|
|
||||||
</div>
|
|
||||||
<div id="messaggio" class="messaggio"></div>
|
<div id="messaggio" class="messaggio"></div>
|
||||||
|
|
||||||
<div id="risultato" hidden style="margin-top:10px">
|
<div id="risultato" hidden style="margin-top:10px">
|
||||||
<strong>Risultato del calcolo</strong>
|
<strong>Risultato del calcolo</strong>
|
||||||
|
<div id="origineCalcolo" class="nota" style="margin:2px 0 6px"></div>
|
||||||
<table id="tabella"></table>
|
<table id="tabella"></table>
|
||||||
<div id="avviso" class="avviso"></div>
|
<div id="avviso" class="avviso"></div>
|
||||||
<div class="riga" style="margin-top:10px">
|
<div class="riga" style="margin-top:10px">
|
||||||
|
<div><label for="nomeCal">Nome</label><input id="nomeCal" type="text" maxlength="60" size="22" autocomplete="off"></div>
|
||||||
<button id="salva">Salva</button>
|
<button id="salva">Salva</button>
|
||||||
<span class="nota" style="margin:0 0 6px">Da camera, salvando si acquisisce e si calcola di nuovo: tenere la scacchiera ferma.</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div id="msgSalva" class="messaggio"></div>
|
||||||
<img id="overlay" alt="Angoli trovati sulla scacchiera" style="max-width:100%;margin-top:8px;border:1px solid var(--bordo);border-radius:6px">
|
<img id="overlay" alt="Angoli trovati sulla scacchiera" style="max-width:100%;margin-top:8px;border:1px solid var(--bordo);border-radius:6px">
|
||||||
</div>
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div style="margin-top:14px">
|
<section class="scheda" id="sezioneSalvate">
|
||||||
<strong>Calibrazione salvata</strong>
|
<h2>Calibrazioni salvate</h2>
|
||||||
<div id="stato" class="stato">-</div>
|
<div id="stato" class="stato">-</div>
|
||||||
<div class="riga" style="margin-top:10px">
|
<div class="scorri"><table id="calibrazioni" class="elenco"></table></div>
|
||||||
<button id="elimina" class="pericolo" disabled>Elimina calibrazione</button>
|
<div id="msgElenco" class="messaggio"></div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -208,7 +249,8 @@ function fmt(v, cifre) {
|
|||||||
return n.toLocaleString("it-IT", o);
|
return n.toLocaleString("it-IT", o);
|
||||||
}
|
}
|
||||||
// numero senza separatore delle migliaia, per le caselle di input
|
// numero senza separatore delle migliaia, per le caselle di input
|
||||||
function fmtCasella(v) { return Number(v).toLocaleString("it-IT", { maximumFractionDigits: 6, useGrouping: false }); }
|
// #87: cifre = decimali massimi; i parametri camera ne usano 1 (la camera rilegge 11999,993164 per 12000)
|
||||||
|
function fmtCasella(v, cifre) { return Number(v).toLocaleString("it-IT", { maximumFractionDigits: cifre === undefined ? 6 : cifre, useGrouping: false }); }
|
||||||
// legge un numero scritto con virgola o con punto
|
// legge un numero scritto con virgola o con punto
|
||||||
function leggiNumero(testo) {
|
function leggiNumero(testo) {
|
||||||
var n = Number(String(testo).split(" ").join("").replace(",", "."));
|
var n = Number(String(testo).split(" ").join("").replace(",", "."));
|
||||||
@@ -274,6 +316,7 @@ function cambioSorgente(salva) {
|
|||||||
fermaAnteprima();
|
fermaAnteprima();
|
||||||
azzeraIndicatori();
|
azzeraIndicatori();
|
||||||
dire("msgAnteprima", "");
|
dire("msgAnteprima", "");
|
||||||
|
dire("msgElenco", ""); // #91
|
||||||
aggiornaStato();
|
aggiornaStato();
|
||||||
caricaParametri();
|
caricaParametri();
|
||||||
if (era) avviaAnteprima();
|
if (era) avviaAnteprima();
|
||||||
@@ -281,7 +324,7 @@ function cambioSorgente(salva) {
|
|||||||
|
|
||||||
// ---- Anteprima (#87)
|
// ---- Anteprima (#87)
|
||||||
|
|
||||||
var A = { attiva: false, gen: 0, inVolo: false, url: null, nitMax: 0 };
|
var A = { attiva: false, gen: 0, inVolo: false, url: null, nitMax: 0, ris: null }; // #91: ris = {w, h} dell'ultimo frame
|
||||||
|
|
||||||
function azzeraIndicatori() {
|
function azzeraIndicatori() {
|
||||||
A.nitMax = 0;
|
A.nitMax = 0;
|
||||||
@@ -289,6 +332,8 @@ function azzeraIndicatori() {
|
|||||||
$("saturati").className = "valore";
|
$("saturati").className = "valore";
|
||||||
$("barraNitidezza").style.width = "0";
|
$("barraNitidezza").style.width = "0";
|
||||||
$("raddrizzato").textContent = " ";
|
$("raddrizzato").textContent = " ";
|
||||||
|
A.ris = null; // #91: risoluzione del frame non piu' nota
|
||||||
|
segnaRisoluzioni();
|
||||||
}
|
}
|
||||||
|
|
||||||
function pulsantiAnteprima() {
|
function pulsantiAnteprima() {
|
||||||
@@ -321,7 +366,12 @@ function aggiornaIndicatori(h) {
|
|||||||
}
|
}
|
||||||
if (isFinite(media)) $("media").textContent = fmt(media, 1);
|
if (isFinite(media)) $("media").textContent = fmt(media, 1);
|
||||||
var w = h.get("X-Larghezza"), a = h.get("X-Altezza");
|
var w = h.get("X-Larghezza"), a = h.get("X-Altezza");
|
||||||
if (w && a) $("dimensioni").textContent = fmt(w, 0) + " x " + fmt(a, 0);
|
if (w && a) {
|
||||||
|
$("dimensioni").textContent = fmt(w, 0) + " x " + fmt(a, 0);
|
||||||
|
// #91: risoluzione nota del frame, per segnare le calibrazioni che non combaciano
|
||||||
|
var nw = parseInt(w, 10), na = parseInt(a, 10);
|
||||||
|
if (!A.ris || A.ris.w !== nw || A.ris.h !== na) { A.ris = { w: nw, h: na }; segnaRisoluzioni(); }
|
||||||
|
}
|
||||||
var r = h.get("X-Raddrizzato");
|
var r = h.get("X-Raddrizzato");
|
||||||
$("raddrizzato").textContent = r === "si" ? "raddrizzata dalla calibrazione" : r === "no" ? "non raddrizzata" : " ";
|
$("raddrizzato").textContent = r === "si" ? "raddrizzata dalla calibrazione" : r === "no" ? "non raddrizzata" : " ";
|
||||||
}
|
}
|
||||||
@@ -357,7 +407,7 @@ async function unaAnteprima(lato) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ciclo sequenziale: la richiesta dopo parte solo a risposta arrivata, almeno 300 ms dopo la precedente
|
// ciclo sequenziale: la richiesta dopo parte solo a risposta arrivata, almeno 100 ms dopo la precedente (#90: ~10 fps)
|
||||||
async function ciclo(g) {
|
async function ciclo(g) {
|
||||||
while (A.inVolo) await pausa(50);
|
while (A.inVolo) await pausa(50);
|
||||||
while (A.attiva && g === A.gen) {
|
while (A.attiva && g === A.gen) {
|
||||||
@@ -365,7 +415,7 @@ async function ciclo(g) {
|
|||||||
var esito = await unaAnteprima(1280);
|
var esito = await unaAnteprima(1280);
|
||||||
if (g !== A.gen) return;
|
if (g !== A.gen) return;
|
||||||
if (esito === "fatale") { fermaAnteprima(); return; }
|
if (esito === "fatale") { fermaAnteprima(); return; }
|
||||||
await pausa(esito === "errore" ? 1500 : Math.max(300 - (Date.now() - t0), 0));
|
await pausa(esito === "errore" ? 1500 : Math.max(100 - (Date.now() - t0), 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -504,20 +554,20 @@ function creaParametro(nome, d) {
|
|||||||
cur.disabled = bloccato;
|
cur.disabled = bloccato;
|
||||||
cur.oninput = function () { // il cursore aggiorna la casella subito, la scrittura arriva dopo 300 ms
|
cur.oninput = function () { // il cursore aggiorna la casella subito, la scrittura arriva dopo 300 ms
|
||||||
var v = adatta(d, daPosizione(d, Number(cur.value)));
|
var v = adatta(d, daPosizione(d, Number(cur.value)));
|
||||||
casella.value = fmtCasella(v);
|
casella.value = fmtCasella(v, 1);
|
||||||
modifica(nome, v);
|
modifica(nome, v);
|
||||||
};
|
};
|
||||||
campo.appendChild(cur);
|
campo.appendChild(cur);
|
||||||
}
|
}
|
||||||
casella.type = "text";
|
casella.type = "text";
|
||||||
casella.inputMode = "decimal";
|
casella.inputMode = "decimal";
|
||||||
casella.value = fmtCasella(d.valore);
|
casella.value = fmtCasella(d.valore, 1);
|
||||||
casella.disabled = bloccato;
|
casella.disabled = bloccato;
|
||||||
casella.onchange = function () {
|
casella.onchange = function () {
|
||||||
var v = leggiNumero(casella.value);
|
var v = leggiNumero(casella.value);
|
||||||
if (isNaN(v)) { dire("msgParametri", "Valore non valido per " + ETICHETTE[nome].toLowerCase() + ".", "errore"); casella.value = fmtCasella(P.dati[nome].valore); return; }
|
if (isNaN(v)) { dire("msgParametri", "Valore non valido per " + ETICHETTE[nome].toLowerCase() + ".", "errore"); casella.value = fmtCasella(P.dati[nome].valore, 1); return; }
|
||||||
v = adatta(d, v);
|
v = adatta(d, v);
|
||||||
casella.value = fmtCasella(v);
|
casella.value = fmtCasella(v, 1);
|
||||||
if (cur) cur.value = aPosizione(d, v);
|
if (cur) cur.value = aPosizione(d, v);
|
||||||
modifica(nome, v);
|
modifica(nome, v);
|
||||||
};
|
};
|
||||||
@@ -588,7 +638,7 @@ function aggiornaValori(j) {
|
|||||||
if (!el || P.pendenti.hasOwnProperty(nome)) return;
|
if (!el || P.pendenti.hasOwnProperty(nome)) return;
|
||||||
P.dati[nome].valore = d.valore;
|
P.dati[nome].valore = d.valore;
|
||||||
if (el.select) el.select.value = d.valore;
|
if (el.select) el.select.value = d.valore;
|
||||||
if (el.casella && document.activeElement !== el.casella) el.casella.value = fmtCasella(d.valore);
|
if (el.casella && document.activeElement !== el.casella) el.casella.value = fmtCasella(d.valore, 1);
|
||||||
if (el.cursore && document.activeElement !== el.cursore) el.cursore.value = aPosizione(P.dati[nome], d.valore);
|
if (el.cursore && document.activeElement !== el.cursore) el.cursore.value = aPosizione(P.dati[nome], d.valore);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -610,6 +660,29 @@ $("salvaParametri").onclick = async function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ---- Tab (#91): «Acquisizione» | «Calibrazione»; l'anteprima sta fuori dai pannelli e resta sempre visibile
|
||||||
|
|
||||||
|
function scegliTab(nome, salva) {
|
||||||
|
var cal = nome === "cal";
|
||||||
|
$("tabAcq").setAttribute("aria-selected", cal ? "false" : "true");
|
||||||
|
$("tabCal").setAttribute("aria-selected", cal ? "true" : "false");
|
||||||
|
$("tabAcq").tabIndex = cal ? -1 : 0;
|
||||||
|
$("tabCal").tabIndex = cal ? 0 : -1;
|
||||||
|
$("pannelloAcq").hidden = cal;
|
||||||
|
$("pannelloCal").hidden = !cal;
|
||||||
|
if (salva) { memoria("tmf.acq.tab", nome); if (cal) caricaCalibrazioni(); } // l'elenco si rilegge entrando
|
||||||
|
}
|
||||||
|
$("tabAcq").onclick = function () { scegliTab("acq", true); };
|
||||||
|
$("tabCal").onclick = function () { scegliTab("cal", true); };
|
||||||
|
[$("tabAcq"), $("tabCal")].forEach(function (b) { // frecce sinistra/destra fra le tab
|
||||||
|
b.onkeydown = function (e) {
|
||||||
|
if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
|
||||||
|
var cal = b.id === "tabAcq";
|
||||||
|
scegliTab(cal ? "cal" : "acq", true);
|
||||||
|
$(cal ? "tabCal" : "tabAcq").focus();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
// ---- Calibrazione (logica di #83 e #84; #87: lato precompilato, data italiana, conferma in pagina)
|
// ---- Calibrazione (logica di #83 e #84; #87: lato precompilato, data italiana, conferma in pagina)
|
||||||
|
|
||||||
function righe(d) {
|
function righe(d) {
|
||||||
@@ -643,37 +716,6 @@ function tabella(el, d) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function aggiornaStato() {
|
|
||||||
var sorgente = $("sorgente").value;
|
|
||||||
var stato = $("stato");
|
|
||||||
annullaConferma();
|
|
||||||
$("elimina").disabled = true;
|
|
||||||
if (!sorgente) { stato.textContent = "-"; $("statoSorgente").textContent = "-"; return; }
|
|
||||||
try {
|
|
||||||
var r = await fetch("/camera/calibration?source=" + encodeURIComponent(sorgente));
|
|
||||||
if (sorgente !== $("sorgente").value) return; // nel frattempo si e' cambiata sorgente
|
|
||||||
if (r.status === 404) {
|
|
||||||
stato.textContent = "Sorgente non calibrata.";
|
|
||||||
$("statoSorgente").textContent = "non calibrata";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!r.ok) { stato.textContent = await dettaglio(r); return; }
|
|
||||||
var d = await r.json();
|
|
||||||
stato.textContent = "";
|
|
||||||
var t = document.createElement("table");
|
|
||||||
tabella(t, d);
|
|
||||||
var quando = document.createElement("div");
|
|
||||||
quando.textContent = "Calibrata il " + dataItaliana(d.calibrated_at);
|
|
||||||
stato.appendChild(t);
|
|
||||||
stato.appendChild(quando);
|
|
||||||
$("elimina").disabled = false;
|
|
||||||
$("statoSorgente").textContent = "calibrata: " + fmt(d.px_per_mm, 2) + " px/mm";
|
|
||||||
if (d.square_mm) $("quadrato").value = fmtCasella(d.square_mm); // #87: parte dal lato gia' usato
|
|
||||||
} catch (e) {
|
|
||||||
stato.textContent = "Servizio non raggiungibile.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// avvisi sulla qualita' (solo calibrazione densa): copertura bassa o residuo alto
|
// avvisi sulla qualita' (solo calibrazione densa): copertura bassa o residuo alto
|
||||||
function avvisi(d) {
|
function avvisi(d) {
|
||||||
var a = [];
|
var a = [];
|
||||||
@@ -686,78 +728,292 @@ function avvisi(d) {
|
|||||||
return a.join(" ");
|
return a.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function calcola(conFile, salva) {
|
// ---- Calibrazioni con nome (#91): archivio unico, una attiva per sorgente
|
||||||
|
|
||||||
|
var C = { elenco: [], attiva: null, celle: [], gen: 0, confermaNome: null, confermaBtn: null, confermaTimer: null };
|
||||||
|
var S = { nome: null, timer: null }; // secondo clic su «Sovrascrivi» entro 4 s
|
||||||
|
var JSON_H = { "Content-Type": "application/json" };
|
||||||
|
|
||||||
|
function descriviOrigine(o) { return String(o || "-").replace(":", " "); }
|
||||||
|
|
||||||
|
// stato della calibrazione attiva sulla sorgente selezionata (come prima di #91, piu' il nome)
|
||||||
|
async function aggiornaStato() {
|
||||||
var sorgente = $("sorgente").value;
|
var sorgente = $("sorgente").value;
|
||||||
if (!sorgente) { messaggio("Scegliere una sorgente.", "errore"); return; }
|
var stato = $("stato");
|
||||||
|
annullaConferma();
|
||||||
|
$("calSorgente").textContent = sorgente ? $("sorgente").options[$("sorgente").selectedIndex].textContent : "-"; // #91
|
||||||
|
if (!sorgente) { stato.textContent = "-"; $("statoSorgente").textContent = "-"; caricaCalibrazioni(); return; }
|
||||||
|
try {
|
||||||
|
var r = await fetch("/camera/calibration?source=" + encodeURIComponent(sorgente));
|
||||||
|
if (sorgente !== $("sorgente").value) return; // nel frattempo si e' cambiata sorgente
|
||||||
|
if (r.status === 404) {
|
||||||
|
stato.textContent = "Sorgente non calibrata.";
|
||||||
|
$("statoSorgente").textContent = "non calibrata";
|
||||||
|
} else if (!r.ok) {
|
||||||
|
stato.textContent = await dettaglio(r);
|
||||||
|
} else {
|
||||||
|
var d = await r.json();
|
||||||
|
stato.textContent = "";
|
||||||
|
var titolo = document.createElement("div");
|
||||||
|
titolo.textContent = "Calibrazione attiva: " + (d.nome ? "«" + d.nome + "»" : "(senza nome)");
|
||||||
|
titolo.style.fontWeight = "600";
|
||||||
|
var t = document.createElement("table");
|
||||||
|
tabella(t, d);
|
||||||
|
var quando = document.createElement("div");
|
||||||
|
quando.textContent = "Calibrata il " + dataItaliana(d.calibrated_at);
|
||||||
|
stato.appendChild(titolo);
|
||||||
|
stato.appendChild(t);
|
||||||
|
stato.appendChild(quando);
|
||||||
|
$("statoSorgente").textContent = "calibrata: " + fmt(d.px_per_mm, 2) + " px/mm";
|
||||||
|
if (d.square_mm) $("quadrato").value = fmtCasella(d.square_mm); // #87: parte dal lato gia' usato
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
stato.textContent = "Servizio non raggiungibile.";
|
||||||
|
}
|
||||||
|
caricaCalibrazioni();
|
||||||
|
}
|
||||||
|
|
||||||
|
// #91: elenco unico delle calibrazioni salvate; "attiva" e' quella della sorgente selezionata
|
||||||
|
async function caricaCalibrazioni() {
|
||||||
|
var sorgente = $("sorgente").value;
|
||||||
|
var g = ++C.gen;
|
||||||
|
try {
|
||||||
|
var r = await fetch("/camera/calibrazioni" + (sorgente ? "?source=" + encodeURIComponent(sorgente) : ""));
|
||||||
|
if (g !== C.gen) return;
|
||||||
|
if (!r.ok) { dire("msgElenco", await dettaglio(r), "errore"); return; }
|
||||||
|
var j = await r.json();
|
||||||
|
if (g !== C.gen) return;
|
||||||
|
C.elenco = j.calibrazioni || [];
|
||||||
|
C.attiva = j.attiva || null;
|
||||||
|
disegnaElenco();
|
||||||
|
} catch (e) {
|
||||||
|
if (g === C.gen) dire("msgElenco", "Servizio non raggiungibile.", "errore");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cella(tr, testo) {
|
||||||
|
var td = document.createElement("td");
|
||||||
|
td.textContent = testo;
|
||||||
|
tr.appendChild(td);
|
||||||
|
return td;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bottone(testo, classe, fn) {
|
||||||
|
var b = document.createElement("button");
|
||||||
|
b.textContent = testo;
|
||||||
|
b.className = classe || "";
|
||||||
|
b.onclick = fn;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
function disegnaElenco() {
|
||||||
|
var t = $("calibrazioni");
|
||||||
|
annullaConferma();
|
||||||
|
t.textContent = "";
|
||||||
|
C.celle = [];
|
||||||
|
if (!C.elenco.length) {
|
||||||
|
var trVuota = document.createElement("tr");
|
||||||
|
cella(trVuota, "Nessuna calibrazione salvata.");
|
||||||
|
t.appendChild(trVuota);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var testa = document.createElement("tr");
|
||||||
|
["Nome", "Risoluzione", "px/mm", "Metodo", "Data", "Origine", ""].forEach(function (h) {
|
||||||
|
var th = document.createElement("th");
|
||||||
|
th.textContent = h;
|
||||||
|
testa.appendChild(th);
|
||||||
|
});
|
||||||
|
t.appendChild(testa);
|
||||||
|
C.elenco.forEach(function (c) {
|
||||||
|
var tr = document.createElement("tr");
|
||||||
|
var tdNome = cella(tr, c.nome);
|
||||||
|
var attiva = C.attiva !== null && c.nome === C.attiva;
|
||||||
|
if (attiva) {
|
||||||
|
var s1 = document.createElement("span");
|
||||||
|
s1.className = "segno";
|
||||||
|
s1.textContent = "attiva";
|
||||||
|
tdNome.appendChild(s1);
|
||||||
|
}
|
||||||
|
var s2 = document.createElement("span"); // «risoluzione diversa» dal frame della sorgente (si accende in segnaRisoluzioni)
|
||||||
|
s2.className = "segno diversa";
|
||||||
|
s2.textContent = "risoluzione diversa";
|
||||||
|
s2.hidden = true;
|
||||||
|
tdNome.appendChild(s2);
|
||||||
|
C.celle.push({ w: Number(c.image_width), h: Number(c.image_height), span: s2 });
|
||||||
|
cella(tr, c.image_width && c.image_height ? fmt(c.image_width, 0) + "×" + fmt(c.image_height, 0) : "-");
|
||||||
|
cella(tr, fmt(c.px_per_mm, 3));
|
||||||
|
cella(tr, c.metodo === "densa" ? "densa" : "planare");
|
||||||
|
cella(tr, c.calibrated_at ? dataItaliana(c.calibrated_at) : "-");
|
||||||
|
cella(tr, descriviOrigine(c.origine));
|
||||||
|
var az = document.createElement("td");
|
||||||
|
az.className = "azioni";
|
||||||
|
var bc = bottone("Carica", "", function () { caricaNome(c.nome); });
|
||||||
|
bc.disabled = !$("sorgente").value;
|
||||||
|
az.appendChild(bc);
|
||||||
|
if (attiva) az.appendChild(bottone("Scollega", "secondario", scollega));
|
||||||
|
az.appendChild(bottone("Elimina", "secondario", function (e) { eliminaNome(c.nome, e.currentTarget); }));
|
||||||
|
tr.appendChild(az);
|
||||||
|
t.appendChild(tr);
|
||||||
|
});
|
||||||
|
segnaRisoluzioni();
|
||||||
|
}
|
||||||
|
|
||||||
|
// #91: «risoluzione diversa» se il frame noto della sorgente non combacia con quello della calibrazione
|
||||||
|
function segnaRisoluzioni() {
|
||||||
|
(C.celle || []).forEach(function (c) {
|
||||||
|
c.span.hidden = !(A.ris && c.w > 0 && c.h > 0 && (A.ris.w !== c.w || A.ris.h !== c.h));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// «Carica»: la calibrazione diventa quella attiva della sorgente. Un errore (es. risoluzione diversa) non ferma l'anteprima.
|
||||||
|
async function caricaNome(nome) {
|
||||||
|
var sorgente = $("sorgente").value;
|
||||||
|
if (!sorgente) { dire("msgElenco", "Scegliere una sorgente nella tab Acquisizione.", "errore"); return; }
|
||||||
|
dire("msgElenco", "Caricamento di «" + nome + "»...", "");
|
||||||
|
try {
|
||||||
|
var r = await fetch("/camera/calibrazione-attiva", { method: "PUT", headers: JSON_H, body: JSON.stringify({ source: sorgente, nome: nome }) });
|
||||||
|
if (sorgente !== $("sorgente").value) return;
|
||||||
|
if (!r.ok) { dire("msgElenco", await dettaglio(r), "errore"); return; }
|
||||||
|
dire("msgElenco", "Calibrazione «" + nome + "» caricata sulla sorgente.", "ok");
|
||||||
|
$("raddrizzato").textContent = $("grezzo").checked ? "non raddrizzata" : "raddrizzata dalla calibrazione"; // il prossimo frame conferma
|
||||||
|
aggiornaStato();
|
||||||
|
} catch (e) {
|
||||||
|
dire("msgElenco", "Servizio non raggiungibile.", "errore");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// «Scollega»: la sorgente torna senza calibrazione, la libreria resta
|
||||||
|
async function scollega() {
|
||||||
|
var sorgente = $("sorgente").value;
|
||||||
|
if (!sorgente) return;
|
||||||
|
try {
|
||||||
|
var r = await fetch("/camera/calibration?source=" + encodeURIComponent(sorgente), { method: "DELETE" });
|
||||||
|
dire("msgElenco", r.ok ? "Calibrazione scollegata dalla sorgente (resta fra le salvate)." : await dettaglio(r), r.ok ? "ok" : "errore");
|
||||||
|
if (r.ok) $("raddrizzato").textContent = "non raddrizzata";
|
||||||
|
} catch (e) {
|
||||||
|
dire("msgElenco", "Servizio non raggiungibile.", "errore");
|
||||||
|
}
|
||||||
|
aggiornaStato();
|
||||||
|
}
|
||||||
|
|
||||||
|
// «Elimina» di una riga: conferma in pagina con un secondo clic entro 4 s (niente finestre del browser)
|
||||||
|
function annullaConferma() {
|
||||||
|
clearTimeout(C.confermaTimer);
|
||||||
|
C.confermaTimer = null;
|
||||||
|
if (C.confermaBtn) C.confermaBtn.textContent = "Elimina";
|
||||||
|
C.confermaBtn = null;
|
||||||
|
C.confermaNome = null;
|
||||||
|
}
|
||||||
|
async function eliminaNome(nome, btn) {
|
||||||
|
if (C.confermaNome !== nome) {
|
||||||
|
annullaConferma();
|
||||||
|
C.confermaNome = nome;
|
||||||
|
C.confermaBtn = btn;
|
||||||
|
btn.textContent = "Confermi? Clic ancora";
|
||||||
|
C.confermaTimer = setTimeout(annullaConferma, 4000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
annullaConferma();
|
||||||
|
try {
|
||||||
|
var r = await fetch("/camera/calibrazioni?nome=" + encodeURIComponent(nome), { method: "DELETE" });
|
||||||
|
dire("msgElenco", r.ok ? "Calibrazione «" + nome + "» eliminata." : await dettaglio(r), r.ok ? "ok" : "errore");
|
||||||
|
} catch (e) {
|
||||||
|
dire("msgElenco", "Servizio non raggiungibile.", "errore");
|
||||||
|
}
|
||||||
|
aggiornaStato();
|
||||||
|
}
|
||||||
|
|
||||||
|
// #91: il calcolo non salva mai; il servizio tiene il risultato e ne da' il calcolo_id per «Salva»
|
||||||
|
async function calcola() {
|
||||||
|
var daFile = $("origFile").checked;
|
||||||
|
var sorgente = $("sorgente").value;
|
||||||
|
if (!daFile && !sorgente) { messaggio("Scegliere una sorgente nella tab Acquisizione.", "errore"); return; }
|
||||||
var lato = leggiNumero($("quadrato").value);
|
var lato = leggiNumero($("quadrato").value);
|
||||||
if (!(lato > 0)) { messaggio("Il lato dello scacco deve essere un numero maggiore di zero.", "errore"); return; }
|
if (!(lato > 0)) { messaggio("Il lato dello scacco deve essere un numero maggiore di zero.", "errore"); return; }
|
||||||
var f = new FormData();
|
var f = new FormData();
|
||||||
f.append("source", sorgente);
|
|
||||||
f.append("square_mm", String(lato)); // al servizio sempre con il punto
|
f.append("square_mm", String(lato)); // al servizio sempre con il punto
|
||||||
f.append("save", salva ? "true" : "false");
|
if (daFile) {
|
||||||
if (conFile) {
|
|
||||||
var file = $("file").files[0];
|
var file = $("file").files[0];
|
||||||
if (!file) { messaggio("Scegliere un file immagine.", "errore"); return; }
|
if (!file) { messaggio("Scegliere un file immagine.", "errore"); return; }
|
||||||
f.append("image", file);
|
f.append("image", file);
|
||||||
|
} else {
|
||||||
|
f.append("source", sorgente);
|
||||||
}
|
}
|
||||||
var eraAttiva = A.attiva; // #87: l'anteprima si sospende e poi riprende
|
var eraAttiva = !daFile && A.attiva; // #87: da sorgente l'anteprima si sospende e poi riprende
|
||||||
if (eraAttiva) fermaAnteprima();
|
if (eraAttiva) fermaAnteprima();
|
||||||
messaggio("Calcolo in corso...", "");
|
messaggio("Calcolo in corso...", "");
|
||||||
["acquisisci", "carica", "salva"].forEach(function (i) { $(i).disabled = true; });
|
["acquisisci", "salva"].forEach(function (i) { $(i).disabled = true; });
|
||||||
try {
|
try {
|
||||||
var r = await fetch("/camera/calibrate", { method: "POST", body: f });
|
var r = await fetch("/camera/calibrate", { method: "POST", body: f });
|
||||||
if (!r.ok) { messaggio(await dettaglio(r), "errore"); return; }
|
if (!r.ok) { messaggio(await dettaglio(r), "errore"); return; }
|
||||||
var d = await r.json();
|
var d = await r.json();
|
||||||
ultimo = { conFile: conFile, dati: d };
|
ultimo = { dati: d };
|
||||||
tabella($("tabella"), d);
|
tabella($("tabella"), d);
|
||||||
$("overlay").src = "data:image/png;base64," + d.overlay_png;
|
$("overlay").src = "data:image/png;base64," + d.overlay_png;
|
||||||
$("avviso").textContent = avvisi(d);
|
$("avviso").textContent = avvisi(d);
|
||||||
|
$("origineCalcolo").textContent = "Origine: " + descriviOrigine(d.origine);
|
||||||
$("risultato").hidden = false;
|
$("risultato").hidden = false;
|
||||||
messaggio(d.saved ? "Calibrazione salvata." : "Calibrazione riuscita: controllare e salvare.", "ok");
|
annullaSovrascrivi();
|
||||||
if (d.saved) aggiornaStato();
|
dire("msgSalva", "");
|
||||||
|
messaggio("Calcolo riuscito: dare un nome e salvare.", "ok");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
messaggio("Servizio non raggiungibile.", "errore");
|
messaggio("Servizio non raggiungibile.", "errore");
|
||||||
} finally {
|
} finally {
|
||||||
["acquisisci", "carica", "salva"].forEach(function (i) { $(i).disabled = false; });
|
$("acquisisci").disabled = false;
|
||||||
|
$("salva").disabled = false;
|
||||||
if (eraAttiva) avviaAnteprima();
|
if (eraAttiva) avviaAnteprima();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$("acquisisci").onclick = function () { calcola(false, false); };
|
// «Salva» con nome; se il nome c'e' gia' il pulsante chiede un secondo clic per sovrascrivere
|
||||||
$("carica").onclick = function () { calcola(true, false); };
|
function annullaSovrascrivi() {
|
||||||
// «Salva» rifa il calcolo con save=true sulla stessa origine (altra acquisizione se da camera)
|
clearTimeout(S.timer);
|
||||||
$("salva").onclick = function () { calcola(ultimo ? ultimo.conFile : false, true); };
|
S.timer = null;
|
||||||
|
S.nome = null;
|
||||||
|
$("salva").textContent = "Salva";
|
||||||
|
}
|
||||||
|
async function salvaNome() {
|
||||||
|
if (!ultimo || !ultimo.dati.calcolo_id) { dire("msgSalva", "Nessun calcolo da salvare: calcolare prima.", "errore"); return; }
|
||||||
|
var nome = $("nomeCal").value.trim();
|
||||||
|
if (!nome) { dire("msgSalva", "Scrivere un nome per la calibrazione.", "errore"); return; }
|
||||||
|
if (nome.length > 60) { dire("msgSalva", "Il nome può avere al massimo 60 caratteri.", "errore"); return; }
|
||||||
|
var sovrascrivi = S.timer !== null && S.nome === nome.toLowerCase(); // secondo clic sullo stesso nome
|
||||||
|
annullaSovrascrivi();
|
||||||
|
$("salva").disabled = true;
|
||||||
|
try {
|
||||||
|
var r = await fetch("/camera/calibrazioni", {
|
||||||
|
method: "POST", headers: JSON_H,
|
||||||
|
body: JSON.stringify({ calcolo_id: ultimo.dati.calcolo_id, nome: nome, sovrascrivi: sovrascrivi })
|
||||||
|
});
|
||||||
|
if (r.status === 409) {
|
||||||
|
S.nome = nome.toLowerCase();
|
||||||
|
$("salva").textContent = "Sovrascrivi «" + nome + "»? Clic ancora";
|
||||||
|
S.timer = setTimeout(annullaSovrascrivi, 4000);
|
||||||
|
dire("msgSalva", await dettaglio(r), "errore");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!r.ok) { dire("msgSalva", await dettaglio(r), "errore"); return; }
|
||||||
|
dire("msgSalva", "Calibrazione «" + nome + "» salvata. Per usarla su una sorgente: «Carica» nell'elenco.", "ok");
|
||||||
|
caricaCalibrazioni();
|
||||||
|
} catch (e) {
|
||||||
|
dire("msgSalva", "Servizio non raggiungibile.", "errore");
|
||||||
|
} finally {
|
||||||
|
$("salva").disabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$("acquisisci").onclick = calcola;
|
||||||
|
$("salva").onclick = salvaNome;
|
||||||
|
$("nomeCal").onkeydown = function (e) { if (e.key === "Enter") salvaNome(); };
|
||||||
// #87: il pulsante del file e' in italiano, l'input nativo resta nascosto
|
// #87: il pulsante del file e' in italiano, l'input nativo resta nascosto
|
||||||
$("scegliFile").onclick = function () { $("file").click(); };
|
$("scegliFile").onclick = function () { $("file").click(); };
|
||||||
$("file").onchange = function () {
|
$("file").onchange = function () {
|
||||||
$("nomeFile").textContent = $("file").files[0] ? $("file").files[0].name : "nessuna immagine scelta";
|
$("nomeFile").textContent = $("file").files[0] ? $("file").files[0].name : "nessuna immagine scelta";
|
||||||
};
|
if ($("file").files[0]) $("origFile").checked = true; // #91: scelto un file, l'origine diventa il file
|
||||||
|
|
||||||
// #87: «Elimina calibrazione» chiede conferma in pagina con un secondo clic (niente finestre del browser)
|
|
||||||
var confermaTimer = null;
|
|
||||||
function annullaConferma() {
|
|
||||||
clearTimeout(confermaTimer);
|
|
||||||
confermaTimer = null;
|
|
||||||
$("elimina").textContent = "Elimina calibrazione";
|
|
||||||
}
|
|
||||||
$("elimina").onclick = async function () {
|
|
||||||
if (!confermaTimer) {
|
|
||||||
$("elimina").textContent = "Confermi? Clic ancora per eliminare";
|
|
||||||
confermaTimer = setTimeout(annullaConferma, 4000);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
annullaConferma();
|
|
||||||
var sorgente = $("sorgente").value;
|
|
||||||
try {
|
|
||||||
var r = await fetch("/camera/calibration?source=" + encodeURIComponent(sorgente), { method: "DELETE" });
|
|
||||||
messaggio(r.ok ? "Calibrazione eliminata." : await dettaglio(r), r.ok ? "ok" : "errore");
|
|
||||||
} catch (e) {
|
|
||||||
messaggio("Servizio non raggiungibile.", "errore");
|
|
||||||
}
|
|
||||||
aggiornaStato();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
$("sorgente").onchange = function () { cambioSorgente(true); };
|
$("sorgente").onchange = function () { cambioSorgente(true); };
|
||||||
|
scegliTab(memoria("tmf.acq.tab") === "cal" ? "cal" : "acq", false); // #91: tab ricordata
|
||||||
caricaSorgenti();
|
caricaSorgenti();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -169,6 +169,12 @@ def create_app(folder: Path | str | None = None,
|
|||||||
sorgente = aperte.get(nome)
|
sorgente = aperte.get(nome)
|
||||||
if sorgente is None:
|
if sorgente is None:
|
||||||
sorgente = open_source(nome, None, config=_config())
|
sorgente = open_source(nome, None, config=_config())
|
||||||
|
# TieVision-Core#341 / #89: free-run, serve la scena di adesso, non il frame vecchio in coda
|
||||||
|
if hasattr(sorgente, "solo_ultimo_frame"):
|
||||||
|
try:
|
||||||
|
sorgente.solo_ultimo_frame()
|
||||||
|
except Exception as e: # noqa: BLE001 - producer senza il nodo: si apre lo stesso
|
||||||
|
_log.warning("frame piu' recente non impostabile su %s: %s", nome, e)
|
||||||
_carica_settaggi(nome, sorgente) # #87: predefiniti salvati, se ci sono
|
_carica_settaggi(nome, sorgente) # #87: predefiniti salvati, se ci sono
|
||||||
with lock:
|
with lock:
|
||||||
aperte[nome] = sorgente
|
aperte[nome] = sorgente
|
||||||
|
|||||||
@@ -278,6 +278,40 @@ def test_settaggi_rotti_non_bloccano_l_apertura(cartella, tmp_path, monkeypatch)
|
|||||||
assert c.get("/camera/parametri", params={"source": SORGENTE}).status_code == 200
|
assert c.get("/camera/parametri", params={"source": SORGENTE}).status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def test_apertura_chiede_il_frame_piu_recente(cartella, tmp_path, monkeypatch):
|
||||||
|
# #89: solo_ultimo_frame() una volta sola all'apertura, non a ogni richiesta
|
||||||
|
class ConUltimoFrame(Finta):
|
||||||
|
chiamate = 0
|
||||||
|
|
||||||
|
def solo_ultimo_frame(self, attivo=True):
|
||||||
|
self.chiamate += 1
|
||||||
|
|
||||||
|
finta = ConUltimoFrame()
|
||||||
|
with _client(cartella, tmp_path / "cfg", monkeypatch, finta) as c:
|
||||||
|
for _ in range(3):
|
||||||
|
assert c.get("/camera/parametri", params={"source": SORGENTE}).status_code == 200
|
||||||
|
assert finta.chiamate == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_frame_piu_recente_non_impostabile_non_blocca_l_apertura(cartella, tmp_path, monkeypatch, caplog):
|
||||||
|
# #89: producer senza il nodo -> avviso nel log, apertura riuscita
|
||||||
|
class SenzaNodo(Finta):
|
||||||
|
def solo_ultimo_frame(self, attivo=True):
|
||||||
|
raise CameraStateError("questo producer non espone StreamBufferHandlingMode")
|
||||||
|
|
||||||
|
with caplog.at_level("WARNING"):
|
||||||
|
with _client(cartella, tmp_path / "cfg", monkeypatch, SenzaNodo()) as c:
|
||||||
|
assert c.get("/camera/parametri", params={"source": SORGENTE}).status_code == 200
|
||||||
|
assert "frame piu' recente non impostabile" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
def test_sorgente_senza_solo_ultimo_frame_si_apre(cartella, tmp_path, monkeypatch):
|
||||||
|
# #89: FolderCamera e simili non hanno il metodo: nessun errore
|
||||||
|
assert not hasattr(Finta(), "solo_ultimo_frame")
|
||||||
|
with _client(cartella, tmp_path / "cfg", monkeypatch, Finta()) as c:
|
||||||
|
assert c.get("/camera/parametri", params={"source": SORGENTE}).status_code == 200
|
||||||
|
|
||||||
|
|
||||||
# ---- pagina
|
# ---- pagina
|
||||||
|
|
||||||
def test_acquisizione_alias_della_pagina(client):
|
def test_acquisizione_alias_della_pagina(client):
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ def test_id_principali():
|
|||||||
attesi = {"sorgente", "avvia", "ferma", "scatta", "grezzo", "mirinoCasella", "immagine",
|
attesi = {"sorgente", "avvia", "ferma", "scatta", "grezzo", "mirinoCasella", "immagine",
|
||||||
"nitidezza", "nitidezzaMax", "saturati", "media", "dimensioni",
|
"nitidezza", "nitidezzaMax", "saturati", "media", "dimensioni",
|
||||||
"parametri", "salvaParametri", "quadrato", "acquisisci", "scegliFile", "file",
|
"parametri", "salvaParametri", "quadrato", "acquisisci", "scegliFile", "file",
|
||||||
"carica", "salva", "elimina", "stato", "statoSorgente"}
|
"salva", "stato", "statoSorgente"} # #91: carica/elimina sono ora per riga, nell'elenco
|
||||||
assert attesi <= ids, attesi - ids
|
assert attesi <= ids, attesi - ids
|
||||||
# ogni id usato dal JS con $("...") esiste nel markup
|
# ogni id usato dal JS con $("...") esiste nel markup
|
||||||
usati = set(re.findall(r'\$\("([^"]+)"\)', PAGINA))
|
usati = set(re.findall(r'\$\("([^"]+)"\)', PAGINA))
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
"""Test della pagina a due tab (#91): contenuto statico di PAGINA, senza servizio."""
|
||||||
|
|
||||||
|
import importlib.util
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
_FILE = Path(__file__).resolve().parents[1] / "calibrazione_pagina.py"
|
||||||
|
_spec = importlib.util.spec_from_file_location("calibrazione_pagina_tab", _FILE)
|
||||||
|
_mod = importlib.util.module_from_spec(_spec)
|
||||||
|
_spec.loader.exec_module(_mod)
|
||||||
|
PAGINA = _mod.PAGINA
|
||||||
|
|
||||||
|
|
||||||
|
def test_due_tab_con_ruolo_e_selezione():
|
||||||
|
assert re.search(r'<button id="tabAcq"[^>]*role="tab"[^>]*aria-selected="true"', PAGINA)
|
||||||
|
assert re.search(r'<button id="tabCal"[^>]*role="tab"[^>]*aria-selected="false"', PAGINA)
|
||||||
|
assert ">Acquisizione</button>" in PAGINA and ">Calibrazione</button>" in PAGINA
|
||||||
|
assert 'role="tablist"' in PAGINA and 'role="tabpanel"' in PAGINA
|
||||||
|
assert 'aria-selected", cal ?' in PAGINA # la selezione cambia da JS
|
||||||
|
assert '"tmf.acq.tab"' in PAGINA # tab scelta ricordata (via memoria(), protetta)
|
||||||
|
|
||||||
|
|
||||||
|
def test_anteprima_fuori_dai_pannelli():
|
||||||
|
# l'anteprima sta nella colonna sinistra, prima dei due pannelli: visibile in entrambe le tab
|
||||||
|
i_ant = PAGINA.index('id="sezioneAnteprima"')
|
||||||
|
i_acq = PAGINA.index('id="pannelloAcq"')
|
||||||
|
i_cal = PAGINA.index('id="pannelloCal"')
|
||||||
|
assert i_ant < i_acq < i_cal
|
||||||
|
# Sorgente e Parametri nel pannello Acquisizione, la calibrazione in quello Calibrazione
|
||||||
|
assert i_acq < PAGINA.index('id="sezioneSorgente"') < PAGINA.index('id="sezioneParametri"') < i_cal
|
||||||
|
assert PAGINA.index('id="sezioneCalibrazione"') > i_cal
|
||||||
|
|
||||||
|
|
||||||
|
def test_id_del_pannello_calibrazione():
|
||||||
|
ids = set(re.findall(r'id="([^"]+)"', PAGINA))
|
||||||
|
attesi = {"calSorgente", "origSorgente", "origFile", "scegliFile", "file", "quadrato", "acquisisci",
|
||||||
|
"nomeCal", "salva", "msgSalva", "calibrazioni", "msgElenco", "stato", "risultato", "overlay"}
|
||||||
|
assert attesi <= ids, attesi - ids
|
||||||
|
usati = set(re.findall(r'\$\("([^"]+)"\)', PAGINA))
|
||||||
|
assert usati <= ids, usati - ids
|
||||||
|
assert len(re.findall(r'id="([^"]+)"', PAGINA)) == len(ids) # nessun id doppio
|
||||||
|
|
||||||
|
|
||||||
|
def test_testi_del_pannello():
|
||||||
|
for testo in ("Sorgente selezionata", "Immagine da file", "Scegli immagine...", "Calcola",
|
||||||
|
"Calibrazioni salvate", "si cambia nella tab Acquisizione", "risoluzione diversa",
|
||||||
|
"Carica", "Elimina", "Scollega", "Sovrascrivi «", "Clic ancora", "Nome"):
|
||||||
|
assert testo in PAGINA, testo
|
||||||
|
|
||||||
|
|
||||||
|
def test_rotte_del_contratto():
|
||||||
|
for rotta in ("/camera/calibrazioni", "/camera/calibrazione-attiva", "/camera/calibrate",
|
||||||
|
"/camera/calibration?source="):
|
||||||
|
assert '"' + rotta in PAGINA, rotta
|
||||||
|
for parola in ("calcolo_id", "sovrascrivi", "method: \"PUT\"", "method: \"DELETE\"", "X-Larghezza", "X-Altezza"):
|
||||||
|
assert parola in PAGINA, parola
|
||||||
|
# il calcolo non salva piu': il campo save sparisce
|
||||||
|
assert 'append("save"' not in PAGINA
|
||||||
|
|
||||||
|
|
||||||
|
def test_nessuna_finestra_del_browser_e_offline():
|
||||||
|
for vietato in ("alert(", "confirm(", "prompt(", "http://", "https://"):
|
||||||
|
assert vietato not in PAGINA, vietato
|
||||||
|
|
||||||
|
|
||||||
|
def test_acquisizione_di_87_90_conservata():
|
||||||
|
# anteprima, indicatori, mirino, grezzo, parametri camera e ciclo a 100 ms restano
|
||||||
|
for parola in ("Parametri camera", "Immagine grezza (senza correzione)", "Mirino centrale",
|
||||||
|
"Math.max(100 - (Date.now() - t0), 0)", "/camera/anteprima", "/camera/parametri"):
|
||||||
|
assert parola in PAGINA, parola
|
||||||
|
|
||||||
|
|
||||||
|
def test_pagina_stretta():
|
||||||
|
assert "@media (max-width: 500px)" in PAGINA
|
||||||
|
assert "overflow-x: auto" in PAGINA # l'elenco scorre di lato invece di rompere la pagina
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
"""Admin blueprint - user management."""
|
"""Admin blueprint - user management."""
|
||||||
|
from urllib.parse import urlparse # #88: validazione url camera
|
||||||
|
import requests as http_requests # #88: lettura sorgenti dall'acquisitore (come maker.py)
|
||||||
from flask import Blueprint, flash, jsonify, redirect, render_template, request, session, url_for
|
from flask import Blueprint, flash, jsonify, redirect, render_template, request, session, url_for
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
|
|
||||||
@@ -170,6 +172,39 @@ def api_toggle_active(user_id: int):
|
|||||||
|
|
||||||
# --- Stations ---
|
# --- Stations ---
|
||||||
|
|
||||||
|
@admin_bp.route("/api/camera/sources", methods=["GET"])
|
||||||
|
@login_required
|
||||||
|
@admin_required
|
||||||
|
def api_camera_sources():
|
||||||
|
"""Proxy (#88): elenco sorgenti di un acquisitore, GET <url>/camera/sources."""
|
||||||
|
url = (request.args.get("url") or "").strip()
|
||||||
|
parsed = urlparse(url)
|
||||||
|
if parsed.scheme not in ("http", "https") or not parsed.netloc:
|
||||||
|
return jsonify({"error": True, "detail": _("Indirizzo della camera non valido")}), 400
|
||||||
|
try:
|
||||||
|
resp = http_requests.get(f"{url.rstrip('/')}/camera/sources", timeout=5)
|
||||||
|
except http_requests.RequestException as exc:
|
||||||
|
return jsonify({
|
||||||
|
"error": True,
|
||||||
|
"detail": _("Servizio camera non raggiungibile: %(detail)s", detail=str(exc)),
|
||||||
|
}), 502
|
||||||
|
invalid = (jsonify({"error": True, "detail": _("Risposta non valida dal servizio camera")}), 502)
|
||||||
|
if resp.status_code != 200:
|
||||||
|
return invalid
|
||||||
|
try:
|
||||||
|
sources = resp.json().get("sources")
|
||||||
|
except (ValueError, AttributeError):
|
||||||
|
return invalid
|
||||||
|
if not isinstance(sources, list):
|
||||||
|
return invalid
|
||||||
|
# solo i tre campi che la UI usa, sempre stringhe
|
||||||
|
clean = [
|
||||||
|
{k: str(s.get(k, "")) for k in ("name", "label", "kind")}
|
||||||
|
for s in sources if isinstance(s, dict)
|
||||||
|
]
|
||||||
|
return jsonify({"sources": clean}), 200
|
||||||
|
|
||||||
|
|
||||||
@admin_bp.route("/api/stations", methods=["POST"])
|
@admin_bp.route("/api/stations", methods=["POST"])
|
||||||
@login_required
|
@login_required
|
||||||
@admin_required
|
@admin_required
|
||||||
|
|||||||
@@ -598,7 +598,7 @@ def api_station_camera_calibration(station_id: int):
|
|||||||
}), 409
|
}), 409
|
||||||
camera_url, camera_source = camera
|
camera_url, camera_source = camera
|
||||||
base = camera_url.rstrip("/")
|
base = camera_url.rstrip("/")
|
||||||
link = f"{base}/calibrazione" # pagina di calibrazione dell'acquisitore (C4)
|
link = f"{base}/acquisizione" # pagina di acquisizione dell'acquisitore (#88; era /calibrazione, C4)
|
||||||
try:
|
try:
|
||||||
resp = http_requests.get(
|
resp = http_requests.get(
|
||||||
f"{base}/camera/calibration",
|
f"{base}/camera/calibration",
|
||||||
|
|||||||
@@ -40,8 +40,8 @@ function stationCalibrationCell(station, msgs) {
|
|||||||
if (!this.hasCamera) return;
|
if (!this.hasCamera) return;
|
||||||
const r = await fetchStationCalibration(station.id);
|
const r = await fetchStationCalibration(station.id);
|
||||||
this.state = r.state || 'unreachable';
|
this.state = r.state || 'unreachable';
|
||||||
// Link «Calibra»: dal proxy, altrimenti costruito dall'indirizzo della camera
|
// Link «Acquisizione» (#88, era «Calibra»): dal proxy, altrimenti costruito dall'indirizzo della camera
|
||||||
this.calibrationUrl = r.calibration_url || (this.cameraUrl.replace(/\/+$/, '') + '/calibrazione');
|
this.calibrationUrl = r.calibration_url || (this.cameraUrl.replace(/\/+$/, '') + '/acquisizione');
|
||||||
if (this.state === 'calibrated') this.label = formatCalibration(r.calibration || {});
|
if (this.state === 'calibrated') this.label = formatCalibration(r.calibration || {});
|
||||||
else if (this.state === 'uncalibrated') this.label = this.msgs.uncalibrated || 'not calibrated';
|
else if (this.state === 'uncalibrated') this.label = this.msgs.uncalibrated || 'not calibrated';
|
||||||
else this.label = this.msgs.unreachable || 'camera service unreachable';
|
else this.label = this.msgs.unreachable || 'camera service unreachable';
|
||||||
|
|||||||
@@ -97,7 +97,7 @@
|
|||||||
</span>
|
</span>
|
||||||
<a :href="calibrationUrl" target="_blank" rel="noopener"
|
<a :href="calibrationUrl" target="_blank" rel="noopener"
|
||||||
x-show="calibrationUrl"
|
x-show="calibrationUrl"
|
||||||
class="font-medium text-primary hover:underline">{{ _('Calibra') }}</a>
|
class="font-medium text-primary hover:underline">{{ _('Acquisizione') }}</a> {# #88: era «Calibra» #}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</td>
|
</td>
|
||||||
@@ -238,21 +238,42 @@
|
|||||||
{# Camera della stazione (#72): servizio camera (vs-gui) e sorgente da cui prendere il frame #}
|
{# Camera della stazione (#72): servizio camera (vs-gui) e sorgente da cui prendere il frame #}
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-[var(--text-primary)] mb-1">{{ _('Camera (URL)') }}</label>
|
<label class="block text-sm font-medium text-[var(--text-primary)] mb-1">{{ _('Camera (URL)') }}</label>
|
||||||
<input type="text" x-model="form.camera_url"
|
<input type="text" x-model="form.camera_url" @change="loadCameraSources()"
|
||||||
class="w-full px-3 py-2 rounded-lg border border-[var(--border-color)] bg-[var(--bg-card)]
|
class="w-full px-3 py-2 rounded-lg border border-[var(--border-color)] bg-[var(--bg-card)]
|
||||||
text-sm font-mono text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-colors"
|
text-sm font-mono text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-colors"
|
||||||
placeholder="host:8765"
|
placeholder="host:8765"
|
||||||
maxlength="500">
|
maxlength="500">
|
||||||
<p class="mt-1 text-xs text-[var(--text-secondary)]">{{ _('Vuoto = nessuna camera. Indirizzo del servizio camera, con http o https, senza / finale') }}</p>
|
<p class="mt-1 text-xs text-[var(--text-secondary)]">{{ _('Vuoto = nessuna camera. Indirizzo del servizio camera, con http o https, senza / finale') }}</p>
|
||||||
</div>
|
</div>
|
||||||
|
{# Sorgente camera (#88): testo libero con suggerimenti letti dall'acquisitore (datalist) #}
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-[var(--text-primary)] mb-1">{{ _('Sorgente camera') }}</label>
|
<label class="block text-sm font-medium text-[var(--text-primary)] mb-1">{{ _('Sorgente camera') }}</label>
|
||||||
<input type="text" x-model="form.camera_source"
|
<div class="flex gap-2">
|
||||||
class="w-full px-3 py-2 rounded-lg border border-[var(--border-color)] bg-[var(--bg-card)]
|
<input type="text" x-model="form.camera_source" list="cameraSourcesList"
|
||||||
text-sm font-mono text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-colors"
|
class="flex-1 min-w-0 px-3 py-2 rounded-lg border border-[var(--border-color)] bg-[var(--bg-card)]
|
||||||
placeholder="camera:folder"
|
text-sm font-mono text-[var(--text-primary)] focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-colors"
|
||||||
maxlength="200">
|
placeholder="camera:folder"
|
||||||
<p class="mt-1 text-xs text-[var(--text-secondary)]">{{ _('Es. camera:<seriale> oppure camera:folder') }}</p>
|
maxlength="200">
|
||||||
|
<datalist id="cameraSourcesList">
|
||||||
|
<template x-for="s in cameraSources" :key="s.name">
|
||||||
|
<option :value="s.name" :label="s.label"></option>
|
||||||
|
</template>
|
||||||
|
</datalist>
|
||||||
|
<button type="button" @click="loadCameraSources()"
|
||||||
|
:disabled="!(form.camera_url || '').trim() || cameraSourcesLoading"
|
||||||
|
class="px-3 py-2 rounded-lg border border-[var(--border-color)] bg-[var(--bg-card)] text-sm font-medium
|
||||||
|
text-[var(--text-primary)] hover:bg-[var(--bg-secondary)] disabled:opacity-50 disabled:cursor-not-allowed transition-colors whitespace-nowrap">
|
||||||
|
{{ _('Leggi sorgenti') }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="mt-1 text-xs"
|
||||||
|
:class="cameraSourcesError ? 'text-red-600 dark:text-red-400' : 'text-[var(--text-secondary)]'"
|
||||||
|
x-text="cameraSourcesStatus || {{ _('Es. camera:<seriale> oppure camera:folder')|tojson_attr }}"></p>
|
||||||
|
<p x-show="cameraSourceMissing" class="mt-1 text-xs text-amber-700 dark:text-amber-300">{{ _("Sorgente non presente nell'acquisitore") }}</p>
|
||||||
|
<a x-show="(form.camera_url || '').trim()"
|
||||||
|
:href="(form.camera_url || '').trim().replace(/\/+$/, '') + '/acquisizione'"
|
||||||
|
target="_blank" rel="noopener"
|
||||||
|
class="mt-1 inline-block text-xs font-medium text-primary hover:underline">{{ _('Apri pagina acquisizione') }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -509,6 +530,12 @@ function stationManagement(initialStations, initialRecipes) {
|
|||||||
camera_source: '', // #72
|
camera_source: '', // #72
|
||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
|
// #88: sorgenti lette dall'acquisitore per il datalist della sorgente camera
|
||||||
|
cameraSources: [],
|
||||||
|
cameraSourcesLoaded: false,
|
||||||
|
cameraSourcesLoading: false,
|
||||||
|
cameraSourcesStatus: '',
|
||||||
|
cameraSourcesError: false,
|
||||||
|
|
||||||
get csrfToken() {
|
get csrfToken() {
|
||||||
const meta = document.querySelector('meta[name=csrf-token]');
|
const meta = document.querySelector('meta[name=csrf-token]');
|
||||||
@@ -556,11 +583,46 @@ function stationManagement(initialStations, initialRecipes) {
|
|||||||
return '{{ _("Nessuna ricetta assegnata") }}';
|
return '{{ _("Nessuna ricetta assegnata") }}';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// #88: legge le sorgenti dall'acquisitore (proxy admin) e riempie il datalist
|
||||||
|
async loadCameraSources() {
|
||||||
|
const url = (this.form.camera_url || '').trim();
|
||||||
|
this.cameraSources = [];
|
||||||
|
this.cameraSourcesLoaded = false;
|
||||||
|
this.cameraSourcesError = false;
|
||||||
|
if (!url) { this.cameraSourcesStatus = ''; return; }
|
||||||
|
this.cameraSourcesLoading = true;
|
||||||
|
this.cameraSourcesStatus = '{{ _("Lettura...") }}';
|
||||||
|
try {
|
||||||
|
const resp = await fetch('/admin/api/camera/sources?url=' + encodeURIComponent(url));
|
||||||
|
const result = await resp.json();
|
||||||
|
if (!resp.ok) {
|
||||||
|
this.cameraSourcesError = true;
|
||||||
|
this.cameraSourcesStatus = result.detail || '{{ _("Risposta non valida dal servizio camera") }}';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.cameraSources = result.sources || [];
|
||||||
|
this.cameraSourcesLoaded = true;
|
||||||
|
this.cameraSourcesStatus = '{{ _("%(n)s sorgenti trovate", n="__N__") }}'.replace('__N__', this.cameraSources.length);
|
||||||
|
} catch (e) {
|
||||||
|
this.cameraSourcesError = true;
|
||||||
|
this.cameraSourcesStatus = '{{ _("Risposta non valida dal servizio camera") }}';
|
||||||
|
} finally {
|
||||||
|
this.cameraSourcesLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// #88: avviso se la sorgente scritta non e' fra quelle lette
|
||||||
|
get cameraSourceMissing() {
|
||||||
|
const src = (this.form.camera_source || '').trim();
|
||||||
|
return this.cameraSourcesLoaded && src !== '' && !this.cameraSources.some(s => s.name === src);
|
||||||
|
},
|
||||||
|
|
||||||
openCreateModal() {
|
openCreateModal() {
|
||||||
this.isEditing = false;
|
this.isEditing = false;
|
||||||
this.editingId = null;
|
this.editingId = null;
|
||||||
this.errorMsg = '';
|
this.errorMsg = '';
|
||||||
this.form = { code: '', name: '', location: '', notes: '', vision_worker_url: '', camera_url: '', camera_source: '', active: true };
|
this.form = { code: '', name: '', location: '', notes: '', vision_worker_url: '', camera_url: '', camera_source: '', active: true };
|
||||||
|
this.loadCameraSources(); // #88: svuota lo stato delle sorgenti
|
||||||
this.showModal = true;
|
this.showModal = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -578,6 +640,7 @@ function stationManagement(initialStations, initialRecipes) {
|
|||||||
camera_source: station.camera_source || '', // #72
|
camera_source: station.camera_source || '', // #72
|
||||||
active: station.active,
|
active: station.active,
|
||||||
};
|
};
|
||||||
|
this.loadCameraSources(); // #88: se la camera e' valorizzata legge subito le sorgenti
|
||||||
this.showModal = true;
|
this.showModal = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -254,3 +254,74 @@ def test_create_station_proxy_forwards_the_camera_fields(logged_in_client, mock_
|
|||||||
resp = logged_in_client.post("/admin/api/stations", json=body)
|
resp = logged_in_client.post("/admin/api/stations", json=body)
|
||||||
assert resp.status_code == 201
|
assert resp.status_code == 201
|
||||||
mock_admin_api.post.assert_called_once_with("/api/stations", data=body)
|
mock_admin_api.post.assert_called_once_with("/api/stations", data=body)
|
||||||
|
|
||||||
|
|
||||||
|
# --- Sorgenti camera lette dall'acquisitore (#88) ---
|
||||||
|
|
||||||
|
def _fake_sources_response(status=200, payload=None):
|
||||||
|
resp = MagicMock()
|
||||||
|
resp.status_code = status
|
||||||
|
resp.json.return_value = payload
|
||||||
|
return resp
|
||||||
|
|
||||||
|
|
||||||
|
def test_camera_sources_proxy_keeps_only_the_three_fields(logged_in_client, mock_admin_api):
|
||||||
|
payload = {"sources": [
|
||||||
|
{"name": "camera:folder", "label": "Cartella", "kind": "folder", "extra": 1},
|
||||||
|
{"name": "camera:123", "label": "Basler", "kind": "gige"},
|
||||||
|
]}
|
||||||
|
with patch("blueprints.admin.http_requests.get",
|
||||||
|
return_value=_fake_sources_response(200, payload)) as get:
|
||||||
|
resp = logged_in_client.get("/admin/api/camera/sources?url=http://acq:8765/")
|
||||||
|
assert resp.status_code == 200
|
||||||
|
assert resp.get_json()["sources"][0] == {
|
||||||
|
"name": "camera:folder", "label": "Cartella", "kind": "folder"}
|
||||||
|
assert len(resp.get_json()["sources"]) == 2
|
||||||
|
assert get.call_args.args[0] == "http://acq:8765/camera/sources"
|
||||||
|
assert get.call_args.kwargs["timeout"] == 5
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("url", ["ftp://x", "", "http://", "acq:8765"])
|
||||||
|
def test_camera_sources_proxy_rejects_invalid_url(logged_in_client, mock_admin_api, url):
|
||||||
|
with patch("blueprints.admin.http_requests.get") as get:
|
||||||
|
resp = logged_in_client.get("/admin/api/camera/sources", query_string={"url": url})
|
||||||
|
assert resp.status_code == 400
|
||||||
|
assert resp.get_json()["error"] is True
|
||||||
|
get.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_camera_sources_proxy_unreachable_is_502(logged_in_client, mock_admin_api):
|
||||||
|
import requests
|
||||||
|
with patch("blueprints.admin.http_requests.get",
|
||||||
|
side_effect=requests.ConnectionError("rifiutata")):
|
||||||
|
resp = logged_in_client.get("/admin/api/camera/sources?url=http://acq:8765")
|
||||||
|
assert resp.status_code == 502
|
||||||
|
assert "rifiutata" in resp.get_json()["detail"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("status,payload", [(200, {"altro": 1}), (200, {"sources": "x"}), (500, {"sources": []})])
|
||||||
|
def test_camera_sources_proxy_invalid_response_is_502(logged_in_client, mock_admin_api, status, payload):
|
||||||
|
with patch("blueprints.admin.http_requests.get",
|
||||||
|
return_value=_fake_sources_response(status, payload)):
|
||||||
|
resp = logged_in_client.get("/admin/api/camera/sources?url=http://acq:8765")
|
||||||
|
assert resp.status_code == 502
|
||||||
|
|
||||||
|
|
||||||
|
def test_camera_sources_proxy_non_admin_is_redirected(client, mock_admin_api):
|
||||||
|
with client.session_transaction() as sess:
|
||||||
|
sess["api_key"] = "test-key"
|
||||||
|
sess["user"] = {"id": 2, "username": "operator", "roles": ["MeasurementTec"],
|
||||||
|
"is_admin": False, "active": True}
|
||||||
|
sess["user_id"] = 2
|
||||||
|
with patch("blueprints.admin.http_requests.get") as get:
|
||||||
|
resp = client.get("/admin/api/camera/sources?url=http://acq:8765")
|
||||||
|
assert resp.status_code in (301, 302)
|
||||||
|
get.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_station_form_has_the_camera_sources_picker(logged_in_client, mock_admin_api):
|
||||||
|
mock_admin_api.get.return_value = []
|
||||||
|
html = logged_in_client.get("/admin/stations").get_data(as_text=True)
|
||||||
|
assert "cameraSourcesList" in html
|
||||||
|
assert "loadCameraSources" in html
|
||||||
|
assert "/acquisizione" in html
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class TestStationCameraCalibration:
|
|||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert body["state"] == "calibrated"
|
assert body["state"] == "calibrated"
|
||||||
assert body["calibration"]["px_per_mm"] == 20.03
|
assert body["calibration"]["px_per_mm"] == 20.03
|
||||||
assert body["calibration_url"] == "http://acq:8765/calibrazione"
|
assert body["calibration_url"] == "http://acq:8765/acquisizione"
|
||||||
args, kwargs = get.call_args
|
args, kwargs = get.call_args
|
||||||
assert args[0] == "http://acq:8765/camera/calibration"
|
assert args[0] == "http://acq:8765/camera/calibration"
|
||||||
assert kwargs["params"] == {"source": "camera:folder"}
|
assert kwargs["params"] == {"source": "camera:folder"}
|
||||||
@@ -130,7 +130,7 @@ class TestStationCameraCalibration:
|
|||||||
resp, _ = self._get(logged_in_client, _fake(404, b"{}", {"detail": "no"}))
|
resp, _ = self._get(logged_in_client, _fake(404, b"{}", {"detail": "no"}))
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
assert resp.get_json()["state"] == "uncalibrated"
|
assert resp.get_json()["state"] == "uncalibrated"
|
||||||
assert resp.get_json()["calibration_url"] == "http://acq:8765/calibrazione"
|
assert resp.get_json()["calibration_url"] == "http://acq:8765/acquisizione"
|
||||||
|
|
||||||
def test_unreachable(self, logged_in_client, mock_api_client):
|
def test_unreachable(self, logged_in_client, mock_api_client):
|
||||||
_stations(mock_api_client)
|
_stations(mock_api_client)
|
||||||
|
|||||||
@@ -3452,3 +3452,36 @@ msgstr "Try"
|
|||||||
#: templates/maker/task_editor.html templates/admin/stations.html blueprints/maker.py
|
#: templates/maker/task_editor.html templates/admin/stations.html blueprints/maker.py
|
||||||
msgid "Salva ricetta"
|
msgid "Salva ricetta"
|
||||||
msgstr "Save recipe"
|
msgstr "Save recipe"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Acquisizione"
|
||||||
|
msgstr "Acquisition"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Leggi sorgenti"
|
||||||
|
msgstr "Read sources"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Lettura..."
|
||||||
|
msgstr "Reading..."
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
#, python-format
|
||||||
|
msgid "%(n)s sorgenti trovate"
|
||||||
|
msgstr "%(n)s sources found"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Sorgente non presente nell'acquisitore"
|
||||||
|
msgstr "Source not present in the acquisition service"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Apri pagina acquisizione"
|
||||||
|
msgstr "Open acquisition page"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Indirizzo della camera non valido"
|
||||||
|
msgstr "Invalid camera address"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Risposta non valida dal servizio camera"
|
||||||
|
msgstr "Invalid response from the camera service"
|
||||||
|
|||||||
@@ -3440,3 +3440,36 @@ msgstr "Prova"
|
|||||||
#: templates/maker/task_editor.html templates/admin/stations.html blueprints/maker.py
|
#: templates/maker/task_editor.html templates/admin/stations.html blueprints/maker.py
|
||||||
msgid "Salva ricetta"
|
msgid "Salva ricetta"
|
||||||
msgstr "Salva ricetta"
|
msgstr "Salva ricetta"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Acquisizione"
|
||||||
|
msgstr "Acquisizione"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Leggi sorgenti"
|
||||||
|
msgstr "Leggi sorgenti"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Lettura..."
|
||||||
|
msgstr "Lettura..."
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
#, python-format
|
||||||
|
msgid "%(n)s sorgenti trovate"
|
||||||
|
msgstr "%(n)s sorgenti trovate"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Sorgente non presente nell'acquisitore"
|
||||||
|
msgstr "Sorgente non presente nell'acquisitore"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Apri pagina acquisizione"
|
||||||
|
msgstr "Apri pagina acquisizione"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Indirizzo della camera non valido"
|
||||||
|
msgstr "Indirizzo della camera non valido"
|
||||||
|
|
||||||
|
#: templates/admin/stations.html blueprints/admin.py (#88)
|
||||||
|
msgid "Risposta non valida dal servizio camera"
|
||||||
|
msgstr "Risposta non valida dal servizio camera"
|
||||||
|
|||||||
Vendored
+1
-1
Submodule vendor/visionsuite updated: e0d19dee7e...06b549a25d
Reference in New Issue
Block a user