diff --git a/src/frontend/flask_app/static/js/dxf_recipe_wizard.js b/src/frontend/flask_app/static/js/dxf_recipe_wizard.js index adbcd5c..6d7048e 100644 --- a/src/frontend/flask_app/static/js/dxf_recipe_wizard.js +++ b/src/frontend/flask_app/static/js/dxf_recipe_wizard.js @@ -128,6 +128,13 @@ function dxfRecipeWizard(taskId, csrf, msgs) { return contorni.filter(c => c && c.length > 1).map(c => c.map(p => p[0] + ',' + p[1]).join(' ')); }, + // #101: tutti i contorni in un solo attributo `d` ("M x y L x y ..."): x-for non funziona dentro + dxfPreviewD() { + const contorni = (this.dxfPreview && this.dxfPreview.contorni) || []; + return contorni.filter(c => c && c.length > 1) + .map(c => c.map((p, i) => (i ? 'L ' : 'M ') + p[0] + ' ' + p[1]).join(' ')).join(' '); + }, + // #101: viewBox sul bbox con margine 5% (minimo 0.5 mm per lato) dxfPreviewViewBox() { const b = this.dxfPreview && this.dxfPreview.bbox; diff --git a/src/frontend/flask_app/templates/maker/task_editor.html b/src/frontend/flask_app/templates/maker/task_editor.html index c3b6fed..7101356 100644 --- a/src/frontend/flask_app/templates/maker/task_editor.html +++ b/src/frontend/flask_app/templates/maker/task_editor.html @@ -718,14 +718,13 @@

{{ _('Lettura DXF…') }}

- - + +

diff --git a/src/frontend/flask_app/tests/js/test_dxf_preview.js b/src/frontend/flask_app/tests/js/test_dxf_preview.js index ad2f1d3..af123a4 100644 --- a/src/frontend/flask_app/tests/js/test_dxf_preview.js +++ b/src/frontend/flask_app/tests/js/test_dxf_preview.js @@ -38,6 +38,12 @@ const PREVIEW = { check('un contorno con >1 punti diventa una polyline (quello da 1 punto no)', paths.length === 1); check('formato points', paths[0] === '0,-5 12.3,-5 12.3,0 0,0 0,-5', paths[0]); + // #101: path unico per + check('dxfPreviewD', w.dxfPreviewD() === 'M 0 -5 L 12.3 -5 L 12.3 0 L 0 0 L 0 -5', w.dxfPreviewD()); + w.dxfPreview = null; + check('dxfPreviewD vuoto senza anteprima', w.dxfPreviewD() === ''); + w.dxfPreview = PREVIEW; + const vb = w.dxfPreviewViewBox().split(' ').map(Number); const m = Math.max(0.5, 0.05 * 12.3); check('viewBox con margine 5%', Math.abs(vb[0] + m) < 1e-3 && Math.abs(vb[2] - (12.3 + 2 * m)) < 1e-3, vb.join(' ')); diff --git a/src/frontend/flask_app/tests/test_dxf_recipe_routes.py b/src/frontend/flask_app/tests/test_dxf_recipe_routes.py index 4e82ce1..b510e3d 100644 --- a/src/frontend/flask_app/tests/test_dxf_recipe_routes.py +++ b/src/frontend/flask_app/tests/test_dxf_recipe_routes.py @@ -279,5 +279,5 @@ class TestPages: assert "dxfRecipeWizard(" in html assert "@dxf-recipe-saved" in html assert 'x-model="mmPx"' in html # #98: campo mm/px a mano - assert "dxfPreviewPaths()" in html # #101: anteprima SVG del DXF + assert "dxfPreviewD()" in html and "view-box.camel" in html # #101: anteprima SVG del DXF assert "Pezzo scuro su fondo chiaro" in html or "Dark part on light" in html