Intermediate Representation (IR)
Il Pattern è il tipo neutro che ogni reader produce e ogni
writer consuma. Coordinate assolute in 0,1 mm,
orientamento standard (y cresce verso l'alto; VIP memorizza y negato,
i readers normalizzano). Vaporizzata ogni eccentricità del formato
sorgente.
Tipo (TS)
type Command =
| 'STITCH' | 'JUMP' | 'TRIM'
| 'COLOR_CHANGE' | 'STOP' | 'END';
interface Stitch {
x: number; // assoluto, 0.1 mm
y: number; // assoluto, 0.1 mm
command: Command;
}
interface Thread {
rgb: number; // 24-bit 0xRRGGBB
description?: string;
catalog?: string;
chart?: string; // es. "Brother", "Janome"
}
interface Extents {
minX: number; minY: number; maxX: number; maxY: number;
}
interface Hoop {
width: number; // 0.1 mm
height: number;
name?: string; // es. "130x180" o un PES hoop-name
}
interface Pattern {
stitches: Stitch[];
threads: Thread[];
extents: Extents;
hoop?: Hoop; // presente solo se il formato lo porta
} Comandi
| Comando | Significato macchina |
|---|---|
STITCH | L'ago scende e cuce un punto. |
JUMP | Sposta senza cucire (per salti tra zone). |
TRIM | Taglia il filo. |
COLOR_CHANGE | Ferma per cambio colore della macchina. |
STOP | Ferma per intervento operatore. |
END | Fine del disegno. |
Ogni reader deve emettere un END come
ultimo record; ogni writer deve terminare il file con
il proprio END e (per i formati che lo prevedono) col checksum finale.
Extents e Hoop
extents è calcolato da computeExtents(stitches)
ignorando gli END. hoop è presente solo se il formato
sorgente lo memorizza (PES, JEF, PCS lo portano; VIP/ZHS solo extents).
Il writer decide cosa fare del hoop quando il formato di destinazione
non lo supporta: solitamente warn.HOOP_UNSUPPORTED.
Warnings strutturate
Lo scrittore segnala deviazioni inevitabili con un ConversionWarning:
interface ConversionWarning {
code:
| 'DELTA_63_SHIFTED' | 'METADATA_0X83_ZEROED'
| 'FILLER_THREAD' | 'COLOR_QUANTIZED'
| 'HOOP_FIT_EXCEEDED' | 'HOOP_UNSUPPORTED'
| 'TRIM_DROPPED';
message: string; // human-readable, EN, dell'engine
}
Il web app rimappa ogni code alla sua chiave i18n
(warn.DELTA_63_SHIFTED, ecc.) e lo mostra nella lista
risultati. Lo store IT/EN/FR/DE/ES/PT vive in
apps/web/src/i18n/strings.ts.
UnsupportedDesignError
Se un disegno contiene qualcosa che il formato di destinazione
proprio non può esprimere (non con un workaround) il writer
solleva UnsupportedDesignError con un
reason: UnsupportedReason. Lo UI mappa ogni reason alla sua
chiave i18n (err.EMPTY, err.MULTI_COLOR,
err.TRIM, err.JUMP, err.STOP,
err.DELTA_RANGE, err.TOO_MANY_RECORDS,
err.TOO_LARGE).